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 // Makes sure the num lock works correctly even when Diamond key exists. | |
Yusuke Sato
2013/01/25 06:19:53
Make
yoshiki
2013/01/25 06:43:36
Done.
| |
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, TestRewriteNumPadKeysOnAppleKeyboardWithDiamondKeyFlag ) { | |
Yusuke Sato
2013/01/25 06:19:53
80col
yoshiki
2013/01/25 06:43:36
Done.
| |
938 // Makes sure the num lock works correctly even when Diamond key exists. | |
939 const CommandLine original_cl(*CommandLine::ForCurrentProcess()); | |
940 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
941 switches::kHasChromeOSDiamondKey, ""); | |
942 | |
943 TestRewriteNumPadKeysOnAppleKeyboard(); | |
944 } | |
945 | |
915 TEST_F(EventRewriterTest, TestRewriteModifiersNoRemap) { | 946 TEST_F(EventRewriterTest, TestRewriteModifiersNoRemap) { |
916 TestingPrefServiceSyncable prefs; | 947 TestingPrefServiceSyncable prefs; |
917 EventRewriter rewriter; | 948 EventRewriter rewriter; |
918 rewriter.set_pref_service_for_testing(&prefs); | 949 rewriter.set_pref_service_for_testing(&prefs); |
919 | 950 |
920 // Press Search. Confirm the event is not rewritten. | 951 // Press Search. Confirm the event is not rewritten. |
921 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_LWIN, | 952 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_LWIN, |
922 0, | 953 0, |
923 ui::ET_KEY_PRESSED, | 954 ui::ET_KEY_PRESSED, |
924 keycode_super_l_, | 955 keycode_super_l_, |
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1622 ui::VKEY_F16, | 1653 ui::VKEY_F16, |
1623 0, | 1654 0, |
1624 ui::ET_KEY_PRESSED, | 1655 ui::ET_KEY_PRESSED, |
1625 keycode_launch7_, | 1656 keycode_launch7_, |
1626 0U)); | 1657 0U)); |
1627 EXPECT_TRUE(xkeyboard.caps_lock_is_enabled_); | 1658 EXPECT_TRUE(xkeyboard.caps_lock_is_enabled_); |
1628 | 1659 |
1629 *CommandLine::ForCurrentProcess() = original_cl; | 1660 *CommandLine::ForCurrentProcess() = original_cl; |
1630 } | 1661 } |
1631 | 1662 |
1663 TEST_F(EventRewriterTest, DISABLED_TestRewriteDiamondKey) { | |
1664 // TODO(yusukes): Reenable the test once build servers are upgraded. | |
1665 | |
1666 TestingPrefServiceSyncable prefs; | |
1667 chromeos::Preferences::RegisterUserPrefs(&prefs); | |
1668 | |
1669 chromeos::input_method::MockXKeyboard xkeyboard; | |
1670 EventRewriter rewriter; | |
1671 rewriter.set_pref_service_for_testing(&prefs); | |
1672 rewriter.set_xkeyboard_for_testing(&xkeyboard); | |
1673 | |
1674 // F15 should work as Ctrl when --has-chromeos-diamond-key is not specified. | |
1675 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CONTROL, | |
1676 ui::EF_CONTROL_DOWN, | |
1677 ui::ET_KEY_PRESSED, | |
1678 keycode_control_l_, | |
1679 0U, | |
1680 KeyPress), | |
1681 GetRewrittenEventAsString(&rewriter, | |
1682 ui::VKEY_F15, | |
1683 0, | |
1684 ui::ET_KEY_PRESSED, | |
1685 keycode_launch6_, | |
1686 0U)); | |
1687 } | |
1688 | |
1689 TEST_F(EventRewriterTest, DISABLED_TestRewriteDiamondKeyWithFlag) { | |
1690 // TODO(yusukes): Reenable the test once build servers are upgraded. | |
1691 | |
1692 const CommandLine original_cl(*CommandLine::ForCurrentProcess()); | |
1693 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
1694 switches::kHasChromeOSDiamondKey, ""); | |
1695 | |
1696 TestingPrefServiceSyncable prefs; | |
1697 chromeos::Preferences::RegisterUserPrefs(&prefs); | |
1698 | |
1699 chromeos::input_method::MockXKeyboard xkeyboard; | |
1700 EventRewriter rewriter; | |
1701 rewriter.set_pref_service_for_testing(&prefs); | |
1702 rewriter.set_xkeyboard_for_testing(&xkeyboard); | |
1703 | |
1704 // By default, F15 should work as Control. | |
1705 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CONTROL, | |
1706 ui::EF_CONTROL_DOWN, | |
1707 ui::ET_KEY_PRESSED, | |
1708 keycode_control_l_, | |
1709 0U, | |
1710 KeyPress), | |
1711 GetRewrittenEventAsString(&rewriter, | |
1712 ui::VKEY_F15, | |
1713 0, | |
1714 ui::ET_KEY_PRESSED, | |
1715 keycode_launch6_, | |
1716 0U)); | |
1717 | |
1718 IntegerPrefMember diamond; | |
1719 diamond.Init(prefs::kLanguageRemapDiamondKeyTo, &prefs); | |
1720 diamond.SetValue(chromeos::input_method::kVoidKey); | |
1721 | |
1722 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_UNKNOWN, | |
1723 0, | |
1724 ui::ET_KEY_PRESSED, | |
1725 keycode_void_symbol_, | |
1726 0U, | |
1727 KeyPress), | |
1728 GetRewrittenEventAsString(&rewriter, | |
1729 ui::VKEY_F15, | |
1730 0, | |
1731 ui::ET_KEY_PRESSED, | |
1732 keycode_launch6_, | |
1733 0U)); | |
1734 | |
1735 diamond.SetValue(chromeos::input_method::kControlKey); | |
1736 | |
1737 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CONTROL, | |
1738 ui::EF_CONTROL_DOWN, | |
1739 ui::ET_KEY_PRESSED, | |
1740 keycode_control_l_, | |
1741 0U, | |
1742 KeyPress), | |
1743 GetRewrittenEventAsString(&rewriter, | |
1744 ui::VKEY_F15, | |
1745 0, | |
1746 ui::ET_KEY_PRESSED, | |
1747 keycode_launch6_, | |
1748 0U)); | |
1749 | |
1750 diamond.SetValue(chromeos::input_method::kAltKey); | |
1751 | |
1752 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_MENU, | |
1753 ui::EF_ALT_DOWN, | |
1754 ui::ET_KEY_PRESSED, | |
1755 keycode_alt_l_, | |
1756 0, | |
1757 KeyPress), | |
1758 GetRewrittenEventAsString(&rewriter, | |
1759 ui::VKEY_F15, | |
1760 0, | |
1761 ui::ET_KEY_PRESSED, | |
1762 keycode_launch6_, | |
1763 0U)); | |
1764 | |
1765 diamond.SetValue(chromeos::input_method::kCapsLockKey); | |
1766 | |
1767 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CAPITAL, | |
1768 ui::EF_CAPS_LOCK_DOWN, | |
1769 ui::ET_KEY_PRESSED, | |
1770 keycode_caps_lock_, | |
1771 0U, | |
1772 KeyPress), | |
1773 GetRewrittenEventAsString(&rewriter, | |
1774 ui::VKEY_F15, | |
1775 0, | |
1776 ui::ET_KEY_PRESSED, | |
1777 keycode_launch6_, | |
1778 0U)); | |
1779 } | |
1780 | |
1632 TEST_F(EventRewriterTest, TestRewriteCapsLockToControl) { | 1781 TEST_F(EventRewriterTest, TestRewriteCapsLockToControl) { |
1633 TestingPrefServiceSyncable prefs; | 1782 TestingPrefServiceSyncable prefs; |
1634 chromeos::Preferences::RegisterUserPrefs(&prefs); | 1783 chromeos::Preferences::RegisterUserPrefs(&prefs); |
1635 IntegerPrefMember control; | 1784 IntegerPrefMember control; |
1636 control.Init(prefs::kLanguageRemapCapsLockKeyTo, &prefs); | 1785 control.Init(prefs::kLanguageRemapCapsLockKeyTo, &prefs); |
1637 control.SetValue(chromeos::input_method::kControlKey); | 1786 control.SetValue(chromeos::input_method::kControlKey); |
1638 | 1787 |
1639 EventRewriter rewriter; | 1788 EventRewriter rewriter; |
1640 rewriter.set_pref_service_for_testing(&prefs); | 1789 rewriter.set_pref_service_for_testing(&prefs); |
1641 | 1790 |
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2197 // flag in the event is True. | 2346 // flag in the event is True. |
2198 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CONTROL, | 2347 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CONTROL, |
2199 ui::EF_CONTROL_DOWN, | 2348 ui::EF_CONTROL_DOWN, |
2200 ui::ET_KEY_PRESSED, | 2349 ui::ET_KEY_PRESSED, |
2201 keycode_control_l_, | 2350 keycode_control_l_, |
2202 0U, | 2351 0U, |
2203 KeyPress), | 2352 KeyPress), |
2204 rewritten_event); | 2353 rewritten_event); |
2205 } | 2354 } |
2206 #endif // OS_CHROMEOS | 2355 #endif // OS_CHROMEOS |
OLD | NEW |