test_bug493251.html (6166B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=493251 5 --> 6 <head> 7 <title>Test for Bug 493251</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <script 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=493251">Mozilla Bug 493251</a> 14 <p id="display"> 15 </p> 16 <div id="content" style="display: none"> 17 18 </div> 19 <pre id="test"> 20 <script type="application/javascript"> 21 22 /** Test for Bug 493251 */ 23 24 var win; 25 26 var mouseDown = 0; 27 var mouseUp = 0; 28 var mouseClick = 0; 29 30 var keyDown = 0; 31 var keyPress = 0; 32 var keyUp = 0; 33 34 function suppressEventHandling(aSuppress) { 35 var utils = SpecialPowers.getDOMWindowUtils(win); 36 ok(true, "suppressEventHandling: aSuppress=" + aSuppress); 37 utils.suppressEventHandling(aSuppress); 38 } 39 40 function dispatchMouseEvent(aType, aX, aY) { 41 ok(true, "Dipatching mouse event: aType=" + aType + ", aX=" + aX + ", aY" + aY); 42 synthesizeMouseAtPoint(aX, aY, { type: aType }, win); 43 } 44 45 function dumpEvent(aEvent) { 46 var detail = "target=" + aEvent.target + ", originalTarget=" + 47 aEvent.originalTarget + ", defaultPrevented=" + 48 aEvent.defaultPrevented + ", isTrusted=" + aEvent.isTrusted; 49 switch (aEvent.type) { 50 case "keydown": 51 case "keypress": 52 case "keyup": 53 detail += ", charCode=0x" + aEvent.charCode.toString(16) + 54 ", keyCode=0x" + aEvent.keyCode.toString(16) + 55 ", altKey=" + (aEvent.altKey ? "PRESSED" : "no") + 56 ", ctrlKey=" + (aEvent.ctrlKey ? "PRESSED" : "no") + 57 ", shiftKey=" + (aEvent.shiftKey ? "PRESSED" : "no") + 58 ", metaKey=" + (aEvent.metaKey ? "PRESSED" : "no"); 59 break; 60 case "mousedown": 61 case "mouseup": 62 case "click": 63 detail += ", screenX=" + aEvent.screenX + ", screenY=" + aEvent.screenY + 64 ", clientX=" + aEvent.clientX + ", clientY=" + aEvent.clientY + 65 ", altKey=" + (aEvent.altKey ? "PRESSED" : "no") + 66 ", ctrlKey=" + (aEvent.ctrlKey ? "PRESSED" : "no") + 67 ", shiftKey=" + (aEvent.shiftKey ? "PRESSED" : "no") + 68 ", metaKey=" + (aEvent.metaKey ? "PRESSED" : "no") + 69 ", button=" + aEvent.button + 70 ", relatedTarget=" + aEvent.relatedTarget; 71 break; 72 } 73 ok(true, aEvent.type + " event is handled: " + detail); 74 75 var fm = SpecialPowers.Cc["@mozilla.org/focus-manager;1"]. 76 getService(SpecialPowers.Ci.nsIFocusManager); 77 ok(true, "focused element is \"" + fm.focusedElement + 78 "\" and focused window is \"" + fm.focusedWindow + 79 "\" (the testing window is \"" + win + "\""); 80 } 81 82 function doTest() { 83 win.document.getElementsByTagName("input")[0].focus(); 84 win.addEventListener("keydown", 85 function(e) { dumpEvent(e); ++keyDown; }, true); 86 win.addEventListener("keypress", 87 function(e) { dumpEvent(e); ++keyPress; }, true); 88 win.addEventListener("keyup", 89 function(e) { dumpEvent(e); ++keyUp; }, true); 90 win.addEventListener("mousedown", 91 function(e) { dumpEvent(e); ++mouseDown; }, true); 92 win.addEventListener("mouseup", 93 function(e) { dumpEvent(e); ++mouseUp; }, true); 94 win.addEventListener("click", 95 function(e) { dumpEvent(e); ++mouseClick; }, true); 96 97 ok(true, "doTest #1..."); 98 synthesizeKey("a", {}, win); 99 is(keyDown, 1, "Wrong number events (1)"); 100 is(keyPress, 1, "Wrong number events (2)"); 101 is(keyUp, 1, "Wrong number events (3)"); 102 103 ok(true, "doTest #2..."); 104 suppressEventHandling(true); 105 synthesizeKey("a", {}, win); 106 is(keyDown, 1, "Wrong number events (4)"); 107 is(keyPress, 1, "Wrong number events (5)"); 108 is(keyUp, 1, "Wrong number events (6)"); 109 suppressEventHandling(false); 110 is(keyDown, 1, "Wrong number events (7)"); 111 is(keyPress, 1, "Wrong number events (8)"); 112 is(keyUp, 1, "Wrong number events (9)"); 113 114 setTimeout(continueTest1, 0); 115 } 116 117 function continueTest1() { 118 ok(true, "continueTest1..."); 119 win.addEventListener("keydown", () => { suppressEventHandling(true); }, {once: true}); 120 synthesizeKey("a", {}, win); 121 is(keyDown, 2, "Wrong number events (10)"); 122 is(keyPress, 1, "Wrong number events (11)"); 123 is(keyUp, 1, "Wrong number events (12)"); 124 suppressEventHandling(false); 125 setTimeout(continueTest2, 0); 126 } 127 128 function continueTest2() { 129 ok(true, "continueTest2 #1..."); 130 is(keyDown, 2, "Wrong number events (13)"); 131 is(keyPress, 2, "Wrong number events (14)"); 132 is(keyUp, 2, "Wrong number events (15)"); 133 134 dispatchMouseEvent("mousedown", 5, 5); 135 dispatchMouseEvent("mouseup", 5, 5); 136 is(mouseDown, 1, "Wrong number events (16)"); 137 is(mouseUp, 1, "Wrong number events (17)"); 138 is(mouseClick, 1, "Wrong number events (18)"); 139 140 ok(true, "continueTest2 #2..."); 141 suppressEventHandling(true); 142 dispatchMouseEvent("mousedown", 5, 5); 143 dispatchMouseEvent("mouseup", 5, 5); 144 suppressEventHandling(false); 145 is(mouseDown, 1, "Wrong number events (19)"); 146 is(mouseUp, 1, "Wrong number events (20)"); 147 is(mouseClick, 1, "Wrong number events (21)"); 148 149 setTimeout(continueTest3, 0); 150 } 151 152 function continueTest3() { 153 ok(true, "continueTest3..."); 154 dispatchMouseEvent("mousedown", 5, 5); 155 suppressEventHandling(true); 156 dispatchMouseEvent("mouseup", 5, 5); 157 suppressEventHandling(false); 158 setTimeout(continueTest4, 1000); 159 } 160 161 function continueTest4() { 162 ok(true, "continueTest4..."); 163 is(mouseDown, 2, "Wrong number events (19)"); 164 is(mouseUp, 2, "Wrong number events (20)"); 165 is(mouseClick, 2, "Wrong number events (21)"); 166 win.close(); 167 SimpleTest.finish(); 168 } 169 170 171 SimpleTest.waitForExplicitFinish(); 172 SimpleTest.requestFlakyTimeout("untriaged"); 173 win = window.open("window_bug493251.html", "_blank" , "width=500,height=500"); 174 175 </script> 176 </pre> 177 </body> 178 </html>