Chromium Code Reviews| Index: chrome/browser/extensions/extension_commands_global_registry_apitest.cc |
| diff --git a/chrome/browser/extensions/extension_commands_global_registry_apitest.cc b/chrome/browser/extensions/extension_commands_global_registry_apitest.cc |
| index f4e17f1a9062e7649b02ece130d6dbaaa45dcd6d..ea3505f916c0a8e9342ac4fa81208de5bc47f3e9 100644 |
| --- a/chrome/browser/extensions/extension_commands_global_registry_apitest.cc |
| +++ b/chrome/browser/extensions/extension_commands_global_registry_apitest.cc |
| @@ -17,9 +17,11 @@ |
| #include <X11/Xlib.h> |
| #include <X11/extensions/XTest.h> |
| #include <X11/keysym.h> |
| - |
| +#include "ui/aura/window.h" |
| #include "ui/events/keycodes/keyboard_code_conversion_x.h" |
| #include "ui/gfx/x/x11_types.h" |
| +#include "ui/views/widget/desktop_aura/desktop_window_tree_host_observer_x11.h" |
| +#include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" |
| #endif |
| #if defined(OS_MACOSX) |
| @@ -115,6 +117,26 @@ void SendNativeCommandShift(int key_code) { |
| } |
| #endif |
| +#if defined(OS_LINUX) && defined(USE_X11) |
|
sadrul
2017/01/27 21:41:01
You can use just 'defined(USE_X11)'
Tom (Use chromium acct)
2017/02/03 19:55:31
Done.
|
| +class GlobalCommandTreeHostObserver |
| + : public views::DesktopWindowTreeHostObserverX11 { |
| + public: |
| + void OnWindowMapped(unsigned long xid) override { |
| + // On Linux, our infrastructure for sending keys just synthesize keyboard |
| + // event and send them directly to the specified window, without notifying |
| + // the X root window. It didn't work while testing global shortcut because |
| + // the stuff of global shortcut on Linux need to be notified when KeyPress |
| + // event is happening on X root window. So we simulate the keyboard input |
| + // here. |
| + SendNativeKeyEventToXDisplay(ui::VKEY_1, true, true, false); |
| + SendNativeKeyEventToXDisplay(ui::VKEY_A, true, true, false); |
| + SendNativeKeyEventToXDisplay(ui::VKEY_8, true, true, false); |
| + } |
| + |
| + void OnWindowUnmapped(unsigned long xid) override {} |
| +}; |
| +#endif |
| + |
| // Test the basics of global commands and make sure they work when Chrome |
| // doesn't have focus. Also test that non-global commands are not treated as |
| // global and that keys beyond Ctrl+Shift+[0..9] cannot be auto-assigned by an |
| @@ -155,16 +177,16 @@ IN_PROC_BROWSER_TEST_F(GlobalCommandsApiTest, MAYBE_GlobalCommand) { |
| incognito_browser, ui::VKEY_8, true, true, false, false)); |
| #elif defined(OS_LINUX) && defined(USE_X11) |
| // Create an incognito browser to capture the focus. |
| - CreateIncognitoBrowser(); |
| + Browser* incognito_browser = CreateIncognitoBrowser(); |
| + |
| + views::DesktopWindowTreeHostX11* host = |
| + static_cast<views::DesktopWindowTreeHostX11*>( |
| + incognito_browser->window()->GetNativeWindow()->GetHost()); |
| + |
| + auto observer = base::MakeUnique<GlobalCommandTreeHostObserver>(); |
| + // The observer sends the commands after window mapping |
| + host->AddObserver(observer.get()); |
| - // On Linux, our infrastructure for sending keys just synthesize keyboard |
| - // event and send them directly to the specified window, without notifying the |
| - // X root window. It didn't work while testing global shortcut because the |
| - // stuff of global shortcut on Linux need to be notified when KeyPress event |
| - // is happening on X root window. So we simulate the keyboard input here. |
| - SendNativeKeyEventToXDisplay(ui::VKEY_1, true, true, false); |
| - SendNativeKeyEventToXDisplay(ui::VKEY_A, true, true, false); |
| - SendNativeKeyEventToXDisplay(ui::VKEY_8, true, true, false); |
| #elif defined(OS_MACOSX) |
| // Create an incognito browser to capture the focus. |
| CreateIncognitoBrowser(); |
| @@ -179,6 +201,9 @@ IN_PROC_BROWSER_TEST_F(GlobalCommandsApiTest, MAYBE_GlobalCommand) { |
| // but it might also be because the non-global shortcuts unexpectedly |
| // worked. |
| ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| +#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_X11) |
| + host->RemoveObserver(observer.get()); |
| +#endif |
| } |
| #if defined(OS_WIN) |