summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/editing/crashtests/remove-editing-host-during-forwarddelete.html
blob: 6013361ccb0e5078292beadc8fec537df9c325a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<!doctype html>
<html class="test-wait">
<head>
<meta charset="utf-8">
<style>
dir {
  animation: kf, 0s infinite paused;
}
svg {
  animation-name: kf;
}
@keyframes kf {}
</style>
<script>
let dir;
// animationend for <svg> and <dir> may be fired before "DOMContentLoaded".
// Therefore, let's start to listen them immediately.
const waitForAnimationEnd = new Promise(resolve => {
  let count = 0;
  function onAnimationEnd() {
    window.find("AAAAAAAAAA");
    document.execCommand("forwardDelete");
    count++;
    function getRemainingEventCount(event) {
      if (count >= 2) {
        return 0;
      }
      if (event.target.tagName == "DIR") {
        return 0;
      }
      // If `animationend` is delayed and `<dir>` has already been removed,
      // `animationend` for it is never fired anymore.
      return dir && !dir.isConnected ? 0 : 1;
    }
    if (!getRemainingEventCount()) {
      window.removeEventListener("animationend", onAnimationEnd);
      resolve();
    }
  }
  window.addEventListener("animationend", onAnimationEnd);
});

document.addEventListener("DOMContentLoaded", async () => {
  dir = document.querySelector("dir");
  window.find("A");
  document.execCommand("insertHTML", false, "AAAAAAAAAAAAAAAA");
  dir.addEventListener("DOMNodeRemoved", event => {
    dir.remove();
  });
  window.find("A");
  document.execCommand("delete");
  await waitForAnimationEnd;
  document.documentElement.removeAttribute("class");
});
</script>
</head>
<body>
<svg>
<s></s>
<dir contenteditable>
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
</dir>
</svg>
</body>
</html>