Skip to content

Commit

Permalink
test: update URL web-platform-tests
Browse files Browse the repository at this point in the history
PR-URL: #47135
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
anonrig authored and danielleadams committed Jul 6, 2023
1 parent 061fb20 commit 6b85472
Show file tree
Hide file tree
Showing 8 changed files with 594 additions and 19 deletions.
2 changes: 1 addition & 1 deletion test/fixtures/wpt/README.md
Expand Up @@ -27,7 +27,7 @@ Last update:
- performance-timeline: https://github.com/web-platform-tests/wpt/tree/17ebc3aea0/performance-timeline
- resources: https://github.com/web-platform-tests/wpt/tree/fbf1e7d247/resources
- streams: https://github.com/web-platform-tests/wpt/tree/9e5ef42bd3/streams
- url: https://github.com/web-platform-tests/wpt/tree/1eaeb0e178/url
- url: https://github.com/web-platform-tests/wpt/tree/84caeb6fbd/url
- user-timing: https://github.com/web-platform-tests/wpt/tree/df24fb604e/user-timing
- wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/d8dbe6990b/wasm/jsapi
- wasm/webapi: https://github.com/web-platform-tests/wpt/tree/fd1b23eeaa/wasm/webapi
Expand Down
63 changes: 63 additions & 0 deletions test/fixtures/wpt/url/javascript-urls.window.js
@@ -0,0 +1,63 @@
// The results of this test are all over the map due to browsers behaving very differently for
// javascript: URLs.
//
// Chromium is pretty close execution-wise, but it parses javascript: URLs incorrectly.
// Gecko navigates to non-string return values of the result of executing a javascript: URL.
// WebKit executes javascript: URLs too early and has a harness error due to URL parsing.
//
// The expectations below should match the HTML and URL standards.
[
{
"description": "javascript: URL that fails to parse due to invalid host",
"input": "javascript://test:test/%0aglobalThis.shouldNotExistA=1",
"property": "shouldNotExistA",
"expected": undefined
},
{
"description": "javascript: URL that fails to parse due to invalid host and has a U+0009 in scheme",
"input": "java\x09script://test:test/%0aglobalThis.shouldNotExistB=1",
"property": "shouldNotExistB",
"expected": undefined
},
{
"description": "javascript: URL without an opaque path",
"input": "javascript://host/1%0a//../0/;globalThis.shouldBeOne=1;/%0aglobalThis.shouldBeOne=2;/..///",
"property": "shouldBeOne",
"expected": 1
},
{
"description": "javascript: URL containing a JavaScript string split over path and query",
// Use ";undefined" to avoid returning a string.
"input": "javascript:globalThis.shouldBeAStringA = \"https://whatsoever.com/?a=b&c=5&x=y\";undefined",
"property": "shouldBeAStringA",
"expected": "https://whatsoever.com/?a=b&c=5&x=y"
},
{
"description": "javascript: URL containing a JavaScript string split over path and query and has a U+000A in scheme",
// Use ";undefined" to avoid returning a string.
"input": "java\x0Ascript:globalThis.shouldBeAStringB = \"https://whatsoever.com/?a=b&c=5&x=y\";undefined",
"property": "shouldBeAStringB",
"expected": "https://whatsoever.com/?a=b&c=5&x=y"
}
].forEach(({ description, input, property, expected }) => {
// Use promise_test so the tests run in sequence. Needed for globalThis.verify below.
promise_test(t => {
const anchor = document.body.appendChild(document.createElement("a"));
t.add_cleanup(() => anchor.remove());
anchor.href = input;
assert_equals(globalThis[property], undefined, "Property is undefined before the click");
anchor.click();
assert_equals(globalThis[property], undefined, "Property is undefined immediately after the click");

// Since we cannot reliably queue a task to run after the task queued as a result of the click()
// above, we do another click() with a new URL.
return new Promise(resolve => {
globalThis.verify = t.step_func(() => {
assert_equals(globalThis[property], expected, `Property is ${expected} once the navigation happened`);
resolve();
});
anchor.href = "javascript:globalThis.verify()";
anchor.click();
});
}, description);
});
72 changes: 72 additions & 0 deletions test/fixtures/wpt/url/resources/setters_tests.json
Expand Up @@ -1061,6 +1061,42 @@
"host": "",
"hostname": ""
}
},
{
"href": "https://example.com/",
"new_value": "a%C2%ADb",
"expected": {
"href": "https://ab/",
"host": "ab",
"hostname": "ab"
}
},
{
"href": "https://example.com/",
"new_value": "\u00AD",
"expected": {
"href": "https://example.com/",
"host": "example.com",
"hostname": "example.com"
}
},
{
"href": "https://example.com/",
"new_value": "%C2%AD",
"expected": {
"href": "https://example.com/",
"host": "example.com",
"hostname": "example.com"
}
},
{
"href": "https://example.com/",
"new_value": "xn--",
"expected": {
"href": "https://example.com/",
"host": "example.com",
"hostname": "example.com"
}
}
],
"hostname": [
Expand Down Expand Up @@ -1436,6 +1472,42 @@
"host": "",
"hostname": ""
}
},
{
"href": "https://example.com/",
"new_value": "a%C2%ADb",
"expected": {
"href": "https://ab/",
"host": "ab",
"hostname": "ab"
}
},
{
"href": "https://example.com/",
"new_value": "\u00AD",
"expected": {
"href": "https://example.com/",
"host": "example.com",
"hostname": "example.com"
}
},
{
"href": "https://example.com/",
"new_value": "%C2%AD",
"expected": {
"href": "https://example.com/",
"host": "example.com",
"hostname": "example.com"
}
},
{
"href": "https://example.com/",
"new_value": "xn--",
"expected": {
"href": "https://example.com/",
"host": "example.com",
"hostname": "example.com"
}
}
],
"port": [
Expand Down
17 changes: 0 additions & 17 deletions test/fixtures/wpt/url/resources/toascii.json
Expand Up @@ -160,23 +160,6 @@
"input": "a\u00ADb",
"output": "ab"
},
{
"input": "a%C2%ADb",
"output": "ab"
},
{
"comment": "Empty host after domain to ASCII",
"input": "\u00AD",
"output": null
},
{
"input": "%C2%AD",
"output": null
},
{
"input": "xn--",
"output": null
},
{
"comment": "Interesting UseSTD3ASCIIRules=false cases",
"input": "",
Expand Down

0 comments on commit 6b85472

Please sign in to comment.