diff --git a/devtools/client/debugger/test/mochitest/browser_dbg-pretty-print-breakpoints.js b/devtools/client/debugger/test/mochitest/browser_dbg-pretty-print-breakpoints.js index 091f17d08a339..1b9bf93264c94 100644 --- a/devtools/client/debugger/test/mochitest/browser_dbg-pretty-print-breakpoints.js +++ b/devtools/client/debugger/test/mochitest/browser_dbg-pretty-print-breakpoints.js @@ -2,7 +2,29 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at . */ -// Tests that breakpoints appear when you reload a page +// Tests that breakpoints set in the pretty printed files display and paused +// correctly. +add_task(async function() { + const dbg = await initDebugger("doc-pretty.html", "pretty.js"); + + await selectSource(dbg, "pretty.js"); + await prettyPrint(dbg); + + await addBreakpoint(dbg, "pretty.js:formatted", 5); + + is(dbg.selectors.getBreakpointCount(), 1, "Only one breakpoint is created"); + + invokeInTab("stuff"); + await waitForPaused(dbg); + + await assertBreakpointsInNonPrettyAndPrettySources(dbg); + + is(dbg.selectors.getBreakpointCount(), 1, "Only one breakpoint still exists after pause "); + + await resume(dbg); +}); + +// Tests that breakpoints appear and work when you reload a page // with pretty-printed files. add_task(async function() { const dbg = await initDebugger("doc-pretty.html", "pretty.js"); @@ -11,11 +33,68 @@ add_task(async function() { await prettyPrint(dbg); await addBreakpoint(dbg, "pretty.js:formatted", 5); - await closeTab(dbg, "pretty.js:formatted"); - await reload(dbg, "pretty.js"); + info("Check that equivalent breakpoint to pretty.js (generated source)"); + await selectSource(dbg, "pretty.js"); + await assertBreakpoint(dbg, 4); + + await selectSource(dbg, "pretty.js:formatted"); + + is(dbg.selectors.getBreakpointCount(), 1, "Only one breakpoint exists"); + + await reload(dbg, "pretty.js", "pretty.js:formatted"); + + await waitForSelectedSource(dbg, "pretty.js:formatted"); + invokeInTab("stuff"); + await waitForPaused(dbg); + + await assertBreakpointsInNonPrettyAndPrettySources(dbg); + is(dbg.selectors.getBreakpointCount(), 1, "Only one breakpoint still exists after reload and pause "); +}); + +// Test that breakpoints appear and work when set in the minified source +add_task(async function() { + const dbg = await initDebugger("doc-pretty.html", "pretty.js"); + + await selectSource(dbg, "pretty.js"); + + info ("Add breakpoint to pretty.js (generated source)"); + await addBreakpoint(dbg, "pretty.js", 4, 7); + + await prettyPrint(dbg); + + info("Check that equivalent breakpoint is added to pretty.js:formatted (original source)"); + await selectSource(dbg, "pretty.js:formatted"); + await assertBreakpoint(dbg, 5); + + is(dbg.selectors.getBreakpointCount(), 1, "Only one breakpoint created"); + + await reload(dbg, "pretty.js", "pretty.js:formatted"); + + await waitForSelectedSource(dbg, "pretty.js:formatted"); + + invokeInTab("stuff"); await waitForPaused(dbg); - await assertBreakpoint(dbg, 4); + + await assertBreakpointsInNonPrettyAndPrettySources(dbg); + + is(dbg.selectors.getBreakpointCount(), 1, "Only one breakpoint still exists after reload and pause "); }); + + + +async function assertBreakpointsInNonPrettyAndPrettySources(dbg) { + info("Asserts breakpoint pause and display on the correct line in the pretty printed source"); + const prettyPrintedSource = findSource(dbg, "pretty.js:formatted"); + await assertPausedAtSourceAndLine(dbg, prettyPrintedSource.id, 5); + await assertBreakpoint(dbg, 5); + + await selectSource(dbg, "pretty.js"); + + info("Assert pause and display on the correct line in the minified source"); + const minifiedSource = findSource(dbg, "pretty.js"); + await assertPausedAtSourceAndLine(dbg, minifiedSource.id, 4, 7); + await assertBreakpoint(dbg, 4); +} diff --git a/devtools/client/debugger/test/mochitest/helpers.js b/devtools/client/debugger/test/mochitest/helpers.js index cffa61e5a5891..66b6413606fc6 100644 --- a/devtools/client/debugger/test/mochitest/helpers.js +++ b/devtools/client/debugger/test/mochitest/helpers.js @@ -262,11 +262,13 @@ function assertEmptyLines(dbg, lines) { } function getVisibleSelectedFrameLine(dbg) { - const { - selectors: { getVisibleSelectedFrame }, - } = dbg; - const frame = getVisibleSelectedFrame(); - return frame && frame.location.line; + const frame = dbg.selectors.getVisibleSelectedFrame(); + return frame?.location.line; +} + +function getVisibleSelectedFrameColumn(dbg) { + const frame = dbg.selectors.getVisibleSelectedFrame(); + return frame?.location.column; } /** @@ -281,7 +283,8 @@ function assertPausedLocation(dbg) { // Check the pause location const pauseLine = getVisibleSelectedFrameLine(dbg); - assertDebugLine(dbg, pauseLine); + const pauseColumn = getVisibleSelectedFrameColumn(dbg); + assertDebugLine(dbg, pauseLine, pauseColumn); ok(isVisibleInEditor(dbg, getCM(dbg).display.gutters), "gutter is visible"); } @@ -394,9 +397,10 @@ function isPaused(dbg) { * @memberof mochitest/asserts * @param {Object} dbg * @param {String} expectedSourceId - * @param {String} expectedLine + * @param {Number} expectedLine + * @param {Number} [expectedColumn] */ -function assertPausedAtSourceAndLine(dbg, expectedSourceId, expectedLine) { +function assertPausedAtSourceAndLine(dbg, expectedSourceId, expectedLine, expectedColumn) { // Check that the debugger is paused. assertPaused(dbg); @@ -407,12 +411,19 @@ function assertPausedAtSourceAndLine(dbg, expectedSourceId, expectedLine) { ok(frames.length >= 1, "Got at least one frame"); // Lets make sure we can assert both original and generated file locations when needed - const { sourceId, line } = isGeneratedId(expectedSourceId) ? frames[0].generatedLocation : frames[0].location; + const { sourceId, line, column } = isGeneratedId(expectedSourceId) ? frames[0].generatedLocation : frames[0].location; is(sourceId, expectedSourceId, "Frame has correct source"); ok( line == expectedLine, - `Frame paused at ${line}, but expected ${expectedLine}` + `Frame paused at line ${line}, but expected line ${expectedLine}` ); + + if (expectedColumn) { + ok( + column == expectedColumn, + `Frame paused at column ${column}, but expected column ${expectedColumn}` + ); + } } async function waitForThreadCount(dbg, count) {