1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // An implementation of BrowserProcess for unit tests that fails for most
6 // services. By preventing creation of services, we reduce dependencies and
7 // keep the profile clean. Clients of this class must handle the NULL return
10 #ifndef CHROME_TEST_BASE_TESTING_BROWSER_PROCESS_H_
11 #define CHROME_TEST_BASE_TESTING_BROWSER_PROCESS_H_
15 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "build/build_config.h"
18 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/browser_process_platform_part.h"
21 class BackgroundModeManager
;
24 class MHTMLGenerationManager
;
25 class NotificationUIManager
;
30 class NotificationService
;
33 namespace extensions
{
34 class ExtensionsBrowserClient
;
42 class BrowserPolicyConnector
;
46 class TestingBrowserProcess
: public BrowserProcess
{
48 // Initializes |g_browser_process| with a new TestingBrowserProcess.
49 static void CreateInstance();
51 // Cleanly destroys |g_browser_process|, which has special deletion semantics.
52 static void DeleteInstance();
54 // Convenience method to get g_browser_process as a TestingBrowserProcess*.
55 static TestingBrowserProcess
* GetGlobal();
57 // BrowserProcess overrides:
58 void ResourceDispatcherHostCreated() override
;
59 void EndSession() override
;
60 MetricsServicesManager
* GetMetricsServicesManager() override
;
61 metrics::MetricsService
* metrics_service() override
;
62 rappor::RapporService
* rappor_service() override
;
63 IOThread
* io_thread() override
;
64 WatchDogThread
* watchdog_thread() override
;
65 ProfileManager
* profile_manager() override
;
66 PrefService
* local_state() override
;
67 variations::VariationsService
* variations_service() override
;
68 web_resource::PromoResourceService
* promo_resource_service() override
;
69 policy::BrowserPolicyConnector
* browser_policy_connector() override
;
70 policy::PolicyService
* policy_service() override
;
71 IconManager
* icon_manager() override
;
72 GLStringManager
* gl_string_manager() override
;
73 GpuModeManager
* gpu_mode_manager() override
;
74 BackgroundModeManager
* background_mode_manager() override
;
75 void set_background_mode_manager_for_test(
76 scoped_ptr
<BackgroundModeManager
> manager
) override
;
77 StatusTray
* status_tray() override
;
78 SafeBrowsingService
* safe_browsing_service() override
;
79 safe_browsing::ClientSideDetectionService
* safe_browsing_detection_service()
81 net::URLRequestContextGetter
* system_request_context() override
;
82 BrowserProcessPlatformPart
* platform_part() override
;
84 extensions::EventRouterForwarder
* extension_event_router_forwarder() override
;
85 NotificationUIManager
* notification_ui_manager() override
;
86 message_center::MessageCenter
* message_center() override
;
87 IntranetRedirectDetector
* intranet_redirect_detector() override
;
88 void CreateDevToolsHttpProtocolHandler(
89 chrome::HostDesktopType host_desktop_type
,
90 const std::string
& ip
,
91 uint16 port
) override
;
92 unsigned int AddRefModule() override
;
93 unsigned int ReleaseModule() override
;
94 bool IsShuttingDown() override
;
95 printing::PrintJobManager
* print_job_manager() override
;
96 printing::PrintPreviewDialogController
* print_preview_dialog_controller()
98 printing::BackgroundPrintingManager
* background_printing_manager() override
;
99 const std::string
& GetApplicationLocale() override
;
100 void SetApplicationLocale(const std::string
& app_locale
) override
;
101 DownloadStatusUpdater
* download_status_updater() override
;
102 DownloadRequestLimiter
* download_request_limiter() override
;
104 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
105 void StartAutoupdateTimer() override
{}
108 net_log::ChromeNetLog
* net_log() override
;
109 component_updater::ComponentUpdateService
* component_updater() override
;
110 CRLSetFetcher
* crl_set_fetcher() override
;
111 component_updater::PnaclComponentInstaller
* pnacl_component_installer()
113 component_updater::SupervisedUserWhitelistInstaller
*
114 supervised_user_whitelist_installer() override
;
115 MediaFileSystemRegistry
* media_file_system_registry() override
;
116 bool created_local_state() const override
;
118 #if defined(ENABLE_WEBRTC)
119 WebRtcLogUploader
* webrtc_log_uploader() override
;
122 network_time::NetworkTimeTracker
* network_time_tracker() override
;
124 gcm::GCMDriver
* gcm_driver() override
;
125 memory::OomPriorityManager
* GetOomPriorityManager() override
;
126 ShellIntegration::DefaultWebClientState
CachedDefaultWebClientState()
129 // Set the local state for tests. Consumer is responsible for cleaning it up
130 // afterwards (using ScopedTestingLocalState, for example).
131 void SetLocalState(PrefService
* local_state
);
132 void SetProfileManager(ProfileManager
* profile_manager
);
133 void SetIOThread(IOThread
* io_thread
);
134 void SetSafeBrowsingService(SafeBrowsingService
* sb_service
);
135 void SetSystemRequestContext(net::URLRequestContextGetter
* context_getter
);
136 void SetNotificationUIManager(
137 scoped_ptr
<NotificationUIManager
> notification_ui_manager
);
138 void ShutdownBrowserPolicyConnector();
141 // See CreateInstance() and DestoryInstance() above.
142 TestingBrowserProcess();
143 ~TestingBrowserProcess() override
;
145 scoped_ptr
<content::NotificationService
> notification_service_
;
146 unsigned int module_ref_count_
;
147 std::string app_locale_
;
149 // TODO(ios): Add back members as more code is compiled.
151 #if defined(ENABLE_CONFIGURATION_POLICY)
152 scoped_ptr
<policy::BrowserPolicyConnector
> browser_policy_connector_
;
153 bool created_browser_policy_connector_
= false;
155 scoped_ptr
<policy::PolicyService
> policy_service_
;
157 scoped_ptr
<ProfileManager
> profile_manager_
;
158 scoped_ptr
<NotificationUIManager
> notification_ui_manager_
;
160 #if defined(ENABLE_PRINTING)
161 scoped_ptr
<printing::PrintJobManager
> print_job_manager_
;
164 #if defined(ENABLE_PRINT_PREVIEW)
165 scoped_ptr
<printing::BackgroundPrintingManager
> background_printing_manager_
;
166 scoped_refptr
<printing::PrintPreviewDialogController
>
167 print_preview_dialog_controller_
;
170 scoped_refptr
<SafeBrowsingService
> sb_service_
;
171 #endif // !defined(OS_IOS)
173 scoped_ptr
<network_time::NetworkTimeTracker
> network_time_tracker_
;
175 // The following objects are not owned by TestingBrowserProcess:
176 PrefService
* local_state_
;
177 IOThread
* io_thread_
;
178 net::URLRequestContextGetter
* system_request_context_
;
180 scoped_ptr
<BrowserProcessPlatformPart
> platform_part_
;
182 #if defined(ENABLE_EXTENSIONS)
183 scoped_ptr
<MediaFileSystemRegistry
> media_file_system_registry_
;
185 scoped_ptr
<extensions::ExtensionsBrowserClient
> extensions_browser_client_
;
188 DISALLOW_COPY_AND_ASSIGN(TestingBrowserProcess
);
191 // RAII (resource acquisition is initialization) for TestingBrowserProcess.
192 // Allows you to initialize TestingBrowserProcess/NotificationService before
193 // other member variables.
195 // This can be helpful if you are running a unit test inside the browser_tests
196 // suite because browser_tests do not make a TestingBrowserProcess for you.
198 // class MyUnitTestRunningAsBrowserTest : public testing::Test {
201 // TestingBrowserProcessInitializer initializer_;
202 // LocalState local_state_; // Needs a BrowserProcess to initialize.
203 // NotificationRegistrar registar_; // Needs NotificationService.
205 class TestingBrowserProcessInitializer
{
207 TestingBrowserProcessInitializer();
208 ~TestingBrowserProcessInitializer();
211 DISALLOW_COPY_AND_ASSIGN(TestingBrowserProcessInitializer
);
214 #endif // CHROME_TEST_BASE_TESTING_BROWSER_PROCESS_H_