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 |
28 SystemHotkeyMap map; | 34 SystemHotkeyMap map; |
29 bool result = map.ParseData(data); | 35 bool result = map.ParseData(data); |
30 EXPECT_TRUE(result); | 36 EXPECT_TRUE(result); |
31 | 37 |
32 // Command + ` is a common key binding. It should exist. | 38 // Command + ` is a common key binding. It should exist. |
33 int key_code = kVK_ANSI_Grave; | 39 int key_code = kVK_ANSI_Grave; |
34 int modifiers = NSCommandKeyMask; | 40 int modifiers = NSCommandKeyMask; |
35 EXPECT_TRUE(map.IsHotkeyReserved(key_code, modifiers)); | 41 EXPECT_TRUE(map.IsHotkeyReserved(key_code, modifiers)); |
36 | 42 |
37 // Command + Shift + ` is a common key binding. It should exist. | 43 // Command + Shift + ` is a common key binding. It should exist. |
38 modifiers = NSCommandKeyMask | NSShiftKeyMask; | 44 modifiers = NSCommandKeyMask | NSShiftKeyMask; |
39 EXPECT_TRUE(map.IsHotkeyReserved(key_code, modifiers)); | 45 EXPECT_TRUE(map.IsHotkeyReserved(key_code, modifiers)); |
40 | 46 |
41 // Command + Shift + Ctr + ` is not a common key binding. | 47 // Command + Shift + Ctr + ` is not a common key binding. |
42 modifiers = NSCommandKeyMask | NSShiftKeyMask | NSControlKeyMask; | 48 modifiers = NSCommandKeyMask | NSShiftKeyMask | NSControlKeyMask; |
43 EXPECT_FALSE(map.IsHotkeyReserved(key_code, modifiers)); | 49 EXPECT_FALSE(map.IsHotkeyReserved(key_code, modifiers)); |
44 | 50 |
45 // Command + L is not a common key binding. | 51 // Command + L is not a common key binding. |
46 key_code = kVK_ANSI_L; | 52 key_code = kVK_ANSI_L; |
47 modifiers = NSCommandKeyMask; | 53 modifiers = NSCommandKeyMask; |
48 EXPECT_FALSE(map.IsHotkeyReserved(key_code, modifiers)); | 54 EXPECT_FALSE(map.IsHotkeyReserved(key_code, modifiers)); |
49 } | 55 } |
50 | 56 |
51 } // namespace | 57 TEST_F(SystemHotkeyMapTest, ParseNil) { |
| 58 NSData* data = nil; |
| 59 |
| 60 SystemHotkeyMap map; |
| 61 bool result = map.ParseData(data); |
| 62 EXPECT_FALSE(result); |
| 63 } |
| 64 |
| 65 } // namespace content |
OLD | NEW |