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