test_WorkerDebuggerGlobalScope.enterEventLoop.xul 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 WorkerDebuggerGlobalScope.enterEventLoop"
  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 = "WorkerDebuggerGlobalScope.enterEventLoop_worker.js";
  17. const CHILD_WORKER_URL = "WorkerDebuggerGlobalScope.enterEventLoop_childWorker.js";
  18. const DEBUGGER_URL = BASE_URL + "WorkerDebuggerGlobalScope.enterEventLoop_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 child worker. This should cause the " +
  31. "child worker debugger to enter a nested event loop.");
  32. promise = waitForDebuggerMessage(childDbg, "paused");
  33. worker.postMessage("child:ping");
  34. yield promise;
  35. info("Send a request to the child worker debugger. This should cause " +
  36. "the child worker debugger to enter a second nested event loop.");
  37. promise = waitForDebuggerMessage(childDbg, "paused");
  38. childDbg.postMessage("eval");
  39. yield promise;
  40. info("Send a request to the child worker debugger. This should cause " +
  41. "the child worker debugger to leave its second nested event " +
  42. "loop. The child worker debugger should not send a response " +
  43. "for its previous request until after it has left the nested " +
  44. "event loop.");
  45. promise = waitForMultiple([
  46. waitForDebuggerMessage(childDbg, "resumed"),
  47. waitForDebuggerMessage(childDbg, "evalled")
  48. ]);
  49. childDbg.postMessage("resume");
  50. yield promise;
  51. info("Send a request to the child worker debugger. This should cause " +
  52. "the child worker debugger to leave its first nested event loop." +
  53. "The child worker should not send a response for its earlier " +
  54. "request until after the child worker debugger has left the " +
  55. "nested event loop.");
  56. promise = waitForMultiple([
  57. waitForDebuggerMessage(childDbg, "resumed"),
  58. waitForWorkerMessage(worker, "child:pong")
  59. ]);
  60. childDbg.postMessage("resume");
  61. yield promise;
  62. info("Send a request to the worker. This should cause the worker " +
  63. "debugger to enter a nested event loop.");
  64. promise = waitForDebuggerMessage(dbg, "paused");
  65. worker.postMessage("ping");
  66. yield promise;
  67. info("Terminate the worker. This should not cause the worker " +
  68. "debugger to terminate as well.");
  69. worker.terminate();
  70. worker.onmessage = function () {
  71. ok(false, "Worker should have been terminated.");
  72. };
  73. info("Send a request to the worker debugger. This should cause the " +
  74. "worker debugger to enter a second nested event loop.");
  75. promise = waitForDebuggerMessage(dbg, "paused");
  76. dbg.postMessage("eval");
  77. yield promise;
  78. info("Send a request to the worker debugger. This should cause the " +
  79. "worker debugger to leave its second nested event loop. The " +
  80. "worker debugger should not send a response for the previous " +
  81. "request until after leaving the nested event loop.");
  82. promise = waitForMultiple([
  83. waitForDebuggerMessage(dbg, "resumed"),
  84. waitForDebuggerMessage(dbg, "evalled")
  85. ]);
  86. dbg.postMessage("resume");
  87. yield promise;
  88. info("Send a request to the worker debugger. This should cause the " +
  89. "worker debugger to leave its first nested event loop. The " +
  90. "worker should not send a response for its earlier request, " +
  91. "since it has been terminated.");
  92. promise = waitForMultiple([
  93. waitForDebuggerMessage(dbg, "resumed"),
  94. ]);
  95. dbg.postMessage("resume");
  96. yield promise;
  97. SimpleTest.finish();
  98. });
  99. }
  100. ]]>
  101. </script>
  102. <body xmlns="http://www.w3.org/1999/xhtml">
  103. <p id="display"></p>
  104. <div id="content" style="display:none;"></div>
  105. <pre id="test"></pre>
  106. </body>
  107. <label id="test-result"/>
  108. </window>