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

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

Issue 2535553002: MacViews: Fix GlobalKeyboardShortcuts.ShortcutsToWindowCommand. (Closed)
Patch Set: #ifdef out failing test. 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 | « no previous file | 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 #include "ui/base/ui_features.h"
14 15
15 TEST(GlobalKeyboardShortcuts, ShortcutsToWindowCommand) { 16 TEST(GlobalKeyboardShortcuts, ShortcutsToWindowCommand) {
16 // Test that an invalid shortcut translates into an invalid command id. 17 // Test that an invalid shortcut translates into an invalid command id.
17 EXPECT_EQ( 18 EXPECT_EQ(
18 -1, CommandForWindowKeyboardShortcut(false, false, false, false, 0, 0)); 19 -1, CommandForWindowKeyboardShortcut(false, false, false, false, 0, 0));
19 20
20 // Check that all known keyboard shortcuts return valid results. 21 // Check that all known keyboard shortcuts return valid results.
21 for (const auto& shortcut : GetWindowKeyboardShortcutTable()) { 22 for (const auto& shortcut : GetWindowKeyboardShortcutTable()) {
22 int cmd_num = CommandForWindowKeyboardShortcut( 23 int cmd_num = CommandForWindowKeyboardShortcut(
23 shortcut.command_key, shortcut.shift_key, shortcut.cntrl_key, 24 shortcut.command_key, shortcut.shift_key, shortcut.cntrl_key,
(...skipping 13 matching lines...) Expand all
37 // and IDC_SELECT_PREVIOUS_TAB regardless of the virtual key code values. 38 // and IDC_SELECT_PREVIOUS_TAB regardless of the virtual key code values.
38 EXPECT_EQ(IDC_SELECT_NEXT_TAB, CommandForWindowKeyboardShortcut( 39 EXPECT_EQ(IDC_SELECT_NEXT_TAB, CommandForWindowKeyboardShortcut(
39 true, false, false, false, kVK_ANSI_Period, '}')); 40 true, false, false, false, kVK_ANSI_Period, '}'));
40 EXPECT_EQ(IDC_SELECT_PREVIOUS_TAB, CommandForWindowKeyboardShortcut( 41 EXPECT_EQ(IDC_SELECT_PREVIOUS_TAB, CommandForWindowKeyboardShortcut(
41 true, true, false, false, kVK_ANSI_Slash, '{')); 42 true, true, false, false, kVK_ANSI_Slash, '{'));
42 43
43 // One more test for Cmd-'{' / Alt-8 (on German keyboard layout). 44 // One more test for Cmd-'{' / Alt-8 (on German keyboard layout).
44 EXPECT_EQ(IDC_SELECT_PREVIOUS_TAB, CommandForWindowKeyboardShortcut( 45 EXPECT_EQ(IDC_SELECT_PREVIOUS_TAB, CommandForWindowKeyboardShortcut(
45 true, false, false, true, kVK_ANSI_8, '{')); 46 true, false, false, true, kVK_ANSI_8, '{'));
46 47
48 // On MacViews the IDC_SELECT_TAB_0 accelerator is mapped via the
49 // accelerator_table.cc, which supports mapping using only using keycodes.
50 // The only reason CommandForWindowKeyboardShortcut is necessary on MacViews
51 // is to handle the Cmd-'{' and Cmd-'}', and it doesn't need to handle
52 // IDC_SELECT_TAB_0, so this test could be omitted.
53 #if !BUILDFLAG(MAC_VIEWS_BROWSER)
47 // Test that switching tabs triggers off keycodes and not characters (visible 54 // Test that switching tabs triggers off keycodes and not characters (visible
48 // with the Italian keyboard layout). 55 // with the Italian keyboard layout).
49 EXPECT_EQ(IDC_SELECT_TAB_0, CommandForWindowKeyboardShortcut( 56 EXPECT_EQ(IDC_SELECT_TAB_0, CommandForWindowKeyboardShortcut(
50 true, false, false, false, kVK_ANSI_1, '&')); 57 true, false, false, false, kVK_ANSI_1, '&'));
58 #endif // !BUILDFLAG(MAC_VIEWS_BROWSER)
51 } 59 }
52 60
53 TEST(GlobalKeyboardShortcuts, KeypadNumberKeysMatch) { 61 TEST(GlobalKeyboardShortcuts, KeypadNumberKeysMatch) {
54 // Test that the shortcuts that are generated by keypad number keys match the 62 // Test that the shortcuts that are generated by keypad number keys match the
55 // equivalent keys. 63 // equivalent keys.
56 static const struct { 64 static const struct {
57 int keycode; 65 int keycode;
58 int keypad_keycode; 66 int keypad_keycode;
59 } equivalents[] = { 67 } equivalents[] = {
60 {kVK_ANSI_0, kVK_ANSI_Keypad0}, 68 {kVK_ANSI_0, kVK_ANSI_Keypad0},
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 // cmd-shift-'[' in an RTL context pre 10.9. 183 // cmd-shift-'[' in an RTL context pre 10.9.
176 EXPECT_EQ('{', KeyCharacterForEvent( 184 EXPECT_EQ('{', KeyCharacterForEvent(
177 KeyEvent(true, true, false, false, @"{", @"}"))); 185 KeyEvent(true, true, false, false, @"{", @"}")));
178 // cmd-shift-'[' in an RTL context on 10.9. 186 // cmd-shift-'[' in an RTL context on 10.9.
179 EXPECT_EQ('{', KeyCharacterForEvent( 187 EXPECT_EQ('{', KeyCharacterForEvent(
180 KeyEvent(true, true, false, false, @"[", @"}"))); 188 KeyEvent(true, true, false, false, @"[", @"}")));
181 // Test if getting dead-key events return 0 and do not hang. 189 // Test if getting dead-key events return 0 and do not hang.
182 EXPECT_EQ(0, KeyCharacterForEvent( 190 EXPECT_EQ(0, KeyCharacterForEvent(
183 KeyEvent(false, false, false, false, @"", @""))); 191 KeyEvent(false, false, false, false, @"", @"")));
184 } 192 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698