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

Side by Side Diff: chrome/browser/chromeos/events/event_rewriter_unittest.cc

Issue 399443004: Maintain Diamond (F15) modifier state when rewriting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments (derat). Created 6 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/chromeos/events/event_rewriter.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/events/event_rewriter.h" 5 #include "chrome/browser/chromeos/events/event_rewriter.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/sticky_keys/sticky_keys_controller.h" 10 #include "ash/sticky_keys/sticky_keys_controller.h"
(...skipping 1009 matching lines...) Expand 10 before | Expand all | Expand 10 after
1020 rewriter.set_ime_keyboard_for_testing(&ime_keyboard); 1020 rewriter.set_ime_keyboard_for_testing(&ime_keyboard);
1021 1021
1022 KeyTestCase tests[] = { 1022 KeyTestCase tests[] = {
1023 // F15 should work as Ctrl when --has-chromeos-diamond-key is not 1023 // F15 should work as Ctrl when --has-chromeos-diamond-key is not
1024 // specified. 1024 // specified.
1025 {KeyTestCase::TEST_VKEY, 1025 {KeyTestCase::TEST_VKEY,
1026 ui::ET_KEY_PRESSED, 1026 ui::ET_KEY_PRESSED,
1027 {ui::VKEY_F15, ui::EF_NONE}, 1027 {ui::VKEY_F15, ui::EF_NONE},
1028 {ui::VKEY_CONTROL, ui::EF_CONTROL_DOWN}}, 1028 {ui::VKEY_CONTROL, ui::EF_CONTROL_DOWN}},
1029 1029
1030 {KeyTestCase::TEST_VKEY,
1031 ui::ET_KEY_RELEASED,
1032 {ui::VKEY_F15, ui::EF_NONE},
1033 {ui::VKEY_CONTROL, ui::EF_NONE}},
1034
1030 // However, Mod2Mask should not be rewritten to CtrlMask when 1035 // However, Mod2Mask should not be rewritten to CtrlMask when
1031 // --has-chromeos-diamond-key is not specified. 1036 // --has-chromeos-diamond-key is not specified.
1032 {KeyTestCase::TEST_VKEY, 1037 {KeyTestCase::TEST_VKEY,
1033 ui::ET_KEY_PRESSED, 1038 ui::ET_KEY_PRESSED,
1034 {ui::VKEY_A, ui::EF_NONE}, 1039 {ui::VKEY_A, ui::EF_NONE},
1035 {ui::VKEY_A, ui::EF_NONE}}, 1040 {ui::VKEY_A, ui::EF_NONE}},
1036 }; 1041 };
1037 1042
1038 for (size_t i = 0; i < arraysize(tests); ++i) { 1043 for (size_t i = 0; i < arraysize(tests); ++i) {
1039 SCOPED_TRACE(i); 1044 SCOPED_TRACE(i);
(...skipping 13 matching lines...) Expand all
1053 EventRewriter rewriter(NULL); 1058 EventRewriter rewriter(NULL);
1054 rewriter.KeyboardDeviceAddedForTesting(kKeyboardDeviceId, "PC Keyboard"); 1059 rewriter.KeyboardDeviceAddedForTesting(kKeyboardDeviceId, "PC Keyboard");
1055 rewriter.set_pref_service_for_testing(&prefs); 1060 rewriter.set_pref_service_for_testing(&prefs);
1056 rewriter.set_ime_keyboard_for_testing(&ime_keyboard); 1061 rewriter.set_ime_keyboard_for_testing(&ime_keyboard);
1057 1062
1058 // By default, F15 should work as Control. 1063 // By default, F15 should work as Control.
1059 EXPECT_EQ(GetExpectedResultAsString( 1064 EXPECT_EQ(GetExpectedResultAsString(
1060 ui::VKEY_CONTROL, ui::EF_CONTROL_DOWN, ui::ET_KEY_PRESSED), 1065 ui::VKEY_CONTROL, ui::EF_CONTROL_DOWN, ui::ET_KEY_PRESSED),
1061 GetRewrittenEventAsString( 1066 GetRewrittenEventAsString(
1062 &rewriter, ui::VKEY_F15, ui::EF_NONE, ui::ET_KEY_PRESSED)); 1067 &rewriter, ui::VKEY_F15, ui::EF_NONE, ui::ET_KEY_PRESSED));
1068 // Check that Control is applied to a subsequent key press.
1069 EXPECT_EQ(GetExpectedResultAsString(
1070 ui::VKEY_A, ui::EF_CONTROL_DOWN, ui::ET_KEY_PRESSED),
1071 GetRewrittenEventAsString(
1072 &rewriter, ui::VKEY_A, ui::EF_NONE, ui::ET_KEY_PRESSED));
1073 // Release F15
1074 EXPECT_EQ(GetExpectedResultAsString(
1075 ui::VKEY_CONTROL, ui::EF_NONE, ui::ET_KEY_RELEASED),
1076 GetRewrittenEventAsString(
1077 &rewriter, ui::VKEY_F15, ui::EF_NONE, ui::ET_KEY_RELEASED));
1078 // Check that Control is no longer applied to a subsequent key press.
1079 EXPECT_EQ(
1080 GetExpectedResultAsString(ui::VKEY_A, ui::EF_NONE, ui::ET_KEY_PRESSED),
1081 GetRewrittenEventAsString(
1082 &rewriter, ui::VKEY_A, ui::EF_NONE, ui::ET_KEY_PRESSED));
1063 1083
1064 IntegerPrefMember diamond; 1084 IntegerPrefMember diamond;
1065 diamond.Init(prefs::kLanguageRemapDiamondKeyTo, &prefs); 1085 diamond.Init(prefs::kLanguageRemapDiamondKeyTo, &prefs);
1066 diamond.SetValue(chromeos::input_method::kVoidKey); 1086 diamond.SetValue(chromeos::input_method::kVoidKey);
1067 1087
1068 EXPECT_EQ(GetExpectedResultAsString( 1088 EXPECT_EQ(GetExpectedResultAsString(
1069 ui::VKEY_UNKNOWN, ui::EF_NONE, ui::ET_KEY_PRESSED), 1089 ui::VKEY_UNKNOWN, ui::EF_NONE, ui::ET_KEY_PRESSED),
1070 GetRewrittenEventAsString( 1090 GetRewrittenEventAsString(
1071 &rewriter, ui::VKEY_F15, ui::EF_NONE, ui::ET_KEY_PRESSED)); 1091 &rewriter, ui::VKEY_F15, ui::EF_NONE, ui::ET_KEY_PRESSED));
1092 // Check that no modifier is applied to another key.
1093 EXPECT_EQ(
1094 GetExpectedResultAsString(ui::VKEY_A, ui::EF_NONE, ui::ET_KEY_PRESSED),
1095 GetRewrittenEventAsString(
1096 &rewriter, ui::VKEY_A, ui::EF_NONE, ui::ET_KEY_PRESSED));
1072 1097
1073 diamond.SetValue(chromeos::input_method::kControlKey); 1098 diamond.SetValue(chromeos::input_method::kControlKey);
1074 1099
1075 EXPECT_EQ(GetExpectedResultAsString( 1100 EXPECT_EQ(GetExpectedResultAsString(
1076 ui::VKEY_CONTROL, ui::EF_CONTROL_DOWN, ui::ET_KEY_PRESSED), 1101 ui::VKEY_CONTROL, ui::EF_CONTROL_DOWN, ui::ET_KEY_PRESSED),
1077 GetRewrittenEventAsString( 1102 GetRewrittenEventAsString(
1078 &rewriter, ui::VKEY_F15, ui::EF_NONE, ui::ET_KEY_PRESSED)); 1103 &rewriter, ui::VKEY_F15, ui::EF_NONE, ui::ET_KEY_PRESSED));
1104 // Check that Control is applied to a subsequent key press.
1105 EXPECT_EQ(GetExpectedResultAsString(
1106 ui::VKEY_A, ui::EF_CONTROL_DOWN, ui::ET_KEY_PRESSED),
1107 GetRewrittenEventAsString(
1108 &rewriter, ui::VKEY_A, ui::EF_NONE, ui::ET_KEY_PRESSED));
1109 // Release F15
1110 EXPECT_EQ(GetExpectedResultAsString(
1111 ui::VKEY_CONTROL, ui::EF_NONE, ui::ET_KEY_RELEASED),
1112 GetRewrittenEventAsString(
1113 &rewriter, ui::VKEY_F15, ui::EF_NONE, ui::ET_KEY_RELEASED));
1114 // Check that Control is no longer applied to a subsequent key press.
1115 EXPECT_EQ(
1116 GetExpectedResultAsString(ui::VKEY_A, ui::EF_NONE, ui::ET_KEY_PRESSED),
1117 GetRewrittenEventAsString(
1118 &rewriter, ui::VKEY_A, ui::EF_NONE, ui::ET_KEY_PRESSED));
1079 1119
1080 diamond.SetValue(chromeos::input_method::kAltKey); 1120 diamond.SetValue(chromeos::input_method::kAltKey);
1081 1121
1082 EXPECT_EQ(GetExpectedResultAsString( 1122 EXPECT_EQ(GetExpectedResultAsString(
1083 ui::VKEY_MENU, ui::EF_ALT_DOWN, ui::ET_KEY_PRESSED), 1123 ui::VKEY_MENU, ui::EF_ALT_DOWN, ui::ET_KEY_PRESSED),
1084 GetRewrittenEventAsString( 1124 GetRewrittenEventAsString(
1085 &rewriter, ui::VKEY_F15, ui::EF_NONE, ui::ET_KEY_PRESSED)); 1125 &rewriter, ui::VKEY_F15, ui::EF_NONE, ui::ET_KEY_PRESSED));
1126 // Check that Alt is applied to a subsequent key press.
1127 EXPECT_EQ(GetExpectedResultAsString(
1128 ui::VKEY_A, ui::EF_ALT_DOWN, ui::ET_KEY_PRESSED),
1129 GetRewrittenEventAsString(
1130 &rewriter, ui::VKEY_A, ui::EF_NONE, ui::ET_KEY_PRESSED));
1131 // Release F15
1132 EXPECT_EQ(GetExpectedResultAsString(
1133 ui::VKEY_MENU, ui::EF_NONE, ui::ET_KEY_RELEASED),
1134 GetRewrittenEventAsString(
1135 &rewriter, ui::VKEY_F15, ui::EF_NONE, ui::ET_KEY_RELEASED));
1136 // Check that Alt is no longer applied to a subsequent key press.
1137 EXPECT_EQ(
1138 GetExpectedResultAsString(ui::VKEY_A, ui::EF_NONE, ui::ET_KEY_PRESSED),
1139 GetRewrittenEventAsString(
1140 &rewriter, ui::VKEY_A, ui::EF_NONE, ui::ET_KEY_PRESSED));
1086 1141
1087 diamond.SetValue(chromeos::input_method::kCapsLockKey); 1142 diamond.SetValue(chromeos::input_method::kCapsLockKey);
1088 1143
1089 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CAPITAL, 1144 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CAPITAL,
1090 ui::EF_CAPS_LOCK_DOWN | ui::EF_MOD3_DOWN, 1145 ui::EF_CAPS_LOCK_DOWN | ui::EF_MOD3_DOWN,
1091 ui::ET_KEY_PRESSED), 1146 ui::ET_KEY_PRESSED),
1092 GetRewrittenEventAsString( 1147 GetRewrittenEventAsString(
1093 &rewriter, ui::VKEY_F15, ui::EF_NONE, ui::ET_KEY_PRESSED)); 1148 &rewriter, ui::VKEY_F15, ui::EF_NONE, ui::ET_KEY_PRESSED));
1149 // Check that Caps is applied to a subsequent key press.
1150 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_A,
1151 ui::EF_CAPS_LOCK_DOWN | ui::EF_MOD3_DOWN,
1152 ui::ET_KEY_PRESSED),
1153 GetRewrittenEventAsString(
1154 &rewriter, ui::VKEY_A, ui::EF_NONE, ui::ET_KEY_PRESSED));
1155 // Release F15
1156 EXPECT_EQ(GetExpectedResultAsString(
1157 ui::VKEY_CAPITAL, ui::EF_NONE, ui::ET_KEY_RELEASED),
1158 GetRewrittenEventAsString(
1159 &rewriter, ui::VKEY_F15, ui::EF_NONE, ui::ET_KEY_RELEASED));
1160 // Check that Control is no longer applied to a subsequent key press.
1161 EXPECT_EQ(
1162 GetExpectedResultAsString(ui::VKEY_A, ui::EF_NONE, ui::ET_KEY_PRESSED),
1163 GetRewrittenEventAsString(
1164 &rewriter, ui::VKEY_A, ui::EF_NONE, ui::ET_KEY_PRESSED));
1094 1165
1095 *CommandLine::ForCurrentProcess() = original_cl; 1166 *CommandLine::ForCurrentProcess() = original_cl;
1096 } 1167 }
1097 1168
1098 TEST_F(EventRewriterTest, TestRewriteCapsLockToControl) { 1169 TEST_F(EventRewriterTest, TestRewriteCapsLockToControl) {
1099 // Remap CapsLock to Control. 1170 // Remap CapsLock to Control.
1100 TestingPrefServiceSyncable prefs; 1171 TestingPrefServiceSyncable prefs;
1101 chromeos::Preferences::RegisterProfilePrefs(prefs.registry()); 1172 chromeos::Preferences::RegisterProfilePrefs(prefs.registry());
1102 IntegerPrefMember control; 1173 IntegerPrefMember control;
1103 control.Init(prefs::kLanguageRemapCapsLockKeyTo, &prefs); 1174 control.Init(prefs::kLanguageRemapCapsLockKeyTo, &prefs);
(...skipping 1287 matching lines...) Expand 10 before | Expand all | Expand 10 after
2391 EXPECT_FALSE(overlay_->GetModifierVisible(ui::EF_ALTGR_DOWN)); 2462 EXPECT_FALSE(overlay_->GetModifierVisible(ui::EF_ALTGR_DOWN));
2392 EXPECT_TRUE(overlay_->GetModifierVisible(ui::EF_MOD3_DOWN)); 2463 EXPECT_TRUE(overlay_->GetModifierVisible(ui::EF_MOD3_DOWN));
2393 2464
2394 // Turn off AltGr and Mod3. 2465 // Turn off AltGr and Mod3.
2395 sticky_keys_controller_->SetModifiersEnabled(false, false); 2466 sticky_keys_controller_->SetModifiersEnabled(false, false);
2396 EXPECT_FALSE(overlay_->GetModifierVisible(ui::EF_ALTGR_DOWN)); 2467 EXPECT_FALSE(overlay_->GetModifierVisible(ui::EF_ALTGR_DOWN));
2397 EXPECT_FALSE(overlay_->GetModifierVisible(ui::EF_MOD3_DOWN)); 2468 EXPECT_FALSE(overlay_->GetModifierVisible(ui::EF_MOD3_DOWN));
2398 } 2469 }
2399 2470
2400 } // namespace chromeos 2471 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/events/event_rewriter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698