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

Side by Side Diff: chrome/browser/notifications/platform_notification_service_unittest.cc

Issue 1026853002: Integrate the notification database with the normal code path. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@n-db-ConfirmShow
Patch Set: delete a now invalid test Created 5 years, 8 months 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/strings/utf_string_conversions.h" 5 #include "base/strings/utf_string_conversions.h"
6 #include "base/threading/platform_thread.h" 6 #include "base/threading/platform_thread.h"
7 #include "base/time/time.h" 7 #include "base/time/time.h"
8 #include "chrome/browser/notifications/notification_test_util.h" 8 #include "chrome/browser/notifications/notification_test_util.h"
9 #include "chrome/browser/notifications/platform_notification_service_impl.h" 9 #include "chrome/browser/notifications/platform_notification_service_impl.h"
10 #include "chrome/test/base/testing_profile.h" 10 #include "chrome/test/base/testing_profile.h"
11 #include "components/content_settings/core/browser/host_content_settings_map.h" 11 #include "components/content_settings/core/browser/host_content_settings_map.h"
12 #include "content/public/browser/desktop_notification_delegate.h" 12 #include "content/public/browser/desktop_notification_delegate.h"
13 #include "content/public/common/platform_notification_data.h" 13 #include "content/public/common/platform_notification_data.h"
14 #include "content/public/test/test_browser_thread_bundle.h" 14 #include "content/public/test/test_browser_thread_bundle.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "third_party/skia/include/core/SkBitmap.h" 16 #include "third_party/skia/include/core/SkBitmap.h"
17 17
18 namespace { 18 namespace {
19 19
20 const int64_t kPersistentNotificationId = 42;
21
20 class MockDesktopNotificationDelegate 22 class MockDesktopNotificationDelegate
21 : public content::DesktopNotificationDelegate { 23 : public content::DesktopNotificationDelegate {
22 public: 24 public:
23 MockDesktopNotificationDelegate() 25 MockDesktopNotificationDelegate()
24 : displayed_(false), 26 : displayed_(false),
25 clicked_(false) {} 27 clicked_(false) {}
26 28
27 ~MockDesktopNotificationDelegate() override {} 29 ~MockDesktopNotificationDelegate() override {}
28 30
29 // content::DesktopNotificationDelegate implementation. 31 // content::DesktopNotificationDelegate implementation.
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 // Note that we cannot verify whether the closed event was called on the 127 // Note that we cannot verify whether the closed event was called on the
126 // delegate given that it'd result in a use-after-free. 128 // delegate given that it'd result in a use-after-free.
127 } 129 }
128 130
129 TEST_F(PlatformNotificationServiceTest, PersistentNotificationDisplay) { 131 TEST_F(PlatformNotificationServiceTest, PersistentNotificationDisplay) {
130 content::PlatformNotificationData notification_data; 132 content::PlatformNotificationData notification_data;
131 notification_data.title = base::ASCIIToUTF16("My notification's title"); 133 notification_data.title = base::ASCIIToUTF16("My notification's title");
132 notification_data.body = base::ASCIIToUTF16("Hello, world!"); 134 notification_data.body = base::ASCIIToUTF16("Hello, world!");
133 135
134 service()->DisplayPersistentNotification( 136 service()->DisplayPersistentNotification(
135 profile(), 42 /* sw_registration_id */, GURL("https://chrome.com/"), 137 profile(), kPersistentNotificationId, GURL("https://chrome.com/"),
136 SkBitmap(), notification_data); 138 SkBitmap(), notification_data);
137 139
138 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); 140 ASSERT_EQ(1u, ui_manager()->GetNotificationCount());
139 141
140 const Notification& notification = ui_manager()->GetNotificationAt(0); 142 const Notification& notification = ui_manager()->GetNotificationAt(0);
141 EXPECT_EQ("https://chrome.com/", notification.origin_url().spec()); 143 EXPECT_EQ("https://chrome.com/", notification.origin_url().spec());
142 EXPECT_EQ("My notification's title", 144 EXPECT_EQ("My notification's title",
143 base::UTF16ToUTF8(notification.title())); 145 base::UTF16ToUTF8(notification.title()));
144 EXPECT_EQ("Hello, world!", 146 EXPECT_EQ("Hello, world!",
145 base::UTF16ToUTF8(notification.message())); 147 base::UTF16ToUTF8(notification.message()));
146 148
147 service()->ClosePersistentNotification(profile(), 149 service()->ClosePersistentNotification(profile(), kPersistentNotificationId);
148 notification.delegate_id());
149 EXPECT_EQ(0u, ui_manager()->GetNotificationCount()); 150 EXPECT_EQ(0u, ui_manager()->GetNotificationCount());
150 } 151 }
151 152
152 TEST_F(PlatformNotificationServiceTest, DisplayPageNotificationMatches) { 153 TEST_F(PlatformNotificationServiceTest, DisplayPageNotificationMatches) {
153 content::PlatformNotificationData notification_data; 154 content::PlatformNotificationData notification_data;
154 notification_data.title = base::ASCIIToUTF16("My notification's title"); 155 notification_data.title = base::ASCIIToUTF16("My notification's title");
155 notification_data.body = base::ASCIIToUTF16("Hello, world!"); 156 notification_data.body = base::ASCIIToUTF16("Hello, world!");
156 notification_data.silent = true; 157 notification_data.silent = true;
157 158
158 MockDesktopNotificationDelegate* delegate 159 MockDesktopNotificationDelegate* delegate
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 245
245 service()->DisplayPersistentNotification( 246 service()->DisplayPersistentNotification(
246 profile(), 42 /* sw_registration_id */, origin, SkBitmap(), 247 profile(), 42 /* sw_registration_id */, origin, SkBitmap(),
247 content::PlatformNotificationData()); 248 content::PlatformNotificationData());
248 249
249 base::Time after_persistent_notification = 250 base::Time after_persistent_notification =
250 profile()->GetHostContentSettingsMap()->GetLastUsage( 251 profile()->GetHostContentSettingsMap()->GetLastUsage(
251 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); 252 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
252 EXPECT_GT(after_persistent_notification, after_page_notification); 253 EXPECT_GT(after_persistent_notification, after_page_notification);
253 } 254 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698