browser_dbg-breakpoints-in-evaled-sources.js (3345B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */ 4 5 // this evaled source includes a "debugger" statement so that it gets 6 // automatically opened in the debugger when it is executed. 7 // We wrap it in a setTimeout to avoid errors in the webconsole actor which 8 // would still be processing the outcome of the evaluation after we destroy 9 // the thread actor. 10 11 "use strict"; 12 13 const EVALED_SOURCE_TEXT = `setTimeout(function() { 14 debugger; 15 console.log("SECOND LINE"); 16 }, 10)`; 17 18 /** 19 * Check against blank debugger panel issues when attempting to restore 20 * breakpoints set in evaled sources (Bug 1720512). 21 * 22 * The STRs triggering this bug require to: 23 * - set a valid breakpoint on a regular source 24 * - then set a breakpoint on an evaled source 25 * - close and reopen the debugger 26 * 27 * This test will follow those STRs while also performing a few additional 28 * checks (eg verify breakpoints can be hit at various stages of the test). 29 */ 30 add_task(async function () { 31 info("Open the debugger and set a breakpoint on a regular script"); 32 const dbg = await initDebugger("doc-scripts.html"); 33 await selectSource(dbg, "doc-scripts.html"); 34 await addBreakpoint(dbg, "doc-scripts.html", 21); 35 36 info("Switch to the console and evaluate a source with a debugger statement"); 37 const { hud } = await dbg.toolbox.selectTool("webconsole"); 38 const onSelected = dbg.toolbox.once("jsdebugger-selected"); 39 await hud.ui.wrapper.dispatchEvaluateExpression(EVALED_SOURCE_TEXT); 40 41 info("Wait for the debugger to be selected"); 42 await onSelected; 43 44 info("Wait for the debugger to be paused on the debugger statement"); 45 await waitForPaused(dbg); 46 47 is( 48 getEditorContent(dbg), 49 EVALED_SOURCE_TEXT, 50 "The debugger is showing the evaled source" 51 ); 52 53 const evaledSource = dbg.selectors.getSelectedSource(); 54 await assertPausedAtSourceAndLine(dbg, evaledSource.id, 2); 55 56 info("Add a breakpoint in the evaled source"); 57 await addBreakpoint(dbg, evaledSource, 3); 58 59 info("Resume and check that we hit the breakpoint"); 60 await resume(dbg); 61 await waitForPaused(dbg); 62 await assertPausedAtSourceAndLine(dbg, evaledSource.id, 3); 63 64 info("Close the toolbox"); 65 await dbg.toolbox.closeToolbox(); 66 67 info("Reopen the toolbox on the debugger"); 68 const toolbox2 = await openToolboxForTab(gBrowser.selectedTab, "jsdebugger"); 69 const dbg2 = createDebuggerContext(toolbox2); 70 71 // The initial regression tested here led to a blank debugger, 72 // if we can see the doc-scripts.html source, this already means the debugger 73 // is functional. 74 await waitForSources(dbg2, "doc-scripts.html"); 75 76 // Wait until codeMirror is rendered before reloading the debugger. 77 await waitFor(() => findElement(dbg2, "codeMirror")); 78 79 info("Reload to check if we hit the breakpoint added in doc-scripts.html"); 80 const onReloaded = reload(dbg2); 81 82 await waitForDispatch(dbg2.store, "NAVIGATE"); 83 await waitForSelectedSource(dbg2, "doc-scripts.html"); 84 await waitForPaused(dbg2); 85 86 const scriptSource = dbg2.selectors.getSelectedSource(); 87 await assertPausedAtSourceAndLine(dbg2, scriptSource.id, 21); 88 await resume(dbg2); 89 90 info("Wait for reload to complete after resume"); 91 await onReloaded; 92 });