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