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/fetch/metadata/tools/templates/window-location.sub.html | |
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/fetch/metadata/tools/templates/window-location.sub.html')
-rw-r--r-- | testing/web-platform/tests/fetch/metadata/tools/templates/window-location.sub.html | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/testing/web-platform/tests/fetch/metadata/tools/templates/window-location.sub.html b/testing/web-platform/tests/fetch/metadata/tools/templates/window-location.sub.html new file mode 100644 index 0000000000..96f3912361 --- /dev/null +++ b/testing/web-platform/tests/fetch/metadata/tools/templates/window-location.sub.html @@ -0,0 +1,128 @@ +<!DOCTYPE html> +<!-- +[%provenance%] +--> +<html lang="en"> + <meta charset="utf-8"> + {%- if subtests|length > 10 %} + <meta name="timeout" content="long"> + {%- endif %} + <title>HTTP headers on request for navigation via the HTML Location API</title> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + {%- if subtests|selectattr('userActivated')|list %} + <script src="/resources/testdriver.js"></script> + <script src="/resources/testdriver-vendor.js"></script> + {%- endif %} + <script src="/fetch/metadata/resources/helper.sub.js"></script> + <body> + <script> + 'use strict'; + + function induceRequest(url, navigate, userActivated) { + const win = window.open(); + + return new Promise((resolve) => { + addEventListener('message', function(event) { + if (event.source === win) { + resolve(); + } + }); + + if (userActivated) { + test_driver.bless('enable user activation', () => { + navigate(win, url); + }); + } else { + navigate(win, url); + } + }) + .then(() => win.close()); + } + + const responseParams = { + mime: 'text/html', + body: `<script>opener.postMessage('done', '*')</${''}script>` + }; + {%- for subtest in subtests %} + + promise_test(() => { + const key = '{{uuid()}}'; + const url = makeRequestURL(key, [% subtest.origins %], responseParams); + + const navigate = (win, path) => { + win.location = path; + }; + return induceRequest(url, navigate, [% 'true' if subtest.userActivated else 'false' %]) + .then(() => retrieve(key)) + .then((headers) => { + {%- if subtest.expected == none %} + assert_not_own_property(headers, '[%subtest.headerName%]'); + {%- else %} + assert_own_property(headers, '[%subtest.headerName%]'); + assert_array_equals(headers['[%subtest.headerName%]'], ['[%subtest.expected%]']); + {%- endif %} + }); + }, '[%subtest.headerName%] - [%subtest.description | pad("end", " - ")%]location[% " with user activation" if subtest.userActivated%]'); + + promise_test(() => { + const key = '{{uuid()}}'; + const url = makeRequestURL(key, [% subtest.origins %], responseParams); + + const navigate = (win, path) => { + win.location.href = path; + }; + return induceRequest(url, navigate, [% 'true' if subtest.userActivated else 'false' %]) + .then(() => retrieve(key)) + .then((headers) => { + {%- if subtest.expected == none %} + assert_not_own_property(headers, '[%subtest.headerName%]'); + {%- else %} + assert_own_property(headers, '[%subtest.headerName%]'); + assert_array_equals(headers['[%subtest.headerName%]'], ['[%subtest.expected%]']); + {%- endif %} + }); + }, '[%subtest.headerName%] - [%subtest.description | pad("end", " - ")%]location.href[% " with user activation" if subtest.userActivated%]'); + + promise_test(() => { + const key = '{{uuid()}}'; + const url = makeRequestURL(key, [% subtest.origins %], responseParams); + + const navigate = (win, path) => { + win.location.assign(path); + }; + return induceRequest(url, navigate, [% 'true' if subtest.userActivated else 'false' %]) + .then(() => retrieve(key)) + .then((headers) => { + {%- if subtest.expected == none %} + assert_not_own_property(headers, '[%subtest.headerName%]'); + {%- else %} + assert_own_property(headers, '[%subtest.headerName%]'); + assert_array_equals(headers['[%subtest.headerName%]'], ['[%subtest.expected%]']); + {%- endif %} + }); + }, '[%subtest.headerName%] - [%subtest.description | pad("end", " - ")%]location.assign[% " with user activation" if subtest.userActivated%]'); + + promise_test(() => { + const key = '{{uuid()}}'; + const url = makeRequestURL(key, [% subtest.origins %], responseParams); + + const navigate = (win, path) => { + win.location.replace(path); + }; + return induceRequest(url, navigate, [% 'true' if subtest.userActivated else 'false' %]) + .then(() => retrieve(key)) + .then((headers) => { + {%- if subtest.expected == none %} + assert_not_own_property(headers, '[%subtest.headerName%]'); + {%- else %} + assert_own_property(headers, '[%subtest.headerName%]'); + assert_array_equals(headers['[%subtest.headerName%]'], ['[%subtest.expected%]']); + {%- endif %} + }); + }, '[%subtest.headerName%] - [%subtest.description | pad("end", " - ")%]location.replace[% " with user activation" if subtest.userActivated%]'); + + {%- endfor %} + </script> + </body> +</html> |