test_bug633058.html 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=633058
  5. -->
  6. <head>
  7. <title>Test for Bug 633058</title>
  8. <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  9. <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  10. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  11. </head>
  12. <body>
  13. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=633058">Mozilla Bug 633058</a>
  14. <p id="display"></p>
  15. <div id="content">
  16. <input>
  17. </div>
  18. <pre id="test">
  19. <script type="application/javascript">
  20. /** Test for Bug 633058 **/
  21. SimpleTest.waitForExplicitFinish();
  22. // Turn off Spatial Navigation so that the 'keypress' event fires.
  23. SimpleTest.waitForFocus(function() {
  24. SpecialPowers.pushPrefEnv({"set":[['snav.enabled', false]]}, startTest);
  25. });
  26. function startTest() {
  27. var nbExpectedKeyPress = 8;
  28. var inputGotKeyPress = 0;
  29. var divGotKeyPress = 0;
  30. var input = document.getElementsByTagName('input')[0];
  31. var content = document.getElementById('content');
  32. content.addEventListener('keypress', function() {
  33. divGotKeyPress++;
  34. if (divGotKeyPress == nbExpectedKeyPress) {
  35. is(inputGotKeyPress, nbExpectedKeyPress, "input got all keypress events");
  36. is(divGotKeyPress, nbExpectedKeyPress, "div got all keypress events");
  37. SimpleTest.finish();
  38. }
  39. }, false);
  40. input.addEventListener('keypress', function() {
  41. inputGotKeyPress++;
  42. }, false);
  43. input.addEventListener('focus', function() {
  44. input.removeEventListener('focus', arguments.callee, false);
  45. synthesizeKey('VK_UP', {});
  46. synthesizeKey('VK_LEFT', {});
  47. synthesizeKey('VK_RIGHT', {});
  48. synthesizeKey('VK_DOWN', {});
  49. synthesizeKey('VK_BACK_SPACE', {});
  50. synthesizeKey('VK_DELETE', {});
  51. synthesizeKey('VK_ESCAPE', {});
  52. synthesizeKey('VK_RETURN', {});
  53. }, false);
  54. input.focus();
  55. }
  56. </script>
  57. </pre>
  58. </body>
  59. </html>