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 #include "base/files/file_path.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #import "content/browser/cocoa/system_hotkey_map.h" | 12 #import "content/browser/cocoa/system_hotkey_map.h" |
13 #include "content/public/common/content_paths.h" | 13 #include "content/public/common/content_paths.h" |
14 | 14 |
15 namespace { | |
16 | |
17 NSData* DataFromTestFile(const char* file) { | |
Robert Sesek
2014/07/22 17:15:24
I'd put this as a method on SystemHotkeyMapTest.
erikchen
2014/07/22 18:30:57
Done.
| |
18 base::FilePath test_data_dir; | |
19 bool result = PathService::Get(content::DIR_TEST_DATA, &test_data_dir); | |
20 if (!result) | |
21 return nil; | |
22 | |
23 base::FilePath test_path = test_data_dir.AppendASCII(file); | |
24 std::string test_path_string = test_path.AsUTF8Unsafe(); | |
25 NSString* file_path = | |
26 [NSString stringWithUTF8String:test_path_string.c_str()]; | |
27 return [NSData dataWithContentsOfFile:file_path]; | |
28 } | |
29 | |
30 } // namespace | |
31 | |
15 namespace content { | 32 namespace content { |
16 | 33 |
17 class SystemHotkeyMapTest : public ::testing::Test { | 34 class SystemHotkeyMapTest : public ::testing::Test { |
18 public: | 35 public: |
19 SystemHotkeyMapTest() {} | 36 SystemHotkeyMapTest() {} |
20 }; | 37 }; |
21 | 38 |
22 TEST_F(SystemHotkeyMapTest, Parse) { | 39 TEST_F(SystemHotkeyMapTest, Parse) { |
23 base::FilePath test_data_dir; | 40 // This plist was pulled from a real machine. It is extensively populated, |
24 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &test_data_dir)); | 41 // and has no missing or incomplete entries. |
25 | 42 NSData* data = DataFromTestFile("mac/mac_system_hotkeys.plist"); |
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); | 43 ASSERT_TRUE(data); |
33 | 44 |
34 NSDictionary* dictionary = SystemHotkeyMap::DictionaryFromData(data); | 45 NSDictionary* dictionary = SystemHotkeyMap::DictionaryFromData(data); |
35 ASSERT_TRUE(dictionary); | 46 ASSERT_TRUE(dictionary); |
36 | 47 |
37 SystemHotkeyMap map; | 48 SystemHotkeyMap map; |
38 bool result = map.ParseDictionary(dictionary); | 49 bool result = map.ParseDictionary(dictionary); |
39 EXPECT_TRUE(result); | 50 EXPECT_TRUE(result); |
40 | 51 |
41 // Command + ` is a common key binding. It should exist. | 52 // Command + ` is a common key binding. It should exist. |
(...skipping 16 matching lines...) Expand all Loading... | |
58 } | 69 } |
59 | 70 |
60 TEST_F(SystemHotkeyMapTest, ParseNil) { | 71 TEST_F(SystemHotkeyMapTest, ParseNil) { |
61 NSDictionary* dictionary = nil; | 72 NSDictionary* dictionary = nil; |
62 | 73 |
63 SystemHotkeyMap map; | 74 SystemHotkeyMap map; |
64 bool result = map.ParseDictionary(dictionary); | 75 bool result = map.ParseDictionary(dictionary); |
65 EXPECT_FALSE(result); | 76 EXPECT_FALSE(result); |
66 } | 77 } |
67 | 78 |
79 TEST_F(SystemHotkeyMapTest, ParseMouse) { | |
80 // This plist was pulled from a real machine. It has missing entries, | |
81 // incomplete entries, and mouse hotkeys. | |
82 NSData* data = DataFromTestFile("mac/mac_system_hotkeys_sparse.plist"); | |
83 ASSERT_TRUE(data); | |
84 | |
85 NSDictionary* dictionary = SystemHotkeyMap::DictionaryFromData(data); | |
86 ASSERT_TRUE(dictionary); | |
87 | |
88 SystemHotkeyMap map; | |
89 bool result = map.ParseDictionary(dictionary); | |
90 EXPECT_TRUE(result); | |
91 | |
92 // Command + ` is a common key binding. It is missing. | |
93 // TODO(erikchen): OSX uses the default value when the keybinding is missing, | |
94 // so the hotkey should still be reserved. | |
95 // http://crbug.com/383558 | |
96 int key_code = kVK_ANSI_Grave; | |
Robert Sesek
2014/07/22 17:15:24
Use the right types here, and on line 97.
erikchen
2014/07/22 18:30:57
Done.
| |
97 int modifiers = NSCommandKeyMask; | |
98 EXPECT_FALSE(map.IsHotkeyReserved(key_code, modifiers)); | |
99 | |
100 // There is a mouse keybinding for 0x08. It should not apply to keyboard | |
101 // hotkeys. | |
102 key_code = kVK_ANSI_C; | |
103 modifiers = 0; | |
104 EXPECT_FALSE(map.IsHotkeyReserved(key_code, modifiers)); | |
105 | |
106 // Command + Alt + = is an accessibility shortcut. Its entry in the plist is | |
107 // incomplete. | |
108 // TODO(erikchen): OSX uses the default bindings, so this hotkey should still | |
109 // be reserved. | |
110 // http://crbug.com/383558 | |
111 key_code = kVK_ANSI_Equal; | |
112 modifiers = NSCommandKeyMask | NSAlternateKeyMask; | |
113 EXPECT_FALSE(map.IsHotkeyReserved(key_code, modifiers)); | |
114 } | |
115 | |
68 } // namespace content | 116 } // namespace content |
OLD | NEW |