Skip to content

Commit

Permalink
Bug 1753594 - [devtools] Improve the add breakpoints in pretty printe…
Browse files Browse the repository at this point in the history
…d sources test r=ochameau

Differential Revision: https://phabricator.services.mozilla.com/D137835
  • Loading branch information
bomsy committed Feb 9, 2022
1 parent 275f5b6 commit 5d54d1d
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <http://mozilla.org/MPL/2.0/>. */

// 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");
Expand All @@ -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);
}
31 changes: 21 additions & 10 deletions devtools/client/debugger/test/mochitest/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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");
}
Expand Down Expand Up @@ -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);

Expand All @@ -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) {
Expand Down

0 comments on commit 5d54d1d

Please sign in to comment.