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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=493251
-->
<head>
<title>Test for Bug 493251</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=493251">Mozilla Bug 493251</a>
<p id="display">
</p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 493251 **/
var win;
var mouseDown = 0;
var mouseUp = 0;
var mouseClick = 0;
var keyDown = 0;
var keyPress = 0;
var keyUp = 0;
function suppressEventHandling(aSuppress) {
var utils = SpecialPowers.getDOMWindowUtils(win);
ok(true, "suppressEventHandling: aSuppress=" + aSuppress);
utils.suppressEventHandling(aSuppress);
}
function dispatchMouseEvent(aType, aX, aY, aButton, aClickCount, aModifiers) {
var utils = SpecialPowers.getDOMWindowUtils(win);
ok(true, "Dipatching mouse event: aType=" + aType + ", aX=" + aX + ", aY" +
aY + ", aButton=" + aButton + ", aClickCount=" + aClickCount +
", aModifiers=" + aModifiers);
utils.sendMouseEvent(aType, aX, aY, aButton, aClickCount, aModifiers);
}
function dumpEvent(aEvent) {
var detail = "target=" + aEvent.target + ", originalTarget=" +
aEvent.originalTarget + ", defaultPrevented=" +
aEvent.defaultPrevented + ", isTrusted=" + aEvent.isTrusted;
switch (aEvent.type) {
case "keydown":
case "keypress":
case "keyup":
detail += ", charCode=0x" + aEvent.charCode.toString(16) +
", keyCode=0x" + aEvent.keyCode.toString(16) +
", altKey=" + (aEvent.altKey ? "PRESSED" : "no") +
", ctrlKey=" + (aEvent.ctrlKey ? "PRESSED" : "no") +
", shiftKey=" + (aEvent.shiftKey ? "PRESSED" : "no") +
", metaKey=" + (aEvent.metaKey ? "PRESSED" : "no");
break;
case "mousedown":
case "mouseup":
case "click":
detail += ", screenX=" + aEvent.screenX + ", screenY=" + aEvent.screenY +
", clientX=" + aEvent.clientX + ", clientY=" + aEvent.clientY +
", altKey=" + (aEvent.altKey ? "PRESSED" : "no") +
", ctrlKey=" + (aEvent.ctrlKey ? "PRESSED" : "no") +
", shiftKey=" + (aEvent.shiftKey ? "PRESSED" : "no") +
", metaKey=" + (aEvent.metaKey ? "PRESSED" : "no") +
", button=" + aEvent.button +
", relatedTarget=" + aEvent.relatedTarget;
break;
}
ok(true, aEvent.type + " event is handled: " + detail);
var fm = SpecialPowers.Cc["@mozilla.org/focus-manager;1"].
getService(SpecialPowers.Ci.nsIFocusManager);
ok(true, "focused element is \"" + fm.focusedElement +
"\" and focused window is \"" + fm.focusedWindow +
"\" (the testing window is \"" + win + "\"");
}
function doTest() {
win.document.getElementsByTagName("input")[0].focus();
win.addEventListener("keydown",
function(e) { dumpEvent(e); ++keyDown; }, true);
win.addEventListener("keypress",
function(e) { dumpEvent(e); ++keyPress; }, true);
win.addEventListener("keyup",
function(e) { dumpEvent(e); ++keyUp; }, true);
win.addEventListener("mousedown",
function(e) { dumpEvent(e); ++mouseDown; }, true);
win.addEventListener("mouseup",
function(e) { dumpEvent(e); ++mouseUp; }, true);
win.addEventListener("click",
function(e) { dumpEvent(e); ++mouseClick; }, true);
ok(true, "doTest #1...");
synthesizeKey("a", {}, win);
is(keyDown, 1, "Wrong number events (1)");
is(keyPress, 1, "Wrong number events (2)");
is(keyUp, 1, "Wrong number events (3)");
ok(true, "doTest #2...");
suppressEventHandling(true);
synthesizeKey("a", {}, win);
is(keyDown, 1, "Wrong number events (4)");
is(keyPress, 1, "Wrong number events (5)");
is(keyUp, 1, "Wrong number events (6)");
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() {
ok(true, "continueTest1...");
win.addEventListener("keydown", () => { suppressEventHandling(true); }, {once: true});
synthesizeKey("a", {}, win);
is(keyDown, 2, "Wrong number events (10)");
is(keyPress, 1, "Wrong number events (11)");
is(keyUp, 1, "Wrong number events (12)");
suppressEventHandling(false);
setTimeout(continueTest2, 0);
}
function continueTest2() {
ok(true, "continueTest2 #1...");
is(keyDown, 2, "Wrong number events (13)");
is(keyPress, 2, "Wrong number events (14)");
is(keyUp, 2, "Wrong number events (15)");
dispatchMouseEvent("mousedown", 5, 5, 0, 1, 0);
dispatchMouseEvent("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)");
ok(true, "continueTest2 #2...");
suppressEventHandling(true);
dispatchMouseEvent("mousedown", 5, 5, 0, 1, 0);
dispatchMouseEvent("mouseup", 5, 5, 0, 1, 0);
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() {
ok(true, "continueTest3...");
dispatchMouseEvent("mousedown", 5, 5, 0, 1, 0);
suppressEventHandling(true);
dispatchMouseEvent("mouseup", 5, 5, 0, 1, 0);
suppressEventHandling(false);
setTimeout(continueTest4, 1000);
}
function continueTest4() {
ok(true, "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("window_bug493251.html", "_blank" , "width=500,height=500");
</script>
</pre>
</body>
</html>
|