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

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

Issue 965573002: Implement support for silent notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix tests Created 5 years, 9 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"
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 146
147 service()->ClosePersistentNotification(profile(), 147 service()->ClosePersistentNotification(profile(),
148 notification.delegate_id()); 148 notification.delegate_id());
149 EXPECT_EQ(0u, ui_manager()->GetNotificationCount()); 149 EXPECT_EQ(0u, ui_manager()->GetNotificationCount());
150 } 150 }
151 151
152 TEST_F(PlatformNotificationServiceTest, DisplayPageNotificationMatches) { 152 TEST_F(PlatformNotificationServiceTest, DisplayPageNotificationMatches) {
153 content::PlatformNotificationData notification_data; 153 content::PlatformNotificationData notification_data;
154 notification_data.title = base::ASCIIToUTF16("My notification's title"); 154 notification_data.title = base::ASCIIToUTF16("My notification's title");
155 notification_data.body = base::ASCIIToUTF16("Hello, world!"); 155 notification_data.body = base::ASCIIToUTF16("Hello, world!");
156 notification_data.silent = true;
156 157
157 MockDesktopNotificationDelegate* delegate 158 MockDesktopNotificationDelegate* delegate
158 = new MockDesktopNotificationDelegate(); 159 = new MockDesktopNotificationDelegate();
159 service()->DisplayNotification(profile(), 160 service()->DisplayNotification(profile(),
160 GURL("https://chrome.com/"), 161 GURL("https://chrome.com/"),
161 SkBitmap(), 162 SkBitmap(),
162 notification_data, 163 notification_data,
163 make_scoped_ptr(delegate), 164 make_scoped_ptr(delegate),
164 nullptr); 165 nullptr);
165 166
166 ASSERT_EQ(1u, ui_manager()->GetNotificationCount()); 167 ASSERT_EQ(1u, ui_manager()->GetNotificationCount());
167 168
168 const Notification& notification = ui_manager()->GetNotificationAt(0); 169 const Notification& notification = ui_manager()->GetNotificationAt(0);
169 EXPECT_EQ("https://chrome.com/", notification.origin_url().spec()); 170 EXPECT_EQ("https://chrome.com/", notification.origin_url().spec());
170 EXPECT_EQ("My notification's title", 171 EXPECT_EQ("My notification's title",
171 base::UTF16ToUTF8(notification.title())); 172 base::UTF16ToUTF8(notification.title()));
172 EXPECT_EQ("Hello, world!", 173 EXPECT_EQ("Hello, world!",
173 base::UTF16ToUTF8(notification.message())); 174 base::UTF16ToUTF8(notification.message()));
175 EXPECT_TRUE(notification.silent());
174 } 176 }
175 177
176 TEST_F(PlatformNotificationServiceTest, DisplayNameForOrigin) { 178 TEST_F(PlatformNotificationServiceTest, DisplayNameForOrigin) {
177 base::string16 display_name = 179 base::string16 display_name =
178 service()->DisplayNameForOrigin(profile(), GURL("https://chrome.com/")); 180 service()->DisplayNameForOrigin(profile(), GURL("https://chrome.com/"));
179 181
180 EXPECT_EQ(base::ASCIIToUTF16("chrome.com"), display_name); 182 EXPECT_EQ(base::ASCIIToUTF16("chrome.com"), display_name);
181 183
182 // TODO(peter): Include unit tests for the extension-name translation 184 // TODO(peter): Include unit tests for the extension-name translation
183 // functionality of DisplayNameForOriginInProcessId. 185 // functionality of DisplayNameForOriginInProcessId.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 244
243 service()->DisplayPersistentNotification( 245 service()->DisplayPersistentNotification(
244 profile(), 42 /* sw_registration_id */, origin, SkBitmap(), 246 profile(), 42 /* sw_registration_id */, origin, SkBitmap(),
245 content::PlatformNotificationData()); 247 content::PlatformNotificationData());
246 248
247 base::Time after_persistent_notification = 249 base::Time after_persistent_notification =
248 profile()->GetHostContentSettingsMap()->GetLastUsage( 250 profile()->GetHostContentSettingsMap()->GetLastUsage(
249 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); 251 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
250 EXPECT_GT(after_persistent_notification, after_page_notification); 252 EXPECT_GT(after_persistent_notification, after_page_notification);
251 } 253 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698