OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 <gtest/gtest.h> | 5 #include <gtest/gtest.h> |
6 | 6 |
7 #import <Carbon/Carbon.h> | 7 #import <Carbon/Carbon.h> |
8 #import <Cocoa/Cocoa.h> | 8 #import <Cocoa/Cocoa.h> |
9 | 9 |
10 #include "base/files/file_path.h" | 10 #import "chrome/browser/ui/cocoa/system_hotkey_map.h" |
11 #include "base/path_service.h" | 11 #include "chrome/test/base/ui_test_utils.h" |
12 #import "content/browser/cocoa/system_hotkey_map.h" | |
13 #include "content/public/common/content_paths.h" | |
14 | 12 |
15 namespace content { | 13 namespace { |
16 | 14 |
17 class SystemHotkeyMapTest : public ::testing::Test { | 15 class SystemHotkeyMapTest : public ::testing::Test { |
18 public: | 16 public: |
19 SystemHotkeyMapTest() {} | 17 SystemHotkeyMapTest() {} |
20 }; | 18 }; |
21 | 19 |
22 TEST_F(SystemHotkeyMapTest, Parse) { | 20 TEST_F(SystemHotkeyMapTest, Parse) { |
23 base::FilePath test_data_dir; | 21 std::string path = ui_test_utils::GetTestUrl( |
24 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &test_data_dir)); | 22 base::FilePath(base::FilePath::kCurrentDirectory), |
25 | 23 base::FilePath("mac/mac_system_hotkeys.plist")).path(); |
26 base::FilePath test_path = | 24 NSString* file_path = [NSString stringWithUTF8String:path.c_str()]; |
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]; | 25 NSData* data = [NSData dataWithContentsOfFile:file_path]; |
32 ASSERT_TRUE(data); | 26 ASSERT_TRUE(data); |
33 | 27 |
34 NSDictionary* dictionary = SystemHotkeyMap::DictionaryFromData(data); | |
35 ASSERT_TRUE(dictionary); | |
36 | |
37 SystemHotkeyMap map; | 28 SystemHotkeyMap map; |
38 bool result = map.ParseDictionary(dictionary); | 29 bool result = map.ParseData(data); |
39 EXPECT_TRUE(result); | 30 EXPECT_TRUE(result); |
40 | 31 |
41 // Command + ` is a common key binding. It should exist. | 32 // Command + ` is a common key binding. It should exist. |
42 int key_code = kVK_ANSI_Grave; | 33 int key_code = kVK_ANSI_Grave; |
43 int modifiers = NSCommandKeyMask; | 34 int modifiers = NSCommandKeyMask; |
44 EXPECT_TRUE(map.IsHotkeyReserved(key_code, modifiers)); | 35 EXPECT_TRUE(map.IsHotkeyReserved(key_code, modifiers)); |
45 | 36 |
46 // Command + Shift + ` is a common key binding. It should exist. | 37 // Command + Shift + ` is a common key binding. It should exist. |
47 modifiers = NSCommandKeyMask | NSShiftKeyMask; | 38 modifiers = NSCommandKeyMask | NSShiftKeyMask; |
48 EXPECT_TRUE(map.IsHotkeyReserved(key_code, modifiers)); | 39 EXPECT_TRUE(map.IsHotkeyReserved(key_code, modifiers)); |
49 | 40 |
50 // Command + Shift + Ctr + ` is not a common key binding. | 41 // Command + Shift + Ctr + ` is not a common key binding. |
51 modifiers = NSCommandKeyMask | NSShiftKeyMask | NSControlKeyMask; | 42 modifiers = NSCommandKeyMask | NSShiftKeyMask | NSControlKeyMask; |
52 EXPECT_FALSE(map.IsHotkeyReserved(key_code, modifiers)); | 43 EXPECT_FALSE(map.IsHotkeyReserved(key_code, modifiers)); |
53 | 44 |
54 // Command + L is not a common key binding. | 45 // Command + L is not a common key binding. |
55 key_code = kVK_ANSI_L; | 46 key_code = kVK_ANSI_L; |
56 modifiers = NSCommandKeyMask; | 47 modifiers = NSCommandKeyMask; |
57 EXPECT_FALSE(map.IsHotkeyReserved(key_code, modifiers)); | 48 EXPECT_FALSE(map.IsHotkeyReserved(key_code, modifiers)); |
58 } | 49 } |
59 | 50 |
60 TEST_F(SystemHotkeyMapTest, ParseNil) { | 51 } // namespace |
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 |