tor-browser

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

update-module-request-mode.https.html (1596B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <meta name="timeout" content="long">
      4 <title>Test that mode is set to same-origin for a main module</title>
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 <script src="resources/test-helpers.sub.js"></script>
      8 <script>
      9 // Tests a main module service worker script fetch during an update check.
     10 // The fetch should have the mode set to 'same-origin'.
     11 //
     12 // The test works by registering a main module service worker. It then does an
     13 // update. The test server responds with an updated worker script that remembers
     14 // the http request. The updated worker reports back this request to the test
     15 // page.
     16 promise_test(async (t) => {
     17  const script = "resources/test-request-mode-worker.py";
     18  const scope = "resources/";
     19 
     20  // Register the service worker.
     21  await service_worker_unregister(t, scope);
     22  const registration = await navigator.serviceWorker.register(
     23      script, {scope, type: 'module'});
     24  await wait_for_state(t, registration.installing, 'activated');
     25 
     26  // Do an update.
     27  await registration.update();
     28 
     29  // Ask the new worker what the request was.
     30  const newWorker = registration.installing;
     31  const sawMessage = new Promise((resolve) => {
     32    navigator.serviceWorker.onmessage = (event) => {
     33      resolve(event.data);
     34    };
     35  });
     36  newWorker.postMessage('getHeaders');
     37  const result = await sawMessage;
     38 
     39  // Test the result.
     40  assert_equals(result['sec-fetch-mode'], 'same-origin');
     41  assert_equals(result['origin'], undefined);
     42 
     43 }, 'headers of a main module script');
     44 
     45 </script>