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

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

Issue 2535553002: MacViews: Fix GlobalKeyboardShortcuts.ShortcutsToWindowCommand. (Closed)
Patch Set: 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 | « chrome/browser/global_keyboard_shortcuts_mac.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 #include <AppKit/NSEvent.h> 5 #include <AppKit/NSEvent.h>
6 #include <Carbon/Carbon.h> 6 #include <Carbon/Carbon.h>
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "chrome/browser/global_keyboard_shortcuts_mac.h" 9 #include "chrome/browser/global_keyboard_shortcuts_mac.h"
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "chrome/app/chrome_command_ids.h" 12 #include "chrome/app/chrome_command_ids.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace {
16
17 // Common shortcut table that's shared between Cocoa and MacViews, so it's
18 // possible that accelerator matching is working correctly in a portable manner.
19 const std::vector<KeyboardShortcutData>& GetTestShortcutTable() {
20 CR_DEFINE_STATIC_LOCAL(std::vector<KeyboardShortcutData>, result, ({
21 // cmd shift cntrl option
22 // --- ----- ----- ------
23 {true, false, false, false, kVK_ANSI_1, 0, IDC_SELECT_TAB_0},
24 {true, false, false, false, kVK_ANSI_Keypad1, 0, IDC_SELECT_TAB_0},
25 }));
26 return result;
27 }
28
29 int CommandForTestShortcut(
30 bool command_key, bool shift_key, bool cntrl_key, bool opt_key,
31 int vkey_code, unichar key_char) {
32 return CommandForKeyboardShortcut(GetTestShortcutTable(),
33 command_key, shift_key,
34 cntrl_key, opt_key, vkey_code,
35 key_char);
36 }
37
38 } // namespace
39
15 TEST(GlobalKeyboardShortcuts, ShortcutsToWindowCommand) { 40 TEST(GlobalKeyboardShortcuts, ShortcutsToWindowCommand) {
16 // Test that an invalid shortcut translates into an invalid command id. 41 // Test that an invalid shortcut translates into an invalid command id.
17 EXPECT_EQ( 42 EXPECT_EQ(
18 -1, CommandForWindowKeyboardShortcut(false, false, false, false, 0, 0)); 43 -1, CommandForWindowKeyboardShortcut(false, false, false, false, 0, 0));
19 44
20 // Check that all known keyboard shortcuts return valid results. 45 // Check that all known keyboard shortcuts return valid results.
21 for (const auto& shortcut : GetWindowKeyboardShortcutTable()) { 46 for (const auto& shortcut : GetWindowKeyboardShortcutTable()) {
22 int cmd_num = CommandForWindowKeyboardShortcut( 47 int cmd_num = CommandForWindowKeyboardShortcut(
23 shortcut.command_key, shortcut.shift_key, shortcut.cntrl_key, 48 shortcut.command_key, shortcut.shift_key, shortcut.cntrl_key,
24 shortcut.opt_key, shortcut.vkey_code, shortcut.key_char); 49 shortcut.opt_key, shortcut.vkey_code, shortcut.key_char);
(...skipping 14 matching lines...) Expand all
39 true, false, false, false, kVK_ANSI_Period, '}')); 64 true, false, false, false, kVK_ANSI_Period, '}'));
40 EXPECT_EQ(IDC_SELECT_PREVIOUS_TAB, CommandForWindowKeyboardShortcut( 65 EXPECT_EQ(IDC_SELECT_PREVIOUS_TAB, CommandForWindowKeyboardShortcut(
41 true, true, false, false, kVK_ANSI_Slash, '{')); 66 true, true, false, false, kVK_ANSI_Slash, '{'));
42 67
43 // One more test for Cmd-'{' / Alt-8 (on German keyboard layout). 68 // One more test for Cmd-'{' / Alt-8 (on German keyboard layout).
44 EXPECT_EQ(IDC_SELECT_PREVIOUS_TAB, CommandForWindowKeyboardShortcut( 69 EXPECT_EQ(IDC_SELECT_PREVIOUS_TAB, CommandForWindowKeyboardShortcut(
45 true, false, false, true, kVK_ANSI_8, '{')); 70 true, false, false, true, kVK_ANSI_8, '{'));
46 71
47 // Test that switching tabs triggers off keycodes and not characters (visible 72 // Test that switching tabs triggers off keycodes and not characters (visible
48 // with the Italian keyboard layout). 73 // with the Italian keyboard layout).
49 EXPECT_EQ(IDC_SELECT_TAB_0, CommandForWindowKeyboardShortcut( 74 EXPECT_EQ(IDC_SELECT_TAB_0, CommandForTestShortcut(
tapted 2016/12/02 07:26:09 I poked around the code, and I think this expectat
themblsha 2016/12/02 17:20:38 Woohoo! This BUILDFLAG will make dealing with fail
50 true, false, false, false, kVK_ANSI_1, '&')); 75 true, false, false, false, kVK_ANSI_1, '&'));
51 } 76 }
52 77
53 TEST(GlobalKeyboardShortcuts, KeypadNumberKeysMatch) { 78 TEST(GlobalKeyboardShortcuts, KeypadNumberKeysMatch) {
54 // Test that the shortcuts that are generated by keypad number keys match the 79 // Test that the shortcuts that are generated by keypad number keys match the
55 // equivalent keys. 80 // equivalent keys.
56 static const struct { 81 static const struct {
57 int keycode; 82 int keycode;
58 int keypad_keycode; 83 int keypad_keycode;
59 } equivalents[] = { 84 } equivalents[] = {
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 // cmd-shift-'[' in an RTL context pre 10.9. 200 // cmd-shift-'[' in an RTL context pre 10.9.
176 EXPECT_EQ('{', KeyCharacterForEvent( 201 EXPECT_EQ('{', KeyCharacterForEvent(
177 KeyEvent(true, true, false, false, @"{", @"}"))); 202 KeyEvent(true, true, false, false, @"{", @"}")));
178 // cmd-shift-'[' in an RTL context on 10.9. 203 // cmd-shift-'[' in an RTL context on 10.9.
179 EXPECT_EQ('{', KeyCharacterForEvent( 204 EXPECT_EQ('{', KeyCharacterForEvent(
180 KeyEvent(true, true, false, false, @"[", @"}"))); 205 KeyEvent(true, true, false, false, @"[", @"}")));
181 // Test if getting dead-key events return 0 and do not hang. 206 // Test if getting dead-key events return 0 and do not hang.
182 EXPECT_EQ(0, KeyCharacterForEvent( 207 EXPECT_EQ(0, KeyCharacterForEvent(
183 KeyEvent(false, false, false, false, @"", @""))); 208 KeyEvent(false, false, false, false, @"", @"")));
184 } 209 }
OLDNEW
« no previous file with comments | « chrome/browser/global_keyboard_shortcuts_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698