blob: e63c13aa58c6d35592b79bfce66db6eb519085b1 (
plain)
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// An implementation of BrowserProcess for unit tests that fails for most
// services. By preventing creation of services, we reduce dependencies and
// keep the profile clean. Clients of this class must handle the NULL return
// value, however.
#ifndef CHROME_TEST_BASE_TESTING_BROWSER_PROCESS_H_
#define CHROME_TEST_BASE_TESTING_BROWSER_PROCESS_H_
#include <stdint.h>
#include <string>
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_platform_part.h"
class BackgroundModeManager;
class CRLSetFetcher;
class IOThread;
class MHTMLGenerationManager;
class NotificationUIManager;
class PrefService;
class WatchDogThread;
namespace content {
class NotificationService;
}
namespace extensions {
class ExtensionsBrowserClient;
}
namespace gcm {
class GCMDriver;
}
namespace policy {
class BrowserPolicyConnector;
class PolicyService;
}
class TestingBrowserProcess : public BrowserProcess {
public:
// Initializes |g_browser_process| with a new TestingBrowserProcess.
static void CreateInstance();
// Cleanly destroys |g_browser_process|, which has special deletion semantics.
static void DeleteInstance();
// Convenience method to get g_browser_process as a TestingBrowserProcess*.
static TestingBrowserProcess* GetGlobal();
// BrowserProcess overrides:
void ResourceDispatcherHostCreated() override;
void EndSession() override;
metrics_services_manager::MetricsServicesManager* GetMetricsServicesManager()
override;
metrics::MetricsService* metrics_service() override;
rappor::RapporService* rappor_service() override;
IOThread* io_thread() override;
WatchDogThread* watchdog_thread() override;
ProfileManager* profile_manager() override;
PrefService* local_state() override;
variations::VariationsService* variations_service() override;
web_resource::PromoResourceService* promo_resource_service() override;
policy::BrowserPolicyConnector* browser_policy_connector() override;
policy::PolicyService* policy_service() override;
IconManager* icon_manager() override;
GLStringManager* gl_string_manager() override;
GpuModeManager* gpu_mode_manager() override;
BackgroundModeManager* background_mode_manager() override;
void set_background_mode_manager_for_test(
scoped_ptr<BackgroundModeManager> manager) override;
StatusTray* status_tray() override;
safe_browsing::SafeBrowsingService* safe_browsing_service() override;
safe_browsing::ClientSideDetectionService* safe_browsing_detection_service()
override;
net::URLRequestContextGetter* system_request_context() override;
BrowserProcessPlatformPart* platform_part() override;
extensions::EventRouterForwarder* extension_event_router_forwarder() override;
NotificationUIManager* notification_ui_manager() override;
message_center::MessageCenter* message_center() override;
IntranetRedirectDetector* intranet_redirect_detector() override;
void CreateDevToolsHttpProtocolHandler(
chrome::HostDesktopType host_desktop_type,
const std::string& ip,
uint16_t port) override;
unsigned int AddRefModule() override;
unsigned int ReleaseModule() override;
bool IsShuttingDown() override;
printing::PrintJobManager* print_job_manager() override;
printing::PrintPreviewDialogController* print_preview_dialog_controller()
override;
printing::BackgroundPrintingManager* background_printing_manager() override;
const std::string& GetApplicationLocale() override;
void SetApplicationLocale(const std::string& app_locale) override;
DownloadStatusUpdater* download_status_updater() override;
DownloadRequestLimiter* download_request_limiter() override;
#if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
void StartAutoupdateTimer() override {}
#endif
net_log::ChromeNetLog* net_log() override;
component_updater::ComponentUpdateService* component_updater() override;
CRLSetFetcher* crl_set_fetcher() override;
component_updater::PnaclComponentInstaller* pnacl_component_installer()
override;
component_updater::SupervisedUserWhitelistInstaller*
supervised_user_whitelist_installer() override;
MediaFileSystemRegistry* media_file_system_registry() override;
bool created_local_state() const override;
#if defined(ENABLE_WEBRTC)
WebRtcLogUploader* webrtc_log_uploader() override;
#endif
network_time::NetworkTimeTracker* network_time_tracker() override;
gcm::GCMDriver* gcm_driver() override;
memory::TabManager* GetTabManager() override;
ShellIntegration::DefaultWebClientState CachedDefaultWebClientState()
override;
// Set the local state for tests. Consumer is responsible for cleaning it up
// afterwards (using ScopedTestingLocalState, for example).
void SetLocalState(PrefService* local_state);
void SetProfileManager(ProfileManager* profile_manager);
void SetIOThread(IOThread* io_thread);
void SetSafeBrowsingService(safe_browsing::SafeBrowsingService* sb_service);
void SetSystemRequestContext(net::URLRequestContextGetter* context_getter);
void SetNotificationUIManager(
scoped_ptr<NotificationUIManager> notification_ui_manager);
void ShutdownBrowserPolicyConnector();
private:
// See CreateInstance() and DestoryInstance() above.
TestingBrowserProcess();
~TestingBrowserProcess() override;
scoped_ptr<content::NotificationService> notification_service_;
unsigned int module_ref_count_;
std::string app_locale_;
// TODO(ios): Add back members as more code is compiled.
#if !defined(OS_IOS)
#if defined(ENABLE_CONFIGURATION_POLICY)
scoped_ptr<policy::BrowserPolicyConnector> browser_policy_connector_;
bool created_browser_policy_connector_ = false;
#else
scoped_ptr<policy::PolicyService> policy_service_;
#endif
scoped_ptr<ProfileManager> profile_manager_;
scoped_ptr<NotificationUIManager> notification_ui_manager_;
#if defined(ENABLE_PRINTING)
scoped_ptr<printing::PrintJobManager> print_job_manager_;
#endif
#if defined(ENABLE_PRINT_PREVIEW)
scoped_ptr<printing::BackgroundPrintingManager> background_printing_manager_;
scoped_refptr<printing::PrintPreviewDialogController>
print_preview_dialog_controller_;
#endif
scoped_refptr<safe_browsing::SafeBrowsingService> sb_service_;
#endif // !defined(OS_IOS)
scoped_ptr<network_time::NetworkTimeTracker> network_time_tracker_;
// The following objects are not owned by TestingBrowserProcess:
PrefService* local_state_;
IOThread* io_thread_;
net::URLRequestContextGetter* system_request_context_;
scoped_ptr<BrowserProcessPlatformPart> platform_part_;
#if defined(ENABLE_EXTENSIONS)
scoped_ptr<MediaFileSystemRegistry> media_file_system_registry_;
scoped_ptr<extensions::ExtensionsBrowserClient> extensions_browser_client_;
#endif
DISALLOW_COPY_AND_ASSIGN(TestingBrowserProcess);
};
// RAII (resource acquisition is initialization) for TestingBrowserProcess.
// Allows you to initialize TestingBrowserProcess/NotificationService before
// other member variables.
//
// This can be helpful if you are running a unit test inside the browser_tests
// suite because browser_tests do not make a TestingBrowserProcess for you.
//
// class MyUnitTestRunningAsBrowserTest : public testing::Test {
// ...stuff...
// private:
// TestingBrowserProcessInitializer initializer_;
// LocalState local_state_; // Needs a BrowserProcess to initialize.
// NotificationRegistrar registar_; // Needs NotificationService.
// };
class TestingBrowserProcessInitializer {
public:
TestingBrowserProcessInitializer();
~TestingBrowserProcessInitializer();
private:
DISALLOW_COPY_AND_ASSIGN(TestingBrowserProcessInitializer);
};
#endif // CHROME_TEST_BASE_TESTING_BROWSER_PROCESS_H_
|