Bug 1493225, part 4 - Cancel content JS when navigating through history to prevent hangs r=smaug
authorJim Porter <jporter@mozilla.com>
Tue, 30 Apr 2019 23:32:01 +0000
changeset 472063 9a0ce3016f03a914367e86c8339a8b885e309c83
parent 472062 100acc204e5e0c5e8767740c4861c906e21139f5
child 472064 fbc294a6fe785b56a5ef52b5b1ea61d511bebc52
push id84445
push userjporter@mozilla.com
push dateWed, 01 May 2019 03:29:15 +0000
treeherderautoland@9a0ce3016f03 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1493225
milestone68.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 1493225, part 4 - Cancel content JS when navigating through history to prevent hangs r=smaug Add tests to verify the behavior of the previous patches. Differential Revision: https://phabricator.services.mozilla.com/D27370
dom/ipc/tests/browser.ini
dom/ipc/tests/browser_cancel_content_js.js
dom/ipc/tests/file_cancel_content_js.html
--- a/dom/ipc/tests/browser.ini
+++ b/dom/ipc/tests/browser.ini
@@ -1,11 +1,14 @@
 [DEFAULT]
 support-files =
   file_disableScript.html
   file_domainPolicy_base.html
+  file_cancel_content_js.html
 
 [browser_domainPolicy.js]
 [browser_memory_distribution_telemetry.js]
 skip-if = !e10 # This is an e10s only probe.
 [browser_remote_navigation_delay_telemetry.js]
 skip-if = !e10s # This is an e10s only probe.
-[browser_JSWindowActor.js]
\ No newline at end of file
+[browser_JSWindowActor.js]
+[browser_cancel_content_js.js]
+skip-if = !e10s # This is an e10s only probe.
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/dom/ipc/tests/browser_cancel_content_js.js
@@ -0,0 +1,44 @@
+"use strict";
+
+const TEST_PAGE = "http://mochi.test:8888/browser/dom/ipc/tests/file_cancel_content_js.html";
+const NEXT_PAGE = "https://example.org/";
+
+function sleep(ms) {
+  // eslint-disable-next-line mozilla/no-arbitrary-setTimeout
+  return new Promise((resolve) => setTimeout(resolve, ms));
+}
+
+async function test_navigation(cancelContentJS) {
+  await SpecialPowers.pushPrefEnv({
+    "set": [
+      ["dom.ipc.cancel_content_js_when_navigating", cancelContentJS],
+    ],
+  });
+  let tab = await BrowserTestUtils.openNewForegroundTab({
+    gBrowser, opening: TEST_PAGE,
+  });
+
+  await sleep(1000);
+  BrowserTestUtils.loadURI(gBrowser, NEXT_PAGE);
+  const nextPageLoaded = BrowserTestUtils.browserLoaded(tab.linkedBrowser,
+                                                        false, NEXT_PAGE);
+  const result = await Promise.race([
+    nextPageLoaded,
+    sleep(1000).then(() => "timeout"),
+  ]);
+
+  const timedOut = result === "timeout";
+  if (cancelContentJS) {
+    ok(timedOut === false, "expected next page to be loaded");
+  } else {
+    ok(timedOut === true, "expected timeout");
+    // Give the page time to finish its long-running JS before we close the
+    // tab...
+    await nextPageLoaded;
+  }
+
+  BrowserTestUtils.removeTab(tab);
+}
+
+add_task(async () => test_navigation(true));
+add_task(async () => test_navigation(false));
new file mode 100644
--- /dev/null
+++ b/dom/ipc/tests/file_cancel_content_js.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <title>while(true)</title>
+    <script>
+    </script>
+    <style>
+    </style>
+  </head>
+  <body>
+  Try to go back to the initial page.
+  <script>
+    const start = Date.now();
+    setTimeout(function() {
+      while (Date.now() - start < 3000);
+    }, 500);
+  </script>
+  </body>
+</html>