Index: chrome/browser/ui/cocoa/notifications/notification_response_builder_mac_unittest.mm |
diff --git a/chrome/browser/ui/cocoa/notifications/notification_response_builder_mac_unittest.mm b/chrome/browser/ui/cocoa/notifications/notification_response_builder_mac_unittest.mm |
index 93896d3c36c0a38976a3874099ec5d90523fa680..40e4220f2cf4ed2d78b5cfcbfee759f7b17937ec 100644 |
--- a/chrome/browser/ui/cocoa/notifications/notification_response_builder_mac_unittest.mm |
+++ b/chrome/browser/ui/cocoa/notifications/notification_response_builder_mac_unittest.mm |
@@ -29,6 +29,11 @@ TEST(NotificationResponseBuilderMacTest, TestNotificationClick) { |
numberWithInt:NotificationCommon::PERSISTENT]]; |
NSUserNotification* notification = [builder buildUserNotification]; |
+ // This will be set by the notification center to indicate the notification |
+ // was clicked. |
+ [notification setValue:@(NSUserNotificationActivationTypeContentsClicked) |
+ forKey:@"_activationType"]; |
+ |
NSDictionary* response = |
[NotificationResponseBuilder buildDictionary:notification]; |
@@ -61,11 +66,8 @@ TEST(NotificationResponseBuilderMacTest, TestNotificationSettingsClick) { |
// This will be set by the notification center to indicate the only available |
// button was clicked. |
- [notification |
- setValue: |
- [NSNumber |
- numberWithInt:NSUserNotificationActivationTypeActionButtonClicked] |
- forKey:@"_activationType"]; |
+ [notification setValue:@(NSUserNotificationActivationTypeActionButtonClicked) |
+ forKey:@"_activationType"]; |
NSDictionary* response = |
[NotificationResponseBuilder buildDictionary:notification]; |
@@ -99,11 +101,8 @@ TEST(NotificationResponseBuilderMacTest, TestNotificationOneActionClick) { |
// These values will be set by the notification center to indicate that button |
// 1 was clicked. |
- [notification |
- setValue: |
- [NSNumber |
- numberWithInt:NSUserNotificationActivationTypeActionButtonClicked] |
- forKey:@"_activationType"]; |
+ [notification setValue:@(NSUserNotificationActivationTypeActionButtonClicked) |
+ forKey:@"_activationType"]; |
[notification setValue:[NSNumber numberWithInt:0] |
forKey:@"_alternateActionIndex"]; |
NSDictionary* response = |
@@ -139,11 +138,8 @@ TEST(NotificationResponseBuilderMacTest, TestNotificationTwoActionClick) { |
// These values will be set by the notification center to indicate that button |
// 2 was clicked. |
- [notification |
- setValue: |
- [NSNumber |
- numberWithInt:NSUserNotificationActivationTypeActionButtonClicked] |
- forKey:@"_activationType"]; |
+ [notification setValue:@(NSUserNotificationActivationTypeActionButtonClicked) |
+ forKey:@"_activationType"]; |
[notification setValue:[NSNumber numberWithInt:1] |
forKey:@"_alternateActionIndex"]; |
@@ -199,3 +195,37 @@ TEST(NotificationResponseBuilderMacTest, |
EXPECT_EQ(2 /* NOTIFICATION_SETTINGS */, operation.intValue); |
EXPECT_EQ(-1, buttonIndex.intValue); |
} |
+ |
+TEST(NotificationResponseBuilderMacTest, TestNotificationClose) { |
+ base::scoped_nsobject<NotificationBuilder> builder( |
+ [[NotificationBuilder alloc] initWithCloseLabel:@"Close" |
+ optionsLabel:@"Options" |
+ settingsLabel:@"Settings"]); |
+ [builder setTitle:@"Title"]; |
+ [builder setSubTitle:@"https://www.miguel.com"]; |
+ [builder setContextMessage:@""]; |
+ [builder setTag:@"tag1"]; |
+ [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
|
+ [builder setNotificationId:@"notificationId"]; |
+ [builder setProfileId:@"profileId"]; |
+ [builder setIncognito:false]; |
+ [builder |
+ setNotificationType:[NSNumber |
+ numberWithInt:NotificationCommon::PERSISTENT]]; |
Robert Sesek
2016/10/11 14:19:32
Does @() work here too?
Miguel Garcia
2016/10/12 13:14:31
Done.
|
+ |
+ NSUserNotification* notification = [builder buildUserNotification]; |
+ // None is what the NSUserNotification center emits when closing since it |
+ // interprets it as not activated. |
+ [notification setValue:@(NSUserNotificationActivationTypeNone) |
+ forKey:@"_activationType"]; |
+ |
+ NSDictionary* response = |
+ [NotificationResponseBuilder buildDictionary:notification]; |
+ |
+ NSNumber* operation = |
+ [response objectForKey:notification_constants::kNotificationOperation]; |
+ NSNumber* buttonIndex = |
+ [response objectForKey:notification_constants::kNotificationButtonIndex]; |
+ EXPECT_EQ(1 /* NOTIFICATION_CLOSE */, operation.intValue); |
+ EXPECT_EQ(-1, buttonIndex.intValue); |
+} |