gecko-dev/dom/workers/test/test_websocket_pref.html

78 строки
1.8 KiB
HTML

<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE HTML>
<html>
<head>
<title>Test for WebSocket object 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>
<script id="js_script" type="text/js-worker">
onmessage = function() {
postMessage("WebSocket" in this ? "OK" : "KO");
}
</script>
<script class="testbody" type="text/javascript">
SpecialPowers.pushPrefEnv({"set": [["dom.workers.websocket.enabled", true]]},
function() {
var blob = new Blob([document.getElementById("js_script").textContent],
{type: "text/javascript"});
var url = URL.createObjectURL(blob);
var tests = [
function() {
SpecialPowers.pushPrefEnv({"set": [["dom.workers.websocket.enabled", true]]},
function() {
ok("WebSocket" in window, "WebSocket are always enabled on main-thread");
var w = new Worker(url);
w.onmessage = function(e) {
is(e.data, "OK", "WebSocket enabled in workers!");
runTest();
}
w.postMessage('go');
});
},
function() {
SpecialPowers.pushPrefEnv({"set": [["dom.workers.websocket.enabled", false]]},
function() {
ok("WebSocket" in window, "WebSocket are always enabled on main-thread");
var w = new Worker(url);
w.onmessage = function(e) {
is(e.data, "KO", "WebSocket disabled in workers!");
runTest();
}
w.postMessage('go');
});
}
];
function runTest() {
if (!tests.length) {
SimpleTest.finish();
return;
}
var t = tests.shift();
t();
}
runTest();
});
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>