Skip to content

Commit

Permalink
Bug 1811454 [wpt PR 38080] - URL: run IdnaTestV2.txt in WPT, a=testonly
Browse files Browse the repository at this point in the history
Automatic update from web-platform-tests
URL: run a subset of IdnaTestV2.txt in WPT

This excludes various tests for now due to the open issues mentioned at the top of IdnaTestV2-parser.py.

For whatwg/url#341.
--

wpt-commits: 9216115f5621b04a27e0f2e9bbf1ce44dd7d3b9e
wpt-pr: 38080
  • Loading branch information
annevk authored and moz-wptsync-bot committed Feb 1, 2023
1 parent 677f9c5 commit 6bfbc11
Show file tree
Hide file tree
Showing 4 changed files with 9,970 additions and 0 deletions.
1 change: 1 addition & 0 deletions testing/web-platform/tests/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ scratch
/css/dist
/css/dist_last
/css/tools/cache
/url/tools/IdnaTestV2.txt
/webaudio/idl/*

# w3c-test.org PR-branch mirroring
Expand Down
41 changes: 41 additions & 0 deletions testing/web-platform/tests/url/IdnaTestV2.window.js
Original file line number Diff line number Diff line change
@@ -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 : ""}`);
}
}
Loading

0 comments on commit 6bfbc11

Please sign in to comment.