Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1787)

Unified Diff: chrome/browser/notifications/platform_notification_service_unittest.cc

Issue 2534443002: Use notification display service to collect persistent notifications. (Closed)
Patch Set: add extra test checks Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/notifications/platform_notification_service_unittest.cc
diff --git a/chrome/browser/notifications/platform_notification_service_unittest.cc b/chrome/browser/notifications/platform_notification_service_unittest.cc
index 8ca62641ad7d84271c4596ecd3745cda9258a478..e263683a06ef1b0807cac41c20ae90f85d263060 100644
--- a/chrome/browser/notifications/platform_notification_service_unittest.cc
+++ b/chrome/browser/notifications/platform_notification_service_unittest.cc
@@ -55,7 +55,8 @@ using content::PlatformNotificationData;
namespace {
-const char kNotificationId[] = "my-notification-id";
+const char kPersistentNotificationId[] = "p:my-notification-id";
+const char kNonPersistentNotificationId[] = "n:my-notification-id";
const int kNotificationVibrationPattern[] = { 100, 200, 300 };
class MockDesktopNotificationDelegate
@@ -126,7 +127,7 @@ class PlatformNotificationServiceTest : public testing::Test {
MockDesktopNotificationDelegate* delegate =
new MockDesktopNotificationDelegate();
- service()->DisplayNotification(profile(), kNotificationId,
+ service()->DisplayNotification(profile(), kNonPersistentNotificationId,
GURL("https://chrome.com/"),
notification_data, NotificationResources(),
base::WrapUnique(delegate), close_closure);
@@ -197,7 +198,7 @@ TEST_F(PlatformNotificationServiceTest, PersistentNotificationDisplay) {
notification_data.body = base::ASCIIToUTF16("Hello, world!");
service()->DisplayPersistentNotification(
- profile(), kNotificationId, GURL() /* service_worker_scope */,
+ profile(), kPersistentNotificationId, GURL() /* service_worker_scope */,
GURL("https://chrome.com/"), notification_data, NotificationResources());
ASSERT_EQ(1u, GetNotificationCount());
@@ -209,7 +210,7 @@ TEST_F(PlatformNotificationServiceTest, PersistentNotificationDisplay) {
EXPECT_EQ("Hello, world!",
base::UTF16ToUTF8(notification.message()));
- service()->ClosePersistentNotification(profile(), kNotificationId);
+ service()->ClosePersistentNotification(profile(), kPersistentNotificationId);
EXPECT_EQ(0u, GetNotificationCount());
}
@@ -226,7 +227,7 @@ TEST_F(PlatformNotificationServiceTest, DisplayPageNotificationMatches) {
MockDesktopNotificationDelegate* delegate
= new MockDesktopNotificationDelegate();
- service()->DisplayNotification(profile(), kNotificationId,
+ service()->DisplayNotification(profile(), kNonPersistentNotificationId,
GURL("https://chrome.com/"), notification_data,
NotificationResources(),
base::WrapUnique(delegate), nullptr);
@@ -268,7 +269,7 @@ TEST_F(PlatformNotificationServiceTest, DisplayPersistentNotificationMatches) {
notification_resources.action_icons.resize(notification_data.actions.size());
service()->DisplayPersistentNotification(
- profile(), kNotificationId, GURL() /* service_worker_scope */,
+ profile(), kPersistentNotificationId, GURL() /* service_worker_scope */,
GURL("https://chrome.com/"), notification_data, notification_resources);
ASSERT_EQ(1u, GetNotificationCount());
@@ -308,8 +309,8 @@ TEST_F(PlatformNotificationServiceTest, NotificationPermissionLastUsage) {
base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1));
service()->DisplayPersistentNotification(
- profile(), kNotificationId, GURL() /* service_worker_scope */, origin,
- PlatformNotificationData(), NotificationResources());
+ profile(), kPersistentNotificationId, GURL() /* service_worker_scope */,
+ origin, PlatformNotificationData(), NotificationResources());
base::Time after_persistent_notification =
HostContentSettingsMapFactory::GetForProfile(profile())->GetLastUsage(
@@ -442,4 +443,30 @@ TEST_F(PlatformNotificationServiceTest, CreateNotificationFromData) {
base::UTF16ToUTF8(notification.context_message()));
}
+TEST_F(PlatformNotificationServiceTest, GetDisplayedPersistentNotifications) {
+ PlatformNotificationData notification_data;
+ notification_data.title =
+ base::ASCIIToUTF16("Non Persistent notification's title");
+ notification_data.body = base::ASCIIToUTF16("Hello, world!");
+
+ MockDesktopNotificationDelegate* delegate =
+ new MockDesktopNotificationDelegate();
+ service()->DisplayNotification(profile(), kNonPersistentNotificationId,
+ GURL("https://chrome.com/"), notification_data,
+ NotificationResources(),
+ base::WrapUnique(delegate), nullptr);
+
+ notification_data.title =
+ base::ASCIIToUTF16("Persistent notification's title");
+ service()->DisplayPersistentNotification(
+ profile(), kPersistentNotificationId, GURL() /* service_worker_scope */,
+ GURL("https://chrome.com/"), notification_data, NotificationResources());
+ ASSERT_EQ(2u, GetNotificationCount());
+
+ std::set<std::string> displayed_notifications;
+ ASSERT_TRUE(service()->GetDisplayedPersistentNotifications(
+ profile(), &displayed_notifications));
+ EXPECT_EQ(1u, displayed_notifications.size());
+}
+
#endif // BUILDFLAG(ENABLE_EXTENSIONS)

Powered by Google App Engine
This is Rietveld 408576698