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..600ee2c38f28ccc887fb05337850f23e685b2f25 100644 |
--- a/chrome/browser/notifications/notification_platform_bridge_mac_unittest.mm |
+++ b/chrome/browser/notifications/notification_platform_bridge_mac_unittest.mm |
@@ -19,6 +19,32 @@ |
#include "testing/gtest_mac.h" |
#include "url/gurl.h" |
+namespace { |
+ |
+NSUserNotification* BuildNotification() { |
Robert Sesek
2016/10/19 18:22:49
This could be on NotificationPlatformBridgeMacTest
Miguel Garcia
2016/10/20 10:24:45
Acknowledged.
|
+ 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]]; |
Robert Sesek
2016/10/19 18:22:49
Does @() work ?
Miguel Garcia
2016/10/20 10:24:45
Done.
|
+ |
+ return [builder buildUserNotification]; |
+} |
+ |
+} // namespace |
+ |
class NotificationPlatformBridgeMacTest : public CocoaTest { |
protected: |
std::unique_ptr<Notification> CreateNotification(const char* title, |
@@ -49,28 +75,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 +184,21 @@ TEST_F(NotificationPlatformBridgeMacTest, TestNotificationVerifyOrigin) { |
EXPECT_NSEQ(@"Options", [notification actionButtonTitle]); |
} |
+- (NSArray<NSUserNotification*>*)expectationsDeliveredNotification { |
+ return @[ BuildNotification() ]; |
+} |
+ |
+- (void)expectationsRemoveDeliveredNotification: |
+ (NSUserNotification*)notification { |
+ EXPECT_NSEQ(@"Title", [notification title]); |
+ EXPECT_NSEQ(@"notificationId", |
+ [notification.userInfo |
+ objectForKey:notification_constants::kNotificationId]); |
+ EXPECT_NSEQ(@"profileId", |
+ [notification.userInfo |
+ objectForKey:notification_constants::kNotificationProfileId]); |
+} |
+ |
@end |
TEST_F(NotificationPlatformBridgeMacTest, TestDisplayNoButtons) { |
@@ -207,3 +229,18 @@ 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 swizzler1( |
+ [notification_center class], @selector(deliveredNotifications), |
+ @selector(expectationsDeliveredNotification)); |
+ base::mac::ScopedObjCClassSwizzler swizzler2( |
Miguel Garcia
2016/10/17 14:17:43
This is needed because base::mac::ScopedObjCClassS
Peter Beverloo
2016/10/17 14:27:14
My only comment is that they could have more descr
Robert Sesek
2016/10/19 18:22:49
I think this is fine, since hopefully it'll be tem
Miguel Garcia
2016/10/20 10:24:45
SG going with that then
Miguel Garcia
2016/10/20 10:24:45
renamed
On 2016/10/17 14:27:14, Peter Beverloo wr
|
+ [notification_center class], @selector(removeDeliveredNotification:), |
+ @selector(expectationsRemoveDeliveredNotification:)); |
+ |
+ std::unique_ptr<NotificationPlatformBridgeMac> bridge( |
+ new NotificationPlatformBridgeMac(notification_center)); |
Peter Beverloo
2016/10/17 14:27:14
auto bridge = base::MakeUnique<NotificationPlatfor
Miguel Garcia
2016/10/20 10:24:45
Acknowledged.
|
+ bridge->Close("profileId", "notificationId"); |
Peter Beverloo
2016/10/17 14:27:14
You're using profile_id and notification_id elsewh
Miguel Garcia
2016/10/20 10:24:45
Done.
|
+} |