1 description("This tests keyboard events with KeyLocationCode argument.");
5 function recordKeyEvent(ev
) {
7 ev
.keyCode
= (ev
.which
|| ev
.keyCode
);
8 if (window
.eventSender
) {
9 lastKeyboardEvent
= ev
;
11 debug('Type=' + ev
.type
+ ',' +
12 'keyCode=' + ev
.keyCode
+ ',' +
13 'ctrlKey=' + ev
.ctrlKey
+ ',' +
14 'shiftKey=' + ev
.shiftKey
+ ',' +
15 'altKey=' + ev
.altKey
+ ',' +
16 'metaKey=' + ev
.metaKey
+ ',' +
17 'location=' + ev
.location
);
21 function testKeyEventWithLocation(evString
, evLocation
, expectedKeyCode
) {
22 eventSender
.keyDown(evString
, [], eval(evLocation
));
23 shouldBe("lastKeyboardEvent.type", '"keydown"');
24 shouldEvaluateTo("lastKeyboardEvent.keyCode", expectedKeyCode
);
25 shouldEvaluateTo("lastKeyboardEvent.location", evLocation
);
28 var textarea
= document
.createElement("textarea");
29 textarea
.addEventListener("keydown", recordKeyEvent
, false);
30 document
.body
.insertBefore(textarea
, document
.body
.firstChild
);
33 if (window
.eventSender
) {
34 testKeyEventWithLocation("pageUp", "KeyboardEvent.DOM_KEY_LOCATION_STANDARD", 33);
35 testKeyEventWithLocation("pageDown", "KeyboardEvent.DOM_KEY_LOCATION_STANDARD", 34);
36 testKeyEventWithLocation("home", "KeyboardEvent.DOM_KEY_LOCATION_STANDARD", 36);
37 testKeyEventWithLocation("end", "KeyboardEvent.DOM_KEY_LOCATION_STANDARD", 35);
38 testKeyEventWithLocation("leftArrow", "KeyboardEvent.DOM_KEY_LOCATION_STANDARD", 37);
39 testKeyEventWithLocation("rightArrow", "KeyboardEvent.DOM_KEY_LOCATION_STANDARD", 39);
40 testKeyEventWithLocation("upArrow", "KeyboardEvent.DOM_KEY_LOCATION_STANDARD", 38);
41 testKeyEventWithLocation("downArrow", "KeyboardEvent.DOM_KEY_LOCATION_STANDARD", 40);
42 testKeyEventWithLocation("insert", "KeyboardEvent.DOM_KEY_LOCATION_STANDARD", 45);
43 testKeyEventWithLocation("delete", "KeyboardEvent.DOM_KEY_LOCATION_STANDARD", 46);
45 testKeyEventWithLocation("pageUp", "KeyboardEvent.DOM_KEY_LOCATION_NUMPAD", 33);
46 testKeyEventWithLocation("pageDown", "KeyboardEvent.DOM_KEY_LOCATION_NUMPAD", 34);
47 testKeyEventWithLocation("home", "KeyboardEvent.DOM_KEY_LOCATION_NUMPAD", 36);
48 testKeyEventWithLocation("end", "KeyboardEvent.DOM_KEY_LOCATION_NUMPAD", 35);
49 testKeyEventWithLocation("leftArrow", "KeyboardEvent.DOM_KEY_LOCATION_NUMPAD", 37);
50 testKeyEventWithLocation("rightArrow", "KeyboardEvent.DOM_KEY_LOCATION_NUMPAD", 39);
51 testKeyEventWithLocation("upArrow", "KeyboardEvent.DOM_KEY_LOCATION_NUMPAD", 38);
52 testKeyEventWithLocation("downArrow", "KeyboardEvent.DOM_KEY_LOCATION_NUMPAD", 40);
53 testKeyEventWithLocation("insert", "KeyboardEvent.DOM_KEY_LOCATION_NUMPAD", 45);
54 testKeyEventWithLocation("delete", "KeyboardEvent.DOM_KEY_LOCATION_NUMPAD", 46);
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 location= value is KeyboardEvent.DOM_KEY_LOCATION_NUMPAD (specified in DOM level 3).");