summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/service-workers/service-worker/next-hop-protocol.https.html
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/service-workers/service-worker/next-hop-protocol.https.html')
-rw-r--r--testing/web-platform/tests/service-workers/service-worker/next-hop-protocol.https.html49
1 files changed, 49 insertions, 0 deletions
diff --git a/testing/web-platform/tests/service-workers/service-worker/next-hop-protocol.https.html b/testing/web-platform/tests/service-workers/service-worker/next-hop-protocol.https.html
new file mode 100644
index 0000000000..7a907438d5
--- /dev/null
+++ b/testing/web-platform/tests/service-workers/service-worker/next-hop-protocol.https.html
@@ -0,0 +1,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>