tor-browser

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

dispose-same-document-navigate-during.html (2214B)


      1 <!doctype html>
      2 <script src="/resources/testharness.js"></script>
      3 <script src="/resources/testharnessreport.js"></script>
      4 <script>
      5 promise_test(async (t) => {
      6  // Wait for after the load event so that the navigation doesn't get converted
      7  // into a replace navigation.
      8  await new Promise(r => window.onload = () => t.step_timeout(r, 0));
      9  let start_length = navigation.entries().length;
     10  let start_index = navigation.currentEntry.index;
     11 
     12  location.hash = "#1";
     13  location.hash = "#2";
     14  location.hash = "#3";
     15 
     16  assert_equals(navigation.entries().length, start_length + 3);
     17  const [entry0, entry1, entry2, entry3] = navigation.entries().slice(start_index);
     18  assert_equals((new URL(entry2.url)).hash, "#2");
     19  assert_equals((new URL(entry3.url)).hash, "#3");
     20 
     21  let dispose3Called = 0;
     22  let spoonPromise;
     23  entry3.addEventListener("dispose", t.step_func(e => {
     24    ++dispose3Called;
     25 
     26    spoonPromise = navigation.navigate("#spoon").committed;
     27  }));
     28 
     29  await navigation.traverseTo(entry1.key).committed;
     30 
     31  const forkPromise = navigation.navigate("#fork").committed;
     32  assert_equals(dispose3Called, 1, "dispose for entry 3 must happen exactly once (first check)")
     33 
     34  // The navigation to #fork will *not* be finished by the time the navigation
     35  // to #spoon kicks off, so the finished promise will reject. But, the
     36  // committed promise should still fulfill, since as we see below, #fork ends
     37  // up in the history list.
     38  await Promise.all([forkPromise, spoonPromise]);
     39 
     40  assert_equals(dispose3Called, 1, "dispose for entry 3 must happen exactly once (final check)");
     41 
     42  assert_equals(navigation.entries().length, start_length + 3);
     43  const [finalEntry0, finalEntry1, finalEntry2, finalEntry3] = navigation.entries().slice(start_index);
     44  assert_equals(finalEntry0, entry0);
     45  assert_equals(finalEntry1, entry1);
     46  assert_not_equals(finalEntry2, entry2);
     47  assert_not_equals(finalEntry3, entry3);
     48  assert_equals(navigation.currentEntry, finalEntry3);
     49  assert_equals((new URL(finalEntry2.url)).hash, "#fork");
     50  assert_equals((new URL(finalEntry3.url)).hash, "#spoon");
     51 }, "navigate() during a same-document-navigation-initiated dispose works (since it's after the previous navigation)");
     52 </script>