1<!doctype html> 2<meta charset=utf-8> 3<title>Test URL parser failure consistency</title> 4<script src=/resources/testharness.js></script> 5<script src=/resources/testharnessreport.js></script> 6<div id=log></div> 7<iframe></iframe> 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 !== "about:blank") { 14 continue 15 } 16 17 const name = test.input + " should throw" 18 19 self.test(() => { // URL's constructor's first argument is tested by url-constructor.html 20 // If a URL fails to parse with any valid base, it must also fail to parse with no base, i.e. 21 // when used as a base URL itself. 22 assert_throws(new TypeError(), () => new URL("about:blank", test.input)); 23 }, "URL's constructor's base argument: " + name) 24 25 self.test(() => { 26 const url = new URL("about:blank") 27 assert_throws(new TypeError, () => url.href = test.input) 28 }, "URL's href: " + name) 29 30 self.test(() => { 31 const client = new XMLHttpRequest() 32 assert_throws("SyntaxError", () => client.open("GET", test.input)) 33 }, "XHR: " + name) 34 35 self.test(() => { 36 assert_throws(new TypeError, () => self.navigator.sendBeacon(test.input)) 37 }, "sendBeacon(): " + name) 38 39 self.test(() => { 40 assert_throws(new TypeError, () => self[0].location = test.input) 41 }, "Location's href: " + name) 42 43 self.test(() => { 44 assert_throws("SyntaxError", () => self.open(test.input).close()) 45 }, "window.open(): " + name) 46 } 47} 48</script> 49