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 23f7e035a02db2829725c12cc3b1612d862f8bc7..7bb69172e4f35880f3474ada6ad082894de5d549 100644 |
--- a/chrome/browser/notifications/notification_platform_bridge_mac_unittest.mm |
+++ b/chrome/browser/notifications/notification_platform_bridge_mac_unittest.mm |
@@ -6,15 +6,16 @@ |
#import <objc/runtime.h> |
#include "base/mac/scoped_nsobject.h" |
-#import "base/mac/scoped_objc_class_swizzler.h" |
#include "base/strings/utf_string_conversions.h" |
#include "chrome/browser/notifications/notification.h" |
#include "chrome/browser/notifications/notification_platform_bridge_mac.h" |
#include "chrome/browser/notifications/notification_test_util.h" |
+#include "chrome/browser/notifications/stub_alert_dispatcher_mac.h" |
#include "chrome/browser/notifications/stub_notification_center_mac.h" |
#include "chrome/browser/ui/cocoa/notifications/notification_builder_mac.h" |
#include "chrome/browser/ui/cocoa/notifications/notification_constants_mac.h" |
#include "chrome/browser/ui/cocoa/notifications/notification_response_builder_mac.h" |
+#include "chrome/common/features.h" |
#include "testing/gtest/include/gtest/gtest.h" |
#include "testing/gtest_mac.h" |
#include "url/gurl.h" |
@@ -50,11 +51,30 @@ class NotificationPlatformBridgeMacTest : public testing::Test { |
return [builder buildUserNotification]; |
} |
+ std::unique_ptr<Notification> CreateBanner(const char* title, |
+ const char* subtitle, |
+ const char* origin, |
+ const char* button1, |
+ const char* button2) { |
+ return CreateNotification(title, subtitle, origin, button1, button2, |
+ false /* require_interaction */); |
+ } |
+ |
+ std::unique_ptr<Notification> CreateAlert(const char* title, |
+ const char* subtitle, |
+ const char* origin, |
+ const char* button1, |
+ const char* button2) { |
+ return CreateNotification(title, subtitle, origin, button1, button2, |
+ true /* require_interaction */); |
+ } |
+ |
std::unique_ptr<Notification> CreateNotification(const char* title, |
const char* subtitle, |
const char* origin, |
const char* button1, |
- const char* button2) { |
+ const char* button2, |
+ bool require_interaction) { |
message_center::RichNotificationData optional_fields; |
optional_fields.context_message = base::UTF8ToUTF16(origin); |
if (button1) { |
@@ -73,6 +93,8 @@ class NotificationPlatformBridgeMacTest : public testing::Test { |
base::UTF8ToUTF16(subtitle), gfx::Image(), |
message_center::NotifierId(url), base::UTF8ToUTF16("Notifier's Name"), |
url, "id1", optional_fields, new MockNotificationDelegate("id1"))); |
+ if (require_interaction) |
+ notification->set_never_timeout(true); |
return notification; |
} |
@@ -158,11 +180,11 @@ TEST_F(NotificationPlatformBridgeMacTest, TestNotificationVerifyOrigin) { |
} |
TEST_F(NotificationPlatformBridgeMacTest, TestDisplayNoButtons) { |
- std::unique_ptr<Notification> notification = CreateNotification( |
- "Title", "Context", "https://gmail.com", nullptr, nullptr); |
+ std::unique_ptr<Notification> notification = |
+ CreateBanner("Title", "Context", "https://gmail.com", nullptr, nullptr); |
std::unique_ptr<NotificationPlatformBridgeMac> bridge( |
- new NotificationPlatformBridgeMac(notification_center())); |
+ new NotificationPlatformBridgeMac(notification_center(), nullptr)); |
bridge->Display(NotificationCommon::PERSISTENT, "notification_id", |
"profile_id", false, *notification); |
NSArray* notifications = [notification_center() deliveredNotifications]; |
@@ -178,11 +200,11 @@ TEST_F(NotificationPlatformBridgeMacTest, TestDisplayNoButtons) { |
} |
TEST_F(NotificationPlatformBridgeMacTest, TestDisplayOneButton) { |
- std::unique_ptr<Notification> notification = CreateNotification( |
+ std::unique_ptr<Notification> notification = CreateBanner( |
"Title", "Context", "https://gmail.com", "Button 1", nullptr); |
std::unique_ptr<NotificationPlatformBridgeMac> bridge( |
- new NotificationPlatformBridgeMac(notification_center())); |
+ new NotificationPlatformBridgeMac(notification_center(), nullptr)); |
bridge->Display(NotificationCommon::PERSISTENT, "notification_id", |
"profile_id", false, *notification); |
@@ -197,11 +219,11 @@ TEST_F(NotificationPlatformBridgeMacTest, TestDisplayOneButton) { |
} |
TEST_F(NotificationPlatformBridgeMacTest, TestCloseNotification) { |
- std::unique_ptr<Notification> notification = CreateNotification( |
+ std::unique_ptr<Notification> notification = CreateBanner( |
"Title", "Context", "https://gmail.com", "Button 1", nullptr); |
std::unique_ptr<NotificationPlatformBridgeMac> bridge( |
- new NotificationPlatformBridgeMac(notification_center())); |
+ new NotificationPlatformBridgeMac(notification_center(), nullptr)); |
EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); |
bridge->Display(NotificationCommon::PERSISTENT, "notification_id", |
"profile_id", false, *notification); |
@@ -212,11 +234,11 @@ TEST_F(NotificationPlatformBridgeMacTest, TestCloseNotification) { |
} |
TEST_F(NotificationPlatformBridgeMacTest, TestCloseNonExistingNotification) { |
- std::unique_ptr<Notification> notification = CreateNotification( |
+ std::unique_ptr<Notification> notification = CreateBanner( |
"Title", "Context", "https://gmail.com", "Button 1", nullptr); |
std::unique_ptr<NotificationPlatformBridgeMac> bridge( |
- new NotificationPlatformBridgeMac(notification_center())); |
+ new NotificationPlatformBridgeMac(notification_center(), nullptr)); |
EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); |
bridge->Display(NotificationCommon::PERSISTENT, "notification_id", |
"profile_id", false, *notification); |
@@ -227,10 +249,10 @@ TEST_F(NotificationPlatformBridgeMacTest, TestCloseNonExistingNotification) { |
} |
TEST_F(NotificationPlatformBridgeMacTest, TestGetDisplayed) { |
- std::unique_ptr<Notification> notification = CreateNotification( |
+ std::unique_ptr<Notification> notification = CreateBanner( |
"Title", "Context", "https://gmail.com", "Button 1", nullptr); |
std::unique_ptr<NotificationPlatformBridgeMac> bridge( |
- new NotificationPlatformBridgeMac(notification_center())); |
+ new NotificationPlatformBridgeMac(notification_center(), nullptr)); |
EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); |
bridge->Display(NotificationCommon::PERSISTENT, "notification_id", |
"profile_id", false, *notification); |
@@ -242,10 +264,10 @@ TEST_F(NotificationPlatformBridgeMacTest, TestGetDisplayed) { |
} |
TEST_F(NotificationPlatformBridgeMacTest, TestGetDisplayedUnknownProfile) { |
- std::unique_ptr<Notification> notification = CreateNotification( |
+ std::unique_ptr<Notification> notification = CreateBanner( |
"Title", "Context", "https://gmail.com", "Button 1", nullptr); |
std::unique_ptr<NotificationPlatformBridgeMac> bridge( |
- new NotificationPlatformBridgeMac(notification_center())); |
+ new NotificationPlatformBridgeMac(notification_center(), nullptr)); |
EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); |
bridge->Display(NotificationCommon::PERSISTENT, "notification_id", |
"profile_id", false, *notification); |
@@ -258,11 +280,11 @@ TEST_F(NotificationPlatformBridgeMacTest, TestGetDisplayedUnknownProfile) { |
} |
TEST_F(NotificationPlatformBridgeMacTest, TestQuitRemovesNotifications) { |
- std::unique_ptr<Notification> notification = CreateNotification( |
+ std::unique_ptr<Notification> notification = CreateBanner( |
"Title", "Context", "https://gmail.com", "Button 1", nullptr); |
{ |
std::unique_ptr<NotificationPlatformBridgeMac> bridge( |
- new NotificationPlatformBridgeMac(notification_center())); |
+ new NotificationPlatformBridgeMac(notification_center(), nullptr)); |
EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); |
bridge->Display(NotificationCommon::PERSISTENT, "notification_id", |
"profile_id", false, *notification); |
@@ -272,3 +294,54 @@ TEST_F(NotificationPlatformBridgeMacTest, TestQuitRemovesNotifications) { |
// The destructor of the bridge should close all notifications. |
EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); |
} |
+ |
+// TODO(miguelg) There is some duplication between these tests and the ones |
+// Above. Once the flag is removed most tests can be merged. |
+#if BUILDFLAG(ENABLE_XPC_NOTIFICATIONS) |
+TEST_F(NotificationPlatformBridgeMacTest, TestDisplayAlert) { |
+ StubAlertDispatcher* alert_dispatcher = [[StubAlertDispatcher alloc] init]; |
+ std::unique_ptr<Notification> alert = |
+ CreateAlert("Title", "Context", "https://gmail.com", "Button 1", nullptr); |
+ std::unique_ptr<NotificationPlatformBridgeMac> bridge( |
+ new NotificationPlatformBridgeMac(notification_center(), |
+ alert_dispatcher)); |
+ bridge->Display(NotificationCommon::PERSISTENT, "notification_id", |
+ "profile_id", false, *alert); |
+ EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); |
+ EXPECT_EQ(1u, [[alert_dispatcher getAlerts] count]); |
+} |
+ |
+TEST_F(NotificationPlatformBridgeMacTest, TestDisplayBannerAndAlert) { |
+ StubAlertDispatcher* alert_dispatcher = [[StubAlertDispatcher alloc] init]; |
+ std::unique_ptr<Notification> alert = |
+ CreateAlert("Title", "Context", "https://gmail.com", "Button 1", nullptr); |
+ std::unique_ptr<Notification> banner = CreateBanner( |
+ "Title", "Context", "https://gmail.com", "Button 1", nullptr); |
+ std::unique_ptr<NotificationPlatformBridgeMac> bridge( |
+ new NotificationPlatformBridgeMac(notification_center(), |
+ alert_dispatcher)); |
+ bridge->Display(NotificationCommon::PERSISTENT, "notification_id", |
+ "profile_id", false, *banner); |
+ bridge->Display(NotificationCommon::PERSISTENT, "notification_id2", |
+ "profile_id", false, *alert); |
+ EXPECT_EQ(1u, [[notification_center() deliveredNotifications] count]); |
+ EXPECT_EQ(1u, [[alert_dispatcher getAlerts] count]); |
+} |
+ |
+TEST_F(NotificationPlatformBridgeMacTest, TestCloseAlert) { |
+ std::unique_ptr<Notification> alert = |
+ CreateAlert("Title", "Context", "https://gmail.com", "Button 1", nullptr); |
+ StubAlertDispatcher* alert_dispatcher = [[StubAlertDispatcher alloc] init]; |
+ std::unique_ptr<NotificationPlatformBridgeMac> bridge( |
+ new NotificationPlatformBridgeMac(notification_center(), |
+ alert_dispatcher)); |
+ EXPECT_EQ(0u, [[alert_dispatcher getAlerts] count]); |
+ bridge->Display(NotificationCommon::PERSISTENT, "notification_id", |
+ "profile_id", false, *alert); |
+ EXPECT_EQ(1u, [[alert_dispatcher getAlerts] count]); |
+ |
+ bridge->Close("profile_id", "notification_id"); |
+ EXPECT_EQ(0u, [[notification_center() deliveredNotifications] count]); |
+} |
+ |
+#endif |