Bug 1721197 - [devtools] Add test re-opening the toolbox after setting breakpoints in evaled sources r=ochameau

Differential Revision: https://phabricator.services.mozilla.com/D120504
This commit is contained in:
Julian Descottes 2021-07-23 08:31:50 +00:00
parent 9460732df4
commit 8c7729a8a4
2 changed files with 85 additions and 0 deletions

View File

@ -49,6 +49,7 @@ skip-if = debug # Window leaks: bug 1575332
[browser_dbg-breakpoints-cond-source-maps.js]
[browser_dbg-breakpoints-debugger-statement.js]
[browser_dbg-breakpoints-duplicate-functions.js]
[browser_dbg-breakpoints-in-evaled-sources.js]
[browser_dbg-browser-content-toolbox.js]
skip-if = !e10s || verify # This test is only valid in e10s
[browser_dbg-continue-to-here.js]

View File

@ -0,0 +1,84 @@
/* 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 <http://mozilla.org/MPL/2.0/>. */
// this evaled source includes a "debugger" statement so that it gets
// automatically opened in the debugger when it is executed.
// We wrap it in a setTimeout to avoid errors in the webconsole actor which
// would still be processing the outcome of the evaluation after we destroy
// the thread actor.
const EVALED_SOURCE_TEXT = `setTimeout(function() {
debugger;
console.log("SECOND LINE");
}, 10)`;
// doc-scripts.html contains some javascript on which we can set breakpoints.
const REGULAR_SOURCE_FILE = "doc-scripts.html";
/**
* Check against blank debugger panel issues when attempting to restore
* breakpoints set in evaled sources (Bug 1720512).
*
* The STRs triggering this bug require to:
* - set a valid breakpoint on a regular source
* - then set a breakpoint on an evaled source
* - close and reopen the debugger
*
* This test will follow those STRs while also performing a few additional
* checks (eg verify breakpoints can be hit at various stages of the test).
*/
add_task(async function() {
info("Open the debugger and set a breakpoint on a regular script");
const dbg = await initDebugger("doc-scripts.html");
await selectSource(dbg, "doc-scripts.html");
await addBreakpoint(dbg, "doc-scripts.html", 21);
info("Switch to the console and evaluate a source with a debugger statement");
const { hud } = await dbg.toolbox.selectTool("webconsole");
const onSelected = dbg.toolbox.once("jsdebugger-selected");
await hud.ui.wrapper.dispatchEvaluateExpression(EVALED_SOURCE_TEXT);
info("Wait for the debugger to be selected");
await onSelected;
info("Wait for the debugger to be paused on the debugger statement");
await waitForPaused(dbg);
is(getCM(dbg).getValue(), EVALED_SOURCE_TEXT, "The debugger is showing the evaled source");
const evaledSource = dbg.selectors.getSelectedSource();
assertPausedAtSourceAndLine(dbg, evaledSource.id, 2);
info("Add a breakpoint in the evaled source")
await addBreakpoint(dbg, evaledSource, 3);
info("Resume and check that we hit the breakpoint");
await resume(dbg);
await waitForPaused(dbg);
assertPausedAtSourceAndLine(dbg, evaledSource.id, 3);
info("Close the toolbox");
await dbg.toolbox.closeToolbox();
info("Reopen the toolbox on the debugger");
const toolbox2 = await openToolboxForTab(gBrowser.selectedTab, "jsdebugger");
const dbg2 = createDebuggerContext(toolbox2);
// The initial regression tested here led to a blank debugger,
// if we can see the doc-scripts.html source, this already means the debugger
// is functional.
await waitForSources(dbg2, "doc-scripts.html");
// Wait until codeMirror is rendered before reloading the debugger.
await waitFor(() => findElement(dbg2, "codeMirror"));
info("Reload to check if we hit the breakpoint added in doc-scripts.html");
reload(dbg2);
await waitForDispatch(dbg2.store, "NAVIGATE");
await waitForSelectedSource(dbg2, "doc-scripts.html");
await waitForPaused(dbg2);
const scriptSource = dbg2.selectors.getSelectedSource();
assertPausedAtSourceAndLine(dbg2, scriptSource.id, 21);
await resume(dbg2);
});