OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // An implementation of BrowserProcess for unit tests that fails for most | 5 // An implementation of BrowserProcess for unit tests that fails for most |
6 // services. By preventing creation of services, we reduce dependencies and | 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 | 7 // keep the profile clean. Clients of this class must handle the NULL return |
8 // value, however. | 8 // value, however. |
9 | 9 |
10 #ifndef CHROME_TEST_TESTING_BROWSER_PROCESS_H_ | 10 #ifndef CHROME_TEST_TESTING_BROWSER_PROCESS_H_ |
11 #define CHROME_TEST_TESTING_BROWSER_PROCESS_H_ | 11 #define CHROME_TEST_TESTING_BROWSER_PROCESS_H_ |
12 #pragma once | 12 #pragma once |
13 | 13 |
14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
15 | 15 |
16 #include <string> | 16 #include <string> |
17 | 17 |
18 #include "base/string_util.h" | 18 #include "base/scoped_ptr.h" |
19 #include "base/synchronization/waitable_event.h" | |
20 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
21 #include "chrome/browser/google/google_url_tracker.h" | |
22 #include "chrome/browser/policy/configuration_policy_pref_store.h" | |
23 #include "chrome/browser/policy/configuration_policy_provider.h" | |
24 #include "chrome/browser/policy/configuration_policy_provider_keeper.h" | |
25 #include "chrome/browser/policy/dummy_configuration_policy_provider.h" | |
26 #include "chrome/browser/prefs/pref_service.h" | |
27 #include "chrome/common/notification_service.h" | 20 #include "chrome/common/notification_service.h" |
Nico
2011/02/07 23:24:28
nice
| |
28 #include "ui/base/clipboard/clipboard.h" | |
29 | 21 |
30 class IOThread; | 22 class IOThread; |
23 class GoogleURLTracker; | |
24 class PrefService; | |
25 | |
26 namespace base { | |
27 class WaitableEvent; | |
28 } | |
29 | |
30 namespace policy { | |
31 class ConfigurationPolicyProviderKeeper; | |
32 } | |
33 | |
34 namespace ui { | |
35 class Clipboard; | |
36 } | |
31 | 37 |
32 class TestingBrowserProcess : public BrowserProcess { | 38 class TestingBrowserProcess : public BrowserProcess { |
33 public: | 39 public: |
34 TestingBrowserProcess() | 40 TestingBrowserProcess(); |
35 : shutdown_event_(new base::WaitableEvent(true, false)), | 41 virtual ~TestingBrowserProcess(); |
36 module_ref_count_(0), | |
37 app_locale_("en"), | |
38 pref_service_(NULL), | |
39 created_configuration_policy_provider_keeper_(false) { | |
40 } | |
41 | 42 |
42 virtual ~TestingBrowserProcess() { | 43 virtual void EndSession(); |
43 } | |
44 | 44 |
45 virtual void EndSession() { | 45 virtual ResourceDispatcherHost* resource_dispatcher_host(); |
46 } | |
47 | 46 |
48 virtual ResourceDispatcherHost* resource_dispatcher_host() { | 47 virtual MetricsService* metrics_service(); |
49 return NULL; | |
50 } | |
51 | 48 |
52 virtual MetricsService* metrics_service() { | 49 virtual IOThread* io_thread(); |
53 return NULL; | |
54 } | |
55 | |
56 virtual IOThread* io_thread() { | |
57 return NULL; | |
58 } | |
59 | 50 |
60 #if defined(OS_LINUX) | 51 #if defined(OS_LINUX) |
61 virtual base::Thread* background_x11_thread() { | 52 virtual base::Thread* background_x11_thread(); |
62 return NULL; | |
63 } | |
64 #endif | 53 #endif |
65 | 54 |
66 virtual base::Thread* file_thread() { | 55 virtual base::Thread* file_thread(); |
67 return NULL; | |
68 } | |
69 | 56 |
70 virtual base::Thread* db_thread() { | 57 virtual base::Thread* db_thread(); |
71 return NULL; | |
72 } | |
73 | 58 |
74 virtual base::Thread* cache_thread() { | 59 virtual base::Thread* cache_thread(); |
75 return NULL; | |
76 } | |
77 | 60 |
78 virtual ProfileManager* profile_manager() { | 61 virtual ProfileManager* profile_manager(); |
79 return NULL; | |
80 } | |
81 | 62 |
82 virtual PrefService* local_state() { | 63 virtual PrefService* local_state(); |
83 return pref_service_; | |
84 } | |
85 | 64 |
86 virtual policy::ConfigurationPolicyProviderKeeper* | 65 virtual policy::ConfigurationPolicyProviderKeeper* |
87 configuration_policy_provider_keeper() { | 66 configuration_policy_provider_keeper(); |
88 if (!created_configuration_policy_provider_keeper_) { | |
89 DCHECK(configuration_policy_provider_keeper_.get() == NULL); | |
90 created_configuration_policy_provider_keeper_ = true; | |
91 const policy::ConfigurationPolicyProvider::PolicyDefinitionList* | |
92 policy_list = policy::ConfigurationPolicyPrefStore:: | |
93 GetChromePolicyDefinitionList(); | |
94 configuration_policy_provider_keeper_.reset( | |
95 new policy::ConfigurationPolicyProviderKeeper( | |
96 new policy::DummyConfigurationPolicyProvider(policy_list), | |
97 new policy::DummyConfigurationPolicyProvider(policy_list), | |
98 new policy::DummyConfigurationPolicyProvider(policy_list))); | |
99 } | |
100 return configuration_policy_provider_keeper_.get(); | |
101 } | |
102 | 67 |
103 virtual IconManager* icon_manager() { | 68 virtual IconManager* icon_manager(); |
104 return NULL; | |
105 } | |
106 | 69 |
107 virtual ThumbnailGenerator* GetThumbnailGenerator() { | 70 virtual ThumbnailGenerator* GetThumbnailGenerator(); |
108 return NULL; | |
109 } | |
110 | 71 |
111 virtual DevToolsManager* devtools_manager() { | 72 virtual DevToolsManager* devtools_manager(); |
112 return NULL; | |
113 } | |
114 | 73 |
115 virtual SidebarManager* sidebar_manager() { | 74 virtual SidebarManager* sidebar_manager(); |
116 return NULL; | |
117 } | |
118 | 75 |
119 virtual TabCloseableStateWatcher* tab_closeable_state_watcher() { | 76 virtual TabCloseableStateWatcher* tab_closeable_state_watcher(); |
120 return NULL; | |
121 } | |
122 | 77 |
123 virtual safe_browsing::ClientSideDetectionService* | 78 virtual safe_browsing::ClientSideDetectionService* |
124 safe_browsing_detection_service() { | 79 safe_browsing_detection_service(); |
125 return NULL; | |
126 } | |
127 | 80 |
128 virtual ui::Clipboard* clipboard() { | 81 virtual ui::Clipboard* clipboard(); |
129 if (!clipboard_.get()) { | |
130 // Note that we need a MessageLoop for the next call to work. | |
131 clipboard_.reset(new ui::Clipboard); | |
132 } | |
133 return clipboard_.get(); | |
134 } | |
135 | 82 |
136 virtual NotificationUIManager* notification_ui_manager() { | 83 virtual NotificationUIManager* notification_ui_manager(); |
137 return NULL; | |
138 } | |
139 | 84 |
140 virtual GoogleURLTracker* google_url_tracker() { | 85 virtual GoogleURLTracker* google_url_tracker(); |
141 return google_url_tracker_.get(); | |
142 } | |
143 | 86 |
144 virtual IntranetRedirectDetector* intranet_redirect_detector() { | 87 virtual IntranetRedirectDetector* intranet_redirect_detector(); |
145 return NULL; | |
146 } | |
147 | 88 |
148 virtual AutomationProviderList* InitAutomationProviderList() { | 89 virtual AutomationProviderList* InitAutomationProviderList(); |
149 return NULL; | |
150 } | |
151 | 90 |
152 virtual void InitDevToolsHttpProtocolHandler( | 91 virtual void InitDevToolsHttpProtocolHandler( |
153 const std::string& ip, | 92 const std::string& ip, |
154 int port, | 93 int port, |
155 const std::string& frontend_url) { | 94 const std::string& frontend_url); |
156 } | |
157 | 95 |
158 virtual void InitDevToolsLegacyProtocolHandler(int port) { | 96 virtual void InitDevToolsLegacyProtocolHandler(int port); |
159 } | |
160 | 97 |
161 virtual unsigned int AddRefModule() { | 98 virtual unsigned int AddRefModule(); |
162 return ++module_ref_count_; | 99 virtual unsigned int ReleaseModule(); |
163 } | |
164 virtual unsigned int ReleaseModule() { | |
165 DCHECK(module_ref_count_ > 0); | |
166 return --module_ref_count_; | |
167 } | |
168 | 100 |
169 virtual bool IsShuttingDown() { | 101 virtual bool IsShuttingDown(); |
170 return false; | |
171 } | |
172 | 102 |
173 virtual printing::PrintJobManager* print_job_manager() { | 103 virtual printing::PrintJobManager* print_job_manager(); |
174 return NULL; | |
175 } | |
176 | 104 |
177 virtual printing::PrintPreviewTabController* print_preview_tab_controller() { | 105 virtual printing::PrintPreviewTabController* print_preview_tab_controller(); |
178 return NULL; | |
179 } | |
180 | 106 |
181 virtual const std::string& GetApplicationLocale() { | 107 virtual const std::string& GetApplicationLocale(); |
182 return app_locale_; | |
183 } | |
184 | 108 |
185 virtual void SetApplicationLocale(const std::string& app_locale) { | 109 virtual void SetApplicationLocale(const std::string& app_locale); |
186 app_locale_ = app_locale; | |
187 } | |
188 | 110 |
189 virtual DownloadStatusUpdater* download_status_updater() { | 111 virtual DownloadStatusUpdater* download_status_updater(); |
190 return NULL; | |
191 } | |
192 | 112 |
193 virtual base::WaitableEvent* shutdown_event() { | 113 virtual base::WaitableEvent* shutdown_event(); |
194 return shutdown_event_.get(); | |
195 } | |
196 | 114 |
197 virtual void CheckForInspectorFiles() {} | 115 virtual void CheckForInspectorFiles() {} |
198 | 116 |
199 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) | 117 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) |
200 virtual void StartAutoupdateTimer() {} | 118 virtual void StartAutoupdateTimer() {} |
201 #endif | 119 #endif |
202 | 120 |
203 virtual bool have_inspector_files() const { return true; } | 121 virtual bool have_inspector_files() const; |
204 #if defined(IPC_MESSAGE_LOG_ENABLED) | 122 #if defined(IPC_MESSAGE_LOG_ENABLED) |
205 virtual void SetIPCLoggingEnabled(bool enable) {} | 123 virtual void SetIPCLoggingEnabled(bool enable) {} |
206 #endif | 124 #endif |
207 | 125 |
208 void SetPrefService(PrefService* pref_service) { | 126 void SetPrefService(PrefService* pref_service); |
209 pref_service_ = pref_service; | 127 void SetGoogleURLTracker(GoogleURLTracker* google_url_tracker); |
210 } | |
211 void SetGoogleURLTracker(GoogleURLTracker* google_url_tracker) { | |
212 google_url_tracker_.reset(google_url_tracker); | |
213 } | |
214 | 128 |
215 private: | 129 private: |
216 NotificationService notification_service_; | 130 NotificationService notification_service_; |
217 scoped_ptr<base::WaitableEvent> shutdown_event_; | 131 scoped_ptr<base::WaitableEvent> shutdown_event_; |
218 unsigned int module_ref_count_; | 132 unsigned int module_ref_count_; |
219 scoped_ptr<ui::Clipboard> clipboard_; | 133 scoped_ptr<ui::Clipboard> clipboard_; |
220 std::string app_locale_; | 134 std::string app_locale_; |
221 | 135 |
222 PrefService* pref_service_; | 136 PrefService* pref_service_; |
223 bool created_configuration_policy_provider_keeper_; | 137 bool created_configuration_policy_provider_keeper_; |
224 scoped_ptr<policy::ConfigurationPolicyProviderKeeper> | 138 scoped_ptr<policy::ConfigurationPolicyProviderKeeper> |
225 configuration_policy_provider_keeper_; | 139 configuration_policy_provider_keeper_; |
226 scoped_ptr<GoogleURLTracker> google_url_tracker_; | 140 scoped_ptr<GoogleURLTracker> google_url_tracker_; |
227 | 141 |
228 DISALLOW_COPY_AND_ASSIGN(TestingBrowserProcess); | 142 DISALLOW_COPY_AND_ASSIGN(TestingBrowserProcess); |
229 }; | 143 }; |
230 | 144 |
231 #endif // CHROME_TEST_TESTING_BROWSER_PROCESS_H_ | 145 #endif // CHROME_TEST_TESTING_BROWSER_PROCESS_H_ |
OLD | NEW |