tor-browser

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

partitioned-matchAll.tentative.https.html (2444B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8"/>
      3 <title>Service Worker: Partitioned Service Workers</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 src="/common/get-host-info.sub.js"></script>
      8 <script src="resources/partitioned-utils.js"></script>
      9 
     10 <body>
     11 This test loads a SW in a first-party context and gets has the SW send
     12 its list of clients from client.matchAll(). It does the same thing for the
     13 SW in a third-party context as well and confirms that each SW see's the correct
     14 clients and that they don't see eachother's clients.
     15 
     16 <script>
     17 promise_test(async t => {
     18 
     19  const script = './resources/partitioned-storage-sw.js'
     20  const scope = './resources/partitioned-'
     21 
     22  // Add service worker to this 1P context.
     23  const reg = await service_worker_unregister_and_register(t, script, scope);
     24  t.add_cleanup(() => reg.unregister());
     25  await wait_for_state(t, reg.installing, 'activated');
     26 
     27  // Register the message listener.
     28  self.addEventListener('message', messageEventHandler);
     29 
     30  // Create a third-party iframe that will send us its SW's clients.
     31  const third_party_iframe_url = new URL(
     32    './resources/partitioned-service-worker-third-party-iframe-matchAll.html',
     33    get_host_info().HTTPS_ORIGIN + self.location.pathname);
     34 
     35  const {urls_list: frame_3p_urls_list} = await loadAndReturnSwData(t,
     36    third_party_iframe_url, 'window');
     37 
     38  // Register a listener on the service worker container and then forward to
     39  // the self event listener so we can reuse the existing message promise
     40  // function.
     41  navigator.serviceWorker.addEventListener('message', evt => {
     42    self.postMessage(evt.data, '*');
     43  });
     44 
     45  const frame_1p_data_promise = makeMessagePromise();
     46 
     47  reg.active.postMessage({type: "get-match-all"});
     48 
     49  const {urls_list: frame_1p_urls_list} = await frame_1p_data_promise;
     50 
     51  // If partitioning is working, the 1p and 3p SWs should only see a single
     52  // client.
     53  assert_equals(frame_3p_urls_list.length, 1);
     54  assert_equals(frame_1p_urls_list.length, 1);
     55  // Confirm that the expected URL was seen by each.
     56  assert_equals(frame_3p_urls_list[0], third_party_iframe_url.toString(),
     57    "3p SW has the correct client url.");
     58  assert_equals(frame_1p_urls_list[0], window.location.href,
     59    "1P SW has the correct client url.");
     60 }, "ServiceWorker's matchAll() is partitioned");
     61 
     62 
     63 </script>
     64 
     65 </body>