dom/base/test/test_messageChannel_post.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   function start() {
    20     var a = new MessageChannel();
    21     ok(a, "MessageChannel created");
    23     window.addEventListener('message', receiveMessage, false);
    24     function receiveMessage(evt) {
    25       if (evt.data.status == 'READY') {
    26         runTest();
    27       } else {
    28         ok(false, "Unknown message");
    29       }
    30     }
    32     var div = document.getElementById("content");
    33     ok(div, "Parent exists");
    35     var ifr = document.createElement("iframe");
    36     ifr.addEventListener("load", iframeLoaded, false);
    37     ifr.setAttribute('src', "iframe_messageChannel_post.html");
    38     div.appendChild(ifr);
    40     function iframeLoaded() {
    41       ifr.contentWindow.postMessage({ port: a.port2 }, '*', [a.port2]);
    42     }
    44     var tests = [ 42,
    45                   null,
    46                   undefined,
    47                   "hello world",
    48                   new Blob([]),
    49                   true ];
    51     a.port1.onmessage = function(evt) {
    52       ok(tests.length, "We are waiting for a message");
    53       is(tests[0], evt.data, "Value ok: " + tests[0]);
    54       tests.shift();
    55       runTest();
    56     }
    58     function runTest() {
    59       if (!tests.length) {
    60         SimpleTest.finish();
    61         return;
    62       }
    64       a.port1.postMessage(tests[0]);
    65     }
    66   }
    68   SimpleTest.waitForExplicitFinish();
    69   SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]}, start);
    70   </script>
    71 </body>
    72 </html>

mercurial