|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <head> |
|
4 <title>Testing postMessage from sandbox</title> |
|
5 <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
|
6 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> |
|
7 <script type="application/javascript"> |
|
8 SimpleTest.waitForExplicitFinish(); |
|
9 function doTest() { |
|
10 var sandbox = Components.utils.Sandbox("http://mochi.test:8888/", { wantXrays: true }); |
|
11 var win = window.frames["sameDomain"]; |
|
12 sandbox.win = win; |
|
13 sandbox.is = is; |
|
14 sandbox.done = SimpleTest.finish; |
|
15 |
|
16 result = Components.utils.evalInSandbox('var data = {some:"data"};' |
|
17 +'win.addEventListener("message", receiveMessage, false);' |
|
18 +'function receiveMessage(event)' |
|
19 +'{' |
|
20 +' is(JSON.stringify(event.data), JSON.stringify(data), "Received the expected message data");' |
|
21 +' done();' |
|
22 +'}' |
|
23 +'win.postMessage(data, "*")' |
|
24 , sandbox); |
|
25 } |
|
26 |
|
27 addLoadEvent(doTest); |
|
28 </script> |
|
29 </head> |
|
30 <body> |
|
31 <iframe src="http://mochi.test:8888/" |
|
32 id="sameDomain" name="sameDomain"> |
|
33 </iframe> |
|
34 </body> |
|
35 </html> |
|
36 |