Revert of Enabling audio quality test on mac. (patchset #1 id:1 of https://codereview...
[chromium-blink-merge.git] / chrome / test / base / testing_browser_process.h
blobbf39038d7dcba3363eea321095a028e0047d9a2b
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
8 // value, however.
10 #ifndef CHROME_TEST_BASE_TESTING_BROWSER_PROCESS_H_
11 #define CHROME_TEST_BASE_TESTING_BROWSER_PROCESS_H_
13 #include <string>
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;
22 class CRLSetFetcher;
23 class IOThread;
24 class MHTMLGenerationManager;
25 class NotificationUIManager;
26 class PrefService;
27 class WatchDogThread;
29 namespace content {
30 class NotificationService;
33 namespace extensions {
34 class ExtensionsBrowserClient;
37 namespace gcm {
38 class GCMDriver;
41 namespace policy {
42 class BrowserPolicyConnector;
43 class PolicyService;
46 namespace prerender {
47 class PrerenderTracker;
50 class TestingBrowserProcess : public BrowserProcess {
51 public:
52 // Initializes |g_browser_process| with a new TestingBrowserProcess.
53 static void CreateInstance();
55 // Cleanly destroys |g_browser_process|, which has special deletion semantics.
56 static void DeleteInstance();
58 // Convenience method to get g_browser_process as a TestingBrowserProcess*.
59 static TestingBrowserProcess* GetGlobal();
61 virtual void ResourceDispatcherHostCreated() OVERRIDE;
62 virtual void EndSession() OVERRIDE;
63 virtual MetricsServicesManager* GetMetricsServicesManager() OVERRIDE;
64 virtual metrics::MetricsService* metrics_service() OVERRIDE;
65 virtual rappor::RapporService* rappor_service() OVERRIDE;
66 virtual IOThread* io_thread() OVERRIDE;
67 virtual WatchDogThread* watchdog_thread() OVERRIDE;
68 virtual ProfileManager* profile_manager() OVERRIDE;
69 virtual PrefService* local_state() OVERRIDE;
70 virtual chrome_variations::VariationsService* variations_service() OVERRIDE;
71 virtual policy::BrowserPolicyConnector* browser_policy_connector() OVERRIDE;
72 virtual policy::PolicyService* policy_service() OVERRIDE;
73 virtual IconManager* icon_manager() OVERRIDE;
74 virtual GLStringManager* gl_string_manager() OVERRIDE;
75 virtual GpuModeManager* gpu_mode_manager() OVERRIDE;
76 virtual BackgroundModeManager* background_mode_manager() OVERRIDE;
77 virtual void set_background_mode_manager_for_test(
78 scoped_ptr<BackgroundModeManager> manager) OVERRIDE;
79 virtual StatusTray* status_tray() OVERRIDE;
80 virtual SafeBrowsingService* safe_browsing_service() OVERRIDE;
81 virtual safe_browsing::ClientSideDetectionService*
82 safe_browsing_detection_service() OVERRIDE;
83 virtual net::URLRequestContextGetter* system_request_context() OVERRIDE;
84 virtual BrowserProcessPlatformPart* platform_part() OVERRIDE;
86 virtual extensions::EventRouterForwarder*
87 extension_event_router_forwarder() OVERRIDE;
88 virtual NotificationUIManager* notification_ui_manager() OVERRIDE;
89 virtual message_center::MessageCenter* message_center() OVERRIDE;
90 virtual IntranetRedirectDetector* intranet_redirect_detector() OVERRIDE;
91 virtual void CreateDevToolsHttpProtocolHandler(
92 chrome::HostDesktopType host_desktop_type,
93 const std::string& ip,
94 int port) OVERRIDE;
95 virtual unsigned int AddRefModule() OVERRIDE;
96 virtual unsigned int ReleaseModule() OVERRIDE;
97 virtual bool IsShuttingDown() OVERRIDE;
98 virtual printing::PrintJobManager* print_job_manager() OVERRIDE;
99 virtual printing::PrintPreviewDialogController*
100 print_preview_dialog_controller() OVERRIDE;
101 virtual printing::BackgroundPrintingManager*
102 background_printing_manager() OVERRIDE;
103 virtual const std::string& GetApplicationLocale() OVERRIDE;
104 virtual void SetApplicationLocale(const std::string& app_locale) OVERRIDE;
105 virtual DownloadStatusUpdater* download_status_updater() OVERRIDE;
106 virtual DownloadRequestLimiter* download_request_limiter() OVERRIDE;
108 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
109 virtual void StartAutoupdateTimer() OVERRIDE {}
110 #endif
112 virtual ChromeNetLog* net_log() OVERRIDE;
113 virtual prerender::PrerenderTracker* prerender_tracker() OVERRIDE;
114 virtual component_updater::ComponentUpdateService*
115 component_updater() OVERRIDE;
116 virtual CRLSetFetcher* crl_set_fetcher() OVERRIDE;
117 virtual component_updater::PnaclComponentInstaller*
118 pnacl_component_installer() OVERRIDE;
119 virtual MediaFileSystemRegistry* media_file_system_registry() OVERRIDE;
120 virtual bool created_local_state() const OVERRIDE;
122 #if defined(ENABLE_WEBRTC)
123 virtual WebRtcLogUploader* webrtc_log_uploader() OVERRIDE;
124 #endif
126 virtual network_time::NetworkTimeTracker* network_time_tracker() OVERRIDE;
128 virtual gcm::GCMDriver* gcm_driver() OVERRIDE;
130 // Set the local state for tests. Consumer is responsible for cleaning it up
131 // afterwards (using ScopedTestingLocalState, for example).
132 void SetLocalState(PrefService* local_state);
133 void SetProfileManager(ProfileManager* profile_manager);
134 void SetIOThread(IOThread* io_thread);
135 void SetBrowserPolicyConnector(policy::BrowserPolicyConnector* connector);
136 void SetSafeBrowsingService(SafeBrowsingService* sb_service);
137 void SetSystemRequestContext(net::URLRequestContextGetter* context_getter);
139 private:
140 // See CreateInstance() and DestoryInstance() above.
141 TestingBrowserProcess();
142 virtual ~TestingBrowserProcess();
144 scoped_ptr<content::NotificationService> notification_service_;
145 unsigned int module_ref_count_;
146 std::string app_locale_;
148 // TODO(ios): Add back members as more code is compiled.
149 #if !defined(OS_IOS)
150 #if defined(ENABLE_CONFIGURATION_POLICY)
151 scoped_ptr<policy::BrowserPolicyConnector> browser_policy_connector_;
152 #else
153 scoped_ptr<policy::PolicyService> policy_service_;
154 #endif
155 scoped_ptr<ProfileManager> profile_manager_;
156 scoped_ptr<NotificationUIManager> notification_ui_manager_;
158 #if defined(ENABLE_PRINTING)
159 scoped_ptr<printing::PrintJobManager> print_job_manager_;
160 #endif
162 #if defined(ENABLE_FULL_PRINTING)
163 scoped_ptr<printing::BackgroundPrintingManager> background_printing_manager_;
164 scoped_refptr<printing::PrintPreviewDialogController>
165 print_preview_dialog_controller_;
166 #endif
168 scoped_ptr<prerender::PrerenderTracker> prerender_tracker_;
169 scoped_refptr<SafeBrowsingService> sb_service_;
170 #endif // !defined(OS_IOS)
172 scoped_ptr<network_time::NetworkTimeTracker> network_time_tracker_;
174 // The following objects are not owned by TestingBrowserProcess:
175 PrefService* local_state_;
176 IOThread* io_thread_;
177 net::URLRequestContextGetter* system_request_context_;
179 scoped_ptr<BrowserProcessPlatformPart> platform_part_;
181 #if defined(ENABLE_EXTENSIONS)
182 scoped_ptr<MediaFileSystemRegistry> media_file_system_registry_;
184 scoped_ptr<extensions::ExtensionsBrowserClient> extensions_browser_client_;
185 #endif
187 DISALLOW_COPY_AND_ASSIGN(TestingBrowserProcess);
190 // RAII (resource acquisition is initialization) for TestingBrowserProcess.
191 // Allows you to initialize TestingBrowserProcess/NotificationService before
192 // other member variables.
194 // This can be helpful if you are running a unit test inside the browser_tests
195 // suite because browser_tests do not make a TestingBrowserProcess for you.
197 // class MyUnitTestRunningAsBrowserTest : public testing::Test {
198 // ...stuff...
199 // private:
200 // TestingBrowserProcessInitializer initializer_;
201 // LocalState local_state_; // Needs a BrowserProcess to initialize.
202 // NotificationRegistrar registar_; // Needs NotificationService.
203 // };
204 class TestingBrowserProcessInitializer {
205 public:
206 TestingBrowserProcessInitializer();
207 ~TestingBrowserProcessInitializer();
209 private:
210 DISALLOW_COPY_AND_ASSIGN(TestingBrowserProcessInitializer);
213 #endif // CHROME_TEST_BASE_TESTING_BROWSER_PROCESS_H_