2015-01-15 16:58:41 +00:00
|
|
|
<!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, {} ] },
|
2015-01-15 16:58:41 +00:00
|
|
|
new Blob([123], { type: 'plain/text' })
|
2015-01-15 16:58:41 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
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() {
|
2015-01-17 07:29:15 +00:00
|
|
|
var count = 2;
|
|
|
|
|
2015-01-15 16:58:41 +00:00
|
|
|
var bc = new BroadcastChannel("foobar");
|
|
|
|
ok(bc, "BroadcastChannel can be created");
|
|
|
|
|
|
|
|
bc.onmessage = function(event) {
|
2015-01-17 07:29:15 +00:00
|
|
|
ok(count < 2, "Still comparing...");
|
|
|
|
info("bc: " + currentTest);
|
2015-01-15 16:58:41 +00:00
|
|
|
compare(event.data, currentTest);
|
2015-01-17 07:29:15 +00:00
|
|
|
++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;
|
2015-01-15 16:58:41 +00:00
|
|
|
next();
|
|
|
|
}
|
|
|
|
|
|
|
|
function next() {
|
2015-01-17 07:29:15 +00:00
|
|
|
if (count < 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
is(count, 2, "Just 2 comparations");
|
|
|
|
count = 0;
|
|
|
|
|
2015-01-15 16:58:41 +00:00
|
|
|
if (!tests.length) {
|
|
|
|
SimpleTest.finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
currentTest = tests.shift();
|
|
|
|
bc.postMessage(currentTest);
|
2015-01-17 07:29:15 +00:00
|
|
|
info("Posted: " + currentTest);
|
2015-01-15 16:58:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var worker = new Worker("broadcastchannel_worker_any.js");
|
|
|
|
worker.onmessage = function(event) {
|
|
|
|
if (event.data == "READY") {
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
SpecialPowers.pushPrefEnv({"set": [["dom.broadcastChannel.enabled", true]]}, runTest);
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
|