dom/tests/mochitest/chrome/test_sandbox_postMessage.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/chrome/test_sandbox_postMessage.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,36 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>Testing postMessage from sandbox</title>
     1.8 +  <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
    1.10 +<script type="application/javascript">
    1.11 +  SimpleTest.waitForExplicitFinish();
    1.12 +  function doTest() {
    1.13 +    var sandbox = Components.utils.Sandbox("http://mochi.test:8888/", { wantXrays: true });
    1.14 +    var win = window.frames["sameDomain"];
    1.15 +    sandbox.win = win;
    1.16 +    sandbox.is = is;
    1.17 +    sandbox.done = SimpleTest.finish;
    1.18 +
    1.19 +    result = Components.utils.evalInSandbox('var data = {some:"data"};'
    1.20 +    +'win.addEventListener("message", receiveMessage, false);'
    1.21 +    +'function receiveMessage(event)'
    1.22 +    +'{'
    1.23 +    +'  is(JSON.stringify(event.data), JSON.stringify(data), "Received the expected message data");'
    1.24 +    +'  done();'
    1.25 +    +'}'
    1.26 +    +'win.postMessage(data, "*")'
    1.27 +    , sandbox);
    1.28 +  }
    1.29 +
    1.30 +  addLoadEvent(doTest);
    1.31 +</script>
    1.32 +</head>
    1.33 +<body>
    1.34 +<iframe src="http://mochi.test:8888/"
    1.35 +  id="sameDomain" name="sameDomain">
    1.36 +</iframe>
    1.37 +</body>
    1.38 +</html>
    1.39 +

mercurial