summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/url/IdnaTestV2.window.js
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/url/IdnaTestV2.window.js
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/url/IdnaTestV2.window.js')
-rw-r--r--testing/web-platform/tests/url/IdnaTestV2.window.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/testing/web-platform/tests/url/IdnaTestV2.window.js b/testing/web-platform/tests/url/IdnaTestV2.window.js
new file mode 100644
index 0000000000..8873886bda
--- /dev/null
+++ b/testing/web-platform/tests/url/IdnaTestV2.window.js
@@ -0,0 +1,41 @@
+promise_test(() => fetch("resources/IdnaTestV2.json").then(res => res.json()).then(runTests), "Loading data…");
+
+// Performance impact of this seems negligible (performance.now() diff in WebKit went from 48 to 52)
+// and there was a preference to let more non-ASCII hit the parser.
+function encodeHostEndingCodePoints(input) {
+ let output = "";
+ for (const codePoint of input) {
+ if ([":", "/", "?", "#", "\\"].includes(codePoint)) {
+ output += encodeURIComponent(codePoint);
+ } else {
+ output += codePoint;
+ }
+ }
+ return output;
+}
+
+function runTests(idnaTests) {
+ for (const idnaTest of idnaTests) {
+ if (typeof idnaTest === "string") {
+ continue // skip comments
+ }
+ if (idnaTest.input === "") {
+ continue // cannot test empty string input through new URL()
+ }
+ // Percent-encode the input such that ? and equivalent code points do not end up counting as
+ // part of the URL, but are parsed through the host parser instead.
+ const encodedInput = encodeHostEndingCodePoints(idnaTest.input);
+
+ test(() => {
+ if (idnaTest.output === null) {
+ assert_throws_js(TypeError, () => new URL(`https://${encodedInput}/x`));
+ } else {
+ const url = new URL(`https://${encodedInput}/x`);
+ assert_equals(url.host, idnaTest.output);
+ assert_equals(url.hostname, idnaTest.output);
+ assert_equals(url.pathname, "/x");
+ assert_equals(url.href, `https://${idnaTest.output}/x`);
+ }
+ }, `ToASCII("${idnaTest.input}")${idnaTest.comment ? " " + idnaTest.comment : ""}`);
+ }
+}