blob: 8d0158ae8f5bcbb80bb7f31708125718d1ad36aa [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]0b0e8a12014-06-14 00:11:3120#include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h"
[email protected]1459fb62011-05-25 19:03:2721#include "chrome/browser/browser_process.h"
[email protected]81d49782013-07-12 01:50:5222#include "chrome/browser/chrome_notification_types.h"
[email protected]9d01a6a2010-11-30 12:03:3323#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]2f69b382011-02-19 00:34:2524#include "chrome/browser/extensions/extension_service.h"
[email protected]19eb80152011-02-26 00:28:4325#include "chrome/browser/extensions/extension_special_storage_policy.h"
[email protected]31d8f5f22012-04-02 15:22:0826#include "chrome/browser/extensions/extension_system_factory.h"
27#include "chrome/browser/extensions/test_extension_system.h"
[email protected]ee2ed42c2011-04-28 22:19:1428#include "chrome/browser/favicon/favicon_service.h"
[email protected]f3d2b312012-08-23 22:27:5929#include "chrome/browser/favicon/favicon_service_factory.h"
[email protected]ad34610c2014-06-04 14:43:5230#include "chrome/browser/history/chrome_history_client.h"
31#include "chrome/browser/history/chrome_history_client_factory.h"
[email protected]075ae732009-02-11 23:58:3132#include "chrome/browser/history/history_backend.h"
[email protected]d891f522013-02-08 03:24:4133#include "chrome/browser/history/history_db_task.h"
[email protected]6a2c09f2013-01-25 04:50:0734#include "chrome/browser/history/history_service.h"
[email protected]f61f4782012-06-08 21:54:2135#include "chrome/browser/history/history_service_factory.h"
[email protected]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]a90c8ca2014-05-20 17:16:0460#include "components/bookmarks/browser/bookmark_model.h"
61#include "components/bookmarks/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]1df3d972014-06-11 04:55:1890#if defined(ENABLE_EXTENSIONS)
91#include "chrome/browser/guest_view/guest_view_manager.h"
92#endif
93
[email protected]bd3093c2014-06-13 07:38:1694#if defined(OS_ANDROID)
95#include "chrome/browser/signin/android_profile_oauth2_token_service.h"
96#endif
97
[email protected]e1480482013-09-11 11:49:5898#if defined(ENABLE_MANAGED_USERS)
99#include "chrome/browser/managed_mode/managed_user_settings_service.h"
100#include "chrome/browser/managed_mode/managed_user_settings_service_factory.h"
101#endif
102
[email protected]e1acf6f2008-10-27 20:43:33103using base::Time;
[email protected]631bb742011-11-02 11:29:39104using content::BrowserThread;
[email protected]b441a8492012-06-06 14:55:57105using content::DownloadManagerDelegate;
[email protected]3c887412010-04-19 20:30:23106using testing::NiceMock;
[email protected]4772b072010-03-30 17:45:46107using testing::Return;
[email protected]e1acf6f2008-10-27 20:43:33108
[email protected]d364c652008-08-29 19:46:56109namespace {
110
[email protected]0bfc29a2009-04-27 16:15:44111// Task used to make sure history has finished processing a request. Intended
112// for use with BlockUntilHistoryProcessesPendingRequests.
113
[email protected]d891f522013-02-08 03:24:41114class QuittingHistoryDBTask : public history::HistoryDBTask {
[email protected]0bfc29a2009-04-27 16:15:44115 public:
116 QuittingHistoryDBTask() {}
117
118 virtual bool RunOnDBThread(history::HistoryBackend* backend,
[email protected]be9826e62013-02-07 02:00:58119 history::HistoryDatabase* db) OVERRIDE {
[email protected]0bfc29a2009-04-27 16:15:44120 return true;
121 }
122
[email protected]be9826e62013-02-07 02:00:58123 virtual void DoneRunOnMainThread() OVERRIDE {
[email protected]bb024fe2013-05-10 21:33:26124 base::MessageLoop::current()->Quit();
[email protected]0bfc29a2009-04-27 16:15:44125 }
126
127 private:
[email protected]be9826e62013-02-07 02:00:58128 virtual ~QuittingHistoryDBTask() {}
[email protected]7991a232009-11-06 01:55:48129
[email protected]0bfc29a2009-04-27 16:15:44130 DISALLOW_COPY_AND_ASSIGN(QuittingHistoryDBTask);
131};
132
[email protected]33ad6ce92013-08-27 14:39:08133class TestExtensionURLRequestContext : public net::URLRequestContext {
134 public:
135 TestExtensionURLRequestContext() {
[email protected]7c4b66b2014-01-04 12:28:13136 net::CookieMonster* cookie_monster =
[email protected]9a6c2aa2014-01-11 22:39:39137 content::CreateCookieStore(content::CookieStoreConfig())->
138 GetCookieMonster();
[email protected]33ad6ce92013-08-27 14:39:08139 const char* schemes[] = {extensions::kExtensionScheme};
140 cookie_monster->SetCookieableSchemes(schemes, 1);
141 set_cookie_store(cookie_monster);
142 }
143
144 virtual ~TestExtensionURLRequestContext() {}
145};
146
147class TestExtensionURLRequestContextGetter
148 : public net::URLRequestContextGetter {
149 public:
150 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE {
151 if (!context_.get())
152 context_.reset(new TestExtensionURLRequestContext());
153 return context_.get();
154 }
155 virtual scoped_refptr<base::SingleThreadTaskRunner>
156 GetNetworkTaskRunner() const OVERRIDE {
157 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
158 }
159
160 protected:
161 virtual ~TestExtensionURLRequestContextGetter() {}
162
163 private:
164 scoped_ptr<net::URLRequestContext> context_;
165};
166
[email protected]1d51882f2013-11-12 01:59:02167#if defined(ENABLE_NOTIFICATIONS)
[email protected]540380fc2014-03-14 10:10:34168KeyedService* CreateTestDesktopNotificationService(
[email protected]c7fa4362013-04-26 18:09:02169 content::BrowserContext* profile) {
[email protected]c7fa4362013-04-26 18:09:02170 return new DesktopNotificationService(static_cast<Profile*>(profile), NULL);
[email protected]dcb72d52011-04-13 12:36:53171}
[email protected]1d51882f2013-11-12 01:59:02172#endif
[email protected]dcb72d52011-04-13 12:36:53173
[email protected]d364c652008-08-29 19:46:56174} // namespace
175
[email protected]89dbb1772012-07-17 13:47:25176// static
177#if defined(OS_CHROMEOS)
178// Must be kept in sync with
179// ChromeBrowserMainPartsChromeos::PreEarlyInitialization.
[email protected]0f13fe8d2013-11-19 08:25:00180const char TestingProfile::kTestUserProfileDir[] = "test-user";
[email protected]89dbb1772012-07-17 13:47:25181#else
182const char TestingProfile::kTestUserProfileDir[] = "Default";
183#endif
184
[email protected]f25387b2008-08-21 15:20:33185TestingProfile::TestingProfile()
[email protected]ea6f76572008-12-18 00:09:55186 : start_time_(Time::Now()),
[email protected]2fb7dc982010-09-29 12:24:28187 testing_prefs_(NULL),
[email protected]5bb2f522011-03-25 19:04:44188 incognito_(false),
[email protected]9819fd02013-08-22 10:49:39189 force_incognito_(false),
[email protected]074311a2013-02-28 23:14:09190 original_profile_(NULL),
[email protected]e9476cd2013-12-04 05:55:34191 guest_session_(false),
[email protected]5cdcd152011-03-31 22:48:52192 last_session_exited_cleanly_(true),
[email protected]f0901a22013-05-27 21:37:53193 browser_context_dependency_manager_(
[email protected]f1484c52013-05-22 23:25:44194 BrowserContextDependencyManager::GetInstance()),
[email protected]37ac95b2013-07-23 23:39:35195 resource_context_(NULL),
[email protected]537c1082011-12-02 02:37:17196 delegate_(NULL) {
[email protected]5c4c89f2012-08-07 21:09:59197 CreateTempProfileDir();
[email protected]49a25632011-08-31 17:03:48198 profile_path_ = temp_dir_.path();
199
200 Init();
[email protected]537c1082011-12-02 02:37:17201 FinishInit();
[email protected]49a25632011-08-31 17:03:48202}
203
[email protected]152ea302013-02-11 04:08:40204TestingProfile::TestingProfile(const base::FilePath& path)
[email protected]49a25632011-08-31 17:03:48205 : start_time_(Time::Now()),
206 testing_prefs_(NULL),
207 incognito_(false),
[email protected]9819fd02013-08-22 10:49:39208 force_incognito_(false),
[email protected]074311a2013-02-28 23:14:09209 original_profile_(NULL),
[email protected]e9476cd2013-12-04 05:55:34210 guest_session_(false),
[email protected]49a25632011-08-31 17:03:48211 last_session_exited_cleanly_(true),
212 profile_path_(path),
[email protected]f0901a22013-05-27 21:37:53213 browser_context_dependency_manager_(
[email protected]f1484c52013-05-22 23:25:44214 BrowserContextDependencyManager::GetInstance()),
[email protected]37ac95b2013-07-23 23:39:35215 resource_context_(NULL),
[email protected]537c1082011-12-02 02:37:17216 delegate_(NULL) {
[email protected]49a25632011-08-31 17:03:48217 Init();
[email protected]537c1082011-12-02 02:37:17218 FinishInit();
219}
220
[email protected]152ea302013-02-11 04:08:40221TestingProfile::TestingProfile(const base::FilePath& path,
[email protected]537c1082011-12-02 02:37:17222 Delegate* delegate)
223 : start_time_(Time::Now()),
224 testing_prefs_(NULL),
225 incognito_(false),
[email protected]9819fd02013-08-22 10:49:39226 force_incognito_(false),
[email protected]074311a2013-02-28 23:14:09227 original_profile_(NULL),
[email protected]e9476cd2013-12-04 05:55:34228 guest_session_(false),
[email protected]537c1082011-12-02 02:37:17229 last_session_exited_cleanly_(true),
230 profile_path_(path),
[email protected]f0901a22013-05-27 21:37:53231 browser_context_dependency_manager_(
[email protected]f1484c52013-05-22 23:25:44232 BrowserContextDependencyManager::GetInstance()),
[email protected]37ac95b2013-07-23 23:39:35233 resource_context_(NULL),
[email protected]537c1082011-12-02 02:37:17234 delegate_(delegate) {
235 Init();
236 if (delegate_) {
[email protected]bb024fe2013-05-10 21:33:26237 base::MessageLoop::current()->PostTask(
238 FROM_HERE,
239 base::Bind(&TestingProfile::FinishInit, base::Unretained(this)));
[email protected]537c1082011-12-02 02:37:17240 } else {
241 FinishInit();
242 }
[email protected]49a25632011-08-31 17:03:48243}
244
[email protected]5c4c89f2012-08-07 21:09:59245TestingProfile::TestingProfile(
[email protected]152ea302013-02-11 04:08:40246 const base::FilePath& path,
[email protected]5c4c89f2012-08-07 21:09:59247 Delegate* delegate,
248 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy,
[email protected]9819fd02013-08-22 10:49:39249 scoped_ptr<PrefServiceSyncable> prefs,
250 bool incognito,
[email protected]e9476cd2013-12-04 05:55:34251 bool guest_session,
[email protected]d20d0432014-06-12 17:14:05252 const std::string& supervised_user_id,
[email protected]a43b9a82013-11-28 16:56:41253 scoped_ptr<policy::PolicyService> policy_service,
[email protected]9819fd02013-08-22 10:49:39254 const TestingFactories& factories)
[email protected]5c4c89f2012-08-07 21:09:59255 : start_time_(Time::Now()),
256 prefs_(prefs.release()),
257 testing_prefs_(NULL),
[email protected]9819fd02013-08-22 10:49:39258 incognito_(incognito),
259 force_incognito_(false),
[email protected]074311a2013-02-28 23:14:09260 original_profile_(NULL),
[email protected]e9476cd2013-12-04 05:55:34261 guest_session_(guest_session),
[email protected]d20d0432014-06-12 17:14:05262 supervised_user_id_(supervised_user_id),
[email protected]5c4c89f2012-08-07 21:09:59263 last_session_exited_cleanly_(true),
264 extension_special_storage_policy_(extension_policy),
[email protected]5c4c89f2012-08-07 21:09:59265 profile_path_(path),
[email protected]f0901a22013-05-27 21:37:53266 browser_context_dependency_manager_(
[email protected]f1484c52013-05-22 23:25:44267 BrowserContextDependencyManager::GetInstance()),
[email protected]37ac95b2013-07-23 23:39:35268 resource_context_(NULL),
[email protected]a43b9a82013-11-28 16:56:41269 delegate_(delegate),
270 policy_service_(policy_service.release()) {
[email protected]5c4c89f2012-08-07 21:09:59271 // If no profile path was supplied, create one.
272 if (profile_path_.empty()) {
273 CreateTempProfileDir();
274 profile_path_ = temp_dir_.path();
275 }
276
[email protected]9819fd02013-08-22 10:49:39277 // Set any testing factories prior to initializing the services.
278 for (TestingFactories::const_iterator it = factories.begin();
279 it != factories.end(); ++it) {
280 it->first->SetTestingFactory(this, it->second);
281 }
282
[email protected]5c4c89f2012-08-07 21:09:59283 Init();
284 // If caller supplied a delegate, delay the FinishInit invocation until other
285 // tasks have run.
286 // TODO(atwilson): See if this is still required once we convert the current
287 // users of the constructor that takes a Delegate* param.
288 if (delegate_) {
[email protected]bb024fe2013-05-10 21:33:26289 base::MessageLoop::current()->PostTask(
290 FROM_HERE,
291 base::Bind(&TestingProfile::FinishInit, base::Unretained(this)));
[email protected]5c4c89f2012-08-07 21:09:59292 } else {
293 FinishInit();
294 }
295}
296
297void TestingProfile::CreateTempProfileDir() {
298 if (!temp_dir_.CreateUniqueTempDir()) {
299 LOG(ERROR) << "Failed to create unique temporary directory.";
300
301 // Fallback logic in case we fail to create unique temporary directory.
[email protected]152ea302013-02-11 04:08:40302 base::FilePath system_tmp_dir;
[email protected]5c4c89f2012-08-07 21:09:59303 bool success = PathService::Get(base::DIR_TEMP, &system_tmp_dir);
304
305 // We're severly screwed if we can't get the system temporary
306 // directory. Die now to avoid writing to the filesystem root
307 // or other bad places.
308 CHECK(success);
309
[email protected]152ea302013-02-11 04:08:40310 base::FilePath fallback_dir(
311 system_tmp_dir.AppendASCII("TestingProfilePath"));
[email protected]dd3aa792013-07-16 19:10:23312 base::DeleteFile(fallback_dir, true);
[email protected]426d1c92013-12-03 20:08:54313 base::CreateDirectory(fallback_dir);
[email protected]5c4c89f2012-08-07 21:09:59314 if (!temp_dir_.Set(fallback_dir)) {
315 // That shouldn't happen, but if it does, try to recover.
316 LOG(ERROR) << "Failed to use a fallback temporary directory.";
317
318 // We're screwed if this fails, see CHECK above.
319 CHECK(temp_dir_.Set(system_tmp_dir));
320 }
321 }
322}
323
[email protected]49a25632011-08-31 17:03:48324void TestingProfile::Init() {
[email protected]bf390cb2013-08-06 02:48:08325 // If threads have been initialized, we should be on the UI thread.
[email protected]33d06242013-08-12 05:20:30326 DCHECK(!content::BrowserThread::IsThreadInitialized(
327 content::BrowserThread::UI) ||
328 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
[email protected]bf390cb2013-08-06 02:48:08329
[email protected]bd3093c2014-06-13 07:38:16330#if defined(OS_ANDROID)
331 // Make sure token service knows its running in tests.
332 AndroidProfileOAuth2TokenService::set_is_testing_profile();
333#endif
334
[email protected]7e75e4a2013-05-17 17:20:03335 // Normally this would happen during browser startup, but for tests
336 // we need to trigger creation of Profile-related services.
337 ChromeBrowserMainExtraPartsProfiles::
[email protected]f1484c52013-05-22 23:25:44338 EnsureBrowserContextKeyedServiceFactoriesBuilt();
[email protected]7e75e4a2013-05-17 17:20:03339
[email protected]75fee372013-03-06 00:42:44340 if (prefs_.get())
[email protected]c7141feb2013-06-11 13:00:16341 user_prefs::UserPrefs::Set(this, prefs_.get());
[email protected]c7fa4362013-04-26 18:09:02342 else
343 CreateTestingPrefService();
[email protected]75fee372013-03-06 00:42:44344
[email protected]7567484142013-07-11 17:36:07345 if (!base::PathExists(profile_path_))
[email protected]426d1c92013-12-03 20:08:54346 base::CreateDirectory(profile_path_);
[email protected]d41e6572012-05-04 20:49:42347
[email protected]d81bb3e2013-05-02 18:17:03348 // TODO(joaodasilva): remove this once this PKS isn't created in ProfileImpl
349 // anymore, after converting the PrefService to a PKS. Until then it must
350 // be associated with a TestingProfile too.
[email protected]eb83c392013-11-07 12:53:24351 if (!IsOffTheRecord())
352 CreateProfilePolicyConnector();
[email protected]d81bb3e2013-05-02 18:17:03353
[email protected]bd306722012-07-11 20:43:59354 extensions::ExtensionSystemFactory::GetInstance()->SetTestingFactory(
355 this, extensions::TestExtensionSystem::Build);
[email protected]31d8f5f22012-04-02 15:22:08356
[email protected]d45c5d52013-12-04 23:41:16357 // If no original profile was specified for this profile: register preferences
358 // even if this is an incognito profile - this allows tests to create a
[email protected]9819fd02013-08-22 10:49:39359 // standalone incognito profile while still having prefs registered.
[email protected]d45c5d52013-12-04 23:41:16360 if (!IsOffTheRecord() || !original_profile_) {
361 user_prefs::PrefRegistrySyncable* pref_registry =
362 static_cast<user_prefs::PrefRegistrySyncable*>(
363 prefs_->DeprecatedGetPrefRegistry());
364 browser_context_dependency_manager_->
365 RegisterProfilePrefsForServices(this, pref_registry);
366 }
367
[email protected]9819fd02013-08-22 10:49:39368 browser_context_dependency_manager_->CreateBrowserContextServicesForTest(
[email protected]d45c5d52013-12-04 23:41:16369 this);
[email protected]49a25632011-08-31 17:03:48370
[email protected]5fd2e842012-03-01 00:29:11371#if defined(ENABLE_NOTIFICATIONS)
[email protected]dcb72d52011-04-13 12:36:53372 // Install profile keyed service factory hooks for dummy/test services
[email protected]7722653b2011-06-03 17:28:22373 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory(
374 this, CreateTestDesktopNotificationService);
[email protected]5fd2e842012-03-01 00:29:11375#endif
[email protected]e1480482013-09-11 11:49:58376
377#if defined(ENABLE_MANAGED_USERS)
378 ManagedUserSettingsService* settings_service =
379 ManagedUserSettingsServiceFactory::GetForProfile(this);
380 TestingPrefStore* store = new TestingPrefStore();
381 settings_service->Init(store);
382 store->SetInitializationCompleted();
383#endif
[email protected]d6001872013-09-24 18:31:26384
385 profile_name_ = "testing_profile";
[email protected]537c1082011-12-02 02:37:17386}
[email protected]12463cd2011-07-19 09:40:20387
[email protected]537c1082011-12-02 02:37:17388void TestingProfile::FinishInit() {
[email protected]080adba92011-12-07 19:00:40389 DCHECK(content::NotificationService::current());
[email protected]ad50def52011-10-19 23:17:07390 content::NotificationService::current()->Notify(
[email protected]12463cd2011-07-19 09:40:20391 chrome::NOTIFICATION_PROFILE_CREATED,
[email protected]6c2381d2011-10-19 02:52:53392 content::Source<Profile>(static_cast<Profile*>(this)),
[email protected]ad50def52011-10-19 23:17:07393 content::NotificationService::NoDetails());
[email protected]537c1082011-12-02 02:37:17394
[email protected]371662e372013-10-17 22:05:22395 ProfileManager* profile_manager = g_browser_process->profile_manager();
396 if (profile_manager)
397 profile_manager->InitProfileUserPrefs(this);
398
[email protected]537c1082011-12-02 02:37:17399 if (delegate_)
[email protected]00b33f802012-03-13 07:46:03400 delegate_->OnProfileCreated(this, true, false);
[email protected]ab23dbe2010-08-12 02:10:46401}
402
[email protected]f25387b2008-08-21 15:20:33403TestingProfile::~TestingProfile() {
[email protected]9819fd02013-08-22 10:49:39404 // Revert to non-incognito mode before shutdown.
405 force_incognito_ = false;
406
[email protected]37ac95b2013-07-23 23:39:35407 // Any objects holding live URLFetchers should be deleted before teardown.
408 TemplateURLFetcherFactory::ShutdownForProfile(this);
409
[email protected]a7c4c032012-07-27 00:36:32410 MaybeSendDestroyedNotification();
[email protected]5cdcd152011-03-31 22:48:52411
[email protected]f0901a22013-05-27 21:37:53412 browser_context_dependency_manager_->DestroyBrowserContextServices(this);
[email protected]5cdcd152011-03-31 22:48:52413
[email protected]5c6ac842013-06-02 23:37:03414 if (host_content_settings_map_.get())
[email protected]35552dc52011-07-12 09:04:38415 host_content_settings_map_->ShutdownOnUIThread();
416
[email protected]809cc4d2010-10-27 15:22:54417 DestroyTopSites();
[email protected]cdba46992011-06-07 11:51:39418
[email protected]cc5bfd42010-11-24 14:44:02419 if (pref_proxy_config_tracker_.get())
420 pref_proxy_config_tracker_->DetachFromPrefService();
[email protected]37ac95b2013-07-23 23:39:35421 // Failing a post == leaks == heapcheck failure. Make that an immediate test
422 // failure.
423 if (resource_context_) {
424 CHECK(BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE,
425 resource_context_));
426 resource_context_ = NULL;
427 content::RunAllPendingInMessageLoop(BrowserThread::IO);
428 }
[email protected]f25387b2008-08-21 15:20:33429}
initial.commit09911bf2008-07-26 23:55:29430
[email protected]540380fc2014-03-14 10:10:34431static KeyedService* BuildFaviconService(content::BrowserContext* profile) {
[email protected]f718290e2013-11-05 07:11:58432 return new FaviconService(static_cast<Profile*>(profile));
[email protected]f3d2b312012-08-23 22:27:59433}
434
[email protected]d2879af2010-02-08 16:02:56435void TestingProfile::CreateFaviconService() {
[email protected]f3d2b312012-08-23 22:27:59436 // It is up to the caller to create the history service if one is needed.
437 FaviconServiceFactory::GetInstance()->SetTestingFactory(
438 this, BuildFaviconService);
[email protected]d2879af2010-02-08 16:02:56439}
440
[email protected]ad34610c2014-06-04 14:43:52441static KeyedService* BuildHistoryService(content::BrowserContext* context) {
442 Profile* profile = static_cast<Profile*>(context);
443 return new HistoryService(ChromeHistoryClientFactory::GetForProfile(profile),
444 profile);
[email protected]f61f4782012-06-08 21:54:21445}
446
[email protected]608e7e02013-07-24 12:23:31447bool TestingProfile::CreateHistoryService(bool delete_file, bool no_db) {
[email protected]809cc4d2010-10-27 15:22:54448 DestroyHistoryService();
[email protected]f25387b2008-08-21 15:20:33449 if (delete_file) {
[email protected]152ea302013-02-11 04:08:40450 base::FilePath path = GetPath();
[email protected]f7011fcb2009-01-28 21:54:32451 path = path.Append(chrome::kHistoryFilename);
[email protected]608e7e02013-07-24 12:23:31452 if (!base::DeleteFile(path, false) || base::PathExists(path))
453 return false;
[email protected]f25387b2008-08-21 15:20:33454 }
[email protected]7019bb6d2012-08-23 09:09:48455 // This will create and init the history service.
[email protected]f61f4782012-06-08 21:54:21456 HistoryService* history_service = static_cast<HistoryService*>(
457 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse(
[email protected]a5894fe2012-11-01 14:40:56458 this, BuildHistoryService));
[email protected]ad34610c2014-06-04 14:43:52459 if (!history_service->Init(this->GetPath(), no_db)) {
[email protected]f61f4782012-06-08 21:54:21460 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse(this, NULL);
[email protected]7019bb6d2012-08-23 09:09:48461 }
[email protected]a50e16a2013-04-25 14:07:17462 // Disable WebHistoryService by default, since it makes network requests.
463 WebHistoryServiceFactory::GetInstance()->SetTestingFactory(this, NULL);
[email protected]608e7e02013-07-24 12:23:31464 return true;
initial.commit09911bf2008-07-26 23:55:29465}
466
467void TestingProfile::DestroyHistoryService() {
[email protected]a5894fe2012-11-01 14:40:56468 HistoryService* history_service =
[email protected]6c537042012-07-13 00:59:02469 HistoryServiceFactory::GetForProfileWithoutCreating(this);
[email protected]a5894fe2012-11-01 14:40:56470 if (!history_service)
initial.commit09911bf2008-07-26 23:55:29471 return;
472
[email protected]378970412014-06-12 07:31:17473 history_service->ClearCachedDataForContextID(0);
[email protected]bb024fe2013-05-10 21:33:26474 history_service->SetOnBackendDestroyTask(base::MessageLoop::QuitClosure());
[email protected]f61f4782012-06-08 21:54:21475 history_service->Cleanup();
476 HistoryServiceFactory::ShutdownForProfile(this);
initial.commit09911bf2008-07-26 23:55:29477
478 // Wait for the backend class to terminate before deleting the files and
479 // moving to the next test. Note: if this never terminates, somebody is
480 // probably leaking a reference to the history backend, so it never calls
481 // our destroy task.
[email protected]bb024fe2013-05-10 21:33:26482 base::MessageLoop::current()->Run();
initial.commit09911bf2008-07-26 23:55:29483
initial.commit09911bf2008-07-26 23:55:29484 // Make sure we don't have any event pending that could disrupt the next
485 // test.
[email protected]bb024fe2013-05-10 21:33:26486 base::MessageLoop::current()->PostTask(FROM_HERE,
487 base::MessageLoop::QuitClosure());
488 base::MessageLoop::current()->Run();
initial.commit09911bf2008-07-26 23:55:29489}
[email protected]4d0cd7ce2008-08-11 16:40:57490
[email protected]809cc4d2010-10-27 15:22:54491void TestingProfile::CreateTopSites() {
492 DestroyTopSites();
[email protected]9a93d3432013-04-29 20:52:12493 top_sites_ = history::TopSites::Create(
494 this, GetPath().Append(chrome::kTopSitesFilename));
[email protected]809cc4d2010-10-27 15:22:54495}
496
497void TestingProfile::DestroyTopSites() {
498 if (top_sites_.get()) {
499 top_sites_->Shutdown();
500 top_sites_ = NULL;
[email protected]9a93d3432013-04-29 20:52:12501 // TopSitesImpl::Shutdown schedules some tasks (from TopSitesBackend) that
502 // need to be run to properly shutdown. Run all pending tasks now. This is
[email protected]809cc4d2010-10-27 15:22:54503 // normally handled by browser_process shutdown.
[email protected]bb024fe2013-05-10 21:33:26504 if (base::MessageLoop::current())
505 base::MessageLoop::current()->RunUntilIdle();
[email protected]809cc4d2010-10-27 15:22:54506 }
507}
508
[email protected]540380fc2014-03-14 10:10:34509static KeyedService* BuildBookmarkModel(content::BrowserContext* context) {
[email protected]c7fa4362013-04-26 18:09:02510 Profile* profile = static_cast<Profile*>(context);
[email protected]6a848b52014-04-26 22:06:54511 ChromeBookmarkClient* bookmark_client =
[email protected]0b0e8a12014-06-14 00:11:31512 ChromeBookmarkClientFactory::GetForProfile(profile);
513 BookmarkModel* bookmark_model = new BookmarkModel(bookmark_client, false);
514 bookmark_client->Init(bookmark_model);
515 bookmark_model->Load(profile->GetPrefs(),
516 profile->GetPrefs()->GetString(prefs::kAcceptLanguages),
517 profile->GetPath(),
518 profile->GetIOTaskRunner(),
519 content::BrowserThread::GetMessageLoopProxyForThread(
520 content::BrowserThread::UI));
521 return bookmark_model;
522}
523
524static KeyedService* BuildChromeBookmarkClient(
525 content::BrowserContext* context) {
526 return new ChromeBookmarkClient(static_cast<Profile*>(context));
[email protected]f61f4782012-06-08 21:54:21527}
528
[email protected]ad34610c2014-06-04 14:43:52529static KeyedService* BuildChromeHistoryClient(
530 content::BrowserContext* context) {
531 Profile* profile = static_cast<Profile*>(context);
532 return new ChromeHistoryClient(BookmarkModelFactory::GetForProfile(profile));
533}
534
[email protected]d8e41ed2008-09-11 15:22:32535void TestingProfile::CreateBookmarkModel(bool delete_file) {
[email protected]90ef13132008-08-27 03:27:46536 if (delete_file) {
[email protected]d4a67d52014-04-12 05:17:03537 base::FilePath path = GetPath().Append(bookmarks::kBookmarksFileName);
[email protected]dd3aa792013-07-16 19:10:23538 base::DeleteFile(path, false);
[email protected]90ef13132008-08-27 03:27:46539 }
[email protected]ad34610c2014-06-04 14:43:52540 ChromeHistoryClientFactory::GetInstance()->SetTestingFactory(
541 this, BuildChromeHistoryClient);
[email protected]0b0e8a12014-06-14 00:11:31542 ChromeBookmarkClientFactory::GetInstance()->SetTestingFactory(
543 this, BuildChromeBookmarkClient);
544 // This creates the BookmarkModel.
545 ignore_result(BookmarkModelFactory::GetInstance()->SetTestingFactoryAndUse(
546 this, BuildBookmarkModel));
[email protected]4d0cd7ce2008-08-11 16:40:57547}
[email protected]d2c017a2008-08-13 21:51:45548
[email protected]540380fc2014-03-14 10:10:34549static KeyedService* BuildWebDataService(content::BrowserContext* profile) {
[email protected]c7fa4362013-04-26 18:09:02550 return new WebDataServiceWrapper(static_cast<Profile*>(profile));
[email protected]d07edd42012-05-14 23:49:46551}
[email protected]2609bc12010-01-24 08:32:55552
[email protected]d07edd42012-05-14 23:49:46553void TestingProfile::CreateWebDataService() {
[email protected]a5c65292012-05-25 00:50:01554 WebDataServiceFactory::GetInstance()->SetTestingFactory(
[email protected]d07edd42012-05-14 23:49:46555 this, BuildWebDataService);
[email protected]2609bc12010-01-24 08:32:55556}
557
[email protected]18a15ca82012-08-30 00:28:16558void TestingProfile::BlockUntilHistoryIndexIsRefreshed() {
559 // Only get the history service if it actually exists since the caller of the
560 // test should explicitly call CreateHistoryService to build it.
561 HistoryService* history_service =
562 HistoryServiceFactory::GetForProfileWithoutCreating(this);
563 DCHECK(history_service);
564 history::InMemoryURLIndex* index = history_service->InMemoryIndex();
565 if (!index || index->restored())
566 return;
567 base::RunLoop run_loop;
568 HistoryIndexRestoreObserver observer(
569 content::GetQuitTaskForRunLoop(&run_loop));
570 index->set_restore_cache_observer(&observer);
571 run_loop.Run();
572 index->set_restore_cache_observer(NULL);
573 DCHECK(index->restored());
574}
575
[email protected]120abf132011-09-27 21:38:06576// TODO(phajdan.jr): Doesn't this hang if Top Sites are already loaded?
[email protected]809cc4d2010-10-27 15:22:54577void TestingProfile::BlockUntilTopSitesLoaded() {
[email protected]a7fe9112012-07-20 02:34:45578 content::WindowedNotificationObserver top_sites_loaded_observer(
[email protected]120abf132011-09-27 21:38:06579 chrome::NOTIFICATION_TOP_SITES_LOADED,
[email protected]ad50def52011-10-19 23:17:07580 content::NotificationService::AllSources());
[email protected]120abf132011-09-27 21:38:06581 top_sites_loaded_observer.Wait();
[email protected]809cc4d2010-10-27 15:22:54582}
583
[email protected]90efc3e2014-04-22 18:39:03584void TestingProfile::SetGuestSession(bool guest) {
585 guest_session_ = guest;
586}
587
[email protected]4251165a2013-07-17 04:33:40588base::FilePath TestingProfile::GetPath() const {
[email protected]49a25632011-08-31 17:03:48589 return profile_path_;
[email protected]f9dec9482010-08-20 20:42:19590}
591
[email protected]0de615a2012-11-08 04:40:59592scoped_refptr<base::SequencedTaskRunner> TestingProfile::GetIOTaskRunner() {
[email protected]bb024fe2013-05-10 21:33:26593 return base::MessageLoop::current()->message_loop_proxy();
[email protected]0de615a2012-11-08 04:40:59594}
595
[email protected]5b199522012-12-22 17:24:44596TestingPrefServiceSyncable* TestingProfile::GetTestingPrefService() {
[email protected]2fb7dc982010-09-29 12:24:28597 if (!prefs_.get())
598 CreateTestingPrefService();
599 DCHECK(testing_prefs_);
600 return testing_prefs_;
[email protected]dbbad7a2010-08-13 18:18:36601}
602
[email protected]8e5c89a2011-06-07 18:13:33603TestingProfile* TestingProfile::AsTestingProfile() {
604 return this;
605}
606
[email protected]29d70252011-04-28 02:16:58607std::string TestingProfile::GetProfileName() {
[email protected]d6001872013-09-24 18:31:26608 return profile_name_;
[email protected]29d70252011-04-28 02:16:58609}
610
[email protected]7b7e0b32014-03-17 16:09:23611Profile::ProfileType TestingProfile::GetProfileType() const {
612 if (guest_session_)
613 return GUEST_PROFILE;
614 if (force_incognito_ || incognito_)
615 return INCOGNITO_PROFILE;
616 return REGULAR_PROFILE;
617}
618
[email protected]27d6e852012-03-02 21:31:32619bool TestingProfile::IsOffTheRecord() const {
[email protected]9819fd02013-08-22 10:49:39620 return force_incognito_ || incognito_;
[email protected]fadc607b62011-02-07 17:55:50621}
622
[email protected]9819fd02013-08-22 10:49:39623void TestingProfile::SetOffTheRecordProfile(scoped_ptr<Profile> profile) {
624 DCHECK(!IsOffTheRecord());
625 incognito_profile_ = profile.Pass();
[email protected]93dba942011-02-23 22:45:01626}
627
[email protected]074311a2013-02-28 23:14:09628void TestingProfile::SetOriginalProfile(Profile* profile) {
[email protected]9819fd02013-08-22 10:49:39629 DCHECK(IsOffTheRecord());
[email protected]074311a2013-02-28 23:14:09630 original_profile_ = profile;
631}
632
[email protected]fadc607b62011-02-07 17:55:50633Profile* TestingProfile::GetOffTheRecordProfile() {
[email protected]9819fd02013-08-22 10:49:39634 if (IsOffTheRecord())
635 return this;
[email protected]cbed02ae2014-03-07 17:16:26636 if (!incognito_profile_) {
637 TestingProfile::Builder builder;
638 builder.SetIncognito();
639 scoped_ptr<TestingProfile> incognito_test_profile(builder.Build());
640 incognito_test_profile->SetOriginalProfile(this);
641 SetOffTheRecordProfile(incognito_test_profile.PassAs<Profile>());
642 }
[email protected]5bb2f522011-03-25 19:04:44643 return incognito_profile_.get();
[email protected]fadc607b62011-02-07 17:55:50644}
645
646bool TestingProfile::HasOffTheRecordProfile() {
[email protected]5bb2f522011-03-25 19:04:44647 return incognito_profile_.get() != NULL;
[email protected]fadc607b62011-02-07 17:55:50648}
649
650Profile* TestingProfile::GetOriginalProfile() {
[email protected]074311a2013-02-28 23:14:09651 if (original_profile_)
652 return original_profile_;
[email protected]fadc607b62011-02-07 17:55:50653 return this;
654}
655
[email protected]d20d0432014-06-12 17:14:05656bool TestingProfile::IsSupervised() {
657 return !supervised_user_id_.empty();
[email protected]e000daf2013-07-31 16:50:58658}
659
[email protected]eaa7dd182010-12-14 11:09:00660ExtensionService* TestingProfile::GetExtensionService() {
[email protected]bd306722012-07-11 20:43:59661 return extensions::ExtensionSystem::Get(this)->extension_service();
[email protected]2fb7dc982010-09-29 12:24:28662}
663
[email protected]2261e7b72011-07-12 13:43:55664void TestingProfile::SetExtensionSpecialStoragePolicy(
665 ExtensionSpecialStoragePolicy* extension_special_storage_policy) {
666 extension_special_storage_policy_ = extension_special_storage_policy;
667}
668
[email protected]19eb80152011-02-26 00:28:43669ExtensionSpecialStoragePolicy*
670TestingProfile::GetExtensionSpecialStoragePolicy() {
[email protected]cdba46992011-06-07 11:51:39671 if (!extension_special_storage_policy_.get())
[email protected]7c5048c2011-08-19 17:07:05672 extension_special_storage_policy_ = new ExtensionSpecialStoragePolicy(NULL);
[email protected]cdba46992011-06-07 11:51:39673 return extension_special_storage_policy_.get();
[email protected]19eb80152011-02-26 00:28:43674}
675
[email protected]33ad6ce92013-08-27 14:39:08676net::CookieMonster* TestingProfile::GetCookieMonster() {
677 if (!GetRequestContext())
678 return NULL;
679 return GetRequestContext()->GetURLRequestContext()->cookie_store()->
680 GetCookieMonster();
681}
682
[email protected]2fb7dc982010-09-29 12:24:28683void TestingProfile::CreateTestingPrefService() {
684 DCHECK(!prefs_.get());
[email protected]5b199522012-12-22 17:24:44685 testing_prefs_ = new TestingPrefServiceSyncable();
[email protected]2fb7dc982010-09-29 12:24:28686 prefs_.reset(testing_prefs_);
[email protected]c7141feb2013-06-11 13:00:16687 user_prefs::UserPrefs::Set(this, prefs_.get());
[email protected]37ca3fe02013-07-05 15:32:44688 chrome::RegisterUserProfilePrefs(testing_prefs_->registry());
[email protected]2fb7dc982010-09-29 12:24:28689}
690
[email protected]d81bb3e2013-05-02 18:17:03691void TestingProfile::CreateProfilePolicyConnector() {
[email protected]d81bb3e2013-05-02 18:17:03692#if defined(ENABLE_CONFIGURATION_POLICY)
[email protected]eb83c392013-11-07 12:53:24693 schema_registry_service_ =
694 policy::SchemaRegistryServiceFactory::CreateForContext(
695 this, policy::Schema(), NULL);
696 CHECK_EQ(schema_registry_service_.get(),
697 policy::SchemaRegistryServiceFactory::GetForContext(this));
[email protected]a43b9a82013-11-28 16:56:41698#endif // defined(ENABLE_CONFIGURATION_POLICY)
[email protected]eb83c392013-11-07 12:53:24699
[email protected]a43b9a82013-11-28 16:56:41700if (!policy_service_) {
701#if defined(ENABLE_CONFIGURATION_POLICY)
702 std::vector<policy::ConfigurationPolicyProvider*> providers;
[email protected]33528402013-12-16 18:38:32703 policy_service_.reset(new policy::PolicyServiceImpl(providers));
[email protected]d81bb3e2013-05-02 18:17:03704#else
[email protected]a43b9a82013-11-28 16:56:41705 policy_service_.reset(new policy::PolicyServiceStub());
[email protected]d81bb3e2013-05-02 18:17:03706#endif
[email protected]a43b9a82013-11-28 16:56:41707 }
[email protected]24a9f1c92013-11-13 12:33:37708 profile_policy_connector_.reset(new policy::ProfilePolicyConnector());
[email protected]a43b9a82013-11-28 16:56:41709 profile_policy_connector_->InitForTesting(policy_service_.Pass());
[email protected]d81bb3e2013-05-02 18:17:03710 policy::ProfilePolicyConnectorFactory::GetInstance()->SetServiceForTesting(
711 this, profile_policy_connector_.get());
712 CHECK_EQ(profile_policy_connector_.get(),
713 policy::ProfilePolicyConnectorFactory::GetForProfile(this));
714}
715
[email protected]c753f142013-02-10 13:14:04716PrefService* TestingProfile::GetPrefs() {
[email protected]dbbad7a2010-08-13 18:18:36717 if (!prefs_.get()) {
[email protected]2fb7dc982010-09-29 12:24:28718 CreateTestingPrefService();
[email protected]dbbad7a2010-08-13 18:18:36719 }
720 return prefs_.get();
721}
722
723history::TopSites* TestingProfile::GetTopSites() {
[email protected]809cc4d2010-10-27 15:22:54724 return top_sites_.get();
[email protected]dbbad7a2010-08-13 18:18:36725}
726
[email protected]fadc607b62011-02-07 17:55:50727history::TopSites* TestingProfile::GetTopSitesWithoutCreating() {
728 return top_sites_.get();
729}
730
[email protected]b441a8492012-06-06 14:55:57731DownloadManagerDelegate* TestingProfile::GetDownloadManagerDelegate() {
[email protected]fadc607b62011-02-07 17:55:50732 return NULL;
733}
734
[email protected]abe2c032011-03-31 18:49:34735net::URLRequestContextGetter* TestingProfile::GetRequestContext() {
[email protected]37ac95b2013-07-23 23:39:35736 return GetDefaultStoragePartition(this)->GetURLRequestContext();
[email protected]812b3a32010-01-08 05:36:04737}
738
[email protected]6bd30072013-02-08 18:17:11739net::URLRequestContextGetter* TestingProfile::CreateRequestContext(
[email protected]7571263c2014-03-10 22:57:09740 content::ProtocolHandlerMap* protocol_handlers,
[email protected]3b90aab2014-05-30 17:56:15741 content::URLRequestInterceptorScopedVector request_interceptors) {
[email protected]37ac95b2013-07-23 23:39:35742 return new net::TestURLRequestContextGetter(
743 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
[email protected]6bd30072013-02-08 18:17:11744}
745
[email protected]da5683db2011-04-23 17:12:21746net::URLRequestContextGetter* TestingProfile::GetRequestContextForRenderProcess(
747 int renderer_child_id) {
[email protected]fb29e6cf2012-07-12 21:27:20748 content::RenderProcessHost* rph = content::RenderProcessHost::FromID(
749 renderer_child_id);
[email protected]1bc28312012-11-08 08:31:53750 return rph->GetStoragePartition()->GetURLRequestContext();
[email protected]d9696672011-03-15 22:45:09751}
752
[email protected]10705a7b2012-08-21 19:07:08753net::URLRequestContextGetter* TestingProfile::GetMediaRequestContext() {
754 return NULL;
755}
756
757net::URLRequestContextGetter*
758TestingProfile::GetMediaRequestContextForRenderProcess(
759 int renderer_child_id) {
[email protected]fadc607b62011-02-07 17:55:50760 return NULL;
761}
762
[email protected]10eb28162012-09-18 03:04:09763net::URLRequestContextGetter*
764TestingProfile::GetMediaRequestContextForStoragePartition(
[email protected]152ea302013-02-11 04:08:40765 const base::FilePath& partition_path,
[email protected]27ddfed22012-10-30 23:22:43766 bool in_memory) {
[email protected]10eb28162012-09-18 03:04:09767 return NULL;
768}
769
[email protected]6e068ea2014-02-04 07:05:47770void TestingProfile::RequestMidiSysExPermission(
[email protected]8aca7252013-07-12 19:18:59771 int render_process_id,
772 int render_view_id,
[email protected]00880a02013-10-30 03:18:30773 int bridge_id,
[email protected]8aca7252013-07-12 19:18:59774 const GURL& requesting_frame,
[email protected]7c6d9482014-03-28 20:19:31775 bool user_gesture,
[email protected]6e068ea2014-02-04 07:05:47776 const MidiSysExPermissionCallback& callback) {
[email protected]8aca7252013-07-12 19:18:59777 // Always reject requests for testing.
778 callback.Run(false);
779}
780
[email protected]6e068ea2014-02-04 07:05:47781void TestingProfile::CancelMidiSysExPermissionRequest(
[email protected]00880a02013-10-30 03:18:30782 int render_process_id,
783 int render_view_id,
784 int bridge_id,
785 const GURL& requesting_frame) {
786}
787
[email protected]566755f82014-01-08 01:14:57788void TestingProfile::RequestProtectedMediaIdentifierPermission(
789 int render_process_id,
790 int render_view_id,
[email protected]5e170a52014-05-29 03:09:02791 const GURL& origin,
[email protected]566755f82014-01-08 01:14:57792 const ProtectedMediaIdentifierPermissionCallback& callback) {
793 // Always reject requests for testing.
794 callback.Run(false);
795}
796
797void TestingProfile::CancelProtectedMediaIdentifierPermissionRequests(
[email protected]5e170a52014-05-29 03:09:02798 int render_process_id,
799 int render_view_id,
800 const GURL& origin) {
[email protected]566755f82014-01-08 01:14:57801}
802
[email protected]33ad6ce92013-08-27 14:39:08803net::URLRequestContextGetter* TestingProfile::GetRequestContextForExtensions() {
804 if (!extensions_request_context_.get())
805 extensions_request_context_ = new TestExtensionURLRequestContextGetter();
806 return extensions_request_context_.get();
807}
808
[email protected]fadc607b62011-02-07 17:55:50809net::SSLConfigService* TestingProfile::GetSSLConfigService() {
[email protected]dc6655b2012-12-14 05:58:24810 if (!GetRequestContext())
811 return NULL;
812 return GetRequestContext()->GetURLRequestContext()->ssl_config_service();
[email protected]fadc607b62011-02-07 17:55:50813}
814
[email protected]10eb28162012-09-18 03:04:09815net::URLRequestContextGetter*
[email protected]6bd30072013-02-08 18:17:11816TestingProfile::CreateRequestContextForStoragePartition(
[email protected]152ea302013-02-11 04:08:40817 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:11818 bool in_memory,
[email protected]7571263c2014-03-10 22:57:09819 content::ProtocolHandlerMap* protocol_handlers,
[email protected]3b90aab2014-05-30 17:56:15820 content::URLRequestInterceptorScopedVector request_interceptors) {
[email protected]10eb28162012-09-18 03:04:09821 // We don't test storage partitions here yet, so returning the same dummy
[email protected]d9696672011-03-15 22:45:09822 // context is sufficient for now.
823 return GetRequestContext();
824}
825
[email protected]df02aca2012-02-09 21:03:20826content::ResourceContext* TestingProfile::GetResourceContext() {
[email protected]37ac95b2013-07-23 23:39:35827 if (!resource_context_)
828 resource_context_ = new content::MockResourceContext();
829 return resource_context_;
[email protected]e89b77d2011-04-15 18:58:10830}
831
[email protected]dbbad7a2010-08-13 18:18:36832HostContentSettingsMap* TestingProfile::GetHostContentSettingsMap() {
[email protected]35552dc52011-07-12 09:04:38833 if (!host_content_settings_map_.get()) {
[email protected]646c29cb62012-06-18 14:31:05834 host_content_settings_map_ = new HostContentSettingsMap(GetPrefs(), false);
[email protected]701550ad2012-09-06 23:43:29835#if defined(ENABLE_EXTENSIONS)
[email protected]646c29cb62012-06-18 14:31:05836 ExtensionService* extension_service = GetExtensionService();
837 if (extension_service)
838 host_content_settings_map_->RegisterExtensionService(extension_service);
[email protected]701550ad2012-09-06 23:43:29839#endif
[email protected]35552dc52011-07-12 09:04:38840 }
[email protected]dbbad7a2010-08-13 18:18:36841 return host_content_settings_map_.get();
842}
843
[email protected]139355f2014-05-11 14:21:28844content::BrowserPluginGuestManager* TestingProfile::GetGuestManager() {
[email protected]1df3d972014-06-11 04:55:18845#if defined(ENABLE_EXTENSIONS)
[email protected]24569262014-05-06 03:31:30846 return GuestViewManager::FromBrowserContext(this);
[email protected]1df3d972014-06-11 04:55:18847#else
848 return NULL;
849#endif
[email protected]24569262014-05-06 03:31:30850}
851
[email protected]c5c89d042014-06-13 14:43:37852content::PushMessagingService* TestingProfile::GetPushMessagingService() {
853 return NULL;
854}
855
[email protected]fadc607b62011-02-07 17:55:50856bool TestingProfile::IsSameProfile(Profile *p) {
857 return this == p;
858}
859
860base::Time TestingProfile::GetStartTime() const {
861 return start_time_;
862}
863
[email protected]152ea302013-02-11 04:08:40864base::FilePath TestingProfile::last_selected_directory() {
[email protected]fadc607b62011-02-07 17:55:50865 return last_selected_directory_;
866}
867
[email protected]152ea302013-02-11 04:08:40868void TestingProfile::set_last_selected_directory(const base::FilePath& path) {
[email protected]fadc607b62011-02-07 17:55:50869 last_selected_directory_ = path;
870}
871
[email protected]cc5bfd42010-11-24 14:44:02872PrefProxyConfigTracker* TestingProfile::GetProxyConfigTracker() {
[email protected]6f96cbcb2011-11-04 02:26:07873 if (!pref_proxy_config_tracker_.get()) {
[email protected]e2930d0902013-07-17 05:25:42874 // TestingProfile is used in unit tests, where local state is not available.
[email protected]6f96cbcb2011-11-04 02:26:07875 pref_proxy_config_tracker_.reset(
[email protected]e2930d0902013-07-17 05:25:42876 ProxyServiceFactory::CreatePrefProxyConfigTrackerOfProfile(GetPrefs(),
877 NULL));
[email protected]6f96cbcb2011-11-04 02:26:07878 }
879 return pref_proxy_config_tracker_.get();
[email protected]cc5bfd42010-11-24 14:44:02880}
881
[email protected]0bfc29a2009-04-27 16:15:44882void TestingProfile::BlockUntilHistoryProcessesPendingRequests() {
[email protected]a5894fe2012-11-01 14:40:56883 HistoryService* history_service =
[email protected]6c537042012-07-13 00:59:02884 HistoryServiceFactory::GetForProfile(this, Profile::EXPLICIT_ACCESS);
[email protected]a5894fe2012-11-01 14:40:56885 DCHECK(history_service);
[email protected]bb024fe2013-05-10 21:33:26886 DCHECK(base::MessageLoop::current());
[email protected]0bfc29a2009-04-27 16:15:44887
888 CancelableRequestConsumer consumer;
[email protected]f61f4782012-06-08 21:54:21889 history_service->ScheduleDBTask(new QuittingHistoryDBTask(), &consumer);
[email protected]bb024fe2013-05-10 21:33:26890 base::MessageLoop::current()->Run();
[email protected]0bfc29a2009-04-27 16:15:44891}
[email protected]345a8b72009-09-29 09:11:44892
[email protected]8382d8c2011-09-15 03:43:17893chrome_browser_net::Predictor* TestingProfile::GetNetworkPredictor() {
894 return NULL;
895}
896
[email protected]a4205202014-06-02 16:03:08897DevToolsNetworkController* TestingProfile::GetDevToolsNetworkController() {
898 return NULL;
899}
900
[email protected]e0e1fc22012-11-05 20:25:36901void TestingProfile::ClearNetworkingHistorySince(
902 base::Time time,
903 const base::Closure& completion) {
904 if (!completion.is_null()) {
905 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, completion);
906 }
[email protected]02896a82011-09-21 18:54:32907}
908
[email protected]9b2034032014-05-11 18:10:31909void TestingProfile::ClearDomainReliabilityMonitor(
910 domain_reliability::DomainReliabilityClearMode mode,
911 const base::Closure& completion) {
912 if (!completion.is_null()) {
913 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, completion);
914 }
915}
916
[email protected]671f9c62011-10-28 19:22:07917GURL TestingProfile::GetHomePage() {
918 return GURL(chrome::kChromeUINewTabURL);
919}
920
[email protected]c753f142013-02-10 13:14:04921PrefService* TestingProfile::GetOffTheRecordPrefs() {
[email protected]fadc607b62011-02-07 17:55:50922 return NULL;
923}
924
[email protected]36fb2c7c2011-04-04 15:49:08925quota::SpecialStoragePolicy* TestingProfile::GetSpecialStoragePolicy() {
926 return GetExtensionSpecialStoragePolicy();
927}
928
[email protected]1bee6ed2012-03-14 06:46:36929bool TestingProfile::WasCreatedByVersionOrLater(const std::string& version) {
930 return true;
931}
[email protected]ef92e172012-04-25 19:40:41932
[email protected]4251165a2013-07-17 04:33:40933bool TestingProfile::IsGuestSession() const {
[email protected]e9476cd2013-12-04 05:55:34934 return guest_session_;
[email protected]4251165a2013-07-17 04:33:40935}
[email protected]1101dbc52013-10-05 00:19:12936
[email protected]6c0ca7fc2012-10-05 16:27:22937Profile::ExitType TestingProfile::GetLastSessionExitType() {
938 return last_session_exited_cleanly_ ? EXIT_NORMAL : EXIT_CRASHED;
[email protected]2ca1ea662012-10-04 02:26:36939}
940
[email protected]5c4c89f2012-08-07 21:09:59941TestingProfile::Builder::Builder()
942 : build_called_(false),
[email protected]9819fd02013-08-22 10:49:39943 delegate_(NULL),
[email protected]e9476cd2013-12-04 05:55:34944 incognito_(false),
945 guest_session_(false) {
[email protected]5c4c89f2012-08-07 21:09:59946}
947
948TestingProfile::Builder::~Builder() {
949}
950
[email protected]152ea302013-02-11 04:08:40951void TestingProfile::Builder::SetPath(const base::FilePath& path) {
[email protected]5c4c89f2012-08-07 21:09:59952 path_ = path;
953}
954
955void TestingProfile::Builder::SetDelegate(Delegate* delegate) {
956 delegate_ = delegate;
957}
958
959void TestingProfile::Builder::SetExtensionSpecialStoragePolicy(
960 scoped_refptr<ExtensionSpecialStoragePolicy> policy) {
961 extension_policy_ = policy;
962}
963
[email protected]5b199522012-12-22 17:24:44964void TestingProfile::Builder::SetPrefService(
965 scoped_ptr<PrefServiceSyncable> prefs) {
[email protected]5c4c89f2012-08-07 21:09:59966 pref_service_ = prefs.Pass();
967}
968
[email protected]9819fd02013-08-22 10:49:39969void TestingProfile::Builder::SetIncognito() {
970 incognito_ = true;
971}
972
[email protected]e9476cd2013-12-04 05:55:34973void TestingProfile::Builder::SetGuestSession() {
974 guest_session_ = true;
975}
976
[email protected]d20d0432014-06-12 17:14:05977void TestingProfile::Builder::SetSupervisedUserId(
978 const std::string& supervised_user_id) {
979 supervised_user_id_ = supervised_user_id;
[email protected]371662e372013-10-17 22:05:22980}
981
[email protected]a43b9a82013-11-28 16:56:41982void TestingProfile::Builder::SetPolicyService(
983 scoped_ptr<policy::PolicyService> policy_service) {
984 policy_service_ = policy_service.Pass();
985}
986
[email protected]9819fd02013-08-22 10:49:39987void TestingProfile::Builder::AddTestingFactory(
988 BrowserContextKeyedServiceFactory* service_factory,
[email protected]d45c5d52013-12-04 23:41:16989 BrowserContextKeyedServiceFactory::TestingFactoryFunction callback) {
[email protected]9819fd02013-08-22 10:49:39990 testing_factories_.push_back(std::make_pair(service_factory, callback));
991}
992
[email protected]5c4c89f2012-08-07 21:09:59993scoped_ptr<TestingProfile> TestingProfile::Builder::Build() {
994 DCHECK(!build_called_);
995 build_called_ = true;
[email protected]371662e372013-10-17 22:05:22996
[email protected]5c4c89f2012-08-07 21:09:59997 return scoped_ptr<TestingProfile>(new TestingProfile(
998 path_,
999 delegate_,
1000 extension_policy_,
[email protected]9819fd02013-08-22 10:49:391001 pref_service_.Pass(),
1002 incognito_,
[email protected]e9476cd2013-12-04 05:55:341003 guest_session_,
[email protected]d20d0432014-06-12 17:14:051004 supervised_user_id_,
[email protected]a43b9a82013-11-28 16:56:411005 policy_service_.Pass(),
[email protected]9819fd02013-08-22 10:49:391006 testing_factories_));
[email protected]5c4c89f2012-08-07 21:09:591007}