From d846da5f6c828f7755c1dd285c6a12ac49be0555 Mon Sep 17 00:00:00 2001 From: rwaldron Date: Thu, 14 Sep 2023 15:50:53 -0400 Subject: [PATCH 1/4] Enable shadowrealm testing for url api Starting with tests that don't have additional dependencies. --- url/historical.any.js | 2 ++ url/url-searchparams.any.js | 2 ++ url/url-setters-stripping.any.js | 2 ++ url/url-statics-canparse.any.js | 2 ++ url/url-tojson.any.js | 2 ++ url/urlencoded-parser.any.js | 2 ++ url/urlsearchparams-append.any.js | 2 ++ url/urlsearchparams-constructor.any.js | 2 ++ url/urlsearchparams-delete.any.js | 2 ++ url/urlsearchparams-foreach.any.js | 2 ++ url/urlsearchparams-get.any.js | 2 ++ url/urlsearchparams-getall.any.js | 2 ++ url/urlsearchparams-has.any.js | 4 +++- url/urlsearchparams-set.any.js | 2 ++ url/urlsearchparams-size.any.js | 2 ++ url/urlsearchparams-sort.any.js | 2 ++ url/urlsearchparams-stringifier.any.js | 2 ++ 17 files changed, 35 insertions(+), 1 deletion(-) diff --git a/url/historical.any.js b/url/historical.any.js index 9c4b5f0ae9bfad..983e730bf74b67 100644 --- a/url/historical.any.js +++ b/url/historical.any.js @@ -1,3 +1,5 @@ +// META: global=window,dedicatedworker,shadowrealm + if (self.location) { test(function() { assert_false("searchParams" in self.location, diff --git a/url/url-searchparams.any.js b/url/url-searchparams.any.js index 9bba12e89cefd1..b5dd5decc638cf 100644 --- a/url/url-searchparams.any.js +++ b/url/url-searchparams.any.js @@ -1,3 +1,5 @@ +// META: global=window,dedicatedworker,shadowrealm + function bURL(url, base) { return new URL(url, base || "about:blank") } diff --git a/url/url-setters-stripping.any.js b/url/url-setters-stripping.any.js index ac90cc17e0bfd5..29405020131230 100644 --- a/url/url-setters-stripping.any.js +++ b/url/url-setters-stripping.any.js @@ -1,3 +1,5 @@ +// META: global=window,dedicatedworker,shadowrealm + function urlString({ scheme = "https", username = "username", password = "password", diff --git a/url/url-statics-canparse.any.js b/url/url-statics-canparse.any.js index 74f3da31f0d175..eb96d5ecfc9395 100644 --- a/url/url-statics-canparse.any.js +++ b/url/url-statics-canparse.any.js @@ -1,3 +1,5 @@ +// META: global=window,dedicatedworker,shadowrealm + // This intentionally does not use resources/urltestdata.json to preserve resources. [ { diff --git a/url/url-tojson.any.js b/url/url-tojson.any.js index 65165f96c572d9..fbc23599e106fa 100644 --- a/url/url-tojson.any.js +++ b/url/url-tojson.any.js @@ -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/\"") diff --git a/url/urlencoded-parser.any.js b/url/urlencoded-parser.any.js index 847465cb9214e1..802f5f9433a91c 100644 --- a/url/urlencoded-parser.any.js +++ b/url/urlencoded-parser.any.js @@ -1,3 +1,5 @@ +// META: global=window,dedicatedworker,shadowrealm + [ { "input": "test", "output": [["test", ""]] }, { "input": "\uFEFFtest=\uFEFF", "output": [["\uFEFFtest", "\uFEFF"]] }, diff --git a/url/urlsearchparams-append.any.js b/url/urlsearchparams-append.any.js index 5a7376144d0637..17a72be4a9a51c 100644 --- a/url/urlsearchparams-append.any.js +++ b/url/urlsearchparams-append.any.js @@ -1,3 +1,5 @@ +// META: global=window,dedicatedworker,shadowrealm + test(function() { var params = new URLSearchParams(); params.append('a', 'b'); diff --git a/url/urlsearchparams-constructor.any.js b/url/urlsearchparams-constructor.any.js index d482911350ba0f..a6339f2a1eee40 100644 --- a/url/urlsearchparams-constructor.any.js +++ b/url/urlsearchparams-constructor.any.js @@ -1,3 +1,5 @@ +// META: global=window,dedicatedworker,shadowrealm + test(function() { var params = new URLSearchParams(); assert_equals(params + '', ''); diff --git a/url/urlsearchparams-delete.any.js b/url/urlsearchparams-delete.any.js index c597142c51d5bf..07ae9bd54d9fdb 100644 --- a/url/urlsearchparams-delete.any.js +++ b/url/urlsearchparams-delete.any.js @@ -1,3 +1,5 @@ +// META: global=window,dedicatedworker,shadowrealm + test(function() { var params = new URLSearchParams('a=b&c=d'); params.delete('a'); diff --git a/url/urlsearchparams-foreach.any.js b/url/urlsearchparams-foreach.any.js index ff19643ac220d1..4f6d941d5c1236 100644 --- a/url/urlsearchparams-foreach.any.js +++ b/url/urlsearchparams-foreach.any.js @@ -1,3 +1,5 @@ +// META: global=window,dedicatedworker,shadowrealm + test(function() { var params = new URLSearchParams('a=1&b=2&c=3'); var keys = []; diff --git a/url/urlsearchparams-get.any.js b/url/urlsearchparams-get.any.js index a2610fc933a772..ccc327afa33b52 100644 --- a/url/urlsearchparams-get.any.js +++ b/url/urlsearchparams-get.any.js @@ -1,3 +1,5 @@ +// META: global=window,dedicatedworker,shadowrealm + test(function() { var params = new URLSearchParams('a=b&c=d'); assert_equals(params.get('a'), 'b'); diff --git a/url/urlsearchparams-getall.any.js b/url/urlsearchparams-getall.any.js index 5d1a35352acf2c..065029e6f60eaf 100644 --- a/url/urlsearchparams-getall.any.js +++ b/url/urlsearchparams-getall.any.js @@ -1,3 +1,5 @@ +// META: global=window,dedicatedworker,shadowrealm + test(function() { var params = new URLSearchParams('a=b&c=d'); assert_array_equals(params.getAll('a'), ['b']); diff --git a/url/urlsearchparams-has.any.js b/url/urlsearchparams-has.any.js index 2133a5da2f8b91..a46c912911cae6 100644 --- a/url/urlsearchparams-has.any.js +++ b/url/urlsearchparams-has.any.js @@ -1,3 +1,5 @@ +// META: global=window,dedicatedworker,shadowrealm + test(function() { var params = new URLSearchParams('a=b&c=d'); assert_true(params.has('a')); @@ -42,4 +44,4 @@ test(() => { assert_false(params.has('a', 'c')); assert_true(params.has('a', 'd')); assert_true(params.has('a', undefined)); -}, "Two-argument has() respects undefined as second arg"); \ No newline at end of file +}, "Two-argument has() respects undefined as second arg"); diff --git a/url/urlsearchparams-set.any.js b/url/urlsearchparams-set.any.js index eb24cac87b6dca..fc5e338792276a 100644 --- a/url/urlsearchparams-set.any.js +++ b/url/urlsearchparams-set.any.js @@ -1,3 +1,5 @@ +// META: global=window,dedicatedworker,shadowrealm + test(function() { var params = new URLSearchParams('a=b&c=d'); params.set('a', 'B'); diff --git a/url/urlsearchparams-size.any.js b/url/urlsearchparams-size.any.js index 7b3abc7c0b421c..e9adaa6e8c7e52 100644 --- a/url/urlsearchparams-size.any.js +++ b/url/urlsearchparams-size.any.js @@ -1,3 +1,5 @@ +// META: global=window,dedicatedworker,shadowrealm + test(() => { const params = new URLSearchParams("a=1&b=2&a=3"); assert_equals(params.size, 3); diff --git a/url/urlsearchparams-sort.any.js b/url/urlsearchparams-sort.any.js index 4fd8cef69239d2..8189885a100a9a 100644 --- a/url/urlsearchparams-sort.any.js +++ b/url/urlsearchparams-sort.any.js @@ -1,3 +1,5 @@ +// META: global=window,dedicatedworker,shadowrealm + [ { "input": "z=b&a=b&z=a&a=a", diff --git a/url/urlsearchparams-stringifier.any.js b/url/urlsearchparams-stringifier.any.js index 6187db64b1747d..cf8f482fc8c3cc 100644 --- a/url/urlsearchparams-stringifier.any.js +++ b/url/urlsearchparams-stringifier.any.js @@ -1,3 +1,5 @@ +// META: global=window,dedicatedworker,shadowrealm + test(function() { var params = new URLSearchParams(); params.append('a', 'b c'); From 447ded0d19de40718edde2edbcad777ad62d2606 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Thu, 7 Dec 2023 16:01:12 -0800 Subject: [PATCH 2/4] Split URL tests into ShadowRealm-applicable and not-applicable files Some tests required interfaces such as Request, Response, or FormData that are not available in ShadowRealm. These should be split into separate test files that are not run in ShadowRealm scopes. --- url/resources/urlencoded-parser-data.json | 37 +++++++++ url/toascii-elements.window.js | 42 ++++++++++ url/toascii.any.js | 38 +++++++++ url/toascii.window.js | 54 ------------- url/urlencoded-parser-request-response.any.js | 30 +++++++ url/urlencoded-parser.any.js | 80 ++++--------------- ...rlsearchparams-constructor-formdata.any.js | 20 +++++ url/urlsearchparams-constructor.any.js | 17 ---- 8 files changed, 181 insertions(+), 137 deletions(-) create mode 100644 url/resources/urlencoded-parser-data.json create mode 100644 url/toascii-elements.window.js create mode 100644 url/toascii.any.js delete mode 100644 url/toascii.window.js create mode 100644 url/urlencoded-parser-request-response.any.js create mode 100644 url/urlsearchparams-constructor-formdata.any.js diff --git a/url/resources/urlencoded-parser-data.json b/url/resources/urlencoded-parser-data.json new file mode 100644 index 00000000000000..fb42fdab164adf --- /dev/null +++ b/url/resources/urlencoded-parser-data.json @@ -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", "%*"]]} +] diff --git a/url/toascii-elements.window.js b/url/toascii-elements.window.js new file mode 100644 index 00000000000000..adb324573e97ae --- /dev/null +++ b/url/toascii-elements.window.js @@ -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": "", "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 + ")") + }) + }) + } +} diff --git a/url/toascii.any.js b/url/toascii.any.js new file mode 100644 index 00000000000000..e9835279e31281 --- /dev/null +++ b/url/toascii.any.js @@ -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 + ")") + }) + } +} diff --git a/url/toascii.window.js b/url/toascii.window.js deleted file mode 100644 index cdc488ec28526f..00000000000000 --- a/url/toascii.window.js +++ /dev/null @@ -1,54 +0,0 @@ -promise_test(() => fetch("resources/toascii.json").then(res => res.json()).then(runTests), "Loading data…"); - -function makeURL(type, input) { - input = "https://" + input + "/x" - if(type === "url") { - return new URL(input) - } else { - 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 = { "url": "URL", "a": "", "area": "" } - ;["url", "a", "area"].forEach((type) => { - test(() => { - if(hostTest.output !== null) { - const url = makeURL("url", 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 { - if(type === "url") { - assert_throws_js(TypeError, () => makeURL("url", hostTest.input)) - } else { - 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 + ")") - }) - }) - } -} diff --git a/url/urlencoded-parser-request-response.any.js b/url/urlencoded-parser-request-response.any.js new file mode 100644 index 00000000000000..fd6bd5821526a7 --- /dev/null +++ b/url/urlencoded-parser-request-response.any.js @@ -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) + }); +} diff --git a/url/urlencoded-parser.any.js b/url/urlencoded-parser.any.js index 802f5f9433a91c..125763fea323a9 100644 --- a/url/urlencoded-parser.any.js +++ b/url/urlencoded-parser.any.js @@ -1,70 +1,18 @@ // META: global=window,dedicatedworker,shadowrealm +promise_test(() => fetch_json("resources/urlencoded-parser-data.json").then(runTests), "Loading data…"); -[ - { "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', '%*']]} -].forEach((val) => { - test(() => { - let sp = new URLSearchParams(val.input), - i = 0 - for (let item of sp) { - assert_array_equals(item, val.output[i]) - i++ - } - }, "URLSearchParams constructed with: " + val.input) +// See urlencoded-parser-request-response.any.js for more tests with +// urlencoded-parser-data.js that don't apply to ShadowRealm - 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++ +function runTests(testData) { + testData.forEach((val) => { + test(() => { + let sp = new URLSearchParams(val.input), + i = 0 + for (let item of sp) { + 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) -}); + }, "URLSearchParams constructed with: " + val.input) + }); +} diff --git a/url/urlsearchparams-constructor-formdata.any.js b/url/urlsearchparams-constructor-formdata.any.js new file mode 100644 index 00000000000000..9f96f7be6724fc --- /dev/null +++ b/url/urlsearchparams-constructor-formdata.any.js @@ -0,0 +1,20 @@ +// META: global=window,dedicatedworker + +// FormData is not present in ShadowRealm + +test(function() { + var formData = new FormData() + formData.append('a', 'b') + formData.append('c', 'd') + var params = new URLSearchParams(formData); + assert_true(params != null, 'constructor returned non-null value.'); + assert_equals(params.get('a'), 'b'); + assert_equals(params.get('c'), 'd'); + assert_false(params.has('d')); + // The name-value pairs are copied when created; later updates + // should not be observable. + formData.append('e', 'f'); + assert_false(params.has('e')); + params.append('g', 'h'); + assert_false(formData.has('g')); +}, 'URLSearchParams constructor, FormData.'); diff --git a/url/urlsearchparams-constructor.any.js b/url/urlsearchparams-constructor.any.js index a6339f2a1eee40..d3109e1038e4c8 100644 --- a/url/urlsearchparams-constructor.any.js +++ b/url/urlsearchparams-constructor.any.js @@ -97,23 +97,6 @@ test(function() { assert_false(seed.has('g')); }, 'URLSearchParams constructor, object.'); -test(function() { - var formData = new FormData() - formData.append('a', 'b') - formData.append('c', 'd') - var params = new URLSearchParams(formData); - assert_true(params != null, 'constructor returned non-null value.'); - assert_equals(params.get('a'), 'b'); - assert_equals(params.get('c'), 'd'); - assert_false(params.has('d')); - // The name-value pairs are copied when created; later updates - // should not be observable. - formData.append('e', 'f'); - assert_false(params.has('e')); - params.append('g', 'h'); - assert_false(formData.has('g')); -}, 'URLSearchParams constructor, FormData.'); - test(function() { var params = new URLSearchParams('a=b+c'); assert_equals(params.get('a'), 'b c'); From 9ea269c83ab6e1f31d51a99c869d3ea63e347074 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Thu, 7 Dec 2023 16:01:32 -0800 Subject: [PATCH 3/4] Split tests for failure to parse base URL into their own file In url/failure.html there were tests passing invalid URLs to the second parameter of the URL constructor. Split these into their own file so they can be run in workers and ShadowRealms, separately from the other tests in url/failure.html that use the current document's URL. --- url/failure.html | 12 ------------ url/url-constructor-base-failure.any.js | 26 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 12 deletions(-) create mode 100644 url/url-constructor-base-failure.any.js diff --git a/url/failure.html b/url/failure.html index d95b1d52d67237..72fa8f4147d5be 100644 --- a/url/failure.html +++ b/url/failure.html @@ -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. diff --git a/url/url-constructor-base-failure.any.js b/url/url-constructor-base-failure.any.js new file mode 100644 index 00000000000000..d3183d92974cd7 --- /dev/null +++ b/url/url-constructor-base-failure.any.js @@ -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) + } +} From f382c0ce932014f0f828a96f7efffd93b21ffd9a Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Thu, 7 Dec 2023 16:01:39 -0800 Subject: [PATCH 4/4] Enable ShadowRealm testing for more URL APIs --- url/{IdnaTestV2.window.js => IdnaTestV2.any.js} | 3 ++- url/url-constructor.any.js | 5 +++-- url/url-origin.any.js | 5 +++-- url/url-setters.any.js | 3 ++- 4 files changed, 10 insertions(+), 6 deletions(-) rename url/{IdnaTestV2.window.js => IdnaTestV2.any.js} (90%) diff --git a/url/IdnaTestV2.window.js b/url/IdnaTestV2.any.js similarity index 90% rename from url/IdnaTestV2.window.js rename to url/IdnaTestV2.any.js index 8873886bdab8a0..bbe9fa4fea699c 100644 --- a/url/IdnaTestV2.window.js +++ b/url/IdnaTestV2.any.js @@ -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. diff --git a/url/url-constructor.any.js b/url/url-constructor.any.js index b4b639b813e975..63b8fb687278da 100644 --- a/url/url-constructor.any.js +++ b/url/url-constructor.any.js @@ -1,3 +1,4 @@ +// META: global=window,dedicatedworker,shadowrealm // META: script=/common/subset-tests-by-key.js // META: timeout=long // META: variant=?include=file @@ -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…"); diff --git a/url/url-origin.any.js b/url/url-origin.any.js index b9e0c8585312f6..d201941f93c763 100644 --- a/url/url-origin.any.js +++ b/url/url-origin.any.js @@ -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) { diff --git a/url/url-setters.any.js b/url/url-setters.any.js index fe88175ac63446..ab47e0adc70735 100644 --- a/url/url-setters.any.js +++ b/url/url-setters.any.js @@ -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 @@ -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…"); function runURLSettersTests(all_test_cases) { for (var attribute_to_be_set in all_test_cases) {