| Index: content/test/mock_platform_notification_service.cc
|
| diff --git a/content/shell/browser/layout_test/layout_test_notification_manager.cc b/content/test/mock_platform_notification_service.cc
|
| similarity index 77%
|
| copy from content/shell/browser/layout_test/layout_test_notification_manager.cc
|
| copy to content/test/mock_platform_notification_service.cc
|
| index cfac368b75d264ebd9f7f0608687652ad95e0180..f1fa04a43f06c0b9fd7c66836f0b9e2550cbc739 100644
|
| --- a/content/shell/browser/layout_test/layout_test_notification_manager.cc
|
| +++ b/content/test/mock_platform_notification_service.cc
|
| @@ -2,7 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "content/shell/browser/layout_test/layout_test_notification_manager.h"
|
| +#include "content/test/mock_platform_notification_service.h"
|
|
|
| #include "base/guid.h"
|
| #include "base/strings/nullable_string16.h"
|
| @@ -13,9 +13,6 @@
|
| #include "content/public/browser/permission_type.h"
|
| #include "content/public/common/persistent_notification_status.h"
|
| #include "content/public/common/platform_notification_data.h"
|
| -#include "content/shell/browser/layout_test/layout_test_browser_context.h"
|
| -#include "content/shell/browser/layout_test/layout_test_content_browser_client.h"
|
| -#include "content/shell/browser/layout_test/layout_test_permission_manager.h"
|
|
|
| namespace content {
|
| namespace {
|
| @@ -26,12 +23,12 @@ void OnEventDispatchComplete(PersistentNotificationStatus status) {}
|
|
|
| } // namespace
|
|
|
| -LayoutTestNotificationManager::LayoutTestNotificationManager()
|
| +MockPlatformNotificationService::MockPlatformNotificationService()
|
| : weak_factory_(this) {}
|
|
|
| -LayoutTestNotificationManager::~LayoutTestNotificationManager() {}
|
| +MockPlatformNotificationService::~MockPlatformNotificationService() {}
|
|
|
| -void LayoutTestNotificationManager::DisplayNotification(
|
| +void MockPlatformNotificationService::DisplayNotification(
|
| BrowserContext* browser_context,
|
| const std::string& notification_id,
|
| const GURL& origin,
|
| @@ -42,7 +39,7 @@ void LayoutTestNotificationManager::DisplayNotification(
|
| DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| DCHECK(cancel_callback);
|
|
|
| - *cancel_callback = base::Bind(&LayoutTestNotificationManager::Close,
|
| + *cancel_callback = base::Bind(&MockPlatformNotificationService::Close,
|
| weak_factory_.GetWeakPtr(), notification_id);
|
|
|
| ReplaceNotificationIfNeeded(notification_id);
|
| @@ -54,7 +51,7 @@ void LayoutTestNotificationManager::DisplayNotification(
|
| notification_id;
|
| }
|
|
|
| -void LayoutTestNotificationManager::DisplayPersistentNotification(
|
| +void MockPlatformNotificationService::DisplayPersistentNotification(
|
| BrowserContext* browser_context,
|
| const std::string& notification_id,
|
| const GURL& service_worker_scope,
|
| @@ -75,7 +72,7 @@ void LayoutTestNotificationManager::DisplayPersistentNotification(
|
| notification_id;
|
| }
|
|
|
| -void LayoutTestNotificationManager::ClosePersistentNotification(
|
| +void MockPlatformNotificationService::ClosePersistentNotification(
|
| BrowserContext* browser_context,
|
| const std::string& notification_id) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| @@ -83,17 +80,19 @@ void LayoutTestNotificationManager::ClosePersistentNotification(
|
| persistent_notifications_.erase(notification_id);
|
| }
|
|
|
| -bool LayoutTestNotificationManager::GetDisplayedNotifications(
|
| +bool MockPlatformNotificationService::GetDisplayedNotifications(
|
| BrowserContext* browser_context,
|
| std::set<std::string>* displayed_notifications) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| DCHECK(displayed_notifications);
|
|
|
| - // Notifications will never outlive the lifetime of running layout tests.
|
| - return false;
|
| + for (const auto& kv : persistent_notifications_)
|
| + displayed_notifications->insert(kv.first);
|
| +
|
| + return true;
|
| }
|
|
|
| -void LayoutTestNotificationManager::SimulateClick(
|
| +void MockPlatformNotificationService::SimulateClick(
|
| const std::string& title,
|
| int action_index,
|
| const base::NullableString16& reply) {
|
| @@ -125,8 +124,8 @@ void LayoutTestNotificationManager::SimulateClick(
|
| }
|
| }
|
|
|
| -void LayoutTestNotificationManager::SimulateClose(const std::string& title,
|
| - bool by_user) {
|
| +void MockPlatformNotificationService::SimulateClose(const std::string& title,
|
| + bool by_user) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
|
|
| const auto notification_id_iter = notification_id_map_.find(title);
|
| @@ -147,7 +146,7 @@ void LayoutTestNotificationManager::SimulateClose(const std::string& title,
|
| }
|
|
|
| blink::mojom::PermissionStatus
|
| -LayoutTestNotificationManager::CheckPermissionOnUIThread(
|
| +MockPlatformNotificationService::CheckPermissionOnUIThread(
|
| BrowserContext* browser_context,
|
| const GURL& origin,
|
| int render_process_id) {
|
| @@ -156,7 +155,7 @@ LayoutTestNotificationManager::CheckPermissionOnUIThread(
|
| }
|
|
|
| blink::mojom::PermissionStatus
|
| -LayoutTestNotificationManager::CheckPermissionOnIOThread(
|
| +MockPlatformNotificationService::CheckPermissionOnIOThread(
|
| ResourceContext* resource_context,
|
| const GURL& origin,
|
| int render_process_id) {
|
| @@ -164,7 +163,8 @@ LayoutTestNotificationManager::CheckPermissionOnIOThread(
|
| return CheckPermission(origin);
|
| }
|
|
|
| -void LayoutTestNotificationManager::Close(const std::string& notification_id) {
|
| +void MockPlatformNotificationService::Close(
|
| + const std::string& notification_id) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| auto iterator = non_persistent_notifications_.find(notification_id);
|
| if (iterator == non_persistent_notifications_.end())
|
| @@ -173,7 +173,7 @@ void LayoutTestNotificationManager::Close(const std::string& notification_id) {
|
| iterator->second->NotificationClosed();
|
| }
|
|
|
| -void LayoutTestNotificationManager::ReplaceNotificationIfNeeded(
|
| +void MockPlatformNotificationService::ReplaceNotificationIfNeeded(
|
| const std::string& notification_id) {
|
| const auto persistent_iter = persistent_notifications_.find(notification_id);
|
| const auto non_persistent_iter =
|
| @@ -188,14 +188,9 @@ void LayoutTestNotificationManager::ReplaceNotificationIfNeeded(
|
| }
|
| }
|
|
|
| -blink::mojom::PermissionStatus
|
| -LayoutTestNotificationManager::CheckPermission(const GURL& origin) {
|
| - return LayoutTestContentBrowserClient::Get()
|
| - ->GetLayoutTestBrowserContext()
|
| - ->GetLayoutTestPermissionManager()
|
| - ->GetPermissionStatus(PermissionType::NOTIFICATIONS,
|
| - origin,
|
| - origin);
|
| +blink::mojom::PermissionStatus MockPlatformNotificationService::CheckPermission(
|
| + const GURL& origin) {
|
| + return blink::mojom::PermissionStatus::GRANTED;
|
| }
|
|
|
| } // namespace content
|
|
|