2 <link rel=
"help" href=
"http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardEvent-code" />
3 <script src=
"../../resources/js-test.js"></script>-
4 <textarea id=
"textarea"></textarea>
6 description('Tests KeyboardEvent.code attribute');
7 var textarea
= document
.getElementById('textarea');
8 textarea
.addEventListener('keydown', recordKeyEvent
, false);
9 textarea
.addEventListener('keyup', recordKeyEvent
, false);
10 textarea
.addEventListener('keypress', recordKeyEvent
, false);
13 var lastKeyboardDownEvent
, lastKeyboardPressEvent
, lastKeyboardUpEvent
;
15 function recordKeyEvent(ev
) {
16 if (window
.eventSender
) {
17 if (ev
.type
=== "keydown")
18 lastKeyboardDownEvent
= ev
;
19 else if (ev
.type
=== "keyup")
20 lastKeyboardUpEvent
= ev
;
21 else if (ev
.type
=== "keypress")
22 lastKeyboardPressEvent
= ev
;
24 debug('Type=' + ev
.type
+ ',' + 'code=' + ev
.code
);
28 if (window
.eventSender
) {
29 debug('AlphaNumeric Keys');
30 eventSender
.keyDown('A');
31 shouldEvaluateTo('lastKeyboardDownEvent.code', '\'KeyA\'') ;
32 shouldEvaluateTo('lastKeyboardUpEvent.code', '\'KeyA\'') ;
33 shouldEvaluateTo('lastKeyboardPressEvent.code', '\'KeyA\'') ;
34 eventSender
.keyDown('a'); // Small letters.
35 shouldEvaluateTo('lastKeyboardDownEvent.code', '\'KeyA\'') ;
36 eventSender
.keyDown('M');
37 shouldEvaluateTo('lastKeyboardDownEvent.code', '\'KeyM\'') ;
38 eventSender
.keyDown('m'); // Small letters.
39 shouldEvaluateTo('lastKeyboardDownEvent.code', '\'KeyM\'');
40 eventSender
.keyDown('Z');
41 shouldEvaluateTo('lastKeyboardDownEvent.code', '\'KeyZ\'') ;
42 eventSender
.keyDown('z');
43 shouldEvaluateTo('lastKeyboardDownEvent.code', '\'KeyZ\'');
44 eventSender
.keyDown('0');
45 shouldEvaluateTo('lastKeyboardDownEvent.code', '\'Digit0\'');
46 shouldEvaluateTo('lastKeyboardUpEvent.code', '\'Digit0\'');
47 shouldEvaluateTo('lastKeyboardPressEvent.code', '\'Digit0\'');
48 eventSender
.keyDown('4');
49 shouldEvaluateTo('lastKeyboardDownEvent.code', '\'Digit4\'');
50 eventSender
.keyDown('9');
51 shouldEvaluateTo('lastKeyboardDownEvent.code', '\'Digit9\'');
52 eventSender
.keyDown('backspace');
53 shouldEvaluateTo('lastKeyboardDownEvent.code', '\'Backspace\'');
55 debug('Functional Keys');
56 eventSender
.keyDown('leftControl');
57 shouldEvaluateTo('lastKeyboardDownEvent.code', '\'ControlLeft\'');
58 shouldEvaluateTo('lastKeyboardUpEvent.code', '\'ControlLeft\'');
59 eventSender
.keyDown('rightControl');
60 shouldEvaluateTo('lastKeyboardDownEvent.code', '\'ControlRight\'');
61 eventSender
.keyDown('leftShift');
62 shouldEvaluateTo('lastKeyboardDownEvent.code', '\'ShiftLeft\'');
63 eventSender
.keyDown('rightShift');
64 shouldEvaluateTo('lastKeyboardDownEvent.code', '\'ShiftRight\'');
65 eventSender
.keyDown('leftAlt');
66 shouldEvaluateTo('lastKeyboardDownEvent.code', '\'AltLeft\'');
67 eventSender
.keyDown('rightAlt');
68 shouldEvaluateTo('lastKeyboardDownEvent.code', '\'AltRight\'');
69 eventSender
.keyDown('\n');
70 shouldEvaluateTo('lastKeyboardDownEvent.code', '\'Enter\'');
71 eventSender
.keyDown('menu');
72 shouldEvaluateTo('lastKeyboardDownEvent.code', '\'ContextMenu\'');
73 eventSender
.keyDown(' ');
74 shouldEvaluateTo('lastKeyboardDownEvent.code', '\'Space\'');
75 shouldEvaluateTo('lastKeyboardUpEvent.code', '\'Space\'');
76 shouldEvaluateTo('lastKeyboardPressEvent.code', '\'Space\'');
77 eventSender
.keyDown('\t');
78 shouldEvaluateTo('lastKeyboardDownEvent.code', '\'Tab\'');
79 shouldEvaluateTo('lastKeyboardUpEvent.code', '\'Tab\'');
82 eventSender
.keyDown('insert');
83 shouldEvaluateTo('lastKeyboardDownEvent.code', '\'Insert\'');
84 shouldEvaluateTo('lastKeyboardUpEvent.code', '\'Insert\'');
85 eventSender
.keyDown('delete');
86 shouldEvaluateTo('lastKeyboardDownEvent.code', '\'Delete\'');
87 eventSender
.keyDown('home');
88 shouldEvaluateTo('lastKeyboardDownEvent.code', '\'Home\'');
89 eventSender
.keyDown('end');
90 shouldEvaluateTo('lastKeyboardDownEvent.code', '\'End\'');
91 eventSender
.keyDown('pageUp');
92 shouldEvaluateTo('lastKeyboardDownEvent.code', '\'PageUp\'');
93 eventSender
.keyDown('pageDown');
94 shouldEvaluateTo('lastKeyboardDownEvent.code', '\'PageDown\'');
95 shouldEvaluateTo('lastKeyboardUpEvent.code', '\'PageDown\'');
97 debug('Arrow Pad Section');
98 eventSender
.keyDown('rightArrow');
99 shouldEvaluateTo('lastKeyboardDownEvent.code', '\'ArrowRight\'');
100 shouldEvaluateTo('lastKeyboardUpEvent.code', '\'ArrowRight\'');
101 eventSender
.keyDown('downArrow');
102 shouldEvaluateTo('lastKeyboardDownEvent.code', '\'ArrowDown\'');
103 eventSender
.keyDown('leftArrow');
104 shouldEvaluateTo('lastKeyboardDownEvent.code', '\'ArrowLeft\'');
105 eventSender
.keyDown('upArrow');
106 shouldEvaluateTo('lastKeyboardDownEvent.code', '\'ArrowUp\'');
107 shouldEvaluateTo('lastKeyboardUpEvent.code', '\'ArrowUp\'');
109 debug('Number Pad Section');
110 eventSender
.keyDown('numLock');
111 shouldEvaluateTo('lastKeyboardDownEvent.code', '\'NumLock\'');
112 shouldEvaluateTo('lastKeyboardUpEvent.code', '\'NumLock\'');
114 debug('Function Section');
115 eventSender
.keyDown('escape');
116 shouldEvaluateTo('lastKeyboardDownEvent.code', '\'Escape\'');
117 shouldEvaluateTo('lastKeyboardUpEvent.code', '\'Escape\'');
118 eventSender
.keyDown('F1');
119 shouldEvaluateTo('lastKeyboardDownEvent.code', '\'F1\'');
120 eventSender
.keyDown('F6');
121 shouldEvaluateTo('lastKeyboardDownEvent.code', '\'F6\'');
122 eventSender
.keyDown('F12');
123 shouldEvaluateTo('lastKeyboardDownEvent.code', '\'F12\'');
124 eventSender
.keyDown('printScreen');
125 shouldEvaluateTo('lastKeyboardDownEvent.code', '\'PrintScreen\'');
126 shouldEvaluateTo('lastKeyboardUpEvent.code', '\'PrintScreen\'');