blob: ec65b2bbc60764497921b1ffd9e06a6525d0f9fc [file] [log] [blame]
[email protected]aeb53f02011-01-15 00:21:341// Copyright (c) 2011 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
5#include "chrome/test/testing_profile.h"
6
[email protected]a42b5592009-09-03 16:52:237#include "build/build_config.h"
[email protected]dbbad7a2010-08-13 18:18:368
9#include "base/base_paths.h"
[email protected]e3e43d92010-02-26 22:02:3810#include "base/command_line.h"
[email protected]dbbad7a2010-08-13 18:18:3611#include "base/file_util.h"
[email protected]83a7d2eb2010-05-03 21:46:1912#include "base/message_loop_proxy.h"
[email protected]dbbad7a2010-08-13 18:18:3613#include "base/path_service.h"
[email protected]e83326f2010-07-31 17:29:2514#include "base/string_number_conversions.h"
[email protected]dbbad7a2010-08-13 18:18:3615#include "chrome/browser/autocomplete/autocomplete_classifier.h"
[email protected]a07676b22011-06-17 16:36:5316#include "chrome/browser/background/background_contents_service_factory.h"
[email protected]a9afddb2009-02-12 17:49:4217#include "chrome/browser/bookmarks/bookmark_model.h"
[email protected]1459fb62011-05-25 19:03:2718#include "chrome/browser/browser_process.h"
[email protected]9d01a6a2010-11-30 12:03:3319#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]a6d36cc2011-02-23 00:39:4820#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
[email protected]2bb51302011-02-18 22:39:2721#include "chrome/browser/extensions/extension_pref_value_map.h"
[email protected]2f69b382011-02-19 00:34:2522#include "chrome/browser/extensions/extension_service.h"
[email protected]19eb80152011-02-26 00:28:4323#include "chrome/browser/extensions/extension_special_storage_policy.h"
[email protected]ee2ed42c2011-04-28 22:19:1424#include "chrome/browser/favicon/favicon_service.h"
[email protected]c476e632011-06-23 11:18:0425#include "chrome/browser/geolocation/chrome_geolocation_permission_context.h"
[email protected]dbbad7a2010-08-13 18:18:3626#include "chrome/browser/geolocation/geolocation_content_settings_map.h"
[email protected]dbbad7a2010-08-13 18:18:3627#include "chrome/browser/history/history.h"
[email protected]075ae732009-02-11 23:58:3128#include "chrome/browser/history/history_backend.h"
[email protected]dbbad7a2010-08-13 18:18:3629#include "chrome/browser/history/top_sites.h"
[email protected]8e4c29612010-07-14 01:24:4530#include "chrome/browser/net/gaia/token_service.h"
[email protected]cc5bfd42010-11-24 14:44:0231#include "chrome/browser/net/pref_proxy_config_service.h"
[email protected]dbbad7a2010-08-13 18:18:3632#include "chrome/browser/notifications/desktop_notification_service.h"
[email protected]dcb72d52011-04-13 12:36:5333#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]37858e52010-08-26 00:22:0234#include "chrome/browser/prefs/browser_prefs.h"
[email protected]9a8c4022011-01-25 14:25:3335#include "chrome/browser/prefs/testing_pref_store.h"
[email protected]4850a7f2011-03-08 23:36:5936#include "chrome/browser/prerender/prerender_manager.h"
[email protected]5cdcd152011-03-31 22:48:5237#include "chrome/browser/profiles/profile_dependency_manager.h"
[email protected]fb9d1f42010-10-06 23:17:5938#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]8e5c89a2011-06-07 18:13:3339#include "chrome/browser/search_engines/template_url_service.h"
40#include "chrome/browser/search_engines/template_url_service_factory.h"
[email protected]92371eb2011-04-28 11:50:1541#include "chrome/browser/sessions/session_service_factory.h"
42#include "chrome/browser/sessions/tab_restore_service_factory.h"
[email protected]4772b072010-03-30 17:45:4643#include "chrome/browser/sync/profile_sync_service_mock.h"
[email protected]45300ad42010-12-02 15:51:1444#include "chrome/browser/ui/find_bar/find_bar_state.h"
[email protected]fd42ac30f2011-02-27 19:33:3645#include "chrome/browser/ui/webui/chrome_url_data_manager.h"
[email protected]a9afddb2009-02-12 17:49:4246#include "chrome/common/chrome_constants.h"
[email protected]432115822011-07-10 15:52:2747#include "chrome/common/chrome_notification_types.h"
[email protected]dbbad7a2010-08-13 18:18:3648#include "chrome/common/url_constants.h"
[email protected]f12de8302011-05-23 16:12:3049#include "chrome/test/bookmark_load_observer.h"
[email protected]5138bbff2010-12-08 09:41:4450#include "chrome/test/test_url_request_context_getter.h"
[email protected]93270d002011-01-19 22:32:5951#include "chrome/test/testing_pref_service.h"
[email protected]809cc4d2010-10-27 15:22:5452#include "chrome/test/ui_test_utils.h"
[email protected]567812d2011-02-24 17:40:5053#include "content/browser/browser_thread.h"
54#include "content/browser/in_process_webkit/webkit_context.h"
[email protected]e89b77d2011-04-15 18:58:1055#include "content/browser/mock_resource_context.h"
[email protected]7f070d42011-03-09 20:25:3256#include "content/common/notification_service.h"
[email protected]dbbad7a2010-08-13 18:18:3657#include "net/base/cookie_monster.h"
[email protected]812b3a32010-01-08 05:36:0458#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:3459#include "net/url_request/url_request_context_getter.h"
[email protected]d2db0292011-01-26 20:23:4460#include "net/url_request/url_request_test_util.h"
[email protected]4772b072010-03-30 17:45:4661#include "testing/gmock/include/gmock/gmock.h"
[email protected]2f351cb2009-11-09 23:43:3462#include "webkit/database/database_tracker.h"
[email protected]de5480fa2011-05-26 22:07:3663#include "webkit/fileapi/file_system_context.h"
64#include "webkit/quota/quota_manager.h"
[email protected]248ce192011-02-10 15:26:3465
[email protected]e1acf6f2008-10-27 20:43:3366using base::Time;
[email protected]3c887412010-04-19 20:30:2367using testing::NiceMock;
[email protected]4772b072010-03-30 17:45:4668using testing::Return;
[email protected]e1acf6f2008-10-27 20:43:3369
[email protected]d364c652008-08-29 19:46:5670namespace {
71
[email protected]0bfc29a2009-04-27 16:15:4472// Task used to make sure history has finished processing a request. Intended
73// for use with BlockUntilHistoryProcessesPendingRequests.
74
75class QuittingHistoryDBTask : public HistoryDBTask {
76 public:
77 QuittingHistoryDBTask() {}
78
79 virtual bool RunOnDBThread(history::HistoryBackend* backend,
80 history::HistoryDatabase* db) {
81 return true;
82 }
83
84 virtual void DoneRunOnMainThread() {
85 MessageLoop::current()->Quit();
86 }
87
88 private:
[email protected]7991a232009-11-06 01:55:4889 ~QuittingHistoryDBTask() {}
90
[email protected]0bfc29a2009-04-27 16:15:4491 DISALLOW_COPY_AND_ASSIGN(QuittingHistoryDBTask);
92};
93
[email protected]aeb53f02011-01-15 00:21:3494class TestExtensionURLRequestContext : public net::URLRequestContext {
[email protected]c10da4b02010-03-25 14:38:3295 public:
96 TestExtensionURLRequestContext() {
97 net::CookieMonster* cookie_monster = new net::CookieMonster(NULL, NULL);
98 const char* schemes[] = {chrome::kExtensionScheme};
99 cookie_monster->SetCookieableSchemes(schemes, 1);
[email protected]f6c21cb2011-02-16 19:45:41100 set_cookie_store(cookie_monster);
[email protected]c10da4b02010-03-25 14:38:32101 }
102};
103
[email protected]abe2c032011-03-31 18:49:34104class TestExtensionURLRequestContextGetter
105 : public net::URLRequestContextGetter {
[email protected]c10da4b02010-03-25 14:38:32106 public:
[email protected]aeb53f02011-01-15 00:21:34107 virtual net::URLRequestContext* GetURLRequestContext() {
[email protected]c10da4b02010-03-25 14:38:32108 if (!context_)
109 context_ = new TestExtensionURLRequestContext();
110 return context_.get();
111 }
[email protected]00ed48f2010-10-22 22:19:24112 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const {
[email protected]0c7d74f2010-10-11 11:55:26113 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
[email protected]83a7d2eb2010-05-03 21:46:19114 }
[email protected]c10da4b02010-03-25 14:38:32115
116 private:
[email protected]aeb53f02011-01-15 00:21:34117 scoped_refptr<net::URLRequestContext> context_;
[email protected]c10da4b02010-03-25 14:38:32118};
119
[email protected]dcb72d52011-04-13 12:36:53120ProfileKeyedService* CreateTestDesktopNotificationService(Profile* profile) {
121 return new DesktopNotificationService(profile, NULL);
122}
123
[email protected]d364c652008-08-29 19:46:56124} // namespace
125
[email protected]f25387b2008-08-21 15:20:33126TestingProfile::TestingProfile()
[email protected]ea6f76572008-12-18 00:09:55127 : start_time_(Time::Now()),
[email protected]2fb7dc982010-09-29 12:24:28128 testing_prefs_(NULL),
[email protected]5bb2f522011-03-25 19:04:44129 incognito_(false),
[email protected]5cdcd152011-03-31 22:48:52130 last_session_exited_cleanly_(true),
131 profile_dependency_manager_(ProfileDependencyManager::GetInstance()) {
[email protected]0e3a385d2011-05-26 23:38:18132#ifndef NDEBUG
133 profile_dependency_manager_->ProfileNowExists(this);
134#endif
135
[email protected]f9dec9482010-08-20 20:42:19136 if (!temp_dir_.CreateUniqueTempDir()) {
137 LOG(ERROR) << "Failed to create unique temporary directory.";
initial.commit09911bf2008-07-26 23:55:29138
[email protected]f9dec9482010-08-20 20:42:19139 // Fallback logic in case we fail to create unique temporary directory.
140 FilePath system_tmp_dir;
141 bool success = PathService::Get(base::DIR_TEMP, &system_tmp_dir);
[email protected]848cd05e2008-09-19 18:33:48142
[email protected]f9dec9482010-08-20 20:42:19143 // We're severly screwed if we can't get the system temporary
144 // directory. Die now to avoid writing to the filesystem root
145 // or other bad places.
146 CHECK(success);
147
148 FilePath fallback_dir(system_tmp_dir.AppendASCII("TestingProfilePath"));
149 file_util::Delete(fallback_dir, true);
150 file_util::CreateDirectory(fallback_dir);
151 if (!temp_dir_.Set(fallback_dir)) {
152 // That shouldn't happen, but if it does, try to recover.
153 LOG(ERROR) << "Failed to use a fallback temporary directory.";
154
155 // We're screwed if this fails, see CHECK above.
156 CHECK(temp_dir_.Set(system_tmp_dir));
157 }
158 }
[email protected]dcb72d52011-04-13 12:36:53159
160 // Install profile keyed service factory hooks for dummy/test services
[email protected]7722653b2011-06-03 17:28:22161 BackgroundContentsServiceFactory::GetInstance()->SetTestingFactory(
[email protected]d2fad142011-04-15 10:18:44162 this, NULL);
[email protected]7722653b2011-06-03 17:28:22163 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory(
164 this, CreateTestDesktopNotificationService);
165 SessionServiceFactory::GetInstance()->SetTestingFactory(this, NULL);
166 TabRestoreServiceFactory::GetInstance()->SetTestingFactory(this, NULL);
[email protected]8e5c89a2011-06-07 18:13:33167 TemplateURLServiceFactory::GetInstance()->SetTestingFactory(this, NULL);
[email protected]ab23dbe2010-08-12 02:10:46168}
169
[email protected]f25387b2008-08-21 15:20:33170TestingProfile::~TestingProfile() {
[email protected]d2879af2010-02-08 16:02:56171 NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27172 chrome::NOTIFICATION_PROFILE_DESTROYED,
[email protected]5cdcd152011-03-31 22:48:52173 Source<Profile>(static_cast<Profile*>(this)),
[email protected]d2879af2010-02-08 16:02:56174 NotificationService::NoDetails());
[email protected]5cdcd152011-03-31 22:48:52175
176 profile_dependency_manager_->DestroyProfileServices(this);
177
[email protected]35552dc52011-07-12 09:04:38178 if (host_content_settings_map_)
179 host_content_settings_map_->ShutdownOnUIThread();
180
[email protected]809cc4d2010-10-27 15:22:54181 DestroyTopSites();
[email protected]f25387b2008-08-21 15:20:33182 DestroyHistoryService();
[email protected]d2879af2010-02-08 16:02:56183 // FaviconService depends on HistoryServce so destroying it later.
184 DestroyFaviconService();
[email protected]2609bc12010-01-24 08:32:55185 DestroyWebDataService();
[email protected]cdba46992011-06-07 11:51:39186
[email protected]cc5bfd42010-11-24 14:44:02187 if (pref_proxy_config_tracker_.get())
188 pref_proxy_config_tracker_->DetachFromPrefService();
[email protected]f25387b2008-08-21 15:20:33189}
initial.commit09911bf2008-07-26 23:55:29190
[email protected]d2879af2010-02-08 16:02:56191void TestingProfile::CreateFaviconService() {
192 favicon_service_ = NULL;
193 favicon_service_ = new FaviconService(this);
194}
195
[email protected]d486a0852009-11-02 21:40:00196void TestingProfile::CreateHistoryService(bool delete_file, bool no_db) {
[email protected]809cc4d2010-10-27 15:22:54197 DestroyHistoryService();
[email protected]f25387b2008-08-21 15:20:33198 if (delete_file) {
[email protected]f7011fcb2009-01-28 21:54:32199 FilePath path = GetPath();
200 path = path.Append(chrome::kHistoryFilename);
[email protected]f25387b2008-08-21 15:20:33201 file_util::Delete(path, false);
202 }
[email protected]90ef13132008-08-27 03:27:46203 history_service_ = new HistoryService(this);
[email protected]d486a0852009-11-02 21:40:00204 history_service_->Init(GetPath(), bookmark_bar_model_.get(), no_db);
initial.commit09911bf2008-07-26 23:55:29205}
206
207void TestingProfile::DestroyHistoryService() {
208 if (!history_service_.get())
209 return;
210
211 history_service_->NotifyRenderProcessHostDestruction(0);
212 history_service_->SetOnBackendDestroyTask(new MessageLoop::QuitTask);
213 history_service_->Cleanup();
214 history_service_ = NULL;
215
216 // Wait for the backend class to terminate before deleting the files and
217 // moving to the next test. Note: if this never terminates, somebody is
218 // probably leaking a reference to the history backend, so it never calls
219 // our destroy task.
220 MessageLoop::current()->Run();
221
initial.commit09911bf2008-07-26 23:55:29222 // Make sure we don't have any event pending that could disrupt the next
223 // test.
224 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask);
225 MessageLoop::current()->Run();
226}
[email protected]4d0cd7ce2008-08-11 16:40:57227
[email protected]809cc4d2010-10-27 15:22:54228void TestingProfile::CreateTopSites() {
229 DestroyTopSites();
230 top_sites_ = new history::TopSites(this);
[email protected]73c47932010-12-06 18:13:43231 FilePath file_name = GetPath().Append(chrome::kTopSitesFilename);
[email protected]809cc4d2010-10-27 15:22:54232 top_sites_->Init(file_name);
233}
234
235void TestingProfile::DestroyTopSites() {
236 if (top_sites_.get()) {
237 top_sites_->Shutdown();
238 top_sites_ = NULL;
239 // TopSites::Shutdown schedules some tasks (from TopSitesBackend) that need
240 // to be run to properly shutdown. Run all pending tasks now. This is
241 // normally handled by browser_process shutdown.
242 if (MessageLoop::current())
243 MessageLoop::current()->RunAllPending();
244 }
245}
246
247void TestingProfile::DestroyFaviconService() {
248 if (!favicon_service_.get())
249 return;
250 favicon_service_ = NULL;
251}
252
[email protected]d8e41ed2008-09-11 15:22:32253void TestingProfile::CreateBookmarkModel(bool delete_file) {
[email protected]90ef13132008-08-27 03:27:46254 // Nuke the model first, that way we're sure it's done writing to disk.
255 bookmark_bar_model_.reset(NULL);
256
257 if (delete_file) {
[email protected]f7011fcb2009-01-28 21:54:32258 FilePath path = GetPath();
259 path = path.Append(chrome::kBookmarksFileName);
[email protected]90ef13132008-08-27 03:27:46260 file_util::Delete(path, false);
261 }
[email protected]d8e41ed2008-09-11 15:22:32262 bookmark_bar_model_.reset(new BookmarkModel(this));
[email protected]90ef13132008-08-27 03:27:46263 if (history_service_.get()) {
264 history_service_->history_backend_->bookmark_service_ =
265 bookmark_bar_model_.get();
266 history_service_->history_backend_->expirer_.bookmark_service_ =
267 bookmark_bar_model_.get();
268 }
269 bookmark_bar_model_->Load();
[email protected]4d0cd7ce2008-08-11 16:40:57270}
[email protected]d2c017a2008-08-13 21:51:45271
[email protected]69c579e2010-04-23 20:01:00272void TestingProfile::CreateAutocompleteClassifier() {
273 autocomplete_classifier_.reset(new AutocompleteClassifier(this));
274}
275
[email protected]a6d36cc2011-02-23 00:39:48276void TestingProfile::CreateProtocolHandlerRegistry() {
[email protected]fd8ca522011-05-02 18:54:49277 protocol_handler_registry_ = new ProtocolHandlerRegistry(this,
278 new ProtocolHandlerRegistry::Delegate());
[email protected]a6d36cc2011-02-23 00:39:48279}
280
[email protected]2609bc12010-01-24 08:32:55281void TestingProfile::CreateWebDataService(bool delete_file) {
282 if (web_data_service_.get())
283 web_data_service_->Shutdown();
284
285 if (delete_file) {
286 FilePath path = GetPath();
287 path = path.Append(chrome::kWebDataFilename);
288 file_util::Delete(path, false);
289 }
290
291 web_data_service_ = new WebDataService;
292 if (web_data_service_.get())
293 web_data_service_->Init(GetPath());
294}
295
[email protected]d364c652008-08-29 19:46:56296void TestingProfile::BlockUntilBookmarkModelLoaded() {
297 DCHECK(bookmark_bar_model_.get());
298 if (bookmark_bar_model_->IsLoaded())
299 return;
300 BookmarkLoadObserver observer;
301 bookmark_bar_model_->AddObserver(&observer);
302 MessageLoop::current()->Run();
303 bookmark_bar_model_->RemoveObserver(&observer);
304 DCHECK(bookmark_bar_model_->IsLoaded());
305}
306
[email protected]809cc4d2010-10-27 15:22:54307void TestingProfile::BlockUntilTopSitesLoaded() {
308 if (!GetHistoryService(Profile::EXPLICIT_ACCESS))
309 GetTopSites()->HistoryLoaded();
[email protected]432115822011-07-10 15:52:27310 ui_test_utils::WaitForNotification(chrome::NOTIFICATION_TOP_SITES_LOADED);
[email protected]809cc4d2010-10-27 15:22:54311}
312
[email protected]fb9d1f42010-10-06 23:17:59313void TestingProfile::CreateTemplateURLFetcher() {
314 template_url_fetcher_.reset(new TemplateURLFetcher(this));
315}
316
[email protected]8e5c89a2011-06-07 18:13:33317static ProfileKeyedService* BuildTemplateURLService(Profile* profile) {
318 return new TemplateURLService(profile);
[email protected]fb9d1f42010-10-06 23:17:59319}
320
[email protected]8e5c89a2011-06-07 18:13:33321void TestingProfile::CreateTemplateURLService() {
322 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
323 this, BuildTemplateURLService);
[email protected]d2c017a2008-08-13 21:51:45324}
[email protected]0bfc29a2009-04-27 16:15:44325
[email protected]9a8c4022011-01-25 14:25:33326ExtensionService* TestingProfile::CreateExtensionService(
[email protected]2fb7dc982010-09-29 12:24:28327 const CommandLine* command_line,
[email protected]90310d92011-04-17 07:35:04328 const FilePath& install_directory,
329 bool autoupdate_enabled) {
[email protected]9a8c4022011-01-25 14:25:33330 // Extension pref store, created for use by |extension_prefs_|.
331
332 extension_pref_value_map_.reset(new ExtensionPrefValueMap);
333 // Note that the GetPrefs() creates a TestingPrefService, therefore
334 // the extension controlled pref values set in extension_prefs_
335 // are not reflected in the pref service. One would need to
336 // inject a new ExtensionPrefStore(extension_pref_value_map_.get(), false).
337 extension_prefs_.reset(
338 new ExtensionPrefs(GetPrefs(),
339 install_directory,
340 extension_pref_value_map_.get()));
[email protected]14908b72011-04-20 06:54:36341 extension_service_.reset(new ExtensionService(this,
342 command_line,
343 install_directory,
344 extension_prefs_.get(),
345 autoupdate_enabled,
346 true));
347 return extension_service_.get();
[email protected]2fb7dc982010-09-29 12:24:28348}
349
[email protected]f9dec9482010-08-20 20:42:19350FilePath TestingProfile::GetPath() {
351 DCHECK(temp_dir_.IsValid()); // TODO(phajdan.jr): do it better.
352 return temp_dir_.path();
353}
354
[email protected]dbbad7a2010-08-13 18:18:36355TestingPrefService* TestingProfile::GetTestingPrefService() {
[email protected]2fb7dc982010-09-29 12:24:28356 if (!prefs_.get())
357 CreateTestingPrefService();
358 DCHECK(testing_prefs_);
359 return testing_prefs_;
[email protected]dbbad7a2010-08-13 18:18:36360}
361
[email protected]8e5c89a2011-06-07 18:13:33362TestingProfile* TestingProfile::AsTestingProfile() {
363 return this;
364}
365
[email protected]29d70252011-04-28 02:16:58366std::string TestingProfile::GetProfileName() {
367 return std::string("testing_profile");
368}
369
[email protected]fadc607b62011-02-07 17:55:50370ProfileId TestingProfile::GetRuntimeId() {
[email protected]8e5c89a2011-06-07 18:13:33371 return reinterpret_cast<ProfileId>(this);
372}
[email protected]fadc607b62011-02-07 17:55:50373
374bool TestingProfile::IsOffTheRecord() {
[email protected]5bb2f522011-03-25 19:04:44375 return incognito_;
[email protected]fadc607b62011-02-07 17:55:50376}
377
[email protected]93dba942011-02-23 22:45:01378void TestingProfile::SetOffTheRecordProfile(Profile* profile) {
[email protected]5bb2f522011-03-25 19:04:44379 incognito_profile_.reset(profile);
[email protected]93dba942011-02-23 22:45:01380}
381
[email protected]fadc607b62011-02-07 17:55:50382Profile* TestingProfile::GetOffTheRecordProfile() {
[email protected]5bb2f522011-03-25 19:04:44383 return incognito_profile_.get();
[email protected]fadc607b62011-02-07 17:55:50384}
385
386bool TestingProfile::HasOffTheRecordProfile() {
[email protected]5bb2f522011-03-25 19:04:44387 return incognito_profile_.get() != NULL;
[email protected]fadc607b62011-02-07 17:55:50388}
389
390Profile* TestingProfile::GetOriginalProfile() {
391 return this;
392}
393
394ChromeAppCacheService* TestingProfile::GetAppCacheService() {
395 return NULL;
396}
397
[email protected]2f351cb2009-11-09 23:43:34398webkit_database::DatabaseTracker* TestingProfile::GetDatabaseTracker() {
[email protected]19eb80152011-02-26 00:28:43399 if (!db_tracker_) {
400 db_tracker_ = new webkit_database::DatabaseTracker(
[email protected]800ad562011-07-08 08:00:50401 GetPath(), false, false, GetExtensionSpecialStoragePolicy(),
402 NULL, NULL);
[email protected]19eb80152011-02-26 00:28:43403 }
[email protected]2f351cb2009-11-09 23:43:34404 return db_tracker_;
405}
406
[email protected]fadc607b62011-02-07 17:55:50407VisitedLinkMaster* TestingProfile::GetVisitedLinkMaster() {
408 return NULL;
409}
410
[email protected]eaa7dd182010-12-14 11:09:00411ExtensionService* TestingProfile::GetExtensionService() {
[email protected]14908b72011-04-20 06:54:36412 return extension_service_.get();
[email protected]2fb7dc982010-09-29 12:24:28413}
414
[email protected]fadc607b62011-02-07 17:55:50415UserScriptMaster* TestingProfile::GetUserScriptMaster() {
416 return NULL;
417}
418
419ExtensionDevToolsManager* TestingProfile::GetExtensionDevToolsManager() {
420 return NULL;
421}
422
423ExtensionProcessManager* TestingProfile::GetExtensionProcessManager() {
424 return NULL;
425}
426
427ExtensionMessageService* TestingProfile::GetExtensionMessageService() {
428 return NULL;
429}
430
431ExtensionEventRouter* TestingProfile::GetExtensionEventRouter() {
432 return NULL;
433}
434
[email protected]19eb80152011-02-26 00:28:43435ExtensionSpecialStoragePolicy*
436TestingProfile::GetExtensionSpecialStoragePolicy() {
[email protected]cdba46992011-06-07 11:51:39437 if (!extension_special_storage_policy_.get())
[email protected]19eb80152011-02-26 00:28:43438 extension_special_storage_policy_ = new ExtensionSpecialStoragePolicy();
[email protected]cdba46992011-06-07 11:51:39439 return extension_special_storage_policy_.get();
[email protected]19eb80152011-02-26 00:28:43440}
441
[email protected]fadc607b62011-02-07 17:55:50442SSLHostState* TestingProfile::GetSSLHostState() {
443 return NULL;
444}
445
446net::TransportSecurityState* TestingProfile::GetTransportSecurityState() {
447 return NULL;
448}
449
450FaviconService* TestingProfile::GetFaviconService(ServiceAccessType access) {
451 return favicon_service_.get();
452}
453
454HistoryService* TestingProfile::GetHistoryService(ServiceAccessType access) {
455 return history_service_.get();
456}
457
458HistoryService* TestingProfile::GetHistoryServiceWithoutCreating() {
459 return history_service_.get();
460}
461
[email protected]dbbad7a2010-08-13 18:18:36462net::CookieMonster* TestingProfile::GetCookieMonster() {
463 if (!GetRequestContext())
464 return NULL;
[email protected]277ec262011-03-30 21:09:40465 return GetRequestContext()->GetURLRequestContext()->cookie_store()->
466 GetCookieMonster();
[email protected]dbbad7a2010-08-13 18:18:36467}
468
[email protected]fadc607b62011-02-07 17:55:50469AutocompleteClassifier* TestingProfile::GetAutocompleteClassifier() {
470 return autocomplete_classifier_.get();
471}
472
473WebDataService* TestingProfile::GetWebDataService(ServiceAccessType access) {
474 return web_data_service_.get();
475}
476
477WebDataService* TestingProfile::GetWebDataServiceWithoutCreating() {
478 return web_data_service_.get();
479}
480
481PasswordStore* TestingProfile::GetPasswordStore(ServiceAccessType access) {
482 return NULL;
483}
484
[email protected]2fb7dc982010-09-29 12:24:28485void TestingProfile::SetPrefService(PrefService* prefs) {
486 DCHECK(!prefs_.get());
487 prefs_.reset(prefs);
488}
489
490void TestingProfile::CreateTestingPrefService() {
491 DCHECK(!prefs_.get());
492 testing_prefs_ = new TestingPrefService();
493 prefs_.reset(testing_prefs_);
494 Profile::RegisterUserPrefs(prefs_.get());
[email protected]2f9d81322011-02-21 09:55:43495 browser::RegisterUserPrefs(prefs_.get());
[email protected]2fb7dc982010-09-29 12:24:28496}
497
[email protected]dbbad7a2010-08-13 18:18:36498PrefService* TestingProfile::GetPrefs() {
499 if (!prefs_.get()) {
[email protected]2fb7dc982010-09-29 12:24:28500 CreateTestingPrefService();
[email protected]dbbad7a2010-08-13 18:18:36501 }
502 return prefs_.get();
503}
504
[email protected]fadc607b62011-02-07 17:55:50505TemplateURLFetcher* TestingProfile::GetTemplateURLFetcher() {
506 return template_url_fetcher_.get();
507}
508
[email protected]dbbad7a2010-08-13 18:18:36509history::TopSites* TestingProfile::GetTopSites() {
[email protected]809cc4d2010-10-27 15:22:54510 return top_sites_.get();
[email protected]dbbad7a2010-08-13 18:18:36511}
512
[email protected]fadc607b62011-02-07 17:55:50513history::TopSites* TestingProfile::GetTopSitesWithoutCreating() {
514 return top_sites_.get();
515}
516
517DownloadManager* TestingProfile::GetDownloadManager() {
518 return NULL;
519}
520
521PersonalDataManager* TestingProfile::GetPersonalDataManager() {
522 return NULL;
523}
524
[email protected]397281f2011-02-14 05:15:53525fileapi::FileSystemContext* TestingProfile::GetFileSystemContext() {
[email protected]de5480fa2011-05-26 22:07:36526 if (!file_system_context_) {
527 file_system_context_ = new fileapi::FileSystemContext(
528 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE),
529 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
530 GetExtensionSpecialStoragePolicy(),
531 NULL,
532 GetPath(),
533 IsOffTheRecord(),
534 true, // Allow file access from files.
535 true, // Unlimited quota.
536 NULL);
537 }
538 return file_system_context_.get();
[email protected]fadc607b62011-02-07 17:55:50539}
540
[email protected]595765c2011-04-27 13:20:14541quota::QuotaManager* TestingProfile::GetQuotaManager() {
542 return NULL;
543}
544
[email protected]fadc607b62011-02-07 17:55:50545BrowserSignin* TestingProfile::GetBrowserSignin() {
546 return NULL;
547}
548
549bool TestingProfile::HasCreatedDownloadManager() const {
550 return false;
551}
552
[email protected]abe2c032011-03-31 18:49:34553net::URLRequestContextGetter* TestingProfile::GetRequestContext() {
[email protected]812b3a32010-01-08 05:36:04554 return request_context_.get();
555}
556
[email protected]da5683db2011-04-23 17:12:21557net::URLRequestContextGetter* TestingProfile::GetRequestContextForRenderProcess(
558 int renderer_child_id) {
559 if (extension_service_.get()) {
560 const Extension* installed_app = extension_service_->
561 GetInstalledAppForRenderer(renderer_child_id);
562 if (installed_app != NULL && installed_app->is_storage_isolated())
563 return GetRequestContextForIsolatedApp(installed_app->id());
564 }
[email protected]d9696672011-03-15 22:45:09565
566 return GetRequestContext();
567}
568
[email protected]812b3a32010-01-08 05:36:04569void TestingProfile::CreateRequestContext() {
570 if (!request_context_)
571 request_context_ = new TestURLRequestContextGetter();
572}
573
[email protected]7c893202010-10-07 20:18:02574void TestingProfile::ResetRequestContext() {
575 request_context_ = NULL;
576}
577
[email protected]abe2c032011-03-31 18:49:34578net::URLRequestContextGetter* TestingProfile::GetRequestContextForMedia() {
[email protected]fadc607b62011-02-07 17:55:50579 return NULL;
580}
581
[email protected]abe2c032011-03-31 18:49:34582net::URLRequestContextGetter* TestingProfile::GetRequestContextForExtensions() {
[email protected]c10da4b02010-03-25 14:38:32583 if (!extensions_request_context_)
584 extensions_request_context_ = new TestExtensionURLRequestContextGetter();
585 return extensions_request_context_.get();
586}
587
[email protected]fadc607b62011-02-07 17:55:50588net::SSLConfigService* TestingProfile::GetSSLConfigService() {
589 return NULL;
590}
591
592UserStyleSheetWatcher* TestingProfile::GetUserStyleSheetWatcher() {
593 return NULL;
594}
595
[email protected]abe2c032011-03-31 18:49:34596net::URLRequestContextGetter* TestingProfile::GetRequestContextForIsolatedApp(
[email protected]d9696672011-03-15 22:45:09597 const std::string& app_id) {
598 // We don't test isolated app storage here yet, so returning the same dummy
599 // context is sufficient for now.
600 return GetRequestContext();
601}
602
[email protected]e89b77d2011-04-15 18:58:10603const content::ResourceContext& TestingProfile::GetResourceContext() {
[email protected]0d9f6f02011-07-08 23:11:21604 return *content::MockResourceContext::GetInstance();
[email protected]e89b77d2011-04-15 18:58:10605}
606
[email protected]dbbad7a2010-08-13 18:18:36607FindBarState* TestingProfile::GetFindBarState() {
608 if (!find_bar_state_.get())
609 find_bar_state_.reset(new FindBarState());
610 return find_bar_state_.get();
611}
612
613HostContentSettingsMap* TestingProfile::GetHostContentSettingsMap() {
[email protected]35552dc52011-07-12 09:04:38614 if (!host_content_settings_map_.get()) {
615 host_content_settings_map_ = new HostContentSettingsMap(
616 GetPrefs(), GetExtensionService(), false);
617 }
[email protected]dbbad7a2010-08-13 18:18:36618 return host_content_settings_map_.get();
619}
620
621GeolocationContentSettingsMap*
622TestingProfile::GetGeolocationContentSettingsMap() {
623 if (!geolocation_content_settings_map_.get()) {
624 geolocation_content_settings_map_ =
625 new GeolocationContentSettingsMap(this);
626 }
627 return geolocation_content_settings_map_.get();
628}
629
630GeolocationPermissionContext*
631TestingProfile::GetGeolocationPermissionContext() {
632 if (!geolocation_permission_context_.get()) {
633 geolocation_permission_context_ =
[email protected]c476e632011-06-23 11:18:04634 new ChromeGeolocationPermissionContext(this);
[email protected]dbbad7a2010-08-13 18:18:36635 }
636 return geolocation_permission_context_.get();
637}
638
[email protected]fadc607b62011-02-07 17:55:50639HostZoomMap* TestingProfile::GetHostZoomMap() {
640 return NULL;
641}
642
[email protected]fadc607b62011-02-07 17:55:50643bool TestingProfile::HasProfileSyncService() const {
644 return (profile_sync_service_.get() != NULL);
645}
646
647std::wstring TestingProfile::GetName() {
648 return std::wstring();
649}
650
651std::wstring TestingProfile::GetID() {
652 return id_;
653}
654
655void TestingProfile::SetID(const std::wstring& id) {
656 id_ = id;
657}
658
659bool TestingProfile::DidLastSessionExitCleanly() {
660 return last_session_exited_cleanly_;
661}
662
663BookmarkModel* TestingProfile::GetBookmarkModel() {
664 return bookmark_bar_model_.get();
665}
666
667bool TestingProfile::IsSameProfile(Profile *p) {
668 return this == p;
669}
670
671base::Time TestingProfile::GetStartTime() const {
672 return start_time_;
673}
674
[email protected]a6d36cc2011-02-23 00:39:48675ProtocolHandlerRegistry* TestingProfile::GetProtocolHandlerRegistry() {
676 return protocol_handler_registry_.get();
677}
678
[email protected]fadc607b62011-02-07 17:55:50679SpellCheckHost* TestingProfile::GetSpellCheckHost() {
680 return NULL;
681}
682
[email protected]dbbad7a2010-08-13 18:18:36683WebKitContext* TestingProfile::GetWebKitContext() {
[email protected]228d06592011-04-01 20:38:59684 if (webkit_context_ == NULL) {
685 webkit_context_ = new WebKitContext(
686 IsOffTheRecord(), GetPath(),
687 GetExtensionSpecialStoragePolicy(),
[email protected]ba7c5152011-06-03 19:43:28688 false, NULL, NULL);
[email protected]228d06592011-04-01 20:38:59689 }
[email protected]dbbad7a2010-08-13 18:18:36690 return webkit_context_;
691}
692
[email protected]fadc607b62011-02-07 17:55:50693WebKitContext* TestingProfile::GetOffTheRecordWebKitContext() {
694 return NULL;
695}
696
[email protected]fadc607b62011-02-07 17:55:50697FilePath TestingProfile::last_selected_directory() {
698 return last_selected_directory_;
699}
700
701void TestingProfile::set_last_selected_directory(const FilePath& path) {
702 last_selected_directory_ = path;
703}
704
[email protected]cc5bfd42010-11-24 14:44:02705PrefProxyConfigTracker* TestingProfile::GetProxyConfigTracker() {
706 if (!pref_proxy_config_tracker_)
707 pref_proxy_config_tracker_ = new PrefProxyConfigTracker(GetPrefs());
708
709 return pref_proxy_config_tracker_;
710}
711
[email protected]0bfc29a2009-04-27 16:15:44712void TestingProfile::BlockUntilHistoryProcessesPendingRequests() {
713 DCHECK(history_service_.get());
714 DCHECK(MessageLoop::current());
715
716 CancelableRequestConsumer consumer;
717 history_service_->ScheduleDBTask(new QuittingHistoryDBTask(), &consumer);
718 MessageLoop::current()->Run();
719}
[email protected]345a8b72009-09-29 09:11:44720
[email protected]8e4c29612010-07-14 01:24:45721TokenService* TestingProfile::GetTokenService() {
722 if (!token_service_.get()) {
723 token_service_.reset(new TokenService());
724 }
725 return token_service_.get();
726}
727
[email protected]345a8b72009-09-29 09:11:44728ProfileSyncService* TestingProfile::GetProfileSyncService() {
[email protected]e8234d32010-09-09 20:36:39729 return GetProfileSyncService("");
730}
731
732ProfileSyncService* TestingProfile::GetProfileSyncService(
733 const std::string& cros_user) {
[email protected]4772b072010-03-30 17:45:46734 if (!profile_sync_service_.get()) {
[email protected]3c887412010-04-19 20:30:23735 // Use a NiceMock here since we are really using the mock as a
736 // fake. Test cases that want to set expectations on a
737 // ProfileSyncService should use the ProfileMock and have this
738 // method return their own mock instance.
739 profile_sync_service_.reset(new NiceMock<ProfileSyncServiceMock>());
[email protected]4772b072010-03-30 17:45:46740 }
[email protected]345a8b72009-09-29 09:11:44741 return profile_sync_service_.get();
[email protected]345a8b72009-09-29 09:11:44742}
[email protected]2609bc12010-01-24 08:32:55743
[email protected]fadc607b62011-02-07 17:55:50744CloudPrintProxyService* TestingProfile::GetCloudPrintProxyService() {
745 return NULL;
746}
747
748ChromeBlobStorageContext* TestingProfile::GetBlobStorageContext() {
749 return NULL;
750}
751
752ExtensionInfoMap* TestingProfile::GetExtensionInfoMap() {
753 return NULL;
754}
755
756PromoCounter* TestingProfile::GetInstantPromoCounter() {
757 return NULL;
758}
759
[email protected]248ce192011-02-10 15:26:34760ChromeURLDataManager* TestingProfile::GetChromeURLDataManager() {
761 if (!chrome_url_data_manager_.get())
762 chrome_url_data_manager_.reset(new ChromeURLDataManager(this));
763 return chrome_url_data_manager_.get();
764}
765
[email protected]4c154ff82011-02-15 11:23:59766prerender::PrerenderManager* TestingProfile::GetPrerenderManager() {
[email protected]503c1cf2011-03-31 12:36:34767 if (!prerender::PrerenderManager::IsPrerenderingPossible())
[email protected]1c6228b2011-04-25 16:37:52768 return NULL;
[email protected]1459fb62011-05-25 19:03:27769 if (!prerender_manager_.get()) {
770 prerender_manager_.reset(new prerender::PrerenderManager(
771 this, g_browser_process->prerender_tracker()));
772 }
[email protected]a4fa83b92011-04-22 18:04:09773 return prerender_manager_.get();
[email protected]fadc607b62011-02-07 17:55:50774}
775
776PrefService* TestingProfile::GetOffTheRecordPrefs() {
777 return NULL;
778}
779
[email protected]36fb2c7c2011-04-04 15:49:08780quota::SpecialStoragePolicy* TestingProfile::GetSpecialStoragePolicy() {
781 return GetExtensionSpecialStoragePolicy();
782}
783
[email protected]2609bc12010-01-24 08:32:55784void TestingProfile::DestroyWebDataService() {
785 if (!web_data_service_.get())
786 return;
787
788 web_data_service_->Shutdown();
789}
[email protected]a5add2c2011-02-14 23:54:47790
791DerivedTestingProfile::DerivedTestingProfile(Profile* profile)
792 : original_profile_(profile) {}
793
794DerivedTestingProfile::~DerivedTestingProfile() {}
795
796ProfileId DerivedTestingProfile::GetRuntimeId() {
797 return original_profile_->GetRuntimeId();
798}