test_bug930374-chrome.html 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  10. <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
  11. <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/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 true in chrome even if it's consumed by default action handler of editor");
  41. setTimeout(function () {
  42. ok(gKeyPress.defaultPrevented,
  43. "Test2: keypress event's defaultPrevented should be true after event dispatching finished");
  44. SimpleTest.finish();
  45. }, 0);
  46. }, false);
  47. sendChar("a");
  48. }
  49. SimpleTest.waitForFocus(runTests);
  50. </script>
  51. </pre>
  52. </body>
  53. </html>