Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable shadowrealm testing for url api #41985

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion url/IdnaTestV2.window.js → url/IdnaTestV2.any.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
promise_test(() => fetch("resources/IdnaTestV2.json").then(res => res.json()).then(runTests), "Loading data…");
// META: global=window,dedicatedworker,shadowrealm
promise_test(() => fetch_json("resources/IdnaTestV2.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.
Expand Down
12 changes: 0 additions & 12 deletions url/failure.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,6 @@

const name = test.input + " should throw"

self.test(() => {
// URL's constructor's first argument is tested by url-constructor.html
// If a URL fails to parse with any valid base, it must also fail to parse with no base, i.e.
// when used as a base URL itself.
assert_throws_js(TypeError, () => new URL("about:blank", test.input));
}, "URL's constructor's base argument: " + name)

self.test(() => {
const url = new URL("about:blank")
assert_throws_js(TypeError, () => url.href = test.input)
}, "URL's href: " + name)

// The following use cases resolve the URL input relative to the current
// document's URL. If this test input could be construed as a valid URL
// when resolved against a base URL, skip these cases.
Expand Down
2 changes: 2 additions & 0 deletions url/historical.any.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// META: global=window,dedicatedworker,shadowrealm
rwaldron marked this conversation as resolved.
Show resolved Hide resolved

if (self.location) {
test(function() {
assert_false("searchParams" in self.location,
Expand Down
37 changes: 37 additions & 0 deletions url/resources/urlencoded-parser-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[
{ "input": "test", "output": [["test", ""]] },
{ "input": "\uFEFFtest=\uFEFF", "output": [["\uFEFFtest", "\uFEFF"]] },
{ "input": "%EF%BB%BFtest=%EF%BB%BF", "output": [["\uFEFFtest", "\uFEFF"]] },
{ "input": "%EF%BF%BF=%EF%BF%BF", "output": [["\uFFFF", "\uFFFF"]] },
{ "input": "%FE%FF", "output": [["\uFFFD\uFFFD", ""]] },
{ "input": "%FF%FE", "output": [["\uFFFD\uFFFD", ""]] },
{ "input": "†&†=x", "output": [["", ""], ["", "x"]] },
{ "input": "%C2", "output": [["\uFFFD", ""]] },
{ "input": "%C2x", "output": [["\uFFFDx", ""]] },
{ "input": "_charset_=windows-1252&test=%C2x", "output": [["_charset_", "windows-1252"], ["test", "\uFFFDx"]] },
{ "input": "", "output": [] },
{ "input": "a", "output": [["a", ""]] },
{ "input": "a=b", "output": [["a", "b"]] },
{ "input": "a=", "output": [["a", ""]] },
{ "input": "=b", "output": [["", "b"]] },
{ "input": "&", "output": [] },
{ "input": "&a", "output": [["a", ""]] },
{ "input": "a&", "output": [["a", ""]] },
{ "input": "a&a", "output": [["a", ""], ["a", ""]] },
{ "input": "a&b&c", "output": [["a", ""], ["b", ""], ["c", ""]] },
{ "input": "a=b&c=d", "output": [["a", "b"], ["c", "d"]] },
{ "input": "a=b&c=d&", "output": [["a", "b"], ["c", "d"]] },
{ "input": "&&&a=b&&&&c=d&", "output": [["a", "b"], ["c", "d"]] },
{ "input": "a=a&a=b&a=c", "output": [["a", "a"], ["a", "b"], ["a", "c"]] },
{ "input": "a==a", "output": [["a", "=a"]] },
{ "input": "a=a+b+c+d", "output": [["a", "a b c d"]] },
{ "input": "%=a", "output": [["%", "a"]] },
{ "input": "%a=a", "output": [["%a", "a"]] },
{ "input": "%a_=a", "output": [["%a_", "a"]] },
{ "input": "%61=a", "output": [["a", "a"]] },
{ "input": "%61+%4d%4D=", "output": [["a MM", ""]] },
{ "input": "id=0&value=%", "output": [["id", "0"], ["value", "%"]] },
{ "input": "b=%2sf%2a", "output": [["b", "%2sf*"]]},
{ "input": "b=%2%2af%2a", "output": [["b", "%2*f*"]]},
{ "input": "b=%%2a", "output": [["b", "%*"]]}
]
42 changes: 42 additions & 0 deletions url/toascii-elements.window.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
promise_test(() => fetch_json("resources/toascii.json").then(runTests), "Loading data…");

function makeURL(type, input) {
input = "https://" + input + "/x"
const url = document.createElement(type)
url.href = input
return url
}

function runTests(tests) {
for(var i = 0, l = tests.length; i < l; i++) {
let hostTest = tests[i]
if (typeof hostTest === "string") {
continue // skip comments
}
const typeName = { "a": "<a>", "area": "<area>" }
;["a", "area"].forEach((type) => {
test(() => {
if(hostTest.output !== null) {
// Tested in toascii.any.js
return
}
const url = makeURL(type, hostTest.input)
assert_equals(url.host, "")
assert_equals(url.hostname, "")
assert_equals(url.pathname, "")
assert_equals(url.href, "https://" + hostTest.input + "/x")
}, hostTest.input + " (using " + typeName[type] + ")")
;["host", "hostname"].forEach((val) => {
test(() => {
const url = makeURL(type, "x")
url[val] = hostTest.input
if(hostTest.output !== null) {
assert_equals(url[val], hostTest.output)
} else {
assert_equals(url[val], "x")
}
}, hostTest.input + " (using " + typeName[type] + "." + val + ")")
})
})
}
}
38 changes: 38 additions & 0 deletions url/toascii.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// META: global=window,dedicatedworker,shadowrealm
promise_test(() => fetch_json("resources/toascii.json").then(runTests), "Loading data…");

function makeURL(input) {
input = "https://" + input + "/x"
return new URL(input)
}

function runTests(tests) {
for(var i = 0, l = tests.length; i < l; i++) {
let hostTest = tests[i]
if (typeof hostTest === "string") {
continue // skip comments
}
test(() => {
if(hostTest.output !== null) {
const url = makeURL(hostTest.input)
assert_equals(url.host, hostTest.output)
assert_equals(url.hostname, hostTest.output)
assert_equals(url.pathname, "/x")
assert_equals(url.href, "https://" + hostTest.output + "/x")
} else {
assert_throws_js(TypeError, () => makeURL(hostTest.input))
}
}, hostTest.input + " (using URL)")
;["host", "hostname"].forEach((val) => {
test(() => {
const url = makeURL("x")
url[val] = hostTest.input
if(hostTest.output !== null) {
assert_equals(url[val], hostTest.output)
} else {
assert_equals(url[val], "x")
}
}, hostTest.input + " (using URL." + val + ")")
})
}
}
54 changes: 0 additions & 54 deletions url/toascii.window.js

This file was deleted.

26 changes: 26 additions & 0 deletions url/url-constructor-base-failure.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// META: global=window,dedicatedworker,shadowrealm

promise_test(() => fetch_json("resources/urltestdata.json").then(runTests), "Loading data…")

function runTests(urlTests) {
for (const expected of urlTests) {
// skip comments, inputs we expect to pass and relative URLs
if (typeof expected === "string" || !expected.failure || expected.base !== null) {
continue;
}

const name = expected.input + " should throw"

test(() => {
// URL's constructor's first argument is tested by url-constructor.any.js
// If a URL fails to parse with any valid base, it must also fail to parse
// with no base, i.e. when used as a base URL itself.
assert_throws_js(TypeError, () => new URL("about:blank", expected.input));
}, "URL's constructor's base argument: " + name)

test(() => {
const url = new URL("about:blank")
assert_throws_js(TypeError, () => url.href = expected.input)
}, "URL's href: " + name)
}
}
5 changes: 3 additions & 2 deletions url/url-constructor.any.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// META: global=window,dedicatedworker,shadowrealm
// META: script=/common/subset-tests-by-key.js
// META: timeout=long
// META: variant=?include=file
Expand Down Expand Up @@ -51,6 +52,6 @@ function runURLTests(urlTests) {
}

promise_test(() => Promise.all([
fetch("resources/urltestdata.json").then(res => res.json()),
fetch("resources/urltestdata-javascript-only.json").then(res => res.json()),
fetch_json("resources/urltestdata.json"),
fetch_json("resources/urltestdata-javascript-only.json"),
]).then((tests) => tests.flat()).then(runURLTests), "Loading data…");
5 changes: 3 additions & 2 deletions url/url-origin.any.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// META: global=window,dedicatedworker,shadowrealm
promise_test(() => Promise.all([
fetch("resources/urltestdata.json").then(res => res.json()),
fetch("resources/urltestdata-javascript-only.json").then(res => res.json()),
fetch_json("resources/urltestdata.json"),
fetch_json("resources/urltestdata-javascript-only.json"),
]).then((tests) => tests.flat()).then(runURLTests), "Loading data…");

function runURLTests(urlTests) {
Expand Down
2 changes: 2 additions & 0 deletions url/url-searchparams.any.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// META: global=window,dedicatedworker,shadowrealm

function bURL(url, base) {
return new URL(url, base || "about:blank")
}
Expand Down
2 changes: 2 additions & 0 deletions url/url-setters-stripping.any.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// META: global=window,dedicatedworker,shadowrealm

function urlString({ scheme = "https",
username = "username",
password = "password",
Expand Down
3 changes: 2 additions & 1 deletion url/url-setters.any.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// META: global=window,dedicatedworker,shadowrealm
// META: script=/common/subset-tests-by-key.js
// META: variant=?include=file
// META: variant=?include=javascript
Expand All @@ -6,7 +7,7 @@

// Keep this file in sync with url-setters-a-area.window.js.

promise_test(() => fetch("resources/setters_tests.json").then(res => res.json()).then(runURLSettersTests), "Loading data…");
promise_test(() => fetch_json("resources/setters_tests.json").then(runURLSettersTests), "Loading data…");
ptomato marked this conversation as resolved.
Show resolved Hide resolved

function runURLSettersTests(all_test_cases) {
for (var attribute_to_be_set in all_test_cases) {
Expand Down
2 changes: 2 additions & 0 deletions url/url-statics-canparse.any.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// META: global=window,dedicatedworker,shadowrealm

// This intentionally does not use resources/urltestdata.json to preserve resources.
[
{
Expand Down
2 changes: 2 additions & 0 deletions url/url-tojson.any.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// META: global=window,dedicatedworker,shadowrealm

test(() => {
const a = new URL("https://example.com/")
assert_equals(JSON.stringify(a), "\"https://example.com/\"")
Expand Down
30 changes: 30 additions & 0 deletions url/urlencoded-parser-request-response.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// META: global=window,dedicatedworker
promise_test(() => fetch_json("resources/urlencoded-parser-data.json").then(runTests), "Loading data…");

// Request and Response are not present in ShadowRealm

function runTests(testData) {
testData.forEach((val) => {
promise_test(() => {
let init = new Request("about:blank", { body: val.input, method: "LADIDA", headers: {"Content-Type": "application/x-www-form-urlencoded;charset=windows-1252"} }).formData()
return init.then((fd) => {
let i = 0
for (let item of fd) {
assert_array_equals(item, val.output[i])
i++
}
})
}, "request.formData() with input: " + val.input)

promise_test(() => {
let init = new Response(val.input, { headers: {"Content-Type": "application/x-www-form-urlencoded;charset=shift_jis"} }).formData()
return init.then((fd) => {
let i = 0
for (let item of fd) {
assert_array_equals(item, val.output[i])
i++
}
})
}, "response.formData() with input: " + val.input)
});
}
Loading