diff options
Diffstat (limited to 'testing/web-platform/tests/client-hints/service-workers')
26 files changed, 164 insertions, 0 deletions
diff --git a/testing/web-platform/tests/client-hints/service-workers/critical-ch/echo-hint-in-html.py b/testing/web-platform/tests/client-hints/service-workers/critical-ch/echo-hint-in-html.py new file mode 100644 index 0000000000..87a1afed7c --- /dev/null +++ b/testing/web-platform/tests/client-hints/service-workers/critical-ch/echo-hint-in-html.py @@ -0,0 +1,24 @@ +import sys + +def main(request, response): + """ + Simple handler that sets a response header based on which client hint + request headers were received. + """ + + response.headers.append(b"Content-Type", b"text/html; charset=UTF-8") + response.headers.append(b"Access-Control-Allow-Origin", b"*") + response.headers.append(b"Access-Control-Allow-Headers", b"*") + response.headers.append(b"Access-Control-Expose-Headers", b"*") + + response.headers.append(b"Cache-Control", b"no-store") + + response.headers.append(b"Accept-CH", b"sec-ch-device-memory,device-memory"); + response.headers.append(b"Critical-CH", b"sec-ch-device-memory,device-memory"); + + result = "FAIL" + + if b"sec-ch-device-memory" in request.headers and b"device-memory" in request.headers: + result = "PASS" + + response.content = result diff --git a/testing/web-platform/tests/client-hints/service-workers/critical-ch/foo.html b/testing/web-platform/tests/client-hints/service-workers/critical-ch/foo.html new file mode 100644 index 0000000000..ba578e48b1 --- /dev/null +++ b/testing/web-platform/tests/client-hints/service-workers/critical-ch/foo.html @@ -0,0 +1 @@ +BAR diff --git a/testing/web-platform/tests/client-hints/service-workers/critical-ch/foo.html.headers b/testing/web-platform/tests/client-hints/service-workers/critical-ch/foo.html.headers new file mode 100644 index 0000000000..56b489178e --- /dev/null +++ b/testing/web-platform/tests/client-hints/service-workers/critical-ch/foo.html.headers @@ -0,0 +1,2 @@ +Accept-CH: sec-ch-device-memory, device-memory +Critical-CH: sec-ch-device-memory, device-memory diff --git a/testing/web-platform/tests/client-hints/service-workers/critical-ch/intercept-request.js b/testing/web-platform/tests/client-hints/service-workers/critical-ch/intercept-request.js new file mode 100644 index 0000000000..4d27ceadcc --- /dev/null +++ b/testing/web-platform/tests/client-hints/service-workers/critical-ch/intercept-request.js @@ -0,0 +1,6 @@ +self.addEventListener('fetch', (event) => { + result="FAIL"; + if(event.request.headers.has("sec-ch-device-memory") && event.request.headers.has("device-memory")) + result="PASS"; + event.respondWith(new Response(result)); +}); diff --git a/testing/web-platform/tests/client-hints/service-workers/critical-ch/navigation-preload.js b/testing/web-platform/tests/client-hints/service-workers/critical-ch/navigation-preload.js new file mode 100644 index 0000000000..d8a38ee7de --- /dev/null +++ b/testing/web-platform/tests/client-hints/service-workers/critical-ch/navigation-preload.js @@ -0,0 +1,2 @@ +self.addEventListener('activate', () => self.registration.navigationPreload.enable()); +self.addEventListener('fetch', (event) => event.respondWith(event.preloadResponse)); diff --git a/testing/web-platform/tests/client-hints/service-workers/critical-ch/new-request.js b/testing/web-platform/tests/client-hints/service-workers/critical-ch/new-request.js new file mode 100644 index 0000000000..395c77183e --- /dev/null +++ b/testing/web-platform/tests/client-hints/service-workers/critical-ch/new-request.js @@ -0,0 +1,3 @@ +self.addEventListener('fetch', (event) => { + event.respondWith(fetch("/client-hints/service-workers/resources/echo-hint-in-html.py")) +}); diff --git a/testing/web-platform/tests/client-hints/service-workers/critical-ch/passthrough-request.js b/testing/web-platform/tests/client-hints/service-workers/critical-ch/passthrough-request.js new file mode 100644 index 0000000000..5541c5eb55 --- /dev/null +++ b/testing/web-platform/tests/client-hints/service-workers/critical-ch/passthrough-request.js @@ -0,0 +1 @@ +self.addEventListener('fetch', (event) => fetch(event.request)); diff --git a/testing/web-platform/tests/client-hints/service-workers/intercept-request-critical.https.window.js b/testing/web-platform/tests/client-hints/service-workers/intercept-request-critical.https.window.js new file mode 100644 index 0000000000..079b9fd9ba --- /dev/null +++ b/testing/web-platform/tests/client-hints/service-workers/intercept-request-critical.https.window.js @@ -0,0 +1,5 @@ +// META: script=/service-workers/service-worker/resources/test-helpers.sub.js +// META: script=resources/util.js +promise_test((t) => + ch_sw_test(t, 'critical-ch/intercept-request.js', 'critical-ch/foo.html', 'FAIL'), + "Service workers succsefully receives hints from request"); diff --git a/testing/web-platform/tests/client-hints/service-workers/intercept-request.https.html b/testing/web-platform/tests/client-hints/service-workers/intercept-request.https.html new file mode 100644 index 0000000000..00e024b7b6 --- /dev/null +++ b/testing/web-platform/tests/client-hints/service-workers/intercept-request.https.html @@ -0,0 +1,11 @@ +<!DOCTYPE html> +<title>Client Hint/Service Worker interaction</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script> +<script src="resources/util.js"></script> +<script> +promise_test((t) => + ch_sw_test(t, 'resources/intercept-request.js', 'resources/foo.html', 'PASS'), + "Service workers succsefully receives hints from request"); +</script> diff --git a/testing/web-platform/tests/client-hints/service-workers/intercept-request.https.html.headers b/testing/web-platform/tests/client-hints/service-workers/intercept-request.https.html.headers new file mode 100644 index 0000000000..546ac83d4b --- /dev/null +++ b/testing/web-platform/tests/client-hints/service-workers/intercept-request.https.html.headers @@ -0,0 +1 @@ +Accept-CH: sec-ch-device-memory, device-memory diff --git a/testing/web-platform/tests/client-hints/service-workers/navigation-preload-critical.https.window.js b/testing/web-platform/tests/client-hints/service-workers/navigation-preload-critical.https.window.js new file mode 100644 index 0000000000..5d05ab3c53 --- /dev/null +++ b/testing/web-platform/tests/client-hints/service-workers/navigation-preload-critical.https.window.js @@ -0,0 +1,5 @@ +//META: script=/service-workers/service-worker/resources/test-helpers.sub.js +//META: script=resources/util.js +promise_test((t) => + ch_sw_test(t, 'critical-ch/navigation-preload.js', 'critical-ch/echo-hint-in-html.py', 'PASS'), + "Service worker successfully passes hints through to new fetch"); diff --git a/testing/web-platform/tests/client-hints/service-workers/navigation-preload.https.html b/testing/web-platform/tests/client-hints/service-workers/navigation-preload.https.html new file mode 100644 index 0000000000..a952e1e406 --- /dev/null +++ b/testing/web-platform/tests/client-hints/service-workers/navigation-preload.https.html @@ -0,0 +1,11 @@ +<!DOCTYPE html> +<title>Client Hint/Service Worker interaction</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script> +<script src="resources/util.js"></script> +<script> +promise_test((t) => + ch_sw_test(t, 'resources/navigation-preload.js', 'resources/echo-hint-in-html.py', 'PASS'), + "Service worker successfully passes hints through to new fetch"); +</script> diff --git a/testing/web-platform/tests/client-hints/service-workers/navigation-preload.https.html.headers b/testing/web-platform/tests/client-hints/service-workers/navigation-preload.https.html.headers new file mode 100644 index 0000000000..546ac83d4b --- /dev/null +++ b/testing/web-platform/tests/client-hints/service-workers/navigation-preload.https.html.headers @@ -0,0 +1 @@ +Accept-CH: sec-ch-device-memory, device-memory diff --git a/testing/web-platform/tests/client-hints/service-workers/new-request-critical.https.window.js b/testing/web-platform/tests/client-hints/service-workers/new-request-critical.https.window.js new file mode 100644 index 0000000000..9dee11a934 --- /dev/null +++ b/testing/web-platform/tests/client-hints/service-workers/new-request-critical.https.window.js @@ -0,0 +1,5 @@ +//META: script=/service-workers/service-worker/resources/test-helpers.sub.js +//META: script=resources/util.js +promise_test((t) => + ch_sw_test(t, 'critical-ch/new-request.js', 'critical-ch/foo.html', 'FAIL'), + "Service worker does NOT generate client hints in a new request"); diff --git a/testing/web-platform/tests/client-hints/service-workers/new-request.https.html b/testing/web-platform/tests/client-hints/service-workers/new-request.https.html new file mode 100644 index 0000000000..006ec24e8b --- /dev/null +++ b/testing/web-platform/tests/client-hints/service-workers/new-request.https.html @@ -0,0 +1,11 @@ +<!DOCTYPE html> +<title>Client Hint/Service Worker interaction</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script> +<script src="resources/util.js"></script> +<script> +promise_test((t) => + ch_sw_test(t, 'resources/new-request.js', 'resources/foo.html', 'FAIL'), + "Service worker does NOT generate client hints in a new request"); +</script> diff --git a/testing/web-platform/tests/client-hints/service-workers/new-request.https.html.headers b/testing/web-platform/tests/client-hints/service-workers/new-request.https.html.headers new file mode 100644 index 0000000000..546ac83d4b --- /dev/null +++ b/testing/web-platform/tests/client-hints/service-workers/new-request.https.html.headers @@ -0,0 +1 @@ +Accept-CH: sec-ch-device-memory, device-memory diff --git a/testing/web-platform/tests/client-hints/service-workers/passthrough-request-critical.https.window.js b/testing/web-platform/tests/client-hints/service-workers/passthrough-request-critical.https.window.js new file mode 100644 index 0000000000..4d59f5f478 --- /dev/null +++ b/testing/web-platform/tests/client-hints/service-workers/passthrough-request-critical.https.window.js @@ -0,0 +1,5 @@ +//META: script=/service-workers/service-worker/resources/test-helpers.sub.js +//META: script=resources/util.js +promise_test((t) => + ch_sw_test(t, 'critical-ch/passthrough-request.js', 'critical-ch/echo-hint-in-html.py', 'PASS'), + "Service worker successfully passes hints through to new fetch"); diff --git a/testing/web-platform/tests/client-hints/service-workers/passthrough-request.https.html b/testing/web-platform/tests/client-hints/service-workers/passthrough-request.https.html new file mode 100644 index 0000000000..8dca424098 --- /dev/null +++ b/testing/web-platform/tests/client-hints/service-workers/passthrough-request.https.html @@ -0,0 +1,11 @@ +<!DOCTYPE html> +<title>Client Hint/Service Worker interaction</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script> +<script src="resources/util.js"></script> +<script> +promise_test((t) => + ch_sw_test(t, 'resources/passthrough-request.js', 'resources/echo-hint-in-html.py', 'PASS'), + "Service worker successfully passes hints through to new fetch"); +</script> diff --git a/testing/web-platform/tests/client-hints/service-workers/passthrough-request.https.html.headers b/testing/web-platform/tests/client-hints/service-workers/passthrough-request.https.html.headers new file mode 100644 index 0000000000..546ac83d4b --- /dev/null +++ b/testing/web-platform/tests/client-hints/service-workers/passthrough-request.https.html.headers @@ -0,0 +1 @@ +Accept-CH: sec-ch-device-memory, device-memory diff --git a/testing/web-platform/tests/client-hints/service-workers/resources/echo-hint-in-html.py b/testing/web-platform/tests/client-hints/service-workers/resources/echo-hint-in-html.py new file mode 100644 index 0000000000..e029b5433b --- /dev/null +++ b/testing/web-platform/tests/client-hints/service-workers/resources/echo-hint-in-html.py @@ -0,0 +1,21 @@ +import sys + +def main(request, response): + """ + Simple handler that sets a response header based on which client hint + request headers were received. + """ + + response.headers.append(b"Content-Type", b"text/html; charset=UTF-8") + response.headers.append(b"Access-Control-Allow-Origin", b"*") + response.headers.append(b"Access-Control-Allow-Headers", b"*") + response.headers.append(b"Access-Control-Expose-Headers", b"*") + + response.headers.append(b"Cache-Control", b"no-store") + + result = "FAIL" + + if b"sec-ch-device-memory" in request.headers and b"device-memory" in request.headers: + result = "PASS" + + response.content = result diff --git a/testing/web-platform/tests/client-hints/service-workers/resources/foo.html b/testing/web-platform/tests/client-hints/service-workers/resources/foo.html new file mode 100644 index 0000000000..ba578e48b1 --- /dev/null +++ b/testing/web-platform/tests/client-hints/service-workers/resources/foo.html @@ -0,0 +1 @@ +BAR diff --git a/testing/web-platform/tests/client-hints/service-workers/resources/intercept-request.js b/testing/web-platform/tests/client-hints/service-workers/resources/intercept-request.js new file mode 100644 index 0000000000..4d27ceadcc --- /dev/null +++ b/testing/web-platform/tests/client-hints/service-workers/resources/intercept-request.js @@ -0,0 +1,6 @@ +self.addEventListener('fetch', (event) => { + result="FAIL"; + if(event.request.headers.has("sec-ch-device-memory") && event.request.headers.has("device-memory")) + result="PASS"; + event.respondWith(new Response(result)); +}); diff --git a/testing/web-platform/tests/client-hints/service-workers/resources/navigation-preload.js b/testing/web-platform/tests/client-hints/service-workers/resources/navigation-preload.js new file mode 100644 index 0000000000..d8a38ee7de --- /dev/null +++ b/testing/web-platform/tests/client-hints/service-workers/resources/navigation-preload.js @@ -0,0 +1,2 @@ +self.addEventListener('activate', () => self.registration.navigationPreload.enable()); +self.addEventListener('fetch', (event) => event.respondWith(event.preloadResponse)); diff --git a/testing/web-platform/tests/client-hints/service-workers/resources/new-request.js b/testing/web-platform/tests/client-hints/service-workers/resources/new-request.js new file mode 100644 index 0000000000..395c77183e --- /dev/null +++ b/testing/web-platform/tests/client-hints/service-workers/resources/new-request.js @@ -0,0 +1,3 @@ +self.addEventListener('fetch', (event) => { + event.respondWith(fetch("/client-hints/service-workers/resources/echo-hint-in-html.py")) +}); diff --git a/testing/web-platform/tests/client-hints/service-workers/resources/passthrough-request.js b/testing/web-platform/tests/client-hints/service-workers/resources/passthrough-request.js new file mode 100644 index 0000000000..5541c5eb55 --- /dev/null +++ b/testing/web-platform/tests/client-hints/service-workers/resources/passthrough-request.js @@ -0,0 +1 @@ +self.addEventListener('fetch', (event) => fetch(event.request)); diff --git a/testing/web-platform/tests/client-hints/service-workers/resources/util.js b/testing/web-platform/tests/client-hints/service-workers/resources/util.js new file mode 100644 index 0000000000..d9b8f3f4d9 --- /dev/null +++ b/testing/web-platform/tests/client-hints/service-workers/resources/util.js @@ -0,0 +1,23 @@ +async function ch_sw_test(t, worker, url, response) { + r = await service_worker_unregister_and_register(t, worker, url); + await wait_for_state(t, r.installing, 'activated') + var popup_window = window.open("/common/blank.html"); + assert_not_equals(popup_window, null, "Popup windows not allowed?"); + + t.add_cleanup(async _=>{ + popup_window.close(); + await r.unregister(); + }); + + popup_load = new Promise((resolve, reject) => { + popup_window.addEventListener('load', t.step_func((e) => { + if(popup_window.location.pathname != "/blank.html") { + assert_equals(popup_window.document.body.textContent, response); + resolve(); + } + })) + }); + + popup_window.location = url; + await popup_load; +} |