test_bug985988.html 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=985988
  5. -->
  6. <head>
  7. <meta charset="utf-8">
  8. <title>Test for Bug 985988</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 985988 **/
  13. function handler() {
  14. return false;
  15. }
  16. function reversedHandler() {
  17. return true;
  18. }
  19. function test() {
  20. var t = document.getElementById("testtarget");
  21. t.onclick = handler;
  22. var e = new MouseEvent("click", {cancelable: true});
  23. t.dispatchEvent(e);
  24. ok(e.defaultPrevented, "Should have prevented default handling.");
  25. t.onclick = reversedHandler;
  26. e = new MouseEvent("click", {cancelable: true});
  27. t.dispatchEvent(e);
  28. ok(!e.defaultPrevented, "Shouldn't have prevented default handling.");
  29. // mouseover has reversed meaning for handler return value.
  30. t.onmouseover = reversedHandler;
  31. e = new MouseEvent("mouseover", {cancelable: true});
  32. t.dispatchEvent(e);
  33. ok(e.defaultPrevented, "Should have prevented default handling.");
  34. t.onmouseover = handler;
  35. e = new MouseEvent("mouseover", {cancelable: true});
  36. t.dispatchEvent(e);
  37. ok(!e.defaultPrevented, "Shouldn't have prevented default handling.");
  38. // error has reversed meaning for handler return value.
  39. t.onerror = reversedHandler;
  40. e = new ErrorEvent("error", {cancelable: true});
  41. t.dispatchEvent(e);
  42. ok(e.defaultPrevented, "Should have prevented default handling.");
  43. t.onerror = handler;
  44. e = new MouseEvent("error", {cancelable: true});
  45. t.dispatchEvent(e);
  46. ok(!e.defaultPrevented, "Shouldn't have prevented default handling.");
  47. SimpleTest.finish();
  48. }
  49. SimpleTest.waitForExplicitFinish();
  50. addLoadEvent(test);
  51. </script>
  52. </head>
  53. <body onload="test()">
  54. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=985988">Mozilla Bug 985988</a>
  55. <p id="display"></p>
  56. <div id="content" style="display: none">
  57. </div>
  58. <a href="#" id="testtarget">test target</a>
  59. <pre id="test">
  60. </pre>
  61. </body>
  62. </html>