| OLD | NEW |
| 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 <Carbon/Carbon.h> | 5 #include <Carbon/Carbon.h> |
| 6 | 6 |
| 7 #include "chrome/browser/global_keyboard_shortcuts_mac.h" | 7 #include "chrome/browser/global_keyboard_shortcuts_mac.h" |
| 8 | 8 |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 TEST(GlobalKeyboardShortcuts, ShortcutsToWindowCommand) { | 11 TEST(GlobalKeyboardShortcuts, ShortcutsToWindowCommand) { |
| 12 // Test that an invalid shortcut translates into an invalid command id. | 12 // Test that an invalid shortcut translates into an invalid command id. |
| 13 ASSERT_EQ(-1, CommandForWindowKeyboardShortcut(false, false, false, 0)); | 13 ASSERT_EQ( |
| 14 -1, CommandForWindowKeyboardShortcut(false, false, false, false, 0)); |
| 14 | 15 |
| 15 // Check that all known keyboard shortcuts return valid results. | 16 // Check that all known keyboard shortcuts return valid results. |
| 16 size_t num_shortcuts = 0; | 17 size_t num_shortcuts = 0; |
| 17 const KeyboardShortcutData *it = | 18 const KeyboardShortcutData *it = |
| 18 GetWindowKeyboardShortcutTable(&num_shortcuts); | 19 GetWindowKeyboardShortcutTable(&num_shortcuts); |
| 19 ASSERT_GT(num_shortcuts, 0U); | 20 ASSERT_GT(num_shortcuts, 0U); |
| 20 for (size_t i = 0; i < num_shortcuts; ++i, ++it) { | 21 for (size_t i = 0; i < num_shortcuts; ++i, ++it) { |
| 21 int cmd_num = CommandForWindowKeyboardShortcut( | 22 int cmd_num = CommandForWindowKeyboardShortcut( |
| 22 it->command_key, it->shift_key, it->cntrl_key, it->vkey_code); | 23 it->command_key, it->shift_key, it->cntrl_key, it->opt_key, |
| 24 it->vkey_code); |
| 23 ASSERT_EQ(cmd_num, it->chrome_command); | 25 ASSERT_EQ(cmd_num, it->chrome_command); |
| 24 } | 26 } |
| 25 | 27 |
| 26 // 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 |
| 27 // 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 |
| 28 // should have text editing functionality). | 30 // should have text editing functionality). |
| 29 ASSERT_EQ(-1, CommandForWindowKeyboardShortcut( | 31 ASSERT_EQ(-1, CommandForWindowKeyboardShortcut( |
| 30 true, false, false, kVK_LeftArrow)); | 32 true, false, false, false, kVK_LeftArrow)); |
| 31 ASSERT_EQ(-1, CommandForWindowKeyboardShortcut( | 33 ASSERT_EQ(-1, CommandForWindowKeyboardShortcut( |
| 32 false, false, false, kVK_Delete)); | 34 false, false, false, false, kVK_Delete)); |
| 33 } | 35 } |
| 34 | 36 |
| 35 TEST(GlobalKeyboardShortcuts, ShortcutsToBrowserCommand) { | 37 TEST(GlobalKeyboardShortcuts, ShortcutsToBrowserCommand) { |
| 36 // Test that an invalid shortcut translates into an invalid command id. | 38 // Test that an invalid shortcut translates into an invalid command id. |
| 37 ASSERT_EQ(-1, CommandForBrowserKeyboardShortcut(false, false, false, 0)); | 39 ASSERT_EQ( |
| 40 -1, CommandForBrowserKeyboardShortcut(false, false, false, false, 0)); |
| 38 | 41 |
| 39 // Check that all known keyboard shortcuts return valid results. | 42 // Check that all known keyboard shortcuts return valid results. |
| 40 size_t num_shortcuts = 0; | 43 size_t num_shortcuts = 0; |
| 41 const KeyboardShortcutData *it = | 44 const KeyboardShortcutData *it = |
| 42 GetBrowserKeyboardShortcutTable(&num_shortcuts); | 45 GetBrowserKeyboardShortcutTable(&num_shortcuts); |
| 43 ASSERT_GT(num_shortcuts, 0U); | 46 ASSERT_GT(num_shortcuts, 0U); |
| 44 for (size_t i = 0; i < num_shortcuts; ++i, ++it) { | 47 for (size_t i = 0; i < num_shortcuts; ++i, ++it) { |
| 45 int cmd_num = CommandForBrowserKeyboardShortcut( | 48 int cmd_num = CommandForBrowserKeyboardShortcut( |
| 46 it->command_key, it->shift_key, it->cntrl_key, it->vkey_code); | 49 it->command_key, it->shift_key, it->cntrl_key, it->opt_key, |
| 47 ASSERT_EQ(cmd_num, it->chrome_command); | 50 it->vkey_code); ASSERT_EQ(cmd_num, it->chrome_command); |
| 48 } | 51 } |
| 49 } | 52 } |
| OLD | NEW |