blob: e9eda9dd9ef8780051907cd0dc68796f932848b6 [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]f61f4782012-06-08 21:54:2118#include "chrome/browser/bookmarks/bookmark_model_factory.h"
[email protected]6a848b52014-04-26 22:06:5419#include "chrome/browser/bookmarks/chrome_bookmark_client.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]24569262014-05-06 03:31:3031#include "chrome/browser/guest_view/guest_view_manager.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]dbbad7a2010-08-13 18:18:3636#include "chrome/browser/history/top_sites.h"
[email protected]a50e16a2013-04-25 14:07:1737#include "chrome/browser/history/web_history_service_factory.h"
[email protected]53c5b0f2013-07-22 10:54:1138#include "chrome/browser/net/pref_proxy_config_tracker.h"
[email protected]6f96cbcb2011-11-04 02:26:0739#include "chrome/browser/net/proxy_service_factory.h"
[email protected]dbbad7a2010-08-13 18:18:3640#include "chrome/browser/notifications/desktop_notification_service.h"
[email protected]dcb72d52011-04-13 12:36:5341#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]d81bb3e2013-05-02 18:17:0342#include "chrome/browser/policy/profile_policy_connector.h"
43#include "chrome/browser/policy/profile_policy_connector_factory.h"
[email protected]37858e52010-08-26 00:22:0244#include "chrome/browser/prefs/browser_prefs.h"
[email protected]c753f142013-02-10 13:14:0445#include "chrome/browser/prefs/pref_service_syncable.h"
[email protected]4850a7f2011-03-08 23:36:5946#include "chrome/browser/prerender/prerender_manager.h"
[email protected]7e75e4a2013-05-17 17:20:0347#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
[email protected]371662e372013-10-17 22:05:2248#include "chrome/browser/profiles/profile_manager.h"
[email protected]27ddfed22012-10-30 23:22:4349#include "chrome/browser/profiles/storage_partition_descriptor.h"
[email protected]16bd088b2012-04-03 08:12:1250#include "chrome/browser/search_engines/template_url_fetcher_factory.h"
[email protected]810ffba2012-06-12 01:07:4851#include "chrome/browser/webdata/web_data_service.h"
[email protected]d07edd42012-05-14 23:49:4652#include "chrome/browser/webdata/web_data_service_factory.h"
[email protected]a9afddb2009-02-12 17:49:4253#include "chrome/common/chrome_constants.h"
[email protected]9e33d7e2011-09-30 16:43:5454#include "chrome/common/chrome_switches.h"
[email protected]e000daf2013-07-31 16:50:5855#include "chrome/common/pref_names.h"
[email protected]dbbad7a2010-08-13 18:18:3656#include "chrome/common/url_constants.h"
[email protected]18a15ca82012-08-30 00:28:1657#include "chrome/test/base/history_index_restore_observer.h"
[email protected]7688968a2013-02-12 21:45:1358#include "chrome/test/base/testing_pref_service_syncable.h"
[email protected]af44e7fb2011-07-29 18:32:3259#include "chrome/test/base/ui_test_utils.h"
[email protected]c47f86fa2014-04-30 02:20:1860#include "components/bookmarks/core/browser/bookmark_model.h"
[email protected]d4a67d52014-04-12 05:17:0361#include "components/bookmarks/core/common/bookmark_constants.h"
[email protected]540380fc2014-03-14 10:10:3462#include "components/keyed_service/content/browser_context_dependency_manager.h"
[email protected]76b4b152013-12-08 21:10:0463#include "components/policy/core/common/policy_service.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]7c4b66b2014-01-04 12:28:1366#include "content/public/browser/cookie_store_factory.h"
[email protected]ad50def52011-10-19 23:17:0767#include "content/public/browser/notification_service.h"
[email protected]fb29e6cf2012-07-12 21:27:2068#include "content/public/browser/render_process_host.h"
[email protected]885c0e92012-11-13 20:27:4269#include "content/public/browser/storage_partition.h"
[email protected]08a932d52012-06-03 21:42:1270#include "content/public/test/mock_resource_context.h"
[email protected]a7fe9112012-07-20 02:34:4571#include "content/public/test/test_utils.h"
[email protected]59b0e602014-01-30 00:41:2472#include "extensions/browser/extension_system.h"
[email protected]885c0e92012-11-13 20:27:4273#include "extensions/common/constants.h"
[email protected]aa84a7e2012-03-15 21:29:0674#include "net/cookies/cookie_monster.h"
[email protected]812b3a32010-01-08 05:36:0475#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:3476#include "net/url_request/url_request_context_getter.h"
[email protected]d2db0292011-01-26 20:23:4477#include "net/url_request/url_request_test_util.h"
[email protected]4772b072010-03-30 17:45:4678#include "testing/gmock/include/gmock/gmock.h"
[email protected]248ce192011-02-10 15:26:3479
[email protected]21d3a882012-05-31 14:41:5580#if defined(ENABLE_CONFIGURATION_POLICY)
[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"
[email protected]f20a3a22013-12-03 16:12:3783#include "components/policy/core/common/configuration_policy_provider.h"
[email protected]76b4b152013-12-08 21:10:0484#include "components/policy/core/common/policy_service_impl.h"
[email protected]eb83c392013-11-07 12:53:2485#include "components/policy/core/common/schema.h"
[email protected]21d3a882012-05-31 14:41:5586#else
[email protected]76b4b152013-12-08 21:10:0487#include "components/policy/core/common/policy_service_stub.h"
[email protected]21d3a882012-05-31 14:41:5588#endif // defined(ENABLE_CONFIGURATION_POLICY)
89
[email protected]e1480482013-09-11 11:49:5890#if defined(ENABLE_MANAGED_USERS)
91#include "chrome/browser/managed_mode/managed_user_settings_service.h"
92#include "chrome/browser/managed_mode/managed_user_settings_service_factory.h"
93#endif
94
[email protected]e1acf6f2008-10-27 20:43:3395using base::Time;
[email protected]631bb742011-11-02 11:29:3996using content::BrowserThread;
[email protected]b441a8492012-06-06 14:55:5797using content::DownloadManagerDelegate;
[email protected]3c887412010-04-19 20:30:2398using testing::NiceMock;
[email protected]4772b072010-03-30 17:45:4699using testing::Return;
[email protected]e1acf6f2008-10-27 20:43:33100
[email protected]d364c652008-08-29 19:46:56101namespace {
102
[email protected]0bfc29a2009-04-27 16:15:44103// Task used to make sure history has finished processing a request. Intended
104// for use with BlockUntilHistoryProcessesPendingRequests.
105
[email protected]d891f522013-02-08 03:24:41106class QuittingHistoryDBTask : public history::HistoryDBTask {
[email protected]0bfc29a2009-04-27 16:15:44107 public:
108 QuittingHistoryDBTask() {}
109
110 virtual bool RunOnDBThread(history::HistoryBackend* backend,
[email protected]be9826e62013-02-07 02:00:58111 history::HistoryDatabase* db) OVERRIDE {
[email protected]0bfc29a2009-04-27 16:15:44112 return true;
113 }
114
[email protected]be9826e62013-02-07 02:00:58115 virtual void DoneRunOnMainThread() OVERRIDE {
[email protected]bb024fe2013-05-10 21:33:26116 base::MessageLoop::current()->Quit();
[email protected]0bfc29a2009-04-27 16:15:44117 }
118
119 private:
[email protected]be9826e62013-02-07 02:00:58120 virtual ~QuittingHistoryDBTask() {}
[email protected]7991a232009-11-06 01:55:48121
[email protected]0bfc29a2009-04-27 16:15:44122 DISALLOW_COPY_AND_ASSIGN(QuittingHistoryDBTask);
123};
124
[email protected]33ad6ce92013-08-27 14:39:08125class TestExtensionURLRequestContext : public net::URLRequestContext {
126 public:
127 TestExtensionURLRequestContext() {
[email protected]7c4b66b2014-01-04 12:28:13128 net::CookieMonster* cookie_monster =
[email protected]9a6c2aa2014-01-11 22:39:39129 content::CreateCookieStore(content::CookieStoreConfig())->
130 GetCookieMonster();
[email protected]33ad6ce92013-08-27 14:39:08131 const char* schemes[] = {extensions::kExtensionScheme};
132 cookie_monster->SetCookieableSchemes(schemes, 1);
133 set_cookie_store(cookie_monster);
134 }
135
136 virtual ~TestExtensionURLRequestContext() {}
137};
138
139class TestExtensionURLRequestContextGetter
140 : public net::URLRequestContextGetter {
141 public:
142 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE {
143 if (!context_.get())
144 context_.reset(new TestExtensionURLRequestContext());
145 return context_.get();
146 }
147 virtual scoped_refptr<base::SingleThreadTaskRunner>
148 GetNetworkTaskRunner() const OVERRIDE {
149 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
150 }
151
152 protected:
153 virtual ~TestExtensionURLRequestContextGetter() {}
154
155 private:
156 scoped_ptr<net::URLRequestContext> context_;
157};
158
[email protected]1d51882f2013-11-12 01:59:02159#if defined(ENABLE_NOTIFICATIONS)
[email protected]540380fc2014-03-14 10:10:34160KeyedService* CreateTestDesktopNotificationService(
[email protected]c7fa4362013-04-26 18:09:02161 content::BrowserContext* profile) {
[email protected]c7fa4362013-04-26 18:09:02162 return new DesktopNotificationService(static_cast<Profile*>(profile), NULL);
[email protected]dcb72d52011-04-13 12:36:53163}
[email protected]1d51882f2013-11-12 01:59:02164#endif
[email protected]dcb72d52011-04-13 12:36:53165
[email protected]d364c652008-08-29 19:46:56166} // namespace
167
[email protected]89dbb1772012-07-17 13:47:25168// static
169#if defined(OS_CHROMEOS)
170// Must be kept in sync with
171// ChromeBrowserMainPartsChromeos::PreEarlyInitialization.
[email protected]0f13fe8d2013-11-19 08:25:00172const char TestingProfile::kTestUserProfileDir[] = "test-user";
[email protected]89dbb1772012-07-17 13:47:25173#else
174const char TestingProfile::kTestUserProfileDir[] = "Default";
175#endif
176
[email protected]f25387b2008-08-21 15:20:33177TestingProfile::TestingProfile()
[email protected]ea6f76572008-12-18 00:09:55178 : start_time_(Time::Now()),
[email protected]2fb7dc982010-09-29 12:24:28179 testing_prefs_(NULL),
[email protected]5bb2f522011-03-25 19:04:44180 incognito_(false),
[email protected]9819fd02013-08-22 10:49:39181 force_incognito_(false),
[email protected]074311a2013-02-28 23:14:09182 original_profile_(NULL),
[email protected]e9476cd2013-12-04 05:55:34183 guest_session_(false),
[email protected]5cdcd152011-03-31 22:48:52184 last_session_exited_cleanly_(true),
[email protected]f0901a22013-05-27 21:37:53185 browser_context_dependency_manager_(
[email protected]f1484c52013-05-22 23:25:44186 BrowserContextDependencyManager::GetInstance()),
[email protected]37ac95b2013-07-23 23:39:35187 resource_context_(NULL),
[email protected]537c1082011-12-02 02:37:17188 delegate_(NULL) {
[email protected]5c4c89f2012-08-07 21:09:59189 CreateTempProfileDir();
[email protected]49a25632011-08-31 17:03:48190 profile_path_ = temp_dir_.path();
191
192 Init();
[email protected]537c1082011-12-02 02:37:17193 FinishInit();
[email protected]49a25632011-08-31 17:03:48194}
195
[email protected]152ea302013-02-11 04:08:40196TestingProfile::TestingProfile(const base::FilePath& path)
[email protected]49a25632011-08-31 17:03:48197 : start_time_(Time::Now()),
198 testing_prefs_(NULL),
199 incognito_(false),
[email protected]9819fd02013-08-22 10:49:39200 force_incognito_(false),
[email protected]074311a2013-02-28 23:14:09201 original_profile_(NULL),
[email protected]e9476cd2013-12-04 05:55:34202 guest_session_(false),
[email protected]49a25632011-08-31 17:03:48203 last_session_exited_cleanly_(true),
204 profile_path_(path),
[email protected]f0901a22013-05-27 21:37:53205 browser_context_dependency_manager_(
[email protected]f1484c52013-05-22 23:25:44206 BrowserContextDependencyManager::GetInstance()),
[email protected]37ac95b2013-07-23 23:39:35207 resource_context_(NULL),
[email protected]537c1082011-12-02 02:37:17208 delegate_(NULL) {
[email protected]49a25632011-08-31 17:03:48209 Init();
[email protected]537c1082011-12-02 02:37:17210 FinishInit();
211}
212
[email protected]152ea302013-02-11 04:08:40213TestingProfile::TestingProfile(const base::FilePath& path,
[email protected]537c1082011-12-02 02:37:17214 Delegate* delegate)
215 : start_time_(Time::Now()),
216 testing_prefs_(NULL),
217 incognito_(false),
[email protected]9819fd02013-08-22 10:49:39218 force_incognito_(false),
[email protected]074311a2013-02-28 23:14:09219 original_profile_(NULL),
[email protected]e9476cd2013-12-04 05:55:34220 guest_session_(false),
[email protected]537c1082011-12-02 02:37:17221 last_session_exited_cleanly_(true),
222 profile_path_(path),
[email protected]f0901a22013-05-27 21:37:53223 browser_context_dependency_manager_(
[email protected]f1484c52013-05-22 23:25:44224 BrowserContextDependencyManager::GetInstance()),
[email protected]37ac95b2013-07-23 23:39:35225 resource_context_(NULL),
[email protected]537c1082011-12-02 02:37:17226 delegate_(delegate) {
227 Init();
228 if (delegate_) {
[email protected]bb024fe2013-05-10 21:33:26229 base::MessageLoop::current()->PostTask(
230 FROM_HERE,
231 base::Bind(&TestingProfile::FinishInit, base::Unretained(this)));
[email protected]537c1082011-12-02 02:37:17232 } else {
233 FinishInit();
234 }
[email protected]49a25632011-08-31 17:03:48235}
236
[email protected]5c4c89f2012-08-07 21:09:59237TestingProfile::TestingProfile(
[email protected]152ea302013-02-11 04:08:40238 const base::FilePath& path,
[email protected]5c4c89f2012-08-07 21:09:59239 Delegate* delegate,
240 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy,
[email protected]9819fd02013-08-22 10:49:39241 scoped_ptr<PrefServiceSyncable> prefs,
242 bool incognito,
[email protected]e9476cd2013-12-04 05:55:34243 bool guest_session,
[email protected]371662e372013-10-17 22:05:22244 const std::string& managed_user_id,
[email protected]a43b9a82013-11-28 16:56:41245 scoped_ptr<policy::PolicyService> policy_service,
[email protected]9819fd02013-08-22 10:49:39246 const TestingFactories& factories)
[email protected]5c4c89f2012-08-07 21:09:59247 : start_time_(Time::Now()),
248 prefs_(prefs.release()),
249 testing_prefs_(NULL),
[email protected]9819fd02013-08-22 10:49:39250 incognito_(incognito),
251 force_incognito_(false),
[email protected]074311a2013-02-28 23:14:09252 original_profile_(NULL),
[email protected]e9476cd2013-12-04 05:55:34253 guest_session_(guest_session),
[email protected]371662e372013-10-17 22:05:22254 managed_user_id_(managed_user_id),
[email protected]5c4c89f2012-08-07 21:09:59255 last_session_exited_cleanly_(true),
256 extension_special_storage_policy_(extension_policy),
[email protected]5c4c89f2012-08-07 21:09:59257 profile_path_(path),
[email protected]f0901a22013-05-27 21:37:53258 browser_context_dependency_manager_(
[email protected]f1484c52013-05-22 23:25:44259 BrowserContextDependencyManager::GetInstance()),
[email protected]37ac95b2013-07-23 23:39:35260 resource_context_(NULL),
[email protected]a43b9a82013-11-28 16:56:41261 delegate_(delegate),
262 policy_service_(policy_service.release()) {
[email protected]5c4c89f2012-08-07 21:09:59263
264 // If no profile path was supplied, create one.
265 if (profile_path_.empty()) {
266 CreateTempProfileDir();
267 profile_path_ = temp_dir_.path();
268 }
269
[email protected]9819fd02013-08-22 10:49:39270 // Set any testing factories prior to initializing the services.
271 for (TestingFactories::const_iterator it = factories.begin();
272 it != factories.end(); ++it) {
273 it->first->SetTestingFactory(this, it->second);
274 }
275
[email protected]5c4c89f2012-08-07 21:09:59276 Init();
277 // If caller supplied a delegate, delay the FinishInit invocation until other
278 // tasks have run.
279 // TODO(atwilson): See if this is still required once we convert the current
280 // users of the constructor that takes a Delegate* param.
281 if (delegate_) {
[email protected]bb024fe2013-05-10 21:33:26282 base::MessageLoop::current()->PostTask(
283 FROM_HERE,
284 base::Bind(&TestingProfile::FinishInit, base::Unretained(this)));
[email protected]5c4c89f2012-08-07 21:09:59285 } else {
286 FinishInit();
287 }
288}
289
290void TestingProfile::CreateTempProfileDir() {
291 if (!temp_dir_.CreateUniqueTempDir()) {
292 LOG(ERROR) << "Failed to create unique temporary directory.";
293
294 // Fallback logic in case we fail to create unique temporary directory.
[email protected]152ea302013-02-11 04:08:40295 base::FilePath system_tmp_dir;
[email protected]5c4c89f2012-08-07 21:09:59296 bool success = PathService::Get(base::DIR_TEMP, &system_tmp_dir);
297
298 // We're severly screwed if we can't get the system temporary
299 // directory. Die now to avoid writing to the filesystem root
300 // or other bad places.
301 CHECK(success);
302
[email protected]152ea302013-02-11 04:08:40303 base::FilePath fallback_dir(
304 system_tmp_dir.AppendASCII("TestingProfilePath"));
[email protected]dd3aa792013-07-16 19:10:23305 base::DeleteFile(fallback_dir, true);
[email protected]426d1c92013-12-03 20:08:54306 base::CreateDirectory(fallback_dir);
[email protected]5c4c89f2012-08-07 21:09:59307 if (!temp_dir_.Set(fallback_dir)) {
308 // That shouldn't happen, but if it does, try to recover.
309 LOG(ERROR) << "Failed to use a fallback temporary directory.";
310
311 // We're screwed if this fails, see CHECK above.
312 CHECK(temp_dir_.Set(system_tmp_dir));
313 }
314 }
315}
316
[email protected]49a25632011-08-31 17:03:48317void TestingProfile::Init() {
[email protected]bf390cb2013-08-06 02:48:08318 // If threads have been initialized, we should be on the UI thread.
[email protected]33d06242013-08-12 05:20:30319 DCHECK(!content::BrowserThread::IsThreadInitialized(
320 content::BrowserThread::UI) ||
321 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
[email protected]bf390cb2013-08-06 02:48:08322
[email protected]7e75e4a2013-05-17 17:20:03323 // Normally this would happen during browser startup, but for tests
324 // we need to trigger creation of Profile-related services.
325 ChromeBrowserMainExtraPartsProfiles::
[email protected]f1484c52013-05-22 23:25:44326 EnsureBrowserContextKeyedServiceFactoriesBuilt();
[email protected]7e75e4a2013-05-17 17:20:03327
[email protected]75fee372013-03-06 00:42:44328 if (prefs_.get())
[email protected]c7141feb2013-06-11 13:00:16329 user_prefs::UserPrefs::Set(this, prefs_.get());
[email protected]c7fa4362013-04-26 18:09:02330 else
331 CreateTestingPrefService();
[email protected]75fee372013-03-06 00:42:44332
[email protected]7567484142013-07-11 17:36:07333 if (!base::PathExists(profile_path_))
[email protected]426d1c92013-12-03 20:08:54334 base::CreateDirectory(profile_path_);
[email protected]d41e6572012-05-04 20:49:42335
[email protected]d81bb3e2013-05-02 18:17:03336 // TODO(joaodasilva): remove this once this PKS isn't created in ProfileImpl
337 // anymore, after converting the PrefService to a PKS. Until then it must
338 // be associated with a TestingProfile too.
[email protected]eb83c392013-11-07 12:53:24339 if (!IsOffTheRecord())
340 CreateProfilePolicyConnector();
[email protected]d81bb3e2013-05-02 18:17:03341
[email protected]bd306722012-07-11 20:43:59342 extensions::ExtensionSystemFactory::GetInstance()->SetTestingFactory(
343 this, extensions::TestExtensionSystem::Build);
[email protected]31d8f5f22012-04-02 15:22:08344
[email protected]d45c5d52013-12-04 23:41:16345 // If no original profile was specified for this profile: register preferences
346 // even if this is an incognito profile - this allows tests to create a
[email protected]9819fd02013-08-22 10:49:39347 // standalone incognito profile while still having prefs registered.
[email protected]d45c5d52013-12-04 23:41:16348 if (!IsOffTheRecord() || !original_profile_) {
349 user_prefs::PrefRegistrySyncable* pref_registry =
350 static_cast<user_prefs::PrefRegistrySyncable*>(
351 prefs_->DeprecatedGetPrefRegistry());
352 browser_context_dependency_manager_->
353 RegisterProfilePrefsForServices(this, pref_registry);
354 }
355
[email protected]9819fd02013-08-22 10:49:39356 browser_context_dependency_manager_->CreateBrowserContextServicesForTest(
[email protected]d45c5d52013-12-04 23:41:16357 this);
[email protected]49a25632011-08-31 17:03:48358
[email protected]5fd2e842012-03-01 00:29:11359#if defined(ENABLE_NOTIFICATIONS)
[email protected]dcb72d52011-04-13 12:36:53360 // Install profile keyed service factory hooks for dummy/test services
[email protected]7722653b2011-06-03 17:28:22361 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory(
362 this, CreateTestDesktopNotificationService);
[email protected]5fd2e842012-03-01 00:29:11363#endif
[email protected]e1480482013-09-11 11:49:58364
365#if defined(ENABLE_MANAGED_USERS)
366 ManagedUserSettingsService* settings_service =
367 ManagedUserSettingsServiceFactory::GetForProfile(this);
368 TestingPrefStore* store = new TestingPrefStore();
369 settings_service->Init(store);
370 store->SetInitializationCompleted();
371#endif
[email protected]d6001872013-09-24 18:31:26372
373 profile_name_ = "testing_profile";
[email protected]537c1082011-12-02 02:37:17374}
[email protected]12463cd2011-07-19 09:40:20375
[email protected]537c1082011-12-02 02:37:17376void TestingProfile::FinishInit() {
[email protected]080adba92011-12-07 19:00:40377 DCHECK(content::NotificationService::current());
[email protected]ad50def52011-10-19 23:17:07378 content::NotificationService::current()->Notify(
[email protected]12463cd2011-07-19 09:40:20379 chrome::NOTIFICATION_PROFILE_CREATED,
[email protected]6c2381d2011-10-19 02:52:53380 content::Source<Profile>(static_cast<Profile*>(this)),
[email protected]ad50def52011-10-19 23:17:07381 content::NotificationService::NoDetails());
[email protected]537c1082011-12-02 02:37:17382
[email protected]371662e372013-10-17 22:05:22383 ProfileManager* profile_manager = g_browser_process->profile_manager();
384 if (profile_manager)
385 profile_manager->InitProfileUserPrefs(this);
386
[email protected]537c1082011-12-02 02:37:17387 if (delegate_)
[email protected]00b33f802012-03-13 07:46:03388 delegate_->OnProfileCreated(this, true, false);
[email protected]ab23dbe2010-08-12 02:10:46389}
390
[email protected]f25387b2008-08-21 15:20:33391TestingProfile::~TestingProfile() {
[email protected]9819fd02013-08-22 10:49:39392 // Revert to non-incognito mode before shutdown.
393 force_incognito_ = false;
394
[email protected]37ac95b2013-07-23 23:39:35395 // Any objects holding live URLFetchers should be deleted before teardown.
396 TemplateURLFetcherFactory::ShutdownForProfile(this);
397
[email protected]a7c4c032012-07-27 00:36:32398 MaybeSendDestroyedNotification();
[email protected]5cdcd152011-03-31 22:48:52399
[email protected]f0901a22013-05-27 21:37:53400 browser_context_dependency_manager_->DestroyBrowserContextServices(this);
[email protected]5cdcd152011-03-31 22:48:52401
[email protected]5c6ac842013-06-02 23:37:03402 if (host_content_settings_map_.get())
[email protected]35552dc52011-07-12 09:04:38403 host_content_settings_map_->ShutdownOnUIThread();
404
[email protected]809cc4d2010-10-27 15:22:54405 DestroyTopSites();
[email protected]cdba46992011-06-07 11:51:39406
[email protected]cc5bfd42010-11-24 14:44:02407 if (pref_proxy_config_tracker_.get())
408 pref_proxy_config_tracker_->DetachFromPrefService();
[email protected]37ac95b2013-07-23 23:39:35409 // Failing a post == leaks == heapcheck failure. Make that an immediate test
410 // failure.
411 if (resource_context_) {
412 CHECK(BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE,
413 resource_context_));
414 resource_context_ = NULL;
415 content::RunAllPendingInMessageLoop(BrowserThread::IO);
416 }
[email protected]f25387b2008-08-21 15:20:33417}
initial.commit09911bf2008-07-26 23:55:29418
[email protected]540380fc2014-03-14 10:10:34419static KeyedService* BuildFaviconService(content::BrowserContext* profile) {
[email protected]f718290e2013-11-05 07:11:58420 return new FaviconService(static_cast<Profile*>(profile));
[email protected]f3d2b312012-08-23 22:27:59421}
422
[email protected]d2879af2010-02-08 16:02:56423void TestingProfile::CreateFaviconService() {
[email protected]f3d2b312012-08-23 22:27:59424 // It is up to the caller to create the history service if one is needed.
425 FaviconServiceFactory::GetInstance()->SetTestingFactory(
426 this, BuildFaviconService);
[email protected]d2879af2010-02-08 16:02:56427}
428
[email protected]540380fc2014-03-14 10:10:34429static KeyedService* BuildHistoryService(content::BrowserContext* profile) {
[email protected]c7fa4362013-04-26 18:09:02430 return new HistoryService(static_cast<Profile*>(profile));
[email protected]f61f4782012-06-08 21:54:21431}
432
[email protected]608e7e02013-07-24 12:23:31433bool TestingProfile::CreateHistoryService(bool delete_file, bool no_db) {
[email protected]809cc4d2010-10-27 15:22:54434 DestroyHistoryService();
[email protected]f25387b2008-08-21 15:20:33435 if (delete_file) {
[email protected]152ea302013-02-11 04:08:40436 base::FilePath path = GetPath();
[email protected]f7011fcb2009-01-28 21:54:32437 path = path.Append(chrome::kHistoryFilename);
[email protected]608e7e02013-07-24 12:23:31438 if (!base::DeleteFile(path, false) || base::PathExists(path))
439 return false;
[email protected]f25387b2008-08-21 15:20:33440 }
[email protected]7019bb6d2012-08-23 09:09:48441 // This will create and init the history service.
[email protected]f61f4782012-06-08 21:54:21442 HistoryService* history_service = static_cast<HistoryService*>(
443 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse(
[email protected]a5894fe2012-11-01 14:40:56444 this, BuildHistoryService));
[email protected]7019bb6d2012-08-23 09:09:48445 if (!history_service->Init(this->GetPath(),
446 BookmarkModelFactory::GetForProfile(this),
447 no_db)) {
[email protected]f61f4782012-06-08 21:54:21448 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse(this, NULL);
[email protected]7019bb6d2012-08-23 09:09:48449 }
[email protected]a50e16a2013-04-25 14:07:17450 // Disable WebHistoryService by default, since it makes network requests.
451 WebHistoryServiceFactory::GetInstance()->SetTestingFactory(this, NULL);
[email protected]608e7e02013-07-24 12:23:31452 return true;
initial.commit09911bf2008-07-26 23:55:29453}
454
455void TestingProfile::DestroyHistoryService() {
[email protected]a5894fe2012-11-01 14:40:56456 HistoryService* history_service =
[email protected]6c537042012-07-13 00:59:02457 HistoryServiceFactory::GetForProfileWithoutCreating(this);
[email protected]a5894fe2012-11-01 14:40:56458 if (!history_service)
initial.commit09911bf2008-07-26 23:55:29459 return;
460
[email protected]f61f4782012-06-08 21:54:21461 history_service->NotifyRenderProcessHostDestruction(0);
[email protected]bb024fe2013-05-10 21:33:26462 history_service->SetOnBackendDestroyTask(base::MessageLoop::QuitClosure());
[email protected]f61f4782012-06-08 21:54:21463 history_service->Cleanup();
464 HistoryServiceFactory::ShutdownForProfile(this);
initial.commit09911bf2008-07-26 23:55:29465
466 // Wait for the backend class to terminate before deleting the files and
467 // moving to the next test. Note: if this never terminates, somebody is
468 // probably leaking a reference to the history backend, so it never calls
469 // our destroy task.
[email protected]bb024fe2013-05-10 21:33:26470 base::MessageLoop::current()->Run();
initial.commit09911bf2008-07-26 23:55:29471
initial.commit09911bf2008-07-26 23:55:29472 // Make sure we don't have any event pending that could disrupt the next
473 // test.
[email protected]bb024fe2013-05-10 21:33:26474 base::MessageLoop::current()->PostTask(FROM_HERE,
475 base::MessageLoop::QuitClosure());
476 base::MessageLoop::current()->Run();
initial.commit09911bf2008-07-26 23:55:29477}
[email protected]4d0cd7ce2008-08-11 16:40:57478
[email protected]809cc4d2010-10-27 15:22:54479void TestingProfile::CreateTopSites() {
480 DestroyTopSites();
[email protected]9a93d3432013-04-29 20:52:12481 top_sites_ = history::TopSites::Create(
482 this, GetPath().Append(chrome::kTopSitesFilename));
[email protected]809cc4d2010-10-27 15:22:54483}
484
485void TestingProfile::DestroyTopSites() {
486 if (top_sites_.get()) {
487 top_sites_->Shutdown();
488 top_sites_ = NULL;
[email protected]9a93d3432013-04-29 20:52:12489 // TopSitesImpl::Shutdown schedules some tasks (from TopSitesBackend) that
490 // need to be run to properly shutdown. Run all pending tasks now. This is
[email protected]809cc4d2010-10-27 15:22:54491 // normally handled by browser_process shutdown.
[email protected]bb024fe2013-05-10 21:33:26492 if (base::MessageLoop::current())
493 base::MessageLoop::current()->RunUntilIdle();
[email protected]809cc4d2010-10-27 15:22:54494 }
495}
496
[email protected]540380fc2014-03-14 10:10:34497static KeyedService* BuildBookmarkModel(content::BrowserContext* context) {
[email protected]c7fa4362013-04-26 18:09:02498 Profile* profile = static_cast<Profile*>(context);
[email protected]6a848b52014-04-26 22:06:54499 ChromeBookmarkClient* bookmark_client =
500 new ChromeBookmarkClient(profile, false);
501 bookmark_client->model()->Load(
502 profile->GetPrefs(),
503 profile->GetPrefs()->GetString(prefs::kAcceptLanguages),
504 profile->GetPath(),
505 profile->GetIOTaskRunner(),
506 content::BrowserThread::GetMessageLoopProxyForThread(
507 content::BrowserThread::UI));
508 return bookmark_client;
[email protected]f61f4782012-06-08 21:54:21509}
510
[email protected]d8e41ed2008-09-11 15:22:32511void TestingProfile::CreateBookmarkModel(bool delete_file) {
[email protected]90ef13132008-08-27 03:27:46512 if (delete_file) {
[email protected]d4a67d52014-04-12 05:17:03513 base::FilePath path = GetPath().Append(bookmarks::kBookmarksFileName);
[email protected]dd3aa792013-07-16 19:10:23514 base::DeleteFile(path, false);
[email protected]90ef13132008-08-27 03:27:46515 }
[email protected]f61f4782012-06-08 21:54:21516 // This will create a bookmark model.
[email protected]6a848b52014-04-26 22:06:54517 BookmarkModel* bookmark_service =
518 static_cast<ChromeBookmarkClient*>(
519 BookmarkModelFactory::GetInstance()->SetTestingFactoryAndUse(
520 this, BuildBookmarkModel))->model();
[email protected]f61f4782012-06-08 21:54:21521
522 HistoryService* history_service =
[email protected]a5894fe2012-11-01 14:40:56523 HistoryServiceFactory::GetForProfileWithoutCreating(this);
[email protected]f61f4782012-06-08 21:54:21524 if (history_service) {
[email protected]8a39b472013-04-04 17:07:42525 history_service->history_backend_->bookmark_service_ = bookmark_service;
[email protected]f61f4782012-06-08 21:54:21526 history_service->history_backend_->expirer_.bookmark_service_ =
527 bookmark_service;
[email protected]90ef13132008-08-27 03:27:46528 }
[email protected]4d0cd7ce2008-08-11 16:40:57529}
[email protected]d2c017a2008-08-13 21:51:45530
[email protected]540380fc2014-03-14 10:10:34531static KeyedService* BuildWebDataService(content::BrowserContext* profile) {
[email protected]c7fa4362013-04-26 18:09:02532 return new WebDataServiceWrapper(static_cast<Profile*>(profile));
[email protected]d07edd42012-05-14 23:49:46533}
[email protected]2609bc12010-01-24 08:32:55534
[email protected]d07edd42012-05-14 23:49:46535void TestingProfile::CreateWebDataService() {
[email protected]a5c65292012-05-25 00:50:01536 WebDataServiceFactory::GetInstance()->SetTestingFactory(
[email protected]d07edd42012-05-14 23:49:46537 this, BuildWebDataService);
[email protected]2609bc12010-01-24 08:32:55538}
539
[email protected]18a15ca82012-08-30 00:28:16540void TestingProfile::BlockUntilHistoryIndexIsRefreshed() {
541 // Only get the history service if it actually exists since the caller of the
542 // test should explicitly call CreateHistoryService to build it.
543 HistoryService* history_service =
544 HistoryServiceFactory::GetForProfileWithoutCreating(this);
545 DCHECK(history_service);
546 history::InMemoryURLIndex* index = history_service->InMemoryIndex();
547 if (!index || index->restored())
548 return;
549 base::RunLoop run_loop;
550 HistoryIndexRestoreObserver observer(
551 content::GetQuitTaskForRunLoop(&run_loop));
552 index->set_restore_cache_observer(&observer);
553 run_loop.Run();
554 index->set_restore_cache_observer(NULL);
555 DCHECK(index->restored());
556}
557
[email protected]120abf132011-09-27 21:38:06558// TODO(phajdan.jr): Doesn't this hang if Top Sites are already loaded?
[email protected]809cc4d2010-10-27 15:22:54559void TestingProfile::BlockUntilTopSitesLoaded() {
[email protected]a7fe9112012-07-20 02:34:45560 content::WindowedNotificationObserver top_sites_loaded_observer(
[email protected]120abf132011-09-27 21:38:06561 chrome::NOTIFICATION_TOP_SITES_LOADED,
[email protected]ad50def52011-10-19 23:17:07562 content::NotificationService::AllSources());
[email protected]120abf132011-09-27 21:38:06563 top_sites_loaded_observer.Wait();
[email protected]809cc4d2010-10-27 15:22:54564}
565
[email protected]90efc3e2014-04-22 18:39:03566void TestingProfile::SetGuestSession(bool guest) {
567 guest_session_ = guest;
568}
569
[email protected]4251165a2013-07-17 04:33:40570base::FilePath TestingProfile::GetPath() const {
[email protected]49a25632011-08-31 17:03:48571 return profile_path_;
[email protected]f9dec9482010-08-20 20:42:19572}
573
[email protected]0de615a2012-11-08 04:40:59574scoped_refptr<base::SequencedTaskRunner> TestingProfile::GetIOTaskRunner() {
[email protected]bb024fe2013-05-10 21:33:26575 return base::MessageLoop::current()->message_loop_proxy();
[email protected]0de615a2012-11-08 04:40:59576}
577
[email protected]5b199522012-12-22 17:24:44578TestingPrefServiceSyncable* TestingProfile::GetTestingPrefService() {
[email protected]2fb7dc982010-09-29 12:24:28579 if (!prefs_.get())
580 CreateTestingPrefService();
581 DCHECK(testing_prefs_);
582 return testing_prefs_;
[email protected]dbbad7a2010-08-13 18:18:36583}
584
[email protected]8e5c89a2011-06-07 18:13:33585TestingProfile* TestingProfile::AsTestingProfile() {
586 return this;
587}
588
[email protected]29d70252011-04-28 02:16:58589std::string TestingProfile::GetProfileName() {
[email protected]d6001872013-09-24 18:31:26590 return profile_name_;
[email protected]29d70252011-04-28 02:16:58591}
592
[email protected]7b7e0b32014-03-17 16:09:23593Profile::ProfileType TestingProfile::GetProfileType() const {
594 if (guest_session_)
595 return GUEST_PROFILE;
596 if (force_incognito_ || incognito_)
597 return INCOGNITO_PROFILE;
598 return REGULAR_PROFILE;
599}
600
[email protected]27d6e852012-03-02 21:31:32601bool TestingProfile::IsOffTheRecord() const {
[email protected]9819fd02013-08-22 10:49:39602 return force_incognito_ || incognito_;
[email protected]fadc607b62011-02-07 17:55:50603}
604
[email protected]9819fd02013-08-22 10:49:39605void TestingProfile::SetOffTheRecordProfile(scoped_ptr<Profile> profile) {
606 DCHECK(!IsOffTheRecord());
607 incognito_profile_ = profile.Pass();
[email protected]93dba942011-02-23 22:45:01608}
609
[email protected]074311a2013-02-28 23:14:09610void TestingProfile::SetOriginalProfile(Profile* profile) {
[email protected]9819fd02013-08-22 10:49:39611 DCHECK(IsOffTheRecord());
[email protected]074311a2013-02-28 23:14:09612 original_profile_ = profile;
613}
614
[email protected]fadc607b62011-02-07 17:55:50615Profile* TestingProfile::GetOffTheRecordProfile() {
[email protected]9819fd02013-08-22 10:49:39616 if (IsOffTheRecord())
617 return this;
[email protected]cbed02ae2014-03-07 17:16:26618 if (!incognito_profile_) {
619 TestingProfile::Builder builder;
620 builder.SetIncognito();
621 scoped_ptr<TestingProfile> incognito_test_profile(builder.Build());
622 incognito_test_profile->SetOriginalProfile(this);
623 SetOffTheRecordProfile(incognito_test_profile.PassAs<Profile>());
624 }
[email protected]5bb2f522011-03-25 19:04:44625 return incognito_profile_.get();
[email protected]fadc607b62011-02-07 17:55:50626}
627
628bool TestingProfile::HasOffTheRecordProfile() {
[email protected]5bb2f522011-03-25 19:04:44629 return incognito_profile_.get() != NULL;
[email protected]fadc607b62011-02-07 17:55:50630}
631
632Profile* TestingProfile::GetOriginalProfile() {
[email protected]074311a2013-02-28 23:14:09633 if (original_profile_)
634 return original_profile_;
[email protected]fadc607b62011-02-07 17:55:50635 return this;
636}
637
[email protected]e000daf2013-07-31 16:50:58638bool TestingProfile::IsManaged() {
[email protected]371662e372013-10-17 22:05:22639 return !managed_user_id_.empty();
[email protected]e000daf2013-07-31 16:50:58640}
641
[email protected]eaa7dd182010-12-14 11:09:00642ExtensionService* TestingProfile::GetExtensionService() {
[email protected]bd306722012-07-11 20:43:59643 return extensions::ExtensionSystem::Get(this)->extension_service();
[email protected]2fb7dc982010-09-29 12:24:28644}
645
[email protected]2261e7b72011-07-12 13:43:55646void TestingProfile::SetExtensionSpecialStoragePolicy(
647 ExtensionSpecialStoragePolicy* extension_special_storage_policy) {
648 extension_special_storage_policy_ = extension_special_storage_policy;
649}
650
[email protected]19eb80152011-02-26 00:28:43651ExtensionSpecialStoragePolicy*
652TestingProfile::GetExtensionSpecialStoragePolicy() {
[email protected]cdba46992011-06-07 11:51:39653 if (!extension_special_storage_policy_.get())
[email protected]7c5048c2011-08-19 17:07:05654 extension_special_storage_policy_ = new ExtensionSpecialStoragePolicy(NULL);
[email protected]cdba46992011-06-07 11:51:39655 return extension_special_storage_policy_.get();
[email protected]19eb80152011-02-26 00:28:43656}
657
[email protected]33ad6ce92013-08-27 14:39:08658net::CookieMonster* TestingProfile::GetCookieMonster() {
659 if (!GetRequestContext())
660 return NULL;
661 return GetRequestContext()->GetURLRequestContext()->cookie_store()->
662 GetCookieMonster();
663}
664
[email protected]2fb7dc982010-09-29 12:24:28665void TestingProfile::CreateTestingPrefService() {
666 DCHECK(!prefs_.get());
[email protected]5b199522012-12-22 17:24:44667 testing_prefs_ = new TestingPrefServiceSyncable();
[email protected]2fb7dc982010-09-29 12:24:28668 prefs_.reset(testing_prefs_);
[email protected]c7141feb2013-06-11 13:00:16669 user_prefs::UserPrefs::Set(this, prefs_.get());
[email protected]37ca3fe02013-07-05 15:32:44670 chrome::RegisterUserProfilePrefs(testing_prefs_->registry());
[email protected]2fb7dc982010-09-29 12:24:28671}
672
[email protected]d81bb3e2013-05-02 18:17:03673void TestingProfile::CreateProfilePolicyConnector() {
[email protected]d81bb3e2013-05-02 18:17:03674#if defined(ENABLE_CONFIGURATION_POLICY)
[email protected]eb83c392013-11-07 12:53:24675 schema_registry_service_ =
676 policy::SchemaRegistryServiceFactory::CreateForContext(
677 this, policy::Schema(), NULL);
678 CHECK_EQ(schema_registry_service_.get(),
679 policy::SchemaRegistryServiceFactory::GetForContext(this));
[email protected]a43b9a82013-11-28 16:56:41680#endif // defined(ENABLE_CONFIGURATION_POLICY)
[email protected]eb83c392013-11-07 12:53:24681
[email protected]a43b9a82013-11-28 16:56:41682if (!policy_service_) {
683#if defined(ENABLE_CONFIGURATION_POLICY)
684 std::vector<policy::ConfigurationPolicyProvider*> providers;
[email protected]33528402013-12-16 18:38:32685 policy_service_.reset(new policy::PolicyServiceImpl(providers));
[email protected]d81bb3e2013-05-02 18:17:03686#else
[email protected]a43b9a82013-11-28 16:56:41687 policy_service_.reset(new policy::PolicyServiceStub());
[email protected]d81bb3e2013-05-02 18:17:03688#endif
[email protected]a43b9a82013-11-28 16:56:41689 }
[email protected]24a9f1c92013-11-13 12:33:37690 profile_policy_connector_.reset(new policy::ProfilePolicyConnector());
[email protected]a43b9a82013-11-28 16:56:41691 profile_policy_connector_->InitForTesting(policy_service_.Pass());
[email protected]d81bb3e2013-05-02 18:17:03692 policy::ProfilePolicyConnectorFactory::GetInstance()->SetServiceForTesting(
693 this, profile_policy_connector_.get());
694 CHECK_EQ(profile_policy_connector_.get(),
695 policy::ProfilePolicyConnectorFactory::GetForProfile(this));
696}
697
[email protected]c753f142013-02-10 13:14:04698PrefService* TestingProfile::GetPrefs() {
[email protected]dbbad7a2010-08-13 18:18:36699 if (!prefs_.get()) {
[email protected]2fb7dc982010-09-29 12:24:28700 CreateTestingPrefService();
[email protected]dbbad7a2010-08-13 18:18:36701 }
702 return prefs_.get();
703}
704
705history::TopSites* TestingProfile::GetTopSites() {
[email protected]809cc4d2010-10-27 15:22:54706 return top_sites_.get();
[email protected]dbbad7a2010-08-13 18:18:36707}
708
[email protected]fadc607b62011-02-07 17:55:50709history::TopSites* TestingProfile::GetTopSitesWithoutCreating() {
710 return top_sites_.get();
711}
712
[email protected]b441a8492012-06-06 14:55:57713DownloadManagerDelegate* TestingProfile::GetDownloadManagerDelegate() {
[email protected]fadc607b62011-02-07 17:55:50714 return NULL;
715}
716
[email protected]abe2c032011-03-31 18:49:34717net::URLRequestContextGetter* TestingProfile::GetRequestContext() {
[email protected]37ac95b2013-07-23 23:39:35718 return GetDefaultStoragePartition(this)->GetURLRequestContext();
[email protected]812b3a32010-01-08 05:36:04719}
720
[email protected]6bd30072013-02-08 18:17:11721net::URLRequestContextGetter* TestingProfile::CreateRequestContext(
[email protected]7571263c2014-03-10 22:57:09722 content::ProtocolHandlerMap* protocol_handlers,
723 content::ProtocolHandlerScopedVector protocol_interceptors) {
[email protected]37ac95b2013-07-23 23:39:35724 return new net::TestURLRequestContextGetter(
725 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
[email protected]6bd30072013-02-08 18:17:11726}
727
[email protected]da5683db2011-04-23 17:12:21728net::URLRequestContextGetter* TestingProfile::GetRequestContextForRenderProcess(
729 int renderer_child_id) {
[email protected]fb29e6cf2012-07-12 21:27:20730 content::RenderProcessHost* rph = content::RenderProcessHost::FromID(
731 renderer_child_id);
[email protected]1bc28312012-11-08 08:31:53732 return rph->GetStoragePartition()->GetURLRequestContext();
[email protected]d9696672011-03-15 22:45:09733}
734
[email protected]10705a7b2012-08-21 19:07:08735net::URLRequestContextGetter* TestingProfile::GetMediaRequestContext() {
736 return NULL;
737}
738
739net::URLRequestContextGetter*
740TestingProfile::GetMediaRequestContextForRenderProcess(
741 int renderer_child_id) {
[email protected]fadc607b62011-02-07 17:55:50742 return NULL;
743}
744
[email protected]10eb28162012-09-18 03:04:09745net::URLRequestContextGetter*
746TestingProfile::GetMediaRequestContextForStoragePartition(
[email protected]152ea302013-02-11 04:08:40747 const base::FilePath& partition_path,
[email protected]27ddfed22012-10-30 23:22:43748 bool in_memory) {
[email protected]10eb28162012-09-18 03:04:09749 return NULL;
750}
751
[email protected]6e068ea2014-02-04 07:05:47752void TestingProfile::RequestMidiSysExPermission(
[email protected]8aca7252013-07-12 19:18:59753 int render_process_id,
754 int render_view_id,
[email protected]00880a02013-10-30 03:18:30755 int bridge_id,
[email protected]8aca7252013-07-12 19:18:59756 const GURL& requesting_frame,
[email protected]7c6d9482014-03-28 20:19:31757 bool user_gesture,
[email protected]6e068ea2014-02-04 07:05:47758 const MidiSysExPermissionCallback& callback) {
[email protected]8aca7252013-07-12 19:18:59759 // Always reject requests for testing.
760 callback.Run(false);
761}
762
[email protected]6e068ea2014-02-04 07:05:47763void TestingProfile::CancelMidiSysExPermissionRequest(
[email protected]00880a02013-10-30 03:18:30764 int render_process_id,
765 int render_view_id,
766 int bridge_id,
767 const GURL& requesting_frame) {
768}
769
[email protected]566755f82014-01-08 01:14:57770void TestingProfile::RequestProtectedMediaIdentifierPermission(
771 int render_process_id,
772 int render_view_id,
773 int bridge_id,
774 int group_id,
775 const GURL& requesting_frame,
776 const ProtectedMediaIdentifierPermissionCallback& callback) {
777 // Always reject requests for testing.
778 callback.Run(false);
779}
780
781void TestingProfile::CancelProtectedMediaIdentifierPermissionRequests(
782 int group_id) {
783}
784
[email protected]33ad6ce92013-08-27 14:39:08785net::URLRequestContextGetter* TestingProfile::GetRequestContextForExtensions() {
786 if (!extensions_request_context_.get())
787 extensions_request_context_ = new TestExtensionURLRequestContextGetter();
788 return extensions_request_context_.get();
789}
790
[email protected]fadc607b62011-02-07 17:55:50791net::SSLConfigService* TestingProfile::GetSSLConfigService() {
[email protected]dc6655b2012-12-14 05:58:24792 if (!GetRequestContext())
793 return NULL;
794 return GetRequestContext()->GetURLRequestContext()->ssl_config_service();
[email protected]fadc607b62011-02-07 17:55:50795}
796
[email protected]10eb28162012-09-18 03:04:09797net::URLRequestContextGetter*
[email protected]6bd30072013-02-08 18:17:11798TestingProfile::CreateRequestContextForStoragePartition(
[email protected]152ea302013-02-11 04:08:40799 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:11800 bool in_memory,
[email protected]7571263c2014-03-10 22:57:09801 content::ProtocolHandlerMap* protocol_handlers,
802 content::ProtocolHandlerScopedVector protocol_interceptors) {
[email protected]10eb28162012-09-18 03:04:09803 // We don't test storage partitions here yet, so returning the same dummy
[email protected]d9696672011-03-15 22:45:09804 // context is sufficient for now.
805 return GetRequestContext();
806}
807
[email protected]df02aca2012-02-09 21:03:20808content::ResourceContext* TestingProfile::GetResourceContext() {
[email protected]37ac95b2013-07-23 23:39:35809 if (!resource_context_)
810 resource_context_ = new content::MockResourceContext();
811 return resource_context_;
[email protected]e89b77d2011-04-15 18:58:10812}
813
[email protected]dbbad7a2010-08-13 18:18:36814HostContentSettingsMap* TestingProfile::GetHostContentSettingsMap() {
[email protected]35552dc52011-07-12 09:04:38815 if (!host_content_settings_map_.get()) {
[email protected]646c29cb62012-06-18 14:31:05816 host_content_settings_map_ = new HostContentSettingsMap(GetPrefs(), false);
[email protected]701550ad2012-09-06 23:43:29817#if defined(ENABLE_EXTENSIONS)
[email protected]646c29cb62012-06-18 14:31:05818 ExtensionService* extension_service = GetExtensionService();
819 if (extension_service)
820 host_content_settings_map_->RegisterExtensionService(extension_service);
[email protected]701550ad2012-09-06 23:43:29821#endif
[email protected]35552dc52011-07-12 09:04:38822 }
[email protected]dbbad7a2010-08-13 18:18:36823 return host_content_settings_map_.get();
824}
825
[email protected]810ddc52012-01-24 01:00:35826content::GeolocationPermissionContext*
[email protected]dbbad7a2010-08-13 18:18:36827TestingProfile::GetGeolocationPermissionContext() {
[email protected]a877a7d2013-01-08 13:40:59828 return ChromeGeolocationPermissionContextFactory::GetForProfile(this);
[email protected]dbbad7a2010-08-13 18:18:36829}
830
[email protected]24569262014-05-06 03:31:30831content::BrowserPluginGuestManagerDelegate*
832 TestingProfile::GetGuestManagerDelegate() {
833 return GuestViewManager::FromBrowserContext(this);
834}
835
[email protected]fadc607b62011-02-07 17:55:50836std::wstring TestingProfile::GetName() {
837 return std::wstring();
838}
839
840std::wstring TestingProfile::GetID() {
841 return id_;
842}
843
844void TestingProfile::SetID(const std::wstring& id) {
845 id_ = id;
846}
847
[email protected]fadc607b62011-02-07 17:55:50848bool TestingProfile::IsSameProfile(Profile *p) {
849 return this == p;
850}
851
852base::Time TestingProfile::GetStartTime() const {
853 return start_time_;
854}
855
[email protected]152ea302013-02-11 04:08:40856base::FilePath TestingProfile::last_selected_directory() {
[email protected]fadc607b62011-02-07 17:55:50857 return last_selected_directory_;
858}
859
[email protected]152ea302013-02-11 04:08:40860void TestingProfile::set_last_selected_directory(const base::FilePath& path) {
[email protected]fadc607b62011-02-07 17:55:50861 last_selected_directory_ = path;
862}
863
[email protected]cc5bfd42010-11-24 14:44:02864PrefProxyConfigTracker* TestingProfile::GetProxyConfigTracker() {
[email protected]6f96cbcb2011-11-04 02:26:07865 if (!pref_proxy_config_tracker_.get()) {
[email protected]e2930d0902013-07-17 05:25:42866 // TestingProfile is used in unit tests, where local state is not available.
[email protected]6f96cbcb2011-11-04 02:26:07867 pref_proxy_config_tracker_.reset(
[email protected]e2930d0902013-07-17 05:25:42868 ProxyServiceFactory::CreatePrefProxyConfigTrackerOfProfile(GetPrefs(),
869 NULL));
[email protected]6f96cbcb2011-11-04 02:26:07870 }
871 return pref_proxy_config_tracker_.get();
[email protected]cc5bfd42010-11-24 14:44:02872}
873
[email protected]0bfc29a2009-04-27 16:15:44874void TestingProfile::BlockUntilHistoryProcessesPendingRequests() {
[email protected]a5894fe2012-11-01 14:40:56875 HistoryService* history_service =
[email protected]6c537042012-07-13 00:59:02876 HistoryServiceFactory::GetForProfile(this, Profile::EXPLICIT_ACCESS);
[email protected]a5894fe2012-11-01 14:40:56877 DCHECK(history_service);
[email protected]bb024fe2013-05-10 21:33:26878 DCHECK(base::MessageLoop::current());
[email protected]0bfc29a2009-04-27 16:15:44879
880 CancelableRequestConsumer consumer;
[email protected]f61f4782012-06-08 21:54:21881 history_service->ScheduleDBTask(new QuittingHistoryDBTask(), &consumer);
[email protected]bb024fe2013-05-10 21:33:26882 base::MessageLoop::current()->Run();
[email protected]0bfc29a2009-04-27 16:15:44883}
[email protected]345a8b72009-09-29 09:11:44884
[email protected]8382d8c2011-09-15 03:43:17885chrome_browser_net::Predictor* TestingProfile::GetNetworkPredictor() {
886 return NULL;
887}
888
[email protected]e0e1fc22012-11-05 20:25:36889void TestingProfile::ClearNetworkingHistorySince(
890 base::Time time,
891 const base::Closure& completion) {
892 if (!completion.is_null()) {
893 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, completion);
894 }
[email protected]02896a82011-09-21 18:54:32895}
896
[email protected]671f9c62011-10-28 19:22:07897GURL TestingProfile::GetHomePage() {
898 return GURL(chrome::kChromeUINewTabURL);
899}
900
[email protected]c753f142013-02-10 13:14:04901PrefService* TestingProfile::GetOffTheRecordPrefs() {
[email protected]fadc607b62011-02-07 17:55:50902 return NULL;
903}
904
[email protected]36fb2c7c2011-04-04 15:49:08905quota::SpecialStoragePolicy* TestingProfile::GetSpecialStoragePolicy() {
906 return GetExtensionSpecialStoragePolicy();
907}
908
[email protected]1bee6ed2012-03-14 06:46:36909bool TestingProfile::WasCreatedByVersionOrLater(const std::string& version) {
910 return true;
911}
[email protected]ef92e172012-04-25 19:40:41912
[email protected]4251165a2013-07-17 04:33:40913bool TestingProfile::IsGuestSession() const {
[email protected]e9476cd2013-12-04 05:55:34914 return guest_session_;
[email protected]4251165a2013-07-17 04:33:40915}
[email protected]1101dbc52013-10-05 00:19:12916
[email protected]6c0ca7fc2012-10-05 16:27:22917Profile::ExitType TestingProfile::GetLastSessionExitType() {
918 return last_session_exited_cleanly_ ? EXIT_NORMAL : EXIT_CRASHED;
[email protected]2ca1ea662012-10-04 02:26:36919}
920
[email protected]5c4c89f2012-08-07 21:09:59921TestingProfile::Builder::Builder()
922 : build_called_(false),
[email protected]9819fd02013-08-22 10:49:39923 delegate_(NULL),
[email protected]e9476cd2013-12-04 05:55:34924 incognito_(false),
925 guest_session_(false) {
[email protected]5c4c89f2012-08-07 21:09:59926}
927
928TestingProfile::Builder::~Builder() {
929}
930
[email protected]152ea302013-02-11 04:08:40931void TestingProfile::Builder::SetPath(const base::FilePath& path) {
[email protected]5c4c89f2012-08-07 21:09:59932 path_ = path;
933}
934
935void TestingProfile::Builder::SetDelegate(Delegate* delegate) {
936 delegate_ = delegate;
937}
938
939void TestingProfile::Builder::SetExtensionSpecialStoragePolicy(
940 scoped_refptr<ExtensionSpecialStoragePolicy> policy) {
941 extension_policy_ = policy;
942}
943
[email protected]5b199522012-12-22 17:24:44944void TestingProfile::Builder::SetPrefService(
945 scoped_ptr<PrefServiceSyncable> prefs) {
[email protected]5c4c89f2012-08-07 21:09:59946 pref_service_ = prefs.Pass();
947}
948
[email protected]9819fd02013-08-22 10:49:39949void TestingProfile::Builder::SetIncognito() {
950 incognito_ = true;
951}
952
[email protected]e9476cd2013-12-04 05:55:34953void TestingProfile::Builder::SetGuestSession() {
954 guest_session_ = true;
955}
956
[email protected]371662e372013-10-17 22:05:22957void TestingProfile::Builder::SetManagedUserId(
958 const std::string& managed_user_id) {
959 managed_user_id_ = managed_user_id;
960}
961
[email protected]a43b9a82013-11-28 16:56:41962void TestingProfile::Builder::SetPolicyService(
963 scoped_ptr<policy::PolicyService> policy_service) {
964 policy_service_ = policy_service.Pass();
965}
966
[email protected]9819fd02013-08-22 10:49:39967void TestingProfile::Builder::AddTestingFactory(
968 BrowserContextKeyedServiceFactory* service_factory,
[email protected]d45c5d52013-12-04 23:41:16969 BrowserContextKeyedServiceFactory::TestingFactoryFunction callback) {
[email protected]9819fd02013-08-22 10:49:39970 testing_factories_.push_back(std::make_pair(service_factory, callback));
971}
972
[email protected]5c4c89f2012-08-07 21:09:59973scoped_ptr<TestingProfile> TestingProfile::Builder::Build() {
974 DCHECK(!build_called_);
975 build_called_ = true;
[email protected]371662e372013-10-17 22:05:22976
[email protected]5c4c89f2012-08-07 21:09:59977 return scoped_ptr<TestingProfile>(new TestingProfile(
978 path_,
979 delegate_,
980 extension_policy_,
[email protected]9819fd02013-08-22 10:49:39981 pref_service_.Pass(),
982 incognito_,
[email protected]e9476cd2013-12-04 05:55:34983 guest_session_,
[email protected]371662e372013-10-17 22:05:22984 managed_user_id_,
[email protected]a43b9a82013-11-28 16:56:41985 policy_service_.Pass(),
[email protected]9819fd02013-08-22 10:49:39986 testing_factories_));
[email protected]5c4c89f2012-08-07 21:09:59987}