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

Side by Side Diff: chrome/browser/global_keyboard_shortcuts_mac_browsertest.mm

Issue 2531033003: MacViews: Fix GlobalKeyboardShortcutsTest.SwitchTabsMac. (Closed)
Patch Set: Remove Views dependency from Cocoa code. 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 unified diff | Download patch
« no previous file with comments | « no previous file | ui/views/test/event_generator_delegate_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #import "chrome/browser/global_keyboard_shortcuts_mac.h" 5 #import "chrome/browser/global_keyboard_shortcuts_mac.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "chrome/browser/extensions/extension_browsertest.h" 10 #include "chrome/browser/extensions/extension_browsertest.h"
11 #include "chrome/browser/ui/browser.h" 11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_commands.h" 12 #include "chrome/browser/ui/browser_commands.h"
13 #include "chrome/browser/ui/browser_window.h" 13 #include "chrome/browser/ui/browser_window.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" 14 #include "chrome/browser/ui/tabs/tab_strip_model.h"
15 #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
15 #import "ui/events/test/cocoa_test_event_utils.h" 16 #import "ui/events/test/cocoa_test_event_utils.h"
16 17
17 using cocoa_test_event_utils::SynthesizeKeyEvent; 18 using cocoa_test_event_utils::SynthesizeKeyEvent;
18 19
19 using GlobalKeyboardShortcutsTest = ExtensionBrowserTest; 20 using GlobalKeyboardShortcutsTest = ExtensionBrowserTest;
20 21
22 namespace {
23
24 void ActivateAccelerator(NSWindow* window, NSEvent* ns_event) {
25 if ([window performKeyEquivalent:ns_event])
26 return;
27
28 // crbug.com/665823: In MacViews not all accelerators are processed at
29 // -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.
30 [window sendEvent:ns_event];
31 }
32
33 } // namespace
34
21 // Test that global keyboard shortcuts are handled by the native window. 35 // Test that global keyboard shortcuts are handled by the native window.
22 IN_PROC_BROWSER_TEST_F(GlobalKeyboardShortcutsTest, SwitchTabsMac) { 36 IN_PROC_BROWSER_TEST_F(GlobalKeyboardShortcutsTest, SwitchTabsMac) {
23 NSWindow* ns_window = browser()->window()->GetNativeWindow(); 37 NSWindow* ns_window = browser()->window()->GetNativeWindow();
24 TabStripModel* tab_strip = browser()->tab_strip_model(); 38 TabStripModel* tab_strip = browser()->tab_strip_model();
25 39
26 // Set up window with 2 tabs. 40 // Set up window with 2 tabs.
27 chrome::NewTab(browser()); 41 chrome::NewTab(browser());
28 EXPECT_EQ(2, tab_strip->count()); 42 EXPECT_EQ(2, tab_strip->count());
29 EXPECT_TRUE(tab_strip->IsTabSelected(1)); 43 EXPECT_TRUE(tab_strip->IsTabSelected(1));
30 44
31 // Ctrl+Tab goes to the next tab, which loops back to the first tab. 45 // Ctrl+Tab goes to the next tab, which loops back to the first tab.
32 [ns_window performKeyEquivalent:SynthesizeKeyEvent( 46 ActivateAccelerator(
33 ns_window, true, ui::VKEY_TAB, NSControlKeyMask)]; 47 ns_window,
48 SynthesizeKeyEvent(ns_window, true, ui::VKEY_TAB, NSControlKeyMask));
34 EXPECT_TRUE(tab_strip->IsTabSelected(0)); 49 EXPECT_TRUE(tab_strip->IsTabSelected(0));
35 50
36 // Cmd+2 goes to the second tab. 51 // Cmd+2 goes to the second tab.
37 [ns_window performKeyEquivalent:SynthesizeKeyEvent( 52 ActivateAccelerator(ns_window, SynthesizeKeyEvent(ns_window, true, ui::VKEY_2,
38 ns_window, true, ui::VKEY_2, NSCommandKeyMask)]; 53 NSCommandKeyMask));
39 EXPECT_TRUE(tab_strip->IsTabSelected(1)); 54 EXPECT_TRUE(tab_strip->IsTabSelected(1));
40 55
41 // Cmd+{ goes to the previous tab. 56 // Cmd+{ goes to the previous tab.
42 [ns_window performKeyEquivalent:SynthesizeKeyEvent( 57 ActivateAccelerator(ns_window,
43 ns_window, true, ui::VKEY_OEM_4, NSShiftKeyMask | NSCommandKeyMask)]; 58 SynthesizeKeyEvent(ns_window, true, ui::VKEY_OEM_4,
59 NSShiftKeyMask | NSCommandKeyMask));
44 EXPECT_TRUE(tab_strip->IsTabSelected(0)); 60 EXPECT_TRUE(tab_strip->IsTabSelected(0));
45 } 61 }
OLDNEW
« 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