OLD | NEW |
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 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 CheckKeyTestCase(&rewriter, tests[i]); | 515 CheckKeyTestCase(&rewriter, tests[i]); |
516 } | 516 } |
517 } | 517 } |
518 | 518 |
519 TEST_F(EventRewriterTest, TestRewriteNumPadKeys) { | 519 TEST_F(EventRewriterTest, TestRewriteNumPadKeys) { |
520 TestRewriteNumPadKeys(); | 520 TestRewriteNumPadKeys(); |
521 } | 521 } |
522 | 522 |
523 TEST_F(EventRewriterTest, TestRewriteNumPadKeysWithDiamondKeyFlag) { | 523 TEST_F(EventRewriterTest, TestRewriteNumPadKeysWithDiamondKeyFlag) { |
524 // Make sure the num lock works correctly even when Diamond key exists. | 524 // Make sure the num lock works correctly even when Diamond key exists. |
525 const CommandLine original_cl(*CommandLine::ForCurrentProcess()); | 525 const base::CommandLine original_cl(*base::CommandLine::ForCurrentProcess()); |
526 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 526 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
527 chromeos::switches::kHasChromeOSDiamondKey, ""); | 527 chromeos::switches::kHasChromeOSDiamondKey, ""); |
528 | 528 |
529 TestRewriteNumPadKeys(); | 529 TestRewriteNumPadKeys(); |
530 *CommandLine::ForCurrentProcess() = original_cl; | 530 *base::CommandLine::ForCurrentProcess() = original_cl; |
531 } | 531 } |
532 | 532 |
533 // Tests if the rewriter can handle a Command + Num Pad event. | 533 // Tests if the rewriter can handle a Command + Num Pad event. |
534 void EventRewriterTest::TestRewriteNumPadKeysOnAppleKeyboard() { | 534 void EventRewriterTest::TestRewriteNumPadKeysOnAppleKeyboard() { |
535 TestingPrefServiceSyncable prefs; | 535 TestingPrefServiceSyncable prefs; |
536 EventRewriter rewriter(NULL); | 536 EventRewriter rewriter(NULL); |
537 rewriter.KeyboardDeviceAddedForTesting(kKeyboardDeviceId, "Apple Keyboard"); | 537 rewriter.KeyboardDeviceAddedForTesting(kKeyboardDeviceId, "Apple Keyboard"); |
538 rewriter.set_last_keyboard_device_id_for_testing(kKeyboardDeviceId); | 538 rewriter.set_last_keyboard_device_id_for_testing(kKeyboardDeviceId); |
539 rewriter.set_pref_service_for_testing(&prefs); | 539 rewriter.set_pref_service_for_testing(&prefs); |
540 | 540 |
(...skipping 18 matching lines...) Expand all Loading... |
559 } | 559 } |
560 } | 560 } |
561 | 561 |
562 TEST_F(EventRewriterTest, TestRewriteNumPadKeysOnAppleKeyboard) { | 562 TEST_F(EventRewriterTest, TestRewriteNumPadKeysOnAppleKeyboard) { |
563 TestRewriteNumPadKeysOnAppleKeyboard(); | 563 TestRewriteNumPadKeysOnAppleKeyboard(); |
564 } | 564 } |
565 | 565 |
566 TEST_F(EventRewriterTest, | 566 TEST_F(EventRewriterTest, |
567 TestRewriteNumPadKeysOnAppleKeyboardWithDiamondKeyFlag) { | 567 TestRewriteNumPadKeysOnAppleKeyboardWithDiamondKeyFlag) { |
568 // Makes sure the num lock works correctly even when Diamond key exists. | 568 // Makes sure the num lock works correctly even when Diamond key exists. |
569 const CommandLine original_cl(*CommandLine::ForCurrentProcess()); | 569 const base::CommandLine original_cl(*base::CommandLine::ForCurrentProcess()); |
570 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 570 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
571 chromeos::switches::kHasChromeOSDiamondKey, ""); | 571 chromeos::switches::kHasChromeOSDiamondKey, ""); |
572 | 572 |
573 TestRewriteNumPadKeysOnAppleKeyboard(); | 573 TestRewriteNumPadKeysOnAppleKeyboard(); |
574 *CommandLine::ForCurrentProcess() = original_cl; | 574 *base::CommandLine::ForCurrentProcess() = original_cl; |
575 } | 575 } |
576 | 576 |
577 TEST_F(EventRewriterTest, TestRewriteModifiersNoRemap) { | 577 TEST_F(EventRewriterTest, TestRewriteModifiersNoRemap) { |
578 TestingPrefServiceSyncable prefs; | 578 TestingPrefServiceSyncable prefs; |
579 EventRewriter rewriter(NULL); | 579 EventRewriter rewriter(NULL); |
580 rewriter.KeyboardDeviceAddedForTesting(kKeyboardDeviceId, "PC Keyboard"); | 580 rewriter.KeyboardDeviceAddedForTesting(kKeyboardDeviceId, "PC Keyboard"); |
581 rewriter.set_pref_service_for_testing(&prefs); | 581 rewriter.set_pref_service_for_testing(&prefs); |
582 | 582 |
583 KeyTestCase tests[] = { | 583 KeyTestCase tests[] = { |
584 // Press Search. Confirm the event is not rewritten. | 584 // Press Search. Confirm the event is not rewritten. |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1043 {ui::VKEY_A, ui::EF_NONE}}, | 1043 {ui::VKEY_A, ui::EF_NONE}}, |
1044 }; | 1044 }; |
1045 | 1045 |
1046 for (size_t i = 0; i < arraysize(tests); ++i) { | 1046 for (size_t i = 0; i < arraysize(tests); ++i) { |
1047 SCOPED_TRACE(i); | 1047 SCOPED_TRACE(i); |
1048 CheckKeyTestCase(&rewriter, tests[i]); | 1048 CheckKeyTestCase(&rewriter, tests[i]); |
1049 } | 1049 } |
1050 } | 1050 } |
1051 | 1051 |
1052 TEST_F(EventRewriterTest, TestRewriteDiamondKeyWithFlag) { | 1052 TEST_F(EventRewriterTest, TestRewriteDiamondKeyWithFlag) { |
1053 const CommandLine original_cl(*CommandLine::ForCurrentProcess()); | 1053 const base::CommandLine original_cl(*base::CommandLine::ForCurrentProcess()); |
1054 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 1054 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
1055 chromeos::switches::kHasChromeOSDiamondKey, ""); | 1055 chromeos::switches::kHasChromeOSDiamondKey, ""); |
1056 | 1056 |
1057 TestingPrefServiceSyncable prefs; | 1057 TestingPrefServiceSyncable prefs; |
1058 chromeos::Preferences::RegisterProfilePrefs(prefs.registry()); | 1058 chromeos::Preferences::RegisterProfilePrefs(prefs.registry()); |
1059 | 1059 |
1060 chromeos::input_method::FakeImeKeyboard ime_keyboard; | 1060 chromeos::input_method::FakeImeKeyboard ime_keyboard; |
1061 EventRewriter rewriter(NULL); | 1061 EventRewriter rewriter(NULL); |
1062 rewriter.KeyboardDeviceAddedForTesting(kKeyboardDeviceId, "PC Keyboard"); | 1062 rewriter.KeyboardDeviceAddedForTesting(kKeyboardDeviceId, "PC Keyboard"); |
1063 rewriter.set_pref_service_for_testing(&prefs); | 1063 rewriter.set_pref_service_for_testing(&prefs); |
1064 rewriter.set_ime_keyboard_for_testing(&ime_keyboard); | 1064 rewriter.set_ime_keyboard_for_testing(&ime_keyboard); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1159 EXPECT_EQ(GetExpectedResultAsString( | 1159 EXPECT_EQ(GetExpectedResultAsString( |
1160 ui::VKEY_CAPITAL, ui::EF_NONE, ui::ET_KEY_RELEASED), | 1160 ui::VKEY_CAPITAL, ui::EF_NONE, ui::ET_KEY_RELEASED), |
1161 GetRewrittenEventAsString( | 1161 GetRewrittenEventAsString( |
1162 &rewriter, ui::VKEY_F15, ui::EF_NONE, ui::ET_KEY_RELEASED)); | 1162 &rewriter, ui::VKEY_F15, ui::EF_NONE, ui::ET_KEY_RELEASED)); |
1163 // Check that Control is no longer applied to a subsequent key press. | 1163 // Check that Control is no longer applied to a subsequent key press. |
1164 EXPECT_EQ( | 1164 EXPECT_EQ( |
1165 GetExpectedResultAsString(ui::VKEY_A, ui::EF_NONE, ui::ET_KEY_PRESSED), | 1165 GetExpectedResultAsString(ui::VKEY_A, ui::EF_NONE, ui::ET_KEY_PRESSED), |
1166 GetRewrittenEventAsString( | 1166 GetRewrittenEventAsString( |
1167 &rewriter, ui::VKEY_A, ui::EF_NONE, ui::ET_KEY_PRESSED)); | 1167 &rewriter, ui::VKEY_A, ui::EF_NONE, ui::ET_KEY_PRESSED)); |
1168 | 1168 |
1169 *CommandLine::ForCurrentProcess() = original_cl; | 1169 *base::CommandLine::ForCurrentProcess() = original_cl; |
1170 } | 1170 } |
1171 | 1171 |
1172 TEST_F(EventRewriterTest, TestRewriteCapsLockToControl) { | 1172 TEST_F(EventRewriterTest, TestRewriteCapsLockToControl) { |
1173 // Remap CapsLock to Control. | 1173 // Remap CapsLock to Control. |
1174 TestingPrefServiceSyncable prefs; | 1174 TestingPrefServiceSyncable prefs; |
1175 chromeos::Preferences::RegisterProfilePrefs(prefs.registry()); | 1175 chromeos::Preferences::RegisterProfilePrefs(prefs.registry()); |
1176 IntegerPrefMember control; | 1176 IntegerPrefMember control; |
1177 control.Init(prefs::kLanguageRemapCapsLockKeyTo, &prefs); | 1177 control.Init(prefs::kLanguageRemapCapsLockKeyTo, &prefs); |
1178 control.SetValue(chromeos::input_method::kControlKey); | 1178 control.SetValue(chromeos::input_method::kControlKey); |
1179 | 1179 |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1657 {ui::VKEY_F12, ui::EF_FUNCTION_KEY}}, | 1657 {ui::VKEY_F12, ui::EF_FUNCTION_KEY}}, |
1658 }; | 1658 }; |
1659 | 1659 |
1660 for (size_t i = 0; i < arraysize(tests); ++i) { | 1660 for (size_t i = 0; i < arraysize(tests); ++i) { |
1661 SCOPED_TRACE(i); | 1661 SCOPED_TRACE(i); |
1662 CheckFunctionKeyTestCase(&rewriter, tests[i]); | 1662 CheckFunctionKeyTestCase(&rewriter, tests[i]); |
1663 } | 1663 } |
1664 } | 1664 } |
1665 | 1665 |
1666 TEST_F(EventRewriterTest, TestRewriteExtendedKeysWithSearchRemapped) { | 1666 TEST_F(EventRewriterTest, TestRewriteExtendedKeysWithSearchRemapped) { |
1667 const CommandLine original_cl(*CommandLine::ForCurrentProcess()); | 1667 const base::CommandLine original_cl(*base::CommandLine::ForCurrentProcess()); |
1668 | 1668 |
1669 // Remap Search to Control. | 1669 // Remap Search to Control. |
1670 TestingPrefServiceSyncable prefs; | 1670 TestingPrefServiceSyncable prefs; |
1671 chromeos::Preferences::RegisterProfilePrefs(prefs.registry()); | 1671 chromeos::Preferences::RegisterProfilePrefs(prefs.registry()); |
1672 IntegerPrefMember search; | 1672 IntegerPrefMember search; |
1673 search.Init(prefs::kLanguageRemapSearchKeyTo, &prefs); | 1673 search.Init(prefs::kLanguageRemapSearchKeyTo, &prefs); |
1674 search.SetValue(chromeos::input_method::kControlKey); | 1674 search.SetValue(chromeos::input_method::kControlKey); |
1675 | 1675 |
1676 EventRewriter rewriter(NULL); | 1676 EventRewriter rewriter(NULL); |
1677 rewriter.KeyboardDeviceAddedForTesting(kKeyboardDeviceId, "PC Keyboard"); | 1677 rewriter.KeyboardDeviceAddedForTesting(kKeyboardDeviceId, "PC Keyboard"); |
1678 rewriter.set_pref_service_for_testing(&prefs); | 1678 rewriter.set_pref_service_for_testing(&prefs); |
1679 | 1679 |
1680 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 1680 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
1681 chromeos::switches::kHasChromeOSKeyboard, ""); | 1681 chromeos::switches::kHasChromeOSKeyboard, ""); |
1682 | 1682 |
1683 KeyTestCase tests[] = { | 1683 KeyTestCase tests[] = { |
1684 // Alt+Search+Down -> End | 1684 // Alt+Search+Down -> End |
1685 {KeyTestCase::TEST_ALL, ui::ET_KEY_PRESSED, | 1685 {KeyTestCase::TEST_ALL, ui::ET_KEY_PRESSED, |
1686 {ui::VKEY_DOWN, ui::EF_ALT_DOWN | ui::EF_COMMAND_DOWN}, | 1686 {ui::VKEY_DOWN, ui::EF_ALT_DOWN | ui::EF_COMMAND_DOWN}, |
1687 {ui::VKEY_END, ui::EF_NONE}}, | 1687 {ui::VKEY_END, ui::EF_NONE}}, |
1688 | 1688 |
1689 // Shift+Alt+Search+Down -> Shift+End | 1689 // Shift+Alt+Search+Down -> Shift+End |
1690 {KeyTestCase::TEST_ALL, ui::ET_KEY_PRESSED, | 1690 {KeyTestCase::TEST_ALL, ui::ET_KEY_PRESSED, |
1691 {ui::VKEY_DOWN, | 1691 {ui::VKEY_DOWN, |
1692 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN | ui::EF_COMMAND_DOWN}, | 1692 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN | ui::EF_COMMAND_DOWN}, |
1693 {ui::VKEY_END, ui::EF_SHIFT_DOWN}}, | 1693 {ui::VKEY_END, ui::EF_SHIFT_DOWN}}, |
1694 }; | 1694 }; |
1695 | 1695 |
1696 for (size_t i = 0; i < arraysize(tests); ++i) { | 1696 for (size_t i = 0; i < arraysize(tests); ++i) { |
1697 SCOPED_TRACE(i); | 1697 SCOPED_TRACE(i); |
1698 CheckKeyTestCase(&rewriter, tests[i]); | 1698 CheckKeyTestCase(&rewriter, tests[i]); |
1699 } | 1699 } |
1700 | 1700 |
1701 *CommandLine::ForCurrentProcess() = original_cl; | 1701 *base::CommandLine::ForCurrentProcess() = original_cl; |
1702 } | 1702 } |
1703 | 1703 |
1704 TEST_F(EventRewriterTest, TestRewriteKeyEventSentByXSendEvent) { | 1704 TEST_F(EventRewriterTest, TestRewriteKeyEventSentByXSendEvent) { |
1705 // Remap Control to Alt. | 1705 // Remap Control to Alt. |
1706 TestingPrefServiceSyncable prefs; | 1706 TestingPrefServiceSyncable prefs; |
1707 chromeos::Preferences::RegisterProfilePrefs(prefs.registry()); | 1707 chromeos::Preferences::RegisterProfilePrefs(prefs.registry()); |
1708 IntegerPrefMember control; | 1708 IntegerPrefMember control; |
1709 control.Init(prefs::kLanguageRemapControlKeyTo, &prefs); | 1709 control.Init(prefs::kLanguageRemapControlKeyTo, &prefs); |
1710 control.SetValue(chromeos::input_method::kAltKey); | 1710 control.SetValue(chromeos::input_method::kAltKey); |
1711 | 1711 |
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2487 EXPECT_FALSE(overlay_->GetModifierVisible(ui::EF_ALTGR_DOWN)); | 2487 EXPECT_FALSE(overlay_->GetModifierVisible(ui::EF_ALTGR_DOWN)); |
2488 EXPECT_TRUE(overlay_->GetModifierVisible(ui::EF_MOD3_DOWN)); | 2488 EXPECT_TRUE(overlay_->GetModifierVisible(ui::EF_MOD3_DOWN)); |
2489 | 2489 |
2490 // Turn off AltGr and Mod3. | 2490 // Turn off AltGr and Mod3. |
2491 sticky_keys_controller_->SetModifiersEnabled(false, false); | 2491 sticky_keys_controller_->SetModifiersEnabled(false, false); |
2492 EXPECT_FALSE(overlay_->GetModifierVisible(ui::EF_ALTGR_DOWN)); | 2492 EXPECT_FALSE(overlay_->GetModifierVisible(ui::EF_ALTGR_DOWN)); |
2493 EXPECT_FALSE(overlay_->GetModifierVisible(ui::EF_MOD3_DOWN)); | 2493 EXPECT_FALSE(overlay_->GetModifierVisible(ui::EF_MOD3_DOWN)); |
2494 } | 2494 } |
2495 | 2495 |
2496 } // namespace chromeos | 2496 } // namespace chromeos |
OLD | NEW |