blob: 1cb4d9940327ef2d3f67a0b89b6fec8f8cabeebc [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]81d49782013-07-12 01:50:5221#include "chrome/browser/chrome_notification_types.h"
[email protected]9d01a6a2010-11-30 12:03:3322#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]2f69b382011-02-19 00:34:2523#include "chrome/browser/extensions/extension_service.h"
[email protected]19eb80152011-02-26 00:28:4324#include "chrome/browser/extensions/extension_special_storage_policy.h"
[email protected]31d8f5f22012-04-02 15:22:0825#include "chrome/browser/extensions/extension_system.h"
26#include "chrome/browser/extensions/extension_system_factory.h"
27#include "chrome/browser/extensions/test_extension_system.h"
[email protected]ee2ed42c2011-04-28 22:19:1428#include "chrome/browser/favicon/favicon_service.h"
[email protected]f3d2b312012-08-23 22:27:5929#include "chrome/browser/favicon/favicon_service_factory.h"
[email protected]c476e632011-06-23 11:18:0430#include "chrome/browser/geolocation/chrome_geolocation_permission_context.h"
[email protected]b2cf4522012-10-23 00:11:5731#include "chrome/browser/geolocation/chrome_geolocation_permission_context_factory.h"
[email protected]075ae732009-02-11 23:58:3132#include "chrome/browser/history/history_backend.h"
[email protected]d891f522013-02-08 03:24:4133#include "chrome/browser/history/history_db_task.h"
[email protected]6a2c09f2013-01-25 04:50:0734#include "chrome/browser/history/history_service.h"
[email protected]f61f4782012-06-08 21:54:2135#include "chrome/browser/history/history_service_factory.h"
[email protected]572f40c9b2012-07-06 20:35:3336#include "chrome/browser/history/shortcuts_backend.h"
37#include "chrome/browser/history/shortcuts_backend_factory.h"
[email protected]dbbad7a2010-08-13 18:18:3638#include "chrome/browser/history/top_sites.h"
[email protected]a50e16a2013-04-25 14:07:1739#include "chrome/browser/history/web_history_service_factory.h"
[email protected]53c5b0f2013-07-22 10:54:1140#include "chrome/browser/net/pref_proxy_config_tracker.h"
[email protected]6f96cbcb2011-11-04 02:26:0741#include "chrome/browser/net/proxy_service_factory.h"
[email protected]dbbad7a2010-08-13 18:18:3642#include "chrome/browser/notifications/desktop_notification_service.h"
[email protected]dcb72d52011-04-13 12:36:5343#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]d81bb3e2013-05-02 18:17:0344#include "chrome/browser/policy/profile_policy_connector.h"
45#include "chrome/browser/policy/profile_policy_connector_factory.h"
[email protected]37858e52010-08-26 00:22:0246#include "chrome/browser/prefs/browser_prefs.h"
[email protected]c753f142013-02-10 13:14:0447#include "chrome/browser/prefs/pref_service_syncable.h"
[email protected]4850a7f2011-03-08 23:36:5948#include "chrome/browser/prerender/prerender_manager.h"
[email protected]7e75e4a2013-05-17 17:20:0349#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
[email protected]27ddfed22012-10-30 23:22:4350#include "chrome/browser/profiles/storage_partition_descriptor.h"
[email protected]16bd088b2012-04-03 08:12:1251#include "chrome/browser/search_engines/template_url_fetcher_factory.h"
[email protected]810ffba2012-06-12 01:07:4852#include "chrome/browser/webdata/web_data_service.h"
[email protected]d07edd42012-05-14 23:49:4653#include "chrome/browser/webdata/web_data_service_factory.h"
[email protected]a9afddb2009-02-12 17:49:4254#include "chrome/common/chrome_constants.h"
[email protected]9e33d7e2011-09-30 16:43:5455#include "chrome/common/chrome_switches.h"
[email protected]e000daf2013-07-31 16:50:5856#include "chrome/common/pref_names.h"
[email protected]dbbad7a2010-08-13 18:18:3657#include "chrome/common/url_constants.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]e1480482013-09-11 11:49:5883#if defined(ENABLE_MANAGED_USERS)
84#include "chrome/browser/managed_mode/managed_user_settings_service.h"
85#include "chrome/browser/managed_mode/managed_user_settings_service_factory.h"
86#endif
87
[email protected]e1acf6f2008-10-27 20:43:3388using base::Time;
[email protected]631bb742011-11-02 11:29:3989using content::BrowserThread;
[email protected]b441a8492012-06-06 14:55:5790using content::DownloadManagerDelegate;
[email protected]3c887412010-04-19 20:30:2391using testing::NiceMock;
[email protected]4772b072010-03-30 17:45:4692using testing::Return;
[email protected]e1acf6f2008-10-27 20:43:3393
[email protected]d364c652008-08-29 19:46:5694namespace {
95
[email protected]0bfc29a2009-04-27 16:15:4496// Task used to make sure history has finished processing a request. Intended
97// for use with BlockUntilHistoryProcessesPendingRequests.
98
[email protected]d891f522013-02-08 03:24:4199class QuittingHistoryDBTask : public history::HistoryDBTask {
[email protected]0bfc29a2009-04-27 16:15:44100 public:
101 QuittingHistoryDBTask() {}
102
103 virtual bool RunOnDBThread(history::HistoryBackend* backend,
[email protected]be9826e62013-02-07 02:00:58104 history::HistoryDatabase* db) OVERRIDE {
[email protected]0bfc29a2009-04-27 16:15:44105 return true;
106 }
107
[email protected]be9826e62013-02-07 02:00:58108 virtual void DoneRunOnMainThread() OVERRIDE {
[email protected]bb024fe2013-05-10 21:33:26109 base::MessageLoop::current()->Quit();
[email protected]0bfc29a2009-04-27 16:15:44110 }
111
112 private:
[email protected]be9826e62013-02-07 02:00:58113 virtual ~QuittingHistoryDBTask() {}
[email protected]7991a232009-11-06 01:55:48114
[email protected]0bfc29a2009-04-27 16:15:44115 DISALLOW_COPY_AND_ASSIGN(QuittingHistoryDBTask);
116};
117
[email protected]33ad6ce92013-08-27 14:39:08118class TestExtensionURLRequestContext : public net::URLRequestContext {
119 public:
120 TestExtensionURLRequestContext() {
121 net::CookieMonster* cookie_monster = new net::CookieMonster(NULL, NULL);
122 const char* schemes[] = {extensions::kExtensionScheme};
123 cookie_monster->SetCookieableSchemes(schemes, 1);
124 set_cookie_store(cookie_monster);
125 }
126
127 virtual ~TestExtensionURLRequestContext() {}
128};
129
130class TestExtensionURLRequestContextGetter
131 : public net::URLRequestContextGetter {
132 public:
133 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE {
134 if (!context_.get())
135 context_.reset(new TestExtensionURLRequestContext());
136 return context_.get();
137 }
138 virtual scoped_refptr<base::SingleThreadTaskRunner>
139 GetNetworkTaskRunner() const OVERRIDE {
140 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
141 }
142
143 protected:
144 virtual ~TestExtensionURLRequestContextGetter() {}
145
146 private:
147 scoped_ptr<net::URLRequestContext> context_;
148};
149
[email protected]f1484c52013-05-22 23:25:44150BrowserContextKeyedService* CreateTestDesktopNotificationService(
[email protected]c7fa4362013-04-26 18:09:02151 content::BrowserContext* profile) {
[email protected]29cebbd2012-06-06 21:43:42152#if defined(ENABLE_NOTIFICATIONS)
[email protected]c7fa4362013-04-26 18:09:02153 return new DesktopNotificationService(static_cast<Profile*>(profile), NULL);
[email protected]29cebbd2012-06-06 21:43:42154#else
155 return NULL;
156#endif
[email protected]dcb72d52011-04-13 12:36:53157}
158
[email protected]d364c652008-08-29 19:46:56159} // namespace
160
[email protected]89dbb1772012-07-17 13:47:25161// static
162#if defined(OS_CHROMEOS)
163// Must be kept in sync with
164// ChromeBrowserMainPartsChromeos::PreEarlyInitialization.
165const char TestingProfile::kTestUserProfileDir[] = "test-user";
166#else
167const char TestingProfile::kTestUserProfileDir[] = "Default";
168#endif
169
[email protected]f25387b2008-08-21 15:20:33170TestingProfile::TestingProfile()
[email protected]ea6f76572008-12-18 00:09:55171 : start_time_(Time::Now()),
[email protected]2fb7dc982010-09-29 12:24:28172 testing_prefs_(NULL),
[email protected]5bb2f522011-03-25 19:04:44173 incognito_(false),
[email protected]9819fd02013-08-22 10:49:39174 force_incognito_(false),
[email protected]074311a2013-02-28 23:14:09175 original_profile_(NULL),
[email protected]5cdcd152011-03-31 22:48:52176 last_session_exited_cleanly_(true),
[email protected]f0901a22013-05-27 21:37:53177 browser_context_dependency_manager_(
[email protected]f1484c52013-05-22 23:25:44178 BrowserContextDependencyManager::GetInstance()),
[email protected]37ac95b2013-07-23 23:39:35179 resource_context_(NULL),
[email protected]537c1082011-12-02 02:37:17180 delegate_(NULL) {
[email protected]5c4c89f2012-08-07 21:09:59181 CreateTempProfileDir();
[email protected]49a25632011-08-31 17:03:48182 profile_path_ = temp_dir_.path();
183
184 Init();
[email protected]537c1082011-12-02 02:37:17185 FinishInit();
[email protected]49a25632011-08-31 17:03:48186}
187
[email protected]152ea302013-02-11 04:08:40188TestingProfile::TestingProfile(const base::FilePath& path)
[email protected]49a25632011-08-31 17:03:48189 : start_time_(Time::Now()),
190 testing_prefs_(NULL),
191 incognito_(false),
[email protected]9819fd02013-08-22 10:49:39192 force_incognito_(false),
[email protected]074311a2013-02-28 23:14:09193 original_profile_(NULL),
[email protected]49a25632011-08-31 17:03:48194 last_session_exited_cleanly_(true),
195 profile_path_(path),
[email protected]f0901a22013-05-27 21:37:53196 browser_context_dependency_manager_(
[email protected]f1484c52013-05-22 23:25:44197 BrowserContextDependencyManager::GetInstance()),
[email protected]37ac95b2013-07-23 23:39:35198 resource_context_(NULL),
[email protected]537c1082011-12-02 02:37:17199 delegate_(NULL) {
[email protected]49a25632011-08-31 17:03:48200 Init();
[email protected]537c1082011-12-02 02:37:17201 FinishInit();
202}
203
[email protected]152ea302013-02-11 04:08:40204TestingProfile::TestingProfile(const base::FilePath& path,
[email protected]537c1082011-12-02 02:37:17205 Delegate* delegate)
206 : start_time_(Time::Now()),
207 testing_prefs_(NULL),
208 incognito_(false),
[email protected]9819fd02013-08-22 10:49:39209 force_incognito_(false),
[email protected]074311a2013-02-28 23:14:09210 original_profile_(NULL),
[email protected]537c1082011-12-02 02:37:17211 last_session_exited_cleanly_(true),
212 profile_path_(path),
[email protected]f0901a22013-05-27 21:37:53213 browser_context_dependency_manager_(
[email protected]f1484c52013-05-22 23:25:44214 BrowserContextDependencyManager::GetInstance()),
[email protected]37ac95b2013-07-23 23:39:35215 resource_context_(NULL),
[email protected]537c1082011-12-02 02:37:17216 delegate_(delegate) {
217 Init();
218 if (delegate_) {
[email protected]bb024fe2013-05-10 21:33:26219 base::MessageLoop::current()->PostTask(
220 FROM_HERE,
221 base::Bind(&TestingProfile::FinishInit, base::Unretained(this)));
[email protected]537c1082011-12-02 02:37:17222 } else {
223 FinishInit();
224 }
[email protected]49a25632011-08-31 17:03:48225}
226
[email protected]5c4c89f2012-08-07 21:09:59227TestingProfile::TestingProfile(
[email protected]152ea302013-02-11 04:08:40228 const base::FilePath& path,
[email protected]5c4c89f2012-08-07 21:09:59229 Delegate* delegate,
230 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy,
[email protected]9819fd02013-08-22 10:49:39231 scoped_ptr<PrefServiceSyncable> prefs,
232 bool incognito,
233 const TestingFactories& factories)
[email protected]5c4c89f2012-08-07 21:09:59234 : start_time_(Time::Now()),
235 prefs_(prefs.release()),
236 testing_prefs_(NULL),
[email protected]9819fd02013-08-22 10:49:39237 incognito_(incognito),
238 force_incognito_(false),
[email protected]074311a2013-02-28 23:14:09239 original_profile_(NULL),
[email protected]5c4c89f2012-08-07 21:09:59240 last_session_exited_cleanly_(true),
241 extension_special_storage_policy_(extension_policy),
[email protected]5c4c89f2012-08-07 21:09:59242 profile_path_(path),
[email protected]f0901a22013-05-27 21:37:53243 browser_context_dependency_manager_(
[email protected]f1484c52013-05-22 23:25:44244 BrowserContextDependencyManager::GetInstance()),
[email protected]37ac95b2013-07-23 23:39:35245 resource_context_(NULL),
[email protected]5c4c89f2012-08-07 21:09:59246 delegate_(delegate) {
247
248 // If no profile path was supplied, create one.
249 if (profile_path_.empty()) {
250 CreateTempProfileDir();
251 profile_path_ = temp_dir_.path();
252 }
253
[email protected]9819fd02013-08-22 10:49:39254 // Set any testing factories prior to initializing the services.
255 for (TestingFactories::const_iterator it = factories.begin();
256 it != factories.end(); ++it) {
257 it->first->SetTestingFactory(this, it->second);
258 }
259
[email protected]5c4c89f2012-08-07 21:09:59260 Init();
261 // If caller supplied a delegate, delay the FinishInit invocation until other
262 // tasks have run.
263 // TODO(atwilson): See if this is still required once we convert the current
264 // users of the constructor that takes a Delegate* param.
265 if (delegate_) {
[email protected]bb024fe2013-05-10 21:33:26266 base::MessageLoop::current()->PostTask(
267 FROM_HERE,
268 base::Bind(&TestingProfile::FinishInit, base::Unretained(this)));
[email protected]5c4c89f2012-08-07 21:09:59269 } else {
270 FinishInit();
271 }
272}
273
274void TestingProfile::CreateTempProfileDir() {
275 if (!temp_dir_.CreateUniqueTempDir()) {
276 LOG(ERROR) << "Failed to create unique temporary directory.";
277
278 // Fallback logic in case we fail to create unique temporary directory.
[email protected]152ea302013-02-11 04:08:40279 base::FilePath system_tmp_dir;
[email protected]5c4c89f2012-08-07 21:09:59280 bool success = PathService::Get(base::DIR_TEMP, &system_tmp_dir);
281
282 // We're severly screwed if we can't get the system temporary
283 // directory. Die now to avoid writing to the filesystem root
284 // or other bad places.
285 CHECK(success);
286
[email protected]152ea302013-02-11 04:08:40287 base::FilePath fallback_dir(
288 system_tmp_dir.AppendASCII("TestingProfilePath"));
[email protected]dd3aa792013-07-16 19:10:23289 base::DeleteFile(fallback_dir, true);
[email protected]5c4c89f2012-08-07 21:09:59290 file_util::CreateDirectory(fallback_dir);
291 if (!temp_dir_.Set(fallback_dir)) {
292 // That shouldn't happen, but if it does, try to recover.
293 LOG(ERROR) << "Failed to use a fallback temporary directory.";
294
295 // We're screwed if this fails, see CHECK above.
296 CHECK(temp_dir_.Set(system_tmp_dir));
297 }
298 }
299}
300
[email protected]49a25632011-08-31 17:03:48301void TestingProfile::Init() {
[email protected]bf390cb2013-08-06 02:48:08302 // If threads have been initialized, we should be on the UI thread.
[email protected]33d06242013-08-12 05:20:30303 DCHECK(!content::BrowserThread::IsThreadInitialized(
304 content::BrowserThread::UI) ||
305 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
[email protected]bf390cb2013-08-06 02:48:08306
[email protected]7e75e4a2013-05-17 17:20:03307 // Normally this would happen during browser startup, but for tests
308 // we need to trigger creation of Profile-related services.
309 ChromeBrowserMainExtraPartsProfiles::
[email protected]f1484c52013-05-22 23:25:44310 EnsureBrowserContextKeyedServiceFactoriesBuilt();
[email protected]7e75e4a2013-05-17 17:20:03311
[email protected]75fee372013-03-06 00:42:44312 if (prefs_.get())
[email protected]c7141feb2013-06-11 13:00:16313 user_prefs::UserPrefs::Set(this, prefs_.get());
[email protected]c7fa4362013-04-26 18:09:02314 else
315 CreateTestingPrefService();
[email protected]75fee372013-03-06 00:42:44316
[email protected]7567484142013-07-11 17:36:07317 if (!base::PathExists(profile_path_))
[email protected]d41e6572012-05-04 20:49:42318 file_util::CreateDirectory(profile_path_);
319
[email protected]d81bb3e2013-05-02 18:17:03320 // TODO(joaodasilva): remove this once this PKS isn't created in ProfileImpl
321 // anymore, after converting the PrefService to a PKS. Until then it must
322 // be associated with a TestingProfile too.
323 CreateProfilePolicyConnector();
324
[email protected]bd306722012-07-11 20:43:59325 extensions::ExtensionSystemFactory::GetInstance()->SetTestingFactory(
326 this, extensions::TestExtensionSystem::Build);
[email protected]31d8f5f22012-04-02 15:22:08327
[email protected]9819fd02013-08-22 10:49:39328 // If there is no separate original profile specified for this profile, then
329 // force preferences to be registered - this allows tests to create a
330 // standalone incognito profile while still having prefs registered.
331 browser_context_dependency_manager_->CreateBrowserContextServicesForTest(
332 this, !original_profile_);
[email protected]49a25632011-08-31 17:03:48333
[email protected]5fd2e842012-03-01 00:29:11334#if defined(ENABLE_NOTIFICATIONS)
[email protected]dcb72d52011-04-13 12:36:53335 // Install profile keyed service factory hooks for dummy/test services
[email protected]7722653b2011-06-03 17:28:22336 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory(
337 this, CreateTestDesktopNotificationService);
[email protected]5fd2e842012-03-01 00:29:11338#endif
[email protected]e1480482013-09-11 11:49:58339
340#if defined(ENABLE_MANAGED_USERS)
341 ManagedUserSettingsService* settings_service =
342 ManagedUserSettingsServiceFactory::GetForProfile(this);
343 TestingPrefStore* store = new TestingPrefStore();
344 settings_service->Init(store);
345 store->SetInitializationCompleted();
346#endif
[email protected]d6001872013-09-24 18:31:26347
348 profile_name_ = "testing_profile";
[email protected]537c1082011-12-02 02:37:17349}
[email protected]12463cd2011-07-19 09:40:20350
[email protected]537c1082011-12-02 02:37:17351void TestingProfile::FinishInit() {
[email protected]080adba92011-12-07 19:00:40352 DCHECK(content::NotificationService::current());
[email protected]ad50def52011-10-19 23:17:07353 content::NotificationService::current()->Notify(
[email protected]12463cd2011-07-19 09:40:20354 chrome::NOTIFICATION_PROFILE_CREATED,
[email protected]6c2381d2011-10-19 02:52:53355 content::Source<Profile>(static_cast<Profile*>(this)),
[email protected]ad50def52011-10-19 23:17:07356 content::NotificationService::NoDetails());
[email protected]537c1082011-12-02 02:37:17357
358 if (delegate_)
[email protected]00b33f802012-03-13 07:46:03359 delegate_->OnProfileCreated(this, true, false);
[email protected]ab23dbe2010-08-12 02:10:46360}
361
[email protected]f25387b2008-08-21 15:20:33362TestingProfile::~TestingProfile() {
[email protected]9819fd02013-08-22 10:49:39363 // Revert to non-incognito mode before shutdown.
364 force_incognito_ = false;
365
[email protected]37ac95b2013-07-23 23:39:35366 // Any objects holding live URLFetchers should be deleted before teardown.
367 TemplateURLFetcherFactory::ShutdownForProfile(this);
368
[email protected]a7c4c032012-07-27 00:36:32369 MaybeSendDestroyedNotification();
[email protected]5cdcd152011-03-31 22:48:52370
[email protected]f0901a22013-05-27 21:37:53371 browser_context_dependency_manager_->DestroyBrowserContextServices(this);
[email protected]5cdcd152011-03-31 22:48:52372
[email protected]5c6ac842013-06-02 23:37:03373 if (host_content_settings_map_.get())
[email protected]35552dc52011-07-12 09:04:38374 host_content_settings_map_->ShutdownOnUIThread();
375
[email protected]809cc4d2010-10-27 15:22:54376 DestroyTopSites();
[email protected]cdba46992011-06-07 11:51:39377
[email protected]cc5bfd42010-11-24 14:44:02378 if (pref_proxy_config_tracker_.get())
379 pref_proxy_config_tracker_->DetachFromPrefService();
[email protected]37ac95b2013-07-23 23:39:35380 // Failing a post == leaks == heapcheck failure. Make that an immediate test
381 // failure.
382 if (resource_context_) {
383 CHECK(BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE,
384 resource_context_));
385 resource_context_ = NULL;
386 content::RunAllPendingInMessageLoop(BrowserThread::IO);
387 }
[email protected]f25387b2008-08-21 15:20:33388}
initial.commit09911bf2008-07-26 23:55:29389
[email protected]f1484c52013-05-22 23:25:44390static BrowserContextKeyedService* BuildFaviconService(
[email protected]c7fa4362013-04-26 18:09:02391 content::BrowserContext* profile) {
[email protected]f3d2b312012-08-23 22:27:59392 return new FaviconService(
[email protected]c7fa4362013-04-26 18:09:02393 HistoryServiceFactory::GetForProfileWithoutCreating(
394 static_cast<Profile*>(profile)));
[email protected]f3d2b312012-08-23 22:27:59395}
396
[email protected]d2879af2010-02-08 16:02:56397void TestingProfile::CreateFaviconService() {
[email protected]f3d2b312012-08-23 22:27:59398 // It is up to the caller to create the history service if one is needed.
399 FaviconServiceFactory::GetInstance()->SetTestingFactory(
400 this, BuildFaviconService);
[email protected]d2879af2010-02-08 16:02:56401}
402
[email protected]f1484c52013-05-22 23:25:44403static BrowserContextKeyedService* BuildHistoryService(
[email protected]c7fa4362013-04-26 18:09:02404 content::BrowserContext* profile) {
405 return new HistoryService(static_cast<Profile*>(profile));
[email protected]f61f4782012-06-08 21:54:21406}
407
[email protected]608e7e02013-07-24 12:23:31408bool TestingProfile::CreateHistoryService(bool delete_file, bool no_db) {
[email protected]809cc4d2010-10-27 15:22:54409 DestroyHistoryService();
[email protected]f25387b2008-08-21 15:20:33410 if (delete_file) {
[email protected]152ea302013-02-11 04:08:40411 base::FilePath path = GetPath();
[email protected]f7011fcb2009-01-28 21:54:32412 path = path.Append(chrome::kHistoryFilename);
[email protected]608e7e02013-07-24 12:23:31413 if (!base::DeleteFile(path, false) || base::PathExists(path))
414 return false;
[email protected]f25387b2008-08-21 15:20:33415 }
[email protected]7019bb6d2012-08-23 09:09:48416 // This will create and init the history service.
[email protected]f61f4782012-06-08 21:54:21417 HistoryService* history_service = static_cast<HistoryService*>(
418 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse(
[email protected]a5894fe2012-11-01 14:40:56419 this, BuildHistoryService));
[email protected]7019bb6d2012-08-23 09:09:48420 if (!history_service->Init(this->GetPath(),
421 BookmarkModelFactory::GetForProfile(this),
422 no_db)) {
[email protected]f61f4782012-06-08 21:54:21423 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse(this, NULL);
[email protected]7019bb6d2012-08-23 09:09:48424 }
[email protected]a50e16a2013-04-25 14:07:17425 // Disable WebHistoryService by default, since it makes network requests.
426 WebHistoryServiceFactory::GetInstance()->SetTestingFactory(this, NULL);
[email protected]608e7e02013-07-24 12:23:31427 return true;
initial.commit09911bf2008-07-26 23:55:29428}
429
430void TestingProfile::DestroyHistoryService() {
[email protected]a5894fe2012-11-01 14:40:56431 HistoryService* history_service =
[email protected]6c537042012-07-13 00:59:02432 HistoryServiceFactory::GetForProfileWithoutCreating(this);
[email protected]a5894fe2012-11-01 14:40:56433 if (!history_service)
initial.commit09911bf2008-07-26 23:55:29434 return;
435
[email protected]f61f4782012-06-08 21:54:21436 history_service->NotifyRenderProcessHostDestruction(0);
[email protected]bb024fe2013-05-10 21:33:26437 history_service->SetOnBackendDestroyTask(base::MessageLoop::QuitClosure());
[email protected]f61f4782012-06-08 21:54:21438 history_service->Cleanup();
439 HistoryServiceFactory::ShutdownForProfile(this);
initial.commit09911bf2008-07-26 23:55:29440
441 // Wait for the backend class to terminate before deleting the files and
442 // moving to the next test. Note: if this never terminates, somebody is
443 // probably leaking a reference to the history backend, so it never calls
444 // our destroy task.
[email protected]bb024fe2013-05-10 21:33:26445 base::MessageLoop::current()->Run();
initial.commit09911bf2008-07-26 23:55:29446
initial.commit09911bf2008-07-26 23:55:29447 // Make sure we don't have any event pending that could disrupt the next
448 // test.
[email protected]bb024fe2013-05-10 21:33:26449 base::MessageLoop::current()->PostTask(FROM_HERE,
450 base::MessageLoop::QuitClosure());
451 base::MessageLoop::current()->Run();
initial.commit09911bf2008-07-26 23:55:29452}
[email protected]4d0cd7ce2008-08-11 16:40:57453
[email protected]809cc4d2010-10-27 15:22:54454void TestingProfile::CreateTopSites() {
455 DestroyTopSites();
[email protected]9a93d3432013-04-29 20:52:12456 top_sites_ = history::TopSites::Create(
457 this, GetPath().Append(chrome::kTopSitesFilename));
[email protected]809cc4d2010-10-27 15:22:54458}
459
460void TestingProfile::DestroyTopSites() {
461 if (top_sites_.get()) {
462 top_sites_->Shutdown();
463 top_sites_ = NULL;
[email protected]9a93d3432013-04-29 20:52:12464 // TopSitesImpl::Shutdown schedules some tasks (from TopSitesBackend) that
465 // need to be run to properly shutdown. Run all pending tasks now. This is
[email protected]809cc4d2010-10-27 15:22:54466 // normally handled by browser_process shutdown.
[email protected]bb024fe2013-05-10 21:33:26467 if (base::MessageLoop::current())
468 base::MessageLoop::current()->RunUntilIdle();
[email protected]809cc4d2010-10-27 15:22:54469 }
470}
471
[email protected]f1484c52013-05-22 23:25:44472static BrowserContextKeyedService* BuildBookmarkModel(
[email protected]c7fa4362013-04-26 18:09:02473 content::BrowserContext* context) {
474 Profile* profile = static_cast<Profile*>(context);
[email protected]f61f4782012-06-08 21:54:21475 BookmarkModel* bookmark_model = new BookmarkModel(profile);
[email protected]afecfb72013-04-18 17:17:33476 bookmark_model->Load(profile->GetIOTaskRunner());
[email protected]f61f4782012-06-08 21:54:21477 return bookmark_model;
478}
479
[email protected]d8e41ed2008-09-11 15:22:32480void TestingProfile::CreateBookmarkModel(bool delete_file) {
[email protected]90ef13132008-08-27 03:27:46481 if (delete_file) {
[email protected]8a39b472013-04-04 17:07:42482 base::FilePath path = GetPath().Append(chrome::kBookmarksFileName);
[email protected]dd3aa792013-07-16 19:10:23483 base::DeleteFile(path, false);
[email protected]90ef13132008-08-27 03:27:46484 }
[email protected]f61f4782012-06-08 21:54:21485 // This will create a bookmark model.
[email protected]8a39b472013-04-04 17:07:42486 BookmarkModel* bookmark_service = static_cast<BookmarkModel*>(
487 BookmarkModelFactory::GetInstance()->SetTestingFactoryAndUse(
488 this, BuildBookmarkModel));
[email protected]f61f4782012-06-08 21:54:21489
490 HistoryService* history_service =
[email protected]a5894fe2012-11-01 14:40:56491 HistoryServiceFactory::GetForProfileWithoutCreating(this);
[email protected]f61f4782012-06-08 21:54:21492 if (history_service) {
[email protected]8a39b472013-04-04 17:07:42493 history_service->history_backend_->bookmark_service_ = bookmark_service;
[email protected]f61f4782012-06-08 21:54:21494 history_service->history_backend_->expirer_.bookmark_service_ =
495 bookmark_service;
[email protected]90ef13132008-08-27 03:27:46496 }
[email protected]4d0cd7ce2008-08-11 16:40:57497}
[email protected]d2c017a2008-08-13 21:51:45498
[email protected]f1484c52013-05-22 23:25:44499static BrowserContextKeyedService* BuildWebDataService(
[email protected]c7fa4362013-04-26 18:09:02500 content::BrowserContext* profile) {
501 return new WebDataServiceWrapper(static_cast<Profile*>(profile));
[email protected]d07edd42012-05-14 23:49:46502}
[email protected]2609bc12010-01-24 08:32:55503
[email protected]d07edd42012-05-14 23:49:46504void TestingProfile::CreateWebDataService() {
[email protected]a5c65292012-05-25 00:50:01505 WebDataServiceFactory::GetInstance()->SetTestingFactory(
[email protected]d07edd42012-05-14 23:49:46506 this, BuildWebDataService);
[email protected]2609bc12010-01-24 08:32:55507}
508
[email protected]18a15ca82012-08-30 00:28:16509void TestingProfile::BlockUntilHistoryIndexIsRefreshed() {
510 // Only get the history service if it actually exists since the caller of the
511 // test should explicitly call CreateHistoryService to build it.
512 HistoryService* history_service =
513 HistoryServiceFactory::GetForProfileWithoutCreating(this);
514 DCHECK(history_service);
515 history::InMemoryURLIndex* index = history_service->InMemoryIndex();
516 if (!index || index->restored())
517 return;
518 base::RunLoop run_loop;
519 HistoryIndexRestoreObserver observer(
520 content::GetQuitTaskForRunLoop(&run_loop));
521 index->set_restore_cache_observer(&observer);
522 run_loop.Run();
523 index->set_restore_cache_observer(NULL);
524 DCHECK(index->restored());
525}
526
[email protected]120abf132011-09-27 21:38:06527// TODO(phajdan.jr): Doesn't this hang if Top Sites are already loaded?
[email protected]809cc4d2010-10-27 15:22:54528void TestingProfile::BlockUntilTopSitesLoaded() {
[email protected]a7fe9112012-07-20 02:34:45529 content::WindowedNotificationObserver top_sites_loaded_observer(
[email protected]120abf132011-09-27 21:38:06530 chrome::NOTIFICATION_TOP_SITES_LOADED,
[email protected]ad50def52011-10-19 23:17:07531 content::NotificationService::AllSources());
[email protected]120abf132011-09-27 21:38:06532 top_sites_loaded_observer.Wait();
[email protected]809cc4d2010-10-27 15:22:54533}
534
[email protected]4251165a2013-07-17 04:33:40535base::FilePath TestingProfile::GetPath() const {
[email protected]49a25632011-08-31 17:03:48536 return profile_path_;
[email protected]f9dec9482010-08-20 20:42:19537}
538
[email protected]0de615a2012-11-08 04:40:59539scoped_refptr<base::SequencedTaskRunner> TestingProfile::GetIOTaskRunner() {
[email protected]bb024fe2013-05-10 21:33:26540 return base::MessageLoop::current()->message_loop_proxy();
[email protected]0de615a2012-11-08 04:40:59541}
542
[email protected]5b199522012-12-22 17:24:44543TestingPrefServiceSyncable* TestingProfile::GetTestingPrefService() {
[email protected]2fb7dc982010-09-29 12:24:28544 if (!prefs_.get())
545 CreateTestingPrefService();
546 DCHECK(testing_prefs_);
547 return testing_prefs_;
[email protected]dbbad7a2010-08-13 18:18:36548}
549
[email protected]8e5c89a2011-06-07 18:13:33550TestingProfile* TestingProfile::AsTestingProfile() {
551 return this;
552}
553
[email protected]29d70252011-04-28 02:16:58554std::string TestingProfile::GetProfileName() {
[email protected]d6001872013-09-24 18:31:26555 return profile_name_;
[email protected]29d70252011-04-28 02:16:58556}
557
[email protected]27d6e852012-03-02 21:31:32558bool TestingProfile::IsOffTheRecord() const {
[email protected]9819fd02013-08-22 10:49:39559 return force_incognito_ || incognito_;
[email protected]fadc607b62011-02-07 17:55:50560}
561
[email protected]9819fd02013-08-22 10:49:39562void TestingProfile::SetOffTheRecordProfile(scoped_ptr<Profile> profile) {
563 DCHECK(!IsOffTheRecord());
564 incognito_profile_ = profile.Pass();
[email protected]93dba942011-02-23 22:45:01565}
566
[email protected]074311a2013-02-28 23:14:09567void TestingProfile::SetOriginalProfile(Profile* profile) {
[email protected]9819fd02013-08-22 10:49:39568 DCHECK(IsOffTheRecord());
[email protected]074311a2013-02-28 23:14:09569 original_profile_ = profile;
570}
571
[email protected]fadc607b62011-02-07 17:55:50572Profile* TestingProfile::GetOffTheRecordProfile() {
[email protected]9819fd02013-08-22 10:49:39573 if (IsOffTheRecord())
574 return this;
[email protected]5bb2f522011-03-25 19:04:44575 return incognito_profile_.get();
[email protected]fadc607b62011-02-07 17:55:50576}
577
578bool TestingProfile::HasOffTheRecordProfile() {
[email protected]5bb2f522011-03-25 19:04:44579 return incognito_profile_.get() != NULL;
[email protected]fadc607b62011-02-07 17:55:50580}
581
582Profile* TestingProfile::GetOriginalProfile() {
[email protected]074311a2013-02-28 23:14:09583 if (original_profile_)
584 return original_profile_;
[email protected]fadc607b62011-02-07 17:55:50585 return this;
586}
587
[email protected]e000daf2013-07-31 16:50:58588bool TestingProfile::IsManaged() {
[email protected]61dadac82013-08-21 12:47:18589 return !GetPrefs()->GetString(prefs::kManagedUserId).empty();
[email protected]e000daf2013-07-31 16:50:58590}
591
[email protected]eaa7dd182010-12-14 11:09:00592ExtensionService* TestingProfile::GetExtensionService() {
[email protected]bd306722012-07-11 20:43:59593 return extensions::ExtensionSystem::Get(this)->extension_service();
[email protected]2fb7dc982010-09-29 12:24:28594}
595
[email protected]2261e7b72011-07-12 13:43:55596void TestingProfile::SetExtensionSpecialStoragePolicy(
597 ExtensionSpecialStoragePolicy* extension_special_storage_policy) {
598 extension_special_storage_policy_ = extension_special_storage_policy;
599}
600
[email protected]19eb80152011-02-26 00:28:43601ExtensionSpecialStoragePolicy*
602TestingProfile::GetExtensionSpecialStoragePolicy() {
[email protected]cdba46992011-06-07 11:51:39603 if (!extension_special_storage_policy_.get())
[email protected]7c5048c2011-08-19 17:07:05604 extension_special_storage_policy_ = new ExtensionSpecialStoragePolicy(NULL);
[email protected]cdba46992011-06-07 11:51:39605 return extension_special_storage_policy_.get();
[email protected]19eb80152011-02-26 00:28:43606}
607
[email protected]33ad6ce92013-08-27 14:39:08608net::CookieMonster* TestingProfile::GetCookieMonster() {
609 if (!GetRequestContext())
610 return NULL;
611 return GetRequestContext()->GetURLRequestContext()->cookie_store()->
612 GetCookieMonster();
613}
614
[email protected]2fb7dc982010-09-29 12:24:28615void TestingProfile::CreateTestingPrefService() {
616 DCHECK(!prefs_.get());
[email protected]5b199522012-12-22 17:24:44617 testing_prefs_ = new TestingPrefServiceSyncable();
[email protected]2fb7dc982010-09-29 12:24:28618 prefs_.reset(testing_prefs_);
[email protected]c7141feb2013-06-11 13:00:16619 user_prefs::UserPrefs::Set(this, prefs_.get());
[email protected]37ca3fe02013-07-05 15:32:44620 chrome::RegisterUserProfilePrefs(testing_prefs_->registry());
[email protected]2fb7dc982010-09-29 12:24:28621}
622
[email protected]d81bb3e2013-05-02 18:17:03623void TestingProfile::CreateProfilePolicyConnector() {
624 scoped_ptr<policy::PolicyService> service;
625#if defined(ENABLE_CONFIGURATION_POLICY)
626 std::vector<policy::ConfigurationPolicyProvider*> providers;
627 service.reset(new policy::PolicyServiceImpl(providers));
628#else
629 service.reset(new policy::PolicyServiceStub());
630#endif
631 profile_policy_connector_.reset(
632 new policy::ProfilePolicyConnector(this));
633 profile_policy_connector_->InitForTesting(service.Pass());
634 policy::ProfilePolicyConnectorFactory::GetInstance()->SetServiceForTesting(
635 this, profile_policy_connector_.get());
636 CHECK_EQ(profile_policy_connector_.get(),
637 policy::ProfilePolicyConnectorFactory::GetForProfile(this));
638}
639
[email protected]c753f142013-02-10 13:14:04640PrefService* TestingProfile::GetPrefs() {
[email protected]dbbad7a2010-08-13 18:18:36641 if (!prefs_.get()) {
[email protected]2fb7dc982010-09-29 12:24:28642 CreateTestingPrefService();
[email protected]dbbad7a2010-08-13 18:18:36643 }
644 return prefs_.get();
645}
646
647history::TopSites* TestingProfile::GetTopSites() {
[email protected]809cc4d2010-10-27 15:22:54648 return top_sites_.get();
[email protected]dbbad7a2010-08-13 18:18:36649}
650
[email protected]fadc607b62011-02-07 17:55:50651history::TopSites* TestingProfile::GetTopSitesWithoutCreating() {
652 return top_sites_.get();
653}
654
[email protected]b441a8492012-06-06 14:55:57655DownloadManagerDelegate* TestingProfile::GetDownloadManagerDelegate() {
[email protected]fadc607b62011-02-07 17:55:50656 return NULL;
657}
658
[email protected]abe2c032011-03-31 18:49:34659net::URLRequestContextGetter* TestingProfile::GetRequestContext() {
[email protected]37ac95b2013-07-23 23:39:35660 return GetDefaultStoragePartition(this)->GetURLRequestContext();
[email protected]812b3a32010-01-08 05:36:04661}
662
[email protected]6bd30072013-02-08 18:17:11663net::URLRequestContextGetter* TestingProfile::CreateRequestContext(
[email protected]672c8c12013-03-07 12:30:06664 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]37ac95b2013-07-23 23:39:35665 return new net::TestURLRequestContextGetter(
666 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
[email protected]6bd30072013-02-08 18:17:11667}
668
[email protected]da5683db2011-04-23 17:12:21669net::URLRequestContextGetter* TestingProfile::GetRequestContextForRenderProcess(
670 int renderer_child_id) {
[email protected]fb29e6cf2012-07-12 21:27:20671 content::RenderProcessHost* rph = content::RenderProcessHost::FromID(
672 renderer_child_id);
[email protected]1bc28312012-11-08 08:31:53673 return rph->GetStoragePartition()->GetURLRequestContext();
[email protected]d9696672011-03-15 22:45:09674}
675
[email protected]10705a7b2012-08-21 19:07:08676net::URLRequestContextGetter* TestingProfile::GetMediaRequestContext() {
677 return NULL;
678}
679
680net::URLRequestContextGetter*
681TestingProfile::GetMediaRequestContextForRenderProcess(
682 int renderer_child_id) {
[email protected]fadc607b62011-02-07 17:55:50683 return NULL;
684}
685
[email protected]10eb28162012-09-18 03:04:09686net::URLRequestContextGetter*
687TestingProfile::GetMediaRequestContextForStoragePartition(
[email protected]152ea302013-02-11 04:08:40688 const base::FilePath& partition_path,
[email protected]27ddfed22012-10-30 23:22:43689 bool in_memory) {
[email protected]10eb28162012-09-18 03:04:09690 return NULL;
691}
692
[email protected]8aca7252013-07-12 19:18:59693void TestingProfile::RequestMIDISysExPermission(
694 int render_process_id,
695 int render_view_id,
696 const GURL& requesting_frame,
697 const MIDISysExPermissionCallback& callback) {
698 // Always reject requests for testing.
699 callback.Run(false);
700}
701
[email protected]33ad6ce92013-08-27 14:39:08702net::URLRequestContextGetter* TestingProfile::GetRequestContextForExtensions() {
703 if (!extensions_request_context_.get())
704 extensions_request_context_ = new TestExtensionURLRequestContextGetter();
705 return extensions_request_context_.get();
706}
707
[email protected]fadc607b62011-02-07 17:55:50708net::SSLConfigService* TestingProfile::GetSSLConfigService() {
[email protected]dc6655b2012-12-14 05:58:24709 if (!GetRequestContext())
710 return NULL;
711 return GetRequestContext()->GetURLRequestContext()->ssl_config_service();
[email protected]fadc607b62011-02-07 17:55:50712}
713
[email protected]10eb28162012-09-18 03:04:09714net::URLRequestContextGetter*
[email protected]6bd30072013-02-08 18:17:11715TestingProfile::CreateRequestContextForStoragePartition(
[email protected]152ea302013-02-11 04:08:40716 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:11717 bool in_memory,
[email protected]672c8c12013-03-07 12:30:06718 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]10eb28162012-09-18 03:04:09719 // We don't test storage partitions here yet, so returning the same dummy
[email protected]d9696672011-03-15 22:45:09720 // context is sufficient for now.
721 return GetRequestContext();
722}
723
[email protected]df02aca2012-02-09 21:03:20724content::ResourceContext* TestingProfile::GetResourceContext() {
[email protected]37ac95b2013-07-23 23:39:35725 if (!resource_context_)
726 resource_context_ = new content::MockResourceContext();
727 return resource_context_;
[email protected]e89b77d2011-04-15 18:58:10728}
729
[email protected]dbbad7a2010-08-13 18:18:36730HostContentSettingsMap* TestingProfile::GetHostContentSettingsMap() {
[email protected]35552dc52011-07-12 09:04:38731 if (!host_content_settings_map_.get()) {
[email protected]646c29cb62012-06-18 14:31:05732 host_content_settings_map_ = new HostContentSettingsMap(GetPrefs(), false);
[email protected]701550ad2012-09-06 23:43:29733#if defined(ENABLE_EXTENSIONS)
[email protected]646c29cb62012-06-18 14:31:05734 ExtensionService* extension_service = GetExtensionService();
735 if (extension_service)
736 host_content_settings_map_->RegisterExtensionService(extension_service);
[email protected]701550ad2012-09-06 23:43:29737#endif
[email protected]35552dc52011-07-12 09:04:38738 }
[email protected]dbbad7a2010-08-13 18:18:36739 return host_content_settings_map_.get();
740}
741
[email protected]810ddc52012-01-24 01:00:35742content::GeolocationPermissionContext*
[email protected]dbbad7a2010-08-13 18:18:36743TestingProfile::GetGeolocationPermissionContext() {
[email protected]a877a7d2013-01-08 13:40:59744 return ChromeGeolocationPermissionContextFactory::GetForProfile(this);
[email protected]dbbad7a2010-08-13 18:18:36745}
746
[email protected]fadc607b62011-02-07 17:55:50747std::wstring TestingProfile::GetName() {
748 return std::wstring();
749}
750
751std::wstring TestingProfile::GetID() {
752 return id_;
753}
754
755void TestingProfile::SetID(const std::wstring& id) {
756 id_ = id;
757}
758
[email protected]fadc607b62011-02-07 17:55:50759bool TestingProfile::IsSameProfile(Profile *p) {
760 return this == p;
761}
762
763base::Time TestingProfile::GetStartTime() const {
764 return start_time_;
765}
766
[email protected]152ea302013-02-11 04:08:40767base::FilePath TestingProfile::last_selected_directory() {
[email protected]fadc607b62011-02-07 17:55:50768 return last_selected_directory_;
769}
770
[email protected]152ea302013-02-11 04:08:40771void TestingProfile::set_last_selected_directory(const base::FilePath& path) {
[email protected]fadc607b62011-02-07 17:55:50772 last_selected_directory_ = path;
773}
774
[email protected]cc5bfd42010-11-24 14:44:02775PrefProxyConfigTracker* TestingProfile::GetProxyConfigTracker() {
[email protected]6f96cbcb2011-11-04 02:26:07776 if (!pref_proxy_config_tracker_.get()) {
[email protected]e2930d0902013-07-17 05:25:42777 // TestingProfile is used in unit tests, where local state is not available.
[email protected]6f96cbcb2011-11-04 02:26:07778 pref_proxy_config_tracker_.reset(
[email protected]e2930d0902013-07-17 05:25:42779 ProxyServiceFactory::CreatePrefProxyConfigTrackerOfProfile(GetPrefs(),
780 NULL));
[email protected]6f96cbcb2011-11-04 02:26:07781 }
782 return pref_proxy_config_tracker_.get();
[email protected]cc5bfd42010-11-24 14:44:02783}
784
[email protected]0bfc29a2009-04-27 16:15:44785void TestingProfile::BlockUntilHistoryProcessesPendingRequests() {
[email protected]a5894fe2012-11-01 14:40:56786 HistoryService* history_service =
[email protected]6c537042012-07-13 00:59:02787 HistoryServiceFactory::GetForProfile(this, Profile::EXPLICIT_ACCESS);
[email protected]a5894fe2012-11-01 14:40:56788 DCHECK(history_service);
[email protected]bb024fe2013-05-10 21:33:26789 DCHECK(base::MessageLoop::current());
[email protected]0bfc29a2009-04-27 16:15:44790
791 CancelableRequestConsumer consumer;
[email protected]f61f4782012-06-08 21:54:21792 history_service->ScheduleDBTask(new QuittingHistoryDBTask(), &consumer);
[email protected]bb024fe2013-05-10 21:33:26793 base::MessageLoop::current()->Run();
[email protected]0bfc29a2009-04-27 16:15:44794}
[email protected]345a8b72009-09-29 09:11:44795
[email protected]8382d8c2011-09-15 03:43:17796chrome_browser_net::Predictor* TestingProfile::GetNetworkPredictor() {
797 return NULL;
798}
799
[email protected]e0e1fc22012-11-05 20:25:36800void TestingProfile::ClearNetworkingHistorySince(
801 base::Time time,
802 const base::Closure& completion) {
803 if (!completion.is_null()) {
804 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, completion);
805 }
[email protected]02896a82011-09-21 18:54:32806}
807
[email protected]671f9c62011-10-28 19:22:07808GURL TestingProfile::GetHomePage() {
809 return GURL(chrome::kChromeUINewTabURL);
810}
811
[email protected]c753f142013-02-10 13:14:04812PrefService* TestingProfile::GetOffTheRecordPrefs() {
[email protected]fadc607b62011-02-07 17:55:50813 return NULL;
814}
815
[email protected]36fb2c7c2011-04-04 15:49:08816quota::SpecialStoragePolicy* TestingProfile::GetSpecialStoragePolicy() {
817 return GetExtensionSpecialStoragePolicy();
818}
819
[email protected]1bee6ed2012-03-14 06:46:36820bool TestingProfile::WasCreatedByVersionOrLater(const std::string& version) {
821 return true;
822}
[email protected]ef92e172012-04-25 19:40:41823
[email protected]4251165a2013-07-17 04:33:40824bool TestingProfile::IsGuestSession() const {
825 return false;
826}
[email protected]6c0ca7fc2012-10-05 16:27:22827Profile::ExitType TestingProfile::GetLastSessionExitType() {
828 return last_session_exited_cleanly_ ? EXIT_NORMAL : EXIT_CRASHED;
[email protected]2ca1ea662012-10-04 02:26:36829}
830
[email protected]5c4c89f2012-08-07 21:09:59831TestingProfile::Builder::Builder()
832 : build_called_(false),
[email protected]9819fd02013-08-22 10:49:39833 delegate_(NULL),
834 incognito_(false) {
[email protected]5c4c89f2012-08-07 21:09:59835}
836
837TestingProfile::Builder::~Builder() {
838}
839
[email protected]152ea302013-02-11 04:08:40840void TestingProfile::Builder::SetPath(const base::FilePath& path) {
[email protected]5c4c89f2012-08-07 21:09:59841 path_ = path;
842}
843
844void TestingProfile::Builder::SetDelegate(Delegate* delegate) {
845 delegate_ = delegate;
846}
847
848void TestingProfile::Builder::SetExtensionSpecialStoragePolicy(
849 scoped_refptr<ExtensionSpecialStoragePolicy> policy) {
850 extension_policy_ = policy;
851}
852
[email protected]5b199522012-12-22 17:24:44853void TestingProfile::Builder::SetPrefService(
854 scoped_ptr<PrefServiceSyncable> prefs) {
[email protected]5c4c89f2012-08-07 21:09:59855 pref_service_ = prefs.Pass();
856}
857
[email protected]9819fd02013-08-22 10:49:39858void TestingProfile::Builder::SetIncognito() {
859 incognito_ = true;
860}
861
862void TestingProfile::Builder::AddTestingFactory(
863 BrowserContextKeyedServiceFactory* service_factory,
864 BrowserContextKeyedServiceFactory::FactoryFunction callback) {
865 testing_factories_.push_back(std::make_pair(service_factory, callback));
866}
867
[email protected]5c4c89f2012-08-07 21:09:59868scoped_ptr<TestingProfile> TestingProfile::Builder::Build() {
869 DCHECK(!build_called_);
870 build_called_ = true;
871 return scoped_ptr<TestingProfile>(new TestingProfile(
872 path_,
873 delegate_,
874 extension_policy_,
[email protected]9819fd02013-08-22 10:49:39875 pref_service_.Pass(),
876 incognito_,
877 testing_factories_));
[email protected]5c4c89f2012-08-07 21:09:59878}