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

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

Issue 11570009: Split PrefService into PrefService, PrefServiceSimple and PrefServiceSyncable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to head again, previous had unrelated broken win_rel test. Created 7 years, 12 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
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/prefs/public/pref_member.h" 9 #include "base/prefs/public/pref_member.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 EXPECT_EQ(2U, rewriter.device_id_to_type_for_testing().size()); 324 EXPECT_EQ(2U, rewriter.device_id_to_type_for_testing().size());
325 // Try to reuse the first ID. 325 // Try to reuse the first ID.
326 EXPECT_EQ(EventRewriter::kDeviceAppleKeyboard, 326 EXPECT_EQ(EventRewriter::kDeviceAppleKeyboard,
327 rewriter.DeviceAddedForTesting(0, "Apple Keyboard")); 327 rewriter.DeviceAddedForTesting(0, "Apple Keyboard"));
328 EXPECT_EQ(2U, rewriter.device_id_to_type_for_testing().size()); 328 EXPECT_EQ(2U, rewriter.device_id_to_type_for_testing().size());
329 } 329 }
330 330
331 #if defined(OS_CHROMEOS) 331 #if defined(OS_CHROMEOS)
332 TEST_F(EventRewriterTest, TestRewriteCommandToControl) { 332 TEST_F(EventRewriterTest, TestRewriteCommandToControl) {
333 // First, test with a PC keyboard. 333 // First, test with a PC keyboard.
334 TestingPrefService prefs; 334 TestingPrefServiceSyncable prefs;
335 EventRewriter rewriter; 335 EventRewriter rewriter;
336 rewriter.DeviceAddedForTesting(0, "PC Keyboard"); 336 rewriter.DeviceAddedForTesting(0, "PC Keyboard");
337 rewriter.set_last_device_id_for_testing(0); 337 rewriter.set_last_device_id_for_testing(0);
338 rewriter.set_pref_service_for_testing(&prefs); 338 rewriter.set_pref_service_for_testing(&prefs);
339 339
340 // XK_a, Alt modifier. 340 // XK_a, Alt modifier.
341 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_A, 341 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_A,
342 ui::EF_ALT_DOWN, 342 ui::EF_ALT_DOWN,
343 ui::ET_KEY_PRESSED, 343 ui::ET_KEY_PRESSED,
344 keycode_a_, 344 keycode_a_,
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 ui::VKEY_RWIN, 478 ui::VKEY_RWIN,
479 ui::EF_ALT_DOWN, 479 ui::EF_ALT_DOWN,
480 ui::ET_KEY_PRESSED, 480 ui::ET_KEY_PRESSED,
481 keycode_super_r_, 481 keycode_super_r_,
482 Mod1Mask)); 482 Mod1Mask));
483 } 483 }
484 484
485 // For crbug.com/133896. 485 // For crbug.com/133896.
486 TEST_F(EventRewriterTest, TestRewriteCommandToControlWithControlRemapped) { 486 TEST_F(EventRewriterTest, TestRewriteCommandToControlWithControlRemapped) {
487 // Remap Control to Alt. 487 // Remap Control to Alt.
488 TestingPrefService prefs; 488 TestingPrefServiceSyncable prefs;
489 chromeos::Preferences::RegisterUserPrefs(&prefs); 489 chromeos::Preferences::RegisterUserPrefs(&prefs);
490 IntegerPrefMember control; 490 IntegerPrefMember control;
491 control.Init(prefs::kLanguageRemapControlKeyTo, &prefs); 491 control.Init(prefs::kLanguageRemapControlKeyTo, &prefs);
492 control.SetValue(chromeos::input_method::kAltKey); 492 control.SetValue(chromeos::input_method::kAltKey);
493 493
494 EventRewriter rewriter; 494 EventRewriter rewriter;
495 rewriter.set_pref_service_for_testing(&prefs); 495 rewriter.set_pref_service_for_testing(&prefs);
496 rewriter.DeviceAddedForTesting(0, "PC Keyboard"); 496 rewriter.DeviceAddedForTesting(0, "PC Keyboard");
497 rewriter.set_last_device_id_for_testing(0); 497 rewriter.set_last_device_id_for_testing(0);
498 498
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 KeyPress), 539 KeyPress),
540 GetRewrittenEventAsString(&rewriter, 540 GetRewrittenEventAsString(&rewriter,
541 ui::VKEY_RWIN, 541 ui::VKEY_RWIN,
542 ui::EF_ALT_DOWN, 542 ui::EF_ALT_DOWN,
543 ui::ET_KEY_PRESSED, 543 ui::ET_KEY_PRESSED,
544 keycode_super_r_, 544 keycode_super_r_,
545 Mod1Mask)); 545 Mod1Mask));
546 } 546 }
547 547
548 TEST_F(EventRewriterTest, TestRewriteNumPadKeys) { 548 TEST_F(EventRewriterTest, TestRewriteNumPadKeys) {
549 TestingPrefService prefs; 549 TestingPrefServiceSyncable prefs;
550 EventRewriter rewriter; 550 EventRewriter rewriter;
551 rewriter.set_pref_service_for_testing(&prefs); 551 rewriter.set_pref_service_for_testing(&prefs);
552 552
553 // XK_KP_Insert (= NumPad 0 without Num Lock), no modifier. 553 // XK_KP_Insert (= NumPad 0 without Num Lock), no modifier.
554 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_NUMPAD0, 554 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_NUMPAD0,
555 0, 555 0,
556 ui::ET_KEY_PRESSED, 556 ui::ET_KEY_PRESSED,
557 keycode_num_pad_0_, 557 keycode_num_pad_0_,
558 Mod2Mask, // Num Lock 558 Mod2Mask, // Num Lock
559 KeyPress), 559 KeyPress),
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 GetRewrittenEventAsString(&rewriter, 868 GetRewrittenEventAsString(&rewriter,
869 ui::VKEY_NUMPAD9, 869 ui::VKEY_NUMPAD9,
870 0, 870 0,
871 ui::ET_KEY_PRESSED, 871 ui::ET_KEY_PRESSED,
872 keycode_num_pad_9_, 872 keycode_num_pad_9_,
873 Mod2Mask)); 873 Mod2Mask));
874 } 874 }
875 875
876 // Tests if the rewriter can handle a Command + Num Pad event. 876 // Tests if the rewriter can handle a Command + Num Pad event.
877 TEST_F(EventRewriterTest, TestRewriteNumPadKeysOnAppleKeyboard) { 877 TEST_F(EventRewriterTest, TestRewriteNumPadKeysOnAppleKeyboard) {
878 TestingPrefService prefs; 878 TestingPrefServiceSyncable prefs;
879 EventRewriter rewriter; 879 EventRewriter rewriter;
880 rewriter.DeviceAddedForTesting(0, "Apple Keyboard"); 880 rewriter.DeviceAddedForTesting(0, "Apple Keyboard");
881 rewriter.set_last_device_id_for_testing(0); 881 rewriter.set_last_device_id_for_testing(0);
882 rewriter.set_pref_service_for_testing(&prefs); 882 rewriter.set_pref_service_for_testing(&prefs);
883 883
884 // XK_KP_End (= NumPad 1 without Num Lock), Win modifier. 884 // XK_KP_End (= NumPad 1 without Num Lock), Win modifier.
885 // The result should be "Num Pad 1 with Control + Num Lock modifiers". 885 // The result should be "Num Pad 1 with Control + Num Lock modifiers".
886 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_NUMPAD1, 886 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_NUMPAD1,
887 ui::EF_CONTROL_DOWN, 887 ui::EF_CONTROL_DOWN,
888 ui::ET_KEY_PRESSED, 888 ui::ET_KEY_PRESSED,
(...skipping 17 matching lines...) Expand all
906 KeyPress), 906 KeyPress),
907 GetRewrittenEventAsString(&rewriter, 907 GetRewrittenEventAsString(&rewriter,
908 ui::VKEY_NUMPAD1, 908 ui::VKEY_NUMPAD1,
909 0, 909 0,
910 ui::ET_KEY_PRESSED, 910 ui::ET_KEY_PRESSED,
911 keycode_num_pad_end_, 911 keycode_num_pad_end_,
912 Mod4Mask)); 912 Mod4Mask));
913 } 913 }
914 914
915 TEST_F(EventRewriterTest, TestRewriteModifiersNoRemap) { 915 TEST_F(EventRewriterTest, TestRewriteModifiersNoRemap) {
916 TestingPrefService prefs; 916 TestingPrefServiceSyncable prefs;
917 EventRewriter rewriter; 917 EventRewriter rewriter;
918 rewriter.set_pref_service_for_testing(&prefs); 918 rewriter.set_pref_service_for_testing(&prefs);
919 919
920 // Press Search. Confirm the event is not rewritten. 920 // Press Search. Confirm the event is not rewritten.
921 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_LWIN, 921 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_LWIN,
922 0, 922 0,
923 ui::ET_KEY_PRESSED, 923 ui::ET_KEY_PRESSED,
924 keycode_super_l_, 924 keycode_super_l_,
925 0U, 925 0U,
926 KeyPress), 926 KeyPress),
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
997 KeyRelease), 997 KeyRelease),
998 GetRewrittenEventAsString(&rewriter, 998 GetRewrittenEventAsString(&rewriter,
999 ui::VKEY_LWIN, 999 ui::VKEY_LWIN,
1000 0, 1000 0,
1001 ui::ET_KEY_RELEASED, 1001 ui::ET_KEY_RELEASED,
1002 keycode_super_l_, 1002 keycode_super_l_,
1003 Mod4Mask)); 1003 Mod4Mask));
1004 } 1004 }
1005 1005
1006 TEST_F(EventRewriterTest, TestRewriteModifiersNoRemapMultipleKeys) { 1006 TEST_F(EventRewriterTest, TestRewriteModifiersNoRemapMultipleKeys) {
1007 TestingPrefService prefs; 1007 TestingPrefServiceSyncable prefs;
1008 EventRewriter rewriter; 1008 EventRewriter rewriter;
1009 rewriter.set_pref_service_for_testing(&prefs); 1009 rewriter.set_pref_service_for_testing(&prefs);
1010 1010
1011 // Press left Alt with Shift. Confirm the event is not rewritten. 1011 // Press left Alt with Shift. Confirm the event is not rewritten.
1012 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_MENU, 1012 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_MENU,
1013 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN, 1013 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN,
1014 ui::ET_KEY_PRESSED, 1014 ui::ET_KEY_PRESSED,
1015 keycode_meta_l_, 1015 keycode_meta_l_,
1016 ShiftMask, 1016 ShiftMask,
1017 KeyPress), 1017 KeyPress),
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 ui::EF_SHIFT_DOWN | 1078 ui::EF_SHIFT_DOWN |
1079 ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, 1079 ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN,
1080 ui::ET_KEY_PRESSED, 1080 ui::ET_KEY_PRESSED,
1081 keycode_b_, 1081 keycode_b_,
1082 ShiftMask | ControlMask | Mod1Mask | 1082 ShiftMask | ControlMask | Mod1Mask |
1083 Mod4Mask)); 1083 Mod4Mask));
1084 } 1084 }
1085 1085
1086 TEST_F(EventRewriterTest, TestRewriteModifiersDisableSome) { 1086 TEST_F(EventRewriterTest, TestRewriteModifiersDisableSome) {
1087 // Disable Search and Control keys. 1087 // Disable Search and Control keys.
1088 TestingPrefService prefs; 1088 TestingPrefServiceSyncable prefs;
1089 chromeos::Preferences::RegisterUserPrefs(&prefs); 1089 chromeos::Preferences::RegisterUserPrefs(&prefs);
1090 IntegerPrefMember search; 1090 IntegerPrefMember search;
1091 search.Init(prefs::kLanguageRemapSearchKeyTo, &prefs); 1091 search.Init(prefs::kLanguageRemapSearchKeyTo, &prefs);
1092 search.SetValue(chromeos::input_method::kVoidKey); 1092 search.SetValue(chromeos::input_method::kVoidKey);
1093 IntegerPrefMember control; 1093 IntegerPrefMember control;
1094 control.Init(prefs::kLanguageRemapControlKeyTo, &prefs); 1094 control.Init(prefs::kLanguageRemapControlKeyTo, &prefs);
1095 control.SetValue(chromeos::input_method::kVoidKey); 1095 control.SetValue(chromeos::input_method::kVoidKey);
1096 1096
1097 EventRewriter rewriter; 1097 EventRewriter rewriter;
1098 rewriter.set_pref_service_for_testing(&prefs); 1098 rewriter.set_pref_service_for_testing(&prefs);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1216 GetRewrittenEventAsString(&rewriter, 1216 GetRewrittenEventAsString(&rewriter,
1217 ui::VKEY_A, 1217 ui::VKEY_A,
1218 ui::EF_ALT_DOWN, 1218 ui::EF_ALT_DOWN,
1219 ui::ET_KEY_PRESSED, 1219 ui::ET_KEY_PRESSED,
1220 keycode_a_, 1220 keycode_a_,
1221 Mod1Mask)); 1221 Mod1Mask));
1222 } 1222 }
1223 1223
1224 TEST_F(EventRewriterTest, TestRewriteModifiersRemapToControl) { 1224 TEST_F(EventRewriterTest, TestRewriteModifiersRemapToControl) {
1225 // Remap Search to Control. 1225 // Remap Search to Control.
1226 TestingPrefService prefs; 1226 TestingPrefServiceSyncable prefs;
1227 chromeos::Preferences::RegisterUserPrefs(&prefs); 1227 chromeos::Preferences::RegisterUserPrefs(&prefs);
1228 IntegerPrefMember search; 1228 IntegerPrefMember search;
1229 search.Init(prefs::kLanguageRemapSearchKeyTo, &prefs); 1229 search.Init(prefs::kLanguageRemapSearchKeyTo, &prefs);
1230 search.SetValue(chromeos::input_method::kControlKey); 1230 search.SetValue(chromeos::input_method::kControlKey);
1231 1231
1232 EventRewriter rewriter; 1232 EventRewriter rewriter;
1233 rewriter.set_pref_service_for_testing(&prefs); 1233 rewriter.set_pref_service_for_testing(&prefs);
1234 1234
1235 // Press Search. Confirm the event is now VKEY_CONTROL + XK_Control_L. 1235 // Press Search. Confirm the event is now VKEY_CONTROL + XK_Control_L.
1236 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CONTROL, 1236 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CONTROL,
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1336 ui::VKEY_B, 1336 ui::VKEY_B,
1337 ui::EF_SHIFT_DOWN | 1337 ui::EF_SHIFT_DOWN |
1338 ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, 1338 ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN,
1339 ui::ET_KEY_PRESSED, 1339 ui::ET_KEY_PRESSED,
1340 keycode_b_, 1340 keycode_b_,
1341 ShiftMask | ControlMask | Mod1Mask)); 1341 ShiftMask | ControlMask | Mod1Mask));
1342 } 1342 }
1343 1343
1344 TEST_F(EventRewriterTest, TestRewriteModifiersRemapMany) { 1344 TEST_F(EventRewriterTest, TestRewriteModifiersRemapMany) {
1345 // Remap Search to Alt. 1345 // Remap Search to Alt.
1346 TestingPrefService prefs; 1346 TestingPrefServiceSyncable prefs;
1347 chromeos::Preferences::RegisterUserPrefs(&prefs); 1347 chromeos::Preferences::RegisterUserPrefs(&prefs);
1348 IntegerPrefMember search; 1348 IntegerPrefMember search;
1349 search.Init(prefs::kLanguageRemapSearchKeyTo, &prefs); 1349 search.Init(prefs::kLanguageRemapSearchKeyTo, &prefs);
1350 search.SetValue(chromeos::input_method::kAltKey); 1350 search.SetValue(chromeos::input_method::kAltKey);
1351 1351
1352 EventRewriter rewriter; 1352 EventRewriter rewriter;
1353 rewriter.set_pref_service_for_testing(&prefs); 1353 rewriter.set_pref_service_for_testing(&prefs);
1354 1354
1355 // Press Search. Confirm the event is now VKEY_MENU + XK_Alt_L. 1355 // Press Search. Confirm the event is now VKEY_MENU + XK_Alt_L.
1356 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_MENU, 1356 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_MENU,
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1448 ui::EF_SHIFT_DOWN | 1448 ui::EF_SHIFT_DOWN |
1449 ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, 1449 ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN,
1450 ui::ET_KEY_PRESSED, 1450 ui::ET_KEY_PRESSED,
1451 keycode_b_, 1451 keycode_b_,
1452 ShiftMask | ControlMask | Mod1Mask | 1452 ShiftMask | ControlMask | Mod1Mask |
1453 Mod4Mask)); 1453 Mod4Mask));
1454 } 1454 }
1455 1455
1456 TEST_F(EventRewriterTest, TestRewriteModifiersRemapToCapsLock) { 1456 TEST_F(EventRewriterTest, TestRewriteModifiersRemapToCapsLock) {
1457 // Remap Search to Caps Lock. 1457 // Remap Search to Caps Lock.
1458 TestingPrefService prefs; 1458 TestingPrefServiceSyncable prefs;
1459 chromeos::Preferences::RegisterUserPrefs(&prefs); 1459 chromeos::Preferences::RegisterUserPrefs(&prefs);
1460 IntegerPrefMember search; 1460 IntegerPrefMember search;
1461 search.Init(prefs::kLanguageRemapSearchKeyTo, &prefs); 1461 search.Init(prefs::kLanguageRemapSearchKeyTo, &prefs);
1462 search.SetValue(chromeos::input_method::kCapsLockKey); 1462 search.SetValue(chromeos::input_method::kCapsLockKey);
1463 1463
1464 chromeos::input_method::MockXKeyboard xkeyboard; 1464 chromeos::input_method::MockXKeyboard xkeyboard;
1465 EventRewriter rewriter; 1465 EventRewriter rewriter;
1466 rewriter.set_pref_service_for_testing(&prefs); 1466 rewriter.set_pref_service_for_testing(&prefs);
1467 rewriter.set_xkeyboard_for_testing(&xkeyboard); 1467 rewriter.set_xkeyboard_for_testing(&xkeyboard);
1468 EXPECT_FALSE(xkeyboard.caps_lock_is_enabled_); 1468 EXPECT_FALSE(xkeyboard.caps_lock_is_enabled_);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1564 keycode_caps_lock_, 1564 keycode_caps_lock_,
1565 LockMask)); 1565 LockMask));
1566 EXPECT_FALSE(xkeyboard.caps_lock_is_enabled_); 1566 EXPECT_FALSE(xkeyboard.caps_lock_is_enabled_);
1567 } 1567 }
1568 1568
1569 TEST_F(EventRewriterTest, DISABLED_TestRewriteCapsLock) { 1569 TEST_F(EventRewriterTest, DISABLED_TestRewriteCapsLock) {
1570 // It seems that the X server running on build servers is too old and does not 1570 // It seems that the X server running on build servers is too old and does not
1571 // support F16 (i.e. 'XKeysymToKeycode(display_, XF86XK_Launch7)' call). 1571 // support F16 (i.e. 'XKeysymToKeycode(display_, XF86XK_Launch7)' call).
1572 // TODO(yusukes): Reenable the test once build servers are upgraded. 1572 // TODO(yusukes): Reenable the test once build servers are upgraded.
1573 1573
1574 TestingPrefService prefs; 1574 TestingPrefServiceSyncable prefs;
1575 chromeos::Preferences::RegisterUserPrefs(&prefs); 1575 chromeos::Preferences::RegisterUserPrefs(&prefs);
1576 1576
1577 chromeos::input_method::MockXKeyboard xkeyboard; 1577 chromeos::input_method::MockXKeyboard xkeyboard;
1578 EventRewriter rewriter; 1578 EventRewriter rewriter;
1579 rewriter.set_pref_service_for_testing(&prefs); 1579 rewriter.set_pref_service_for_testing(&prefs);
1580 rewriter.set_xkeyboard_for_testing(&xkeyboard); 1580 rewriter.set_xkeyboard_for_testing(&xkeyboard);
1581 EXPECT_FALSE(xkeyboard.caps_lock_is_enabled_); 1581 EXPECT_FALSE(xkeyboard.caps_lock_is_enabled_);
1582 1582
1583 // On Chrome OS, CapsLock is mapped to F16 with Mod3Mask. 1583 // On Chrome OS, CapsLock is mapped to F16 with Mod3Mask.
1584 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CAPITAL, 1584 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CAPITAL,
1585 ui::EF_CAPS_LOCK_DOWN, 1585 ui::EF_CAPS_LOCK_DOWN,
1586 ui::ET_KEY_PRESSED, 1586 ui::ET_KEY_PRESSED,
1587 keycode_caps_lock_, 1587 keycode_caps_lock_,
1588 0U, 1588 0U,
1589 KeyPress), 1589 KeyPress),
1590 GetRewrittenEventAsString(&rewriter, 1590 GetRewrittenEventAsString(&rewriter,
1591 ui::VKEY_F16, 1591 ui::VKEY_F16,
1592 0, 1592 0,
1593 ui::ET_KEY_PRESSED, 1593 ui::ET_KEY_PRESSED,
1594 keycode_launch7_, 1594 keycode_launch7_,
1595 0U)); 1595 0U));
1596 EXPECT_TRUE(xkeyboard.caps_lock_is_enabled_); 1596 EXPECT_TRUE(xkeyboard.caps_lock_is_enabled_);
1597 } 1597 }
1598 1598
1599 TEST_F(EventRewriterTest, DISABLED_TestRewriteCapsLockWithFlag) { 1599 TEST_F(EventRewriterTest, DISABLED_TestRewriteCapsLockWithFlag) {
1600 // TODO(yusukes): Reenable the test once build servers are upgraded. 1600 // TODO(yusukes): Reenable the test once build servers are upgraded.
1601 TestingPrefService prefs; 1601 TestingPrefServiceSyncable prefs;
1602 chromeos::Preferences::RegisterUserPrefs(&prefs); 1602 chromeos::Preferences::RegisterUserPrefs(&prefs);
1603 1603
1604 chromeos::input_method::MockXKeyboard xkeyboard; 1604 chromeos::input_method::MockXKeyboard xkeyboard;
1605 EventRewriter rewriter; 1605 EventRewriter rewriter;
1606 rewriter.set_pref_service_for_testing(&prefs); 1606 rewriter.set_pref_service_for_testing(&prefs);
1607 rewriter.set_xkeyboard_for_testing(&xkeyboard); 1607 rewriter.set_xkeyboard_for_testing(&xkeyboard);
1608 EXPECT_FALSE(xkeyboard.caps_lock_is_enabled_); 1608 EXPECT_FALSE(xkeyboard.caps_lock_is_enabled_);
1609 1609
1610 // F16 should work as CapsLock even when --has-chromeos-keyboard is specified. 1610 // F16 should work as CapsLock even when --has-chromeos-keyboard is specified.
1611 const CommandLine original_cl(*CommandLine::ForCurrentProcess()); 1611 const CommandLine original_cl(*CommandLine::ForCurrentProcess());
(...skipping 11 matching lines...) Expand all
1623 0, 1623 0,
1624 ui::ET_KEY_PRESSED, 1624 ui::ET_KEY_PRESSED,
1625 keycode_launch7_, 1625 keycode_launch7_,
1626 0U)); 1626 0U));
1627 EXPECT_TRUE(xkeyboard.caps_lock_is_enabled_); 1627 EXPECT_TRUE(xkeyboard.caps_lock_is_enabled_);
1628 1628
1629 *CommandLine::ForCurrentProcess() = original_cl; 1629 *CommandLine::ForCurrentProcess() = original_cl;
1630 } 1630 }
1631 1631
1632 TEST_F(EventRewriterTest, TestRewriteCapsLockToControl) { 1632 TEST_F(EventRewriterTest, TestRewriteCapsLockToControl) {
1633 TestingPrefService prefs; 1633 TestingPrefServiceSyncable prefs;
1634 chromeos::Preferences::RegisterUserPrefs(&prefs); 1634 chromeos::Preferences::RegisterUserPrefs(&prefs);
1635 IntegerPrefMember control; 1635 IntegerPrefMember control;
1636 control.Init(prefs::kLanguageRemapCapsLockKeyTo, &prefs); 1636 control.Init(prefs::kLanguageRemapCapsLockKeyTo, &prefs);
1637 control.SetValue(chromeos::input_method::kControlKey); 1637 control.SetValue(chromeos::input_method::kControlKey);
1638 1638
1639 EventRewriter rewriter; 1639 EventRewriter rewriter;
1640 rewriter.set_pref_service_for_testing(&prefs); 1640 rewriter.set_pref_service_for_testing(&prefs);
1641 1641
1642 // Press CapsLock+a. Confirm that Mod3Mask is rewritten to ControlMask. 1642 // Press CapsLock+a. Confirm that Mod3Mask is rewritten to ControlMask.
1643 // On Chrome OS, CapsLock works as a Mod3 modifier. 1643 // On Chrome OS, CapsLock works as a Mod3 modifier.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1678 GetRewrittenEventAsString(&rewriter, 1678 GetRewrittenEventAsString(&rewriter,
1679 ui::VKEY_A, 1679 ui::VKEY_A,
1680 ui::EF_ALT_DOWN, 1680 ui::EF_ALT_DOWN,
1681 ui::ET_KEY_PRESSED, 1681 ui::ET_KEY_PRESSED,
1682 keycode_a_, 1682 keycode_a_,
1683 Mod1Mask | Mod3Mask)); 1683 Mod1Mask | Mod3Mask));
1684 } 1684 }
1685 1685
1686 TEST_F(EventRewriterTest, DISABLED_TestRewriteCapsLockToControlWithFlag) { 1686 TEST_F(EventRewriterTest, DISABLED_TestRewriteCapsLockToControlWithFlag) {
1687 // TODO(yusukes): Reenable the test once build servers are upgraded. 1687 // TODO(yusukes): Reenable the test once build servers are upgraded.
1688 TestingPrefService prefs; 1688 TestingPrefServiceSyncable prefs;
1689 chromeos::Preferences::RegisterUserPrefs(&prefs); 1689 chromeos::Preferences::RegisterUserPrefs(&prefs);
1690 IntegerPrefMember control; 1690 IntegerPrefMember control;
1691 control.Init(prefs::kLanguageRemapCapsLockKeyTo, &prefs); 1691 control.Init(prefs::kLanguageRemapCapsLockKeyTo, &prefs);
1692 control.SetValue(chromeos::input_method::kControlKey); 1692 control.SetValue(chromeos::input_method::kControlKey);
1693 1693
1694 EventRewriter rewriter; 1694 EventRewriter rewriter;
1695 rewriter.set_pref_service_for_testing(&prefs); 1695 rewriter.set_pref_service_for_testing(&prefs);
1696 1696
1697 // The prefs::kLanguageRemapCapsLockKeyTo pref should be ignored when 1697 // The prefs::kLanguageRemapCapsLockKeyTo pref should be ignored when
1698 // --has-chromeos-keyboard is set. 1698 // --has-chromeos-keyboard is set.
(...skipping 25 matching lines...) Expand all
1724 0, 1724 0,
1725 ui::ET_KEY_PRESSED, 1725 ui::ET_KEY_PRESSED,
1726 keycode_a_, 1726 keycode_a_,
1727 Mod3Mask)); 1727 Mod3Mask));
1728 1728
1729 *CommandLine::ForCurrentProcess() = original_cl; 1729 *CommandLine::ForCurrentProcess() = original_cl;
1730 } 1730 }
1731 1731
1732 TEST_F(EventRewriterTest, TestRewriteCapsLockMod3InUse) { 1732 TEST_F(EventRewriterTest, TestRewriteCapsLockMod3InUse) {
1733 // Remap CapsLock to Control. 1733 // Remap CapsLock to Control.
1734 TestingPrefService prefs; 1734 TestingPrefServiceSyncable prefs;
1735 chromeos::Preferences::RegisterUserPrefs(&prefs); 1735 chromeos::Preferences::RegisterUserPrefs(&prefs);
1736 IntegerPrefMember control; 1736 IntegerPrefMember control;
1737 control.Init(prefs::kLanguageRemapCapsLockKeyTo, &prefs); 1737 control.Init(prefs::kLanguageRemapCapsLockKeyTo, &prefs);
1738 control.SetValue(chromeos::input_method::kControlKey); 1738 control.SetValue(chromeos::input_method::kControlKey);
1739 1739
1740 EventRewriter rewriter; 1740 EventRewriter rewriter;
1741 rewriter.set_pref_service_for_testing(&prefs); 1741 rewriter.set_pref_service_for_testing(&prefs);
1742 input_method_manager_mock_->SetCurrentInputMethodId("xkb:de:neo:ger"); 1742 input_method_manager_mock_->SetCurrentInputMethodId("xkb:de:neo:ger");
1743 1743
1744 // Press CapsLock+a. Confirm that Mod3Mask is NOT rewritten to ControlMask 1744 // Press CapsLock+a. Confirm that Mod3Mask is NOT rewritten to ControlMask
1745 // when Mod3Mask is already in use by the current XKB layout. 1745 // when Mod3Mask is already in use by the current XKB layout.
1746 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_A, 1746 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_A,
1747 0, 1747 0,
1748 ui::ET_KEY_PRESSED, 1748 ui::ET_KEY_PRESSED,
1749 keycode_a_, 1749 keycode_a_,
1750 Mod3Mask, 1750 Mod3Mask,
1751 KeyPress), 1751 KeyPress),
1752 GetRewrittenEventAsString(&rewriter, 1752 GetRewrittenEventAsString(&rewriter,
1753 ui::VKEY_A, 1753 ui::VKEY_A,
1754 0, 1754 0,
1755 ui::ET_KEY_PRESSED, 1755 ui::ET_KEY_PRESSED,
1756 keycode_a_, 1756 keycode_a_,
1757 Mod3Mask)); 1757 Mod3Mask));
1758 1758
1759 input_method_manager_mock_->SetCurrentInputMethodId("xkb:us::eng"); 1759 input_method_manager_mock_->SetCurrentInputMethodId("xkb:us::eng");
1760 } 1760 }
1761 1761
1762 TEST_F(EventRewriterTest, TestRewriteExtendedKeys) { 1762 TEST_F(EventRewriterTest, TestRewriteExtendedKeys) {
1763 TestingPrefService prefs; 1763 TestingPrefServiceSyncable prefs;
1764 chromeos::Preferences::RegisterUserPrefs(&prefs); 1764 chromeos::Preferences::RegisterUserPrefs(&prefs);
1765 EventRewriter rewriter; 1765 EventRewriter rewriter;
1766 rewriter.set_pref_service_for_testing(&prefs); 1766 rewriter.set_pref_service_for_testing(&prefs);
1767 1767
1768 struct { 1768 struct {
1769 ui::KeyboardCode input; 1769 ui::KeyboardCode input;
1770 KeyCode input_native; 1770 KeyCode input_native;
1771 unsigned int input_mods; 1771 unsigned int input_mods;
1772 unsigned int input_native_mods; 1772 unsigned int input_native_mods;
1773 ui::KeyboardCode output; 1773 ui::KeyboardCode output;
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1897 chromeos_tests[i].input, 1897 chromeos_tests[i].input,
1898 chromeos_tests[i].input_mods, 1898 chromeos_tests[i].input_mods,
1899 ui::ET_KEY_PRESSED, 1899 ui::ET_KEY_PRESSED,
1900 chromeos_tests[i].input_native, 1900 chromeos_tests[i].input_native,
1901 chromeos_tests[i].input_native_mods)); 1901 chromeos_tests[i].input_native_mods));
1902 } 1902 }
1903 } 1903 }
1904 1904
1905 TEST_F(EventRewriterTest, TestRewriteFunctionKeys) { 1905 TEST_F(EventRewriterTest, TestRewriteFunctionKeys) {
1906 const CommandLine original_cl(*CommandLine::ForCurrentProcess()); 1906 const CommandLine original_cl(*CommandLine::ForCurrentProcess());
1907 TestingPrefService prefs; 1907 TestingPrefServiceSyncable prefs;
1908 chromeos::Preferences::RegisterUserPrefs(&prefs); 1908 chromeos::Preferences::RegisterUserPrefs(&prefs);
1909 EventRewriter rewriter; 1909 EventRewriter rewriter;
1910 rewriter.set_pref_service_for_testing(&prefs); 1910 rewriter.set_pref_service_for_testing(&prefs);
1911 1911
1912 struct { 1912 struct {
1913 ui::KeyboardCode input; 1913 ui::KeyboardCode input;
1914 KeyCode input_native; 1914 KeyCode input_native;
1915 unsigned int input_native_mods; 1915 unsigned int input_native_mods;
1916 unsigned int input_mods; 1916 unsigned int input_mods;
1917 ui::KeyboardCode output; 1917 ui::KeyboardCode output;
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
2116 ui::ET_KEY_PRESSED, 2116 ui::ET_KEY_PRESSED,
2117 tests[i].input_native, 2117 tests[i].input_native,
2118 tests[i].input_native_mods)); 2118 tests[i].input_native_mods));
2119 } 2119 }
2120 } 2120 }
2121 2121
2122 TEST_F(EventRewriterTest, TestRewriteExtendedKeysWithSearchRemapped) { 2122 TEST_F(EventRewriterTest, TestRewriteExtendedKeysWithSearchRemapped) {
2123 const CommandLine original_cl(*CommandLine::ForCurrentProcess()); 2123 const CommandLine original_cl(*CommandLine::ForCurrentProcess());
2124 2124
2125 // Remap Search to Control. 2125 // Remap Search to Control.
2126 TestingPrefService prefs; 2126 TestingPrefServiceSyncable prefs;
2127 chromeos::Preferences::RegisterUserPrefs(&prefs); 2127 chromeos::Preferences::RegisterUserPrefs(&prefs);
2128 IntegerPrefMember search; 2128 IntegerPrefMember search;
2129 search.Init(prefs::kLanguageRemapSearchKeyTo, &prefs); 2129 search.Init(prefs::kLanguageRemapSearchKeyTo, &prefs);
2130 search.SetValue(chromeos::input_method::kControlKey); 2130 search.SetValue(chromeos::input_method::kControlKey);
2131 2131
2132 EventRewriter rewriter; 2132 EventRewriter rewriter;
2133 rewriter.set_pref_service_for_testing(&prefs); 2133 rewriter.set_pref_service_for_testing(&prefs);
2134 2134
2135 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 2135 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
2136 switches::kHasChromeOSKeyboard, ""); 2136 switches::kHasChromeOSKeyboard, "");
(...skipping 24 matching lines...) Expand all
2161 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN, 2161 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN,
2162 ui::ET_KEY_PRESSED, 2162 ui::ET_KEY_PRESSED,
2163 keycode_down_, 2163 keycode_down_,
2164 ShiftMask | Mod1Mask | Mod4Mask)); 2164 ShiftMask | Mod1Mask | Mod4Mask));
2165 2165
2166 *CommandLine::ForCurrentProcess() = original_cl; 2166 *CommandLine::ForCurrentProcess() = original_cl;
2167 } 2167 }
2168 2168
2169 TEST_F(EventRewriterTest, TestRewriteKeyEventSentByXSendEvent) { 2169 TEST_F(EventRewriterTest, TestRewriteKeyEventSentByXSendEvent) {
2170 // Remap Control to Alt. 2170 // Remap Control to Alt.
2171 TestingPrefService prefs; 2171 TestingPrefServiceSyncable prefs;
2172 chromeos::Preferences::RegisterUserPrefs(&prefs); 2172 chromeos::Preferences::RegisterUserPrefs(&prefs);
2173 IntegerPrefMember control; 2173 IntegerPrefMember control;
2174 control.Init(prefs::kLanguageRemapControlKeyTo, &prefs); 2174 control.Init(prefs::kLanguageRemapControlKeyTo, &prefs);
2175 control.SetValue(chromeos::input_method::kAltKey); 2175 control.SetValue(chromeos::input_method::kAltKey);
2176 2176
2177 EventRewriter rewriter; 2177 EventRewriter rewriter;
2178 rewriter.set_pref_service_for_testing(&prefs); 2178 rewriter.set_pref_service_for_testing(&prefs);
2179 2179
2180 // Send left control press. 2180 // Send left control press.
2181 std::string rewritten_event; 2181 std::string rewritten_event;
(...skipping 15 matching lines...) Expand all
2197 // flag in the event is True. 2197 // flag in the event is True.
2198 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CONTROL, 2198 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CONTROL,
2199 ui::EF_CONTROL_DOWN, 2199 ui::EF_CONTROL_DOWN,
2200 ui::ET_KEY_PRESSED, 2200 ui::ET_KEY_PRESSED,
2201 keycode_control_l_, 2201 keycode_control_l_,
2202 0U, 2202 0U,
2203 KeyPress), 2203 KeyPress),
2204 rewritten_event); 2204 rewritten_event);
2205 } 2205 }
2206 #endif // OS_CHROMEOS 2206 #endif // OS_CHROMEOS
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/chrome_launcher_prefs.cc ('k') | chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698