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

Unified Diff: content/browser/renderer_host/input/web_input_event_builders_mac_unittest.mm

Issue 1706683002: [Mac] Produce correct DomKey when Ctrl/Shift/Command is down (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use std::iscntrl to check control characters instead of writing own method Created 4 years, 10 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
« no previous file with comments | « no previous file | ui/events/keycodes/keyboard_code_conversion_mac.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/renderer_host/input/web_input_event_builders_mac_unittest.mm
diff --git a/content/browser/renderer_host/input/web_input_event_builders_mac_unittest.mm b/content/browser/renderer_host/input/web_input_event_builders_mac_unittest.mm
index 3c8c5a284b5f242daac2a713939359a59015d668..3809e692295c954c983b041e209df3f0c2036197 100644
--- a/content/browser/renderer_host/input/web_input_event_builders_mac_unittest.mm
+++ b/content/browser/renderer_host/input/web_input_event_builders_mac_unittest.mm
@@ -46,11 +46,15 @@ const ModifierKey kModifierKeys[] = {
{62, 1 << 13, NSControlKeyMask}, // Right Control
};
-NSEvent* BuildFakeKeyEvent(NSUInteger key_code,
- unichar character,
- NSUInteger modifier_flags,
- NSEventType event_type) {
+NSEvent* BuildFakeKeyEventWithModifiedCharacter(
+ NSUInteger key_code,
+ unichar character,
+ unichar character_ignoring_modifiers,
+ NSUInteger modifier_flags,
+ NSEventType event_type) {
NSString* string = [NSString stringWithCharacters:&character length:1];
+ NSString* string_ignoring_modifiers =
+ [NSString stringWithCharacters:&character_ignoring_modifiers length:1];
return [NSEvent keyEventWithType:event_type
location:NSZeroPoint
modifierFlags:modifier_flags
@@ -58,11 +62,19 @@ NSEvent* BuildFakeKeyEvent(NSUInteger key_code,
windowNumber:0
context:nil
characters:string
- charactersIgnoringModifiers:string
+ charactersIgnoringModifiers:string_ignoring_modifiers
isARepeat:NO
keyCode:key_code];
}
+NSEvent* BuildFakeKeyEvent(NSUInteger key_code,
+ unichar character,
+ NSUInteger modifier_flags,
+ NSEventType event_type) {
+ return BuildFakeKeyEventWithModifiedCharacter(key_code, character, character,
+ modifier_flags, event_type);
+}
+
} // namespace
// Test that arrow keys don't have numpad modifier set.
@@ -106,13 +118,13 @@ TEST(WebInputEventBuilderMacTest, ArrowKeyNumPad) {
// Test that control sequence generate the correct vkey code.
TEST(WebInputEventBuilderMacTest, ControlSequence) {
// Ctrl-[ generates escape.
- NSEvent* mac_event =
- BuildFakeKeyEvent(0x21, 0x1b, NSControlKeyMask, NSKeyDown);
+ NSEvent* mac_event = BuildFakeKeyEventWithModifiedCharacter(
+ 0x21, 0x1b, '[', NSControlKeyMask, NSKeyDown);
WebKeyboardEvent web_event = WebKeyboardEventBuilder::Build(mac_event);
EXPECT_EQ(ui::VKEY_OEM_4, web_event.windowsKeyCode);
EXPECT_EQ(ui::DomCode::BRACKET_LEFT,
static_cast<ui::DomCode>(web_event.domCode));
- EXPECT_EQ(ui::DomKey::FromCharacter(0x1b), web_event.domKey);
+ EXPECT_EQ(ui::DomKey::FromCharacter('['), web_event.domKey);
}
// Test that numpad keys get mapped correctly.
@@ -246,3 +258,46 @@ TEST(WebInputEventBuilderMacTest, SystemKeyEvents) {
webEvent = WebKeyboardEventBuilder::Build(macEvent);
EXPECT_TRUE(webEvent.isSystemKey);
}
+
+// Test conversion from key combination with Control to DomKey.
+// TODO(chongz): Move DomKey tests for all platforms into one place.
+TEST(WebInputEventBuilderMacTest, DomKeyWithControlKey) {
+ struct DomKeyTestCase {
+ int mac_key_code;
+ unichar character;
+ ui::DomKey dom_key;
+ } table[] = {{kVK_ANSI_A, 'a', ui::DomKey::FromCharacter('a')},
dtapuska 2016/02/17 20:42:35 We likely should add a test case with Shift set.
+ {kVK_ANSI_B, 'b', ui::DomKey::FromCharacter('b')},
+ {kVK_ANSI_C, 'c', ui::DomKey::FromCharacter('c')},
+ {kVK_ANSI_D, 'd', ui::DomKey::FromCharacter('d')},
+ {kVK_ANSI_E, 'e', ui::DomKey::FromCharacter('e')},
+ {kVK_ANSI_F, 'f', ui::DomKey::FromCharacter('f')},
+ {kVK_ANSI_G, 'g', ui::DomKey::FromCharacter('g')},
+ {kVK_ANSI_H, 'h', ui::DomKey::FromCharacter('h')},
+ {kVK_ANSI_I, 'i', ui::DomKey::FromCharacter('i')},
+ {kVK_ANSI_J, 'j', ui::DomKey::FromCharacter('j')},
+ {kVK_ANSI_K, 'k', ui::DomKey::FromCharacter('k')},
+ {kVK_ANSI_L, 'l', ui::DomKey::FromCharacter('l')},
+ {kVK_ANSI_M, 'm', ui::DomKey::FromCharacter('m')},
+ {kVK_ANSI_N, 'n', ui::DomKey::FromCharacter('n')},
+ {kVK_ANSI_O, 'o', ui::DomKey::FromCharacter('o')},
+ {kVK_ANSI_P, 'p', ui::DomKey::FromCharacter('p')},
+ {kVK_ANSI_Q, 'q', ui::DomKey::FromCharacter('q')},
+ {kVK_ANSI_R, 'r', ui::DomKey::FromCharacter('r')},
+ {kVK_ANSI_S, 's', ui::DomKey::FromCharacter('s')},
+ {kVK_ANSI_T, 't', ui::DomKey::FromCharacter('t')},
+ {kVK_ANSI_U, 'u', ui::DomKey::FromCharacter('u')},
+ {kVK_ANSI_V, 'v', ui::DomKey::FromCharacter('v')},
+ {kVK_ANSI_W, 'w', ui::DomKey::FromCharacter('w')},
+ {kVK_ANSI_X, 'x', ui::DomKey::FromCharacter('x')},
+ {kVK_ANSI_Y, 'y', ui::DomKey::FromCharacter('y')},
+ {kVK_ANSI_Z, 'z', ui::DomKey::FromCharacter('z')}};
+
+ for (size_t i = 0; i < arraysize(table); ++i) {
+ NSEvent* mac_event = BuildFakeKeyEventWithModifiedCharacter(
+ table[i].mac_key_code, table[i].character & 0x1F, table[i].character,
+ NSControlKeyMask, NSKeyDown);
+ WebKeyboardEvent web_event = WebKeyboardEventBuilder::Build(mac_event);
+ EXPECT_EQ(table[i].dom_key, web_event.domKey);
+ }
+}
« no previous file with comments | « no previous file | ui/events/keycodes/keyboard_code_conversion_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698