test_bug684208.html 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=684208
  5. -->
  6. <head>
  7. <meta charset="utf-8">
  8. <title>Test for Bug 684208</title>
  9. <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  10. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  11. <script type="application/javascript">
  12. /** Test for Bug 684208 **/
  13. function checkDispatchReturnValue(targetOrUndefined) {
  14. var target = targetOrUndefined ? targetOrUndefined : self;
  15. function createEvent() {
  16. if ("MouseEvent" in this) {
  17. return new MouseEvent("click", {cancelable: true});
  18. }
  19. return new Event("dummy", {cancelable: true});
  20. }
  21. function postSelfMessage(msg) {
  22. try {
  23. self.postMessage(msg);
  24. } catch(ex) {
  25. self.postMessage(msg, "*");
  26. }
  27. }
  28. function passiveListener(e) {
  29. e.target.removeEventListener(e.type, passiveListener);
  30. }
  31. var event = createEvent();
  32. target.addEventListener(event.type, passiveListener);
  33. postSelfMessage(target.dispatchEvent(event) == true);
  34. function cancellingListener(e) {
  35. e.target.removeEventListener(e.type, cancellingListener);
  36. e.preventDefault();
  37. }
  38. event = createEvent();
  39. target.addEventListener(event.type, cancellingListener);
  40. postSelfMessage(target.dispatchEvent(event) == false);
  41. }
  42. function test() {
  43. var expectedEvents = 6;
  44. function messageHandler(e) {
  45. ok(e.data, "All the dispatchEvent calls should pass.");
  46. --expectedEvents;
  47. if (!expectedEvents) {
  48. window.onmessage = null;
  49. window.worker.onmessage = null;
  50. SimpleTest.finish();
  51. }
  52. }
  53. window.onmessage = messageHandler;
  54. checkDispatchReturnValue();
  55. checkDispatchReturnValue(document.getElementById("link"));
  56. window.worker =
  57. new Worker(URL.createObjectURL(new Blob(["(" + checkDispatchReturnValue.toString() + ")();"])));
  58. window.worker.onmessage = messageHandler;
  59. }
  60. SimpleTest.waitForExplicitFinish();
  61. </script>
  62. </head>
  63. <body onload="test();">
  64. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=684208">Mozilla Bug 684208</a>
  65. <p id="display"></p>
  66. <div id="content" style="display: none">
  67. <a id="link" href="#foo">foo</a>
  68. </div>
  69. <pre id="test">
  70. </pre>
  71. </body>
  72. </html>