Index: chrome/browser/notifications/notification_platform_bridge_mac_unittest.mm |
diff --git a/chrome/browser/notifications/notification_platform_bridge_mac_unittest.mm b/chrome/browser/notifications/notification_platform_bridge_mac_unittest.mm |
index b7db856d82f532b62cd69d3d0df86ff3b539d9f2..da9e9f415aca52b1d888a8635d71f84de6dd3532 100644 |
--- a/chrome/browser/notifications/notification_platform_bridge_mac_unittest.mm |
+++ b/chrome/browser/notifications/notification_platform_bridge_mac_unittest.mm |
@@ -19,6 +19,30 @@ |
#include "testing/gtest_mac.h" |
#include "url/gurl.h" |
+namespace { |
+ |
+NSUserNotification* BuildNotification() { |
+ base::scoped_nsobject<NotificationBuilder> builder( |
+ [[NotificationBuilder alloc] initWithCloseLabel:@"Close" |
+ optionsLabel:@"Options" |
+ settingsLabel:@"Settings"]); |
+ [builder setTitle:@"Title"]; |
+ [builder setSubTitle:@"https://www.miguel.com"]; |
+ [builder setOrigin:@"https://www.miguel.com/"]; |
+ [builder setContextMessage:@""]; |
+ [builder setButtons:@"Button1" secondaryButton:@"Button2"]; |
+ [builder setTag:@"tag1"]; |
+ [builder setIcon:[NSImage imageNamed:@"NSApplicationIcon"]]; |
+ [builder setNotificationId:@"notification_id"]; |
+ [builder setProfileId:@"profile_id"]; |
+ [builder setIncognito:false]; |
+ [builder setNotificationType:@(NotificationCommon::PERSISTENT)]; |
+ |
+ return [builder buildUserNotification]; |
+} |
+ |
+} // namespace |
+ |
class NotificationPlatformBridgeMacTest : public CocoaTest { |
protected: |
std::unique_ptr<Notification> CreateNotification(const char* title, |
@@ -49,28 +73,9 @@ class NotificationPlatformBridgeMacTest : public CocoaTest { |
} |
NSMutableDictionary* BuildDefaultNotificationResponse() { |
- base::scoped_nsobject<NotificationBuilder> builder( |
- [[NotificationBuilder alloc] initWithCloseLabel:@"Close" |
- optionsLabel:@"Options" |
- settingsLabel:@"Settings"]); |
- [builder setTitle:@"Title"]; |
- [builder setSubTitle:@"https://www.miguel.com"]; |
- [builder setOrigin:@"https://www.miguel.com/"]; |
- [builder setContextMessage:@""]; |
- [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]; |
return [NSMutableDictionary |
dictionaryWithDictionary:[NotificationResponseBuilder |
- buildDictionary:notification]]; |
+ buildDictionary:BuildNotification()]]; |
} |
}; |
@@ -177,6 +182,21 @@ TEST_F(NotificationPlatformBridgeMacTest, TestNotificationVerifyOrigin) { |
EXPECT_NSEQ(@"Options", [notification actionButtonTitle]); |
} |
+- (NSArray*)expectationsDeliveredNotification { |
+ return @[ BuildNotification() ]; |
+} |
+ |
+- (void)expectationsRemoveDeliveredNotification: |
+ (NSUserNotification*)notification { |
+ EXPECT_NSEQ(@"Title", [notification title]); |
+ EXPECT_NSEQ(@"notification_id", |
+ [notification.userInfo |
+ objectForKey:notification_constants::kNotificationId]); |
+ EXPECT_NSEQ(@"profile_id", |
+ [notification.userInfo |
+ objectForKey:notification_constants::kNotificationProfileId]); |
+} |
+ |
@end |
TEST_F(NotificationPlatformBridgeMacTest, TestDisplayNoButtons) { |
@@ -207,3 +227,19 @@ TEST_F(NotificationPlatformBridgeMacTest, TestDisplayOneButton) { |
bridge->Display(NotificationCommon::PERSISTENT, "notification_id", |
"profile_id", false, *notification); |
} |
+ |
+TEST_F(NotificationPlatformBridgeMacTest, TestCloseNotification) { |
+ base::scoped_nsobject<NSUserNotificationCenter> notification_center( |
+ [NSUserNotificationCenter _centerForIdentifier:@"" type:0x0]); |
+ |
+ base::mac::ScopedObjCClassSwizzler delivered_notifications_swizzler( |
+ [notification_center class], @selector(deliveredNotifications), |
+ @selector(expectationsDeliveredNotification)); |
+ base::mac::ScopedObjCClassSwizzler remove_delivered_notification_swizzler( |
+ [notification_center class], @selector(removeDeliveredNotification:), |
+ @selector(expectationsRemoveDeliveredNotification:)); |
+ |
+ std::unique_ptr<NotificationPlatformBridgeMac> bridge( |
+ new NotificationPlatformBridgeMac(notification_center)); |
+ bridge->Close("profile_id", "notification_id"); |
+} |