OLD | NEW |
| (Empty) |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include <gtest/gtest.h> | |
6 | |
7 #import <Carbon/Carbon.h> | |
8 #import <Cocoa/Cocoa.h> | |
9 | |
10 #include "base/files/file_path.h" | |
11 #include "base/path_service.h" | |
12 #import "content/browser/cocoa/system_hotkey_map.h" | |
13 #include "content/public/common/content_paths.h" | |
14 | |
15 namespace content { | |
16 | |
17 class SystemHotkeyMapTest : public ::testing::Test { | |
18 public: | |
19 SystemHotkeyMapTest() {} | |
20 }; | |
21 | |
22 TEST_F(SystemHotkeyMapTest, Parse) { | |
23 base::FilePath test_data_dir; | |
24 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &test_data_dir)); | |
25 | |
26 base::FilePath test_path = | |
27 test_data_dir.AppendASCII("mac/mac_system_hotkeys.plist"); | |
28 std::string test_path_string = test_path.AsUTF8Unsafe(); | |
29 NSString* file_path = | |
30 [NSString stringWithUTF8String:test_path_string.c_str()]; | |
31 NSData* data = [NSData dataWithContentsOfFile:file_path]; | |
32 ASSERT_TRUE(data); | |
33 | |
34 NSDictionary* dictionary = SystemHotkeyMap::DictionaryFromData(data); | |
35 ASSERT_TRUE(dictionary); | |
36 | |
37 SystemHotkeyMap map; | |
38 bool result = map.ParseDictionary(dictionary); | |
39 EXPECT_TRUE(result); | |
40 | |
41 // Command + ` is a common key binding. It should exist. | |
42 int key_code = kVK_ANSI_Grave; | |
43 int modifiers = NSCommandKeyMask; | |
44 EXPECT_TRUE(map.IsHotkeyReserved(key_code, modifiers)); | |
45 | |
46 // Command + Shift + ` is a common key binding. It should exist. | |
47 modifiers = NSCommandKeyMask | NSShiftKeyMask; | |
48 EXPECT_TRUE(map.IsHotkeyReserved(key_code, modifiers)); | |
49 | |
50 // Command + Shift + Ctr + ` is not a common key binding. | |
51 modifiers = NSCommandKeyMask | NSShiftKeyMask | NSControlKeyMask; | |
52 EXPECT_FALSE(map.IsHotkeyReserved(key_code, modifiers)); | |
53 | |
54 // Command + L is not a common key binding. | |
55 key_code = kVK_ANSI_L; | |
56 modifiers = NSCommandKeyMask; | |
57 EXPECT_FALSE(map.IsHotkeyReserved(key_code, modifiers)); | |
58 } | |
59 | |
60 TEST_F(SystemHotkeyMapTest, ParseNil) { | |
61 NSDictionary* dictionary = nil; | |
62 | |
63 SystemHotkeyMap map; | |
64 bool result = map.ParseDictionary(dictionary); | |
65 EXPECT_FALSE(result); | |
66 } | |
67 | |
68 } // namespace content | |
OLD | NEW |