|
1 <!DOCTYPE html> |
|
2 <html> |
|
3 <head> |
|
4 <title>Overriding postMessage and dispatchEvent bindings</title> |
|
5 <script type="application/javascript"> |
|
6 window.postMessage = function (evt) |
|
7 { |
|
8 window.parent.postMessage("FAIL overridden postMessage called", "*"); |
|
9 }; |
|
10 |
|
11 var count = 0; |
|
12 |
|
13 function receiveMessage(evt) |
|
14 { |
|
15 count++; |
|
16 if (count == 1) |
|
17 { |
|
18 window.dispatchEvent = function(evt) |
|
19 { |
|
20 window.parent.postMessage("FAIL", "*"); |
|
21 throw "dispatchEvent threw"; |
|
22 }; |
|
23 } |
|
24 |
|
25 window.parent.postMessage(evt.data, "http://mochi.test:8888"); |
|
26 } |
|
27 |
|
28 function setup() |
|
29 { |
|
30 var target = document.getElementById("location"); |
|
31 target.textContent = location.hostname + ":" + (location.port || 80); |
|
32 } |
|
33 |
|
34 window.addEventListener("message", receiveMessage, false); |
|
35 |
|
36 window.addEventListener("load", setup, false); |
|
37 </script> |
|
38 </head> |
|
39 <body> |
|
40 <h1 id="location">No location!</h1> |
|
41 </body> |
|
42 </html> |