Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit 080c35d

Browse files
committed
Fixup console pretty print test (#5689)
* Fixup console pretty print test * Make selectSource more paranoid
1 parent e8fdb9a commit 080c35d

File tree

7 files changed

+35
-49
lines changed

7 files changed

+35
-49
lines changed

src/test/mochitest/browser_dbg-content-script-sources.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
"use strict";
22

3-
/* global ExtensionTestUtils, closeTab, openToolboxForTab, assertDebugLine,
4-
waitForSelectedSource */
5-
63
// Tests that the content scripts are listed in the source tree.
74

85
async function selectContentScriptSources(dbg) {
@@ -67,8 +64,8 @@ add_task(async function() {
6764
info(`Reloading tab (${i} time)`);
6865
gBrowser.reloadTab(gBrowser.selectedTab);
6966
await waitForPaused(dbg);
70-
await waitForSources(dbg, "content_script.js");
7167
await waitForSelectedSource(dbg, "content_script.js");
68+
7269
ok(
7370
findElementWithSelector(dbg, ".sources-list .focused"),
7471
"Source is focused"

src/test/mochitest/browser_dbg-editor-highlight.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,8 @@ add_task(async function() {
1313
// The source itself doesn't even exist yet, and using
1414
// `selectSourceURL` will set a pending request to load this source
1515
// and highlight a specific line.
16-
dbg.actions.selectSourceURL(sourceUrl, { location: { line: 66 } });
1716

18-
// Wait for the source text to load and make sure we're in the right
19-
// place.
20-
await waitForSelectedSource(dbg, sourceUrl);
21-
log(`loaded source`);
17+
await selectSource(dbg, sourceUrl, 66)
2218

2319
// TODO: revisit highlighting lines when the debugger opens
2420
// assertHighlightLocation(dbg, "long.js", 66);

src/test/mochitest/browser_dbg-outline.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ add_task(async function() {
1717
const { selectors: { getSelectedSource }, getState } = dbg;
1818

1919
await selectSource(dbg, "simple1", 1);
20-
await waitForSelectedSource(dbg, "simple1");
2120

2221
findElementWithSelector(dbg, ".outline-tab").click();
2322
is(getItems(dbg).length, 5, "5 items in the list");

src/test/mochitest/browser_dbg-pretty-print-console.js

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,43 @@
33

44
"use strict";
55

6-
// Tests that pretty-printing updates console messages.
6+
async function waitForConsoleLink(dbg, text) {
7+
const toolbox = dbg.toolbox;
8+
const console = await toolbox.selectTool("webconsole");
9+
const hud = console.hud;
10+
11+
return waitFor(() => {
12+
// Wait until the message updates.
13+
const found = hud.ui.outputNode.querySelector(".frame-link-source");
14+
if (!found) {
15+
return false;
16+
}
17+
18+
const linkText = found.textContent;
19+
if (!text) {
20+
return linkText;
21+
}
22+
23+
return linkText == text ? linkText : null;
24+
});
25+
}
726

27+
// Tests that pretty-printing updates console messages.
828
add_task(async function() {
929
const dbg = await initDebugger("doc-minified.html");
1030
invokeInTab("arithmetic");
1131

1232
info("Switch to console and check message");
13-
const toolbox = dbg.toolbox;
14-
const console = await toolbox.selectTool("webconsole");
15-
const hud = console.hud;
16-
17-
let node = await waitFor(() =>
18-
hud.ui.outputNode.querySelector(".frame-link-source")
19-
);
20-
const initialLocation = "math.min.js:3:65";
21-
is(node.textContent, initialLocation, "location is correct in minified code");
33+
await waitForConsoleLink(dbg, "math.min.js:3:65");
2234

2335
info("Switch back to debugger and pretty-print");
24-
await toolbox.selectTool("jsdebugger");
36+
await dbg.toolbox.selectTool("jsdebugger");
2537
await selectSource(dbg, "math.min.js", 2);
26-
await waitForSelectedSource(dbg, "math.min.js");
2738

2839
clickElement(dbg, "prettyPrintButton");
29-
30-
await waitForSource(dbg, "math.min.js:formatted");
31-
const ppSrc = findSource(dbg, "math.min.js:formatted");
32-
33-
ok(ppSrc, "Pretty-printed source exists");
40+
await waitForSelectedSource(dbg, "math.min.js:formatted");
3441

3542
info("Switch back to console and check message");
36-
node = await waitFor(() => {
37-
// Wait until the message updates.
38-
const found = hud.ui.outputNode.querySelector(".frame-link-source");
39-
if (found.textContent == initialLocation) {
40-
return null;
41-
}
42-
return found;
43-
});
44-
45-
is(
46-
node.textContent,
47-
"math.min.js:formatted:22",
48-
"location is correct in minified code"
49-
);
43+
await waitForConsoleLink(dbg, "math.min.js:formatted:22");
44+
ok(true);
5045
});

src/test/mochitest/browser_dbg-reload.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ add_task(async function() {
2121
const dbg = await initDebugger("reload/doc-reload.html");
2222
await waitForSource(dbg, "sjs_code_reload");
2323
await selectSource(dbg, "sjs_code_reload");
24-
await waitForSelectedSource(dbg, "sjs_code_reload");
25-
2624
await addBreakpoint(dbg, "sjs_code_reload", 2);
2725

2826
await reload(dbg, "sjs_code_reload");

src/test/mochitest/browser_dbg-sourcemaps2.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ add_task(async function() {
4545
// Tests the existence of the sourcemap link in the original source.
4646
ok(findElement(dbg, "sourceMapLink"), "Sourcemap link in original source");
4747
await selectSource(dbg, "main.min.js");
48-
await waitForSelectedSource(dbg, "main.min.js");
4948

5049
ok(
5150
!findElement(dbg, "sourceMapLink"),

src/test/mochitest/head.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,11 @@ function waitForState(dbg, predicate, msg) {
177177
}
178178

179179
const unsubscribe = dbg.store.subscribe(() => {
180-
if (predicate(dbg.store.getState())) {
180+
const result = predicate(dbg.store.getState())
181+
if (result) {
181182
info(`Finished waiting for state change: ${msg || ""}`);
182183
unsubscribe();
183-
resolve();
184+
resolve(result);
184185
}
185186
});
186187
});
@@ -230,7 +231,7 @@ function waitForSource(dbg, url) {
230231
return waitForState(dbg, state => {
231232
const sources = dbg.selectors.getSources(state);
232233
return sources.find(s => (s.get("url") || "").includes(url));
233-
});
234+
}, `source exists`);
234235
}
235236

236237
async function waitForElement(dbg, name) {
@@ -592,9 +593,10 @@ function waitForLoadedSources(dbg) {
592593
* @return {Promise}
593594
* @static
594595
*/
595-
function selectSource(dbg, url, line) {
596+
async function selectSource(dbg, url, line) {
596597
const source = findSource(dbg, url);
597-
return dbg.actions.selectLocation({ sourceId: source.id, line });
598+
await dbg.actions.selectLocation({ sourceId: source.id, line });
599+
return waitForSelectedSource(dbg, url);
598600
}
599601

600602
function closeTab(dbg, url) {

0 commit comments

Comments
 (0)