summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/client-hints/critical-ch
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/critical-ch
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/critical-ch')
-rw-r--r--testing/web-platform/tests/client-hints/critical-ch/iframe.https.window.js8
-rw-r--r--testing/web-platform/tests/client-hints/critical-ch/mis-matched-count.https.window.js4
-rw-r--r--testing/web-platform/tests/client-hints/critical-ch/mis-matched.https.window.js3
-rw-r--r--testing/web-platform/tests/client-hints/critical-ch/navigation.https.window.js3
-rw-r--r--testing/web-platform/tests/client-hints/critical-ch/non-secure.http.window.js3
-rw-r--r--testing/web-platform/tests/client-hints/critical-ch/request-count.https.window.js4
-rw-r--r--testing/web-platform/tests/client-hints/critical-ch/resources/echo-critical-hint.py43
-rw-r--r--testing/web-platform/tests/client-hints/critical-ch/resources/util.js15
-rw-r--r--testing/web-platform/tests/client-hints/critical-ch/subresource.https.window.js10
-rw-r--r--testing/web-platform/tests/client-hints/critical-ch/unsafe-method.https.window.js23
10 files changed, 116 insertions, 0 deletions
diff --git a/testing/web-platform/tests/client-hints/critical-ch/iframe.https.window.js b/testing/web-platform/tests/client-hints/critical-ch/iframe.https.window.js
new file mode 100644
index 0000000000..f4dd295208
--- /dev/null
+++ b/testing/web-platform/tests/client-hints/critical-ch/iframe.https.window.js
@@ -0,0 +1,8 @@
+// META: script=resources/util.js
+
+async_test((t) => {
+ var iframe = document.createElement("iframe");
+ iframe.src = ECHO_URL;
+ document.body.appendChild(iframe);
+ iframe.contentWindow.addEventListener('message', message_listener(t, "FAIL"));
+}, "Critical-CH iframe");
diff --git a/testing/web-platform/tests/client-hints/critical-ch/mis-matched-count.https.window.js b/testing/web-platform/tests/client-hints/critical-ch/mis-matched-count.https.window.js
new file mode 100644
index 0000000000..54bd667897
--- /dev/null
+++ b/testing/web-platform/tests/client-hints/critical-ch/mis-matched-count.https.window.js
@@ -0,0 +1,4 @@
+// META: script=resources/util.js
+// META: script=/common/utils.js
+
+async_test(make_message_test(ECHO_URL+"?mismatch=true&token="+token(), "1"), "Critical-CH no restart on mismatched hints")
diff --git a/testing/web-platform/tests/client-hints/critical-ch/mis-matched.https.window.js b/testing/web-platform/tests/client-hints/critical-ch/mis-matched.https.window.js
new file mode 100644
index 0000000000..9476640b35
--- /dev/null
+++ b/testing/web-platform/tests/client-hints/critical-ch/mis-matched.https.window.js
@@ -0,0 +1,3 @@
+// META: script=resources/util.js
+
+async_test(make_message_test(ECHO_URL+"?mismatch=true", "FAIL"), "Critical-CH Mis-matched hints")
diff --git a/testing/web-platform/tests/client-hints/critical-ch/navigation.https.window.js b/testing/web-platform/tests/client-hints/critical-ch/navigation.https.window.js
new file mode 100644
index 0000000000..549b321443
--- /dev/null
+++ b/testing/web-platform/tests/client-hints/critical-ch/navigation.https.window.js
@@ -0,0 +1,3 @@
+// META: script=resources/util.js
+
+async_test(make_message_test(ECHO_URL, "PASS"), "Critical-CH navigation")
diff --git a/testing/web-platform/tests/client-hints/critical-ch/non-secure.http.window.js b/testing/web-platform/tests/client-hints/critical-ch/non-secure.http.window.js
new file mode 100644
index 0000000000..cdd7924398
--- /dev/null
+++ b/testing/web-platform/tests/client-hints/critical-ch/non-secure.http.window.js
@@ -0,0 +1,3 @@
+// META: script=resources/util.js
+
+async_test(make_message_test(ECHO_URL, "FAIL"), "Critical-CH navigation non-secure")
diff --git a/testing/web-platform/tests/client-hints/critical-ch/request-count.https.window.js b/testing/web-platform/tests/client-hints/critical-ch/request-count.https.window.js
new file mode 100644
index 0000000000..b337340509
--- /dev/null
+++ b/testing/web-platform/tests/client-hints/critical-ch/request-count.https.window.js
@@ -0,0 +1,4 @@
+// META: script=resources/util.js
+// META: script=/common/utils.js
+
+async_test(make_message_test(ECHO_URL+"?token="+token(), "2"), "Critical-CH navigation restart")
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..e4e77ad2a9
--- /dev/null
+++ b/testing/web-platform/tests/client-hints/critical-ch/resources/echo-critical-hint.py
@@ -0,0 +1,43 @@
+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"Accept-CH", b"sec-ch-device-memory,device-memory")
+
+ 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"
+
+ 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.postMessage('{0}', '*')</script>".format(result)
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..7471d9022e
--- /dev/null
+++ b/testing/web-platform/tests/client-hints/critical-ch/resources/util.js
@@ -0,0 +1,15 @@
+ECHO_URL = "resources/echo-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?");
+ popup_window.addEventListener('message', message_listener(t, message));
+ popup_window.location = url;
+ }
diff --git a/testing/web-platform/tests/client-hints/critical-ch/subresource.https.window.js b/testing/web-platform/tests/client-hints/critical-ch/subresource.https.window.js
new file mode 100644
index 0000000000..f8112b628d
--- /dev/null
+++ b/testing/web-platform/tests/client-hints/critical-ch/subresource.https.window.js
@@ -0,0 +1,10 @@
+// META: script=resources/util.js
+// META: script=/common/utils.js
+
+promise_test(() =>
+ fetch("resources/echo-critical-hint.py")
+ .then((r) => r.text())
+ .then((r) => {
+ assert_true(r.includes("FAIL"));
+ })
+, "Critical-CH subresource fetch");
diff --git a/testing/web-platform/tests/client-hints/critical-ch/unsafe-method.https.window.js b/testing/web-platform/tests/client-hints/critical-ch/unsafe-method.https.window.js
new file mode 100644
index 0000000000..0eca0eb8e9
--- /dev/null
+++ b/testing/web-platform/tests/client-hints/critical-ch/unsafe-method.https.window.js
@@ -0,0 +1,23 @@
+async_test((t) => {
+ // This test requires a navigation with a non-safe (i.e. non-GET) HTTP
+ // response, which the Critical-CH spec says to ignore. The most
+ // "straight-forward" way to do this in JS is by making a form with an
+ // unsafe method (e.g. POST) method and submit it.
+
+ // Build the form DOM element
+ var form = document.createElement("form");
+ form.setAttribute("method", "post");
+ form.setAttribute("action", "resources/echo-critical-hint.py");
+ form.setAttribute("target", "popup"); //don't navigate away from the page running the test...
+ document.body.appendChild(form);
+
+ var popup_window = window.open("/common/blank.html", "popup");
+ assert_not_equals(popup_window, null, "Popup windows not allowed?");
+
+ popup_window.addEventListener('message', (e) => {
+ t.step(()=>{assert_equals(e.data, "FAIL")});
+ t.done();
+ });
+
+ form.submit();
+}, "Critical-CH unsafe method")