Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: content/browser/cocoa/system_hotkey_map_unittest.mm

Issue 408973002: mac: Load the system hotkeys after launch. (reland) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments from rsesek. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 NSData* DataFromTestFile(const char* file) {
22 base::FilePath test_data_dir;
23 bool result = PathService::Get(DIR_TEST_DATA, &test_data_dir);
24 if (!result)
25 return nil;
26
27 base::FilePath test_path = test_data_dir.AppendASCII(file);
28 std::string test_path_string = test_path.AsUTF8Unsafe();
29 NSString* file_path =
30 [NSString stringWithUTF8String:test_path_string.c_str()];
31 return [NSData dataWithContentsOfFile:file_path];
32 }
33 };
34
35 TEST_F(SystemHotkeyMapTest, Parse) {
36 // This plist was pulled from a real machine. It is extensively populated,
37 // and has no missing or incomplete entries.
38 NSData* data = DataFromTestFile("mac/mac_system_hotkeys.plist");
39 ASSERT_TRUE(data);
40
41 NSDictionary* dictionary = SystemHotkeyMap::DictionaryFromData(data);
42 ASSERT_TRUE(dictionary);
43
44 SystemHotkeyMap map;
45 bool result = map.ParseDictionary(dictionary);
46 EXPECT_TRUE(result);
47
48 // Command + ` is a common key binding. It should exist.
49 unsigned short key_code = kVK_ANSI_Grave;
50 NSUInteger modifiers = NSCommandKeyMask;
51 EXPECT_TRUE(map.IsHotkeyReserved(key_code, modifiers));
52
53 // Command + Shift + ` is a common key binding. It should exist.
54 modifiers = NSCommandKeyMask | NSShiftKeyMask;
55 EXPECT_TRUE(map.IsHotkeyReserved(key_code, modifiers));
56
57 // Command + Shift + Ctr + ` is not a common key binding.
58 modifiers = NSCommandKeyMask | NSShiftKeyMask | NSControlKeyMask;
59 EXPECT_FALSE(map.IsHotkeyReserved(key_code, modifiers));
60
61 // Command + L is not a common key binding.
62 key_code = kVK_ANSI_L;
63 modifiers = NSCommandKeyMask;
64 EXPECT_FALSE(map.IsHotkeyReserved(key_code, modifiers));
Robert Sesek 2014/07/23 15:34:07 You don't ever test if modifiers = 0.
erikchen 2014/07/23 18:05:34 I added a new batch of tests.
65 }
66
67 TEST_F(SystemHotkeyMapTest, ParseNil) {
68 NSDictionary* dictionary = nil;
69
70 SystemHotkeyMap map;
71 bool result = map.ParseDictionary(dictionary);
72 EXPECT_FALSE(result);
73 }
74
75 TEST_F(SystemHotkeyMapTest, ParseMouse) {
76 // This plist was pulled from a real machine. It has missing entries,
77 // incomplete entries, and mouse hotkeys.
78 NSData* data = DataFromTestFile("mac/mac_system_hotkeys_sparse.plist");
79 ASSERT_TRUE(data);
80
81 NSDictionary* dictionary = SystemHotkeyMap::DictionaryFromData(data);
82 ASSERT_TRUE(dictionary);
83
84 SystemHotkeyMap map;
85 bool result = map.ParseDictionary(dictionary);
86 EXPECT_TRUE(result);
87
88 // Command + ` is a common key binding. It is missing.
89 // TODO(erikchen): OSX uses the default value when the keybinding is missing,
90 // so the hotkey should still be reserved.
91 // http://crbug.com/383558
92 unsigned short key_code = kVK_ANSI_Grave;
93 NSUInteger modifiers = NSCommandKeyMask;
94 EXPECT_FALSE(map.IsHotkeyReserved(key_code, modifiers));
95
96 // There is a mouse keybinding for 0x08. It should not apply to keyboard
97 // hotkeys.
98 key_code = kVK_ANSI_C;
99 modifiers = 0;
100 EXPECT_FALSE(map.IsHotkeyReserved(key_code, modifiers));
101
102 // Command + Alt + = is an accessibility shortcut. Its entry in the plist is
103 // incomplete.
104 // TODO(erikchen): OSX uses the default bindings, so this hotkey should still
105 // be reserved.
106 // http://crbug.com/383558
107 key_code = kVK_ANSI_Equal;
108 modifiers = NSCommandKeyMask | NSAlternateKeyMask;
109 EXPECT_FALSE(map.IsHotkeyReserved(key_code, modifiers));
110 }
111
112 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/cocoa/system_hotkey_map.mm ('k') | content/browser/renderer_host/render_widget_host_view_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698