browser_dbg-unselected-pause.js (5897B)
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 // Test that the debugger pauses and is automatically highlighted and selected, 6 // even when it hasn't been opened. 7 8 "use strict"; 9 10 const IFRAME_TEST_COM_URI = `https://example.com/document-builder.sjs?html=${encodeURI( 11 `<script>const a=2;\ndebugger;\nconsole.log(a);</script>` 12 )}`; 13 14 // Embed the example.com test page in an example.org iframe. 15 const IFRAME_TEST_URI = `https://example.org/document-builder.sjs?html=${encodeURI( 16 `<script>function breakDebugger() {const b=3;\ndebugger;\nconsole.log(b);}</script><iframe src="${IFRAME_TEST_COM_URI}"></iframe><body>` 17 )}`; 18 19 add_task(async function () { 20 info("Test a debugger statement from the top level document"); 21 22 // Make sure the toolbox opens with the webconsole initially selected. 23 const toolbox = await initPane("doc-debugger-statements.html", "webconsole"); 24 25 info("Execute a debugger statement"); 26 const pausedRun = SpecialPowers.spawn( 27 gBrowser.selectedBrowser, 28 [], 29 function () { 30 content.wrappedJSObject.test(); 31 } 32 ); 33 34 const dbg = await assertDebuggerIsHighlightedAndPaused(toolbox); 35 const source = findSource(dbg, "doc-debugger-statements.html"); 36 await assertPausedAtSourceAndLine(dbg, source.id, 16); 37 38 await resume(dbg); 39 info("Wait for the paused code to complete after resume"); 40 await pausedRun; 41 42 ok( 43 !toolbox.isHighlighted("jsdebugger"), 44 "Debugger is no longer highlighted after resume" 45 ); 46 }); 47 48 add_task(async function () { 49 info("Test a debugger statement from an iframe"); 50 51 // Make sure the toolbox opens with the webconsole initially selected. 52 const toolbox = await openNewTabAndToolbox(IFRAME_TEST_URI, "webconsole"); 53 54 info( 55 "Reload the test page, which will trigger the debugger statement in the iframe" 56 ); 57 const pausedReload = reloadBrowser(); 58 59 const dbg = await assertDebuggerIsHighlightedAndPaused(toolbox); 60 const source = findSource(dbg, IFRAME_TEST_COM_URI); 61 await assertPausedAtSourceAndLine(dbg, source.id, 2); 62 63 await resume(dbg); 64 info("Wait for the paused code to complete after resume"); 65 await pausedReload; 66 67 ok( 68 !toolbox.isHighlighted("jsdebugger"), 69 "Debugger is no longer highlighted after resume" 70 ); 71 }); 72 73 add_task(async function () { 74 info("Test pausing from two distinct targets"); 75 76 // Make sure the toolbox opens with the webconsole initially selected. 77 const toolbox = await openNewTabAndToolbox(IFRAME_TEST_URI, "webconsole"); 78 79 info( 80 "Reload the test page, which will trigger the debugger statement in the iframe" 81 ); 82 const pausedReload = reloadBrowser(); 83 84 const dbg = await assertDebuggerIsHighlightedAndPaused(toolbox); 85 const topLevelThread = 86 toolbox.commands.targetCommand.targetFront.threadFront.actorID; 87 const iframeThread = dbg.selectors.getCurrentThread(); 88 isnot( 89 topLevelThread, 90 iframeThread, 91 "We get two distinct threads and could pause two times" 92 ); 93 ok( 94 !dbg.selectors.getIsPaused(topLevelThread), 95 "The top level document thread is not paused" 96 ); 97 ok( 98 dbg.selectors.getIsPaused(iframeThread), 99 "Only the iframe thread is paused" 100 ); 101 102 const source = findSource(dbg, IFRAME_TEST_COM_URI); 103 await assertPausedAtSourceAndLine(dbg, source.id, 2); 104 105 info("Step over to the next line"); 106 await stepOver(dbg); 107 await assertPausedAtSourceAndLine(dbg, source.id, 3); 108 109 info("Now execute a debugger statement in the top level target"); 110 const onPaused = waitForPausedThread(dbg, topLevelThread); 111 const pausedTopTarget = SpecialPowers.spawn( 112 gBrowser.selectedBrowser, 113 [], 114 function () { 115 content.wrappedJSObject.breakDebugger(); 116 } 117 ); 118 119 info("Wait for the top level target to be paused"); 120 await onPaused; 121 // also use waitForPause to wait for UI updates 122 await waitForPaused(dbg); 123 124 ok( 125 dbg.selectors.getIsPaused(topLevelThread), 126 "The top level document thread is paused" 127 ); 128 ok(dbg.selectors.getIsPaused(iframeThread), "The iframe thread is paused"); 129 130 ok( 131 toolbox.isHighlighted("jsdebugger"), 132 "Debugger stays highlighted when pausing on another thread" 133 ); 134 135 info( 136 "The new paused state refers to the latest breakpoint being hit, on the top level target" 137 ); 138 const source2 = findSource(dbg, IFRAME_TEST_URI); 139 await assertPausedAtSourceAndLine(dbg, source2.id, 2); 140 141 info("Resume the top level target"); 142 await resume(dbg); 143 144 info("Wait for top level target paused code to complete after resume"); 145 await pausedTopTarget; 146 147 info( 148 "By default we stay on the last selected thread on resume and so the current thread is no longer paused" 149 ); 150 assertNotPaused(dbg); 151 ok( 152 toolbox.isHighlighted("jsdebugger"), 153 "Debugger stays highlighted when resuming only the top level target" 154 ); 155 156 info( 157 "Re-select the iframe thread, which is still paused on the original breakpoint" 158 ); 159 dbg.actions.selectThread(iframeThread); 160 await waitForPausedThread(dbg, iframeThread); 161 await waitForSelectedSource(dbg, source); 162 await assertPausedAtSourceAndLine(dbg, source.id, 3); 163 164 info("Resume the iframe target"); 165 await resume(dbg); 166 assertNotPaused(dbg); 167 168 info("Wait for the paused code in the iframe to complete after resume"); 169 await pausedReload; 170 171 await waitUntil(() => !toolbox.isHighlighted("jsdebugger")); 172 ok( 173 true, 174 "Debugger is no longer highlighted after resuming all the paused targets" 175 ); 176 177 info("Resume the last paused thread"); 178 await resume(dbg); 179 assertNotPaused(dbg); 180 181 info("Wait for the paused code in the iframe to complete after resume"); 182 await pausedReload; 183 184 await waitUntil(() => !toolbox.isHighlighted("jsdebugger")); 185 ok( 186 true, 187 "Debugger is no longer highlighted after resuming all the paused targets" 188 ); 189 });