tor-browser

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

task-attribution-hash-change.html (1345B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8" />
      3 <script src="/resources/testharness.js"></script>
      4 <script src="/resources/testharnessreport.js"></script>
      5 <script src="/resources/testdriver.js"></script>
      6 <script src="/resources/testdriver-vendor.js"></script>
      7 <script src="/soft-navigation-heuristics/resources/soft-navigation-test-helper.js"></script>
      8 
      9 <button id="navigateButton">Click here!</button>
     10 <div id="content"></div>
     11 
     12 <script>
     13  promise_test(async t => {
     14    navigateButton.addEventListener('click', () => {
     15      window.location.hash = '#hash1';
     16    }, {once: true});
     17 
     18    window.addEventListener('hashchange', () => {
     19      content.innerHTML = '<h1>Content</h1>'
     20    }, {once: true});
     21 
     22    const softNavPromise = SoftNavigationTestHelper.getPerformanceEntries(
     23        /*type=*/'soft-navigation', /*min_num_entries=*/1);
     24 
     25    if (test_driver) {
     26      test_driver.click(navigateButton);
     27    }
     28 
     29    const helper = new SoftNavigationTestHelper(t);
     30    const entries = await helper.withTimeoutMessage(
     31        softNavPromise, 'Soft navigation entry never arrived.', 3000);
     32    assert_equals(entries.length, 1, 'Expected exactly one soft navigation.');
     33    assert_true(
     34        entries[0].name.endsWith('#hash1'), 'Unexpected Soft Navigation URL.');
     35  }, 'Soft Navigation Detection supports propagating through the hashchange event');
     36 </script>