Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" | |
| 15 #import "ui/events/test/cocoa_test_event_utils.h" | 16 #import "ui/events/test/cocoa_test_event_utils.h" |
| 17 #include "ui/events/test/event_generator.h" | |
| 18 #include "ui/views/test/event_generator_delegate_mac.h" | |
|
tapted
2016/11/28 08:14:18
I've been trying to avoid introducing ui/views dep
themblsha
2016/11/30 12:35:33
I thought about doing a local function that does p
| |
| 16 | 19 |
| 17 using cocoa_test_event_utils::SynthesizeKeyEvent; | 20 using cocoa_test_event_utils::SynthesizeKeyEvent; |
| 18 | 21 |
| 19 using GlobalKeyboardShortcutsTest = ExtensionBrowserTest; | 22 using GlobalKeyboardShortcutsTest = ExtensionBrowserTest; |
| 20 | 23 |
| 24 namespace { | |
| 25 | |
| 26 void PressAccelerator(ui::test::EventGenerator* event_generator, | |
| 27 const ui::Accelerator& accelerator) { | |
| 28 event_generator->PressKey(accelerator.key_code(), accelerator.modifiers()); | |
| 29 event_generator->ReleaseKey(accelerator.key_code(), accelerator.modifiers()); | |
| 30 } | |
| 31 | |
| 32 } // namespace | |
| 33 | |
| 21 // Test that global keyboard shortcuts are handled by the native window. | 34 // Test that global keyboard shortcuts are handled by the native window. |
| 22 IN_PROC_BROWSER_TEST_F(GlobalKeyboardShortcutsTest, SwitchTabsMac) { | 35 IN_PROC_BROWSER_TEST_F(GlobalKeyboardShortcutsTest, SwitchTabsMac) { |
| 23 NSWindow* ns_window = browser()->window()->GetNativeWindow(); | 36 NSWindow* ns_window = browser()->window()->GetNativeWindow(); |
| 24 TabStripModel* tab_strip = browser()->tab_strip_model(); | 37 TabStripModel* tab_strip = browser()->tab_strip_model(); |
| 25 | 38 |
| 26 // Set up window with 2 tabs. | 39 // Set up window with 2 tabs. |
| 27 chrome::NewTab(browser()); | 40 chrome::NewTab(browser()); |
| 28 EXPECT_EQ(2, tab_strip->count()); | 41 EXPECT_EQ(2, tab_strip->count()); |
| 29 EXPECT_TRUE(tab_strip->IsTabSelected(1)); | 42 EXPECT_TRUE(tab_strip->IsTabSelected(1)); |
| 30 | 43 |
| 44 views::test::InitializeMacEventGeneratorDelegate(); | |
| 45 ui::test::EventGenerator event_generator(ns_window); | |
| 46 event_generator.set_target(ui::test::EventGenerator::Target::WINDOW); | |
| 47 | |
| 31 // Ctrl+Tab goes to the next tab, which loops back to the first tab. | 48 // Ctrl+Tab goes to the next tab, which loops back to the first tab. |
| 32 [ns_window performKeyEquivalent:SynthesizeKeyEvent( | 49 PressAccelerator(&event_generator, |
| 33 ns_window, true, ui::VKEY_TAB, NSControlKeyMask)]; | 50 ui::Accelerator(ui::VKEY_TAB, ui::EF_CONTROL_DOWN)); |
| 34 EXPECT_TRUE(tab_strip->IsTabSelected(0)); | 51 EXPECT_TRUE(tab_strip->IsTabSelected(0)); |
| 35 | 52 |
| 36 // Cmd+2 goes to the second tab. | 53 // Cmd+2 goes to the second tab. |
| 37 [ns_window performKeyEquivalent:SynthesizeKeyEvent( | 54 PressAccelerator(&event_generator, |
| 38 ns_window, true, ui::VKEY_2, NSCommandKeyMask)]; | 55 ui::Accelerator(ui::VKEY_2, ui::EF_COMMAND_DOWN)); |
| 39 EXPECT_TRUE(tab_strip->IsTabSelected(1)); | 56 EXPECT_TRUE(tab_strip->IsTabSelected(1)); |
| 40 | 57 |
| 41 // Cmd+{ goes to the previous tab. | 58 // Cmd+{ goes to the previous tab. |
| 42 [ns_window performKeyEquivalent:SynthesizeKeyEvent( | 59 PressAccelerator( |
| 43 ns_window, true, ui::VKEY_OEM_4, NSShiftKeyMask | NSCommandKeyMask)]; | 60 &event_generator, |
| 61 ui::Accelerator(ui::VKEY_OEM_4, ui::EF_SHIFT_DOWN | ui::EF_COMMAND_DOWN)); | |
| 44 EXPECT_TRUE(tab_strip->IsTabSelected(0)); | 62 EXPECT_TRUE(tab_strip->IsTabSelected(0)); |
| 45 } | 63 } |
| OLD | NEW |