1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/base/test/test_messageChannel_cloning.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,70 @@ 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 + // This test checks if MessagePorts can be shared with iframes 1.23 + function test_iframe() { 1.24 + window.addEventListener('message', receiveMessage, false); 1.25 + function receiveMessage(evt) { 1.26 + if (evt.data.status == 'OK') { 1.27 + ok(true, evt.data.message); 1.28 + } else if (evt.data.status == 'KO') { 1.29 + ok(false, evt.data.message); 1.30 + } else if (evt.data.status == 'FINISH') { 1.31 + ok (evt.data.port instanceof MessagePort, "Data contains a MessagePort"); 1.32 + window.removeEventListener('message', receiveMessage); 1.33 + runTest(); 1.34 + } else { 1.35 + ok(false, "Unknown message"); 1.36 + } 1.37 + } 1.38 + 1.39 + var a = new MessageChannel(); 1.40 + ok(a, "MessageChannel created"); 1.41 + 1.42 + var div = document.getElementById("content"); 1.43 + ok(div, "Parent exists"); 1.44 + 1.45 + var ifr = document.createElement("iframe"); 1.46 + ifr.addEventListener("load", iframeLoaded, false); 1.47 + ifr.setAttribute('src', "iframe_messageChannel_cloning.html"); 1.48 + div.appendChild(ifr); 1.49 + 1.50 + function iframeLoaded() { 1.51 + ifr.contentWindow.postMessage({ port: a.port2 }, '*', [a.port2]); 1.52 + } 1.53 + } 1.54 + 1.55 + var tests = [ 1.56 + test_iframe 1.57 + ]; 1.58 + 1.59 + function runTest() { 1.60 + if (!tests.length) { 1.61 + SimpleTest.finish(); 1.62 + return; 1.63 + } 1.64 + 1.65 + var test = tests.shift(); 1.66 + test(); 1.67 + } 1.68 + 1.69 + SimpleTest.waitForExplicitFinish(); 1.70 + SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]}, runTest); 1.71 + </script> 1.72 +</body> 1.73 +</html>