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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 CGEventPost(event_tap_location, shift_down); | 110 CGEventPost(event_tap_location, shift_down); |
109 CGEventPost(event_tap_location, key_down); | 111 CGEventPost(event_tap_location, key_down); |
110 CGEventPost(event_tap_location, key_up); | 112 CGEventPost(event_tap_location, key_up); |
111 CGEventPost(event_tap_location, shift_up); | 113 CGEventPost(event_tap_location, shift_up); |
112 CGEventPost(event_tap_location, command_up); | 114 CGEventPost(event_tap_location, command_up); |
113 | 115 |
114 CFRelease(event_source); | 116 CFRelease(event_source); |
115 } | 117 } |
116 #endif | 118 #endif |
117 | 119 |
| 120 #if defined(OS_LINUX) && defined(USE_X11) |
| 121 class GlobalCommandTreeHostObserver |
| 122 : public views::DesktopWindowTreeHostObserverX11 { |
| 123 public: |
| 124 void OnWindowMapped(unsigned long xid) override { |
| 125 // On Linux, our infrastructure for sending keys just synthesize keyboard |
| 126 // event and send them directly to the specified window, without notifying |
| 127 // the X root window. It didn't work while testing global shortcut because |
| 128 // the stuff of global shortcut on Linux need to be notified when KeyPress |
| 129 // event is happening on X root window. So we simulate the keyboard input |
| 130 // here. |
| 131 SendNativeKeyEventToXDisplay(ui::VKEY_1, true, true, false); |
| 132 SendNativeKeyEventToXDisplay(ui::VKEY_A, true, true, false); |
| 133 SendNativeKeyEventToXDisplay(ui::VKEY_8, true, true, false); |
| 134 } |
| 135 |
| 136 void OnWindowUnmapped(unsigned long xid) override {} |
| 137 }; |
| 138 #endif |
| 139 |
118 // Test the basics of global commands and make sure they work when Chrome | 140 // Test the basics of global commands and make sure they work when Chrome |
119 // doesn't have focus. Also test that non-global commands are not treated as | 141 // doesn't have focus. Also test that non-global commands are not treated as |
120 // global and that keys beyond Ctrl+Shift+[0..9] cannot be auto-assigned by an | 142 // global and that keys beyond Ctrl+Shift+[0..9] cannot be auto-assigned by an |
121 // extension. | 143 // extension. |
122 // | 144 // |
123 // Doesn't work in GN CrOS ozone builds yet, http://crbug.com/619784 | 145 // Doesn't work in GN CrOS ozone builds yet, http://crbug.com/619784 |
124 #if defined(OS_CHROMEOS) && defined(USE_OZONE) | 146 #if defined(OS_CHROMEOS) && defined(USE_OZONE) |
125 #define MAYBE_GlobalCommand DISABLED_GlobalCommand | 147 #define MAYBE_GlobalCommand DISABLED_GlobalCommand |
126 #else | 148 #else |
127 #define MAYBE_GlobalCommand GlobalCommand | 149 #define MAYBE_GlobalCommand GlobalCommand |
(...skipping 20 matching lines...) Expand all Loading... |
148 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 170 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
149 incognito_browser, ui::VKEY_1, true, true, false, false)); | 171 incognito_browser, ui::VKEY_1, true, true, false, false)); |
150 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 172 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
151 incognito_browser, ui::VKEY_A, true, true, false, false)); | 173 incognito_browser, ui::VKEY_A, true, true, false, false)); |
152 | 174 |
153 // Activate the shortcut (Ctrl+Shift+8). This should have an effect. | 175 // Activate the shortcut (Ctrl+Shift+8). This should have an effect. |
154 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 176 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
155 incognito_browser, ui::VKEY_8, true, true, false, false)); | 177 incognito_browser, ui::VKEY_8, true, true, false, false)); |
156 #elif defined(OS_LINUX) && defined(USE_X11) | 178 #elif defined(OS_LINUX) && defined(USE_X11) |
157 // Create an incognito browser to capture the focus. | 179 // Create an incognito browser to capture the focus. |
158 CreateIncognitoBrowser(); | 180 Browser* incognito_browser = CreateIncognitoBrowser(); |
159 | 181 |
160 // On Linux, our infrastructure for sending keys just synthesize keyboard | 182 views::DesktopWindowTreeHostX11* host = |
161 // event and send them directly to the specified window, without notifying the | 183 static_cast<views::DesktopWindowTreeHostX11*>( |
162 // X root window. It didn't work while testing global shortcut because the | 184 incognito_browser->window()->GetNativeWindow()->GetHost()); |
163 // stuff of global shortcut on Linux need to be notified when KeyPress event | 185 |
164 // is happening on X root window. So we simulate the keyboard input here. | 186 GlobalCommandTreeHostObserver* observer = new GlobalCommandTreeHostObserver(); |
165 SendNativeKeyEventToXDisplay(ui::VKEY_1, true, true, false); | 187 // The observer sends the commands after window mapping |
166 SendNativeKeyEventToXDisplay(ui::VKEY_A, true, true, false); | 188 host->AddObserver(observer); |
167 SendNativeKeyEventToXDisplay(ui::VKEY_8, true, true, false); | 189 |
168 #elif defined(OS_MACOSX) | 190 #elif defined(OS_MACOSX) |
169 // Create an incognito browser to capture the focus. | 191 // Create an incognito browser to capture the focus. |
170 CreateIncognitoBrowser(); | 192 CreateIncognitoBrowser(); |
171 | 193 |
172 // Send some native mac key events. | 194 // Send some native mac key events. |
173 SendNativeCommandShift(kVK_ANSI_1); | 195 SendNativeCommandShift(kVK_ANSI_1); |
174 SendNativeCommandShift(kVK_ANSI_A); | 196 SendNativeCommandShift(kVK_ANSI_A); |
175 SendNativeCommandShift(kVK_ANSI_8); | 197 SendNativeCommandShift(kVK_ANSI_8); |
176 #endif | 198 #endif |
177 | 199 |
(...skipping 29 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 |