tor-browser

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

claim-worker-fetch.https.html (3273B)


      1 <!doctype html>
      2 <meta charset=utf-8>
      3 <title></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 <body>
      8 <script>
      9 
     10 promise_test((t) => {
     11  return runTest(t, 'resources/claim-worker-fetch-iframe.html');
     12 }, 'fetch() in Worker should be intercepted after the client is claimed.');
     13 
     14 promise_test((t) => {
     15  return runTest(t, 'resources/claim-nested-worker-fetch-iframe.html');
     16 }, 'fetch() in nested Worker should be intercepted after the client is claimed.');
     17 
     18 promise_test((t) => {
     19  return runTest(t, 'resources/claim-blob-url-worker-fetch-iframe.html');
     20 }, 'fetch() in blob URL Worker should be intercepted after the client is claimed.');
     21 
     22 promise_test((t) => {
     23  return runTest(t, 'resources/nested-blob-url-workers.html');
     24 }, 'fetch() in nested blob URL Worker created from a blob URL Worker should be intercepted after the client is claimed.');
     25 
     26 promise_test((t) => {
     27  return runTest(t, 'resources/nested-worker-created-from-blob-url-worker.html');
     28 }, 'fetch() in nested Worker created from a blob URL Worker should be intercepted after the client is claimed.');
     29 
     30 promise_test((t) => {
     31  return runTest(t, 'resources/nested-blob-url-worker-created-from-worker.html');
     32 }, 'fetch() in nested blob URL Worker created from a Worker should be intercepted after the client is claimed.');
     33 
     34 async function runTest(t, iframe_url) {
     35  const resource = 'simple.txt';
     36  const scope = 'resources/';
     37  const script = 'resources/claim-worker.js';
     38 
     39  // Create the test iframe with a dedicated worker.
     40  const frame = await with_iframe(iframe_url);
     41  t.add_cleanup(_ => frame.remove());
     42 
     43  // Check the controller and test with fetch in the worker.
     44  assert_equals(frame.contentWindow.navigator.controller,
     45                undefined, 'Should have no controller.');
     46  {
     47    const response_text = await frame.contentWindow.fetch_in_worker(resource);
     48    assert_equals(response_text, 'a simple text file\n',
     49                  'fetch() should not be intercepted.');
     50  }
     51 
     52  // Register a service worker.
     53  const reg = await service_worker_unregister_and_register(t, script, scope);
     54  t.add_cleanup(_ => reg.unregister());
     55  await wait_for_state(t, reg.installing, 'activated');
     56 
     57  // Let the service worker claim the iframe and the worker.
     58  const channel = new MessageChannel();
     59  const saw_message = new Promise(function(resolve) {
     60    channel.port1.onmessage = t.step_func(function(e) {
     61      assert_equals(e.data, 'PASS', 'Worker call to claim() should fulfill.');
     62      resolve();
     63    });
     64  });
     65  reg.active.postMessage({port: channel.port2}, [channel.port2]);
     66  await saw_message;
     67 
     68  // Check the controller and test with fetch in the worker.
     69  const reg2 =
     70    await frame.contentWindow.navigator.serviceWorker.getRegistration(scope);
     71  assert_equals(frame.contentWindow.navigator.serviceWorker.controller,
     72                reg2.active, 'Test iframe should be claimed.');
     73 
     74  {
     75    // TODO(horo): Check the worker's navigator.seviceWorker.controller.
     76    const response_text = await frame.contentWindow.fetch_in_worker(resource);
     77    assert_equals(response_text, 'Intercepted!',
     78                  'fetch() in the worker should be intercepted.');
     79  }
     80 }
     81 
     82 </script>
     83 </body>