Chromium Code Reviews| Index: chrome/browser/global_keyboard_shortcuts_mac_browsertest.mm |
| diff --git a/chrome/browser/global_keyboard_shortcuts_mac_browsertest.mm b/chrome/browser/global_keyboard_shortcuts_mac_browsertest.mm |
| index 3e6b7f2dad86366f93d7a8c970122aef7a4d6bb9..b3f0ff24bc423f21434fad0cb9ac61d14009397d 100644 |
| --- a/chrome/browser/global_keyboard_shortcuts_mac_browsertest.mm |
| +++ b/chrome/browser/global_keyboard_shortcuts_mac_browsertest.mm |
| @@ -12,12 +12,26 @@ |
| #include "chrome/browser/ui/browser_commands.h" |
| #include "chrome/browser/ui/browser_window.h" |
| #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| +#include "ui/base/accelerators/accelerator.h" |
|
tapted
2016/11/30 23:53:03
(oh, and a nit: is this still needed?)
themblsha
2016/12/01 11:24:17
Whoops. I wanted to use ui::Accelerator, but conve
|
| #import "ui/events/test/cocoa_test_event_utils.h" |
| using cocoa_test_event_utils::SynthesizeKeyEvent; |
| using GlobalKeyboardShortcutsTest = ExtensionBrowserTest; |
| +namespace { |
| + |
| +void ActivateAccelerator(NSWindow* window, NSEvent* ns_event) { |
| + if ([window performKeyEquivalent:ns_event]) |
| + return; |
| + |
| + // crbug.com/665823: In MacViews not all accelerators are processed at |
| + // -performKeyEquivalent: stage, we also need to invoke -sendEvent:. |
|
tapted
2016/11/30 23:52:03
Thanks! this is much clearer. I would add a bit mo
themblsha
2016/12/01 11:24:17
Done.
|
| + [window sendEvent:ns_event]; |
| +} |
| + |
| +} // namespace |
| + |
| // Test that global keyboard shortcuts are handled by the native window. |
| IN_PROC_BROWSER_TEST_F(GlobalKeyboardShortcutsTest, SwitchTabsMac) { |
| NSWindow* ns_window = browser()->window()->GetNativeWindow(); |
| @@ -29,17 +43,19 @@ IN_PROC_BROWSER_TEST_F(GlobalKeyboardShortcutsTest, SwitchTabsMac) { |
| EXPECT_TRUE(tab_strip->IsTabSelected(1)); |
| // Ctrl+Tab goes to the next tab, which loops back to the first tab. |
| - [ns_window performKeyEquivalent:SynthesizeKeyEvent( |
| - ns_window, true, ui::VKEY_TAB, NSControlKeyMask)]; |
| + ActivateAccelerator( |
| + ns_window, |
| + SynthesizeKeyEvent(ns_window, true, ui::VKEY_TAB, NSControlKeyMask)); |
| EXPECT_TRUE(tab_strip->IsTabSelected(0)); |
| // Cmd+2 goes to the second tab. |
| - [ns_window performKeyEquivalent:SynthesizeKeyEvent( |
| - ns_window, true, ui::VKEY_2, NSCommandKeyMask)]; |
| + ActivateAccelerator(ns_window, SynthesizeKeyEvent(ns_window, true, ui::VKEY_2, |
| + NSCommandKeyMask)); |
| EXPECT_TRUE(tab_strip->IsTabSelected(1)); |
| // Cmd+{ goes to the previous tab. |
| - [ns_window performKeyEquivalent:SynthesizeKeyEvent( |
| - ns_window, true, ui::VKEY_OEM_4, NSShiftKeyMask | NSCommandKeyMask)]; |
| + ActivateAccelerator(ns_window, |
| + SynthesizeKeyEvent(ns_window, true, ui::VKEY_OEM_4, |
| + NSShiftKeyMask | NSCommandKeyMask)); |
| EXPECT_TRUE(tab_strip->IsTabSelected(0)); |
| } |