Skip to content

Commit 972bdee

Browse files
anonrigdanielleadams
authored andcommitted
test: update web-platform tests for url
PR-URL: #46547 Backport-PR-URL: #47435 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Filip Skokan <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 484c4f6 commit 972bdee

17 files changed

+10305
-8
lines changed

test/fixtures/wpt/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Last update:
2727
- performance-timeline: https://github.com/web-platform-tests/wpt/tree/17ebc3aea0/performance-timeline
2828
- resources: https://github.com/web-platform-tests/wpt/tree/fbf1e7d247/resources
2929
- streams: https://github.com/web-platform-tests/wpt/tree/9e5ef42bd3/streams
30-
- url: https://github.com/web-platform-tests/wpt/tree/0a187bc169/url
30+
- url: https://github.com/web-platform-tests/wpt/tree/f1ade799d0/url
3131
- user-timing: https://github.com/web-platform-tests/wpt/tree/df24fb604e/user-timing
3232
- wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/d8dbe6990b/wasm/jsapi
3333
- wasm/webapi: https://github.com/web-platform-tests/wpt/tree/fd1b23eeaa/wasm/webapi
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
promise_test(() => fetch("resources/IdnaTestV2.json").then(res => res.json()).then(runTests), "Loading data…");
2+
3+
// Performance impact of this seems negligible (performance.now() diff in WebKit went from 48 to 52)
4+
// and there was a preference to let more non-ASCII hit the parser.
5+
function encodeHostEndingCodePoints(input) {
6+
let output = "";
7+
for (const codePoint of input) {
8+
if ([":", "/", "?", "#", "\\"].includes(codePoint)) {
9+
output += encodeURIComponent(codePoint);
10+
} else {
11+
output += codePoint;
12+
}
13+
}
14+
return output;
15+
}
16+
17+
function runTests(idnaTests) {
18+
for (const idnaTest of idnaTests) {
19+
if (typeof idnaTest === "string") {
20+
continue // skip comments
21+
}
22+
if (idnaTest.input === "") {
23+
continue // cannot test empty string input through new URL()
24+
}
25+
// Percent-encode the input such that ? and equivalent code points do not end up counting as
26+
// part of the URL, but are parsed through the host parser instead.
27+
const encodedInput = encodeHostEndingCodePoints(idnaTest.input);
28+
29+
test(() => {
30+
if (idnaTest.output === null) {
31+
assert_throws_js(TypeError, () => new URL(`https://${encodedInput}/x`));
32+
} else {
33+
const url = new URL(`https://${encodedInput}/x`);
34+
assert_equals(url.host, idnaTest.output);
35+
assert_equals(url.hostname, idnaTest.output);
36+
assert_equals(url.pathname, "/x");
37+
assert_equals(url.href, `https://${idnaTest.output}/x`);
38+
}
39+
}, `ToASCII("${idnaTest.input}")${idnaTest.comment ? " " + idnaTest.comment : ""}`);
40+
}
41+
}

test/fixtures/wpt/url/a-element-xhtml.xhtml

+5
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
33
<html xmlns="http://www.w3.org/1999/xhtml">
44
<head>
55
<title>URL Test</title>
6+
<meta name="variant" content="?include=file"/>
7+
<meta name="variant" content="?include=javascript"/>
8+
<meta name="variant" content="?include=mailto"/>
9+
<meta name="variant" content="?exclude=(file|javascript|mailto)"/>
610
<script src="/resources/testharness.js"></script>
711
<script src="/resources/testharnessreport.js"></script>
12+
<script src="/common/subset-tests-by-key.js"></script>
813
<base id="base"/>
914
</head>
1015
<body>

test/fixtures/wpt/url/a-element.html

+5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
<!doctype html>
22
<meta charset=utf-8>
3+
<meta name="variant" content="?include=file">
4+
<meta name="variant" content="?include=javascript">
5+
<meta name="variant" content="?include=mailto">
6+
<meta name="variant" content="?exclude=(file|javascript|mailto)">
37
<script src=/resources/testharness.js></script>
48
<script src=/resources/testharnessreport.js></script>
9+
<script src="/common/subset-tests-by-key.js"></script>
510
<base id=base>
611
<div id=log></div>
712
<script src=resources/a-element.js></script>

test/fixtures/wpt/url/historical.any.js

+8
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,12 @@ test(function() {
2828
assert_equals(URL.domainToUnicode, undefined);
2929
}, "URL.domainToUnicode should be undefined");
3030

31+
test(() => {
32+
assert_throws_dom("DataCloneError", () => self.structuredClone(new URL("about:blank")));
33+
}, "URL: no structured serialize/deserialize support");
34+
35+
test(() => {
36+
assert_throws_dom("DataCloneError", () => self.structuredClone(new URLSearchParams()));
37+
}, "URLSearchParams: no structured serialize/deserialize support");
38+
3139
done();

0 commit comments

Comments
 (0)