summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fetch/metadata/tools/templates
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/fetch/metadata/tools/templates
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/fetch/metadata/tools/templates')
-rw-r--r--testing/web-platform/tests/fetch/metadata/tools/templates/appcache-manifest.sub.https.html63
-rw-r--r--testing/web-platform/tests/fetch/metadata/tools/templates/audioworklet.https.sub.html53
-rw-r--r--testing/web-platform/tests/fetch/metadata/tools/templates/css-font-face.sub.html60
-rw-r--r--testing/web-platform/tests/fetch/metadata/tools/templates/css-images.sub.html137
-rw-r--r--testing/web-platform/tests/fetch/metadata/tools/templates/element-a.sub.html72
-rw-r--r--testing/web-platform/tests/fetch/metadata/tools/templates/element-area.sub.html72
-rw-r--r--testing/web-platform/tests/fetch/metadata/tools/templates/element-audio.sub.html51
-rw-r--r--testing/web-platform/tests/fetch/metadata/tools/templates/element-embed.sub.html54
-rw-r--r--testing/web-platform/tests/fetch/metadata/tools/templates/element-frame.sub.html62
-rw-r--r--testing/web-platform/tests/fetch/metadata/tools/templates/element-iframe.sub.html62
-rw-r--r--testing/web-platform/tests/fetch/metadata/tools/templates/element-img-environment-change.sub.html78
-rw-r--r--testing/web-platform/tests/fetch/metadata/tools/templates/element-img.sub.html52
-rw-r--r--testing/web-platform/tests/fetch/metadata/tools/templates/element-input-image.sub.html48
-rw-r--r--testing/web-platform/tests/fetch/metadata/tools/templates/element-link-icon.sub.html75
-rw-r--r--testing/web-platform/tests/fetch/metadata/tools/templates/element-link-prefetch.optional.sub.html71
-rw-r--r--testing/web-platform/tests/fetch/metadata/tools/templates/element-meta-refresh.optional.sub.html60
-rw-r--r--testing/web-platform/tests/fetch/metadata/tools/templates/element-picture.sub.html101
-rw-r--r--testing/web-platform/tests/fetch/metadata/tools/templates/element-script.sub.html54
-rw-r--r--testing/web-platform/tests/fetch/metadata/tools/templates/element-video-poster.sub.html62
-rw-r--r--testing/web-platform/tests/fetch/metadata/tools/templates/element-video.sub.html51
-rw-r--r--testing/web-platform/tests/fetch/metadata/tools/templates/fetch-via-serviceworker.https.sub.html88
-rw-r--r--testing/web-platform/tests/fetch/metadata/tools/templates/fetch.sub.html42
-rw-r--r--testing/web-platform/tests/fetch/metadata/tools/templates/form-submission.sub.html87
-rw-r--r--testing/web-platform/tests/fetch/metadata/tools/templates/header-link.sub.html56
-rw-r--r--testing/web-platform/tests/fetch/metadata/tools/templates/header-refresh.optional.sub.html59
-rw-r--r--testing/web-platform/tests/fetch/metadata/tools/templates/script-module-import-dynamic.sub.html35
-rw-r--r--testing/web-platform/tests/fetch/metadata/tools/templates/script-module-import-static.sub.html53
-rw-r--r--testing/web-platform/tests/fetch/metadata/tools/templates/serviceworker.https.sub.html72
-rw-r--r--testing/web-platform/tests/fetch/metadata/tools/templates/svg-image.sub.html75
-rw-r--r--testing/web-platform/tests/fetch/metadata/tools/templates/window-history.sub.html134
-rw-r--r--testing/web-platform/tests/fetch/metadata/tools/templates/window-location.sub.html128
-rw-r--r--testing/web-platform/tests/fetch/metadata/tools/templates/worker-dedicated-constructor.sub.html49
-rw-r--r--testing/web-platform/tests/fetch/metadata/tools/templates/worker-dedicated-importscripts.sub.html54
33 files changed, 2270 insertions, 0 deletions
diff --git a/testing/web-platform/tests/fetch/metadata/tools/templates/appcache-manifest.sub.https.html b/testing/web-platform/tests/fetch/metadata/tools/templates/appcache-manifest.sub.https.html
new file mode 100644
index 0000000000..0dfc084f2e
--- /dev/null
+++ b/testing/web-platform/tests/fetch/metadata/tools/templates/appcache-manifest.sub.https.html
@@ -0,0 +1,63 @@
+<!DOCTYPE html>
+<!--
+[%provenance%]
+-->
+<html lang="en">
+ <meta charset="utf-8">
+ <title>HTTP headers on request for Appcache manifest</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/fetch/metadata/resources/helper.sub.js"></script>
+ <body>
+ <script>
+ 'use strict';
+
+ function induceRequest(url) {
+ const iframe = document.createElement('iframe');
+ iframe.src =
+ '/fetch/metadata/resources/appcache-iframe.sub.html?manifest=' + encodeURIComponent(url);
+
+ return new Promise((resolve) => {
+ addEventListener('message', function onMessage(event) {
+ if (event.source !== iframe.contentWindow) {
+ return;
+ }
+ removeEventListener('message', onMessage);
+ resolve(event.data);
+ });
+
+ document.body.appendChild(iframe);
+ })
+ .then((message) => {
+ if (message !== 'okay') {
+ throw message;
+ }
+ })
+ .then(() => iframe.remove());
+ }
+
+ {%- for subtest in subtests %}
+
+ async_test((t) => {
+ const key = '{{uuid()}}';
+ assert_implements_optional(
+ !!window.applicationCache, 'Application Cache supported.'
+ );
+
+ induceRequest(makeRequestURL(key, [% subtest.origins %]))
+ .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 %}
+ })
+ .then(() => t.done(), t.step_func((error) => { throw error; }));
+ }, '[%subtest.headerName%][%subtest.description | pad("start", " - ")%]');
+
+ {%- endfor %}
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/fetch/metadata/tools/templates/audioworklet.https.sub.html b/testing/web-platform/tests/fetch/metadata/tools/templates/audioworklet.https.sub.html
new file mode 100644
index 0000000000..7be309c506
--- /dev/null
+++ b/testing/web-platform/tests/fetch/metadata/tools/templates/audioworklet.https.sub.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html>
+<!--
+[%provenance%]
+-->
+<html lang="en">
+ <meta charset="utf-8">
+ <title>HTTP headers on request for AudioWorklet module</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/resources/testdriver.js"></script>
+ <script src="/resources/testdriver-vendor.js"></script>
+ <script src="/fetch/metadata/resources/helper.sub.js"></script>
+ <body>
+ <script>
+ 'use strict';
+
+ function induceRequest(url, test) {
+ return test_driver.bless(
+ 'Enable WebAudio playback',
+ () => {
+ const audioContext = new AudioContext();
+
+ test.add_cleanup(() => audioContext.close());
+
+ return audioContext.audioWorklet.addModule(url);
+ }
+ );
+ }
+
+ {%- for subtest in subtests %}
+
+ promise_test((t) => {
+ const key = '{{uuid()}}';
+
+ return induceRequest(
+ makeRequestURL(key, [% subtest.origins %], {mime: 'text/javascript'}),
+ t
+ )
+ .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("start", " - ")%]');
+
+ {%- endfor %}
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/fetch/metadata/tools/templates/css-font-face.sub.html b/testing/web-platform/tests/fetch/metadata/tools/templates/css-font-face.sub.html
new file mode 100644
index 0000000000..94b33f4e6b
--- /dev/null
+++ b/testing/web-platform/tests/fetch/metadata/tools/templates/css-font-face.sub.html
@@ -0,0 +1,60 @@
+<!DOCTYPE html>
+<!--
+[%provenance%]
+-->
+<html lang="en">
+ <meta charset="utf-8">
+ <title>HTTP headers on request for CSS font-face</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/fetch/metadata/resources/helper.sub.js"></script>
+ <body>
+ <script>
+ 'use strict';
+
+ let count = 0;
+
+ function induceRequest(t, url) {
+ const id = `el-${count += 1}`;
+ const style = document.createElement('style');
+ style.appendChild(document.createTextNode(`
+ @font-face {
+ font-family: wpt-font-family${id};
+ src: url(${url});
+ }
+ #el-${id} {
+ font-family: wpt-font-family${id};
+ }
+ `));
+ const div = document.createElement('div');
+ div.setAttribute('id', 'el-' + id);
+ div.appendChild(style);
+ div.appendChild(document.createTextNode('x'));
+ document.body.appendChild(div);
+
+ t.add_cleanup(() => div.remove());
+
+ return document.fonts.ready;
+ }
+
+ {%- for subtest in subtests %}
+
+ promise_test((t) => {
+ const key = '{{uuid()}}';
+
+ return induceRequest(t, makeRequestURL(key, [% subtest.origins %]))
+ .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("start", " - ")%]');
+
+ {%- endfor %}
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/fetch/metadata/tools/templates/css-images.sub.html b/testing/web-platform/tests/fetch/metadata/tools/templates/css-images.sub.html
new file mode 100644
index 0000000000..e394f9f5b0
--- /dev/null
+++ b/testing/web-platform/tests/fetch/metadata/tools/templates/css-images.sub.html
@@ -0,0 +1,137 @@
+<!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 CSS image-accepting properties</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/fetch/metadata/resources/helper.sub.js"></script>
+ <body>
+ <script>
+ 'use strict';
+
+ /**
+ * The subtests in this file use an iframe to induce requests for CSS
+ * resources because an iframe's `onload` event is the most direct and
+ * generic mechanism to detect loading of CSS resources. As an optimization,
+ * the subtests share the same iframe and document.
+ */
+ const declarations = [];
+ const iframe = document.createElement('iframe');
+ const whenIframeReady = new Promise((resolve, reject) => {
+ iframe.onload = resolve;
+ iframe.onerror = reject;
+ });
+
+ {%- for subtest in subtests %}
+
+ async_test((t) => {
+ const key = '{{uuid()}}';
+ const url = makeRequestURL(key, [% subtest.origins %]);
+
+ declarations.push(`background-image: url("${url}");`);
+
+ whenIframeReady
+ .then(() => retrieve(key))
+ .then((headers) => {
+ {%- if subtest.expected == none %}
+ assert_not_own_property(headers, '[%subtest.headerName%]');
+ {%- else %}
+ assert_own_property(headers, '[%subtest.headerName%]');
+ assert_equals(headers['[%subtest.headerName%]'], '[%subtest.expected%]');
+ {%- endif %}
+ })
+ .then(t.step_func_done(), (error) => t.unreached_func());
+ }, 'background-image [%subtest.headerName%][%subtest.description | pad("start", " - ")%]');
+
+ async_test((t) => {
+ const key = '{{uuid()}}';
+ const url = makeRequestURL(key, [% subtest.origins %]);
+
+ declarations.push(`border-image: url("${url}");`);
+
+ whenIframeReady
+ .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 %}
+ })
+ .then(t.step_func_done(), t.unreached_func());
+ }, 'border-image [%subtest.headerName%][%subtest.description | pad("start", " - ")%]');
+
+ async_test((t) => {
+ const key = '{{uuid()}}';
+ const url = makeRequestURL(key, [% subtest.origins %]);
+
+ declarations.push(`content: url("${url}");`);
+
+ whenIframeReady
+ .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 %}
+ })
+ .then(t.step_func_done(), t.unreached_func());
+ }, 'content [%subtest.headerName%][%subtest.description | pad("start", " - ")%]');
+
+ async_test((t) => {
+ const key = '{{uuid()}}';
+ const url = makeRequestURL(key, [% subtest.origins %]);
+
+ declarations.push(`cursor: url("${url}"), auto;`);
+
+ whenIframeReady
+ .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 %}
+ })
+ .then(t.step_func_done(), t.unreached_func());
+ }, 'cursor [%subtest.headerName%][%subtest.description | pad("start", " - ")%]');
+
+ async_test((t) => {
+ const key = '{{uuid()}}';
+ const url = makeRequestURL(key, [% subtest.origins %]);
+
+ declarations.push(`list-style-image: url("${url}");`);
+
+ whenIframeReady
+ .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 %}
+ })
+ .then(t.step_func_done(), t.unreached_func());
+ }, 'list-style-image [%subtest.headerName%][%subtest.description | pad("start", " - ")%]');
+
+ {%- endfor %}
+
+ iframe.srcdoc = declarations.map((declaration, index) => `
+ <style>.el${index} { ${declaration} }</style><div class="el${index}"></div>`
+ ).join('');
+ document.body.appendChild(iframe);
+
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/fetch/metadata/tools/templates/element-a.sub.html b/testing/web-platform/tests/fetch/metadata/tools/templates/element-a.sub.html
new file mode 100644
index 0000000000..2bd8e8a40e
--- /dev/null
+++ b/testing/web-platform/tests/fetch/metadata/tools/templates/element-a.sub.html
@@ -0,0 +1,72 @@
+<!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 HTML "a" element navigation</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, {test, userActivated, attributes}) {
+ const win = window.open();
+ const anchor = win.document.createElement('a');
+ anchor.setAttribute('href', url);
+
+ for (const [ name, value ] of Object.entries(attributes)) {
+ anchor.setAttribute(name, value);
+ }
+
+ win.document.body.appendChild(anchor);
+
+ test.add_cleanup(() => win.close());
+
+ if (userActivated) {
+ test_driver.bless('enable user activation', () => anchor.click());
+ } else {
+ anchor.click();
+ }
+ }
+
+ {%- for subtest in subtests %}
+
+ promise_test((t) => {
+ const key = '{{uuid()}}';
+
+ induceRequest(
+ makeRequestURL(key, [% subtest.origins %], {mime: 'text/html'}),
+ {
+ test: t,
+ userActivated: [%subtest.userActivated | default(false) | tojson%],
+ attributes: [%subtest.elementAttrs | default({}) | tojson%]
+ }
+ );
+
+ // `induceRequest` does not necessarily trigger a navigation, so the Python
+ // handler must be polled until it has received the initial request.
+ return retrieve(key, {poll: true})
+ .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("start", " - ")%] - [%subtest.elementAttrs | collection("attributes")%][% " with user activation" if subtest.userActivated%]');
+
+ {%- endfor %}
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/fetch/metadata/tools/templates/element-area.sub.html b/testing/web-platform/tests/fetch/metadata/tools/templates/element-area.sub.html
new file mode 100644
index 0000000000..0cef5b2294
--- /dev/null
+++ b/testing/web-platform/tests/fetch/metadata/tools/templates/element-area.sub.html
@@ -0,0 +1,72 @@
+<!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 HTML "area" element navigation</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, {test, userActivated, attributes}) {
+ const win = window.open();
+ const area = win.document.createElement('area');
+ area.setAttribute('href', url);
+
+ for (const [ name, value ] of Object.entries(attributes)) {
+ area.setAttribute(name, value);
+ }
+
+ win.document.body.appendChild(area);
+
+ test.add_cleanup(() => win.close());
+
+ if (userActivated) {
+ test_driver.bless('enable user activation', () => area.click());
+ } else {
+ area.click();
+ }
+ }
+
+ {%- for subtest in subtests %}
+
+ promise_test((t) => {
+ const key = '{{uuid()}}';
+
+ induceRequest(
+ makeRequestURL(key, [% subtest.origins %], {mime: 'text/html'}),
+ {
+ test: t,
+ userActivated: [%subtest.userActivated | default(false) | tojson%],
+ attributes: [%subtest.elementAttrs | default({}) | tojson%]
+ }
+ );
+
+ // `induceRequest` does not necessarily trigger a navigation, so the Python
+ // handler must be polled until it has received the initial request.
+ return retrieve(key, {poll: true})
+ .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("start", " - ")%] - [%subtest.elementAttrs | collection("attributes")%][% " with user activation" if subtest.userActivated%]');
+
+ {%- endfor %}
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/fetch/metadata/tools/templates/element-audio.sub.html b/testing/web-platform/tests/fetch/metadata/tools/templates/element-audio.sub.html
new file mode 100644
index 0000000000..92bc22198e
--- /dev/null
+++ b/testing/web-platform/tests/fetch/metadata/tools/templates/element-audio.sub.html
@@ -0,0 +1,51 @@
+<!DOCTYPE html>
+<!--
+[%provenance%]
+-->
+<html lang="en">
+ <meta charset="utf-8">
+ <title>HTTP headers on request for HTML "audio" element source</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/fetch/metadata/resources/helper.sub.js"></script>
+ <body>
+ <script>
+ 'use strict';
+
+ function induceRequest(url, attributes) {
+ const audio = document.createElement('audio');
+
+ for (const [ name, value ] of Object.entries(attributes)) {
+ audio.setAttribute(name, value);
+ }
+
+ return new Promise((resolve) => {
+ audio.setAttribute('src', url);
+ audio.onload = audio.onerror = resolve;
+ });
+ }
+
+ {%- for subtest in subtests %}
+
+ promise_test(() => {
+ const key = '{{uuid()}}';
+
+ return induceRequest(
+ makeRequestURL(key, [% subtest.origins %]),
+ [%subtest.elementAttrs | default({}) | tojson%]
+ )
+ .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", ", ")%][%subtest.elementAttrs | collection("attributes")%]');
+
+ {%- endfor %}
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/fetch/metadata/tools/templates/element-embed.sub.html b/testing/web-platform/tests/fetch/metadata/tools/templates/element-embed.sub.html
new file mode 100644
index 0000000000..18ce09e5fd
--- /dev/null
+++ b/testing/web-platform/tests/fetch/metadata/tools/templates/element-embed.sub.html
@@ -0,0 +1,54 @@
+<!DOCTYPE html>
+<!--
+[%provenance%]
+-->
+<html lang="en">
+ <meta charset="utf-8">
+ <title>HTTP headers on request for HTML "embed" element source</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/fetch/metadata/resources/helper.sub.js"></script>
+ <body>
+ <script>
+ 'use strict';
+
+ const params = {
+ body: `
+ <svg xmlns="http://www.w3.org/2000/svg" width="123" height="123">
+ <rect fill="lime" width="123" height="123"/>
+ </svg>
+ `,
+ mime: 'image/svg+xml'
+ };
+
+ function induceRequest(t, url) {
+ const embed = document.createElement('embed');
+ embed.setAttribute('src', url);
+ document.body.appendChild(embed);
+
+ t.add_cleanup(() => embed.remove());
+
+ return new Promise((resolve) => embed.addEventListener('load', resolve));
+ }
+
+ {%- for subtest in subtests %}
+
+ promise_test((t) => {
+ const key = '{{uuid()}}';
+
+ return induceRequest(t, makeRequestURL(key, [% subtest.origins %], params))
+ .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("start", " - ")%]');
+
+ {%- endfor %}
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/fetch/metadata/tools/templates/element-frame.sub.html b/testing/web-platform/tests/fetch/metadata/tools/templates/element-frame.sub.html
new file mode 100644
index 0000000000..ce90171779
--- /dev/null
+++ b/testing/web-platform/tests/fetch/metadata/tools/templates/element-frame.sub.html
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<!--
+[%provenance%]
+-->
+<html lang="en">
+ <meta charset="utf-8">
+ <title>HTTP headers on request for HTML "frame" element source</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, test, userActivated) {
+ const frame = document.createElement('frame');
+
+ const setSrc = () => frame.setAttribute('src', url);
+
+ document.body.appendChild(frame);
+ test.add_cleanup(() => frame.remove());
+
+ return new Promise((resolve) => {
+ if (userActivated) {
+ test_driver.bless('enable user activation', setSrc);
+ } else {
+ setSrc();
+ }
+
+ frame.onload = frame.onerror = resolve;
+ });
+ }
+
+ {%- for subtest in subtests %}
+
+ promise_test((t) => {
+ const key = '{{uuid()}}';
+
+ return induceRequest(
+ makeRequestURL(key, [% subtest.origins %], {mime: 'text/html'}),
+ t,
+ [%subtest.userActivated | default(false) | tojson%]
+ )
+ .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("start", " - ")%][% " with user activation" if subtest.userActivated%]');
+
+ {%- endfor %}
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/fetch/metadata/tools/templates/element-iframe.sub.html b/testing/web-platform/tests/fetch/metadata/tools/templates/element-iframe.sub.html
new file mode 100644
index 0000000000..43a632a15c
--- /dev/null
+++ b/testing/web-platform/tests/fetch/metadata/tools/templates/element-iframe.sub.html
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<!--
+[%provenance%]
+-->
+<html lang="en">
+ <meta charset="utf-8">
+ <title>HTTP headers on request for HTML "frame" element source</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, test, userActivated) {
+ const iframe = document.createElement('iframe');
+
+ const setSrc = () => iframe.setAttribute('src', url);
+
+ document.body.appendChild(iframe);
+ test.add_cleanup(() => iframe.remove());
+
+ return new Promise((resolve) => {
+ if (userActivated) {
+ test_driver.bless('enable user activation', setSrc);
+ } else {
+ setSrc();
+ }
+
+ iframe.onload = iframe.onerror = resolve;
+ });
+ }
+
+ {%- for subtest in subtests %}
+
+ promise_test((t) => {
+ const key = '{{uuid()}}';
+
+ return induceRequest(
+ makeRequestURL(key, [% subtest.origins %], {mime: 'text/html'}),
+ t,
+ [%subtest.userActivated | default(false) | tojson%]
+ )
+ .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("start", " - ")%][% " with user activation" if subtest.userActivated%]');
+
+ {%- endfor %}
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/fetch/metadata/tools/templates/element-img-environment-change.sub.html b/testing/web-platform/tests/fetch/metadata/tools/templates/element-img-environment-change.sub.html
new file mode 100644
index 0000000000..5a65114f18
--- /dev/null
+++ b/testing/web-platform/tests/fetch/metadata/tools/templates/element-img-environment-change.sub.html
@@ -0,0 +1,78 @@
+<!DOCTYPE html>
+<!--
+[%provenance%]
+-->
+<html lang="en">
+ <meta charset="utf-8">
+ <title>HTTP headers on image request triggered by change to environment</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/fetch/metadata/resources/helper.sub.js"></script>
+ <body>
+ <script>
+ 'use strict';
+
+ // The response to the request under test must describe a valid image
+ // resource in order for the `load` event to be fired.
+ const params = {
+ body: `
+ <svg xmlns="http://www.w3.org/2000/svg" width="123" height="123">
+ <rect fill="lime" width="123" height="123"/>
+ </svg>
+ `,
+ mime: 'image/svg+xml'
+ };
+
+ function induceRequest(t, url, attributes) {
+ const iframe = document.createElement('iframe');
+ iframe.style.width = '50px';
+ document.body.appendChild(iframe);
+ t.add_cleanup(() => iframe.remove());
+ iframe.contentDocument.open();
+ iframe.contentDocument.close();
+
+ const image = iframe.contentDocument.createElement('img');
+ for (const [ name, value ] of Object.entries(attributes)) {
+ image.setAttribute(name, value);
+ }
+ iframe.contentDocument.body.appendChild(image);
+
+ image.setAttribute('srcset', `${url} 100w, /media/1x1-green.png 1w`);
+ image.setAttribute('sizes', '(max-width: 100px) 1px, (min-width: 150px) 123px');
+
+ return new Promise((resolve) => {
+ image.onload = image.onerror = resolve;
+ })
+ .then(() => {
+
+ iframe.style.width = '200px';
+
+ return new Promise((resolve) => image.onload = resolve);
+ });
+ }
+
+ {%- for subtest in subtests %}
+
+ promise_test((t) => {
+ const key = '{{uuid()}}';
+
+ return induceRequest(
+ t,
+ makeRequestURL(key, [% subtest.origins %], params),
+ [%subtest.elementAttrs | default({}) | tojson%]
+ )
+ .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", ", ")%][%subtest.elementAttrs | collection("attributes")%]');
+
+ {%- endfor %}
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/fetch/metadata/tools/templates/element-img.sub.html b/testing/web-platform/tests/fetch/metadata/tools/templates/element-img.sub.html
new file mode 100644
index 0000000000..1dac5843ec
--- /dev/null
+++ b/testing/web-platform/tests/fetch/metadata/tools/templates/element-img.sub.html
@@ -0,0 +1,52 @@
+<!DOCTYPE html>
+<!--
+[%provenance%]
+-->
+<html lang="en">
+ <meta charset="utf-8">
+ <title>HTTP headers on request for HTML "img" element source</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/fetch/metadata/resources/helper.sub.js"></script>
+ <body>
+ <script>
+ 'use strict';
+
+ function induceRequest(url, sourceAttr, attributes) {
+ const image = document.createElement('img');
+
+ for (const [ name, value ] of Object.entries(attributes)) {
+ image.setAttribute(name, value);
+ }
+
+ return new Promise((resolve) => {
+ image.setAttribute(sourceAttr, url);
+ image.onload = image.onerror = resolve;
+ });
+ }
+
+ {%- for subtest in subtests %}
+
+ promise_test(() => {
+ const key = '{{uuid()}}';
+
+ return induceRequest(
+ makeRequestURL(key, [% subtest.origins %]),
+ '[%subtest.sourceAttr%]',
+ [%subtest.elementAttrs | default({}) | tojson%]
+ )
+ .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.sourceAttr%] - [%subtest.description | pad("end", ", ")%][%subtest.elementAttrs | collection("attributes")%]');
+
+ {%- endfor %}
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/fetch/metadata/tools/templates/element-input-image.sub.html b/testing/web-platform/tests/fetch/metadata/tools/templates/element-input-image.sub.html
new file mode 100644
index 0000000000..3c50008433
--- /dev/null
+++ b/testing/web-platform/tests/fetch/metadata/tools/templates/element-input-image.sub.html
@@ -0,0 +1,48 @@
+<!DOCTYPE html>
+<!--
+[%provenance%]
+-->
+<html lang="en">
+ <meta charset="utf-8">
+ <title>HTTP headers on request for HTML "input" element with type="button"</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/fetch/metadata/resources/helper.sub.js"></script>
+ <body>
+ <script>
+ 'use strict';
+
+ function induceRequest(url, test) {
+ const input = document.createElement('input');
+ input.setAttribute('type', 'image');
+
+ document.body.appendChild(input);
+ test.add_cleanup(() => input.remove());
+
+ return new Promise((resolve) => {
+ input.onload = input.onerror = resolve;
+ input.setAttribute('src', url);
+ });
+ }
+
+ {%- for subtest in subtests %}
+
+ promise_test((t) => {
+ const key = '{{uuid()}}';
+
+ return induceRequest(makeRequestURL(key, [% subtest.origins %]), t)
+ .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", ", ")%][%subtest.elementAttrs | collection("attributes")%]');
+
+ {%- endfor %}
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/fetch/metadata/tools/templates/element-link-icon.sub.html b/testing/web-platform/tests/fetch/metadata/tools/templates/element-link-icon.sub.html
new file mode 100644
index 0000000000..18ce12a689
--- /dev/null
+++ b/testing/web-platform/tests/fetch/metadata/tools/templates/element-link-icon.sub.html
@@ -0,0 +1,75 @@
+<!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 HTML "link" element with rel="icon"</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/fetch/metadata/resources/helper.sub.js"></script>
+ <body>
+ <script>
+ 'use strict';
+
+ const params = {
+ body: `
+ <svg xmlns="http://www.w3.org/2000/svg" width="123" height="123">
+ <rect fill="lime" width="123" height="123"/>
+ </svg>
+ `,
+ mime: 'image/svg+xml'
+ };
+
+ /**
+ * The `link` element supports a `load` event. That event would reliably
+ * indicate that the browser had received the request. Multiple major
+ * browsers do not implement the event, however, so in order to promote the
+ * visibility of this test, a less efficient polling-based detection
+ * mechanism is used.
+ *
+ * https://bugzilla.mozilla.org/show_bug.cgi?id=1638188
+ * https://bugs.chromium.org/p/chromium/issues/detail?id=1083034
+ */
+ function induceRequest(t, url, attributes) {
+ const link = document.createElement('link');
+ link.setAttribute('rel', 'icon');
+ link.setAttribute('href', url);
+
+ for (const [ name, value ] of Object.entries(attributes)) {
+ link.setAttribute(name, value);
+ }
+
+ document.head.appendChild(link);
+ t.add_cleanup(() => link.remove());
+ }
+
+ {%- for subtest in subtests %}
+
+ promise_test((t) => {
+ const key = '{{uuid()}}';
+
+ induceRequest(
+ t,
+ makeRequestURL(key, [% subtest.origins %], params),
+ [%subtest.elementAttrs | default({}) | tojson%]
+ );
+
+ return retrieve(key, {poll:true})
+ .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("start", " - ")%] [%subtest.elementAttrs | collection("attributes")%]');
+
+ {%- endfor %}
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/fetch/metadata/tools/templates/element-link-prefetch.optional.sub.html b/testing/web-platform/tests/fetch/metadata/tools/templates/element-link-prefetch.optional.sub.html
new file mode 100644
index 0000000000..59d677d8d6
--- /dev/null
+++ b/testing/web-platform/tests/fetch/metadata/tools/templates/element-link-prefetch.optional.sub.html
@@ -0,0 +1,71 @@
+<!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 HTML "link" element with rel="prefetch"</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/fetch/metadata/resources/helper.sub.js"></script>
+ <body>
+ <script>
+ 'use strict';
+
+ /**
+ * The `link` element supports a `load` event. That event would reliably
+ * indicate that the browser had received the request. Multiple major
+ * browsers do not implement the event, however, so in order to promote the
+ * visibility of this test, a less efficient polling-based detection
+ * mechanism is used.
+ *
+ * https://bugzilla.mozilla.org/show_bug.cgi?id=1638188
+ * https://bugs.chromium.org/p/chromium/issues/detail?id=1083034
+ */
+ function induceRequest(t, url, attributes) {
+ const link = document.createElement('link');
+ link.setAttribute('rel', 'prefetch');
+ link.setAttribute('href', url);
+
+ for (const [ name, value ] of Object.entries(attributes)) {
+ link.setAttribute(name, value);
+ }
+
+ document.head.appendChild(link);
+ t.add_cleanup(() => link.remove());
+ }
+
+ setup(() => {
+ assert_implements_optional(document.createElement('link').relList.supports('prefetch'));
+ });
+
+ {%- for subtest in subtests %}
+
+ promise_test((t) => {
+ const key = '{{uuid()}}';
+
+ induceRequest(
+ t,
+ makeRequestURL(key, [% subtest.origins %]),
+ [%subtest.elementAttrs | default({}) | tojson%]
+ );
+
+ return retrieve(key, {poll:true})
+ .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("start", " - ")%] [%subtest.elementAttrs | collection("attributes")%]');
+
+ {%- endfor %}
+ </script>
+ </body>
+</html>
+
diff --git a/testing/web-platform/tests/fetch/metadata/tools/templates/element-meta-refresh.optional.sub.html b/testing/web-platform/tests/fetch/metadata/tools/templates/element-meta-refresh.optional.sub.html
new file mode 100644
index 0000000000..5a8d8f8ecd
--- /dev/null
+++ b/testing/web-platform/tests/fetch/metadata/tools/templates/element-meta-refresh.optional.sub.html
@@ -0,0 +1,60 @@
+<!DOCTYPE html>
+<!--
+[%provenance%]
+-->
+<html lang="en">
+ <meta charset="utf-8">
+ <title>HTTP headers on request for HTML "meta" element with http-equiv="refresh"</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/fetch/metadata/resources/helper.sub.js"></script>
+ <body>
+ <script>
+ 'use strict';
+
+ function induceRequest(url, test) {
+ const win = window.open();
+ test.add_cleanup(() => win.close());
+
+ win.document.open();
+ win.document.write(
+ `<meta http-equiv="Refresh" content="0; URL=${url}">`
+ );
+ win.document.close();
+
+ return new Promise((resolve) => {
+ addEventListener('message', (event) => {
+ if (event.source === win) {
+ resolve();
+ }
+ });
+ });
+ }
+
+ const responseParams = {
+ mime: 'text/html',
+ body: `<script>opener.postMessage(0, '*')</${''}script>`
+ };
+ {%- for subtest in subtests %}
+
+ promise_test((t) => {
+ const key = '{{uuid()}}';
+
+ return induceRequest(
+ makeRequestURL(key, [% subtest.origins %], responseParams), t
+ )
+ .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("start", " - ")%]');
+
+ {%- endfor %}
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/fetch/metadata/tools/templates/element-picture.sub.html b/testing/web-platform/tests/fetch/metadata/tools/templates/element-picture.sub.html
new file mode 100644
index 0000000000..903aeed1f3
--- /dev/null
+++ b/testing/web-platform/tests/fetch/metadata/tools/templates/element-picture.sub.html
@@ -0,0 +1,101 @@
+<!DOCTYPE html>
+<!--
+[%provenance%]
+-->
+<html lang="en">
+ <meta charset="utf-8">
+ <title>HTTP headers on request for HTML "picture" element source</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/fetch/metadata/resources/helper.sub.js"></script>
+ <body>
+ <script>
+ 'use strict';
+
+ function induceRequest(url, sourceEl, sourceAttr, attributes) {
+ const picture = document.createElement('picture');
+ const els = {
+ img: document.createElement('img'),
+ source: document.createElement('source')
+ };
+ picture.appendChild(els.source);
+ picture.appendChild(els.img);
+ document.body.appendChild(picture);
+
+ for (const [ name, value ] of Object.entries(attributes)) {
+ els.img.setAttribute(name, value);
+ }
+
+ return new Promise((resolve) => {
+ els[sourceEl].setAttribute(sourceAttr, url);
+ els.img.onload = els.img.onerror = resolve;
+ });
+ }
+
+ {%- for subtest in subtests %}
+
+ promise_test(() => {
+ const key = '{{uuid()}}';
+
+ return induceRequest(
+ makeRequestURL(key, [% subtest.origins %]),
+ 'img',
+ 'src',
+ [%subtest.elementAttrs | default({}) | tojson%]
+ )
+ .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%] - img[src] - [%subtest.description | pad("end", ", ")%][%subtest.elementAttrs | collection("attributes")%]');
+
+ promise_test(() => {
+ const key = '{{uuid()}}';
+
+ return induceRequest(
+ makeRequestURL(key, [% subtest.origins %]),
+ 'img',
+ 'srcset',
+ [%subtest.elementAttrs | default({}) | tojson%]
+ )
+ .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%] - img[srcset] - [%subtest.description | pad("end", ", ")%][%subtest.elementAttrs | collection("attributes")%]');
+
+ promise_test(() => {
+ const key = '{{uuid()}}';
+
+ return induceRequest(
+ makeRequestURL(key, [% subtest.origins %]),
+ 'source',
+ 'srcset',
+ [%subtest.elementAttrs | default({}) | tojson%]
+ )
+ .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%] - source[srcset] - [%subtest.description | pad("end", ", ")%][%subtest.elementAttrs | collection("attributes")%]');
+
+ {%- endfor %}
+ </script>
+ </body>
+</html>
+
diff --git a/testing/web-platform/tests/fetch/metadata/tools/templates/element-script.sub.html b/testing/web-platform/tests/fetch/metadata/tools/templates/element-script.sub.html
new file mode 100644
index 0000000000..4a281ae519
--- /dev/null
+++ b/testing/web-platform/tests/fetch/metadata/tools/templates/element-script.sub.html
@@ -0,0 +1,54 @@
+<!DOCTYPE html>
+<!--
+[%provenance%]
+-->
+<html lang="en">
+ <meta charset="utf-8">
+ <title>HTTP headers on request for HTML "script" element source</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/fetch/metadata/resources/helper.sub.js"></script>
+ <body>
+ <script>
+ 'use strict';
+
+ function induceRequest(url, attributes) {
+ const script = document.createElement('script');
+ script.setAttribute('src', url);
+
+ for (const [ name, value ] of Object.entries(attributes)) {
+ script.setAttribute(name, value);
+ }
+
+ return new Promise((resolve, reject) => {
+ script.onload = resolve;
+ script.onerror = () => reject('Failed to load script');
+ document.body.appendChild(script);
+ })
+ .then(() => script.remove());
+ }
+ {%- for subtest in subtests %}
+
+ promise_test(() => {
+ const key = '{{uuid()}}';
+ const url = makeRequestURL(
+ key, [% subtest.origins %], { mime: 'application/javascript' }
+ );
+
+ return induceRequest(url,
+ [%subtest.elementAttrs | default({}) | tojson%]
+ )
+ .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", ", ")%][%-subtest.elementAttrs | collection("attributes")%]');
+
+ {%- endfor %}
+ </script>
+</html>
diff --git a/testing/web-platform/tests/fetch/metadata/tools/templates/element-video-poster.sub.html b/testing/web-platform/tests/fetch/metadata/tools/templates/element-video-poster.sub.html
new file mode 100644
index 0000000000..9cdaf063ac
--- /dev/null
+++ b/testing/web-platform/tests/fetch/metadata/tools/templates/element-video-poster.sub.html
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<!--
+[%provenance%]
+-->
+<html lang="en">
+ <meta charset="utf-8">
+ <title>HTTP headers on request for HTML "video" element "poster"</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/fetch/metadata/resources/helper.sub.js"></script>
+ <body>
+ <script>
+ 'use strict';
+
+ const params = {
+ body: `
+ <svg xmlns="http://www.w3.org/2000/svg" width="123" height="123">
+ <rect fill="lime" width="123" height="123"/>
+ </svg>
+ `,
+ mime: 'image/svg+xml'
+ };
+
+ function induceRequest(t, url) {
+ var video = document.createElement('video');
+ video.setAttribute('poster', url);
+ document.body.appendChild(video);
+
+ const poll = () => {
+ if (video.clientWidth === 123) {
+ return;
+ }
+
+ return new Promise((resolve) => t.step_timeout(resolve, 0))
+ .then(poll);
+ };
+ t.add_cleanup(() => video.remove());
+
+ return poll();
+ }
+
+ {%- for subtest in subtests %}
+
+ promise_test((t) => {
+ const key = '{{uuid()}}';
+
+ return induceRequest(t, makeRequestURL(key, [% subtest.origins %], params))
+ .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("start", " - ")%]');
+
+ {%- endfor %}
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/fetch/metadata/tools/templates/element-video.sub.html b/testing/web-platform/tests/fetch/metadata/tools/templates/element-video.sub.html
new file mode 100644
index 0000000000..1b7b976d7c
--- /dev/null
+++ b/testing/web-platform/tests/fetch/metadata/tools/templates/element-video.sub.html
@@ -0,0 +1,51 @@
+<!DOCTYPE html>
+<!--
+[%provenance%]
+-->
+<html lang="en">
+ <meta charset="utf-8">
+ <title>HTTP headers on request for HTML "video" element source</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/fetch/metadata/resources/helper.sub.js"></script>
+ <body>
+ <script>
+ 'use strict';
+
+ function induceRequest(url, attributes) {
+ const video = document.createElement('video');
+
+ for (const [ name, value ] of Object.entries(attributes)) {
+ video.setAttribute(name, value);
+ }
+
+ return new Promise((resolve) => {
+ video.setAttribute('src', url);
+ video.onload = video.onerror = resolve;
+ });
+ }
+
+ {%- for subtest in subtests %}
+
+ promise_test(() => {
+ const key = '{{uuid()}}';
+
+ return induceRequest(
+ makeRequestURL(key, [% subtest.origins %]),
+ [%subtest.elementAttrs | default({}) | tojson%]
+ )
+ .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", ", ")%][%subtest.elementAttrs | collection("attributes")%]');
+
+ {%- endfor %}
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/fetch/metadata/tools/templates/fetch-via-serviceworker.https.sub.html b/testing/web-platform/tests/fetch/metadata/tools/templates/fetch-via-serviceworker.https.sub.html
new file mode 100644
index 0000000000..eead710200
--- /dev/null
+++ b/testing/web-platform/tests/fetch/metadata/tools/templates/fetch-via-serviceworker.https.sub.html
@@ -0,0 +1,88 @@
+<!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 using the "fetch" API and passing through a Serive Worker</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script>
+ <script src="/fetch/metadata/resources/helper.sub.js"></script>
+ <body>
+ <script>
+ 'use strict';
+
+ const scripts = {
+ fallback: '/fetch/metadata/resources/fetch-via-serviceworker--fallback--sw.js',
+ respondWith: '/fetch/metadata/resources/fetch-via-serviceworker--respondWith--sw.js'
+ };
+
+ function induceRequest(t, url, init, script) {
+ const SCOPE = '/fetch/metadata/resources/fetch-via-serviceworker-frame.html';
+ const SCRIPT = scripts[script];
+
+ return service_worker_unregister_and_register(t, SCRIPT, SCOPE)
+ .then((registration) => {
+ t.add_cleanup(() => registration.unregister());
+
+ return wait_for_state(t, registration.installing, 'activated');
+ })
+ .then(() => with_iframe(SCOPE))
+ .then((frame) => {
+ t.add_cleanup(() => frame.remove());
+
+ return frame.contentWindow.fetch(url, init);
+ });
+ }
+
+ {%- for subtest in subtests %}
+
+ promise_test((t) => {
+ const key = '{{uuid()}}';
+
+ return induceRequest(
+ t,
+ makeRequestURL(key, [% subtest.origins %]),
+ [%subtest.init | default({}) | tojson%],
+ 'respondWith'
+ )
+ .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", ", ")%][%subtest.init | collection("init")%] - respondWith');
+
+ promise_test((t) => {
+ const key = '{{uuid()}}';
+
+ return induceRequest(
+ t,
+ makeRequestURL(key, [% subtest.origins %]),
+ [%subtest.init | default({}) | tojson%],
+ 'fallback'
+ )
+ .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", ", ")%][%subtest.init | collection("init")%] - fallback');
+
+ {%- endfor %}
+
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/fetch/metadata/tools/templates/fetch.sub.html b/testing/web-platform/tests/fetch/metadata/tools/templates/fetch.sub.html
new file mode 100644
index 0000000000..a8dc5368f8
--- /dev/null
+++ b/testing/web-platform/tests/fetch/metadata/tools/templates/fetch.sub.html
@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<!--
+[%provenance%]
+-->
+<html lang="en">
+ <meta charset="utf-8">
+ <title>HTTP headers on request using the "fetch" API</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/fetch/metadata/resources/helper.sub.js"></script>
+ <body>
+ <script>
+ 'use strict';
+
+ function induceRequest(url, init) {
+ return fetch(url, init);
+ }
+
+ {%- for subtest in subtests %}
+
+ promise_test(() => {
+ const key = '{{uuid()}}';
+
+ return induceRequest(
+ makeRequestURL(key, [% subtest.origins %]),
+ [%subtest.init | default({}) | tojson%]
+ )
+ .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", ", ")%][%subtest.init | collection("init")%]');
+
+ {%- endfor %}
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/fetch/metadata/tools/templates/form-submission.sub.html b/testing/web-platform/tests/fetch/metadata/tools/templates/form-submission.sub.html
new file mode 100644
index 0000000000..4c9c8c50f8
--- /dev/null
+++ b/testing/web-platform/tests/fetch/metadata/tools/templates/form-submission.sub.html
@@ -0,0 +1,87 @@
+<!DOCTYPE html>
+<!--
+[%provenance%]
+-->
+<html lang="en">
+ <meta charset="utf-8">
+ <meta name="timeout" content="long">
+ <title>HTTP headers on request for HTML form navigation</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(method, url, userActivated) {
+ const windowName = String(Math.random());
+ const form = document.createElement('form');
+ const submit = document.createElement('input');
+ submit.setAttribute('type', 'submit');
+ form.appendChild(submit);
+ const win = open('about:blank', windowName);
+ form.setAttribute('method', method);
+ form.setAttribute('action', url);
+ form.setAttribute('target', windowName);
+ document.body.appendChild(form);
+
+ // Query parameters must be expressed as form values so that they are sent
+ // with the submission of forms whose method is POST.
+ Array.from(new URL(url, location.origin).searchParams)
+ .forEach(([name, value]) => {
+ const input = document.createElement('input');
+ input.setAttribute('type', 'hidden');
+ input.setAttribute('name', name);
+ input.setAttribute('value', value);
+ form.appendChild(input);
+ });
+
+ return new Promise((resolve) => {
+ addEventListener('message', function(event) {
+ if (event.source === win) {
+ resolve();
+ }
+ });
+
+ if (userActivated) {
+ test_driver.click(submit);
+ } else {
+ submit.click();
+ }
+ })
+ .then(() => {
+ form.remove();
+ 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 userActivated = [% 'true' if subtest.userActivated else 'false' %];
+ return induceRequest('[%subtest.method | default("POST")%]', url, userActivated)
+ .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", " - ")%][%subtest.method | default("POST")%][%" with user activation" if subtest.userActivated%]');
+
+ {%- endfor %}
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/fetch/metadata/tools/templates/header-link.sub.html b/testing/web-platform/tests/fetch/metadata/tools/templates/header-link.sub.html
new file mode 100644
index 0000000000..2831f221d5
--- /dev/null
+++ b/testing/web-platform/tests/fetch/metadata/tools/templates/header-link.sub.html
@@ -0,0 +1,56 @@
+<!DOCTYPE html>
+<!--
+[%provenance%]
+-->
+<html lang="en">
+ <meta charset="utf-8">
+ <title>HTTP headers on request for HTTP "Link" header</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/fetch/metadata/resources/helper.sub.js"></script>
+ <body>
+ <script>
+ 'use strict';
+
+ function induceRequest(url, rel, test) {
+ const iframe = document.createElement('iframe');
+
+ iframe.setAttribute(
+ 'src',
+ '/fetch/metadata/resources/header-link.py' +
+ `?location=${encodeURIComponent(url)}&rel=${rel}`
+ );
+
+ document.body.appendChild(iframe);
+ test.add_cleanup(() => iframe.remove());
+
+ return new Promise((resolve) => {
+ iframe.onload = iframe.onerror = resolve;
+ });
+ }
+
+ {%- for subtest in subtests %}
+
+ promise_test((t) => {
+ const key = '{{uuid()}}';
+
+ return induceRequest(
+ makeRequestURL(key, [% subtest.origins %], {mime: 'text/html'}),
+ '[%subtest.rel%]',
+ t
+ )
+ .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%] rel=[%subtest.rel%][%subtest.description | pad("start", " - ")%]');
+
+ {%- endfor %}
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/fetch/metadata/tools/templates/header-refresh.optional.sub.html b/testing/web-platform/tests/fetch/metadata/tools/templates/header-refresh.optional.sub.html
new file mode 100644
index 0000000000..ec963d5cc0
--- /dev/null
+++ b/testing/web-platform/tests/fetch/metadata/tools/templates/header-refresh.optional.sub.html
@@ -0,0 +1,59 @@
+<!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 HTTP "Refresh" header</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/fetch/metadata/resources/helper.sub.js"></script>
+ <body>
+ <script>
+ 'use strict';
+
+ function induceRequest(url, test) {
+ const win = window.open();
+ test.add_cleanup(() => win.close());
+
+ win.location = `/common/refresh.py?location=${encodeURIComponent(url)}`
+
+ return new Promise((resolve) => {
+ addEventListener('message', (event) => {
+ if (event.source === win) {
+ resolve();
+ }
+ });
+ });
+ }
+
+ const responseParams = {
+ mime: 'text/html',
+ body: `<script>opener.postMessage(0, '*')</${''}script>`
+ };
+ {%- for subtest in subtests %}
+
+ promise_test((t) => {
+ const key = '{{uuid()}}';
+
+ return induceRequest(
+ makeRequestURL(key, [% subtest.origins %], responseParams), t
+ )
+ .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("start", " - ")%]');
+
+ {%- endfor %}
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/fetch/metadata/tools/templates/script-module-import-dynamic.sub.html b/testing/web-platform/tests/fetch/metadata/tools/templates/script-module-import-dynamic.sub.html
new file mode 100644
index 0000000000..653d3cdec4
--- /dev/null
+++ b/testing/web-platform/tests/fetch/metadata/tools/templates/script-module-import-dynamic.sub.html
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<!--
+[%provenance%]
+-->
+<html lang="en">
+ <meta charset="utf-8">
+ <title>HTTP headers on request for dynamic ECMAScript module import</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/fetch/metadata/resources/helper.sub.js"></script>
+ <script type="module">
+ 'use strict';
+ {%- for subtest in subtests %}
+
+ promise_test(() => {
+ const key = '{{uuid()}}';
+ const url = makeRequestURL(
+ key, [% subtest.origins %], { mime: 'application/javascript' }
+ );
+
+ return import(url)
+ .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("start", " - ")%]');
+
+ {%- endfor %}
+ </script>
+</html>
diff --git a/testing/web-platform/tests/fetch/metadata/tools/templates/script-module-import-static.sub.html b/testing/web-platform/tests/fetch/metadata/tools/templates/script-module-import-static.sub.html
new file mode 100644
index 0000000000..c8d5f9532a
--- /dev/null
+++ b/testing/web-platform/tests/fetch/metadata/tools/templates/script-module-import-static.sub.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html>
+<!--
+[%provenance%]
+-->
+<html lang="en">
+ <meta charset="utf-8">
+ <title>HTTP headers on request for static ECMAScript module import</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/fetch/metadata/resources/helper.sub.js"></script>
+ <body>
+ <script>
+ 'use strict';
+
+ function induceRequest(url) {
+ const script = document.createElement('script');
+ script.setAttribute('type', 'module');
+ script.setAttribute(
+ 'src',
+ '/fetch/metadata/resources/es-module.sub.js?moduleId=' + encodeURIComponent(url)
+ );
+
+ return new Promise((resolve, reject) => {
+ script.onload = resolve;
+ script.onerror = () => reject('Failed to load script');
+ document.body.appendChild(script);
+ })
+ .then(() => script.remove());
+ }
+ {%- for subtest in subtests %}
+
+ promise_test(() => {
+ const key = '{{uuid()}}';
+
+ return induceRequest(
+ makeRequestURL(
+ key, [% subtest.origins %], { mime: 'application/javascript' }
+ )
+ )
+ .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("start", " - ")%]');
+
+ {%- endfor %}
+ </script>
+</html>
diff --git a/testing/web-platform/tests/fetch/metadata/tools/templates/serviceworker.https.sub.html b/testing/web-platform/tests/fetch/metadata/tools/templates/serviceworker.https.sub.html
new file mode 100644
index 0000000000..8284325546
--- /dev/null
+++ b/testing/web-platform/tests/fetch/metadata/tools/templates/serviceworker.https.sub.html
@@ -0,0 +1,72 @@
+<!DOCTYPE html>
+<!--
+[%provenance%]
+-->
+<!DOCTYPE html>
+<html lang="en">
+ <meta charset="utf-8">
+ <title>HTTP headers on request for Service Workers</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/fetch/metadata/resources/helper.sub.js"></script>
+ <body>
+ <script>
+ 'use strict';
+
+ function induceRequest(t, url, options, event, clear) {
+ // Register a service worker and check the request header.
+ return navigator.serviceWorker.register(url, options)
+ .then((registration) => {
+ t.add_cleanup(() => registration.unregister());
+ if (event === 'register') {
+ return;
+ }
+ return clear().then(() => registration.update());
+ });
+ }
+
+ {%- for subtest in subtests %}
+ {%- set origin = subtest.origins[0]|default('httpsOrigin') %}
+ {%- if origin == 'httpsOrigin' or not origin %}
+
+ promise_test((t) => {
+ const key = '{{uuid()}}';
+ const url = makeRequestURL(
+ key, [% subtest.origins %], { mime: 'application/javascript' }
+ );
+
+ return induceRequest(t, url, [%subtest.options | default({}) | tojson%], 'register')
+ .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", ", ")%][%subtest.options | collection("options")%] - registration');
+
+ promise_test((t) => {
+ const key = '{{uuid()}}';
+ const url = makeRequestURL(
+ key, [% subtest.origins %], { mime: 'application/javascript' }
+ );
+
+ return induceRequest(t, url, [%subtest.options | default({}) | tojson%], 'update', () => retrieve(key))
+ .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", ", ")%][%subtest.options | collection("options")%] - updating');
+
+ {%- endif %}
+ {%- endfor %}
+ </script>
+</body>
+</html>
diff --git a/testing/web-platform/tests/fetch/metadata/tools/templates/svg-image.sub.html b/testing/web-platform/tests/fetch/metadata/tools/templates/svg-image.sub.html
new file mode 100644
index 0000000000..52f7806b33
--- /dev/null
+++ b/testing/web-platform/tests/fetch/metadata/tools/templates/svg-image.sub.html
@@ -0,0 +1,75 @@
+<!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 SVG "image" element source</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/fetch/metadata/resources/helper.sub.js"></script>
+ <body>
+ <script>
+ 'use strict';
+
+ const params = {
+ body: `
+ <svg xmlns="http://www.w3.org/2000/svg" width="123" height="123">
+ <rect fill="lime" width="123" height="123"/>
+ </svg>
+ `,
+ mime: 'image/svg+xml'
+ };
+
+ function induceRequest(t, url, attributes) {
+ const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
+ svg.setAttributeNS(
+ "http://www.w3.org/2000/xmlns/",
+ "xmlns:xlink",
+ "http://www.w3.org/1999/xlink"
+ );
+ const image = document.createElementNS("http://www.w3.org/2000/svg", "image");
+ image.setAttribute("href", url);
+ svg.appendChild(image);
+
+ for (const [ name, value ] of Object.entries(attributes)) {
+ image.setAttribute(name, value);
+ }
+
+ document.body.appendChild(svg);
+ t.add_cleanup(() => svg.remove());
+
+ return new Promise((resolve, reject) => {
+ image.onload = resolve;
+ image.onerror = reject;
+ });
+ }
+
+ {%- for subtest in subtests %}
+
+ promise_test((t) => {
+ const key = '{{uuid()}}';
+
+ return induceRequest(
+ t,
+ makeRequestURL(key, [% subtest.origins %], params),
+ [%subtest.elementAttrs | default({}) | tojson%]
+ )
+ .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("start", " - ")%] [%subtest.elementAttrs | collection("attributes")%]');
+
+ {%- endfor %}
+ </script>
+ </body>
+</html>
diff --git a/testing/web-platform/tests/fetch/metadata/tools/templates/window-history.sub.html b/testing/web-platform/tests/fetch/metadata/tools/templates/window-history.sub.html
new file mode 100644
index 0000000000..286d019887
--- /dev/null
+++ b/testing/web-platform/tests/fetch/metadata/tools/templates/window-history.sub.html
@@ -0,0 +1,134 @@
+<!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 History 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';
+
+ const whenDone = (win) => {
+ return new Promise((resolve) => {
+ addEventListener('message', function handle(event) {
+ if (event.source === win) {
+ resolve();
+ removeEventListener('message', handle);
+ }
+ });
+ })
+ };
+
+ /**
+ * Prime the UA's session history such that the location of the request is
+ * immediately behind the current entry. Because the location may not be
+ * same-origin with the current browsing context, this must be done via a
+ * true navigation and not, e.g. the `history.pushState` API. The initial
+ * navigation will alter the WPT server's internal state; in order to avoid
+ * false positives, clear that state prior to initiating the second
+ * navigation via `history.back`.
+ */
+ function induceBackRequest(url, test, clear) {
+ const win = window.open(url);
+
+ test.add_cleanup(() => win.close());
+
+ return whenDone(win)
+ .then(clear)
+ .then(() => win.history.back())
+ .then(() => whenDone(win));
+ }
+
+ /**
+ * Prime the UA's session history such that the location of the request is
+ * immediately ahead of the current entry. Because the location may not be
+ * same-origin with the current browsing context, this must be done via a
+ * true navigation and not, e.g. the `history.pushState` API. The initial
+ * navigation will alter the WPT server's internal state; in order to avoid
+ * false positives, clear that state prior to initiating the second
+ * navigation via `history.forward`.
+ */
+ function induceForwardRequest(url, test, clear) {
+ const win = window.open(messageOpenerUrl);
+
+ test.add_cleanup(() => win.close());
+
+ return whenDone(win)
+ .then(() => win.location = url)
+ .then(() => whenDone(win))
+ .then(clear)
+ .then(() => win.history.go(-2))
+ .then(() => whenDone(win))
+ .then(() => win.history.forward())
+ .then(() => whenDone(win));
+ }
+
+ const messageOpenerUrl = new URL(
+ '/fetch/metadata/resources/message-opener.html', location
+ );
+ // For these tests to function, replacement must *not* be enabled during
+ // navigation. Assignment must therefore take place after the document has
+ // completely loaded [1]. This event is not directly observable, but it is
+ // scheduled as a task immediately following the global object's `load`
+ // event [2]. By queuing a task during the dispatch of the `load` event,
+ // navigation can be consistently triggered without replacement.
+ //
+ // [1] https://html.spec.whatwg.org/multipage/history.html#location-object-setter-navigate
+ // [2] https://html.spec.whatwg.org/multipage/parsing.html#the-end
+ const responseParams = {
+ mime: 'text/html',
+ body: `<script>
+ window.addEventListener('load', () => {
+ set`+`Timeout(() => location.assign('${messageOpenerUrl}'));
+ });
+ <`+`/script>`
+ };
+ {%- for subtest in subtests %}
+
+ promise_test((t) => {
+ const key = '{{uuid()}}';
+ const url = makeRequestURL(key, [% subtest.origins %], responseParams);
+
+ return induceBackRequest(url, t, () => retrieve(key))
+ .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("right", " - ")%]history.back[%subtest.api%][% " with user activation" if subtest.userActivated%]');
+
+ promise_test((t) => {
+ const key = '{{uuid()}}';
+ const url = makeRequestURL(key, [% subtest.origins %], responseParams);
+
+ return induceForwardRequest(url, t, () => retrieve(key))
+ .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("right", " - ")%]history.forward[%subtest.api%][% " with user activation" if subtest.userActivated%]');
+
+ {%- endfor %}
+ </script>
+ </body>
+</html>
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>
diff --git a/testing/web-platform/tests/fetch/metadata/tools/templates/worker-dedicated-constructor.sub.html b/testing/web-platform/tests/fetch/metadata/tools/templates/worker-dedicated-constructor.sub.html
new file mode 100644
index 0000000000..fede5965d3
--- /dev/null
+++ b/testing/web-platform/tests/fetch/metadata/tools/templates/worker-dedicated-constructor.sub.html
@@ -0,0 +1,49 @@
+<!DOCTYPE html>
+<!--
+[%provenance%]
+-->
+<html lang="en">
+ <meta charset="utf-8">
+ <title>HTTP headers on request for dedicated worker via the "Worker" constructor</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/fetch/metadata/resources/helper.sub.js"></script>
+ <script type="module">
+ 'use strict';
+ function induceRequest(url, options) {
+ return new Promise((resolve, reject) => {
+ const worker = new Worker(url, options);
+ worker.onmessage = resolve;
+ worker.onerror = reject;
+ });
+ }
+
+ {%- for subtest in subtests %}
+
+ promise_test(() => {
+ const key = '{{uuid()}}';
+ const url = makeRequestURL(
+ key,
+ [% subtest.origins %],
+ { mime: 'application/javascript', body: 'postMessage("")' }
+ );
+
+ return induceRequest(url
+ {%- if subtest.options -%}
+ , [% subtest.options | tojson %]
+ {%- endif -%}
+ )
+ .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", ", ")%][%subtest.options|collection("options")%]');
+
+ {%- endfor %}
+ </script>
+</html>
diff --git a/testing/web-platform/tests/fetch/metadata/tools/templates/worker-dedicated-importscripts.sub.html b/testing/web-platform/tests/fetch/metadata/tools/templates/worker-dedicated-importscripts.sub.html
new file mode 100644
index 0000000000..93e6374d54
--- /dev/null
+++ b/testing/web-platform/tests/fetch/metadata/tools/templates/worker-dedicated-importscripts.sub.html
@@ -0,0 +1,54 @@
+<!DOCTYPE html>
+<!--
+[%provenance%]
+-->
+<html lang="en">
+ <meta charset="utf-8">
+ <title>HTTP headers on request for dedicated worker via the "importScripts" API</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src="/fetch/metadata/resources/helper.sub.js"></script>
+ <script type="module">
+ 'use strict';
+ function induceRequest(url, options) {
+ const src = `
+ importScripts('${url}');
+ postMessage('done');
+ `;
+ const workerUrl = URL.createObjectURL(
+ new Blob([src], { type: 'application/javascript' })
+ );
+ return new Promise((resolve, reject) => {
+ const worker = new Worker(workerUrl, options);
+ worker.onmessage = resolve;
+ worker.onerror = reject;
+ });
+ }
+
+ {%- for subtest in subtests %}
+
+ promise_test(() => {
+ const key = '{{uuid()}}';
+ const url = makeRequestURL(
+ key, [% subtest.origins %], { mime: 'application/javascript' }
+ );
+
+ return induceRequest(url
+ {%- if subtest.options -%}
+ , [% subtest.options | tojson %]
+ {%- endif -%}
+ )
+ .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("start", " - ")%]');
+
+ {%- endfor %}
+ </script>
+</html>