summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/url/resources/a-element.js
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/url/resources/a-element.js')
-rw-r--r--testing/web-platform/tests/url/resources/a-element.js59
1 files changed, 59 insertions, 0 deletions
diff --git a/testing/web-platform/tests/url/resources/a-element.js b/testing/web-platform/tests/url/resources/a-element.js
new file mode 100644
index 0000000000..d87937d002
--- /dev/null
+++ b/testing/web-platform/tests/url/resources/a-element.js
@@ -0,0 +1,59 @@
+promise_test(() => fetch("resources/urltestdata.json").then(res => res.json()).then(runURLTests), "Loading data…");
+
+function setBase(base) {
+ document.getElementById("base").href = base;
+}
+
+function bURL(url, base) {
+ setBase(base);
+ const a = document.createElement("a");
+ a.setAttribute("href", url);
+ return a;
+}
+
+function runURLTests(urlTests) {
+ for (const expected of urlTests) {
+ // Skip comments
+ if (typeof expected === "string")
+ continue;
+
+ // Fragments are relative against "about:blank"
+ if (expected.relativeTo === "any-base")
+ continue;
+
+ // We cannot use a null base for HTML tests
+ const base = expected.base === null ? "about:blank" : expected.base;
+
+ 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() {
+ var url = bURL(expected.input, base)
+ if(expected.failure) {
+ if(url.protocol !== ':') {
+ assert_unreached("Expected URL to fail parsing")
+ }
+ assert_equals(url.href, expected.input, "failure should set href to input")
+ return
+ }
+
+ 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")
+ assert_equals(url.hash, expected.hash, "hash")
+ }, "Parsing: <" + expected.input + "> against <" + base + ">")
+ }
+}