tor-browser

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

static-router-request-destination.https.html (2568B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>
      4  Static Router: routers are evaluated with the request desitnation condition.
      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_DESTINATION_SCRIPT = 'condition-request-destination-script-network';
     16 const FRAME_SRC = 'resources/direct.html';
     17 const SCRIPT_SRC = 'direct.js';
     18 const STYLE_SRC = 'direct.txt';
     19 
     20 const appendScript = async (iwin, src) => {
     21  const promise = new Promise(resolve => {
     22    const script = iwin.document.createElement('script');
     23    script.src = src;
     24    iwin.document.body.appendChild(script);
     25    script.onload = () => {
     26      resolve(script);
     27    };
     28  });
     29 
     30  return promise;
     31 };
     32 
     33 const appendCSS = async (iwin, src) => {
     34  const promise = new Promise(resolve => {
     35    const link = iwin.document.createElement('link');
     36    link.rel = 'stylesheet';
     37    link.href = src;
     38    iwin.document.head.appendChild(link);
     39    link.onload = () => {
     40      resolve(link);
     41    };
     42  });
     43 
     44  return promise;
     45 };
     46 
     47 promise_test(async t => {
     48  const worker = await registerAndActivate(t, ROUTER_KEY_DESTINATION_SCRIPT);
     49  const iframe = await createIframe(t, FRAME_SRC);
     50 
     51  let info = await get_info_from_worker(worker);
     52  assert_equals(info.requests.length, 1);
     53  assert_equals(info.requests[0].destination, 'iframe');
     54 
     55  // JavaScript is not handled by fetch handler.
     56  await appendScript(iframe.contentWindow, SCRIPT_SRC);
     57  assert_equals(iframe.contentWindow.router_condition_request_destination_script, true);
     58  info = await get_info_from_worker(worker);
     59  assert_equals(info.requests.length, 1);
     60 }, 'Subreosurce load matched with the requestMethod script condition');
     61 
     62 promise_test(async t => {
     63  const worker = await registerAndActivate(t, ROUTER_KEY_DESTINATION_SCRIPT);
     64  const iframe = await createIframe(t, FRAME_SRC);
     65 
     66  let info = await get_info_from_worker(worker);
     67  assert_equals(info.requests.length, 1);
     68  assert_equals(info.requests[0].destination, 'iframe');
     69 
     70  // Stylesheet is not handled by fetch handler.
     71  await appendCSS(iframe.contentWindow, STYLE_SRC);
     72  info = await get_info_from_worker(worker);
     73  assert_equals(info.requests.length, 2);
     74  assert_equals(info.requests[1].destination, 'style');
     75 }, 'Subreosurce load not matched with the requestMethod script condition');
     76 </script>
     77 </body>