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
213
214
215
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
// This contains tests for
// 1) The context menu items that blackboxes multiple files in the Sources Panel.
// Checks if submenu works correctly for options:
// - 'Un/Blackbox files in this group'
// - 'Un/Blackbox files outside this group'
// - 'Un/Blackbox files in this directory'
// - 'Un/Blackbox files outside this directory'
// 2) The context menu item to hide/show the blackboxed files.
"use strict";
const SOURCE_FILES = {
nestedSource: "nested-source.js",
codeReload1: "code_reload_1.js",
};
const NODE_SELECTORS = {
nodeBlackBoxAll: "#node-blackbox-all",
nodeBlackBoxAllInside: "#node-blackbox-all-inside",
nodeUnBlackBoxAllInside: "#node-unblackbox-all-inside",
nodeBlackBoxAllOutside: "#node-blackbox-all-outside",
nodeUnBlackBoxAllOutside: "#node-unblackbox-all-outside",
};
add_task(async function testBlackBoxOnMultipleFiles() {
const dbg = await initDebugger(
"doc-blackbox-all.html",
SOURCE_FILES.nestedSource,
SOURCE_FILES.codeReload1
);
// Expand the SourceTree and wait for all sources to be visible,
// so that we can assert the visible state of blackboxing in the source tree.
await waitForSourcesInSourceTree(dbg, Object.values(SOURCE_FILES));
info("Loads the source file and sets a breakpoint at line 2.");
await selectSource(dbg, SOURCE_FILES.nestedSource);
await addBreakpoint(dbg, SOURCE_FILES.nestedSource, 2);
info("Selecting the source will highlight it and expand the tree down to it");
await waitForAllElements(dbg, "sourceTreeFolderNode", 3);
const sourceTreeFolderNodeEls = findAllElements(dbg, "sourceTreeFolderNode");
const sourceTreeRootNodeEl = findElement(dbg, "sourceTreeRootNode");
info("Blackbox files in this directory.");
rightClickEl(dbg, sourceTreeFolderNodeEls[1]);
await waitForContextMenu(dbg);
await openContextMenuSubmenu(dbg, NODE_SELECTORS.nodeBlackBoxAll);
await assertContextMenuLabel(
dbg,
NODE_SELECTORS.nodeBlackBoxAllInside,
"Ignore files in this directory"
);
await assertContextMenuLabel(
dbg,
NODE_SELECTORS.nodeBlackBoxAllOutside,
"Ignore files outside this directory"
);
selectContextMenuItem(dbg, NODE_SELECTORS.nodeBlackBoxAllInside);
await waitForDispatch(dbg.store, "BLACKBOX_WHOLE_SOURCES");
await waitForBlackboxCount(dbg, 1);
await waitForRequestsToSettle(dbg);
assertSourceNodeIsBlackBoxed(dbg, SOURCE_FILES.nestedSource, true);
assertSourceNodeIsBlackBoxed(dbg, SOURCE_FILES.codeReload1, false);
info("The invoked function is blackboxed and the debugger does not pause.");
invokeInTab("computeSomething");
assertNotPaused(dbg);
info("Unblackbox files outside this directory.");
rightClickEl(dbg, sourceTreeFolderNodeEls[2]);
await waitForContextMenu(dbg);
await openContextMenuSubmenu(dbg, NODE_SELECTORS.nodeBlackBoxAll);
await assertContextMenuLabel(
dbg,
NODE_SELECTORS.nodeBlackBoxAllInside,
"Ignore files in this directory"
);
await assertContextMenuLabel(
dbg,
NODE_SELECTORS.nodeUnBlackBoxAllOutside,
"Unignore files outside this directory"
);
selectContextMenuItem(dbg, NODE_SELECTORS.nodeUnBlackBoxAllOutside);
await waitForDispatch(dbg.store, "UNBLACKBOX_WHOLE_SOURCES");
await waitForBlackboxCount(dbg, 0);
await waitForRequestsToSettle(dbg);
info("Wait for any breakpoints in the source to get enabled");
await waitForDispatch(dbg.store, "SET_BREAKPOINT");
assertSourceNodeIsBlackBoxed(dbg, SOURCE_FILES.nestedSource, false);
assertSourceNodeIsBlackBoxed(dbg, SOURCE_FILES.codeReload1, false);
info("All sources are unblackboxed and the debugger pauses on line 2.");
invokeInTab("computeSomething");
await waitForPaused(dbg);
await resume(dbg);
info("Blackbox files in this group.");
rightClickEl(dbg, sourceTreeRootNodeEl);
await waitForContextMenu(dbg);
await assertContextMenuLabel(
dbg,
NODE_SELECTORS.nodeBlackBoxAllInside,
"Ignore files in this group"
);
selectContextMenuItem(dbg, NODE_SELECTORS.nodeBlackBoxAllInside);
await waitForBlackboxCount(dbg, 2);
await waitForRequestsToSettle(dbg);
assertSourceNodeIsBlackBoxed(dbg, SOURCE_FILES.nestedSource, true);
assertSourceNodeIsBlackBoxed(dbg, SOURCE_FILES.codeReload1, true);
info("Unblackbox files in this group.");
rightClickEl(dbg, sourceTreeRootNodeEl);
await waitForContextMenu(dbg);
await assertContextMenuLabel(
dbg,
NODE_SELECTORS.nodeUnBlackBoxAllInside,
"Unignore files in this group"
);
selectContextMenuItem(dbg, NODE_SELECTORS.nodeUnBlackBoxAllInside);
await waitForBlackboxCount(dbg, 0);
await waitForRequestsToSettle(dbg);
assertSourceNodeIsBlackBoxed(dbg, SOURCE_FILES.nestedSource, false);
assertSourceNodeIsBlackBoxed(dbg, SOURCE_FILES.codeReload1, false);
});
add_task(async function testHideAndShowBlackBoxedFiles() {
Services.prefs.setBoolPref("devtools.debugger.hide-ignored-sources", false);
const dbg = await initDebugger(
"doc-blackbox-all.html",
SOURCE_FILES.nestedSource,
SOURCE_FILES.codeReload1
);
await waitForSourcesInSourceTree(dbg, Object.values(SOURCE_FILES));
await selectSource(dbg, SOURCE_FILES.nestedSource);
clickElement(dbg, "blackbox");
await waitForDispatch(dbg.store, "BLACKBOX_WHOLE_SOURCES");
info("Assert and click the hide ignored files button in the settings menu");
await toggleDebbuggerSettingsMenuItem(dbg, {
className: ".debugger-settings-menu-item-hide-ignored-sources",
isChecked: false,
});
info("Wait until ignored sources are no longer visible");
await waitUntil(
() => !findSourceNodeWithText(dbg, SOURCE_FILES.nestedSource)
);
is(
Services.prefs.getBoolPref("devtools.debugger.hide-ignored-sources"),
true,
"Hide ignored files is enabled"
);
is(
dbg.win.document.querySelector(".source-list-footer").innerText,
"Ignored sources are hidden.\nShow all sources",
"Notification is visible with the correct message"
);
info("Assert that newly ignored files are automatically hidden");
await selectSource(dbg, SOURCE_FILES.codeReload1);
await triggerSourceTreeContextMenu(
dbg,
findSourceNodeWithText(dbg, SOURCE_FILES.codeReload1),
"#node-menu-blackbox"
);
await waitForDispatch(dbg.store, "BLACKBOX_WHOLE_SOURCES");
await waitUntil(() => !findSourceNodeWithText(dbg, SOURCE_FILES.codeReload1));
info("Show the hidden ignored files using the button in the notification");
clickElementWithSelector(dbg, ".source-list-footer button");
info("Wait until ignored sources are visible");
await waitUntil(() => findSourceNodeWithText(dbg, SOURCE_FILES.nestedSource));
is(
Services.prefs.getBoolPref("devtools.debugger.hide-ignored-sources"),
false,
"Hide ignored files is disabled"
);
ok(
!document.querySelector(".source-list-footer"),
"Notification is no longer visible"
);
});
function waitForBlackboxCount(dbg, count) {
return waitForState(
dbg,
state => Object.keys(dbg.selectors.getBlackBoxRanges()).length === count
);
}
function assertSourceNodeIsBlackBoxed(dbg, sourceFilename, shouldBeBlackBoxed) {
const treeItem = findSourceNodeWithText(dbg, sourceFilename);
ok(treeItem, `Found tree item for ${sourceFilename}`);
is(
!!treeItem.querySelector(".img.blackBox"),
shouldBeBlackBoxed,
`${sourceFilename} is ${shouldBeBlackBoxed ? "" : "not"} blackboxed`
);
}
|