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 7226812a01062151b8ea43b1c390153dbb5bbcda..e79fb255c43ca15fa7ca5de431ff09530c3133a0 100644 |
--- a/chrome/browser/notifications/platform_notification_service_unittest.cc |
+++ b/chrome/browser/notifications/platform_notification_service_unittest.cc |
@@ -3,9 +3,11 @@ |
// found in the LICENSE file. |
#include "base/strings/utf_string_conversions.h" |
+#include "base/time/time.h" |
#include "chrome/browser/notifications/notification_test_util.h" |
#include "chrome/browser/notifications/platform_notification_service_impl.h" |
#include "chrome/test/base/testing_profile.h" |
+#include "components/content_settings/core/browser/host_content_settings_map.h" |
#include "content/public/browser/desktop_notification_delegate.h" |
#include "content/public/test/test_browser_thread_bundle.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -65,7 +67,7 @@ class PlatformNotificationServiceTest : public testing::Test { |
MockDesktopNotificationDelegate* CreateSimplePageNotificationWithCloseClosure( |
base::Closure* close_closure) const { |
content::ShowDesktopNotificationHostMsgParams params; |
- params.origin = GURL("https://example.com/"); |
+ params.origin = GURL("https://chrome.com/"); |
params.title = base::ASCIIToUTF16("My Notification"); |
params.body = base::ASCIIToUTF16("Hello, world!"); |
@@ -121,6 +123,31 @@ TEST_F(PlatformNotificationServiceTest, DisplayPageCloseClosure) { |
// delegate given that it'd result in a use-after-free. |
} |
+TEST_F(PlatformNotificationServiceTest, PersistentNotificationDisplay) { |
+ content::ShowDesktopNotificationHostMsgParams params; |
+ params.origin = GURL("https://chrome.com/"); |
+ params.title = base::ASCIIToUTF16("My notification's title"); |
+ params.body = base::ASCIIToUTF16("Hello, world!"); |
+ |
+ service()->DisplayPersistentNotification(profile(), |
+ 42 /* sw_registration_id */, |
+ params, |
+ 0 /* render_process_id */); |
+ |
+ ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); |
+ |
+ const Notification& notification = ui_manager()->GetNotificationAt(0); |
+ EXPECT_EQ("https://chrome.com/", notification.origin_url().spec()); |
+ EXPECT_EQ("My notification's title", |
+ base::UTF16ToUTF8(notification.title())); |
+ EXPECT_EQ("Hello, world!", |
+ base::UTF16ToUTF8(notification.message())); |
+ |
+ service()->ClosePersistentNotification(profile(), |
+ notification.delegate_id()); |
+ EXPECT_EQ(0u, ui_manager()->GetNotificationCount()); |
+} |
+ |
TEST_F(PlatformNotificationServiceTest, DisplayPageNotificationMatches) { |
content::ShowDesktopNotificationHostMsgParams params; |
params.origin = GURL("https://chrome.com/"); |
@@ -156,3 +183,30 @@ TEST_F(PlatformNotificationServiceTest, DisplayNameForOrigin) { |
// TODO(peter): Include unit tests for the extension-name translation |
// functionality of DisplayNameForOriginInProcessId. |
} |
+ |
+TEST_F(PlatformNotificationServiceTest, NotificationPermissionLastUsage) { |
+ // Both page and persistent notifications should update the last usage |
+ // time of the notification permission for the origin. |
+ GURL origin("https://chrome.com/"); |
+ base::Time begin_time; |
+ |
+ CreateSimplePageNotification(); |
+ |
+ base::Time after_page_notification = |
+ profile()->GetHostContentSettingsMap()->GetLastUsage( |
+ origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
+ EXPECT_GT(after_page_notification, begin_time); |
+ |
+ content::ShowDesktopNotificationHostMsgParams params; |
+ params.origin = origin; |
+ |
+ service()->DisplayPersistentNotification(profile(), |
+ 42 /* sw_registration_id */, |
+ params, |
+ 0 /* render_process_id */); |
+ |
+ base::Time after_persistent_notification = |
+ profile()->GetHostContentSettingsMap()->GetLastUsage( |
+ origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
+ EXPECT_GT(after_persistent_notification, after_page_notification); |
+} |