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