blob: c69447fa05f8cbd8e20c65c377baf1d2e99c62ca [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]83a7d2eb2010-05-03 21:46:1912#include "base/message_loop_proxy.h"
[email protected]dbbad7a2010-08-13 18:18:3613#include "base/path_service.h"
[email protected]8e937c1e2012-06-28 22:57:3014#include "base/run_loop.h"
[email protected]e83326f2010-07-31 17:29:2515#include "base/string_number_conversions.h"
[email protected]dbbad7a2010-08-13 18:18:3616#include "chrome/browser/autocomplete/autocomplete_classifier.h"
[email protected]a9afddb2009-02-12 17:49:4217#include "chrome/browser/bookmarks/bookmark_model.h"
[email protected]f61f4782012-06-08 21:54:2118#include "chrome/browser/bookmarks/bookmark_model_factory.h"
[email protected]1459fb62011-05-25 19:03:2719#include "chrome/browser/browser_process.h"
[email protected]9d01a6a2010-11-30 12:03:3320#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]a6d36cc2011-02-23 00:39:4821#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
[email protected]2f69b382011-02-19 00:34:2522#include "chrome/browser/extensions/extension_service.h"
[email protected]19eb80152011-02-26 00:28:4323#include "chrome/browser/extensions/extension_special_storage_policy.h"
[email protected]31d8f5f22012-04-02 15:22:0824#include "chrome/browser/extensions/extension_system.h"
25#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]c476e632011-06-23 11:18:0428#include "chrome/browser/geolocation/chrome_geolocation_permission_context.h"
[email protected]dbbad7a2010-08-13 18:18:3629#include "chrome/browser/history/history.h"
[email protected]075ae732009-02-11 23:58:3130#include "chrome/browser/history/history_backend.h"
[email protected]f61f4782012-06-08 21:54:2131#include "chrome/browser/history/history_service_factory.h"
[email protected]dbbad7a2010-08-13 18:18:3632#include "chrome/browser/history/top_sites.h"
[email protected]6f96cbcb2011-11-04 02:26:0733#include "chrome/browser/net/proxy_service_factory.h"
[email protected]dbbad7a2010-08-13 18:18:3634#include "chrome/browser/notifications/desktop_notification_service.h"
[email protected]dcb72d52011-04-13 12:36:5335#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]37858e52010-08-26 00:22:0236#include "chrome/browser/prefs/browser_prefs.h"
[email protected]9a8c4022011-01-25 14:25:3337#include "chrome/browser/prefs/testing_pref_store.h"
[email protected]4850a7f2011-03-08 23:36:5938#include "chrome/browser/prerender/prerender_manager.h"
[email protected]5cdcd152011-03-31 22:48:5239#include "chrome/browser/profiles/profile_dependency_manager.h"
[email protected]ee78d8a2012-03-15 16:53:4840#include "chrome/browser/protector/protector_service_factory.h"
[email protected]16bd088b2012-04-03 08:12:1241#include "chrome/browser/search_engines/template_url_fetcher_factory.h"
[email protected]c52b2892012-03-07 11:01:0242#include "chrome/browser/speech/chrome_speech_recognition_preferences.h"
[email protected]810ffba2012-06-12 01:07:4843#include "chrome/browser/webdata/web_data_service.h"
[email protected]d07edd42012-05-14 23:49:4644#include "chrome/browser/webdata/web_data_service_factory.h"
[email protected]a9afddb2009-02-12 17:49:4245#include "chrome/common/chrome_constants.h"
[email protected]432115822011-07-10 15:52:2746#include "chrome/common/chrome_notification_types.h"
[email protected]9e33d7e2011-09-30 16:43:5447#include "chrome/common/chrome_switches.h"
[email protected]dbbad7a2010-08-13 18:18:3648#include "chrome/common/url_constants.h"
[email protected]7bc60682011-07-29 20:55:5949#include "chrome/test/base/bookmark_load_observer.h"
[email protected]8ad3636e2011-08-01 22:31:4050#include "chrome/test/base/testing_pref_service.h"
[email protected]af44e7fb2011-07-29 18:32:3251#include "chrome/test/base/ui_test_utils.h"
[email protected]c38831a12011-10-28 12:44:4952#include "content/public/browser/browser_thread.h"
[email protected]ad50def52011-10-19 23:17:0753#include "content/public/browser/notification_service.h"
[email protected]08a932d52012-06-03 21:42:1254#include "content/public/test/mock_resource_context.h"
[email protected]aa84a7e2012-03-15 21:29:0655#include "net/cookies/cookie_monster.h"
[email protected]812b3a32010-01-08 05:36:0456#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:3457#include "net/url_request/url_request_context_getter.h"
[email protected]d2db0292011-01-26 20:23:4458#include "net/url_request/url_request_test_util.h"
[email protected]4772b072010-03-30 17:45:4659#include "testing/gmock/include/gmock/gmock.h"
[email protected]248ce192011-02-10 15:26:3460
[email protected]21d3a882012-05-31 14:41:5561#if defined(ENABLE_CONFIGURATION_POLICY)
62#include "chrome/browser/policy/policy_service_impl.h"
63#else
64#include "chrome/browser/policy/policy_service_stub.h"
65#endif // defined(ENABLE_CONFIGURATION_POLICY)
66
[email protected]6f96cbcb2011-11-04 02:26:0767#if defined(OS_CHROMEOS)
68#include "chrome/browser/chromeos/proxy_config_service_impl.h"
69#endif // defined(OS_CHROMEOS)
70
[email protected]e1acf6f2008-10-27 20:43:3371using base::Time;
[email protected]631bb742011-11-02 11:29:3972using content::BrowserThread;
[email protected]b441a8492012-06-06 14:55:5773using content::DownloadManagerDelegate;
[email protected]3c887412010-04-19 20:30:2374using testing::NiceMock;
[email protected]4772b072010-03-30 17:45:4675using testing::Return;
[email protected]e1acf6f2008-10-27 20:43:3376
[email protected]d364c652008-08-29 19:46:5677namespace {
78
[email protected]0bfc29a2009-04-27 16:15:4479// Task used to make sure history has finished processing a request. Intended
80// for use with BlockUntilHistoryProcessesPendingRequests.
81
82class QuittingHistoryDBTask : public HistoryDBTask {
83 public:
84 QuittingHistoryDBTask() {}
85
86 virtual bool RunOnDBThread(history::HistoryBackend* backend,
87 history::HistoryDatabase* db) {
88 return true;
89 }
90
91 virtual void DoneRunOnMainThread() {
92 MessageLoop::current()->Quit();
93 }
94
95 private:
[email protected]7991a232009-11-06 01:55:4896 ~QuittingHistoryDBTask() {}
97
[email protected]0bfc29a2009-04-27 16:15:4498 DISALLOW_COPY_AND_ASSIGN(QuittingHistoryDBTask);
99};
100
[email protected]aeb53f02011-01-15 00:21:34101class TestExtensionURLRequestContext : public net::URLRequestContext {
[email protected]c10da4b02010-03-25 14:38:32102 public:
103 TestExtensionURLRequestContext() {
104 net::CookieMonster* cookie_monster = new net::CookieMonster(NULL, NULL);
105 const char* schemes[] = {chrome::kExtensionScheme};
106 cookie_monster->SetCookieableSchemes(schemes, 1);
[email protected]f6c21cb2011-02-16 19:45:41107 set_cookie_store(cookie_monster);
[email protected]c10da4b02010-03-25 14:38:32108 }
[email protected]7b2720b2012-04-25 16:59:11109
[email protected]7b2720b2012-04-25 16:59:11110 virtual ~TestExtensionURLRequestContext() {}
[email protected]c10da4b02010-03-25 14:38:32111};
112
[email protected]abe2c032011-03-31 18:49:34113class TestExtensionURLRequestContextGetter
114 : public net::URLRequestContextGetter {
[email protected]c10da4b02010-03-25 14:38:32115 public:
[email protected]aeb53f02011-01-15 00:21:34116 virtual net::URLRequestContext* GetURLRequestContext() {
[email protected]ef2bf422012-05-11 03:27:09117 if (!context_.get())
118 context_.reset(new TestExtensionURLRequestContext());
[email protected]c10da4b02010-03-25 14:38:32119 return context_.get();
120 }
[email protected]4969b0122012-06-16 01:58:28121 virtual scoped_refptr<base::SingleThreadTaskRunner>
122 GetNetworkTaskRunner() const OVERRIDE {
[email protected]0c7d74f2010-10-11 11:55:26123 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
[email protected]83a7d2eb2010-05-03 21:46:19124 }
[email protected]c10da4b02010-03-25 14:38:32125
[email protected]13ed17f82012-04-06 02:27:18126 protected:
127 virtual ~TestExtensionURLRequestContextGetter() {}
128
[email protected]c10da4b02010-03-25 14:38:32129 private:
[email protected]ef2bf422012-05-11 03:27:09130 scoped_ptr<net::URLRequestContext> context_;
[email protected]c10da4b02010-03-25 14:38:32131};
132
[email protected]abc77242012-03-16 04:32:31133ProfileKeyedService* CreateTestDesktopNotificationService(Profile* profile) {
[email protected]29cebbd2012-06-06 21:43:42134#if defined(ENABLE_NOTIFICATIONS)
[email protected]dcb72d52011-04-13 12:36:53135 return new DesktopNotificationService(profile, NULL);
[email protected]29cebbd2012-06-06 21:43:42136#else
137 return NULL;
138#endif
[email protected]dcb72d52011-04-13 12:36:53139}
140
[email protected]d364c652008-08-29 19:46:56141} // namespace
142
[email protected]f25387b2008-08-21 15:20:33143TestingProfile::TestingProfile()
[email protected]ea6f76572008-12-18 00:09:55144 : start_time_(Time::Now()),
[email protected]2fb7dc982010-09-29 12:24:28145 testing_prefs_(NULL),
[email protected]5bb2f522011-03-25 19:04:44146 incognito_(false),
[email protected]5cdcd152011-03-31 22:48:52147 last_session_exited_cleanly_(true),
[email protected]537c1082011-12-02 02:37:17148 profile_dependency_manager_(ProfileDependencyManager::GetInstance()),
149 delegate_(NULL) {
[email protected]f9dec9482010-08-20 20:42:19150 if (!temp_dir_.CreateUniqueTempDir()) {
151 LOG(ERROR) << "Failed to create unique temporary directory.";
initial.commit09911bf2008-07-26 23:55:29152
[email protected]f9dec9482010-08-20 20:42:19153 // Fallback logic in case we fail to create unique temporary directory.
154 FilePath system_tmp_dir;
155 bool success = PathService::Get(base::DIR_TEMP, &system_tmp_dir);
[email protected]848cd05e2008-09-19 18:33:48156
[email protected]f9dec9482010-08-20 20:42:19157 // We're severly screwed if we can't get the system temporary
158 // directory. Die now to avoid writing to the filesystem root
159 // or other bad places.
160 CHECK(success);
161
162 FilePath fallback_dir(system_tmp_dir.AppendASCII("TestingProfilePath"));
163 file_util::Delete(fallback_dir, true);
164 file_util::CreateDirectory(fallback_dir);
165 if (!temp_dir_.Set(fallback_dir)) {
166 // That shouldn't happen, but if it does, try to recover.
167 LOG(ERROR) << "Failed to use a fallback temporary directory.";
168
169 // We're screwed if this fails, see CHECK above.
170 CHECK(temp_dir_.Set(system_tmp_dir));
171 }
172 }
[email protected]dcb72d52011-04-13 12:36:53173
[email protected]49a25632011-08-31 17:03:48174 profile_path_ = temp_dir_.path();
175
176 Init();
[email protected]537c1082011-12-02 02:37:17177 FinishInit();
[email protected]49a25632011-08-31 17:03:48178}
179
180TestingProfile::TestingProfile(const FilePath& path)
181 : start_time_(Time::Now()),
182 testing_prefs_(NULL),
183 incognito_(false),
184 last_session_exited_cleanly_(true),
185 profile_path_(path),
[email protected]537c1082011-12-02 02:37:17186 profile_dependency_manager_(ProfileDependencyManager::GetInstance()),
187 delegate_(NULL) {
[email protected]49a25632011-08-31 17:03:48188 Init();
[email protected]537c1082011-12-02 02:37:17189 FinishInit();
190}
191
192TestingProfile::TestingProfile(const FilePath& path,
193 Delegate* delegate)
194 : start_time_(Time::Now()),
195 testing_prefs_(NULL),
196 incognito_(false),
197 last_session_exited_cleanly_(true),
198 profile_path_(path),
199 profile_dependency_manager_(ProfileDependencyManager::GetInstance()),
200 delegate_(delegate) {
201 Init();
202 if (delegate_) {
203 MessageLoop::current()->PostTask(FROM_HERE,
204 base::Bind(&TestingProfile::FinishInit,
205 base::Unretained(this)));
206 } else {
207 FinishInit();
208 }
[email protected]49a25632011-08-31 17:03:48209}
210
211void TestingProfile::Init() {
[email protected]d41e6572012-05-04 20:49:42212 if (!file_util::PathExists(profile_path_))
213 file_util::CreateDirectory(profile_path_);
214
[email protected]31d8f5f22012-04-02 15:22:08215 ExtensionSystemFactory::GetInstance()->SetTestingFactory(
216 this, TestExtensionSystem::Build);
217
[email protected]49a25632011-08-31 17:03:48218 profile_dependency_manager_->CreateProfileServices(this, true);
219
[email protected]5fd2e842012-03-01 00:29:11220#if defined(ENABLE_NOTIFICATIONS)
[email protected]dcb72d52011-04-13 12:36:53221 // Install profile keyed service factory hooks for dummy/test services
[email protected]7722653b2011-06-03 17:28:22222 DesktopNotificationServiceFactory::GetInstance()->SetTestingFactory(
223 this, CreateTestDesktopNotificationService);
[email protected]5fd2e842012-03-01 00:29:11224#endif
[email protected]537c1082011-12-02 02:37:17225}
[email protected]12463cd2011-07-19 09:40:20226
[email protected]537c1082011-12-02 02:37:17227void TestingProfile::FinishInit() {
[email protected]080adba92011-12-07 19:00:40228 DCHECK(content::NotificationService::current());
[email protected]ad50def52011-10-19 23:17:07229 content::NotificationService::current()->Notify(
[email protected]12463cd2011-07-19 09:40:20230 chrome::NOTIFICATION_PROFILE_CREATED,
[email protected]6c2381d2011-10-19 02:52:53231 content::Source<Profile>(static_cast<Profile*>(this)),
[email protected]ad50def52011-10-19 23:17:07232 content::NotificationService::NoDetails());
[email protected]537c1082011-12-02 02:37:17233
234 if (delegate_)
[email protected]00b33f802012-03-13 07:46:03235 delegate_->OnProfileCreated(this, true, false);
[email protected]ab23dbe2010-08-12 02:10:46236}
237
[email protected]f25387b2008-08-21 15:20:33238TestingProfile::~TestingProfile() {
[email protected]080adba92011-12-07 19:00:40239 DCHECK(content::NotificationService::current());
[email protected]ad50def52011-10-19 23:17:07240 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:27241 chrome::NOTIFICATION_PROFILE_DESTROYED,
[email protected]6c2381d2011-10-19 02:52:53242 content::Source<Profile>(static_cast<Profile*>(this)),
[email protected]ad50def52011-10-19 23:17:07243 content::NotificationService::NoDetails());
[email protected]5cdcd152011-03-31 22:48:52244
245 profile_dependency_manager_->DestroyProfileServices(this);
246
[email protected]35552dc52011-07-12 09:04:38247 if (host_content_settings_map_)
248 host_content_settings_map_->ShutdownOnUIThread();
249
[email protected]809cc4d2010-10-27 15:22:54250 DestroyTopSites();
[email protected]d2879af2010-02-08 16:02:56251 DestroyFaviconService();
[email protected]cdba46992011-06-07 11:51:39252
[email protected]cc5bfd42010-11-24 14:44:02253 if (pref_proxy_config_tracker_.get())
254 pref_proxy_config_tracker_->DetachFromPrefService();
[email protected]f25387b2008-08-21 15:20:33255}
initial.commit09911bf2008-07-26 23:55:29256
[email protected]d2879af2010-02-08 16:02:56257void TestingProfile::CreateFaviconService() {
[email protected]04732c0e2011-09-16 13:21:53258 favicon_service_.reset(new FaviconService(this));
[email protected]d2879af2010-02-08 16:02:56259}
260
[email protected]f61f4782012-06-08 21:54:21261static scoped_refptr<RefcountedProfileKeyedService> BuildHistoryService(
262 Profile* profile) {
263 return new HistoryService(profile);
264}
265
[email protected]d486a0852009-11-02 21:40:00266void TestingProfile::CreateHistoryService(bool delete_file, bool no_db) {
[email protected]809cc4d2010-10-27 15:22:54267 DestroyHistoryService();
[email protected]f25387b2008-08-21 15:20:33268 if (delete_file) {
[email protected]f7011fcb2009-01-28 21:54:32269 FilePath path = GetPath();
270 path = path.Append(chrome::kHistoryFilename);
[email protected]f25387b2008-08-21 15:20:33271 file_util::Delete(path, false);
272 }
[email protected]f61f4782012-06-08 21:54:21273 // This will create and init the history service.
274 HistoryService* history_service = static_cast<HistoryService*>(
275 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse(
276 this, BuildHistoryService).get());
277 if (!history_service->Init(this->GetPath(),
[email protected]34f2149b2012-06-13 08:23:23278 BookmarkModelFactory::GetForProfile(this),
[email protected]f61f4782012-06-08 21:54:21279 no_db)) {
280 HistoryServiceFactory::GetInstance()->SetTestingFactoryAndUse(this, NULL);
281 }
initial.commit09911bf2008-07-26 23:55:29282}
283
284void TestingProfile::DestroyHistoryService() {
[email protected]f61f4782012-06-08 21:54:21285 scoped_refptr<HistoryService> history_service =
[email protected]92a0fb772012-06-25 20:56:46286 HistoryServiceFactory::GetForProfileIfExists(this);
[email protected]f61f4782012-06-08 21:54:21287 if (!history_service.get())
initial.commit09911bf2008-07-26 23:55:29288 return;
289
[email protected]f61f4782012-06-08 21:54:21290 history_service->NotifyRenderProcessHostDestruction(0);
291 history_service->SetOnBackendDestroyTask(MessageLoop::QuitClosure());
292 history_service->Cleanup();
293 HistoryServiceFactory::ShutdownForProfile(this);
initial.commit09911bf2008-07-26 23:55:29294
295 // Wait for the backend class to terminate before deleting the files and
296 // moving to the next test. Note: if this never terminates, somebody is
297 // probably leaking a reference to the history backend, so it never calls
298 // our destroy task.
299 MessageLoop::current()->Run();
300
initial.commit09911bf2008-07-26 23:55:29301 // Make sure we don't have any event pending that could disrupt the next
302 // test.
[email protected]1cb1a242011-12-10 18:36:51303 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
initial.commit09911bf2008-07-26 23:55:29304 MessageLoop::current()->Run();
305}
[email protected]4d0cd7ce2008-08-11 16:40:57306
[email protected]809cc4d2010-10-27 15:22:54307void TestingProfile::CreateTopSites() {
308 DestroyTopSites();
309 top_sites_ = new history::TopSites(this);
[email protected]73c47932010-12-06 18:13:43310 FilePath file_name = GetPath().Append(chrome::kTopSitesFilename);
[email protected]809cc4d2010-10-27 15:22:54311 top_sites_->Init(file_name);
312}
313
314void TestingProfile::DestroyTopSites() {
315 if (top_sites_.get()) {
316 top_sites_->Shutdown();
317 top_sites_ = NULL;
318 // TopSites::Shutdown schedules some tasks (from TopSitesBackend) that need
319 // to be run to properly shutdown. Run all pending tasks now. This is
320 // normally handled by browser_process shutdown.
321 if (MessageLoop::current())
322 MessageLoop::current()->RunAllPending();
323 }
324}
325
326void TestingProfile::DestroyFaviconService() {
[email protected]04732c0e2011-09-16 13:21:53327 favicon_service_.reset();
[email protected]809cc4d2010-10-27 15:22:54328}
329
[email protected]f61f4782012-06-08 21:54:21330static ProfileKeyedService* BuildBookmarkModel(Profile* profile) {
331 BookmarkModel* bookmark_model = new BookmarkModel(profile);
332 bookmark_model->Load();
333 return bookmark_model;
334}
335
336
[email protected]d8e41ed2008-09-11 15:22:32337void TestingProfile::CreateBookmarkModel(bool delete_file) {
[email protected]90ef13132008-08-27 03:27:46338
339 if (delete_file) {
[email protected]f7011fcb2009-01-28 21:54:32340 FilePath path = GetPath();
341 path = path.Append(chrome::kBookmarksFileName);
[email protected]90ef13132008-08-27 03:27:46342 file_util::Delete(path, false);
343 }
[email protected]f61f4782012-06-08 21:54:21344 // This will create a bookmark model.
345 BookmarkModel* bookmark_service =
346 static_cast<BookmarkModel*>(
347 BookmarkModelFactory::GetInstance()->SetTestingFactoryAndUse(
348 this, BuildBookmarkModel));
349
350 HistoryService* history_service =
[email protected]92a0fb772012-06-25 20:56:46351 HistoryServiceFactory::GetForProfileIfExists(this).get();
[email protected]f61f4782012-06-08 21:54:21352 if (history_service) {
353 history_service->history_backend_->bookmark_service_ =
354 bookmark_service;
355 history_service->history_backend_->expirer_.bookmark_service_ =
356 bookmark_service;
[email protected]90ef13132008-08-27 03:27:46357 }
[email protected]4d0cd7ce2008-08-11 16:40:57358}
[email protected]d2c017a2008-08-13 21:51:45359
[email protected]a6d36cc2011-02-23 00:39:48360void TestingProfile::CreateProtocolHandlerRegistry() {
[email protected]fd8ca522011-05-02 18:54:49361 protocol_handler_registry_ = new ProtocolHandlerRegistry(this,
362 new ProtocolHandlerRegistry::Delegate());
[email protected]a6d36cc2011-02-23 00:39:48363}
364
[email protected]d07edd42012-05-14 23:49:46365static scoped_refptr<RefcountedProfileKeyedService> BuildWebDataService(
366 Profile* profile) {
367 WebDataService* web_data_service = new WebDataService();
368 if (web_data_service)
369 web_data_service->Init(profile->GetPath());
[email protected]a5c65292012-05-25 00:50:01370 return web_data_service;
[email protected]d07edd42012-05-14 23:49:46371}
[email protected]2609bc12010-01-24 08:32:55372
[email protected]d07edd42012-05-14 23:49:46373void TestingProfile::CreateWebDataService() {
[email protected]a5c65292012-05-25 00:50:01374 WebDataServiceFactory::GetInstance()->SetTestingFactory(
[email protected]d07edd42012-05-14 23:49:46375 this, BuildWebDataService);
[email protected]2609bc12010-01-24 08:32:55376}
377
[email protected]d364c652008-08-29 19:46:56378void TestingProfile::BlockUntilBookmarkModelLoaded() {
[email protected]f61f4782012-06-08 21:54:21379 DCHECK(GetBookmarkModel());
380 if (GetBookmarkModel()->IsLoaded())
[email protected]d364c652008-08-29 19:46:56381 return;
[email protected]8e937c1e2012-06-28 22:57:30382 base::RunLoop run_loop;
383 BookmarkLoadObserver observer(
384 ui_test_utils::GetQuitTaskForRunLoop(&run_loop));
[email protected]f61f4782012-06-08 21:54:21385 GetBookmarkModel()->AddObserver(&observer);
[email protected]8e937c1e2012-06-28 22:57:30386 run_loop.Run();
[email protected]f61f4782012-06-08 21:54:21387 GetBookmarkModel()->RemoveObserver(&observer);
388 DCHECK(GetBookmarkModel()->IsLoaded());
[email protected]d364c652008-08-29 19:46:56389}
390
[email protected]120abf132011-09-27 21:38:06391// TODO(phajdan.jr): Doesn't this hang if Top Sites are already loaded?
[email protected]809cc4d2010-10-27 15:22:54392void TestingProfile::BlockUntilTopSitesLoaded() {
[email protected]120abf132011-09-27 21:38:06393 ui_test_utils::WindowedNotificationObserver top_sites_loaded_observer(
394 chrome::NOTIFICATION_TOP_SITES_LOADED,
[email protected]ad50def52011-10-19 23:17:07395 content::NotificationService::AllSources());
[email protected]809cc4d2010-10-27 15:22:54396 if (!GetHistoryService(Profile::EXPLICIT_ACCESS))
397 GetTopSites()->HistoryLoaded();
[email protected]120abf132011-09-27 21:38:06398 top_sites_loaded_observer.Wait();
[email protected]809cc4d2010-10-27 15:22:54399}
400
[email protected]f9dec9482010-08-20 20:42:19401FilePath TestingProfile::GetPath() {
[email protected]49a25632011-08-31 17:03:48402 return profile_path_;
[email protected]f9dec9482010-08-20 20:42:19403}
404
[email protected]dbbad7a2010-08-13 18:18:36405TestingPrefService* TestingProfile::GetTestingPrefService() {
[email protected]2fb7dc982010-09-29 12:24:28406 if (!prefs_.get())
407 CreateTestingPrefService();
408 DCHECK(testing_prefs_);
409 return testing_prefs_;
[email protected]dbbad7a2010-08-13 18:18:36410}
411
[email protected]8e5c89a2011-06-07 18:13:33412TestingProfile* TestingProfile::AsTestingProfile() {
413 return this;
414}
415
[email protected]29d70252011-04-28 02:16:58416std::string TestingProfile::GetProfileName() {
417 return std::string("testing_profile");
418}
419
[email protected]27d6e852012-03-02 21:31:32420bool TestingProfile::IsOffTheRecord() const {
[email protected]5bb2f522011-03-25 19:04:44421 return incognito_;
[email protected]fadc607b62011-02-07 17:55:50422}
423
[email protected]93dba942011-02-23 22:45:01424void TestingProfile::SetOffTheRecordProfile(Profile* profile) {
[email protected]5bb2f522011-03-25 19:04:44425 incognito_profile_.reset(profile);
[email protected]93dba942011-02-23 22:45:01426}
427
[email protected]fadc607b62011-02-07 17:55:50428Profile* TestingProfile::GetOffTheRecordProfile() {
[email protected]5bb2f522011-03-25 19:04:44429 return incognito_profile_.get();
[email protected]fadc607b62011-02-07 17:55:50430}
431
[email protected]d4f5d1162011-11-30 01:41:52432GAIAInfoUpdateService* TestingProfile::GetGAIAInfoUpdateService() {
433 return NULL;
434}
435
[email protected]fadc607b62011-02-07 17:55:50436bool TestingProfile::HasOffTheRecordProfile() {
[email protected]5bb2f522011-03-25 19:04:44437 return incognito_profile_.get() != NULL;
[email protected]fadc607b62011-02-07 17:55:50438}
439
440Profile* TestingProfile::GetOriginalProfile() {
441 return this;
442}
443
[email protected]fadc607b62011-02-07 17:55:50444VisitedLinkMaster* TestingProfile::GetVisitedLinkMaster() {
445 return NULL;
446}
447
[email protected]eaa7dd182010-12-14 11:09:00448ExtensionService* TestingProfile::GetExtensionService() {
[email protected]749d59a2012-04-05 00:23:24449 return ExtensionSystem::Get(this)->extension_service();
[email protected]2fb7dc982010-09-29 12:24:28450}
451
[email protected]fadc607b62011-02-07 17:55:50452UserScriptMaster* TestingProfile::GetUserScriptMaster() {
[email protected]749d59a2012-04-05 00:23:24453 return ExtensionSystem::Get(this)->user_script_master();
[email protected]fadc607b62011-02-07 17:55:50454}
455
456ExtensionProcessManager* TestingProfile::GetExtensionProcessManager() {
[email protected]749d59a2012-04-05 00:23:24457 return ExtensionSystem::Get(this)->process_manager();
[email protected]fadc607b62011-02-07 17:55:50458}
459
460ExtensionEventRouter* TestingProfile::GetExtensionEventRouter() {
[email protected]749d59a2012-04-05 00:23:24461 return ExtensionSystem::Get(this)->event_router();
[email protected]fadc607b62011-02-07 17:55:50462}
463
[email protected]2261e7b72011-07-12 13:43:55464void TestingProfile::SetExtensionSpecialStoragePolicy(
465 ExtensionSpecialStoragePolicy* extension_special_storage_policy) {
466 extension_special_storage_policy_ = extension_special_storage_policy;
467}
468
[email protected]19eb80152011-02-26 00:28:43469ExtensionSpecialStoragePolicy*
470TestingProfile::GetExtensionSpecialStoragePolicy() {
[email protected]cdba46992011-06-07 11:51:39471 if (!extension_special_storage_policy_.get())
[email protected]7c5048c2011-08-19 17:07:05472 extension_special_storage_policy_ = new ExtensionSpecialStoragePolicy(NULL);
[email protected]cdba46992011-06-07 11:51:39473 return extension_special_storage_policy_.get();
[email protected]19eb80152011-02-26 00:28:43474}
475
[email protected]fadc607b62011-02-07 17:55:50476FaviconService* TestingProfile::GetFaviconService(ServiceAccessType access) {
477 return favicon_service_.get();
478}
479
480HistoryService* TestingProfile::GetHistoryService(ServiceAccessType access) {
[email protected]92a0fb772012-06-25 20:56:46481 return HistoryServiceFactory::GetForProfileIfExists(this);
[email protected]fadc607b62011-02-07 17:55:50482}
483
484HistoryService* TestingProfile::GetHistoryServiceWithoutCreating() {
[email protected]92a0fb772012-06-25 20:56:46485 return HistoryServiceFactory::GetForProfileIfExists(this);
[email protected]fadc607b62011-02-07 17:55:50486}
487
[email protected]dbbad7a2010-08-13 18:18:36488net::CookieMonster* TestingProfile::GetCookieMonster() {
489 if (!GetRequestContext())
490 return NULL;
[email protected]277ec262011-03-30 21:09:40491 return GetRequestContext()->GetURLRequestContext()->cookie_store()->
492 GetCookieMonster();
[email protected]dbbad7a2010-08-13 18:18:36493}
494
[email protected]21d3a882012-05-31 14:41:55495policy::PolicyService* TestingProfile::GetPolicyService() {
496 if (!policy_service_.get()) {
497#if defined(ENABLE_CONFIGURATION_POLICY)
498 policy::PolicyServiceImpl::Providers providers;
499 policy_service_.reset(new policy::PolicyServiceImpl(providers));
500#else
501 policy_service_.reset(new policy::PolicyServiceStub());
502#endif
503 }
504 return policy_service_.get();
505}
506
[email protected]c620fd52011-07-22 18:33:29507history::ShortcutsBackend* TestingProfile::GetShortcutsBackend() {
508 return NULL;
509}
510
[email protected]2fb7dc982010-09-29 12:24:28511void TestingProfile::SetPrefService(PrefService* prefs) {
[email protected]ddcaa412012-03-30 19:57:29512#if defined(ENABLE_PROTECTOR_SERVICE)
[email protected]ee78d8a2012-03-15 16:53:48513 // ProtectorService binds itself very closely to the PrefService at the moment
514 // of Profile creation and watches pref changes to update their backup.
515 // For tests that replace the PrefService after TestingProfile creation,
516 // ProtectorService is disabled to prevent further invalid memory accesses.
517 protector::ProtectorServiceFactory::GetInstance()->
518 SetTestingFactory(this, NULL);
[email protected]ddcaa412012-03-30 19:57:29519#endif
[email protected]2fb7dc982010-09-29 12:24:28520 prefs_.reset(prefs);
521}
522
523void TestingProfile::CreateTestingPrefService() {
524 DCHECK(!prefs_.get());
525 testing_prefs_ = new TestingPrefService();
526 prefs_.reset(testing_prefs_);
527 Profile::RegisterUserPrefs(prefs_.get());
[email protected]2f9d81322011-02-21 09:55:43528 browser::RegisterUserPrefs(prefs_.get());
[email protected]2fb7dc982010-09-29 12:24:28529}
530
[email protected]dbbad7a2010-08-13 18:18:36531PrefService* TestingProfile::GetPrefs() {
532 if (!prefs_.get()) {
[email protected]2fb7dc982010-09-29 12:24:28533 CreateTestingPrefService();
[email protected]dbbad7a2010-08-13 18:18:36534 }
535 return prefs_.get();
536}
537
538history::TopSites* TestingProfile::GetTopSites() {
[email protected]809cc4d2010-10-27 15:22:54539 return top_sites_.get();
[email protected]dbbad7a2010-08-13 18:18:36540}
541
[email protected]fadc607b62011-02-07 17:55:50542history::TopSites* TestingProfile::GetTopSitesWithoutCreating() {
543 return top_sites_.get();
544}
545
[email protected]b441a8492012-06-06 14:55:57546DownloadManagerDelegate* TestingProfile::GetDownloadManagerDelegate() {
[email protected]fadc607b62011-02-07 17:55:50547 return NULL;
548}
549
[email protected]abe2c032011-03-31 18:49:34550net::URLRequestContextGetter* TestingProfile::GetRequestContext() {
[email protected]812b3a32010-01-08 05:36:04551 return request_context_.get();
552}
553
[email protected]da5683db2011-04-23 17:12:21554net::URLRequestContextGetter* TestingProfile::GetRequestContextForRenderProcess(
555 int renderer_child_id) {
[email protected]31d8f5f22012-04-02 15:22:08556 ExtensionService* extension_service =
[email protected]749d59a2012-04-05 00:23:24557 ExtensionSystem::Get(this)->extension_service();
[email protected]31d8f5f22012-04-02 15:22:08558 if (extension_service) {
[email protected]1c321ee2012-05-21 03:02:34559 const extensions::Extension* installed_app = extension_service->
[email protected]da5683db2011-04-23 17:12:21560 GetInstalledAppForRenderer(renderer_child_id);
561 if (installed_app != NULL && installed_app->is_storage_isolated())
562 return GetRequestContextForIsolatedApp(installed_app->id());
563 }
[email protected]d9696672011-03-15 22:45:09564
565 return GetRequestContext();
566}
567
[email protected]812b3a32010-01-08 05:36:04568void TestingProfile::CreateRequestContext() {
569 if (!request_context_)
[email protected]44738602012-03-02 22:56:01570 request_context_ =
571 new TestURLRequestContextGetter(
572 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
[email protected]812b3a32010-01-08 05:36:04573}
574
[email protected]7c893202010-10-07 20:18:02575void TestingProfile::ResetRequestContext() {
[email protected]3931fd82012-03-12 21:18:48576 // Any objects holding live URLFetchers should be deleted before the request
577 // context is shut down.
[email protected]16bd088b2012-04-03 08:12:12578 TemplateURLFetcherFactory::ShutdownForProfile(this);
[email protected]3931fd82012-03-12 21:18:48579
[email protected]7c893202010-10-07 20:18:02580 request_context_ = NULL;
581}
582
[email protected]abe2c032011-03-31 18:49:34583net::URLRequestContextGetter* TestingProfile::GetRequestContextForMedia() {
[email protected]fadc607b62011-02-07 17:55:50584 return NULL;
585}
586
[email protected]abe2c032011-03-31 18:49:34587net::URLRequestContextGetter* TestingProfile::GetRequestContextForExtensions() {
[email protected]c10da4b02010-03-25 14:38:32588 if (!extensions_request_context_)
[email protected]00dea9582012-05-09 15:20:05589 extensions_request_context_ = new TestExtensionURLRequestContextGetter();
[email protected]c10da4b02010-03-25 14:38:32590 return extensions_request_context_.get();
591}
592
[email protected]fadc607b62011-02-07 17:55:50593net::SSLConfigService* TestingProfile::GetSSLConfigService() {
594 return NULL;
595}
596
[email protected]abe2c032011-03-31 18:49:34597net::URLRequestContextGetter* TestingProfile::GetRequestContextForIsolatedApp(
[email protected]d9696672011-03-15 22:45:09598 const std::string& app_id) {
599 // We don't test isolated app storage here yet, so returning the same dummy
600 // context is sufficient for now.
601 return GetRequestContext();
602}
603
[email protected]df02aca2012-02-09 21:03:20604content::ResourceContext* TestingProfile::GetResourceContext() {
[email protected]314c3e22012-02-21 03:57:42605 if (!resource_context_.get())
606 resource_context_.reset(new content::MockResourceContext());
607 return resource_context_.get();
[email protected]e89b77d2011-04-15 18:58:10608}
609
[email protected]dbbad7a2010-08-13 18:18:36610HostContentSettingsMap* TestingProfile::GetHostContentSettingsMap() {
[email protected]35552dc52011-07-12 09:04:38611 if (!host_content_settings_map_.get()) {
[email protected]646c29cb62012-06-18 14:31:05612 host_content_settings_map_ = new HostContentSettingsMap(GetPrefs(), false);
613 ExtensionService* extension_service = GetExtensionService();
614 if (extension_service)
615 host_content_settings_map_->RegisterExtensionService(extension_service);
[email protected]35552dc52011-07-12 09:04:38616 }
[email protected]dbbad7a2010-08-13 18:18:36617 return host_content_settings_map_.get();
618}
619
[email protected]810ddc52012-01-24 01:00:35620content::GeolocationPermissionContext*
[email protected]dbbad7a2010-08-13 18:18:36621TestingProfile::GetGeolocationPermissionContext() {
622 if (!geolocation_permission_context_.get()) {
623 geolocation_permission_context_ =
[email protected]c476e632011-06-23 11:18:04624 new ChromeGeolocationPermissionContext(this);
[email protected]dbbad7a2010-08-13 18:18:36625 }
626 return geolocation_permission_context_.get();
627}
628
[email protected]c52b2892012-03-07 11:01:02629content::SpeechRecognitionPreferences*
630 TestingProfile::GetSpeechRecognitionPreferences() {
[email protected]3297132a2012-02-21 23:27:59631#if defined(ENABLE_INPUT_SPEECH)
[email protected]750e9572012-06-06 15:21:24632 return ChromeSpeechRecognitionPreferences::GetForProfile(this);
[email protected]3297132a2012-02-21 23:27:59633#else
634 return NULL;
635#endif
[email protected]8238dd62011-09-29 15:13:01636}
637
[email protected]fadc607b62011-02-07 17:55:50638std::wstring TestingProfile::GetName() {
639 return std::wstring();
640}
641
642std::wstring TestingProfile::GetID() {
643 return id_;
644}
645
646void TestingProfile::SetID(const std::wstring& id) {
647 id_ = id;
648}
649
650bool TestingProfile::DidLastSessionExitCleanly() {
651 return last_session_exited_cleanly_;
652}
653
654BookmarkModel* TestingProfile::GetBookmarkModel() {
[email protected]f61f4782012-06-08 21:54:21655 return BookmarkModelFactory::GetForProfileIfExists(this);
[email protected]fadc607b62011-02-07 17:55:50656}
657
658bool TestingProfile::IsSameProfile(Profile *p) {
659 return this == p;
660}
661
662base::Time TestingProfile::GetStartTime() const {
663 return start_time_;
664}
665
[email protected]a6d36cc2011-02-23 00:39:48666ProtocolHandlerRegistry* TestingProfile::GetProtocolHandlerRegistry() {
667 return protocol_handler_registry_.get();
668}
669
[email protected]fadc607b62011-02-07 17:55:50670FilePath TestingProfile::last_selected_directory() {
671 return last_selected_directory_;
672}
673
674void TestingProfile::set_last_selected_directory(const FilePath& path) {
675 last_selected_directory_ = path;
676}
677
[email protected]cc5bfd42010-11-24 14:44:02678PrefProxyConfigTracker* TestingProfile::GetProxyConfigTracker() {
[email protected]6f96cbcb2011-11-04 02:26:07679 if (!pref_proxy_config_tracker_.get()) {
680 pref_proxy_config_tracker_.reset(
681 ProxyServiceFactory::CreatePrefProxyConfigTracker(GetPrefs()));
682 }
683 return pref_proxy_config_tracker_.get();
[email protected]cc5bfd42010-11-24 14:44:02684}
685
[email protected]0bfc29a2009-04-27 16:15:44686void TestingProfile::BlockUntilHistoryProcessesPendingRequests() {
[email protected]f61f4782012-06-08 21:54:21687 scoped_refptr<HistoryService> history_service =
[email protected]92a0fb772012-06-25 20:56:46688 HistoryServiceFactory::GetForProfileIfExists(this);
[email protected]f61f4782012-06-08 21:54:21689 DCHECK(history_service.get());
[email protected]0bfc29a2009-04-27 16:15:44690 DCHECK(MessageLoop::current());
691
692 CancelableRequestConsumer consumer;
[email protected]f61f4782012-06-08 21:54:21693 history_service->ScheduleDBTask(new QuittingHistoryDBTask(), &consumer);
[email protected]0bfc29a2009-04-27 16:15:44694 MessageLoop::current()->Run();
695}
[email protected]345a8b72009-09-29 09:11:44696
[email protected]8382d8c2011-09-15 03:43:17697chrome_browser_net::Predictor* TestingProfile::GetNetworkPredictor() {
698 return NULL;
699}
700
[email protected]db96a882011-10-09 02:01:54701void TestingProfile::ClearNetworkingHistorySince(base::Time time) {
[email protected]02896a82011-09-21 18:54:32702 NOTIMPLEMENTED();
703}
704
[email protected]671f9c62011-10-28 19:22:07705GURL TestingProfile::GetHomePage() {
706 return GURL(chrome::kChromeUINewTabURL);
707}
708
[email protected]fadc607b62011-02-07 17:55:50709PrefService* TestingProfile::GetOffTheRecordPrefs() {
710 return NULL;
711}
712
[email protected]36fb2c7c2011-04-04 15:49:08713quota::SpecialStoragePolicy* TestingProfile::GetSpecialStoragePolicy() {
714 return GetExtensionSpecialStoragePolicy();
715}
716
[email protected]1bee6ed2012-03-14 06:46:36717bool TestingProfile::WasCreatedByVersionOrLater(const std::string& version) {
718 return true;
719}
[email protected]ef92e172012-04-25 19:40:41720
721base::Callback<ChromeURLDataManagerBackend*(void)>
722 TestingProfile::GetChromeURLDataManagerBackendGetter() const {
723 return base::Callback<ChromeURLDataManagerBackend*(void)>();
724}