dom/tests/mochitest/chrome/test_sandbox_postMessage.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial