ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / chrome / test / base / testing_browser_process.h
blob757b5ba4a7266c4ab706b86b14758ee70d5c6a19
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 void ResourceDispatcherHostCreated() override;
62 void EndSession() override;
63 MetricsServicesManager* GetMetricsServicesManager() override;
64 metrics::MetricsService* metrics_service() override;
65 rappor::RapporService* rappor_service() override;
66 IOThread* io_thread() override;
67 WatchDogThread* watchdog_thread() override;
68 ProfileManager* profile_manager() override;
69 PrefService* local_state() override;
70 chrome_variations::VariationsService* variations_service() override;
71 policy::BrowserPolicyConnector* browser_policy_connector() override;
72 policy::PolicyService* policy_service() override;
73 IconManager* icon_manager() override;
74 GLStringManager* gl_string_manager() override;
75 GpuModeManager* gpu_mode_manager() override;
76 BackgroundModeManager* background_mode_manager() override;
77 void set_background_mode_manager_for_test(
78 scoped_ptr<BackgroundModeManager> manager) override;
79 StatusTray* status_tray() override;
80 SafeBrowsingService* safe_browsing_service() override;
81 safe_browsing::ClientSideDetectionService* safe_browsing_detection_service()
82 override;
83 net::URLRequestContextGetter* system_request_context() override;
84 BrowserProcessPlatformPart* platform_part() override;
86 extensions::EventRouterForwarder* extension_event_router_forwarder() override;
87 NotificationUIManager* notification_ui_manager() override;
88 message_center::MessageCenter* message_center() override;
89 IntranetRedirectDetector* intranet_redirect_detector() override;
90 void CreateDevToolsHttpProtocolHandler(
91 chrome::HostDesktopType host_desktop_type,
92 const std::string& ip,
93 uint16 port) override;
94 unsigned int AddRefModule() override;
95 unsigned int ReleaseModule() override;
96 bool IsShuttingDown() override;
97 printing::PrintJobManager* print_job_manager() override;
98 printing::PrintPreviewDialogController* print_preview_dialog_controller()
99 override;
100 printing::BackgroundPrintingManager* background_printing_manager() override;
101 const std::string& GetApplicationLocale() override;
102 void SetApplicationLocale(const std::string& app_locale) override;
103 DownloadStatusUpdater* download_status_updater() override;
104 DownloadRequestLimiter* download_request_limiter() override;
106 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
107 void StartAutoupdateTimer() override {}
108 #endif
110 ChromeNetLog* net_log() override;
111 prerender::PrerenderTracker* prerender_tracker() override;
112 component_updater::ComponentUpdateService* component_updater() override;
113 CRLSetFetcher* crl_set_fetcher() override;
114 component_updater::PnaclComponentInstaller* pnacl_component_installer()
115 override;
116 component_updater::SupervisedUserWhitelistInstaller*
117 supervised_user_whitelist_installer() override;
118 MediaFileSystemRegistry* media_file_system_registry() override;
119 bool created_local_state() const override;
121 #if defined(ENABLE_WEBRTC)
122 WebRtcLogUploader* webrtc_log_uploader() override;
123 #endif
125 network_time::NetworkTimeTracker* network_time_tracker() override;
127 gcm::GCMDriver* gcm_driver() override;
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 SetBrowserPolicyConnector(policy::BrowserPolicyConnector* connector);
135 void SetSafeBrowsingService(SafeBrowsingService* sb_service);
136 void SetSystemRequestContext(net::URLRequestContextGetter* context_getter);
138 private:
139 // See CreateInstance() and DestoryInstance() above.
140 TestingBrowserProcess();
141 ~TestingBrowserProcess() override;
143 scoped_ptr<content::NotificationService> notification_service_;
144 unsigned int module_ref_count_;
145 std::string app_locale_;
147 // TODO(ios): Add back members as more code is compiled.
148 #if !defined(OS_IOS)
149 #if defined(ENABLE_CONFIGURATION_POLICY)
150 scoped_ptr<policy::BrowserPolicyConnector> browser_policy_connector_;
151 #else
152 scoped_ptr<policy::PolicyService> policy_service_;
153 #endif
154 scoped_ptr<ProfileManager> profile_manager_;
155 scoped_ptr<NotificationUIManager> notification_ui_manager_;
157 #if defined(ENABLE_PRINTING)
158 scoped_ptr<printing::PrintJobManager> print_job_manager_;
159 #endif
161 #if defined(ENABLE_PRINT_PREVIEW)
162 scoped_ptr<printing::BackgroundPrintingManager> background_printing_manager_;
163 scoped_refptr<printing::PrintPreviewDialogController>
164 print_preview_dialog_controller_;
165 #endif
167 scoped_ptr<prerender::PrerenderTracker> prerender_tracker_;
168 scoped_refptr<SafeBrowsingService> sb_service_;
169 #endif // !defined(OS_IOS)
171 scoped_ptr<network_time::NetworkTimeTracker> network_time_tracker_;
173 // The following objects are not owned by TestingBrowserProcess:
174 PrefService* local_state_;
175 IOThread* io_thread_;
176 net::URLRequestContextGetter* system_request_context_;
178 scoped_ptr<BrowserProcessPlatformPart> platform_part_;
180 #if defined(ENABLE_EXTENSIONS)
181 scoped_ptr<MediaFileSystemRegistry> media_file_system_registry_;
183 scoped_ptr<extensions::ExtensionsBrowserClient> extensions_browser_client_;
184 #endif
186 DISALLOW_COPY_AND_ASSIGN(TestingBrowserProcess);
189 // RAII (resource acquisition is initialization) for TestingBrowserProcess.
190 // Allows you to initialize TestingBrowserProcess/NotificationService before
191 // other member variables.
193 // This can be helpful if you are running a unit test inside the browser_tests
194 // suite because browser_tests do not make a TestingBrowserProcess for you.
196 // class MyUnitTestRunningAsBrowserTest : public testing::Test {
197 // ...stuff...
198 // private:
199 // TestingBrowserProcessInitializer initializer_;
200 // LocalState local_state_; // Needs a BrowserProcess to initialize.
201 // NotificationRegistrar registar_; // Needs NotificationService.
202 // };
203 class TestingBrowserProcessInitializer {
204 public:
205 TestingBrowserProcessInitializer();
206 ~TestingBrowserProcessInitializer();
208 private:
209 DISALLOW_COPY_AND_ASSIGN(TestingBrowserProcessInitializer);
212 #endif // CHROME_TEST_BASE_TESTING_BROWSER_PROCESS_H_