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/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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 keycode_backspace_(XKeysymToKeycode(display_, XK_BackSpace)), | 110 keycode_backspace_(XKeysymToKeycode(display_, XK_BackSpace)), |
111 keycode_up_(XKeysymToKeycode(display_, XK_Up)), | 111 keycode_up_(XKeysymToKeycode(display_, XK_Up)), |
112 keycode_down_(XKeysymToKeycode(display_, XK_Down)), | 112 keycode_down_(XKeysymToKeycode(display_, XK_Down)), |
113 keycode_left_(XKeysymToKeycode(display_, XK_Left)), | 113 keycode_left_(XKeysymToKeycode(display_, XK_Left)), |
114 keycode_right_(XKeysymToKeycode(display_, XK_Right)), | 114 keycode_right_(XKeysymToKeycode(display_, XK_Right)), |
115 keycode_prior_(XKeysymToKeycode(display_, XK_Prior)), | 115 keycode_prior_(XKeysymToKeycode(display_, XK_Prior)), |
116 keycode_next_(XKeysymToKeycode(display_, XK_Next)), | 116 keycode_next_(XKeysymToKeycode(display_, XK_Next)), |
117 keycode_home_(XKeysymToKeycode(display_, XK_Home)), | 117 keycode_home_(XKeysymToKeycode(display_, XK_Home)), |
118 keycode_end_(XKeysymToKeycode(display_, XK_End)), | 118 keycode_end_(XKeysymToKeycode(display_, XK_End)), |
119 keycode_launch7_(XKeysymToKeycode(display_, XF86XK_Launch7)), | 119 keycode_launch7_(XKeysymToKeycode(display_, XF86XK_Launch7)), |
| 120 keycode_f1_(XKeysymToKeycode(display_, XK_F1)), |
| 121 keycode_f2_(XKeysymToKeycode(display_, XK_F2)), |
| 122 keycode_f3_(XKeysymToKeycode(display_, XK_F3)), |
| 123 keycode_f4_(XKeysymToKeycode(display_, XK_F4)), |
| 124 keycode_f5_(XKeysymToKeycode(display_, XK_F5)), |
| 125 keycode_f6_(XKeysymToKeycode(display_, XK_F6)), |
| 126 keycode_f7_(XKeysymToKeycode(display_, XK_F7)), |
| 127 keycode_f8_(XKeysymToKeycode(display_, XK_F8)), |
| 128 keycode_f9_(XKeysymToKeycode(display_, XK_F9)), |
| 129 keycode_f10_(XKeysymToKeycode(display_, XK_F10)), |
| 130 keycode_f11_(XKeysymToKeycode(display_, XK_F11)), |
| 131 keycode_f12_(XKeysymToKeycode(display_, XK_F12)), |
| 132 keycode_browser_back_(XKeysymToKeycode(display_, XF86XK_Back)), |
| 133 keycode_browser_forward_(XKeysymToKeycode(display_, XF86XK_Forward)), |
| 134 keycode_browser_refresh_(XKeysymToKeycode(display_, XF86XK_Reload)), |
| 135 keycode_media_launch_app1_(XKeysymToKeycode(display_, XF86XK_LaunchA)), |
| 136 keycode_media_launch_app2_(XKeysymToKeycode(display_, XF86XK_LaunchB)), |
| 137 keycode_brightness_down_(XKeysymToKeycode( |
| 138 display_, XF86XK_MonBrightnessDown)), |
| 139 keycode_brightness_up_(XKeysymToKeycode( |
| 140 display_, XF86XK_MonBrightnessUp)), |
| 141 keycode_volume_mute_(XKeysymToKeycode(display_, XF86XK_AudioMute)), |
| 142 keycode_volume_down_(XKeysymToKeycode( |
| 143 display_, XF86XK_AudioLowerVolume)), |
| 144 keycode_volume_up_(XKeysymToKeycode( |
| 145 display_, XF86XK_AudioRaiseVolume)), |
| 146 keycode_power_(XKeysymToKeycode(display_, XF86XK_PowerOff)), |
| 147 keycode_1_(XKeysymToKeycode(display_, XK_1)), |
| 148 keycode_2_(XKeysymToKeycode(display_, XK_2)), |
| 149 keycode_3_(XKeysymToKeycode(display_, XK_3)), |
| 150 keycode_4_(XKeysymToKeycode(display_, XK_4)), |
| 151 keycode_5_(XKeysymToKeycode(display_, XK_5)), |
| 152 keycode_6_(XKeysymToKeycode(display_, XK_6)), |
| 153 keycode_7_(XKeysymToKeycode(display_, XK_7)), |
| 154 keycode_8_(XKeysymToKeycode(display_, XK_8)), |
| 155 keycode_9_(XKeysymToKeycode(display_, XK_9)), |
| 156 keycode_0_(XKeysymToKeycode(display_, XK_0)), |
| 157 keycode_minus_(XKeysymToKeycode(display_, XK_minus)), |
| 158 keycode_equal_(XKeysymToKeycode(display_, XK_equal)), |
120 input_method_manager_mock_(NULL) { | 159 input_method_manager_mock_(NULL) { |
121 } | 160 } |
122 virtual ~EventRewriterTest() {} | 161 virtual ~EventRewriterTest() {} |
123 | 162 |
124 virtual void SetUp() { | 163 virtual void SetUp() { |
125 // Mocking user manager because the real one needs to be called on UI thread | 164 // Mocking user manager because the real one needs to be called on UI thread |
126 EXPECT_CALL(*user_manager_mock_.user_manager(), IsLoggedInAsGuest()) | 165 EXPECT_CALL(*user_manager_mock_.user_manager(), IsLoggedInAsGuest()) |
127 .WillRepeatedly(testing::Return(false)); | 166 .WillRepeatedly(testing::Return(false)); |
128 input_method_manager_mock_ = | 167 input_method_manager_mock_ = |
129 new chromeos::input_method::MockInputMethodManager; | 168 new chromeos::input_method::MockInputMethodManager; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 const KeyCode keycode_backspace_; | 215 const KeyCode keycode_backspace_; |
177 const KeyCode keycode_up_; | 216 const KeyCode keycode_up_; |
178 const KeyCode keycode_down_; | 217 const KeyCode keycode_down_; |
179 const KeyCode keycode_left_; | 218 const KeyCode keycode_left_; |
180 const KeyCode keycode_right_; | 219 const KeyCode keycode_right_; |
181 const KeyCode keycode_prior_; | 220 const KeyCode keycode_prior_; |
182 const KeyCode keycode_next_; | 221 const KeyCode keycode_next_; |
183 const KeyCode keycode_home_; | 222 const KeyCode keycode_home_; |
184 const KeyCode keycode_end_; | 223 const KeyCode keycode_end_; |
185 const KeyCode keycode_launch7_; // F16 | 224 const KeyCode keycode_launch7_; // F16 |
| 225 const KeyCode keycode_f1_; |
| 226 const KeyCode keycode_f2_; |
| 227 const KeyCode keycode_f3_; |
| 228 const KeyCode keycode_f4_; |
| 229 const KeyCode keycode_f5_; |
| 230 const KeyCode keycode_f6_; |
| 231 const KeyCode keycode_f7_; |
| 232 const KeyCode keycode_f8_; |
| 233 const KeyCode keycode_f9_; |
| 234 const KeyCode keycode_f10_; |
| 235 const KeyCode keycode_f11_; |
| 236 const KeyCode keycode_f12_; |
| 237 const KeyCode keycode_browser_back_; |
| 238 const KeyCode keycode_browser_forward_; |
| 239 const KeyCode keycode_browser_refresh_; |
| 240 const KeyCode keycode_media_launch_app1_; |
| 241 const KeyCode keycode_media_launch_app2_; |
| 242 const KeyCode keycode_brightness_down_; |
| 243 const KeyCode keycode_brightness_up_; |
| 244 const KeyCode keycode_volume_mute_; |
| 245 const KeyCode keycode_volume_down_; |
| 246 const KeyCode keycode_volume_up_; |
| 247 const KeyCode keycode_power_; |
| 248 const KeyCode keycode_1_; |
| 249 const KeyCode keycode_2_; |
| 250 const KeyCode keycode_3_; |
| 251 const KeyCode keycode_4_; |
| 252 const KeyCode keycode_5_; |
| 253 const KeyCode keycode_6_; |
| 254 const KeyCode keycode_7_; |
| 255 const KeyCode keycode_8_; |
| 256 const KeyCode keycode_9_; |
| 257 const KeyCode keycode_0_; |
| 258 const KeyCode keycode_minus_; |
| 259 const KeyCode keycode_equal_; |
186 chromeos::ScopedMockUserManagerEnabler user_manager_mock_; | 260 chromeos::ScopedMockUserManagerEnabler user_manager_mock_; |
187 chromeos::input_method::MockInputMethodManager* input_method_manager_mock_; | 261 chromeos::input_method::MockInputMethodManager* input_method_manager_mock_; |
188 }; | 262 }; |
189 | 263 |
190 } // namespace | 264 } // namespace |
191 #else | 265 #else |
192 class EventRewriterTest : public testing::Test { | 266 class EventRewriterTest : public testing::Test { |
193 public: | 267 public: |
194 EventRewriterTest() {} | 268 EventRewriterTest() {} |
195 virtual ~EventRewriterTest() {} | 269 virtual ~EventRewriterTest() {} |
(...skipping 1483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1679 | 1753 |
1680 input_method_manager_mock_->SetCurrentInputMethodId("xkb:us::eng"); | 1754 input_method_manager_mock_->SetCurrentInputMethodId("xkb:us::eng"); |
1681 } | 1755 } |
1682 | 1756 |
1683 TEST_F(EventRewriterTest, TestRewriteBackspaceAndArrowKeys) { | 1757 TEST_F(EventRewriterTest, TestRewriteBackspaceAndArrowKeys) { |
1684 TestingPrefService prefs; | 1758 TestingPrefService prefs; |
1685 chromeos::Preferences::RegisterUserPrefs(&prefs); | 1759 chromeos::Preferences::RegisterUserPrefs(&prefs); |
1686 EventRewriter rewriter; | 1760 EventRewriter rewriter; |
1687 rewriter.set_pref_service_for_testing(&prefs); | 1761 rewriter.set_pref_service_for_testing(&prefs); |
1688 | 1762 |
1689 // Alt+Backspace -> Delete | 1763 // On non-chromebooks, the keyboard doesn't need to be remapped. |
1690 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_DELETE, | |
1691 0, | |
1692 ui::ET_KEY_PRESSED, | |
1693 keycode_delete_, | |
1694 0U, | |
1695 KeyPress), | |
1696 GetRewrittenEventAsString(&rewriter, | |
1697 ui::VKEY_BACK, | |
1698 ui::EF_ALT_DOWN, | |
1699 ui::ET_KEY_PRESSED, | |
1700 keycode_backspace_, | |
1701 Mod1Mask)); | |
1702 | 1764 |
1703 // Ctrl+Alt+Backspace -> Ctrl+Delete | 1765 struct { |
1704 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_DELETE, | 1766 ui::KeyboardCode input; |
1705 ui::EF_CONTROL_DOWN, | 1767 KeyCode input_native; |
1706 ui::ET_KEY_PRESSED, | 1768 unsigned int input_mods; |
1707 keycode_delete_, | 1769 unsigned int input_native_mods; |
1708 ControlMask, | 1770 ui::KeyboardCode output; |
1709 KeyPress), | 1771 KeyCode output_native; |
1710 GetRewrittenEventAsString(&rewriter, | 1772 unsigned int output_mods; |
1711 ui::VKEY_BACK, | 1773 unsigned int output_native_mods; |
1712 ui::EF_ALT_DOWN | ui::EF_CONTROL_DOWN, | 1774 } default_tests[] = { |
1713 ui::ET_KEY_PRESSED, | 1775 { ui::VKEY_BACK, keycode_backspace_, |
1714 keycode_backspace_, | 1776 ui::EF_ALT_DOWN, Mod1Mask, |
1715 Mod1Mask | ControlMask)); | 1777 ui::VKEY_BACK, keycode_backspace_, |
| 1778 ui::EF_ALT_DOWN, Mod1Mask, }, |
| 1779 { ui::VKEY_UP, keycode_up_, |
| 1780 ui::EF_ALT_DOWN, Mod1Mask, |
| 1781 ui::VKEY_UP, keycode_up_, |
| 1782 ui::EF_ALT_DOWN, Mod1Mask, }, |
| 1783 { ui::VKEY_UP, keycode_up_, |
| 1784 ui::EF_ALT_DOWN | ui::EF_CONTROL_DOWN, Mod1Mask | ControlMask, |
| 1785 ui::VKEY_UP, keycode_up_, |
| 1786 ui::EF_ALT_DOWN | ui::EF_CONTROL_DOWN, Mod1Mask | ControlMask, }, |
| 1787 { ui::VKEY_DOWN, keycode_down_, |
| 1788 ui::EF_ALT_DOWN, Mod1Mask, |
| 1789 ui::VKEY_DOWN, keycode_down_, |
| 1790 ui::EF_ALT_DOWN, Mod1Mask, }, |
| 1791 { ui::VKEY_LEFT, keycode_left_, 0, 0, |
| 1792 ui::VKEY_LEFT, keycode_left_, 0, 0 }, |
| 1793 { ui::VKEY_RIGHT, keycode_right_, 0, 0, |
| 1794 ui::VKEY_RIGHT, keycode_right_, 0, 0 } |
| 1795 }; |
1716 | 1796 |
1717 // Alt+Up -> Prior | 1797 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(default_tests); ++i) { |
1718 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_PRIOR, | 1798 EXPECT_EQ(GetExpectedResultAsString(default_tests[i].output, |
1719 0, | 1799 default_tests[i].output_mods, |
1720 ui::ET_KEY_PRESSED, | 1800 ui::ET_KEY_PRESSED, |
1721 keycode_prior_, | 1801 default_tests[i].output_native, |
1722 0U, | 1802 default_tests[i].output_native_mods, |
1723 KeyPress), | 1803 KeyPress), |
1724 GetRewrittenEventAsString(&rewriter, | 1804 GetRewrittenEventAsString(&rewriter, |
1725 ui::VKEY_UP, | 1805 default_tests[i].input, |
1726 ui::EF_ALT_DOWN, | 1806 default_tests[i].input_mods, |
1727 ui::ET_KEY_PRESSED, | 1807 ui::ET_KEY_PRESSED, |
1728 keycode_up_, | 1808 default_tests[i].input_native, |
1729 Mod1Mask)); | 1809 default_tests[i].input_native_mods)); |
1730 | 1810 |
1731 // Alt+Down -> Next | 1811 // Search key as a modifier does not change the outcome. |
1732 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_NEXT, | 1812 EXPECT_EQ(GetExpectedResultAsString(default_tests[i].output, |
1733 0, | 1813 default_tests[i].output_mods, |
1734 ui::ET_KEY_PRESSED, | 1814 ui::ET_KEY_PRESSED, |
1735 keycode_next_, | 1815 default_tests[i].output_native, |
1736 0U, | 1816 Mod4Mask | |
1737 KeyPress), | 1817 default_tests[i].output_native_mods, |
1738 GetRewrittenEventAsString(&rewriter, | 1818 KeyPress), |
1739 ui::VKEY_DOWN, | 1819 GetRewrittenEventAsString(&rewriter, |
1740 ui::EF_ALT_DOWN, | 1820 default_tests[i].input, |
1741 ui::ET_KEY_PRESSED, | 1821 default_tests[i].input_mods, |
1742 keycode_down_, | 1822 ui::ET_KEY_PRESSED, |
1743 Mod1Mask)); | 1823 default_tests[i].input_native, |
| 1824 Mod4Mask | |
| 1825 default_tests[i].input_native_mods)); |
| 1826 } |
1744 | 1827 |
1745 // Ctrl+Alt+Up -> Home | 1828 // On a chromebook, an external keyboard doesn't need to be remapped. |
1746 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_HOME, | 1829 const CommandLine original_cl(*CommandLine::ForCurrentProcess()); |
1747 0, | 1830 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
1748 ui::ET_KEY_PRESSED, | 1831 switches::kHasChromeOSKeyboard, ""); |
1749 keycode_home_, | |
1750 0U, | |
1751 KeyPress), | |
1752 GetRewrittenEventAsString(&rewriter, | |
1753 ui::VKEY_UP, | |
1754 ui::EF_ALT_DOWN | ui::EF_CONTROL_DOWN, | |
1755 ui::ET_KEY_PRESSED, | |
1756 keycode_up_, | |
1757 Mod1Mask | ControlMask)); | |
1758 | 1832 |
1759 // Ctrl+Alt+Down -> End | 1833 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(default_tests); ++i) { |
1760 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_END, | 1834 EXPECT_EQ(GetExpectedResultAsString(default_tests[i].output, |
1761 0, | 1835 default_tests[i].output_mods, |
1762 ui::ET_KEY_PRESSED, | 1836 ui::ET_KEY_PRESSED, |
1763 keycode_end_, | 1837 default_tests[i].output_native, |
1764 0U, | 1838 default_tests[i].output_native_mods, |
1765 KeyPress), | 1839 KeyPress), |
1766 GetRewrittenEventAsString(&rewriter, | 1840 GetRewrittenEventAsString(&rewriter, |
1767 ui::VKEY_DOWN, | 1841 default_tests[i].input, |
1768 ui::EF_ALT_DOWN | ui::EF_CONTROL_DOWN, | 1842 default_tests[i].input_mods, |
1769 ui::ET_KEY_PRESSED, | 1843 ui::ET_KEY_PRESSED, |
1770 keycode_down_, | 1844 default_tests[i].input_native, |
1771 Mod1Mask | ControlMask)); | 1845 default_tests[i].input_native_mods)); |
1772 | 1846 |
1773 // Shift+Ctrl+Alt+Down -> Shift+End | 1847 // Search key as a modifier does not change the outcome. |
1774 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_END, | 1848 EXPECT_EQ(GetExpectedResultAsString(default_tests[i].output, |
1775 ui::EF_SHIFT_DOWN, | 1849 default_tests[i].output_mods, |
1776 ui::ET_KEY_PRESSED, | 1850 ui::ET_KEY_PRESSED, |
1777 keycode_end_, | 1851 default_tests[i].output_native, |
1778 ShiftMask, | 1852 Mod4Mask | |
1779 KeyPress), | 1853 default_tests[i].output_native_mods, |
1780 GetRewrittenEventAsString(&rewriter, | 1854 KeyPress), |
1781 ui::VKEY_DOWN, | 1855 GetRewrittenEventAsString(&rewriter, |
1782 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN | | 1856 default_tests[i].input, |
1783 ui::EF_CONTROL_DOWN, | 1857 default_tests[i].input_mods, |
1784 ui::ET_KEY_PRESSED, | 1858 ui::ET_KEY_PRESSED, |
1785 keycode_down_, | 1859 default_tests[i].input_native, |
1786 ShiftMask | Mod1Mask | ControlMask)); | 1860 Mod4Mask | |
| 1861 default_tests[i].input_native_mods)); |
| 1862 } |
| 1863 |
| 1864 // The internal chromebook keybaord should be remapped. |
| 1865 rewriter.set_force_chromeos_keyboard_for_testing(true); |
| 1866 |
| 1867 struct { |
| 1868 ui::KeyboardCode input; |
| 1869 KeyCode input_native; |
| 1870 unsigned int input_mods; |
| 1871 unsigned int input_native_mods; |
| 1872 ui::KeyboardCode output; |
| 1873 KeyCode output_native; |
| 1874 unsigned int output_mods; |
| 1875 unsigned int output_native_mods; |
| 1876 } chromeos_tests[] = { |
| 1877 // Alt+Backspace -> Delete |
| 1878 { ui::VKEY_BACK, keycode_backspace_, |
| 1879 ui::EF_ALT_DOWN, Mod1Mask, |
| 1880 ui::VKEY_DELETE, keycode_delete_, |
| 1881 0, 0, }, |
| 1882 // Control+Alt+Backspace -> Control+Delete |
| 1883 { ui::VKEY_BACK, keycode_backspace_, |
| 1884 ui::EF_ALT_DOWN | ui::EF_CONTROL_DOWN, Mod1Mask | ControlMask, |
| 1885 ui::VKEY_DELETE, keycode_delete_, |
| 1886 ui::EF_CONTROL_DOWN, ControlMask, }, |
| 1887 // Alt+Up -> Prior |
| 1888 { ui::VKEY_UP, keycode_up_, |
| 1889 ui::EF_ALT_DOWN, Mod1Mask, |
| 1890 ui::VKEY_PRIOR, keycode_prior_, |
| 1891 0, 0, }, |
| 1892 // Alt+Down -> Next |
| 1893 { ui::VKEY_DOWN, keycode_down_, |
| 1894 ui::EF_ALT_DOWN, Mod1Mask, |
| 1895 ui::VKEY_NEXT, keycode_next_, |
| 1896 0, 0, }, |
| 1897 // Ctrl+Alt+Up -> Home |
| 1898 { ui::VKEY_UP, keycode_up_, |
| 1899 ui::EF_ALT_DOWN | ui::EF_CONTROL_DOWN, Mod1Mask | ControlMask, |
| 1900 ui::VKEY_HOME, keycode_home_, |
| 1901 0, 0, }, |
| 1902 // Ctrl+Alt+Down -> End |
| 1903 { ui::VKEY_DOWN, keycode_down_, |
| 1904 ui::EF_ALT_DOWN | ui::EF_CONTROL_DOWN, Mod1Mask | ControlMask, |
| 1905 ui::VKEY_END, keycode_end_, |
| 1906 0, 0, } |
| 1907 }; |
| 1908 |
| 1909 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(chromeos_tests); ++i) { |
| 1910 EXPECT_EQ(GetExpectedResultAsString(chromeos_tests[i].output, |
| 1911 chromeos_tests[i].output_mods, |
| 1912 ui::ET_KEY_PRESSED, |
| 1913 chromeos_tests[i].output_native, |
| 1914 chromeos_tests[i].output_native_mods, |
| 1915 KeyPress), |
| 1916 GetRewrittenEventAsString(&rewriter, |
| 1917 chromeos_tests[i].input, |
| 1918 chromeos_tests[i].input_mods, |
| 1919 ui::ET_KEY_PRESSED, |
| 1920 chromeos_tests[i].input_native, |
| 1921 chromeos_tests[i].input_native_mods)); |
| 1922 |
| 1923 // Search key as a modifier does not change the outcome. |
| 1924 EXPECT_EQ(GetExpectedResultAsString(chromeos_tests[i].output, |
| 1925 chromeos_tests[i].output_mods, |
| 1926 ui::ET_KEY_PRESSED, |
| 1927 chromeos_tests[i].output_native, |
| 1928 Mod4Mask | |
| 1929 chromeos_tests[i].output_native_mods, |
| 1930 KeyPress), |
| 1931 GetRewrittenEventAsString(&rewriter, |
| 1932 chromeos_tests[i].input, |
| 1933 chromeos_tests[i].input_mods, |
| 1934 ui::ET_KEY_PRESSED, |
| 1935 chromeos_tests[i].input_native, |
| 1936 Mod4Mask | |
| 1937 chromeos_tests[i].input_native_mods)); |
| 1938 } |
1787 | 1939 |
1788 // 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 |
1789 // bindings. | 1941 // bindings. |
1790 const CommandLine original_cl(*CommandLine::ForCurrentProcess()); | |
1791 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 1942 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
1792 switches::kEnableChromebookFunctionKey, ""); | 1943 switches::kEnableChromebookFunctionKey, ""); |
1793 BooleanPrefMember search_key_as_function_key; | 1944 BooleanPrefMember search_key_as_function_key; |
1794 search_key_as_function_key.Init(prefs::kLanguageSearchKeyActsAsFunctionKey, | 1945 search_key_as_function_key.Init(prefs::kLanguageSearchKeyActsAsFunctionKey, |
1795 &prefs, NULL); | 1946 &prefs, NULL); |
1796 search_key_as_function_key.SetValue(true); | 1947 search_key_as_function_key.SetValue(true); |
1797 | 1948 |
1798 // Alt+Backspace -> Alt+Backspace | 1949 |
1799 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_BACK, | 1950 // An external keyboard should still not be remapped. |
1800 ui::EF_ALT_DOWN, | 1951 rewriter.set_force_chromeos_keyboard_for_testing(false); |
1801 ui::ET_KEY_PRESSED, | 1952 |
1802 keycode_backspace_, | 1953 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(default_tests); ++i) { |
1803 Mod1Mask, | 1954 EXPECT_EQ(GetExpectedResultAsString(default_tests[i].output, |
1804 KeyPress), | 1955 default_tests[i].output_mods, |
1805 GetRewrittenEventAsString(&rewriter, | 1956 ui::ET_KEY_PRESSED, |
1806 ui::VKEY_BACK, | 1957 default_tests[i].output_native, |
1807 ui::EF_ALT_DOWN, | 1958 default_tests[i].output_native_mods, |
1808 ui::ET_KEY_PRESSED, | 1959 KeyPress), |
1809 keycode_backspace_, | 1960 GetRewrittenEventAsString(&rewriter, |
1810 Mod1Mask)); | 1961 default_tests[i].input, |
1811 | 1962 default_tests[i].input_mods, |
1812 // Search+Backspace -> Delete | 1963 ui::ET_KEY_PRESSED, |
1813 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_DELETE, | 1964 default_tests[i].input_native, |
1814 0, | 1965 default_tests[i].input_native_mods)); |
1815 ui::ET_KEY_PRESSED, | 1966 |
1816 keycode_delete_, | 1967 // Search key as a modifier does not change the outcome. |
1817 0U, | 1968 EXPECT_EQ(GetExpectedResultAsString(default_tests[i].output, |
1818 KeyPress), | 1969 default_tests[i].output_mods, |
1819 GetRewrittenEventAsString(&rewriter, | 1970 ui::ET_KEY_PRESSED, |
1820 ui::VKEY_BACK, | 1971 default_tests[i].output_native, |
1821 0, | 1972 Mod4Mask | |
1822 ui::ET_KEY_PRESSED, | 1973 default_tests[i].output_native_mods, |
1823 keycode_backspace_, | 1974 KeyPress), |
1824 Mod4Mask)); | 1975 GetRewrittenEventAsString(&rewriter, |
1825 | 1976 default_tests[i].input, |
1826 // Ctrl+Search+Backspace -> Ctrl+Delete | 1977 default_tests[i].input_mods, |
1827 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_DELETE, | 1978 ui::ET_KEY_PRESSED, |
1828 ui::EF_CONTROL_DOWN, | 1979 default_tests[i].input_native, |
1829 ui::ET_KEY_PRESSED, | 1980 Mod4Mask | |
1830 keycode_delete_, | 1981 default_tests[i].input_native_mods)); |
1831 ControlMask, | 1982 } |
1832 KeyPress), | 1983 |
1833 GetRewrittenEventAsString(&rewriter, | 1984 // The ChromeOS keyboard should be remapped with Search key modifiers. |
1834 ui::VKEY_BACK, | 1985 rewriter.set_force_chromeos_keyboard_for_testing(true); |
1835 0, | 1986 |
1836 ui::ET_KEY_PRESSED, | 1987 struct { |
1837 keycode_backspace_, | 1988 ui::KeyboardCode input; |
1838 Mod4Mask | ControlMask)); | 1989 KeyCode input_native; |
1839 | 1990 unsigned int input_mods; |
1840 // Alt+Search+Backspace -> Alt+Delete | 1991 unsigned int input_native_mods; |
1841 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_DELETE, | 1992 ui::KeyboardCode output; |
1842 ui::EF_ALT_DOWN, | 1993 KeyCode output_native; |
1843 ui::ET_KEY_PRESSED, | 1994 unsigned int output_mods; |
1844 keycode_delete_, | 1995 unsigned int output_native_mods; |
1845 Mod1Mask, | 1996 } search_tests[] = { |
1846 KeyPress), | 1997 { ui::VKEY_BACK, keycode_backspace_, |
1847 GetRewrittenEventAsString(&rewriter, | 1998 ui::EF_ALT_DOWN, Mod1Mask, |
1848 ui::VKEY_BACK, | 1999 ui::VKEY_BACK, keycode_backspace_, |
1849 0, | 2000 ui::EF_ALT_DOWN, Mod1Mask, }, |
1850 ui::ET_KEY_PRESSED, | 2001 { ui::VKEY_UP, keycode_up_, |
1851 keycode_backspace_, | 2002 ui::EF_ALT_DOWN, Mod1Mask, |
1852 Mod4Mask | Mod1Mask)); | 2003 ui::VKEY_UP, keycode_up_, |
1853 | 2004 ui::EF_ALT_DOWN, Mod1Mask, }, |
1854 // Alt+Up -> Alt+Up | 2005 { ui::VKEY_UP, keycode_up_, |
1855 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_UP, | 2006 ui::EF_ALT_DOWN | ui::EF_CONTROL_DOWN, Mod1Mask | ControlMask, |
1856 ui::EF_ALT_DOWN, | 2007 ui::VKEY_UP, keycode_up_, |
1857 ui::ET_KEY_PRESSED, | 2008 ui::EF_ALT_DOWN | ui::EF_CONTROL_DOWN, Mod1Mask | ControlMask, }, |
1858 keycode_up_, | 2009 { ui::VKEY_DOWN, keycode_down_, |
1859 Mod1Mask, | 2010 ui::EF_ALT_DOWN, Mod1Mask, |
1860 KeyPress), | 2011 ui::VKEY_DOWN, keycode_down_, |
1861 GetRewrittenEventAsString(&rewriter, | 2012 ui::EF_ALT_DOWN, Mod1Mask, }, |
1862 ui::VKEY_UP, | 2013 { ui::VKEY_LEFT, keycode_left_, 0, 0, |
1863 ui::EF_ALT_DOWN, | 2014 ui::VKEY_LEFT, keycode_left_, 0, 0 }, |
1864 ui::ET_KEY_PRESSED, | 2015 { ui::VKEY_RIGHT, keycode_right_, 0, 0, |
1865 keycode_up_, | 2016 ui::VKEY_RIGHT, keycode_right_, 0, 0 }, |
1866 Mod1Mask)); | 2017 |
1867 | 2018 // Search+Backspace -> Delete |
1868 // Search+Up -> Prior | 2019 { ui::VKEY_BACK, keycode_backspace_, |
1869 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_PRIOR, | 2020 0, Mod4Mask, |
1870 0, | 2021 ui::VKEY_DELETE, keycode_delete_, |
1871 ui::ET_KEY_PRESSED, | 2022 0, 0, }, |
1872 keycode_prior_, | 2023 // Alt+Search+Backspace -> Alt+Delete |
1873 0U, | 2024 { ui::VKEY_BACK, keycode_backspace_, |
1874 KeyPress), | 2025 ui::EF_ALT_DOWN, Mod4Mask | Mod1Mask, |
1875 GetRewrittenEventAsString(&rewriter, | 2026 ui::VKEY_DELETE, keycode_delete_, |
1876 ui::VKEY_UP, | 2027 ui::EF_ALT_DOWN, Mod1Mask, }, |
1877 0, | 2028 // Search+Up -> Prior |
1878 ui::ET_KEY_PRESSED, | 2029 { ui::VKEY_UP, keycode_up_, |
1879 keycode_up_, | 2030 0, Mod4Mask, |
1880 Mod4Mask)); | 2031 ui::VKEY_PRIOR, keycode_prior_, |
1881 | 2032 0, 0, }, |
1882 // Alt+Down -> Alt+Down | 2033 // Search+Down -> Next |
1883 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_DOWN, | 2034 { ui::VKEY_DOWN, keycode_down_, |
1884 ui::EF_ALT_DOWN, | 2035 0, Mod4Mask, |
1885 ui::ET_KEY_PRESSED, | 2036 ui::VKEY_NEXT, keycode_next_, |
1886 keycode_down_, | 2037 0, 0, }, |
1887 Mod1Mask, | 2038 // Search+Left -> Home |
1888 KeyPress), | 2039 { ui::VKEY_LEFT, keycode_left_, |
1889 GetRewrittenEventAsString(&rewriter, | 2040 0, Mod4Mask, |
1890 ui::VKEY_DOWN, | 2041 ui::VKEY_HOME, keycode_home_, |
1891 ui::EF_ALT_DOWN, | 2042 0, 0, }, |
1892 ui::ET_KEY_PRESSED, | 2043 // Control+Search+Left -> Home |
1893 keycode_down_, | 2044 { ui::VKEY_LEFT, keycode_left_, |
1894 Mod1Mask)); | 2045 ui::EF_CONTROL_DOWN, Mod4Mask | ControlMask, |
1895 | 2046 ui::VKEY_HOME, keycode_home_, |
1896 // Search+Down -> Next | 2047 ui::EF_CONTROL_DOWN, ControlMask }, |
1897 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_NEXT, | 2048 // Search+Right -> End |
1898 0, | 2049 { ui::VKEY_RIGHT, keycode_right_, |
1899 ui::ET_KEY_PRESSED, | 2050 0, Mod4Mask, |
1900 keycode_next_, | 2051 ui::VKEY_END, keycode_end_, |
1901 0U, | 2052 0, 0, }, |
1902 KeyPress), | 2053 // Control+Search+Right -> End |
1903 GetRewrittenEventAsString(&rewriter, | 2054 { ui::VKEY_RIGHT, keycode_right_, |
1904 ui::VKEY_DOWN, | 2055 ui::EF_CONTROL_DOWN, Mod4Mask | ControlMask, |
1905 0, | 2056 ui::VKEY_END, keycode_end_, |
1906 ui::ET_KEY_PRESSED, | 2057 ui::EF_CONTROL_DOWN, ControlMask } |
1907 keycode_down_, | 2058 }; |
1908 Mod4Mask)); | 2059 |
1909 | 2060 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(search_tests); ++i) { |
1910 // Ctrl+Alt+Up -> Ctrl+Alt+Up | 2061 EXPECT_EQ(GetExpectedResultAsString(search_tests[i].output, |
1911 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_UP, | 2062 search_tests[i].output_mods, |
1912 ui::EF_ALT_DOWN | ui::EF_CONTROL_DOWN, | 2063 ui::ET_KEY_PRESSED, |
1913 ui::ET_KEY_PRESSED, | 2064 search_tests[i].output_native, |
1914 keycode_up_, | 2065 search_tests[i].output_native_mods, |
1915 Mod1Mask | ControlMask, | 2066 KeyPress), |
1916 KeyPress), | 2067 GetRewrittenEventAsString(&rewriter, |
1917 GetRewrittenEventAsString(&rewriter, | 2068 search_tests[i].input, |
1918 ui::VKEY_UP, | 2069 search_tests[i].input_mods, |
1919 ui::EF_ALT_DOWN | ui::EF_CONTROL_DOWN, | 2070 ui::ET_KEY_PRESSED, |
1920 ui::ET_KEY_PRESSED, | 2071 search_tests[i].input_native, |
1921 keycode_up_, | 2072 search_tests[i].input_native_mods)); |
1922 Mod1Mask | ControlMask)); | 2073 } |
1923 | |
1924 // Search+Left -> Home | |
1925 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_HOME, | |
1926 0, | |
1927 ui::ET_KEY_PRESSED, | |
1928 keycode_home_, | |
1929 0U, | |
1930 KeyPress), | |
1931 GetRewrittenEventAsString(&rewriter, | |
1932 ui::VKEY_LEFT, | |
1933 0, | |
1934 ui::ET_KEY_PRESSED, | |
1935 keycode_left_, | |
1936 Mod4Mask)); | |
1937 | |
1938 // Ctrl+Alt+Down -> Ctrl+Alt+Down | |
1939 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_DOWN, | |
1940 ui::EF_ALT_DOWN | ui::EF_CONTROL_DOWN, | |
1941 ui::ET_KEY_PRESSED, | |
1942 keycode_down_, | |
1943 Mod1Mask | ControlMask, | |
1944 KeyPress), | |
1945 GetRewrittenEventAsString(&rewriter, | |
1946 ui::VKEY_DOWN, | |
1947 ui::EF_ALT_DOWN | ui::EF_CONTROL_DOWN, | |
1948 ui::ET_KEY_PRESSED, | |
1949 keycode_down_, | |
1950 Mod1Mask | ControlMask)); | |
1951 | |
1952 // Search+Right -> End | |
1953 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_END, | |
1954 0, | |
1955 ui::ET_KEY_PRESSED, | |
1956 keycode_end_, | |
1957 0U, | |
1958 KeyPress), | |
1959 GetRewrittenEventAsString(&rewriter, | |
1960 ui::VKEY_RIGHT, | |
1961 0, | |
1962 ui::ET_KEY_PRESSED, | |
1963 keycode_right_, | |
1964 Mod4Mask)); | |
1965 | |
1966 // Ctrl+Search+Left -> Control+Home | |
1967 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_HOME, | |
1968 ui::EF_CONTROL_DOWN, | |
1969 ui::ET_KEY_PRESSED, | |
1970 keycode_home_, | |
1971 ControlMask, | |
1972 KeyPress), | |
1973 GetRewrittenEventAsString(&rewriter, | |
1974 ui::VKEY_LEFT, | |
1975 0, | |
1976 ui::ET_KEY_PRESSED, | |
1977 keycode_left_, | |
1978 Mod4Mask | ControlMask)); | |
1979 | |
1980 // Ctrl+Search+Right -> Control+End | |
1981 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_END, | |
1982 ui::EF_CONTROL_DOWN, | |
1983 ui::ET_KEY_PRESSED, | |
1984 keycode_end_, | |
1985 ControlMask, | |
1986 KeyPress), | |
1987 GetRewrittenEventAsString(&rewriter, | |
1988 ui::VKEY_RIGHT, | |
1989 0, | |
1990 ui::ET_KEY_PRESSED, | |
1991 keycode_right_, | |
1992 Mod4Mask | ControlMask)); | |
1993 | 2074 |
1994 *CommandLine::ForCurrentProcess() = original_cl; | 2075 *CommandLine::ForCurrentProcess() = original_cl; |
1995 } | 2076 } |
1996 | 2077 |
| 2078 TEST_F(EventRewriterTest, TestRewriteFunctionKeys) { |
| 2079 const CommandLine original_cl(*CommandLine::ForCurrentProcess()); |
| 2080 TestingPrefService prefs; |
| 2081 chromeos::Preferences::RegisterUserPrefs(&prefs); |
| 2082 EventRewriter rewriter; |
| 2083 rewriter.set_pref_service_for_testing(&prefs); |
| 2084 |
| 2085 // When not on a chromebook, F<numbers> are not rewritten. |
| 2086 |
| 2087 struct { |
| 2088 ui::KeyboardCode input; |
| 2089 KeyCode input_native; |
| 2090 ui::KeyboardCode output; |
| 2091 KeyCode output_native; |
| 2092 } default_tests[] = { |
| 2093 { ui::VKEY_F1, keycode_f1_, ui::VKEY_F1, keycode_f1_, }, |
| 2094 { ui::VKEY_F2, keycode_f2_, ui::VKEY_F2, keycode_f2_, }, |
| 2095 { ui::VKEY_F3, keycode_f3_, ui::VKEY_F3, keycode_f3_, }, |
| 2096 { ui::VKEY_F4, keycode_f4_, ui::VKEY_F4, keycode_f4_, }, |
| 2097 { ui::VKEY_F5, keycode_f5_, ui::VKEY_F5, keycode_f5_, }, |
| 2098 { ui::VKEY_F6, keycode_f6_, ui::VKEY_F6, keycode_f6_, }, |
| 2099 { ui::VKEY_F7, keycode_f7_, ui::VKEY_F7, keycode_f7_, }, |
| 2100 { ui::VKEY_F8, keycode_f8_, ui::VKEY_F8, keycode_f8_, }, |
| 2101 { ui::VKEY_F9, keycode_f9_, ui::VKEY_F9, keycode_f9_, }, |
| 2102 { ui::VKEY_F10, keycode_f10_, ui::VKEY_F10, keycode_f10_, }, |
| 2103 { ui::VKEY_F11, keycode_f11_, ui::VKEY_F11, keycode_f11_, }, |
| 2104 { ui::VKEY_F12, keycode_f12_, ui::VKEY_F12, keycode_f12_, }, |
| 2105 { ui::VKEY_1, keycode_1_, ui::VKEY_1, keycode_1_, }, |
| 2106 { ui::VKEY_2, keycode_2_, ui::VKEY_2, keycode_2_, }, |
| 2107 { ui::VKEY_3, keycode_3_, ui::VKEY_3, keycode_3_, }, |
| 2108 { ui::VKEY_4, keycode_4_, ui::VKEY_4, keycode_4_, }, |
| 2109 { ui::VKEY_5, keycode_5_, ui::VKEY_5, keycode_5_, }, |
| 2110 { ui::VKEY_6, keycode_6_, ui::VKEY_6, keycode_6_, }, |
| 2111 { ui::VKEY_7, keycode_7_, ui::VKEY_7, keycode_7_, }, |
| 2112 { ui::VKEY_8, keycode_8_, ui::VKEY_8, keycode_8_, }, |
| 2113 { ui::VKEY_9, keycode_9_, ui::VKEY_9, keycode_9_, }, |
| 2114 { ui::VKEY_0, keycode_0_, ui::VKEY_0, keycode_0_, }, |
| 2115 { ui::VKEY_OEM_MINUS, keycode_minus_, ui::VKEY_OEM_MINUS, keycode_minus_, }, |
| 2116 { ui::VKEY_OEM_PLUS, keycode_equal_, ui::VKEY_OEM_PLUS, keycode_equal_, }, |
| 2117 }; |
| 2118 |
| 2119 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(default_tests); ++i) { |
| 2120 EXPECT_EQ(GetExpectedResultAsString(default_tests[i].output, |
| 2121 0, |
| 2122 ui::ET_KEY_PRESSED, |
| 2123 default_tests[i].output_native, |
| 2124 0U, |
| 2125 KeyPress), |
| 2126 GetRewrittenEventAsString(&rewriter, |
| 2127 default_tests[i].input, |
| 2128 0, |
| 2129 ui::ET_KEY_PRESSED, |
| 2130 default_tests[i].input_native, |
| 2131 0)); |
| 2132 |
| 2133 // Search key as a modifier does not change the outcome. |
| 2134 EXPECT_EQ(GetExpectedResultAsString(default_tests[i].output, |
| 2135 0, |
| 2136 ui::ET_KEY_PRESSED, |
| 2137 default_tests[i].output_native, |
| 2138 Mod4Mask, |
| 2139 KeyPress), |
| 2140 GetRewrittenEventAsString(&rewriter, |
| 2141 default_tests[i].input, |
| 2142 0, |
| 2143 ui::ET_KEY_PRESSED, |
| 2144 default_tests[i].input_native, |
| 2145 Mod4Mask)); |
| 2146 } |
| 2147 |
| 2148 // When on a Chromebook, but on the external keyboard, F<numbers> are not |
| 2149 // rewritten. |
| 2150 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 2151 switches::kHasChromeOSKeyboard, ""); |
| 2152 |
| 2153 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(default_tests); ++i) { |
| 2154 EXPECT_EQ(GetExpectedResultAsString(default_tests[i].output, |
| 2155 0, |
| 2156 ui::ET_KEY_PRESSED, |
| 2157 default_tests[i].output_native, |
| 2158 0U, |
| 2159 KeyPress), |
| 2160 GetRewrittenEventAsString(&rewriter, |
| 2161 default_tests[i].input, |
| 2162 0, |
| 2163 ui::ET_KEY_PRESSED, |
| 2164 default_tests[i].input_native, |
| 2165 0)); |
| 2166 |
| 2167 // Search key as a modifier does not change the outcome. |
| 2168 EXPECT_EQ(GetExpectedResultAsString(default_tests[i].output, |
| 2169 0, |
| 2170 ui::ET_KEY_PRESSED, |
| 2171 default_tests[i].output_native, |
| 2172 Mod4Mask, |
| 2173 KeyPress), |
| 2174 GetRewrittenEventAsString(&rewriter, |
| 2175 default_tests[i].input, |
| 2176 0, |
| 2177 ui::ET_KEY_PRESSED, |
| 2178 default_tests[i].input_native, |
| 2179 Mod4Mask)); |
| 2180 } |
| 2181 |
| 2182 // When on a chromebook keyboard, F<number> keys do special stuff. |
| 2183 rewriter.set_force_chromeos_keyboard_for_testing(true); |
| 2184 |
| 2185 struct { |
| 2186 ui::KeyboardCode input; |
| 2187 KeyCode input_native; |
| 2188 ui::KeyboardCode output; |
| 2189 KeyCode output_native; |
| 2190 } chromeos_tests[] = { |
| 2191 { // F1 -> Back |
| 2192 ui::VKEY_F1, keycode_f1_, |
| 2193 ui::VKEY_BROWSER_BACK, keycode_browser_back_ |
| 2194 }, |
| 2195 { // F2 -> Forward |
| 2196 ui::VKEY_F2, keycode_f2_, |
| 2197 ui::VKEY_BROWSER_FORWARD, keycode_browser_forward_ |
| 2198 }, |
| 2199 { // F3 -> Refresh |
| 2200 ui::VKEY_F3, keycode_f3_, |
| 2201 ui::VKEY_BROWSER_REFRESH, keycode_browser_refresh_ |
| 2202 }, |
| 2203 { // F4 -> Launch App 2 |
| 2204 ui::VKEY_F4, keycode_f4_, |
| 2205 ui::VKEY_MEDIA_LAUNCH_APP2, keycode_media_launch_app2_ |
| 2206 }, |
| 2207 { // F5 -> Launch App 1 |
| 2208 ui::VKEY_F5, keycode_f5_, |
| 2209 ui::VKEY_MEDIA_LAUNCH_APP1, keycode_media_launch_app1_ |
| 2210 }, |
| 2211 { // F6 -> Brightness down |
| 2212 ui::VKEY_F6, keycode_f6_, |
| 2213 ui::VKEY_BRIGHTNESS_DOWN, keycode_brightness_down_ |
| 2214 }, |
| 2215 { // F7 -> Brightness up |
| 2216 ui::VKEY_F7, keycode_f7_, |
| 2217 ui::VKEY_BRIGHTNESS_UP, keycode_brightness_up_ |
| 2218 }, |
| 2219 { // F8 -> Volume Mute |
| 2220 ui::VKEY_F8, keycode_f8_, |
| 2221 ui::VKEY_VOLUME_MUTE, keycode_volume_mute_ |
| 2222 }, |
| 2223 { // F9 -> Volume Down |
| 2224 ui::VKEY_F9, keycode_f9_, |
| 2225 ui::VKEY_VOLUME_DOWN, keycode_volume_down_ |
| 2226 }, |
| 2227 { // F10 -> Volume Up |
| 2228 ui::VKEY_F10, keycode_f10_, |
| 2229 ui::VKEY_VOLUME_UP, keycode_volume_up_ |
| 2230 }, |
| 2231 { // F11 -> F11 |
| 2232 ui::VKEY_F11, keycode_f11_, |
| 2233 ui::VKEY_F11, keycode_f11_ |
| 2234 }, |
| 2235 { // F12 -> F12 |
| 2236 ui::VKEY_F12, keycode_f12_, |
| 2237 ui::VKEY_F12, keycode_f12_, |
| 2238 }, |
| 2239 // The number row should not be rewritten. |
| 2240 { ui::VKEY_1, keycode_1_, ui::VKEY_1, keycode_1_, }, |
| 2241 { ui::VKEY_2, keycode_2_, ui::VKEY_2, keycode_2_, }, |
| 2242 { ui::VKEY_3, keycode_3_, ui::VKEY_3, keycode_3_, }, |
| 2243 { ui::VKEY_4, keycode_4_, ui::VKEY_4, keycode_4_, }, |
| 2244 { ui::VKEY_5, keycode_5_, ui::VKEY_5, keycode_5_, }, |
| 2245 { ui::VKEY_6, keycode_6_, ui::VKEY_6, keycode_6_, }, |
| 2246 { ui::VKEY_7, keycode_7_, ui::VKEY_7, keycode_7_, }, |
| 2247 { ui::VKEY_8, keycode_8_, ui::VKEY_8, keycode_8_, }, |
| 2248 { ui::VKEY_9, keycode_9_, ui::VKEY_9, keycode_9_, }, |
| 2249 { ui::VKEY_0, keycode_0_, ui::VKEY_0, keycode_0_, }, |
| 2250 { ui::VKEY_OEM_MINUS, keycode_minus_, ui::VKEY_OEM_MINUS, keycode_minus_, }, |
| 2251 { ui::VKEY_OEM_PLUS, keycode_equal_, ui::VKEY_OEM_PLUS, keycode_equal_, }, |
| 2252 }; |
| 2253 |
| 2254 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(chromeos_tests); ++i) { |
| 2255 EXPECT_EQ(GetExpectedResultAsString(chromeos_tests[i].output, |
| 2256 0, |
| 2257 ui::ET_KEY_PRESSED, |
| 2258 chromeos_tests[i].output_native, |
| 2259 0U, |
| 2260 KeyPress), |
| 2261 GetRewrittenEventAsString(&rewriter, |
| 2262 chromeos_tests[i].input, |
| 2263 0, |
| 2264 ui::ET_KEY_PRESSED, |
| 2265 chromeos_tests[i].input_native, |
| 2266 0)); |
| 2267 |
| 2268 // Search key as a modifier does not change the outcome. |
| 2269 EXPECT_EQ(GetExpectedResultAsString(chromeos_tests[i].output, |
| 2270 0, |
| 2271 ui::ET_KEY_PRESSED, |
| 2272 chromeos_tests[i].output_native, |
| 2273 Mod4Mask, |
| 2274 KeyPress), |
| 2275 GetRewrittenEventAsString(&rewriter, |
| 2276 chromeos_tests[i].input, |
| 2277 0, |
| 2278 ui::ET_KEY_PRESSED, |
| 2279 chromeos_tests[i].input_native, |
| 2280 Mod4Mask)); |
| 2281 } |
| 2282 |
| 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 |
| 2285 // act like the F<number> row. |
| 2286 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 2287 switches::kEnableChromebookFunctionKey, ""); |
| 2288 BooleanPrefMember search_key_as_function_key; |
| 2289 search_key_as_function_key.Init(prefs::kLanguageSearchKeyActsAsFunctionKey, |
| 2290 &prefs, NULL); |
| 2291 search_key_as_function_key.SetValue(true); |
| 2292 |
| 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) { |
| 2295 EXPECT_EQ(GetExpectedResultAsString(chromeos_tests[i].output, |
| 2296 0, |
| 2297 ui::ET_KEY_PRESSED, |
| 2298 chromeos_tests[i].output_native, |
| 2299 0U, |
| 2300 KeyPress), |
| 2301 GetRewrittenEventAsString(&rewriter, |
| 2302 chromeos_tests[i].input, |
| 2303 0, |
| 2304 ui::ET_KEY_PRESSED, |
| 2305 chromeos_tests[i].input_native, |
| 2306 0)); |
| 2307 } |
| 2308 |
| 2309 struct { |
| 2310 ui::KeyboardCode input; |
| 2311 KeyCode input_native; |
| 2312 ui::KeyboardCode output; |
| 2313 KeyCode output_native; |
| 2314 } search_key_tests[] = { |
| 2315 // The number row should be rewritten as the F<number> row. |
| 2316 { ui::VKEY_1, keycode_1_, ui::VKEY_F1, keycode_f1_, }, |
| 2317 { ui::VKEY_2, keycode_2_, ui::VKEY_F2, keycode_f2_, }, |
| 2318 { ui::VKEY_3, keycode_3_, ui::VKEY_F3, keycode_f3_, }, |
| 2319 { ui::VKEY_4, keycode_4_, ui::VKEY_F4, keycode_f4_, }, |
| 2320 { ui::VKEY_5, keycode_5_, ui::VKEY_F5, keycode_f5_, }, |
| 2321 { ui::VKEY_6, keycode_6_, ui::VKEY_F6, keycode_f6_, }, |
| 2322 { ui::VKEY_7, keycode_7_, ui::VKEY_F7, keycode_f7_, }, |
| 2323 { ui::VKEY_8, keycode_8_, ui::VKEY_F8, keycode_f8_, }, |
| 2324 { ui::VKEY_9, keycode_9_, ui::VKEY_F9, keycode_f9_, }, |
| 2325 { ui::VKEY_0, keycode_0_, ui::VKEY_F10, keycode_f10_, }, |
| 2326 { ui::VKEY_OEM_MINUS, keycode_minus_, ui::VKEY_F11, keycode_f11_, }, |
| 2327 { ui::VKEY_OEM_PLUS, keycode_equal_, ui::VKEY_F12, keycode_f12_, }, |
| 2328 }; |
| 2329 |
| 2330 // But with a Search key as a modifier, we should have new rewrite rules now. |
| 2331 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(search_key_tests); ++i) { |
| 2332 EXPECT_EQ(GetExpectedResultAsString(search_key_tests[i].output, |
| 2333 0, |
| 2334 ui::ET_KEY_PRESSED, |
| 2335 search_key_tests[i].output_native, |
| 2336 0, |
| 2337 KeyPress), |
| 2338 GetRewrittenEventAsString(&rewriter, |
| 2339 search_key_tests[i].input, |
| 2340 0, |
| 2341 ui::ET_KEY_PRESSED, |
| 2342 search_key_tests[i].input_native, |
| 2343 Mod4Mask)); |
| 2344 |
| 2345 // Other modifiers should be preserved. |
| 2346 EXPECT_EQ(GetExpectedResultAsString(search_key_tests[i].output, |
| 2347 ui::EF_ALT_DOWN, |
| 2348 ui::ET_KEY_PRESSED, |
| 2349 search_key_tests[i].output_native, |
| 2350 Mod1Mask, |
| 2351 KeyPress), |
| 2352 GetRewrittenEventAsString(&rewriter, |
| 2353 search_key_tests[i].input, |
| 2354 ui::EF_ALT_DOWN, |
| 2355 ui::ET_KEY_PRESSED, |
| 2356 search_key_tests[i].input_native, |
| 2357 Mod4Mask | Mod1Mask)); |
| 2358 |
| 2359 EXPECT_EQ(GetExpectedResultAsString(search_key_tests[i].output, |
| 2360 ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, |
| 2361 ui::ET_KEY_PRESSED, |
| 2362 search_key_tests[i].output_native, |
| 2363 ControlMask | Mod1Mask, |
| 2364 KeyPress), |
| 2365 GetRewrittenEventAsString(&rewriter, |
| 2366 search_key_tests[i].input, |
| 2367 ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN, |
| 2368 ui::ET_KEY_PRESSED, |
| 2369 search_key_tests[i].input_native, |
| 2370 Mod4Mask | ControlMask | Mod1Mask)); |
| 2371 } |
| 2372 |
| 2373 *CommandLine::ForCurrentProcess() = original_cl; |
| 2374 } |
| 2375 |
1997 TEST_F(EventRewriterTest, TestRewriteBackspaceAndArrowKeysWithSearchRemapped) { | 2376 TEST_F(EventRewriterTest, TestRewriteBackspaceAndArrowKeysWithSearchRemapped) { |
| 2377 const CommandLine original_cl(*CommandLine::ForCurrentProcess()); |
| 2378 |
1998 // Remap Search to Control. | 2379 // Remap Search to Control. |
1999 TestingPrefService prefs; | 2380 TestingPrefService prefs; |
2000 chromeos::Preferences::RegisterUserPrefs(&prefs); | 2381 chromeos::Preferences::RegisterUserPrefs(&prefs); |
2001 IntegerPrefMember search; | 2382 IntegerPrefMember search; |
2002 search.Init(prefs::kLanguageRemapSearchKeyTo, &prefs, NULL); | 2383 search.Init(prefs::kLanguageRemapSearchKeyTo, &prefs, NULL); |
2003 search.SetValue(chromeos::input_method::kControlKey); | 2384 search.SetValue(chromeos::input_method::kControlKey); |
2004 | 2385 |
2005 EventRewriter rewriter; | 2386 EventRewriter rewriter; |
2006 rewriter.set_pref_service_for_testing(&prefs); | 2387 rewriter.set_pref_service_for_testing(&prefs); |
2007 | 2388 |
| 2389 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 2390 switches::kHasChromeOSKeyboard, ""); |
| 2391 rewriter.set_force_chromeos_keyboard_for_testing(true); |
| 2392 |
2008 // Alt+Search+Down -> End | 2393 // Alt+Search+Down -> End |
2009 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_END, | 2394 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_END, |
2010 0, | 2395 0, |
2011 ui::ET_KEY_PRESSED, | 2396 ui::ET_KEY_PRESSED, |
2012 keycode_end_, | 2397 keycode_end_, |
2013 0U, | 2398 0U, |
2014 KeyPress), | 2399 KeyPress), |
2015 GetRewrittenEventAsString(&rewriter, | 2400 GetRewrittenEventAsString(&rewriter, |
2016 ui::VKEY_DOWN, | 2401 ui::VKEY_DOWN, |
2017 ui::EF_ALT_DOWN, | 2402 ui::EF_ALT_DOWN, |
2018 ui::ET_KEY_PRESSED, | 2403 ui::ET_KEY_PRESSED, |
2019 keycode_down_, | 2404 keycode_down_, |
2020 Mod1Mask | Mod4Mask)); | 2405 Mod1Mask | Mod4Mask)); |
2021 | 2406 |
2022 // Shift+Alt+Search+Down -> Shift+End | 2407 // Shift+Alt+Search+Down -> Shift+End |
2023 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_END, | 2408 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_END, |
2024 ui::EF_SHIFT_DOWN, | 2409 ui::EF_SHIFT_DOWN, |
2025 ui::ET_KEY_PRESSED, | 2410 ui::ET_KEY_PRESSED, |
2026 keycode_end_, | 2411 keycode_end_, |
2027 ShiftMask, | 2412 ShiftMask, |
2028 KeyPress), | 2413 KeyPress), |
2029 GetRewrittenEventAsString(&rewriter, | 2414 GetRewrittenEventAsString(&rewriter, |
2030 ui::VKEY_DOWN, | 2415 ui::VKEY_DOWN, |
2031 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN, | 2416 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN, |
2032 ui::ET_KEY_PRESSED, | 2417 ui::ET_KEY_PRESSED, |
2033 keycode_down_, | 2418 keycode_down_, |
2034 ShiftMask | Mod1Mask | Mod4Mask)); | 2419 ShiftMask | Mod1Mask | Mod4Mask)); |
| 2420 |
| 2421 *CommandLine::ForCurrentProcess() = original_cl; |
2035 } | 2422 } |
2036 | 2423 |
2037 TEST_F(EventRewriterTest, TestRewriteKeyEventSentByXSendEvent) { | 2424 TEST_F(EventRewriterTest, TestRewriteKeyEventSentByXSendEvent) { |
2038 // Remap Control to Alt. | 2425 // Remap Control to Alt. |
2039 TestingPrefService prefs; | 2426 TestingPrefService prefs; |
2040 chromeos::Preferences::RegisterUserPrefs(&prefs); | 2427 chromeos::Preferences::RegisterUserPrefs(&prefs); |
2041 IntegerPrefMember control; | 2428 IntegerPrefMember control; |
2042 control.Init(prefs::kLanguageRemapControlKeyTo, &prefs, NULL); | 2429 control.Init(prefs::kLanguageRemapControlKeyTo, &prefs, NULL); |
2043 control.SetValue(chromeos::input_method::kAltKey); | 2430 control.SetValue(chromeos::input_method::kAltKey); |
2044 | 2431 |
(...skipping 20 matching lines...) Expand all Loading... |
2065 // flag in the event is True. | 2452 // flag in the event is True. |
2066 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CONTROL, | 2453 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CONTROL, |
2067 ui::EF_CONTROL_DOWN, | 2454 ui::EF_CONTROL_DOWN, |
2068 ui::ET_KEY_PRESSED, | 2455 ui::ET_KEY_PRESSED, |
2069 keycode_control_l_, | 2456 keycode_control_l_, |
2070 0U, | 2457 0U, |
2071 KeyPress), | 2458 KeyPress), |
2072 rewritten_event); | 2459 rewritten_event); |
2073 } | 2460 } |
2074 #endif // OS_CHROMEOS | 2461 #endif // OS_CHROMEOS |
OLD | NEW |