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.location); |
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, [], 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.location", 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 // location=0 indicates that we send events as standard keys. |
35 testKeyEventWithLocation("pageUp", 0, 33); | 35 testKeyEventWithLocation("pageUp", 0, 33); |
(...skipping 14 matching lines...) Expand all Loading... |
50 testKeyEventWithLocation("end", 3, 35); | 50 testKeyEventWithLocation("end", 3, 35); |
51 testKeyEventWithLocation("leftArrow", 3, 37); | 51 testKeyEventWithLocation("leftArrow", 3, 37); |
52 testKeyEventWithLocation("rightArrow", 3, 39); | 52 testKeyEventWithLocation("rightArrow", 3, 39); |
53 testKeyEventWithLocation("upArrow", 3, 38); | 53 testKeyEventWithLocation("upArrow", 3, 38); |
54 testKeyEventWithLocation("downArrow", 3, 40); | 54 testKeyEventWithLocation("downArrow", 3, 40); |
55 testKeyEventWithLocation("insert", 3, 45); | 55 testKeyEventWithLocation("insert", 3, 45); |
56 testKeyEventWithLocation("delete", 3, 46); | 56 testKeyEventWithLocation("delete", 3, 46); |
57 } else { | 57 } 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)."); | 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)."); |
59 } | 59 } |
OLD | NEW |