location-protocol-setter-non-broken.html (2199B)
1 <!doctype html> 2 <title>Set location.protocol to a non-broken-non-functioning scheme</title> 3 <!-- In particular, valid non-broken schemes that are nevertheless not going to work --> 4 <script src=/resources/testharness.js></script> 5 <script src=/resources/testharnessreport.js></script> 6 <div id=log></div> 7 <script> 8 self.onload = () => { 9 [ 10 'x', 11 'data', 12 // 'mailto' opens an email client in Chrome and Firefox and then ends up passing anyway... 13 'file', 14 'ftp', 15 'http+x' 16 ].forEach((val) => { 17 async_test((t) => { 18 // HTTP URL <iframe> 19 const frame = document.createElement("iframe") 20 t.add_cleanup(() => frame.remove()) 21 frame.src = "/common/blank.html" 22 frame.onload = t.step_func(() => { 23 frame.contentWindow.location.protocol = val 24 t.step_timeout(() => { 25 assert_equals(frame.contentWindow.location.protocol, location.protocol) 26 assert_equals(frame.contentWindow.location.host, location.host) 27 assert_equals(frame.contentWindow.location.port, location.port) 28 t.done() 29 // Matches the timeout from location-protocol-setter-non-broken-weird.html which suggests 30 // that 4 seconds is enough for a navigation to complete. 31 }, 4000) 32 }) 33 document.body.appendChild(frame) 34 }, "Set HTTP URL frame location.protocol to " + val) 35 36 async_test((t) => { 37 // data URL <iframe> 38 const dataFrame = document.createElement("iframe") 39 t.add_cleanup(() => dataFrame.remove()) 40 const channel = new MessageChannel() 41 dataFrame.src = `data:text/html,<script> 42 onmessage = (e) => { 43 let result = false; 44 try { 45 location.protocol = e.data 46 } catch(e) { 47 result = true 48 } 49 setTimeout(() => e.ports[0].postMessage([result, location.protocol]), 4000) 50 } 51 <\/script>` 52 dataFrame.onload = t.step_func(() => { 53 dataFrame.contentWindow.postMessage(val, "*", [channel.port2]) 54 }) 55 channel.port1.onmessage = t.step_func_done((e) => { 56 assert_false(e.data[0]) 57 assert_equals(e.data[1], "data:") 58 }) 59 document.body.appendChild(dataFrame) 60 }, "Set data URL frame location.protocol to " + val) 61 }) 62 } 63 </script>