dom/workers/test/test_workersDisabled.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 <!--
michael@0 2 Any copyright is dedicated to the Public Domain.
michael@0 3 http://creativecommons.org/publicdomain/zero/1.0/
michael@0 4 -->
michael@0 5 <!DOCTYPE HTML>
michael@0 6 <html>
michael@0 7 <head>
michael@0 8 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js">
michael@0 9 </script>
michael@0 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 11 </head>
michael@0 12 <body>
michael@0 13 <script type="text/javascript">
michael@0 14 SimpleTest.waitForExplicitFinish();
michael@0 15
michael@0 16 const enabledPref = "dom.workers.enabled";
michael@0 17
michael@0 18 is(SpecialPowers.getBoolPref(enabledPref), true,
michael@0 19 "Workers should be enabled.");
michael@0 20
michael@0 21 SpecialPowers.pushPrefEnv({"set": [[enabledPref, false]]}, test1);
michael@0 22
michael@0 23 function test1() {
michael@0 24 ok(!("Worker" in window), "Worker constructor should not be available.");
michael@0 25
michael@0 26 var exception;
michael@0 27 try {
michael@0 28 var worker = new Worker("workersDisabled_worker.js");
michael@0 29 }
michael@0 30 catch(e) {
michael@0 31 exception = e;
michael@0 32 }
michael@0 33
michael@0 34 ok(exception, "Shouldn't be able to make a worker.");
michael@0 35
michael@0 36 SpecialPowers.pushPrefEnv({"set": [[enabledPref, true]]}, test2);
michael@0 37 }
michael@0 38
michael@0 39 function test2() {
michael@0 40 ok(("Worker" in window), "Worker constructor should be available.");
michael@0 41
michael@0 42 const message = "Hi";
michael@0 43
michael@0 44 var worker = new Worker("workersDisabled_worker.js");
michael@0 45 worker.onmessage = function(event) {
michael@0 46 is(event.data, message, "Good message.");
michael@0 47 SimpleTest.finish();
michael@0 48 }
michael@0 49 worker.postMessage(message);
michael@0 50 }
michael@0 51 </script>
michael@0 52 </body>
michael@0 53 </html>
michael@0 54

mercurial