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

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: 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 class ScopedTabStripModelObserver : public TabStripModelObserver {
tapted 2015/07/27 04:58:57 nit: class comment
jackhou1 2015/07/28 05:19:45 Done.
23 public:
24 ScopedTabStripModelObserver(TabStripModel* tab_strip_model)
25 : tab_strip_model_(tab_strip_model), changed_observed_(false) {
26 tab_strip_model_->AddObserver(this);
27 }
28
29 ~ScopedTabStripModelObserver() override {
30 tab_strip_model_->RemoveObserver(this);
31 }
32
33 void WaitForActiveTabChange() {
34 if (changed_observed_)
35 return;
36
37 run_loop_.reset(new base::RunLoop);
38 run_loop_->Run();
39 }
40
41 void ActiveTabChanged(content::WebContents* old_contents,
42 content::WebContents* new_contents,
43 int index,
44 int reason) override {
45 changed_observed_ = true;
46 if (run_loop_.get())
47 run_loop_->Quit();
48 }
49
50 private:
51 TabStripModel* tab_strip_model_;
52 bool changed_observed_;
53 scoped_ptr<base::RunLoop> run_loop_;
54
55 DISALLOW_COPY_AND_ASSIGN(ScopedTabStripModelObserver);
56 };
57
58 } // namespace
59
60 // Test that global keyboard shortcuts are handled by the native window.
61 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, GlobalKeyboardShortcuts) {
62 LOG(INFO) << [NSStringFromClass([NSApp class]) UTF8String];
tapted 2015/07/27 04:58:57 remove?
jackhou1 2015/07/28 05:19:45 Done.
63
64 NSWindow* ns_window = browser()->window()->GetNativeWindow();
65 TabStripModel* tab_strip = browser()->tab_strip_model();
66 scoped_ptr<ScopedTabStripModelObserver> observer;
67
68 // Set up window with 2 tabs.
69 observer.reset(new ScopedTabStripModelObserver(tab_strip));
70 chrome::NewTab(browser());
71 observer->WaitForActiveTabChange();
72 EXPECT_EQ(2, tab_strip->count());
73 EXPECT_TRUE(tab_strip->IsTabSelected(1));
74
75 // Ctrl+Tab goes to the next tab, which loops back to the first tab.
76 observer.reset(new ScopedTabStripModelObserver(tab_strip));
77 [ns_window performKeyEquivalent:SynthesizeKeyEvent(
78 ns_window, true, ui::VKEY_TAB, NSControlKeyMask)];
79 observer->WaitForActiveTabChange();
80 EXPECT_TRUE(tab_strip->IsTabSelected(0));
81
82 // Cmd+2 goes to the second tab.
83 observer.reset(new ScopedTabStripModelObserver(tab_strip));
84 [ns_window performKeyEquivalent:SynthesizeKeyEvent(
85 ns_window, true, ui::VKEY_2, NSCommandKeyMask)];
86 observer->WaitForActiveTabChange();
87 EXPECT_TRUE(tab_strip->IsTabSelected(1));
88
89 // Cmd+{ goes to the previous tab.
90 observer.reset(new ScopedTabStripModelObserver(tab_strip));
91 [ns_window performKeyEquivalent:SynthesizeKeyEvent(
92 ns_window, true, ui::VKEY_OEM_4, NSShiftKeyMask | NSCommandKeyMask)];
93 observer->WaitForActiveTabChange();
94 EXPECT_TRUE(tab_strip->IsTabSelected(0));
95 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698