Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1026)

Side by Side Diff: chrome/browser/extensions/extension_commands_global_registry_apitest.cc

Issue 48953004: Enable global command test on Linux Aura. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Disable on linux_chrome_os Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "ui/base/base_window.h" 11 #include "ui/base/base_window.h"
12 12
13 #if defined(TOOLKIT_GTK) 13 #if defined(OS_LINUX)
14 #include <X11/Xlib.h> 14 #include <X11/Xlib.h>
15 #include <X11/extensions/XTest.h> 15 #include <X11/extensions/XTest.h>
16 #include <X11/keysym.h> 16 #include <X11/keysym.h>
17 17
18 #include "ui/events/keycodes/keyboard_code_conversion_x.h" 18 #include "ui/events/keycodes/keyboard_code_conversion_x.h"
19 #include "ui/gfx/x/x11_types.h" 19 #include "ui/gfx/x/x11_types.h"
20 #endif 20 #endif
21 21
22 namespace extensions { 22 namespace extensions {
23 23
24 typedef ExtensionApiTest GlobalCommandsApiTest; 24 typedef ExtensionApiTest GlobalCommandsApiTest;
25 25
26 #if defined(TOOLKIT_GTK) 26 #if defined(OS_LINUX)
27 // Send a simulated key press and release event, where |control|, |shift| or 27 // Send a simulated key press and release event, where |control|, |shift| or
28 // |alt| indicates whether the key is struck with corresponding modifier. 28 // |alt| indicates whether the key is struck with corresponding modifier.
29 void SendNativeKeyEventToXDisplay(ui::KeyboardCode key, 29 void SendNativeKeyEventToXDisplay(ui::KeyboardCode key,
30 bool control, 30 bool control,
31 bool shift, 31 bool shift,
32 bool alt) { 32 bool alt) {
33 Display* display = gfx::GetXDisplay(); 33 Display* display = gfx::GetXDisplay();
34 KeyCode ctrl_key_code = XKeysymToKeycode(display, XK_Control_L); 34 KeyCode ctrl_key_code = XKeysymToKeycode(display, XK_Control_L);
35 KeyCode shift_key_code = XKeysymToKeycode(display, XK_Shift_L); 35 KeyCode shift_key_code = XKeysymToKeycode(display, XK_Shift_L);
36 KeyCode alt_key_code = XKeysymToKeycode(display, XK_Alt_L); 36 KeyCode alt_key_code = XKeysymToKeycode(display, XK_Alt_L);
(...skipping 20 matching lines...) Expand all
57 // Simulate the keys being pressed. 57 // Simulate the keys being pressed.
58 for (KeyCodes::iterator it = key_codes.begin(); it != key_codes.end(); it++) 58 for (KeyCodes::iterator it = key_codes.begin(); it != key_codes.end(); it++)
59 XTestFakeKeyEvent(display, *it, True, CurrentTime); 59 XTestFakeKeyEvent(display, *it, True, CurrentTime);
60 60
61 // Simulate the keys being released. 61 // Simulate the keys being released.
62 for (KeyCodes::iterator it = key_codes.begin(); it != key_codes.end(); it++) 62 for (KeyCodes::iterator it = key_codes.begin(); it != key_codes.end(); it++)
63 XTestFakeKeyEvent(display, *it, False, CurrentTime); 63 XTestFakeKeyEvent(display, *it, False, CurrentTime);
64 64
65 XFlush(display); 65 XFlush(display);
66 } 66 }
67 #endif // TOOLKIT_GTK 67 #endif // OS_LINUX
68 68
69 #if defined(OS_WIN) || defined(TOOLKIT_GTK) 69 #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS))
70 // The feature is only fully implemented on Windows and Linux GTK+, other 70 // The feature is only fully implemented on Windows and Linux, other platforms
71 // platforms coming. 71 // coming.
72 #define MAYBE_GlobalCommand GlobalCommand 72 #define MAYBE_GlobalCommand GlobalCommand
73 #else 73 #else
74 #define MAYBE_GlobalCommand DISABLED_GlobalCommand 74 #define MAYBE_GlobalCommand DISABLED_GlobalCommand
75 #endif 75 #endif
76 76
77 // Test the basics of global commands and make sure they work when Chrome 77 // Test the basics of global commands and make sure they work when Chrome
78 // doesn't have focus. Also test that non-global commands are not treated as 78 // doesn't have focus. Also test that non-global commands are not treated as
79 // global and that keys beyond Ctrl+Shift+[0..9] cannot be auto-assigned by an 79 // global and that keys beyond Ctrl+Shift+[0..9] cannot be auto-assigned by an
80 // extension. 80 // extension.
81 IN_PROC_BROWSER_TEST_F(GlobalCommandsApiTest, MAYBE_GlobalCommand) { 81 IN_PROC_BROWSER_TEST_F(GlobalCommandsApiTest, MAYBE_GlobalCommand) {
82 FeatureSwitch::ScopedOverride enable_global_commands( 82 FeatureSwitch::ScopedOverride enable_global_commands(
83 FeatureSwitch::global_commands(), true); 83 FeatureSwitch::global_commands(), true);
84 84
85 // Load the extension in the non-incognito browser. 85 // Load the extension in the non-incognito browser.
86 ResultCatcher catcher; 86 ResultCatcher catcher;
87 ASSERT_TRUE(RunExtensionTest("keybinding/global")) << message_; 87 ASSERT_TRUE(RunExtensionTest("keybinding/global")) << message_;
88 ASSERT_TRUE(catcher.GetNextResult()); 88 ASSERT_TRUE(catcher.GetNextResult());
89 89
90 #if !defined(TOOLKIT_GTK) 90 #if !defined(OS_LINUX)
91 // Our infrastructure for sending keys expects a browser to send them to, but 91 // Our infrastructure for sending keys expects a browser to send them to, but
92 // to properly test global shortcuts you need to send them to another target. 92 // to properly test global shortcuts you need to send them to another target.
93 // So, create an incognito browser to use as a target to send the shortcuts 93 // So, create an incognito browser to use as a target to send the shortcuts
94 // to. It will ignore all of them and allow us test whether the global 94 // to. It will ignore all of them and allow us test whether the global
95 // shortcut really is global in nature and also that the non-global shortcut 95 // shortcut really is global in nature and also that the non-global shortcut
96 // is non-global. 96 // is non-global.
97 Browser* incognito_browser = CreateIncognitoBrowser(); 97 Browser* incognito_browser = CreateIncognitoBrowser();
98 98
99 // Try to activate the non-global shortcut (Ctrl+Shift+1) and the 99 // Try to activate the non-global shortcut (Ctrl+Shift+1) and the
100 // non-assignable shortcut (Ctrl+Shift+A) by sending the keystrokes to the 100 // non-assignable shortcut (Ctrl+Shift+A) by sending the keystrokes to the
101 // incognito browser. Both shortcuts should have no effect (extension is not 101 // incognito browser. Both shortcuts should have no effect (extension is not
102 // loaded there). 102 // loaded there).
103 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 103 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
104 incognito_browser, ui::VKEY_1, true, true, false, false)); 104 incognito_browser, ui::VKEY_1, true, true, false, false));
105 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 105 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
106 incognito_browser, ui::VKEY_A, true, true, false, false)); 106 incognito_browser, ui::VKEY_A, true, true, false, false));
107 107
108 // Activate the shortcut (Ctrl+Shift+9). This should have an effect. 108 // Activate the shortcut (Ctrl+Shift+9). This should have an effect.
109 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 109 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
110 incognito_browser, ui::VKEY_9, true, true, false, false)); 110 incognito_browser, ui::VKEY_9, true, true, false, false));
111 #else 111 #else
112 // On Linux GTK+, our infrastructure for sending keys just synthesize keyboard 112 // Create an incognito browser to capture the focus.
113 CreateIncognitoBrowser();
114
115 // On Linux, our infrastructure for sending keys just synthesize keyboard
113 // event and send them directly to the specified window, without notifying the 116 // event and send them directly to the specified window, without notifying the
114 // X root window. It didn't work while testing global shortcut because the 117 // X root window. It didn't work while testing global shortcut because the
115 // stuff of global shortcut on Linux need to be notified when KeyPress event 118 // stuff of global shortcut on Linux need to be notified when KeyPress event
116 // is happening on X root window. So we simulate the keyboard input here. 119 // is happening on X root window. So we simulate the keyboard input here.
117 SendNativeKeyEventToXDisplay(ui::VKEY_1, true, true, false); 120 SendNativeKeyEventToXDisplay(ui::VKEY_1, true, true, false);
118 SendNativeKeyEventToXDisplay(ui::VKEY_A, true, true, false); 121 SendNativeKeyEventToXDisplay(ui::VKEY_A, true, true, false);
119 SendNativeKeyEventToXDisplay(ui::VKEY_9, true, true, false); 122 SendNativeKeyEventToXDisplay(ui::VKEY_9, true, true, false);
120 #endif 123 #endif
121 124
122 // If this fails, it might be because the global shortcut failed to work, 125 // If this fails, it might be because the global shortcut failed to work,
123 // but it might also be because the non-global shortcuts unexpectedly 126 // but it might also be because the non-global shortcuts unexpectedly
124 // worked. 127 // worked.
125 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 128 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
126 } 129 }
127 130
128 } // namespace extensions 131 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698