tor-browser

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

fragment.https.html (1388B)


      1 <!DOCTYPE html>
      2 <script src="/resources/testharness.js"></script>
      3 <script src="/resources/testharnessreport.js"></script>
      4 <script src="/common/dispatcher/dispatcher.js"></script>
      5 <script src="/common/utils.js"></script>
      6 <script src="../resources/utils.js"></script>
      7 <script src="resources/utils.sub.js"></script>
      8 <script>
      9 setup(() => assertSpeculationRulesIsSupported());
     10 
     11 promise_test(async t => {
     12  const testUrl = document.URL;
     13  const [prefetchUrl, anotherPrefetchUrl] = getPrefetchUrlList(2);
     14  try {
     15    history.pushState({}, '', prefetchUrl);
     16    const urls = [
     17      new URL('#fragment', prefetchUrl),
     18      new URL('#fragment', anotherPrefetchUrl),
     19    ];
     20    insertSpeculationRules({prefetch: [{source: 'list', urls}]});
     21    await new Promise(resolve => t.step_timeout(resolve, 2000));
     22    assert_equals(await isUrlPrefetched(prefetchUrl), 0);
     23    assert_equals(await isUrlPrefetched(anotherPrefetchUrl), 1);
     24  } finally {
     25    // We needed to temporarily change the document URL to do the previous
     26    // test. Undo that to avoid breaking any other test cases.
     27    history.back();
     28    await new Promise(resolve => {
     29      addEventListener('popstate', () => resolve(), {once: true});
     30    });
     31    await new Promise(resolve => t.step_timeout(resolve, 0));
     32    assert_equals(document.URL, testUrl);
     33  }
     34 }, "fragment links to the current document URL are not prefetched");
     35 </script>