OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #import <AppKit/AppKit.h> | 5 #import <AppKit/AppKit.h> |
6 | 6 |
7 #include "base/mac/scoped_nsobject.h" | 7 #include "base/mac/scoped_nsobject.h" |
8 #include "chrome/browser/notifications/notification_common.h" | 8 #include "chrome/browser/notifications/notification_common.h" |
9 #include "chrome/browser/ui/cocoa/notifications/notification_builder_mac.h" | 9 #include "chrome/browser/ui/cocoa/notifications/notification_builder_mac.h" |
10 #include "chrome/browser/ui/cocoa/notifications/notification_constants_mac.h" | 10 #include "chrome/browser/ui/cocoa/notifications/notification_constants_mac.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
22 [builder setTag:@"tag1"]; | 22 [builder setTag:@"tag1"]; |
23 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; | 23 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; |
24 [builder setNotificationId:@"notificationId"]; | 24 [builder setNotificationId:@"notificationId"]; |
25 [builder setProfileId:@"profileId"]; | 25 [builder setProfileId:@"profileId"]; |
26 [builder setIncognito:false]; | 26 [builder setIncognito:false]; |
27 [builder | 27 [builder |
28 setNotificationType:[NSNumber | 28 setNotificationType:[NSNumber |
29 numberWithInt:NotificationCommon::PERSISTENT]]; | 29 numberWithInt:NotificationCommon::PERSISTENT]]; |
30 | 30 |
31 NSUserNotification* notification = [builder buildUserNotification]; | 31 NSUserNotification* notification = [builder buildUserNotification]; |
32 // This will be set by the notification center to indicate the notification | |
33 // was clicked. | |
34 [notification setValue:@(NSUserNotificationActivationTypeContentsClicked) | |
35 forKey:@"_activationType"]; | |
36 | |
32 NSDictionary* response = | 37 NSDictionary* response = |
33 [NotificationResponseBuilder buildDictionary:notification]; | 38 [NotificationResponseBuilder buildDictionary:notification]; |
34 | 39 |
35 NSNumber* operation = | 40 NSNumber* operation = |
36 [response objectForKey:notification_constants::kNotificationOperation]; | 41 [response objectForKey:notification_constants::kNotificationOperation]; |
37 NSNumber* buttonIndex = | 42 NSNumber* buttonIndex = |
38 [response objectForKey:notification_constants::kNotificationButtonIndex]; | 43 [response objectForKey:notification_constants::kNotificationButtonIndex]; |
39 EXPECT_EQ(0 /* NOTIFICATION_CLICK */, operation.intValue); | 44 EXPECT_EQ(0 /* NOTIFICATION_CLICK */, operation.intValue); |
40 EXPECT_EQ(-1, buttonIndex.intValue); | 45 EXPECT_EQ(-1, buttonIndex.intValue); |
41 } | 46 } |
(...skipping 12 matching lines...) Expand all Loading... | |
54 [builder setProfileId:@"profileId"]; | 59 [builder setProfileId:@"profileId"]; |
55 [builder setIncognito:false]; | 60 [builder setIncognito:false]; |
56 [builder | 61 [builder |
57 setNotificationType:[NSNumber | 62 setNotificationType:[NSNumber |
58 numberWithInt:NotificationCommon::PERSISTENT]]; | 63 numberWithInt:NotificationCommon::PERSISTENT]]; |
59 | 64 |
60 NSUserNotification* notification = [builder buildUserNotification]; | 65 NSUserNotification* notification = [builder buildUserNotification]; |
61 | 66 |
62 // This will be set by the notification center to indicate the only available | 67 // This will be set by the notification center to indicate the only available |
63 // button was clicked. | 68 // button was clicked. |
64 [notification | 69 [notification setValue:@(NSUserNotificationActivationTypeActionButtonClicked) |
65 setValue: | 70 forKey:@"_activationType"]; |
66 [NSNumber | |
67 numberWithInt:NSUserNotificationActivationTypeActionButtonClicked] | |
68 forKey:@"_activationType"]; | |
69 NSDictionary* response = | 71 NSDictionary* response = |
70 [NotificationResponseBuilder buildDictionary:notification]; | 72 [NotificationResponseBuilder buildDictionary:notification]; |
71 | 73 |
72 NSNumber* operation = | 74 NSNumber* operation = |
73 [response objectForKey:notification_constants::kNotificationOperation]; | 75 [response objectForKey:notification_constants::kNotificationOperation]; |
74 NSNumber* buttonIndex = | 76 NSNumber* buttonIndex = |
75 [response objectForKey:notification_constants::kNotificationButtonIndex]; | 77 [response objectForKey:notification_constants::kNotificationButtonIndex]; |
76 EXPECT_EQ(2 /* NOTIFICATION_SETTINGS */, operation.intValue); | 78 EXPECT_EQ(2 /* NOTIFICATION_SETTINGS */, operation.intValue); |
77 EXPECT_EQ(-1, buttonIndex.intValue); | 79 EXPECT_EQ(-1, buttonIndex.intValue); |
78 } | 80 } |
(...skipping 13 matching lines...) Expand all Loading... | |
92 [builder setProfileId:@"profileId"]; | 94 [builder setProfileId:@"profileId"]; |
93 [builder setIncognito:false]; | 95 [builder setIncognito:false]; |
94 [builder | 96 [builder |
95 setNotificationType:[NSNumber | 97 setNotificationType:[NSNumber |
96 numberWithInt:NotificationCommon::PERSISTENT]]; | 98 numberWithInt:NotificationCommon::PERSISTENT]]; |
97 | 99 |
98 NSUserNotification* notification = [builder buildUserNotification]; | 100 NSUserNotification* notification = [builder buildUserNotification]; |
99 | 101 |
100 // These values will be set by the notification center to indicate that button | 102 // These values will be set by the notification center to indicate that button |
101 // 1 was clicked. | 103 // 1 was clicked. |
102 [notification | 104 [notification setValue:@(NSUserNotificationActivationTypeActionButtonClicked) |
103 setValue: | 105 forKey:@"_activationType"]; |
104 [NSNumber | |
105 numberWithInt:NSUserNotificationActivationTypeActionButtonClicked] | |
106 forKey:@"_activationType"]; | |
107 [notification setValue:[NSNumber numberWithInt:0] | 106 [notification setValue:[NSNumber numberWithInt:0] |
108 forKey:@"_alternateActionIndex"]; | 107 forKey:@"_alternateActionIndex"]; |
109 NSDictionary* response = | 108 NSDictionary* response = |
110 [NotificationResponseBuilder buildDictionary:notification]; | 109 [NotificationResponseBuilder buildDictionary:notification]; |
111 | 110 |
112 NSNumber* operation = | 111 NSNumber* operation = |
113 [response objectForKey:notification_constants::kNotificationOperation]; | 112 [response objectForKey:notification_constants::kNotificationOperation]; |
114 NSNumber* buttonIndex = | 113 NSNumber* buttonIndex = |
115 [response objectForKey:notification_constants::kNotificationButtonIndex]; | 114 [response objectForKey:notification_constants::kNotificationButtonIndex]; |
116 EXPECT_EQ(0 /* NOTIFICATION_CLICK */, operation.intValue); | 115 EXPECT_EQ(0 /* NOTIFICATION_CLICK */, operation.intValue); |
(...skipping 15 matching lines...) Expand all Loading... | |
132 [builder setProfileId:@"profileId"]; | 131 [builder setProfileId:@"profileId"]; |
133 [builder setIncognito:false]; | 132 [builder setIncognito:false]; |
134 [builder | 133 [builder |
135 setNotificationType:[NSNumber | 134 setNotificationType:[NSNumber |
136 numberWithInt:NotificationCommon::PERSISTENT]]; | 135 numberWithInt:NotificationCommon::PERSISTENT]]; |
137 | 136 |
138 NSUserNotification* notification = [builder buildUserNotification]; | 137 NSUserNotification* notification = [builder buildUserNotification]; |
139 | 138 |
140 // These values will be set by the notification center to indicate that button | 139 // These values will be set by the notification center to indicate that button |
141 // 2 was clicked. | 140 // 2 was clicked. |
142 [notification | 141 [notification setValue:@(NSUserNotificationActivationTypeActionButtonClicked) |
143 setValue: | 142 forKey:@"_activationType"]; |
144 [NSNumber | |
145 numberWithInt:NSUserNotificationActivationTypeActionButtonClicked] | |
146 forKey:@"_activationType"]; | |
147 [notification setValue:[NSNumber numberWithInt:1] | 143 [notification setValue:[NSNumber numberWithInt:1] |
148 forKey:@"_alternateActionIndex"]; | 144 forKey:@"_alternateActionIndex"]; |
149 | 145 |
150 NSDictionary* response = | 146 NSDictionary* response = |
151 [NotificationResponseBuilder buildDictionary:notification]; | 147 [NotificationResponseBuilder buildDictionary:notification]; |
152 | 148 |
153 NSNumber* operation = | 149 NSNumber* operation = |
154 [response objectForKey:notification_constants::kNotificationOperation]; | 150 [response objectForKey:notification_constants::kNotificationOperation]; |
155 NSNumber* buttonIndex = | 151 NSNumber* buttonIndex = |
156 [response objectForKey:notification_constants::kNotificationButtonIndex]; | 152 [response objectForKey:notification_constants::kNotificationButtonIndex]; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 NSDictionary* response = | 188 NSDictionary* response = |
193 [NotificationResponseBuilder buildDictionary:notification]; | 189 [NotificationResponseBuilder buildDictionary:notification]; |
194 | 190 |
195 NSNumber* operation = | 191 NSNumber* operation = |
196 [response objectForKey:notification_constants::kNotificationOperation]; | 192 [response objectForKey:notification_constants::kNotificationOperation]; |
197 NSNumber* buttonIndex = | 193 NSNumber* buttonIndex = |
198 [response objectForKey:notification_constants::kNotificationButtonIndex]; | 194 [response objectForKey:notification_constants::kNotificationButtonIndex]; |
199 EXPECT_EQ(2 /* NOTIFICATION_SETTINGS */, operation.intValue); | 195 EXPECT_EQ(2 /* NOTIFICATION_SETTINGS */, operation.intValue); |
200 EXPECT_EQ(-1, buttonIndex.intValue); | 196 EXPECT_EQ(-1, buttonIndex.intValue); |
201 } | 197 } |
198 | |
199 TEST(NotificationResponseBuilderMacTest, TestNotificationClose) { | |
200 base::scoped_nsobject<NotificationBuilder> builder( | |
201 [[NotificationBuilder alloc] initWithCloseLabel:@"Close" | |
202 optionsLabel:@"Options" | |
203 settingsLabel:@"Settings"]); | |
204 [builder setTitle:@"Title"]; | |
205 [builder setSubTitle:@"https://www.miguel.com"]; | |
206 [builder setContextMessage:@""]; | |
207 [builder setTag:@"tag1"]; | |
208 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; | |
Robert Sesek
2016/10/11 14:19:32
Is this non-nil in tests? I don't think unit_tests
Miguel Garcia
2016/10/12 13:14:31
Yeah this is non null in tests, I know because the
| |
209 [builder setNotificationId:@"notificationId"]; | |
210 [builder setProfileId:@"profileId"]; | |
211 [builder setIncognito:false]; | |
212 [builder | |
213 setNotificationType:[NSNumber | |
214 numberWithInt:NotificationCommon::PERSISTENT]]; | |
Robert Sesek
2016/10/11 14:19:32
Does @() work here too?
Miguel Garcia
2016/10/12 13:14:31
Done.
| |
215 | |
216 NSUserNotification* notification = [builder buildUserNotification]; | |
217 // None is what the NSUserNotification center emits when closing since it | |
218 // interprets it as not activated. | |
219 [notification setValue:@(NSUserNotificationActivationTypeNone) | |
220 forKey:@"_activationType"]; | |
221 | |
222 NSDictionary* response = | |
223 [NotificationResponseBuilder buildDictionary:notification]; | |
224 | |
225 NSNumber* operation = | |
226 [response objectForKey:notification_constants::kNotificationOperation]; | |
227 NSNumber* buttonIndex = | |
228 [response objectForKey:notification_constants::kNotificationButtonIndex]; | |
229 EXPECT_EQ(1 /* NOTIFICATION_CLOSE */, operation.intValue); | |
230 EXPECT_EQ(-1, buttonIndex.intValue); | |
231 } | |
OLD | NEW |