11cb0ef41Sopenharmony_ci<!doctype html>
21cb0ef41Sopenharmony_ci<meta charset=utf-8>
31cb0ef41Sopenharmony_ci<title>Test URL parser failure consistency</title>
41cb0ef41Sopenharmony_ci<meta name=timeout content=long>
51cb0ef41Sopenharmony_ci<script src=/resources/testharness.js></script>
61cb0ef41Sopenharmony_ci<script src=/resources/testharnessreport.js></script>
71cb0ef41Sopenharmony_ci<div id=log></div>
81cb0ef41Sopenharmony_ci<script>
91cb0ef41Sopenharmony_cipromise_test(() => fetch("resources/urltestdata.json").then(res => res.json()).then(runTests), "Loading data…")
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_cifunction runTests(testData) {
121cb0ef41Sopenharmony_ci  for (const test of testData) {
131cb0ef41Sopenharmony_ci    if (typeof test === "string" || !test.failure || test.base !== null) {
141cb0ef41Sopenharmony_ci      continue;
151cb0ef41Sopenharmony_ci    }
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ci    const name = test.input + " should throw"
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ci    self.test(() => {
201cb0ef41Sopenharmony_ci      // URL's constructor's first argument is tested by url-constructor.html
211cb0ef41Sopenharmony_ci      // If a URL fails to parse with any valid base, it must also fail to parse with no base, i.e.
221cb0ef41Sopenharmony_ci      // when used as a base URL itself.
231cb0ef41Sopenharmony_ci      assert_throws_js(TypeError, () => new URL("about:blank", test.input));
241cb0ef41Sopenharmony_ci    }, "URL's constructor's base argument: " + name)
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci    self.test(() => {
271cb0ef41Sopenharmony_ci      const url = new URL("about:blank")
281cb0ef41Sopenharmony_ci      assert_throws_js(TypeError, () => url.href = test.input)
291cb0ef41Sopenharmony_ci    }, "URL's href: " + name)
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci    // The following use cases resolve the URL input relative to the current
321cb0ef41Sopenharmony_ci    // document's URL. If this test input could be construed as a valid URL
331cb0ef41Sopenharmony_ci    // when resolved against a base URL, skip these cases.
341cb0ef41Sopenharmony_ci    if (test.relativeTo === undefined) {
351cb0ef41Sopenharmony_ci      self.test(() => {
361cb0ef41Sopenharmony_ci        const client = new XMLHttpRequest()
371cb0ef41Sopenharmony_ci        assert_throws_dom("SyntaxError", () => client.open("GET", test.input))
381cb0ef41Sopenharmony_ci      }, "XHR: " + name)
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_ci      self.test(() => {
411cb0ef41Sopenharmony_ci        assert_throws_js(TypeError, () => self.navigator.sendBeacon(test.input))
421cb0ef41Sopenharmony_ci      }, "sendBeacon(): " + name)
431cb0ef41Sopenharmony_ci
441cb0ef41Sopenharmony_ci      self.test(t => {
451cb0ef41Sopenharmony_ci        const frame = document.body.appendChild(document.createElement("iframe"));
461cb0ef41Sopenharmony_ci        t.add_cleanup(() => frame.remove());
471cb0ef41Sopenharmony_ci        assert_throws_dom("SyntaxError", frame.contentWindow.DOMException, () => frame.contentWindow.location = test.input);
481cb0ef41Sopenharmony_ci      }, "Location's href: " + name);
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_ci      self.test(() => {
511cb0ef41Sopenharmony_ci        assert_throws_dom("SyntaxError", () => self.open(test.input).close())
521cb0ef41Sopenharmony_ci      }, "window.open(): " + name)
531cb0ef41Sopenharmony_ci    }
541cb0ef41Sopenharmony_ci  }
551cb0ef41Sopenharmony_ci}
561cb0ef41Sopenharmony_ci</script>
57