test_bug545268.html 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=545268
  5. -->
  6. <head>
  7. <title>Test for Bug 545268</title>
  8. <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  9. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  10. </head>
  11. <body>
  12. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=545268">Mozilla Bug 545268</a>
  13. <p id="display">
  14. </p>
  15. <div id="content" style="display: none">
  16. </div>
  17. <pre id="test">
  18. <script type="application/javascript">
  19. /** Test for Bug 545268
  20. Like the test for bug 493251, but we test that suppressing events in
  21. a parent window stops the events from reaching the child window. */
  22. var win;
  23. var subwin;
  24. var mouseDown = 0;
  25. var mouseUp = 0;
  26. var mouseClick = 0;
  27. var keyDown = 0;
  28. var keyPress = 0;
  29. var keyUp = 0;
  30. function dispatchKeyEvent(type) {
  31. var utils = SpecialPowers.getDOMWindowUtils(subwin);
  32. utils.sendKeyEvent(type,
  33. SpecialPowers.Ci.nsIDOMKeyEvent.DOM_VK_A,
  34. 0, 0);
  35. }
  36. function doTest() {
  37. var utils = SpecialPowers.getDOMWindowUtils(win);
  38. var f = win.document.getElementById("f");
  39. subwin = f.contentWindow;
  40. subwin.document.getElementsByTagName("input")[0].focus();
  41. subwin.addEventListener("keydown", function(e) { ++keyDown; }, true);
  42. subwin.addEventListener("keypress", function(e) { ++keyPress; }, true);
  43. subwin.addEventListener("keyup", function(e) { ++keyUp; }, true);
  44. subwin.addEventListener("mousedown", function(e) { ++mouseDown; }, true);
  45. subwin.addEventListener("mouseup", function(e) { ++mouseUp; }, true);
  46. subwin.addEventListener("click", function(e) { ++mouseClick; }, true);
  47. dispatchKeyEvent("keydown");
  48. dispatchKeyEvent("keypress");
  49. dispatchKeyEvent("keyup");
  50. is(keyDown, 1, "Wrong number events (1)");
  51. is(keyPress, 1, "Wrong number events (2)");
  52. is(keyUp, 1, "Wrong number events (3)");
  53. // Test that suppressing events on the parent window prevents key
  54. // events in the subdocument window
  55. utils.suppressEventHandling(true);
  56. dispatchKeyEvent("keydown");
  57. dispatchKeyEvent("keypress");
  58. dispatchKeyEvent("keyup");
  59. is(keyDown, 1, "Wrong number events (4)");
  60. is(keyPress, 1, "Wrong number events (5)");
  61. is(keyUp, 1, "Wrong number events (6)");
  62. utils.suppressEventHandling(false);
  63. is(keyDown, 1, "Wrong number events (7)");
  64. is(keyPress, 1, "Wrong number events (8)");
  65. is(keyUp, 1, "Wrong number events (9)");
  66. setTimeout(continueTest1, 0);
  67. }
  68. function continueTest1() {
  69. var utils = SpecialPowers.getDOMWindowUtils(win);
  70. dispatchKeyEvent("keydown");
  71. utils.suppressEventHandling(true);
  72. dispatchKeyEvent("keypress");
  73. dispatchKeyEvent("keyup");
  74. is(keyDown, 2, "Wrong number events (10)");
  75. is(keyPress, 1, "Wrong number events (11)");
  76. is(keyUp, 1, "Wrong number events (12)");
  77. utils.suppressEventHandling(false);
  78. setTimeout(continueTest2, 0);
  79. }
  80. function continueTest2() {
  81. var utils = SpecialPowers.getDOMWindowUtils(win);
  82. is(keyDown, 2, "Wrong number events (13)");
  83. is(keyPress, 2, "Wrong number events (14)");
  84. is(keyUp, 2, "Wrong number events (15)");
  85. utils.sendMouseEvent("mousedown", 5, 5, 0, 1, 0);
  86. utils.sendMouseEvent("mouseup", 5, 5, 0, 1, 0);
  87. is(mouseDown, 1, "Wrong number events (16)");
  88. is(mouseUp, 1, "Wrong number events (17)");
  89. is(mouseClick, 1, "Wrong number events (18)");
  90. utils.suppressEventHandling(true);
  91. utils.sendMouseEvent("mousedown", 5, 5, 0, 1, 0);
  92. utils.sendMouseEvent("mouseup", 5, 5, 0, 1, 0);
  93. utils.suppressEventHandling(false);
  94. is(mouseDown, 1, "Wrong number events (19)");
  95. is(mouseUp, 1, "Wrong number events (20)");
  96. is(mouseClick, 1, "Wrong number events (21)");
  97. setTimeout(continueTest3, 0);
  98. }
  99. function continueTest3() {
  100. var utils = SpecialPowers.getDOMWindowUtils(win);
  101. utils.sendMouseEvent("mousedown", 5, 5, 0, 1, 0);
  102. utils.suppressEventHandling(true);
  103. utils.sendMouseEvent("mouseup", 5, 5, 0, 1, 0);
  104. utils.suppressEventHandling(false);
  105. setTimeout(continueTest4, 1000);
  106. }
  107. function continueTest4() {
  108. is(mouseDown, 2, "Wrong number events (19)");
  109. is(mouseUp, 2, "Wrong number events (20)");
  110. is(mouseClick, 2, "Wrong number events (21)");
  111. win.close();
  112. SimpleTest.finish();
  113. }
  114. SimpleTest.waitForExplicitFinish();
  115. SimpleTest.requestFlakyTimeout("untriaged");
  116. win = window.open("data:text/html,<iframe id='f' style='position:absolute; border:none; width:100%; height:100%; left:0; top:0' src='data:text/html,&lt;input&gt;'>", "" , "");
  117. win.onload = doTest;
  118. </script>
  119. </pre>
  120. </body>
  121. </html>