OLD | NEW |
---|---|
(Empty) | |
1 <!DOCTYPE html> | |
2 <link rel="help" href="http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardE vent-key" /> | |
3 <script src="../../resources/js-test.js"></script>- | |
4 <textarea id="textarea"></textarea> | |
5 <script> | |
6 description('Tests KeyboardEvent.key 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); | |
11 textarea.focus(); | |
12 | |
13 var lastKeyboardDownEvent, lastKeyboardPressEvent, lastKeyboardUpEvent; | |
14 | |
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; | |
Wez
2015/05/06 01:32:13
You never test against lastKeyboardPressEvent, so
| |
23 } else { | |
24 debug('Type=' + ev.type + ',' + 'key=' + ev.key); | |
25 } | |
26 } | |
27 | |
28 if (window.eventSender) { | |
29 debug('Modifier Keys'); | |
30 eventSender.keyDown('leftControl'); | |
31 shouldEvaluateTo('lastKeyboardUpEvent.key', '\'Control\''); | |
Wez
2015/05/06 01:32:13
Why are you testing the last keyup here, but the l
| |
32 eventSender.keyDown('rightControl'); | |
33 shouldEvaluateTo('lastKeyboardDownEvent.key', '\'Control\''); | |
34 eventSender.keyDown('leftShift'); | |
35 shouldEvaluateTo('lastKeyboardDownEvent.key', '\'Shift\''); | |
36 eventSender.keyDown('rightShift'); | |
37 shouldEvaluateTo('lastKeyboardDownEvent.key', '\'Shift\''); | |
38 eventSender.keyDown('leftAlt'); | |
39 shouldEvaluateTo('lastKeyboardDownEvent.key', '\'Alt\''); | |
40 eventSender.keyDown('rightAlt'); | |
41 shouldEvaluateTo('lastKeyboardDownEvent.key', '\'AltGraph\''); | |
Wez
2015/05/06 01:32:13
The left Alt key should only generate AltGraph und
| |
42 eventSender.keyDown('numLock'); | |
43 shouldEvaluateTo('lastKeyboardDownEvent.key', '\'NumLock\''); | |
44 shouldEvaluateTo('lastKeyboardUpEvent.key', '\'NumLock\''); | |
45 | |
46 debug('Whitespace Keys'); | |
47 eventSender.keyDown('\n'); | |
48 shouldEvaluateTo('lastKeyboardDownEvent.key', '\'Enter\''); | |
49 eventSender.keyDown('\t'); | |
50 shouldEvaluateTo('lastKeyboardDownEvent.key', '\'Tab\''); | |
51 shouldEvaluateTo('lastKeyboardUpEvent.key', '\'Tab\''); | |
52 | |
53 debug('Navigation keys'); | |
54 eventSender.keyDown('rightArrow'); | |
55 shouldEvaluateTo('lastKeyboardDownEvent.key', '\'ArrowRight\''); | |
56 shouldEvaluateTo('lastKeyboardUpEvent.key', '\'ArrowRight\''); | |
57 eventSender.keyDown('downArrow'); | |
58 shouldEvaluateTo('lastKeyboardDownEvent.key', '\'ArrowDown\''); | |
59 eventSender.keyDown('leftArrow'); | |
60 shouldEvaluateTo('lastKeyboardDownEvent.key', '\'ArrowLeft\''); | |
61 eventSender.keyDown('upArrow'); | |
62 shouldEvaluateTo('lastKeyboardDownEvent.key', '\'ArrowUp\''); | |
63 shouldEvaluateTo('lastKeyboardUpEvent.key', '\'ArrowUp\''); | |
64 eventSender.keyDown('home'); | |
65 shouldEvaluateTo('lastKeyboardDownEvent.key', '\'Home\''); | |
66 eventSender.keyDown('end'); | |
67 shouldEvaluateTo('lastKeyboardDownEvent.key', '\'End\''); | |
68 eventSender.keyDown('pageUp'); | |
69 shouldEvaluateTo('lastKeyboardDownEvent.key', '\'PageUp\''); | |
70 eventSender.keyDown('pageDown'); | |
71 shouldEvaluateTo('lastKeyboardDownEvent.key', '\'PageDown\''); | |
72 shouldEvaluateTo('lastKeyboardUpEvent.key', '\'PageDown\''); | |
73 | |
74 debug('Editing Keys'); | |
75 eventSender.keyDown('backspace'); | |
76 shouldEvaluateTo('lastKeyboardDownEvent.code', '\'Backspace\''); | |
77 eventSender.keyDown('insert'); | |
78 shouldEvaluateTo('lastKeyboardDownEvent.key', '\'Insert\''); | |
79 shouldEvaluateTo('lastKeyboardUpEvent.key', '\'Insert\''); | |
80 eventSender.keyDown('delete'); | |
81 shouldEvaluateTo('lastKeyboardDownEvent.key', '\'Delete\''); | |
82 | |
83 debug('Device Keys'); | |
84 eventSender.keyDown('printScreen'); | |
85 shouldEvaluateTo('lastKeyboardDownEvent.key', '\'PrintScreen\''); | |
86 shouldEvaluateTo('lastKeyboardUpEvent.key', '\'PrintScreen\''); | |
87 | |
88 debug('General Purpose Function Section'); | |
89 eventSender.keyDown('F1'); | |
90 shouldEvaluateTo('lastKeyboardDownEvent.key', '\'F1\''); | |
91 eventSender.keyDown('F6'); | |
92 shouldEvaluateTo('lastKeyboardDownEvent.key', '\'F6\''); | |
93 eventSender.keyDown('F12'); | |
94 shouldEvaluateTo('lastKeyboardDownEvent.key', '\'F12\''); | |
95 | |
96 debug('UI Keys'); | |
97 eventSender.keyDown('escape'); | |
98 shouldEvaluateTo('lastKeyboardDownEvent.key', '\'Escape\''); | |
99 shouldEvaluateTo('lastKeyboardUpEvent.key', '\'Escape\''); | |
100 eventSender.keyDown('menu'); | |
101 shouldEvaluateTo('lastKeyboardDownEvent.key', '\'MediaApps\''); | |
102 } | |
103 </script> | |
OLD | NEW |