| 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/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/threading/platform_thread.h" | 12 #include "base/threading/platform_thread.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 15 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 16 #include "chrome/browser/notifications/message_center_display_service.h" | 16 #include "chrome/browser/notifications/message_center_display_service.h" |
| 17 #include "chrome/browser/notifications/notification_delegate.h" | 17 #include "chrome/browser/notifications/notification_delegate.h" |
| 18 #include "chrome/browser/notifications/notification_display_service_factory.h" | 18 #include "chrome/browser/notifications/notification_display_service_factory.h" |
| 19 #include "chrome/browser/notifications/notification_test_util.h" | 19 #include "chrome/browser/notifications/notification_test_util.h" |
| 20 #include "chrome/browser/notifications/platform_notification_service_impl.h" | 20 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
| 21 #include "chrome/browser/notifications/stub_notification_platform_bridge.h" | 21 #include "chrome/browser/notifications/stub_notification_platform_bridge.h" |
| 22 #include "chrome/test/base/testing_browser_process.h" | 22 #include "chrome/test/base/testing_browser_process.h" |
| 23 #include "chrome/test/base/testing_profile.h" | 23 #include "chrome/test/base/testing_profile.h" |
| 24 #include "chrome/test/base/testing_profile_manager.h" | 24 #include "chrome/test/base/testing_profile_manager.h" |
| 25 #include "components/content_settings/core/browser/host_content_settings_map.h" | 25 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 26 #include "components/permissions/permission_status.mojom.h" | |
| 27 #include "content/public/browser/desktop_notification_delegate.h" | 26 #include "content/public/browser/desktop_notification_delegate.h" |
| 28 #include "content/public/common/notification_resources.h" | 27 #include "content/public/common/notification_resources.h" |
| 29 #include "content/public/common/platform_notification_data.h" | 28 #include "content/public/common/platform_notification_data.h" |
| 30 #include "content/public/test/test_browser_thread_bundle.h" | 29 #include "content/public/test/test_browser_thread_bundle.h" |
| 31 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
| 32 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 32 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat
us.mojom.h" |
| 33 | 33 |
| 34 #if defined(ENABLE_EXTENSIONS) | 34 #if defined(ENABLE_EXTENSIONS) |
| 35 #include "base/command_line.h" | 35 #include "base/command_line.h" |
| 36 #include "chrome/browser/extensions/extension_service.h" | 36 #include "chrome/browser/extensions/extension_service.h" |
| 37 #include "chrome/browser/extensions/test_extension_system.h" | 37 #include "chrome/browser/extensions/test_extension_system.h" |
| 38 #include "extensions/browser/extension_registry.h" | 38 #include "extensions/browser/extension_registry.h" |
| 39 #include "extensions/browser/process_map.h" | 39 #include "extensions/browser/process_map.h" |
| 40 #include "extensions/common/extension.h" | 40 #include "extensions/common/extension.h" |
| 41 #include "extensions/common/extension_builder.h" | 41 #include "extensions/common/extension_builder.h" |
| 42 #include "extensions/common/permissions/api_permission.h" | 42 #include "extensions/common/permissions/api_permission.h" |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 const int kFakeRenderProcessId = 42; | 388 const int kFakeRenderProcessId = 42; |
| 389 | 389 |
| 390 // Mock that the extension is running in a fake render process id. | 390 // Mock that the extension is running in a fake render process id. |
| 391 extensions::ProcessMap::Get(profile())->Insert(extension->id(), | 391 extensions::ProcessMap::Get(profile())->Insert(extension->id(), |
| 392 kFakeRenderProcessId, | 392 kFakeRenderProcessId, |
| 393 -1 /* site_instance_id */); | 393 -1 /* site_instance_id */); |
| 394 | 394 |
| 395 // Verify that the service indicates that permission has been granted. We only | 395 // Verify that the service indicates that permission has been granted. We only |
| 396 // check the UI thread-method for now, as that's the one guarding the behavior | 396 // check the UI thread-method for now, as that's the one guarding the behavior |
| 397 // in the browser process. | 397 // in the browser process. |
| 398 EXPECT_EQ(permissions::mojom::PermissionStatus::GRANTED, | 398 EXPECT_EQ(blink::mojom::PermissionStatus::GRANTED, |
| 399 service()->CheckPermissionOnUIThread(profile(), extension->url(), | 399 service()->CheckPermissionOnUIThread(profile(), |
| 400 extension->url(), |
| 400 kFakeRenderProcessId)); | 401 kFakeRenderProcessId)); |
| 401 } | 402 } |
| 402 | 403 |
| 403 TEST_F(PlatformNotificationServiceTest, CreateNotificationFromData) { | 404 TEST_F(PlatformNotificationServiceTest, CreateNotificationFromData) { |
| 404 PlatformNotificationData notification_data; | 405 PlatformNotificationData notification_data; |
| 405 notification_data.title = base::ASCIIToUTF16("My Notification"); | 406 notification_data.title = base::ASCIIToUTF16("My Notification"); |
| 406 notification_data.body = base::ASCIIToUTF16("Hello, world!"); | 407 notification_data.body = base::ASCIIToUTF16("Hello, world!"); |
| 407 | 408 |
| 408 Notification notification = service()->CreateNotificationFromData( | 409 Notification notification = service()->CreateNotificationFromData( |
| 409 profile(), GURL("https://chrome.com/"), notification_data, | 410 profile(), GURL("https://chrome.com/"), notification_data, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 429 notification = service()->CreateNotificationFromData( | 430 notification = service()->CreateNotificationFromData( |
| 430 profile(), | 431 profile(), |
| 431 GURL("chrome-extension://honijodknafkokifofgiaalefdiedpko/main.html"), | 432 GURL("chrome-extension://honijodknafkokifofgiaalefdiedpko/main.html"), |
| 432 notification_data, NotificationResources(), | 433 notification_data, NotificationResources(), |
| 433 new MockNotificationDelegate("hello")); | 434 new MockNotificationDelegate("hello")); |
| 434 EXPECT_EQ("NotificationTest", | 435 EXPECT_EQ("NotificationTest", |
| 435 base::UTF16ToUTF8(notification.context_message())); | 436 base::UTF16ToUTF8(notification.context_message())); |
| 436 } | 437 } |
| 437 | 438 |
| 438 #endif // defined(ENABLE_EXTENSIONS) | 439 #endif // defined(ENABLE_EXTENSIONS) |
| OLD | NEW |