blob: 9d53560c57ad8b041693f9f147d935d116971a2d [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_factory.h"
26#include "chrome/browser/extensions/test_extension_system.h"
[email protected]ee2ed42c2011-04-28 22:19:1427#include "chrome/browser/favicon/favicon_service.h"
[email protected]f3d2b312012-08-23 22:27:5928#include "chrome/browser/favicon/favicon_service_factory.h"
[email protected]c476e632011-06-23 11:18:0429#include "chrome/browser/geolocation/chrome_geolocation_permission_context.h"
[email protected]b2cf4522012-10-23 00:11:5730#include "chrome/browser/geolocation/chrome_geolocation_permission_context_factory.h"
[email protected]075ae732009-02-11 23:58:3131#include "chrome/browser/history/history_backend.h"
[email protected]d891f522013-02-08 03:24:4132#include "chrome/browser/history/history_db_task.h"
[email protected]6a2c09f2013-01-25 04:50:0733#include "chrome/browser/history/history_service.h"
[email protected]f61f4782012-06-08 21:54:2134#include "chrome/browser/history/history_service_factory.h"
[email protected]dbbad7a2010-08-13 18:18:3635#include "chrome/browser/history/top_sites.h"
[email protected]a50e16a2013-04-25 14:07:1736#include "chrome/browser/history/web_history_service_factory.h"
[email protected]53c5b0f2013-07-22 10:54:1137#include "chrome/browser/net/pref_proxy_config_tracker.h"
[email protected]6f96cbcb2011-11-04 02:26:0738#include "chrome/browser/net/proxy_service_factory.h"
[email protected]dbbad7a2010-08-13 18:18:3639#include "chrome/browser/notifications/desktop_notification_service.h"
[email protected]dcb72d52011-04-13 12:36:5340#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]d81bb3e2013-05-02 18:17:0341#include "chrome/browser/policy/profile_policy_connector.h"
42#include "chrome/browser/policy/profile_policy_connector_factory.h"
[email protected]37858e52010-08-26 00:22:0243#include "chrome/browser/prefs/browser_prefs.h"
[email protected]c753f142013-02-10 13:14:0444#include "chrome/browser/prefs/pref_service_syncable.h"
[email protected]4850a7f2011-03-08 23:36:5945#include "chrome/browser/prerender/prerender_manager.h"
[email protected]7e75e4a2013-05-17 17:20:0346#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
[email protected]371662e372013-10-17 22:05:2247#include "chrome/browser/profiles/profile_manager.h"
[email protected]27ddfed22012-10-30 23:22:4348#include "chrome/browser/profiles/storage_partition_descriptor.h"
[email protected]16bd088b2012-04-03 08:12:1249#include "chrome/browser/search_engines/template_url_fetcher_factory.h"
[email protected]810ffba2012-06-12 01:07:4850#include "chrome/browser/webdata/web_data_service.h"
[email protected]d07edd42012-05-14 23:49:4651#include "chrome/browser/webdata/web_data_service_factory.h"
[email protected]a9afddb2009-02-12 17:49:4252#include "chrome/common/chrome_constants.h"
[email protected]9e33d7e2011-09-30 16:43:5453#include "chrome/common/chrome_switches.h"
[email protected]e000daf2013-07-31 16:50:5854#include "chrome/common/pref_names.h"
[email protected]dbbad7a2010-08-13 18:18:3655#include "chrome/common/url_constants.h"
[email protected]18a15ca82012-08-30 00:28:1656#include "chrome/test/base/history_index_restore_observer.h"
[email protected]7688968a2013-02-12 21:45:1357#include "chrome/test/base/testing_pref_service_syncable.h"
[email protected]af44e7fb2011-07-29 18:32:3258#include "chrome/test/base/ui_test_utils.h"
[email protected]d4a67d52014-04-12 05:17:0359#include "components/bookmarks/core/common/bookmark_constants.h"
[email protected]540380fc2014-03-14 10:10:3460#include "components/keyed_service/content/browser_context_dependency_manager.h"
[email protected]76b4b152013-12-08 21:10:0461#include "components/policy/core/common/policy_service.h"
[email protected]75fee372013-03-06 00:42:4462#include "components/user_prefs/user_prefs.h"
[email protected]c38831a12011-10-28 12:44:4963#include "content/public/browser/browser_thread.h"
[email protected]7c4b66b2014-01-04 12:28:1364#include "content/public/browser/cookie_store_factory.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]59b0e602014-01-30 00:41:2470#include "extensions/browser/extension_system.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]eb83c392013-11-07 12:53:2479#include "chrome/browser/policy/schema_registry_service.h"
80#include "chrome/browser/policy/schema_registry_service_factory.h"
[email protected]f20a3a22013-12-03 16:12:3781#include "components/policy/core/common/configuration_policy_provider.h"
[email protected]76b4b152013-12-08 21:10:0482#include "components/policy/core/common/policy_service_impl.h"
[email protected]eb83c392013-11-07 12:53:2483#include "components/policy/core/common/schema.h"
[email protected]21d3a882012-05-31 14:41:5584#else
[email protected]76b4b152013-12-08 21:10:0485#include "components/policy/core/common/policy_service_stub.h"
[email protected]21d3a882012-05-31 14:41:5586#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() {
[email protected]7c4b66b2014-01-04 12:28:13126 net::CookieMonster* cookie_monster =
[email protected]9a6c2aa2014-01-11 22:39:39127 content::CreateCookieStore(content::CookieStoreConfig())->
128 GetCookieMonster();
[email protected]33ad6ce92013-08-27 14:39:08129 const char* schemes[] = {extensions::kExtensionScheme};
130 cookie_monster->SetCookieableSchemes(schemes, 1);
131 set_cookie_store(cookie_monster);
132 }
133
134 virtual ~TestExtensionURLRequestContext() {}
135};
136
137class TestExtensionURLRequestContextGetter
138 : public net::URLRequestContextGetter {
139 public:
140 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE {
141 if (!context_.get())
142 context_.reset(new TestExtensionURLRequestContext());
143 return context_.get();
144 }
145 virtual scoped_refptr<base::SingleThreadTaskRunner>
146 GetNetworkTaskRunner() const OVERRIDE {
147 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
148 }
149
150 protected:
151 virtual ~TestExtensionURLRequestContextGetter() {}
152
153 private:
154 scoped_ptr<net::URLRequestContext> context_;
155};
156
[email protected]1d51882f2013-11-12 01:59:02157#if defined(ENABLE_NOTIFICATIONS)
[email protected]540380fc2014-03-14 10:10:34158KeyedService* CreateTestDesktopNotificationService(
[email protected]c7fa4362013-04-26 18:09:02159 content::BrowserContext* profile) {
[email protected]c7fa4362013-04-26 18:09:02160 return new DesktopNotificationService(static_cast<Profile*>(profile), NULL);
[email protected]dcb72d52011-04-13 12:36:53161}
[email protected]1d51882f2013-11-12 01:59:02162#endif
[email protected]dcb72d52011-04-13 12:36:53163
[email protected]d364c652008-08-29 19:46:56164} // namespace
165
[email protected]89dbb1772012-07-17 13:47:25166// static
167#if defined(OS_CHROMEOS)
168// Must be kept in sync with
169// ChromeBrowserMainPartsChromeos::PreEarlyInitialization.
[email protected]0f13fe8d2013-11-19 08:25:00170const char TestingProfile::kTestUserProfileDir[] = "test-user";
[email protected]89dbb1772012-07-17 13:47:25171#else
172const char TestingProfile::kTestUserProfileDir[] = "Default";
173#endif
174
[email protected]f25387b2008-08-21 15:20:33175TestingProfile::TestingProfile()
[email protected]ea6f76572008-12-18 00:09:55176 : start_time_(Time::Now()),
[email protected]2fb7dc982010-09-29 12:24:28177 testing_prefs_(NULL),
[email protected]5bb2f522011-03-25 19:04:44178 incognito_(false),
[email protected]9819fd02013-08-22 10:49:39179 force_incognito_(false),
[email protected]074311a2013-02-28 23:14:09180 original_profile_(NULL),
[email protected]e9476cd2013-12-04 05:55:34181 guest_session_(false),
[email protected]5cdcd152011-03-31 22:48:52182 last_session_exited_cleanly_(true),
[email protected]f0901a22013-05-27 21:37:53183 browser_context_dependency_manager_(
[email protected]f1484c52013-05-22 23:25:44184 BrowserContextDependencyManager::GetInstance()),
[email protected]37ac95b2013-07-23 23:39:35185 resource_context_(NULL),
[email protected]537c1082011-12-02 02:37:17186 delegate_(NULL) {
[email protected]5c4c89f2012-08-07 21:09:59187 CreateTempProfileDir();
[email protected]49a25632011-08-31 17:03:48188 profile_path_ = temp_dir_.path();
189
190 Init();
[email protected]537c1082011-12-02 02:37:17191 FinishInit();
[email protected]49a25632011-08-31 17:03:48192}
193
[email protected]152ea302013-02-11 04:08:40194TestingProfile::TestingProfile(const base::FilePath& path)
[email protected]49a25632011-08-31 17:03:48195 : start_time_(Time::Now()),
196 testing_prefs_(NULL),
197 incognito_(false),
[email protected]9819fd02013-08-22 10:49:39198 force_incognito_(false),
[email protected]074311a2013-02-28 23:14:09199 original_profile_(NULL),
[email protected]e9476cd2013-12-04 05:55:34200 guest_session_(false),
[email protected]49a25632011-08-31 17:03:48201 last_session_exited_cleanly_(true),
202 profile_path_(path),
[email protected]f0901a22013-05-27 21:37:53203 browser_context_dependency_manager_(
[email protected]f1484c52013-05-22 23:25:44204 BrowserContextDependencyManager::GetInstance()),
[email protected]37ac95b2013-07-23 23:39:35205 resource_context_(NULL),
[email protected]537c1082011-12-02 02:37:17206 delegate_(NULL) {
[email protected]49a25632011-08-31 17:03:48207 Init();
[email protected]537c1082011-12-02 02:37:17208 FinishInit();
209}
210
[email protected]152ea302013-02-11 04:08:40211TestingProfile::TestingProfile(const base::FilePath& path,
[email protected]537c1082011-12-02 02:37:17212 Delegate* delegate)
213 : start_time_(Time::Now()),
214 testing_prefs_(NULL),
215 incognito_(false),
[email protected]9819fd02013-08-22 10:49:39216 force_incognito_(false),
[email protected]074311a2013-02-28 23:14:09217 original_profile_(NULL),
[email protected]e9476cd2013-12-04 05:55:34218 guest_session_(false),
[email protected]537c1082011-12-02 02:37:17219 last_session_exited_cleanly_(true),
220 profile_path_(path),
[email protected]f0901a22013-05-27 21:37:53221 browser_context_dependency_manager_(
[email protected]f1484c52013-05-22 23:25:44222 BrowserContextDependencyManager::GetInstance()),
[email protected]37ac95b2013-07-23 23:39:35223 resource_context_(NULL),
[email protected]537c1082011-12-02 02:37:17224 delegate_(delegate) {
225 Init();
226 if (delegate_) {
[email protected]bb024fe2013-05-10 21:33:26227 base::MessageLoop::current()->PostTask(
228 FROM_HERE,
229 base::Bind(&TestingProfile::FinishInit, base::Unretained(this)));
[email protected]537c1082011-12-02 02:37:17230 } else {
231 FinishInit();
232 }
[email protected]49a25632011-08-31 17:03:48233}
234
[email protected]5c4c89f2012-08-07 21:09:59235TestingProfile::TestingProfile(
[email protected]152ea302013-02-11 04:08:40236 const base::FilePath& path,
[email protected]5c4c89f2012-08-07 21:09:59237 Delegate* delegate,
238 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy,
[email protected]9819fd02013-08-22 10:49:39239 scoped_ptr<PrefServiceSyncable> prefs,
240 bool incognito,
[email protected]e9476cd2013-12-04 05:55:34241 bool guest_session,
[email protected]371662e372013-10-17 22:05:22242 const std::string& managed_user_id,
[email protected]a43b9a82013-11-28 16:56:41243 scoped_ptr<policy::PolicyService> policy_service,
[email protected]9819fd02013-08-22 10:49:39244 const TestingFactories& factories)
[email protected]5c4c89f2012-08-07 21:09:59245 : start_time_(Time::Now()),
246 prefs_(prefs.release()),
247 testing_prefs_(NULL),
[email protected]9819fd02013-08-22 10:49:39248 incognito_(incognito),
249 force_incognito_(false),
[email protected]074311a2013-02-28 23:14:09250 original_profile_(NULL),
[email protected]e9476cd2013-12-04 05:55:34251 guest_session_(guest_session),
[email protected]371662e372013-10-17 22:05:22252 managed_user_id_(managed_user_id),
[email protected]5c4c89f2012-08-07 21:09:59253 last_session_exited_cleanly_(true),
254 extension_special_storage_policy_(extension_policy),
[email protected]5c4c89f2012-08-07 21:09:59255 profile_path_(path),
[email protected]f0901a22013-05-27 21:37:53256 browser_context_dependency_manager_(
[email protected]f1484c52013-05-22 23:25:44257 BrowserContextDependencyManager::GetInstance()),
[email protected]37ac95b2013-07-23 23:39:35258 resource_context_(NULL),
[email protected]a43b9a82013-11-28 16:56:41259 delegate_(delegate),
260 policy_service_(policy_service.release()) {
[email protected]5c4c89f2012-08-07 21:09:59261
262 // If no profile path was supplied, create one.
263 if (profile_path_.empty()) {
264 CreateTempProfileDir();
265 profile_path_ = temp_dir_.path();
266 }
267
[email protected]9819fd02013-08-22 10:49:39268 // Set any testing factories prior to initializing the services.
269 for (TestingFactories::const_iterator it = factories.begin();
270 it != factories.end(); ++it) {
271 it->first->SetTestingFactory(this, it->second);
272 }
273
[email protected]5c4c89f2012-08-07 21:09:59274 Init();
275 // If caller supplied a delegate, delay the FinishInit invocation until other
276 // tasks have run.
277 // TODO(atwilson): See if this is still required once we convert the current
278 // users of the constructor that takes a Delegate* param.
279 if (delegate_) {
[email protected]bb024fe2013-05-10 21:33:26280 base::MessageLoop::current()->PostTask(
281 FROM_HERE,
282 base::Bind(&TestingProfile::FinishInit, base::Unretained(this)));
[email protected]5c4c89f2012-08-07 21:09:59283 } else {
284 FinishInit();
285 }
286}
287
288void TestingProfile::CreateTempProfileDir() {
289 if (!temp_dir_.CreateUniqueTempDir()) {
290 LOG(ERROR) << "Failed to create unique temporary directory.";
291
292 // Fallback logic in case we fail to create unique temporary directory.
[email protected]152ea302013-02-11 04:08:40293 base::FilePath system_tmp_dir;
[email protected]5c4c89f2012-08-07 21:09:59294 bool success = PathService::Get(base::DIR_TEMP, &system_tmp_dir);
295
296 // We're severly screwed if we can't get the system temporary
297 // directory. Die now to avoid writing to the filesystem root
298 // or other bad places.
299 CHECK(success);
300
[email protected]152ea302013-02-11 04:08:40301 base::FilePath fallback_dir(
302 system_tmp_dir.AppendASCII("TestingProfilePath"));
[email protected]dd3aa792013-07-16 19:10:23303 base::DeleteFile(fallback_dir, true);
[email protected]426d1c92013-12-03 20:08:54304 base::CreateDirectory(fallback_dir);
[email protected]5c4c89f2012-08-07 21:09:59305 if (!temp_dir_.Set(fallback_dir)) {
306 // That shouldn't happen, but if it does, try to recover.
307 LOG(ERROR) << "Failed to use a fallback temporary directory.";
308
309 // We're screwed if this fails, see CHECK above.
310 CHECK(temp_dir_.Set(system_tmp_dir));
311 }
312 }
313}
314
[email protected]49a25632011-08-31 17:03:48315void TestingProfile::Init() {
[email protected]bf390cb2013-08-06 02:48:08316 // If threads have been initialized, we should be on the UI thread.
[email protected]33d06242013-08-12 05:20:30317 DCHECK(!content::BrowserThread::IsThreadInitialized(
318 content::BrowserThread::UI) ||
319 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
[email protected]bf390cb2013-08-06 02:48:08320
[email protected]7e75e4a2013-05-17 17:20:03321 // Normally this would happen during browser startup, but for tests
322 // we need to trigger creation of Profile-related services.
323 ChromeBrowserMainExtraPartsProfiles::
[email protected]f1484c52013-05-22 23:25:44324 EnsureBrowserContextKeyedServiceFactoriesBuilt();
[email protected]7e75e4a2013-05-17 17:20:03325
[email protected]75fee372013-03-06 00:42:44326 if (prefs_.get())
[email protected]c7141feb2013-06-11 13:00:16327 user_prefs::UserPrefs::Set(this, prefs_.get());
[email protected]c7fa4362013-04-26 18:09:02328 else
329 CreateTestingPrefService();
[email protected]75fee372013-03-06 00:42:44330
[email protected]7567484142013-07-11 17:36:07331 if (!base::PathExists(profile_path_))
[email protected]426d1c92013-12-03 20:08:54332 base::CreateDirectory(profile_path_);
[email protected]d41e6572012-05-04 20:49:42333
[email protected]d81bb3e2013-05-02 18:17:03334 // TODO(joaodasilva): remove this once this PKS isn't created in ProfileImpl
335 // anymore, after converting the PrefService to a PKS. Until then it must
336 // be associated with a TestingProfile too.
[email protected]eb83c392013-11-07 12:53:24337 if (!IsOffTheRecord())
338 CreateProfilePolicyConnector();
[email protected]d81bb3e2013-05-02 18:17:03339
[email protected]bd306722012-07-11 20:43:59340 extensions::ExtensionSystemFactory::GetInstance()->SetTestingFactory(
341 this, extensions::TestExtensionSystem::Build);
[email protected]31d8f5f22012-04-02 15:22:08342
[email protected]d45c5d52013-12-04 23:41:16343 // If no original profile was specified for this profile: register preferences
344 // even if this is an incognito profile - this allows tests to create a
[email protected]9819fd02013-08-22 10:49:39345 // standalone incognito profile while still having prefs registered.
[email protected]d45c5d52013-12-04 23:41:16346 if (!IsOffTheRecord() || !original_profile_) {
347 user_prefs::PrefRegistrySyncable* pref_registry =
348 static_cast<user_prefs::PrefRegistrySyncable*>(
349 prefs_->DeprecatedGetPrefRegistry());
350 browser_context_dependency_manager_->
351 RegisterProfilePrefsForServices(this, pref_registry);
352 }
353
[email protected]9819fd02013-08-22 10:49:39354 browser_context_dependency_manager_->CreateBrowserContextServicesForTest(
[email protected]d45c5d52013-12-04 23:41:16355 this);
[email protected]49a25632011-08-31 17:03:48356
[email protected]5fd2e842012-03-01 00:29:11357#if defined(ENABLE_NOTIFICATIONS)
[email protected]dcb72d52011-04-13 12:36:53358 // Install profile keyed service factory hooks for dummy/test services
[email protected]7722653b2011-06-03 17:28:22359 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory(
360 this, CreateTestDesktopNotificationService);
[email protected]5fd2e842012-03-01 00:29:11361#endif
[email protected]e1480482013-09-11 11:49:58362
363#if defined(ENABLE_MANAGED_USERS)
364 ManagedUserSettingsService* settings_service =
365 ManagedUserSettingsServiceFactory::GetForProfile(this);
366 TestingPrefStore* store = new TestingPrefStore();
367 settings_service->Init(store);
368 store->SetInitializationCompleted();
369#endif
[email protected]d6001872013-09-24 18:31:26370
371 profile_name_ = "testing_profile";
[email protected]537c1082011-12-02 02:37:17372}
[email protected]12463cd2011-07-19 09:40:20373
[email protected]537c1082011-12-02 02:37:17374void TestingProfile::FinishInit() {
[email protected]080adba92011-12-07 19:00:40375 DCHECK(content::NotificationService::current());
[email protected]ad50def52011-10-19 23:17:07376 content::NotificationService::current()->Notify(
[email protected]12463cd2011-07-19 09:40:20377 chrome::NOTIFICATION_PROFILE_CREATED,
[email protected]6c2381d2011-10-19 02:52:53378 content::Source<Profile>(static_cast<Profile*>(this)),
[email protected]ad50def52011-10-19 23:17:07379 content::NotificationService::NoDetails());
[email protected]537c1082011-12-02 02:37:17380
[email protected]371662e372013-10-17 22:05:22381 ProfileManager* profile_manager = g_browser_process->profile_manager();
382 if (profile_manager)
383 profile_manager->InitProfileUserPrefs(this);
384
[email protected]537c1082011-12-02 02:37:17385 if (delegate_)
[email protected]00b33f802012-03-13 07:46:03386 delegate_->OnProfileCreated(this, true, false);
[email protected]ab23dbe2010-08-12 02:10:46387}
388
[email protected]f25387b2008-08-21 15:20:33389TestingProfile::~TestingProfile() {
[email protected]9819fd02013-08-22 10:49:39390 // Revert to non-incognito mode before shutdown.
391 force_incognito_ = false;
392
[email protected]37ac95b2013-07-23 23:39:35393 // Any objects holding live URLFetchers should be deleted before teardown.
394 TemplateURLFetcherFactory::ShutdownForProfile(this);
395
[email protected]a7c4c032012-07-27 00:36:32396 MaybeSendDestroyedNotification();
[email protected]5cdcd152011-03-31 22:48:52397
[email protected]f0901a22013-05-27 21:37:53398 browser_context_dependency_manager_->DestroyBrowserContextServices(this);
[email protected]5cdcd152011-03-31 22:48:52399
[email protected]5c6ac842013-06-02 23:37:03400 if (host_content_settings_map_.get())
[email protected]35552dc52011-07-12 09:04:38401 host_content_settings_map_->ShutdownOnUIThread();
402
[email protected]809cc4d2010-10-27 15:22:54403 DestroyTopSites();
[email protected]cdba46992011-06-07 11:51:39404
[email protected]cc5bfd42010-11-24 14:44:02405 if (pref_proxy_config_tracker_.get())
406 pref_proxy_config_tracker_->DetachFromPrefService();
[email protected]37ac95b2013-07-23 23:39:35407 // Failing a post == leaks == heapcheck failure. Make that an immediate test
408 // failure.
409 if (resource_context_) {
410 CHECK(BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE,
411 resource_context_));
412 resource_context_ = NULL;
413 content::RunAllPendingInMessageLoop(BrowserThread::IO);
414 }
[email protected]f25387b2008-08-21 15:20:33415}
initial.commit09911bf2008-07-26 23:55:29416
[email protected]540380fc2014-03-14 10:10:34417static KeyedService* BuildFaviconService(content::BrowserContext* profile) {
[email protected]f718290e2013-11-05 07:11:58418 return new FaviconService(static_cast<Profile*>(profile));
[email protected]f3d2b312012-08-23 22:27:59419}
420
[email protected]d2879af2010-02-08 16:02:56421void TestingProfile::CreateFaviconService() {
[email protected]f3d2b312012-08-23 22:27:59422 // It is up to the caller to create the history service if one is needed.
423 FaviconServiceFactory::GetInstance()->SetTestingFactory(
424 this, BuildFaviconService);
[email protected]d2879af2010-02-08 16:02:56425}
426
[email protected]540380fc2014-03-14 10:10:34427static KeyedService* BuildHistoryService(content::BrowserContext* profile) {
[email protected]c7fa4362013-04-26 18:09:02428 return new HistoryService(static_cast<Profile*>(profile));
[email protected]f61f4782012-06-08 21:54:21429}
430
[email protected]608e7e02013-07-24 12:23:31431bool TestingProfile::CreateHistoryService(bool delete_file, bool no_db) {
[email protected]809cc4d2010-10-27 15:22:54432 DestroyHistoryService();
[email protected]f25387b2008-08-21 15:20:33433 if (delete_file) {
[email protected]152ea302013-02-11 04:08:40434 base::FilePath path = GetPath();
[email protected]f7011fcb2009-01-28 21:54:32435 path = path.Append(chrome::kHistoryFilename);
[email protected]608e7e02013-07-24 12:23:31436 if (!base::DeleteFile(path, false) || base::PathExists(path))
437 return false;
[email protected]f25387b2008-08-21 15:20:33438 }
[email protected]7019bb6d2012-08-23 09:09:48439 // This will create and init the history service.
[email protected]f61f4782012-06-08 21:54:21440 HistoryService* history_service = static_cast<HistoryService*>(
441 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse(
[email protected]a5894fe2012-11-01 14:40:56442 this, BuildHistoryService));
[email protected]7019bb6d2012-08-23 09:09:48443 if (!history_service->Init(this->GetPath(),
444 BookmarkModelFactory::GetForProfile(this),
445 no_db)) {
[email protected]f61f4782012-06-08 21:54:21446 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse(this, NULL);
[email protected]7019bb6d2012-08-23 09:09:48447 }
[email protected]a50e16a2013-04-25 14:07:17448 // Disable WebHistoryService by default, since it makes network requests.
449 WebHistoryServiceFactory::GetInstance()->SetTestingFactory(this, NULL);
[email protected]608e7e02013-07-24 12:23:31450 return true;
initial.commit09911bf2008-07-26 23:55:29451}
452
453void TestingProfile::DestroyHistoryService() {
[email protected]a5894fe2012-11-01 14:40:56454 HistoryService* history_service =
[email protected]6c537042012-07-13 00:59:02455 HistoryServiceFactory::GetForProfileWithoutCreating(this);
[email protected]a5894fe2012-11-01 14:40:56456 if (!history_service)
initial.commit09911bf2008-07-26 23:55:29457 return;
458
[email protected]f61f4782012-06-08 21:54:21459 history_service->NotifyRenderProcessHostDestruction(0);
[email protected]bb024fe2013-05-10 21:33:26460 history_service->SetOnBackendDestroyTask(base::MessageLoop::QuitClosure());
[email protected]f61f4782012-06-08 21:54:21461 history_service->Cleanup();
462 HistoryServiceFactory::ShutdownForProfile(this);
initial.commit09911bf2008-07-26 23:55:29463
464 // Wait for the backend class to terminate before deleting the files and
465 // moving to the next test. Note: if this never terminates, somebody is
466 // probably leaking a reference to the history backend, so it never calls
467 // our destroy task.
[email protected]bb024fe2013-05-10 21:33:26468 base::MessageLoop::current()->Run();
initial.commit09911bf2008-07-26 23:55:29469
initial.commit09911bf2008-07-26 23:55:29470 // Make sure we don't have any event pending that could disrupt the next
471 // test.
[email protected]bb024fe2013-05-10 21:33:26472 base::MessageLoop::current()->PostTask(FROM_HERE,
473 base::MessageLoop::QuitClosure());
474 base::MessageLoop::current()->Run();
initial.commit09911bf2008-07-26 23:55:29475}
[email protected]4d0cd7ce2008-08-11 16:40:57476
[email protected]809cc4d2010-10-27 15:22:54477void TestingProfile::CreateTopSites() {
478 DestroyTopSites();
[email protected]9a93d3432013-04-29 20:52:12479 top_sites_ = history::TopSites::Create(
480 this, GetPath().Append(chrome::kTopSitesFilename));
[email protected]809cc4d2010-10-27 15:22:54481}
482
483void TestingProfile::DestroyTopSites() {
484 if (top_sites_.get()) {
485 top_sites_->Shutdown();
486 top_sites_ = NULL;
[email protected]9a93d3432013-04-29 20:52:12487 // TopSitesImpl::Shutdown schedules some tasks (from TopSitesBackend) that
488 // need to be run to properly shutdown. Run all pending tasks now. This is
[email protected]809cc4d2010-10-27 15:22:54489 // normally handled by browser_process shutdown.
[email protected]bb024fe2013-05-10 21:33:26490 if (base::MessageLoop::current())
491 base::MessageLoop::current()->RunUntilIdle();
[email protected]809cc4d2010-10-27 15:22:54492 }
493}
494
[email protected]540380fc2014-03-14 10:10:34495static KeyedService* BuildBookmarkModel(content::BrowserContext* context) {
[email protected]c7fa4362013-04-26 18:09:02496 Profile* profile = static_cast<Profile*>(context);
[email protected]f61f4782012-06-08 21:54:21497 BookmarkModel* bookmark_model = new BookmarkModel(profile);
[email protected]afecfb72013-04-18 17:17:33498 bookmark_model->Load(profile->GetIOTaskRunner());
[email protected]f61f4782012-06-08 21:54:21499 return bookmark_model;
500}
501
[email protected]d8e41ed2008-09-11 15:22:32502void TestingProfile::CreateBookmarkModel(bool delete_file) {
[email protected]90ef13132008-08-27 03:27:46503 if (delete_file) {
[email protected]d4a67d52014-04-12 05:17:03504 base::FilePath path = GetPath().Append(bookmarks::kBookmarksFileName);
[email protected]dd3aa792013-07-16 19:10:23505 base::DeleteFile(path, false);
[email protected]90ef13132008-08-27 03:27:46506 }
[email protected]f61f4782012-06-08 21:54:21507 // This will create a bookmark model.
[email protected]8a39b472013-04-04 17:07:42508 BookmarkModel* bookmark_service = static_cast<BookmarkModel*>(
509 BookmarkModelFactory::GetInstance()->SetTestingFactoryAndUse(
510 this, BuildBookmarkModel));
[email protected]f61f4782012-06-08 21:54:21511
512 HistoryService* history_service =
[email protected]a5894fe2012-11-01 14:40:56513 HistoryServiceFactory::GetForProfileWithoutCreating(this);
[email protected]f61f4782012-06-08 21:54:21514 if (history_service) {
[email protected]8a39b472013-04-04 17:07:42515 history_service->history_backend_->bookmark_service_ = bookmark_service;
[email protected]f61f4782012-06-08 21:54:21516 history_service->history_backend_->expirer_.bookmark_service_ =
517 bookmark_service;
[email protected]90ef13132008-08-27 03:27:46518 }
[email protected]4d0cd7ce2008-08-11 16:40:57519}
[email protected]d2c017a2008-08-13 21:51:45520
[email protected]540380fc2014-03-14 10:10:34521static KeyedService* BuildWebDataService(content::BrowserContext* profile) {
[email protected]c7fa4362013-04-26 18:09:02522 return new WebDataServiceWrapper(static_cast<Profile*>(profile));
[email protected]d07edd42012-05-14 23:49:46523}
[email protected]2609bc12010-01-24 08:32:55524
[email protected]d07edd42012-05-14 23:49:46525void TestingProfile::CreateWebDataService() {
[email protected]a5c65292012-05-25 00:50:01526 WebDataServiceFactory::GetInstance()->SetTestingFactory(
[email protected]d07edd42012-05-14 23:49:46527 this, BuildWebDataService);
[email protected]2609bc12010-01-24 08:32:55528}
529
[email protected]18a15ca82012-08-30 00:28:16530void TestingProfile::BlockUntilHistoryIndexIsRefreshed() {
531 // Only get the history service if it actually exists since the caller of the
532 // test should explicitly call CreateHistoryService to build it.
533 HistoryService* history_service =
534 HistoryServiceFactory::GetForProfileWithoutCreating(this);
535 DCHECK(history_service);
536 history::InMemoryURLIndex* index = history_service->InMemoryIndex();
537 if (!index || index->restored())
538 return;
539 base::RunLoop run_loop;
540 HistoryIndexRestoreObserver observer(
541 content::GetQuitTaskForRunLoop(&run_loop));
542 index->set_restore_cache_observer(&observer);
543 run_loop.Run();
544 index->set_restore_cache_observer(NULL);
545 DCHECK(index->restored());
546}
547
[email protected]120abf132011-09-27 21:38:06548// TODO(phajdan.jr): Doesn't this hang if Top Sites are already loaded?
[email protected]809cc4d2010-10-27 15:22:54549void TestingProfile::BlockUntilTopSitesLoaded() {
[email protected]a7fe9112012-07-20 02:34:45550 content::WindowedNotificationObserver top_sites_loaded_observer(
[email protected]120abf132011-09-27 21:38:06551 chrome::NOTIFICATION_TOP_SITES_LOADED,
[email protected]ad50def52011-10-19 23:17:07552 content::NotificationService::AllSources());
[email protected]120abf132011-09-27 21:38:06553 top_sites_loaded_observer.Wait();
[email protected]809cc4d2010-10-27 15:22:54554}
555
[email protected]4251165a2013-07-17 04:33:40556base::FilePath TestingProfile::GetPath() const {
[email protected]49a25632011-08-31 17:03:48557 return profile_path_;
[email protected]f9dec9482010-08-20 20:42:19558}
559
[email protected]0de615a2012-11-08 04:40:59560scoped_refptr<base::SequencedTaskRunner> TestingProfile::GetIOTaskRunner() {
[email protected]bb024fe2013-05-10 21:33:26561 return base::MessageLoop::current()->message_loop_proxy();
[email protected]0de615a2012-11-08 04:40:59562}
563
[email protected]5b199522012-12-22 17:24:44564TestingPrefServiceSyncable* TestingProfile::GetTestingPrefService() {
[email protected]2fb7dc982010-09-29 12:24:28565 if (!prefs_.get())
566 CreateTestingPrefService();
567 DCHECK(testing_prefs_);
568 return testing_prefs_;
[email protected]dbbad7a2010-08-13 18:18:36569}
570
[email protected]8e5c89a2011-06-07 18:13:33571TestingProfile* TestingProfile::AsTestingProfile() {
572 return this;
573}
574
[email protected]29d70252011-04-28 02:16:58575std::string TestingProfile::GetProfileName() {
[email protected]d6001872013-09-24 18:31:26576 return profile_name_;
[email protected]29d70252011-04-28 02:16:58577}
578
[email protected]7b7e0b32014-03-17 16:09:23579Profile::ProfileType TestingProfile::GetProfileType() const {
580 if (guest_session_)
581 return GUEST_PROFILE;
582 if (force_incognito_ || incognito_)
583 return INCOGNITO_PROFILE;
584 return REGULAR_PROFILE;
585}
586
[email protected]27d6e852012-03-02 21:31:32587bool TestingProfile::IsOffTheRecord() const {
[email protected]9819fd02013-08-22 10:49:39588 return force_incognito_ || incognito_;
[email protected]fadc607b62011-02-07 17:55:50589}
590
[email protected]9819fd02013-08-22 10:49:39591void TestingProfile::SetOffTheRecordProfile(scoped_ptr<Profile> profile) {
592 DCHECK(!IsOffTheRecord());
593 incognito_profile_ = profile.Pass();
[email protected]93dba942011-02-23 22:45:01594}
595
[email protected]074311a2013-02-28 23:14:09596void TestingProfile::SetOriginalProfile(Profile* profile) {
[email protected]9819fd02013-08-22 10:49:39597 DCHECK(IsOffTheRecord());
[email protected]074311a2013-02-28 23:14:09598 original_profile_ = profile;
599}
600
[email protected]fadc607b62011-02-07 17:55:50601Profile* TestingProfile::GetOffTheRecordProfile() {
[email protected]9819fd02013-08-22 10:49:39602 if (IsOffTheRecord())
603 return this;
[email protected]cbed02ae2014-03-07 17:16:26604 if (!incognito_profile_) {
605 TestingProfile::Builder builder;
606 builder.SetIncognito();
607 scoped_ptr<TestingProfile> incognito_test_profile(builder.Build());
608 incognito_test_profile->SetOriginalProfile(this);
609 SetOffTheRecordProfile(incognito_test_profile.PassAs<Profile>());
610 }
[email protected]5bb2f522011-03-25 19:04:44611 return incognito_profile_.get();
[email protected]fadc607b62011-02-07 17:55:50612}
613
614bool TestingProfile::HasOffTheRecordProfile() {
[email protected]5bb2f522011-03-25 19:04:44615 return incognito_profile_.get() != NULL;
[email protected]fadc607b62011-02-07 17:55:50616}
617
618Profile* TestingProfile::GetOriginalProfile() {
[email protected]074311a2013-02-28 23:14:09619 if (original_profile_)
620 return original_profile_;
[email protected]fadc607b62011-02-07 17:55:50621 return this;
622}
623
[email protected]e000daf2013-07-31 16:50:58624bool TestingProfile::IsManaged() {
[email protected]371662e372013-10-17 22:05:22625 return !managed_user_id_.empty();
[email protected]e000daf2013-07-31 16:50:58626}
627
[email protected]eaa7dd182010-12-14 11:09:00628ExtensionService* TestingProfile::GetExtensionService() {
[email protected]bd306722012-07-11 20:43:59629 return extensions::ExtensionSystem::Get(this)->extension_service();
[email protected]2fb7dc982010-09-29 12:24:28630}
631
[email protected]2261e7b72011-07-12 13:43:55632void TestingProfile::SetExtensionSpecialStoragePolicy(
633 ExtensionSpecialStoragePolicy* extension_special_storage_policy) {
634 extension_special_storage_policy_ = extension_special_storage_policy;
635}
636
[email protected]19eb80152011-02-26 00:28:43637ExtensionSpecialStoragePolicy*
638TestingProfile::GetExtensionSpecialStoragePolicy() {
[email protected]cdba46992011-06-07 11:51:39639 if (!extension_special_storage_policy_.get())
[email protected]7c5048c2011-08-19 17:07:05640 extension_special_storage_policy_ = new ExtensionSpecialStoragePolicy(NULL);
[email protected]cdba46992011-06-07 11:51:39641 return extension_special_storage_policy_.get();
[email protected]19eb80152011-02-26 00:28:43642}
643
[email protected]33ad6ce92013-08-27 14:39:08644net::CookieMonster* TestingProfile::GetCookieMonster() {
645 if (!GetRequestContext())
646 return NULL;
647 return GetRequestContext()->GetURLRequestContext()->cookie_store()->
648 GetCookieMonster();
649}
650
[email protected]2fb7dc982010-09-29 12:24:28651void TestingProfile::CreateTestingPrefService() {
652 DCHECK(!prefs_.get());
[email protected]5b199522012-12-22 17:24:44653 testing_prefs_ = new TestingPrefServiceSyncable();
[email protected]2fb7dc982010-09-29 12:24:28654 prefs_.reset(testing_prefs_);
[email protected]c7141feb2013-06-11 13:00:16655 user_prefs::UserPrefs::Set(this, prefs_.get());
[email protected]37ca3fe02013-07-05 15:32:44656 chrome::RegisterUserProfilePrefs(testing_prefs_->registry());
[email protected]2fb7dc982010-09-29 12:24:28657}
658
[email protected]d81bb3e2013-05-02 18:17:03659void TestingProfile::CreateProfilePolicyConnector() {
[email protected]d81bb3e2013-05-02 18:17:03660#if defined(ENABLE_CONFIGURATION_POLICY)
[email protected]eb83c392013-11-07 12:53:24661 schema_registry_service_ =
662 policy::SchemaRegistryServiceFactory::CreateForContext(
663 this, policy::Schema(), NULL);
664 CHECK_EQ(schema_registry_service_.get(),
665 policy::SchemaRegistryServiceFactory::GetForContext(this));
[email protected]a43b9a82013-11-28 16:56:41666#endif // defined(ENABLE_CONFIGURATION_POLICY)
[email protected]eb83c392013-11-07 12:53:24667
[email protected]a43b9a82013-11-28 16:56:41668if (!policy_service_) {
669#if defined(ENABLE_CONFIGURATION_POLICY)
670 std::vector<policy::ConfigurationPolicyProvider*> providers;
[email protected]33528402013-12-16 18:38:32671 policy_service_.reset(new policy::PolicyServiceImpl(providers));
[email protected]d81bb3e2013-05-02 18:17:03672#else
[email protected]a43b9a82013-11-28 16:56:41673 policy_service_.reset(new policy::PolicyServiceStub());
[email protected]d81bb3e2013-05-02 18:17:03674#endif
[email protected]a43b9a82013-11-28 16:56:41675 }
[email protected]24a9f1c92013-11-13 12:33:37676 profile_policy_connector_.reset(new policy::ProfilePolicyConnector());
[email protected]a43b9a82013-11-28 16:56:41677 profile_policy_connector_->InitForTesting(policy_service_.Pass());
[email protected]d81bb3e2013-05-02 18:17:03678 policy::ProfilePolicyConnectorFactory::GetInstance()->SetServiceForTesting(
679 this, profile_policy_connector_.get());
680 CHECK_EQ(profile_policy_connector_.get(),
681 policy::ProfilePolicyConnectorFactory::GetForProfile(this));
682}
683
[email protected]c753f142013-02-10 13:14:04684PrefService* TestingProfile::GetPrefs() {
[email protected]dbbad7a2010-08-13 18:18:36685 if (!prefs_.get()) {
[email protected]2fb7dc982010-09-29 12:24:28686 CreateTestingPrefService();
[email protected]dbbad7a2010-08-13 18:18:36687 }
688 return prefs_.get();
689}
690
691history::TopSites* TestingProfile::GetTopSites() {
[email protected]809cc4d2010-10-27 15:22:54692 return top_sites_.get();
[email protected]dbbad7a2010-08-13 18:18:36693}
694
[email protected]fadc607b62011-02-07 17:55:50695history::TopSites* TestingProfile::GetTopSitesWithoutCreating() {
696 return top_sites_.get();
697}
698
[email protected]b441a8492012-06-06 14:55:57699DownloadManagerDelegate* TestingProfile::GetDownloadManagerDelegate() {
[email protected]fadc607b62011-02-07 17:55:50700 return NULL;
701}
702
[email protected]abe2c032011-03-31 18:49:34703net::URLRequestContextGetter* TestingProfile::GetRequestContext() {
[email protected]37ac95b2013-07-23 23:39:35704 return GetDefaultStoragePartition(this)->GetURLRequestContext();
[email protected]812b3a32010-01-08 05:36:04705}
706
[email protected]6bd30072013-02-08 18:17:11707net::URLRequestContextGetter* TestingProfile::CreateRequestContext(
[email protected]7571263c2014-03-10 22:57:09708 content::ProtocolHandlerMap* protocol_handlers,
709 content::ProtocolHandlerScopedVector protocol_interceptors) {
[email protected]37ac95b2013-07-23 23:39:35710 return new net::TestURLRequestContextGetter(
711 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
[email protected]6bd30072013-02-08 18:17:11712}
713
[email protected]da5683db2011-04-23 17:12:21714net::URLRequestContextGetter* TestingProfile::GetRequestContextForRenderProcess(
715 int renderer_child_id) {
[email protected]fb29e6cf2012-07-12 21:27:20716 content::RenderProcessHost* rph = content::RenderProcessHost::FromID(
717 renderer_child_id);
[email protected]1bc28312012-11-08 08:31:53718 return rph->GetStoragePartition()->GetURLRequestContext();
[email protected]d9696672011-03-15 22:45:09719}
720
[email protected]10705a7b2012-08-21 19:07:08721net::URLRequestContextGetter* TestingProfile::GetMediaRequestContext() {
722 return NULL;
723}
724
725net::URLRequestContextGetter*
726TestingProfile::GetMediaRequestContextForRenderProcess(
727 int renderer_child_id) {
[email protected]fadc607b62011-02-07 17:55:50728 return NULL;
729}
730
[email protected]10eb28162012-09-18 03:04:09731net::URLRequestContextGetter*
732TestingProfile::GetMediaRequestContextForStoragePartition(
[email protected]152ea302013-02-11 04:08:40733 const base::FilePath& partition_path,
[email protected]27ddfed22012-10-30 23:22:43734 bool in_memory) {
[email protected]10eb28162012-09-18 03:04:09735 return NULL;
736}
737
[email protected]6e068ea2014-02-04 07:05:47738void TestingProfile::RequestMidiSysExPermission(
[email protected]8aca7252013-07-12 19:18:59739 int render_process_id,
740 int render_view_id,
[email protected]00880a02013-10-30 03:18:30741 int bridge_id,
[email protected]8aca7252013-07-12 19:18:59742 const GURL& requesting_frame,
[email protected]7c6d9482014-03-28 20:19:31743 bool user_gesture,
[email protected]6e068ea2014-02-04 07:05:47744 const MidiSysExPermissionCallback& callback) {
[email protected]8aca7252013-07-12 19:18:59745 // Always reject requests for testing.
746 callback.Run(false);
747}
748
[email protected]6e068ea2014-02-04 07:05:47749void TestingProfile::CancelMidiSysExPermissionRequest(
[email protected]00880a02013-10-30 03:18:30750 int render_process_id,
751 int render_view_id,
752 int bridge_id,
753 const GURL& requesting_frame) {
754}
755
[email protected]566755f82014-01-08 01:14:57756void TestingProfile::RequestProtectedMediaIdentifierPermission(
757 int render_process_id,
758 int render_view_id,
759 int bridge_id,
760 int group_id,
761 const GURL& requesting_frame,
762 const ProtectedMediaIdentifierPermissionCallback& callback) {
763 // Always reject requests for testing.
764 callback.Run(false);
765}
766
767void TestingProfile::CancelProtectedMediaIdentifierPermissionRequests(
768 int group_id) {
769}
770
[email protected]33ad6ce92013-08-27 14:39:08771net::URLRequestContextGetter* TestingProfile::GetRequestContextForExtensions() {
772 if (!extensions_request_context_.get())
773 extensions_request_context_ = new TestExtensionURLRequestContextGetter();
774 return extensions_request_context_.get();
775}
776
[email protected]fadc607b62011-02-07 17:55:50777net::SSLConfigService* TestingProfile::GetSSLConfigService() {
[email protected]dc6655b2012-12-14 05:58:24778 if (!GetRequestContext())
779 return NULL;
780 return GetRequestContext()->GetURLRequestContext()->ssl_config_service();
[email protected]fadc607b62011-02-07 17:55:50781}
782
[email protected]10eb28162012-09-18 03:04:09783net::URLRequestContextGetter*
[email protected]6bd30072013-02-08 18:17:11784TestingProfile::CreateRequestContextForStoragePartition(
[email protected]152ea302013-02-11 04:08:40785 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:11786 bool in_memory,
[email protected]7571263c2014-03-10 22:57:09787 content::ProtocolHandlerMap* protocol_handlers,
788 content::ProtocolHandlerScopedVector protocol_interceptors) {
[email protected]10eb28162012-09-18 03:04:09789 // We don't test storage partitions here yet, so returning the same dummy
[email protected]d9696672011-03-15 22:45:09790 // context is sufficient for now.
791 return GetRequestContext();
792}
793
[email protected]df02aca2012-02-09 21:03:20794content::ResourceContext* TestingProfile::GetResourceContext() {
[email protected]37ac95b2013-07-23 23:39:35795 if (!resource_context_)
796 resource_context_ = new content::MockResourceContext();
797 return resource_context_;
[email protected]e89b77d2011-04-15 18:58:10798}
799
[email protected]dbbad7a2010-08-13 18:18:36800HostContentSettingsMap* TestingProfile::GetHostContentSettingsMap() {
[email protected]35552dc52011-07-12 09:04:38801 if (!host_content_settings_map_.get()) {
[email protected]646c29cb62012-06-18 14:31:05802 host_content_settings_map_ = new HostContentSettingsMap(GetPrefs(), false);
[email protected]701550ad2012-09-06 23:43:29803#if defined(ENABLE_EXTENSIONS)
[email protected]646c29cb62012-06-18 14:31:05804 ExtensionService* extension_service = GetExtensionService();
805 if (extension_service)
806 host_content_settings_map_->RegisterExtensionService(extension_service);
[email protected]701550ad2012-09-06 23:43:29807#endif
[email protected]35552dc52011-07-12 09:04:38808 }
[email protected]dbbad7a2010-08-13 18:18:36809 return host_content_settings_map_.get();
810}
811
[email protected]810ddc52012-01-24 01:00:35812content::GeolocationPermissionContext*
[email protected]dbbad7a2010-08-13 18:18:36813TestingProfile::GetGeolocationPermissionContext() {
[email protected]a877a7d2013-01-08 13:40:59814 return ChromeGeolocationPermissionContextFactory::GetForProfile(this);
[email protected]dbbad7a2010-08-13 18:18:36815}
816
[email protected]fadc607b62011-02-07 17:55:50817std::wstring TestingProfile::GetName() {
818 return std::wstring();
819}
820
821std::wstring TestingProfile::GetID() {
822 return id_;
823}
824
825void TestingProfile::SetID(const std::wstring& id) {
826 id_ = id;
827}
828
[email protected]fadc607b62011-02-07 17:55:50829bool TestingProfile::IsSameProfile(Profile *p) {
830 return this == p;
831}
832
833base::Time TestingProfile::GetStartTime() const {
834 return start_time_;
835}
836
[email protected]152ea302013-02-11 04:08:40837base::FilePath TestingProfile::last_selected_directory() {
[email protected]fadc607b62011-02-07 17:55:50838 return last_selected_directory_;
839}
840
[email protected]152ea302013-02-11 04:08:40841void TestingProfile::set_last_selected_directory(const base::FilePath& path) {
[email protected]fadc607b62011-02-07 17:55:50842 last_selected_directory_ = path;
843}
844
[email protected]cc5bfd42010-11-24 14:44:02845PrefProxyConfigTracker* TestingProfile::GetProxyConfigTracker() {
[email protected]6f96cbcb2011-11-04 02:26:07846 if (!pref_proxy_config_tracker_.get()) {
[email protected]e2930d0902013-07-17 05:25:42847 // TestingProfile is used in unit tests, where local state is not available.
[email protected]6f96cbcb2011-11-04 02:26:07848 pref_proxy_config_tracker_.reset(
[email protected]e2930d0902013-07-17 05:25:42849 ProxyServiceFactory::CreatePrefProxyConfigTrackerOfProfile(GetPrefs(),
850 NULL));
[email protected]6f96cbcb2011-11-04 02:26:07851 }
852 return pref_proxy_config_tracker_.get();
[email protected]cc5bfd42010-11-24 14:44:02853}
854
[email protected]0bfc29a2009-04-27 16:15:44855void TestingProfile::BlockUntilHistoryProcessesPendingRequests() {
[email protected]a5894fe2012-11-01 14:40:56856 HistoryService* history_service =
[email protected]6c537042012-07-13 00:59:02857 HistoryServiceFactory::GetForProfile(this, Profile::EXPLICIT_ACCESS);
[email protected]a5894fe2012-11-01 14:40:56858 DCHECK(history_service);
[email protected]bb024fe2013-05-10 21:33:26859 DCHECK(base::MessageLoop::current());
[email protected]0bfc29a2009-04-27 16:15:44860
861 CancelableRequestConsumer consumer;
[email protected]f61f4782012-06-08 21:54:21862 history_service->ScheduleDBTask(new QuittingHistoryDBTask(), &consumer);
[email protected]bb024fe2013-05-10 21:33:26863 base::MessageLoop::current()->Run();
[email protected]0bfc29a2009-04-27 16:15:44864}
[email protected]345a8b72009-09-29 09:11:44865
[email protected]8382d8c2011-09-15 03:43:17866chrome_browser_net::Predictor* TestingProfile::GetNetworkPredictor() {
867 return NULL;
868}
869
[email protected]e0e1fc22012-11-05 20:25:36870void TestingProfile::ClearNetworkingHistorySince(
871 base::Time time,
872 const base::Closure& completion) {
873 if (!completion.is_null()) {
874 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, completion);
875 }
[email protected]02896a82011-09-21 18:54:32876}
877
[email protected]671f9c62011-10-28 19:22:07878GURL TestingProfile::GetHomePage() {
879 return GURL(chrome::kChromeUINewTabURL);
880}
881
[email protected]c753f142013-02-10 13:14:04882PrefService* TestingProfile::GetOffTheRecordPrefs() {
[email protected]fadc607b62011-02-07 17:55:50883 return NULL;
884}
885
[email protected]36fb2c7c2011-04-04 15:49:08886quota::SpecialStoragePolicy* TestingProfile::GetSpecialStoragePolicy() {
887 return GetExtensionSpecialStoragePolicy();
888}
889
[email protected]1bee6ed2012-03-14 06:46:36890bool TestingProfile::WasCreatedByVersionOrLater(const std::string& version) {
891 return true;
892}
[email protected]ef92e172012-04-25 19:40:41893
[email protected]4251165a2013-07-17 04:33:40894bool TestingProfile::IsGuestSession() const {
[email protected]e9476cd2013-12-04 05:55:34895 return guest_session_;
[email protected]4251165a2013-07-17 04:33:40896}
[email protected]1101dbc52013-10-05 00:19:12897
[email protected]6c0ca7fc2012-10-05 16:27:22898Profile::ExitType TestingProfile::GetLastSessionExitType() {
899 return last_session_exited_cleanly_ ? EXIT_NORMAL : EXIT_CRASHED;
[email protected]2ca1ea662012-10-04 02:26:36900}
901
[email protected]5c4c89f2012-08-07 21:09:59902TestingProfile::Builder::Builder()
903 : build_called_(false),
[email protected]9819fd02013-08-22 10:49:39904 delegate_(NULL),
[email protected]e9476cd2013-12-04 05:55:34905 incognito_(false),
906 guest_session_(false) {
[email protected]5c4c89f2012-08-07 21:09:59907}
908
909TestingProfile::Builder::~Builder() {
910}
911
[email protected]152ea302013-02-11 04:08:40912void TestingProfile::Builder::SetPath(const base::FilePath& path) {
[email protected]5c4c89f2012-08-07 21:09:59913 path_ = path;
914}
915
916void TestingProfile::Builder::SetDelegate(Delegate* delegate) {
917 delegate_ = delegate;
918}
919
920void TestingProfile::Builder::SetExtensionSpecialStoragePolicy(
921 scoped_refptr<ExtensionSpecialStoragePolicy> policy) {
922 extension_policy_ = policy;
923}
924
[email protected]5b199522012-12-22 17:24:44925void TestingProfile::Builder::SetPrefService(
926 scoped_ptr<PrefServiceSyncable> prefs) {
[email protected]5c4c89f2012-08-07 21:09:59927 pref_service_ = prefs.Pass();
928}
929
[email protected]9819fd02013-08-22 10:49:39930void TestingProfile::Builder::SetIncognito() {
931 incognito_ = true;
932}
933
[email protected]e9476cd2013-12-04 05:55:34934void TestingProfile::Builder::SetGuestSession() {
935 guest_session_ = true;
936}
937
[email protected]371662e372013-10-17 22:05:22938void TestingProfile::Builder::SetManagedUserId(
939 const std::string& managed_user_id) {
940 managed_user_id_ = managed_user_id;
941}
942
[email protected]a43b9a82013-11-28 16:56:41943void TestingProfile::Builder::SetPolicyService(
944 scoped_ptr<policy::PolicyService> policy_service) {
945 policy_service_ = policy_service.Pass();
946}
947
[email protected]9819fd02013-08-22 10:49:39948void TestingProfile::Builder::AddTestingFactory(
949 BrowserContextKeyedServiceFactory* service_factory,
[email protected]d45c5d52013-12-04 23:41:16950 BrowserContextKeyedServiceFactory::TestingFactoryFunction callback) {
[email protected]9819fd02013-08-22 10:49:39951 testing_factories_.push_back(std::make_pair(service_factory, callback));
952}
953
[email protected]5c4c89f2012-08-07 21:09:59954scoped_ptr<TestingProfile> TestingProfile::Builder::Build() {
955 DCHECK(!build_called_);
956 build_called_ = true;
[email protected]371662e372013-10-17 22:05:22957
[email protected]5c4c89f2012-08-07 21:09:59958 return scoped_ptr<TestingProfile>(new TestingProfile(
959 path_,
960 delegate_,
961 extension_policy_,
[email protected]9819fd02013-08-22 10:49:39962 pref_service_.Pass(),
963 incognito_,
[email protected]e9476cd2013-12-04 05:55:34964 guest_session_,
[email protected]371662e372013-10-17 22:05:22965 managed_user_id_,
[email protected]a43b9a82013-11-28 16:56:41966 policy_service_.Pass(),
[email protected]9819fd02013-08-22 10:49:39967 testing_factories_));
[email protected]5c4c89f2012-08-07 21:09:59968}