summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/service-workers/service-worker/next-hop-protocol.https.html
blob: 7a907438d5d9f0b3ba1e198e048ea0b2e86a2415 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<!DOCTYPE html>
<meta charset="utf-8">
<title>Service Worker: Verify nextHopProtocol is set correctly</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/test-helpers.sub.js"></script>
<script>

async function getNextHopProtocol(frame, url) {
  let final_url = new URL(url, self.location).href;
  await frame.contentWindow.fetch(final_url).then(r => r.text());
  let entryList = frame.contentWindow.performance.getEntriesByName(final_url);
  let entry = entryList[entryList.length - 1];
  return entry.nextHopProtocol;
}

async function runTest(t, base_url, expected_protocol) {
  const scope = 'resources/empty.html?next-hop-protocol';
  const script = 'resources/fetch-rewrite-worker.js';
  let frame;

  const registration =
      await service_worker_unregister_and_register(t, script, scope);
  t.add_cleanup(async _ => registration.unregister());
  await wait_for_state(t, registration.installing, 'activated');
  frame = await with_iframe(scope);
  t.add_cleanup(_ => frame.remove());

  assert_equals(await getNextHopProtocol(frame, `${base_url}?generate-png`),
                '', 'nextHopProtocol is not set on synthetic response');
  assert_equals(await getNextHopProtocol(frame, `${base_url}?ignore`),
                expected_protocol, 'nextHopProtocol is set on fallback');
  assert_equals(await getNextHopProtocol(frame, `${base_url}`),
                expected_protocol, 'nextHopProtocol is set on pass-through');
  assert_equals(await getNextHopProtocol(frame, `${base_url}?cache`),
                expected_protocol, 'nextHopProtocol is set on cached response');
}

promise_test(async (t) => {
  return runTest(t, 'resources/empty.js', 'http/1.1');
}, 'nextHopProtocol reports H1 correctly when routed via a service worker.');

// This may be expected to fail if the WPT infrastructure does not fully
// support H2 protocol testing yet.
promise_test(async (t) => {
  return runTest(t, 'resources/empty.h2.js', 'h2');
}, 'nextHopProtocol reports H2 correctly when routed via a service worker.');

</script>