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

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 // This test checks if MessagePorts can be shared with iframes
michael@0 20 function test_iframe() {
michael@0 21 window.addEventListener('message', receiveMessage, false);
michael@0 22 function receiveMessage(evt) {
michael@0 23 if (evt.data.status == 'OK') {
michael@0 24 ok(true, evt.data.message);
michael@0 25 } else if (evt.data.status == 'KO') {
michael@0 26 ok(false, evt.data.message);
michael@0 27 } else if (evt.data.status == 'FINISH') {
michael@0 28 ok (evt.data.port instanceof MessagePort, "Data contains a MessagePort");
michael@0 29 window.removeEventListener('message', receiveMessage);
michael@0 30 runTest();
michael@0 31 } else {
michael@0 32 ok(false, "Unknown message");
michael@0 33 }
michael@0 34 }
michael@0 35
michael@0 36 var a = new MessageChannel();
michael@0 37 ok(a, "MessageChannel created");
michael@0 38
michael@0 39 var div = document.getElementById("content");
michael@0 40 ok(div, "Parent exists");
michael@0 41
michael@0 42 var ifr = document.createElement("iframe");
michael@0 43 ifr.addEventListener("load", iframeLoaded, false);
michael@0 44 ifr.setAttribute('src', "iframe_messageChannel_cloning.html");
michael@0 45 div.appendChild(ifr);
michael@0 46
michael@0 47 function iframeLoaded() {
michael@0 48 ifr.contentWindow.postMessage({ port: a.port2 }, '*', [a.port2]);
michael@0 49 }
michael@0 50 }
michael@0 51
michael@0 52 var tests = [
michael@0 53 test_iframe
michael@0 54 ];
michael@0 55
michael@0 56 function runTest() {
michael@0 57 if (!tests.length) {
michael@0 58 SimpleTest.finish();
michael@0 59 return;
michael@0 60 }
michael@0 61
michael@0 62 var test = tests.shift();
michael@0 63 test();
michael@0 64 }
michael@0 65
michael@0 66 SimpleTest.waitForExplicitFinish();
michael@0 67 SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]}, runTest);
michael@0 68 </script>
michael@0 69 </body>
michael@0 70 </html>

mercurial