11cb0ef41Sopenharmony_cipromise_test(() => fetch("resources/urltestdata.json").then(res => res.json()).then(runURLTests), "Loading data…");
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_cifunction setBase(base) {
41cb0ef41Sopenharmony_ci  document.getElementById("base").href = base
51cb0ef41Sopenharmony_ci}
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_cifunction bURL(url, base) {
81cb0ef41Sopenharmony_ci  setBase(base);
91cb0ef41Sopenharmony_ci  const a = document.createElement("a");
101cb0ef41Sopenharmony_ci  a.setAttribute("href", url);
111cb0ef41Sopenharmony_ci  return a;
121cb0ef41Sopenharmony_ci}
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_cifunction runURLTests(urlTests) {
151cb0ef41Sopenharmony_ci  for (const expected of urlTests) {
161cb0ef41Sopenharmony_ci    // Skip comments and tests without "origin" expectation
171cb0ef41Sopenharmony_ci    if (typeof expected === "string" || !("origin" in expected))
181cb0ef41Sopenharmony_ci      continue;
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ci    // Fragments are relative against "about:blank" (this might always be redundant due to requiring "origin" in expected)
211cb0ef41Sopenharmony_ci    if (expected.base === null && expected.input.startsWith("#"))
221cb0ef41Sopenharmony_ci      continue;
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci    // We cannot use a null base for HTML tests
251cb0ef41Sopenharmony_ci    const base = expected.base === null ? "about:blank" : expected.base;
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ci    test(function() {
281cb0ef41Sopenharmony_ci      var url = bURL(expected.input, base)
291cb0ef41Sopenharmony_ci      assert_equals(url.origin, expected.origin, "origin")
301cb0ef41Sopenharmony_ci    }, "Parsing origin: <" + expected.input + "> against <" + base + ">")
311cb0ef41Sopenharmony_ci  }
321cb0ef41Sopenharmony_ci}
33