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

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=677638
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <meta charset="utf-8">
michael@0 8 <title>Test for Bug 677638 - port cloning</title>
michael@0 9 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 11 </head>
michael@0 12 <body>
michael@0 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=677638">Mozilla Bug 677638</a>
michael@0 14 <div id="content"></div>
michael@0 15 <pre id="test">
michael@0 16 </pre>
michael@0 17 <script type="application/javascript">
michael@0 18
michael@0 19 function start() {
michael@0 20 var a = new MessageChannel();
michael@0 21 ok(a, "MessageChannel created");
michael@0 22
michael@0 23 window.addEventListener('message', receiveMessage, false);
michael@0 24 function receiveMessage(evt) {
michael@0 25 if (evt.data.status == 'READY') {
michael@0 26 runTest();
michael@0 27 } else {
michael@0 28 ok(false, "Unknown message");
michael@0 29 }
michael@0 30 }
michael@0 31
michael@0 32 var div = document.getElementById("content");
michael@0 33 ok(div, "Parent exists");
michael@0 34
michael@0 35 var ifr = document.createElement("iframe");
michael@0 36 ifr.addEventListener("load", iframeLoaded, false);
michael@0 37 ifr.setAttribute('src', "iframe_messageChannel_post.html");
michael@0 38 div.appendChild(ifr);
michael@0 39
michael@0 40 function iframeLoaded() {
michael@0 41 ifr.contentWindow.postMessage({ port: a.port2 }, '*', [a.port2]);
michael@0 42 }
michael@0 43
michael@0 44 var tests = [ 42,
michael@0 45 null,
michael@0 46 undefined,
michael@0 47 "hello world",
michael@0 48 new Blob([]),
michael@0 49 true ];
michael@0 50
michael@0 51 a.port1.onmessage = function(evt) {
michael@0 52 ok(tests.length, "We are waiting for a message");
michael@0 53 is(tests[0], evt.data, "Value ok: " + tests[0]);
michael@0 54 tests.shift();
michael@0 55 runTest();
michael@0 56 }
michael@0 57
michael@0 58 function runTest() {
michael@0 59 if (!tests.length) {
michael@0 60 SimpleTest.finish();
michael@0 61 return;
michael@0 62 }
michael@0 63
michael@0 64 a.port1.postMessage(tests[0]);
michael@0 65 }
michael@0 66 }
michael@0 67
michael@0 68 SimpleTest.waitForExplicitFinish();
michael@0 69 SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]}, start);
michael@0 70 </script>
michael@0 71 </body>
michael@0 72 </html>

mercurial