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