mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
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:
parent
4af9097f62
commit
039c838ed8
12
dom/broadcastchannel/tests/broadcastchannel_sharedWorker.js
Normal file
12
dom/broadcastchannel/tests/broadcastchannel_sharedWorker.js
Normal 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");
|
||||
}
|
||||
}
|
@ -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");
|
||||
|
@ -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);
|
||||
|
@ -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]
|
||||
|
@ -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>
|
@ -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>
|
||||
|
@ -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>
|
Loading…
Reference in New Issue
Block a user