diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/client-hints/resources/feature-policy-navigation.js | |
parent | Initial commit. (diff) | |
download | firefox-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/resources/feature-policy-navigation.js')
-rw-r--r-- | testing/web-platform/tests/client-hints/resources/feature-policy-navigation.js | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/testing/web-platform/tests/client-hints/resources/feature-policy-navigation.js b/testing/web-platform/tests/client-hints/resources/feature-policy-navigation.js new file mode 100644 index 0000000000..23782fdfdb --- /dev/null +++ b/testing/web-platform/tests/client-hints/resources/feature-policy-navigation.js @@ -0,0 +1,72 @@ +const meta_name_enabled = [ + "sec-ch-device-memory", + "device-memory", + "sec-ch-dpr", + "dpr", + "sec-ch-viewport-width", + "viewport-width", + "sec-ch-ua", + "sec-ch-ua-mobile", + "sec-ch-ua-platform", +]; + +const meta_name_client_hints = iframe_src + + client_hints_list.map((e) => { + if(meta_name_enabled.includes(e)) { + return e+"=true"; + } else { + return e+"=false"; + } + }).join("&"); + +const cross_origin_enabled = [ + "device-memory", + "sec-ch-device-memory", + "sec-ch-ua-platform", +]; + +const cross_origin_client_hints = iframe_src + + client_hints_list.map((e) => { + if(cross_origin_enabled.includes(e)) { + return e+"=true"; + } else { + return e+"=false"; + } + }).join("&"); + +const same_origin_disabled = [ + "dpr", + "sec-ch-dpr", + "sec-ch-ua-mobile", +]; + +const same_origin_client_hints = iframe_src + + client_hints_list.map((e) => { + if(same_origin_disabled.includes(e)) { + return e+"=false"; + } else { + return e+"=true"; + } + }).join("&"); + +const test_frame = (origin, url, allow, message) => { + promise_test(() => { + return new Promise((resolve, reject) => { + let frame = document.createElement('iframe'); + frame.allow = allow; + window.addEventListener('message', function(e) { + try { + assert_equals(typeof e.data, "string"); + assert_equals(e.data, "PASS"); + } catch { + reject(e.data); + } + resolve(); + }); + document.body.appendChild(frame); + // Writing to |frame.src| triggers the navigation, so + // everything else need to happen first. + frame.src = get_host_info()[origin] + url; + }); + }, message); +} |