| OLD | NEW |
| 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/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/feature_list.h" | 10 #include "base/feature_list.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/threading/platform_thread.h" | 15 #include "base/threading/platform_thread.h" |
| 16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 18 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 18 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 19 #include "chrome/browser/notifications/message_center_display_service.h" | 19 #include "chrome/browser/notifications/message_center_display_service.h" |
| 20 #include "chrome/browser/notifications/native_notification_delegate.h" | |
| 21 #include "chrome/browser/notifications/notification_display_service_factory.h" | 20 #include "chrome/browser/notifications/notification_display_service_factory.h" |
| 22 #include "chrome/browser/notifications/notification_test_util.h" | 21 #include "chrome/browser/notifications/notification_test_util.h" |
| 23 #include "chrome/browser/notifications/platform_notification_service_impl.h" | 22 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
| 24 #include "chrome/browser/notifications/stub_notification_platform_bridge.h" | 23 #include "chrome/browser/notifications/stub_notification_platform_bridge.h" |
| 24 #include "chrome/browser/notifications/web_notification_delegate.h" |
| 25 #include "chrome/common/chrome_features.h" | 25 #include "chrome/common/chrome_features.h" |
| 26 #include "chrome/test/base/testing_browser_process.h" | 26 #include "chrome/test/base/testing_browser_process.h" |
| 27 #include "chrome/test/base/testing_profile.h" | 27 #include "chrome/test/base/testing_profile.h" |
| 28 #include "chrome/test/base/testing_profile_manager.h" | 28 #include "chrome/test/base/testing_profile_manager.h" |
| 29 #include "components/content_settings/core/browser/host_content_settings_map.h" | 29 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 30 #include "content/public/common/notification_resources.h" | 30 #include "content/public/common/notification_resources.h" |
| 31 #include "content/public/common/platform_notification_data.h" | 31 #include "content/public/common/platform_notification_data.h" |
| 32 #include "content/public/test/test_browser_thread_bundle.h" | 32 #include "content/public/test/test_browser_thread_bundle.h" |
| 33 #include "extensions/features/features.h" | 33 #include "extensions/features/features.h" |
| 34 #include "testing/gmock/include/gmock/gmock.h" | 34 #include "testing/gmock/include/gmock/gmock.h" |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 EXPECT_EQ(blink::mojom::PermissionStatus::GRANTED, | 344 EXPECT_EQ(blink::mojom::PermissionStatus::GRANTED, |
| 345 service()->CheckPermissionOnUIThread(profile(), | 345 service()->CheckPermissionOnUIThread(profile(), |
| 346 extension->url(), | 346 extension->url(), |
| 347 kFakeRenderProcessId)); | 347 kFakeRenderProcessId)); |
| 348 } | 348 } |
| 349 | 349 |
| 350 TEST_F(PlatformNotificationServiceTest, CreateNotificationFromData) { | 350 TEST_F(PlatformNotificationServiceTest, CreateNotificationFromData) { |
| 351 PlatformNotificationData notification_data; | 351 PlatformNotificationData notification_data; |
| 352 notification_data.title = base::ASCIIToUTF16("My Notification"); | 352 notification_data.title = base::ASCIIToUTF16("My Notification"); |
| 353 notification_data.body = base::ASCIIToUTF16("Hello, world!"); | 353 notification_data.body = base::ASCIIToUTF16("Hello, world!"); |
| 354 GURL origin("https://chrome.com/"); |
| 354 | 355 |
| 355 Notification notification = service()->CreateNotificationFromData( | 356 Notification notification = service()->CreateNotificationFromData( |
| 356 profile(), GURL() /* service_worker_scope */, GURL("https://chrome.com/"), | 357 profile(), GURL() /* service_worker_scope */, origin, notification_data, |
| 357 notification_data, NotificationResources(), | 358 NotificationResources(), |
| 358 new NativeNotificationDelegate("hello")); | 359 new WebNotificationDelegate(NotificationCommon::PERSISTENT, profile(), |
| 360 "id", origin)); |
| 359 EXPECT_TRUE(notification.context_message().empty()); | 361 EXPECT_TRUE(notification.context_message().empty()); |
| 360 | 362 |
| 361 // Create a mocked extension. | 363 // Create a mocked extension. |
| 362 scoped_refptr<extensions::Extension> extension = | 364 scoped_refptr<extensions::Extension> extension = |
| 363 extensions::ExtensionBuilder() | 365 extensions::ExtensionBuilder() |
| 364 .SetID("honijodknafkokifofgiaalefdiedpko") | 366 .SetID("honijodknafkokifofgiaalefdiedpko") |
| 365 .SetManifest(extensions::DictionaryBuilder() | 367 .SetManifest(extensions::DictionaryBuilder() |
| 366 .Set("name", "NotificationTest") | 368 .Set("name", "NotificationTest") |
| 367 .Set("version", "1.0") | 369 .Set("version", "1.0") |
| 368 .Set("manifest_version", 2) | 370 .Set("manifest_version", 2) |
| 369 .Set("description", "Test Extension") | 371 .Set("description", "Test Extension") |
| 370 .Build()) | 372 .Build()) |
| 371 .Build(); | 373 .Build(); |
| 372 | 374 |
| 373 extensions::ExtensionRegistry* registry = | 375 extensions::ExtensionRegistry* registry = |
| 374 extensions::ExtensionRegistry::Get(profile()); | 376 extensions::ExtensionRegistry::Get(profile()); |
| 375 EXPECT_TRUE(registry->AddEnabled(extension)); | 377 EXPECT_TRUE(registry->AddEnabled(extension)); |
| 376 | 378 |
| 377 notification = service()->CreateNotificationFromData( | 379 notification = service()->CreateNotificationFromData( |
| 378 profile(), GURL() /* service_worker_scope */, | 380 profile(), GURL() /* service_worker_scope */, |
| 379 GURL("chrome-extension://honijodknafkokifofgiaalefdiedpko/main.html"), | 381 GURL("chrome-extension://honijodknafkokifofgiaalefdiedpko/main.html"), |
| 380 notification_data, NotificationResources(), | 382 notification_data, NotificationResources(), |
| 381 new NativeNotificationDelegate("hello")); | 383 new WebNotificationDelegate(NotificationCommon::EXTENSION, profile(), |
| 384 "id", origin)); |
| 382 EXPECT_EQ("NotificationTest", | 385 EXPECT_EQ("NotificationTest", |
| 383 base::UTF16ToUTF8(notification.context_message())); | 386 base::UTF16ToUTF8(notification.context_message())); |
| 384 } | 387 } |
| 385 | 388 |
| 386 #endif // BUILDFLAG(ENABLE_EXTENSIONS) | 389 #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
| OLD | NEW |