tor-browser

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

header-only-top-level.html (1322B)


      1 <!DOCTYPE html>
      2 <title>Speculation-Rules header must only be fetched for top-level windows</title>
      3 <script src="/resources/testharness.js"></script>
      4 <script src="/resources/testharnessreport.js"></script>
      5 <script src="/common/utils.js"></script>
      6 <script src="/common/dispatcher/dispatcher.js"></script>
      7 <script src="/html/browsers/browsing-the-web/remote-context-helper/resources/remote-context-helper.js"></script>
      8 
      9 <script>
     10 promise_test(async t => {
     11  const uuid = token();
     12  const rulesURL = (new URL(`resources/counter.py?uuid=${uuid}`, document.baseURI)).href;
     13 
     14  const rcHelper = new RemoteContextHelper();
     15  const rc = await rcHelper.addWindow({
     16    headers: [["Speculation-Rules", `"${rulesURL}"`]]
     17  });
     18 
     19  await t.step_wait(async () => {
     20    const requestCount1 = await (await fetch(rulesURL + "&check")).json();
     21    return requestCount1 === 1;
     22  }, "wait for request count to be updated for top-level window");
     23 
     24  const iframe = rc.addIframe({
     25    headers: [["Speculation-Rules", `"${rulesURL}"`]]
     26  });
     27 
     28  // Just wait 2 seconds and hope that any erroneous request shows up by then.
     29  await new Promise(resolve => t.step_timeout(resolve, 2000));
     30 
     31  const requestCount2 = await (await fetch(rulesURL + "&check")).json();
     32  assert_equals(requestCount2, 1, "rules must not be fetched for iframes");
     33 });
     34 </script>