diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/url/url-constructor.any.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/url/url-constructor.any.js')
-rw-r--r-- | testing/web-platform/tests/url/url-constructor.any.js | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/testing/web-platform/tests/url/url-constructor.any.js b/testing/web-platform/tests/url/url-constructor.any.js new file mode 100644 index 0000000000..bea06d025b --- /dev/null +++ b/testing/web-platform/tests/url/url-constructor.any.js @@ -0,0 +1,53 @@ +// META: script=/common/subset-tests-by-key.js +// META: timeout=long +// META: variant=?include=file +// META: variant=?include=javascript +// META: variant=?include=mailto +// META: variant=?exclude=(file|javascript|mailto) + +function runURLTests(urlTests) { + for (const expected of urlTests) { + // Skip comments + if (typeof expected === "string") + continue; + + const base = expected.base !== null ? expected.base : undefined; + + function getKey(expected) { + if (expected.protocol) { + return expected.protocol.replace(":", ""); + } + if (expected.failure) { + return expected.input.split(":")[0]; + } + return "other"; + } + + subsetTestByKey(getKey(expected), test, function() { + if (expected.failure) { + assert_throws_js(TypeError, function() { + new URL(expected.input, base); + }); + return; + } + + const url = new URL(expected.input, base); + assert_equals(url.href, expected.href, "href") + assert_equals(url.protocol, expected.protocol, "protocol") + assert_equals(url.username, expected.username, "username") + assert_equals(url.password, expected.password, "password") + assert_equals(url.host, expected.host, "host") + assert_equals(url.hostname, expected.hostname, "hostname") + assert_equals(url.port, expected.port, "port") + assert_equals(url.pathname, expected.pathname, "pathname") + assert_equals(url.search, expected.search, "search") + if ("searchParams" in expected) { + assert_true("searchParams" in url) + assert_equals(url.searchParams.toString(), expected.searchParams, "searchParams") + } + assert_equals(url.hash, expected.hash, "hash") + }, `Parsing: <${expected.input}> ${base ? "against <" + base + ">" : "without base"}`) + } +} + +promise_test(() => fetch("resources/urltestdata.json").then(res => res.json()).then(runURLTests), "Loading data…"); |