OLD | NEW |
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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 keycode_delete_(XKeysymToKeycode(display_, XK_Delete)), | 110 keycode_delete_(XKeysymToKeycode(display_, XK_Delete)), |
111 keycode_backspace_(XKeysymToKeycode(display_, XK_BackSpace)), | 111 keycode_backspace_(XKeysymToKeycode(display_, XK_BackSpace)), |
112 keycode_up_(XKeysymToKeycode(display_, XK_Up)), | 112 keycode_up_(XKeysymToKeycode(display_, XK_Up)), |
113 keycode_down_(XKeysymToKeycode(display_, XK_Down)), | 113 keycode_down_(XKeysymToKeycode(display_, XK_Down)), |
114 keycode_left_(XKeysymToKeycode(display_, XK_Left)), | 114 keycode_left_(XKeysymToKeycode(display_, XK_Left)), |
115 keycode_right_(XKeysymToKeycode(display_, XK_Right)), | 115 keycode_right_(XKeysymToKeycode(display_, XK_Right)), |
116 keycode_prior_(XKeysymToKeycode(display_, XK_Prior)), | 116 keycode_prior_(XKeysymToKeycode(display_, XK_Prior)), |
117 keycode_next_(XKeysymToKeycode(display_, XK_Next)), | 117 keycode_next_(XKeysymToKeycode(display_, XK_Next)), |
118 keycode_home_(XKeysymToKeycode(display_, XK_Home)), | 118 keycode_home_(XKeysymToKeycode(display_, XK_Home)), |
119 keycode_end_(XKeysymToKeycode(display_, XK_End)), | 119 keycode_end_(XKeysymToKeycode(display_, XK_End)), |
| 120 keycode_launch6_(XKeysymToKeycode(display_, XF86XK_Launch6)), |
120 keycode_launch7_(XKeysymToKeycode(display_, XF86XK_Launch7)), | 121 keycode_launch7_(XKeysymToKeycode(display_, XF86XK_Launch7)), |
121 keycode_f1_(XKeysymToKeycode(display_, XK_F1)), | 122 keycode_f1_(XKeysymToKeycode(display_, XK_F1)), |
122 keycode_f2_(XKeysymToKeycode(display_, XK_F2)), | 123 keycode_f2_(XKeysymToKeycode(display_, XK_F2)), |
123 keycode_f3_(XKeysymToKeycode(display_, XK_F3)), | 124 keycode_f3_(XKeysymToKeycode(display_, XK_F3)), |
124 keycode_f4_(XKeysymToKeycode(display_, XK_F4)), | 125 keycode_f4_(XKeysymToKeycode(display_, XK_F4)), |
125 keycode_f5_(XKeysymToKeycode(display_, XK_F5)), | 126 keycode_f5_(XKeysymToKeycode(display_, XK_F5)), |
126 keycode_f6_(XKeysymToKeycode(display_, XK_F6)), | 127 keycode_f6_(XKeysymToKeycode(display_, XK_F6)), |
127 keycode_f7_(XKeysymToKeycode(display_, XK_F7)), | 128 keycode_f7_(XKeysymToKeycode(display_, XK_F7)), |
128 keycode_f8_(XKeysymToKeycode(display_, XK_F8)), | 129 keycode_f8_(XKeysymToKeycode(display_, XK_F8)), |
129 keycode_f9_(XKeysymToKeycode(display_, XK_F9)), | 130 keycode_f9_(XKeysymToKeycode(display_, XK_F9)), |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 chromeos::input_method::InitializeForTesting( | 173 chromeos::input_method::InitializeForTesting( |
173 input_method_manager_mock_); // pass ownership | 174 input_method_manager_mock_); // pass ownership |
174 } | 175 } |
175 | 176 |
176 virtual void TearDown() { | 177 virtual void TearDown() { |
177 // Shutdown() deletes the IME mock object. | 178 // Shutdown() deletes the IME mock object. |
178 chromeos::input_method::Shutdown(); | 179 chromeos::input_method::Shutdown(); |
179 } | 180 } |
180 | 181 |
181 protected: | 182 protected: |
| 183 void TestRewriteNumPadKeys(); |
| 184 void TestRewriteNumPadKeysOnAppleKeyboard(); |
| 185 |
182 Display* display_; | 186 Display* display_; |
183 const KeyCode keycode_a_; | 187 const KeyCode keycode_a_; |
184 const KeyCode keycode_alt_l_; | 188 const KeyCode keycode_alt_l_; |
185 const KeyCode keycode_alt_r_; | 189 const KeyCode keycode_alt_r_; |
186 const KeyCode keycode_b_; | 190 const KeyCode keycode_b_; |
187 const KeyCode keycode_caps_lock_; | 191 const KeyCode keycode_caps_lock_; |
188 const KeyCode keycode_control_l_; | 192 const KeyCode keycode_control_l_; |
189 const KeyCode keycode_control_r_; | 193 const KeyCode keycode_control_r_; |
190 const KeyCode keycode_meta_l_; | 194 const KeyCode keycode_meta_l_; |
191 const KeyCode keycode_meta_r_; | 195 const KeyCode keycode_meta_r_; |
(...skipping 25 matching lines...) Expand all Loading... |
217 const KeyCode keycode_delete_; | 221 const KeyCode keycode_delete_; |
218 const KeyCode keycode_backspace_; | 222 const KeyCode keycode_backspace_; |
219 const KeyCode keycode_up_; | 223 const KeyCode keycode_up_; |
220 const KeyCode keycode_down_; | 224 const KeyCode keycode_down_; |
221 const KeyCode keycode_left_; | 225 const KeyCode keycode_left_; |
222 const KeyCode keycode_right_; | 226 const KeyCode keycode_right_; |
223 const KeyCode keycode_prior_; | 227 const KeyCode keycode_prior_; |
224 const KeyCode keycode_next_; | 228 const KeyCode keycode_next_; |
225 const KeyCode keycode_home_; | 229 const KeyCode keycode_home_; |
226 const KeyCode keycode_end_; | 230 const KeyCode keycode_end_; |
| 231 const KeyCode keycode_launch6_; // F15 |
227 const KeyCode keycode_launch7_; // F16 | 232 const KeyCode keycode_launch7_; // F16 |
228 const KeyCode keycode_f1_; | 233 const KeyCode keycode_f1_; |
229 const KeyCode keycode_f2_; | 234 const KeyCode keycode_f2_; |
230 const KeyCode keycode_f3_; | 235 const KeyCode keycode_f3_; |
231 const KeyCode keycode_f4_; | 236 const KeyCode keycode_f4_; |
232 const KeyCode keycode_f5_; | 237 const KeyCode keycode_f5_; |
233 const KeyCode keycode_f6_; | 238 const KeyCode keycode_f6_; |
234 const KeyCode keycode_f7_; | 239 const KeyCode keycode_f7_; |
235 const KeyCode keycode_f8_; | 240 const KeyCode keycode_f8_; |
236 const KeyCode keycode_f9_; | 241 const KeyCode keycode_f9_; |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 Mod1Mask, | 543 Mod1Mask, |
539 KeyPress), | 544 KeyPress), |
540 GetRewrittenEventAsString(&rewriter, | 545 GetRewrittenEventAsString(&rewriter, |
541 ui::VKEY_RWIN, | 546 ui::VKEY_RWIN, |
542 ui::EF_ALT_DOWN, | 547 ui::EF_ALT_DOWN, |
543 ui::ET_KEY_PRESSED, | 548 ui::ET_KEY_PRESSED, |
544 keycode_super_r_, | 549 keycode_super_r_, |
545 Mod1Mask)); | 550 Mod1Mask)); |
546 } | 551 } |
547 | 552 |
548 TEST_F(EventRewriterTest, TestRewriteNumPadKeys) { | 553 void EventRewriterTest::TestRewriteNumPadKeys() { |
549 TestingPrefServiceSyncable prefs; | 554 TestingPrefServiceSyncable prefs; |
550 EventRewriter rewriter; | 555 EventRewriter rewriter; |
551 rewriter.set_pref_service_for_testing(&prefs); | 556 rewriter.set_pref_service_for_testing(&prefs); |
552 | 557 |
553 // XK_KP_Insert (= NumPad 0 without Num Lock), no modifier. | 558 // XK_KP_Insert (= NumPad 0 without Num Lock), no modifier. |
554 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_NUMPAD0, | 559 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_NUMPAD0, |
555 0, | 560 0, |
556 ui::ET_KEY_PRESSED, | 561 ui::ET_KEY_PRESSED, |
557 keycode_num_pad_0_, | 562 keycode_num_pad_0_, |
558 Mod2Mask, // Num Lock | 563 Mod2Mask, // Num Lock |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 Mod2Mask, | 871 Mod2Mask, |
867 KeyPress), | 872 KeyPress), |
868 GetRewrittenEventAsString(&rewriter, | 873 GetRewrittenEventAsString(&rewriter, |
869 ui::VKEY_NUMPAD9, | 874 ui::VKEY_NUMPAD9, |
870 0, | 875 0, |
871 ui::ET_KEY_PRESSED, | 876 ui::ET_KEY_PRESSED, |
872 keycode_num_pad_9_, | 877 keycode_num_pad_9_, |
873 Mod2Mask)); | 878 Mod2Mask)); |
874 } | 879 } |
875 | 880 |
| 881 TEST_F(EventRewriterTest, TestRewriteNumPadKeys) { |
| 882 TestRewriteNumPadKeys(); |
| 883 } |
| 884 |
| 885 TEST_F(EventRewriterTest, TestRewriteNumPadKeysWithDiamondKeyFlag) { |
| 886 // Make sure the num lock works correctly even when Diamond key exists. |
| 887 const CommandLine original_cl(*CommandLine::ForCurrentProcess()); |
| 888 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 889 switches::kHasChromeOSDiamondKey, ""); |
| 890 |
| 891 TestRewriteNumPadKeys(); |
| 892 } |
| 893 |
876 // Tests if the rewriter can handle a Command + Num Pad event. | 894 // Tests if the rewriter can handle a Command + Num Pad event. |
877 TEST_F(EventRewriterTest, TestRewriteNumPadKeysOnAppleKeyboard) { | 895 void EventRewriterTest::TestRewriteNumPadKeysOnAppleKeyboard() { |
878 TestingPrefServiceSyncable prefs; | 896 TestingPrefServiceSyncable prefs; |
879 EventRewriter rewriter; | 897 EventRewriter rewriter; |
880 rewriter.DeviceAddedForTesting(0, "Apple Keyboard"); | 898 rewriter.DeviceAddedForTesting(0, "Apple Keyboard"); |
881 rewriter.set_last_device_id_for_testing(0); | 899 rewriter.set_last_device_id_for_testing(0); |
882 rewriter.set_pref_service_for_testing(&prefs); | 900 rewriter.set_pref_service_for_testing(&prefs); |
883 | 901 |
884 // XK_KP_End (= NumPad 1 without Num Lock), Win modifier. | 902 // XK_KP_End (= NumPad 1 without Num Lock), Win modifier. |
885 // The result should be "Num Pad 1 with Control + Num Lock modifiers". | 903 // The result should be "Num Pad 1 with Control + Num Lock modifiers". |
886 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_NUMPAD1, | 904 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_NUMPAD1, |
887 ui::EF_CONTROL_DOWN, | 905 ui::EF_CONTROL_DOWN, |
(...skipping 17 matching lines...) Expand all Loading... |
905 ControlMask | Mod2Mask, | 923 ControlMask | Mod2Mask, |
906 KeyPress), | 924 KeyPress), |
907 GetRewrittenEventAsString(&rewriter, | 925 GetRewrittenEventAsString(&rewriter, |
908 ui::VKEY_NUMPAD1, | 926 ui::VKEY_NUMPAD1, |
909 0, | 927 0, |
910 ui::ET_KEY_PRESSED, | 928 ui::ET_KEY_PRESSED, |
911 keycode_num_pad_end_, | 929 keycode_num_pad_end_, |
912 Mod4Mask)); | 930 Mod4Mask)); |
913 } | 931 } |
914 | 932 |
| 933 TEST_F(EventRewriterTest, TestRewriteNumPadKeysOnAppleKeyboard) { |
| 934 TestRewriteNumPadKeysOnAppleKeyboard(); |
| 935 } |
| 936 |
| 937 TEST_F(EventRewriterTest, |
| 938 TestRewriteNumPadKeysOnAppleKeyboardWithDiamondKeyFlag) { |
| 939 // Makes sure the num lock works correctly even when Diamond key exists. |
| 940 const CommandLine original_cl(*CommandLine::ForCurrentProcess()); |
| 941 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 942 switches::kHasChromeOSDiamondKey, ""); |
| 943 |
| 944 TestRewriteNumPadKeysOnAppleKeyboard(); |
| 945 } |
| 946 |
915 TEST_F(EventRewriterTest, TestRewriteModifiersNoRemap) { | 947 TEST_F(EventRewriterTest, TestRewriteModifiersNoRemap) { |
916 TestingPrefServiceSyncable prefs; | 948 TestingPrefServiceSyncable prefs; |
917 EventRewriter rewriter; | 949 EventRewriter rewriter; |
918 rewriter.set_pref_service_for_testing(&prefs); | 950 rewriter.set_pref_service_for_testing(&prefs); |
919 | 951 |
920 // Press Search. Confirm the event is not rewritten. | 952 // Press Search. Confirm the event is not rewritten. |
921 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_LWIN, | 953 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_LWIN, |
922 0, | 954 0, |
923 ui::ET_KEY_PRESSED, | 955 ui::ET_KEY_PRESSED, |
924 keycode_super_l_, | 956 keycode_super_l_, |
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1622 ui::VKEY_F16, | 1654 ui::VKEY_F16, |
1623 0, | 1655 0, |
1624 ui::ET_KEY_PRESSED, | 1656 ui::ET_KEY_PRESSED, |
1625 keycode_launch7_, | 1657 keycode_launch7_, |
1626 0U)); | 1658 0U)); |
1627 EXPECT_TRUE(xkeyboard.caps_lock_is_enabled_); | 1659 EXPECT_TRUE(xkeyboard.caps_lock_is_enabled_); |
1628 | 1660 |
1629 *CommandLine::ForCurrentProcess() = original_cl; | 1661 *CommandLine::ForCurrentProcess() = original_cl; |
1630 } | 1662 } |
1631 | 1663 |
| 1664 TEST_F(EventRewriterTest, DISABLED_TestRewriteDiamondKey) { |
| 1665 // TODO(yusukes): Reenable the test once build servers are upgraded. |
| 1666 |
| 1667 TestingPrefServiceSyncable prefs; |
| 1668 chromeos::Preferences::RegisterUserPrefs(&prefs); |
| 1669 |
| 1670 chromeos::input_method::MockXKeyboard xkeyboard; |
| 1671 EventRewriter rewriter; |
| 1672 rewriter.set_pref_service_for_testing(&prefs); |
| 1673 rewriter.set_xkeyboard_for_testing(&xkeyboard); |
| 1674 |
| 1675 // F15 should work as Ctrl when --has-chromeos-diamond-key is not specified. |
| 1676 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CONTROL, |
| 1677 ui::EF_CONTROL_DOWN, |
| 1678 ui::ET_KEY_PRESSED, |
| 1679 keycode_control_l_, |
| 1680 0U, |
| 1681 KeyPress), |
| 1682 GetRewrittenEventAsString(&rewriter, |
| 1683 ui::VKEY_F15, |
| 1684 0, |
| 1685 ui::ET_KEY_PRESSED, |
| 1686 keycode_launch6_, |
| 1687 0U)); |
| 1688 } |
| 1689 |
| 1690 TEST_F(EventRewriterTest, DISABLED_TestRewriteDiamondKeyWithFlag) { |
| 1691 // TODO(yusukes): Reenable the test once build servers are upgraded. |
| 1692 |
| 1693 const CommandLine original_cl(*CommandLine::ForCurrentProcess()); |
| 1694 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 1695 switches::kHasChromeOSDiamondKey, ""); |
| 1696 |
| 1697 TestingPrefServiceSyncable prefs; |
| 1698 chromeos::Preferences::RegisterUserPrefs(&prefs); |
| 1699 |
| 1700 chromeos::input_method::MockXKeyboard xkeyboard; |
| 1701 EventRewriter rewriter; |
| 1702 rewriter.set_pref_service_for_testing(&prefs); |
| 1703 rewriter.set_xkeyboard_for_testing(&xkeyboard); |
| 1704 |
| 1705 // By default, F15 should work as Control. |
| 1706 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CONTROL, |
| 1707 ui::EF_CONTROL_DOWN, |
| 1708 ui::ET_KEY_PRESSED, |
| 1709 keycode_control_l_, |
| 1710 0U, |
| 1711 KeyPress), |
| 1712 GetRewrittenEventAsString(&rewriter, |
| 1713 ui::VKEY_F15, |
| 1714 0, |
| 1715 ui::ET_KEY_PRESSED, |
| 1716 keycode_launch6_, |
| 1717 0U)); |
| 1718 |
| 1719 IntegerPrefMember diamond; |
| 1720 diamond.Init(prefs::kLanguageRemapDiamondKeyTo, &prefs); |
| 1721 diamond.SetValue(chromeos::input_method::kVoidKey); |
| 1722 |
| 1723 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_UNKNOWN, |
| 1724 0, |
| 1725 ui::ET_KEY_PRESSED, |
| 1726 keycode_void_symbol_, |
| 1727 0U, |
| 1728 KeyPress), |
| 1729 GetRewrittenEventAsString(&rewriter, |
| 1730 ui::VKEY_F15, |
| 1731 0, |
| 1732 ui::ET_KEY_PRESSED, |
| 1733 keycode_launch6_, |
| 1734 0U)); |
| 1735 |
| 1736 diamond.SetValue(chromeos::input_method::kControlKey); |
| 1737 |
| 1738 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CONTROL, |
| 1739 ui::EF_CONTROL_DOWN, |
| 1740 ui::ET_KEY_PRESSED, |
| 1741 keycode_control_l_, |
| 1742 0U, |
| 1743 KeyPress), |
| 1744 GetRewrittenEventAsString(&rewriter, |
| 1745 ui::VKEY_F15, |
| 1746 0, |
| 1747 ui::ET_KEY_PRESSED, |
| 1748 keycode_launch6_, |
| 1749 0U)); |
| 1750 |
| 1751 diamond.SetValue(chromeos::input_method::kAltKey); |
| 1752 |
| 1753 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_MENU, |
| 1754 ui::EF_ALT_DOWN, |
| 1755 ui::ET_KEY_PRESSED, |
| 1756 keycode_alt_l_, |
| 1757 0, |
| 1758 KeyPress), |
| 1759 GetRewrittenEventAsString(&rewriter, |
| 1760 ui::VKEY_F15, |
| 1761 0, |
| 1762 ui::ET_KEY_PRESSED, |
| 1763 keycode_launch6_, |
| 1764 0U)); |
| 1765 |
| 1766 diamond.SetValue(chromeos::input_method::kCapsLockKey); |
| 1767 |
| 1768 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CAPITAL, |
| 1769 ui::EF_CAPS_LOCK_DOWN, |
| 1770 ui::ET_KEY_PRESSED, |
| 1771 keycode_caps_lock_, |
| 1772 0U, |
| 1773 KeyPress), |
| 1774 GetRewrittenEventAsString(&rewriter, |
| 1775 ui::VKEY_F15, |
| 1776 0, |
| 1777 ui::ET_KEY_PRESSED, |
| 1778 keycode_launch6_, |
| 1779 0U)); |
| 1780 } |
| 1781 |
1632 TEST_F(EventRewriterTest, TestRewriteCapsLockToControl) { | 1782 TEST_F(EventRewriterTest, TestRewriteCapsLockToControl) { |
1633 TestingPrefServiceSyncable prefs; | 1783 TestingPrefServiceSyncable prefs; |
1634 chromeos::Preferences::RegisterUserPrefs(&prefs); | 1784 chromeos::Preferences::RegisterUserPrefs(&prefs); |
1635 IntegerPrefMember control; | 1785 IntegerPrefMember control; |
1636 control.Init(prefs::kLanguageRemapCapsLockKeyTo, &prefs); | 1786 control.Init(prefs::kLanguageRemapCapsLockKeyTo, &prefs); |
1637 control.SetValue(chromeos::input_method::kControlKey); | 1787 control.SetValue(chromeos::input_method::kControlKey); |
1638 | 1788 |
1639 EventRewriter rewriter; | 1789 EventRewriter rewriter; |
1640 rewriter.set_pref_service_for_testing(&prefs); | 1790 rewriter.set_pref_service_for_testing(&prefs); |
1641 | 1791 |
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2197 // flag in the event is True. | 2347 // flag in the event is True. |
2198 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CONTROL, | 2348 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CONTROL, |
2199 ui::EF_CONTROL_DOWN, | 2349 ui::EF_CONTROL_DOWN, |
2200 ui::ET_KEY_PRESSED, | 2350 ui::ET_KEY_PRESSED, |
2201 keycode_control_l_, | 2351 keycode_control_l_, |
2202 0U, | 2352 0U, |
2203 KeyPress), | 2353 KeyPress), |
2204 rewritten_event); | 2354 rewritten_event); |
2205 } | 2355 } |
2206 #endif // OS_CHROMEOS | 2356 #endif // OS_CHROMEOS |
OLD | NEW |