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

Unified Diff: chrome/browser/global_keyboard_shortcuts_mac_browsertest.mm

Issue 2531033003: MacViews: Fix GlobalKeyboardShortcutsTest.SwitchTabsMac. (Closed)
Patch Set: Fix tapted's remarks. Created 4 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ui/views/test/event_generator_delegate_mac.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..1f69ccde5e5f44f3f5a09da893afb93beae22f35 100644
--- a/chrome/browser/global_keyboard_shortcuts_mac_browsertest.mm
+++ b/chrome/browser/global_keyboard_shortcuts_mac_browsertest.mm
@@ -18,6 +18,20 @@ using cocoa_test_event_utils::SynthesizeKeyEvent;
using GlobalKeyboardShortcutsTest = ExtensionBrowserTest;
+namespace {
+
+void ActivateAccelerator(NSWindow* window, NSEvent* ns_event) {
+ if ([window performKeyEquivalent:ns_event])
+ return;
+
+ // This is consistent with the way AppKit dispatches events when
+ // -performKeyEquivalent: returns NO. See "The Path of Key Events" in the
+ // Cocoa Event Architecture documentation.
+ [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));
}
« no previous file with comments | « no previous file | ui/views/test/event_generator_delegate_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698