diff options
Diffstat (limited to 'testing/web-platform/tests/client-hints/critical-ch')
27 files changed, 258 insertions, 0 deletions
diff --git a/testing/web-platform/tests/client-hints/critical-ch/critical-ch.navigation-timing.no-restart.https.html b/testing/web-platform/tests/client-hints/critical-ch/critical-ch.navigation-timing.no-restart.https.html new file mode 100644 index 0000000000..a7c2ad705d --- /dev/null +++ b/testing/web-platform/tests/client-hints/critical-ch/critical-ch.navigation-timing.no-restart.https.html @@ -0,0 +1,13 @@ +<!DOCTYPE html> +<body> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +promise_test(async t => { + var navigationTiming = window.performance.getEntriesByType('navigation')[0]; + assert_not_equals(navigationTiming, undefined); + assert_equals(navigationTiming.criticalCHRestart, 0, "This should be 0 as there was no restart."); +}, "Critical-CH no-restart navigation timing test"); +</script> +</body> +</html> diff --git a/testing/web-platform/tests/client-hints/critical-ch/critical-ch.navigation-timing.restart.https.html b/testing/web-platform/tests/client-hints/critical-ch/critical-ch.navigation-timing.restart.https.html new file mode 100644 index 0000000000..d3a49a2e91 --- /dev/null +++ b/testing/web-platform/tests/client-hints/critical-ch/critical-ch.navigation-timing.restart.https.html @@ -0,0 +1,14 @@ +<!DOCTYPE html> +<body> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +promise_test(async t => { + var navigationTiming = window.performance.getEntriesByType('navigation')[0]; + assert_not_equals(navigationTiming, undefined); + assert_less_than(navigationTiming.startTime, navigationTiming.criticalCHRestart, "Restarts happen after the beginning of the navigation"); + assert_less_than(navigationTiming.criticalCHRestart, navigationTiming.fetchStart, "Restarts happen before fetch"); +}, "Critical-CH restart navigation timing test"); +</script> +</body> +</html> diff --git a/testing/web-platform/tests/client-hints/critical-ch/critical-ch.navigation-timing.restart.https.html.headers b/testing/web-platform/tests/client-hints/critical-ch/critical-ch.navigation-timing.restart.https.html.headers new file mode 100644 index 0000000000..b221a32886 --- /dev/null +++ b/testing/web-platform/tests/client-hints/critical-ch/critical-ch.navigation-timing.restart.https.html.headers @@ -0,0 +1,2 @@ +Accept-CH: sec-ch-device-memory +Critical-CH: sec-ch-device-memory 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..cbf128149e --- /dev/null +++ b/testing/web-platform/tests/client-hints/critical-ch/iframe.https.window.js @@ -0,0 +1,15 @@ +// META: script=resources/util.js + +async_test((t) => { + window.addEventListener('message', message_listener(t, "FAIL")); + var iframe = document.createElement("iframe"); + iframe.src = ECHO_URL; + document.body.appendChild(iframe); +}, "Critical-CH iframe"); + +async_test((t) => { + window.addEventListener('message', message_listener(t, "FAIL")); + var iframe = document.createElement("iframe"); + iframe.src = ECHO_URL+"?multiple=true"; + document.body.appendChild(iframe); +}, "Critical-CH w/ multiple headers and 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..23d297837e --- /dev/null +++ b/testing/web-platform/tests/client-hints/critical-ch/mis-matched-count.https.window.js @@ -0,0 +1,5 @@ +// 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") +async_test(make_message_test(ECHO_URL+"?multiple=true&mismatch=true&token="+token(), "1"), "Critical-CH w/ multiple headers and 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/mis-matched.multiple.https.window.js b/testing/web-platform/tests/client-hints/critical-ch/mis-matched.multiple.https.window.js new file mode 100644 index 0000000000..97b94ccf71 --- /dev/null +++ b/testing/web-platform/tests/client-hints/critical-ch/mis-matched.multiple.https.window.js @@ -0,0 +1,3 @@ +// META: script=resources/util.js + +async_test(make_message_test(ECHO_URL+"?multiple=true&mismatch=true", "FAIL"), "Critical-CH w/ multiple headers and Mis-matched hints") diff --git a/testing/web-platform/tests/client-hints/critical-ch/navigation.cross-origin.https.window.js b/testing/web-platform/tests/client-hints/critical-ch/navigation.cross-origin.https.window.js new file mode 100644 index 0000000000..6fdcee71d4 --- /dev/null +++ b/testing/web-platform/tests/client-hints/critical-ch/navigation.cross-origin.https.window.js @@ -0,0 +1,4 @@ +// META: script=resources/util.js +// META: script=/common/get-host-info.sub.js + +async_test(make_message_test(get_host_info().HTTPS_REMOTE_ORIGIN+"/client-hints/critical-ch/"+ECHO_URL, "PASS"), "Critical-CH cross-origin navigation") diff --git a/testing/web-platform/tests/client-hints/critical-ch/navigation.cross-origin.multiple.https.window.js b/testing/web-platform/tests/client-hints/critical-ch/navigation.cross-origin.multiple.https.window.js new file mode 100644 index 0000000000..91a57da3e4 --- /dev/null +++ b/testing/web-platform/tests/client-hints/critical-ch/navigation.cross-origin.multiple.https.window.js @@ -0,0 +1,4 @@ +// META: script=resources/util.js +// META: script=/common/get-host-info.sub.js + +async_test(make_message_test(get_host_info().HTTPS_REMOTE_ORIGIN+"/client-hints/critical-ch/"+ECHO_URL+"?multiple=true", "PASS"), "Critical-CH w/ multiple headers and cross-origin navigation") diff --git a/testing/web-platform/tests/client-hints/critical-ch/navigation.same-origin.https.window.js b/testing/web-platform/tests/client-hints/critical-ch/navigation.same-origin.https.window.js new file mode 100644 index 0000000000..549b321443 --- /dev/null +++ b/testing/web-platform/tests/client-hints/critical-ch/navigation.same-origin.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/navigation.same-origin.multiple.https.window.js b/testing/web-platform/tests/client-hints/critical-ch/navigation.same-origin.multiple.https.window.js new file mode 100644 index 0000000000..ff9cc210fe --- /dev/null +++ b/testing/web-platform/tests/client-hints/critical-ch/navigation.same-origin.multiple.https.window.js @@ -0,0 +1,3 @@ +// META: script=resources/util.js + +async_test(make_message_test(ECHO_URL+"?multiple=true", "PASS"), "Critical-CH w/ multiple headers and 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..b634f98e55 --- /dev/null +++ b/testing/web-platform/tests/client-hints/critical-ch/non-secure.http.window.js @@ -0,0 +1,4 @@ +// META: script=resources/util.js + +async_test(make_message_test(ECHO_URL, "FAIL"), "Critical-CH navigation non-secure") +async_test(make_message_test(ECHO_URL+"?multiple=true", "FAIL"), "Critical-CH w/ multiple headers and navigation non-secure") diff --git a/testing/web-platform/tests/client-hints/critical-ch/redirect.critical.cross-origin.https.window.js b/testing/web-platform/tests/client-hints/critical-ch/redirect.critical.cross-origin.https.window.js new file mode 100644 index 0000000000..74d9a0cc3b --- /dev/null +++ b/testing/web-platform/tests/client-hints/critical-ch/redirect.critical.cross-origin.https.window.js @@ -0,0 +1,4 @@ +// META: script=resources/util.js +// META: script=/common/get-host-info.sub.js + +async_test(make_message_test(REDIRECT_URL+"?critical=true&location="+get_host_info().HTTPS_REMOTE_ORIGIN+"/client-hints/critical-ch/"+ECHO_URL, "PASS"), "Critical-CH cross-origin critical redirect") diff --git a/testing/web-platform/tests/client-hints/critical-ch/redirect.critical.cross-origin.multiple.https.window.js b/testing/web-platform/tests/client-hints/critical-ch/redirect.critical.cross-origin.multiple.https.window.js new file mode 100644 index 0000000000..d1a3c67ecb --- /dev/null +++ b/testing/web-platform/tests/client-hints/critical-ch/redirect.critical.cross-origin.multiple.https.window.js @@ -0,0 +1,4 @@ +// META: script=resources/util.js +// META: script=/common/get-host-info.sub.js + +async_test(make_message_test(REDIRECT_URL+"?critical=true&location="+get_host_info().HTTPS_REMOTE_ORIGIN+"/client-hints/critical-ch/"+ECHO_URL+"?multiple=true", "PASS"), "Critical-CH w/ multiple headers cross-origin critical redirect") diff --git a/testing/web-platform/tests/client-hints/critical-ch/redirect.critical.same-origin.https.window.js b/testing/web-platform/tests/client-hints/critical-ch/redirect.critical.same-origin.https.window.js new file mode 100644 index 0000000000..1c6511a007 --- /dev/null +++ b/testing/web-platform/tests/client-hints/critical-ch/redirect.critical.same-origin.https.window.js @@ -0,0 +1,3 @@ +// META: script=resources/util.js + +async_test(make_message_test(REDIRECT_URL+"?critical=true&location=/client-hints/critical-ch/"+ECHO_URL, "FAIL"), "Critical-CH critical redirect") diff --git a/testing/web-platform/tests/client-hints/critical-ch/redirect.critical.same-origin.multiple.https.window.js b/testing/web-platform/tests/client-hints/critical-ch/redirect.critical.same-origin.multiple.https.window.js new file mode 100644 index 0000000000..5bf653afbc --- /dev/null +++ b/testing/web-platform/tests/client-hints/critical-ch/redirect.critical.same-origin.multiple.https.window.js @@ -0,0 +1,3 @@ +// META: script=resources/util.js + +async_test(make_message_test(REDIRECT_URL+"?critical=true&location=/client-hints/critical-ch/"+ECHO_URL+"?multiple=true", "FAIL"), "Critical-CH w/ multiple headers and critical redirect") diff --git a/testing/web-platform/tests/client-hints/critical-ch/redirect.cross-origin.https.window.js b/testing/web-platform/tests/client-hints/critical-ch/redirect.cross-origin.https.window.js new file mode 100644 index 0000000000..5d781bd082 --- /dev/null +++ b/testing/web-platform/tests/client-hints/critical-ch/redirect.cross-origin.https.window.js @@ -0,0 +1,4 @@ +// META: script=resources/util.js +// META: script=/common/get-host-info.sub.js + +async_test(make_message_test(REDIRECT_URL+"?location="+get_host_info().HTTPS_REMOTE_ORIGIN+"/client-hints/critical-ch/"+ECHO_URL, "PASS"), "Critical-CH cross-origin redirect") diff --git a/testing/web-platform/tests/client-hints/critical-ch/redirect.cross-origin.multiple.https.window.js b/testing/web-platform/tests/client-hints/critical-ch/redirect.cross-origin.multiple.https.window.js new file mode 100644 index 0000000000..5688c8459c --- /dev/null +++ b/testing/web-platform/tests/client-hints/critical-ch/redirect.cross-origin.multiple.https.window.js @@ -0,0 +1,4 @@ +// META: script=resources/util.js +// META: script=/common/get-host-info.sub.js + +async_test(make_message_test(REDIRECT_URL+"?location="+get_host_info().HTTPS_REMOTE_ORIGIN+"/client-hints/critical-ch/"+ECHO_URL+"?multiple=true", "PASS"), "Critical-CH w/ multiple headers cross-origin redirect") diff --git a/testing/web-platform/tests/client-hints/critical-ch/redirect.same-origin.https.window.js b/testing/web-platform/tests/client-hints/critical-ch/redirect.same-origin.https.window.js new file mode 100644 index 0000000000..b2401025d9 --- /dev/null +++ b/testing/web-platform/tests/client-hints/critical-ch/redirect.same-origin.https.window.js @@ -0,0 +1,3 @@ +// META: script=resources/util.js + +async_test(make_message_test(REDIRECT_URL+"?location=/client-hints/critical-ch/"+ECHO_URL, "PASS"), "Critical-CH redirect") diff --git a/testing/web-platform/tests/client-hints/critical-ch/redirect.same-origin.multiple.https.window.js b/testing/web-platform/tests/client-hints/critical-ch/redirect.same-origin.multiple.https.window.js new file mode 100644 index 0000000000..86305023f4 --- /dev/null +++ b/testing/web-platform/tests/client-hints/critical-ch/redirect.same-origin.multiple.https.window.js @@ -0,0 +1,3 @@ +// META: script=resources/util.js + +async_test(make_message_test(REDIRECT_URL+"?location=/client-hints/critical-ch/"+ECHO_URL+"?multiple=true", "PASS"), "Critical-CH w/ multiple headers and redirect") 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/request-count.multiple.https.window.js b/testing/web-platform/tests/client-hints/critical-ch/request-count.multiple.https.window.js new file mode 100644 index 0000000000..602803b5d6 --- /dev/null +++ b/testing/web-platform/tests/client-hints/critical-ch/request-count.multiple.https.window.js @@ -0,0 +1,4 @@ +// META: script=resources/util.js +// META: script=/common/utils.js + +async_test(make_message_test(ECHO_URL+"?multiple=true&token="+token(), "2"), "Critical-CH w/ multiple headers and 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..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; + } 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..81dfc303c6 --- /dev/null +++ b/testing/web-platform/tests/client-hints/critical-ch/subresource.https.window.js @@ -0,0 +1,18 @@ +// META: script=resources/util.js +// META: script=/common/utils.js + +promise_test(() => + fetch(ECHO_URL) + .then((r) => r.text()) + .then((r) => { + assert_true(r.includes("FAIL")); + }) +, "Critical-CH subresource fetch"); + +promise_test(() => + fetch(ECHO_URL+"?multiple=true") + .then((r) => r.text()) + .then((r) => { + assert_true(r.includes("FAIL")); + }) +, "Critical-CH w/ multiple headers and 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..61fca618f3 --- /dev/null +++ b/testing/web-platform/tests/client-hints/critical-ch/unsafe-method.https.window.js @@ -0,0 +1,49 @@ +// META: script=resources/util.js + +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", ECHO_URL); + form.setAttribute("target", "popup"); //don't navigate away from the page running the test... + document.body.appendChild(form); + + window.addEventListener('message', (e) => { + t.step(()=>{assert_equals(e.data, "FAIL")}); + t.done(); + }); + + var popup_window = window.open("/common/blank.html", "popup"); + assert_not_equals(popup_window, null, "Popup windows not allowed?"); + + form.submit(); +}, "Critical-CH unsafe method") + +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", ECHO_URL+"?multiple=true"); + form.setAttribute("target", "popup"); //don't navigate away from the page running the test... + document.body.appendChild(form); + + window.addEventListener('message', (e) => { + t.step(()=>{assert_equals(e.data, "FAIL")}); + t.done(); + }); + + var popup_window = window.open("/common/blank.html", "popup"); + assert_not_equals(popup_window, null, "Popup windows not allowed?"); + + form.submit(); +}, "Critical-CH w/ multiple headers and unsafe method") |