tor-browser

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

anchor-fragment-history-back-on-click.html (1206B)


      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(resolve => window.onload = () => t.step_timeout(resolve, 0));
      9 
     10  location.hash = "#1";
     11  assert_equals(location.hash, "#1");
     12  location.hash = "#2";
     13  assert_equals(location.hash, "#2");
     14 
     15  let anchor = document.createElement("a");
     16  anchor.href = "#3";
     17  anchor.onclick = () => {
     18    history.back();
     19  };
     20 
     21  let navigations = [];
     22  let navigationsPromise = new Promise(resolve => {
     23    onpopstate = () => {
     24      navigations.push(location.hash);
     25      if (navigations.length === 2) {
     26        resolve();
     27      }
     28    }
     29  });
     30 
     31  anchor.click();
     32  await navigationsPromise;
     33 
     34  // We were on #2 when history.back() was called so we should be on #1 now.
     35  assert_equals(location.hash, "#1");
     36 
     37  // While the history navigation back to "#1" was pending, we should have navigated to "#3".
     38  assert_array_equals(navigations, ["#3", "#1"]);
     39 }, "Anchor with a fragment href and a click handler that navigates back");
     40 </script>