Bug 1743347 - [devtools] Check whyPaused text in mochitests. r=bomsy.
authorNicolas Chevobbe <nchevobbe@mozilla.com>
Thu, 02 Dec 2021 07:10:28 +0000
changeset 600874 41993db6c7a1b1e65d71e01a81777517de5bae1d
parent 600873 6eaac86a49224c5818897ddb47466da5c52f4a53
child 600875 90369a230cb466c36dea3c186b3b92716c9bc826
push id39031
push usersmolnar@mozilla.com
push dateThu, 02 Dec 2021 21:50:58 +0000
treeherdermozilla-central@260e2362bbc3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbomsy
bugs1743347
milestone96.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1743347 - [devtools] Check whyPaused text in mochitests. r=bomsy. While working around those strings, I realized we didn't check the text of the component in the different situations it handles, so I added a few assertions. Differential Revision: https://phabricator.services.mozilla.com/D132338
devtools/client/debugger/test/mochitest/browser_dbg-breaking.js
devtools/client/debugger/test/mochitest/browser_dbg-dom-mutation-breakpoints.js
devtools/client/debugger/test/mochitest/browser_dbg-event-breakpoints.js
devtools/client/debugger/test/mochitest/browser_dbg-pause-exceptions.js
devtools/client/debugger/test/mochitest/browser_dbg-stepping.js
devtools/client/debugger/test/mochitest/browser_dbg-watchpoints.js
devtools/client/debugger/test/mochitest/browser_dbg-xhr-breakpoints.js
devtools/client/debugger/test/mochitest/examples/doc-dom-mutation.html
devtools/client/debugger/test/mochitest/examples/dom-mutation.js
--- a/devtools/client/debugger/test/mochitest/browser_dbg-breaking.js
+++ b/devtools/client/debugger/test/mochitest/browser_dbg-breaking.js
@@ -18,23 +18,33 @@ add_task(async function() {
   await addBreakpoint(dbg, "scripts.html", 21);
 
   reload(dbg);
 
   await waitForDispatch(dbg.store, "NAVIGATE");
   await waitForSelectedSource(dbg, "doc-scripts.html");
   await waitForPaused(dbg);
 
+  let whyPaused = await waitFor(
+    () => dbg.win.document.querySelector(".why-paused")?.innerText
+  );
+  is(whyPaused, "Paused on breakpoint");
+
   assertPausedLocation(dbg);
   await resume(dbg);
 
   info("Create an eval script that pauses itself.");
   invokeInTab("doEval");
   await waitForPaused(dbg);
 
+  whyPaused = await waitFor(
+    () => dbg.win.document.querySelector(".why-paused")?.innerText
+  );
+  is(whyPaused, "Paused on debugger statement");
+
   await resume(dbg);
   const source = getSelectedSource();
   ok(!source.url, "It is an eval source");
 
   await addBreakpoint(dbg, source, 5);
   invokeInTab("evaledFunc");
   await waitForPaused(dbg);
   assertPausedLocation(dbg);
--- a/devtools/client/debugger/test/mochitest/browser_dbg-dom-mutation-breakpoints.js
+++ b/devtools/client/debugger/test/mochitest/browser_dbg-dom-mutation-breakpoints.js
@@ -16,17 +16,16 @@ const DMB_TEST_URL =
   "https://example.com/browser/devtools/client/debugger/test/mochitest/examples/doc-dom-mutation.html";
 
 async function enableMutationBreakpoints() {
   await pushPref("devtools.debugger.features.dom-mutation-breakpoints", true);
   await pushPref("devtools.markup.mutationBreakpoints.enabled", true);
   await pushPref("devtools.debugger.dom-mutation-breakpoints-visible", true);
 }
 
-
 add_task(async function() {
   // Enable features
   await enableMutationBreakpoints();
   info("Switches over to the inspector pane");
 
   const { inspector, toolbox } = await openInspectorForURL(DMB_TEST_URL);
 
   info("Selecting the body node");
@@ -63,30 +62,61 @@ add_task(async function() {
   checkbox.click();
   await waitFor(() => checkbox.checked);
 
   info("Changing attribute to trigger debugger pause");
   SpecialPowers.spawn(gBrowser.selectedBrowser, [], function() {
     content.document.querySelector("#attribute").click();
   });
   await waitForPaused(dbg);
+  let whyPaused = await waitFor(
+    () => dbg.win.document.querySelector(".why-paused")?.innerText
+  );
+  is(
+    whyPaused,
+    `Paused on DOM mutation\nDOM Mutation: 'attributeModified'\nbody`
+  );
+
   await resume(dbg);
 
   info("Changing style to trigger debugger pause");
   SpecialPowers.spawn(gBrowser.selectedBrowser, [], function() {
     content.document.querySelector("#style-attribute").click();
   });
   await waitForPaused(dbg);
   await resume(dbg);
 
-  info("Changing subtree to trigger debugger pause");
+  info("Adding element in subtree to trigger debugger pause");
   SpecialPowers.spawn(gBrowser.selectedBrowser, [], function() {
-    content.document.querySelector("#subtree").click();
+    content.document.querySelector("#add-in-subtree").click();
   });
   await waitForPaused(dbg);
+  whyPaused = await waitFor(
+    () => dbg.win.document.querySelector(".why-paused")?.innerText
+  );
+  is(
+    whyPaused,
+    `Paused on DOM mutation\nDOM Mutation: 'subtreeModified'\nbodyAdded:div`
+  );
+
+  await resume(dbg);
+
+  info("Removing element in subtree to trigger debugger pause");
+  SpecialPowers.spawn(gBrowser.selectedBrowser, [], function() {
+    content.document.querySelector("#remove-in-subtree").click();
+  });
+  await waitForPaused(dbg);
+  whyPaused = await waitFor(
+    () => dbg.win.document.querySelector(".why-paused")?.innerText
+  );
+  is(
+    whyPaused,
+    `Paused on DOM mutation\nDOM Mutation: 'subtreeModified'\nbodyRemoved:div`
+  );
+
   await resume(dbg);
 
   info("Blackboxing the source prevents debugger pause");
   await waitForSource(dbg, "dom-mutation.original.js");
 
   const source = findSource(dbg, "dom-mutation.original.js");
 
   await selectSource(dbg, source);
@@ -102,10 +132,9 @@ add_task(async function() {
 
   await selectSource(dbg, source);
   await clickElement(dbg, "blackbox");
   await waitForDispatch(dbg.store, "BLACKBOX");
 
   info("Removing breakpoints works");
   dbg.win.document.querySelector(".dom-mutation-list .close-btn").click();
   await waitForAllElements(dbg, "domMutationItem", 1, true);
-
 });
--- a/devtools/client/debugger/test/mochitest/browser_dbg-event-breakpoints.js
+++ b/devtools/client/debugger/test/mochitest/browser_dbg-event-breakpoints.js
@@ -23,16 +23,22 @@ add_task(async function() {
     "timer.timeout.set",
     "timer.timeout.fire",
     "script.source.firstStatement",
   ]);
 
   invokeInTab("clickHandler");
   await waitForPaused(dbg);
   assertPauseLocation(dbg, 12);
+
+  const whyPaused = await waitFor(
+    () => dbg.win.document.querySelector(".why-paused")?.innerText
+  );
+  is(whyPaused, `Paused on event breakpoint\nDOM 'click' event`);
+
   await resume(dbg);
 
   invokeInTab("xhrHandler");
   await waitForPaused(dbg);
   assertPauseLocation(dbg, 20);
   await resume(dbg);
 
   invokeInTab("timerHandler");
@@ -85,12 +91,16 @@ function assertPauseLocation(dbg, line, 
   is(location.sourceId, source.id, `correct sourceId`);
   is(location.line, line, `correct line`);
 
   assertPausedLocation(dbg);
 }
 
 async function invokeOnElement(selector, action) {
   await SpecialPowers.focus(gBrowser.selectedBrowser);
-  await SpecialPowers.spawn(gBrowser.selectedBrowser, [selector, action], (_selector, _action) => {
-    content.document.querySelector(_selector)[_action]();
-  });
+  await SpecialPowers.spawn(
+    gBrowser.selectedBrowser,
+    [selector, action],
+    (_selector, _action) => {
+      content.document.querySelector(_selector)[_action]();
+    }
+  );
 }
--- a/devtools/client/debugger/test/mochitest/browser_dbg-pause-exceptions.js
+++ b/devtools/client/debugger/test/mochitest/browser_dbg-pause-exceptions.js
@@ -17,16 +17,22 @@ add_task(async function() {
   await uncaughtException();
   ok(!isPaused(dbg));
 
   log("2. Test pausing on an uncaught exception");
   await togglePauseOnExceptions(dbg, true, true);
   uncaughtException();
   await waitForPaused(dbg);
   assertPausedLocation(dbg);
+
+  const whyPaused = await waitFor(
+    () => dbg.win.document.querySelector(".why-paused")?.innerText
+  );
+  is(whyPaused, `Paused on exception\nunreachable`);
+
   await resume(dbg);
 
   log("2.b Test throwing the same uncaught exception pauses again");
   await togglePauseOnExceptions(dbg, true, true);
   uncaughtException();
   await waitForPaused(dbg);
   assertPausedLocation(dbg);
   await resume(dbg);
--- a/devtools/client/debugger/test/mochitest/browser_dbg-stepping.js
+++ b/devtools/client/debugger/test/mochitest/browser_dbg-stepping.js
@@ -6,16 +6,22 @@
 requestLongerTimeout(5);
 
 add_task(async function test() {
   const dbg = await initDebugger("big-sourcemap.html", "big-sourcemap");
   invokeInTab("hitDebugStatement");
   await waitForPaused(dbg, "bundle.js");
 
   await stepIn(dbg);
+
+  const whyPaused = await waitFor(
+    () => dbg.win.document.querySelector(".why-paused")?.innerText
+  );
+  is(whyPaused, `Paused while stepping`);
+
   await stepIn(dbg);
   await stepIn(dbg);
   await stepIn(dbg);
   await stepIn(dbg);
   await stepIn(dbg);
   await stepIn(dbg);
   await stepIn(dbg);
   await stepIn(dbg);
--- a/devtools/client/debugger/test/mochitest/browser_dbg-watchpoints.js
+++ b/devtools/client/debugger/test/mochitest/browser_dbg-watchpoints.js
@@ -28,16 +28,20 @@ add_task(async function() {
   await addedWatchpoint;
   popup.hidePopup();
 
   await resume(dbg);
   await waitForPaused(dbg);
   await waitForState(dbg, () => dbg.selectors.getSelectedInlinePreviews());
   assertPausedAtSourceAndLine(dbg, sourceId, 17);
   is(await getScopeValue(dbg, 5), "3");
+  const whyPaused = await waitFor(
+    () => dbg.win.document.querySelector(".why-paused")?.innerText
+  );
+  is(whyPaused, `Paused on property get\nobj.b`);
 
   info("Resume and wait to pause at the access to b in the first `obj.b;`");
   await resume(dbg);
   await waitForPaused(dbg);
   assertPausedAtSourceAndLine(dbg, sourceId, 19);
 
   info("Remove the get watchpoint on b");
   const removedWatchpoint1 = waitForDispatch(dbg.store, "REMOVE_WATCHPOINT");
--- a/devtools/client/debugger/test/mochitest/browser_dbg-xhr-breakpoints.js
+++ b/devtools/client/debugger/test/mochitest/browser_dbg-xhr-breakpoints.js
@@ -7,33 +7,39 @@ add_task(async function() {
 
   const dbg = await initDebugger("doc-xhr.html", "fetch.js");
 
   await addXHRBreakpoint(dbg, "doc", "GET");
 
   await SpecialPowers.spawn(
     gBrowser.selectedBrowser,
     [EXAMPLE_REMOTE_URL + "doc-early-xhr.html"],
-    (remoteUrl) => {
+    remoteUrl => {
       const firstIframe = content.document.createElement("iframe");
       content.document.body.append(firstIframe);
       firstIframe.src = remoteUrl;
     }
   );
 
   await waitForPaused(dbg);
   assertPausedLocation(dbg);
+
+  const whyPaused = await waitFor(
+    () => dbg.win.document.querySelector(".why-paused")?.innerText
+  );
+  is(whyPaused, `Paused on XMLHttpRequest`);
+
   await resume(dbg);
 
   await dbg.actions.removeXHRBreakpoint(0);
 
   await SpecialPowers.spawn(
     gBrowser.selectedBrowser,
     [EXAMPLE_REMOTE_URL + "doc-early-xhr.html"],
-    (remoteUrl) => {
+    remoteUrl => {
       const secondIframe = content.document.createElement("iframe");
       content.document.body.append(secondIframe);
       secondIframe.src = remoteUrl;
     }
   );
 
   // Wait for some time, in order to wait for it to be paused
   // in case we regress
@@ -53,17 +59,16 @@ add_task(async function() {
   await waitForPaused(dbg);
   assertPausedLocation(dbg);
   await resume(dbg);
 
   await dbg.actions.removeXHRBreakpoint(0);
   await invokeInTab("main", "doc-xhr.html");
   assertNotPaused(dbg);
 
-
   info("Test that we do not pause on different method type");
   await addXHRBreakpoint(dbg, "doc", "POST");
   await invokeInTab("main", "doc-xhr.html");
   assertNotPaused(dbg);
 });
 
 // Tests the "pause on any URL" checkbox works properly
 add_task(async function() {
@@ -152,17 +157,19 @@ async function removeXHRBreakpoint(dbg, 
     closeButtons[index].click();
   }
 
   await waitForDispatch(dbg.store, "REMOVE_XHR_BREAKPOINT");
 }
 
 function getXHRBreakpointsElements(dbg) {
   return [
-    ...dbg.win.document.querySelectorAll(".xhr-breakpoints-pane .xhr-container")
+    ...dbg.win.document.querySelectorAll(
+      ".xhr-breakpoints-pane .xhr-container"
+    ),
   ];
 }
 
 function getXHRBreakpointLabels(elements) {
   return elements.map(element => element.title);
 }
 
 function getXHRBreakpointCheckbox(dbg) {
--- a/devtools/client/debugger/test/mochitest/examples/doc-dom-mutation.html
+++ b/devtools/client/debugger/test/mochitest/examples/doc-dom-mutation.html
@@ -6,13 +6,14 @@
   <head>
     <meta charset="utf-8"/>
     <title>Debugger test page</title>
   </head>
 
   <body>
     <button title="Hello" id="attribute" onclick="changeAttribute()">Click me!</button>
     <button id="style-attribute" onclick="changeStyleAttribute()">Click me!</button>
-    <button id="subtree" onclick="changeSubtree()">Click me!</button>
+    <button id="add-in-subtree" onclick="addDivToBody()">add div to body</button>
+    <button id="remove-in-subtree" onclick="removeDivInBody()">remove div in body</button>
     <button id="blackbox" onclick="changeAttribute();&#xA;debugger;&#xA;//# sourceURL=click.js">Click me!</button>
     <script src="dom-mutation.js"></script>
   </body>
 </html>
--- a/devtools/client/debugger/test/mochitest/examples/dom-mutation.js
+++ b/devtools/client/debugger/test/mochitest/examples/dom-mutation.js
@@ -2,12 +2,17 @@ function changeAttribute() {
   const title = document.body.title === "Goodbye" ? "Hello" : "Goodbye";
   document.body.setAttribute("title", title);
 }
 
 function changeStyleAttribute() {
   document.body.style.color = "blue";
 }
 
-function changeSubtree() {
+function addDivToBody() {
   document.body.appendChild(document.createElement("div"));
 }
+
+function removeDivInBody() {
+  document.body.querySelector("div").remove();
+}
+
 //# sourceMappingURL=dom-mutation.js.map