OLD | NEW |
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> | 1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <script src="../js/resources/js-test-pre.js"></script> | 4 <script src="../js/resources/js-test-pre.js"></script> |
5 </head> | 5 </head> |
6 <body> | 6 <body> |
7 <script> | 7 <script> |
8 description("This tests keyboard events with KeyLocationCode argument."); | 8 description("This tests keyboard events with KeyLocationCode argument."); |
9 | 9 |
10 var lastKeyboardEvent; | 10 var lastKeyboardEvent; |
11 var VK_SHIFT = 16; | 11 var VK_SHIFT = 16; |
12 var VK_CONTROL = 17; | 12 var VK_CONTROL = 17; |
13 var VK_MENU = 18; | 13 var VK_MENU = 18; |
14 var KEY_LOCATION_LEFT = 1; | 14 var KEY_LOCATION_LEFT = 1; |
15 var KEY_LOCATION_RIGHT = 2; | 15 var KEY_LOCATION_RIGHT = 2; |
16 | 16 |
17 function recordKeyEvent(ev) { | 17 function recordKeyEvent(ev) { |
18 ev = ev || event; | 18 ev = ev || event; |
19 ev.keyCode = (ev.which || ev.keyCode); | 19 ev.keyCode = (ev.which || ev.keyCode); |
20 if (window.eventSender) { | 20 if (window.eventSender) { |
21 lastKeyboardEvent = ev; | 21 lastKeyboardEvent = ev; |
22 } else { | 22 } else { |
23 debug('Type=' + ev.type + ',' + | 23 debug('Type=' + ev.type + ',' + |
24 'keyCode=' + ev.keyCode + ',' + | 24 'keyCode=' + ev.keyCode + ',' + |
25 'ctrlKey=' + ev.ctrlKey + ',' + | 25 'ctrlKey=' + ev.ctrlKey + ',' + |
26 'shiftKey=' + ev.shiftKey + ',' + | 26 'shiftKey=' + ev.shiftKey + ',' + |
27 'altKey=' + ev.altKey + ',' + | 27 'altKey=' + ev.altKey + ',' + |
28 'metaKey=' + ev.metaKey + ',' + | 28 'metaKey=' + ev.metaKey + ',' + |
29 'location=' + ev.keyLocation); | 29 'location=' + ev.location); |
30 } | 30 } |
31 } | 31 } |
32 | 32 |
33 function testKeyEventWithLocation(evString, expectedKeyCode, expectedLocation) { | 33 function testKeyEventWithLocation(evString, expectedKeyCode, expectedLocation) { |
34 eventSender.keyDown(evString, []); | 34 eventSender.keyDown(evString, []); |
35 shouldBe("lastKeyboardEvent.type", '"keydown"'); | 35 shouldBe("lastKeyboardEvent.type", '"keydown"'); |
36 shouldEvaluateTo("lastKeyboardEvent.keyCode", expectedKeyCode); | 36 shouldEvaluateTo("lastKeyboardEvent.keyCode", expectedKeyCode); |
37 shouldEvaluateTo("lastKeyboardEvent.keyLocation", expectedLocation); | 37 shouldEvaluateTo("lastKeyboardEvent.location", expectedLocation); |
38 } | 38 } |
39 | 39 |
40 var textarea = document.createElement("textarea"); | 40 var textarea = document.createElement("textarea"); |
41 textarea.addEventListener("keydown", recordKeyEvent, false); | 41 textarea.addEventListener("keydown", recordKeyEvent, false); |
42 document.body.insertBefore(textarea, document.body.firstChild); | 42 document.body.insertBefore(textarea, document.body.firstChild); |
43 textarea.focus(); | 43 textarea.focus(); |
44 | 44 |
45 if (window.eventSender) { | 45 if (window.eventSender) { |
46 // location=0 indicates that we send events as standard keys. | 46 // location=0 indicates that we send events as standard keys. |
47 testKeyEventWithLocation("leftShift", VK_SHIFT, "KEY_LOCATION_LEFT"); | 47 testKeyEventWithLocation("leftShift", VK_SHIFT, "KEY_LOCATION_LEFT"); |
48 testKeyEventWithLocation("leftControl", VK_CONTROL, "KEY_LOCATION_LEFT"); | 48 testKeyEventWithLocation("leftControl", VK_CONTROL, "KEY_LOCATION_LEFT"); |
49 testKeyEventWithLocation("leftAlt", VK_MENU, "KEY_LOCATION_LEFT"); | 49 testKeyEventWithLocation("leftAlt", VK_MENU, "KEY_LOCATION_LEFT"); |
50 | 50 |
51 testKeyEventWithLocation("rightShift", VK_SHIFT, "KEY_LOCATION_RIGHT"); | 51 testKeyEventWithLocation("rightShift", VK_SHIFT, "KEY_LOCATION_RIGHT"); |
52 testKeyEventWithLocation("rightControl", VK_CONTROL, "KEY_LOCATION_RIGHT"); | 52 testKeyEventWithLocation("rightControl", VK_CONTROL, "KEY_LOCATION_RIGHT"); |
53 testKeyEventWithLocation("rightAlt", VK_MENU, "KEY_LOCATION_RIGHT"); | 53 testKeyEventWithLocation("rightAlt", VK_MENU, "KEY_LOCATION_RIGHT"); |
54 } else { | 54 } else { |
55 debug("This test requires DumpRenderTree."); | 55 debug("This test requires DumpRenderTree."); |
56 } | 56 } |
57 </script> | 57 </script> |
58 <script src="../js/resources/js-test-post.js"></script> | 58 <script src="../js/resources/js-test-post.js"></script> |
59 </body> | 59 </body> |
60 </html> | 60 </html> |
OLD | NEW |