Chromium Code Reviews| Index: content/browser/cocoa/system_hotkey_map_unittest.mm |
| diff --git a/content/browser/cocoa/system_hotkey_map_unittest.mm b/content/browser/cocoa/system_hotkey_map_unittest.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d28d42e0ca5f18725cd44b8a2fae2cd9029f655d |
| --- /dev/null |
| +++ b/content/browser/cocoa/system_hotkey_map_unittest.mm |
| @@ -0,0 +1,112 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include <gtest/gtest.h> |
| + |
| +#import <Carbon/Carbon.h> |
| +#import <Cocoa/Cocoa.h> |
| + |
| +#include "base/files/file_path.h" |
| +#include "base/path_service.h" |
| +#import "content/browser/cocoa/system_hotkey_map.h" |
| +#include "content/public/common/content_paths.h" |
| + |
| +namespace content { |
| + |
| +class SystemHotkeyMapTest : public ::testing::Test { |
| + public: |
| + SystemHotkeyMapTest() {} |
| + |
| + NSData* DataFromTestFile(const char* file) { |
| + base::FilePath test_data_dir; |
| + bool result = PathService::Get(DIR_TEST_DATA, &test_data_dir); |
| + if (!result) |
| + return nil; |
| + |
| + base::FilePath test_path = test_data_dir.AppendASCII(file); |
| + std::string test_path_string = test_path.AsUTF8Unsafe(); |
| + NSString* file_path = |
| + [NSString stringWithUTF8String:test_path_string.c_str()]; |
| + return [NSData dataWithContentsOfFile:file_path]; |
| + } |
| +}; |
| + |
| +TEST_F(SystemHotkeyMapTest, Parse) { |
| + // This plist was pulled from a real machine. It is extensively populated, |
| + // and has no missing or incomplete entries. |
| + NSData* data = DataFromTestFile("mac/mac_system_hotkeys.plist"); |
| + ASSERT_TRUE(data); |
| + |
| + NSDictionary* dictionary = SystemHotkeyMap::DictionaryFromData(data); |
| + ASSERT_TRUE(dictionary); |
| + |
| + SystemHotkeyMap map; |
| + bool result = map.ParseDictionary(dictionary); |
| + EXPECT_TRUE(result); |
| + |
| + // Command + ` is a common key binding. It should exist. |
| + unsigned short key_code = kVK_ANSI_Grave; |
| + NSUInteger modifiers = NSCommandKeyMask; |
| + EXPECT_TRUE(map.IsHotkeyReserved(key_code, modifiers)); |
| + |
| + // Command + Shift + ` is a common key binding. It should exist. |
| + modifiers = NSCommandKeyMask | NSShiftKeyMask; |
| + EXPECT_TRUE(map.IsHotkeyReserved(key_code, modifiers)); |
| + |
| + // Command + Shift + Ctr + ` is not a common key binding. |
| + modifiers = NSCommandKeyMask | NSShiftKeyMask | NSControlKeyMask; |
| + EXPECT_FALSE(map.IsHotkeyReserved(key_code, modifiers)); |
| + |
| + // Command + L is not a common key binding. |
| + key_code = kVK_ANSI_L; |
| + modifiers = NSCommandKeyMask; |
| + EXPECT_FALSE(map.IsHotkeyReserved(key_code, modifiers)); |
|
Robert Sesek
2014/07/23 15:34:07
You don't ever test if modifiers = 0.
erikchen
2014/07/23 18:05:34
I added a new batch of tests.
|
| +} |
| + |
| +TEST_F(SystemHotkeyMapTest, ParseNil) { |
| + NSDictionary* dictionary = nil; |
| + |
| + SystemHotkeyMap map; |
| + bool result = map.ParseDictionary(dictionary); |
| + EXPECT_FALSE(result); |
| +} |
| + |
| +TEST_F(SystemHotkeyMapTest, ParseMouse) { |
| + // This plist was pulled from a real machine. It has missing entries, |
| + // incomplete entries, and mouse hotkeys. |
| + NSData* data = DataFromTestFile("mac/mac_system_hotkeys_sparse.plist"); |
| + ASSERT_TRUE(data); |
| + |
| + NSDictionary* dictionary = SystemHotkeyMap::DictionaryFromData(data); |
| + ASSERT_TRUE(dictionary); |
| + |
| + SystemHotkeyMap map; |
| + bool result = map.ParseDictionary(dictionary); |
| + EXPECT_TRUE(result); |
| + |
| + // Command + ` is a common key binding. It is missing. |
| + // TODO(erikchen): OSX uses the default value when the keybinding is missing, |
| + // so the hotkey should still be reserved. |
| + // http://crbug.com/383558 |
| + unsigned short key_code = kVK_ANSI_Grave; |
| + NSUInteger modifiers = NSCommandKeyMask; |
| + EXPECT_FALSE(map.IsHotkeyReserved(key_code, modifiers)); |
| + |
| + // There is a mouse keybinding for 0x08. It should not apply to keyboard |
| + // hotkeys. |
| + key_code = kVK_ANSI_C; |
| + modifiers = 0; |
| + EXPECT_FALSE(map.IsHotkeyReserved(key_code, modifiers)); |
| + |
| + // Command + Alt + = is an accessibility shortcut. Its entry in the plist is |
| + // incomplete. |
| + // TODO(erikchen): OSX uses the default bindings, so this hotkey should still |
| + // be reserved. |
| + // http://crbug.com/383558 |
| + key_code = kVK_ANSI_Equal; |
| + modifiers = NSCommandKeyMask | NSAlternateKeyMask; |
| + EXPECT_FALSE(map.IsHotkeyReserved(key_code, modifiers)); |
| +} |
| + |
| +} // namespace content |