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

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

Issue 2074643003: MacViews: Views accelerators table should match the Cocoa one. (Closed) Base URL: ssh://bitbucket.browser.yandex-team.ru/chromium/src.git@master
Patch Set: Fix compilation. Created 4 years, 1 month 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
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 TEST(GlobalKeyboardShortcuts, ShortcutsToWindowCommand) { 15 TEST(GlobalKeyboardShortcuts, ShortcutsToWindowCommand) {
16 // Test that an invalid shortcut translates into an invalid command id. 16 // Test that an invalid shortcut translates into an invalid command id.
17 EXPECT_EQ( 17 EXPECT_EQ(
18 -1, CommandForWindowKeyboardShortcut(false, false, false, false, 0, 0)); 18 -1, CommandForWindowKeyboardShortcut(false, false, false, false, 0, 0));
19 19
20 // Check that all known keyboard shortcuts return valid results. 20 // Check that all known keyboard shortcuts return valid results.
21 size_t num_shortcuts = 0; 21 for (const auto& shortcut : GetWindowKeyboardShortcutTable()) {
22 const KeyboardShortcutData *it =
23 GetWindowKeyboardShortcutTable(&num_shortcuts);
24 ASSERT_GT(num_shortcuts, 0U);
25 for (size_t i = 0; i < num_shortcuts; ++i, ++it) {
26 int cmd_num = CommandForWindowKeyboardShortcut( 22 int cmd_num = CommandForWindowKeyboardShortcut(
27 it->command_key, it->shift_key, it->cntrl_key, it->opt_key, 23 shortcut.command_key, shortcut.shift_key, shortcut.cntrl_key,
28 it->vkey_code, it->key_char); 24 shortcut.opt_key, shortcut.vkey_code, shortcut.key_char);
29 EXPECT_EQ(cmd_num, it->chrome_command); 25 EXPECT_EQ(cmd_num, shortcut.chrome_command);
30 } 26 }
31 27
32 // Test that cmd-left and backspace are not window-level commands (else they 28 // Test that cmd-left and backspace are not window-level commands (else they
33 // would be invoked even if e.g. the omnibox had focus, where they really 29 // would be invoked even if e.g. the omnibox had focus, where they really
34 // should have text editing functionality). 30 // should have text editing functionality).
35 EXPECT_EQ(-1, CommandForWindowKeyboardShortcut( 31 EXPECT_EQ(-1, CommandForWindowKeyboardShortcut(
36 true, false, false, false, kVK_LeftArrow, 0)); 32 true, false, false, false, kVK_LeftArrow, 0));
37 EXPECT_EQ(-1, CommandForWindowKeyboardShortcut( 33 EXPECT_EQ(-1, CommandForWindowKeyboardShortcut(
38 false, false, false, false, kVK_Delete, 0)); 34 false, false, false, false, kVK_Delete, 0));
39 35
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 } 99 }
104 } 100 }
105 101
106 TEST(GlobalKeyboardShortcuts, ShortcutsToDelayedWindowCommand) { 102 TEST(GlobalKeyboardShortcuts, ShortcutsToDelayedWindowCommand) {
107 // Test that an invalid shortcut translates into an invalid command id. 103 // Test that an invalid shortcut translates into an invalid command id.
108 EXPECT_EQ(-1, 104 EXPECT_EQ(-1,
109 CommandForDelayedWindowKeyboardShortcut(false, false, false, false, 105 CommandForDelayedWindowKeyboardShortcut(false, false, false, false,
110 0, 0)); 106 0, 0));
111 107
112 // Check that all known keyboard shortcuts return valid results. 108 // Check that all known keyboard shortcuts return valid results.
113 size_t num_shortcuts = 0; 109 for (const auto& shortcut : GetDelayedWindowKeyboardShortcutTable()) {
114 const KeyboardShortcutData *it =
115 GetDelayedWindowKeyboardShortcutTable(&num_shortcuts);
116 ASSERT_GT(num_shortcuts, 0U);
117 for (size_t i = 0; i < num_shortcuts; ++i, ++it) {
118 int cmd_num = CommandForDelayedWindowKeyboardShortcut( 110 int cmd_num = CommandForDelayedWindowKeyboardShortcut(
119 it->command_key, it->shift_key, it->cntrl_key, it->opt_key, 111 shortcut.command_key, shortcut.shift_key, shortcut.cntrl_key,
120 it->vkey_code, it->key_char); 112 shortcut.opt_key, shortcut.vkey_code, shortcut.key_char);
121 EXPECT_EQ(cmd_num, it->chrome_command); 113 EXPECT_EQ(cmd_num, shortcut.chrome_command);
122 } 114 }
123 } 115 }
124 116
125 TEST(GlobalKeyboardShortcuts, ShortcutsToBrowserCommand) { 117 TEST(GlobalKeyboardShortcuts, ShortcutsToBrowserCommand) {
126 // Test that an invalid shortcut translates into an invalid command id. 118 // Test that an invalid shortcut translates into an invalid command id.
127 EXPECT_EQ( 119 EXPECT_EQ(
128 -1, CommandForBrowserKeyboardShortcut(false, false, false, false, 120 -1, CommandForBrowserKeyboardShortcut(false, false, false, false,
129 0, 0)); 121 0, 0));
130 122
131 // Check that all known keyboard shortcuts return valid results. 123 // Check that all known keyboard shortcuts return valid results.
132 size_t num_shortcuts = 0; 124 for (const auto& shortcut : GetBrowserKeyboardShortcutTable()) {
133 const KeyboardShortcutData *it =
134 GetBrowserKeyboardShortcutTable(&num_shortcuts);
135 ASSERT_GT(num_shortcuts, 0U);
136 for (size_t i = 0; i < num_shortcuts; ++i, ++it) {
137 int cmd_num = CommandForBrowserKeyboardShortcut( 125 int cmd_num = CommandForBrowserKeyboardShortcut(
138 it->command_key, it->shift_key, it->cntrl_key, it->opt_key, 126 shortcut.command_key, shortcut.shift_key, shortcut.cntrl_key,
139 it->vkey_code, it->key_char); 127 shortcut.opt_key, shortcut.vkey_code, shortcut.key_char);
140 EXPECT_EQ(cmd_num, it->chrome_command); 128 EXPECT_EQ(cmd_num, shortcut.chrome_command);
141 } 129 }
142 } 130 }
143 131
144 NSEvent* KeyEvent(bool command_key, bool shift_key, 132 NSEvent* KeyEvent(bool command_key, bool shift_key,
145 bool cntrl_key, bool opt_key, 133 bool cntrl_key, bool opt_key,
146 NSString* chars, NSString* charsNoMods) { 134 NSString* chars, NSString* charsNoMods) {
147 NSUInteger modifierFlags = 0; 135 NSUInteger modifierFlags = 0;
148 if (command_key) 136 if (command_key)
149 modifierFlags |= NSCommandKeyMask; 137 modifierFlags |= NSCommandKeyMask;
150 if (shift_key) 138 if (shift_key)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 // cmd-shift-'[' in an RTL context pre 10.9. 175 // cmd-shift-'[' in an RTL context pre 10.9.
188 EXPECT_EQ('{', KeyCharacterForEvent( 176 EXPECT_EQ('{', KeyCharacterForEvent(
189 KeyEvent(true, true, false, false, @"{", @"}"))); 177 KeyEvent(true, true, false, false, @"{", @"}")));
190 // cmd-shift-'[' in an RTL context on 10.9. 178 // cmd-shift-'[' in an RTL context on 10.9.
191 EXPECT_EQ('{', KeyCharacterForEvent( 179 EXPECT_EQ('{', KeyCharacterForEvent(
192 KeyEvent(true, true, false, false, @"[", @"}"))); 180 KeyEvent(true, true, false, false, @"[", @"}")));
193 // Test if getting dead-key events return 0 and do not hang. 181 // Test if getting dead-key events return 0 and do not hang.
194 EXPECT_EQ(0, KeyCharacterForEvent( 182 EXPECT_EQ(0, KeyCharacterForEvent(
195 KeyEvent(false, false, false, false, @"", @""))); 183 KeyEvent(false, false, false, false, @"", @"")));
196 } 184 }
OLDNEW
« no previous file with comments | « chrome/browser/global_keyboard_shortcuts_mac.mm ('k') | chrome/browser/global_keyboard_shortcuts_views_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698