Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / events / keyboardevent-getModifierState.html
blob6d30c89a54194e3556d7e35874b51c54da03a38d
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <link rel="help" href="http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardEvent-getModifierState" />
5 <script src="../../resources/js-test.js"></script>
6 </head>
7 <body>
8 <script>
9 description("Tests KeyboardEvent.getModifierState()");
11 var lastKeyboardEvent;
13 function recordKeyEvent(ev) {
14 ev = ev || event;
15 ev.keyCode = (ev.which || ev.keyCode);
16 if (window.eventSender) {
17 lastKeyboardEvent = ev;
18 } else {
19 debug("Type=" + ev.type + "," +
20 "keyCode=" + ev.keyCode + ',' +
21 "ctrlKey=" + ev.getModifierState("Control") + "," +
22 "shiftKey=" + ev.getModifierState("Shift") + "," +
23 "altKey=" + ev.getModifierState("Alt") + "," +
24 "metaKey=" + ev.getModifierState("Meta"));
28 var allEventModifiers = ["ctrlKey", "shiftKey", "metaKey", "altKey"];
29 var allKeyModifiers = ["Control", "Shift", "Meta", "Alt"];
31 function testKeyEventWithModifiers(evString, eventModifiers, expectedKeyCode) {
32 eventSender.keyDown(evString, eventModifiers);
33 shouldBe("lastKeyboardEvent.type", '"keydown"');
34 shouldEvaluateTo("lastKeyboardEvent.keyCode", expectedKeyCode);
35 for (var i = 0; i < allEventModifiers.length; ++i) {
36 var expectedModifierState = eventModifiers.indexOf(allEventModifiers[i]) >= 0;
37 shouldEvaluateTo("lastKeyboardEvent.getModifierState('" + allKeyModifiers[i] + "')", expectedModifierState);
38 shouldEvaluateTo("lastKeyboardEvent." + allEventModifiers[i], expectedModifierState);
42 var textarea = document.createElement("textarea");
43 textarea.addEventListener("keydown", recordKeyEvent, false);
44 document.body.insertBefore(textarea, document.body.firstChild);
45 textarea.focus();
47 if (window.eventSender) {
48 testKeyEventWithModifiers("pageUp", ["ctrlKey"], 33);
49 testKeyEventWithModifiers("pageDown", ["shiftKey"], 34);
50 testKeyEventWithModifiers("home", ["altKey"], 36);
51 testKeyEventWithModifiers("end", ["metaKey"], 35);
52 testKeyEventWithModifiers("leftArrow", ["ctrlKey", "shiftKey"], 37);
53 testKeyEventWithModifiers("rightArrow", ["ctrlKey", "shiftKey", "altKey"], 39);
54 testKeyEventWithModifiers("upArrow", ["ctrlKey", "shiftKey", "altKey", "metaKey"], 38);
55 } else {
56 debug("This test requires DumpRenderTree. To manually test, 1) focus on the textarea above and press keys while holding modifiers 2) see if the ctrlKey/shiftKey/altKey/metaKey= values are correctly reported.");
58 </script>
59 </body>
60 </html>