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..14be1ae515f4148f5957b41bc5480f7e6633997a 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 |
@@ -11,24 +11,34 @@ |
#include "chrome/browser/ui/cocoa/notifications/notification_response_builder_mac.h" |
#include "testing/gtest/include/gtest/gtest.h" |
-TEST(NotificationResponseBuilderMacTest, TestNotificationClick) { |
- 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"]]; |
- [builder setNotificationId:@"notificationId"]; |
- [builder setProfileId:@"profileId"]; |
- [builder setIncognito:false]; |
- [builder |
- setNotificationType:[NSNumber |
- numberWithInt:NotificationCommon::PERSISTENT]]; |
- |
+class NotificationResponseBuilderMacTest : public testing::Test { |
+ protected: |
+ base::scoped_nsobject<NotificationBuilder> NewTestBuilder() { |
+ 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:NSImageNameApplicationIcon]]; |
+ [builder setNotificationId:@"notificationId"]; |
+ [builder setProfileId:@"profileId"]; |
+ [builder setIncognito:false]; |
+ [builder setNotificationType:@(NotificationCommon::PERSISTENT)]; |
+ return builder; |
+ } |
+}; |
+ |
+TEST_F(NotificationResponseBuilderMacTest, TestNotificationClick) { |
+ base::scoped_nsobject<NotificationBuilder> builder = NewTestBuilder(); |
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]; |
@@ -40,32 +50,14 @@ TEST(NotificationResponseBuilderMacTest, TestNotificationClick) { |
EXPECT_EQ(-1, buttonIndex.intValue); |
} |
-TEST(NotificationResponseBuilderMacTest, TestNotificationSettingsClick) { |
- 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"]]; |
- [builder setNotificationId:@"notificationId"]; |
- [builder setProfileId:@"profileId"]; |
- [builder setIncognito:false]; |
- [builder |
- setNotificationType:[NSNumber |
- numberWithInt:NotificationCommon::PERSISTENT]]; |
- |
+TEST_F(NotificationResponseBuilderMacTest, TestNotificationSettingsClick) { |
+ base::scoped_nsobject<NotificationBuilder> builder = NewTestBuilder(); |
NSUserNotification* notification = [builder buildUserNotification]; |
// 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]; |
@@ -77,33 +69,16 @@ TEST(NotificationResponseBuilderMacTest, TestNotificationSettingsClick) { |
EXPECT_EQ(-1, buttonIndex.intValue); |
} |
-TEST(NotificationResponseBuilderMacTest, TestNotificationOneActionClick) { |
- base::scoped_nsobject<NotificationBuilder> builder( |
- [[NotificationBuilder alloc] initWithCloseLabel:@"Close" |
- optionsLabel:@"Options" |
- settingsLabel:@"Settings"]); |
- [builder setTitle:@"Title"]; |
- [builder setSubTitle:@"https://www.miguel.com"]; |
- [builder setContextMessage:@""]; |
+TEST_F(NotificationResponseBuilderMacTest, TestNotificationOneActionClick) { |
+ base::scoped_nsobject<NotificationBuilder> builder = NewTestBuilder(); |
[builder setButtons:@"Button1" secondaryButton:@""]; |
- [builder setTag:@"tag1"]; |
- [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; |
- [builder setNotificationId:@"notificationId"]; |
- [builder setProfileId:@"profileId"]; |
- [builder setIncognito:false]; |
- [builder |
- setNotificationType:[NSNumber |
- numberWithInt:NotificationCommon::PERSISTENT]]; |
NSUserNotification* notification = [builder buildUserNotification]; |
// 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 = |
@@ -117,33 +92,16 @@ TEST(NotificationResponseBuilderMacTest, TestNotificationOneActionClick) { |
EXPECT_EQ(0, buttonIndex.intValue); |
} |
-TEST(NotificationResponseBuilderMacTest, TestNotificationTwoActionClick) { |
- base::scoped_nsobject<NotificationBuilder> builder( |
- [[NotificationBuilder alloc] initWithCloseLabel:@"Close" |
- optionsLabel:@"Options" |
- settingsLabel:@"Settings"]); |
- [builder setTitle:@"Title"]; |
- [builder setSubTitle:@"https://www.miguel.com"]; |
- [builder setContextMessage:@""]; |
+TEST_F(NotificationResponseBuilderMacTest, TestNotificationTwoActionClick) { |
+ base::scoped_nsobject<NotificationBuilder> builder = NewTestBuilder(); |
[builder setButtons:@"Button1" secondaryButton:@"Button2"]; |
- [builder setTag:@"tag1"]; |
- [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; |
- [builder setNotificationId:@"notificationId"]; |
- [builder setProfileId:@"profileId"]; |
- [builder setIncognito:false]; |
- [builder |
- setNotificationType:[NSNumber |
- numberWithInt:NotificationCommon::PERSISTENT]]; |
NSUserNotification* notification = [builder buildUserNotification]; |
// 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"]; |
@@ -158,25 +116,10 @@ TEST(NotificationResponseBuilderMacTest, TestNotificationTwoActionClick) { |
EXPECT_EQ(1, buttonIndex.intValue); |
} |
-TEST(NotificationResponseBuilderMacTest, |
- TestNotificationTwoActionSettingsClick) { |
- base::scoped_nsobject<NotificationBuilder> builder( |
- [[NotificationBuilder alloc] initWithCloseLabel:@"Close" |
- optionsLabel:@"Options" |
- settingsLabel:@"Settings"]); |
- [builder setTitle:@"Title"]; |
- [builder setSubTitle:@"https://www.miguel.com"]; |
- [builder setContextMessage:@""]; |
+TEST_F(NotificationResponseBuilderMacTest, |
+ TestNotificationTwoActionSettingsClick) { |
+ base::scoped_nsobject<NotificationBuilder> builder = NewTestBuilder(); |
[builder setButtons:@"Button1" secondaryButton:@"Button2"]; |
- [builder setTag:@"tag1"]; |
- [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; |
- [builder setNotificationId:@"notificationId"]; |
- [builder setProfileId:@"profileId"]; |
- [builder setIncognito:false]; |
- [builder |
- setNotificationType:[NSNumber |
- numberWithInt:NotificationCommon::PERSISTENT]]; |
- |
NSUserNotification* notification = [builder buildUserNotification]; |
// These values will be set by the notification center to indicate that button |
@@ -199,3 +142,23 @@ TEST(NotificationResponseBuilderMacTest, |
EXPECT_EQ(2 /* NOTIFICATION_SETTINGS */, operation.intValue); |
EXPECT_EQ(-1, buttonIndex.intValue); |
} |
+ |
+TEST_F(NotificationResponseBuilderMacTest, TestNotificationClose) { |
+ base::scoped_nsobject<NotificationBuilder> builder = NewTestBuilder(); |
+ 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); |
+} |