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..4144121d670c8cb7b192edcc23f30b477c99906c 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,38 @@ |
#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( |
+@interface TestBuilder : NSObject |
++ (NotificationBuilder*)newTestBuilder; |
+@end |
+ |
+@implementation TestBuilder |
++ (NotificationBuilder*)newTestBuilder { |
Robert Sesek
2016/10/12 15:34:30
Splitting this out makes sense, but because ObjC i
Robert Sesek
2016/10/12 15:34:30
This can return a scoped_nsobject<> too.
Miguel Garcia
2016/10/13 15:17:35
Done.
Miguel Garcia
2016/10/13 15:17:35
Switched to a protected method in NotificationResp
|
+ NotificationBuilder* builder = |
[[NotificationBuilder alloc] initWithCloseLabel:@"Close" |
optionsLabel:@"Options" |
- settingsLabel:@"Settings"]); |
+ settingsLabel:@"Settings"]; |
[builder setTitle:@"Title"]; |
[builder setSubTitle:@"https://www.miguel.com"]; |
[builder setContextMessage:@""]; |
[builder setTag:@"tag1"]; |
- [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; |
+ [builder setIcon:[NSImage imageNamed:NSImageNameApplicationIcon]]; |
[builder setNotificationId:@"notificationId"]; |
[builder setProfileId:@"profileId"]; |
[builder setIncognito:false]; |
- [builder |
- setNotificationType:[NSNumber |
- numberWithInt:NotificationCommon::PERSISTENT]]; |
+ [builder setNotificationType:@(NotificationCommon::PERSISTENT)]; |
+ return builder; |
+} |
+@end |
+TEST(NotificationResponseBuilderMacTest, TestNotificationClick) { |
+ base::scoped_nsobject<NotificationBuilder> builder( |
+ [TestBuilder 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]; |
@@ -49,23 +63,18 @@ TEST(NotificationResponseBuilderMacTest, TestNotificationSettingsClick) { |
[builder setSubTitle:@"https://www.miguel.com"]; |
[builder setContextMessage:@""]; |
[builder setTag:@"tag1"]; |
- [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; |
+ [builder setIcon:[NSImage imageNamed:NSImageNameApplicationIcon]]; |
[builder setNotificationId:@"notificationId"]; |
[builder setProfileId:@"profileId"]; |
[builder setIncognito:false]; |
- [builder |
- setNotificationType:[NSNumber |
- numberWithInt:NotificationCommon::PERSISTENT]]; |
+ [builder setNotificationType:@(NotificationCommon::PERSISTENT)]; |
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]; |
@@ -79,31 +88,15 @@ TEST(NotificationResponseBuilderMacTest, TestNotificationSettingsClick) { |
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:@""]; |
+ [TestBuilder 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 = |
@@ -119,31 +112,15 @@ TEST(NotificationResponseBuilderMacTest, TestNotificationOneActionClick) { |
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:@""]; |
+ [TestBuilder 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"]; |
@@ -161,22 +138,8 @@ TEST(NotificationResponseBuilderMacTest, TestNotificationTwoActionClick) { |
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:@""]; |
+ [TestBuilder 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 +162,24 @@ TEST(NotificationResponseBuilderMacTest, |
EXPECT_EQ(2 /* NOTIFICATION_SETTINGS */, operation.intValue); |
EXPECT_EQ(-1, buttonIndex.intValue); |
} |
+ |
+TEST(NotificationResponseBuilderMacTest, TestNotificationClose) { |
+ base::scoped_nsobject<NotificationBuilder> builder( |
+ [TestBuilder 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); |
+} |