blob: 73efdfb5d0a9d8f115c02e9121774673af5e33b4 [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]a43b9a82013-11-28 16:56:4144#include "chrome/browser/policy/policy_service.h"
[email protected]d81bb3e2013-05-02 18:17:0345#include "chrome/browser/policy/profile_policy_connector.h"
46#include "chrome/browser/policy/profile_policy_connector_factory.h"
[email protected]37858e52010-08-26 00:22:0247#include "chrome/browser/prefs/browser_prefs.h"
[email protected]c753f142013-02-10 13:14:0448#include "chrome/browser/prefs/pref_service_syncable.h"
[email protected]4850a7f2011-03-08 23:36:5949#include "chrome/browser/prerender/prerender_manager.h"
[email protected]7e75e4a2013-05-17 17:20:0350#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
[email protected]371662e372013-10-17 22:05:2251#include "chrome/browser/profiles/profile_manager.h"
[email protected]27ddfed22012-10-30 23:22:4352#include "chrome/browser/profiles/storage_partition_descriptor.h"
[email protected]16bd088b2012-04-03 08:12:1253#include "chrome/browser/search_engines/template_url_fetcher_factory.h"
[email protected]810ffba2012-06-12 01:07:4854#include "chrome/browser/webdata/web_data_service.h"
[email protected]d07edd42012-05-14 23:49:4655#include "chrome/browser/webdata/web_data_service_factory.h"
[email protected]a9afddb2009-02-12 17:49:4256#include "chrome/common/chrome_constants.h"
[email protected]9e33d7e2011-09-30 16:43:5457#include "chrome/common/chrome_switches.h"
[email protected]e000daf2013-07-31 16:50:5858#include "chrome/common/pref_names.h"
[email protected]dbbad7a2010-08-13 18:18:3659#include "chrome/common/url_constants.h"
[email protected]18a15ca82012-08-30 00:28:1660#include "chrome/test/base/history_index_restore_observer.h"
[email protected]7688968a2013-02-12 21:45:1361#include "chrome/test/base/testing_pref_service_syncable.h"
[email protected]af44e7fb2011-07-29 18:32:3262#include "chrome/test/base/ui_test_utils.h"
[email protected]0dd6f2032013-05-20 23:33:4063#include "components/browser_context_keyed_service/browser_context_dependency_manager.h"
[email protected]75fee372013-03-06 00:42:4464#include "components/user_prefs/user_prefs.h"
[email protected]c38831a12011-10-28 12:44:4965#include "content/public/browser/browser_thread.h"
[email protected]ad50def52011-10-19 23:17:0766#include "content/public/browser/notification_service.h"
[email protected]fb29e6cf2012-07-12 21:27:2067#include "content/public/browser/render_process_host.h"
[email protected]885c0e92012-11-13 20:27:4268#include "content/public/browser/storage_partition.h"
[email protected]08a932d52012-06-03 21:42:1269#include "content/public/test/mock_resource_context.h"
[email protected]a7fe9112012-07-20 02:34:4570#include "content/public/test/test_utils.h"
[email protected]885c0e92012-11-13 20:27:4271#include "extensions/common/constants.h"
[email protected]aa84a7e2012-03-15 21:29:0672#include "net/cookies/cookie_monster.h"
[email protected]812b3a32010-01-08 05:36:0473#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:3474#include "net/url_request/url_request_context_getter.h"
[email protected]d2db0292011-01-26 20:23:4475#include "net/url_request/url_request_test_util.h"
[email protected]4772b072010-03-30 17:45:4676#include "testing/gmock/include/gmock/gmock.h"
[email protected]248ce192011-02-10 15:26:3477
[email protected]21d3a882012-05-31 14:41:5578#if defined(ENABLE_CONFIGURATION_POLICY)
[email protected]d81bb3e2013-05-02 18:17:0379#include "chrome/browser/policy/configuration_policy_provider.h"
[email protected]21d3a882012-05-31 14:41:5580#include "chrome/browser/policy/policy_service_impl.h"
[email protected]eb83c392013-11-07 12:53:2481#include "chrome/browser/policy/schema_registry_service.h"
82#include "chrome/browser/policy/schema_registry_service_factory.h"
83#include "components/policy/core/common/schema.h"
[email protected]21d3a882012-05-31 14:41:5584#else
85#include "chrome/browser/policy/policy_service_stub.h"
86#endif // defined(ENABLE_CONFIGURATION_POLICY)
87
[email protected]e1480482013-09-11 11:49:5888#if defined(ENABLE_MANAGED_USERS)
89#include "chrome/browser/managed_mode/managed_user_settings_service.h"
90#include "chrome/browser/managed_mode/managed_user_settings_service_factory.h"
91#endif
92
[email protected]e1acf6f2008-10-27 20:43:3393using base::Time;
[email protected]631bb742011-11-02 11:29:3994using content::BrowserThread;
[email protected]b441a8492012-06-06 14:55:5795using content::DownloadManagerDelegate;
[email protected]3c887412010-04-19 20:30:2396using testing::NiceMock;
[email protected]4772b072010-03-30 17:45:4697using testing::Return;
[email protected]e1acf6f2008-10-27 20:43:3398
[email protected]d364c652008-08-29 19:46:5699namespace {
100
[email protected]0bfc29a2009-04-27 16:15:44101// Task used to make sure history has finished processing a request. Intended
102// for use with BlockUntilHistoryProcessesPendingRequests.
103
[email protected]d891f522013-02-08 03:24:41104class QuittingHistoryDBTask : public history::HistoryDBTask {
[email protected]0bfc29a2009-04-27 16:15:44105 public:
106 QuittingHistoryDBTask() {}
107
108 virtual bool RunOnDBThread(history::HistoryBackend* backend,
[email protected]be9826e62013-02-07 02:00:58109 history::HistoryDatabase* db) OVERRIDE {
[email protected]0bfc29a2009-04-27 16:15:44110 return true;
111 }
112
[email protected]be9826e62013-02-07 02:00:58113 virtual void DoneRunOnMainThread() OVERRIDE {
[email protected]bb024fe2013-05-10 21:33:26114 base::MessageLoop::current()->Quit();
[email protected]0bfc29a2009-04-27 16:15:44115 }
116
117 private:
[email protected]be9826e62013-02-07 02:00:58118 virtual ~QuittingHistoryDBTask() {}
[email protected]7991a232009-11-06 01:55:48119
[email protected]0bfc29a2009-04-27 16:15:44120 DISALLOW_COPY_AND_ASSIGN(QuittingHistoryDBTask);
121};
122
[email protected]33ad6ce92013-08-27 14:39:08123class TestExtensionURLRequestContext : public net::URLRequestContext {
124 public:
125 TestExtensionURLRequestContext() {
126 net::CookieMonster* cookie_monster = new net::CookieMonster(NULL, NULL);
127 const char* schemes[] = {extensions::kExtensionScheme};
128 cookie_monster->SetCookieableSchemes(schemes, 1);
129 set_cookie_store(cookie_monster);
130 }
131
132 virtual ~TestExtensionURLRequestContext() {}
133};
134
135class TestExtensionURLRequestContextGetter
136 : public net::URLRequestContextGetter {
137 public:
138 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE {
139 if (!context_.get())
140 context_.reset(new TestExtensionURLRequestContext());
141 return context_.get();
142 }
143 virtual scoped_refptr<base::SingleThreadTaskRunner>
144 GetNetworkTaskRunner() const OVERRIDE {
145 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
146 }
147
148 protected:
149 virtual ~TestExtensionURLRequestContextGetter() {}
150
151 private:
152 scoped_ptr<net::URLRequestContext> context_;
153};
154
[email protected]1d51882f2013-11-12 01:59:02155#if defined(ENABLE_NOTIFICATIONS)
[email protected]f1484c52013-05-22 23:25:44156BrowserContextKeyedService* CreateTestDesktopNotificationService(
[email protected]c7fa4362013-04-26 18:09:02157 content::BrowserContext* profile) {
[email protected]c7fa4362013-04-26 18:09:02158 return new DesktopNotificationService(static_cast<Profile*>(profile), NULL);
[email protected]dcb72d52011-04-13 12:36:53159}
[email protected]1d51882f2013-11-12 01:59:02160#endif
[email protected]dcb72d52011-04-13 12:36:53161
[email protected]d364c652008-08-29 19:46:56162} // namespace
163
[email protected]89dbb1772012-07-17 13:47:25164// static
165#if defined(OS_CHROMEOS)
166// Must be kept in sync with
167// ChromeBrowserMainPartsChromeos::PreEarlyInitialization.
[email protected]0f13fe8d2013-11-19 08:25:00168const char TestingProfile::kTestUserProfileDir[] = "test-user";
[email protected]89dbb1772012-07-17 13:47:25169#else
170const char TestingProfile::kTestUserProfileDir[] = "Default";
171#endif
172
[email protected]f25387b2008-08-21 15:20:33173TestingProfile::TestingProfile()
[email protected]ea6f76572008-12-18 00:09:55174 : start_time_(Time::Now()),
[email protected]2fb7dc982010-09-29 12:24:28175 testing_prefs_(NULL),
[email protected]5bb2f522011-03-25 19:04:44176 incognito_(false),
[email protected]9819fd02013-08-22 10:49:39177 force_incognito_(false),
[email protected]074311a2013-02-28 23:14:09178 original_profile_(NULL),
[email protected]5cdcd152011-03-31 22:48:52179 last_session_exited_cleanly_(true),
[email protected]f0901a22013-05-27 21:37:53180 browser_context_dependency_manager_(
[email protected]f1484c52013-05-22 23:25:44181 BrowserContextDependencyManager::GetInstance()),
[email protected]37ac95b2013-07-23 23:39:35182 resource_context_(NULL),
[email protected]537c1082011-12-02 02:37:17183 delegate_(NULL) {
[email protected]5c4c89f2012-08-07 21:09:59184 CreateTempProfileDir();
[email protected]49a25632011-08-31 17:03:48185 profile_path_ = temp_dir_.path();
186
187 Init();
[email protected]537c1082011-12-02 02:37:17188 FinishInit();
[email protected]49a25632011-08-31 17:03:48189}
190
[email protected]152ea302013-02-11 04:08:40191TestingProfile::TestingProfile(const base::FilePath& path)
[email protected]49a25632011-08-31 17:03:48192 : start_time_(Time::Now()),
193 testing_prefs_(NULL),
194 incognito_(false),
[email protected]9819fd02013-08-22 10:49:39195 force_incognito_(false),
[email protected]074311a2013-02-28 23:14:09196 original_profile_(NULL),
[email protected]49a25632011-08-31 17:03:48197 last_session_exited_cleanly_(true),
198 profile_path_(path),
[email protected]f0901a22013-05-27 21:37:53199 browser_context_dependency_manager_(
[email protected]f1484c52013-05-22 23:25:44200 BrowserContextDependencyManager::GetInstance()),
[email protected]37ac95b2013-07-23 23:39:35201 resource_context_(NULL),
[email protected]537c1082011-12-02 02:37:17202 delegate_(NULL) {
[email protected]49a25632011-08-31 17:03:48203 Init();
[email protected]537c1082011-12-02 02:37:17204 FinishInit();
205}
206
[email protected]152ea302013-02-11 04:08:40207TestingProfile::TestingProfile(const base::FilePath& path,
[email protected]537c1082011-12-02 02:37:17208 Delegate* delegate)
209 : start_time_(Time::Now()),
210 testing_prefs_(NULL),
211 incognito_(false),
[email protected]9819fd02013-08-22 10:49:39212 force_incognito_(false),
[email protected]074311a2013-02-28 23:14:09213 original_profile_(NULL),
[email protected]537c1082011-12-02 02:37:17214 last_session_exited_cleanly_(true),
215 profile_path_(path),
[email protected]f0901a22013-05-27 21:37:53216 browser_context_dependency_manager_(
[email protected]f1484c52013-05-22 23:25:44217 BrowserContextDependencyManager::GetInstance()),
[email protected]37ac95b2013-07-23 23:39:35218 resource_context_(NULL),
[email protected]537c1082011-12-02 02:37:17219 delegate_(delegate) {
220 Init();
221 if (delegate_) {
[email protected]bb024fe2013-05-10 21:33:26222 base::MessageLoop::current()->PostTask(
223 FROM_HERE,
224 base::Bind(&TestingProfile::FinishInit, base::Unretained(this)));
[email protected]537c1082011-12-02 02:37:17225 } else {
226 FinishInit();
227 }
[email protected]49a25632011-08-31 17:03:48228}
229
[email protected]5c4c89f2012-08-07 21:09:59230TestingProfile::TestingProfile(
[email protected]152ea302013-02-11 04:08:40231 const base::FilePath& path,
[email protected]5c4c89f2012-08-07 21:09:59232 Delegate* delegate,
233 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy,
[email protected]9819fd02013-08-22 10:49:39234 scoped_ptr<PrefServiceSyncable> prefs,
235 bool incognito,
[email protected]371662e372013-10-17 22:05:22236 const std::string& managed_user_id,
[email protected]a43b9a82013-11-28 16:56:41237 scoped_ptr<policy::PolicyService> policy_service,
[email protected]9819fd02013-08-22 10:49:39238 const TestingFactories& factories)
[email protected]5c4c89f2012-08-07 21:09:59239 : start_time_(Time::Now()),
240 prefs_(prefs.release()),
241 testing_prefs_(NULL),
[email protected]9819fd02013-08-22 10:49:39242 incognito_(incognito),
243 force_incognito_(false),
[email protected]074311a2013-02-28 23:14:09244 original_profile_(NULL),
[email protected]371662e372013-10-17 22:05:22245 managed_user_id_(managed_user_id),
[email protected]5c4c89f2012-08-07 21:09:59246 last_session_exited_cleanly_(true),
247 extension_special_storage_policy_(extension_policy),
[email protected]5c4c89f2012-08-07 21:09:59248 profile_path_(path),
[email protected]f0901a22013-05-27 21:37:53249 browser_context_dependency_manager_(
[email protected]f1484c52013-05-22 23:25:44250 BrowserContextDependencyManager::GetInstance()),
[email protected]37ac95b2013-07-23 23:39:35251 resource_context_(NULL),
[email protected]a43b9a82013-11-28 16:56:41252 delegate_(delegate),
253 policy_service_(policy_service.release()) {
[email protected]5c4c89f2012-08-07 21:09:59254
255 // If no profile path was supplied, create one.
256 if (profile_path_.empty()) {
257 CreateTempProfileDir();
258 profile_path_ = temp_dir_.path();
259 }
260
[email protected]9819fd02013-08-22 10:49:39261 // Set any testing factories prior to initializing the services.
262 for (TestingFactories::const_iterator it = factories.begin();
263 it != factories.end(); ++it) {
264 it->first->SetTestingFactory(this, it->second);
265 }
266
[email protected]5c4c89f2012-08-07 21:09:59267 Init();
268 // If caller supplied a delegate, delay the FinishInit invocation until other
269 // tasks have run.
270 // TODO(atwilson): See if this is still required once we convert the current
271 // users of the constructor that takes a Delegate* param.
272 if (delegate_) {
[email protected]bb024fe2013-05-10 21:33:26273 base::MessageLoop::current()->PostTask(
274 FROM_HERE,
275 base::Bind(&TestingProfile::FinishInit, base::Unretained(this)));
[email protected]5c4c89f2012-08-07 21:09:59276 } else {
277 FinishInit();
278 }
279}
280
281void TestingProfile::CreateTempProfileDir() {
282 if (!temp_dir_.CreateUniqueTempDir()) {
283 LOG(ERROR) << "Failed to create unique temporary directory.";
284
285 // Fallback logic in case we fail to create unique temporary directory.
[email protected]152ea302013-02-11 04:08:40286 base::FilePath system_tmp_dir;
[email protected]5c4c89f2012-08-07 21:09:59287 bool success = PathService::Get(base::DIR_TEMP, &system_tmp_dir);
288
289 // We're severly screwed if we can't get the system temporary
290 // directory. Die now to avoid writing to the filesystem root
291 // or other bad places.
292 CHECK(success);
293
[email protected]152ea302013-02-11 04:08:40294 base::FilePath fallback_dir(
295 system_tmp_dir.AppendASCII("TestingProfilePath"));
[email protected]dd3aa792013-07-16 19:10:23296 base::DeleteFile(fallback_dir, true);
[email protected]5c4c89f2012-08-07 21:09:59297 file_util::CreateDirectory(fallback_dir);
298 if (!temp_dir_.Set(fallback_dir)) {
299 // That shouldn't happen, but if it does, try to recover.
300 LOG(ERROR) << "Failed to use a fallback temporary directory.";
301
302 // We're screwed if this fails, see CHECK above.
303 CHECK(temp_dir_.Set(system_tmp_dir));
304 }
305 }
306}
307
[email protected]49a25632011-08-31 17:03:48308void TestingProfile::Init() {
[email protected]bf390cb2013-08-06 02:48:08309 // If threads have been initialized, we should be on the UI thread.
[email protected]33d06242013-08-12 05:20:30310 DCHECK(!content::BrowserThread::IsThreadInitialized(
311 content::BrowserThread::UI) ||
312 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
[email protected]bf390cb2013-08-06 02:48:08313
[email protected]7e75e4a2013-05-17 17:20:03314 // Normally this would happen during browser startup, but for tests
315 // we need to trigger creation of Profile-related services.
316 ChromeBrowserMainExtraPartsProfiles::
[email protected]f1484c52013-05-22 23:25:44317 EnsureBrowserContextKeyedServiceFactoriesBuilt();
[email protected]7e75e4a2013-05-17 17:20:03318
[email protected]75fee372013-03-06 00:42:44319 if (prefs_.get())
[email protected]c7141feb2013-06-11 13:00:16320 user_prefs::UserPrefs::Set(this, prefs_.get());
[email protected]c7fa4362013-04-26 18:09:02321 else
322 CreateTestingPrefService();
[email protected]75fee372013-03-06 00:42:44323
[email protected]7567484142013-07-11 17:36:07324 if (!base::PathExists(profile_path_))
[email protected]d41e6572012-05-04 20:49:42325 file_util::CreateDirectory(profile_path_);
326
[email protected]d81bb3e2013-05-02 18:17:03327 // TODO(joaodasilva): remove this once this PKS isn't created in ProfileImpl
328 // anymore, after converting the PrefService to a PKS. Until then it must
329 // be associated with a TestingProfile too.
[email protected]eb83c392013-11-07 12:53:24330 if (!IsOffTheRecord())
331 CreateProfilePolicyConnector();
[email protected]d81bb3e2013-05-02 18:17:03332
[email protected]bd306722012-07-11 20:43:59333 extensions::ExtensionSystemFactory::GetInstance()->SetTestingFactory(
334 this, extensions::TestExtensionSystem::Build);
[email protected]31d8f5f22012-04-02 15:22:08335
[email protected]9819fd02013-08-22 10:49:39336 // If there is no separate original profile specified for this profile, then
337 // force preferences to be registered - this allows tests to create a
338 // standalone incognito profile while still having prefs registered.
339 browser_context_dependency_manager_->CreateBrowserContextServicesForTest(
340 this, !original_profile_);
[email protected]49a25632011-08-31 17:03:48341
[email protected]5fd2e842012-03-01 00:29:11342#if defined(ENABLE_NOTIFICATIONS)
[email protected]dcb72d52011-04-13 12:36:53343 // Install profile keyed service factory hooks for dummy/test services
[email protected]7722653b2011-06-03 17:28:22344 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory(
345 this, CreateTestDesktopNotificationService);
[email protected]5fd2e842012-03-01 00:29:11346#endif
[email protected]e1480482013-09-11 11:49:58347
348#if defined(ENABLE_MANAGED_USERS)
349 ManagedUserSettingsService* settings_service =
350 ManagedUserSettingsServiceFactory::GetForProfile(this);
351 TestingPrefStore* store = new TestingPrefStore();
352 settings_service->Init(store);
353 store->SetInitializationCompleted();
354#endif
[email protected]d6001872013-09-24 18:31:26355
356 profile_name_ = "testing_profile";
[email protected]537c1082011-12-02 02:37:17357}
[email protected]12463cd2011-07-19 09:40:20358
[email protected]537c1082011-12-02 02:37:17359void TestingProfile::FinishInit() {
[email protected]080adba92011-12-07 19:00:40360 DCHECK(content::NotificationService::current());
[email protected]ad50def52011-10-19 23:17:07361 content::NotificationService::current()->Notify(
[email protected]12463cd2011-07-19 09:40:20362 chrome::NOTIFICATION_PROFILE_CREATED,
[email protected]6c2381d2011-10-19 02:52:53363 content::Source<Profile>(static_cast<Profile*>(this)),
[email protected]ad50def52011-10-19 23:17:07364 content::NotificationService::NoDetails());
[email protected]537c1082011-12-02 02:37:17365
[email protected]371662e372013-10-17 22:05:22366 ProfileManager* profile_manager = g_browser_process->profile_manager();
367 if (profile_manager)
368 profile_manager->InitProfileUserPrefs(this);
369
[email protected]537c1082011-12-02 02:37:17370 if (delegate_)
[email protected]00b33f802012-03-13 07:46:03371 delegate_->OnProfileCreated(this, true, false);
[email protected]ab23dbe2010-08-12 02:10:46372}
373
[email protected]f25387b2008-08-21 15:20:33374TestingProfile::~TestingProfile() {
[email protected]9819fd02013-08-22 10:49:39375 // Revert to non-incognito mode before shutdown.
376 force_incognito_ = false;
377
[email protected]37ac95b2013-07-23 23:39:35378 // Any objects holding live URLFetchers should be deleted before teardown.
379 TemplateURLFetcherFactory::ShutdownForProfile(this);
380
[email protected]a7c4c032012-07-27 00:36:32381 MaybeSendDestroyedNotification();
[email protected]5cdcd152011-03-31 22:48:52382
[email protected]f0901a22013-05-27 21:37:53383 browser_context_dependency_manager_->DestroyBrowserContextServices(this);
[email protected]5cdcd152011-03-31 22:48:52384
[email protected]5c6ac842013-06-02 23:37:03385 if (host_content_settings_map_.get())
[email protected]35552dc52011-07-12 09:04:38386 host_content_settings_map_->ShutdownOnUIThread();
387
[email protected]809cc4d2010-10-27 15:22:54388 DestroyTopSites();
[email protected]cdba46992011-06-07 11:51:39389
[email protected]cc5bfd42010-11-24 14:44:02390 if (pref_proxy_config_tracker_.get())
391 pref_proxy_config_tracker_->DetachFromPrefService();
[email protected]37ac95b2013-07-23 23:39:35392 // Failing a post == leaks == heapcheck failure. Make that an immediate test
393 // failure.
394 if (resource_context_) {
395 CHECK(BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE,
396 resource_context_));
397 resource_context_ = NULL;
398 content::RunAllPendingInMessageLoop(BrowserThread::IO);
399 }
[email protected]f25387b2008-08-21 15:20:33400}
initial.commit09911bf2008-07-26 23:55:29401
[email protected]f1484c52013-05-22 23:25:44402static BrowserContextKeyedService* BuildFaviconService(
[email protected]c7fa4362013-04-26 18:09:02403 content::BrowserContext* profile) {
[email protected]f718290e2013-11-05 07:11:58404 return new FaviconService(static_cast<Profile*>(profile));
[email protected]f3d2b312012-08-23 22:27:59405}
406
[email protected]d2879af2010-02-08 16:02:56407void TestingProfile::CreateFaviconService() {
[email protected]f3d2b312012-08-23 22:27:59408 // It is up to the caller to create the history service if one is needed.
409 FaviconServiceFactory::GetInstance()->SetTestingFactory(
410 this, BuildFaviconService);
[email protected]d2879af2010-02-08 16:02:56411}
412
[email protected]f1484c52013-05-22 23:25:44413static BrowserContextKeyedService* BuildHistoryService(
[email protected]c7fa4362013-04-26 18:09:02414 content::BrowserContext* profile) {
415 return new HistoryService(static_cast<Profile*>(profile));
[email protected]f61f4782012-06-08 21:54:21416}
417
[email protected]608e7e02013-07-24 12:23:31418bool TestingProfile::CreateHistoryService(bool delete_file, bool no_db) {
[email protected]809cc4d2010-10-27 15:22:54419 DestroyHistoryService();
[email protected]f25387b2008-08-21 15:20:33420 if (delete_file) {
[email protected]152ea302013-02-11 04:08:40421 base::FilePath path = GetPath();
[email protected]f7011fcb2009-01-28 21:54:32422 path = path.Append(chrome::kHistoryFilename);
[email protected]608e7e02013-07-24 12:23:31423 if (!base::DeleteFile(path, false) || base::PathExists(path))
424 return false;
[email protected]f25387b2008-08-21 15:20:33425 }
[email protected]7019bb6d2012-08-23 09:09:48426 // This will create and init the history service.
[email protected]f61f4782012-06-08 21:54:21427 HistoryService* history_service = static_cast<HistoryService*>(
428 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse(
[email protected]a5894fe2012-11-01 14:40:56429 this, BuildHistoryService));
[email protected]7019bb6d2012-08-23 09:09:48430 if (!history_service->Init(this->GetPath(),
431 BookmarkModelFactory::GetForProfile(this),
432 no_db)) {
[email protected]f61f4782012-06-08 21:54:21433 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse(this, NULL);
[email protected]7019bb6d2012-08-23 09:09:48434 }
[email protected]a50e16a2013-04-25 14:07:17435 // Disable WebHistoryService by default, since it makes network requests.
436 WebHistoryServiceFactory::GetInstance()->SetTestingFactory(this, NULL);
[email protected]608e7e02013-07-24 12:23:31437 return true;
initial.commit09911bf2008-07-26 23:55:29438}
439
440void TestingProfile::DestroyHistoryService() {
[email protected]a5894fe2012-11-01 14:40:56441 HistoryService* history_service =
[email protected]6c537042012-07-13 00:59:02442 HistoryServiceFactory::GetForProfileWithoutCreating(this);
[email protected]a5894fe2012-11-01 14:40:56443 if (!history_service)
initial.commit09911bf2008-07-26 23:55:29444 return;
445
[email protected]f61f4782012-06-08 21:54:21446 history_service->NotifyRenderProcessHostDestruction(0);
[email protected]bb024fe2013-05-10 21:33:26447 history_service->SetOnBackendDestroyTask(base::MessageLoop::QuitClosure());
[email protected]f61f4782012-06-08 21:54:21448 history_service->Cleanup();
449 HistoryServiceFactory::ShutdownForProfile(this);
initial.commit09911bf2008-07-26 23:55:29450
451 // Wait for the backend class to terminate before deleting the files and
452 // moving to the next test. Note: if this never terminates, somebody is
453 // probably leaking a reference to the history backend, so it never calls
454 // our destroy task.
[email protected]bb024fe2013-05-10 21:33:26455 base::MessageLoop::current()->Run();
initial.commit09911bf2008-07-26 23:55:29456
initial.commit09911bf2008-07-26 23:55:29457 // Make sure we don't have any event pending that could disrupt the next
458 // test.
[email protected]bb024fe2013-05-10 21:33:26459 base::MessageLoop::current()->PostTask(FROM_HERE,
460 base::MessageLoop::QuitClosure());
461 base::MessageLoop::current()->Run();
initial.commit09911bf2008-07-26 23:55:29462}
[email protected]4d0cd7ce2008-08-11 16:40:57463
[email protected]809cc4d2010-10-27 15:22:54464void TestingProfile::CreateTopSites() {
465 DestroyTopSites();
[email protected]9a93d3432013-04-29 20:52:12466 top_sites_ = history::TopSites::Create(
467 this, GetPath().Append(chrome::kTopSitesFilename));
[email protected]809cc4d2010-10-27 15:22:54468}
469
470void TestingProfile::DestroyTopSites() {
471 if (top_sites_.get()) {
472 top_sites_->Shutdown();
473 top_sites_ = NULL;
[email protected]9a93d3432013-04-29 20:52:12474 // TopSitesImpl::Shutdown schedules some tasks (from TopSitesBackend) that
475 // need to be run to properly shutdown. Run all pending tasks now. This is
[email protected]809cc4d2010-10-27 15:22:54476 // normally handled by browser_process shutdown.
[email protected]bb024fe2013-05-10 21:33:26477 if (base::MessageLoop::current())
478 base::MessageLoop::current()->RunUntilIdle();
[email protected]809cc4d2010-10-27 15:22:54479 }
480}
481
[email protected]f1484c52013-05-22 23:25:44482static BrowserContextKeyedService* BuildBookmarkModel(
[email protected]c7fa4362013-04-26 18:09:02483 content::BrowserContext* context) {
484 Profile* profile = static_cast<Profile*>(context);
[email protected]f61f4782012-06-08 21:54:21485 BookmarkModel* bookmark_model = new BookmarkModel(profile);
[email protected]afecfb72013-04-18 17:17:33486 bookmark_model->Load(profile->GetIOTaskRunner());
[email protected]f61f4782012-06-08 21:54:21487 return bookmark_model;
488}
489
[email protected]d8e41ed2008-09-11 15:22:32490void TestingProfile::CreateBookmarkModel(bool delete_file) {
[email protected]90ef13132008-08-27 03:27:46491 if (delete_file) {
[email protected]8a39b472013-04-04 17:07:42492 base::FilePath path = GetPath().Append(chrome::kBookmarksFileName);
[email protected]dd3aa792013-07-16 19:10:23493 base::DeleteFile(path, false);
[email protected]90ef13132008-08-27 03:27:46494 }
[email protected]f61f4782012-06-08 21:54:21495 // This will create a bookmark model.
[email protected]8a39b472013-04-04 17:07:42496 BookmarkModel* bookmark_service = static_cast<BookmarkModel*>(
497 BookmarkModelFactory::GetInstance()->SetTestingFactoryAndUse(
498 this, BuildBookmarkModel));
[email protected]f61f4782012-06-08 21:54:21499
500 HistoryService* history_service =
[email protected]a5894fe2012-11-01 14:40:56501 HistoryServiceFactory::GetForProfileWithoutCreating(this);
[email protected]f61f4782012-06-08 21:54:21502 if (history_service) {
[email protected]8a39b472013-04-04 17:07:42503 history_service->history_backend_->bookmark_service_ = bookmark_service;
[email protected]f61f4782012-06-08 21:54:21504 history_service->history_backend_->expirer_.bookmark_service_ =
505 bookmark_service;
[email protected]90ef13132008-08-27 03:27:46506 }
[email protected]4d0cd7ce2008-08-11 16:40:57507}
[email protected]d2c017a2008-08-13 21:51:45508
[email protected]f1484c52013-05-22 23:25:44509static BrowserContextKeyedService* BuildWebDataService(
[email protected]c7fa4362013-04-26 18:09:02510 content::BrowserContext* profile) {
511 return new WebDataServiceWrapper(static_cast<Profile*>(profile));
[email protected]d07edd42012-05-14 23:49:46512}
[email protected]2609bc12010-01-24 08:32:55513
[email protected]d07edd42012-05-14 23:49:46514void TestingProfile::CreateWebDataService() {
[email protected]a5c65292012-05-25 00:50:01515 WebDataServiceFactory::GetInstance()->SetTestingFactory(
[email protected]d07edd42012-05-14 23:49:46516 this, BuildWebDataService);
[email protected]2609bc12010-01-24 08:32:55517}
518
[email protected]18a15ca82012-08-30 00:28:16519void TestingProfile::BlockUntilHistoryIndexIsRefreshed() {
520 // Only get the history service if it actually exists since the caller of the
521 // test should explicitly call CreateHistoryService to build it.
522 HistoryService* history_service =
523 HistoryServiceFactory::GetForProfileWithoutCreating(this);
524 DCHECK(history_service);
525 history::InMemoryURLIndex* index = history_service->InMemoryIndex();
526 if (!index || index->restored())
527 return;
528 base::RunLoop run_loop;
529 HistoryIndexRestoreObserver observer(
530 content::GetQuitTaskForRunLoop(&run_loop));
531 index->set_restore_cache_observer(&observer);
532 run_loop.Run();
533 index->set_restore_cache_observer(NULL);
534 DCHECK(index->restored());
535}
536
[email protected]120abf132011-09-27 21:38:06537// TODO(phajdan.jr): Doesn't this hang if Top Sites are already loaded?
[email protected]809cc4d2010-10-27 15:22:54538void TestingProfile::BlockUntilTopSitesLoaded() {
[email protected]a7fe9112012-07-20 02:34:45539 content::WindowedNotificationObserver top_sites_loaded_observer(
[email protected]120abf132011-09-27 21:38:06540 chrome::NOTIFICATION_TOP_SITES_LOADED,
[email protected]ad50def52011-10-19 23:17:07541 content::NotificationService::AllSources());
[email protected]120abf132011-09-27 21:38:06542 top_sites_loaded_observer.Wait();
[email protected]809cc4d2010-10-27 15:22:54543}
544
[email protected]4251165a2013-07-17 04:33:40545base::FilePath TestingProfile::GetPath() const {
[email protected]49a25632011-08-31 17:03:48546 return profile_path_;
[email protected]f9dec9482010-08-20 20:42:19547}
548
[email protected]0de615a2012-11-08 04:40:59549scoped_refptr<base::SequencedTaskRunner> TestingProfile::GetIOTaskRunner() {
[email protected]bb024fe2013-05-10 21:33:26550 return base::MessageLoop::current()->message_loop_proxy();
[email protected]0de615a2012-11-08 04:40:59551}
552
[email protected]5b199522012-12-22 17:24:44553TestingPrefServiceSyncable* TestingProfile::GetTestingPrefService() {
[email protected]2fb7dc982010-09-29 12:24:28554 if (!prefs_.get())
555 CreateTestingPrefService();
556 DCHECK(testing_prefs_);
557 return testing_prefs_;
[email protected]dbbad7a2010-08-13 18:18:36558}
559
[email protected]8e5c89a2011-06-07 18:13:33560TestingProfile* TestingProfile::AsTestingProfile() {
561 return this;
562}
563
[email protected]29d70252011-04-28 02:16:58564std::string TestingProfile::GetProfileName() {
[email protected]d6001872013-09-24 18:31:26565 return profile_name_;
[email protected]29d70252011-04-28 02:16:58566}
567
[email protected]27d6e852012-03-02 21:31:32568bool TestingProfile::IsOffTheRecord() const {
[email protected]9819fd02013-08-22 10:49:39569 return force_incognito_ || incognito_;
[email protected]fadc607b62011-02-07 17:55:50570}
571
[email protected]9819fd02013-08-22 10:49:39572void TestingProfile::SetOffTheRecordProfile(scoped_ptr<Profile> profile) {
573 DCHECK(!IsOffTheRecord());
574 incognito_profile_ = profile.Pass();
[email protected]93dba942011-02-23 22:45:01575}
576
[email protected]074311a2013-02-28 23:14:09577void TestingProfile::SetOriginalProfile(Profile* profile) {
[email protected]9819fd02013-08-22 10:49:39578 DCHECK(IsOffTheRecord());
[email protected]074311a2013-02-28 23:14:09579 original_profile_ = profile;
580}
581
[email protected]fadc607b62011-02-07 17:55:50582Profile* TestingProfile::GetOffTheRecordProfile() {
[email protected]9819fd02013-08-22 10:49:39583 if (IsOffTheRecord())
584 return this;
[email protected]5bb2f522011-03-25 19:04:44585 return incognito_profile_.get();
[email protected]fadc607b62011-02-07 17:55:50586}
587
588bool TestingProfile::HasOffTheRecordProfile() {
[email protected]5bb2f522011-03-25 19:04:44589 return incognito_profile_.get() != NULL;
[email protected]fadc607b62011-02-07 17:55:50590}
591
592Profile* TestingProfile::GetOriginalProfile() {
[email protected]074311a2013-02-28 23:14:09593 if (original_profile_)
594 return original_profile_;
[email protected]fadc607b62011-02-07 17:55:50595 return this;
596}
597
[email protected]e000daf2013-07-31 16:50:58598bool TestingProfile::IsManaged() {
[email protected]371662e372013-10-17 22:05:22599 return !managed_user_id_.empty();
[email protected]e000daf2013-07-31 16:50:58600}
601
[email protected]eaa7dd182010-12-14 11:09:00602ExtensionService* TestingProfile::GetExtensionService() {
[email protected]bd306722012-07-11 20:43:59603 return extensions::ExtensionSystem::Get(this)->extension_service();
[email protected]2fb7dc982010-09-29 12:24:28604}
605
[email protected]2261e7b72011-07-12 13:43:55606void TestingProfile::SetExtensionSpecialStoragePolicy(
607 ExtensionSpecialStoragePolicy* extension_special_storage_policy) {
608 extension_special_storage_policy_ = extension_special_storage_policy;
609}
610
[email protected]19eb80152011-02-26 00:28:43611ExtensionSpecialStoragePolicy*
612TestingProfile::GetExtensionSpecialStoragePolicy() {
[email protected]cdba46992011-06-07 11:51:39613 if (!extension_special_storage_policy_.get())
[email protected]7c5048c2011-08-19 17:07:05614 extension_special_storage_policy_ = new ExtensionSpecialStoragePolicy(NULL);
[email protected]cdba46992011-06-07 11:51:39615 return extension_special_storage_policy_.get();
[email protected]19eb80152011-02-26 00:28:43616}
617
[email protected]33ad6ce92013-08-27 14:39:08618net::CookieMonster* TestingProfile::GetCookieMonster() {
619 if (!GetRequestContext())
620 return NULL;
621 return GetRequestContext()->GetURLRequestContext()->cookie_store()->
622 GetCookieMonster();
623}
624
[email protected]2fb7dc982010-09-29 12:24:28625void TestingProfile::CreateTestingPrefService() {
626 DCHECK(!prefs_.get());
[email protected]5b199522012-12-22 17:24:44627 testing_prefs_ = new TestingPrefServiceSyncable();
[email protected]2fb7dc982010-09-29 12:24:28628 prefs_.reset(testing_prefs_);
[email protected]c7141feb2013-06-11 13:00:16629 user_prefs::UserPrefs::Set(this, prefs_.get());
[email protected]37ca3fe02013-07-05 15:32:44630 chrome::RegisterUserProfilePrefs(testing_prefs_->registry());
[email protected]2fb7dc982010-09-29 12:24:28631}
632
[email protected]d81bb3e2013-05-02 18:17:03633void TestingProfile::CreateProfilePolicyConnector() {
[email protected]d81bb3e2013-05-02 18:17:03634#if defined(ENABLE_CONFIGURATION_POLICY)
[email protected]eb83c392013-11-07 12:53:24635 schema_registry_service_ =
636 policy::SchemaRegistryServiceFactory::CreateForContext(
637 this, policy::Schema(), NULL);
638 CHECK_EQ(schema_registry_service_.get(),
639 policy::SchemaRegistryServiceFactory::GetForContext(this));
[email protected]a43b9a82013-11-28 16:56:41640#endif // defined(ENABLE_CONFIGURATION_POLICY)
[email protected]eb83c392013-11-07 12:53:24641
[email protected]a43b9a82013-11-28 16:56:41642if (!policy_service_) {
643#if defined(ENABLE_CONFIGURATION_POLICY)
644 std::vector<policy::ConfigurationPolicyProvider*> providers;
645 policy_service_.reset(new policy::PolicyServiceImpl(
646 providers, policy::PolicyServiceImpl::PreprocessCallback()));
[email protected]d81bb3e2013-05-02 18:17:03647#else
[email protected]a43b9a82013-11-28 16:56:41648 policy_service_.reset(new policy::PolicyServiceStub());
[email protected]d81bb3e2013-05-02 18:17:03649#endif
[email protected]a43b9a82013-11-28 16:56:41650 }
[email protected]24a9f1c92013-11-13 12:33:37651 profile_policy_connector_.reset(new policy::ProfilePolicyConnector());
[email protected]a43b9a82013-11-28 16:56:41652 profile_policy_connector_->InitForTesting(policy_service_.Pass());
[email protected]d81bb3e2013-05-02 18:17:03653 policy::ProfilePolicyConnectorFactory::GetInstance()->SetServiceForTesting(
654 this, profile_policy_connector_.get());
655 CHECK_EQ(profile_policy_connector_.get(),
656 policy::ProfilePolicyConnectorFactory::GetForProfile(this));
657}
658
[email protected]c753f142013-02-10 13:14:04659PrefService* TestingProfile::GetPrefs() {
[email protected]dbbad7a2010-08-13 18:18:36660 if (!prefs_.get()) {
[email protected]2fb7dc982010-09-29 12:24:28661 CreateTestingPrefService();
[email protected]dbbad7a2010-08-13 18:18:36662 }
663 return prefs_.get();
664}
665
666history::TopSites* TestingProfile::GetTopSites() {
[email protected]809cc4d2010-10-27 15:22:54667 return top_sites_.get();
[email protected]dbbad7a2010-08-13 18:18:36668}
669
[email protected]fadc607b62011-02-07 17:55:50670history::TopSites* TestingProfile::GetTopSitesWithoutCreating() {
671 return top_sites_.get();
672}
673
[email protected]b441a8492012-06-06 14:55:57674DownloadManagerDelegate* TestingProfile::GetDownloadManagerDelegate() {
[email protected]fadc607b62011-02-07 17:55:50675 return NULL;
676}
677
[email protected]abe2c032011-03-31 18:49:34678net::URLRequestContextGetter* TestingProfile::GetRequestContext() {
[email protected]37ac95b2013-07-23 23:39:35679 return GetDefaultStoragePartition(this)->GetURLRequestContext();
[email protected]812b3a32010-01-08 05:36:04680}
681
[email protected]6bd30072013-02-08 18:17:11682net::URLRequestContextGetter* TestingProfile::CreateRequestContext(
[email protected]672c8c12013-03-07 12:30:06683 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]37ac95b2013-07-23 23:39:35684 return new net::TestURLRequestContextGetter(
685 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
[email protected]6bd30072013-02-08 18:17:11686}
687
[email protected]da5683db2011-04-23 17:12:21688net::URLRequestContextGetter* TestingProfile::GetRequestContextForRenderProcess(
689 int renderer_child_id) {
[email protected]fb29e6cf2012-07-12 21:27:20690 content::RenderProcessHost* rph = content::RenderProcessHost::FromID(
691 renderer_child_id);
[email protected]1bc28312012-11-08 08:31:53692 return rph->GetStoragePartition()->GetURLRequestContext();
[email protected]d9696672011-03-15 22:45:09693}
694
[email protected]10705a7b2012-08-21 19:07:08695net::URLRequestContextGetter* TestingProfile::GetMediaRequestContext() {
696 return NULL;
697}
698
699net::URLRequestContextGetter*
700TestingProfile::GetMediaRequestContextForRenderProcess(
701 int renderer_child_id) {
[email protected]fadc607b62011-02-07 17:55:50702 return NULL;
703}
704
[email protected]10eb28162012-09-18 03:04:09705net::URLRequestContextGetter*
706TestingProfile::GetMediaRequestContextForStoragePartition(
[email protected]152ea302013-02-11 04:08:40707 const base::FilePath& partition_path,
[email protected]27ddfed22012-10-30 23:22:43708 bool in_memory) {
[email protected]10eb28162012-09-18 03:04:09709 return NULL;
710}
711
[email protected]8aca7252013-07-12 19:18:59712void TestingProfile::RequestMIDISysExPermission(
713 int render_process_id,
714 int render_view_id,
[email protected]00880a02013-10-30 03:18:30715 int bridge_id,
[email protected]8aca7252013-07-12 19:18:59716 const GURL& requesting_frame,
717 const MIDISysExPermissionCallback& callback) {
718 // Always reject requests for testing.
719 callback.Run(false);
720}
721
[email protected]00880a02013-10-30 03:18:30722void TestingProfile::CancelMIDISysExPermissionRequest(
723 int render_process_id,
724 int render_view_id,
725 int bridge_id,
726 const GURL& requesting_frame) {
727}
728
[email protected]33ad6ce92013-08-27 14:39:08729net::URLRequestContextGetter* TestingProfile::GetRequestContextForExtensions() {
730 if (!extensions_request_context_.get())
731 extensions_request_context_ = new TestExtensionURLRequestContextGetter();
732 return extensions_request_context_.get();
733}
734
[email protected]fadc607b62011-02-07 17:55:50735net::SSLConfigService* TestingProfile::GetSSLConfigService() {
[email protected]dc6655b2012-12-14 05:58:24736 if (!GetRequestContext())
737 return NULL;
738 return GetRequestContext()->GetURLRequestContext()->ssl_config_service();
[email protected]fadc607b62011-02-07 17:55:50739}
740
[email protected]10eb28162012-09-18 03:04:09741net::URLRequestContextGetter*
[email protected]6bd30072013-02-08 18:17:11742TestingProfile::CreateRequestContextForStoragePartition(
[email protected]152ea302013-02-11 04:08:40743 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:11744 bool in_memory,
[email protected]672c8c12013-03-07 12:30:06745 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]10eb28162012-09-18 03:04:09746 // We don't test storage partitions here yet, so returning the same dummy
[email protected]d9696672011-03-15 22:45:09747 // context is sufficient for now.
748 return GetRequestContext();
749}
750
[email protected]df02aca2012-02-09 21:03:20751content::ResourceContext* TestingProfile::GetResourceContext() {
[email protected]37ac95b2013-07-23 23:39:35752 if (!resource_context_)
753 resource_context_ = new content::MockResourceContext();
754 return resource_context_;
[email protected]e89b77d2011-04-15 18:58:10755}
756
[email protected]dbbad7a2010-08-13 18:18:36757HostContentSettingsMap* TestingProfile::GetHostContentSettingsMap() {
[email protected]35552dc52011-07-12 09:04:38758 if (!host_content_settings_map_.get()) {
[email protected]646c29cb62012-06-18 14:31:05759 host_content_settings_map_ = new HostContentSettingsMap(GetPrefs(), false);
[email protected]701550ad2012-09-06 23:43:29760#if defined(ENABLE_EXTENSIONS)
[email protected]646c29cb62012-06-18 14:31:05761 ExtensionService* extension_service = GetExtensionService();
762 if (extension_service)
763 host_content_settings_map_->RegisterExtensionService(extension_service);
[email protected]701550ad2012-09-06 23:43:29764#endif
[email protected]35552dc52011-07-12 09:04:38765 }
[email protected]dbbad7a2010-08-13 18:18:36766 return host_content_settings_map_.get();
767}
768
[email protected]810ddc52012-01-24 01:00:35769content::GeolocationPermissionContext*
[email protected]dbbad7a2010-08-13 18:18:36770TestingProfile::GetGeolocationPermissionContext() {
[email protected]a877a7d2013-01-08 13:40:59771 return ChromeGeolocationPermissionContextFactory::GetForProfile(this);
[email protected]dbbad7a2010-08-13 18:18:36772}
773
[email protected]fadc607b62011-02-07 17:55:50774std::wstring TestingProfile::GetName() {
775 return std::wstring();
776}
777
778std::wstring TestingProfile::GetID() {
779 return id_;
780}
781
782void TestingProfile::SetID(const std::wstring& id) {
783 id_ = id;
784}
785
[email protected]fadc607b62011-02-07 17:55:50786bool TestingProfile::IsSameProfile(Profile *p) {
787 return this == p;
788}
789
790base::Time TestingProfile::GetStartTime() const {
791 return start_time_;
792}
793
[email protected]152ea302013-02-11 04:08:40794base::FilePath TestingProfile::last_selected_directory() {
[email protected]fadc607b62011-02-07 17:55:50795 return last_selected_directory_;
796}
797
[email protected]152ea302013-02-11 04:08:40798void TestingProfile::set_last_selected_directory(const base::FilePath& path) {
[email protected]fadc607b62011-02-07 17:55:50799 last_selected_directory_ = path;
800}
801
[email protected]cc5bfd42010-11-24 14:44:02802PrefProxyConfigTracker* TestingProfile::GetProxyConfigTracker() {
[email protected]6f96cbcb2011-11-04 02:26:07803 if (!pref_proxy_config_tracker_.get()) {
[email protected]e2930d0902013-07-17 05:25:42804 // TestingProfile is used in unit tests, where local state is not available.
[email protected]6f96cbcb2011-11-04 02:26:07805 pref_proxy_config_tracker_.reset(
[email protected]e2930d0902013-07-17 05:25:42806 ProxyServiceFactory::CreatePrefProxyConfigTrackerOfProfile(GetPrefs(),
807 NULL));
[email protected]6f96cbcb2011-11-04 02:26:07808 }
809 return pref_proxy_config_tracker_.get();
[email protected]cc5bfd42010-11-24 14:44:02810}
811
[email protected]0bfc29a2009-04-27 16:15:44812void TestingProfile::BlockUntilHistoryProcessesPendingRequests() {
[email protected]a5894fe2012-11-01 14:40:56813 HistoryService* history_service =
[email protected]6c537042012-07-13 00:59:02814 HistoryServiceFactory::GetForProfile(this, Profile::EXPLICIT_ACCESS);
[email protected]a5894fe2012-11-01 14:40:56815 DCHECK(history_service);
[email protected]bb024fe2013-05-10 21:33:26816 DCHECK(base::MessageLoop::current());
[email protected]0bfc29a2009-04-27 16:15:44817
818 CancelableRequestConsumer consumer;
[email protected]f61f4782012-06-08 21:54:21819 history_service->ScheduleDBTask(new QuittingHistoryDBTask(), &consumer);
[email protected]bb024fe2013-05-10 21:33:26820 base::MessageLoop::current()->Run();
[email protected]0bfc29a2009-04-27 16:15:44821}
[email protected]345a8b72009-09-29 09:11:44822
[email protected]8382d8c2011-09-15 03:43:17823chrome_browser_net::Predictor* TestingProfile::GetNetworkPredictor() {
824 return NULL;
825}
826
[email protected]e0e1fc22012-11-05 20:25:36827void TestingProfile::ClearNetworkingHistorySince(
828 base::Time time,
829 const base::Closure& completion) {
830 if (!completion.is_null()) {
831 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, completion);
832 }
[email protected]02896a82011-09-21 18:54:32833}
834
[email protected]671f9c62011-10-28 19:22:07835GURL TestingProfile::GetHomePage() {
836 return GURL(chrome::kChromeUINewTabURL);
837}
838
[email protected]c753f142013-02-10 13:14:04839PrefService* TestingProfile::GetOffTheRecordPrefs() {
[email protected]fadc607b62011-02-07 17:55:50840 return NULL;
841}
842
[email protected]36fb2c7c2011-04-04 15:49:08843quota::SpecialStoragePolicy* TestingProfile::GetSpecialStoragePolicy() {
844 return GetExtensionSpecialStoragePolicy();
845}
846
[email protected]1bee6ed2012-03-14 06:46:36847bool TestingProfile::WasCreatedByVersionOrLater(const std::string& version) {
848 return true;
849}
[email protected]ef92e172012-04-25 19:40:41850
[email protected]4251165a2013-07-17 04:33:40851bool TestingProfile::IsGuestSession() const {
852 return false;
853}
[email protected]1101dbc52013-10-05 00:19:12854
[email protected]6c0ca7fc2012-10-05 16:27:22855Profile::ExitType TestingProfile::GetLastSessionExitType() {
856 return last_session_exited_cleanly_ ? EXIT_NORMAL : EXIT_CRASHED;
[email protected]2ca1ea662012-10-04 02:26:36857}
858
[email protected]5c4c89f2012-08-07 21:09:59859TestingProfile::Builder::Builder()
860 : build_called_(false),
[email protected]9819fd02013-08-22 10:49:39861 delegate_(NULL),
862 incognito_(false) {
[email protected]5c4c89f2012-08-07 21:09:59863}
864
865TestingProfile::Builder::~Builder() {
866}
867
[email protected]152ea302013-02-11 04:08:40868void TestingProfile::Builder::SetPath(const base::FilePath& path) {
[email protected]5c4c89f2012-08-07 21:09:59869 path_ = path;
870}
871
872void TestingProfile::Builder::SetDelegate(Delegate* delegate) {
873 delegate_ = delegate;
874}
875
876void TestingProfile::Builder::SetExtensionSpecialStoragePolicy(
877 scoped_refptr<ExtensionSpecialStoragePolicy> policy) {
878 extension_policy_ = policy;
879}
880
[email protected]5b199522012-12-22 17:24:44881void TestingProfile::Builder::SetPrefService(
882 scoped_ptr<PrefServiceSyncable> prefs) {
[email protected]5c4c89f2012-08-07 21:09:59883 pref_service_ = prefs.Pass();
884}
885
[email protected]9819fd02013-08-22 10:49:39886void TestingProfile::Builder::SetIncognito() {
887 incognito_ = true;
888}
889
[email protected]371662e372013-10-17 22:05:22890void TestingProfile::Builder::SetManagedUserId(
891 const std::string& managed_user_id) {
892 managed_user_id_ = managed_user_id;
893}
894
[email protected]a43b9a82013-11-28 16:56:41895void TestingProfile::Builder::SetPolicyService(
896 scoped_ptr<policy::PolicyService> policy_service) {
897 policy_service_ = policy_service.Pass();
898}
899
[email protected]9819fd02013-08-22 10:49:39900void TestingProfile::Builder::AddTestingFactory(
901 BrowserContextKeyedServiceFactory* service_factory,
902 BrowserContextKeyedServiceFactory::FactoryFunction callback) {
903 testing_factories_.push_back(std::make_pair(service_factory, callback));
904}
905
[email protected]5c4c89f2012-08-07 21:09:59906scoped_ptr<TestingProfile> TestingProfile::Builder::Build() {
907 DCHECK(!build_called_);
908 build_called_ = true;
[email protected]371662e372013-10-17 22:05:22909
[email protected]5c4c89f2012-08-07 21:09:59910 return scoped_ptr<TestingProfile>(new TestingProfile(
911 path_,
912 delegate_,
913 extension_policy_,
[email protected]9819fd02013-08-22 10:49:39914 pref_service_.Pass(),
915 incognito_,
[email protected]371662e372013-10-17 22:05:22916 managed_user_id_,
[email protected]a43b9a82013-11-28 16:56:41917 policy_service_.Pass(),
[email protected]9819fd02013-08-22 10:49:39918 testing_factories_));
[email protected]5c4c89f2012-08-07 21:09:59919}