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

Side by Side Diff: chrome/browser/ui/ash/event_rewriter_unittest.cc

Issue 11316163: Remove the last usages of PrefObserver outside of Prefs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix build. Created 8 years 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/ash/event_rewriter.h" 5 #include "chrome/browser/ui/ash/event_rewriter.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "chrome/browser/api/prefs/pref_member.h" 10 #include "chrome/browser/api/prefs/pref_member.h"
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 keycode_super_r_, 476 keycode_super_r_,
477 Mod1Mask)); 477 Mod1Mask));
478 } 478 }
479 479
480 // For crbug.com/133896. 480 // For crbug.com/133896.
481 TEST_F(EventRewriterTest, TestRewriteCommandToControlWithControlRemapped) { 481 TEST_F(EventRewriterTest, TestRewriteCommandToControlWithControlRemapped) {
482 // Remap Control to Alt. 482 // Remap Control to Alt.
483 TestingPrefService prefs; 483 TestingPrefService prefs;
484 chromeos::Preferences::RegisterUserPrefs(&prefs); 484 chromeos::Preferences::RegisterUserPrefs(&prefs);
485 IntegerPrefMember control; 485 IntegerPrefMember control;
486 control.Init(prefs::kLanguageRemapControlKeyTo, &prefs, NULL); 486 control.Init(prefs::kLanguageRemapControlKeyTo, &prefs);
487 control.SetValue(chromeos::input_method::kAltKey); 487 control.SetValue(chromeos::input_method::kAltKey);
488 488
489 EventRewriter rewriter; 489 EventRewriter rewriter;
490 rewriter.set_pref_service_for_testing(&prefs); 490 rewriter.set_pref_service_for_testing(&prefs);
491 rewriter.DeviceAddedForTesting(0, "PC Keyboard"); 491 rewriter.DeviceAddedForTesting(0, "PC Keyboard");
492 rewriter.set_last_device_id_for_testing(0); 492 rewriter.set_last_device_id_for_testing(0);
493 493
494 // XK_Control_L (left Control key) should be remapped to Alt. 494 // XK_Control_L (left Control key) should be remapped to Alt.
495 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_MENU, 495 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_MENU,
496 ui::EF_ALT_DOWN, 496 ui::EF_ALT_DOWN,
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 keycode_b_, 1076 keycode_b_,
1077 ShiftMask | ControlMask | Mod1Mask | 1077 ShiftMask | ControlMask | Mod1Mask |
1078 Mod4Mask)); 1078 Mod4Mask));
1079 } 1079 }
1080 1080
1081 TEST_F(EventRewriterTest, TestRewriteModifiersDisableSome) { 1081 TEST_F(EventRewriterTest, TestRewriteModifiersDisableSome) {
1082 // Disable Search and Control keys. 1082 // Disable Search and Control keys.
1083 TestingPrefService prefs; 1083 TestingPrefService prefs;
1084 chromeos::Preferences::RegisterUserPrefs(&prefs); 1084 chromeos::Preferences::RegisterUserPrefs(&prefs);
1085 IntegerPrefMember search; 1085 IntegerPrefMember search;
1086 search.Init(prefs::kLanguageRemapSearchKeyTo, &prefs, NULL); 1086 search.Init(prefs::kLanguageRemapSearchKeyTo, &prefs);
1087 search.SetValue(chromeos::input_method::kVoidKey); 1087 search.SetValue(chromeos::input_method::kVoidKey);
1088 IntegerPrefMember control; 1088 IntegerPrefMember control;
1089 control.Init(prefs::kLanguageRemapControlKeyTo, &prefs, NULL); 1089 control.Init(prefs::kLanguageRemapControlKeyTo, &prefs);
1090 control.SetValue(chromeos::input_method::kVoidKey); 1090 control.SetValue(chromeos::input_method::kVoidKey);
1091 1091
1092 EventRewriter rewriter; 1092 EventRewriter rewriter;
1093 rewriter.set_pref_service_for_testing(&prefs); 1093 rewriter.set_pref_service_for_testing(&prefs);
1094 1094
1095 // Press left Alt with Shift. This key press shouldn't be affected by the 1095 // Press left Alt with Shift. This key press shouldn't be affected by the
1096 // pref. Confirm the event is not rewritten. 1096 // pref. Confirm the event is not rewritten.
1097 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_MENU, 1097 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_MENU,
1098 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN, 1098 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN,
1099 ui::ET_KEY_PRESSED, 1099 ui::ET_KEY_PRESSED,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 KeyPress), 1175 KeyPress),
1176 GetRewrittenEventAsString(&rewriter, 1176 GetRewrittenEventAsString(&rewriter,
1177 ui::VKEY_A, 1177 ui::VKEY_A,
1178 ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, 1178 ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN,
1179 ui::ET_KEY_PRESSED, 1179 ui::ET_KEY_PRESSED,
1180 keycode_a_, 1180 keycode_a_,
1181 ControlMask | Mod1Mask | Mod4Mask)); 1181 ControlMask | Mod1Mask | Mod4Mask));
1182 1182
1183 // Remap Alt to Control. 1183 // Remap Alt to Control.
1184 IntegerPrefMember alt; 1184 IntegerPrefMember alt;
1185 alt.Init(prefs::kLanguageRemapAltKeyTo, &prefs, NULL); 1185 alt.Init(prefs::kLanguageRemapAltKeyTo, &prefs);
1186 alt.SetValue(chromeos::input_method::kControlKey); 1186 alt.SetValue(chromeos::input_method::kControlKey);
1187 1187
1188 // Press left Alt. Confirm the event is now VKEY_CONTROL + XK_Control_L 1188 // Press left Alt. Confirm the event is now VKEY_CONTROL + XK_Control_L
1189 // even though the Control key itself is disabled. 1189 // even though the Control key itself is disabled.
1190 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CONTROL, 1190 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CONTROL,
1191 ui::EF_CONTROL_DOWN, 1191 ui::EF_CONTROL_DOWN,
1192 ui::ET_KEY_PRESSED, 1192 ui::ET_KEY_PRESSED,
1193 keycode_control_l_, 1193 keycode_control_l_,
1194 0U, 1194 0U,
1195 KeyPress), 1195 KeyPress),
(...skipping 18 matching lines...) Expand all
1214 ui::ET_KEY_PRESSED, 1214 ui::ET_KEY_PRESSED,
1215 keycode_a_, 1215 keycode_a_,
1216 Mod1Mask)); 1216 Mod1Mask));
1217 } 1217 }
1218 1218
1219 TEST_F(EventRewriterTest, TestRewriteModifiersRemapToControl) { 1219 TEST_F(EventRewriterTest, TestRewriteModifiersRemapToControl) {
1220 // Remap Search to Control. 1220 // Remap Search to Control.
1221 TestingPrefService prefs; 1221 TestingPrefService prefs;
1222 chromeos::Preferences::RegisterUserPrefs(&prefs); 1222 chromeos::Preferences::RegisterUserPrefs(&prefs);
1223 IntegerPrefMember search; 1223 IntegerPrefMember search;
1224 search.Init(prefs::kLanguageRemapSearchKeyTo, &prefs, NULL); 1224 search.Init(prefs::kLanguageRemapSearchKeyTo, &prefs);
1225 search.SetValue(chromeos::input_method::kControlKey); 1225 search.SetValue(chromeos::input_method::kControlKey);
1226 1226
1227 EventRewriter rewriter; 1227 EventRewriter rewriter;
1228 rewriter.set_pref_service_for_testing(&prefs); 1228 rewriter.set_pref_service_for_testing(&prefs);
1229 1229
1230 // Press Search. Confirm the event is now VKEY_CONTROL + XK_Control_L. 1230 // Press Search. Confirm the event is now VKEY_CONTROL + XK_Control_L.
1231 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CONTROL, 1231 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CONTROL,
1232 ui::EF_CONTROL_DOWN, 1232 ui::EF_CONTROL_DOWN,
1233 ui::ET_KEY_PRESSED, 1233 ui::ET_KEY_PRESSED,
1234 keycode_control_l_, 1234 keycode_control_l_,
1235 0U, 1235 0U,
1236 KeyPress), 1236 KeyPress),
1237 GetRewrittenEventAsString(&rewriter, 1237 GetRewrittenEventAsString(&rewriter,
1238 ui::VKEY_LWIN, 1238 ui::VKEY_LWIN,
1239 0, 1239 0,
1240 ui::ET_KEY_PRESSED, 1240 ui::ET_KEY_PRESSED,
1241 keycode_super_l_, 1241 keycode_super_l_,
1242 0U)); 1242 0U));
1243 1243
1244 // Remap Alt to Control too. 1244 // Remap Alt to Control too.
1245 IntegerPrefMember alt; 1245 IntegerPrefMember alt;
1246 alt.Init(prefs::kLanguageRemapAltKeyTo, &prefs, NULL); 1246 alt.Init(prefs::kLanguageRemapAltKeyTo, &prefs);
1247 alt.SetValue(chromeos::input_method::kControlKey); 1247 alt.SetValue(chromeos::input_method::kControlKey);
1248 1248
1249 // Press left Alt. Confirm the event is now VKEY_CONTROL + XK_Control_L. 1249 // Press left Alt. Confirm the event is now VKEY_CONTROL + XK_Control_L.
1250 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CONTROL, 1250 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CONTROL,
1251 ui::EF_CONTROL_DOWN, 1251 ui::EF_CONTROL_DOWN,
1252 ui::ET_KEY_PRESSED, 1252 ui::ET_KEY_PRESSED,
1253 keycode_control_l_, 1253 keycode_control_l_,
1254 0U, 1254 0U,
1255 KeyPress), 1255 KeyPress),
1256 GetRewrittenEventAsString(&rewriter, 1256 GetRewrittenEventAsString(&rewriter,
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1334 ui::ET_KEY_PRESSED, 1334 ui::ET_KEY_PRESSED,
1335 keycode_b_, 1335 keycode_b_,
1336 ShiftMask | ControlMask | Mod1Mask)); 1336 ShiftMask | ControlMask | Mod1Mask));
1337 } 1337 }
1338 1338
1339 TEST_F(EventRewriterTest, TestRewriteModifiersRemapMany) { 1339 TEST_F(EventRewriterTest, TestRewriteModifiersRemapMany) {
1340 // Remap Search to Alt. 1340 // Remap Search to Alt.
1341 TestingPrefService prefs; 1341 TestingPrefService prefs;
1342 chromeos::Preferences::RegisterUserPrefs(&prefs); 1342 chromeos::Preferences::RegisterUserPrefs(&prefs);
1343 IntegerPrefMember search; 1343 IntegerPrefMember search;
1344 search.Init(prefs::kLanguageRemapSearchKeyTo, &prefs, NULL); 1344 search.Init(prefs::kLanguageRemapSearchKeyTo, &prefs);
1345 search.SetValue(chromeos::input_method::kAltKey); 1345 search.SetValue(chromeos::input_method::kAltKey);
1346 1346
1347 EventRewriter rewriter; 1347 EventRewriter rewriter;
1348 rewriter.set_pref_service_for_testing(&prefs); 1348 rewriter.set_pref_service_for_testing(&prefs);
1349 1349
1350 // Press Search. Confirm the event is now VKEY_MENU + XK_Alt_L. 1350 // Press Search. Confirm the event is now VKEY_MENU + XK_Alt_L.
1351 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_MENU, 1351 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_MENU,
1352 ui::EF_ALT_DOWN, 1352 ui::EF_ALT_DOWN,
1353 ui::ET_KEY_PRESSED, 1353 ui::ET_KEY_PRESSED,
1354 keycode_alt_l_, 1354 keycode_alt_l_,
1355 0U, 1355 0U,
1356 KeyPress), 1356 KeyPress),
1357 GetRewrittenEventAsString(&rewriter, 1357 GetRewrittenEventAsString(&rewriter,
1358 ui::VKEY_LWIN, 1358 ui::VKEY_LWIN,
1359 0, 1359 0,
1360 ui::ET_KEY_PRESSED, 1360 ui::ET_KEY_PRESSED,
1361 keycode_super_l_, 1361 keycode_super_l_,
1362 0U)); 1362 0U));
1363 1363
1364 // Remap Alt to Control. 1364 // Remap Alt to Control.
1365 IntegerPrefMember alt; 1365 IntegerPrefMember alt;
1366 alt.Init(prefs::kLanguageRemapAltKeyTo, &prefs, NULL); 1366 alt.Init(prefs::kLanguageRemapAltKeyTo, &prefs);
1367 alt.SetValue(chromeos::input_method::kControlKey); 1367 alt.SetValue(chromeos::input_method::kControlKey);
1368 1368
1369 // Press left Alt. Confirm the event is now VKEY_CONTROL + XK_Control_L. 1369 // Press left Alt. Confirm the event is now VKEY_CONTROL + XK_Control_L.
1370 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CONTROL, 1370 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CONTROL,
1371 ui::EF_CONTROL_DOWN, 1371 ui::EF_CONTROL_DOWN,
1372 ui::ET_KEY_PRESSED, 1372 ui::ET_KEY_PRESSED,
1373 keycode_control_l_, 1373 keycode_control_l_,
1374 0U, 1374 0U,
1375 KeyPress), 1375 KeyPress),
1376 GetRewrittenEventAsString(&rewriter, 1376 GetRewrittenEventAsString(&rewriter,
1377 ui::VKEY_MENU, 1377 ui::VKEY_MENU,
1378 0, 1378 0,
1379 ui::ET_KEY_PRESSED, 1379 ui::ET_KEY_PRESSED,
1380 keycode_alt_l_, 1380 keycode_alt_l_,
1381 0U)); 1381 0U));
1382 1382
1383 // Remap Control to Search. 1383 // Remap Control to Search.
1384 IntegerPrefMember control; 1384 IntegerPrefMember control;
1385 control.Init(prefs::kLanguageRemapControlKeyTo, &prefs, NULL); 1385 control.Init(prefs::kLanguageRemapControlKeyTo, &prefs);
1386 control.SetValue(chromeos::input_method::kSearchKey); 1386 control.SetValue(chromeos::input_method::kSearchKey);
1387 1387
1388 // Press left Control. Confirm the event is now VKEY_LWIN. 1388 // Press left Control. Confirm the event is now VKEY_LWIN.
1389 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_LWIN, 1389 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_LWIN,
1390 0, 1390 0,
1391 ui::ET_KEY_PRESSED, 1391 ui::ET_KEY_PRESSED,
1392 keycode_super_l_, 1392 keycode_super_l_,
1393 0U, 1393 0U,
1394 KeyPress), 1394 KeyPress),
1395 GetRewrittenEventAsString(&rewriter, 1395 GetRewrittenEventAsString(&rewriter,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1446 keycode_b_, 1446 keycode_b_,
1447 ShiftMask | ControlMask | Mod1Mask | 1447 ShiftMask | ControlMask | Mod1Mask |
1448 Mod4Mask)); 1448 Mod4Mask));
1449 } 1449 }
1450 1450
1451 TEST_F(EventRewriterTest, TestRewriteModifiersRemapToCapsLock) { 1451 TEST_F(EventRewriterTest, TestRewriteModifiersRemapToCapsLock) {
1452 // Remap Search to Caps Lock. 1452 // Remap Search to Caps Lock.
1453 TestingPrefService prefs; 1453 TestingPrefService prefs;
1454 chromeos::Preferences::RegisterUserPrefs(&prefs); 1454 chromeos::Preferences::RegisterUserPrefs(&prefs);
1455 IntegerPrefMember search; 1455 IntegerPrefMember search;
1456 search.Init(prefs::kLanguageRemapSearchKeyTo, &prefs, NULL); 1456 search.Init(prefs::kLanguageRemapSearchKeyTo, &prefs);
1457 search.SetValue(chromeos::input_method::kCapsLockKey); 1457 search.SetValue(chromeos::input_method::kCapsLockKey);
1458 1458
1459 chromeos::input_method::MockXKeyboard xkeyboard; 1459 chromeos::input_method::MockXKeyboard xkeyboard;
1460 EventRewriter rewriter; 1460 EventRewriter rewriter;
1461 rewriter.set_pref_service_for_testing(&prefs); 1461 rewriter.set_pref_service_for_testing(&prefs);
1462 rewriter.set_xkeyboard_for_testing(&xkeyboard); 1462 rewriter.set_xkeyboard_for_testing(&xkeyboard);
1463 EXPECT_FALSE(xkeyboard.caps_lock_is_enabled_); 1463 EXPECT_FALSE(xkeyboard.caps_lock_is_enabled_);
1464 1464
1465 // Press Search. 1465 // Press Search.
1466 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CAPITAL, 1466 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CAPITAL,
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1621 0U)); 1621 0U));
1622 EXPECT_TRUE(xkeyboard.caps_lock_is_enabled_); 1622 EXPECT_TRUE(xkeyboard.caps_lock_is_enabled_);
1623 1623
1624 *CommandLine::ForCurrentProcess() = original_cl; 1624 *CommandLine::ForCurrentProcess() = original_cl;
1625 } 1625 }
1626 1626
1627 TEST_F(EventRewriterTest, TestRewriteCapsLockToControl) { 1627 TEST_F(EventRewriterTest, TestRewriteCapsLockToControl) {
1628 TestingPrefService prefs; 1628 TestingPrefService prefs;
1629 chromeos::Preferences::RegisterUserPrefs(&prefs); 1629 chromeos::Preferences::RegisterUserPrefs(&prefs);
1630 IntegerPrefMember control; 1630 IntegerPrefMember control;
1631 control.Init(prefs::kLanguageRemapCapsLockKeyTo, &prefs, NULL); 1631 control.Init(prefs::kLanguageRemapCapsLockKeyTo, &prefs);
1632 control.SetValue(chromeos::input_method::kControlKey); 1632 control.SetValue(chromeos::input_method::kControlKey);
1633 1633
1634 EventRewriter rewriter; 1634 EventRewriter rewriter;
1635 rewriter.set_pref_service_for_testing(&prefs); 1635 rewriter.set_pref_service_for_testing(&prefs);
1636 1636
1637 // Press CapsLock+a. Confirm that Mod3Mask is rewritten to ControlMask. 1637 // Press CapsLock+a. Confirm that Mod3Mask is rewritten to ControlMask.
1638 // On Chrome OS, CapsLock works as a Mod3 modifier. 1638 // On Chrome OS, CapsLock works as a Mod3 modifier.
1639 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_A, 1639 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_A,
1640 ui::EF_CONTROL_DOWN, 1640 ui::EF_CONTROL_DOWN,
1641 ui::ET_KEY_PRESSED, 1641 ui::ET_KEY_PRESSED,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1676 ui::ET_KEY_PRESSED, 1676 ui::ET_KEY_PRESSED,
1677 keycode_a_, 1677 keycode_a_,
1678 Mod1Mask | Mod3Mask)); 1678 Mod1Mask | Mod3Mask));
1679 } 1679 }
1680 1680
1681 TEST_F(EventRewriterTest, DISABLED_TestRewriteCapsLockToControlWithFlag) { 1681 TEST_F(EventRewriterTest, DISABLED_TestRewriteCapsLockToControlWithFlag) {
1682 // TODO(yusukes): Reenable the test once build servers are upgraded. 1682 // TODO(yusukes): Reenable the test once build servers are upgraded.
1683 TestingPrefService prefs; 1683 TestingPrefService prefs;
1684 chromeos::Preferences::RegisterUserPrefs(&prefs); 1684 chromeos::Preferences::RegisterUserPrefs(&prefs);
1685 IntegerPrefMember control; 1685 IntegerPrefMember control;
1686 control.Init(prefs::kLanguageRemapCapsLockKeyTo, &prefs, NULL); 1686 control.Init(prefs::kLanguageRemapCapsLockKeyTo, &prefs);
1687 control.SetValue(chromeos::input_method::kControlKey); 1687 control.SetValue(chromeos::input_method::kControlKey);
1688 1688
1689 EventRewriter rewriter; 1689 EventRewriter rewriter;
1690 rewriter.set_pref_service_for_testing(&prefs); 1690 rewriter.set_pref_service_for_testing(&prefs);
1691 1691
1692 // The prefs::kLanguageRemapCapsLockKeyTo pref should be ignored when 1692 // The prefs::kLanguageRemapCapsLockKeyTo pref should be ignored when
1693 // --has-chromeos-keyboard is set. 1693 // --has-chromeos-keyboard is set.
1694 const CommandLine original_cl(*CommandLine::ForCurrentProcess()); 1694 const CommandLine original_cl(*CommandLine::ForCurrentProcess());
1695 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 1695 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
1696 switches::kHasChromeOSKeyboard, ""); 1696 switches::kHasChromeOSKeyboard, "");
(...skipping 25 matching lines...) Expand all
1722 Mod3Mask)); 1722 Mod3Mask));
1723 1723
1724 *CommandLine::ForCurrentProcess() = original_cl; 1724 *CommandLine::ForCurrentProcess() = original_cl;
1725 } 1725 }
1726 1726
1727 TEST_F(EventRewriterTest, TestRewriteCapsLockMod3InUse) { 1727 TEST_F(EventRewriterTest, TestRewriteCapsLockMod3InUse) {
1728 // Remap CapsLock to Control. 1728 // Remap CapsLock to Control.
1729 TestingPrefService prefs; 1729 TestingPrefService prefs;
1730 chromeos::Preferences::RegisterUserPrefs(&prefs); 1730 chromeos::Preferences::RegisterUserPrefs(&prefs);
1731 IntegerPrefMember control; 1731 IntegerPrefMember control;
1732 control.Init(prefs::kLanguageRemapCapsLockKeyTo, &prefs, NULL); 1732 control.Init(prefs::kLanguageRemapCapsLockKeyTo, &prefs);
1733 control.SetValue(chromeos::input_method::kControlKey); 1733 control.SetValue(chromeos::input_method::kControlKey);
1734 1734
1735 EventRewriter rewriter; 1735 EventRewriter rewriter;
1736 rewriter.set_pref_service_for_testing(&prefs); 1736 rewriter.set_pref_service_for_testing(&prefs);
1737 input_method_manager_mock_->SetCurrentInputMethodId("xkb:de:neo:ger"); 1737 input_method_manager_mock_->SetCurrentInputMethodId("xkb:de:neo:ger");
1738 1738
1739 // Press CapsLock+a. Confirm that Mod3Mask is NOT rewritten to ControlMask 1739 // Press CapsLock+a. Confirm that Mod3Mask is NOT rewritten to ControlMask
1740 // when Mod3Mask is already in use by the current XKB layout. 1740 // when Mod3Mask is already in use by the current XKB layout.
1741 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_A, 1741 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_A,
1742 0, 1742 0,
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1936 Mod4Mask | 1936 Mod4Mask |
1937 chromeos_tests[i].input_native_mods)); 1937 chromeos_tests[i].input_native_mods));
1938 } 1938 }
1939 1939
1940 // Make Search key act like a Function key for accessing extended key 1940 // Make Search key act like a Function key for accessing extended key
1941 // bindings. 1941 // bindings.
1942 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 1942 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
1943 switches::kEnableChromebookFunctionKey, ""); 1943 switches::kEnableChromebookFunctionKey, "");
1944 BooleanPrefMember search_key_as_function_key; 1944 BooleanPrefMember search_key_as_function_key;
1945 search_key_as_function_key.Init(prefs::kLanguageSearchKeyActsAsFunctionKey, 1945 search_key_as_function_key.Init(prefs::kLanguageSearchKeyActsAsFunctionKey,
1946 &prefs, NULL); 1946 &prefs);
1947 search_key_as_function_key.SetValue(true); 1947 search_key_as_function_key.SetValue(true);
1948 1948
1949 1949
1950 // An external keyboard should still not be remapped. 1950 // An external keyboard should still not be remapped.
1951 rewriter.set_force_chromeos_keyboard_for_testing(false); 1951 rewriter.set_force_chromeos_keyboard_for_testing(false);
1952 1952
1953 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(default_tests); ++i) { 1953 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(default_tests); ++i) {
1954 EXPECT_EQ(GetExpectedResultAsString(default_tests[i].output, 1954 EXPECT_EQ(GetExpectedResultAsString(default_tests[i].output,
1955 default_tests[i].output_mods, 1955 default_tests[i].output_mods,
1956 ui::ET_KEY_PRESSED, 1956 ui::ET_KEY_PRESSED,
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
2280 Mod4Mask)); 2280 Mod4Mask));
2281 } 2281 }
2282 2282
2283 // Make Search key act like a Function key for accessing extended key 2283 // Make Search key act like a Function key for accessing extended key
2284 // bindings. Now Search key as a modifier will make the number row 2284 // bindings. Now Search key as a modifier will make the number row
2285 // act like the F<number> row. 2285 // act like the F<number> row.
2286 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 2286 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
2287 switches::kEnableChromebookFunctionKey, ""); 2287 switches::kEnableChromebookFunctionKey, "");
2288 BooleanPrefMember search_key_as_function_key; 2288 BooleanPrefMember search_key_as_function_key;
2289 search_key_as_function_key.Init(prefs::kLanguageSearchKeyActsAsFunctionKey, 2289 search_key_as_function_key.Init(prefs::kLanguageSearchKeyActsAsFunctionKey,
2290 &prefs, NULL); 2290 &prefs);
2291 search_key_as_function_key.SetValue(true); 2291 search_key_as_function_key.SetValue(true);
2292 2292
2293 // Without a Search key modifier, the results should be the same as before. 2293 // Without a Search key modifier, the results should be the same as before.
2294 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(chromeos_tests); ++i) { 2294 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(chromeos_tests); ++i) {
2295 EXPECT_EQ(GetExpectedResultAsString(chromeos_tests[i].output, 2295 EXPECT_EQ(GetExpectedResultAsString(chromeos_tests[i].output,
2296 0, 2296 0,
2297 ui::ET_KEY_PRESSED, 2297 ui::ET_KEY_PRESSED,
2298 chromeos_tests[i].output_native, 2298 chromeos_tests[i].output_native,
2299 0U, 2299 0U,
2300 KeyPress), 2300 KeyPress),
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
2373 *CommandLine::ForCurrentProcess() = original_cl; 2373 *CommandLine::ForCurrentProcess() = original_cl;
2374 } 2374 }
2375 2375
2376 TEST_F(EventRewriterTest, TestRewriteBackspaceAndArrowKeysWithSearchRemapped) { 2376 TEST_F(EventRewriterTest, TestRewriteBackspaceAndArrowKeysWithSearchRemapped) {
2377 const CommandLine original_cl(*CommandLine::ForCurrentProcess()); 2377 const CommandLine original_cl(*CommandLine::ForCurrentProcess());
2378 2378
2379 // Remap Search to Control. 2379 // Remap Search to Control.
2380 TestingPrefService prefs; 2380 TestingPrefService prefs;
2381 chromeos::Preferences::RegisterUserPrefs(&prefs); 2381 chromeos::Preferences::RegisterUserPrefs(&prefs);
2382 IntegerPrefMember search; 2382 IntegerPrefMember search;
2383 search.Init(prefs::kLanguageRemapSearchKeyTo, &prefs, NULL); 2383 search.Init(prefs::kLanguageRemapSearchKeyTo, &prefs);
2384 search.SetValue(chromeos::input_method::kControlKey); 2384 search.SetValue(chromeos::input_method::kControlKey);
2385 2385
2386 EventRewriter rewriter; 2386 EventRewriter rewriter;
2387 rewriter.set_pref_service_for_testing(&prefs); 2387 rewriter.set_pref_service_for_testing(&prefs);
2388 2388
2389 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 2389 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
2390 switches::kHasChromeOSKeyboard, ""); 2390 switches::kHasChromeOSKeyboard, "");
2391 rewriter.set_force_chromeos_keyboard_for_testing(true); 2391 rewriter.set_force_chromeos_keyboard_for_testing(true);
2392 2392
2393 // Alt+Search+Down -> End 2393 // Alt+Search+Down -> End
(...skipping 25 matching lines...) Expand all
2419 ShiftMask | Mod1Mask | Mod4Mask)); 2419 ShiftMask | Mod1Mask | Mod4Mask));
2420 2420
2421 *CommandLine::ForCurrentProcess() = original_cl; 2421 *CommandLine::ForCurrentProcess() = original_cl;
2422 } 2422 }
2423 2423
2424 TEST_F(EventRewriterTest, TestRewriteKeyEventSentByXSendEvent) { 2424 TEST_F(EventRewriterTest, TestRewriteKeyEventSentByXSendEvent) {
2425 // Remap Control to Alt. 2425 // Remap Control to Alt.
2426 TestingPrefService prefs; 2426 TestingPrefService prefs;
2427 chromeos::Preferences::RegisterUserPrefs(&prefs); 2427 chromeos::Preferences::RegisterUserPrefs(&prefs);
2428 IntegerPrefMember control; 2428 IntegerPrefMember control;
2429 control.Init(prefs::kLanguageRemapControlKeyTo, &prefs, NULL); 2429 control.Init(prefs::kLanguageRemapControlKeyTo, &prefs);
2430 control.SetValue(chromeos::input_method::kAltKey); 2430 control.SetValue(chromeos::input_method::kAltKey);
2431 2431
2432 EventRewriter rewriter; 2432 EventRewriter rewriter;
2433 rewriter.set_pref_service_for_testing(&prefs); 2433 rewriter.set_pref_service_for_testing(&prefs);
2434 2434
2435 // Send left control press. 2435 // Send left control press.
2436 std::string rewritten_event; 2436 std::string rewritten_event;
2437 { 2437 {
2438 XEvent xev; 2438 XEvent xev;
2439 InitXKeyEvent(ui::VKEY_CONTROL, 0, ui::ET_KEY_PRESSED, 2439 InitXKeyEvent(ui::VKEY_CONTROL, 0, ui::ET_KEY_PRESSED,
(...skipping 12 matching lines...) Expand all
2452 // flag in the event is True. 2452 // flag in the event is True.
2453 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CONTROL, 2453 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CONTROL,
2454 ui::EF_CONTROL_DOWN, 2454 ui::EF_CONTROL_DOWN,
2455 ui::ET_KEY_PRESSED, 2455 ui::ET_KEY_PRESSED,
2456 keycode_control_l_, 2456 keycode_control_l_,
2457 0U, 2457 0U,
2458 KeyPress), 2458 KeyPress),
2459 rewritten_event); 2459 rewritten_event);
2460 } 2460 }
2461 #endif // OS_CHROMEOS 2461 #endif // OS_CHROMEOS
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698