summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/url/percent-encoding.window.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/url/percent-encoding.window.js
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--testing/web-platform/tests/url/percent-encoding.window.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/testing/web-platform/tests/url/percent-encoding.window.js b/testing/web-platform/tests/url/percent-encoding.window.js
new file mode 100644
index 0000000000..dcb5c1e55b
--- /dev/null
+++ b/testing/web-platform/tests/url/percent-encoding.window.js
@@ -0,0 +1,33 @@
+promise_test(() => fetch("resources/percent-encoding.json").then(res => res.json()).then(runTests), "Loading data…");
+
+function runTests(testUnits) {
+ for (const testUnit of testUnits) {
+ // Ignore comments
+ if (typeof testUnit === "string") {
+ continue;
+ }
+ for (const encoding of Object.keys(testUnit.output)) {
+ async_test(t => {
+ const frame = document.body.appendChild(document.createElement("iframe"));
+ t.add_cleanup(() => frame.remove());
+ frame.onload = t.step_func_done(() => {
+ const output = frame.contentDocument.querySelector("a");
+ // Test that the fragment is always UTF-8 encoded
+ assert_equals(output.hash, `#${testUnit.output["utf-8"]}`, "fragment");
+ assert_equals(output.search, `?${testUnit.output[encoding]}`, "query");
+ });
+ frame.src = `resources/percent-encoding.py?encoding=${encoding}&value=${toBase64(testUnit.input)}`;
+ }, `Input ${testUnit.input} with encoding ${encoding}`);
+ }
+ }
+}
+
+// Use base64 to avoid relying on the URL parser to get UTF-8 percent-encoding correctly. This does
+// not use btoa directly as that only works with code points in the range U+0000 to U+00FF,
+// inclusive.
+function toBase64(input) {
+ const bytes = new TextEncoder().encode(input);
+ const byteString = Array.from(bytes, byte => String.fromCharCode(byte)).join("");
+ const encoded = self.btoa(byteString);
+ return encoded;
+}