tor-browser

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

referrer-toplevel-script-fetch.https.html (2692B)


      1 <!DOCTYPE html>
      2 <title>Service Worker: check referrer of top-level script fetch</title>
      3 <meta name="timeout" content="long">
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <script src="/common/get-host-info.sub.js"></script>
      7 <script src="resources/test-helpers.sub.js?pipe=sub"></script>
      8 <script>
      9 
     10 async function get_toplevel_script_headers(worker) {
     11  worker.postMessage("getHeaders");
     12  return new Promise((resolve) => {
     13    navigator.serviceWorker.onmessage = (event) => {
     14      resolve(event.data);
     15    };
     16  });
     17 }
     18 
     19 promise_test(async (t) => {
     20  const script = "resources/test-request-headers-worker.py";
     21  const scope = "resources/blank.html";
     22  const host_info = get_host_info();
     23 
     24  const registration = await service_worker_unregister_and_register(
     25    t, script, scope);
     26  t.add_cleanup(() => service_worker_unregister(t, scope));
     27  await wait_for_state(t, registration.installing, "activated");
     28 
     29  const expected_referrer = host_info["HTTPS_ORIGIN"] + location.pathname;
     30 
     31  // Check referrer for register().
     32  const register_headers = await get_toplevel_script_headers(registration.active);
     33  assert_equals(register_headers["referer"], expected_referrer, "referrer of register()");
     34 
     35  // Check referrer for update().
     36  await registration.update();
     37  await wait_for_state(t, registration.installing, "installed");
     38  const update_headers = await get_toplevel_script_headers(registration.waiting);
     39  assert_equals(update_headers["referer"], expected_referrer, "referrer of update()");
     40 }, "Referrer of the top-level script fetch should be the document URL");
     41 
     42 promise_test(async (t) => {
     43  const script = "resources/test-request-headers-worker.py";
     44  const scope = "resources/blank.html";
     45  const host_info = get_host_info();
     46 
     47  const registration = await service_worker_unregister_and_register(
     48    t, script, scope, {type: 'module'});
     49  t.add_cleanup(() => service_worker_unregister(t, scope));
     50  await wait_for_state(t, registration.installing, "activated");
     51 
     52  const expected_referrer = host_info["HTTPS_ORIGIN"] + location.pathname;
     53 
     54  // Check referrer for register().
     55  const register_headers = await get_toplevel_script_headers(registration.active);
     56  assert_equals(register_headers["referer"], expected_referrer, "referrer of register()");
     57 
     58  // Check referrer for update().
     59  await registration.update();
     60  await wait_for_state(t, registration.installing, "installed");
     61  const update_headers = await get_toplevel_script_headers(registration.waiting);
     62  assert_equals(update_headers["referer"], expected_referrer, "referrer of update()");
     63 }, "Referrer of the module script fetch should be the document URL");
     64 </script>