blob: 75f27cef311d12526634bb1ef169e9a4adf4ad3c [file] [log] [blame]
[email protected]e7e46732012-01-05 11:45:551// Copyright (c) 2012 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]03b9b4e2012-10-22 20:01:5214#include "base/prefs/testing_pref_store.h"
[email protected]8e937c1e2012-06-28 22:57:3015#include "base/run_loop.h"
[email protected]3ea1b182013-02-08 22:38:4116#include "base/strings/string_number_conversions.h"
[email protected]dbbad7a2010-08-13 18:18:3617#include "chrome/browser/autocomplete/autocomplete_classifier.h"
[email protected]a9afddb2009-02-12 17:49:4218#include "chrome/browser/bookmarks/bookmark_model.h"
[email protected]f61f4782012-06-08 21:54:2119#include "chrome/browser/bookmarks/bookmark_model_factory.h"
[email protected]1459fb62011-05-25 19:03:2720#include "chrome/browser/browser_process.h"
[email protected]9d01a6a2010-11-30 12:03:3321#include "chrome/browser/content_settings/host_content_settings_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]31d8f5f22012-04-02 15:22:0824#include "chrome/browser/extensions/extension_system.h"
25#include "chrome/browser/extensions/extension_system_factory.h"
26#include "chrome/browser/extensions/test_extension_system.h"
[email protected]ee2ed42c2011-04-28 22:19:1427#include "chrome/browser/favicon/favicon_service.h"
[email protected]f3d2b312012-08-23 22:27:5928#include "chrome/browser/favicon/favicon_service_factory.h"
[email protected]c476e632011-06-23 11:18:0429#include "chrome/browser/geolocation/chrome_geolocation_permission_context.h"
[email protected]b2cf4522012-10-23 00:11:5730#include "chrome/browser/geolocation/chrome_geolocation_permission_context_factory.h"
[email protected]075ae732009-02-11 23:58:3131#include "chrome/browser/history/history_backend.h"
[email protected]d891f522013-02-08 03:24:4132#include "chrome/browser/history/history_db_task.h"
[email protected]6a2c09f2013-01-25 04:50:0733#include "chrome/browser/history/history_service.h"
[email protected]f61f4782012-06-08 21:54:2134#include "chrome/browser/history/history_service_factory.h"
[email protected]572f40c9b2012-07-06 20:35:3335#include "chrome/browser/history/shortcuts_backend.h"
36#include "chrome/browser/history/shortcuts_backend_factory.h"
[email protected]dbbad7a2010-08-13 18:18:3637#include "chrome/browser/history/top_sites.h"
[email protected]6f96cbcb2011-11-04 02:26:0738#include "chrome/browser/net/proxy_service_factory.h"
[email protected]dbbad7a2010-08-13 18:18:3639#include "chrome/browser/notifications/desktop_notification_service.h"
[email protected]dcb72d52011-04-13 12:36:5340#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]37858e52010-08-26 00:22:0241#include "chrome/browser/prefs/browser_prefs.h"
[email protected]c753f142013-02-10 13:14:0442#include "chrome/browser/prefs/pref_service_syncable.h"
[email protected]4850a7f2011-03-08 23:36:5943#include "chrome/browser/prerender/prerender_manager.h"
[email protected]5cdcd152011-03-31 22:48:5244#include "chrome/browser/profiles/profile_dependency_manager.h"
[email protected]27ddfed22012-10-30 23:22:4345#include "chrome/browser/profiles/storage_partition_descriptor.h"
[email protected]16bd088b2012-04-03 08:12:1246#include "chrome/browser/search_engines/template_url_fetcher_factory.h"
[email protected]c52b2892012-03-07 11:01:0247#include "chrome/browser/speech/chrome_speech_recognition_preferences.h"
[email protected]810ffba2012-06-12 01:07:4848#include "chrome/browser/webdata/web_data_service.h"
[email protected]d07edd42012-05-14 23:49:4649#include "chrome/browser/webdata/web_data_service_factory.h"
[email protected]a9afddb2009-02-12 17:49:4250#include "chrome/common/chrome_constants.h"
[email protected]432115822011-07-10 15:52:2751#include "chrome/common/chrome_notification_types.h"
[email protected]9e33d7e2011-09-30 16:43:5452#include "chrome/common/chrome_switches.h"
[email protected]dbbad7a2010-08-13 18:18:3653#include "chrome/common/url_constants.h"
[email protected]7bc60682011-07-29 20:55:5954#include "chrome/test/base/bookmark_load_observer.h"
[email protected]18a15ca82012-08-30 00:28:1655#include "chrome/test/base/history_index_restore_observer.h"
[email protected]7688968a2013-02-12 21:45:1356#include "chrome/test/base/testing_pref_service_syncable.h"
[email protected]af44e7fb2011-07-29 18:32:3257#include "chrome/test/base/ui_test_utils.h"
[email protected]c38831a12011-10-28 12:44:4958#include "content/public/browser/browser_thread.h"
[email protected]ad50def52011-10-19 23:17:0759#include "content/public/browser/notification_service.h"
[email protected]fb29e6cf2012-07-12 21:27:2060#include "content/public/browser/render_process_host.h"
[email protected]885c0e92012-11-13 20:27:4261#include "content/public/browser/storage_partition.h"
[email protected]08a932d52012-06-03 21:42:1262#include "content/public/test/mock_resource_context.h"
[email protected]a7fe9112012-07-20 02:34:4563#include "content/public/test/test_utils.h"
[email protected]885c0e92012-11-13 20:27:4264#include "extensions/common/constants.h"
[email protected]aa84a7e2012-03-15 21:29:0665#include "net/cookies/cookie_monster.h"
[email protected]812b3a32010-01-08 05:36:0466#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:3467#include "net/url_request/url_request_context_getter.h"
[email protected]d2db0292011-01-26 20:23:4468#include "net/url_request/url_request_test_util.h"
[email protected]4772b072010-03-30 17:45:4669#include "testing/gmock/include/gmock/gmock.h"
[email protected]248ce192011-02-10 15:26:3470
[email protected]21d3a882012-05-31 14:41:5571#if defined(ENABLE_CONFIGURATION_POLICY)
72#include "chrome/browser/policy/policy_service_impl.h"
73#else
74#include "chrome/browser/policy/policy_service_stub.h"
75#endif // defined(ENABLE_CONFIGURATION_POLICY)
76
[email protected]6f96cbcb2011-11-04 02:26:0777#if defined(OS_CHROMEOS)
78#include "chrome/browser/chromeos/proxy_config_service_impl.h"
79#endif // defined(OS_CHROMEOS)
80
[email protected]e1acf6f2008-10-27 20:43:3381using base::Time;
[email protected]631bb742011-11-02 11:29:3982using content::BrowserThread;
[email protected]b441a8492012-06-06 14:55:5783using content::DownloadManagerDelegate;
[email protected]3c887412010-04-19 20:30:2384using testing::NiceMock;
[email protected]4772b072010-03-30 17:45:4685using testing::Return;
[email protected]e1acf6f2008-10-27 20:43:3386
[email protected]d364c652008-08-29 19:46:5687namespace {
88
[email protected]0bfc29a2009-04-27 16:15:4489// Task used to make sure history has finished processing a request. Intended
90// for use with BlockUntilHistoryProcessesPendingRequests.
91
[email protected]d891f522013-02-08 03:24:4192class QuittingHistoryDBTask : public history::HistoryDBTask {
[email protected]0bfc29a2009-04-27 16:15:4493 public:
94 QuittingHistoryDBTask() {}
95
96 virtual bool RunOnDBThread(history::HistoryBackend* backend,
[email protected]be9826e62013-02-07 02:00:5897 history::HistoryDatabase* db) OVERRIDE {
[email protected]0bfc29a2009-04-27 16:15:4498 return true;
99 }
100
[email protected]be9826e62013-02-07 02:00:58101 virtual void DoneRunOnMainThread() OVERRIDE {
[email protected]0bfc29a2009-04-27 16:15:44102 MessageLoop::current()->Quit();
103 }
104
105 private:
[email protected]be9826e62013-02-07 02:00:58106 virtual ~QuittingHistoryDBTask() {}
[email protected]7991a232009-11-06 01:55:48107
[email protected]0bfc29a2009-04-27 16:15:44108 DISALLOW_COPY_AND_ASSIGN(QuittingHistoryDBTask);
109};
110
[email protected]aeb53f02011-01-15 00:21:34111class TestExtensionURLRequestContext : public net::URLRequestContext {
[email protected]c10da4b02010-03-25 14:38:32112 public:
113 TestExtensionURLRequestContext() {
114 net::CookieMonster* cookie_monster = new net::CookieMonster(NULL, NULL);
[email protected]885c0e92012-11-13 20:27:42115 const char* schemes[] = {extensions::kExtensionScheme};
[email protected]c10da4b02010-03-25 14:38:32116 cookie_monster->SetCookieableSchemes(schemes, 1);
[email protected]f6c21cb2011-02-16 19:45:41117 set_cookie_store(cookie_monster);
[email protected]c10da4b02010-03-25 14:38:32118 }
[email protected]7b2720b2012-04-25 16:59:11119
[email protected]7b2720b2012-04-25 16:59:11120 virtual ~TestExtensionURLRequestContext() {}
[email protected]c10da4b02010-03-25 14:38:32121};
122
[email protected]abe2c032011-03-31 18:49:34123class TestExtensionURLRequestContextGetter
124 : public net::URLRequestContextGetter {
[email protected]c10da4b02010-03-25 14:38:32125 public:
[email protected]be9826e62013-02-07 02:00:58126 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE {
[email protected]ef2bf422012-05-11 03:27:09127 if (!context_.get())
128 context_.reset(new TestExtensionURLRequestContext());
[email protected]c10da4b02010-03-25 14:38:32129 return context_.get();
130 }
[email protected]4969b0122012-06-16 01:58:28131 virtual scoped_refptr<base::SingleThreadTaskRunner>
132 GetNetworkTaskRunner() const OVERRIDE {
[email protected]0c7d74f2010-10-11 11:55:26133 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
[email protected]83a7d2eb2010-05-03 21:46:19134 }
[email protected]c10da4b02010-03-25 14:38:32135
[email protected]13ed17f82012-04-06 02:27:18136 protected:
137 virtual ~TestExtensionURLRequestContextGetter() {}
138
[email protected]c10da4b02010-03-25 14:38:32139 private:
[email protected]ef2bf422012-05-11 03:27:09140 scoped_ptr<net::URLRequestContext> context_;
[email protected]c10da4b02010-03-25 14:38:32141};
142
[email protected]abc77242012-03-16 04:32:31143ProfileKeyedService* CreateTestDesktopNotificationService(Profile* profile) {
[email protected]29cebbd2012-06-06 21:43:42144#if defined(ENABLE_NOTIFICATIONS)
[email protected]dcb72d52011-04-13 12:36:53145 return new DesktopNotificationService(profile, NULL);
[email protected]29cebbd2012-06-06 21:43:42146#else
147 return NULL;
148#endif
[email protected]dcb72d52011-04-13 12:36:53149}
150
[email protected]d364c652008-08-29 19:46:56151} // namespace
152
[email protected]89dbb1772012-07-17 13:47:25153// static
154#if defined(OS_CHROMEOS)
155// Must be kept in sync with
156// ChromeBrowserMainPartsChromeos::PreEarlyInitialization.
157const char TestingProfile::kTestUserProfileDir[] = "test-user";
158#else
159const char TestingProfile::kTestUserProfileDir[] = "Default";
160#endif
161
[email protected]f25387b2008-08-21 15:20:33162TestingProfile::TestingProfile()
[email protected]ea6f76572008-12-18 00:09:55163 : start_time_(Time::Now()),
[email protected]2fb7dc982010-09-29 12:24:28164 testing_prefs_(NULL),
[email protected]5bb2f522011-03-25 19:04:44165 incognito_(false),
[email protected]074311a2013-02-28 23:14:09166 original_profile_(NULL),
[email protected]5cdcd152011-03-31 22:48:52167 last_session_exited_cleanly_(true),
[email protected]537c1082011-12-02 02:37:17168 profile_dependency_manager_(ProfileDependencyManager::GetInstance()),
169 delegate_(NULL) {
[email protected]5c4c89f2012-08-07 21:09:59170 CreateTempProfileDir();
[email protected]49a25632011-08-31 17:03:48171 profile_path_ = temp_dir_.path();
172
173 Init();
[email protected]537c1082011-12-02 02:37:17174 FinishInit();
[email protected]49a25632011-08-31 17:03:48175}
176
[email protected]152ea302013-02-11 04:08:40177TestingProfile::TestingProfile(const base::FilePath& path)
[email protected]49a25632011-08-31 17:03:48178 : start_time_(Time::Now()),
179 testing_prefs_(NULL),
180 incognito_(false),
[email protected]074311a2013-02-28 23:14:09181 original_profile_(NULL),
[email protected]49a25632011-08-31 17:03:48182 last_session_exited_cleanly_(true),
183 profile_path_(path),
[email protected]537c1082011-12-02 02:37:17184 profile_dependency_manager_(ProfileDependencyManager::GetInstance()),
185 delegate_(NULL) {
[email protected]49a25632011-08-31 17:03:48186 Init();
[email protected]537c1082011-12-02 02:37:17187 FinishInit();
188}
189
[email protected]152ea302013-02-11 04:08:40190TestingProfile::TestingProfile(const base::FilePath& path,
[email protected]537c1082011-12-02 02:37:17191 Delegate* delegate)
192 : start_time_(Time::Now()),
193 testing_prefs_(NULL),
194 incognito_(false),
[email protected]074311a2013-02-28 23:14:09195 original_profile_(NULL),
[email protected]537c1082011-12-02 02:37:17196 last_session_exited_cleanly_(true),
197 profile_path_(path),
198 profile_dependency_manager_(ProfileDependencyManager::GetInstance()),
199 delegate_(delegate) {
200 Init();
201 if (delegate_) {
202 MessageLoop::current()->PostTask(FROM_HERE,
203 base::Bind(&TestingProfile::FinishInit,
204 base::Unretained(this)));
205 } else {
206 FinishInit();
207 }
[email protected]49a25632011-08-31 17:03:48208}
209
[email protected]5c4c89f2012-08-07 21:09:59210TestingProfile::TestingProfile(
[email protected]152ea302013-02-11 04:08:40211 const base::FilePath& path,
[email protected]5c4c89f2012-08-07 21:09:59212 Delegate* delegate,
213 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy,
[email protected]a0cc9a532013-02-12 02:23:12214 scoped_ptr<PrefServiceSyncable> prefs)
[email protected]5c4c89f2012-08-07 21:09:59215 : start_time_(Time::Now()),
216 prefs_(prefs.release()),
217 testing_prefs_(NULL),
[email protected]a0cc9a532013-02-12 02:23:12218 incognito_(false),
[email protected]074311a2013-02-28 23:14:09219 original_profile_(NULL),
[email protected]5c4c89f2012-08-07 21:09:59220 last_session_exited_cleanly_(true),
221 extension_special_storage_policy_(extension_policy),
[email protected]5c4c89f2012-08-07 21:09:59222 profile_path_(path),
223 profile_dependency_manager_(ProfileDependencyManager::GetInstance()),
224 delegate_(delegate) {
225
226 // If no profile path was supplied, create one.
227 if (profile_path_.empty()) {
228 CreateTempProfileDir();
229 profile_path_ = temp_dir_.path();
230 }
231
232 Init();
233 // If caller supplied a delegate, delay the FinishInit invocation until other
234 // tasks have run.
235 // TODO(atwilson): See if this is still required once we convert the current
236 // users of the constructor that takes a Delegate* param.
237 if (delegate_) {
238 MessageLoop::current()->PostTask(FROM_HERE,
239 base::Bind(&TestingProfile::FinishInit,
240 base::Unretained(this)));
241 } else {
242 FinishInit();
243 }
244}
245
246void TestingProfile::CreateTempProfileDir() {
247 if (!temp_dir_.CreateUniqueTempDir()) {
248 LOG(ERROR) << "Failed to create unique temporary directory.";
249
250 // Fallback logic in case we fail to create unique temporary directory.
[email protected]152ea302013-02-11 04:08:40251 base::FilePath system_tmp_dir;
[email protected]5c4c89f2012-08-07 21:09:59252 bool success = PathService::Get(base::DIR_TEMP, &system_tmp_dir);
253
254 // We're severly screwed if we can't get the system temporary
255 // directory. Die now to avoid writing to the filesystem root
256 // or other bad places.
257 CHECK(success);
258
[email protected]152ea302013-02-11 04:08:40259 base::FilePath fallback_dir(
260 system_tmp_dir.AppendASCII("TestingProfilePath"));
[email protected]5c4c89f2012-08-07 21:09:59261 file_util::Delete(fallback_dir, true);
262 file_util::CreateDirectory(fallback_dir);
263 if (!temp_dir_.Set(fallback_dir)) {
264 // That shouldn't happen, but if it does, try to recover.
265 LOG(ERROR) << "Failed to use a fallback temporary directory.";
266
267 // We're screwed if this fails, see CHECK above.
268 CHECK(temp_dir_.Set(system_tmp_dir));
269 }
270 }
271}
272
[email protected]49a25632011-08-31 17:03:48273void TestingProfile::Init() {
[email protected]d41e6572012-05-04 20:49:42274 if (!file_util::PathExists(profile_path_))
275 file_util::CreateDirectory(profile_path_);
276
[email protected]bd306722012-07-11 20:43:59277 extensions::ExtensionSystemFactory::GetInstance()->SetTestingFactory(
278 this, extensions::TestExtensionSystem::Build);
[email protected]31d8f5f22012-04-02 15:22:08279
[email protected]49a25632011-08-31 17:03:48280 profile_dependency_manager_->CreateProfileServices(this, true);
281
[email protected]5fd2e842012-03-01 00:29:11282#if defined(ENABLE_NOTIFICATIONS)
[email protected]dcb72d52011-04-13 12:36:53283 // Install profile keyed service factory hooks for dummy/test services
[email protected]7722653b2011-06-03 17:28:22284 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory(
285 this, CreateTestDesktopNotificationService);
[email protected]5fd2e842012-03-01 00:29:11286#endif
[email protected]537c1082011-12-02 02:37:17287}
[email protected]12463cd2011-07-19 09:40:20288
[email protected]537c1082011-12-02 02:37:17289void TestingProfile::FinishInit() {
[email protected]080adba92011-12-07 19:00:40290 DCHECK(content::NotificationService::current());
[email protected]ad50def52011-10-19 23:17:07291 content::NotificationService::current()->Notify(
[email protected]12463cd2011-07-19 09:40:20292 chrome::NOTIFICATION_PROFILE_CREATED,
[email protected]6c2381d2011-10-19 02:52:53293 content::Source<Profile>(static_cast<Profile*>(this)),
[email protected]ad50def52011-10-19 23:17:07294 content::NotificationService::NoDetails());
[email protected]537c1082011-12-02 02:37:17295
296 if (delegate_)
[email protected]00b33f802012-03-13 07:46:03297 delegate_->OnProfileCreated(this, true, false);
[email protected]ab23dbe2010-08-12 02:10:46298}
299
[email protected]f25387b2008-08-21 15:20:33300TestingProfile::~TestingProfile() {
[email protected]a7c4c032012-07-27 00:36:32301 MaybeSendDestroyedNotification();
[email protected]5cdcd152011-03-31 22:48:52302
303 profile_dependency_manager_->DestroyProfileServices(this);
304
[email protected]35552dc52011-07-12 09:04:38305 if (host_content_settings_map_)
306 host_content_settings_map_->ShutdownOnUIThread();
307
[email protected]809cc4d2010-10-27 15:22:54308 DestroyTopSites();
[email protected]cdba46992011-06-07 11:51:39309
[email protected]cc5bfd42010-11-24 14:44:02310 if (pref_proxy_config_tracker_.get())
311 pref_proxy_config_tracker_->DetachFromPrefService();
[email protected]f25387b2008-08-21 15:20:33312}
initial.commit09911bf2008-07-26 23:55:29313
[email protected]f3d2b312012-08-23 22:27:59314static ProfileKeyedService* BuildFaviconService(Profile* profile) {
315 return new FaviconService(
316 HistoryServiceFactory::GetForProfileWithoutCreating(profile));
317}
318
[email protected]d2879af2010-02-08 16:02:56319void TestingProfile::CreateFaviconService() {
[email protected]f3d2b312012-08-23 22:27:59320 // It is up to the caller to create the history service if one is needed.
321 FaviconServiceFactory::GetInstance()->SetTestingFactory(
322 this, BuildFaviconService);
[email protected]d2879af2010-02-08 16:02:56323}
324
[email protected]a5894fe2012-11-01 14:40:56325static ProfileKeyedService* BuildHistoryService(Profile* profile) {
[email protected]f61f4782012-06-08 21:54:21326 return new HistoryService(profile);
327}
328
[email protected]d486a0852009-11-02 21:40:00329void TestingProfile::CreateHistoryService(bool delete_file, bool no_db) {
[email protected]809cc4d2010-10-27 15:22:54330 DestroyHistoryService();
[email protected]f25387b2008-08-21 15:20:33331 if (delete_file) {
[email protected]152ea302013-02-11 04:08:40332 base::FilePath path = GetPath();
[email protected]f7011fcb2009-01-28 21:54:32333 path = path.Append(chrome::kHistoryFilename);
[email protected]f25387b2008-08-21 15:20:33334 file_util::Delete(path, false);
335 }
[email protected]7019bb6d2012-08-23 09:09:48336 // This will create and init the history service.
[email protected]f61f4782012-06-08 21:54:21337 HistoryService* history_service = static_cast<HistoryService*>(
338 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse(
[email protected]a5894fe2012-11-01 14:40:56339 this, BuildHistoryService));
[email protected]7019bb6d2012-08-23 09:09:48340 if (!history_service->Init(this->GetPath(),
341 BookmarkModelFactory::GetForProfile(this),
342 no_db)) {
[email protected]f61f4782012-06-08 21:54:21343 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse(this, NULL);
[email protected]7019bb6d2012-08-23 09:09:48344 }
initial.commit09911bf2008-07-26 23:55:29345}
346
347void TestingProfile::DestroyHistoryService() {
[email protected]a5894fe2012-11-01 14:40:56348 HistoryService* history_service =
[email protected]6c537042012-07-13 00:59:02349 HistoryServiceFactory::GetForProfileWithoutCreating(this);
[email protected]a5894fe2012-11-01 14:40:56350 if (!history_service)
initial.commit09911bf2008-07-26 23:55:29351 return;
352
[email protected]f61f4782012-06-08 21:54:21353 history_service->NotifyRenderProcessHostDestruction(0);
354 history_service->SetOnBackendDestroyTask(MessageLoop::QuitClosure());
355 history_service->Cleanup();
356 HistoryServiceFactory::ShutdownForProfile(this);
initial.commit09911bf2008-07-26 23:55:29357
358 // Wait for the backend class to terminate before deleting the files and
359 // moving to the next test. Note: if this never terminates, somebody is
360 // probably leaking a reference to the history backend, so it never calls
361 // our destroy task.
362 MessageLoop::current()->Run();
363
initial.commit09911bf2008-07-26 23:55:29364 // Make sure we don't have any event pending that could disrupt the next
365 // test.
[email protected]1cb1a242011-12-10 18:36:51366 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
initial.commit09911bf2008-07-26 23:55:29367 MessageLoop::current()->Run();
368}
[email protected]4d0cd7ce2008-08-11 16:40:57369
[email protected]809cc4d2010-10-27 15:22:54370void TestingProfile::CreateTopSites() {
371 DestroyTopSites();
372 top_sites_ = new history::TopSites(this);
[email protected]152ea302013-02-11 04:08:40373 base::FilePath file_name = GetPath().Append(chrome::kTopSitesFilename);
[email protected]809cc4d2010-10-27 15:22:54374 top_sites_->Init(file_name);
375}
376
377void TestingProfile::DestroyTopSites() {
378 if (top_sites_.get()) {
379 top_sites_->Shutdown();
380 top_sites_ = NULL;
381 // TopSites::Shutdown schedules some tasks (from TopSitesBackend) that need
382 // to be run to properly shutdown. Run all pending tasks now. This is
383 // normally handled by browser_process shutdown.
384 if (MessageLoop::current())
[email protected]d8996a012012-11-19 00:06:08385 MessageLoop::current()->RunUntilIdle();
[email protected]809cc4d2010-10-27 15:22:54386 }
387}
388
[email protected]f61f4782012-06-08 21:54:21389static ProfileKeyedService* BuildBookmarkModel(Profile* profile) {
390 BookmarkModel* bookmark_model = new BookmarkModel(profile);
391 bookmark_model->Load();
392 return bookmark_model;
393}
394
395
[email protected]d8e41ed2008-09-11 15:22:32396void TestingProfile::CreateBookmarkModel(bool delete_file) {
[email protected]90ef13132008-08-27 03:27:46397
398 if (delete_file) {
[email protected]152ea302013-02-11 04:08:40399 base::FilePath path = GetPath();
[email protected]f7011fcb2009-01-28 21:54:32400 path = path.Append(chrome::kBookmarksFileName);
[email protected]90ef13132008-08-27 03:27:46401 file_util::Delete(path, false);
402 }
[email protected]f61f4782012-06-08 21:54:21403 // This will create a bookmark model.
404 BookmarkModel* bookmark_service =
405 static_cast<BookmarkModel*>(
406 BookmarkModelFactory::GetInstance()->SetTestingFactoryAndUse(
407 this, BuildBookmarkModel));
408
409 HistoryService* history_service =
[email protected]a5894fe2012-11-01 14:40:56410 HistoryServiceFactory::GetForProfileWithoutCreating(this);
[email protected]f61f4782012-06-08 21:54:21411 if (history_service) {
412 history_service->history_backend_->bookmark_service_ =
413 bookmark_service;
414 history_service->history_backend_->expirer_.bookmark_service_ =
415 bookmark_service;
[email protected]90ef13132008-08-27 03:27:46416 }
[email protected]4d0cd7ce2008-08-11 16:40:57417}
[email protected]d2c017a2008-08-13 21:51:45418
[email protected]d07edd42012-05-14 23:49:46419static scoped_refptr<RefcountedProfileKeyedService> BuildWebDataService(
420 Profile* profile) {
421 WebDataService* web_data_service = new WebDataService();
422 if (web_data_service)
423 web_data_service->Init(profile->GetPath());
[email protected]a5c65292012-05-25 00:50:01424 return web_data_service;
[email protected]d07edd42012-05-14 23:49:46425}
[email protected]2609bc12010-01-24 08:32:55426
[email protected]d07edd42012-05-14 23:49:46427void TestingProfile::CreateWebDataService() {
[email protected]a5c65292012-05-25 00:50:01428 WebDataServiceFactory::GetInstance()->SetTestingFactory(
[email protected]d07edd42012-05-14 23:49:46429 this, BuildWebDataService);
[email protected]2609bc12010-01-24 08:32:55430}
431
[email protected]d364c652008-08-29 19:46:56432void TestingProfile::BlockUntilBookmarkModelLoaded() {
[email protected]d7f7f752012-08-08 02:02:55433 // Only get the bookmark model if it actually exists since the caller of the
434 // test should explicitly call CreateBookmarkModel to build it.
435 BookmarkModel* bookmark_model =
436 BookmarkModelFactory::GetForProfileIfExists(this);
437 DCHECK(bookmark_model);
[email protected]b5e3eb692013-03-01 18:11:21438 ui_test_utils::WaitForBookmarkModelToLoad(bookmark_model);
[email protected]d364c652008-08-29 19:46:56439}
440
[email protected]18a15ca82012-08-30 00:28:16441void TestingProfile::BlockUntilHistoryIndexIsRefreshed() {
442 // Only get the history service if it actually exists since the caller of the
443 // test should explicitly call CreateHistoryService to build it.
444 HistoryService* history_service =
445 HistoryServiceFactory::GetForProfileWithoutCreating(this);
446 DCHECK(history_service);
447 history::InMemoryURLIndex* index = history_service->InMemoryIndex();
448 if (!index || index->restored())
449 return;
450 base::RunLoop run_loop;
451 HistoryIndexRestoreObserver observer(
452 content::GetQuitTaskForRunLoop(&run_loop));
453 index->set_restore_cache_observer(&observer);
454 run_loop.Run();
455 index->set_restore_cache_observer(NULL);
456 DCHECK(index->restored());
457}
458
[email protected]120abf132011-09-27 21:38:06459// TODO(phajdan.jr): Doesn't this hang if Top Sites are already loaded?
[email protected]809cc4d2010-10-27 15:22:54460void TestingProfile::BlockUntilTopSitesLoaded() {
[email protected]a7fe9112012-07-20 02:34:45461 content::WindowedNotificationObserver top_sites_loaded_observer(
[email protected]120abf132011-09-27 21:38:06462 chrome::NOTIFICATION_TOP_SITES_LOADED,
[email protected]ad50def52011-10-19 23:17:07463 content::NotificationService::AllSources());
[email protected]d7f7f752012-08-08 02:02:55464 if (!HistoryServiceFactory::GetForProfile(this, Profile::EXPLICIT_ACCESS))
[email protected]809cc4d2010-10-27 15:22:54465 GetTopSites()->HistoryLoaded();
[email protected]120abf132011-09-27 21:38:06466 top_sites_loaded_observer.Wait();
[email protected]809cc4d2010-10-27 15:22:54467}
468
[email protected]152ea302013-02-11 04:08:40469base::FilePath TestingProfile::GetPath() {
[email protected]49a25632011-08-31 17:03:48470 return profile_path_;
[email protected]f9dec9482010-08-20 20:42:19471}
472
[email protected]0de615a2012-11-08 04:40:59473scoped_refptr<base::SequencedTaskRunner> TestingProfile::GetIOTaskRunner() {
474 return MessageLoop::current()->message_loop_proxy();
475}
476
[email protected]5b199522012-12-22 17:24:44477TestingPrefServiceSyncable* TestingProfile::GetTestingPrefService() {
[email protected]2fb7dc982010-09-29 12:24:28478 if (!prefs_.get())
479 CreateTestingPrefService();
480 DCHECK(testing_prefs_);
481 return testing_prefs_;
[email protected]dbbad7a2010-08-13 18:18:36482}
483
[email protected]8e5c89a2011-06-07 18:13:33484TestingProfile* TestingProfile::AsTestingProfile() {
485 return this;
486}
487
[email protected]29d70252011-04-28 02:16:58488std::string TestingProfile::GetProfileName() {
489 return std::string("testing_profile");
490}
491
[email protected]27d6e852012-03-02 21:31:32492bool TestingProfile::IsOffTheRecord() const {
[email protected]5bb2f522011-03-25 19:04:44493 return incognito_;
[email protected]fadc607b62011-02-07 17:55:50494}
495
[email protected]93dba942011-02-23 22:45:01496void TestingProfile::SetOffTheRecordProfile(Profile* profile) {
[email protected]5bb2f522011-03-25 19:04:44497 incognito_profile_.reset(profile);
[email protected]93dba942011-02-23 22:45:01498}
499
[email protected]074311a2013-02-28 23:14:09500void TestingProfile::SetOriginalProfile(Profile* profile) {
501 original_profile_ = profile;
502}
503
[email protected]fadc607b62011-02-07 17:55:50504Profile* TestingProfile::GetOffTheRecordProfile() {
[email protected]5bb2f522011-03-25 19:04:44505 return incognito_profile_.get();
[email protected]fadc607b62011-02-07 17:55:50506}
507
508bool TestingProfile::HasOffTheRecordProfile() {
[email protected]5bb2f522011-03-25 19:04:44509 return incognito_profile_.get() != NULL;
[email protected]fadc607b62011-02-07 17:55:50510}
511
512Profile* TestingProfile::GetOriginalProfile() {
[email protected]074311a2013-02-28 23:14:09513 if (original_profile_)
514 return original_profile_;
[email protected]fadc607b62011-02-07 17:55:50515 return this;
516}
517
[email protected]eaa7dd182010-12-14 11:09:00518ExtensionService* TestingProfile::GetExtensionService() {
[email protected]bd306722012-07-11 20:43:59519 return extensions::ExtensionSystem::Get(this)->extension_service();
[email protected]2fb7dc982010-09-29 12:24:28520}
521
[email protected]2261e7b72011-07-12 13:43:55522void TestingProfile::SetExtensionSpecialStoragePolicy(
523 ExtensionSpecialStoragePolicy* extension_special_storage_policy) {
524 extension_special_storage_policy_ = extension_special_storage_policy;
525}
526
[email protected]19eb80152011-02-26 00:28:43527ExtensionSpecialStoragePolicy*
528TestingProfile::GetExtensionSpecialStoragePolicy() {
[email protected]cdba46992011-06-07 11:51:39529 if (!extension_special_storage_policy_.get())
[email protected]7c5048c2011-08-19 17:07:05530 extension_special_storage_policy_ = new ExtensionSpecialStoragePolicy(NULL);
[email protected]cdba46992011-06-07 11:51:39531 return extension_special_storage_policy_.get();
[email protected]19eb80152011-02-26 00:28:43532}
533
[email protected]dbbad7a2010-08-13 18:18:36534net::CookieMonster* TestingProfile::GetCookieMonster() {
535 if (!GetRequestContext())
536 return NULL;
[email protected]277ec262011-03-30 21:09:40537 return GetRequestContext()->GetURLRequestContext()->cookie_store()->
538 GetCookieMonster();
[email protected]dbbad7a2010-08-13 18:18:36539}
540
[email protected]3b19e8e2012-10-17 19:15:49541policy::ManagedModePolicyProvider*
542TestingProfile::GetManagedModePolicyProvider() {
543 return NULL;
544}
545
[email protected]21d3a882012-05-31 14:41:55546policy::PolicyService* TestingProfile::GetPolicyService() {
547 if (!policy_service_.get()) {
548#if defined(ENABLE_CONFIGURATION_POLICY)
549 policy::PolicyServiceImpl::Providers providers;
550 policy_service_.reset(new policy::PolicyServiceImpl(providers));
551#else
552 policy_service_.reset(new policy::PolicyServiceStub());
553#endif
554 }
555 return policy_service_.get();
556}
557
[email protected]2fb7dc982010-09-29 12:24:28558void TestingProfile::CreateTestingPrefService() {
559 DCHECK(!prefs_.get());
[email protected]5b199522012-12-22 17:24:44560 testing_prefs_ = new TestingPrefServiceSyncable();
[email protected]2fb7dc982010-09-29 12:24:28561 prefs_.reset(testing_prefs_);
[email protected]5879cef2013-03-02 17:02:25562 chrome::RegisterUserPrefs(testing_prefs_->registry());
[email protected]2fb7dc982010-09-29 12:24:28563}
564
[email protected]c753f142013-02-10 13:14:04565PrefService* TestingProfile::GetPrefs() {
[email protected]dbbad7a2010-08-13 18:18:36566 if (!prefs_.get()) {
[email protected]2fb7dc982010-09-29 12:24:28567 CreateTestingPrefService();
[email protected]dbbad7a2010-08-13 18:18:36568 }
569 return prefs_.get();
570}
571
572history::TopSites* TestingProfile::GetTopSites() {
[email protected]809cc4d2010-10-27 15:22:54573 return top_sites_.get();
[email protected]dbbad7a2010-08-13 18:18:36574}
575
[email protected]fadc607b62011-02-07 17:55:50576history::TopSites* TestingProfile::GetTopSitesWithoutCreating() {
577 return top_sites_.get();
578}
579
[email protected]b441a8492012-06-06 14:55:57580DownloadManagerDelegate* TestingProfile::GetDownloadManagerDelegate() {
[email protected]fadc607b62011-02-07 17:55:50581 return NULL;
582}
583
[email protected]abe2c032011-03-31 18:49:34584net::URLRequestContextGetter* TestingProfile::GetRequestContext() {
[email protected]812b3a32010-01-08 05:36:04585 return request_context_.get();
586}
587
[email protected]6bd30072013-02-08 18:17:11588net::URLRequestContextGetter* TestingProfile::CreateRequestContext(
589 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
590 blob_protocol_handler,
591 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
592 file_system_protocol_handler,
593 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
594 developer_protocol_handler,
595 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
596 chrome_protocol_handler,
597 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
598 chrome_devtools_protocol_handler) {
599 return request_context_.get();
600}
601
[email protected]da5683db2011-04-23 17:12:21602net::URLRequestContextGetter* TestingProfile::GetRequestContextForRenderProcess(
603 int renderer_child_id) {
[email protected]fb29e6cf2012-07-12 21:27:20604 content::RenderProcessHost* rph = content::RenderProcessHost::FromID(
605 renderer_child_id);
[email protected]1bc28312012-11-08 08:31:53606 return rph->GetStoragePartition()->GetURLRequestContext();
[email protected]d9696672011-03-15 22:45:09607}
608
[email protected]812b3a32010-01-08 05:36:04609void TestingProfile::CreateRequestContext() {
610 if (!request_context_)
[email protected]44738602012-03-02 22:56:01611 request_context_ =
[email protected]2086a3d2012-11-13 17:49:20612 new net::TestURLRequestContextGetter(
[email protected]44738602012-03-02 22:56:01613 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
[email protected]812b3a32010-01-08 05:36:04614}
615
[email protected]7c893202010-10-07 20:18:02616void TestingProfile::ResetRequestContext() {
[email protected]3931fd82012-03-12 21:18:48617 // Any objects holding live URLFetchers should be deleted before the request
618 // context is shut down.
[email protected]16bd088b2012-04-03 08:12:12619 TemplateURLFetcherFactory::ShutdownForProfile(this);
[email protected]3931fd82012-03-12 21:18:48620
[email protected]7c893202010-10-07 20:18:02621 request_context_ = NULL;
622}
623
[email protected]10705a7b2012-08-21 19:07:08624net::URLRequestContextGetter* TestingProfile::GetMediaRequestContext() {
625 return NULL;
626}
627
628net::URLRequestContextGetter*
629TestingProfile::GetMediaRequestContextForRenderProcess(
630 int renderer_child_id) {
[email protected]fadc607b62011-02-07 17:55:50631 return NULL;
632}
633
[email protected]10eb28162012-09-18 03:04:09634net::URLRequestContextGetter*
635TestingProfile::GetMediaRequestContextForStoragePartition(
[email protected]152ea302013-02-11 04:08:40636 const base::FilePath& partition_path,
[email protected]27ddfed22012-10-30 23:22:43637 bool in_memory) {
[email protected]10eb28162012-09-18 03:04:09638 return NULL;
639}
640
[email protected]abe2c032011-03-31 18:49:34641net::URLRequestContextGetter* TestingProfile::GetRequestContextForExtensions() {
[email protected]c10da4b02010-03-25 14:38:32642 if (!extensions_request_context_)
[email protected]00dea9582012-05-09 15:20:05643 extensions_request_context_ = new TestExtensionURLRequestContextGetter();
[email protected]c10da4b02010-03-25 14:38:32644 return extensions_request_context_.get();
645}
646
[email protected]fadc607b62011-02-07 17:55:50647net::SSLConfigService* TestingProfile::GetSSLConfigService() {
[email protected]dc6655b2012-12-14 05:58:24648 if (!GetRequestContext())
649 return NULL;
650 return GetRequestContext()->GetURLRequestContext()->ssl_config_service();
[email protected]fadc607b62011-02-07 17:55:50651}
652
[email protected]10eb28162012-09-18 03:04:09653net::URLRequestContextGetter*
[email protected]6bd30072013-02-08 18:17:11654TestingProfile::CreateRequestContextForStoragePartition(
[email protected]152ea302013-02-11 04:08:40655 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:11656 bool in_memory,
657 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
658 blob_protocol_handler,
659 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
660 file_system_protocol_handler,
661 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
662 developer_protocol_handler,
663 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
664 chrome_protocol_handler,
665 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
666 chrome_devtools_protocol_handler) {
[email protected]10eb28162012-09-18 03:04:09667 // We don't test storage partitions here yet, so returning the same dummy
[email protected]d9696672011-03-15 22:45:09668 // context is sufficient for now.
669 return GetRequestContext();
670}
671
[email protected]df02aca2012-02-09 21:03:20672content::ResourceContext* TestingProfile::GetResourceContext() {
[email protected]314c3e22012-02-21 03:57:42673 if (!resource_context_.get())
674 resource_context_.reset(new content::MockResourceContext());
675 return resource_context_.get();
[email protected]e89b77d2011-04-15 18:58:10676}
677
[email protected]dbbad7a2010-08-13 18:18:36678HostContentSettingsMap* TestingProfile::GetHostContentSettingsMap() {
[email protected]35552dc52011-07-12 09:04:38679 if (!host_content_settings_map_.get()) {
[email protected]646c29cb62012-06-18 14:31:05680 host_content_settings_map_ = new HostContentSettingsMap(GetPrefs(), false);
[email protected]701550ad2012-09-06 23:43:29681#if defined(ENABLE_EXTENSIONS)
[email protected]646c29cb62012-06-18 14:31:05682 ExtensionService* extension_service = GetExtensionService();
683 if (extension_service)
684 host_content_settings_map_->RegisterExtensionService(extension_service);
[email protected]701550ad2012-09-06 23:43:29685#endif
[email protected]35552dc52011-07-12 09:04:38686 }
[email protected]dbbad7a2010-08-13 18:18:36687 return host_content_settings_map_.get();
688}
689
[email protected]810ddc52012-01-24 01:00:35690content::GeolocationPermissionContext*
[email protected]dbbad7a2010-08-13 18:18:36691TestingProfile::GetGeolocationPermissionContext() {
[email protected]a877a7d2013-01-08 13:40:59692 return ChromeGeolocationPermissionContextFactory::GetForProfile(this);
[email protected]dbbad7a2010-08-13 18:18:36693}
694
[email protected]c52b2892012-03-07 11:01:02695content::SpeechRecognitionPreferences*
696 TestingProfile::GetSpeechRecognitionPreferences() {
[email protected]3297132a2012-02-21 23:27:59697#if defined(ENABLE_INPUT_SPEECH)
[email protected]750e9572012-06-06 15:21:24698 return ChromeSpeechRecognitionPreferences::GetForProfile(this);
[email protected]3297132a2012-02-21 23:27:59699#else
700 return NULL;
701#endif
[email protected]8238dd62011-09-29 15:13:01702}
703
[email protected]fadc607b62011-02-07 17:55:50704std::wstring TestingProfile::GetName() {
705 return std::wstring();
706}
707
708std::wstring TestingProfile::GetID() {
709 return id_;
710}
711
712void TestingProfile::SetID(const std::wstring& id) {
713 id_ = id;
714}
715
[email protected]fadc607b62011-02-07 17:55:50716bool TestingProfile::IsSameProfile(Profile *p) {
717 return this == p;
718}
719
720base::Time TestingProfile::GetStartTime() const {
721 return start_time_;
722}
723
[email protected]a6d36cc2011-02-23 00:39:48724ProtocolHandlerRegistry* TestingProfile::GetProtocolHandlerRegistry() {
[email protected]ab563ff2012-07-21 00:26:32725 return NULL;
[email protected]a6d36cc2011-02-23 00:39:48726}
727
[email protected]152ea302013-02-11 04:08:40728base::FilePath TestingProfile::last_selected_directory() {
[email protected]fadc607b62011-02-07 17:55:50729 return last_selected_directory_;
730}
731
[email protected]152ea302013-02-11 04:08:40732void TestingProfile::set_last_selected_directory(const base::FilePath& path) {
[email protected]fadc607b62011-02-07 17:55:50733 last_selected_directory_ = path;
734}
735
[email protected]cc5bfd42010-11-24 14:44:02736PrefProxyConfigTracker* TestingProfile::GetProxyConfigTracker() {
[email protected]6f96cbcb2011-11-04 02:26:07737 if (!pref_proxy_config_tracker_.get()) {
738 pref_proxy_config_tracker_.reset(
739 ProxyServiceFactory::CreatePrefProxyConfigTracker(GetPrefs()));
740 }
741 return pref_proxy_config_tracker_.get();
[email protected]cc5bfd42010-11-24 14:44:02742}
743
[email protected]0bfc29a2009-04-27 16:15:44744void TestingProfile::BlockUntilHistoryProcessesPendingRequests() {
[email protected]a5894fe2012-11-01 14:40:56745 HistoryService* history_service =
[email protected]6c537042012-07-13 00:59:02746 HistoryServiceFactory::GetForProfile(this, Profile::EXPLICIT_ACCESS);
[email protected]a5894fe2012-11-01 14:40:56747 DCHECK(history_service);
[email protected]0bfc29a2009-04-27 16:15:44748 DCHECK(MessageLoop::current());
749
750 CancelableRequestConsumer consumer;
[email protected]f61f4782012-06-08 21:54:21751 history_service->ScheduleDBTask(new QuittingHistoryDBTask(), &consumer);
[email protected]0bfc29a2009-04-27 16:15:44752 MessageLoop::current()->Run();
753}
[email protected]345a8b72009-09-29 09:11:44754
[email protected]8382d8c2011-09-15 03:43:17755chrome_browser_net::Predictor* TestingProfile::GetNetworkPredictor() {
756 return NULL;
757}
758
[email protected]e0e1fc22012-11-05 20:25:36759void TestingProfile::ClearNetworkingHistorySince(
760 base::Time time,
761 const base::Closure& completion) {
762 if (!completion.is_null()) {
763 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, completion);
764 }
[email protected]02896a82011-09-21 18:54:32765}
766
[email protected]671f9c62011-10-28 19:22:07767GURL TestingProfile::GetHomePage() {
768 return GURL(chrome::kChromeUINewTabURL);
769}
770
[email protected]c753f142013-02-10 13:14:04771PrefService* TestingProfile::GetOffTheRecordPrefs() {
[email protected]fadc607b62011-02-07 17:55:50772 return NULL;
773}
774
[email protected]36fb2c7c2011-04-04 15:49:08775quota::SpecialStoragePolicy* TestingProfile::GetSpecialStoragePolicy() {
776 return GetExtensionSpecialStoragePolicy();
777}
778
[email protected]1bee6ed2012-03-14 06:46:36779bool TestingProfile::WasCreatedByVersionOrLater(const std::string& version) {
780 return true;
781}
[email protected]ef92e172012-04-25 19:40:41782
[email protected]6c0ca7fc2012-10-05 16:27:22783Profile::ExitType TestingProfile::GetLastSessionExitType() {
784 return last_session_exited_cleanly_ ? EXIT_NORMAL : EXIT_CRASHED;
[email protected]2ca1ea662012-10-04 02:26:36785}
786
[email protected]5c4c89f2012-08-07 21:09:59787TestingProfile::Builder::Builder()
788 : build_called_(false),
[email protected]a0cc9a532013-02-12 02:23:12789 delegate_(NULL) {
[email protected]5c4c89f2012-08-07 21:09:59790}
791
792TestingProfile::Builder::~Builder() {
793}
794
[email protected]152ea302013-02-11 04:08:40795void TestingProfile::Builder::SetPath(const base::FilePath& path) {
[email protected]5c4c89f2012-08-07 21:09:59796 path_ = path;
797}
798
799void TestingProfile::Builder::SetDelegate(Delegate* delegate) {
800 delegate_ = delegate;
801}
802
803void TestingProfile::Builder::SetExtensionSpecialStoragePolicy(
804 scoped_refptr<ExtensionSpecialStoragePolicy> policy) {
805 extension_policy_ = policy;
806}
807
[email protected]5b199522012-12-22 17:24:44808void TestingProfile::Builder::SetPrefService(
809 scoped_ptr<PrefServiceSyncable> prefs) {
[email protected]5c4c89f2012-08-07 21:09:59810 pref_service_ = prefs.Pass();
811}
812
[email protected]5c4c89f2012-08-07 21:09:59813scoped_ptr<TestingProfile> TestingProfile::Builder::Build() {
814 DCHECK(!build_called_);
815 build_called_ = true;
816 return scoped_ptr<TestingProfile>(new TestingProfile(
817 path_,
818 delegate_,
819 extension_policy_,
[email protected]a0cc9a532013-02-12 02:23:12820 pref_service_.Pass()));
[email protected]5c4c89f2012-08-07 21:09:59821}