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

Unified Diff: chrome/browser/global_keyboard_shortcuts_mac_unittest.mm

Issue 5072003: Allow keypad 1..9 keys to be used as shortcuts to switch tabs.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/global_keyboard_shortcuts_mac.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/global_keyboard_shortcuts_mac_unittest.mm
===================================================================
--- chrome/browser/global_keyboard_shortcuts_mac_unittest.mm (revision 66317)
+++ chrome/browser/global_keyboard_shortcuts_mac_unittest.mm (working copy)
@@ -12,7 +12,7 @@
TEST(GlobalKeyboardShortcuts, ShortcutsToWindowCommand) {
// Test that an invalid shortcut translates into an invalid command id.
- ASSERT_EQ(
+ EXPECT_EQ(
-1, CommandForWindowKeyboardShortcut(false, false, false, false, 0, 0));
// Check that all known keyboard shortcuts return valid results.
@@ -24,32 +24,86 @@
int cmd_num = CommandForWindowKeyboardShortcut(
it->command_key, it->shift_key, it->cntrl_key, it->opt_key,
it->vkey_code, it->key_char);
- ASSERT_EQ(cmd_num, it->chrome_command);
+ EXPECT_EQ(cmd_num, it->chrome_command);
}
// Test that cmd-left and backspace are not window-level commands (else they
// would be invoked even if e.g. the omnibox had focus, where they really
// should have text editing functionality).
- ASSERT_EQ(-1, CommandForWindowKeyboardShortcut(
+ EXPECT_EQ(-1, CommandForWindowKeyboardShortcut(
true, false, false, false, kVK_LeftArrow, 0));
- ASSERT_EQ(-1, CommandForWindowKeyboardShortcut(
+ EXPECT_EQ(-1, CommandForWindowKeyboardShortcut(
false, false, false, false, kVK_Delete, 0));
// Test that Cmd-'{' and Cmd-'}' are interpreted as IDC_SELECT_NEXT_TAB
// and IDC_SELECT_PREVIOUS_TAB regardless of the virtual key code values.
- ASSERT_EQ(IDC_SELECT_NEXT_TAB, CommandForWindowKeyboardShortcut(
+ EXPECT_EQ(IDC_SELECT_NEXT_TAB, CommandForWindowKeyboardShortcut(
true, false, false, false, kVK_ANSI_Period, '}'));
- ASSERT_EQ(IDC_SELECT_PREVIOUS_TAB, CommandForWindowKeyboardShortcut(
+ EXPECT_EQ(IDC_SELECT_PREVIOUS_TAB, CommandForWindowKeyboardShortcut(
true, true, false, false, kVK_ANSI_Slash, '{'));
- // One more test for Cmd-'{' / Alt-8 (on german keyboard layout).
- ASSERT_EQ(IDC_SELECT_PREVIOUS_TAB, CommandForWindowKeyboardShortcut(
+ // One more test for Cmd-'{' / Alt-8 (on German keyboard layout).
+ EXPECT_EQ(IDC_SELECT_PREVIOUS_TAB, CommandForWindowKeyboardShortcut(
true, false, false, true, kVK_ANSI_8, '{'));
+
+ // Test that switching tabs triggers off keycodes and not characters (visible
+ // with the Italian keyboard layout).
+ EXPECT_EQ(IDC_SELECT_TAB_0, CommandForWindowKeyboardShortcut(
+ true, false, false, false, kVK_ANSI_1, '&'));
}
+TEST(GlobalKeyboardShortcuts, KeypadNumberKeysMatch) {
+ // Test that the shortcuts that are generated by keypad number keys match the
+ // equivalent keys.
+ static const struct {
+ int keycode;
+ int keypad_keycode;
+ } equivalents[] = {
+ {kVK_ANSI_0, kVK_ANSI_Keypad0},
+ {kVK_ANSI_1, kVK_ANSI_Keypad1},
+ {kVK_ANSI_2, kVK_ANSI_Keypad2},
+ {kVK_ANSI_3, kVK_ANSI_Keypad3},
+ {kVK_ANSI_4, kVK_ANSI_Keypad4},
+ {kVK_ANSI_5, kVK_ANSI_Keypad5},
+ {kVK_ANSI_6, kVK_ANSI_Keypad6},
+ {kVK_ANSI_7, kVK_ANSI_Keypad7},
+ {kVK_ANSI_8, kVK_ANSI_Keypad8},
+ {kVK_ANSI_9, kVK_ANSI_Keypad9},
+ };
+
+ for (int i = 0; i < 10; ++i) {
Nico 2010/11/16 23:19:34 arraysize(equivalents) (or UNSAFE_ARRAYSIZE(equiva
Avi (use Gerrit) 2010/11/16 23:24:23 arraysize doesn't work because the array is of an
+ for (int command = 0; command <= 1; ++command) {
+ for (int shift = 0; shift <= 1; ++shift) {
+ for (int control = 0; control <= 1; ++control) {
+ for (int option = 0; option <= 1; ++option) {
+ EXPECT_EQ(
+ CommandForWindowKeyboardShortcut(
+ command, shift, control, option, equivalents[i].keycode, 0),
+ CommandForWindowKeyboardShortcut(
+ command, shift, control, option,
+ equivalents[i].keypad_keycode, 0));
+ EXPECT_EQ(
+ CommandForDelayedWindowKeyboardShortcut(
+ command, shift, control, option, equivalents[i].keycode, 0),
+ CommandForDelayedWindowKeyboardShortcut(
+ command, shift, control, option,
+ equivalents[i].keypad_keycode, 0));
+ EXPECT_EQ(
+ CommandForBrowserKeyboardShortcut(
+ command, shift, control, option, equivalents[i].keycode, 0),
+ CommandForBrowserKeyboardShortcut(
+ command, shift, control, option,
+ equivalents[i].keypad_keycode, 0));
+ }
+ }
+ }
+ }
+ }
+}
+
TEST(GlobalKeyboardShortcuts, ShortcutsToDelayedWindowCommand) {
// Test that an invalid shortcut translates into an invalid command id.
- ASSERT_EQ(-1,
+ EXPECT_EQ(-1,
CommandForDelayedWindowKeyboardShortcut(false, false, false, false,
0, 0));
@@ -62,13 +116,13 @@
int cmd_num = CommandForDelayedWindowKeyboardShortcut(
it->command_key, it->shift_key, it->cntrl_key, it->opt_key,
it->vkey_code, it->key_char);
- ASSERT_EQ(cmd_num, it->chrome_command);
+ EXPECT_EQ(cmd_num, it->chrome_command);
}
}
TEST(GlobalKeyboardShortcuts, ShortcutsToBrowserCommand) {
// Test that an invalid shortcut translates into an invalid command id.
- ASSERT_EQ(
+ EXPECT_EQ(
-1, CommandForBrowserKeyboardShortcut(false, false, false, false,
0, 0));
@@ -81,7 +135,7 @@
int cmd_num = CommandForBrowserKeyboardShortcut(
it->command_key, it->shift_key, it->cntrl_key, it->opt_key,
it->vkey_code, it->key_char);
- ASSERT_EQ(cmd_num, it->chrome_command);
+ EXPECT_EQ(cmd_num, it->chrome_command);
}
}
@@ -111,27 +165,27 @@
TEST(GlobalKeyboardShortcuts, KeyCharacterForEvent) {
// 'a'
- ASSERT_EQ('a', KeyCharacterForEvent(
+ EXPECT_EQ('a', KeyCharacterForEvent(
KeyEvent(false, false, false, false, @"a", @"a")));
// cmd-'a' / cmd-shift-'a'
- ASSERT_EQ('a', KeyCharacterForEvent(
+ EXPECT_EQ('a', KeyCharacterForEvent(
KeyEvent(true, true, false, false, @"a", @"A")));
// '8'
- ASSERT_EQ('8', KeyCharacterForEvent(
+ EXPECT_EQ('8', KeyCharacterForEvent(
KeyEvent(false, false, false, false, @"8", @"8")));
// '{' / alt-'8' on german
- ASSERT_EQ('{', KeyCharacterForEvent(
+ EXPECT_EQ('{', KeyCharacterForEvent(
KeyEvent(false, false, false, true, @"{", @"8")));
// cmd-'{' / cmd-shift-'[' on ansi
- ASSERT_EQ('{', KeyCharacterForEvent(
+ EXPECT_EQ('{', KeyCharacterForEvent(
KeyEvent(true, true, false, false, @"[", @"{")));
// cmd-'z' / cmd-shift-';' on dvorak-qwerty
- ASSERT_EQ('z', KeyCharacterForEvent(
+ EXPECT_EQ('z', KeyCharacterForEvent(
KeyEvent(true, true, false, false, @"z", @":")));
// cmd-shift-'[' in an RTL context.
- ASSERT_EQ('{', KeyCharacterForEvent(
+ EXPECT_EQ('{', KeyCharacterForEvent(
KeyEvent(true, true, false, false, @"{", @"}")));
// Test if getting dead-key events return 0 and do not hang.
- ASSERT_EQ(0, KeyCharacterForEvent(
+ EXPECT_EQ(0, KeyCharacterForEvent(
KeyEvent(false, false, false, false, @"", @"")));
}
« 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