OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/extensions/extension_apitest.h" | 5 #include "chrome/browser/extensions/extension_apitest.h" |
6 #include "chrome/browser/extensions/window_controller.h" | 6 #include "chrome/browser/extensions/window_controller.h" |
7 #include "chrome/browser/ui/browser_window.h" | 7 #include "chrome/browser/ui/browser_window.h" |
8 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 8 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
9 #include "chrome/test/base/interactive_test_utils.h" | 9 #include "chrome/test/base/interactive_test_utils.h" |
10 #include "content/public/test/browser_test_utils.h" | 10 #include "content/public/test/browser_test_utils.h" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 CGEventPost(event_tap_location, shift_down); | 104 CGEventPost(event_tap_location, shift_down); |
105 CGEventPost(event_tap_location, key_down); | 105 CGEventPost(event_tap_location, key_down); |
106 CGEventPost(event_tap_location, key_up); | 106 CGEventPost(event_tap_location, key_up); |
107 CGEventPost(event_tap_location, shift_up); | 107 CGEventPost(event_tap_location, shift_up); |
108 CGEventPost(event_tap_location, command_up); | 108 CGEventPost(event_tap_location, command_up); |
109 | 109 |
110 CFRelease(event_source); | 110 CFRelease(event_source); |
111 } | 111 } |
112 #endif | 112 #endif |
113 | 113 |
114 #if defined(OS_CHROMEOS) | |
115 // Fully implemented everywhere except Chrome OS. | |
116 #define MAYBE_GlobalCommand DISABLED_GlobalCommand | |
117 #else | |
118 #define MAYBE_GlobalCommand GlobalCommand | |
119 #endif | |
120 | |
121 // Test the basics of global commands and make sure they work when Chrome | 114 // Test the basics of global commands and make sure they work when Chrome |
122 // doesn't have focus. Also test that non-global commands are not treated as | 115 // doesn't have focus. Also test that non-global commands are not treated as |
123 // global and that keys beyond Ctrl+Shift+[0..9] cannot be auto-assigned by an | 116 // global and that keys beyond Ctrl+Shift+[0..9] cannot be auto-assigned by an |
124 // extension. | 117 // extension. |
125 IN_PROC_BROWSER_TEST_F(GlobalCommandsApiTest, MAYBE_GlobalCommand) { | 118 IN_PROC_BROWSER_TEST_F(GlobalCommandsApiTest, GlobalCommand) { |
126 FeatureSwitch::ScopedOverride enable_global_commands( | |
127 FeatureSwitch::global_commands(), true); | |
128 | |
129 // Load the extension in the non-incognito browser. | 119 // Load the extension in the non-incognito browser. |
130 ResultCatcher catcher; | 120 ResultCatcher catcher; |
131 ASSERT_TRUE(RunExtensionTest("keybinding/global")) << message_; | 121 ASSERT_TRUE(RunExtensionTest("keybinding/global")) << message_; |
132 ASSERT_TRUE(catcher.GetNextResult()); | 122 ASSERT_TRUE(catcher.GetNextResult()); |
133 | 123 |
134 #if defined(OS_WIN) | 124 #if defined(OS_WIN) || defined(OS_CHROMEOS) |
135 // Our infrastructure for sending keys expects a browser to send them to, but | 125 // Our infrastructure for sending keys expects a browser to send them to, but |
136 // to properly test global shortcuts you need to send them to another target. | 126 // to properly test global shortcuts you need to send them to another target. |
137 // So, create an incognito browser to use as a target to send the shortcuts | 127 // So, create an incognito browser to use as a target to send the shortcuts |
138 // to. It will ignore all of them and allow us test whether the global | 128 // to. It will ignore all of them and allow us test whether the global |
139 // shortcut really is global in nature and also that the non-global shortcut | 129 // shortcut really is global in nature and also that the non-global shortcut |
140 // is non-global. | 130 // is non-global. |
141 Browser* incognito_browser = CreateIncognitoBrowser(); | 131 Browser* incognito_browser = CreateIncognitoBrowser(); |
142 | 132 |
143 // Try to activate the non-global shortcut (Ctrl+Shift+1) and the | 133 // Try to activate the non-global shortcut (Ctrl+Shift+1) and the |
144 // non-assignable shortcut (Ctrl+Shift+A) by sending the keystrokes to the | 134 // non-assignable shortcut (Ctrl+Shift+A) by sending the keystrokes to the |
145 // incognito browser. Both shortcuts should have no effect (extension is not | 135 // incognito browser. Both shortcuts should have no effect (extension is not |
146 // loaded there). | 136 // loaded there). |
147 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 137 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
148 incognito_browser, ui::VKEY_1, true, true, false, false)); | 138 incognito_browser, ui::VKEY_1, true, true, false, false)); |
149 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 139 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
150 incognito_browser, ui::VKEY_A, true, true, false, false)); | 140 incognito_browser, ui::VKEY_A, true, true, false, false)); |
151 | 141 |
152 // Activate the shortcut (Ctrl+Shift+9). This should have an effect. | 142 // Activate the shortcut (Ctrl+Shift+8). This should have an effect. |
153 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 143 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
154 incognito_browser, ui::VKEY_9, true, true, false, false)); | 144 incognito_browser, ui::VKEY_8, true, true, false, false)); |
155 #elif defined(OS_LINUX) && defined(USE_X11) | 145 #elif defined(OS_LINUX) && defined(USE_X11) |
156 // Create an incognito browser to capture the focus. | 146 // Create an incognito browser to capture the focus. |
157 CreateIncognitoBrowser(); | 147 CreateIncognitoBrowser(); |
158 | 148 |
159 // On Linux, our infrastructure for sending keys just synthesize keyboard | 149 // On Linux, our infrastructure for sending keys just synthesize keyboard |
160 // event and send them directly to the specified window, without notifying the | 150 // event and send them directly to the specified window, without notifying the |
161 // X root window. It didn't work while testing global shortcut because the | 151 // X root window. It didn't work while testing global shortcut because the |
162 // stuff of global shortcut on Linux need to be notified when KeyPress event | 152 // stuff of global shortcut on Linux need to be notified when KeyPress event |
163 // is happening on X root window. So we simulate the keyboard input here. | 153 // is happening on X root window. So we simulate the keyboard input here. |
164 SendNativeKeyEventToXDisplay(ui::VKEY_1, true, true, false); | 154 SendNativeKeyEventToXDisplay(ui::VKEY_1, true, true, false); |
165 SendNativeKeyEventToXDisplay(ui::VKEY_A, true, true, false); | 155 SendNativeKeyEventToXDisplay(ui::VKEY_A, true, true, false); |
166 SendNativeKeyEventToXDisplay(ui::VKEY_9, true, true, false); | 156 SendNativeKeyEventToXDisplay(ui::VKEY_8, true, true, false); |
167 #elif defined(OS_MACOSX) | 157 #elif defined(OS_MACOSX) |
168 // Create an incognito browser to capture the focus. | 158 // Create an incognito browser to capture the focus. |
169 CreateIncognitoBrowser(); | 159 CreateIncognitoBrowser(); |
170 | 160 |
171 // Send some native mac key events. | 161 // Send some native mac key events. |
172 SendNativeCommandShift(kVK_ANSI_1); | 162 SendNativeCommandShift(kVK_ANSI_1); |
173 SendNativeCommandShift(kVK_ANSI_A); | 163 SendNativeCommandShift(kVK_ANSI_A); |
174 SendNativeCommandShift(kVK_ANSI_9); | 164 SendNativeCommandShift(kVK_ANSI_8); |
175 #endif | 165 #endif |
176 | 166 |
177 // If this fails, it might be because the global shortcut failed to work, | 167 // If this fails, it might be because the global shortcut failed to work, |
178 // but it might also be because the non-global shortcuts unexpectedly | 168 // but it might also be because the non-global shortcuts unexpectedly |
179 // worked. | 169 // worked. |
180 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 170 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
181 } | 171 } |
182 | 172 |
183 #if defined(OS_WIN) | 173 #if defined(OS_WIN) |
184 // The feature is only fully implemented on Windows, other platforms coming. | 174 // Feature only fully implemented on Windows, other platforms coming. |
185 // TODO(smus): On mac, SendKeyPress must first support media keys. | 175 // TODO(smus): On mac, SendKeyPress must first support media keys. |
186 #define MAYBE_GlobalDuplicatedMediaKey GlobalDuplicatedMediaKey | 176 #define MAYBE_GlobalDuplicatedMediaKey GlobalDuplicatedMediaKey |
187 #else | 177 #else |
188 #define MAYBE_GlobalDuplicatedMediaKey DISABLED_GlobalDuplicatedMediaKey | 178 #define MAYBE_GlobalDuplicatedMediaKey DISABLED_GlobalDuplicatedMediaKey |
189 #endif | 179 #endif |
190 | 180 |
191 IN_PROC_BROWSER_TEST_F(GlobalCommandsApiTest, MAYBE_GlobalDuplicatedMediaKey) { | 181 IN_PROC_BROWSER_TEST_F(GlobalCommandsApiTest, MAYBE_GlobalDuplicatedMediaKey) { |
192 FeatureSwitch::ScopedOverride enable_global_commands( | |
193 FeatureSwitch::global_commands(), true); | |
194 | |
195 ResultCatcher catcher; | 182 ResultCatcher catcher; |
196 ASSERT_TRUE(RunExtensionTest("keybinding/global_media_keys_0")) << message_; | 183 ASSERT_TRUE(RunExtensionTest("keybinding/global_media_keys_0")) << message_; |
197 ASSERT_TRUE(catcher.GetNextResult()); | 184 ASSERT_TRUE(catcher.GetNextResult()); |
198 ASSERT_TRUE(RunExtensionTest("keybinding/global_media_keys_1")) << message_; | 185 ASSERT_TRUE(RunExtensionTest("keybinding/global_media_keys_1")) << message_; |
199 ASSERT_TRUE(catcher.GetNextResult()); | 186 ASSERT_TRUE(catcher.GetNextResult()); |
200 | 187 |
201 Browser* incognito_browser = CreateIncognitoBrowser(); // Ditto. | 188 Browser* incognito_browser = CreateIncognitoBrowser(); // Ditto. |
202 WindowController* controller = | 189 WindowController* controller = |
203 incognito_browser->extension_window_controller(); | 190 incognito_browser->extension_window_controller(); |
204 | 191 |
205 ui_controls::SendKeyPress(controller->window()->GetNativeWindow(), | 192 ui_controls::SendKeyPress(controller->window()->GetNativeWindow(), |
206 ui::VKEY_MEDIA_NEXT_TRACK, | 193 ui::VKEY_MEDIA_NEXT_TRACK, |
207 false, | 194 false, |
208 false, | 195 false, |
209 false, | 196 false, |
210 false); | 197 false); |
211 | 198 |
212 // We should get two success result. | 199 // We should get two success results. |
213 ASSERT_TRUE(catcher.GetNextResult()); | 200 ASSERT_TRUE(catcher.GetNextResult()); |
214 ASSERT_TRUE(catcher.GetNextResult()); | 201 ASSERT_TRUE(catcher.GetNextResult()); |
215 } | 202 } |
216 | 203 |
217 } // namespace extensions | 204 } // namespace extensions |
OLD | NEW |