Bug 1880216 - Migrate Fenix docs into Sphinx. r=owlish,geckoview-reviewers,android...
[gecko.git] / dom / events / test / test_bug545268.html
blobda4d0d1649d62c9823e55e324ffaea4ffccff9cd
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=545268
5 -->
6 <head>
7 <title>Test for Bug 545268</title>
8 <script src="/tests/SimpleTest/SimpleTest.js"></script>
9 <script src="/tests/SimpleTest/EventUtils.js"></script>
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
11 </head>
12 <body>
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=545268">Mozilla Bug 545268</a>
14 <p id="display">
15 </p>
16 <div id="content" style="display: none">
18 </div>
19 <pre id="test">
20 <script type="application/javascript">
22 /** Test for Bug 545268
23 Like the test for bug 493251, but we test that suppressing events in
24 a parent window stops the events from reaching the child window. */
26 var win;
27 var subwin;
29 var mouseDown = 0;
30 var mouseUp = 0;
31 var mouseClick = 0;
33 var keyDown = 0;
34 var keyPress = 0;
35 var keyUp = 0;
37 function doTest() {
38 var utils = SpecialPowers.getDOMWindowUtils(win);
39 var f = win.document.getElementById("f");
40 subwin = f.contentWindow;
41 subwin.document.getElementsByTagName("input")[0].focus();
42 subwin.addEventListener("keydown", function(e) { ++keyDown; }, true);
43 subwin.addEventListener("keypress", function(e) { ++keyPress; }, true);
44 subwin.addEventListener("keyup", function(e) { ++keyUp; }, true);
45 subwin.addEventListener("mousedown", function(e) { ++mouseDown; }, true);
46 subwin.addEventListener("mouseup", function(e) { ++mouseUp; }, true);
47 subwin.addEventListener("click", function(e) { ++mouseClick; }, true);
49 synthesizeKey("a", {}, subwin);
50 is(keyDown, 1, "Wrong number events (1)");
51 is(keyPress, 1, "Wrong number events (2)");
52 is(keyUp, 1, "Wrong number events (3)");
54 // Test that suppressing events on the parent window prevents key
55 // events in the subdocument window
56 utils.suppressEventHandling(true);
57 synthesizeKey("a", {}, subwin);
58 is(keyDown, 1, "Wrong number events (4)");
59 is(keyPress, 1, "Wrong number events (5)");
60 is(keyUp, 1, "Wrong number events (6)");
61 utils.suppressEventHandling(false);
62 is(keyDown, 1, "Wrong number events (7)");
63 is(keyPress, 1, "Wrong number events (8)");
64 is(keyUp, 1, "Wrong number events (9)");
66 setTimeout(continueTest1, 0);
69 function continueTest1() {
70 var utils = SpecialPowers.getDOMWindowUtils(win);
71 subwin.addEventListener("keydown", () => { utils.suppressEventHandling(true); }, {once: true});
72 synthesizeKey("a", {}, subwin);
73 is(keyDown, 2, "Wrong number events (10)");
74 is(keyPress, 1, "Wrong number events (11)");
75 is(keyUp, 1, "Wrong number events (12)");
76 utils.suppressEventHandling(false);
77 setTimeout(continueTest2, 0);
80 function continueTest2() {
81 var utils = SpecialPowers.getDOMWindowUtils(win);
82 is(keyDown, 2, "Wrong number events (13)");
83 is(keyPress, 2, "Wrong number events (14)");
84 is(keyUp, 2, "Wrong number events (15)");
86 utils.sendMouseEvent("mousedown", 5, 5, 0, 1, 0);
87 utils.sendMouseEvent("mouseup", 5, 5, 0, 1, 0);
88 is(mouseDown, 1, "Wrong number events (16)");
89 is(mouseUp, 1, "Wrong number events (17)");
90 is(mouseClick, 1, "Wrong number events (18)");
92 utils.suppressEventHandling(true);
93 utils.sendMouseEvent("mousedown", 5, 5, 0, 1, 0);
94 utils.sendMouseEvent("mouseup", 5, 5, 0, 1, 0);
95 utils.suppressEventHandling(false);
96 is(mouseDown, 1, "Wrong number events (19)");
97 is(mouseUp, 1, "Wrong number events (20)");
98 is(mouseClick, 1, "Wrong number events (21)");
100 setTimeout(continueTest3, 0);
103 function continueTest3() {
104 var utils = SpecialPowers.getDOMWindowUtils(win);
105 utils.sendMouseEvent("mousedown", 5, 5, 0, 1, 0);
106 utils.suppressEventHandling(true);
107 utils.sendMouseEvent("mouseup", 5, 5, 0, 1, 0);
108 utils.suppressEventHandling(false);
109 setTimeout(continueTest4, 1000);
112 function continueTest4() {
113 is(mouseDown, 2, "Wrong number events (19)");
114 is(mouseUp, 2, "Wrong number events (20)");
115 is(mouseClick, 2, "Wrong number events (21)");
116 win.close();
117 SimpleTest.finish();
121 SimpleTest.waitForExplicitFinish();
122 SimpleTest.requestFlakyTimeout("untriaged");
123 win = window.open("bug545268.html", "" , "");
124 win.onload = doTest;
126 </script>
127 </pre>
128 </body>
129 </html>