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

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

Issue 2151993002: [WebAPKs] Plumb service worker scope to notifications (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge branch 'master' into notification_scope Created 4 years, 5 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 192
193 // TODO(peter): Re-enable this test when //content is responsible for creating 193 // TODO(peter): Re-enable this test when //content is responsible for creating
194 // the notification delegate ids. 194 // the notification delegate ids.
195 #if !defined(OS_ANDROID) 195 #if !defined(OS_ANDROID)
196 TEST_F(PlatformNotificationServiceTest, PersistentNotificationDisplay) { 196 TEST_F(PlatformNotificationServiceTest, PersistentNotificationDisplay) {
197 PlatformNotificationData notification_data; 197 PlatformNotificationData notification_data;
198 notification_data.title = base::ASCIIToUTF16("My notification's title"); 198 notification_data.title = base::ASCIIToUTF16("My notification's title");
199 notification_data.body = base::ASCIIToUTF16("Hello, world!"); 199 notification_data.body = base::ASCIIToUTF16("Hello, world!");
200 200
201 service()->DisplayPersistentNotification( 201 service()->DisplayPersistentNotification(
202 profile(), kPersistentNotificationId, GURL("https://chrome.com/"), 202 profile(), kPersistentNotificationId, GURL() /* service_worker_scope */,
203 notification_data, NotificationResources()); 203 GURL("https://chrome.com/"), notification_data, NotificationResources());
204 204
205 ASSERT_EQ(1u, GetNotificationCount()); 205 ASSERT_EQ(1u, GetNotificationCount());
206 206
207 Notification notification = GetDisplayedNotification(); 207 Notification notification = GetDisplayedNotification();
208 EXPECT_EQ("https://chrome.com/", notification.origin_url().spec()); 208 EXPECT_EQ("https://chrome.com/", notification.origin_url().spec());
209 EXPECT_EQ("My notification's title", 209 EXPECT_EQ("My notification's title",
210 base::UTF16ToUTF8(notification.title())); 210 base::UTF16ToUTF8(notification.title()));
211 EXPECT_EQ("Hello, world!", 211 EXPECT_EQ("Hello, world!",
212 base::UTF16ToUTF8(notification.message())); 212 base::UTF16ToUTF8(notification.message()));
213 213
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 notification_data.vibration_pattern = vibration_pattern; 259 notification_data.vibration_pattern = vibration_pattern;
260 notification_data.silent = true; 260 notification_data.silent = true;
261 notification_data.actions.resize(2); 261 notification_data.actions.resize(2);
262 notification_data.actions[0].title = base::ASCIIToUTF16("Button 1"); 262 notification_data.actions[0].title = base::ASCIIToUTF16("Button 1");
263 notification_data.actions[1].title = base::ASCIIToUTF16("Button 2"); 263 notification_data.actions[1].title = base::ASCIIToUTF16("Button 2");
264 264
265 NotificationResources notification_resources; 265 NotificationResources notification_resources;
266 notification_resources.action_icons.resize(notification_data.actions.size()); 266 notification_resources.action_icons.resize(notification_data.actions.size());
267 267
268 service()->DisplayPersistentNotification( 268 service()->DisplayPersistentNotification(
269 profile(), 0u /* persistent notification */, GURL("https://chrome.com/"), 269 profile(), 0u /* persistent notification */,
270 GURL() /* service_worker_scope */, GURL("https://chrome.com/"),
270 notification_data, notification_resources); 271 notification_data, notification_resources);
271 272
272 ASSERT_EQ(1u, GetNotificationCount()); 273 ASSERT_EQ(1u, GetNotificationCount());
273 274
274 Notification notification = GetDisplayedNotification(); 275 Notification notification = GetDisplayedNotification();
275 EXPECT_EQ("https://chrome.com/", notification.origin_url().spec()); 276 EXPECT_EQ("https://chrome.com/", notification.origin_url().spec());
276 EXPECT_EQ("My notification's title", base::UTF16ToUTF8(notification.title())); 277 EXPECT_EQ("My notification's title", base::UTF16ToUTF8(notification.title()));
277 EXPECT_EQ("Hello, world!", base::UTF16ToUTF8(notification.message())); 278 EXPECT_EQ("Hello, world!", base::UTF16ToUTF8(notification.message()));
278 279
279 EXPECT_THAT(notification.vibration_pattern(), 280 EXPECT_THAT(notification.vibration_pattern(),
(...skipping 17 matching lines...) Expand all
297 298
298 base::Time after_page_notification = 299 base::Time after_page_notification =
299 HostContentSettingsMapFactory::GetForProfile(profile())->GetLastUsage( 300 HostContentSettingsMapFactory::GetForProfile(profile())->GetLastUsage(
300 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); 301 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
301 EXPECT_GT(after_page_notification, begin_time); 302 EXPECT_GT(after_page_notification, begin_time);
302 303
303 // Ensure that there is at least some time between the two calls. 304 // Ensure that there is at least some time between the two calls.
304 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1)); 305 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1));
305 306
306 service()->DisplayPersistentNotification( 307 service()->DisplayPersistentNotification(
307 profile(), 42 /* sw_registration_id */, origin, 308 profile(), 42 /* sw_registration_id */, GURL() /* service_worker_scope */,
308 PlatformNotificationData(), NotificationResources()); 309 origin, PlatformNotificationData(), NotificationResources());
309 310
310 base::Time after_persistent_notification = 311 base::Time after_persistent_notification =
311 HostContentSettingsMapFactory::GetForProfile(profile())->GetLastUsage( 312 HostContentSettingsMapFactory::GetForProfile(profile())->GetLastUsage(
312 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); 313 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
313 EXPECT_GT(after_persistent_notification, after_page_notification); 314 EXPECT_GT(after_persistent_notification, after_page_notification);
314 } 315 }
315 316
316 #if defined(ENABLE_EXTENSIONS) 317 #if defined(ENABLE_EXTENSIONS)
317 318
318 TEST_F(PlatformNotificationServiceTest, DisplayNameForContextMessage) { 319 TEST_F(PlatformNotificationServiceTest, DisplayNameForContextMessage) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 extension->url(), 401 extension->url(),
401 kFakeRenderProcessId)); 402 kFakeRenderProcessId));
402 } 403 }
403 404
404 TEST_F(PlatformNotificationServiceTest, CreateNotificationFromData) { 405 TEST_F(PlatformNotificationServiceTest, CreateNotificationFromData) {
405 PlatformNotificationData notification_data; 406 PlatformNotificationData notification_data;
406 notification_data.title = base::ASCIIToUTF16("My Notification"); 407 notification_data.title = base::ASCIIToUTF16("My Notification");
407 notification_data.body = base::ASCIIToUTF16("Hello, world!"); 408 notification_data.body = base::ASCIIToUTF16("Hello, world!");
408 409
409 Notification notification = service()->CreateNotificationFromData( 410 Notification notification = service()->CreateNotificationFromData(
410 profile(), GURL("https://chrome.com/"), notification_data, 411 profile(), GURL() /* service_worker_scope */, GURL("https://chrome.com/"),
411 NotificationResources(), new MockNotificationDelegate("hello")); 412 notification_data, NotificationResources(),
413 new MockNotificationDelegate("hello"));
412 EXPECT_TRUE(notification.context_message().empty()); 414 EXPECT_TRUE(notification.context_message().empty());
413 415
414 // Create a mocked extension. 416 // Create a mocked extension.
415 scoped_refptr<extensions::Extension> extension = 417 scoped_refptr<extensions::Extension> extension =
416 extensions::ExtensionBuilder() 418 extensions::ExtensionBuilder()
417 .SetID("honijodknafkokifofgiaalefdiedpko") 419 .SetID("honijodknafkokifofgiaalefdiedpko")
418 .SetManifest(extensions::DictionaryBuilder() 420 .SetManifest(extensions::DictionaryBuilder()
419 .Set("name", "NotificationTest") 421 .Set("name", "NotificationTest")
420 .Set("version", "1.0") 422 .Set("version", "1.0")
421 .Set("manifest_version", 2) 423 .Set("manifest_version", 2)
422 .Set("description", "Test Extension") 424 .Set("description", "Test Extension")
423 .Build()) 425 .Build())
424 .Build(); 426 .Build();
425 427
426 extensions::ExtensionRegistry* registry = 428 extensions::ExtensionRegistry* registry =
427 extensions::ExtensionRegistry::Get(profile()); 429 extensions::ExtensionRegistry::Get(profile());
428 EXPECT_TRUE(registry->AddEnabled(extension)); 430 EXPECT_TRUE(registry->AddEnabled(extension));
429 431
430 notification = service()->CreateNotificationFromData( 432 notification = service()->CreateNotificationFromData(
431 profile(), 433 profile(),
434 GURL() /* service_worker_scope */,
432 GURL("chrome-extension://honijodknafkokifofgiaalefdiedpko/main.html"), 435 GURL("chrome-extension://honijodknafkokifofgiaalefdiedpko/main.html"),
433 notification_data, NotificationResources(), 436 notification_data, NotificationResources(),
434 new MockNotificationDelegate("hello")); 437 new MockNotificationDelegate("hello"));
435 EXPECT_EQ("NotificationTest", 438 EXPECT_EQ("NotificationTest",
436 base::UTF16ToUTF8(notification.context_message())); 439 base::UTF16ToUTF8(notification.context_message()));
437 } 440 }
438 441
439 #endif // defined(ENABLE_EXTENSIONS) 442 #endif // defined(ENABLE_EXTENSIONS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698