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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 #include "chrome/browser/extensions/extension_apitest.h" | 6 #include "chrome/browser/extensions/extension_apitest.h" |
7 #include "chrome/browser/extensions/window_controller.h" | 7 #include "chrome/browser/extensions/window_controller.h" |
8 #include "chrome/browser/ui/browser_window.h" | 8 #include "chrome/browser/ui/browser_window.h" |
9 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 9 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
10 #include "chrome/test/base/interactive_test_utils.h" | 10 #include "chrome/test/base/interactive_test_utils.h" |
11 #include "content/public/test/browser_test_utils.h" | 11 #include "content/public/test/browser_test_utils.h" |
12 #include "extensions/test/result_catcher.h" | 12 #include "extensions/test/result_catcher.h" |
13 #include "ui/base/base_window.h" | 13 #include "ui/base/base_window.h" |
14 #include "ui/base/test/ui_controls.h" | 14 #include "ui/base/test/ui_controls.h" |
15 | 15 |
16 #if defined(OS_LINUX) && defined(USE_X11) | 16 #if defined(OS_LINUX) && defined(USE_X11) |
17 #include <X11/Xlib.h> | 17 #include <X11/Xlib.h> |
18 #include <X11/extensions/XTest.h> | 18 #include <X11/extensions/XTest.h> |
19 #include <X11/keysym.h> | 19 #include <X11/keysym.h> |
20 | 20 #include "ui/aura/window.h" |
21 #include "ui/events/keycodes/keyboard_code_conversion_x.h" | 21 #include "ui/events/keycodes/keyboard_code_conversion_x.h" |
22 #include "ui/gfx/x/x11_types.h" | 22 #include "ui/gfx/x/x11_types.h" |
| 23 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_observer_x11.h" |
| 24 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" |
23 #endif | 25 #endif |
24 | 26 |
25 #if defined(OS_MACOSX) | 27 #if defined(OS_MACOSX) |
26 #include <Carbon/Carbon.h> | 28 #include <Carbon/Carbon.h> |
27 | 29 |
28 #include "base/mac/scoped_cftyperef.h" | 30 #include "base/mac/scoped_cftyperef.h" |
29 #endif | 31 #endif |
30 | 32 |
31 namespace extensions { | 33 namespace extensions { |
32 | 34 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 150 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
149 incognito_browser, ui::VKEY_1, true, true, false, false)); | 151 incognito_browser, ui::VKEY_1, true, true, false, false)); |
150 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 152 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
151 incognito_browser, ui::VKEY_A, true, true, false, false)); | 153 incognito_browser, ui::VKEY_A, true, true, false, false)); |
152 | 154 |
153 // Activate the shortcut (Ctrl+Shift+8). This should have an effect. | 155 // Activate the shortcut (Ctrl+Shift+8). This should have an effect. |
154 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 156 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
155 incognito_browser, ui::VKEY_8, true, true, false, false)); | 157 incognito_browser, ui::VKEY_8, true, true, false, false)); |
156 #elif defined(OS_LINUX) && defined(USE_X11) | 158 #elif defined(OS_LINUX) && defined(USE_X11) |
157 // Create an incognito browser to capture the focus. | 159 // Create an incognito browser to capture the focus. |
158 CreateIncognitoBrowser(); | 160 Browser* incognito_browser = CreateIncognitoBrowser(); |
159 | 161 |
160 // On Linux, our infrastructure for sending keys just synthesize keyboard | 162 views::DesktopWindowTreeHostX11* host = |
161 // event and send them directly to the specified window, without notifying the | 163 static_cast<views::DesktopWindowTreeHostX11*>( |
162 // X root window. It didn't work while testing global shortcut because the | 164 incognito_browser->window()->GetNativeWindow()->GetHost()); |
163 // stuff of global shortcut on Linux need to be notified when KeyPress event | 165 |
164 // is happening on X root window. So we simulate the keyboard input here. | 166 class GlobalCommandTreeHostObserver |
165 SendNativeKeyEventToXDisplay(ui::VKEY_1, true, true, false); | 167 : public views::DesktopWindowTreeHostObserverX11 { |
166 SendNativeKeyEventToXDisplay(ui::VKEY_A, true, true, false); | 168 public: |
167 SendNativeKeyEventToXDisplay(ui::VKEY_8, true, true, false); | 169 void OnWindowMapped(unsigned long xid) override { |
| 170 // On Linux, our infrastructure for sending keys just synthesize keyboard |
| 171 // event and send them directly to the specified window, without notifying |
| 172 // the X root window. It didn't work while testing global shortcut because |
| 173 // the stuff of global shortcut on Linux need to be notified when KeyPress |
| 174 // event is happening on X root window. So we simulate the keyboard input |
| 175 // here. |
| 176 SendNativeKeyEventToXDisplay(ui::VKEY_1, true, true, false); |
| 177 SendNativeKeyEventToXDisplay(ui::VKEY_A, true, true, false); |
| 178 SendNativeKeyEventToXDisplay(ui::VKEY_8, true, true, false); |
| 179 } |
| 180 |
| 181 void OnWindowUnmapped(unsigned long xid) override {} |
| 182 } observer; |
| 183 |
| 184 // The observer sends the commands after window mapping |
| 185 host->AddObserver(&observer); |
| 186 |
168 #elif defined(OS_MACOSX) | 187 #elif defined(OS_MACOSX) |
169 // Create an incognito browser to capture the focus. | 188 // Create an incognito browser to capture the focus. |
170 CreateIncognitoBrowser(); | 189 CreateIncognitoBrowser(); |
171 | 190 |
172 // Send some native mac key events. | 191 // Send some native mac key events. |
173 SendNativeCommandShift(kVK_ANSI_1); | 192 SendNativeCommandShift(kVK_ANSI_1); |
174 SendNativeCommandShift(kVK_ANSI_A); | 193 SendNativeCommandShift(kVK_ANSI_A); |
175 SendNativeCommandShift(kVK_ANSI_8); | 194 SendNativeCommandShift(kVK_ANSI_8); |
176 #endif | 195 #endif |
177 | 196 |
178 // If this fails, it might be because the global shortcut failed to work, | 197 // If this fails, it might be because the global shortcut failed to work, |
179 // but it might also be because the non-global shortcuts unexpectedly | 198 // but it might also be because the non-global shortcuts unexpectedly |
180 // worked. | 199 // worked. |
181 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 200 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 201 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_X11) |
| 202 host->RemoveObserver(&observer); |
| 203 #endif |
182 } | 204 } |
183 | 205 |
184 #if defined(OS_WIN) | 206 #if defined(OS_WIN) |
185 // Feature only fully implemented on Windows, other platforms coming. | 207 // Feature only fully implemented on Windows, other platforms coming. |
186 // TODO(smus): On mac, SendKeyPress must first support media keys. | 208 // TODO(smus): On mac, SendKeyPress must first support media keys. |
187 // Test occasionally times out on Windows. http://crbug.com/428813 | 209 // Test occasionally times out on Windows. http://crbug.com/428813 |
188 #define MAYBE_GlobalDuplicatedMediaKey DISABLED_GlobalDuplicatedMediaKey | 210 #define MAYBE_GlobalDuplicatedMediaKey DISABLED_GlobalDuplicatedMediaKey |
189 #else | 211 #else |
190 #define MAYBE_GlobalDuplicatedMediaKey DISABLED_GlobalDuplicatedMediaKey | 212 #define MAYBE_GlobalDuplicatedMediaKey DISABLED_GlobalDuplicatedMediaKey |
191 #endif | 213 #endif |
(...skipping 15 matching lines...) Expand all Loading... |
207 false, | 229 false, |
208 false, | 230 false, |
209 false); | 231 false); |
210 | 232 |
211 // We should get two success results. | 233 // We should get two success results. |
212 ASSERT_TRUE(catcher.GetNextResult()); | 234 ASSERT_TRUE(catcher.GetNextResult()); |
213 ASSERT_TRUE(catcher.GetNextResult()); | 235 ASSERT_TRUE(catcher.GetNextResult()); |
214 } | 236 } |
215 | 237 |
216 } // namespace extensions | 238 } // namespace extensions |
OLD | NEW |