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 | |
35 setValue:[NSNumber numberWithInt: | |
36 NSUserNotificationActivationTypeContentsClicked] | |
Robert Sesek
2016/10/05 20:33:32
You should be able to just use @(NSUserNotificatio
Miguel Garcia
2016/10/05 21:58:37
Ah great, changed in all the tests.
| |
37 forKey:@"_activationType"]; | |
38 | |
32 NSDictionary* response = | 39 NSDictionary* response = |
33 [NotificationResponseBuilder buildDictionary:notification]; | 40 [NotificationResponseBuilder buildDictionary:notification]; |
34 | 41 |
35 NSNumber* operation = | 42 NSNumber* operation = |
36 [response objectForKey:notification_constants::kNotificationOperation]; | 43 [response objectForKey:notification_constants::kNotificationOperation]; |
37 NSNumber* buttonIndex = | 44 NSNumber* buttonIndex = |
38 [response objectForKey:notification_constants::kNotificationButtonIndex]; | 45 [response objectForKey:notification_constants::kNotificationButtonIndex]; |
39 EXPECT_EQ(0 /* NOTIFICATION_CLICK */, operation.intValue); | 46 EXPECT_EQ(0 /* NOTIFICATION_CLICK */, operation.intValue); |
40 EXPECT_EQ(-1, buttonIndex.intValue); | 47 EXPECT_EQ(-1, buttonIndex.intValue); |
41 } | 48 } |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 NSDictionary* response = | 199 NSDictionary* response = |
193 [NotificationResponseBuilder buildDictionary:notification]; | 200 [NotificationResponseBuilder buildDictionary:notification]; |
194 | 201 |
195 NSNumber* operation = | 202 NSNumber* operation = |
196 [response objectForKey:notification_constants::kNotificationOperation]; | 203 [response objectForKey:notification_constants::kNotificationOperation]; |
197 NSNumber* buttonIndex = | 204 NSNumber* buttonIndex = |
198 [response objectForKey:notification_constants::kNotificationButtonIndex]; | 205 [response objectForKey:notification_constants::kNotificationButtonIndex]; |
199 EXPECT_EQ(2 /* NOTIFICATION_SETTINGS */, operation.intValue); | 206 EXPECT_EQ(2 /* NOTIFICATION_SETTINGS */, operation.intValue); |
200 EXPECT_EQ(-1, buttonIndex.intValue); | 207 EXPECT_EQ(-1, buttonIndex.intValue); |
201 } | 208 } |
209 | |
210 TEST(NotificationResponseBuilderMacTest, TestNotificationClose) { | |
211 base::scoped_nsobject<NotificationBuilder> builder( | |
212 [[NotificationBuilder alloc] initWithCloseLabel:@"Close" | |
213 optionsLabel:@"Options" | |
214 settingsLabel:@"Settings"]); | |
215 [builder setTitle:@"Title"]; | |
216 [builder setSubTitle:@"https://www.miguel.com"]; | |
217 [builder setContextMessage:@""]; | |
218 [builder setTag:@"tag1"]; | |
219 [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; | |
220 [builder setNotificationId:@"notificationId"]; | |
221 [builder setProfileId:@"profileId"]; | |
222 [builder setIncognito:false]; | |
223 [builder | |
224 setNotificationType:[NSNumber | |
225 numberWithInt:NotificationCommon::PERSISTENT]]; | |
226 | |
227 NSUserNotification* notification = [builder buildUserNotification]; | |
228 // None is what the NSUserNotification center emits when closing since it | |
229 // interprets it as not activated. | |
230 [notification | |
231 setValue:[NSNumber numberWithInt:NSUserNotificationActivationTypeNone] | |
232 forKey:@"_activationType"]; | |
233 | |
234 NSDictionary* response = | |
235 [NotificationResponseBuilder buildDictionary:notification]; | |
236 | |
237 NSNumber* operation = | |
238 [response objectForKey:notification_constants::kNotificationOperation]; | |
239 NSNumber* buttonIndex = | |
240 [response objectForKey:notification_constants::kNotificationButtonIndex]; | |
241 EXPECT_EQ(1 /* NOTIFICATION_CLOSE */, operation.intValue); | |
242 EXPECT_EQ(-1, buttonIndex.intValue); | |
243 } | |
OLD | NEW |