summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/client-hints/service-workers/resources
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/client-hints/service-workers/resources
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/client-hints/service-workers/resources')
-rw-r--r--testing/web-platform/tests/client-hints/service-workers/resources/echo-hint-in-html.py21
-rw-r--r--testing/web-platform/tests/client-hints/service-workers/resources/foo.html1
-rw-r--r--testing/web-platform/tests/client-hints/service-workers/resources/intercept-request.js6
-rw-r--r--testing/web-platform/tests/client-hints/service-workers/resources/navigation-preload.js2
-rw-r--r--testing/web-platform/tests/client-hints/service-workers/resources/new-request.js3
-rw-r--r--testing/web-platform/tests/client-hints/service-workers/resources/passthrough-request.js1
-rw-r--r--testing/web-platform/tests/client-hints/service-workers/resources/util.js23
7 files changed, 57 insertions, 0 deletions
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;
+}