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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 keycode_num_pad_prior_(XKeysymToKeycode(display_, XK_KP_Prior)), | 103 keycode_num_pad_prior_(XKeysymToKeycode(display_, XK_KP_Prior)), |
104 keycode_num_pad_right_(XKeysymToKeycode(display_, XK_KP_Right)), | 104 keycode_num_pad_right_(XKeysymToKeycode(display_, XK_KP_Right)), |
105 keycode_num_pad_up_(XKeysymToKeycode(display_, XK_KP_Up)), | 105 keycode_num_pad_up_(XKeysymToKeycode(display_, XK_KP_Up)), |
106 keycode_super_l_(XKeysymToKeycode(display_, XK_Super_L)), | 106 keycode_super_l_(XKeysymToKeycode(display_, XK_Super_L)), |
107 keycode_super_r_(XKeysymToKeycode(display_, XK_Super_R)), | 107 keycode_super_r_(XKeysymToKeycode(display_, XK_Super_R)), |
108 keycode_void_symbol_(XKeysymToKeycode(display_, XK_VoidSymbol)), | 108 keycode_void_symbol_(XKeysymToKeycode(display_, XK_VoidSymbol)), |
109 keycode_delete_(XKeysymToKeycode(display_, XK_Delete)), | 109 keycode_delete_(XKeysymToKeycode(display_, XK_Delete)), |
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)), |
| 114 keycode_right_(XKeysymToKeycode(display_, XK_Right)), |
113 keycode_prior_(XKeysymToKeycode(display_, XK_Prior)), | 115 keycode_prior_(XKeysymToKeycode(display_, XK_Prior)), |
114 keycode_next_(XKeysymToKeycode(display_, XK_Next)), | 116 keycode_next_(XKeysymToKeycode(display_, XK_Next)), |
115 keycode_home_(XKeysymToKeycode(display_, XK_Home)), | 117 keycode_home_(XKeysymToKeycode(display_, XK_Home)), |
116 keycode_end_(XKeysymToKeycode(display_, XK_End)), | 118 keycode_end_(XKeysymToKeycode(display_, XK_End)), |
117 keycode_launch7_(XKeysymToKeycode(display_, XF86XK_Launch7)), | 119 keycode_launch7_(XKeysymToKeycode(display_, XF86XK_Launch7)), |
118 input_method_manager_mock_(NULL) { | 120 input_method_manager_mock_(NULL) { |
119 } | 121 } |
120 virtual ~EventRewriterTest() {} | 122 virtual ~EventRewriterTest() {} |
121 | 123 |
122 virtual void SetUp() { | 124 virtual void SetUp() { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 const KeyCode keycode_num_pad_prior_; | 169 const KeyCode keycode_num_pad_prior_; |
168 const KeyCode keycode_num_pad_right_; | 170 const KeyCode keycode_num_pad_right_; |
169 const KeyCode keycode_num_pad_up_; | 171 const KeyCode keycode_num_pad_up_; |
170 const KeyCode keycode_super_l_; | 172 const KeyCode keycode_super_l_; |
171 const KeyCode keycode_super_r_; | 173 const KeyCode keycode_super_r_; |
172 const KeyCode keycode_void_symbol_; | 174 const KeyCode keycode_void_symbol_; |
173 const KeyCode keycode_delete_; | 175 const KeyCode keycode_delete_; |
174 const KeyCode keycode_backspace_; | 176 const KeyCode keycode_backspace_; |
175 const KeyCode keycode_up_; | 177 const KeyCode keycode_up_; |
176 const KeyCode keycode_down_; | 178 const KeyCode keycode_down_; |
| 179 const KeyCode keycode_left_; |
| 180 const KeyCode keycode_right_; |
177 const KeyCode keycode_prior_; | 181 const KeyCode keycode_prior_; |
178 const KeyCode keycode_next_; | 182 const KeyCode keycode_next_; |
179 const KeyCode keycode_home_; | 183 const KeyCode keycode_home_; |
180 const KeyCode keycode_end_; | 184 const KeyCode keycode_end_; |
181 const KeyCode keycode_launch7_; // F16 | 185 const KeyCode keycode_launch7_; // F16 |
182 chromeos::ScopedMockUserManagerEnabler user_manager_mock_; | 186 chromeos::ScopedMockUserManagerEnabler user_manager_mock_; |
183 chromeos::input_method::MockInputMethodManager* input_method_manager_mock_; | 187 chromeos::input_method::MockInputMethodManager* input_method_manager_mock_; |
184 }; | 188 }; |
185 | 189 |
186 } // namespace | 190 } // namespace |
(...skipping 1484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1671 0, | 1675 0, |
1672 ui::ET_KEY_PRESSED, | 1676 ui::ET_KEY_PRESSED, |
1673 keycode_a_, | 1677 keycode_a_, |
1674 Mod3Mask)); | 1678 Mod3Mask)); |
1675 | 1679 |
1676 input_method_manager_mock_->SetCurrentInputMethodId("xkb:us::eng"); | 1680 input_method_manager_mock_->SetCurrentInputMethodId("xkb:us::eng"); |
1677 } | 1681 } |
1678 | 1682 |
1679 TEST_F(EventRewriterTest, TestRewriteBackspaceAndArrowKeys) { | 1683 TEST_F(EventRewriterTest, TestRewriteBackspaceAndArrowKeys) { |
1680 TestingPrefService prefs; | 1684 TestingPrefService prefs; |
| 1685 chromeos::Preferences::RegisterUserPrefs(&prefs); |
1681 EventRewriter rewriter; | 1686 EventRewriter rewriter; |
1682 rewriter.set_pref_service_for_testing(&prefs); | 1687 rewriter.set_pref_service_for_testing(&prefs); |
1683 | 1688 |
1684 // Alt+Backspace -> Delete | 1689 // Alt+Backspace -> Delete |
1685 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_DELETE, | 1690 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_DELETE, |
1686 0, | 1691 0, |
1687 ui::ET_KEY_PRESSED, | 1692 ui::ET_KEY_PRESSED, |
1688 keycode_delete_, | 1693 keycode_delete_, |
1689 0U, | 1694 0U, |
1690 KeyPress), | 1695 KeyPress), |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1772 keycode_end_, | 1777 keycode_end_, |
1773 ShiftMask, | 1778 ShiftMask, |
1774 KeyPress), | 1779 KeyPress), |
1775 GetRewrittenEventAsString(&rewriter, | 1780 GetRewrittenEventAsString(&rewriter, |
1776 ui::VKEY_DOWN, | 1781 ui::VKEY_DOWN, |
1777 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN | | 1782 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN | |
1778 ui::EF_CONTROL_DOWN, | 1783 ui::EF_CONTROL_DOWN, |
1779 ui::ET_KEY_PRESSED, | 1784 ui::ET_KEY_PRESSED, |
1780 keycode_down_, | 1785 keycode_down_, |
1781 ShiftMask | Mod1Mask | ControlMask)); | 1786 ShiftMask | Mod1Mask | ControlMask)); |
| 1787 |
| 1788 // Make Search key act like a Function key for accessing extended key |
| 1789 // bindings. |
| 1790 const CommandLine original_cl(*CommandLine::ForCurrentProcess()); |
| 1791 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 1792 switches::kEnableChromebookFunctionKey, ""); |
| 1793 BooleanPrefMember search_key_as_function_key; |
| 1794 search_key_as_function_key.Init(prefs::kLanguageSearchKeyActsAsFunctionKey, |
| 1795 &prefs, NULL); |
| 1796 search_key_as_function_key.SetValue(true); |
| 1797 |
| 1798 // Alt+Backspace -> Alt+Backspace |
| 1799 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_BACK, |
| 1800 ui::EF_ALT_DOWN, |
| 1801 ui::ET_KEY_PRESSED, |
| 1802 keycode_backspace_, |
| 1803 Mod1Mask, |
| 1804 KeyPress), |
| 1805 GetRewrittenEventAsString(&rewriter, |
| 1806 ui::VKEY_BACK, |
| 1807 ui::EF_ALT_DOWN, |
| 1808 ui::ET_KEY_PRESSED, |
| 1809 keycode_backspace_, |
| 1810 Mod1Mask)); |
| 1811 |
| 1812 // Search+Backspace -> Delete |
| 1813 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_DELETE, |
| 1814 0, |
| 1815 ui::ET_KEY_PRESSED, |
| 1816 keycode_delete_, |
| 1817 0U, |
| 1818 KeyPress), |
| 1819 GetRewrittenEventAsString(&rewriter, |
| 1820 ui::VKEY_BACK, |
| 1821 0, |
| 1822 ui::ET_KEY_PRESSED, |
| 1823 keycode_backspace_, |
| 1824 Mod4Mask)); |
| 1825 |
| 1826 // Ctrl+Search+Backspace -> Ctrl+Delete |
| 1827 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_DELETE, |
| 1828 ui::EF_CONTROL_DOWN, |
| 1829 ui::ET_KEY_PRESSED, |
| 1830 keycode_delete_, |
| 1831 ControlMask, |
| 1832 KeyPress), |
| 1833 GetRewrittenEventAsString(&rewriter, |
| 1834 ui::VKEY_BACK, |
| 1835 0, |
| 1836 ui::ET_KEY_PRESSED, |
| 1837 keycode_backspace_, |
| 1838 Mod4Mask | ControlMask)); |
| 1839 |
| 1840 // Alt+Search+Backspace -> Alt+Delete |
| 1841 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_DELETE, |
| 1842 ui::EF_ALT_DOWN, |
| 1843 ui::ET_KEY_PRESSED, |
| 1844 keycode_delete_, |
| 1845 Mod1Mask, |
| 1846 KeyPress), |
| 1847 GetRewrittenEventAsString(&rewriter, |
| 1848 ui::VKEY_BACK, |
| 1849 0, |
| 1850 ui::ET_KEY_PRESSED, |
| 1851 keycode_backspace_, |
| 1852 Mod4Mask | Mod1Mask)); |
| 1853 |
| 1854 // Alt+Up -> Alt+Up |
| 1855 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_UP, |
| 1856 ui::EF_ALT_DOWN, |
| 1857 ui::ET_KEY_PRESSED, |
| 1858 keycode_up_, |
| 1859 Mod1Mask, |
| 1860 KeyPress), |
| 1861 GetRewrittenEventAsString(&rewriter, |
| 1862 ui::VKEY_UP, |
| 1863 ui::EF_ALT_DOWN, |
| 1864 ui::ET_KEY_PRESSED, |
| 1865 keycode_up_, |
| 1866 Mod1Mask)); |
| 1867 |
| 1868 // Search+Up -> Prior |
| 1869 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_PRIOR, |
| 1870 0, |
| 1871 ui::ET_KEY_PRESSED, |
| 1872 keycode_prior_, |
| 1873 0U, |
| 1874 KeyPress), |
| 1875 GetRewrittenEventAsString(&rewriter, |
| 1876 ui::VKEY_UP, |
| 1877 0, |
| 1878 ui::ET_KEY_PRESSED, |
| 1879 keycode_up_, |
| 1880 Mod4Mask)); |
| 1881 |
| 1882 // Alt+Down -> Alt+Down |
| 1883 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_DOWN, |
| 1884 ui::EF_ALT_DOWN, |
| 1885 ui::ET_KEY_PRESSED, |
| 1886 keycode_down_, |
| 1887 Mod1Mask, |
| 1888 KeyPress), |
| 1889 GetRewrittenEventAsString(&rewriter, |
| 1890 ui::VKEY_DOWN, |
| 1891 ui::EF_ALT_DOWN, |
| 1892 ui::ET_KEY_PRESSED, |
| 1893 keycode_down_, |
| 1894 Mod1Mask)); |
| 1895 |
| 1896 // Search+Down -> Next |
| 1897 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_NEXT, |
| 1898 0, |
| 1899 ui::ET_KEY_PRESSED, |
| 1900 keycode_next_, |
| 1901 0U, |
| 1902 KeyPress), |
| 1903 GetRewrittenEventAsString(&rewriter, |
| 1904 ui::VKEY_DOWN, |
| 1905 0, |
| 1906 ui::ET_KEY_PRESSED, |
| 1907 keycode_down_, |
| 1908 Mod4Mask)); |
| 1909 |
| 1910 // Ctrl+Alt+Up -> Ctrl+Alt+Up |
| 1911 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_UP, |
| 1912 ui::EF_ALT_DOWN | ui::EF_CONTROL_DOWN, |
| 1913 ui::ET_KEY_PRESSED, |
| 1914 keycode_up_, |
| 1915 Mod1Mask | ControlMask, |
| 1916 KeyPress), |
| 1917 GetRewrittenEventAsString(&rewriter, |
| 1918 ui::VKEY_UP, |
| 1919 ui::EF_ALT_DOWN | ui::EF_CONTROL_DOWN, |
| 1920 ui::ET_KEY_PRESSED, |
| 1921 keycode_up_, |
| 1922 Mod1Mask | ControlMask)); |
| 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 |
| 1994 *CommandLine::ForCurrentProcess() = original_cl; |
1782 } | 1995 } |
1783 | 1996 |
1784 TEST_F(EventRewriterTest, TestRewriteBackspaceAndArrowKeysWithSearchRemapped) { | 1997 TEST_F(EventRewriterTest, TestRewriteBackspaceAndArrowKeysWithSearchRemapped) { |
1785 // Remap Search to Control. | 1998 // Remap Search to Control. |
1786 TestingPrefService prefs; | 1999 TestingPrefService prefs; |
1787 chromeos::Preferences::RegisterUserPrefs(&prefs); | 2000 chromeos::Preferences::RegisterUserPrefs(&prefs); |
1788 IntegerPrefMember search; | 2001 IntegerPrefMember search; |
1789 search.Init(prefs::kLanguageRemapSearchKeyTo, &prefs, NULL); | 2002 search.Init(prefs::kLanguageRemapSearchKeyTo, &prefs, NULL); |
1790 search.SetValue(chromeos::input_method::kControlKey); | 2003 search.SetValue(chromeos::input_method::kControlKey); |
1791 | 2004 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1852 // flag in the event is True. | 2065 // flag in the event is True. |
1853 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CONTROL, | 2066 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CONTROL, |
1854 ui::EF_CONTROL_DOWN, | 2067 ui::EF_CONTROL_DOWN, |
1855 ui::ET_KEY_PRESSED, | 2068 ui::ET_KEY_PRESSED, |
1856 keycode_control_l_, | 2069 keycode_control_l_, |
1857 0U, | 2070 0U, |
1858 KeyPress), | 2071 KeyPress), |
1859 rewritten_event); | 2072 rewritten_event); |
1860 } | 2073 } |
1861 #endif // OS_CHROMEOS | 2074 #endif // OS_CHROMEOS |
OLD | NEW |