dom/workers/test/test_workersDisabled.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/workers/test/test_workersDisabled.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,54 @@
     1.4 +<!--
     1.5 +  Any copyright is dedicated to the Public Domain.
     1.6 +  http://creativecommons.org/publicdomain/zero/1.0/
     1.7 +-->
     1.8 +<!DOCTYPE HTML>
     1.9 +<html>
    1.10 +  <head>
    1.11 +    <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js">
    1.12 +    </script>
    1.13 +    <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.14 +  </head>
    1.15 +  <body>
    1.16 +    <script type="text/javascript">
    1.17 +      SimpleTest.waitForExplicitFinish();
    1.18 +
    1.19 +      const enabledPref = "dom.workers.enabled";
    1.20 +
    1.21 +      is(SpecialPowers.getBoolPref(enabledPref), true,
    1.22 +         "Workers should be enabled.");
    1.23 +
    1.24 +      SpecialPowers.pushPrefEnv({"set": [[enabledPref, false]]}, test1);
    1.25 +
    1.26 +      function test1() {
    1.27 +        ok(!("Worker" in window), "Worker constructor should not be available.");
    1.28 +
    1.29 +        var exception;
    1.30 +        try {
    1.31 +          var worker = new Worker("workersDisabled_worker.js");
    1.32 +        }
    1.33 +        catch(e) {
    1.34 +          exception = e;
    1.35 +        }
    1.36 +
    1.37 +        ok(exception, "Shouldn't be able to make a worker.");
    1.38 +
    1.39 +        SpecialPowers.pushPrefEnv({"set": [[enabledPref, true]]}, test2);
    1.40 +      }
    1.41 +
    1.42 +      function test2() {
    1.43 +        ok(("Worker" in window), "Worker constructor should be available.");
    1.44 +
    1.45 +        const message = "Hi";
    1.46 +
    1.47 +        var worker = new Worker("workersDisabled_worker.js");
    1.48 +        worker.onmessage = function(event) {
    1.49 +          is(event.data, message, "Good message.");
    1.50 +          SimpleTest.finish();
    1.51 +        }
    1.52 +        worker.postMessage(message);
    1.53 +      }
    1.54 +    </script>
    1.55 +  </body>
    1.56 +</html>
    1.57 +

mercurial