blob: 9570da03e3e207afaaea2ddd3fdd0b1dff5ceea8 [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]7bc60682011-07-29 20:55:5958#include "chrome/test/base/bookmark_load_observer.h"
[email protected]18a15ca82012-08-30 00:28:1659#include "chrome/test/base/history_index_restore_observer.h"
[email protected]7688968a2013-02-12 21:45:1360#include "chrome/test/base/testing_pref_service_syncable.h"
[email protected]af44e7fb2011-07-29 18:32:3261#include "chrome/test/base/ui_test_utils.h"
[email protected]0dd6f2032013-05-20 23:33:4062#include "components/browser_context_keyed_service/browser_context_dependency_manager.h"
[email protected]75fee372013-03-06 00:42:4463#include "components/user_prefs/user_prefs.h"
[email protected]c38831a12011-10-28 12:44:4964#include "content/public/browser/browser_thread.h"
[email protected]ad50def52011-10-19 23:17:0765#include "content/public/browser/notification_service.h"
[email protected]fb29e6cf2012-07-12 21:27:2066#include "content/public/browser/render_process_host.h"
[email protected]885c0e92012-11-13 20:27:4267#include "content/public/browser/storage_partition.h"
[email protected]08a932d52012-06-03 21:42:1268#include "content/public/test/mock_resource_context.h"
[email protected]a7fe9112012-07-20 02:34:4569#include "content/public/test/test_utils.h"
[email protected]885c0e92012-11-13 20:27:4270#include "extensions/common/constants.h"
[email protected]aa84a7e2012-03-15 21:29:0671#include "net/cookies/cookie_monster.h"
[email protected]812b3a32010-01-08 05:36:0472#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:3473#include "net/url_request/url_request_context_getter.h"
[email protected]d2db0292011-01-26 20:23:4474#include "net/url_request/url_request_test_util.h"
[email protected]4772b072010-03-30 17:45:4675#include "testing/gmock/include/gmock/gmock.h"
[email protected]248ce192011-02-10 15:26:3476
[email protected]21d3a882012-05-31 14:41:5577#if defined(ENABLE_CONFIGURATION_POLICY)
[email protected]d81bb3e2013-05-02 18:17:0378#include "chrome/browser/policy/configuration_policy_provider.h"
[email protected]21d3a882012-05-31 14:41:5579#include "chrome/browser/policy/policy_service_impl.h"
80#else
81#include "chrome/browser/policy/policy_service_stub.h"
82#endif // defined(ENABLE_CONFIGURATION_POLICY)
83
[email protected]e1acf6f2008-10-27 20:43:3384using base::Time;
[email protected]631bb742011-11-02 11:29:3985using content::BrowserThread;
[email protected]b441a8492012-06-06 14:55:5786using content::DownloadManagerDelegate;
[email protected]3c887412010-04-19 20:30:2387using testing::NiceMock;
[email protected]4772b072010-03-30 17:45:4688using testing::Return;
[email protected]e1acf6f2008-10-27 20:43:3389
[email protected]d364c652008-08-29 19:46:5690namespace {
91
[email protected]0bfc29a2009-04-27 16:15:4492// Task used to make sure history has finished processing a request. Intended
93// for use with BlockUntilHistoryProcessesPendingRequests.
94
[email protected]d891f522013-02-08 03:24:4195class QuittingHistoryDBTask : public history::HistoryDBTask {
[email protected]0bfc29a2009-04-27 16:15:4496 public:
97 QuittingHistoryDBTask() {}
98
99 virtual bool RunOnDBThread(history::HistoryBackend* backend,
[email protected]be9826e62013-02-07 02:00:58100 history::HistoryDatabase* db) OVERRIDE {
[email protected]0bfc29a2009-04-27 16:15:44101 return true;
102 }
103
[email protected]be9826e62013-02-07 02:00:58104 virtual void DoneRunOnMainThread() OVERRIDE {
[email protected]bb024fe2013-05-10 21:33:26105 base::MessageLoop::current()->Quit();
[email protected]0bfc29a2009-04-27 16:15:44106 }
107
108 private:
[email protected]be9826e62013-02-07 02:00:58109 virtual ~QuittingHistoryDBTask() {}
[email protected]7991a232009-11-06 01:55:48110
[email protected]0bfc29a2009-04-27 16:15:44111 DISALLOW_COPY_AND_ASSIGN(QuittingHistoryDBTask);
112};
113
[email protected]aeb53f02011-01-15 00:21:34114class TestExtensionURLRequestContext : public net::URLRequestContext {
[email protected]c10da4b02010-03-25 14:38:32115 public:
116 TestExtensionURLRequestContext() {
117 net::CookieMonster* cookie_monster = new net::CookieMonster(NULL, NULL);
[email protected]885c0e92012-11-13 20:27:42118 const char* schemes[] = {extensions::kExtensionScheme};
[email protected]c10da4b02010-03-25 14:38:32119 cookie_monster->SetCookieableSchemes(schemes, 1);
[email protected]f6c21cb2011-02-16 19:45:41120 set_cookie_store(cookie_monster);
[email protected]c10da4b02010-03-25 14:38:32121 }
[email protected]7b2720b2012-04-25 16:59:11122
[email protected]7b2720b2012-04-25 16:59:11123 virtual ~TestExtensionURLRequestContext() {}
[email protected]c10da4b02010-03-25 14:38:32124};
125
[email protected]abe2c032011-03-31 18:49:34126class TestExtensionURLRequestContextGetter
127 : public net::URLRequestContextGetter {
[email protected]c10da4b02010-03-25 14:38:32128 public:
[email protected]be9826e62013-02-07 02:00:58129 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE {
[email protected]ef2bf422012-05-11 03:27:09130 if (!context_.get())
131 context_.reset(new TestExtensionURLRequestContext());
[email protected]c10da4b02010-03-25 14:38:32132 return context_.get();
133 }
[email protected]4969b0122012-06-16 01:58:28134 virtual scoped_refptr<base::SingleThreadTaskRunner>
135 GetNetworkTaskRunner() const OVERRIDE {
[email protected]0c7d74f2010-10-11 11:55:26136 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
[email protected]83a7d2eb2010-05-03 21:46:19137 }
[email protected]c10da4b02010-03-25 14:38:32138
[email protected]13ed17f82012-04-06 02:27:18139 protected:
140 virtual ~TestExtensionURLRequestContextGetter() {}
141
[email protected]c10da4b02010-03-25 14:38:32142 private:
[email protected]ef2bf422012-05-11 03:27:09143 scoped_ptr<net::URLRequestContext> context_;
[email protected]c10da4b02010-03-25 14:38:32144};
145
[email protected]f1484c52013-05-22 23:25:44146BrowserContextKeyedService* CreateTestDesktopNotificationService(
[email protected]c7fa4362013-04-26 18:09:02147 content::BrowserContext* profile) {
[email protected]29cebbd2012-06-06 21:43:42148#if defined(ENABLE_NOTIFICATIONS)
[email protected]c7fa4362013-04-26 18:09:02149 return new DesktopNotificationService(static_cast<Profile*>(profile), NULL);
[email protected]29cebbd2012-06-06 21:43:42150#else
151 return NULL;
152#endif
[email protected]dcb72d52011-04-13 12:36:53153}
154
[email protected]d364c652008-08-29 19:46:56155} // namespace
156
[email protected]89dbb1772012-07-17 13:47:25157// static
158#if defined(OS_CHROMEOS)
159// Must be kept in sync with
160// ChromeBrowserMainPartsChromeos::PreEarlyInitialization.
161const char TestingProfile::kTestUserProfileDir[] = "test-user";
162#else
163const char TestingProfile::kTestUserProfileDir[] = "Default";
164#endif
165
[email protected]f25387b2008-08-21 15:20:33166TestingProfile::TestingProfile()
[email protected]ea6f76572008-12-18 00:09:55167 : start_time_(Time::Now()),
[email protected]2fb7dc982010-09-29 12:24:28168 testing_prefs_(NULL),
[email protected]5bb2f522011-03-25 19:04:44169 incognito_(false),
[email protected]074311a2013-02-28 23:14:09170 original_profile_(NULL),
[email protected]5cdcd152011-03-31 22:48:52171 last_session_exited_cleanly_(true),
[email protected]f0901a22013-05-27 21:37:53172 browser_context_dependency_manager_(
[email protected]f1484c52013-05-22 23:25:44173 BrowserContextDependencyManager::GetInstance()),
[email protected]37ac95b2013-07-23 23:39:35174 resource_context_(NULL),
[email protected]537c1082011-12-02 02:37:17175 delegate_(NULL) {
[email protected]5c4c89f2012-08-07 21:09:59176 CreateTempProfileDir();
[email protected]49a25632011-08-31 17:03:48177 profile_path_ = temp_dir_.path();
178
179 Init();
[email protected]537c1082011-12-02 02:37:17180 FinishInit();
[email protected]49a25632011-08-31 17:03:48181}
182
[email protected]152ea302013-02-11 04:08:40183TestingProfile::TestingProfile(const base::FilePath& path)
[email protected]49a25632011-08-31 17:03:48184 : start_time_(Time::Now()),
185 testing_prefs_(NULL),
186 incognito_(false),
[email protected]074311a2013-02-28 23:14:09187 original_profile_(NULL),
[email protected]49a25632011-08-31 17:03:48188 last_session_exited_cleanly_(true),
189 profile_path_(path),
[email protected]f0901a22013-05-27 21:37:53190 browser_context_dependency_manager_(
[email protected]f1484c52013-05-22 23:25:44191 BrowserContextDependencyManager::GetInstance()),
[email protected]37ac95b2013-07-23 23:39:35192 resource_context_(NULL),
[email protected]537c1082011-12-02 02:37:17193 delegate_(NULL) {
[email protected]49a25632011-08-31 17:03:48194 Init();
[email protected]537c1082011-12-02 02:37:17195 FinishInit();
196}
197
[email protected]152ea302013-02-11 04:08:40198TestingProfile::TestingProfile(const base::FilePath& path,
[email protected]537c1082011-12-02 02:37:17199 Delegate* delegate)
200 : start_time_(Time::Now()),
201 testing_prefs_(NULL),
202 incognito_(false),
[email protected]074311a2013-02-28 23:14:09203 original_profile_(NULL),
[email protected]537c1082011-12-02 02:37:17204 last_session_exited_cleanly_(true),
205 profile_path_(path),
[email protected]f0901a22013-05-27 21:37:53206 browser_context_dependency_manager_(
[email protected]f1484c52013-05-22 23:25:44207 BrowserContextDependencyManager::GetInstance()),
[email protected]37ac95b2013-07-23 23:39:35208 resource_context_(NULL),
[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]37ac95b2013-07-23 23:39:35235 resource_context_(NULL),
[email protected]5c4c89f2012-08-07 21:09:59236 delegate_(delegate) {
237
238 // If no profile path was supplied, create one.
239 if (profile_path_.empty()) {
240 CreateTempProfileDir();
241 profile_path_ = temp_dir_.path();
242 }
243
244 Init();
245 // If caller supplied a delegate, delay the FinishInit invocation until other
246 // tasks have run.
247 // TODO(atwilson): See if this is still required once we convert the current
248 // users of the constructor that takes a Delegate* param.
249 if (delegate_) {
[email protected]bb024fe2013-05-10 21:33:26250 base::MessageLoop::current()->PostTask(
251 FROM_HERE,
252 base::Bind(&TestingProfile::FinishInit, base::Unretained(this)));
[email protected]5c4c89f2012-08-07 21:09:59253 } else {
254 FinishInit();
255 }
256}
257
258void TestingProfile::CreateTempProfileDir() {
259 if (!temp_dir_.CreateUniqueTempDir()) {
260 LOG(ERROR) << "Failed to create unique temporary directory.";
261
262 // Fallback logic in case we fail to create unique temporary directory.
[email protected]152ea302013-02-11 04:08:40263 base::FilePath system_tmp_dir;
[email protected]5c4c89f2012-08-07 21:09:59264 bool success = PathService::Get(base::DIR_TEMP, &system_tmp_dir);
265
266 // We're severly screwed if we can't get the system temporary
267 // directory. Die now to avoid writing to the filesystem root
268 // or other bad places.
269 CHECK(success);
270
[email protected]152ea302013-02-11 04:08:40271 base::FilePath fallback_dir(
272 system_tmp_dir.AppendASCII("TestingProfilePath"));
[email protected]dd3aa792013-07-16 19:10:23273 base::DeleteFile(fallback_dir, true);
[email protected]5c4c89f2012-08-07 21:09:59274 file_util::CreateDirectory(fallback_dir);
275 if (!temp_dir_.Set(fallback_dir)) {
276 // That shouldn't happen, but if it does, try to recover.
277 LOG(ERROR) << "Failed to use a fallback temporary directory.";
278
279 // We're screwed if this fails, see CHECK above.
280 CHECK(temp_dir_.Set(system_tmp_dir));
281 }
282 }
283}
284
[email protected]49a25632011-08-31 17:03:48285void TestingProfile::Init() {
[email protected]bf390cb2013-08-06 02:48:08286 // If threads have been initialized, we should be on the UI thread.
287 DCHECK(
288 !content::BrowserThread::IsWellKnownThread(content::BrowserThread::UI) ||
289 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
290
[email protected]7e75e4a2013-05-17 17:20:03291 // Normally this would happen during browser startup, but for tests
292 // we need to trigger creation of Profile-related services.
293 ChromeBrowserMainExtraPartsProfiles::
[email protected]f1484c52013-05-22 23:25:44294 EnsureBrowserContextKeyedServiceFactoriesBuilt();
[email protected]7e75e4a2013-05-17 17:20:03295
[email protected]75fee372013-03-06 00:42:44296 if (prefs_.get())
[email protected]c7141feb2013-06-11 13:00:16297 user_prefs::UserPrefs::Set(this, prefs_.get());
[email protected]c7fa4362013-04-26 18:09:02298 else
299 CreateTestingPrefService();
[email protected]75fee372013-03-06 00:42:44300
[email protected]7567484142013-07-11 17:36:07301 if (!base::PathExists(profile_path_))
[email protected]d41e6572012-05-04 20:49:42302 file_util::CreateDirectory(profile_path_);
303
[email protected]d81bb3e2013-05-02 18:17:03304 // TODO(joaodasilva): remove this once this PKS isn't created in ProfileImpl
305 // anymore, after converting the PrefService to a PKS. Until then it must
306 // be associated with a TestingProfile too.
307 CreateProfilePolicyConnector();
308
[email protected]bd306722012-07-11 20:43:59309 extensions::ExtensionSystemFactory::GetInstance()->SetTestingFactory(
310 this, extensions::TestExtensionSystem::Build);
[email protected]31d8f5f22012-04-02 15:22:08311
[email protected]f0901a22013-05-27 21:37:53312 browser_context_dependency_manager_->CreateBrowserContextServices(this, true);
[email protected]49a25632011-08-31 17:03:48313
[email protected]5fd2e842012-03-01 00:29:11314#if defined(ENABLE_NOTIFICATIONS)
[email protected]dcb72d52011-04-13 12:36:53315 // Install profile keyed service factory hooks for dummy/test services
[email protected]7722653b2011-06-03 17:28:22316 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory(
317 this, CreateTestDesktopNotificationService);
[email protected]5fd2e842012-03-01 00:29:11318#endif
[email protected]537c1082011-12-02 02:37:17319}
[email protected]12463cd2011-07-19 09:40:20320
[email protected]537c1082011-12-02 02:37:17321void TestingProfile::FinishInit() {
[email protected]080adba92011-12-07 19:00:40322 DCHECK(content::NotificationService::current());
[email protected]ad50def52011-10-19 23:17:07323 content::NotificationService::current()->Notify(
[email protected]12463cd2011-07-19 09:40:20324 chrome::NOTIFICATION_PROFILE_CREATED,
[email protected]6c2381d2011-10-19 02:52:53325 content::Source<Profile>(static_cast<Profile*>(this)),
[email protected]ad50def52011-10-19 23:17:07326 content::NotificationService::NoDetails());
[email protected]537c1082011-12-02 02:37:17327
328 if (delegate_)
[email protected]00b33f802012-03-13 07:46:03329 delegate_->OnProfileCreated(this, true, false);
[email protected]ab23dbe2010-08-12 02:10:46330}
331
[email protected]f25387b2008-08-21 15:20:33332TestingProfile::~TestingProfile() {
[email protected]37ac95b2013-07-23 23:39:35333 // Any objects holding live URLFetchers should be deleted before teardown.
334 TemplateURLFetcherFactory::ShutdownForProfile(this);
335
[email protected]a7c4c032012-07-27 00:36:32336 MaybeSendDestroyedNotification();
[email protected]5cdcd152011-03-31 22:48:52337
[email protected]f0901a22013-05-27 21:37:53338 browser_context_dependency_manager_->DestroyBrowserContextServices(this);
[email protected]5cdcd152011-03-31 22:48:52339
[email protected]5c6ac842013-06-02 23:37:03340 if (host_content_settings_map_.get())
[email protected]35552dc52011-07-12 09:04:38341 host_content_settings_map_->ShutdownOnUIThread();
342
[email protected]809cc4d2010-10-27 15:22:54343 DestroyTopSites();
[email protected]cdba46992011-06-07 11:51:39344
[email protected]cc5bfd42010-11-24 14:44:02345 if (pref_proxy_config_tracker_.get())
346 pref_proxy_config_tracker_->DetachFromPrefService();
[email protected]37ac95b2013-07-23 23:39:35347 // Failing a post == leaks == heapcheck failure. Make that an immediate test
348 // failure.
349 if (resource_context_) {
350 CHECK(BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE,
351 resource_context_));
352 resource_context_ = NULL;
353 content::RunAllPendingInMessageLoop(BrowserThread::IO);
354 }
[email protected]f25387b2008-08-21 15:20:33355}
initial.commit09911bf2008-07-26 23:55:29356
[email protected]f1484c52013-05-22 23:25:44357static BrowserContextKeyedService* BuildFaviconService(
[email protected]c7fa4362013-04-26 18:09:02358 content::BrowserContext* profile) {
[email protected]f3d2b312012-08-23 22:27:59359 return new FaviconService(
[email protected]c7fa4362013-04-26 18:09:02360 HistoryServiceFactory::GetForProfileWithoutCreating(
361 static_cast<Profile*>(profile)));
[email protected]f3d2b312012-08-23 22:27:59362}
363
[email protected]d2879af2010-02-08 16:02:56364void TestingProfile::CreateFaviconService() {
[email protected]f3d2b312012-08-23 22:27:59365 // It is up to the caller to create the history service if one is needed.
366 FaviconServiceFactory::GetInstance()->SetTestingFactory(
367 this, BuildFaviconService);
[email protected]d2879af2010-02-08 16:02:56368}
369
[email protected]f1484c52013-05-22 23:25:44370static BrowserContextKeyedService* BuildHistoryService(
[email protected]c7fa4362013-04-26 18:09:02371 content::BrowserContext* profile) {
372 return new HistoryService(static_cast<Profile*>(profile));
[email protected]f61f4782012-06-08 21:54:21373}
374
[email protected]608e7e02013-07-24 12:23:31375bool TestingProfile::CreateHistoryService(bool delete_file, bool no_db) {
[email protected]809cc4d2010-10-27 15:22:54376 DestroyHistoryService();
[email protected]f25387b2008-08-21 15:20:33377 if (delete_file) {
[email protected]152ea302013-02-11 04:08:40378 base::FilePath path = GetPath();
[email protected]f7011fcb2009-01-28 21:54:32379 path = path.Append(chrome::kHistoryFilename);
[email protected]608e7e02013-07-24 12:23:31380 if (!base::DeleteFile(path, false) || base::PathExists(path))
381 return false;
[email protected]f25387b2008-08-21 15:20:33382 }
[email protected]7019bb6d2012-08-23 09:09:48383 // This will create and init the history service.
[email protected]f61f4782012-06-08 21:54:21384 HistoryService* history_service = static_cast<HistoryService*>(
385 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse(
[email protected]a5894fe2012-11-01 14:40:56386 this, BuildHistoryService));
[email protected]7019bb6d2012-08-23 09:09:48387 if (!history_service->Init(this->GetPath(),
388 BookmarkModelFactory::GetForProfile(this),
389 no_db)) {
[email protected]f61f4782012-06-08 21:54:21390 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse(this, NULL);
[email protected]7019bb6d2012-08-23 09:09:48391 }
[email protected]a50e16a2013-04-25 14:07:17392 // Disable WebHistoryService by default, since it makes network requests.
393 WebHistoryServiceFactory::GetInstance()->SetTestingFactory(this, NULL);
[email protected]608e7e02013-07-24 12:23:31394 return true;
initial.commit09911bf2008-07-26 23:55:29395}
396
397void TestingProfile::DestroyHistoryService() {
[email protected]a5894fe2012-11-01 14:40:56398 HistoryService* history_service =
[email protected]6c537042012-07-13 00:59:02399 HistoryServiceFactory::GetForProfileWithoutCreating(this);
[email protected]a5894fe2012-11-01 14:40:56400 if (!history_service)
initial.commit09911bf2008-07-26 23:55:29401 return;
402
[email protected]f61f4782012-06-08 21:54:21403 history_service->NotifyRenderProcessHostDestruction(0);
[email protected]bb024fe2013-05-10 21:33:26404 history_service->SetOnBackendDestroyTask(base::MessageLoop::QuitClosure());
[email protected]f61f4782012-06-08 21:54:21405 history_service->Cleanup();
406 HistoryServiceFactory::ShutdownForProfile(this);
initial.commit09911bf2008-07-26 23:55:29407
408 // Wait for the backend class to terminate before deleting the files and
409 // moving to the next test. Note: if this never terminates, somebody is
410 // probably leaking a reference to the history backend, so it never calls
411 // our destroy task.
[email protected]bb024fe2013-05-10 21:33:26412 base::MessageLoop::current()->Run();
initial.commit09911bf2008-07-26 23:55:29413
initial.commit09911bf2008-07-26 23:55:29414 // Make sure we don't have any event pending that could disrupt the next
415 // test.
[email protected]bb024fe2013-05-10 21:33:26416 base::MessageLoop::current()->PostTask(FROM_HERE,
417 base::MessageLoop::QuitClosure());
418 base::MessageLoop::current()->Run();
initial.commit09911bf2008-07-26 23:55:29419}
[email protected]4d0cd7ce2008-08-11 16:40:57420
[email protected]809cc4d2010-10-27 15:22:54421void TestingProfile::CreateTopSites() {
422 DestroyTopSites();
[email protected]9a93d3432013-04-29 20:52:12423 top_sites_ = history::TopSites::Create(
424 this, GetPath().Append(chrome::kTopSitesFilename));
[email protected]809cc4d2010-10-27 15:22:54425}
426
427void TestingProfile::DestroyTopSites() {
428 if (top_sites_.get()) {
429 top_sites_->Shutdown();
430 top_sites_ = NULL;
[email protected]9a93d3432013-04-29 20:52:12431 // TopSitesImpl::Shutdown schedules some tasks (from TopSitesBackend) that
432 // need to be run to properly shutdown. Run all pending tasks now. This is
[email protected]809cc4d2010-10-27 15:22:54433 // normally handled by browser_process shutdown.
[email protected]bb024fe2013-05-10 21:33:26434 if (base::MessageLoop::current())
435 base::MessageLoop::current()->RunUntilIdle();
[email protected]809cc4d2010-10-27 15:22:54436 }
437}
438
[email protected]f1484c52013-05-22 23:25:44439static BrowserContextKeyedService* BuildBookmarkModel(
[email protected]c7fa4362013-04-26 18:09:02440 content::BrowserContext* context) {
441 Profile* profile = static_cast<Profile*>(context);
[email protected]f61f4782012-06-08 21:54:21442 BookmarkModel* bookmark_model = new BookmarkModel(profile);
[email protected]afecfb72013-04-18 17:17:33443 bookmark_model->Load(profile->GetIOTaskRunner());
[email protected]f61f4782012-06-08 21:54:21444 return bookmark_model;
445}
446
447
[email protected]d8e41ed2008-09-11 15:22:32448void TestingProfile::CreateBookmarkModel(bool delete_file) {
[email protected]90ef13132008-08-27 03:27:46449 if (delete_file) {
[email protected]8a39b472013-04-04 17:07:42450 base::FilePath path = GetPath().Append(chrome::kBookmarksFileName);
[email protected]dd3aa792013-07-16 19:10:23451 base::DeleteFile(path, false);
[email protected]90ef13132008-08-27 03:27:46452 }
[email protected]f61f4782012-06-08 21:54:21453 // This will create a bookmark model.
[email protected]8a39b472013-04-04 17:07:42454 BookmarkModel* bookmark_service = static_cast<BookmarkModel*>(
455 BookmarkModelFactory::GetInstance()->SetTestingFactoryAndUse(
456 this, BuildBookmarkModel));
[email protected]f61f4782012-06-08 21:54:21457
458 HistoryService* history_service =
[email protected]a5894fe2012-11-01 14:40:56459 HistoryServiceFactory::GetForProfileWithoutCreating(this);
[email protected]f61f4782012-06-08 21:54:21460 if (history_service) {
[email protected]8a39b472013-04-04 17:07:42461 history_service->history_backend_->bookmark_service_ = bookmark_service;
[email protected]f61f4782012-06-08 21:54:21462 history_service->history_backend_->expirer_.bookmark_service_ =
463 bookmark_service;
[email protected]90ef13132008-08-27 03:27:46464 }
[email protected]4d0cd7ce2008-08-11 16:40:57465}
[email protected]d2c017a2008-08-13 21:51:45466
[email protected]f1484c52013-05-22 23:25:44467static BrowserContextKeyedService* BuildWebDataService(
[email protected]c7fa4362013-04-26 18:09:02468 content::BrowserContext* profile) {
469 return new WebDataServiceWrapper(static_cast<Profile*>(profile));
[email protected]d07edd42012-05-14 23:49:46470}
[email protected]2609bc12010-01-24 08:32:55471
[email protected]d07edd42012-05-14 23:49:46472void TestingProfile::CreateWebDataService() {
[email protected]a5c65292012-05-25 00:50:01473 WebDataServiceFactory::GetInstance()->SetTestingFactory(
[email protected]d07edd42012-05-14 23:49:46474 this, BuildWebDataService);
[email protected]2609bc12010-01-24 08:32:55475}
476
[email protected]18a15ca82012-08-30 00:28:16477void TestingProfile::BlockUntilHistoryIndexIsRefreshed() {
478 // Only get the history service if it actually exists since the caller of the
479 // test should explicitly call CreateHistoryService to build it.
480 HistoryService* history_service =
481 HistoryServiceFactory::GetForProfileWithoutCreating(this);
482 DCHECK(history_service);
483 history::InMemoryURLIndex* index = history_service->InMemoryIndex();
484 if (!index || index->restored())
485 return;
486 base::RunLoop run_loop;
487 HistoryIndexRestoreObserver observer(
488 content::GetQuitTaskForRunLoop(&run_loop));
489 index->set_restore_cache_observer(&observer);
490 run_loop.Run();
491 index->set_restore_cache_observer(NULL);
492 DCHECK(index->restored());
493}
494
[email protected]120abf132011-09-27 21:38:06495// TODO(phajdan.jr): Doesn't this hang if Top Sites are already loaded?
[email protected]809cc4d2010-10-27 15:22:54496void TestingProfile::BlockUntilTopSitesLoaded() {
[email protected]a7fe9112012-07-20 02:34:45497 content::WindowedNotificationObserver top_sites_loaded_observer(
[email protected]120abf132011-09-27 21:38:06498 chrome::NOTIFICATION_TOP_SITES_LOADED,
[email protected]ad50def52011-10-19 23:17:07499 content::NotificationService::AllSources());
[email protected]d7f7f752012-08-08 02:02:55500 if (!HistoryServiceFactory::GetForProfile(this, Profile::EXPLICIT_ACCESS))
[email protected]809cc4d2010-10-27 15:22:54501 GetTopSites()->HistoryLoaded();
[email protected]120abf132011-09-27 21:38:06502 top_sites_loaded_observer.Wait();
[email protected]809cc4d2010-10-27 15:22:54503}
504
[email protected]4251165a2013-07-17 04:33:40505base::FilePath TestingProfile::GetPath() const {
[email protected]49a25632011-08-31 17:03:48506 return profile_path_;
[email protected]f9dec9482010-08-20 20:42:19507}
508
[email protected]0de615a2012-11-08 04:40:59509scoped_refptr<base::SequencedTaskRunner> TestingProfile::GetIOTaskRunner() {
[email protected]bb024fe2013-05-10 21:33:26510 return base::MessageLoop::current()->message_loop_proxy();
[email protected]0de615a2012-11-08 04:40:59511}
512
[email protected]5b199522012-12-22 17:24:44513TestingPrefServiceSyncable* TestingProfile::GetTestingPrefService() {
[email protected]2fb7dc982010-09-29 12:24:28514 if (!prefs_.get())
515 CreateTestingPrefService();
516 DCHECK(testing_prefs_);
517 return testing_prefs_;
[email protected]dbbad7a2010-08-13 18:18:36518}
519
[email protected]8e5c89a2011-06-07 18:13:33520TestingProfile* TestingProfile::AsTestingProfile() {
521 return this;
522}
523
[email protected]29d70252011-04-28 02:16:58524std::string TestingProfile::GetProfileName() {
525 return std::string("testing_profile");
526}
527
[email protected]27d6e852012-03-02 21:31:32528bool TestingProfile::IsOffTheRecord() const {
[email protected]5bb2f522011-03-25 19:04:44529 return incognito_;
[email protected]fadc607b62011-02-07 17:55:50530}
531
[email protected]93dba942011-02-23 22:45:01532void TestingProfile::SetOffTheRecordProfile(Profile* profile) {
[email protected]5bb2f522011-03-25 19:04:44533 incognito_profile_.reset(profile);
[email protected]93dba942011-02-23 22:45:01534}
535
[email protected]074311a2013-02-28 23:14:09536void TestingProfile::SetOriginalProfile(Profile* profile) {
537 original_profile_ = profile;
538}
539
[email protected]fadc607b62011-02-07 17:55:50540Profile* TestingProfile::GetOffTheRecordProfile() {
[email protected]5bb2f522011-03-25 19:04:44541 return incognito_profile_.get();
[email protected]fadc607b62011-02-07 17:55:50542}
543
544bool TestingProfile::HasOffTheRecordProfile() {
[email protected]5bb2f522011-03-25 19:04:44545 return incognito_profile_.get() != NULL;
[email protected]fadc607b62011-02-07 17:55:50546}
547
548Profile* TestingProfile::GetOriginalProfile() {
[email protected]074311a2013-02-28 23:14:09549 if (original_profile_)
550 return original_profile_;
[email protected]fadc607b62011-02-07 17:55:50551 return this;
552}
553
[email protected]e000daf2013-07-31 16:50:58554bool TestingProfile::IsManaged() {
[email protected]a6e01b42013-08-05 14:13:13555 return GetPrefs()->GetBoolean(prefs::kProfileIsManaged) ||
556 !GetPrefs()->GetString(prefs::kManagedUserId).empty();
[email protected]e000daf2013-07-31 16:50:58557}
558
[email protected]eaa7dd182010-12-14 11:09:00559ExtensionService* TestingProfile::GetExtensionService() {
[email protected]bd306722012-07-11 20:43:59560 return extensions::ExtensionSystem::Get(this)->extension_service();
[email protected]2fb7dc982010-09-29 12:24:28561}
562
[email protected]2261e7b72011-07-12 13:43:55563void TestingProfile::SetExtensionSpecialStoragePolicy(
564 ExtensionSpecialStoragePolicy* extension_special_storage_policy) {
565 extension_special_storage_policy_ = extension_special_storage_policy;
566}
567
[email protected]19eb80152011-02-26 00:28:43568ExtensionSpecialStoragePolicy*
569TestingProfile::GetExtensionSpecialStoragePolicy() {
[email protected]cdba46992011-06-07 11:51:39570 if (!extension_special_storage_policy_.get())
[email protected]7c5048c2011-08-19 17:07:05571 extension_special_storage_policy_ = new ExtensionSpecialStoragePolicy(NULL);
[email protected]cdba46992011-06-07 11:51:39572 return extension_special_storage_policy_.get();
[email protected]19eb80152011-02-26 00:28:43573}
574
[email protected]dbbad7a2010-08-13 18:18:36575net::CookieMonster* TestingProfile::GetCookieMonster() {
576 if (!GetRequestContext())
577 return NULL;
[email protected]277ec262011-03-30 21:09:40578 return GetRequestContext()->GetURLRequestContext()->cookie_store()->
579 GetCookieMonster();
[email protected]dbbad7a2010-08-13 18:18:36580}
581
[email protected]2fb7dc982010-09-29 12:24:28582void TestingProfile::CreateTestingPrefService() {
583 DCHECK(!prefs_.get());
[email protected]5b199522012-12-22 17:24:44584 testing_prefs_ = new TestingPrefServiceSyncable();
[email protected]2fb7dc982010-09-29 12:24:28585 prefs_.reset(testing_prefs_);
[email protected]c7141feb2013-06-11 13:00:16586 user_prefs::UserPrefs::Set(this, prefs_.get());
[email protected]37ca3fe02013-07-05 15:32:44587 chrome::RegisterUserProfilePrefs(testing_prefs_->registry());
[email protected]2fb7dc982010-09-29 12:24:28588}
589
[email protected]d81bb3e2013-05-02 18:17:03590void TestingProfile::CreateProfilePolicyConnector() {
591 scoped_ptr<policy::PolicyService> service;
592#if defined(ENABLE_CONFIGURATION_POLICY)
593 std::vector<policy::ConfigurationPolicyProvider*> providers;
594 service.reset(new policy::PolicyServiceImpl(providers));
595#else
596 service.reset(new policy::PolicyServiceStub());
597#endif
598 profile_policy_connector_.reset(
599 new policy::ProfilePolicyConnector(this));
600 profile_policy_connector_->InitForTesting(service.Pass());
601 policy::ProfilePolicyConnectorFactory::GetInstance()->SetServiceForTesting(
602 this, profile_policy_connector_.get());
603 CHECK_EQ(profile_policy_connector_.get(),
604 policy::ProfilePolicyConnectorFactory::GetForProfile(this));
605}
606
[email protected]c753f142013-02-10 13:14:04607PrefService* TestingProfile::GetPrefs() {
[email protected]dbbad7a2010-08-13 18:18:36608 if (!prefs_.get()) {
[email protected]2fb7dc982010-09-29 12:24:28609 CreateTestingPrefService();
[email protected]dbbad7a2010-08-13 18:18:36610 }
611 return prefs_.get();
612}
613
614history::TopSites* TestingProfile::GetTopSites() {
[email protected]809cc4d2010-10-27 15:22:54615 return top_sites_.get();
[email protected]dbbad7a2010-08-13 18:18:36616}
617
[email protected]fadc607b62011-02-07 17:55:50618history::TopSites* TestingProfile::GetTopSitesWithoutCreating() {
619 return top_sites_.get();
620}
621
[email protected]b441a8492012-06-06 14:55:57622DownloadManagerDelegate* TestingProfile::GetDownloadManagerDelegate() {
[email protected]fadc607b62011-02-07 17:55:50623 return NULL;
624}
625
[email protected]abe2c032011-03-31 18:49:34626net::URLRequestContextGetter* TestingProfile::GetRequestContext() {
[email protected]37ac95b2013-07-23 23:39:35627 return GetDefaultStoragePartition(this)->GetURLRequestContext();
[email protected]812b3a32010-01-08 05:36:04628}
629
[email protected]6bd30072013-02-08 18:17:11630net::URLRequestContextGetter* TestingProfile::CreateRequestContext(
[email protected]672c8c12013-03-07 12:30:06631 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]37ac95b2013-07-23 23:39:35632 return new net::TestURLRequestContextGetter(
633 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
[email protected]6bd30072013-02-08 18:17:11634}
635
[email protected]da5683db2011-04-23 17:12:21636net::URLRequestContextGetter* TestingProfile::GetRequestContextForRenderProcess(
637 int renderer_child_id) {
[email protected]fb29e6cf2012-07-12 21:27:20638 content::RenderProcessHost* rph = content::RenderProcessHost::FromID(
639 renderer_child_id);
[email protected]1bc28312012-11-08 08:31:53640 return rph->GetStoragePartition()->GetURLRequestContext();
[email protected]d9696672011-03-15 22:45:09641}
642
[email protected]10705a7b2012-08-21 19:07:08643net::URLRequestContextGetter* TestingProfile::GetMediaRequestContext() {
644 return NULL;
645}
646
647net::URLRequestContextGetter*
648TestingProfile::GetMediaRequestContextForRenderProcess(
649 int renderer_child_id) {
[email protected]fadc607b62011-02-07 17:55:50650 return NULL;
651}
652
[email protected]10eb28162012-09-18 03:04:09653net::URLRequestContextGetter*
654TestingProfile::GetMediaRequestContextForStoragePartition(
[email protected]152ea302013-02-11 04:08:40655 const base::FilePath& partition_path,
[email protected]27ddfed22012-10-30 23:22:43656 bool in_memory) {
[email protected]10eb28162012-09-18 03:04:09657 return NULL;
658}
659
[email protected]8aca7252013-07-12 19:18:59660void TestingProfile::RequestMIDISysExPermission(
661 int render_process_id,
662 int render_view_id,
663 const GURL& requesting_frame,
664 const MIDISysExPermissionCallback& callback) {
665 // Always reject requests for testing.
666 callback.Run(false);
667}
668
[email protected]abe2c032011-03-31 18:49:34669net::URLRequestContextGetter* TestingProfile::GetRequestContextForExtensions() {
[email protected]5c6ac842013-06-02 23:37:03670 if (!extensions_request_context_.get())
[email protected]00dea9582012-05-09 15:20:05671 extensions_request_context_ = new TestExtensionURLRequestContextGetter();
[email protected]c10da4b02010-03-25 14:38:32672 return extensions_request_context_.get();
673}
674
[email protected]fadc607b62011-02-07 17:55:50675net::SSLConfigService* TestingProfile::GetSSLConfigService() {
[email protected]dc6655b2012-12-14 05:58:24676 if (!GetRequestContext())
677 return NULL;
678 return GetRequestContext()->GetURLRequestContext()->ssl_config_service();
[email protected]fadc607b62011-02-07 17:55:50679}
680
[email protected]10eb28162012-09-18 03:04:09681net::URLRequestContextGetter*
[email protected]6bd30072013-02-08 18:17:11682TestingProfile::CreateRequestContextForStoragePartition(
[email protected]152ea302013-02-11 04:08:40683 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:11684 bool in_memory,
[email protected]672c8c12013-03-07 12:30:06685 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]10eb28162012-09-18 03:04:09686 // We don't test storage partitions here yet, so returning the same dummy
[email protected]d9696672011-03-15 22:45:09687 // context is sufficient for now.
688 return GetRequestContext();
689}
690
[email protected]df02aca2012-02-09 21:03:20691content::ResourceContext* TestingProfile::GetResourceContext() {
[email protected]37ac95b2013-07-23 23:39:35692 if (!resource_context_)
693 resource_context_ = new content::MockResourceContext();
694 return resource_context_;
[email protected]e89b77d2011-04-15 18:58:10695}
696
[email protected]dbbad7a2010-08-13 18:18:36697HostContentSettingsMap* TestingProfile::GetHostContentSettingsMap() {
[email protected]35552dc52011-07-12 09:04:38698 if (!host_content_settings_map_.get()) {
[email protected]646c29cb62012-06-18 14:31:05699 host_content_settings_map_ = new HostContentSettingsMap(GetPrefs(), false);
[email protected]701550ad2012-09-06 23:43:29700#if defined(ENABLE_EXTENSIONS)
[email protected]646c29cb62012-06-18 14:31:05701 ExtensionService* extension_service = GetExtensionService();
702 if (extension_service)
703 host_content_settings_map_->RegisterExtensionService(extension_service);
[email protected]701550ad2012-09-06 23:43:29704#endif
[email protected]35552dc52011-07-12 09:04:38705 }
[email protected]dbbad7a2010-08-13 18:18:36706 return host_content_settings_map_.get();
707}
708
[email protected]810ddc52012-01-24 01:00:35709content::GeolocationPermissionContext*
[email protected]dbbad7a2010-08-13 18:18:36710TestingProfile::GetGeolocationPermissionContext() {
[email protected]a877a7d2013-01-08 13:40:59711 return ChromeGeolocationPermissionContextFactory::GetForProfile(this);
[email protected]dbbad7a2010-08-13 18:18:36712}
713
[email protected]fadc607b62011-02-07 17:55:50714std::wstring TestingProfile::GetName() {
715 return std::wstring();
716}
717
718std::wstring TestingProfile::GetID() {
719 return id_;
720}
721
722void TestingProfile::SetID(const std::wstring& id) {
723 id_ = id;
724}
725
[email protected]fadc607b62011-02-07 17:55:50726bool TestingProfile::IsSameProfile(Profile *p) {
727 return this == p;
728}
729
730base::Time TestingProfile::GetStartTime() const {
731 return start_time_;
732}
733
[email protected]152ea302013-02-11 04:08:40734base::FilePath TestingProfile::last_selected_directory() {
[email protected]fadc607b62011-02-07 17:55:50735 return last_selected_directory_;
736}
737
[email protected]152ea302013-02-11 04:08:40738void TestingProfile::set_last_selected_directory(const base::FilePath& path) {
[email protected]fadc607b62011-02-07 17:55:50739 last_selected_directory_ = path;
740}
741
[email protected]cc5bfd42010-11-24 14:44:02742PrefProxyConfigTracker* TestingProfile::GetProxyConfigTracker() {
[email protected]6f96cbcb2011-11-04 02:26:07743 if (!pref_proxy_config_tracker_.get()) {
[email protected]e2930d0902013-07-17 05:25:42744 // TestingProfile is used in unit tests, where local state is not available.
[email protected]6f96cbcb2011-11-04 02:26:07745 pref_proxy_config_tracker_.reset(
[email protected]e2930d0902013-07-17 05:25:42746 ProxyServiceFactory::CreatePrefProxyConfigTrackerOfProfile(GetPrefs(),
747 NULL));
[email protected]6f96cbcb2011-11-04 02:26:07748 }
749 return pref_proxy_config_tracker_.get();
[email protected]cc5bfd42010-11-24 14:44:02750}
751
[email protected]0bfc29a2009-04-27 16:15:44752void TestingProfile::BlockUntilHistoryProcessesPendingRequests() {
[email protected]a5894fe2012-11-01 14:40:56753 HistoryService* history_service =
[email protected]6c537042012-07-13 00:59:02754 HistoryServiceFactory::GetForProfile(this, Profile::EXPLICIT_ACCESS);
[email protected]a5894fe2012-11-01 14:40:56755 DCHECK(history_service);
[email protected]bb024fe2013-05-10 21:33:26756 DCHECK(base::MessageLoop::current());
[email protected]0bfc29a2009-04-27 16:15:44757
758 CancelableRequestConsumer consumer;
[email protected]f61f4782012-06-08 21:54:21759 history_service->ScheduleDBTask(new QuittingHistoryDBTask(), &consumer);
[email protected]bb024fe2013-05-10 21:33:26760 base::MessageLoop::current()->Run();
[email protected]0bfc29a2009-04-27 16:15:44761}
[email protected]345a8b72009-09-29 09:11:44762
[email protected]8382d8c2011-09-15 03:43:17763chrome_browser_net::Predictor* TestingProfile::GetNetworkPredictor() {
764 return NULL;
765}
766
[email protected]e0e1fc22012-11-05 20:25:36767void TestingProfile::ClearNetworkingHistorySince(
768 base::Time time,
769 const base::Closure& completion) {
770 if (!completion.is_null()) {
771 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, completion);
772 }
[email protected]02896a82011-09-21 18:54:32773}
774
[email protected]671f9c62011-10-28 19:22:07775GURL TestingProfile::GetHomePage() {
776 return GURL(chrome::kChromeUINewTabURL);
777}
778
[email protected]c753f142013-02-10 13:14:04779PrefService* TestingProfile::GetOffTheRecordPrefs() {
[email protected]fadc607b62011-02-07 17:55:50780 return NULL;
781}
782
[email protected]36fb2c7c2011-04-04 15:49:08783quota::SpecialStoragePolicy* TestingProfile::GetSpecialStoragePolicy() {
784 return GetExtensionSpecialStoragePolicy();
785}
786
[email protected]1bee6ed2012-03-14 06:46:36787bool TestingProfile::WasCreatedByVersionOrLater(const std::string& version) {
788 return true;
789}
[email protected]ef92e172012-04-25 19:40:41790
[email protected]4251165a2013-07-17 04:33:40791bool TestingProfile::IsGuestSession() const {
792 return false;
793}
[email protected]6c0ca7fc2012-10-05 16:27:22794Profile::ExitType TestingProfile::GetLastSessionExitType() {
795 return last_session_exited_cleanly_ ? EXIT_NORMAL : EXIT_CRASHED;
[email protected]2ca1ea662012-10-04 02:26:36796}
797
[email protected]5c4c89f2012-08-07 21:09:59798TestingProfile::Builder::Builder()
799 : build_called_(false),
[email protected]a0cc9a532013-02-12 02:23:12800 delegate_(NULL) {
[email protected]5c4c89f2012-08-07 21:09:59801}
802
803TestingProfile::Builder::~Builder() {
804}
805
[email protected]152ea302013-02-11 04:08:40806void TestingProfile::Builder::SetPath(const base::FilePath& path) {
[email protected]5c4c89f2012-08-07 21:09:59807 path_ = path;
808}
809
810void TestingProfile::Builder::SetDelegate(Delegate* delegate) {
811 delegate_ = delegate;
812}
813
814void TestingProfile::Builder::SetExtensionSpecialStoragePolicy(
815 scoped_refptr<ExtensionSpecialStoragePolicy> policy) {
816 extension_policy_ = policy;
817}
818
[email protected]5b199522012-12-22 17:24:44819void TestingProfile::Builder::SetPrefService(
820 scoped_ptr<PrefServiceSyncable> prefs) {
[email protected]5c4c89f2012-08-07 21:09:59821 pref_service_ = prefs.Pass();
822}
823
[email protected]5c4c89f2012-08-07 21:09:59824scoped_ptr<TestingProfile> TestingProfile::Builder::Build() {
825 DCHECK(!build_called_);
826 build_called_ = true;
827 return scoped_ptr<TestingProfile>(new TestingProfile(
828 path_,
829 delegate_,
830 extension_policy_,
[email protected]a0cc9a532013-02-12 02:23:12831 pref_service_.Pass()));
[email protected]5c4c89f2012-08-07 21:09:59832}