tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

precommitHandler-traversal-commit-new-navigation-before-commit.html (1593B)


      1 <!doctype html>
      2 <script src="/resources/testharness.js"></script>
      3 <script src="/resources/testharnessreport.js"></script>
      4 <script src="../navigation-methods/return-value/resources/helpers.js"></script>
      5 <body>
      6 <script>
      7 promise_test(async t => {
      8  // Wait for after the load event so that the navigation doesn't get converted
      9  // into a replace navigation.
     10  await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0));
     11 
     12  await navigation.navigate("#1").finished;
     13 
     14  let navigateerror_called = false;
     15  navigation.onnavigateerror = t.step_func(() => {
     16    navigateerror_called = true;
     17    assert_equals(location.hash, "#1");
     18  });
     19 
     20  // Go back and wait for the navigate event to fire. This traversal will be deferred.
     21  let promises_should_not_commit = assertBothRejectDOM(t, navigation.back(), "AbortError");
     22  navigation.addEventListener("navigate", e => e.intercept({ precommitHandler: () => new Promise(r => t.step_timeout(r, 1000)) }), { once: "true" });
     23  await new Promise(resolve => navigation.addEventListener("navigate", resolve, { once: "true" }));
     24 
     25  // While the traversal is deferred, start a new navigation and commit immediately.
     26  navigation.addEventListener("navigate", e => e.intercept(), { once: "true" });
     27  let promises_fulfilled = navigation.navigate("#2");
     28 
     29  await promises_should_not_commit;
     30  await assertBothFulfill(t, promises_fulfilled, navigation.currentEntry);
     31 
     32  assert_equals(location.hash, "#2");
     33  assert_true(navigateerror_called);
     34 }, "Cancel a precommitHandler traversal before commit by starting a new navigation");
     35 </script>
     36 </body>