| 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" |
| 20 #include "chrome/browser/notifications/notification_display_service_factory.h" | 21 #include "chrome/browser/notifications/notification_display_service_factory.h" |
| 21 #include "chrome/browser/notifications/notification_test_util.h" | 22 #include "chrome/browser/notifications/notification_test_util.h" |
| 22 #include "chrome/browser/notifications/platform_notification_service_impl.h" | 23 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
| 23 #include "chrome/browser/notifications/stub_notification_platform_bridge.h" | 24 #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/"); | |
| 355 | 354 |
| 356 Notification notification = service()->CreateNotificationFromData( | 355 Notification notification = service()->CreateNotificationFromData( |
| 357 profile(), GURL() /* service_worker_scope */, origin, notification_data, | 356 profile(), GURL() /* service_worker_scope */, GURL("https://chrome.com/"), |
| 358 NotificationResources(), | 357 notification_data, NotificationResources(), |
| 359 new WebNotificationDelegate(NotificationCommon::PERSISTENT, profile(), | 358 new NativeNotificationDelegate("hello")); |
| 360 "id", origin)); | |
| 361 EXPECT_TRUE(notification.context_message().empty()); | 359 EXPECT_TRUE(notification.context_message().empty()); |
| 362 | 360 |
| 363 // Create a mocked extension. | 361 // Create a mocked extension. |
| 364 scoped_refptr<extensions::Extension> extension = | 362 scoped_refptr<extensions::Extension> extension = |
| 365 extensions::ExtensionBuilder() | 363 extensions::ExtensionBuilder() |
| 366 .SetID("honijodknafkokifofgiaalefdiedpko") | 364 .SetID("honijodknafkokifofgiaalefdiedpko") |
| 367 .SetManifest(extensions::DictionaryBuilder() | 365 .SetManifest(extensions::DictionaryBuilder() |
| 368 .Set("name", "NotificationTest") | 366 .Set("name", "NotificationTest") |
| 369 .Set("version", "1.0") | 367 .Set("version", "1.0") |
| 370 .Set("manifest_version", 2) | 368 .Set("manifest_version", 2) |
| 371 .Set("description", "Test Extension") | 369 .Set("description", "Test Extension") |
| 372 .Build()) | 370 .Build()) |
| 373 .Build(); | 371 .Build(); |
| 374 | 372 |
| 375 extensions::ExtensionRegistry* registry = | 373 extensions::ExtensionRegistry* registry = |
| 376 extensions::ExtensionRegistry::Get(profile()); | 374 extensions::ExtensionRegistry::Get(profile()); |
| 377 EXPECT_TRUE(registry->AddEnabled(extension)); | 375 EXPECT_TRUE(registry->AddEnabled(extension)); |
| 378 | 376 |
| 379 notification = service()->CreateNotificationFromData( | 377 notification = service()->CreateNotificationFromData( |
| 380 profile(), GURL() /* service_worker_scope */, | 378 profile(), GURL() /* service_worker_scope */, |
| 381 GURL("chrome-extension://honijodknafkokifofgiaalefdiedpko/main.html"), | 379 GURL("chrome-extension://honijodknafkokifofgiaalefdiedpko/main.html"), |
| 382 notification_data, NotificationResources(), | 380 notification_data, NotificationResources(), |
| 383 new WebNotificationDelegate(NotificationCommon::EXTENSION, profile(), | 381 new NativeNotificationDelegate("hello")); |
| 384 "id", origin)); | |
| 385 EXPECT_EQ("NotificationTest", | 382 EXPECT_EQ("NotificationTest", |
| 386 base::UTF16ToUTF8(notification.context_message())); | 383 base::UTF16ToUTF8(notification.context_message())); |
| 387 } | 384 } |
| 388 | 385 |
| 389 #endif // BUILDFLAG(ENABLE_EXTENSIONS) | 386 #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
| OLD | NEW |