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/content-type/script.window.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/fetch/content-type/script.window.js')
-rw-r--r-- | testing/web-platform/tests/fetch/content-type/script.window.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/testing/web-platform/tests/fetch/content-type/script.window.js b/testing/web-platform/tests/fetch/content-type/script.window.js new file mode 100644 index 0000000000..31598957ef --- /dev/null +++ b/testing/web-platform/tests/fetch/content-type/script.window.js @@ -0,0 +1,48 @@ +promise_test(() => { + return fetch("resources/script-content-types.json").then(res => res.json()).then(runTests); +}, "Loading JSON…"); + +self.stringFromExecutedScript = undefined; + +function runTests(allTestData) { + allTestData.forEach(testData => { + runScriptTest(testData, false); + if (testData.contentType.length > 1) { + runScriptTest(testData, true); + } + }); +} + +function runScriptTest(testData, singleHeader) { + async_test(t => { + const script = document.createElement("script"); + t.add_cleanup(() => { + script.remove() + self.stringFromExecutedScript = undefined; + }); + script.src = getURL(testData.contentType, singleHeader); + document.head.appendChild(script); + if (testData.executes) { + script.onload = t.step_func_done(() => { + assert_equals(self.stringFromExecutedScript, testData.encoding === "windows-1252" ? "€" : "€"); + }); + script.onerror = t.unreached_func("onerror"); + } else { + script.onerror = t.step_func_done(); + script.onload = t.unreached_func("onload"); + } + }, (singleHeader ? "combined" : "separate") + " " + testData.contentType.join(" ")); +} + +function getURL(input, singleHeader) { + // Edge does not support URLSearchParams + let url = "resources/content-type.py?" + if (singleHeader) { + url += "single_header&" + } + input.forEach(val => { + url += "value=" + encodeURIComponent(val) + "&"; + }); + url += "&content=" + encodeURIComponent("self.stringFromExecutedScript = \"€\""); + return url; +} |