summaryrefslogtreecommitdiffstats
path: root/dom/messagechannel/tests
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /dom/messagechannel/tests
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/messagechannel/tests')
-rw-r--r--dom/messagechannel/tests/chrome.ini12
-rw-r--r--dom/messagechannel/tests/iframe_messageChannel_chrome.html11
-rw-r--r--dom/messagechannel/tests/iframe_messageChannel_cloning.html22
-rw-r--r--dom/messagechannel/tests/iframe_messageChannel_pingpong.html33
-rw-r--r--dom/messagechannel/tests/iframe_messageChannel_post.html24
-rw-r--r--dom/messagechannel/tests/iframe_messageChannel_sharedWorker2.html14
-rw-r--r--dom/messagechannel/tests/iframe_messageChannel_transferable.html26
-rw-r--r--dom/messagechannel/tests/mm_messageChannel.js76
-rw-r--r--dom/messagechannel/tests/mm_messageChannelParent.js143
-rw-r--r--dom/messagechannel/tests/mm_messageChannelParent.xul12
-rw-r--r--dom/messagechannel/tests/mm_messageChannelParentNotRemote.xul12
-rw-r--r--dom/messagechannel/tests/mochitest.ini28
-rw-r--r--dom/messagechannel/tests/moz.build8
-rw-r--r--dom/messagechannel/tests/sharedWorker2_messageChannel.js7
-rw-r--r--dom/messagechannel/tests/sharedWorker_messageChannel.js8
-rw-r--r--dom/messagechannel/tests/test_messageChannel.html43
-rw-r--r--dom/messagechannel/tests/test_messageChannel.xul38
-rw-r--r--dom/messagechannel/tests/test_messageChannelWithMessageManager.xul28
-rw-r--r--dom/messagechannel/tests/test_messageChannelWithMessageManagerNotRemote.xul28
-rw-r--r--dom/messagechannel/tests/test_messageChannel_any.html115
-rw-r--r--dom/messagechannel/tests/test_messageChannel_bug1178076.html38
-rw-r--r--dom/messagechannel/tests/test_messageChannel_bug1224825.html94
-rw-r--r--dom/messagechannel/tests/test_messageChannel_cloning.html70
-rw-r--r--dom/messagechannel/tests/test_messageChannel_forceClose.html30
-rw-r--r--dom/messagechannel/tests/test_messageChannel_pingpong.html77
-rw-r--r--dom/messagechannel/tests/test_messageChannel_post.html76
-rw-r--r--dom/messagechannel/tests/test_messageChannel_selfTransferring.html33
-rw-r--r--dom/messagechannel/tests/test_messageChannel_sharedWorker.html36
-rw-r--r--dom/messagechannel/tests/test_messageChannel_sharedWorker2.html34
-rw-r--r--dom/messagechannel/tests/test_messageChannel_start.html235
-rw-r--r--dom/messagechannel/tests/test_messageChannel_transferable.html111
-rw-r--r--dom/messagechannel/tests/test_messageChannel_unshipped.html123
-rw-r--r--dom/messagechannel/tests/test_messageChannel_worker.html60
-rw-r--r--dom/messagechannel/tests/test_messageChannel_worker_forceClose.html27
-rw-r--r--dom/messagechannel/tests/worker_messageChannel.js119
-rw-r--r--dom/messagechannel/tests/worker_messageChannel_any.js7
36 files changed, 1858 insertions, 0 deletions
diff --git a/dom/messagechannel/tests/chrome.ini b/dom/messagechannel/tests/chrome.ini
new file mode 100644
index 000000000..8613309c5
--- /dev/null
+++ b/dom/messagechannel/tests/chrome.ini
@@ -0,0 +1,12 @@
+[DEFAULT]
+support-files =
+ iframe_messageChannel_chrome.html
+ mm_messageChannelParent.xul
+ mm_messageChannelParentNotRemote.xul
+ mm_messageChannelParent.js
+ mm_messageChannel.js
+
+[test_messageChannel.xul]
+[test_messageChannelWithMessageManager.xul]
+skip-if = os == 'android'
+[test_messageChannelWithMessageManagerNotRemote.xul]
diff --git a/dom/messagechannel/tests/iframe_messageChannel_chrome.html b/dom/messagechannel/tests/iframe_messageChannel_chrome.html
new file mode 100644
index 000000000..1c9e4d3e1
--- /dev/null
+++ b/dom/messagechannel/tests/iframe_messageChannel_chrome.html
@@ -0,0 +1,11 @@
+<!DOCTYPE HTML>
+<html>
+<body>
+ <script type="application/javascript">
+
+window.addEventListener('message', receiveMessage, false);
+function receiveMessage(evt) {
+ evt.data.postMessage("Hello world");
+}
+ </script>
+</body>
diff --git a/dom/messagechannel/tests/iframe_messageChannel_cloning.html b/dom/messagechannel/tests/iframe_messageChannel_cloning.html
new file mode 100644
index 000000000..de03cead9
--- /dev/null
+++ b/dom/messagechannel/tests/iframe_messageChannel_cloning.html
@@ -0,0 +1,22 @@
+<!DOCTYPE HTML>
+<html>
+<body>
+ <script type="application/javascript">
+
+ function ok(a, msg) {
+ window.parent.postMessage({ status: a ? "OK" : "KO", message: msg }, "*");
+ }
+
+ window.addEventListener('message', receiveMessage, false);
+ function receiveMessage(evt) {
+ ok (evt.data, "Data received");
+ ok (evt.data.port instanceof MessagePort, "Data contains a MessagePort");
+
+ var a = new MessageChannel();
+ window.parent.postMessage({ status: "FINISH", port: a.port2 }, '*', [a.port2]);
+ }
+
+ </script>
+</body>
+</html>
+
diff --git a/dom/messagechannel/tests/iframe_messageChannel_pingpong.html b/dom/messagechannel/tests/iframe_messageChannel_pingpong.html
new file mode 100644
index 000000000..d83d75c48
--- /dev/null
+++ b/dom/messagechannel/tests/iframe_messageChannel_pingpong.html
@@ -0,0 +1,33 @@
+<!DOCTYPE HTML>
+<html>
+<body>
+ <script type="application/javascript">
+
+ function ok(what, msg) {
+ window.parent.postMessage({type: what ? 'OK' : 'KO', msg: msg }, '*');
+ }
+
+ window.addEventListener('message', receiveMessage, false);
+ function receiveMessage(evt) {
+ if (evt.data.type == 'PORT') {
+ var port = evt.data.port;
+ var counter = 0;
+ port.onmessage = function(evt) {
+ if (counter++ == 0) {
+ ok(!(evt.data % 2), "The number " + evt.data + " has been received correctly by the iframe");
+
+ window.parent.postMessage({ type: 'PORT', port: port }, '*', [port]);
+ }
+ else {
+ ok(false, "Wrong message!");
+ }
+ }
+ } else {
+ ok(false, "Unknown message");
+ }
+ }
+
+ </script>
+</body>
+</html>
+
diff --git a/dom/messagechannel/tests/iframe_messageChannel_post.html b/dom/messagechannel/tests/iframe_messageChannel_post.html
new file mode 100644
index 000000000..e551dd61c
--- /dev/null
+++ b/dom/messagechannel/tests/iframe_messageChannel_post.html
@@ -0,0 +1,24 @@
+<!DOCTYPE HTML>
+<html>
+<body>
+ <script type="application/javascript">
+
+ var port;
+
+ window.addEventListener('message', receiveMessage, false);
+ function receiveMessage(evt) {
+ port = evt.data.port;
+
+ port.addEventListener('message', receivePostMessage, false);
+ function receivePostMessage(evt) {
+ port.postMessage(evt.data);
+ }
+ port.start();
+
+ window.parent.postMessage({ status: "READY" }, '*');
+ }
+
+ </script>
+</body>
+</html>
+
diff --git a/dom/messagechannel/tests/iframe_messageChannel_sharedWorker2.html b/dom/messagechannel/tests/iframe_messageChannel_sharedWorker2.html
new file mode 100644
index 000000000..a693cba22
--- /dev/null
+++ b/dom/messagechannel/tests/iframe_messageChannel_sharedWorker2.html
@@ -0,0 +1,14 @@
+<!DOCTYPE HTML>
+<html>
+<body>
+ <script type="application/javascript">
+
+ var a = new SharedWorker('sharedWorker2_messageChannel.js');
+ a.port.onmessage = function(evt) {
+ evt.ports[0].postMessage("Hello from the iframe!");
+ }
+
+ </script>
+</body>
+</html>
+
diff --git a/dom/messagechannel/tests/iframe_messageChannel_transferable.html b/dom/messagechannel/tests/iframe_messageChannel_transferable.html
new file mode 100644
index 000000000..108edeb7e
--- /dev/null
+++ b/dom/messagechannel/tests/iframe_messageChannel_transferable.html
@@ -0,0 +1,26 @@
+<!DOCTYPE HTML>
+<html>
+<body>
+ <script type="application/javascript">
+
+ function ok(what, msg) {
+ window.parent.postMessage({type: what ? 'OK' : 'KO', msg: msg }, '*');
+ }
+
+ window.addEventListener('message', receiveMessage, false);
+ function receiveMessage(evt) {
+ ok(evt.ports.length == 1, "Port transferred!");
+
+ var a = new MessageChannel();
+ ok(a, "MessageChannel created");
+ evt.ports[0].postMessage('hello world!', [a.port2]);
+ a.port1.onmessage = function(evt) {
+ evt.target.postMessage(evt.data);
+ }
+ }
+
+ </script>
+</body>
+</html>
+
+
diff --git a/dom/messagechannel/tests/mm_messageChannel.js b/dom/messagechannel/tests/mm_messageChannel.js
new file mode 100644
index 000000000..914d800fd
--- /dev/null
+++ b/dom/messagechannel/tests/mm_messageChannel.js
@@ -0,0 +1,76 @@
+function debug(msg) {
+ dump("[mmMessageChannelChild]" + msg + "\n");
+}
+
+/**
+ * Preparation Test
+ */
+let port;
+let toString = Object.prototype.toString;
+
+(function prepare() {
+ debug("Script loaded.");
+ addTestReceiver();
+ sendAsyncMessage("mmMessagePort:finishScriptLoad", {}, {});
+})();
+
+function ok(condition, message) {
+ debug('condition: ' + condition + ', ' + message + '\n');
+ if (!condition) {
+ sendAsyncMessage("mmMessagePort:fail", { message: message });
+ throw 'failed check: ' + message;
+ }
+}
+
+function is(a, b, message) {
+ ok(a===b, message);
+}
+
+
+/**
+ * Testing codes.
+ */
+function addTestReceiver() {
+ addMessageListener("BasicTest:PortCreated", basicTest);
+ addMessageListener("CloseTest:PortCreated", closeTest);
+ addMessageListener("EmptyTest:PortCreated", emptyTest);
+ addMessageListener("NotTransferableTest:PortCreated", notTransferableTest);
+}
+
+function basicTest(msg) {
+ port = msg.ports[0];
+ is(toString.call(port), "[object MessagePort]", "created MessagePort.");
+
+ port.onmessage = (msg) => {
+ is(msg.data, "BasicTest:StartTest", "Replied message is correct.");
+ port.postMessage("BasicTest:TestOK");
+ };
+
+ sendAsyncMessage("BasicTest:FinishPrepare", { message: "OK" });
+}
+
+function closeTest(msg) {
+ port = msg.ports[0];
+ is(toString.call(port), "[object MessagePort]", "created MessagePort.");
+
+ port.onmessage = (msg) => {
+ ok(msg.data,"CloseTest:StartTest", "Replied message is correct.");
+ port.postMessage("CloseTest:TestOK");
+ };
+
+ port.close();
+
+ sendAsyncMessage("CloseTest:FinishPrepare", { message: "OK"});
+}
+
+function emptyTest(msg) {
+ let portSize = msg.ports.length;
+ is(portSize, 0, "transfered port size is zero.");
+
+ sendAsyncMessage("EmptyTest:FinishPrepare", { message: "OK"});
+}
+
+function notTransferableTest(msg) {
+ sendAsyncMessage("NotTransferableTest:FinishPrepare", {message: "OK"});
+}
+
diff --git a/dom/messagechannel/tests/mm_messageChannelParent.js b/dom/messagechannel/tests/mm_messageChannelParent.js
new file mode 100644
index 000000000..a5ffa2caf
--- /dev/null
+++ b/dom/messagechannel/tests/mm_messageChannelParent.js
@@ -0,0 +1,143 @@
+Components.utils.import("resource://gre/modules/Services.jsm");
+let port;
+let mm;
+
+function info(message) {
+ return opener.wrappedJSObject.info(message);
+}
+
+function ok(condition, message) {
+ return opener.wrappedJSObject.ok(condition, message);
+}
+
+function is(v1, v2, message) {
+ return opener.wrappedJSObject.is(v1, v2, message);
+}
+
+function todo_is(v1, v2, message) {
+ return opener.wrappedJSObject.todo_is(v1, v2, message);
+}
+
+function finish() {
+ opener.setTimeout("done()", 0);
+ window.close();
+}
+
+function debug(msg) {
+ dump("[mmMessageChannelParent]" + msg + "\n");
+}
+
+let tests = [ basic_test,
+ close_test,
+ empty_transferable,
+ not_transferable];
+
+// Test Routine
+function run_tests() {
+ let test = tests.shift();
+ if (test === undefined) {
+ finish();
+ return;
+ }
+
+ test(function() {
+ setTimeout(run_tests,0);
+ });
+}
+
+// Basic communication test.
+function basic_test(finish) {
+ ok(mm, "basic_test");
+
+ let finishPrepare = (msg) => {
+ is(msg.data.message, "OK", "");
+ ok(port, "");
+ port.onmessage = (msg) => {
+ is(msg.data, "BasicTest:TestOK", "");
+ finish();
+ }
+ port.postMessage("BasicTest:StartTest");
+ mm.removeMessageListener("BasicTest:FinishPrepare", finishPrepare);
+ };
+
+ let channel = new MessageChannel();
+ port = channel.port2;
+ mm.addMessageListener("BasicTest:FinishPrepare", finishPrepare);
+ mm.sendAsyncMessage("BasicTest:PortCreated", {}, {}, undefined, [channel.port1]);
+}
+
+// Communicate with closed port.
+function close_test(finish) {
+ ok(mm, "close_test");
+
+ let finishPrepare = (msg) => {
+ is(msg.data.message, "OK", "");
+ ok(port, "");
+
+ port.onmessage = (msg) => {
+ ok(false, "Port is alive.");
+ finish();
+ }
+
+ port.postMessage("CloseTest:StartTest");
+ mm.removeMessageListener("CloseTest:FinishPrepare", finishPrepare);
+ finish();
+ }
+
+ let channel = new MessageChannel();
+ port = channel.port2;
+ mm.addMessageListener("CloseTest:FinishPrepare", finishPrepare);
+ mm.sendAsyncMessage("CloseTest:PortCreated", {}, {}, undefined, [channel.port1]);
+}
+
+// Empty transferable object
+function empty_transferable(finish) {
+ ok(mm, "empty_transferable");
+
+ let finishPrepare = (msg) => {
+ ok(true, "Same basic test.");
+ mm.removeMessageListener("EmptyTest:FinishPrepare", finishPrepare);
+ finish();
+ };
+
+ mm.addMessageListener("EmptyTest:FinishPrepare", finishPrepare);
+ mm.sendAsyncMessage("EmptyTest:PortCreated", {}, {}, undefined, []);
+}
+
+// Not transferable object.
+function not_transferable(finish) {
+ ok(mm, "not_transferable");
+
+ let finishPrepare = (msg) => {
+ ok(true, "Same basic test.");
+ finish();
+ }
+
+ mm.addMessageListener("NotTransferableTest:FinishPrepare", finishPrepare);
+ mm.sendAsyncMessage("NotTransferableTest:PortCreated", {}, {}, undefined, [""]);
+}
+
+/*
+ * Test preparation
+ */
+function finishLoad(msg) {
+ run_tests();
+}
+
+function prepare_test() {
+ debug("start run_tests()");
+ var node = document.getElementById('messagechannel_remote');
+ mm = node.messageManager; //Services.ppmm.getChildAt(1);
+ ok(mm, "created MessageManager.")
+
+ mm.addMessageListener("mmMessagePort:finishScriptLoad", finishLoad);
+ mm.addMessageListener("mmMessagePort:fail", failed_test);
+ //mm.loadProcessScript("chrome://mochitests/content/chrome/dom/messagechannel/tests/mm_messageChannel.js", true);
+ mm.loadFrameScript("chrome://mochitests/content/chrome/dom/messagechannel/tests/mm_messageChannel.js", true);
+ ok(true, "Loaded");
+}
+
+function failed_test() {
+ debug("failed test in child process");
+ ok(false, "");
+}
diff --git a/dom/messagechannel/tests/mm_messageChannelParent.xul b/dom/messagechannel/tests/mm_messageChannelParent.xul
new file mode 100644
index 000000000..5f5c5ae5b
--- /dev/null
+++ b/dom/messagechannel/tests/mm_messageChannelParent.xul
@@ -0,0 +1,12 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
+<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
+<window title="Test MessageChannel API with nsFrameMessageManager(bug 1174624)"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+ onload="prepare_test()">
+
+ <!-- test code goes here -->
+ <script type="application/javascript"
+ src="chrome://mochitests/content/chrome/dom/messagechannel/tests/mm_messageChannelParent.js"></script>
+ <browser type="content" src="about:blank" id="messagechannel_remote" remote="true"/>
+</window>
diff --git a/dom/messagechannel/tests/mm_messageChannelParentNotRemote.xul b/dom/messagechannel/tests/mm_messageChannelParentNotRemote.xul
new file mode 100644
index 000000000..cb3b55dea
--- /dev/null
+++ b/dom/messagechannel/tests/mm_messageChannelParentNotRemote.xul
@@ -0,0 +1,12 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
+<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
+<window title="Test MessageChannel API with nsFrameMessageManager(bug 1174624)"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+ onload="prepare_test()">
+
+ <!-- test code goes here -->
+ <script type="application/javascript"
+ src="chrome://mochitests/content/chrome/dom/messagechannel/tests/mm_messageChannelParent.js"></script>
+ <browser type="content" src="about:blank" id="messagechannel_remote"/>
+</window>
diff --git a/dom/messagechannel/tests/mochitest.ini b/dom/messagechannel/tests/mochitest.ini
new file mode 100644
index 000000000..67d18d06f
--- /dev/null
+++ b/dom/messagechannel/tests/mochitest.ini
@@ -0,0 +1,28 @@
+[DEFAULT]
+support-files =
+ iframe_messageChannel_cloning.html
+ iframe_messageChannel_pingpong.html
+ iframe_messageChannel_post.html
+ iframe_messageChannel_transferable.html
+ worker_messageChannel.js
+ worker_messageChannel_any.js
+ sharedWorker_messageChannel.js
+ sharedWorker2_messageChannel.js
+ iframe_messageChannel_sharedWorker2.html
+
+[test_messageChannel.html]
+[test_messageChannel_cloning.html]
+[test_messageChannel_pingpong.html]
+[test_messageChannel_post.html]
+[test_messageChannel_start.html]
+[test_messageChannel_transferable.html]
+[test_messageChannel_unshipped.html]
+[test_messageChannel_worker.html]
+[test_messageChannel_selfTransferring.html]
+[test_messageChannel_sharedWorker.html]
+[test_messageChannel_sharedWorker2.html]
+[test_messageChannel_any.html]
+[test_messageChannel_forceClose.html]
+[test_messageChannel_bug1178076.html]
+[test_messageChannel_bug1224825.html]
+[test_messageChannel_worker_forceClose.html]
diff --git a/dom/messagechannel/tests/moz.build b/dom/messagechannel/tests/moz.build
new file mode 100644
index 000000000..42fcbb69e
--- /dev/null
+++ b/dom/messagechannel/tests/moz.build
@@ -0,0 +1,8 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+MOCHITEST_MANIFESTS += ['mochitest.ini']
+MOCHITEST_CHROME_MANIFESTS += ['chrome.ini']
diff --git a/dom/messagechannel/tests/sharedWorker2_messageChannel.js b/dom/messagechannel/tests/sharedWorker2_messageChannel.js
new file mode 100644
index 000000000..8cc98aa20
--- /dev/null
+++ b/dom/messagechannel/tests/sharedWorker2_messageChannel.js
@@ -0,0 +1,7 @@
+var mc = new MessageChannel();
+var i = 0;
+
+onconnect = function(evt) {
+ dump("CONNECTING: "+ i +"\n");
+ evt.ports[0].postMessage(42, [mc['port' + ++i]]);
+}
diff --git a/dom/messagechannel/tests/sharedWorker_messageChannel.js b/dom/messagechannel/tests/sharedWorker_messageChannel.js
new file mode 100644
index 000000000..4b24642f9
--- /dev/null
+++ b/dom/messagechannel/tests/sharedWorker_messageChannel.js
@@ -0,0 +1,8 @@
+onconnect = function(evt) {
+ var mc = new MessageChannel();
+
+ evt.ports[0].postMessage(42, [mc.port2]);
+ mc.port1.onmessage = function(e) {
+ mc.port1.postMessage(e.data);
+ }
+}
diff --git a/dom/messagechannel/tests/test_messageChannel.html b/dom/messagechannel/tests/test_messageChannel.html
new file mode 100644
index 000000000..3e761e299
--- /dev/null
+++ b/dom/messagechannel/tests/test_messageChannel.html
@@ -0,0 +1,43 @@
+
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=677638
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 677638 - basic support</title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=677638">Mozilla Bug 677638</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+ <iframe name="x" id="x"></iframe>
+ <iframe name="y" id="y"></iframe>
+</div>
+<pre id="test">
+</pre>
+ <script type="application/javascript">
+
+ /** Test for Bug 677638 **/
+ var a = new MessageChannel();
+ ok(a, "MessageChannel created");
+
+ var port1 = a.port1;
+ ok(port1, "MessageChannel.port1 exists");
+ is(port1, a.port1, "MessageChannel.port1 is port1");
+
+ var port2 = a.port2;
+ ok(port2, "MessageChannel.port1 exists");
+ is(port2, a.port2, "MessageChannel.port2 is port2");
+
+ [ 'postMessage', 'start', 'close' ].forEach(function(e) {
+ ok(e in port1, "MessagePort1." + e + " exists");
+ ok(e in port2, "MessagePort2." + e + " exists");
+ });
+
+ </script>
+</body>
+</html>
diff --git a/dom/messagechannel/tests/test_messageChannel.xul b/dom/messagechannel/tests/test_messageChannel.xul
new file mode 100644
index 000000000..3d8e3485c
--- /dev/null
+++ b/dom/messagechannel/tests/test_messageChannel.xul
@@ -0,0 +1,38 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
+<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
+<window title="Test for MessageChannel API"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+ <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+
+ <!-- test results are displayed in the html:body -->
+ <body xmlns="http://www.w3.org/1999/xhtml" id="body">
+ </body>
+
+ <!-- test code goes here -->
+ <script type="application/javascript"><![CDATA[
+
+ ok("MessageChannel" in window, "Should MessageChannel exist?");
+
+ var channel = new MessageChannel();
+ ok(channel, "MessageChannel is created");
+
+ channel.port1.onmessage = function(evt) {
+ ok(true, "message received!");
+ SimpleTest.finish();
+ }
+
+ var ifr = document.createElement('browser');
+ ifr.setAttribute("src", "iframe_messageChannel_chrome.html");
+ ifr.setAttribute("flex", "1");
+ ifr.addEventListener('load', function() {
+ ifr.contentWindow.postMessage(channel.port2, '*', [channel.port2]);
+ });
+
+ var body = document.getElementById("body");
+ body.appendChild(ifr);
+
+ SimpleTest.waitForExplicitFinish();
+
+ ]]></script>
+</window>
diff --git a/dom/messagechannel/tests/test_messageChannelWithMessageManager.xul b/dom/messagechannel/tests/test_messageChannelWithMessageManager.xul
new file mode 100644
index 000000000..11a1fc585
--- /dev/null
+++ b/dom/messagechannel/tests/test_messageChannelWithMessageManager.xul
@@ -0,0 +1,28 @@
+<?xml version="1.0"?>
+<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
+<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
+ type="text/css"?>
+<window title="Test MessageChannel API with nsFrameMessageManager(bug 1174624)"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+ <script type="application/javascript"
+ src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+
+ <!-- test results are displayed in the html:body -->
+ <body xmlns="http://www.w3.org/1999/xhtml">
+ </body>
+
+ <!-- test code goes here -->
+ <script type="application/javascript"><![CDATA[
+
+ SimpleTest.waitForExplicitFinish();
+
+ function done() {
+ info("done called");
+ SimpleTest.finish();
+ }
+
+ addLoadEvent(function() {
+ window.open("mm_messageChannelParent.xul", "", "chrome");
+ });
+ ]]></script>
+</window>
diff --git a/dom/messagechannel/tests/test_messageChannelWithMessageManagerNotRemote.xul b/dom/messagechannel/tests/test_messageChannelWithMessageManagerNotRemote.xul
new file mode 100644
index 000000000..24ea7ed0d
--- /dev/null
+++ b/dom/messagechannel/tests/test_messageChannelWithMessageManagerNotRemote.xul
@@ -0,0 +1,28 @@
+<?xml version="1.0"?>
+<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
+<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
+ type="text/css"?>
+<window title="Test MessageChannel API with nsFrameMessageManager(bug 1174624)"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+ <script type="application/javascript"
+ src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+
+ <!-- test results are displayed in the html:body -->
+ <body xmlns="http://www.w3.org/1999/xhtml">
+ </body>
+
+ <!-- test code goes here -->
+ <script type="application/javascript"><![CDATA[
+
+ SimpleTest.waitForExplicitFinish();
+
+ function done() {
+ info("done called");
+ SimpleTest.finish();
+ }
+
+ addLoadEvent(function() {
+ window.open("mm_messageChannelParentNotRemote.xul", "", "chrome");
+ });
+ ]]></script>
+</window>
diff --git a/dom/messagechannel/tests/test_messageChannel_any.html b/dom/messagechannel/tests/test_messageChannel_any.html
new file mode 100644
index 000000000..845f5c734
--- /dev/null
+++ b/dom/messagechannel/tests/test_messageChannel_any.html
@@ -0,0 +1,115 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=677638
+-->
+<head>
+ <meta charset="utf-8">
+ <title>MessagePort/Channel any content</title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=677638">Mozilla Bug 677638</a>
+<div id="content"></div>
+<pre id="test">
+</pre>
+ <script type="application/javascript">
+
+var tests = [
+ 'hello world',
+ 123,
+ null,
+ true,
+ new Date(),
+ [ 1, 'test', true, new Date() ],
+ { a: true, b: null, c: new Date(), d: [ true, false, {} ] },
+ new Blob([123], { type: 'plain/text' })
+];
+
+var currentTest = null;
+
+function getType(a) {
+ if (a === null || a === undefined)
+ return 'null';
+
+ if (Array.isArray(a))
+ return 'array';
+
+ if (typeof a == 'object')
+ return 'object';
+
+ return 'primitive';
+}
+
+function compare(a, b) {
+ is (getType(a), getType(b), 'Type matches');
+
+ var type = getType(a);
+ if (type == 'array') {
+ is (a.length, b.length, 'Array.length matches');
+ for (var i = 0; i < a.length; ++i) {
+ compare(a[i], b[i]);
+ }
+
+ return;
+ }
+
+ if (type == 'object') {
+ ok (a !== b, 'They should not match');
+
+ var aProps = [];
+ for (var p in a) aProps.push(p);
+
+ var bProps = [];
+ for (var p in b) bProps.push(p);
+
+ is (aProps.length, bProps.length, 'Props match');
+ is (aProps.sort().toSource(), bProps.sort().toSource(), 'Props match - using toSource()');
+
+ for (var p in a) {
+ compare(a[p], b[p]);
+ }
+
+ return;
+ }
+
+ if (type != 'null') {
+ is (a.toSource(), b.toSource(), 'Matching using toSource()');
+ }
+}
+
+function runTest() {
+ var mc = new MessageChannel('foobar');
+ ok(mc, "MessageChannel can be created");
+
+ mc.port1.onmessage = function(event) {
+ compare(event.data, currentTest);
+ next();
+ }
+
+ function next() {
+ if (!tests.length) {
+ SimpleTest.finish();
+ return;
+ }
+
+ currentTest = tests.shift();
+ mc.port1.postMessage(currentTest);
+ }
+
+ var worker = new Worker("worker_messageChannel_any.js");
+ worker.onmessage = function(event) {
+ if (event.data == "READY") {
+ next();
+ }
+ };
+
+ worker.postMessage(mc.port2, [mc.port2]);
+}
+
+SimpleTest.waitForExplicitFinish();
+runTest();
+ </script>
+</body>
+</html>
diff --git a/dom/messagechannel/tests/test_messageChannel_bug1178076.html b/dom/messagechannel/tests/test_messageChannel_bug1178076.html
new file mode 100644
index 000000000..bf7077250
--- /dev/null
+++ b/dom/messagechannel/tests/test_messageChannel_bug1178076.html
@@ -0,0 +1,38 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1178076
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 1178076</title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1178076">Mozilla Bug 1178076</a>
+<div id="content"></div>
+<pre id="test">
+</pre>
+ <script type="application/javascript">
+
+ function runTest() {
+ onmessage = function(e) {
+ ok(e.ports.length, 1, "A port has been received!");
+ var port = e.ports[0];
+ ok(port instanceof MessagePort, "This is a port.");
+ SimpleTest.finish();
+ }
+
+ // In this test we want to see if we leak a neutered port closing port1
+ // and sending port2 to the same window. This operation doesn't involve IPC.
+ var mc = new MessageChannel();
+ mc.port1.close();
+ postMessage(42, '*', [mc.port2]);
+ }
+
+ SimpleTest.waitForExplicitFinish();
+ runTest();
+ </script>
+</body>
+</html>
diff --git a/dom/messagechannel/tests/test_messageChannel_bug1224825.html b/dom/messagechannel/tests/test_messageChannel_bug1224825.html
new file mode 100644
index 000000000..f50115547
--- /dev/null
+++ b/dom/messagechannel/tests/test_messageChannel_bug1224825.html
@@ -0,0 +1,94 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1224825
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 1224825</title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1224825">Mozilla Bug 1224825</a>
+<div id="content"></div>
+<pre id="test">
+</pre>
+ <script type="application/javascript">
+
+var MAX = 100;
+
+function test_fullDeliveredMessages() {
+ var worker = new Worker('data:javascript,onmessage = function(e) { e.ports[0].onmessage = function(evt) { postMessage(evt.data);}}');
+
+ var count = 0;
+ worker.onmessage = function(e) {
+ is(e.data, count, "Correct value expected!");
+ ok(count < MAX,"No count > MAX messages!");
+ if (++count == MAX) {
+
+ SimpleTest.requestFlakyTimeout("Testing an event not happening");
+ setTimeout(function() {
+ runTests();
+ }, 200);
+
+ info("All the messages correctly received");
+ }
+ }
+
+ var mc = new MessageChannel();
+ worker.postMessage(42, [mc.port2]);
+
+ for (var i = 0; i < MAX; ++i) {
+ mc.port1.postMessage(i);
+ }
+
+ mc.port1.close();
+
+ for (var i = 0; i < MAX * 2; ++i) {
+ mc.port1.postMessage(i);
+ }
+}
+
+function test_closeInBetween() {
+ var mc = new MessageChannel();
+
+ for (var i = 0; i < MAX; ++i) {
+ mc.port1.postMessage(i);
+ }
+
+ mc.port1.onmessage = function(e) {
+ ok (e.data < MAX/2, "Correct message received from port1:" + e.data);
+ }
+
+ mc.port2.onmessage = function(e) {
+ ok (e.data < MAX, "Correct message received from port2:" + e.data);
+ if (e.data == MAX/2) {
+ mc.port2.close();
+ }
+
+ mc.port2.postMessage(e.data);
+
+ if (e.data == MAX - 1) {
+ runTests();
+ }
+ }
+}
+
+var tests = [ test_fullDeliveredMessages, test_closeInBetween ];
+
+function runTests() {
+ if (!tests.length) {
+ SimpleTest.finish();
+ return;
+ }
+
+ var test = tests.shift();
+ test();
+}
+
+SimpleTest.waitForExplicitFinish();
+runTests();
+ </script>
+</body>
+</html>
diff --git a/dom/messagechannel/tests/test_messageChannel_cloning.html b/dom/messagechannel/tests/test_messageChannel_cloning.html
new file mode 100644
index 000000000..36aa3f0b7
--- /dev/null
+++ b/dom/messagechannel/tests/test_messageChannel_cloning.html
@@ -0,0 +1,70 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=677638
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 677638 - port cloning</title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=677638">Mozilla Bug 677638</a>
+<div id="content"></div>
+<pre id="test">
+</pre>
+ <script type="application/javascript">
+
+ // This test checks if MessagePorts can be shared with iframes
+ function test_iframe() {
+ window.addEventListener('message', receiveMessage, false);
+ function receiveMessage(evt) {
+ if (evt.data.status == 'OK') {
+ ok(true, evt.data.message);
+ } else if (evt.data.status == 'KO') {
+ ok(false, evt.data.message);
+ } else if (evt.data.status == 'FINISH') {
+ ok (evt.data.port instanceof MessagePort, "Data contains a MessagePort");
+ window.removeEventListener('message', receiveMessage);
+ runTest();
+ } else {
+ ok(false, "Unknown message");
+ }
+ }
+
+ var a = new MessageChannel();
+ ok(a, "MessageChannel created");
+
+ var div = document.getElementById("content");
+ ok(div, "Parent exists");
+
+ var ifr = document.createElement("iframe");
+ ifr.addEventListener("load", iframeLoaded, false);
+ ifr.setAttribute('src', "iframe_messageChannel_cloning.html");
+ div.appendChild(ifr);
+
+ function iframeLoaded() {
+ ifr.contentWindow.postMessage({ port: a.port2 }, '*', [a.port2]);
+ }
+ }
+
+ var tests = [
+ test_iframe
+ ];
+
+ function runTest() {
+ if (!tests.length) {
+ SimpleTest.finish();
+ return;
+ }
+
+ var test = tests.shift();
+ test();
+ }
+
+ SimpleTest.waitForExplicitFinish();
+ runTest();
+ </script>
+</body>
+</html>
diff --git a/dom/messagechannel/tests/test_messageChannel_forceClose.html b/dom/messagechannel/tests/test_messageChannel_forceClose.html
new file mode 100644
index 000000000..fd3efdc70
--- /dev/null
+++ b/dom/messagechannel/tests/test_messageChannel_forceClose.html
@@ -0,0 +1,30 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1176034
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 1176034 - start/close</title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1176034">Mozilla Bug 1176034</a>
+<div id="content"></div>
+<pre id="test">
+</pre>
+ <script type="application/javascript">
+
+ var mc = new MessageChannel();
+
+ try {
+ postMessage(42, "*", [ mc.port1, window ]);
+ ok(false, "Something went wrong.");
+ } catch(e) {
+ ok(true, "PostMessage should fail and we should not leak.");
+ }
+
+ </script>
+</body>
+</html>
diff --git a/dom/messagechannel/tests/test_messageChannel_pingpong.html b/dom/messagechannel/tests/test_messageChannel_pingpong.html
new file mode 100644
index 000000000..f13eb54e6
--- /dev/null
+++ b/dom/messagechannel/tests/test_messageChannel_pingpong.html
@@ -0,0 +1,77 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=677638
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 677638 - port cloning</title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=677638">Mozilla Bug 677638</a>
+<div id="content"></div>
+<pre id="test">
+</pre>
+ <script type="application/javascript">
+
+ function runTest() {
+ var MAX = 100;
+
+ var a = new MessageChannel();
+ ok(a, "MessageChannel created");
+
+ // Populate the message queue of this port.
+ for (var i = 0; i < MAX; ++i) {
+ a.port1.postMessage(i);
+ }
+
+ window.addEventListener('message', receiveMessage, false);
+ function receiveMessage(evt) {
+
+ // This test sends the port from this window to the iframe and viceversa.
+ if (evt.data.type == 'PORT') {
+ var port = evt.data.port;
+ var counter = 0;
+ port.onmessage = function(evt) {
+ // only 1 message should be received by this port.
+ if (counter++ == 0) {
+ ok(evt.data % 2, "The number " + evt.data + " has been received correctly by the main window");
+
+ if (evt.data < MAX - 1) {
+ ifr.contentWindow.postMessage({ type: 'PORT', port: port }, '*', [port]);
+ } else {
+ SimpleTest.finish();
+ }
+ } else {
+ ok(false, "Wrong message!");
+ }
+ }
+ } else if (evt.data.type == 'OK') {
+ ok(true, evt.data.msg);
+ } else if (evt.data.type == 'KO') {
+ ok(false, evt.data.msg);
+ } else {
+ ok(false, "Unknown message");
+ }
+ }
+
+ var div = document.getElementById("content");
+ ok(div, "Parent exists");
+
+ var ifr = document.createElement("iframe");
+ ifr.addEventListener("load", iframeLoaded, false);
+ ifr.setAttribute('src', "iframe_messageChannel_pingpong.html");
+ div.appendChild(ifr);
+
+ function iframeLoaded() {
+ ifr.contentWindow.postMessage({ type: 'PORT', port: a.port2 }, '*', [a.port2]);
+ }
+ }
+
+ SimpleTest.waitForExplicitFinish();
+ runTest();
+ </script>
+</body>
+</html>
diff --git a/dom/messagechannel/tests/test_messageChannel_post.html b/dom/messagechannel/tests/test_messageChannel_post.html
new file mode 100644
index 000000000..ddbf59dc9
--- /dev/null
+++ b/dom/messagechannel/tests/test_messageChannel_post.html
@@ -0,0 +1,76 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=677638
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 677638 - port cloning</title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=677638">Mozilla Bug 677638</a>
+<div id="content"></div>
+<pre id="test">
+</pre>
+ <script type="application/javascript">
+
+ function start() {
+ var a = new MessageChannel();
+ ok(a, "MessageChannel created");
+
+ window.addEventListener('message', receiveMessage, false);
+ function receiveMessage(evt) {
+ if (evt.data.status == 'READY') {
+ runTest();
+ } else {
+ ok(false, "Unknown message");
+ }
+ }
+
+ var div = document.getElementById("content");
+ ok(div, "Parent exists");
+
+ var ifr = document.createElement("iframe");
+ ifr.addEventListener("load", iframeLoaded, false);
+ ifr.setAttribute('src', "iframe_messageChannel_post.html");
+ div.appendChild(ifr);
+
+ function iframeLoaded() {
+ ifr.contentWindow.postMessage({ port: a.port2 }, '*', [a.port2]);
+ }
+
+ var tests = [ 42,
+ null,
+ undefined,
+ "hello world",
+ new Blob([]),
+ true ];
+
+ a.port1.onmessage = function(evt) {
+ ok(tests.length, "We are waiting for a message");
+ if (typeof(tests[0]) == 'object') {
+ is(typeof(tests[0]), typeof(evt.data), "Value ok: " + tests[0]);
+ } else {
+ is(tests[0], evt.data, "Value ok: " + tests[0]);
+ }
+ tests.shift();
+ runTest();
+ }
+
+ function runTest() {
+ if (!tests.length) {
+ SimpleTest.finish();
+ return;
+ }
+
+ a.port1.postMessage(tests[0]);
+ }
+ }
+
+ SimpleTest.waitForExplicitFinish();
+ start();
+ </script>
+</body>
+</html>
diff --git a/dom/messagechannel/tests/test_messageChannel_selfTransferring.html b/dom/messagechannel/tests/test_messageChannel_selfTransferring.html
new file mode 100644
index 000000000..d01ca5fc3
--- /dev/null
+++ b/dom/messagechannel/tests/test_messageChannel_selfTransferring.html
@@ -0,0 +1,33 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=677638
+-->
+<head>
+ <meta charset="utf-8">
+ <title>MessagePort/Channel no self tranferring</title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=677638">Mozilla Bug 677638</a>
+<div id="content"></div>
+<pre id="test">
+</pre>
+ <script type="application/javascript">
+
+ var a = new MessageChannel();
+
+ var status = false;
+ try {
+ a.port1.postMessage('foobar', [a.port1]);
+ } catch(e) {
+ status =true;
+ }
+
+ ok(status, "Transfering the same port should throw");
+
+ </script>
+</body>
+</html>
+
diff --git a/dom/messagechannel/tests/test_messageChannel_sharedWorker.html b/dom/messagechannel/tests/test_messageChannel_sharedWorker.html
new file mode 100644
index 000000000..3b7b9ea69
--- /dev/null
+++ b/dom/messagechannel/tests/test_messageChannel_sharedWorker.html
@@ -0,0 +1,36 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=677638
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 677638 - sharedWorker</title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=677638">Mozilla Bug 677638</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+ <iframe name="x" id="x"></iframe>
+ <iframe name="y" id="y"></iframe>
+</div>
+<pre id="test">
+</pre>
+ <script type="application/javascript">
+
+ var a = new SharedWorker('sharedWorker_messageChannel.js');
+ a.port.onmessage = function(evt) {
+ is(evt.ports.length, 1, "We received a port.");
+ evt.ports[0].onmessage = function(e) {
+ is(e.data, 42, "Message reiceved back!");
+ SimpleTest.finish();
+ }
+ evt.ports[0].postMessage(42);
+ }
+
+ SimpleTest.waitForExplicitFinish();
+ </script>
+</body>
+</html>
diff --git a/dom/messagechannel/tests/test_messageChannel_sharedWorker2.html b/dom/messagechannel/tests/test_messageChannel_sharedWorker2.html
new file mode 100644
index 000000000..57a1e606a
--- /dev/null
+++ b/dom/messagechannel/tests/test_messageChannel_sharedWorker2.html
@@ -0,0 +1,34 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=677638
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 677638 - sharedWorker</title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+ <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=677638">Mozilla Bug 677638</a>
+ <div id="content"></div>
+
+ <script type="application/javascript">
+
+ var iframe = document.createElement('iframe');
+ iframe.setAttribute('src', "iframe_messageChannel_sharedWorker2.html");
+ document.getElementById('content').appendChild(iframe);
+
+ var a = new SharedWorker('sharedWorker2_messageChannel.js');
+ a.port.onmessage = function(evt) {
+ is(evt.ports.length, 1, "We received a port.");
+ evt.ports[0].onmessage = function(e) {
+ is(e.data, "Hello from the iframe!", "Message reiceved from the iframe!");
+ SimpleTest.finish();
+ }
+ }
+
+ SimpleTest.waitForExplicitFinish();
+ </script>
+</body>
+</html>
diff --git a/dom/messagechannel/tests/test_messageChannel_start.html b/dom/messagechannel/tests/test_messageChannel_start.html
new file mode 100644
index 000000000..192230adb
--- /dev/null
+++ b/dom/messagechannel/tests/test_messageChannel_start.html
@@ -0,0 +1,235 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=677638
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 677638 - start/close</title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=677638">Mozilla Bug 677638</a>
+<div id="content"></div>
+<pre id="test">
+</pre>
+ <script type="application/javascript">
+
+ function runTests() {
+ if (!tests.length) {
+ SimpleTest.finish();
+ return;
+ }
+
+ var test = tests.shift();
+ test();
+ }
+
+ function testOnMessage() {
+ var a = new MessageChannel();
+ ok(a, "MessageChannel created");
+
+ a.port1.postMessage(42);
+ a.port2.postMessage(43);
+ ok(true, "MessagePort{1,2}.postmessage() invoked");
+
+ var events = 2;
+
+ a.port1.onmessage = function(evt) {
+ ok(true, "This method should be called");
+ if (!--events) runTests();
+ }
+
+ a.port2.onmessage = function(evt) {
+ ok(true, "This method should be called");
+ if (!--events) runTests();
+ }
+ }
+
+ function testAddEventListener() {
+ var a = new MessageChannel();
+ ok(a, "MessageChannel created");
+
+ a.port1.postMessage(42);
+ a.port2.postMessage(43);
+ ok(true, "MessagePort{1,2}.postmessage() invoked");
+
+ a.port1.addEventListener('message', function(evt) {
+ ok(false, "This method should not be called");
+ }, false);
+
+ a.port2.addEventListener('message', function(evt) {
+ ok(false, "This method should not be called");
+ }, false);
+
+ setTimeout(runTests, 0);
+ }
+
+ function testAddEventListenerAndStart() {
+ var a = new MessageChannel();
+ ok(a, "MessageChannel created");
+
+ a.port1.postMessage(42);
+ a.port2.postMessage(43);
+ ok(true, "MessagePort{1,2}.postmessage() invoked");
+
+ var events = 2;
+
+ a.port1.addEventListener('message', function(evt) {
+ ok(true, "This method should be called");
+ if (!--events) runTests();
+ }, false);
+
+ a.port2.addEventListener('message', function(evt) {
+ ok(true, "This method should be called");
+ if (!--events) runTests();
+ }, false);
+
+ a.port1.start();
+ a.port2.start();
+ }
+
+ function testAddEventListener1AndStart() {
+ var a = new MessageChannel();
+ ok(a, "MessageChannel created");
+
+ a.port1.postMessage(42);
+ a.port2.postMessage(43);
+ ok(true, "MessagePort{1,2}.postmessage() invoked");
+
+ var events = 1;
+
+ a.port1.addEventListener('message', function(evt) {
+ ok(true, "This method should be called");
+ if (!--events) runTests();
+ }, false);
+
+ a.port2.addEventListener('message', function(evt) {
+ ok(false, "This method should not be called");
+ }, false);
+
+ a.port1.start();
+ }
+
+ function testAddEventListener2AndStart() {
+ var a = new MessageChannel();
+ ok(a, "MessageChannel created");
+
+ a.port1.postMessage(42);
+ a.port2.postMessage(43);
+ ok(true, "MessagePort{1,2}.postmessage() invoked");
+
+ var events = 1;
+
+ a.port1.addEventListener('message', function(evt) {
+ ok(false, "This method should not be called");
+ }, false);
+
+ a.port2.addEventListener('message', function(evt) {
+ ok(true, "This method should be called");
+ if (!--events) runTests();
+ }, false);
+
+ a.port2.start();
+ }
+
+ function testTimer() {
+ var a = new MessageChannel();
+ ok(a, "MessageChannel created");
+
+ a.port1.postMessage(42);
+ a.port2.postMessage(43);
+ ok(true, "MessagePort{1,2}.postmessage() invoked");
+
+ setTimeout(function() {
+ var events = 2;
+ a.port1.onmessage = function(evt) {
+ ok(true, "This method should be called");
+ if (!--events) runTests();
+ }
+
+ a.port2.onmessage = function(evt) {
+ ok(true, "This method should be called");
+ if (!--events) runTests();
+ }
+ }, 200);
+ }
+
+ function testAddEventListenerAndStartWrongOrder() {
+ var a = new MessageChannel();
+ ok(a, "MessageChannel created");
+
+ a.port1.postMessage(42);
+ a.port2.postMessage(43);
+ ok(true, "MessagePort{1,2}.postmessage() invoked");
+
+ var events = 2;
+
+ a.port1.start();
+ a.port1.addEventListener('message', function(evt) {
+ ok(true, "This method should be called");
+ if (!--events) runTests();
+ }, false);
+
+ a.port2.start();
+ a.port2.addEventListener('message', function(evt) {
+ ok(true, "This method should be called");
+ if (!--events) runTests();
+ }, false);
+ }
+
+ function testOnMessageClone() {
+ var a = new MessageChannel();
+ ok(a, "MessageChannel created");
+
+ a.port1.postMessage(42);
+ a.port2.postMessage(43);
+ ok(true, "MessagePort{1,2}.postmessage() invoked");
+
+ var events = 2;
+
+ addEventListener('message', testOnMessageCloneCb, false);
+ function testOnMessageCloneCb(evt) {
+ a.port1.onmessage = function(evt) {
+ ok(true, "This method should be called");
+ testOnMessageCloneFinish();
+ }
+
+ evt.data.onmessage = function(evt) {
+ ok(true, "This method should be called");
+ testOnMessageCloneFinish();
+ }
+
+ a.port2.onmessage = function(evt) {
+ ok(false, "This method should not be called");
+ }
+ }
+
+ function testOnMessageCloneFinish() {
+ if (!--events) {
+ removeEventListener('message', testOnMessageCloneCb);
+ runTests();
+ }
+ }
+
+ postMessage(a.port2, '*', [a.port2]);
+ }
+
+ var tests = [
+ testOnMessage,
+ testAddEventListener,
+ testAddEventListenerAndStart,
+ testAddEventListener1AndStart,
+ testAddEventListener2AndStart,
+ testTimer,
+ testAddEventListenerAndStartWrongOrder,
+ testOnMessageClone,
+ ];
+
+ SimpleTest.waitForExplicitFinish();
+ SimpleTest.requestFlakyTimeout("untriaged");
+ runTests();
+ </script>
+</body>
+</html>
diff --git a/dom/messagechannel/tests/test_messageChannel_transferable.html b/dom/messagechannel/tests/test_messageChannel_transferable.html
new file mode 100644
index 000000000..095bf25dc
--- /dev/null
+++ b/dom/messagechannel/tests/test_messageChannel_transferable.html
@@ -0,0 +1,111 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=677638
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 677638 - port cloning</title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=677638">Mozilla Bug 677638</a>
+<div id="content"></div>
+<pre id="test">
+</pre>
+ <script type="application/javascript">
+
+ function basic_test() {
+ var a = new MessageChannel();
+ ok(a, "MessageChannel created");
+
+ window.addEventListener('message', receiveMessage, false);
+ function receiveMessage(evt) {
+ if (evt.data.status == 'READY') {
+ a.port1.postMessage({ab: ab, cb: ab}, [ab]);
+ ok(ab.byteLength == 0, "PostMessage - The size is: 0 == " + ab.byteLength)
+ } else {
+ ok(false, "Unknown message");
+ }
+ }
+
+ var div = document.getElementById("content");
+ ok(div, "Parent exists");
+
+ var ifr = document.createElement("iframe");
+ ifr.addEventListener("load", iframeLoaded, false);
+ ifr.setAttribute('src', "iframe_messageChannel_post.html");
+ div.appendChild(ifr);
+
+ function iframeLoaded() {
+ ifr.contentWindow.postMessage({ port: a.port2 }, '*', [a.port2]);
+ }
+
+ a.port1.addEventListener('message', receivePortMessage, false);
+ function receivePortMessage(evt) {
+ is(evt.data.ab.byteLength, size, "The size is: " + size + " == " + ab.byteLength);
+ window.removeEventListener('message', receiveMessage);
+ runTests();
+ }
+
+ // Start() is not implicity invoked when addEventListener is used.
+ a.port1.start();
+
+ var size = 1024 * 1024 * 32;
+ var ab = new ArrayBuffer(size);
+ is(ab.byteLength, size, "The size is: " + size + " == " + ab.byteLength);
+ }
+
+ function port_test() {
+ window.addEventListener('message', receiveMessage, false);
+ function receiveMessage(evt) {
+ ok(evt.data.type == 'OK', evt.data.msg);
+ }
+
+ var a = new MessageChannel();
+ ok(a, "MessageChannel created");
+
+ var div = document.getElementById("content");
+ ok(div, "Parent exists");
+
+ var ifr = document.createElement("iframe");
+ ifr.addEventListener("load", iframeLoaded, false);
+ ifr.setAttribute('src', "iframe_messageChannel_transferable.html");
+ div.appendChild(ifr);
+
+ function iframeLoaded() {
+ ifr.contentWindow.postMessage('foobar!', '*', [a.port2]);
+ }
+
+ a.port1.onmessage = function(evt) {
+ ok(evt.ports.length == 1, "Iframe sent a new port!");
+ evt.ports[0].onmessage = function(evt) {
+ is(evt.data, "hello world!", "Message sent and received!");
+ runTests();
+ }
+
+ evt.ports[0].postMessage("hello world!");
+ }
+ }
+
+ var tests = [
+ basic_test,
+ port_test
+ ];
+
+ function runTests() {
+ if (!tests.length) {
+ SimpleTest.finish();
+ return;
+ }
+
+ var t = tests.shift();
+ t();
+ }
+
+ SimpleTest.waitForExplicitFinish();
+ runTests();
+ </script>
+</body>
+</html>
diff --git a/dom/messagechannel/tests/test_messageChannel_unshipped.html b/dom/messagechannel/tests/test_messageChannel_unshipped.html
new file mode 100644
index 000000000..6661b7d0a
--- /dev/null
+++ b/dom/messagechannel/tests/test_messageChannel_unshipped.html
@@ -0,0 +1,123 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=677638
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 677638 - unshipped message port queue</title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=677638">Mozilla Bug 677638</a>
+<div id="content"></div>
+<pre id="test">
+</pre>
+ <script type="application/javascript">
+
+ function test_orderedMessages() {
+ var a = new MessageChannel();
+ ok(a, "MessageChannel created");
+
+ var b = new MessageChannel();
+ ok(b, "MessageChannel created");
+
+ var expectedNumber = 1;
+ function testEvent(number, id) {
+ is(expectedNumber, number, "This is the right number!");
+ ok(!((expectedNumber - id) % 4), "From the right port: " + expectedNumber + " " + id);
+ expectedNumber++;
+
+ if (expectedNumber >100) {
+ runTests();
+ }
+ }
+
+ a.port1.onmessage = function(evt) {
+ testEvent(evt.data, 2);
+ };
+
+ a.port2.onmessage = function(evt) {
+ testEvent(evt.data, 1);
+ };
+
+ b.port1.onmessage = function(evt) {
+ testEvent(evt.data, 4);
+ };
+
+ b.port2.onmessage = function(evt) {
+ testEvent(evt.data, 3);
+ };
+
+ for (var i = 0; i < 100;) {
+ a.port1.postMessage(++i);
+ a.port2.postMessage(++i);
+ b.port1.postMessage(++i);
+ b.port2.postMessage(++i);
+ }
+ }
+
+ function test_unstarted() {
+ var a = new MessageChannel();
+ ok(a, "MessageChannel created");
+
+ var b = new MessageChannel();
+ ok(b, "MessageChannel created");
+
+ var expectedNumber = 1;
+ function testEvent(number, id) {
+ is(expectedNumber, number, "This is the right number!");
+ ok(!((expectedNumber - id) % 3), "From the right port: " + expectedNumber + " " + id);
+ expectedNumber++;
+
+ // 102 because it's the first multiple of 3.
+ if (expectedNumber > 102) {
+ runTests();
+ }
+ }
+
+ a.port1.onmessage = function(evt) {
+ testEvent(evt.data, 2);
+ };
+
+ a.port2.onmessage = function(evt) {
+ testEvent(evt.data, 1);
+ };
+
+ b.port1.addEventListener("message", function() {
+ ok(false, "shouldn't be called");
+ });
+
+ b.port2.onmessage = function(evt) {
+ testEvent(evt.data, 3);
+ };
+
+ for (var i = 0; i < 100;) {
+ a.port1.postMessage(++i);
+ a.port2.postMessage(++i);
+ b.port1.postMessage(++i);
+ b.port2.postMessage(1000);
+ }
+ }
+
+ var tests = [
+ test_orderedMessages,
+ test_unstarted
+ ];
+
+ function runTests() {
+ if (!tests.length) {
+ SimpleTest.finish();
+ return;
+ }
+
+ var test = tests.shift();
+ test();
+ }
+
+ SimpleTest.waitForExplicitFinish();
+ runTests();
+ </script>
+</body>
+</html>
diff --git a/dom/messagechannel/tests/test_messageChannel_worker.html b/dom/messagechannel/tests/test_messageChannel_worker.html
new file mode 100644
index 000000000..2c1c02626
--- /dev/null
+++ b/dom/messagechannel/tests/test_messageChannel_worker.html
@@ -0,0 +1,60 @@
+
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=677638
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 677638 - basic support</title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=677638">Mozilla Bug 677638</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+ <iframe name="x" id="x"></iframe>
+ <iframe name="y" id="y"></iframe>
+</div>
+<pre id="test">
+</pre>
+ <script type="application/javascript">
+
+ var tests = [ 0, 3 ];
+
+ function runTests() {
+ if (!tests.length) {
+ SimpleTest.finish();
+ return;
+ }
+
+ var a = new Worker('worker_messageChannel.js');
+ a.onmessage = function(evt) {
+ if (evt.data.type == 'finish') {
+ runTests();
+ } else if (evt.data.type == 'info') {
+ info(evt.data.message);
+ } else if (evt.data.type == 'check') {
+ ok(evt.data.check, evt.data.message);
+ } else if (evt.data.type == 'port') {
+ is(evt.ports.length, 1, "A port has been received!");
+ evt.ports[0].onmessage = function(e) {
+ e.target.postMessage(e.data);
+ }
+ } else if (evt.data.type == 'newport') {
+ var ch = new MessageChannel();
+ ok(ch, "MessageChannel created");
+ ch.port1.postMessage(42);
+ a.postMessage('a gift!', [ch.port2]);
+ }
+ }
+
+ a.postMessage(tests.shift());
+ }
+
+ SimpleTest.waitForExplicitFinish();
+ runTests();
+ </script>
+</body>
+</html>
diff --git a/dom/messagechannel/tests/test_messageChannel_worker_forceClose.html b/dom/messagechannel/tests/test_messageChannel_worker_forceClose.html
new file mode 100644
index 000000000..1610fc265
--- /dev/null
+++ b/dom/messagechannel/tests/test_messageChannel_worker_forceClose.html
@@ -0,0 +1,27 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>Test for forcing the closing of the port in workers</title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<div id="content"></div>
+<pre id="test">
+</pre>
+ <script type="application/javascript">
+
+ var worker = new Worker('data:javascript,onmessage = function(e) { "doing nothing with this port"; }');
+
+ var mc = new MessageChannel();
+ worker.postMessage(42, [mc.port2]);
+
+ for (var i = 0; i < 10; ++i) {
+ mc.port1.postMessage(i);
+ }
+
+ ok(true, "All the messages are sent! We should shutdown correctly.");
+ </script>
+</body>
+</html>
diff --git a/dom/messagechannel/tests/worker_messageChannel.js b/dom/messagechannel/tests/worker_messageChannel.js
new file mode 100644
index 000000000..87b0b8eb0
--- /dev/null
+++ b/dom/messagechannel/tests/worker_messageChannel.js
@@ -0,0 +1,119 @@
+function ok(a, msg) {
+ postMessage({ type: 'check', check: !!a, message: msg });
+}
+
+function is(a, b, msg) {
+ ok (a === b, msg);
+}
+
+function info(msg) {
+ postMessage({ type: 'info', message: msg });
+}
+
+function finish() {
+ postMessage({ type: 'finish' });
+}
+
+function basic()
+{
+ var a = new MessageChannel();
+ ok(a, "MessageChannel created");
+
+ var port1 = a.port1;
+ ok(port1, "MessageChannel.port1 exists");
+ is(port1, a.port1, "MessageChannel.port1 is port1");
+
+ var port2 = a.port2;
+ ok(port2, "MessageChannel.port1 exists");
+ is(port2, a.port2, "MessageChannel.port2 is port2");
+
+ [ 'postMessage', 'start', 'close' ].forEach(function(e) {
+ ok(e in port1, "MessagePort1." + e + " exists");
+ ok(e in port2, "MessagePort2." + e + " exists");
+ });
+
+ runTests();
+}
+
+function sendMessages()
+{
+ var a = new MessageChannel();
+ ok(a, "MessageChannel created");
+
+ a.port1.postMessage("Hello world!");
+ a.port1.onmessage = function(e) {
+ is(e.data, "Hello world!", "The message is back!");
+ runTests();
+ }
+
+ a.port2.onmessage = function(e) {
+ a.port2.postMessage(e.data);
+ }
+}
+
+function transferPort()
+{
+ var a = new MessageChannel();
+ ok(a, "MessageChannel created");
+
+ a.port1.postMessage("Hello world!");
+ a.port1.onmessage = function(e) {
+ is(e.data, "Hello world!", "The message is back!");
+ runTests();
+ }
+
+ postMessage({ type: 'port' }, [a.port2]);
+}
+
+function transferPort2()
+{
+ onmessage = function(evt) {
+ is(evt.ports.length, 1, "A port has been received by the worker");
+ evt.ports[0].onmessage = function(e) {
+ is(e.data, 42, "Data is 42!");
+ runTests();
+ }
+ }
+
+ postMessage({ type: 'newport' });
+}
+
+var tests = [
+ basic,
+ sendMessages,
+ transferPort,
+ transferPort2,
+];
+
+function runTests() {
+ if (!tests.length) {
+ finish();
+ return;
+ }
+
+ var t = tests.shift();
+ t();
+}
+
+var subworker;
+onmessage = function(evt) {
+ if (evt.data == 0) {
+ runTests();
+ return;
+ }
+
+ if (!subworker) {
+ info("Create a subworkers. ID: " + evt.data);
+ subworker = new Worker('worker_messageChannel.js');
+ subworker.onmessage = function(e) {
+ info("Proxy a message to the parent.");
+ postMessage(e.data, e.ports);
+ }
+
+ subworker.postMessage(evt.data - 1);
+ return;
+ }
+
+ info("Dispatch a message to the subworker.");
+ subworker.postMessage(evt.data, evt.ports);
+}
diff --git a/dom/messagechannel/tests/worker_messageChannel_any.js b/dom/messagechannel/tests/worker_messageChannel_any.js
new file mode 100644
index 000000000..bbb1d50f9
--- /dev/null
+++ b/dom/messagechannel/tests/worker_messageChannel_any.js
@@ -0,0 +1,7 @@
+onmessage = function(evt) {
+ evt.data.onmessage = function(event) {
+ evt.data.postMessage(event.data);
+ }
+}
+
+postMessage("READY");