diff --git a/devtools/client/debugger/src/actions/sources/prettyPrint.js b/devtools/client/debugger/src/actions/sources/prettyPrint.js index 1be232cbfaeb..3880ab19d646 100644 --- a/devtools/client/debugger/src/actions/sources/prettyPrint.js +++ b/devtools/client/debugger/src/actions/sources/prettyPrint.js @@ -16,24 +16,27 @@ import { isGenerated, isJavaScript, } from "../../utils/source"; -import { isFulfilled } from "../../utils/async-value"; import { loadSourceText } from "./loadSourceText"; import { mapFrames } from "../pause"; import { selectSpecificLocation } from "../sources"; import { getSource, - getSourceContent, getSourceFromId, getSourceByURL, getSelectedLocation, getThreadContext, - getSourceActorsForSource, } from "../../selectors"; import type { Action, ThunkArgs } from "../types"; import { selectSource } from "./select"; -import type { Source, SourceContent, SourceActor, Context } from "../../types"; +import type { + Source, + SourceContent, + SourceActor, + Context, + SourceLocation, +} from "../../types"; export async function prettyPrintSource( sourceMaps: typeof SourceMaps, @@ -84,21 +87,21 @@ export function createPrettySource(cx: Context, sourceId: string) { dispatch(({ type: "ADD_SOURCE", cx, source: prettySource }: Action)); - const actors = getSourceActorsForSource(getState(), sourceId); - const content = getSourceContent(getState(), sourceId); - if (!content || !isFulfilled(content)) { - throw new Error("Cannot pretty-print a file that has not loaded"); - } - await prettyPrintSource(sourceMaps, source, content.value, actors); - await dispatch(loadSourceText({ cx, source: prettySource })); + await dispatch(selectSource(cx, id)); return prettySource; }; } -function selectPrettyLocation(cx: Context, prettySource: Source) { +function selectPrettyLocation( + cx: Context, + prettySource: Source, + generatedLocation: ?SourceLocation +) { return async ({ dispatch, sourceMaps, getState }: ThunkArgs) => { - let location = getSelectedLocation(getState()); + let location = generatedLocation + ? generatedLocation + : getSelectedLocation(getState()); if (location && location.line >= 1) { location = await sourceMaps.getOriginalLocation(location); @@ -148,9 +151,9 @@ export function togglePrettyPrint(cx: Context, sourceId: string) { return dispatch(selectPrettyLocation(cx, prettySource)); } + const selectedLocation = getSelectedLocation(getState()); const newPrettySource = await dispatch(createPrettySource(cx, sourceId)); - - await dispatch(selectPrettyLocation(cx, newPrettySource)); + dispatch(selectPrettyLocation(cx, newPrettySource, selectedLocation)); const threadcx = getThreadContext(getState()); await dispatch(mapFrames(threadcx)); diff --git a/devtools/client/debugger/test/mochitest/.eslintrc b/devtools/client/debugger/test/mochitest/.eslintrc index 76bd2ca41f16..620cbed8ec16 100644 --- a/devtools/client/debugger/test/mochitest/.eslintrc +++ b/devtools/client/debugger/test/mochitest/.eslintrc @@ -62,6 +62,7 @@ "waitForSource": false, "waitForLoadedSource": false, "waitForSelectedSource": false, + "waitForSelectedLocation": false, "waitForBreakpoint": false, "waitForBreakpointCount": false, "waitForCondition": false, @@ -117,6 +118,7 @@ "rightClickElement": false, "rightClickEl": false, "clickGutter": false, + "countTabs": false, "typeInPanel": false, "selectMenuItem": false, "selectContextMenuItem": false, diff --git a/devtools/client/debugger/test/mochitest/browser.ini b/devtools/client/debugger/test/mochitest/browser.ini index a4a34e239390..55fa6b9bbc3b 100644 --- a/devtools/client/debugger/test/mochitest/browser.ini +++ b/devtools/client/debugger/test/mochitest/browser.ini @@ -101,6 +101,7 @@ skip-if = (verify && debug && (os == 'mac')) || (os == 'linux' && debug && bits [browser_dbg-pretty-print-breakpoints.js] [browser_dbg-pretty-print-console.js] [browser_dbg-pretty-print-paused.js] +[browser_dbg-pretty-print-flow.js] [browser_dbg-preview.js] skip-if = os == "win" [browser_dbg-preview-frame.js] diff --git a/devtools/client/debugger/test/mochitest/browser_dbg-pretty-print-flow.js b/devtools/client/debugger/test/mochitest/browser_dbg-pretty-print-flow.js new file mode 100644 index 000000000000..dbcf69cc84fb --- /dev/null +++ b/devtools/client/debugger/test/mochitest/browser_dbg-pretty-print-flow.js @@ -0,0 +1,24 @@ +/* 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 . */ + +// Tests that loader and new tab appear when pretty printing, +// and the selected location is mapped afterwards +function waitForTabCounts(dbg, counts) { + return waitForState(dbg, state => { + const tabCounts = countTabs(dbg); + + return tabCounts == counts; + }); +} + +add_task(async function() { + const dbg = await initDebugger("doc-pretty.html", "pretty.js"); + + await selectSource(dbg, "pretty.js", 4, 8); + + prettyPrint(dbg); + await waitForTabCounts(dbg, 2); + await waitForElementWithSelector(dbg, selectors.prettyPrintLoader); + await waitForSelectedLocation(dbg, 5); +}); diff --git a/devtools/client/debugger/test/mochitest/helpers.js b/devtools/client/debugger/test/mochitest/helpers.js index 337c3c03f963..f5ef9fe1ee96 100644 --- a/devtools/client/debugger/test/mochitest/helpers.js +++ b/devtools/client/debugger/test/mochitest/helpers.js @@ -243,10 +243,14 @@ function assertClass(el, className, exists = true) { } } -function waitForSelectedLocation(dbg, line) { +function waitForSelectedLocation(dbg, line, column) { return waitForState(dbg, state => { const location = dbg.selectors.getSelectedLocation(); - return location && location.line == line; + return ( + location && + (line ? location.line == line : true) && + (column ? location.column == column : true) + ); }); } @@ -715,11 +719,11 @@ function getThreadContext(dbg) { * @return {Promise} * @static */ -async function selectSource(dbg, url, line) { +async function selectSource(dbg, url, line, column) { const source = findSource(dbg, url); await dbg.actions.selectLocation( getContext(dbg), - { sourceId: source.id, line }, + { sourceId: source.id, line, column }, { keepContext: false } ); return waitForSelectedSource(dbg, url); @@ -1315,6 +1319,7 @@ const selectors = { replayNext: ".replay-next.active", toggleBreakpoints: ".breakpoints-toggle", prettyPrintButton: ".source-footer .prettyPrint", + prettyPrintLoader: ".source-footer .spin", sourceMapLink: ".source-footer .mapped-source", sourcesFooter: ".sources-panel .source-footer", editorFooter: ".editor-pane .source-footer",