Bug 1704628 Part 1: Make selectContextMenuItem use .activateItem() semantics. r=ochameau
[gecko.git] / devtools / client / debugger / test / mochitest / browser_dbg-watchpoints.js
bloba9cd1cf273ad3e0d6d9df2bb101a4beacb6d0723
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/>. */
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
10 add_task(async function() {
11   const dbg = await initDebugger("doc-sources.html");
13   await navigate(dbg, "doc-watchpoints.html", "doc-watchpoints.html");
14   await selectSource(dbg, "doc-watchpoints.html");
15   await waitForPaused(dbg);
16   const sourceId = findSource(dbg, "doc-watchpoints.html").id;
18   info("Add a get watchpoint at b");
19   await toggleScopeNode(dbg, 3);
20   const addedWatchpoint = waitForDispatch(dbg.store, "SET_WATCHPOINT");
21   await rightClickScopeNode(dbg, 5);
22   const sub = findContextMenu(dbg, selectors.watchpointsSubmenu);
23   sub.openMenu(true);
24   const getWatchpointItem = document.querySelector(selectors.addGetWatchpoint);
25   getWatchpointItem.click();
26   pressKey(dbg, "Escape");
27   await addedWatchpoint;
29   await resume(dbg);
30   await waitForPaused(dbg);
31   await waitForState(dbg, () => dbg.selectors.getSelectedInlinePreviews());
32   assertPausedAtSourceAndLine(dbg, sourceId, 17);
33   is(await getScopeValue(dbg, 5), "3");
35   info("Resume and wait to pause at the access to b in the first `obj.b;`");
36   await resume(dbg);
37   await waitForPaused(dbg);
38   assertPausedAtSourceAndLine(dbg, sourceId, 19);
40   info("Remove the get watchpoint on b");
41   const removedWatchpoint1 = waitForDispatch(dbg.store, "REMOVE_WATCHPOINT");
42   const el1 = await waitForElementWithSelector(dbg, ".remove-get-watchpoint");
43   el1.scrollIntoView();
44   clickElementWithSelector(dbg, ".remove-get-watchpoint");
45   await removedWatchpoint1;
47   info(
48     "Resume and wait to skip the second `obj.b` and pause on the debugger statement"
49   );
50   await resume(dbg);
51   await waitForPaused(dbg);
52   assertPausedAtSourceAndLine(dbg, sourceId, 21);
54   info("Resume and pause on the debugger statement in getB");
55   await resume(dbg);
56   await waitForPaused(dbg);
57   assertPausedAtSourceAndLine(dbg, sourceId, 5);
59   info("Add a get watchpoint to b");
60   await toggleScopeNode(dbg, 4);
61   const addedWatchpoint2 = waitForDispatch(dbg.store, "SET_WATCHPOINT");
62   await rightClickScopeNode(dbg, 6);
63   sub.openMenu(true);
64   const getWatchpointItem2 = document.querySelector(selectors.addGetWatchpoint);
65   getWatchpointItem2.click();
66   pressKey(dbg, "Escape");
67   await addedWatchpoint2;
69   info("Resume and wait to pause at the access to b in getB");
70   await resume(dbg);
71   await waitForPaused(dbg);
72   assertPausedAtSourceAndLine(dbg, sourceId, 6);
74   info("Resume and pause on the debugger statement");
75   await waitForRequestsToSettle(dbg);
76   await resume(dbg);
77   await waitForPaused(dbg);
78   assertPausedAtSourceAndLine(dbg, sourceId, 24);
80   info("Remove the get watchpoint on b");
81   const removedWatchpoint2 = waitForDispatch(dbg.store, "REMOVE_WATCHPOINT");
82   await toggleScopeNode(dbg, 3);
83   await rightClickScopeNode(dbg, 5);
84   const el2 = await waitForElementWithSelector(dbg, ".remove-get-watchpoint");
85   el2.scrollIntoView();
86   clickElementWithSelector(dbg, ".remove-get-watchpoint");
87   await removedWatchpoint2;
89   info("Add back the get watchpoint on b");
90   const addedWatchpoint3 = waitForDispatch(dbg.store, "SET_WATCHPOINT");
91   await rightClickScopeNode(dbg, 5);
92   sub.openMenu(true);
93   const getWatchpointItem3 = document.querySelector(selectors.addGetWatchpoint);
94   getWatchpointItem3.click();
95   pressKey(dbg, "Escape");
96   await addedWatchpoint3;
98   info("Resume and wait to pause on the final `obj.b;`");
99   await resume(dbg);
101   await waitForPaused(dbg);
102   assertPausedAtSourceAndLine(dbg, sourceId, 25);
103   await waitForRequestsToSettle(dbg);
106 async function getScopeValue(dbg, index) {
107   return (await waitForElement(dbg, "scopeValue", index)).innerText;