summaryrefslogtreecommitdiff
path: root/dom/broadcastchannel/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/broadcastchannel/tests
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloaduxp-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/broadcastchannel/tests')
-rw-r--r--dom/broadcastchannel/tests/blank.html2
-rw-r--r--dom/broadcastchannel/tests/broadcastchannel_sharedWorker.js12
-rw-r--r--dom/broadcastchannel/tests/broadcastchannel_worker.js18
-rw-r--r--dom/broadcastchannel/tests/broadcastchannel_worker_alive.js8
-rw-r--r--dom/broadcastchannel/tests/broadcastchannel_worker_any.js5
-rw-r--r--dom/broadcastchannel/tests/browser.ini6
-rw-r--r--dom/broadcastchannel/tests/browser_private_browsing.js74
-rw-r--r--dom/broadcastchannel/tests/file_mozbrowser.html20
-rw-r--r--dom/broadcastchannel/tests/file_mozbrowser2.html21
-rw-r--r--dom/broadcastchannel/tests/iframe_broadcastchannel.html35
-rw-r--r--dom/broadcastchannel/tests/iframe_mozbrowser.html15
-rw-r--r--dom/broadcastchannel/tests/iframe_mozbrowser2.html15
-rw-r--r--dom/broadcastchannel/tests/mochitest.ini24
-rw-r--r--dom/broadcastchannel/tests/test_bfcache.html96
-rw-r--r--dom/broadcastchannel/tests/test_broadcastchannel_any.html138
-rw-r--r--dom/broadcastchannel/tests/test_broadcastchannel_basic.html68
-rw-r--r--dom/broadcastchannel/tests/test_broadcastchannel_close.html61
-rw-r--r--dom/broadcastchannel/tests/test_broadcastchannel_close2.html39
-rw-r--r--dom/broadcastchannel/tests/test_broadcastchannel_self.html38
-rw-r--r--dom/broadcastchannel/tests/test_broadcastchannel_sharedWorker.html52
-rw-r--r--dom/broadcastchannel/tests/test_broadcastchannel_worker.html62
-rw-r--r--dom/broadcastchannel/tests/test_broadcastchannel_worker_alive.html56
-rw-r--r--dom/broadcastchannel/tests/test_dataCloning.html27
-rw-r--r--dom/broadcastchannel/tests/test_invalidState.html28
-rw-r--r--dom/broadcastchannel/tests/test_ordering.html65
25 files changed, 985 insertions, 0 deletions
diff --git a/dom/broadcastchannel/tests/blank.html b/dom/broadcastchannel/tests/blank.html
new file mode 100644
index 0000000000..358db717dd
--- /dev/null
+++ b/dom/broadcastchannel/tests/blank.html
@@ -0,0 +1,2 @@
+<!DOCTYPE HTML>
+<html><body></body></html>
diff --git a/dom/broadcastchannel/tests/broadcastchannel_sharedWorker.js b/dom/broadcastchannel/tests/broadcastchannel_sharedWorker.js
new file mode 100644
index 0000000000..4dad5ae825
--- /dev/null
+++ b/dom/broadcastchannel/tests/broadcastchannel_sharedWorker.js
@@ -0,0 +1,12 @@
+onconnect = function(evt) {
+ evt.ports[0].onmessage = function(evt) {
+ var bc = new BroadcastChannel('foobar');
+ bc.addEventListener('message', function(event) {
+ bc.postMessage(event.data == "hello world from the window" ?
+ "hello world from the worker" : "KO");
+ bc.close();
+ }, false);
+
+ evt.target.postMessage("READY");
+ }
+}
diff --git a/dom/broadcastchannel/tests/broadcastchannel_worker.js b/dom/broadcastchannel/tests/broadcastchannel_worker.js
new file mode 100644
index 0000000000..4714d59d02
--- /dev/null
+++ b/dom/broadcastchannel/tests/broadcastchannel_worker.js
@@ -0,0 +1,18 @@
+onmessage = function(evt) {
+ if (evt.data != 0) {
+ var worker = new Worker("broadcastchannel_worker.js");
+ worker.onmessage = function(evt) {
+ postMessage(evt.data);
+ }
+ worker.postMessage(evt.data - 1);
+ return;
+ }
+
+ var bc = new BroadcastChannel('foobar');
+ bc.addEventListener('message', function(event) {
+ bc.postMessage(event.data == "hello world from the window" ? "hello world from the worker" : "KO");
+ bc.close();
+ }, false);
+
+ postMessage("READY");
+}
diff --git a/dom/broadcastchannel/tests/broadcastchannel_worker_alive.js b/dom/broadcastchannel/tests/broadcastchannel_worker_alive.js
new file mode 100644
index 0000000000..78ab44015c
--- /dev/null
+++ b/dom/broadcastchannel/tests/broadcastchannel_worker_alive.js
@@ -0,0 +1,8 @@
+(new BroadcastChannel('foobar')).postMessage('READY');
+
+(new BroadcastChannel('foobar')).addEventListener('message', function(event) {
+ if (event.data != 'READY') {
+ event.target.postMessage(event.data);
+ }
+}, false);
+
diff --git a/dom/broadcastchannel/tests/broadcastchannel_worker_any.js b/dom/broadcastchannel/tests/broadcastchannel_worker_any.js
new file mode 100644
index 0000000000..da8625c4d8
--- /dev/null
+++ b/dom/broadcastchannel/tests/broadcastchannel_worker_any.js
@@ -0,0 +1,5 @@
+(new BroadcastChannel('foobar')).onmessage = function(event) {
+ event.target.postMessage(event.data);
+}
+
+postMessage("READY");
diff --git a/dom/broadcastchannel/tests/browser.ini b/dom/broadcastchannel/tests/browser.ini
new file mode 100644
index 0000000000..b036a1e9bf
--- /dev/null
+++ b/dom/broadcastchannel/tests/browser.ini
@@ -0,0 +1,6 @@
+[DEFAULT]
+skip-if = os == 'android'
+support-files =
+ blank.html
+
+[browser_private_browsing.js]
diff --git a/dom/broadcastchannel/tests/browser_private_browsing.js b/dom/broadcastchannel/tests/browser_private_browsing.js
new file mode 100644
index 0000000000..5724225fc3
--- /dev/null
+++ b/dom/broadcastchannel/tests/browser_private_browsing.js
@@ -0,0 +1,74 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+const URL = "http://mochi.test:8888/browser/dom/broadcastchannel/tests/blank.html";
+
+add_task(function*() {
+ var win1 = OpenBrowserWindow({private: true});
+ var win1Promise = new win1.Promise(resolve => {
+ win1.addEventListener("load", function onLoad() {
+ win1.removeEventListener("load", onLoad, false);
+ resolve();
+ });
+ });
+ yield win1Promise;
+
+ var win2 = OpenBrowserWindow({private: false});
+ var win2Promise = new win2.Promise(resolve => {
+ win2.addEventListener("load", function onLoad() {
+ win2.removeEventListener("load", onLoad, false);
+ resolve();
+ });
+ });
+ yield win2Promise;
+
+ var tab1 = win1.gBrowser.addTab(URL);
+ yield BrowserTestUtils.browserLoaded(win1.gBrowser.getBrowserForTab(tab1));
+ var browser1 = gBrowser.getBrowserForTab(tab1);
+
+ var tab2 = win2.gBrowser.addTab(URL);
+ yield BrowserTestUtils.browserLoaded(win2.gBrowser.getBrowserForTab(tab2));
+ var browser2 = gBrowser.getBrowserForTab(tab2);
+
+ var p1 = ContentTask.spawn(browser1, null, function(opts) {
+ return new content.window.Promise(resolve => {
+ content.window.bc = new content.window.BroadcastChannel('foobar');
+ content.window.bc.onmessage = function(e) { resolve(e.data); }
+ });
+ });
+
+ var p2 = ContentTask.spawn(browser2, null, function(opts) {
+ return new content.window.Promise(resolve => {
+ content.window.bc = new content.window.BroadcastChannel('foobar');
+ content.window.bc.onmessage = function(e) { resolve(e.data); }
+ });
+ });
+
+ yield ContentTask.spawn(browser1, null, function(opts) {
+ return new content.window.Promise(resolve => {
+ var bc = new content.window.BroadcastChannel('foobar');
+ bc.postMessage('hello world from private browsing');
+ resolve();
+ });
+ });
+
+ yield ContentTask.spawn(browser2, null, function(opts) {
+ return new content.window.Promise(resolve => {
+ var bc = new content.window.BroadcastChannel('foobar');
+ bc.postMessage('hello world from non private browsing');
+ resolve();
+ });
+ });
+
+ var what1 = yield p1;
+ ok(what1, 'hello world from private browsing', 'No messages received from the other window.');
+
+ var what2 = yield p2;
+ ok(what1, 'hello world from non private browsing', 'No messages received from the other window.');
+
+ yield BrowserTestUtils.removeTab(tab1);
+ yield BrowserTestUtils.closeWindow(win1);
+
+ yield BrowserTestUtils.removeTab(tab2);
+ yield BrowserTestUtils.closeWindow(win2);
+});
diff --git a/dom/broadcastchannel/tests/file_mozbrowser.html b/dom/broadcastchannel/tests/file_mozbrowser.html
new file mode 100644
index 0000000000..5f69021320
--- /dev/null
+++ b/dom/broadcastchannel/tests/file_mozbrowser.html
@@ -0,0 +1,20 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>MozBrowser iframe</title>
+</head>
+<body>
+<div id="container"></div>
+ <script type="application/javascript;version=1.7">
+
+ var ifr = document.createElement('iframe');
+ ifr.src = 'http://mochi.test:8888/tests/dom/broadcastchannel/tests/iframe_mozbrowser.html';
+ ifr.onload = function() { alert('DONE'); }
+
+ var domParent = document.getElementById('container');
+ domParent.appendChild(ifr);
+
+ </script>
+</body>
+</html>
diff --git a/dom/broadcastchannel/tests/file_mozbrowser2.html b/dom/broadcastchannel/tests/file_mozbrowser2.html
new file mode 100644
index 0000000000..85abce7bff
--- /dev/null
+++ b/dom/broadcastchannel/tests/file_mozbrowser2.html
@@ -0,0 +1,21 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>MozBrowser iframe</title>
+</head>
+<body>
+<div id="container"></div>
+ <script type="application/javascript;version=1.7">
+
+ var ifr = document.createElement('iframe');
+ ifr.setAttribute('mozbrowser', true);
+ ifr.src = 'http://mochi.test:8888/tests/dom/broadcastchannel/tests/iframe_mozbrowser2.html';
+ ifr.onload = function() { alert('DONE'); }
+
+ var domParent = document.getElementById('container');
+ domParent.appendChild(ifr);
+
+ </script>
+</body>
+</html>
diff --git a/dom/broadcastchannel/tests/iframe_broadcastchannel.html b/dom/broadcastchannel/tests/iframe_broadcastchannel.html
new file mode 100644
index 0000000000..fb9a12b4bd
--- /dev/null
+++ b/dom/broadcastchannel/tests/iframe_broadcastchannel.html
@@ -0,0 +1,35 @@
+<!DOCTYPE HTML>
+<html>
+<body>
+ <script type="application/javascript">
+
+function is(a, b, msg) {
+ ok(a == b, msg);
+}
+
+function ok(a, msg) {
+ window.parent.postMessage({ status: a ? "OK" : "KO", message: msg }, "*");
+}
+
+ok("BroadcastChannel" in window, "BroadcastChannel exists");
+
+var bc = new BroadcastChannel("foobar");
+ok(bc, "BroadcastChannel can be created");
+is(bc.name, 'foobar', "BroadcastChannel.name is foobar");
+
+ok("postMessage" in bc, "BroadcastChannel has postMessage() method");
+
+bc.onmessage = function(evt) {
+ ok(evt instanceof MessageEvent, 'evt is a MessageEvent');
+ is(evt.target, bc, 'MessageEvent.target is bc');
+ is(evt.target.name, 'foobar', 'MessageEvent.target.name is foobar');
+ is(evt.target.name, bc.name, 'MessageEvent.target.name is bc.name');
+ is(evt.data, "Hello world from the window!", "Message received from the window");
+ bc.postMessage("Hello world from the iframe!");
+}
+
+ </script>
+</body>
+</html>
+
+
diff --git a/dom/broadcastchannel/tests/iframe_mozbrowser.html b/dom/broadcastchannel/tests/iframe_mozbrowser.html
new file mode 100644
index 0000000000..dbcf63d883
--- /dev/null
+++ b/dom/broadcastchannel/tests/iframe_mozbrowser.html
@@ -0,0 +1,15 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>MozBrowser iframe</title>
+</head>
+<body>
+ <script type="application/javascript;version=1.7">
+
+var bc = new BroadcastChannel('foobar');
+bc.postMessage('This is wrong!');
+
+ </script>
+</body>
+</html>
diff --git a/dom/broadcastchannel/tests/iframe_mozbrowser2.html b/dom/broadcastchannel/tests/iframe_mozbrowser2.html
new file mode 100644
index 0000000000..dbcf63d883
--- /dev/null
+++ b/dom/broadcastchannel/tests/iframe_mozbrowser2.html
@@ -0,0 +1,15 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>MozBrowser iframe</title>
+</head>
+<body>
+ <script type="application/javascript;version=1.7">
+
+var bc = new BroadcastChannel('foobar');
+bc.postMessage('This is wrong!');
+
+ </script>
+</body>
+</html>
diff --git a/dom/broadcastchannel/tests/mochitest.ini b/dom/broadcastchannel/tests/mochitest.ini
new file mode 100644
index 0000000000..6dff47db48
--- /dev/null
+++ b/dom/broadcastchannel/tests/mochitest.ini
@@ -0,0 +1,24 @@
+[DEFAULT]
+support-files =
+ iframe_broadcastchannel.html
+ broadcastchannel_sharedWorker.js
+ broadcastchannel_worker.js
+ broadcastchannel_worker_alive.js
+ broadcastchannel_worker_any.js
+ file_mozbrowser.html
+ file_mozbrowser2.html
+ iframe_mozbrowser.html
+ iframe_mozbrowser2.html
+
+[test_broadcastchannel_any.html]
+[test_broadcastchannel_basic.html]
+[test_broadcastchannel_close.html]
+[test_broadcastchannel_close2.html]
+[test_broadcastchannel_self.html]
+[test_broadcastchannel_sharedWorker.html]
+[test_broadcastchannel_worker.html]
+[test_broadcastchannel_worker_alive.html]
+[test_bfcache.html]
+[test_invalidState.html]
+[test_ordering.html]
+[test_dataCloning.html]
diff --git a/dom/broadcastchannel/tests/test_bfcache.html b/dom/broadcastchannel/tests/test_bfcache.html
new file mode 100644
index 0000000000..e42496bac8
--- /dev/null
+++ b/dom/broadcastchannel/tests/test_bfcache.html
@@ -0,0 +1,96 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>Test for bfcache and BroadcastChannel</title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+ <script type="application/javascript">
+
+ /* This test is hard to follow so here a quick description of what it is about.
+ * We want to test that when BroadcastChannel is used in a bfcached page,
+ * this page is fully removed by bfcache.
+ *
+ * To test it we have 2 pages (testUrl1 and testUrl2).
+ * The steps are:
+ * - we show testUrl1. When this is shown page1Shown is called.
+ * - page1Shown creates a BroadcastChannel object, then it loads testUrl2.
+ * - page2Shown is called by testUrl2.
+ * - Based on expectedPersisted we use or not the BroadcastChannel object of
+ * testUrl1.
+ * - Then we call history.back() and testUrl1 will be loaded again.
+ * - when page1Shown is called by testUrl1, if BroadcastChannel has been used
+ * when testUrl2 was shown, we want event.persisted be false, otherwise
+ * true.
+ */
+ var testUrl1 = "data:text/html,<script>onpageshow = function(e) { opener.page1Shown(e); };<" + "/script>";
+ var testUrl2 = "data:text/html,<script>onpageshow = function(e) { opener.page2Shown(e); };<" + "/script>";
+
+ var testWin;
+ var counter = 0;
+ var expectedPersisted = false;
+ var bc;
+
+ function page1Shown(e) {
+ info("Page1Shown: " + testWin.location.href);
+
+ if (counter == 0) {
+ ok(!e.persisted, "test page should have been persisted initially");
+
+ bc = new testWin.BroadcastChannel('a');
+
+ SimpleTest.executeSoon(function() {
+ info("New location: " + testUrl2);
+ testWin.location.href = testUrl2;
+ });
+ } else {
+ is(e.persisted, expectedPersisted, "test page should have been persisted in pageshow");
+ testWin.close();
+ runTest();
+ }
+
+ counter++;
+ }
+
+ function page2Shown(e) {
+ info("Page2Shown: " + testWin.location.href);
+
+ if (!expectedPersisted) {
+ SimpleTest.executeSoon(function() {
+ info("Posting a message.");
+ bc.postMessage(42);
+ });
+ }
+
+ SimpleTest.executeSoon(function() {
+ info("Going back");
+ testWin.history.back();
+ });
+ }
+
+ var tests = [
+ { expectedPersisted: true },
+ { expectedPersisted: false },
+ ];
+
+ function runTest() {
+ if (!tests.length) {
+ SimpleTest.finish();
+ return;
+ }
+
+ var test = tests.shift();
+
+ counter = 0;
+ expectedPersisted = test.expectedPersisted;
+ testWin = window.open(testUrl1);
+ }
+
+ SimpleTest.waitForExplicitFinish();
+ runTest();
+
+ </script>
+</body>
+</html>
diff --git a/dom/broadcastchannel/tests/test_broadcastchannel_any.html b/dom/broadcastchannel/tests/test_broadcastchannel_any.html
new file mode 100644
index 0000000000..2225e7cad9
--- /dev/null
+++ b/dom/broadcastchannel/tests/test_broadcastchannel_any.html
@@ -0,0 +1,138 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for BroadcastChannel</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>
+
+<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 count = 2;
+
+ var bc = new BroadcastChannel("foobar");
+ ok(bc, "BroadcastChannel can be created");
+
+ bc.onmessage = function(event) {
+ ok(count < 2, "Still comparing...");
+ info("bc: " + currentTest);
+ compare(event.data, currentTest);
+ ++count;
+ next();
+ }
+
+ var bc2 = new BroadcastChannel("foobar");
+ ok(bc2, "BroadcastChannel can be created");
+
+ var toSkip = true;
+ bc2.onmessage = function(event) {
+ toSkip = !toSkip;
+ if (toSkip) return;
+
+ ok(count < 2, "Still comparing...");
+ info("bc2: " + currentTest);
+ compare(event.data, currentTest);
+ ++count;
+ next();
+ }
+
+ function next() {
+ if (count < 2) {
+ return;
+ }
+
+ is(count, 2, "Just 2 comparations");
+ count = 0;
+
+ if (!tests.length) {
+ SimpleTest.finish();
+ return;
+ }
+
+ currentTest = tests.shift();
+ bc.postMessage(currentTest);
+ info("Posted: " + currentTest);
+ }
+
+ var worker = new Worker("broadcastchannel_worker_any.js");
+ worker.onmessage = function(event) {
+ if (event.data == "READY") {
+ next();
+ }
+ };
+}
+
+SimpleTest.waitForExplicitFinish();
+runTest();
+
+</script>
+</body>
+</html>
+
diff --git a/dom/broadcastchannel/tests/test_broadcastchannel_basic.html b/dom/broadcastchannel/tests/test_broadcastchannel_basic.html
new file mode 100644
index 0000000000..45fa3c4a9d
--- /dev/null
+++ b/dom/broadcastchannel/tests/test_broadcastchannel_basic.html
@@ -0,0 +1,68 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for BroadcastChannel</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>
+
+<script type="application/javascript">
+
+function runTest() {
+ 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 {
+ ok(false, "Unknown message");
+ }
+ }
+
+ ok("BroadcastChannel" in window, "BroadcastChannel exists");
+
+ var bc = new BroadcastChannel("foobar");
+ ok(bc, "BroadcastChannel can be created");
+ is(bc.name, 'foobar', "BroadcastChannel.name is foobar");
+
+ ok("postMessage" in bc, "BroadcastChannel has postMessage() method");
+
+ bc.onmessage = function(evt) {
+ ok(evt instanceof MessageEvent, "This is a MessageEvent");
+ is(evt.target, bc, "MessageEvent.target is bc");
+ is(evt.target.name, 'foobar', "MessageEvent.target.name is foobar");
+ is(evt.target.name, bc.name, "MessageEvent.target.name == bc.name");
+ ok(evt.origin.indexOf('http://mochi.test:8888') == 0, "MessageEvent.origin is correct");
+ is(evt.data, "Hello world from the iframe!", "The message from the iframe has been received!");
+ SimpleTest.finish();
+ }
+
+ var div = document.getElementById("content");
+ ok(div, "Parent exists");
+
+ var ifr = document.createElement("iframe");
+ ifr.addEventListener("load", iframeLoaded, false);
+ ifr.setAttribute('src', "iframe_broadcastchannel.html");
+ div.appendChild(ifr);
+
+ function iframeLoaded() {
+ bc.postMessage("Hello world from the window!");
+ }
+
+ // A leak test
+ var dummyBc = new BroadcastChannel("dont_leak_this");
+ dummyBc.foo = "bar";
+ // don't add message listener!
+}
+
+SimpleTest.waitForExplicitFinish();
+runTest();
+
+</script>
+</body>
+</html>
+
diff --git a/dom/broadcastchannel/tests/test_broadcastchannel_close.html b/dom/broadcastchannel/tests/test_broadcastchannel_close.html
new file mode 100644
index 0000000000..84d41db4f9
--- /dev/null
+++ b/dom/broadcastchannel/tests/test_broadcastchannel_close.html
@@ -0,0 +1,61 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for BroadcastChannel</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>
+
+<script type="application/javascript">
+
+function runTest() {
+ var receiver = new BroadcastChannel('foo');
+ var sequence = [ '2', 'done' ];
+ receiver.onmessage = function(e) {
+ if (!sequence.length) {
+ ok (false, 'No more data is expected');
+ return;
+ }
+
+ var data = sequence.shift();
+ is(e.data, data);
+
+ if (!sequence.length) {
+ SimpleTest.executeSoon(function() {
+ SimpleTest.finish();
+ });
+ }
+ }
+
+ var x = new BroadcastChannel('foo');
+ x.close();
+ try {
+ x.postMessage('1');
+ ok(false, "PostMessage should throw if called after a close().");
+ } catch(e) {
+ ok(true, "PostMessage should throw if called after a close().");
+ }
+
+ var y = new BroadcastChannel('foo');
+ y.postMessage('2');
+ y.close();
+ try {
+ y.postMessage('3');
+ ok(false, "PostMessage should throw if called after a close().");
+ } catch(e) {
+ ok(true, "PostMessage should throw if called after a close().");
+ }
+
+ var z = new BroadcastChannel('foo');
+ z.postMessage('done');
+}
+
+SimpleTest.waitForExplicitFinish();
+runTest();
+
+</script>
+</body>
+</html>
diff --git a/dom/broadcastchannel/tests/test_broadcastchannel_close2.html b/dom/broadcastchannel/tests/test_broadcastchannel_close2.html
new file mode 100644
index 0000000000..a8a748c462
--- /dev/null
+++ b/dom/broadcastchannel/tests/test_broadcastchannel_close2.html
@@ -0,0 +1,39 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for BroadcastChannel</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>
+
+<script type="application/javascript">
+
+function runTest() {
+ var c1 = new BroadcastChannel('foo');
+ var c2 = new BroadcastChannel('foo');
+
+ var status = [];
+ c2.onmessage = function(e) {
+ status.push(e.data);
+ if (status.length == 2) {
+ is (status[0], 'first', "First message has been received");
+ is (status[1], 'second', "Second message has been received");
+ SimpleTest.finish();
+ }
+
+ c2.close();
+ }
+
+ c1.postMessage('first');
+ c1.postMessage('second');
+}
+
+SimpleTest.waitForExplicitFinish();
+runTest();
+
+</script>
+</body>
+</html>
diff --git a/dom/broadcastchannel/tests/test_broadcastchannel_self.html b/dom/broadcastchannel/tests/test_broadcastchannel_self.html
new file mode 100644
index 0000000000..32df390be1
--- /dev/null
+++ b/dom/broadcastchannel/tests/test_broadcastchannel_self.html
@@ -0,0 +1,38 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for BroadcastChannel</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>
+
+<script type="application/javascript">
+
+function runTest() {
+ x = new BroadcastChannel('foo');
+ y = new BroadcastChannel('foo');
+
+ function func(e) {
+ is(e.target, y, "The target is !x");
+
+ SimpleTest.executeSoon(function() {
+ SimpleTest.finish();
+ });
+ }
+
+ x.onmessage = func;
+ y.onmessage = func;
+
+ x.postMessage('foo');
+}
+
+SimpleTest.waitForExplicitFinish();
+runTest();
+
+</script>
+</body>
+</html>
+
diff --git a/dom/broadcastchannel/tests/test_broadcastchannel_sharedWorker.html b/dom/broadcastchannel/tests/test_broadcastchannel_sharedWorker.html
new file mode 100644
index 0000000000..16f847acae
--- /dev/null
+++ b/dom/broadcastchannel/tests/test_broadcastchannel_sharedWorker.html
@@ -0,0 +1,52 @@
+<!--
+ Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<!DOCTYPE HTML>
+<html>
+<!--
+Tests of DOM BroadcastChannel in SharedWorkers
+-->
+<head>
+ <title>Test for BroadcastChannel in SharedWorkers</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" language="javascript">
+
+function runTests() {
+ var worker = new SharedWorker("broadcastchannel_sharedWorker.js");
+
+ var bc = new BroadcastChannel('foobar');
+
+ worker.port.onmessage = function(event) {
+ if (event.data == "READY") {
+ ok(true, "SharedWorker is ready!");
+ bc.postMessage('hello world from the window');
+ } else {
+ ok(false, "Something wrong happened");
+ }
+ };
+
+ bc.onmessage = function(event) {
+ is("hello world from the worker", event.data, "The message matches!");
+ bc.close();
+ SimpleTest.finish();
+ }
+
+ worker.port.postMessage('go');
+}
+
+SimpleTest.waitForExplicitFinish();
+runTests();
+
+</script>
+</pre>
+</body>
+</html>
diff --git a/dom/broadcastchannel/tests/test_broadcastchannel_worker.html b/dom/broadcastchannel/tests/test_broadcastchannel_worker.html
new file mode 100644
index 0000000000..42e93cc1e1
--- /dev/null
+++ b/dom/broadcastchannel/tests/test_broadcastchannel_worker.html
@@ -0,0 +1,62 @@
+<!--
+ Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<!DOCTYPE HTML>
+<html>
+<!--
+Tests of DOM BroadcastChannel in workers
+-->
+<head>
+ <title>Test for BroadcastChannel in workers</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" language="javascript">
+
+function testWorker(x) {
+ var worker = new Worker("broadcastchannel_worker.js");
+
+ var bc = new BroadcastChannel('foobar');
+
+ worker.onmessage = function(event) {
+ if (event.data == "READY") {
+ ok(true, "Worker is ready!");
+ bc.postMessage('hello world from the window');
+ } else {
+ ok(false, "Something wrong happened");
+ }
+ };
+
+ bc.onmessage = function(event) {
+ is("hello world from the worker", event.data, "The message matches!");
+ bc.close();
+ runTests();
+ }
+
+ worker.postMessage(x);
+}
+
+var tests = [ 0, 3 ];
+function runTests() {
+ if (tests.length == 0) {
+ SimpleTest.finish();
+ return;
+ }
+
+ testWorker(tests.shift());
+}
+
+SimpleTest.waitForExplicitFinish();
+runTests();
+
+</script>
+</pre>
+</body>
+</html>
diff --git a/dom/broadcastchannel/tests/test_broadcastchannel_worker_alive.html b/dom/broadcastchannel/tests/test_broadcastchannel_worker_alive.html
new file mode 100644
index 0000000000..8b1b03c4e7
--- /dev/null
+++ b/dom/broadcastchannel/tests/test_broadcastchannel_worker_alive.html
@@ -0,0 +1,56 @@
+<!--
+ Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<!DOCTYPE HTML>
+<html>
+<!--
+Tests of DOM BroadcastChannel in workers
+-->
+<head>
+ <title>Test for BroadcastChannel in workers</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" language="javascript">
+
+function runTests() {
+ var id = 0;
+ (new BroadcastChannel('foobar')).onmessage = function(event) {
+ info("MSG: " + event.data);
+
+ if (event.data == "READY") {
+ ok(true, "Worker is ready!");
+ } else {
+ is(id, event.data, "The message is correct: " + id);
+ }
+
+ for (var i = 0; i < 3; ++i) {
+ SpecialPowers.forceCC();
+ SpecialPowers.forceGC();
+ }
+
+ if (id == 5) {
+ SimpleTest.finish();
+ return;
+ }
+
+ event.target.postMessage(++id);
+ };
+
+ new Worker("broadcastchannel_worker_alive.js");
+}
+
+SimpleTest.waitForExplicitFinish();
+runTests();
+
+</script>
+</pre>
+</body>
+</html>
diff --git a/dom/broadcastchannel/tests/test_dataCloning.html b/dom/broadcastchannel/tests/test_dataCloning.html
new file mode 100644
index 0000000000..6aa164e944
--- /dev/null
+++ b/dom/broadcastchannel/tests/test_dataCloning.html
@@ -0,0 +1,27 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for BroadcastChannel.postMessage invalid State</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>
+
+<script type="application/javascript">
+
+
+let c = new BroadcastChannel("foo");
+
+try {
+ c.postMessage(Symbol());
+ ok(false, "This should throw!");
+} catch(e) {
+ ok(true, "This should throw!");
+ is(e.name, "DataCloneError", "Correct DataCloneError exception thrown");
+}
+
+</script>
+</body>
+</html>
diff --git a/dom/broadcastchannel/tests/test_invalidState.html b/dom/broadcastchannel/tests/test_invalidState.html
new file mode 100644
index 0000000000..8e4a1df354
--- /dev/null
+++ b/dom/broadcastchannel/tests/test_invalidState.html
@@ -0,0 +1,28 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for BroadcastChannel.postMessage invalid State</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>
+
+<script type="application/javascript">
+
+var c = new BroadcastChannel("foo");
+c.close();
+
+try {
+ c.postMessage("bar");
+ ok(false, "This should throw!");
+} catch(e) {
+ ok(true, "This should throw!");
+ is(e.name, "InvalidStateError", "Correct invalid-state exception thrown");
+}
+
+</script>
+</body>
+</html>
+
diff --git a/dom/broadcastchannel/tests/test_ordering.html b/dom/broadcastchannel/tests/test_ordering.html
new file mode 100644
index 0000000000..eab1f955e5
--- /dev/null
+++ b/dom/broadcastchannel/tests/test_ordering.html
@@ -0,0 +1,65 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for BroadcastChannel.postMessage invalid State</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>
+
+<script type="application/javascript">
+
+let c1 = new BroadcastChannel('order');
+let c2 = new BroadcastChannel('order');
+let c3 = new BroadcastChannel('order');
+
+let events = [];
+let doneCount = 0;
+
+function whichBC(bc) {
+ if (bc == c1) return "c1";
+ if (bc == c2) return "c2";
+ if (bc == c3) return "c3";
+ return "What?!?";
+}
+
+function handler(e) {
+ events.push(e);
+ if (e.data == 'done') {
+ doneCount++;
+ if (doneCount == 2) {
+ is(events.length, 6, "Correct length");
+ is(whichBC(events[0].target), "c2", 'target for event 0');
+ is(events[0].data, 'from c1');
+ is(whichBC(events[1].target), "c3", 'target for event 1');
+ is(events[1].data, 'from c1');
+ is(whichBC(events[2].target), "c1", 'target for event 2');
+ is(events[2].data, 'from c3');
+ is(whichBC(events[3].target), "c2", 'target for event 3');
+ is(events[3].data, 'from c3');
+ is(whichBC(events[4].target), "c1", 'target for event 4');
+ is(events[4].data, 'done');
+ is(whichBC(events[5].target), "c3", 'target for event 5');
+ is(events[5].data, 'done');
+
+ SimpleTest.finish();
+ }
+ }
+}
+
+c1.onmessage = handler;
+c2.onmessage = handler;
+c3.onmessage = handler;
+
+c1.postMessage('from c1');
+c3.postMessage('from c3');
+c2.postMessage('done');
+
+SimpleTest.waitForExplicitFinish();
+
+</script>
+</body>
+</html>
+