tor-browser

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

intercept-same-document-history-back.html (1617B)


      1 <!doctype html>
      2 <script src="/resources/testharness.js"></script>
      3 <script src="/resources/testharnessreport.js"></script>
      4 <script>
      5 async_test(t => {
      6  let start_length = navigation.entries().length;
      7  let start_index = navigation.currentEntry.index;
      8 
      9  // Wait for after the load event so that the navigation doesn't get converted
     10  // into a replace navigation.
     11  window.onload = () => t.step_timeout(() => {
     12    let onnavigate_calls = 0;
     13    let onnavigatesuccess_calls = 0;
     14    navigation.onnavigate = e => {
     15      onnavigate_calls++;
     16      e.intercept();
     17    }
     18    navigation.onnavigatesuccess = t.step_func(e => {
     19      onnavigatesuccess_calls++;
     20      if (onnavigatesuccess_calls == 3) {
     21        assert_equals(navigation.entries().length, start_length + 2);
     22        assert_equals(navigation.currentEntry.index, start_index + 1);
     23        assert_equals(onnavigate_calls, 3);
     24        history.back();
     25      } else if (onnavigatesuccess_calls == 4) {
     26        assert_equals(navigation.entries().length, start_length + 2);
     27        assert_equals(navigation.currentEntry.index, start_index);
     28        assert_equals(onnavigate_calls, 4);
     29        t.done();
     30      }
     31    });
     32 
     33    navigation.navigate("?foo").finished
     34      .then(t.step_func(() => navigation.navigate("?bar").finished))
     35      .then(t.step_func(() => {
     36        assert_equals(navigation.entries().length, start_length + 2);
     37        assert_equals(navigation.currentEntry.index, start_index + 2);
     38        assert_equals(onnavigate_calls, 2);
     39        history.back();
     40      }));
     41  }, 0);
     42 }, "event.intercept() can intercept same-document history.back()");
     43 </script>