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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Test that the breadcrumbs widget refreshes correctly when there are markup
// mutations (and that it doesn't refresh when those mutations don't change its
// output).
const TEST_URI = URL_ROOT + "doc_inspector_breadcrumbs.html";
// Each item in the TEST_DATA array is a test case that should contain the
// following properties:
// - desc {String} A description of this test case (will be logged).
// - setup {Function*} A generator function (can yield promises) that sets up
// the test case. Useful for selecting a node before starting the test.
// - run {Function*} A generator function (can yield promises) that runs the
// actual test case, i.e, mutates the content DOM to cause the breadcrumbs
// to refresh, or not.
// - shouldRefresh {Boolean} Once the `run` function has completed, and the test
// has detected that the page has changed, this boolean instructs the test to
// verify if the breadcrumbs has refreshed or not.
// - output {Array} A list of strings for the text that should be found in each
// button after the test has run.
const TEST_DATA = [{
desc: "Adding a child at the end of the chain shouldn't change anything",
setup: function* (inspector) {
yield selectNode("#i1111", inspector);
},
run: function* ({walker, selection}) {
yield walker.setInnerHTML(selection.nodeFront, "<b>test</b>");
},
shouldRefresh: false,
output: ["html", "body", "article#i1", "div#i11", "div#i111", "div#i1111"]
}, {
desc: "Updating an ID to an displayed element should refresh",
setup: function* () {},
run: function* ({walker}) {
let node = yield walker.querySelector(walker.rootNode, "#i1");
yield node.modifyAttributes([{
attributeName: "id",
newValue: "i1-changed"
}]);
},
shouldRefresh: true,
output: ["html", "body", "article#i1-changed", "div#i11", "div#i111",
"div#i1111"]
}, {
desc: "Updating an class to a displayed element should refresh",
setup: function* () {},
run: function* ({walker}) {
let node = yield walker.querySelector(walker.rootNode, "body");
yield node.modifyAttributes([{
attributeName: "class",
newValue: "test-class"
}]);
},
shouldRefresh: true,
output: ["html", "body.test-class", "article#i1-changed", "div#i11",
"div#i111", "div#i1111"]
}, {
desc: "Updating a non id/class attribute to a displayed element should not " +
"refresh",
setup: function* () {},
run: function* ({walker}) {
let node = yield walker.querySelector(walker.rootNode, "#i11");
yield node.modifyAttributes([{
attributeName: "name",
newValue: "value"
}]);
},
shouldRefresh: false,
output: ["html", "body.test-class", "article#i1-changed", "div#i11",
"div#i111", "div#i1111"]
}, {
desc: "Moving a child in an element that's not displayed should not refresh",
setup: function* () {},
run: function* ({walker}) {
// Re-append #i1211 as a last child of #i2.
let parent = yield walker.querySelector(walker.rootNode, "#i2");
let child = yield walker.querySelector(walker.rootNode, "#i211");
yield walker.insertBefore(child, parent);
},
shouldRefresh: false,
output: ["html", "body.test-class", "article#i1-changed", "div#i11",
"div#i111", "div#i1111"]
}, {
desc: "Moving an undisplayed child in a displayed element should not refresh",
setup: function* () {},
run: function* ({walker}) {
// Re-append #i2 in body (move it to the end).
let parent = yield walker.querySelector(walker.rootNode, "body");
let child = yield walker.querySelector(walker.rootNode, "#i2");
yield walker.insertBefore(child, parent);
},
shouldRefresh: false,
output: ["html", "body.test-class", "article#i1-changed", "div#i11",
"div#i111", "div#i1111"]
}, {
desc: "Updating attributes on an element that's not displayed should not " +
"refresh",
setup: function* () {},
run: function* ({walker}) {
let node = yield walker.querySelector(walker.rootNode, "#i2");
yield node.modifyAttributes([{
attributeName: "id",
newValue: "i2-changed"
}, {
attributeName: "class",
newValue: "test-class"
}]);
},
shouldRefresh: false,
output: ["html", "body.test-class", "article#i1-changed", "div#i11",
"div#i111", "div#i1111"]
}, {
desc: "Removing the currently selected node should refresh",
setup: function* (inspector) {
yield selectNode("#i2-changed", inspector);
},
run: function* ({walker, selection}) {
yield walker.removeNode(selection.nodeFront);
},
shouldRefresh: true,
output: ["html", "body.test-class"]
}, {
desc: "Changing the class of the currently selected node should refresh",
setup: function* () {},
run: function* ({selection}) {
yield selection.nodeFront.modifyAttributes([{
attributeName: "class",
newValue: "test-class-changed"
}]);
},
shouldRefresh: true,
output: ["html", "body.test-class-changed"]
}, {
desc: "Changing the id of the currently selected node should refresh",
setup: function* () {},
run: function* ({selection}) {
yield selection.nodeFront.modifyAttributes([{
attributeName: "id",
newValue: "new-id"
}]);
},
shouldRefresh: true,
output: ["html", "body#new-id.test-class-changed"]
}];
add_task(function* () {
let {inspector} = yield openInspectorForURL(TEST_URI);
let breadcrumbs = inspector.panelDoc.getElementById("inspector-breadcrumbs");
let container = breadcrumbs.querySelector(".html-arrowscrollbox-inner");
let win = container.ownerDocument.defaultView;
for (let {desc, setup, run, shouldRefresh, output} of TEST_DATA) {
info("Running test case: " + desc);
info("Listen to markupmutation events from the inspector to know when a " +
"test case has completed");
let onContentMutation = inspector.once("markupmutation");
info("Running setup");
yield setup(inspector);
info("Listen to mutations on the breadcrumbs container");
let hasBreadcrumbsMutated = false;
let observer = new win.MutationObserver(mutations => {
// Only consider childList changes or tooltiptext/checked attributes
// changes. The rest may be mutations caused by the overflowing arrowbox.
for (let {type, attributeName} of mutations) {
let isChildList = type === "childList";
let isAttributes = type === "attributes" &&
(attributeName === "checked" ||
attributeName === "tooltiptext");
if (isChildList || isAttributes) {
hasBreadcrumbsMutated = true;
break;
}
}
});
observer.observe(container, {
attributes: true,
childList: true,
subtree: true
});
info("Running the test case");
yield run(inspector);
info("Wait until the page has mutated");
yield onContentMutation;
if (shouldRefresh) {
info("The breadcrumbs is expected to refresh, so wait for it");
yield inspector.once("inspector-updated");
} else {
ok(!inspector._updateProgress,
"The breadcrumbs widget is not currently updating");
}
is(shouldRefresh, hasBreadcrumbsMutated, "Has the breadcrumbs refreshed?");
observer.disconnect();
info("Check the output of the breadcrumbs widget");
is(container.childNodes.length, output.length, "Correct number of buttons");
for (let i = 0; i < container.childNodes.length; i++) {
is(output[i], container.childNodes[i].textContent,
"Text content for button " + i + " is correct");
}
}
});
|