blob: bf737f7f1e0cdc745fda5c3f6d7a9fce38f13bd2 [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
[email protected]a4ff9eae2011-08-01 19:58:165#include "chrome/test/base/testing_profile.h"
initial.commit09911bf2008-07-26 23:55:296
[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]a9afddb2009-02-12 17:49:4216#include "chrome/browser/bookmarks/bookmark_model.h"
[email protected]1459fb62011-05-25 19:03:2717#include "chrome/browser/browser_process.h"
[email protected]9d01a6a2010-11-30 12:03:3318#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]a6d36cc2011-02-23 00:39:4819#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
[email protected]2bb51302011-02-18 22:39:2720#include "chrome/browser/extensions/extension_pref_value_map.h"
[email protected]2f69b382011-02-19 00:34:2521#include "chrome/browser/extensions/extension_service.h"
[email protected]19eb80152011-02-26 00:28:4322#include "chrome/browser/extensions/extension_special_storage_policy.h"
[email protected]ee2ed42c2011-04-28 22:19:1423#include "chrome/browser/favicon/favicon_service.h"
[email protected]c476e632011-06-23 11:18:0424#include "chrome/browser/geolocation/chrome_geolocation_permission_context.h"
[email protected]dbbad7a2010-08-13 18:18:3625#include "chrome/browser/history/history.h"
[email protected]075ae732009-02-11 23:58:3126#include "chrome/browser/history/history_backend.h"
[email protected]dbbad7a2010-08-13 18:18:3627#include "chrome/browser/history/top_sites.h"
[email protected]8e4c29612010-07-14 01:24:4528#include "chrome/browser/net/gaia/token_service.h"
[email protected]cc5bfd42010-11-24 14:44:0229#include "chrome/browser/net/pref_proxy_config_service.h"
[email protected]dbbad7a2010-08-13 18:18:3630#include "chrome/browser/notifications/desktop_notification_service.h"
[email protected]dcb72d52011-04-13 12:36:5331#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]37858e52010-08-26 00:22:0232#include "chrome/browser/prefs/browser_prefs.h"
[email protected]9a8c4022011-01-25 14:25:3333#include "chrome/browser/prefs/testing_pref_store.h"
[email protected]4850a7f2011-03-08 23:36:5934#include "chrome/browser/prerender/prerender_manager.h"
[email protected]5cdcd152011-03-31 22:48:5235#include "chrome/browser/profiles/profile_dependency_manager.h"
[email protected]fb9d1f42010-10-06 23:17:5936#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]8e5c89a2011-06-07 18:13:3337#include "chrome/browser/search_engines/template_url_service.h"
38#include "chrome/browser/search_engines/template_url_service_factory.h"
[email protected]8238dd62011-09-29 15:13:0139#include "chrome/browser/speech/chrome_speech_input_preferences.h"
[email protected]4772b072010-03-30 17:45:4640#include "chrome/browser/sync/profile_sync_service_mock.h"
[email protected]45300ad42010-12-02 15:51:1441#include "chrome/browser/ui/find_bar/find_bar_state.h"
[email protected]fd42ac30f2011-02-27 19:33:3642#include "chrome/browser/ui/webui/chrome_url_data_manager.h"
[email protected]a9afddb2009-02-12 17:49:4243#include "chrome/common/chrome_constants.h"
[email protected]432115822011-07-10 15:52:2744#include "chrome/common/chrome_notification_types.h"
[email protected]9e33d7e2011-09-30 16:43:5445#include "chrome/common/chrome_switches.h"
[email protected]dbbad7a2010-08-13 18:18:3646#include "chrome/common/url_constants.h"
[email protected]7bc60682011-07-29 20:55:5947#include "chrome/test/base/bookmark_load_observer.h"
[email protected]aecb6ca2011-07-29 22:56:1448#include "chrome/test/base/test_url_request_context_getter.h"
[email protected]8ad3636e2011-08-01 22:31:4049#include "chrome/test/base/testing_pref_service.h"
[email protected]af44e7fb2011-07-29 18:32:3250#include "chrome/test/base/ui_test_utils.h"
[email protected]567812d2011-02-24 17:40:5051#include "content/browser/browser_thread.h"
52#include "content/browser/in_process_webkit/webkit_context.h"
[email protected]e89b77d2011-04-15 18:58:1053#include "content/browser/mock_resource_context.h"
[email protected]7f070d42011-03-09 20:25:3254#include "content/common/notification_service.h"
[email protected]dbbad7a2010-08-13 18:18:3655#include "net/base/cookie_monster.h"
[email protected]812b3a32010-01-08 05:36:0456#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:3457#include "net/url_request/url_request_context_getter.h"
[email protected]d2db0292011-01-26 20:23:4458#include "net/url_request/url_request_test_util.h"
[email protected]4772b072010-03-30 17:45:4659#include "testing/gmock/include/gmock/gmock.h"
[email protected]2f351cb2009-11-09 23:43:3460#include "webkit/database/database_tracker.h"
[email protected]de5480fa2011-05-26 22:07:3661#include "webkit/fileapi/file_system_context.h"
62#include "webkit/quota/quota_manager.h"
[email protected]94704172011-08-01 16:23:4063#include "webkit/quota/mock_quota_manager.h"
[email protected]248ce192011-02-10 15:26:3464
[email protected]e1acf6f2008-10-27 20:43:3365using base::Time;
[email protected]3c887412010-04-19 20:30:2366using testing::NiceMock;
[email protected]4772b072010-03-30 17:45:4667using testing::Return;
[email protected]e1acf6f2008-10-27 20:43:3368
[email protected]d364c652008-08-29 19:46:5669namespace {
70
[email protected]0bfc29a2009-04-27 16:15:4471// Task used to make sure history has finished processing a request. Intended
72// for use with BlockUntilHistoryProcessesPendingRequests.
73
74class QuittingHistoryDBTask : public HistoryDBTask {
75 public:
76 QuittingHistoryDBTask() {}
77
78 virtual bool RunOnDBThread(history::HistoryBackend* backend,
79 history::HistoryDatabase* db) {
80 return true;
81 }
82
83 virtual void DoneRunOnMainThread() {
84 MessageLoop::current()->Quit();
85 }
86
87 private:
[email protected]7991a232009-11-06 01:55:4888 ~QuittingHistoryDBTask() {}
89
[email protected]0bfc29a2009-04-27 16:15:4490 DISALLOW_COPY_AND_ASSIGN(QuittingHistoryDBTask);
91};
92
[email protected]aeb53f02011-01-15 00:21:3493class TestExtensionURLRequestContext : public net::URLRequestContext {
[email protected]c10da4b02010-03-25 14:38:3294 public:
95 TestExtensionURLRequestContext() {
96 net::CookieMonster* cookie_monster = new net::CookieMonster(NULL, NULL);
97 const char* schemes[] = {chrome::kExtensionScheme};
98 cookie_monster->SetCookieableSchemes(schemes, 1);
[email protected]f6c21cb2011-02-16 19:45:4199 set_cookie_store(cookie_monster);
[email protected]c10da4b02010-03-25 14:38:32100 }
101};
102
[email protected]abe2c032011-03-31 18:49:34103class TestExtensionURLRequestContextGetter
104 : public net::URLRequestContextGetter {
[email protected]c10da4b02010-03-25 14:38:32105 public:
[email protected]aeb53f02011-01-15 00:21:34106 virtual net::URLRequestContext* GetURLRequestContext() {
[email protected]c10da4b02010-03-25 14:38:32107 if (!context_)
108 context_ = new TestExtensionURLRequestContext();
109 return context_.get();
110 }
[email protected]00ed48f2010-10-22 22:19:24111 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const {
[email protected]0c7d74f2010-10-11 11:55:26112 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
[email protected]83a7d2eb2010-05-03 21:46:19113 }
[email protected]c10da4b02010-03-25 14:38:32114
115 private:
[email protected]aeb53f02011-01-15 00:21:34116 scoped_refptr<net::URLRequestContext> context_;
[email protected]c10da4b02010-03-25 14:38:32117};
118
[email protected]dcb72d52011-04-13 12:36:53119ProfileKeyedService* CreateTestDesktopNotificationService(Profile* profile) {
120 return new DesktopNotificationService(profile, NULL);
121}
122
[email protected]d364c652008-08-29 19:46:56123} // namespace
124
[email protected]f25387b2008-08-21 15:20:33125TestingProfile::TestingProfile()
[email protected]ea6f76572008-12-18 00:09:55126 : start_time_(Time::Now()),
[email protected]2fb7dc982010-09-29 12:24:28127 testing_prefs_(NULL),
[email protected]5bb2f522011-03-25 19:04:44128 incognito_(false),
[email protected]5cdcd152011-03-31 22:48:52129 last_session_exited_cleanly_(true),
130 profile_dependency_manager_(ProfileDependencyManager::GetInstance()) {
[email protected]f9dec9482010-08-20 20:42:19131 if (!temp_dir_.CreateUniqueTempDir()) {
132 LOG(ERROR) << "Failed to create unique temporary directory.";
initial.commit09911bf2008-07-26 23:55:29133
[email protected]f9dec9482010-08-20 20:42:19134 // Fallback logic in case we fail to create unique temporary directory.
135 FilePath system_tmp_dir;
136 bool success = PathService::Get(base::DIR_TEMP, &system_tmp_dir);
[email protected]848cd05e2008-09-19 18:33:48137
[email protected]f9dec9482010-08-20 20:42:19138 // We're severly screwed if we can't get the system temporary
139 // directory. Die now to avoid writing to the filesystem root
140 // or other bad places.
141 CHECK(success);
142
143 FilePath fallback_dir(system_tmp_dir.AppendASCII("TestingProfilePath"));
144 file_util::Delete(fallback_dir, true);
145 file_util::CreateDirectory(fallback_dir);
146 if (!temp_dir_.Set(fallback_dir)) {
147 // That shouldn't happen, but if it does, try to recover.
148 LOG(ERROR) << "Failed to use a fallback temporary directory.";
149
150 // We're screwed if this fails, see CHECK above.
151 CHECK(temp_dir_.Set(system_tmp_dir));
152 }
153 }
[email protected]dcb72d52011-04-13 12:36:53154
[email protected]49a25632011-08-31 17:03:48155 profile_path_ = temp_dir_.path();
156
157 Init();
158}
159
160TestingProfile::TestingProfile(const FilePath& path)
161 : start_time_(Time::Now()),
162 testing_prefs_(NULL),
163 incognito_(false),
164 last_session_exited_cleanly_(true),
165 profile_path_(path),
166 profile_dependency_manager_(ProfileDependencyManager::GetInstance()) {
167 Init();
168}
169
170void TestingProfile::Init() {
171 profile_dependency_manager_->CreateProfileServices(this, true);
172
[email protected]dcb72d52011-04-13 12:36:53173 // Install profile keyed service factory hooks for dummy/test services
[email protected]7722653b2011-06-03 17:28:22174 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory(
175 this, CreateTestDesktopNotificationService);
[email protected]12463cd2011-07-19 09:40:20176
177 NotificationService::current()->Notify(
178 chrome::NOTIFICATION_PROFILE_CREATED,
179 Source<Profile>(static_cast<Profile*>(this)),
180 NotificationService::NoDetails());
[email protected]ab23dbe2010-08-12 02:10:46181}
182
[email protected]f25387b2008-08-21 15:20:33183TestingProfile::~TestingProfile() {
[email protected]d2879af2010-02-08 16:02:56184 NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27185 chrome::NOTIFICATION_PROFILE_DESTROYED,
[email protected]5cdcd152011-03-31 22:48:52186 Source<Profile>(static_cast<Profile*>(this)),
[email protected]d2879af2010-02-08 16:02:56187 NotificationService::NoDetails());
[email protected]5cdcd152011-03-31 22:48:52188
189 profile_dependency_manager_->DestroyProfileServices(this);
190
[email protected]35552dc52011-07-12 09:04:38191 if (host_content_settings_map_)
192 host_content_settings_map_->ShutdownOnUIThread();
193
[email protected]809cc4d2010-10-27 15:22:54194 DestroyTopSites();
[email protected]f25387b2008-08-21 15:20:33195 DestroyHistoryService();
[email protected]d2879af2010-02-08 16:02:56196 // FaviconService depends on HistoryServce so destroying it later.
197 DestroyFaviconService();
[email protected]2609bc12010-01-24 08:32:55198 DestroyWebDataService();
[email protected]cdba46992011-06-07 11:51:39199
[email protected]cc5bfd42010-11-24 14:44:02200 if (pref_proxy_config_tracker_.get())
201 pref_proxy_config_tracker_->DetachFromPrefService();
[email protected]f25387b2008-08-21 15:20:33202}
initial.commit09911bf2008-07-26 23:55:29203
[email protected]d2879af2010-02-08 16:02:56204void TestingProfile::CreateFaviconService() {
[email protected]04732c0e2011-09-16 13:21:53205 favicon_service_.reset(new FaviconService(this));
[email protected]d2879af2010-02-08 16:02:56206}
207
[email protected]d486a0852009-11-02 21:40:00208void TestingProfile::CreateHistoryService(bool delete_file, bool no_db) {
[email protected]809cc4d2010-10-27 15:22:54209 DestroyHistoryService();
[email protected]f25387b2008-08-21 15:20:33210 if (delete_file) {
[email protected]f7011fcb2009-01-28 21:54:32211 FilePath path = GetPath();
212 path = path.Append(chrome::kHistoryFilename);
[email protected]f25387b2008-08-21 15:20:33213 file_util::Delete(path, false);
214 }
[email protected]90ef13132008-08-27 03:27:46215 history_service_ = new HistoryService(this);
[email protected]d486a0852009-11-02 21:40:00216 history_service_->Init(GetPath(), bookmark_bar_model_.get(), no_db);
initial.commit09911bf2008-07-26 23:55:29217}
218
219void TestingProfile::DestroyHistoryService() {
220 if (!history_service_.get())
221 return;
222
223 history_service_->NotifyRenderProcessHostDestruction(0);
224 history_service_->SetOnBackendDestroyTask(new MessageLoop::QuitTask);
225 history_service_->Cleanup();
226 history_service_ = NULL;
227
228 // Wait for the backend class to terminate before deleting the files and
229 // moving to the next test. Note: if this never terminates, somebody is
230 // probably leaking a reference to the history backend, so it never calls
231 // our destroy task.
232 MessageLoop::current()->Run();
233
initial.commit09911bf2008-07-26 23:55:29234 // Make sure we don't have any event pending that could disrupt the next
235 // test.
236 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask);
237 MessageLoop::current()->Run();
238}
[email protected]4d0cd7ce2008-08-11 16:40:57239
[email protected]809cc4d2010-10-27 15:22:54240void TestingProfile::CreateTopSites() {
241 DestroyTopSites();
242 top_sites_ = new history::TopSites(this);
[email protected]73c47932010-12-06 18:13:43243 FilePath file_name = GetPath().Append(chrome::kTopSitesFilename);
[email protected]809cc4d2010-10-27 15:22:54244 top_sites_->Init(file_name);
245}
246
247void TestingProfile::DestroyTopSites() {
248 if (top_sites_.get()) {
249 top_sites_->Shutdown();
250 top_sites_ = NULL;
251 // TopSites::Shutdown schedules some tasks (from TopSitesBackend) that need
252 // to be run to properly shutdown. Run all pending tasks now. This is
253 // normally handled by browser_process shutdown.
254 if (MessageLoop::current())
255 MessageLoop::current()->RunAllPending();
256 }
257}
258
259void TestingProfile::DestroyFaviconService() {
[email protected]04732c0e2011-09-16 13:21:53260 favicon_service_.reset();
[email protected]809cc4d2010-10-27 15:22:54261}
262
[email protected]d8e41ed2008-09-11 15:22:32263void TestingProfile::CreateBookmarkModel(bool delete_file) {
[email protected]90ef13132008-08-27 03:27:46264 // Nuke the model first, that way we're sure it's done writing to disk.
265 bookmark_bar_model_.reset(NULL);
266
267 if (delete_file) {
[email protected]f7011fcb2009-01-28 21:54:32268 FilePath path = GetPath();
269 path = path.Append(chrome::kBookmarksFileName);
[email protected]90ef13132008-08-27 03:27:46270 file_util::Delete(path, false);
271 }
[email protected]d8e41ed2008-09-11 15:22:32272 bookmark_bar_model_.reset(new BookmarkModel(this));
[email protected]90ef13132008-08-27 03:27:46273 if (history_service_.get()) {
274 history_service_->history_backend_->bookmark_service_ =
275 bookmark_bar_model_.get();
276 history_service_->history_backend_->expirer_.bookmark_service_ =
277 bookmark_bar_model_.get();
278 }
279 bookmark_bar_model_->Load();
[email protected]4d0cd7ce2008-08-11 16:40:57280}
[email protected]d2c017a2008-08-13 21:51:45281
[email protected]69c579e2010-04-23 20:01:00282void TestingProfile::CreateAutocompleteClassifier() {
283 autocomplete_classifier_.reset(new AutocompleteClassifier(this));
284}
285
[email protected]a6d36cc2011-02-23 00:39:48286void TestingProfile::CreateProtocolHandlerRegistry() {
[email protected]fd8ca522011-05-02 18:54:49287 protocol_handler_registry_ = new ProtocolHandlerRegistry(this,
288 new ProtocolHandlerRegistry::Delegate());
[email protected]a6d36cc2011-02-23 00:39:48289}
290
[email protected]2609bc12010-01-24 08:32:55291void TestingProfile::CreateWebDataService(bool delete_file) {
292 if (web_data_service_.get())
293 web_data_service_->Shutdown();
294
295 if (delete_file) {
296 FilePath path = GetPath();
297 path = path.Append(chrome::kWebDataFilename);
298 file_util::Delete(path, false);
299 }
300
301 web_data_service_ = new WebDataService;
302 if (web_data_service_.get())
303 web_data_service_->Init(GetPath());
304}
305
[email protected]d364c652008-08-29 19:46:56306void TestingProfile::BlockUntilBookmarkModelLoaded() {
307 DCHECK(bookmark_bar_model_.get());
308 if (bookmark_bar_model_->IsLoaded())
309 return;
310 BookmarkLoadObserver observer;
311 bookmark_bar_model_->AddObserver(&observer);
312 MessageLoop::current()->Run();
313 bookmark_bar_model_->RemoveObserver(&observer);
314 DCHECK(bookmark_bar_model_->IsLoaded());
315}
316
[email protected]120abf132011-09-27 21:38:06317// TODO(phajdan.jr): Doesn't this hang if Top Sites are already loaded?
[email protected]809cc4d2010-10-27 15:22:54318void TestingProfile::BlockUntilTopSitesLoaded() {
[email protected]120abf132011-09-27 21:38:06319 ui_test_utils::WindowedNotificationObserver top_sites_loaded_observer(
320 chrome::NOTIFICATION_TOP_SITES_LOADED,
321 NotificationService::AllSources());
[email protected]809cc4d2010-10-27 15:22:54322 if (!GetHistoryService(Profile::EXPLICIT_ACCESS))
323 GetTopSites()->HistoryLoaded();
[email protected]120abf132011-09-27 21:38:06324 top_sites_loaded_observer.Wait();
[email protected]809cc4d2010-10-27 15:22:54325}
326
[email protected]fb9d1f42010-10-06 23:17:59327void TestingProfile::CreateTemplateURLFetcher() {
328 template_url_fetcher_.reset(new TemplateURLFetcher(this));
329}
330
[email protected]8e5c89a2011-06-07 18:13:33331static ProfileKeyedService* BuildTemplateURLService(Profile* profile) {
332 return new TemplateURLService(profile);
[email protected]fb9d1f42010-10-06 23:17:59333}
334
[email protected]8e5c89a2011-06-07 18:13:33335void TestingProfile::CreateTemplateURLService() {
336 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
337 this, BuildTemplateURLService);
[email protected]d2c017a2008-08-13 21:51:45338}
[email protected]0bfc29a2009-04-27 16:15:44339
[email protected]9a8c4022011-01-25 14:25:33340ExtensionService* TestingProfile::CreateExtensionService(
[email protected]2fb7dc982010-09-29 12:24:28341 const CommandLine* command_line,
[email protected]90310d92011-04-17 07:35:04342 const FilePath& install_directory,
343 bool autoupdate_enabled) {
[email protected]9a8c4022011-01-25 14:25:33344 // Extension pref store, created for use by |extension_prefs_|.
345
346 extension_pref_value_map_.reset(new ExtensionPrefValueMap);
[email protected]9e33d7e2011-09-30 16:43:54347
348 bool extensions_disabled =
349 command_line && command_line->HasSwitch(switches::kDisableExtensions);
350
[email protected]9a8c4022011-01-25 14:25:33351 // Note that the GetPrefs() creates a TestingPrefService, therefore
352 // the extension controlled pref values set in extension_prefs_
353 // are not reflected in the pref service. One would need to
354 // inject a new ExtensionPrefStore(extension_pref_value_map_.get(), false).
355 extension_prefs_.reset(
356 new ExtensionPrefs(GetPrefs(),
357 install_directory,
358 extension_pref_value_map_.get()));
[email protected]9e33d7e2011-09-30 16:43:54359 extension_prefs_->Init(extensions_disabled);
[email protected]14908b72011-04-20 06:54:36360 extension_service_.reset(new ExtensionService(this,
361 command_line,
362 install_directory,
363 extension_prefs_.get(),
364 autoupdate_enabled,
365 true));
366 return extension_service_.get();
[email protected]2fb7dc982010-09-29 12:24:28367}
368
[email protected]f9dec9482010-08-20 20:42:19369FilePath TestingProfile::GetPath() {
[email protected]49a25632011-08-31 17:03:48370 return profile_path_;
[email protected]f9dec9482010-08-20 20:42:19371}
372
[email protected]dbbad7a2010-08-13 18:18:36373TestingPrefService* TestingProfile::GetTestingPrefService() {
[email protected]2fb7dc982010-09-29 12:24:28374 if (!prefs_.get())
375 CreateTestingPrefService();
376 DCHECK(testing_prefs_);
377 return testing_prefs_;
[email protected]dbbad7a2010-08-13 18:18:36378}
379
[email protected]8e5c89a2011-06-07 18:13:33380TestingProfile* TestingProfile::AsTestingProfile() {
381 return this;
382}
383
[email protected]29d70252011-04-28 02:16:58384std::string TestingProfile::GetProfileName() {
385 return std::string("testing_profile");
386}
387
[email protected]fadc607b62011-02-07 17:55:50388bool TestingProfile::IsOffTheRecord() {
[email protected]5bb2f522011-03-25 19:04:44389 return incognito_;
[email protected]fadc607b62011-02-07 17:55:50390}
391
[email protected]93dba942011-02-23 22:45:01392void TestingProfile::SetOffTheRecordProfile(Profile* profile) {
[email protected]5bb2f522011-03-25 19:04:44393 incognito_profile_.reset(profile);
[email protected]93dba942011-02-23 22:45:01394}
395
[email protected]fadc607b62011-02-07 17:55:50396Profile* TestingProfile::GetOffTheRecordProfile() {
[email protected]5bb2f522011-03-25 19:04:44397 return incognito_profile_.get();
[email protected]fadc607b62011-02-07 17:55:50398}
399
400bool TestingProfile::HasOffTheRecordProfile() {
[email protected]5bb2f522011-03-25 19:04:44401 return incognito_profile_.get() != NULL;
[email protected]fadc607b62011-02-07 17:55:50402}
403
404Profile* TestingProfile::GetOriginalProfile() {
405 return this;
406}
407
[email protected]2261e7b72011-07-12 13:43:55408void TestingProfile::SetAppCacheService(
409 ChromeAppCacheService* appcache_service) {
410 appcache_service_ = appcache_service;
411}
412
[email protected]fadc607b62011-02-07 17:55:50413ChromeAppCacheService* TestingProfile::GetAppCacheService() {
[email protected]2261e7b72011-07-12 13:43:55414 return appcache_service_.get();
[email protected]fadc607b62011-02-07 17:55:50415}
416
[email protected]2f351cb2009-11-09 23:43:34417webkit_database::DatabaseTracker* TestingProfile::GetDatabaseTracker() {
[email protected]19eb80152011-02-26 00:28:43418 if (!db_tracker_) {
419 db_tracker_ = new webkit_database::DatabaseTracker(
[email protected]800ad562011-07-08 08:00:50420 GetPath(), false, false, GetExtensionSpecialStoragePolicy(),
421 NULL, NULL);
[email protected]19eb80152011-02-26 00:28:43422 }
[email protected]2f351cb2009-11-09 23:43:34423 return db_tracker_;
424}
425
[email protected]fadc607b62011-02-07 17:55:50426VisitedLinkMaster* TestingProfile::GetVisitedLinkMaster() {
427 return NULL;
428}
429
[email protected]eaa7dd182010-12-14 11:09:00430ExtensionService* TestingProfile::GetExtensionService() {
[email protected]14908b72011-04-20 06:54:36431 return extension_service_.get();
[email protected]2fb7dc982010-09-29 12:24:28432}
433
[email protected]fadc607b62011-02-07 17:55:50434UserScriptMaster* TestingProfile::GetUserScriptMaster() {
435 return NULL;
436}
437
438ExtensionDevToolsManager* TestingProfile::GetExtensionDevToolsManager() {
439 return NULL;
440}
441
442ExtensionProcessManager* TestingProfile::GetExtensionProcessManager() {
443 return NULL;
444}
445
446ExtensionMessageService* TestingProfile::GetExtensionMessageService() {
447 return NULL;
448}
449
450ExtensionEventRouter* TestingProfile::GetExtensionEventRouter() {
451 return NULL;
452}
453
[email protected]2261e7b72011-07-12 13:43:55454void TestingProfile::SetExtensionSpecialStoragePolicy(
455 ExtensionSpecialStoragePolicy* extension_special_storage_policy) {
456 extension_special_storage_policy_ = extension_special_storage_policy;
457}
458
[email protected]19eb80152011-02-26 00:28:43459ExtensionSpecialStoragePolicy*
460TestingProfile::GetExtensionSpecialStoragePolicy() {
[email protected]cdba46992011-06-07 11:51:39461 if (!extension_special_storage_policy_.get())
[email protected]7c5048c2011-08-19 17:07:05462 extension_special_storage_policy_ = new ExtensionSpecialStoragePolicy(NULL);
[email protected]cdba46992011-06-07 11:51:39463 return extension_special_storage_policy_.get();
[email protected]19eb80152011-02-26 00:28:43464}
465
[email protected]fadc607b62011-02-07 17:55:50466SSLHostState* TestingProfile::GetSSLHostState() {
467 return NULL;
468}
469
[email protected]fadc607b62011-02-07 17:55:50470FaviconService* TestingProfile::GetFaviconService(ServiceAccessType access) {
471 return favicon_service_.get();
472}
473
474HistoryService* TestingProfile::GetHistoryService(ServiceAccessType access) {
475 return history_service_.get();
476}
477
478HistoryService* TestingProfile::GetHistoryServiceWithoutCreating() {
479 return history_service_.get();
480}
481
[email protected]dbbad7a2010-08-13 18:18:36482net::CookieMonster* TestingProfile::GetCookieMonster() {
483 if (!GetRequestContext())
484 return NULL;
[email protected]277ec262011-03-30 21:09:40485 return GetRequestContext()->GetURLRequestContext()->cookie_store()->
486 GetCookieMonster();
[email protected]dbbad7a2010-08-13 18:18:36487}
488
[email protected]fadc607b62011-02-07 17:55:50489AutocompleteClassifier* TestingProfile::GetAutocompleteClassifier() {
490 return autocomplete_classifier_.get();
491}
492
[email protected]c620fd52011-07-22 18:33:29493history::ShortcutsBackend* TestingProfile::GetShortcutsBackend() {
494 return NULL;
495}
496
[email protected]fadc607b62011-02-07 17:55:50497WebDataService* TestingProfile::GetWebDataService(ServiceAccessType access) {
498 return web_data_service_.get();
499}
500
501WebDataService* TestingProfile::GetWebDataServiceWithoutCreating() {
502 return web_data_service_.get();
503}
504
505PasswordStore* TestingProfile::GetPasswordStore(ServiceAccessType access) {
506 return NULL;
507}
508
[email protected]2fb7dc982010-09-29 12:24:28509void TestingProfile::SetPrefService(PrefService* prefs) {
510 DCHECK(!prefs_.get());
511 prefs_.reset(prefs);
512}
513
514void TestingProfile::CreateTestingPrefService() {
515 DCHECK(!prefs_.get());
516 testing_prefs_ = new TestingPrefService();
517 prefs_.reset(testing_prefs_);
518 Profile::RegisterUserPrefs(prefs_.get());
[email protected]2f9d81322011-02-21 09:55:43519 browser::RegisterUserPrefs(prefs_.get());
[email protected]2fb7dc982010-09-29 12:24:28520}
521
[email protected]dbbad7a2010-08-13 18:18:36522PrefService* TestingProfile::GetPrefs() {
523 if (!prefs_.get()) {
[email protected]2fb7dc982010-09-29 12:24:28524 CreateTestingPrefService();
[email protected]dbbad7a2010-08-13 18:18:36525 }
526 return prefs_.get();
527}
528
[email protected]fadc607b62011-02-07 17:55:50529TemplateURLFetcher* TestingProfile::GetTemplateURLFetcher() {
530 return template_url_fetcher_.get();
531}
532
[email protected]dbbad7a2010-08-13 18:18:36533history::TopSites* TestingProfile::GetTopSites() {
[email protected]809cc4d2010-10-27 15:22:54534 return top_sites_.get();
[email protected]dbbad7a2010-08-13 18:18:36535}
536
[email protected]fadc607b62011-02-07 17:55:50537history::TopSites* TestingProfile::GetTopSitesWithoutCreating() {
538 return top_sites_.get();
539}
540
541DownloadManager* TestingProfile::GetDownloadManager() {
542 return NULL;
543}
544
[email protected]397281f2011-02-14 05:15:53545fileapi::FileSystemContext* TestingProfile::GetFileSystemContext() {
[email protected]de5480fa2011-05-26 22:07:36546 if (!file_system_context_) {
547 file_system_context_ = new fileapi::FileSystemContext(
548 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE),
549 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
550 GetExtensionSpecialStoragePolicy(),
551 NULL,
552 GetPath(),
553 IsOffTheRecord(),
554 true, // Allow file access from files.
[email protected]de5480fa2011-05-26 22:07:36555 NULL);
556 }
557 return file_system_context_.get();
[email protected]fadc607b62011-02-07 17:55:50558}
559
[email protected]94704172011-08-01 16:23:40560void TestingProfile::SetQuotaManager(quota::QuotaManager* manager) {
561 quota_manager_ = manager;
562}
563
[email protected]595765c2011-04-27 13:20:14564quota::QuotaManager* TestingProfile::GetQuotaManager() {
[email protected]94704172011-08-01 16:23:40565 return quota_manager_.get();
[email protected]595765c2011-04-27 13:20:14566}
567
[email protected]fadc607b62011-02-07 17:55:50568bool TestingProfile::HasCreatedDownloadManager() const {
569 return false;
570}
571
[email protected]abe2c032011-03-31 18:49:34572net::URLRequestContextGetter* TestingProfile::GetRequestContext() {
[email protected]812b3a32010-01-08 05:36:04573 return request_context_.get();
574}
575
[email protected]da5683db2011-04-23 17:12:21576net::URLRequestContextGetter* TestingProfile::GetRequestContextForRenderProcess(
577 int renderer_child_id) {
578 if (extension_service_.get()) {
579 const Extension* installed_app = extension_service_->
580 GetInstalledAppForRenderer(renderer_child_id);
581 if (installed_app != NULL && installed_app->is_storage_isolated())
582 return GetRequestContextForIsolatedApp(installed_app->id());
583 }
[email protected]d9696672011-03-15 22:45:09584
585 return GetRequestContext();
586}
587
[email protected]812b3a32010-01-08 05:36:04588void TestingProfile::CreateRequestContext() {
589 if (!request_context_)
590 request_context_ = new TestURLRequestContextGetter();
591}
592
[email protected]7c893202010-10-07 20:18:02593void TestingProfile::ResetRequestContext() {
594 request_context_ = NULL;
595}
596
[email protected]abe2c032011-03-31 18:49:34597net::URLRequestContextGetter* TestingProfile::GetRequestContextForMedia() {
[email protected]fadc607b62011-02-07 17:55:50598 return NULL;
599}
600
[email protected]abe2c032011-03-31 18:49:34601net::URLRequestContextGetter* TestingProfile::GetRequestContextForExtensions() {
[email protected]c10da4b02010-03-25 14:38:32602 if (!extensions_request_context_)
603 extensions_request_context_ = new TestExtensionURLRequestContextGetter();
604 return extensions_request_context_.get();
605}
606
[email protected]fadc607b62011-02-07 17:55:50607net::SSLConfigService* TestingProfile::GetSSLConfigService() {
608 return NULL;
609}
610
611UserStyleSheetWatcher* TestingProfile::GetUserStyleSheetWatcher() {
612 return NULL;
613}
614
[email protected]abe2c032011-03-31 18:49:34615net::URLRequestContextGetter* TestingProfile::GetRequestContextForIsolatedApp(
[email protected]d9696672011-03-15 22:45:09616 const std::string& app_id) {
617 // We don't test isolated app storage here yet, so returning the same dummy
618 // context is sufficient for now.
619 return GetRequestContext();
620}
621
[email protected]e89b77d2011-04-15 18:58:10622const content::ResourceContext& TestingProfile::GetResourceContext() {
[email protected]0d9f6f02011-07-08 23:11:21623 return *content::MockResourceContext::GetInstance();
[email protected]e89b77d2011-04-15 18:58:10624}
625
[email protected]dbbad7a2010-08-13 18:18:36626FindBarState* TestingProfile::GetFindBarState() {
627 if (!find_bar_state_.get())
628 find_bar_state_.reset(new FindBarState());
629 return find_bar_state_.get();
630}
631
632HostContentSettingsMap* TestingProfile::GetHostContentSettingsMap() {
[email protected]35552dc52011-07-12 09:04:38633 if (!host_content_settings_map_.get()) {
634 host_content_settings_map_ = new HostContentSettingsMap(
635 GetPrefs(), GetExtensionService(), false);
636 }
[email protected]dbbad7a2010-08-13 18:18:36637 return host_content_settings_map_.get();
638}
639
[email protected]dbbad7a2010-08-13 18:18:36640GeolocationPermissionContext*
641TestingProfile::GetGeolocationPermissionContext() {
642 if (!geolocation_permission_context_.get()) {
643 geolocation_permission_context_ =
[email protected]c476e632011-06-23 11:18:04644 new ChromeGeolocationPermissionContext(this);
[email protected]dbbad7a2010-08-13 18:18:36645 }
646 return geolocation_permission_context_.get();
647}
648
[email protected]8238dd62011-09-29 15:13:01649SpeechInputPreferences* TestingProfile::GetSpeechInputPreferences() {
650 if (!speech_input_preferences_.get())
651 speech_input_preferences_ = new ChromeSpeechInputPreferences(GetPrefs());
652 return speech_input_preferences_.get();
653}
654
[email protected]fadc607b62011-02-07 17:55:50655HostZoomMap* TestingProfile::GetHostZoomMap() {
656 return NULL;
657}
658
[email protected]fadc607b62011-02-07 17:55:50659bool TestingProfile::HasProfileSyncService() const {
660 return (profile_sync_service_.get() != NULL);
661}
662
663std::wstring TestingProfile::GetName() {
664 return std::wstring();
665}
666
667std::wstring TestingProfile::GetID() {
668 return id_;
669}
670
671void TestingProfile::SetID(const std::wstring& id) {
672 id_ = id;
673}
674
675bool TestingProfile::DidLastSessionExitCleanly() {
676 return last_session_exited_cleanly_;
677}
678
679BookmarkModel* TestingProfile::GetBookmarkModel() {
680 return bookmark_bar_model_.get();
681}
682
683bool TestingProfile::IsSameProfile(Profile *p) {
684 return this == p;
685}
686
687base::Time TestingProfile::GetStartTime() const {
688 return start_time_;
689}
690
[email protected]a6d36cc2011-02-23 00:39:48691ProtocolHandlerRegistry* TestingProfile::GetProtocolHandlerRegistry() {
692 return protocol_handler_registry_.get();
693}
694
[email protected]fadc607b62011-02-07 17:55:50695SpellCheckHost* TestingProfile::GetSpellCheckHost() {
696 return NULL;
697}
698
[email protected]dbbad7a2010-08-13 18:18:36699WebKitContext* TestingProfile::GetWebKitContext() {
[email protected]228d06592011-04-01 20:38:59700 if (webkit_context_ == NULL) {
701 webkit_context_ = new WebKitContext(
702 IsOffTheRecord(), GetPath(),
703 GetExtensionSpecialStoragePolicy(),
[email protected]ba7c5152011-06-03 19:43:28704 false, NULL, NULL);
[email protected]228d06592011-04-01 20:38:59705 }
[email protected]dbbad7a2010-08-13 18:18:36706 return webkit_context_;
707}
708
[email protected]fadc607b62011-02-07 17:55:50709WebKitContext* TestingProfile::GetOffTheRecordWebKitContext() {
710 return NULL;
711}
712
[email protected]fadc607b62011-02-07 17:55:50713FilePath TestingProfile::last_selected_directory() {
714 return last_selected_directory_;
715}
716
717void TestingProfile::set_last_selected_directory(const FilePath& path) {
718 last_selected_directory_ = path;
719}
720
[email protected]cc5bfd42010-11-24 14:44:02721PrefProxyConfigTracker* TestingProfile::GetProxyConfigTracker() {
722 if (!pref_proxy_config_tracker_)
723 pref_proxy_config_tracker_ = new PrefProxyConfigTracker(GetPrefs());
724
725 return pref_proxy_config_tracker_;
726}
727
[email protected]0bfc29a2009-04-27 16:15:44728void TestingProfile::BlockUntilHistoryProcessesPendingRequests() {
729 DCHECK(history_service_.get());
730 DCHECK(MessageLoop::current());
731
732 CancelableRequestConsumer consumer;
733 history_service_->ScheduleDBTask(new QuittingHistoryDBTask(), &consumer);
734 MessageLoop::current()->Run();
735}
[email protected]345a8b72009-09-29 09:11:44736
[email protected]8e4c29612010-07-14 01:24:45737TokenService* TestingProfile::GetTokenService() {
738 if (!token_service_.get()) {
739 token_service_.reset(new TokenService());
740 }
741 return token_service_.get();
742}
743
[email protected]345a8b72009-09-29 09:11:44744ProfileSyncService* TestingProfile::GetProfileSyncService() {
[email protected]e8234d32010-09-09 20:36:39745 return GetProfileSyncService("");
746}
747
748ProfileSyncService* TestingProfile::GetProfileSyncService(
749 const std::string& cros_user) {
[email protected]4772b072010-03-30 17:45:46750 if (!profile_sync_service_.get()) {
[email protected]3c887412010-04-19 20:30:23751 // Use a NiceMock here since we are really using the mock as a
752 // fake. Test cases that want to set expectations on a
753 // ProfileSyncService should use the ProfileMock and have this
754 // method return their own mock instance.
755 profile_sync_service_.reset(new NiceMock<ProfileSyncServiceMock>());
[email protected]4772b072010-03-30 17:45:46756 }
[email protected]345a8b72009-09-29 09:11:44757 return profile_sync_service_.get();
[email protected]345a8b72009-09-29 09:11:44758}
[email protected]2609bc12010-01-24 08:32:55759
[email protected]fadc607b62011-02-07 17:55:50760ChromeBlobStorageContext* TestingProfile::GetBlobStorageContext() {
761 return NULL;
762}
763
764ExtensionInfoMap* TestingProfile::GetExtensionInfoMap() {
765 return NULL;
766}
767
768PromoCounter* TestingProfile::GetInstantPromoCounter() {
769 return NULL;
770}
771
[email protected]248ce192011-02-10 15:26:34772ChromeURLDataManager* TestingProfile::GetChromeURLDataManager() {
773 if (!chrome_url_data_manager_.get())
[email protected]63e26822011-07-16 19:07:35774 chrome_url_data_manager_.reset(
775 new ChromeURLDataManager(
776 base::Callback<ChromeURLDataManagerBackend*(void)>()));
[email protected]248ce192011-02-10 15:26:34777 return chrome_url_data_manager_.get();
778}
779
[email protected]ada01b92011-09-07 21:01:39780prerender::PrerenderManager* TestingProfile::GetPrerenderManager() {
781 if (!prerender::PrerenderManager::IsPrerenderingPossible())
782 return NULL;
783 if (!prerender_manager_.get()) {
784 prerender_manager_.reset(new prerender::PrerenderManager(
785 this, g_browser_process->prerender_tracker()));
786 }
787 return prerender_manager_.get();
788}
789
[email protected]d7e601b2011-09-14 19:13:53790void TestingProfile::SetDownloadManagerDelegate(
791 ChromeDownloadManagerDelegate* delegate) {
792 // Specially marked so errors from use will occur near to the site
793 // of the error.
794 NOTIMPLEMENTED();
795}
796
[email protected]8382d8c2011-09-15 03:43:17797chrome_browser_net::Predictor* TestingProfile::GetNetworkPredictor() {
798 return NULL;
799}
800
[email protected]02896a82011-09-21 18:54:32801void TestingProfile::DeleteTransportSecurityStateSince(base::Time time) {
802 NOTIMPLEMENTED();
803}
804
[email protected]fadc607b62011-02-07 17:55:50805PrefService* TestingProfile::GetOffTheRecordPrefs() {
806 return NULL;
807}
808
[email protected]36fb2c7c2011-04-04 15:49:08809quota::SpecialStoragePolicy* TestingProfile::GetSpecialStoragePolicy() {
810 return GetExtensionSpecialStoragePolicy();
811}
812
[email protected]2609bc12010-01-24 08:32:55813void TestingProfile::DestroyWebDataService() {
814 if (!web_data_service_.get())
815 return;
816
817 web_data_service_->Shutdown();
818}