tor-browser

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

next-hop-protocol.https.html (2109B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>Service Worker: Verify nextHopProtocol is set correctly</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 
      9 async function getNextHopProtocol(frame, url) {
     10  let final_url = new URL(url, self.location).href;
     11  await frame.contentWindow.fetch(final_url).then(r => r.text());
     12  let entryList = frame.contentWindow.performance.getEntriesByName(final_url);
     13  let entry = entryList[entryList.length - 1];
     14  return entry.nextHopProtocol;
     15 }
     16 
     17 async function runTest(t, base_url, expected_protocol) {
     18  const scope = 'resources/empty.html?next-hop-protocol';
     19  const script = 'resources/fetch-rewrite-worker.js';
     20  let frame;
     21 
     22  const registration =
     23      await service_worker_unregister_and_register(t, script, scope);
     24  t.add_cleanup(async _ => registration.unregister());
     25  await wait_for_state(t, registration.installing, 'activated');
     26  frame = await with_iframe(scope);
     27  t.add_cleanup(_ => frame.remove());
     28 
     29  assert_equals(await getNextHopProtocol(frame, `${base_url}?generate-png`),
     30                '', 'nextHopProtocol is not set on synthetic response');
     31  assert_equals(await getNextHopProtocol(frame, `${base_url}?ignore`),
     32                expected_protocol, 'nextHopProtocol is set on fallback');
     33  assert_equals(await getNextHopProtocol(frame, `${base_url}`),
     34                expected_protocol, 'nextHopProtocol is set on pass-through');
     35  assert_equals(await getNextHopProtocol(frame, `${base_url}?cache`),
     36                expected_protocol, 'nextHopProtocol is set on cached response');
     37 }
     38 
     39 promise_test(async (t) => {
     40  return runTest(t, 'resources/empty.js', 'http/1.1');
     41 }, 'nextHopProtocol reports H1 correctly when routed via a service worker.');
     42 
     43 // This may be expected to fail if the WPT infrastructure does not fully
     44 // support H2 protocol testing yet.
     45 promise_test(async (t) => {
     46  return runTest(t, 'resources/empty.h2.js', 'h2');
     47 }, 'nextHopProtocol reports H2 correctly when routed via a service worker.');
     48 
     49 </script>