summaryrefslogtreecommitdiffstats
path: root/dom/events/test/test_bug545268.html
blob: da4d0d1649d62c9823e55e324ffaea4ffccff9cd (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=545268
-->
<head>
  <title>Test for Bug 545268</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"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=545268">Mozilla Bug 545268</a>
<p id="display">
</p>
<div id="content" style="display: none">
  
</div>
<pre id="test">
<script type="application/javascript">

/** Test for Bug 545268
    Like the test for bug 493251, but we test that suppressing events in
    a parent window stops the events from reaching the child window. */

  var win;
  var subwin;

  var mouseDown = 0;
  var mouseUp = 0;
  var mouseClick = 0;

  var keyDown = 0;
  var keyPress = 0;
  var keyUp = 0;

  function doTest() {
    var utils = SpecialPowers.getDOMWindowUtils(win);
    var f = win.document.getElementById("f");
    subwin = f.contentWindow;
    subwin.document.getElementsByTagName("input")[0].focus();
    subwin.addEventListener("keydown", function(e) { ++keyDown; }, true);
    subwin.addEventListener("keypress", function(e) { ++keyPress; }, true);
    subwin.addEventListener("keyup", function(e) { ++keyUp; }, true);
    subwin.addEventListener("mousedown", function(e) { ++mouseDown; }, true);
    subwin.addEventListener("mouseup", function(e) { ++mouseUp; }, true);
    subwin.addEventListener("click", function(e) { ++mouseClick; }, true);

    synthesizeKey("a", {}, subwin);
    is(keyDown, 1, "Wrong number events (1)");
    is(keyPress, 1, "Wrong number events (2)");
    is(keyUp, 1, "Wrong number events (3)");

    // Test that suppressing events on the parent window prevents key
    // events in the subdocument window
    utils.suppressEventHandling(true);
    synthesizeKey("a", {}, subwin);
    is(keyDown, 1, "Wrong number events (4)");
    is(keyPress, 1, "Wrong number events (5)");
    is(keyUp, 1, "Wrong number events (6)");
    utils.suppressEventHandling(false);
    is(keyDown, 1, "Wrong number events (7)");
    is(keyPress, 1, "Wrong number events (8)");
    is(keyUp, 1, "Wrong number events (9)");

    setTimeout(continueTest1, 0);
    }

  function continueTest1() {
    var utils = SpecialPowers.getDOMWindowUtils(win);
    subwin.addEventListener("keydown", () => { utils.suppressEventHandling(true); }, {once: true});
    synthesizeKey("a", {}, subwin);
    is(keyDown, 2, "Wrong number events (10)");
    is(keyPress, 1, "Wrong number events (11)");
    is(keyUp, 1, "Wrong number events (12)");
    utils.suppressEventHandling(false);
    setTimeout(continueTest2, 0);
  }

  function continueTest2() {
    var utils = SpecialPowers.getDOMWindowUtils(win);
    is(keyDown, 2, "Wrong number events (13)");
    is(keyPress, 2, "Wrong number events (14)");
    is(keyUp, 2, "Wrong number events (15)");

    utils.sendMouseEvent("mousedown", 5, 5, 0, 1, 0);
    utils.sendMouseEvent("mouseup", 5, 5, 0, 1, 0);
    is(mouseDown, 1, "Wrong number events (16)");
    is(mouseUp, 1, "Wrong number events (17)");
    is(mouseClick, 1, "Wrong number events (18)");

    utils.suppressEventHandling(true);
    utils.sendMouseEvent("mousedown", 5, 5, 0, 1, 0);
    utils.sendMouseEvent("mouseup", 5, 5, 0, 1, 0);
    utils.suppressEventHandling(false);
    is(mouseDown, 1, "Wrong number events (19)");
    is(mouseUp, 1, "Wrong number events (20)");
    is(mouseClick, 1, "Wrong number events (21)");

    setTimeout(continueTest3, 0);
  }

  function continueTest3() {
    var utils = SpecialPowers.getDOMWindowUtils(win);
    utils.sendMouseEvent("mousedown", 5, 5, 0, 1, 0);
    utils.suppressEventHandling(true);
    utils.sendMouseEvent("mouseup", 5, 5, 0, 1, 0);
    utils.suppressEventHandling(false);
    setTimeout(continueTest4, 1000);
  }

  function continueTest4() {
    is(mouseDown, 2, "Wrong number events (19)");
    is(mouseUp, 2, "Wrong number events (20)");
    is(mouseClick, 2, "Wrong number events (21)");
    win.close();
    SimpleTest.finish();
  }


  SimpleTest.waitForExplicitFinish();
  SimpleTest.requestFlakyTimeout("untriaged");
  win = window.open("bug545268.html", "" , "");
  win.onload = doTest;

</script>
</pre>
</body>
</html>