navigate-to-unparseable-url.html (1766B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>location.href unparseable URL throws a SyntaxError DOMException</title> 4 <link rel="help" href="https://html.spec.whatwg.org/#the-location-interface:dom-location-href-2"> 5 <link rel="help" href="https://html.spec.whatwg.org/#following-hyperlinks-2"> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 9 <body> 10 <script> 11 const kUnparseableURL = self.origin + ":notaport/common/blank.html"; 12 13 promise_test(async t => { 14 const win = window.open("/common/blank.html"); 15 t.add_cleanup(() => { 16 win.close(); 17 }); 18 19 await new Promise(resolve => { 20 win.onload = resolve; 21 }); 22 23 assert_throws_dom("SyntaxError", win.DOMException, () => { 24 win.location.href = kUnparseableURL; 25 }, "location.href setter throws a SyntaxError DOMException"); 26 }, "location.href setter throws a SyntaxError DOMException for unparseable " + 27 "URLs"); 28 29 promise_test(async t => { 30 const win = window.open("/common/blank.html"); 31 t.add_cleanup(() => { 32 win.close(); 33 }); 34 35 await new Promise(resolve => { 36 win.onload = resolve; 37 }); 38 39 // If the newly-opened window tries to navigate, fail the test. 40 const failPromise = new Promise((resolve, reject) => { 41 win.onpagehide = () => 42 reject(new Error("Navigation was attempted to unparseable URL")); 43 }); 44 45 // A promise to wait on to confirm the newly-opened window did not navigate. 46 const successPromise = new Promise(resolve => { 47 t.step_timeout(resolve, 2000); 48 }); 49 50 const a = win.document.createElement('a'); 51 a.href = kUnparseableURL; 52 win.document.body.append(a); 53 a.click(); 54 55 return Promise.race([successPromise, failPromise]); 56 }, "<a> tag navigate fails for unparseable URLs"); 57 </script> 58 </body>