Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(484)

Side by Side Diff: LayoutTests/fast/events/keyboardevent-getModifierState.html

Issue 21030004: Add support for KeyboardEvent.getModifierState() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase on master Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <link rel="help" href="http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardE vent-getModifierState" />
5 <script src="../js/resources/js-test-pre.js"></script>
6 </head>
7 <body>
8 <script>
9 description("Tests KeyboardEvent.getModifierState()");
10
11 var lastKeyboardEvent;
12
13 function recordKeyEvent(ev) {
14 ev = ev || event;
arv (Not doing code reviews) 2013/07/31 16:22:54 why? event is not defined (unless you count the d
15 ev.keyCode = (ev.which || ev.keyCode);
arv (Not doing code reviews) 2013/07/31 16:22:54 This looks bad. Why are we assigning keyCode to `w
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"));
25 }
26 }
27
28 var allEventModifiers = ["ctrlKey", "shiftKey", "metaKey", "altKey"];
29 var allKeyModifiers = ["Control", "Shift", "Meta", "Alt"];
30
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('" + allKeyModifier s[i] + "')", expectedModifierState);
38 shouldEvaluateTo("lastKeyboardEvent." + allEventModifiers[i], expectedMo difierState);
39 }
40 }
41
42 var textarea = document.createElement("textarea");
43 textarea.addEventListener("keydown", recordKeyEvent, false);
44 document.body.insertBefore(textarea, document.body.firstChild);
45 textarea.focus();
46
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"], 3 9);
54 testKeyEventWithModifiers("upArrow", ["ctrlKey", "shiftKey", "altKey", "meta Key"], 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/shi ftKey/altKey/metaKey= values are correctly reported.");
57 }
58 </script>
59 <script src="../js/resources/js-test-post.js"></script>
60 </body>
61 </html>
OLDNEW
« no previous file with comments | « no previous file | LayoutTests/fast/events/keyboardevent-getModifierState-expected.txt » ('j') | Source/core/dom/KeyboardEvent.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698