| OLD | NEW |
| 1 description("This tests keyboard events with KeyLocationCode argument."); | 1 description("This tests keyboard events with KeyLocationCode argument."); |
| 2 | 2 |
| 3 var lastKeyboardEvent; | 3 var lastKeyboardEvent; |
| 4 | 4 |
| 5 function recordKeyEvent(ev) { | 5 function recordKeyEvent(ev) { |
| 6 ev = ev || event; | 6 ev = ev || event; |
| 7 ev.keyCode = (ev.which || ev.keyCode); | 7 ev.keyCode = (ev.which || ev.keyCode); |
| 8 if (window.eventSender) { | 8 if (window.eventSender) { |
| 9 lastKeyboardEvent = ev; | 9 lastKeyboardEvent = ev; |
| 10 } else { | 10 } else { |
| 11 debug('Type=' + ev.type + ',' + | 11 debug('Type=' + ev.type + ',' + |
| 12 'keyCode=' + ev.keyCode + ',' + | 12 'keyCode=' + ev.keyCode + ',' + |
| 13 'ctrlKey=' + ev.ctrlKey + ',' + | 13 'ctrlKey=' + ev.ctrlKey + ',' + |
| 14 'shiftKey=' + ev.shiftKey + ',' + | 14 'shiftKey=' + ev.shiftKey + ',' + |
| 15 'altKey=' + ev.altKey + ',' + | 15 'altKey=' + ev.altKey + ',' + |
| 16 'metaKey=' + ev.metaKey + ',' + | 16 'metaKey=' + ev.metaKey + ',' + |
| 17 'location=' + ev.keyLocation); | 17 'location=' + ev.keyLocation); |
| 18 } | 18 } |
| 19 } | 19 } |
| 20 | 20 |
| 21 function testKeyEventWithLocation(evString, evLocation, expectedKeyCode) { | 21 function testKeyEventWithLocation(evString, evLocation, expectedKeyCode) { |
| 22 eventSender.keyDown(evString, [], evLocation); | 22 eventSender.keyDown(evString, [], eval(evLocation)); |
| 23 shouldBe("lastKeyboardEvent.type", '"keydown"'); | 23 shouldBe("lastKeyboardEvent.type", '"keydown"'); |
| 24 shouldEvaluateTo("lastKeyboardEvent.keyCode", expectedKeyCode); | 24 shouldEvaluateTo("lastKeyboardEvent.keyCode", expectedKeyCode); |
| 25 shouldEvaluateTo("lastKeyboardEvent.keyLocation", evLocation); | 25 shouldEvaluateTo("lastKeyboardEvent.keyLocation", evLocation); |
| 26 } | 26 } |
| 27 | 27 |
| 28 var textarea = document.createElement("textarea"); | 28 var textarea = document.createElement("textarea"); |
| 29 textarea.addEventListener("keydown", recordKeyEvent, false); | 29 textarea.addEventListener("keydown", recordKeyEvent, false); |
| 30 document.body.insertBefore(textarea, document.body.firstChild); | 30 document.body.insertBefore(textarea, document.body.firstChild); |
| 31 textarea.focus(); | 31 textarea.focus(); |
| 32 | 32 |
| 33 if (window.eventSender) { | 33 if (window.eventSender) { |
| 34 // location=0 indicates that we send events as standard keys. | 34 testKeyEventWithLocation("pageUp", "KeyboardEvent.DOM_KEY_LOCATION_STANDARD"
, 33); |
| 35 testKeyEventWithLocation("pageUp", 0, 33); | 35 testKeyEventWithLocation("pageDown", "KeyboardEvent.DOM_KEY_LOCATION_STANDAR
D", 34); |
| 36 testKeyEventWithLocation("pageDown", 0, 34); | 36 testKeyEventWithLocation("home", "KeyboardEvent.DOM_KEY_LOCATION_STANDARD",
36); |
| 37 testKeyEventWithLocation("home", 0, 36); | 37 testKeyEventWithLocation("end", "KeyboardEvent.DOM_KEY_LOCATION_STANDARD", 3
5); |
| 38 testKeyEventWithLocation("end", 0, 35); | 38 testKeyEventWithLocation("leftArrow", "KeyboardEvent.DOM_KEY_LOCATION_STANDA
RD", 37); |
| 39 testKeyEventWithLocation("leftArrow", 0, 37); | 39 testKeyEventWithLocation("rightArrow", "KeyboardEvent.DOM_KEY_LOCATION_STAND
ARD", 39); |
| 40 testKeyEventWithLocation("rightArrow", 0, 39); | 40 testKeyEventWithLocation("upArrow", "KeyboardEvent.DOM_KEY_LOCATION_STANDARD
", 38); |
| 41 testKeyEventWithLocation("upArrow", 0, 38); | 41 testKeyEventWithLocation("downArrow", "KeyboardEvent.DOM_KEY_LOCATION_STANDA
RD", 40); |
| 42 testKeyEventWithLocation("downArrow", 0, 40); | 42 testKeyEventWithLocation("insert", "KeyboardEvent.DOM_KEY_LOCATION_STANDARD"
, 45); |
| 43 testKeyEventWithLocation("insert", 0, 45); | 43 testKeyEventWithLocation("delete", "KeyboardEvent.DOM_KEY_LOCATION_STANDARD"
, 46); |
| 44 testKeyEventWithLocation("delete", 0, 46); | |
| 45 | 44 |
| 46 // location=3 indicates that we send events as numeric-pad keys. | 45 testKeyEventWithLocation("pageUp", "KeyboardEvent.DOM_KEY_LOCATION_NUMPAD",
33); |
| 47 testKeyEventWithLocation("pageUp", 3, 33); | 46 testKeyEventWithLocation("pageDown", "KeyboardEvent.DOM_KEY_LOCATION_NUMPAD"
, 34); |
| 48 testKeyEventWithLocation("pageDown", 3, 34); | 47 testKeyEventWithLocation("home", "KeyboardEvent.DOM_KEY_LOCATION_NUMPAD", 36
); |
| 49 testKeyEventWithLocation("home", 3, 36); | 48 testKeyEventWithLocation("end", "KeyboardEvent.DOM_KEY_LOCATION_NUMPAD", 35)
; |
| 50 testKeyEventWithLocation("end", 3, 35); | 49 testKeyEventWithLocation("leftArrow", "KeyboardEvent.DOM_KEY_LOCATION_NUMPAD
", 37); |
| 51 testKeyEventWithLocation("leftArrow", 3, 37); | 50 testKeyEventWithLocation("rightArrow", "KeyboardEvent.DOM_KEY_LOCATION_NUMPA
D", 39); |
| 52 testKeyEventWithLocation("rightArrow", 3, 39); | 51 testKeyEventWithLocation("upArrow", "KeyboardEvent.DOM_KEY_LOCATION_NUMPAD",
38); |
| 53 testKeyEventWithLocation("upArrow", 3, 38); | 52 testKeyEventWithLocation("downArrow", "KeyboardEvent.DOM_KEY_LOCATION_NUMPAD
", 40); |
| 54 testKeyEventWithLocation("downArrow", 3, 40); | 53 testKeyEventWithLocation("insert", "KeyboardEvent.DOM_KEY_LOCATION_NUMPAD",
45); |
| 55 testKeyEventWithLocation("insert", 3, 45); | 54 testKeyEventWithLocation("delete", "KeyboardEvent.DOM_KEY_LOCATION_NUMPAD",
46); |
| 56 testKeyEventWithLocation("delete", 3, 46); | |
| 57 } else { | 55 } else { |
| 58 debug("This test requires DumpRenderTree. To manually test, 1) focus on the
textarea above and push numpad keys without locking NumLock and 2) see if the l
ocation= value is 3 (DOM_KEY_LOCATION_NUMPAD specified in DOM level 3)."); | 56 debug("This test requires DumpRenderTree. To manually test, 1) focus on the
textarea above and push numpad keys without locking NumLock and 2) see if the l
ocation= value is KeyboardEvent.DOM_KEY_LOCATION_NUMPAD (specified in DOM level
3)."); |
| 59 } | 57 } |
| OLD | NEW |