Bug 966439 - BroadcastChannel API - patch 4 - tests for Workers and SharedWorkers, r=smaug

--HG--
rename : dom/broadcastchannel/tests/broadcastchannel_worker.js => dom/broadcastchannel/tests/broadcastchannel_worker_alive.js
This commit is contained in:
Andrea Marchesini 2015-01-14 11:50:35 +00:00
parent 4af9097f62
commit 039c838ed8
7 changed files with 162 additions and 8 deletions

View File

@ -0,0 +1,12 @@
onconnect = function(evt) {
evt.ports[0].onmessage = function(evt) {
var bc = new BroadcastChannel('foobar');
bc.addEventListener('message', function(event) {
evt.target.postMessage(event.data == "hello world from the window" ? "OK" : "KO");
bc.postMessage("hello world from the worker");
bc.close();
}, false);
evt.target.postMessage("READY");
}
}

View File

@ -1,8 +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) {
postMessage(event.data == "hello world from the window" ? "OK" : "KO");
bc.postMessage("hello world from the worker");
bc.close();
}, false);
postMessage("READY");

View File

@ -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);

View File

@ -1,11 +1,15 @@
[DEFAULT]
support-files =
iframe_broadcastchannel.html
broadcastchannel_worker.js
broadcastchannel_pref_worker.js
broadcastchannel_sharedWorker.js
broadcastchannel_worker.js
broadcastchannel_worker_alive.js
[test_broadcastchannel_basic.html]
[test_broadcastchannel_self.html]
[test_broadcastchannel_worker.html]
[test_broadcastchannel_close.html]
[test_broadcastchannel_self.html]
[test_broadcastchannel_pref.html]
[test_broadcastchannel_sharedWorker.html]
[test_broadcastchannel_worker.html]
[test_broadcastchannel_worker_alive.html]

View File

@ -0,0 +1,55 @@
<!--
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 if(event.data == "OK") {
ok(true, "SharedWorker has received the message");
} 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();
SpecialPowers.pushPrefEnv({"set": [["dom.broadcastChannel.enabled", true],
["dom.workers.sharedWorkers.enabled", true]]}, runTests);
</script>
</pre>
</body>
</html>

View File

@ -20,8 +20,7 @@ Tests of DOM BroadcastChannel in workers
<pre id="test">
<script class="testbody" language="javascript">
function runTest() {
function testWorker(x) {
var worker = new Worker("broadcastchannel_worker.js");
var bc = new BroadcastChannel('foobar');
@ -39,14 +38,25 @@ function runTest() {
bc.onmessage = function(event) {
is("hello world from the worker", event.data, "The message matches!");
SimpleTest.finish();
bc.close();
runTests();
}
worker.postMessage('go');
worker.postMessage(x);
}
var tests = [ 0, 3 ];
function runTests() {
if (tests.length == 0) {
SimpleTest.finish();
return;
}
testWorker(tests.shift());
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [["dom.broadcastChannel.enabled", true]]}, runTest);
SpecialPowers.pushPrefEnv({"set": [["dom.broadcastChannel.enabled", true]]}, runTests);
</script>
</pre>

View File

@ -0,0 +1,55 @@
<!--
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");
}
for (var i = 0; i < 3; ++i) {
SpecialPowers.forceCC();
SpecialPowers.forceGC();
}
if (id == 5) {
SimpleTest.finish();
}
event.target.postMessage(++id);
};
new Worker("broadcastchannel_worker_alive.js");
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [["dom.broadcastChannel.enabled", true]]}, runTests);
</script>
</pre>
</body>
</html>