test_WorkerDebugger.postMessage.xul 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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="Test for WorkerDebugger.postMessage"
  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"
  12. src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
  13. <script type="application/javascript" src="dom_worker_helper.js"/>
  14. <script type="application/javascript">
  15. <![CDATA[
  16. const WORKER_URL = "WorkerDebugger.postMessage_worker.js";
  17. const CHILD_WORKER_URL = "WorkerDebugger.postMessage_childWorker.js";
  18. const DEBUGGER_URL = BASE_URL + "WorkerDebugger.postMessage_debugger.js";
  19. function test() {
  20. Task.spawn(function* () {
  21. SimpleTest.waitForExplicitFinish();
  22. info("Create a worker that creates a child worker, wait for their " +
  23. "debuggers to be registered, and initialize them.");
  24. let promise = waitForMultiple([
  25. waitForRegister(WORKER_URL, DEBUGGER_URL),
  26. waitForRegister(CHILD_WORKER_URL, DEBUGGER_URL)
  27. ]);
  28. let worker = new Worker(WORKER_URL);
  29. let [dbg, childDbg] = yield promise;
  30. info("Send a request to the worker debugger. This should cause the " +
  31. "the worker debugger to send a response.");
  32. promise = waitForDebuggerMessage(dbg, "pong");
  33. dbg.postMessage("ping");
  34. yield promise;
  35. info("Send a request to the child worker debugger. This should cause " +
  36. "the child worker debugger to send a response.");
  37. promise = waitForDebuggerMessage(childDbg, "pong");
  38. childDbg.postMessage("ping");
  39. yield promise;
  40. SimpleTest.finish();
  41. });
  42. }
  43. ]]>
  44. </script>
  45. <body xmlns="http://www.w3.org/1999/xhtml">
  46. <p id="display"></p>
  47. <div id="content" style="display:none;"></div>
  48. <pre id="test"></pre>
  49. </body>
  50. <label id="test-result"/>
  51. </window>