test_workersDisabled.xul 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?xml version="1.0"?>
  2. <!--
  3. Any copyright is dedicated to the Public Domain.
  4. http://creativecommons.org/publicdomain/zero/1.0/
  5. -->
  6. <window title="DOM Worker Threads Test"
  7. xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  8. onload="test();">
  9. <script type="application/javascript"
  10. src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
  11. <script type="application/javascript" src="dom_worker_helper.js"/>
  12. <script type="application/javascript">
  13. <![CDATA[
  14. function test()
  15. {
  16. const enabledPref = "dom.workers.enabled";
  17. const message = "Hi";
  18. var prefs = Components.classes["@mozilla.org/preferences-service;1"]
  19. .getService(Components.interfaces.nsIPrefBranch);
  20. is(prefs.getBoolPref(enabledPref), true, "Workers should be enabled.");
  21. prefs.setBoolPref(enabledPref, false);
  22. ok("Worker" in window, "Worker constructor should be available.");
  23. ok("ChromeWorker" in window,
  24. "ChromeWorker constructor should be available.");
  25. var worker = new ChromeWorker("workersDisabled_worker.js");
  26. worker.onmessage = function(event) {
  27. is(event.data, message, "Good message.");
  28. prefs.clearUserPref(enabledPref);
  29. finish();
  30. }
  31. worker.postMessage(message);
  32. waitForWorkerFinish();
  33. }
  34. ]]>
  35. </script>
  36. <body xmlns="http://www.w3.org/1999/xhtml">
  37. <p id="display"></p>
  38. <div id="content" style="display:none;"></div>
  39. <pre id="test"></pre>
  40. </body>
  41. <label id="test-result"/>
  42. </window>