Bug 1782718 - Make browser_content_shutdown_with_endless_js.js more robust against other processes' noise. r=smaug
authorJens Stutte <jstutte@mozilla.com>
Wed, 03 Aug 2022 14:51:21 +0000
changeset 625996 e06a58bd4c0a61dd59d87fb9e07761d2e598e7b3
parent 625995 01f1a7f0b385eb9d5db96f1714f8190fd8c682af
child 625997 92f831c8044ebbc3580e23d434681e61eaf57dff
push id40079
push usersmolnar@mozilla.com
push dateWed, 03 Aug 2022 21:28:30 +0000
treeherdermozilla-central@ae4cb105d717 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1782718
milestone105.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 1782718 - Make browser_content_shutdown_with_endless_js.js more robust against other processes' noise. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D153560
dom/ipc/tests/browser_content_shutdown_with_endless_js.js
--- a/dom/ipc/tests/browser_content_shutdown_with_endless_js.js
+++ b/dom/ipc/tests/browser_content_shutdown_with_endless_js.js
@@ -12,60 +12,48 @@ const HANG_PAGE =
 
 function pushPref(name, val) {
   return SpecialPowers.pushPrefEnv({ set: [[name, val]] });
 }
 
 async function createAndShutdownContentProcess(url) {
   info("Create and shutdown a content process for " + url);
 
-  let oldChildCount = Services.ppmm.childCount;
-  info("Old process count: " + oldChildCount);
+  // Launch a new process and load url. Sets up a promise that will resolve
+  // on shutdown.
+  let browserParentDestroyed = PromiseUtils.defer();
+  await BrowserTestUtils.withNewTab(
+    {
+      gBrowser,
+      opening: url,
+      waitForLoad: true,
+      forceNewProcess: true,
+    },
+    async function(otherBrowser) {
+      let remoteTab = otherBrowser.frameLoader.remoteTab;
 
-  let tabpromise = BrowserTestUtils.openNewForegroundTab({
-    gBrowser,
-    opening: url,
-    waitForLoad: true,
-    forceNewProcess: true,
-  });
+      ok(true, "Content process created.");
 
-  let tab = await tabpromise;
+      browserParentDestroyed.resolve(
+        TestUtils.topicObserved(
+          "ipc:browser-destroyed",
+          subject => subject === remoteTab
+        )
+      );
 
-  // It seems that the ppmm counter is racy wrt tabpromise.
-  Services.tm.spinEventLoopUntil(
-    "browser_content_shutdown_with_endless_js",
-    () => Services.ppmm.childCount > oldChildCount
+      // withNewTab will start the shutdown of the child process for us
+    }
   );
 
-  let newChildCount = Services.ppmm.childCount;
-  info("New process count: " + newChildCount);
-
-  // There can be (unrelated) other processes launching, so we cannot do an
-  // exact `newChildCount == oldChildCount + 1` here. This is weird but not
-  // relevant for our test.
-  ok(newChildCount > oldChildCount, "Process created.");
-
-  // Start the shutdown of the child process
-  let tabClosed = BrowserTestUtils.waitForTabClosing(tab);
-  BrowserTestUtils.removeTab(tab);
-  ok(true, "removeTab");
-
-  Services.tm.spinEventLoopUntil(
-    "browser_content_shutdown_with_endless_js",
-    () => Services.ppmm.childCount < newChildCount
-  );
-
-  info("New count: " + Services.ppmm.childCount);
-  await tabClosed;
+  // Now wait for it to really shut down.
+  // If the HANG_PAGE JS is not canceled we will hang here.
+  await browserParentDestroyed.promise;
 
   // If we do not hang and get here, we are fine.
-  ok(
-    Services.ppmm.childCount < newChildCount,
-    "Shutdown of content process complete."
-  );
+  ok(true, "Shutdown of content process.");
 }
 
 add_task(async () => {
   // This test is only relevant in e10s.
   if (!gMultiProcessBrowser) {
     ok(true, "We are not in multiprocess mode, skipping test.");
     return;
   }