blob: 41a1116837feb3fa1ac74ade2e9d5357dc022f23 [file] [log] [blame]
commit-queue@webkit.org2da5ec82012-05-22 17:45:13 +00001<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2<html>
3<head>
mark.lam@apple.com436bf822013-09-07 23:07:25 +00004<script src="../../resources/js-test-pre.js"></script>
commit-queue@webkit.org2da5ec82012-05-22 17:45:13 +00005</head>
6<body>
7<script>
8description("This tests keyboard events with KeyLocationCode argument.");
9
10var lastKeyboardEvent;
11var VK_SHIFT = 16;
12var VK_CONTROL = 17;
13var VK_MENU = 18;
commit-queue@webkit.org2da5ec82012-05-22 17:45:13 +000014
15function recordKeyEvent(ev) {
16 ev = ev || event;
17 ev.keyCode = (ev.which || ev.keyCode);
18 if (window.eventSender) {
19 lastKeyboardEvent = ev;
20 } else {
21 debug('Type=' + ev.type + ',' +
22 'keyCode=' + ev.keyCode + ',' +
23 'ctrlKey=' + ev.ctrlKey + ',' +
24 'shiftKey=' + ev.shiftKey + ',' +
25 'altKey=' + ev.altKey + ',' +
26 'metaKey=' + ev.metaKey + ',' +
ch.dumez@sisa.samsung.comb3d683a2013-08-09 18:56:16 +000027 'location=' + ev.location);
commit-queue@webkit.org2da5ec82012-05-22 17:45:13 +000028 }
29}
30
31function testKeyEventWithLocation(evString, expectedKeyCode, expectedLocation) {
32 eventSender.keyDown(evString, []);
33 shouldBe("lastKeyboardEvent.type", '"keydown"');
34 shouldEvaluateTo("lastKeyboardEvent.keyCode", expectedKeyCode);
ch.dumez@sisa.samsung.comb3d683a2013-08-09 18:56:16 +000035 shouldEvaluateTo("lastKeyboardEvent.location", expectedLocation);
commit-queue@webkit.org2da5ec82012-05-22 17:45:13 +000036}
37
38var textarea = document.createElement("textarea");
39textarea.addEventListener("keydown", recordKeyEvent, false);
40document.body.insertBefore(textarea, document.body.firstChild);
41textarea.focus();
42
43if (window.eventSender) {
44 // location=0 indicates that we send events as standard keys.
ch.dumez@sisa.samsung.com25c754f2013-08-12 19:47:09 +000045 testKeyEventWithLocation("leftShift", VK_SHIFT, "KeyboardEvent.DOM_KEY_LOCATION_LEFT");
46 testKeyEventWithLocation("leftControl", VK_CONTROL, "KeyboardEvent.DOM_KEY_LOCATION_LEFT");
47 testKeyEventWithLocation("leftAlt", VK_MENU, "KeyboardEvent.DOM_KEY_LOCATION_LEFT");
commit-queue@webkit.org2da5ec82012-05-22 17:45:13 +000048
ch.dumez@sisa.samsung.com25c754f2013-08-12 19:47:09 +000049 testKeyEventWithLocation("rightShift", VK_SHIFT, "KeyboardEvent.DOM_KEY_LOCATION_RIGHT");
50 testKeyEventWithLocation("rightControl", VK_CONTROL, "KeyboardEvent.DOM_KEY_LOCATION_RIGHT");
51 testKeyEventWithLocation("rightAlt", VK_MENU, "KeyboardEvent.DOM_KEY_LOCATION_RIGHT");
commit-queue@webkit.org2da5ec82012-05-22 17:45:13 +000052} else {
53 debug("This test requires DumpRenderTree.");
54}
55</script>
mark.lam@apple.com436bf822013-09-07 23:07:25 +000056<script src="../../resources/js-test-post.js"></script>
commit-queue@webkit.org2da5ec82012-05-22 17:45:13 +000057</body>
58</html>