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

Unified 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, 5 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 side-by-side diff with in-line comments
Download patch
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
new file mode 100644
index 0000000000000000000000000000000000000000..1311be85d8d2c4f36474beed1c77a4f6393bc6b4
--- /dev/null
+++ b/chrome/browser/global_keyboard_shortcuts_mac_browsertest.mm
@@ -0,0 +1,94 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "chrome/browser/global_keyboard_shortcuts_mac.h"
+
+#import <Cocoa/Cocoa.h>
+
+#include "base/run_loop.h"
+#include "chrome/browser/extensions/extension_browsertest.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_commands.h"
+#include "chrome/browser/ui/browser_window.h"
+#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
+#import "ui/events/test/cocoa_test_event_utils.h"
+
+using cocoa_test_event_utils::SynthesizeKeyEvent;
+
+namespace {
+
+// 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.
+class ScopedTabStripModelObserver : public TabStripModelObserver {
+ public:
+ ScopedTabStripModelObserver(TabStripModel* tab_strip_model)
+ : tab_strip_model_(tab_strip_model), changed_observed_(false) {
+ tab_strip_model_->AddObserver(this);
+ }
+
+ ~ScopedTabStripModelObserver() override {
+ tab_strip_model_->RemoveObserver(this);
+ }
+
+ void WaitForActiveTabChanged() {
+ if (changed_observed_)
+ return;
+
+ run_loop_.reset(new base::RunLoop);
+ run_loop_->Run();
+ }
+
+ void ActiveTabChanged(content::WebContents* old_contents,
+ content::WebContents* new_contents,
+ int index,
+ int reason) override {
+ changed_observed_ = true;
+ if (run_loop_.get())
+ run_loop_->Quit();
+ }
+
+ private:
+ TabStripModel* tab_strip_model_;
+ bool changed_observed_;
+ scoped_ptr<base::RunLoop> run_loop_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedTabStripModelObserver);
+};
+
+} // namespace
+
+// Test that global keyboard shortcuts are handled by the native window.
+IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, GlobalKeyboardShortcuts) {
+ NSWindow* ns_window = browser()->window()->GetNativeWindow();
+ TabStripModel* tab_strip = browser()->tab_strip_model();
+ scoped_ptr<ScopedTabStripModelObserver> observer;
+
+ // Set up window with 2 tabs.
+ observer.reset(new ScopedTabStripModelObserver(tab_strip));
+ chrome::NewTab(browser());
+ observer->WaitForActiveTabChanged();
+ EXPECT_EQ(2, tab_strip->count());
+ EXPECT_TRUE(tab_strip->IsTabSelected(1));
+
+ // Ctrl+Tab goes to the next tab, which loops back to the first tab.
+ observer.reset(new ScopedTabStripModelObserver(tab_strip));
+ [ns_window performKeyEquivalent:SynthesizeKeyEvent(
+ ns_window, true, ui::VKEY_TAB, NSControlKeyMask)];
+ observer->WaitForActiveTabChanged();
+ EXPECT_TRUE(tab_strip->IsTabSelected(0));
+
+ // Cmd+2 goes to the second tab.
+ observer.reset(new ScopedTabStripModelObserver(tab_strip));
+ [ns_window performKeyEquivalent:SynthesizeKeyEvent(
+ ns_window, true, ui::VKEY_2, NSCommandKeyMask)];
+ observer->WaitForActiveTabChanged();
+ EXPECT_TRUE(tab_strip->IsTabSelected(1));
+
+ // Cmd+{ goes to the previous tab.
+ observer.reset(new ScopedTabStripModelObserver(tab_strip));
+ [ns_window performKeyEquivalent:SynthesizeKeyEvent(
+ ns_window, true, ui::VKEY_OEM_4, NSShiftKeyMask | NSCommandKeyMask)];
+ observer->WaitForActiveTabChanged();
+ EXPECT_TRUE(tab_strip->IsTabSelected(0));
+}

Powered by Google App Engine
This is Rietveld 408576698