browser_dbg-watchpoints.js (4516B)
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 // - Tests adding a watchpoint 6 // - Tests removing a watchpoint 7 // - Tests adding a watchpoint, resuming to after the youngest frame has popped, 8 // then removing and adding a watchpoint during the same pause 9 10 "use strict"; 11 12 add_task(async function () { 13 const dbg = await initDebugger("doc-sources.html"); 14 15 // Do not await for navigation as an early breakpoint pauses the document load 16 const onNavigated = navigateTo(`${EXAMPLE_URL}doc-watchpoints.html`); 17 await waitForSources(dbg, "doc-watchpoints.html"); 18 await selectSource(dbg, "doc-watchpoints.html"); 19 await waitForPaused(dbg); 20 const sourceId = findSource(dbg, "doc-watchpoints.html").id; 21 22 info("Add a get watchpoint at b"); 23 await toggleScopeNode(dbg, 3); 24 const addedWatchpoint = waitForDispatch(dbg.store, "SET_WATCHPOINT"); 25 await rightClickScopeNode(dbg, 5); 26 let popup = await waitForContextMenu(dbg); 27 let submenu = await openContextMenuSubmenu(dbg, selectors.watchpointsSubmenu); 28 const getWatchpointItem = document.querySelector(selectors.addGetWatchpoint); 29 submenu.activateItem(getWatchpointItem); 30 await addedWatchpoint; 31 popup.hidePopup(); 32 33 await resume(dbg); 34 await waitForPaused(dbg); 35 await waitForState(dbg, () => dbg.selectors.getSelectedInlinePreviews()); 36 assertPausedAtSourceAndLine(dbg, sourceId, 17); 37 is(await getScopeNodeValue(dbg, 5), "3"); 38 const whyPaused = await waitFor( 39 () => dbg.win.document.querySelector(".why-paused")?.innerText 40 ); 41 is(whyPaused, `Paused on property get\nobj.b`); 42 43 info("Resume and wait to pause at the access to b in the first `obj.b;`"); 44 await resume(dbg); 45 await waitForPaused(dbg); 46 await assertPausedAtSourceAndLine(dbg, sourceId, 19); 47 48 info("Remove the get watchpoint on b"); 49 const removedWatchpoint1 = waitForDispatch(dbg.store, "REMOVE_WATCHPOINT"); 50 const el1 = await waitForElementWithSelector(dbg, ".remove-watchpoint-get"); 51 el1.scrollIntoView(); 52 clickElementWithSelector(dbg, ".remove-watchpoint-get"); 53 await removedWatchpoint1; 54 55 info( 56 "Resume and wait to skip the second `obj.b` and pause on the debugger statement" 57 ); 58 await resume(dbg); 59 await waitForPaused(dbg); 60 await assertPausedAtSourceAndLine(dbg, sourceId, 21); 61 62 info("Resume and pause on the debugger statement in getB"); 63 await resume(dbg); 64 await waitForPaused(dbg); 65 await assertPausedAtSourceAndLine(dbg, sourceId, 5); 66 67 info("Add a get watchpoint to b"); 68 await toggleScopeNode(dbg, 4); 69 const addedWatchpoint2 = waitForDispatch(dbg.store, "SET_WATCHPOINT"); 70 await rightClickScopeNode(dbg, 6); 71 popup = await waitForContextMenu(dbg); 72 submenu = await openContextMenuSubmenu(dbg, selectors.watchpointsSubmenu); 73 const getWatchpointItem2 = document.querySelector(selectors.addGetWatchpoint); 74 submenu.activateItem(getWatchpointItem2); 75 await addedWatchpoint2; 76 popup.hidePopup(); 77 78 info("Resume and wait to pause at the access to b in getB"); 79 await resume(dbg); 80 await waitForPaused(dbg); 81 await assertPausedAtSourceAndLine(dbg, sourceId, 6); 82 83 info("Resume and pause on the debugger statement"); 84 await waitForRequestsToSettle(dbg); 85 await resume(dbg); 86 await waitForPaused(dbg); 87 await assertPausedAtSourceAndLine(dbg, sourceId, 24); 88 89 info("Remove the get watchpoint on b"); 90 const removedWatchpoint2 = waitForDispatch(dbg.store, "REMOVE_WATCHPOINT"); 91 await toggleScopeNode(dbg, 3); 92 93 const el2 = await waitForElementWithSelector(dbg, ".remove-watchpoint-get"); 94 el2.scrollIntoView(); 95 clickElementWithSelector(dbg, ".remove-watchpoint-get"); 96 await removedWatchpoint2; 97 98 info("Add back the get watchpoint on b"); 99 const addedWatchpoint3 = waitForDispatch(dbg.store, "SET_WATCHPOINT"); 100 await rightClickScopeNode(dbg, 5); 101 popup = await waitForContextMenu(dbg); 102 submenu = await openContextMenuSubmenu(dbg, selectors.watchpointsSubmenu); 103 const getWatchpointItem3 = document.querySelector(selectors.addGetWatchpoint); 104 submenu.activateItem(getWatchpointItem3); 105 await addedWatchpoint3; 106 popup.hidePopup(); 107 108 info("Resume and wait to pause on the final `obj.b;`"); 109 await resume(dbg); 110 await waitForPaused(dbg); 111 await assertPausedAtSourceAndLine(dbg, sourceId, 25); 112 113 info("Do a last resume to finalize the document load"); 114 await resume(dbg); 115 await onNavigated; 116 117 await waitForRequestsToSettle(dbg); 118 });