Skip to content

Commit 261cef2

Browse files
AnshulMalikjasonLaster
authored andcommitted
[Tabs] Display pretty source after reload (firefox-devtools#4963)
1 parent 028ef6d commit 261cef2

6 files changed

Lines changed: 46 additions & 12 deletions

File tree

src/actions/sources/newSources.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
import { syncBreakpoint } from "../breakpoints";
1313
import { loadSourceText } from "./loadSourceText";
14+
import { togglePrettyPrint } from "./prettyPrint";
1415
import { selectLocation } from "../sources";
16+
import { getRawSourceURL, isPrettyURL } from "../../utils/source";
1517

1618
import { prefs } from "../../utils/prefs";
1719

@@ -66,11 +68,22 @@ function loadSourceMap(generatedSource) {
6668

6769
// If a request has been made to show this source, go ahead and
6870
// select it.
69-
function checkSelectedSource(source) {
71+
function checkSelectedSource(source: Source) {
7072
return async ({ dispatch, getState }: ThunkArgs) => {
7173
const pendingLocation = getPendingSelectedLocation(getState());
7274

73-
if (pendingLocation && !!source.url && pendingLocation.url === source.url) {
75+
if (!pendingLocation || !pendingLocation.url || !source.url) {
76+
return;
77+
}
78+
79+
const pendingUrl = pendingLocation.url;
80+
const rawPendingUrl = getRawSourceURL(pendingUrl);
81+
82+
if (rawPendingUrl === source.url) {
83+
if (isPrettyURL(pendingUrl)) {
84+
return await dispatch(togglePrettyPrint(source.id));
85+
}
86+
7487
await dispatch(
7588
selectLocation({ ...pendingLocation, sourceId: source.id })
7689
);

src/test/mochitest/browser.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ skip-if = true # regular failures during release in Bug 1415300
120120
[browser_dbg-sourcemaps-bogus.js]
121121
[browser_dbg-sources.js]
122122
[browser_dbg-tabs.js]
123+
[browser_dbg-tabs-pretty-print.js]
123124
[browser_dbg-toggling-tools.js]
124125
skip-if = true # Bug 1414124
125126
[browser_dbg-wasm-sourcemaps.js]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* Any copyright is dedicated to the Public Domain.
2+
* http://creativecommons.org/publicdomain/zero/1.0/ */
3+
4+
// Tests re-opening pretty printed tabs on load
5+
6+
add_task(async function() {
7+
const dbg = await initDebugger("doc-minified.html");
8+
9+
await selectSource(dbg, "math.min.js");
10+
clickElement(dbg, "prettyPrintButton");
11+
await waitForSource(dbg, "math.min.js:formatted");
12+
// Test reloading the debugger
13+
await waitForSelectedSource(dbg, "math.min.js:formatted");
14+
await reload(dbg);
15+
16+
await waitForSelectedSource(dbg, "math.min.js:formatted");
17+
ok(true, "Pretty printed source is selected on reload");
18+
});

src/test/mochitest/browser_dbg-tabs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function countTabs(dbg) {
88
}
99

1010
add_task(async function() {
11-
let dbg = await initDebugger("doc-scripts.html");
11+
const dbg = await initDebugger("doc-scripts.html");
1212

1313
await selectSource(dbg, "simple1");
1414
await selectSource(dbg, "simple2");
@@ -26,7 +26,7 @@ add_task(async function() {
2626
});
2727

2828
add_task(async function() {
29-
let dbg = await initDebugger("doc-scripts.html", "simple1", "simple2");
29+
const dbg = await initDebugger("doc-scripts.html", "simple1", "simple2");
3030

3131
await selectSource(dbg, "simple1");
3232
await selectSource(dbg, "simple2");

src/utils/source.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ export function isJavaScript(source: SourceRecord): boolean {
8383
*/
8484
export function isPretty(source: SourceRecord): boolean {
8585
const url = source.get("url");
86+
return isPrettyURL(url);
87+
}
88+
89+
export function isPrettyURL(url: string): boolean {
8690
return url ? /formatted$/.test(url) : false;
8791
}
8892

src/utils/test-head.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,17 @@ function makeSymbolDeclaration(name: string, line: number) {
8282
* @static
8383
*/
8484
function waitForState(store: any, predicate: any): Promise<void> {
85-
if (predicate(store.getState())) {
86-
return Promise.resolve();
87-
}
88-
8985
return new Promise(resolve => {
90-
if (predicate(store.getState())) {
91-
resolve();
86+
let ret = predicate(store.getState());
87+
if (ret) {
88+
resolve(ret);
9289
}
9390

9491
const unsubscribe = store.subscribe(() => {
95-
if (predicate(store.getState())) {
92+
ret = predicate(store.getState());
93+
if (ret) {
9694
unsubscribe();
97-
resolve();
95+
resolve(ret);
9896
}
9997
});
10098
});

0 commit comments

Comments
 (0)