• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!doctype html>
2<meta charset=utf-8>
3<title>Test URL parser failure consistency</title>
4<meta name=timeout content=long>
5<script src=/resources/testharness.js></script>
6<script src=/resources/testharnessreport.js></script>
7<div id=log></div>
8<script>
9promise_test(() => fetch("resources/urltestdata.json").then(res => res.json()).then(runTests), "Loading data…")
10
11function runTests(testData) {
12  for (const test of testData) {
13    if (typeof test === "string" || !test.failure || test.base !== null) {
14      continue;
15    }
16
17    const name = test.input + " should throw"
18
19    self.test(() => {
20      // URL's constructor's first argument is tested by url-constructor.html
21      // If a URL fails to parse with any valid base, it must also fail to parse with no base, i.e.
22      // when used as a base URL itself.
23      assert_throws_js(TypeError, () => new URL("about:blank", test.input));
24    }, "URL's constructor's base argument: " + name)
25
26    self.test(() => {
27      const url = new URL("about:blank")
28      assert_throws_js(TypeError, () => url.href = test.input)
29    }, "URL's href: " + name)
30
31    // The following use cases resolve the URL input relative to the current
32    // document's URL. If this test input could be construed as a valid URL
33    // when resolved against a base URL, skip these cases.
34    if (test.relativeTo === undefined) {
35      self.test(() => {
36        const client = new XMLHttpRequest()
37        assert_throws_dom("SyntaxError", () => client.open("GET", test.input))
38      }, "XHR: " + name)
39
40      self.test(() => {
41        assert_throws_js(TypeError, () => self.navigator.sendBeacon(test.input))
42      }, "sendBeacon(): " + name)
43
44      self.test(t => {
45        const frame = document.body.appendChild(document.createElement("iframe"));
46        t.add_cleanup(() => frame.remove());
47        assert_throws_dom("SyntaxError", frame.contentWindow.DOMException, () => frame.contentWindow.location = test.input);
48      }, "Location's href: " + name);
49
50      self.test(() => {
51        assert_throws_dom("SyntaxError", () => self.open(test.input).close())
52      }, "window.open(): " + name)
53    }
54  }
55}
56</script>
57