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
|
<!DOCTYPE HTML>
<html>
<head>
<title>Test for Bug 989198</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/NativeKeyCodes.js"></script>
<script type="text/javascript" src="bug989198_helper.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body onload="runTests();">
<a target="_blank"
href="https://bugzilla.mozilla.org/show_bug.cgi?id=989198">Mozilla Bug 989198</a>
<p id="display"></p>
<pre id="test">
<script type="application/javascript">
SimpleTest.waitForExplicitFinish();
function cleanupTest()
{
teardownHandlers(window, embedderHandler);
runTests();
}
function testEventOrderAndAttr()
{
const kTests = [
{
description: "Testing the order of the events",
expectedEvents: [ [ kParent | kBeforeEvent | kKeyDownEvent,
kChild | kKeyDownEvent,
kParent | kAfterEvent | kKeyDownEvent ],
[ kParent | kBeforeEvent | kKeyUpEvent,
kChild | kKeyUpEvent,
kParent | kAfterEvent | kKeyUpEvent ] ],
resultEvents: [],
classifiedEvents: [ [], [] ],
doPreventDefaultAt: kUnknownEvent
},
{
description: "Testing the order of the events, calling preventDefault() at \"mozbrowserbeforekeydown\" event",
expectedEvents: [ [ kParent | kBeforeEvent | kKeyDownEvent,
kParent | kAfterEvent | kKeyDownEvent ],
[ kParent | kBeforeEvent | kKeyUpEvent,
kChild | kKeyUpEvent,
kParent | kAfterEvent | kKeyUpEvent ] ],
resultEvents: [],
classifiedEvents: [ [], [] ],
doPreventDefaultAt: kParent | kBeforeEvent | kKeyDownEvent
},
{
description: "Testing the order of the events, calling preventDefault() at \"mozbrowserbeforekeyup\" event",
expectedEvents: [ [ kParent | kBeforeEvent | kKeyDownEvent,
kChild | kKeyDownEvent,
kParent | kAfterEvent | kKeyDownEvent ],
[ kParent | kBeforeEvent | kKeyUpEvent,
kParent | kAfterEvent | kKeyUpEvent ] ],
resultEvents: [],
classifiedEvents: [ [], [] ],
doPreventDefaultAt: kParent | kBeforeEvent | kKeyUpEvent
},
{
description: "Testing the order of the events, calling preventDefault() at \"keydown\" event",
expectedEvents: [ [ kParent | kBeforeEvent | kKeyDownEvent,
kChild | kKeyDownEvent,
kParent | kAfterEvent | kKeyDownEvent ],
[ kParent | kBeforeEvent | kKeyUpEvent,
kChild | kKeyUpEvent,
kParent | kAfterEvent | kKeyUpEvent ] ],
resultEvents: [],
classifiedEvents: [ [], [] ],
doPreventDefaultAt: kChild | kKeyDownEvent
},
{
description: "Testing the order of the events, calling preventDefault() at \"keyup\" event",
expectedEvents: [ [ kParent | kBeforeEvent | kKeyDownEvent,
kChild | kKeyDownEvent,
kParent | kAfterEvent | kKeyDownEvent ],
[ kParent | kBeforeEvent | kKeyUpEvent,
kChild | kKeyUpEvent,
kParent | kAfterEvent | kKeyUpEvent ] ],
resultEvents: [],
classifiedEvents: [ [], [] ],
doPreventDefaultAt: kChild | kKeyUpEvent
}
];
for (var k = 0; k < kTests.length; k++ ) {
gCurrentTest = kTests[k];
synthesizeKey('a', {}, document.getElementById("embedded").contentWindow);
classifyEvents(kTests[k]);
verifyResults(kTests[k]);
}
runTests();
}
var tests = [
function addPermissions() {
SpecialPowers.pushPermissions(
[{ type: "before-after-keyboard-event", allow: true, context: document },
{ type: "browser", allow: true, context: document }],
runTests);
},
function addPreferences() {
SpecialPowers.pushPrefEnv(
{ "set": [["dom.beforeAfterKeyboardEvent.enabled", true],
["dom.mozBrowserFramesEnabled", true],
["network.disable.ipc.security", true],
["dom.ipc.tabs.disabled", false]] },
runTests);
},
// Tests for in-process iframe, i.e. <iframe mozbrowser>.
function () {
prepareTest(false);
},
testEventOrderAndAttr,
cleanupTest,
];
function runTests()
{
if (!tests.length) {
SimpleTest.finish();
return;
}
var test = tests.shift();
test();
}
</script>
</body>
</html>
|