browser_dbg-navigation.js (2348B)
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 "use strict"; 6 7 const SOURCES = [ 8 "simple1.js", 9 "simple2.js", 10 "simple3.js", 11 "long.js", 12 "doc-scripts.html", 13 ]; 14 15 /** 16 * Test navigating 17 * navigating while paused will reset the pause state and sources 18 */ 19 add_task(async function () { 20 const dbg = await initDebugger("doc-script-switching.html"); 21 const { 22 selectors: { getSelectedSource, getIsPaused, getCurrentThread }, 23 } = dbg; 24 ok(getCurrentThread(), "We get a thread selected on debugger opening"); 25 26 info("Pause in the first document"); 27 invokeInTab("firstCall"); 28 await waitForPaused(dbg); 29 30 info("Navigate while being paused in the first document"); 31 await navigate(dbg, "doc-scripts.html", "simple1.js"); 32 ok( 33 getCurrentThread(), 34 "The new top level thread is selected after navigation" 35 ); 36 37 info("Set a breakpoint on the second document and pause on it"); 38 await selectSource(dbg, "simple1.js"); 39 await addBreakpoint(dbg, "simple1.js", 4); 40 invokeInTab("main"); 41 await waitForPaused(dbg); 42 const source = findSource(dbg, "simple1.js"); 43 await assertPausedAtSourceAndLine(dbg, source.id, 4); 44 is(countSources(dbg), 5, "5 sources are loaded."); 45 46 await waitForRequestsToSettle(dbg); 47 let onBreakpoint = waitForDispatch(dbg.store, "SET_BREAKPOINT"); 48 await navigate(dbg, "doc-scripts.html", ...SOURCES); 49 await onBreakpoint; 50 is(countSources(dbg), 5, "5 sources are loaded."); 51 ok(!getIsPaused(getCurrentThread()), "Is not paused"); 52 53 await waitForRequestsToSettle(dbg); 54 onBreakpoint = waitForDispatch(dbg.store, "SET_BREAKPOINT"); 55 await navigate(dbg, "doc-scripts.html", ...SOURCES); 56 await onBreakpoint; 57 is(countSources(dbg), 5, "5 sources are loaded."); 58 59 info("Test that the current selected source persists across reloads"); 60 await selectSource(dbg, "long.js"); 61 62 await waitForRequestsToSettle(dbg); 63 onBreakpoint = waitForDispatch(dbg.store, "SET_BREAKPOINT"); 64 await reload(dbg, "long.js"); 65 await onBreakpoint; 66 await waitForSelectedSource(dbg, "long.js"); 67 68 ok(getSelectedSource().url.includes("long.js"), "Selected source is long.js"); 69 }); 70 71 function countSources(dbg) { 72 return dbg.selectors.getSourceCount(); 73 }