summaryrefslogtreecommitdiffstats
path: root/dom/ipc/tests/browser_content_shutdown_with_endless_js.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /dom/ipc/tests/browser_content_shutdown_with_endless_js.js
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/ipc/tests/browser_content_shutdown_with_endless_js.js')
-rw-r--r--dom/ipc/tests/browser_content_shutdown_with_endless_js.js86
1 files changed, 86 insertions, 0 deletions
diff --git a/dom/ipc/tests/browser_content_shutdown_with_endless_js.js b/dom/ipc/tests/browser_content_shutdown_with_endless_js.js
new file mode 100644
index 0000000000..c97e22f633
--- /dev/null
+++ b/dom/ipc/tests/browser_content_shutdown_with_endless_js.js
@@ -0,0 +1,86 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const EMPTY_PAGE =
+ "http://mochi.test:8888/browser/dom/ipc/tests/file_dummy.html";
+
+const HANG_PAGE =
+ "http://mochi.test:8888/browser/dom/ipc/tests/file_endless_js.html";
+
+function pushPref(name, val) {
+ return SpecialPowers.pushPrefEnv({ set: [[name, val]] });
+}
+
+async function createAndShutdownContentProcess(url) {
+ info("Create and shutdown a content process for " + url);
+
+ // Launch a new process and load url. Sets up a promise that will resolve
+ // on shutdown.
+ let browserDestroyed = PromiseUtils.defer();
+ await BrowserTestUtils.withNewTab(
+ {
+ gBrowser,
+ opening: url,
+ waitForLoad: true,
+ forceNewProcess: true,
+ },
+ async function (otherBrowser) {
+ let remoteTab = otherBrowser.frameLoader.remoteTab;
+
+ ok(true, "Content process created.");
+
+ browserDestroyed.resolve(
+ TestUtils.topicObserved(
+ "ipc:browser-destroyed",
+ subject => subject === remoteTab
+ )
+ );
+
+ // Trigger onmessage in the content browser
+ await SpecialPowers.spawn(otherBrowser, [], function () {
+ content.postMessage("LoadedMessage", "*");
+ });
+
+ // Give the content process some extra time before we start its shutdown.
+ // eslint-disable-next-line mozilla/no-arbitrary-setTimeout
+ await new Promise(resolve => setTimeout(resolve, 50));
+
+ // withNewTab will start the shutdown of the child process for us
+ }
+ );
+
+ // Now wait for it to really shut down.
+ // If the HANG_PAGE JS is not canceled we will hang here.
+ await browserDestroyed.promise;
+
+ // If we do not hang and get here, we are fine.
+ 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;
+ }
+
+ await pushPref("dom.abort_script_on_child_shutdown", true);
+
+ // Ensure the process cache cannot interfere.
+ pushPref("dom.ipc.processPreload.enabled", false);
+ // Ensure we have no cached processes from previous tests.
+ Services.ppmm.releaseCachedProcesses();
+
+ // First let's do a dry run that should always succeed.
+ await createAndShutdownContentProcess(EMPTY_PAGE);
+
+ // Now we will start a shutdown of our content process while our content
+ // script is running an endless loop.
+ //
+ // If the JS does not get interrupted on shutdown, it will cause this test
+ // to hang.
+ await createAndShutdownContentProcess(HANG_PAGE);
+});