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
182
183
|
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1157469
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 1157469</title>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
<script type="application/javascript;version=1.8" src="inspector-helpers.js"></script>
<script type="application/javascript;version=1.8">
window.onload = function() {
const Cu = Components.utils;
const {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
const {InspectorFront} = require("devtools/shared/fronts/inspector");
SimpleTest.waitForExplicitFinish();
let inspectee = null;
let inspector = null;
let walker = null;
let eventListener1 = function () {};
let eventListener2 = function () {};
let eventNode1;
let eventNode2;
let eventFront1;
let eventFront2;
addAsyncTest(function* setup() {
info ("Setting up inspector and walker actors.");
let url = document.getElementById("inspectorContent").href;
yield new Promise(resolve => {
attachURL(url, function(err, client, tab, doc) {
inspectee = doc;
inspector = InspectorFront(client, tab);
resolve();
});
});
walker = yield inspector.getWalker();
ok(walker, "getWalker() should return an actor.");
runNextTest();
});
addAsyncTest(function* setupEventTest() {
eventNode1 = inspectee.querySelector("#a")
eventNode2 = inspectee.querySelector("#b")
eventFront1 = yield walker.querySelector(walker.rootNode, "#a");
eventFront2 = yield walker.querySelector(walker.rootNode, "#b");
runNextTest();
});
addAsyncTest(function* testChangeEventListenerOnSingleNode() {
checkNodesHaveNoEventListener();
info("add event listener on a single node");
eventNode1.addEventListener("click", eventListener1);
let mutations = yield waitForMutations();
is(mutations.length, 1, "one mutation expected");
is(mutations[0].target, eventFront1, "mutation targets eventFront1");
is(mutations[0].type, "events", "mutation type is events");
is(mutations[0].hasEventListeners, true, "mutation target should have event listeners");
is(eventFront1.hasEventListeners, true, "eventFront1 should have event listeners");
info("remove event listener on a single node");
eventNode1.removeEventListener("click", eventListener1);
mutations = yield waitForMutations();
is(mutations.length, 1, "one mutation expected");
is(mutations[0].target, eventFront1, "mutation targets eventFront1");
is(mutations[0].type, "events", "mutation type is events");
is(mutations[0].hasEventListeners, false, "mutation target should have no event listeners");
is(eventFront1.hasEventListeners, false, "eventFront1 should have no event listeners");
info("perform several event listener changes on a single node")
eventNode1.addEventListener("click", eventListener1);
eventNode1.addEventListener("click", eventListener2);
eventNode1.removeEventListener("click", eventListener1);
eventNode1.removeEventListener("click", eventListener2);
mutations = yield waitForMutations();
is(mutations.length, 1, "one mutation expected");
is(mutations[0].target, eventFront1, "mutation targets eventFront1");
is(mutations[0].type, "events", "mutation type is events");
is(mutations[0].hasEventListeners, false, "no event listener expected on mutation target");
is(eventFront1.hasEventListeners, false, "no event listener expected on node");
runNextTest();
});
addAsyncTest(function* testChangeEventsOnSeveralNodes() {
checkNodesHaveNoEventListener();
info("add event listeners on both nodes");
eventNode1.addEventListener("click", eventListener1);
eventNode2.addEventListener("click", eventListener2);
let mutations = yield waitForMutations();
is(mutations.length, 2, "two mutations expected, one for each modified node");
// first mutation
is(mutations[0].target, eventFront1, "first mutation targets eventFront1");
is(mutations[0].type, "events", "mutation type is events");
is(mutations[0].hasEventListeners, true, "mutation target should have event listeners");
is(eventFront1.hasEventListeners, true, "eventFront1 should have event listeners");
// second mutation
is(mutations[1].target, eventFront2, "second mutation targets eventFront2");
is(mutations[1].type, "events", "mutation type is events");
is(mutations[1].hasEventListeners, true, "mutation target should have event listeners");
is(eventFront2.hasEventListeners, true, "eventFront1 should have event listeners");
info("remove event listeners on both nodes");
eventNode1.removeEventListener("click", eventListener1);
eventNode2.removeEventListener("click", eventListener2);
mutations = yield waitForMutations();
is(mutations.length, 2, "one mutation registered for event listener change");
// first mutation
is(mutations[0].target, eventFront1, "first mutation targets eventFront1");
is(mutations[0].type, "events", "mutation type is events");
is(mutations[0].hasEventListeners, false, "mutation target should have no event listeners");
is(eventFront1.hasEventListeners, false, "eventFront2 should have no event listeners");
// second mutation
is(mutations[1].target, eventFront2, "second mutation targets eventFront2");
is(mutations[1].type, "events", "mutation type is events");
is(mutations[1].hasEventListeners, false, "mutation target should have no event listeners");
is(eventFront2.hasEventListeners, false, "eventFront2 should have no event listeners");
runNextTest();
});
addAsyncTest(function* testRemoveMissingEvent() {
checkNodesHaveNoEventListener();
info("try to remove an event listener not previously added");
eventNode1.removeEventListener("click", eventListener1);
info("set any attribute on the node to trigger a mutation")
eventNode1.setAttribute("data-attr", "somevalue");
let mutations = yield waitForMutations();
is(mutations.length, 1, "expect only one mutation");
isnot(mutations.type, "events", "mutation type should not be events");
runNextTest();
});
function checkNodesHaveNoEventListener() {
is(eventFront1.hasEventListeners, false, "eventFront1 hasEventListeners should be false");
is(eventFront2.hasEventListeners, false, "eventFront2 hasEventListeners should be false");
};
function waitForMutations() {
return new Promise(resolve => {
walker.once("mutations", mutations => {
resolve(mutations);
});
});
}
runNextTest();
}
</script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1157469">Mozilla Bug 1157469</a>
<a id="inspectorContent" target="_blank" href="inspector-traversal-data.html">Test Document</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</html>
|