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

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

Issue 1250533003: [Mac] Remove BrowserCommandExecutor protocol. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't take a window for handleExtraKeyboardShortcut. Created 5 years, 4 months 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "chrome/browser/global_keyboard_shortcuts_mac.h"
6
7 #import <Cocoa/Cocoa.h>
8
9 #include "base/run_loop.h"
10 #include "chrome/browser/extensions/extension_browsertest.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_commands.h"
13 #include "chrome/browser/ui/browser_window.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
16 #import "ui/events/test/cocoa_test_event_utils.h"
17
18 using cocoa_test_event_utils::SynthesizeKeyEvent;
19
20 namespace {
21
22 // Observes a TabStripModel for a single ActiveTabChanged.
tapted 2015/07/28 06:57:10 I think this needs to say why it's needed. It's no
jackhou1 2015/07/29 00:33:53 Ah, you're right. It seems to be fine without it.
23 class ScopedTabStripModelObserver : public TabStripModelObserver {
24 public:
25 ScopedTabStripModelObserver(TabStripModel* tab_strip_model)
26 : tab_strip_model_(tab_strip_model), changed_observed_(false) {
27 tab_strip_model_->AddObserver(this);
28 }
29
30 ~ScopedTabStripModelObserver() override {
31 tab_strip_model_->RemoveObserver(this);
32 }
33
34 void WaitForActiveTabChanged() {
35 if (changed_observed_)
36 return;
37
38 run_loop_.reset(new base::RunLoop);
39 run_loop_->Run();
40 }
41
42 void ActiveTabChanged(content::WebContents* old_contents,
43 content::WebContents* new_contents,
44 int index,
45 int reason) override {
46 changed_observed_ = true;
47 if (run_loop_.get())
48 run_loop_->Quit();
49 }
50
51 private:
52 TabStripModel* tab_strip_model_;
53 bool changed_observed_;
54 scoped_ptr<base::RunLoop> run_loop_;
55
56 DISALLOW_COPY_AND_ASSIGN(ScopedTabStripModelObserver);
57 };
58
59 } // namespace
60
61 // Test that global keyboard shortcuts are handled by the native window.
62 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, GlobalKeyboardShortcuts) {
63 NSWindow* ns_window = browser()->window()->GetNativeWindow();
64 TabStripModel* tab_strip = browser()->tab_strip_model();
65 scoped_ptr<ScopedTabStripModelObserver> observer;
66
67 // Set up window with 2 tabs.
68 observer.reset(new ScopedTabStripModelObserver(tab_strip));
69 chrome::NewTab(browser());
70 observer->WaitForActiveTabChanged();
71 EXPECT_EQ(2, tab_strip->count());
72 EXPECT_TRUE(tab_strip->IsTabSelected(1));
73
74 // Ctrl+Tab goes to the next tab, which loops back to the first tab.
75 observer.reset(new ScopedTabStripModelObserver(tab_strip));
76 [ns_window performKeyEquivalent:SynthesizeKeyEvent(
77 ns_window, true, ui::VKEY_TAB, NSControlKeyMask)];
78 observer->WaitForActiveTabChanged();
79 EXPECT_TRUE(tab_strip->IsTabSelected(0));
80
81 // Cmd+2 goes to the second tab.
82 observer.reset(new ScopedTabStripModelObserver(tab_strip));
83 [ns_window performKeyEquivalent:SynthesizeKeyEvent(
84 ns_window, true, ui::VKEY_2, NSCommandKeyMask)];
85 observer->WaitForActiveTabChanged();
86 EXPECT_TRUE(tab_strip->IsTabSelected(1));
87
88 // Cmd+{ goes to the previous tab.
89 observer.reset(new ScopedTabStripModelObserver(tab_strip));
90 [ns_window performKeyEquivalent:SynthesizeKeyEvent(
91 ns_window, true, ui::VKEY_OEM_4, NSShiftKeyMask | NSCommandKeyMask)];
92 observer->WaitForActiveTabChanged();
93 EXPECT_TRUE(tab_strip->IsTabSelected(0));
94 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698