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