diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /testing/web-platform/tests/url/percent-encoding.window.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/url/percent-encoding.window.js')
-rw-r--r-- | testing/web-platform/tests/url/percent-encoding.window.js | 33 |
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; +} |