summaryrefslogtreecommitdiffstats
path: root/dom/events/test/test_mouse_over_at_removing_down_target.html
blob: c5e001b9f1a3f8676534e994ac9ce78d16f4668f (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
66
67
68
69
70
71
72
73
74
75
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Check whether `mouseup` events are fired after pending boundary events</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
<style>
div#parent {
  width: 100%;
  height: 50px;
  background-color: gray;
}
div#child {
  width: 100%;
  height: 40px;
  background-color: lime;
}
</style>
<script>
"use strict";

SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(async () => {
  await SpecialPowers.pushPrefEnv({ set: [["layout.reflow.synthMouseMove", true]] });
  const winUtils = SpecialPowers.wrap(window).windowUtils;
  try {
    winUtils.disableNonTestMouseEvents(true);
    const parent = document.querySelector("div");
    const child = parent.querySelector("div");
    synthesizeMouseAtCenter(child, { type: "mousemove" });
    await new Promise(resolve => requestAnimationFrame(
      () => requestAnimationFrame(resolve)
    ));

    const mouseEvents = [];
    child.addEventListener("mousedown", event => {
      event.target.remove();
      mouseEvents.push("mousedown@div#child");
    });
    document.addEventListener("mouseover", event => {
      mouseEvents.push(`mouseover@${event.target.localName}${event.target.id ? `#${event.target.id}` : ""}`);
    }, {capture: true});
    document.addEventListener("mouseup", event => {
      mouseEvents.push(`mouseup@${event.target.localName}${event.target.id ? `#${event.target.id}` : ""}`);
    }, {capture: true});
    winUtils.advanceTimeAndRefresh(100);
    // Click in the child, then, the child will be removed by the "mousedown"
    // event listener and that should cause "mouseover" on the parent and that
    // must be fired before "mouseup".
    synthesizeMouseAtCenter(child, {});
    winUtils.restoreNormalRefresh();
    await new Promise(resolve => requestAnimationFrame(
      () => requestAnimationFrame(resolve)
    ));
    is(
      mouseEvents.toString(),
      "mousedown@div#child,mouseover@div#parent,mouseup@div#parent",
      "mouseover should be fired before mouseup on the ex-parent of the removed child"
    );
  } finally {
    winUtils.disableNonTestMouseEvents(false);
    document.querySelector("style").remove();
  }
  SimpleTest.finish();
});
</script>
</head>
<body>
<div id="parent">
 <div id="child"></div>
</div>
</body>
</html>