test_WorkerDebugger_promise.xul 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 with DOM Promises"
  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_promise_worker.js";
  17. const DEBUGGER_URL = BASE_URL + "WorkerDebugger_promise_debugger.js";
  18. function test() {
  19. Task.spawn(function* () {
  20. SimpleTest.waitForExplicitFinish();
  21. let promise = waitForRegister(WORKER_URL, DEBUGGER_URL);
  22. let worker = new Worker(WORKER_URL);
  23. let dbg = yield promise;
  24. info("Send a request to the worker. This should cause the worker " +
  25. "to send a response.");
  26. promise = waitForWorkerMessage(worker, "resolved");
  27. worker.postMessage("resolve");
  28. yield promise;
  29. info("Send a request to the debugger. This should cause the debugger " +
  30. "to send a response.");
  31. promise = waitForDebuggerMessage(dbg, "resolved");
  32. dbg.postMessage("resolve");
  33. yield promise;
  34. info("Send a request to the worker. This should cause the debugger " +
  35. "to enter a nested event loop.");
  36. promise = waitForDebuggerMessage(dbg, "paused");
  37. worker.postMessage("pause");
  38. yield promise;
  39. info("Send a request to the debugger. This should cause the debugger " +
  40. "to leave the nested event loop.");
  41. promise = waitForMultiple([
  42. waitForDebuggerMessage(dbg, "resumed"),
  43. waitForWorkerMessage(worker, "resumed")
  44. ]);
  45. dbg.postMessage("resume");
  46. yield promise;
  47. SimpleTest.finish();
  48. });
  49. }
  50. ]]>
  51. </script>
  52. <body xmlns="http://www.w3.org/1999/xhtml">
  53. <p id="display"></p>
  54. <div id="content" style="display:none;"></div>
  55. <pre id="test"></pre>
  56. </body>
  57. <label id="test-result"/>
  58. </window>