| OLD | NEW |
| (Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <script src="resources/recv.js"></script> |
| 5 <script> |
| 6 if (window.testRunner) { |
| 7 testRunner.dumpAsText(); |
| 8 testRunner.waitUntilDone(); |
| 9 } |
| 10 |
| 11 var totalExpectedReplies = 0; |
| 12 var receivedMessages = []; |
| 13 |
| 14 function tryPostMessage(win, origin, shouldExpectReply) { |
| 15 try { |
| 16 win.postMessage("Trying origin=" + origin, origin); |
| 17 if (shouldExpectReply) |
| 18 totalExpectedReplies++; |
| 19 } catch(ex) { |
| 20 log("Error sending message to " + origin + ". " + ex); |
| 21 } |
| 22 } |
| 23 |
| 24 function receiveAndSort(e) { |
| 25 var msg = extractMessage(e); |
| 26 receivedMessages.push(msg); |
| 27 if (receivedMessages.length == totalExpectedReplies) { |
| 28 receivedMessages.sort(); |
| 29 receivedMessages.map(log); |
| 30 if (window.testRunner) |
| 31 testRunner.notifyDone(); |
| 32 } |
| 33 } |
| 34 |
| 35 addEventListener("message", receiveAndSort, false); |
| 36 |
| 37 function test() { |
| 38 var win127 = document.getElementById('iframe-127').contentWindow; |
| 39 |
| 40 // Should succeed: |
| 41 tryPostMessage(win127, "http://127.0.0.1:8000", true); |
| 42 tryPostMessage(win127, "http://127.0.0.1:8000/", true); |
| 43 tryPostMessage(win127, "http://127.0.0.1:8000/foo", true); |
| 44 tryPostMessage(win127, "http://127.0.0.1:8000/foo?bar#baz", true); |
| 45 tryPostMessage(win127, "http://127.0.0.1:8000/foo?bar", true); |
| 46 tryPostMessage(win127, "http://user:pass@127.0.0.1:8000/foo?bar#baz", true); |
| 47 |
| 48 // Should fail: |
| 49 tryPostMessage(win127, "http://127.0.0.1:9090", false); |
| 50 tryPostMessage(win127, "http://127.0.0.1", false); |
| 51 tryPostMessage(win127, "https://127.0.0.1", false); |
| 52 tryPostMessage(win127, "https://127.0.0.1:8000", false); |
| 53 tryPostMessage(win127, "http://www.example.com", false); |
| 54 tryPostMessage(win127, "asdf:", false); |
| 55 |
| 56 // Should throw syntax error: |
| 57 tryPostMessage(win127, "", false); |
| 58 tryPostMessage(win127, "asdf", false); |
| 59 tryPostMessage(win127, "/tmp/foo", false); |
| 60 tryPostMessage(win127, "//localhost", false); |
| 61 tryPostMessage(win127, "http:", false); |
| 62 } |
| 63 |
| 64 </script> |
| 65 <body onload="test()"> |
| 66 <div>window.location.href = <script>document.write(window.location.href);</scrip
t></div> |
| 67 <div><iframe src="http://127.0.0.1:8000/security/postMessage/resources/post-mess
age-listener.html" |
| 68 id="iframe-127" width="800" height="300" style="border: 1px solid black;"></if
rame> |
| 69 <div id="result">waiting...</div> |
| 70 </body> |
| 71 </html> |
| OLD | NEW |