test_bug930374-content.html 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=930374
  5. -->
  6. <head>
  7. <meta charset="utf-8">
  8. <title>Test for Bug 930374</title>
  9. <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  10. <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  11. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  12. </head>
  13. <body>
  14. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=930374">Mozilla Bug 930374</a>
  15. <div id="display">
  16. <input id="input-text">
  17. </div>
  18. <div id="content" style="display: none">
  19. </div>
  20. <pre id="test">
  21. <script type="application/javascript">
  22. SimpleTest.waitForExplicitFinish();
  23. var gKeyPress = null;
  24. function onKeyPress(aEvent)
  25. {
  26. gKeyPress = aEvent;
  27. is(aEvent.target, document.getElementById("input-text"), "input element should have focus");
  28. ok(!aEvent.defaultPrevented, "keypress event should be consumed before keypress event handler");
  29. }
  30. function runTests()
  31. {
  32. document.addEventListener("keypress", onKeyPress, false);
  33. var input = document.getElementById("input-text");
  34. input.focus();
  35. input.addEventListener("input", function (aEvent) {
  36. input.removeEventListener("input", arguments.callee, false);
  37. ok(gKeyPress,
  38. "Test1: keypress event must be fired before an input event");
  39. ok(!gKeyPress.defaultPrevented,
  40. "Test1: keypress event's defaultPrevented should be false even though it's consumed by the default action handler of editor");
  41. gKeyPress.preventDefault();
  42. ok(gKeyPress.defaultPrevented,
  43. "Test1: keypress event's defaultPrevented should become true because of a call of preventDefault()");
  44. }, false);
  45. sendChar("a");
  46. gKeyPress = null;
  47. input.addEventListener("input", function (aEvent) {
  48. input.removeEventListener("input", arguments.callee, false);
  49. ok(gKeyPress,
  50. "Test2: keypress event must be fired before an input event");
  51. ok(!gKeyPress.defaultPrevented,
  52. "Test2: keypress event's defaultPrevented should be false even though it's consumed by the default action handler of editor");
  53. setTimeout(function () {
  54. ok(!gKeyPress.defaultPrevented,
  55. "Test2: keypress event's defaultPrevented should not become true after event dispatching finished");
  56. SimpleTest.finish();
  57. }, 0);
  58. }, false);
  59. sendChar("b");
  60. }
  61. SimpleTest.waitForFocus(runTests);
  62. </script>
  63. </pre>
  64. </body>
  65. </html>