location-protocol-setter.html (2052B)
1 <!doctype html> 2 <title>Set location.protocol to schemes that throw</title> 3 <script src=/resources/testharness.js></script> 4 <script src=/resources/testharnessreport.js></script> 5 <div id=log></div> 6 <iframe src="data:text/html,<script> 7 onmessage = (e) => { 8 let results = []; 9 e.data.forEach((val) => { 10 try { 11 location.protocol = val; 12 results.push('failure') 13 } catch(e) { 14 results.push(e.name) 15 } 16 }); 17 parent.postMessage(results, '*') 18 } 19 </script>"></iframe> 20 <iframe srcdoc="<script> 21 onmessage = (e) => { 22 let results = []; 23 e.data.forEach((val) => { 24 try { 25 location.protocol = val; 26 results.push('failure') 27 } catch(e) { 28 results.push(e.name) 29 } 30 }); 31 parent.postMessage(results, '*') 32 } 33 </script>"></iframe> 34 <script> 35 const broken = [ 36 '\x00', 37 '\x01', 38 '\x09', // becomes the empty string 39 '\x0A', // becomes the empty string 40 '\x0C', 41 '\x0D', 42 '\x20', 43 '\x21', 44 '\x7F', 45 '\x80', 46 '\xFF', 47 ':', 48 '†', 49 '\x00x', 50 '\x01x', 51 '\x20x', 52 '\x21x', 53 '\x7Fx', 54 '\x80x', 55 '\xFFx', 56 ':x', 57 '†x', 58 '\x00X', 59 '\x01X', 60 '\x20X', 61 '\x21X', 62 '\x7FX', 63 '\x80X', 64 '\xFFX', 65 ':X', 66 '†X', 67 'x\x00', 68 'x\x01', 69 'x\x20', 70 'x\x21', 71 'x\x7F', 72 'x\x80', 73 'x\xFF', 74 'x†', 75 'X\x00', 76 'X\x01', 77 'X\x20', 78 'X\x21', 79 'X\x7F', 80 'X\x80', 81 'X\xFF', 82 'X†', 83 ]; 84 85 broken.forEach(val => { 86 test(() => { 87 assert_throws_dom("SyntaxError", () => { location.protocol = val }) 88 }, `${encodeURI(val)} (percent-encoded here for clarity) is not a scheme`) 89 }) 90 let c = 0 91 async_test((t) => { 92 self.onload = t.step_func(() => { 93 self.onmessage = t.step_func((e) => { 94 assert_array_equals(e.data, broken.map(() => "SyntaxError")) 95 c++ 96 if(c === 2) { 97 t.done() 98 } 99 }) 100 self[0].postMessage(broken, "*") 101 self[1].postMessage(broken, "*") 102 }) 103 }, "Equivalent tests for data URL and srcdoc <iframe>s") 104 </script>