summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/client-hints/critical-ch/resources
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/client-hints/critical-ch/resources
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/client-hints/critical-ch/resources')
-rw-r--r--testing/web-platform/tests/client-hints/critical-ch/resources/echo-critical-hint.py52
-rw-r--r--testing/web-platform/tests/client-hints/critical-ch/resources/redirect-critical-hint.py14
-rw-r--r--testing/web-platform/tests/client-hints/critical-ch/resources/util.js16
3 files changed, 82 insertions, 0 deletions
diff --git a/testing/web-platform/tests/client-hints/critical-ch/resources/echo-critical-hint.py b/testing/web-platform/tests/client-hints/critical-ch/resources/echo-critical-hint.py
new file mode 100644
index 0000000000..a5c5160f75
--- /dev/null
+++ b/testing/web-platform/tests/client-hints/critical-ch/resources/echo-critical-hint.py
@@ -0,0 +1,52 @@
+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"*")
+
+ accept = b"sec-ch-device-memory,device-memory"
+ if(request.GET.first(b"multiple", None) is not None):
+ for accept_part in accept.split(b","):
+ response.headers.append(b"Accept-CH", accept_part)
+ else:
+ response.headers.append(b"Accept-CH", accept)
+
+ critical = b"sec-ch-device-memory,device-memory"
+ if(request.GET.first(b"mismatch", None) is not None):
+ critical = b"sec-ch-viewport-width,viewport-width"
+
+ if(request.GET.first(b"multiple", None) is not None):
+ for critical_part in critical.split(b","):
+ response.headers.append(b"Critical-CH", critical_part)
+ else:
+ response.headers.append(b"Critical-CH", critical)
+
+ 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"
+
+ token = request.GET.first(b"token", None)
+ if(token is not None):
+ with request.server.stash.lock:
+ count = request.server.stash.take(token)
+ if(count == None):
+ count = 1
+ else:
+ count += 1
+ request.server.stash.put(token, count)
+ result = str(count)
+
+ if b"sec-ch-viewport-width" in request.headers and b"viewport-width" in request.headers:
+ result = "MISMATCH"
+
+ response.content = "<script>(window.opener || window.top).postMessage('{0}', '*')</script>".format(result)
diff --git a/testing/web-platform/tests/client-hints/critical-ch/resources/redirect-critical-hint.py b/testing/web-platform/tests/client-hints/critical-ch/resources/redirect-critical-hint.py
new file mode 100644
index 0000000000..77b8652e20
--- /dev/null
+++ b/testing/web-platform/tests/client-hints/critical-ch/resources/redirect-critical-hint.py
@@ -0,0 +1,14 @@
+def main(request, response):
+ """
+ Simple handler that redirects to echo-critical-hint.py.
+ """
+
+ response.status = 302
+ location = request.GET.first(b"location")
+ response.headers.set(b"Location", location)
+ response.headers.set(b"Access-Control-Allow-Origin", b"*")
+ if(request.GET.first(b"critical", None) is not None):
+ hints = b"sec-ch-dpr,dpr"
+ response.headers.append(b"Accept-CH", hints)
+ response.headers.append(b"Critical-CH", hints)
+
diff --git a/testing/web-platform/tests/client-hints/critical-ch/resources/util.js b/testing/web-platform/tests/client-hints/critical-ch/resources/util.js
new file mode 100644
index 0000000000..36800f1e4f
--- /dev/null
+++ b/testing/web-platform/tests/client-hints/critical-ch/resources/util.js
@@ -0,0 +1,16 @@
+ECHO_URL = "resources/echo-critical-hint.py"
+REDIRECT_URL = "resources/redirect-critical-hint.py"
+
+message_listener = (t, message) =>
+ (e) => {
+ t.step(()=>{assert_equals(e.data, message)});
+ t.done();
+ }
+
+make_message_test = (url, message) =>
+ (t) => {
+ popup_window = window.open("/common/blank.html");
+ assert_not_equals(popup_window, null, "Popup windows not allowed?");
+ window.addEventListener('message', message_listener(t, message));
+ popup_window.location = url;
+ }