tor-browser

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

static-router-multiple-router-registrations.https.html (2338B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>
      4  Static Router: routers are registered multiple times.
      5 </title>
      6 <script src="/common/get-host-info.sub.js"></script>
      7 <script src="/resources/testharness.js"></script>
      8 <script src="/resources/testharnessreport.js"></script>
      9 <script src="/service-workers/service-worker/resources/test-helpers.sub.js">
     10 </script>
     11 <script src="resources/static-router-helpers.sub.js">
     12 </script>
     13 <body>
     14 <script>
     15 const ROUTER_KEY_MULTIPLE_RULES = 'multiple-router-rules';
     16 const ROUTER_KEY_1 = 'condition-urlpattern-string-source-network';
     17 const ROUTER_KEY_2 = 'condition-request-method-post-network';
     18 
     19 const REGISTERED_ROUTE_1 = 'resources/direct.txt';
     20 const REGISTERED_ROUTE_2 = 'resources/direct.html';
     21 const REGISTERED_ROUTE_3 = 'direct.py';
     22 
     23 promise_test(async t => {
     24  const worker = await registerAndActivate(t, ROUTER_KEY_MULTIPLE_RULES);
     25 
     26  // Matched with the first rule.
     27  const iframe = await createIframe(t, REGISTERED_ROUTE_1);
     28  assert_equals(iframe.contentWindow.document.body.innerText, "Network\n");
     29 
     30  // Matched with the second rule.
     31  const second_iframe = await createIframe(t, REGISTERED_ROUTE_2);
     32  assert_equals(second_iframe.contentWindow.document.body.innerText, "Here's a direct html from network.");
     33 
     34  const {requests} = await get_info_from_worker(worker);
     35  assert_equals(requests.length, 0);
     36 }, 'Main reosurce load matched with the service worker having multiple rules');
     37 
     38 promise_test(async t => {
     39  const worker = await registerAndActivate(t,
     40    `${ROUTER_KEY_1}&imported-sw-router-key=${ROUTER_KEY_2}`);
     41 
     42  // Matched with the first rule.
     43  const iframe = await createIframe(t, REGISTERED_ROUTE_1);
     44  assert_equals(iframe.contentWindow.document.body.innerText, "Network\n");
     45  let info = await get_info_from_worker(worker);
     46  assert_equals(info.requests.length, 0);
     47 
     48  // Matched with the second rule, which is registered in the service worker
     49  // loaded via `import` by the main script.
     50  const response = await iframe.contentWindow.fetch(REGISTERED_ROUTE_3, {method: 'POST'});
     51  assert_equals(response.status, 200);
     52  assert_equals(await response.text(), "Network with POST request");
     53  info = await get_info_from_worker(worker);
     54  assert_equals(info.requests.length, 0);
     55 }, 'Resource load matched with the rule registered in the imported service worker');
     56 </script>
     57 </body>