dom/base/test/test_messageChannel_cloning.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=677638
     5 -->
     6 <head>
     7   <meta charset="utf-8">
     8   <title>Test for Bug 677638 - port cloning</title>
     9   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    10   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    11 </head>
    12 <body>
    13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=677638">Mozilla Bug 677638</a>
    14 <div id="content"></div>
    15 <pre id="test">
    16 </pre>
    17   <script type="application/javascript">
    19   // This test checks if MessagePorts can be shared with iframes
    20   function test_iframe() {
    21     window.addEventListener('message', receiveMessage, false);
    22     function receiveMessage(evt) {
    23       if (evt.data.status == 'OK') {
    24         ok(true, evt.data.message);
    25       } else if (evt.data.status == 'KO') {
    26         ok(false, evt.data.message);
    27       } else if (evt.data.status == 'FINISH') {
    28         ok (evt.data.port instanceof MessagePort, "Data contains a MessagePort");
    29         window.removeEventListener('message', receiveMessage);
    30         runTest();
    31       } else {
    32         ok(false, "Unknown message");
    33       }
    34     }
    36     var a = new MessageChannel();
    37     ok(a, "MessageChannel created");
    39     var div = document.getElementById("content");
    40     ok(div, "Parent exists");
    42     var ifr = document.createElement("iframe");
    43     ifr.addEventListener("load", iframeLoaded, false);
    44     ifr.setAttribute('src', "iframe_messageChannel_cloning.html");
    45     div.appendChild(ifr);
    47     function iframeLoaded() {
    48       ifr.contentWindow.postMessage({ port: a.port2 }, '*', [a.port2]);
    49     }
    50   }
    52   var tests = [
    53     test_iframe
    54   ];
    56   function runTest() {
    57     if (!tests.length) {
    58       SimpleTest.finish();
    59       return;
    60     }
    62     var test = tests.shift();
    63     test();
    64   }
    66   SimpleTest.waitForExplicitFinish();
    67   SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]}, runTest);
    68   </script>
    69 </body>
    70 </html>

mercurial