1promise_test(() => fetch("resources/urltestdata.json").then(res => res.json()).then(runURLTests), "Loading data…");
2
3function setBase(base) {
4  document.getElementById("base").href = base
5}
6
7function bURL(url, base) {
8  setBase(base);
9  const a = document.createElement("a");
10  a.setAttribute("href", url);
11  return a;
12}
13
14function runURLTests(urlTests) {
15  for (const expected of urlTests) {
16    // Skip comments and tests without "origin" expectation
17    if (typeof expected === "string" || !("origin" in expected))
18      continue;
19
20    // Fragments are relative against "about:blank" (this might always be redundant due to requiring "origin" in expected)
21    if (expected.base === null && expected.input.startsWith("#"))
22      continue;
23
24    // We cannot use a null base for HTML tests
25    const base = expected.base === null ? "about:blank" : expected.base;
26
27    test(function() {
28      var url = bURL(expected.input, base)
29      assert_equals(url.origin, expected.origin, "origin")
30    }, "Parsing origin: <" + expected.input + "> against <" + base + ">")
31  }
32}
33