tor-browser

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

update-no-cache-request-headers.https.html (1832B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>Test that cache is being bypassed/validated in no-cache mode on update</title>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <script src="resources/test-helpers.sub.js"></script>
      7 <script>
      8 // Tests a service worker script fetch during an update check which
      9 // bypasses/validates the browser cache. The fetch should have the
     10 // 'if-none-match' request header.
     11 //
     12 // This tests the Update step:
     13 //  "Set request’s cache mode to "no-cache" if any of the following are true..."
     14 // https://w3c.github.io/ServiceWorker/#update-algorithm
     15 //
     16 // The test works by registering a service worker with |updateViaCache|
     17 // set to "none". It then does an update. The test server responds with
     18 // an updated worker script that remembers the http request headers.
     19 // The updated worker reports back these headers to the test page.
     20 promise_test(async (t) => {
     21  const script = "resources/test-request-headers-worker.py";
     22  const scope = "resources/";
     23 
     24  // Register the service worker.
     25  await service_worker_unregister(t, scope);
     26  const registration = await navigator.serviceWorker.register(
     27      script, {scope, updateViaCache: 'none'});
     28  await wait_for_state(t, registration.installing, 'activated');
     29 
     30  // Do an update.
     31  await registration.update();
     32 
     33  // Ask the new worker what the request headers were.
     34  const newWorker = registration.installing;
     35  const sawMessage = new Promise((resolve) => {
     36    navigator.serviceWorker.onmessage = (event) => {
     37      resolve(event.data);
     38    };
     39  });
     40  newWorker.postMessage('getHeaders');
     41  const result = await sawMessage;
     42 
     43  // Test the result.
     44  assert_equals(result['service-worker'], 'script');
     45  assert_equals(result['if-none-match'], 'etag');
     46 }, 'headers in no-cache mode');
     47 
     48 </script>