1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/web_test/browser/web_test_browser_context.h"
#include <memory>
#include <utility>
#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "build/build_config.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/push_messaging_service.h"
#include "content/public/browser/resource_context.h"
#include "content/public/test/mock_client_hints_controller_delegate.h"
#include "content/shell/browser/shell_content_browser_client.h"
#include "content/test/mock_background_sync_controller.h"
#include "content/test/mock_platform_notification_service.h"
#include "content/test/mock_reduce_accept_language_controller_delegate.h"
#include "content/web_test/browser/web_test_background_fetch_delegate.h"
#include "content/web_test/browser/web_test_download_manager_delegate.h"
#include "content/web_test/browser/web_test_permission_manager.h"
#include "content/web_test/browser/web_test_push_messaging_service.h"
#include "content/web_test/browser/web_test_storage_access_manager.h"
#include "services/device/public/cpp/test/scoped_geolocation_overrider.h"
#if BUILDFLAG(IS_WIN)
#include "base/base_paths_win.h"
#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#include "base/nix/xdg_util.h"
#elif BUILDFLAG(IS_MAC)
#include "base/apple/foundation_util.h"
#include "base/base_paths_mac.h"
#endif
namespace content {
WebTestBrowserContext::WebTestBrowserContext(bool off_the_record)
: ShellBrowserContext(off_the_record) {
// Configure the Geolocation API to provide no location by default.
geolocation_overrider_ = std::make_unique<device::ScopedGeolocationOverrider>(
/*position=*/nullptr);
}
WebTestBrowserContext::~WebTestBrowserContext() {
NotifyWillBeDestroyed();
}
DownloadManagerDelegate* WebTestBrowserContext::GetDownloadManagerDelegate() {
if (!download_manager_delegate_) {
download_manager_delegate_ =
std::make_unique<WebTestDownloadManagerDelegate>();
download_manager_delegate_->SetDownloadManager(GetDownloadManager());
download_manager_delegate_->SetDownloadBehaviorForTesting(
GetPath().Append(FILE_PATH_LITERAL("downloads")));
}
return download_manager_delegate_.get();
}
PlatformNotificationService*
WebTestBrowserContext::GetPlatformNotificationService() {
if (!platform_notification_service_) {
platform_notification_service_ =
std::make_unique<MockPlatformNotificationService>(this);
}
return platform_notification_service_.get();
}
PushMessagingService* WebTestBrowserContext::GetPushMessagingService() {
if (!push_messaging_service_)
push_messaging_service_ = std::make_unique<WebTestPushMessagingService>();
return push_messaging_service_.get();
}
PermissionControllerDelegate*
WebTestBrowserContext::GetPermissionControllerDelegate() {
if (!permission_manager_.get())
permission_manager_ = std::make_unique<WebTestPermissionManager>(*this);
return permission_manager_.get();
}
BackgroundFetchDelegate* WebTestBrowserContext::GetBackgroundFetchDelegate() {
if (!background_fetch_delegate_) {
background_fetch_delegate_ =
std::make_unique<WebTestBackgroundFetchDelegate>(this);
}
return background_fetch_delegate_.get();
}
BackgroundSyncController* WebTestBrowserContext::GetBackgroundSyncController() {
if (!background_sync_controller_) {
background_sync_controller_ =
std::make_unique<MockBackgroundSyncController>();
}
return background_sync_controller_.get();
}
WebTestPermissionManager* WebTestBrowserContext::GetWebTestPermissionManager() {
return static_cast<WebTestPermissionManager*>(
GetPermissionControllerDelegate());
}
WebTestStorageAccessManager*
WebTestBrowserContext::GetWebTestStorageAccessManager() {
if (!storage_access_.get())
storage_access_ = std::make_unique<WebTestStorageAccessManager>(this);
return storage_access_.get();
}
ClientHintsControllerDelegate*
WebTestBrowserContext::GetClientHintsControllerDelegate() {
if (!client_hints_controller_delegate_) {
client_hints_controller_delegate_ =
std::make_unique<content::MockClientHintsControllerDelegate>(
content::GetShellUserAgentMetadata());
}
return client_hints_controller_delegate_.get();
}
ReduceAcceptLanguageControllerDelegate*
WebTestBrowserContext::GetReduceAcceptLanguageControllerDelegate() {
if (!reduce_accept_lang_controller_delegate_) {
reduce_accept_lang_controller_delegate_ =
std::make_unique<content::MockReduceAcceptLanguageControllerDelegate>(
content::GetShellLanguage());
}
return reduce_accept_lang_controller_delegate_.get();
}
} // namespace content
|