dom/base/test/test_messageChannel_post.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/base/test/test_messageChannel_post.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,72 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=677638
     1.8 +-->
     1.9 +<head>
    1.10 +  <meta charset="utf-8">
    1.11 +  <title>Test for Bug 677638 - port cloning</title>
    1.12 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.13 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.14 +</head>
    1.15 +<body>
    1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=677638">Mozilla Bug 677638</a>
    1.17 +<div id="content"></div>
    1.18 +<pre id="test">
    1.19 +</pre>
    1.20 +  <script type="application/javascript">
    1.21 +
    1.22 +  function start() {
    1.23 +    var a = new MessageChannel();
    1.24 +    ok(a, "MessageChannel created");
    1.25 +
    1.26 +    window.addEventListener('message', receiveMessage, false);
    1.27 +    function receiveMessage(evt) {
    1.28 +      if (evt.data.status == 'READY') {
    1.29 +        runTest();
    1.30 +      } else {
    1.31 +        ok(false, "Unknown message");
    1.32 +      }
    1.33 +    }
    1.34 +
    1.35 +    var div = document.getElementById("content");
    1.36 +    ok(div, "Parent exists");
    1.37 +
    1.38 +    var ifr = document.createElement("iframe");
    1.39 +    ifr.addEventListener("load", iframeLoaded, false);
    1.40 +    ifr.setAttribute('src', "iframe_messageChannel_post.html");
    1.41 +    div.appendChild(ifr);
    1.42 +
    1.43 +    function iframeLoaded() {
    1.44 +      ifr.contentWindow.postMessage({ port: a.port2 }, '*', [a.port2]);
    1.45 +    }
    1.46 +
    1.47 +    var tests = [ 42,
    1.48 +                  null,
    1.49 +                  undefined,
    1.50 +                  "hello world",
    1.51 +                  new Blob([]),
    1.52 +                  true ];
    1.53 +
    1.54 +    a.port1.onmessage = function(evt) {
    1.55 +      ok(tests.length, "We are waiting for a message");
    1.56 +      is(tests[0], evt.data, "Value ok: " + tests[0]);
    1.57 +      tests.shift();
    1.58 +      runTest();
    1.59 +    }
    1.60 +
    1.61 +    function runTest() {
    1.62 +      if (!tests.length) {
    1.63 +        SimpleTest.finish();
    1.64 +        return;
    1.65 +      }
    1.66 +
    1.67 +      a.port1.postMessage(tests[0]);
    1.68 +    }
    1.69 +  }
    1.70 +
    1.71 +  SimpleTest.waitForExplicitFinish();
    1.72 +  SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]}, start);
    1.73 +  </script>
    1.74 +</body>
    1.75 +</html>

mercurial