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

Unified 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, 5 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 side-by-side diff with in-line comments
Download patch
Index: LayoutTests/fast/events/keyboardevent-getModifierState.html
diff --git a/LayoutTests/fast/events/keyboardevent-getModifierState.html b/LayoutTests/fast/events/keyboardevent-getModifierState.html
new file mode 100644
index 0000000000000000000000000000000000000000..3e80590047bee8364c9ae1a1c7804baf0b3e1c15
--- /dev/null
+++ b/LayoutTests/fast/events/keyboardevent-getModifierState.html
@@ -0,0 +1,61 @@
+<!DOCTYPE html>
+<html>
+<head>
+<link rel="help" href="http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardEvent-getModifierState" />
+<script src="../js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<script>
+description("Tests KeyboardEvent.getModifierState()");
+
+var lastKeyboardEvent;
+
+function recordKeyEvent(ev) {
+ ev = ev || event;
arv (Not doing code reviews) 2013/07/31 16:22:54 why? event is not defined (unless you count the d
+ 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
+ if (window.eventSender) {
+ lastKeyboardEvent = ev;
+ } else {
+ debug("Type=" + ev.type + "," +
+ "keyCode=" + ev.keyCode + ',' +
+ "ctrlKey=" + ev.getModifierState("Control") + "," +
+ "shiftKey=" + ev.getModifierState("Shift") + "," +
+ "altKey=" + ev.getModifierState("Alt") + "," +
+ "metaKey=" + ev.getModifierState("Meta"));
+ }
+}
+
+var allEventModifiers = ["ctrlKey", "shiftKey", "metaKey", "altKey"];
+var allKeyModifiers = ["Control", "Shift", "Meta", "Alt"];
+
+function testKeyEventWithModifiers(evString, eventModifiers, expectedKeyCode) {
+ eventSender.keyDown(evString, eventModifiers);
+ shouldBe("lastKeyboardEvent.type", '"keydown"');
+ shouldEvaluateTo("lastKeyboardEvent.keyCode", expectedKeyCode);
+ for (var i = 0; i < allEventModifiers.length; ++i) {
+ var expectedModifierState = eventModifiers.indexOf(allEventModifiers[i]) >= 0;
+ shouldEvaluateTo("lastKeyboardEvent.getModifierState('" + allKeyModifiers[i] + "')", expectedModifierState);
+ shouldEvaluateTo("lastKeyboardEvent." + allEventModifiers[i], expectedModifierState);
+ }
+}
+
+var textarea = document.createElement("textarea");
+textarea.addEventListener("keydown", recordKeyEvent, false);
+document.body.insertBefore(textarea, document.body.firstChild);
+textarea.focus();
+
+if (window.eventSender) {
+ testKeyEventWithModifiers("pageUp", ["ctrlKey"], 33);
+ testKeyEventWithModifiers("pageDown", ["shiftKey"], 34);
+ testKeyEventWithModifiers("home", ["altKey"], 36);
+ testKeyEventWithModifiers("end", ["metaKey"], 35);
+ testKeyEventWithModifiers("leftArrow", ["ctrlKey", "shiftKey"], 37);
+ testKeyEventWithModifiers("rightArrow", ["ctrlKey", "shiftKey", "altKey"], 39);
+ testKeyEventWithModifiers("upArrow", ["ctrlKey", "shiftKey", "altKey", "metaKey"], 38);
+} else {
+ 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.");
+}
+</script>
+<script src="../js/resources/js-test-post.js"></script>
+</body>
+</html>
« 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