blob: 145804e01e3c92c95664ff7583d7a9a5f50b144a [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]76ae8a62013-05-10 05:34:2212#include "base/message_loop/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]a50e16a2013-04-25 14:07:1738#include "chrome/browser/history/web_history_service_factory.h"
[email protected]6f96cbcb2011-11-04 02:26:0739#include "chrome/browser/net/proxy_service_factory.h"
[email protected]dbbad7a2010-08-13 18:18:3640#include "chrome/browser/notifications/desktop_notification_service.h"
[email protected]dcb72d52011-04-13 12:36:5341#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]d81bb3e2013-05-02 18:17:0342#include "chrome/browser/policy/profile_policy_connector.h"
43#include "chrome/browser/policy/profile_policy_connector_factory.h"
[email protected]37858e52010-08-26 00:22:0244#include "chrome/browser/prefs/browser_prefs.h"
[email protected]c753f142013-02-10 13:14:0445#include "chrome/browser/prefs/pref_service_syncable.h"
[email protected]4850a7f2011-03-08 23:36:5946#include "chrome/browser/prerender/prerender_manager.h"
[email protected]7e75e4a2013-05-17 17:20:0347#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
[email protected]27ddfed22012-10-30 23:22:4348#include "chrome/browser/profiles/storage_partition_descriptor.h"
[email protected]16bd088b2012-04-03 08:12:1249#include "chrome/browser/search_engines/template_url_fetcher_factory.h"
[email protected]c52b2892012-03-07 11:01:0250#include "chrome/browser/speech/chrome_speech_recognition_preferences.h"
[email protected]810ffba2012-06-12 01:07:4851#include "chrome/browser/webdata/web_data_service.h"
[email protected]d07edd42012-05-14 23:49:4652#include "chrome/browser/webdata/web_data_service_factory.h"
[email protected]a9afddb2009-02-12 17:49:4253#include "chrome/common/chrome_constants.h"
[email protected]432115822011-07-10 15:52:2754#include "chrome/common/chrome_notification_types.h"
[email protected]9e33d7e2011-09-30 16:43:5455#include "chrome/common/chrome_switches.h"
[email protected]dbbad7a2010-08-13 18:18:3656#include "chrome/common/url_constants.h"
[email protected]7bc60682011-07-29 20:55:5957#include "chrome/test/base/bookmark_load_observer.h"
[email protected]18a15ca82012-08-30 00:28:1658#include "chrome/test/base/history_index_restore_observer.h"
[email protected]7688968a2013-02-12 21:45:1359#include "chrome/test/base/testing_pref_service_syncable.h"
[email protected]af44e7fb2011-07-29 18:32:3260#include "chrome/test/base/ui_test_utils.h"
[email protected]0dd6f2032013-05-20 23:33:4061#include "components/browser_context_keyed_service/browser_context_dependency_manager.h"
[email protected]75fee372013-03-06 00:42:4462#include "components/user_prefs/user_prefs.h"
[email protected]c38831a12011-10-28 12:44:4963#include "content/public/browser/browser_thread.h"
[email protected]ad50def52011-10-19 23:17:0764#include "content/public/browser/notification_service.h"
[email protected]fb29e6cf2012-07-12 21:27:2065#include "content/public/browser/render_process_host.h"
[email protected]885c0e92012-11-13 20:27:4266#include "content/public/browser/storage_partition.h"
[email protected]08a932d52012-06-03 21:42:1267#include "content/public/test/mock_resource_context.h"
[email protected]a7fe9112012-07-20 02:34:4568#include "content/public/test/test_utils.h"
[email protected]885c0e92012-11-13 20:27:4269#include "extensions/common/constants.h"
[email protected]aa84a7e2012-03-15 21:29:0670#include "net/cookies/cookie_monster.h"
[email protected]812b3a32010-01-08 05:36:0471#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:3472#include "net/url_request/url_request_context_getter.h"
[email protected]d2db0292011-01-26 20:23:4473#include "net/url_request/url_request_test_util.h"
[email protected]4772b072010-03-30 17:45:4674#include "testing/gmock/include/gmock/gmock.h"
[email protected]248ce192011-02-10 15:26:3475
[email protected]21d3a882012-05-31 14:41:5576#if defined(ENABLE_CONFIGURATION_POLICY)
[email protected]d81bb3e2013-05-02 18:17:0377#include "chrome/browser/policy/configuration_policy_provider.h"
[email protected]21d3a882012-05-31 14:41:5578#include "chrome/browser/policy/policy_service_impl.h"
79#else
80#include "chrome/browser/policy/policy_service_stub.h"
81#endif // defined(ENABLE_CONFIGURATION_POLICY)
82
[email protected]6f96cbcb2011-11-04 02:26:0783#if defined(OS_CHROMEOS)
84#include "chrome/browser/chromeos/proxy_config_service_impl.h"
85#endif // defined(OS_CHROMEOS)
86
[email protected]e1acf6f2008-10-27 20:43:3387using base::Time;
[email protected]631bb742011-11-02 11:29:3988using content::BrowserThread;
[email protected]b441a8492012-06-06 14:55:5789using content::DownloadManagerDelegate;
[email protected]3c887412010-04-19 20:30:2390using testing::NiceMock;
[email protected]4772b072010-03-30 17:45:4691using testing::Return;
[email protected]e1acf6f2008-10-27 20:43:3392
[email protected]d364c652008-08-29 19:46:5693namespace {
94
[email protected]0bfc29a2009-04-27 16:15:4495// Task used to make sure history has finished processing a request. Intended
96// for use with BlockUntilHistoryProcessesPendingRequests.
97
[email protected]d891f522013-02-08 03:24:4198class QuittingHistoryDBTask : public history::HistoryDBTask {
[email protected]0bfc29a2009-04-27 16:15:4499 public:
100 QuittingHistoryDBTask() {}
101
102 virtual bool RunOnDBThread(history::HistoryBackend* backend,
[email protected]be9826e62013-02-07 02:00:58103 history::HistoryDatabase* db) OVERRIDE {
[email protected]0bfc29a2009-04-27 16:15:44104 return true;
105 }
106
[email protected]be9826e62013-02-07 02:00:58107 virtual void DoneRunOnMainThread() OVERRIDE {
[email protected]bb024fe2013-05-10 21:33:26108 base::MessageLoop::current()->Quit();
[email protected]0bfc29a2009-04-27 16:15:44109 }
110
111 private:
[email protected]be9826e62013-02-07 02:00:58112 virtual ~QuittingHistoryDBTask() {}
[email protected]7991a232009-11-06 01:55:48113
[email protected]0bfc29a2009-04-27 16:15:44114 DISALLOW_COPY_AND_ASSIGN(QuittingHistoryDBTask);
115};
116
[email protected]aeb53f02011-01-15 00:21:34117class TestExtensionURLRequestContext : public net::URLRequestContext {
[email protected]c10da4b02010-03-25 14:38:32118 public:
119 TestExtensionURLRequestContext() {
120 net::CookieMonster* cookie_monster = new net::CookieMonster(NULL, NULL);
[email protected]885c0e92012-11-13 20:27:42121 const char* schemes[] = {extensions::kExtensionScheme};
[email protected]c10da4b02010-03-25 14:38:32122 cookie_monster->SetCookieableSchemes(schemes, 1);
[email protected]f6c21cb2011-02-16 19:45:41123 set_cookie_store(cookie_monster);
[email protected]c10da4b02010-03-25 14:38:32124 }
[email protected]7b2720b2012-04-25 16:59:11125
[email protected]7b2720b2012-04-25 16:59:11126 virtual ~TestExtensionURLRequestContext() {}
[email protected]c10da4b02010-03-25 14:38:32127};
128
[email protected]abe2c032011-03-31 18:49:34129class TestExtensionURLRequestContextGetter
130 : public net::URLRequestContextGetter {
[email protected]c10da4b02010-03-25 14:38:32131 public:
[email protected]be9826e62013-02-07 02:00:58132 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE {
[email protected]ef2bf422012-05-11 03:27:09133 if (!context_.get())
134 context_.reset(new TestExtensionURLRequestContext());
[email protected]c10da4b02010-03-25 14:38:32135 return context_.get();
136 }
[email protected]4969b0122012-06-16 01:58:28137 virtual scoped_refptr<base::SingleThreadTaskRunner>
138 GetNetworkTaskRunner() const OVERRIDE {
[email protected]0c7d74f2010-10-11 11:55:26139 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
[email protected]83a7d2eb2010-05-03 21:46:19140 }
[email protected]c10da4b02010-03-25 14:38:32141
[email protected]13ed17f82012-04-06 02:27:18142 protected:
143 virtual ~TestExtensionURLRequestContextGetter() {}
144
[email protected]c10da4b02010-03-25 14:38:32145 private:
[email protected]ef2bf422012-05-11 03:27:09146 scoped_ptr<net::URLRequestContext> context_;
[email protected]c10da4b02010-03-25 14:38:32147};
148
[email protected]f1484c52013-05-22 23:25:44149BrowserContextKeyedService* CreateTestDesktopNotificationService(
[email protected]c7fa4362013-04-26 18:09:02150 content::BrowserContext* profile) {
[email protected]29cebbd2012-06-06 21:43:42151#if defined(ENABLE_NOTIFICATIONS)
[email protected]c7fa4362013-04-26 18:09:02152 return new DesktopNotificationService(static_cast<Profile*>(profile), NULL);
[email protected]29cebbd2012-06-06 21:43:42153#else
154 return NULL;
155#endif
[email protected]dcb72d52011-04-13 12:36:53156}
157
[email protected]d364c652008-08-29 19:46:56158} // namespace
159
[email protected]89dbb1772012-07-17 13:47:25160// static
161#if defined(OS_CHROMEOS)
162// Must be kept in sync with
163// ChromeBrowserMainPartsChromeos::PreEarlyInitialization.
164const char TestingProfile::kTestUserProfileDir[] = "test-user";
165#else
166const char TestingProfile::kTestUserProfileDir[] = "Default";
167#endif
168
[email protected]f25387b2008-08-21 15:20:33169TestingProfile::TestingProfile()
[email protected]ea6f76572008-12-18 00:09:55170 : start_time_(Time::Now()),
[email protected]2fb7dc982010-09-29 12:24:28171 testing_prefs_(NULL),
[email protected]5bb2f522011-03-25 19:04:44172 incognito_(false),
[email protected]074311a2013-02-28 23:14:09173 original_profile_(NULL),
[email protected]5cdcd152011-03-31 22:48:52174 last_session_exited_cleanly_(true),
[email protected]f0901a22013-05-27 21:37:53175 browser_context_dependency_manager_(
[email protected]f1484c52013-05-22 23:25:44176 BrowserContextDependencyManager::GetInstance()),
[email protected]537c1082011-12-02 02:37:17177 delegate_(NULL) {
[email protected]5c4c89f2012-08-07 21:09:59178 CreateTempProfileDir();
[email protected]49a25632011-08-31 17:03:48179 profile_path_ = temp_dir_.path();
180
181 Init();
[email protected]537c1082011-12-02 02:37:17182 FinishInit();
[email protected]49a25632011-08-31 17:03:48183}
184
[email protected]152ea302013-02-11 04:08:40185TestingProfile::TestingProfile(const base::FilePath& path)
[email protected]49a25632011-08-31 17:03:48186 : start_time_(Time::Now()),
187 testing_prefs_(NULL),
188 incognito_(false),
[email protected]074311a2013-02-28 23:14:09189 original_profile_(NULL),
[email protected]49a25632011-08-31 17:03:48190 last_session_exited_cleanly_(true),
191 profile_path_(path),
[email protected]f0901a22013-05-27 21:37:53192 browser_context_dependency_manager_(
[email protected]f1484c52013-05-22 23:25:44193 BrowserContextDependencyManager::GetInstance()),
[email protected]537c1082011-12-02 02:37:17194 delegate_(NULL) {
[email protected]49a25632011-08-31 17:03:48195 Init();
[email protected]537c1082011-12-02 02:37:17196 FinishInit();
197}
198
[email protected]152ea302013-02-11 04:08:40199TestingProfile::TestingProfile(const base::FilePath& path,
[email protected]537c1082011-12-02 02:37:17200 Delegate* delegate)
201 : start_time_(Time::Now()),
202 testing_prefs_(NULL),
203 incognito_(false),
[email protected]074311a2013-02-28 23:14:09204 original_profile_(NULL),
[email protected]537c1082011-12-02 02:37:17205 last_session_exited_cleanly_(true),
206 profile_path_(path),
[email protected]f0901a22013-05-27 21:37:53207 browser_context_dependency_manager_(
[email protected]f1484c52013-05-22 23:25:44208 BrowserContextDependencyManager::GetInstance()),
[email protected]537c1082011-12-02 02:37:17209 delegate_(delegate) {
210 Init();
211 if (delegate_) {
[email protected]bb024fe2013-05-10 21:33:26212 base::MessageLoop::current()->PostTask(
213 FROM_HERE,
214 base::Bind(&TestingProfile::FinishInit, base::Unretained(this)));
[email protected]537c1082011-12-02 02:37:17215 } else {
216 FinishInit();
217 }
[email protected]49a25632011-08-31 17:03:48218}
219
[email protected]5c4c89f2012-08-07 21:09:59220TestingProfile::TestingProfile(
[email protected]152ea302013-02-11 04:08:40221 const base::FilePath& path,
[email protected]5c4c89f2012-08-07 21:09:59222 Delegate* delegate,
223 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy,
[email protected]a0cc9a532013-02-12 02:23:12224 scoped_ptr<PrefServiceSyncable> prefs)
[email protected]5c4c89f2012-08-07 21:09:59225 : start_time_(Time::Now()),
226 prefs_(prefs.release()),
227 testing_prefs_(NULL),
[email protected]a0cc9a532013-02-12 02:23:12228 incognito_(false),
[email protected]074311a2013-02-28 23:14:09229 original_profile_(NULL),
[email protected]5c4c89f2012-08-07 21:09:59230 last_session_exited_cleanly_(true),
231 extension_special_storage_policy_(extension_policy),
[email protected]5c4c89f2012-08-07 21:09:59232 profile_path_(path),
[email protected]f0901a22013-05-27 21:37:53233 browser_context_dependency_manager_(
[email protected]f1484c52013-05-22 23:25:44234 BrowserContextDependencyManager::GetInstance()),
[email protected]5c4c89f2012-08-07 21:09:59235 delegate_(delegate) {
236
237 // If no profile path was supplied, create one.
238 if (profile_path_.empty()) {
239 CreateTempProfileDir();
240 profile_path_ = temp_dir_.path();
241 }
242
243 Init();
244 // If caller supplied a delegate, delay the FinishInit invocation until other
245 // tasks have run.
246 // TODO(atwilson): See if this is still required once we convert the current
247 // users of the constructor that takes a Delegate* param.
248 if (delegate_) {
[email protected]bb024fe2013-05-10 21:33:26249 base::MessageLoop::current()->PostTask(
250 FROM_HERE,
251 base::Bind(&TestingProfile::FinishInit, base::Unretained(this)));
[email protected]5c4c89f2012-08-07 21:09:59252 } else {
253 FinishInit();
254 }
255}
256
257void TestingProfile::CreateTempProfileDir() {
258 if (!temp_dir_.CreateUniqueTempDir()) {
259 LOG(ERROR) << "Failed to create unique temporary directory.";
260
261 // Fallback logic in case we fail to create unique temporary directory.
[email protected]152ea302013-02-11 04:08:40262 base::FilePath system_tmp_dir;
[email protected]5c4c89f2012-08-07 21:09:59263 bool success = PathService::Get(base::DIR_TEMP, &system_tmp_dir);
264
265 // We're severly screwed if we can't get the system temporary
266 // directory. Die now to avoid writing to the filesystem root
267 // or other bad places.
268 CHECK(success);
269
[email protected]152ea302013-02-11 04:08:40270 base::FilePath fallback_dir(
271 system_tmp_dir.AppendASCII("TestingProfilePath"));
[email protected]918efbf2013-07-01 19:41:02272 base::Delete(fallback_dir, true);
[email protected]5c4c89f2012-08-07 21:09:59273 file_util::CreateDirectory(fallback_dir);
274 if (!temp_dir_.Set(fallback_dir)) {
275 // That shouldn't happen, but if it does, try to recover.
276 LOG(ERROR) << "Failed to use a fallback temporary directory.";
277
278 // We're screwed if this fails, see CHECK above.
279 CHECK(temp_dir_.Set(system_tmp_dir));
280 }
281 }
282}
283
[email protected]49a25632011-08-31 17:03:48284void TestingProfile::Init() {
[email protected]7e75e4a2013-05-17 17:20:03285 // Normally this would happen during browser startup, but for tests
286 // we need to trigger creation of Profile-related services.
287 ChromeBrowserMainExtraPartsProfiles::
[email protected]f1484c52013-05-22 23:25:44288 EnsureBrowserContextKeyedServiceFactoriesBuilt();
[email protected]7e75e4a2013-05-17 17:20:03289
[email protected]75fee372013-03-06 00:42:44290 if (prefs_.get())
[email protected]c7141feb2013-06-11 13:00:16291 user_prefs::UserPrefs::Set(this, prefs_.get());
[email protected]c7fa4362013-04-26 18:09:02292 else
293 CreateTestingPrefService();
[email protected]75fee372013-03-06 00:42:44294
[email protected]d41e6572012-05-04 20:49:42295 if (!file_util::PathExists(profile_path_))
296 file_util::CreateDirectory(profile_path_);
297
[email protected]d81bb3e2013-05-02 18:17:03298 // TODO(joaodasilva): remove this once this PKS isn't created in ProfileImpl
299 // anymore, after converting the PrefService to a PKS. Until then it must
300 // be associated with a TestingProfile too.
301 CreateProfilePolicyConnector();
302
[email protected]bd306722012-07-11 20:43:59303 extensions::ExtensionSystemFactory::GetInstance()->SetTestingFactory(
304 this, extensions::TestExtensionSystem::Build);
[email protected]31d8f5f22012-04-02 15:22:08305
[email protected]f0901a22013-05-27 21:37:53306 browser_context_dependency_manager_->CreateBrowserContextServices(this, true);
[email protected]49a25632011-08-31 17:03:48307
[email protected]5fd2e842012-03-01 00:29:11308#if defined(ENABLE_NOTIFICATIONS)
[email protected]dcb72d52011-04-13 12:36:53309 // Install profile keyed service factory hooks for dummy/test services
[email protected]7722653b2011-06-03 17:28:22310 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory(
311 this, CreateTestDesktopNotificationService);
[email protected]5fd2e842012-03-01 00:29:11312#endif
[email protected]537c1082011-12-02 02:37:17313}
[email protected]12463cd2011-07-19 09:40:20314
[email protected]537c1082011-12-02 02:37:17315void TestingProfile::FinishInit() {
[email protected]080adba92011-12-07 19:00:40316 DCHECK(content::NotificationService::current());
[email protected]ad50def52011-10-19 23:17:07317 content::NotificationService::current()->Notify(
[email protected]12463cd2011-07-19 09:40:20318 chrome::NOTIFICATION_PROFILE_CREATED,
[email protected]6c2381d2011-10-19 02:52:53319 content::Source<Profile>(static_cast<Profile*>(this)),
[email protected]ad50def52011-10-19 23:17:07320 content::NotificationService::NoDetails());
[email protected]537c1082011-12-02 02:37:17321
322 if (delegate_)
[email protected]00b33f802012-03-13 07:46:03323 delegate_->OnProfileCreated(this, true, false);
[email protected]ab23dbe2010-08-12 02:10:46324}
325
[email protected]f25387b2008-08-21 15:20:33326TestingProfile::~TestingProfile() {
[email protected]a7c4c032012-07-27 00:36:32327 MaybeSendDestroyedNotification();
[email protected]5cdcd152011-03-31 22:48:52328
[email protected]f0901a22013-05-27 21:37:53329 browser_context_dependency_manager_->DestroyBrowserContextServices(this);
[email protected]5cdcd152011-03-31 22:48:52330
[email protected]5c6ac842013-06-02 23:37:03331 if (host_content_settings_map_.get())
[email protected]35552dc52011-07-12 09:04:38332 host_content_settings_map_->ShutdownOnUIThread();
333
[email protected]809cc4d2010-10-27 15:22:54334 DestroyTopSites();
[email protected]cdba46992011-06-07 11:51:39335
[email protected]cc5bfd42010-11-24 14:44:02336 if (pref_proxy_config_tracker_.get())
337 pref_proxy_config_tracker_->DetachFromPrefService();
[email protected]f25387b2008-08-21 15:20:33338}
initial.commit09911bf2008-07-26 23:55:29339
[email protected]f1484c52013-05-22 23:25:44340static BrowserContextKeyedService* BuildFaviconService(
[email protected]c7fa4362013-04-26 18:09:02341 content::BrowserContext* profile) {
[email protected]f3d2b312012-08-23 22:27:59342 return new FaviconService(
[email protected]c7fa4362013-04-26 18:09:02343 HistoryServiceFactory::GetForProfileWithoutCreating(
344 static_cast<Profile*>(profile)));
[email protected]f3d2b312012-08-23 22:27:59345}
346
[email protected]d2879af2010-02-08 16:02:56347void TestingProfile::CreateFaviconService() {
[email protected]f3d2b312012-08-23 22:27:59348 // It is up to the caller to create the history service if one is needed.
349 FaviconServiceFactory::GetInstance()->SetTestingFactory(
350 this, BuildFaviconService);
[email protected]d2879af2010-02-08 16:02:56351}
352
[email protected]f1484c52013-05-22 23:25:44353static BrowserContextKeyedService* BuildHistoryService(
[email protected]c7fa4362013-04-26 18:09:02354 content::BrowserContext* profile) {
355 return new HistoryService(static_cast<Profile*>(profile));
[email protected]f61f4782012-06-08 21:54:21356}
357
[email protected]d486a0852009-11-02 21:40:00358void TestingProfile::CreateHistoryService(bool delete_file, bool no_db) {
[email protected]809cc4d2010-10-27 15:22:54359 DestroyHistoryService();
[email protected]f25387b2008-08-21 15:20:33360 if (delete_file) {
[email protected]152ea302013-02-11 04:08:40361 base::FilePath path = GetPath();
[email protected]f7011fcb2009-01-28 21:54:32362 path = path.Append(chrome::kHistoryFilename);
[email protected]918efbf2013-07-01 19:41:02363 base::Delete(path, false);
[email protected]f25387b2008-08-21 15:20:33364 }
[email protected]7019bb6d2012-08-23 09:09:48365 // This will create and init the history service.
[email protected]f61f4782012-06-08 21:54:21366 HistoryService* history_service = static_cast<HistoryService*>(
367 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse(
[email protected]a5894fe2012-11-01 14:40:56368 this, BuildHistoryService));
[email protected]7019bb6d2012-08-23 09:09:48369 if (!history_service->Init(this->GetPath(),
370 BookmarkModelFactory::GetForProfile(this),
371 no_db)) {
[email protected]f61f4782012-06-08 21:54:21372 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse(this, NULL);
[email protected]7019bb6d2012-08-23 09:09:48373 }
[email protected]a50e16a2013-04-25 14:07:17374 // Disable WebHistoryService by default, since it makes network requests.
375 WebHistoryServiceFactory::GetInstance()->SetTestingFactory(this, NULL);
initial.commit09911bf2008-07-26 23:55:29376}
377
378void TestingProfile::DestroyHistoryService() {
[email protected]a5894fe2012-11-01 14:40:56379 HistoryService* history_service =
[email protected]6c537042012-07-13 00:59:02380 HistoryServiceFactory::GetForProfileWithoutCreating(this);
[email protected]a5894fe2012-11-01 14:40:56381 if (!history_service)
initial.commit09911bf2008-07-26 23:55:29382 return;
383
[email protected]f61f4782012-06-08 21:54:21384 history_service->NotifyRenderProcessHostDestruction(0);
[email protected]bb024fe2013-05-10 21:33:26385 history_service->SetOnBackendDestroyTask(base::MessageLoop::QuitClosure());
[email protected]f61f4782012-06-08 21:54:21386 history_service->Cleanup();
387 HistoryServiceFactory::ShutdownForProfile(this);
initial.commit09911bf2008-07-26 23:55:29388
389 // Wait for the backend class to terminate before deleting the files and
390 // moving to the next test. Note: if this never terminates, somebody is
391 // probably leaking a reference to the history backend, so it never calls
392 // our destroy task.
[email protected]bb024fe2013-05-10 21:33:26393 base::MessageLoop::current()->Run();
initial.commit09911bf2008-07-26 23:55:29394
initial.commit09911bf2008-07-26 23:55:29395 // Make sure we don't have any event pending that could disrupt the next
396 // test.
[email protected]bb024fe2013-05-10 21:33:26397 base::MessageLoop::current()->PostTask(FROM_HERE,
398 base::MessageLoop::QuitClosure());
399 base::MessageLoop::current()->Run();
initial.commit09911bf2008-07-26 23:55:29400}
[email protected]4d0cd7ce2008-08-11 16:40:57401
[email protected]809cc4d2010-10-27 15:22:54402void TestingProfile::CreateTopSites() {
403 DestroyTopSites();
[email protected]9a93d3432013-04-29 20:52:12404 top_sites_ = history::TopSites::Create(
405 this, GetPath().Append(chrome::kTopSitesFilename));
[email protected]809cc4d2010-10-27 15:22:54406}
407
408void TestingProfile::DestroyTopSites() {
409 if (top_sites_.get()) {
410 top_sites_->Shutdown();
411 top_sites_ = NULL;
[email protected]9a93d3432013-04-29 20:52:12412 // TopSitesImpl::Shutdown schedules some tasks (from TopSitesBackend) that
413 // need to be run to properly shutdown. Run all pending tasks now. This is
[email protected]809cc4d2010-10-27 15:22:54414 // normally handled by browser_process shutdown.
[email protected]bb024fe2013-05-10 21:33:26415 if (base::MessageLoop::current())
416 base::MessageLoop::current()->RunUntilIdle();
[email protected]809cc4d2010-10-27 15:22:54417 }
418}
419
[email protected]f1484c52013-05-22 23:25:44420static BrowserContextKeyedService* BuildBookmarkModel(
[email protected]c7fa4362013-04-26 18:09:02421 content::BrowserContext* context) {
422 Profile* profile = static_cast<Profile*>(context);
[email protected]f61f4782012-06-08 21:54:21423 BookmarkModel* bookmark_model = new BookmarkModel(profile);
[email protected]afecfb72013-04-18 17:17:33424 bookmark_model->Load(profile->GetIOTaskRunner());
[email protected]f61f4782012-06-08 21:54:21425 return bookmark_model;
426}
427
428
[email protected]d8e41ed2008-09-11 15:22:32429void TestingProfile::CreateBookmarkModel(bool delete_file) {
[email protected]90ef13132008-08-27 03:27:46430 if (delete_file) {
[email protected]8a39b472013-04-04 17:07:42431 base::FilePath path = GetPath().Append(chrome::kBookmarksFileName);
[email protected]918efbf2013-07-01 19:41:02432 base::Delete(path, false);
[email protected]90ef13132008-08-27 03:27:46433 }
[email protected]f61f4782012-06-08 21:54:21434 // This will create a bookmark model.
[email protected]8a39b472013-04-04 17:07:42435 BookmarkModel* bookmark_service = static_cast<BookmarkModel*>(
436 BookmarkModelFactory::GetInstance()->SetTestingFactoryAndUse(
437 this, BuildBookmarkModel));
[email protected]f61f4782012-06-08 21:54:21438
439 HistoryService* history_service =
[email protected]a5894fe2012-11-01 14:40:56440 HistoryServiceFactory::GetForProfileWithoutCreating(this);
[email protected]f61f4782012-06-08 21:54:21441 if (history_service) {
[email protected]8a39b472013-04-04 17:07:42442 history_service->history_backend_->bookmark_service_ = bookmark_service;
[email protected]f61f4782012-06-08 21:54:21443 history_service->history_backend_->expirer_.bookmark_service_ =
444 bookmark_service;
[email protected]90ef13132008-08-27 03:27:46445 }
[email protected]4d0cd7ce2008-08-11 16:40:57446}
[email protected]d2c017a2008-08-13 21:51:45447
[email protected]f1484c52013-05-22 23:25:44448static BrowserContextKeyedService* BuildWebDataService(
[email protected]c7fa4362013-04-26 18:09:02449 content::BrowserContext* profile) {
450 return new WebDataServiceWrapper(static_cast<Profile*>(profile));
[email protected]d07edd42012-05-14 23:49:46451}
[email protected]2609bc12010-01-24 08:32:55452
[email protected]d07edd42012-05-14 23:49:46453void TestingProfile::CreateWebDataService() {
[email protected]a5c65292012-05-25 00:50:01454 WebDataServiceFactory::GetInstance()->SetTestingFactory(
[email protected]d07edd42012-05-14 23:49:46455 this, BuildWebDataService);
[email protected]2609bc12010-01-24 08:32:55456}
457
[email protected]18a15ca82012-08-30 00:28:16458void TestingProfile::BlockUntilHistoryIndexIsRefreshed() {
459 // Only get the history service if it actually exists since the caller of the
460 // test should explicitly call CreateHistoryService to build it.
461 HistoryService* history_service =
462 HistoryServiceFactory::GetForProfileWithoutCreating(this);
463 DCHECK(history_service);
464 history::InMemoryURLIndex* index = history_service->InMemoryIndex();
465 if (!index || index->restored())
466 return;
467 base::RunLoop run_loop;
468 HistoryIndexRestoreObserver observer(
469 content::GetQuitTaskForRunLoop(&run_loop));
470 index->set_restore_cache_observer(&observer);
471 run_loop.Run();
472 index->set_restore_cache_observer(NULL);
473 DCHECK(index->restored());
474}
475
[email protected]120abf132011-09-27 21:38:06476// TODO(phajdan.jr): Doesn't this hang if Top Sites are already loaded?
[email protected]809cc4d2010-10-27 15:22:54477void TestingProfile::BlockUntilTopSitesLoaded() {
[email protected]a7fe9112012-07-20 02:34:45478 content::WindowedNotificationObserver top_sites_loaded_observer(
[email protected]120abf132011-09-27 21:38:06479 chrome::NOTIFICATION_TOP_SITES_LOADED,
[email protected]ad50def52011-10-19 23:17:07480 content::NotificationService::AllSources());
[email protected]d7f7f752012-08-08 02:02:55481 if (!HistoryServiceFactory::GetForProfile(this, Profile::EXPLICIT_ACCESS))
[email protected]809cc4d2010-10-27 15:22:54482 GetTopSites()->HistoryLoaded();
[email protected]120abf132011-09-27 21:38:06483 top_sites_loaded_observer.Wait();
[email protected]809cc4d2010-10-27 15:22:54484}
485
[email protected]152ea302013-02-11 04:08:40486base::FilePath TestingProfile::GetPath() {
[email protected]49a25632011-08-31 17:03:48487 return profile_path_;
[email protected]f9dec9482010-08-20 20:42:19488}
489
[email protected]0de615a2012-11-08 04:40:59490scoped_refptr<base::SequencedTaskRunner> TestingProfile::GetIOTaskRunner() {
[email protected]bb024fe2013-05-10 21:33:26491 return base::MessageLoop::current()->message_loop_proxy();
[email protected]0de615a2012-11-08 04:40:59492}
493
[email protected]5b199522012-12-22 17:24:44494TestingPrefServiceSyncable* TestingProfile::GetTestingPrefService() {
[email protected]2fb7dc982010-09-29 12:24:28495 if (!prefs_.get())
496 CreateTestingPrefService();
497 DCHECK(testing_prefs_);
498 return testing_prefs_;
[email protected]dbbad7a2010-08-13 18:18:36499}
500
[email protected]8e5c89a2011-06-07 18:13:33501TestingProfile* TestingProfile::AsTestingProfile() {
502 return this;
503}
504
[email protected]29d70252011-04-28 02:16:58505std::string TestingProfile::GetProfileName() {
506 return std::string("testing_profile");
507}
508
[email protected]27d6e852012-03-02 21:31:32509bool TestingProfile::IsOffTheRecord() const {
[email protected]5bb2f522011-03-25 19:04:44510 return incognito_;
[email protected]fadc607b62011-02-07 17:55:50511}
512
[email protected]93dba942011-02-23 22:45:01513void TestingProfile::SetOffTheRecordProfile(Profile* profile) {
[email protected]5bb2f522011-03-25 19:04:44514 incognito_profile_.reset(profile);
[email protected]93dba942011-02-23 22:45:01515}
516
[email protected]074311a2013-02-28 23:14:09517void TestingProfile::SetOriginalProfile(Profile* profile) {
518 original_profile_ = profile;
519}
520
[email protected]fadc607b62011-02-07 17:55:50521Profile* TestingProfile::GetOffTheRecordProfile() {
[email protected]5bb2f522011-03-25 19:04:44522 return incognito_profile_.get();
[email protected]fadc607b62011-02-07 17:55:50523}
524
525bool TestingProfile::HasOffTheRecordProfile() {
[email protected]5bb2f522011-03-25 19:04:44526 return incognito_profile_.get() != NULL;
[email protected]fadc607b62011-02-07 17:55:50527}
528
529Profile* TestingProfile::GetOriginalProfile() {
[email protected]074311a2013-02-28 23:14:09530 if (original_profile_)
531 return original_profile_;
[email protected]fadc607b62011-02-07 17:55:50532 return this;
533}
534
[email protected]eaa7dd182010-12-14 11:09:00535ExtensionService* TestingProfile::GetExtensionService() {
[email protected]bd306722012-07-11 20:43:59536 return extensions::ExtensionSystem::Get(this)->extension_service();
[email protected]2fb7dc982010-09-29 12:24:28537}
538
[email protected]2261e7b72011-07-12 13:43:55539void TestingProfile::SetExtensionSpecialStoragePolicy(
540 ExtensionSpecialStoragePolicy* extension_special_storage_policy) {
541 extension_special_storage_policy_ = extension_special_storage_policy;
542}
543
[email protected]19eb80152011-02-26 00:28:43544ExtensionSpecialStoragePolicy*
545TestingProfile::GetExtensionSpecialStoragePolicy() {
[email protected]cdba46992011-06-07 11:51:39546 if (!extension_special_storage_policy_.get())
[email protected]7c5048c2011-08-19 17:07:05547 extension_special_storage_policy_ = new ExtensionSpecialStoragePolicy(NULL);
[email protected]cdba46992011-06-07 11:51:39548 return extension_special_storage_policy_.get();
[email protected]19eb80152011-02-26 00:28:43549}
550
[email protected]dbbad7a2010-08-13 18:18:36551net::CookieMonster* TestingProfile::GetCookieMonster() {
552 if (!GetRequestContext())
553 return NULL;
[email protected]277ec262011-03-30 21:09:40554 return GetRequestContext()->GetURLRequestContext()->cookie_store()->
555 GetCookieMonster();
[email protected]dbbad7a2010-08-13 18:18:36556}
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]c7141feb2013-06-11 13:00:16562 user_prefs::UserPrefs::Set(this, prefs_.get());
[email protected]37ca3fe02013-07-05 15:32:44563 chrome::RegisterUserProfilePrefs(testing_prefs_->registry());
[email protected]2fb7dc982010-09-29 12:24:28564}
565
[email protected]d81bb3e2013-05-02 18:17:03566void TestingProfile::CreateProfilePolicyConnector() {
567 scoped_ptr<policy::PolicyService> service;
568#if defined(ENABLE_CONFIGURATION_POLICY)
569 std::vector<policy::ConfigurationPolicyProvider*> providers;
570 service.reset(new policy::PolicyServiceImpl(providers));
571#else
572 service.reset(new policy::PolicyServiceStub());
573#endif
574 profile_policy_connector_.reset(
575 new policy::ProfilePolicyConnector(this));
576 profile_policy_connector_->InitForTesting(service.Pass());
577 policy::ProfilePolicyConnectorFactory::GetInstance()->SetServiceForTesting(
578 this, profile_policy_connector_.get());
579 CHECK_EQ(profile_policy_connector_.get(),
580 policy::ProfilePolicyConnectorFactory::GetForProfile(this));
581}
582
[email protected]c753f142013-02-10 13:14:04583PrefService* TestingProfile::GetPrefs() {
[email protected]dbbad7a2010-08-13 18:18:36584 if (!prefs_.get()) {
[email protected]2fb7dc982010-09-29 12:24:28585 CreateTestingPrefService();
[email protected]dbbad7a2010-08-13 18:18:36586 }
587 return prefs_.get();
588}
589
590history::TopSites* TestingProfile::GetTopSites() {
[email protected]809cc4d2010-10-27 15:22:54591 return top_sites_.get();
[email protected]dbbad7a2010-08-13 18:18:36592}
593
[email protected]fadc607b62011-02-07 17:55:50594history::TopSites* TestingProfile::GetTopSitesWithoutCreating() {
595 return top_sites_.get();
596}
597
[email protected]b441a8492012-06-06 14:55:57598DownloadManagerDelegate* TestingProfile::GetDownloadManagerDelegate() {
[email protected]fadc607b62011-02-07 17:55:50599 return NULL;
600}
601
[email protected]abe2c032011-03-31 18:49:34602net::URLRequestContextGetter* TestingProfile::GetRequestContext() {
[email protected]812b3a32010-01-08 05:36:04603 return request_context_.get();
604}
605
[email protected]6bd30072013-02-08 18:17:11606net::URLRequestContextGetter* TestingProfile::CreateRequestContext(
[email protected]672c8c12013-03-07 12:30:06607 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11608 return request_context_.get();
609}
610
[email protected]da5683db2011-04-23 17:12:21611net::URLRequestContextGetter* TestingProfile::GetRequestContextForRenderProcess(
612 int renderer_child_id) {
[email protected]fb29e6cf2012-07-12 21:27:20613 content::RenderProcessHost* rph = content::RenderProcessHost::FromID(
614 renderer_child_id);
[email protected]1bc28312012-11-08 08:31:53615 return rph->GetStoragePartition()->GetURLRequestContext();
[email protected]d9696672011-03-15 22:45:09616}
617
[email protected]812b3a32010-01-08 05:36:04618void TestingProfile::CreateRequestContext() {
[email protected]5c6ac842013-06-02 23:37:03619 if (!request_context_.get())
620 request_context_ = new net::TestURLRequestContextGetter(
621 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
[email protected]812b3a32010-01-08 05:36:04622}
623
[email protected]7c893202010-10-07 20:18:02624void TestingProfile::ResetRequestContext() {
[email protected]3931fd82012-03-12 21:18:48625 // Any objects holding live URLFetchers should be deleted before the request
626 // context is shut down.
[email protected]16bd088b2012-04-03 08:12:12627 TemplateURLFetcherFactory::ShutdownForProfile(this);
[email protected]3931fd82012-03-12 21:18:48628
[email protected]7c893202010-10-07 20:18:02629 request_context_ = NULL;
630}
631
[email protected]10705a7b2012-08-21 19:07:08632net::URLRequestContextGetter* TestingProfile::GetMediaRequestContext() {
633 return NULL;
634}
635
636net::URLRequestContextGetter*
637TestingProfile::GetMediaRequestContextForRenderProcess(
638 int renderer_child_id) {
[email protected]fadc607b62011-02-07 17:55:50639 return NULL;
640}
641
[email protected]10eb28162012-09-18 03:04:09642net::URLRequestContextGetter*
643TestingProfile::GetMediaRequestContextForStoragePartition(
[email protected]152ea302013-02-11 04:08:40644 const base::FilePath& partition_path,
[email protected]27ddfed22012-10-30 23:22:43645 bool in_memory) {
[email protected]10eb28162012-09-18 03:04:09646 return NULL;
647}
648
[email protected]abe2c032011-03-31 18:49:34649net::URLRequestContextGetter* TestingProfile::GetRequestContextForExtensions() {
[email protected]5c6ac842013-06-02 23:37:03650 if (!extensions_request_context_.get())
[email protected]00dea9582012-05-09 15:20:05651 extensions_request_context_ = new TestExtensionURLRequestContextGetter();
[email protected]c10da4b02010-03-25 14:38:32652 return extensions_request_context_.get();
653}
654
[email protected]fadc607b62011-02-07 17:55:50655net::SSLConfigService* TestingProfile::GetSSLConfigService() {
[email protected]dc6655b2012-12-14 05:58:24656 if (!GetRequestContext())
657 return NULL;
658 return GetRequestContext()->GetURLRequestContext()->ssl_config_service();
[email protected]fadc607b62011-02-07 17:55:50659}
660
[email protected]10eb28162012-09-18 03:04:09661net::URLRequestContextGetter*
[email protected]6bd30072013-02-08 18:17:11662TestingProfile::CreateRequestContextForStoragePartition(
[email protected]152ea302013-02-11 04:08:40663 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:11664 bool in_memory,
[email protected]672c8c12013-03-07 12:30:06665 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]10eb28162012-09-18 03:04:09666 // We don't test storage partitions here yet, so returning the same dummy
[email protected]d9696672011-03-15 22:45:09667 // context is sufficient for now.
668 return GetRequestContext();
669}
670
[email protected]df02aca2012-02-09 21:03:20671content::ResourceContext* TestingProfile::GetResourceContext() {
[email protected]314c3e22012-02-21 03:57:42672 if (!resource_context_.get())
673 resource_context_.reset(new content::MockResourceContext());
674 return resource_context_.get();
[email protected]e89b77d2011-04-15 18:58:10675}
676
[email protected]dbbad7a2010-08-13 18:18:36677HostContentSettingsMap* TestingProfile::GetHostContentSettingsMap() {
[email protected]35552dc52011-07-12 09:04:38678 if (!host_content_settings_map_.get()) {
[email protected]646c29cb62012-06-18 14:31:05679 host_content_settings_map_ = new HostContentSettingsMap(GetPrefs(), false);
[email protected]701550ad2012-09-06 23:43:29680#if defined(ENABLE_EXTENSIONS)
[email protected]646c29cb62012-06-18 14:31:05681 ExtensionService* extension_service = GetExtensionService();
682 if (extension_service)
683 host_content_settings_map_->RegisterExtensionService(extension_service);
[email protected]701550ad2012-09-06 23:43:29684#endif
[email protected]35552dc52011-07-12 09:04:38685 }
[email protected]dbbad7a2010-08-13 18:18:36686 return host_content_settings_map_.get();
687}
688
[email protected]810ddc52012-01-24 01:00:35689content::GeolocationPermissionContext*
[email protected]dbbad7a2010-08-13 18:18:36690TestingProfile::GetGeolocationPermissionContext() {
[email protected]a877a7d2013-01-08 13:40:59691 return ChromeGeolocationPermissionContextFactory::GetForProfile(this);
[email protected]dbbad7a2010-08-13 18:18:36692}
693
[email protected]c52b2892012-03-07 11:01:02694content::SpeechRecognitionPreferences*
695 TestingProfile::GetSpeechRecognitionPreferences() {
[email protected]3297132a2012-02-21 23:27:59696#if defined(ENABLE_INPUT_SPEECH)
[email protected]cadac622013-06-11 16:46:36697 return ChromeSpeechRecognitionPreferences::GetForProfile(this).get();
[email protected]3297132a2012-02-21 23:27:59698#else
699 return NULL;
700#endif
[email protected]8238dd62011-09-29 15:13:01701}
702
[email protected]fadc607b62011-02-07 17:55:50703std::wstring TestingProfile::GetName() {
704 return std::wstring();
705}
706
707std::wstring TestingProfile::GetID() {
708 return id_;
709}
710
711void TestingProfile::SetID(const std::wstring& id) {
712 id_ = id;
713}
714
[email protected]fadc607b62011-02-07 17:55:50715bool TestingProfile::IsSameProfile(Profile *p) {
716 return this == p;
717}
718
719base::Time TestingProfile::GetStartTime() const {
720 return start_time_;
721}
722
[email protected]152ea302013-02-11 04:08:40723base::FilePath TestingProfile::last_selected_directory() {
[email protected]fadc607b62011-02-07 17:55:50724 return last_selected_directory_;
725}
726
[email protected]152ea302013-02-11 04:08:40727void TestingProfile::set_last_selected_directory(const base::FilePath& path) {
[email protected]fadc607b62011-02-07 17:55:50728 last_selected_directory_ = path;
729}
730
[email protected]cc5bfd42010-11-24 14:44:02731PrefProxyConfigTracker* TestingProfile::GetProxyConfigTracker() {
[email protected]6f96cbcb2011-11-04 02:26:07732 if (!pref_proxy_config_tracker_.get()) {
733 pref_proxy_config_tracker_.reset(
734 ProxyServiceFactory::CreatePrefProxyConfigTracker(GetPrefs()));
735 }
736 return pref_proxy_config_tracker_.get();
[email protected]cc5bfd42010-11-24 14:44:02737}
738
[email protected]0bfc29a2009-04-27 16:15:44739void TestingProfile::BlockUntilHistoryProcessesPendingRequests() {
[email protected]a5894fe2012-11-01 14:40:56740 HistoryService* history_service =
[email protected]6c537042012-07-13 00:59:02741 HistoryServiceFactory::GetForProfile(this, Profile::EXPLICIT_ACCESS);
[email protected]a5894fe2012-11-01 14:40:56742 DCHECK(history_service);
[email protected]bb024fe2013-05-10 21:33:26743 DCHECK(base::MessageLoop::current());
[email protected]0bfc29a2009-04-27 16:15:44744
745 CancelableRequestConsumer consumer;
[email protected]f61f4782012-06-08 21:54:21746 history_service->ScheduleDBTask(new QuittingHistoryDBTask(), &consumer);
[email protected]bb024fe2013-05-10 21:33:26747 base::MessageLoop::current()->Run();
[email protected]0bfc29a2009-04-27 16:15:44748}
[email protected]345a8b72009-09-29 09:11:44749
[email protected]8382d8c2011-09-15 03:43:17750chrome_browser_net::Predictor* TestingProfile::GetNetworkPredictor() {
751 return NULL;
752}
753
[email protected]e0e1fc22012-11-05 20:25:36754void TestingProfile::ClearNetworkingHistorySince(
755 base::Time time,
756 const base::Closure& completion) {
757 if (!completion.is_null()) {
758 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, completion);
759 }
[email protected]02896a82011-09-21 18:54:32760}
761
[email protected]671f9c62011-10-28 19:22:07762GURL TestingProfile::GetHomePage() {
763 return GURL(chrome::kChromeUINewTabURL);
764}
765
[email protected]c753f142013-02-10 13:14:04766PrefService* TestingProfile::GetOffTheRecordPrefs() {
[email protected]fadc607b62011-02-07 17:55:50767 return NULL;
768}
769
[email protected]36fb2c7c2011-04-04 15:49:08770quota::SpecialStoragePolicy* TestingProfile::GetSpecialStoragePolicy() {
771 return GetExtensionSpecialStoragePolicy();
772}
773
[email protected]1bee6ed2012-03-14 06:46:36774bool TestingProfile::WasCreatedByVersionOrLater(const std::string& version) {
775 return true;
776}
[email protected]ef92e172012-04-25 19:40:41777
[email protected]6c0ca7fc2012-10-05 16:27:22778Profile::ExitType TestingProfile::GetLastSessionExitType() {
779 return last_session_exited_cleanly_ ? EXIT_NORMAL : EXIT_CRASHED;
[email protected]2ca1ea662012-10-04 02:26:36780}
781
[email protected]5c4c89f2012-08-07 21:09:59782TestingProfile::Builder::Builder()
783 : build_called_(false),
[email protected]a0cc9a532013-02-12 02:23:12784 delegate_(NULL) {
[email protected]5c4c89f2012-08-07 21:09:59785}
786
787TestingProfile::Builder::~Builder() {
788}
789
[email protected]152ea302013-02-11 04:08:40790void TestingProfile::Builder::SetPath(const base::FilePath& path) {
[email protected]5c4c89f2012-08-07 21:09:59791 path_ = path;
792}
793
794void TestingProfile::Builder::SetDelegate(Delegate* delegate) {
795 delegate_ = delegate;
796}
797
798void TestingProfile::Builder::SetExtensionSpecialStoragePolicy(
799 scoped_refptr<ExtensionSpecialStoragePolicy> policy) {
800 extension_policy_ = policy;
801}
802
[email protected]5b199522012-12-22 17:24:44803void TestingProfile::Builder::SetPrefService(
804 scoped_ptr<PrefServiceSyncable> prefs) {
[email protected]5c4c89f2012-08-07 21:09:59805 pref_service_ = prefs.Pass();
806}
807
[email protected]5c4c89f2012-08-07 21:09:59808scoped_ptr<TestingProfile> TestingProfile::Builder::Build() {
809 DCHECK(!build_called_);
810 build_called_ = true;
811 return scoped_ptr<TestingProfile>(new TestingProfile(
812 path_,
813 delegate_,
814 extension_policy_,
[email protected]a0cc9a532013-02-12 02:23:12815 pref_service_.Pass()));
[email protected]5c4c89f2012-08-07 21:09:59816}