tor-browser

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

dispose-same-document.html (3102B)


      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 dispose2Called = false;
     22  entry2.ondispose = t.step_func(e => {
     23    dispose2Called = true;
     24 
     25    assert_equals(e.constructor, Event);
     26    assert_equals(e.bubbles, false);
     27    assert_equals(e.cancelable, false);
     28    assert_equals(e.composed, false);
     29 
     30    assert_array_equals(
     31      navigation.entries().slice(start_index),
     32      [entry0, entry1, navigation.currentEntry],
     33      "entries() is updated during dispose for entry 2");
     34    assert_not_equals(navigation.currentEntry, entry1, "current entry must be updated during dispose for entry 3");
     35    assert_true(navigation.canGoBack, "canGoBack is still true during dispose for entry 2");
     36    assert_false(navigation.canGoForward, "canGoForward is still false during beforedispose for entry 2");
     37    assert_equals(navigation.transition, null, "transition during dispose for entry 2");
     38    assert_equals(location.hash, "#fork", "location.hash is updated during dispose for entry 2");
     39  });
     40 
     41  entry3.addEventListener("dispose", t.step_func_done(e => {
     42    assert_true(dispose2Called, "dispose for entry 2 must have happened before entry 3");
     43 
     44    assert_array_equals(
     45      navigation.entries().slice(start_index),
     46      [entry0, entry1, navigation.currentEntry],
     47      "entries() is updated during dispose for entry 3");
     48    assert_not_equals(navigation.currentEntry, entry1, "current entry must be updated during dispose for entry 3");
     49    assert_true(navigation.canGoBack, "canGoBack is still true during dispose for entry 3");
     50    assert_false(navigation.canGoForward, "canGoForward is still false during beforedispose for entry 3");
     51    assert_equals(navigation.transition, null, "transition during dispose for entry 2");
     52    assert_equals(location.hash, "#fork", "location.hash is updated during dispose for entry 3");
     53  }));
     54 
     55  await navigation.traverseTo(entry1.key).committed;
     56 
     57  navigation.navigate("#fork");
     58 
     59  assert_equals(navigation.entries().length, start_length + 2);
     60  const [finalEntry0, finalEntry1, finalEntry2] = navigation.entries().slice(start_index);
     61  assert_equals(finalEntry0, entry0);
     62  assert_equals(finalEntry1, entry1);
     63  assert_not_equals(finalEntry2, entry2);
     64  assert_equals(navigation.currentEntry, finalEntry2);
     65  assert_equals((new URL(finalEntry2.url)).hash, "#fork");
     66 }, "dispose events when forward-pruning same-document entries");
     67 </script>