blob: 3b0dd38a893bc8a6dcb18febfdecc57caa5204be [file] [log] [blame]
[email protected]aeb53f02011-01-15 00:21:341// Copyright (c) 2011 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
5#include "chrome/test/testing_profile.h"
6
[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]e83326f2010-07-31 17:29:2514#include "base/string_number_conversions.h"
[email protected]dbbad7a2010-08-13 18:18:3615#include "chrome/browser/autocomplete/autocomplete_classifier.h"
[email protected]a9afddb2009-02-12 17:49:4216#include "chrome/browser/bookmarks/bookmark_model.h"
[email protected]9d01a6a2010-11-30 12:03:3317#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]a6d36cc2011-02-23 00:39:4818#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
[email protected]2bb51302011-02-18 22:39:2719#include "chrome/browser/extensions/extension_pref_value_map.h"
[email protected]2f69b382011-02-19 00:34:2520#include "chrome/browser/extensions/extension_service.h"
[email protected]19eb80152011-02-26 00:28:4321#include "chrome/browser/extensions/extension_special_storage_policy.h"
[email protected]dbbad7a2010-08-13 18:18:3622#include "chrome/browser/favicon_service.h"
[email protected]dbbad7a2010-08-13 18:18:3623#include "chrome/browser/geolocation/geolocation_content_settings_map.h"
[email protected]dbbad7a2010-08-13 18:18:3624#include "chrome/browser/history/history.h"
[email protected]075ae732009-02-11 23:58:3125#include "chrome/browser/history/history_backend.h"
[email protected]dbbad7a2010-08-13 18:18:3626#include "chrome/browser/history/top_sites.h"
[email protected]8e4c29612010-07-14 01:24:4527#include "chrome/browser/net/gaia/token_service.h"
[email protected]cc5bfd42010-11-24 14:44:0228#include "chrome/browser/net/pref_proxy_config_service.h"
[email protected]dbbad7a2010-08-13 18:18:3629#include "chrome/browser/notifications/desktop_notification_service.h"
[email protected]37858e52010-08-26 00:22:0230#include "chrome/browser/prefs/browser_prefs.h"
[email protected]9a8c4022011-01-25 14:25:3331#include "chrome/browser/prefs/testing_pref_store.h"
[email protected]4850a7f2011-03-08 23:36:5932#include "chrome/browser/prerender/prerender_manager.h"
[email protected]fb9d1f42010-10-06 23:17:5933#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]dbbad7a2010-08-13 18:18:3634#include "chrome/browser/search_engines/template_url_model.h"
[email protected]8cb5d5b2010-02-09 11:36:1635#include "chrome/browser/sessions/session_service.h"
[email protected]4772b072010-03-30 17:45:4636#include "chrome/browser/sync/profile_sync_service_mock.h"
[email protected]45300ad42010-12-02 15:51:1437#include "chrome/browser/ui/find_bar/find_bar_state.h"
[email protected]fd42ac30f2011-02-27 19:33:3638#include "chrome/browser/ui/webui/chrome_url_data_manager.h"
39#include "chrome/browser/ui/webui/ntp_resource_cache.h"
[email protected]a9afddb2009-02-12 17:49:4240#include "chrome/common/chrome_constants.h"
[email protected]68d2a05f2010-05-07 21:39:5541#include "chrome/common/net/url_request_context_getter.h"
[email protected]dbbad7a2010-08-13 18:18:3642#include "chrome/common/url_constants.h"
[email protected]5138bbff2010-12-08 09:41:4443#include "chrome/test/test_url_request_context_getter.h"
[email protected]93270d002011-01-19 22:32:5944#include "chrome/test/testing_pref_service.h"
[email protected]809cc4d2010-10-27 15:22:5445#include "chrome/test/ui_test_utils.h"
[email protected]567812d2011-02-24 17:40:5046#include "content/browser/browser_thread.h"
[email protected]87678d992011-02-28 17:33:3047#include "content/browser/geolocation/geolocation_permission_context.h"
[email protected]567812d2011-02-24 17:40:5048#include "content/browser/in_process_webkit/webkit_context.h"
[email protected]7f070d42011-03-09 20:25:3249#include "content/common/notification_service.h"
[email protected]dbbad7a2010-08-13 18:18:3650#include "net/base/cookie_monster.h"
[email protected]812b3a32010-01-08 05:36:0451#include "net/url_request/url_request_context.h"
[email protected]d2db0292011-01-26 20:23:4452#include "net/url_request/url_request_test_util.h"
[email protected]4772b072010-03-30 17:45:4653#include "testing/gmock/include/gmock/gmock.h"
[email protected]2f351cb2009-11-09 23:43:3454#include "webkit/database/database_tracker.h"
[email protected]248ce192011-02-10 15:26:3455
[email protected]e1acf6f2008-10-27 20:43:3356using base::Time;
[email protected]3c887412010-04-19 20:30:2357using testing::NiceMock;
[email protected]4772b072010-03-30 17:45:4658using testing::Return;
[email protected]e1acf6f2008-10-27 20:43:3359
[email protected]d364c652008-08-29 19:46:5660namespace {
61
[email protected]0bfc29a2009-04-27 16:15:4462// Task used to make sure history has finished processing a request. Intended
63// for use with BlockUntilHistoryProcessesPendingRequests.
64
65class QuittingHistoryDBTask : public HistoryDBTask {
66 public:
67 QuittingHistoryDBTask() {}
68
69 virtual bool RunOnDBThread(history::HistoryBackend* backend,
70 history::HistoryDatabase* db) {
71 return true;
72 }
73
74 virtual void DoneRunOnMainThread() {
75 MessageLoop::current()->Quit();
76 }
77
78 private:
[email protected]7991a232009-11-06 01:55:4879 ~QuittingHistoryDBTask() {}
80
[email protected]0bfc29a2009-04-27 16:15:4481 DISALLOW_COPY_AND_ASSIGN(QuittingHistoryDBTask);
82};
83
[email protected]d8e41ed2008-09-11 15:22:3284// BookmarkLoadObserver is used when blocking until the BookmarkModel
85// finishes loading. As soon as the BookmarkModel finishes loading the message
86// loop is quit.
87class BookmarkLoadObserver : public BookmarkModelObserver {
[email protected]d364c652008-08-29 19:46:5688 public:
89 BookmarkLoadObserver() {}
[email protected]d8e41ed2008-09-11 15:22:3290 virtual void Loaded(BookmarkModel* model) {
[email protected]d364c652008-08-29 19:46:5691 MessageLoop::current()->Quit();
92 }
93
[email protected]d8e41ed2008-09-11 15:22:3294 virtual void BookmarkNodeMoved(BookmarkModel* model,
[email protected]b3c33d462009-06-26 22:29:2095 const BookmarkNode* old_parent,
[email protected]d364c652008-08-29 19:46:5696 int old_index,
[email protected]b3c33d462009-06-26 22:29:2097 const BookmarkNode* new_parent,
[email protected]d364c652008-08-29 19:46:5698 int new_index) {}
[email protected]d8e41ed2008-09-11 15:22:3299 virtual void BookmarkNodeAdded(BookmarkModel* model,
[email protected]b3c33d462009-06-26 22:29:20100 const BookmarkNode* parent,
[email protected]d364c652008-08-29 19:46:56101 int index) {}
[email protected]d8e41ed2008-09-11 15:22:32102 virtual void BookmarkNodeRemoved(BookmarkModel* model,
[email protected]b3c33d462009-06-26 22:29:20103 const BookmarkNode* parent,
[email protected]66965022009-07-15 17:20:01104 int old_index,
105 const BookmarkNode* node) {}
[email protected]d8e41ed2008-09-11 15:22:32106 virtual void BookmarkNodeChanged(BookmarkModel* model,
[email protected]b3c33d462009-06-26 22:29:20107 const BookmarkNode* node) {}
[email protected]58b359d2009-02-27 22:05:08108 virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
[email protected]b3c33d462009-06-26 22:29:20109 const BookmarkNode* node) {}
[email protected]abc2f262011-03-15 21:15:44110 virtual void BookmarkNodeFaviconLoaded(BookmarkModel* model,
[email protected]b3c33d462009-06-26 22:29:20111 const BookmarkNode* node) {}
[email protected]d364c652008-08-29 19:46:56112
113 private:
114 DISALLOW_COPY_AND_ASSIGN(BookmarkLoadObserver);
115};
116
[email protected]aeb53f02011-01-15 00:21:34117class TestExtensionURLRequestContext : public net::URLRequestContext {
[email protected]c10da4b02010-03-25 14:38:32118 public:
119 TestExtensionURLRequestContext() {
120 net::CookieMonster* cookie_monster = new net::CookieMonster(NULL, NULL);
121 const char* schemes[] = {chrome::kExtensionScheme};
122 cookie_monster->SetCookieableSchemes(schemes, 1);
[email protected]f6c21cb2011-02-16 19:45:41123 set_cookie_store(cookie_monster);
[email protected]c10da4b02010-03-25 14:38:32124 }
125};
126
127class TestExtensionURLRequestContextGetter : public URLRequestContextGetter {
128 public:
[email protected]aeb53f02011-01-15 00:21:34129 virtual net::URLRequestContext* GetURLRequestContext() {
[email protected]c10da4b02010-03-25 14:38:32130 if (!context_)
131 context_ = new TestExtensionURLRequestContext();
132 return context_.get();
133 }
[email protected]00ed48f2010-10-22 22:19:24134 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const {
[email protected]0c7d74f2010-10-11 11:55:26135 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
[email protected]83a7d2eb2010-05-03 21:46:19136 }
[email protected]c10da4b02010-03-25 14:38:32137
138 private:
[email protected]aeb53f02011-01-15 00:21:34139 scoped_refptr<net::URLRequestContext> context_;
[email protected]c10da4b02010-03-25 14:38:32140};
141
[email protected]d364c652008-08-29 19:46:56142} // namespace
143
[email protected]f25387b2008-08-21 15:20:33144TestingProfile::TestingProfile()
[email protected]ea6f76572008-12-18 00:09:55145 : start_time_(Time::Now()),
[email protected]2fb7dc982010-09-29 12:24:28146 testing_prefs_(NULL),
[email protected]ea6f76572008-12-18 00:09:55147 has_history_service_(false),
[email protected]5bb2f522011-03-25 19:04:44148 incognito_(false),
[email protected]ea6f76572008-12-18 00:09:55149 last_session_exited_cleanly_(true) {
[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]ab23dbe2010-08-12 02:10:46173}
174
[email protected]f25387b2008-08-21 15:20:33175TestingProfile::~TestingProfile() {
[email protected]d2879af2010-02-08 16:02:56176 NotificationService::current()->Notify(
177 NotificationType::PROFILE_DESTROYED,
178 Source<Profile>(this),
179 NotificationService::NoDetails());
[email protected]809cc4d2010-10-27 15:22:54180 DestroyTopSites();
[email protected]f25387b2008-08-21 15:20:33181 DestroyHistoryService();
[email protected]d2879af2010-02-08 16:02:56182 // FaviconService depends on HistoryServce so destroying it later.
183 DestroyFaviconService();
[email protected]2609bc12010-01-24 08:32:55184 DestroyWebDataService();
[email protected]2fb7dc982010-09-29 12:24:28185 if (extensions_service_.get()) {
186 extensions_service_->DestroyingProfile();
187 extensions_service_ = NULL;
188 }
[email protected]cc5bfd42010-11-24 14:44:02189 if (pref_proxy_config_tracker_.get())
190 pref_proxy_config_tracker_->DetachFromPrefService();
[email protected]f25387b2008-08-21 15:20:33191}
initial.commit09911bf2008-07-26 23:55:29192
[email protected]d2879af2010-02-08 16:02:56193void TestingProfile::CreateFaviconService() {
194 favicon_service_ = NULL;
195 favicon_service_ = new FaviconService(this);
196}
197
[email protected]d486a0852009-11-02 21:40:00198void TestingProfile::CreateHistoryService(bool delete_file, bool no_db) {
[email protected]809cc4d2010-10-27 15:22:54199 DestroyHistoryService();
[email protected]f25387b2008-08-21 15:20:33200 if (delete_file) {
[email protected]f7011fcb2009-01-28 21:54:32201 FilePath path = GetPath();
202 path = path.Append(chrome::kHistoryFilename);
[email protected]f25387b2008-08-21 15:20:33203 file_util::Delete(path, false);
204 }
[email protected]90ef13132008-08-27 03:27:46205 history_service_ = new HistoryService(this);
[email protected]d486a0852009-11-02 21:40:00206 history_service_->Init(GetPath(), bookmark_bar_model_.get(), no_db);
initial.commit09911bf2008-07-26 23:55:29207}
208
209void TestingProfile::DestroyHistoryService() {
210 if (!history_service_.get())
211 return;
212
213 history_service_->NotifyRenderProcessHostDestruction(0);
214 history_service_->SetOnBackendDestroyTask(new MessageLoop::QuitTask);
215 history_service_->Cleanup();
216 history_service_ = NULL;
217
218 // Wait for the backend class to terminate before deleting the files and
219 // moving to the next test. Note: if this never terminates, somebody is
220 // probably leaking a reference to the history backend, so it never calls
221 // our destroy task.
222 MessageLoop::current()->Run();
223
initial.commit09911bf2008-07-26 23:55:29224 // Make sure we don't have any event pending that could disrupt the next
225 // test.
226 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask);
227 MessageLoop::current()->Run();
228}
[email protected]4d0cd7ce2008-08-11 16:40:57229
[email protected]809cc4d2010-10-27 15:22:54230void TestingProfile::CreateTopSites() {
231 DestroyTopSites();
232 top_sites_ = new history::TopSites(this);
[email protected]73c47932010-12-06 18:13:43233 FilePath file_name = GetPath().Append(chrome::kTopSitesFilename);
[email protected]809cc4d2010-10-27 15:22:54234 top_sites_->Init(file_name);
235}
236
237void TestingProfile::DestroyTopSites() {
238 if (top_sites_.get()) {
239 top_sites_->Shutdown();
240 top_sites_ = NULL;
241 // TopSites::Shutdown schedules some tasks (from TopSitesBackend) that need
242 // to be run to properly shutdown. Run all pending tasks now. This is
243 // normally handled by browser_process shutdown.
244 if (MessageLoop::current())
245 MessageLoop::current()->RunAllPending();
246 }
247}
248
249void TestingProfile::DestroyFaviconService() {
250 if (!favicon_service_.get())
251 return;
252 favicon_service_ = NULL;
253}
254
[email protected]d8e41ed2008-09-11 15:22:32255void TestingProfile::CreateBookmarkModel(bool delete_file) {
[email protected]90ef13132008-08-27 03:27:46256 // Nuke the model first, that way we're sure it's done writing to disk.
257 bookmark_bar_model_.reset(NULL);
258
259 if (delete_file) {
[email protected]f7011fcb2009-01-28 21:54:32260 FilePath path = GetPath();
261 path = path.Append(chrome::kBookmarksFileName);
[email protected]90ef13132008-08-27 03:27:46262 file_util::Delete(path, false);
263 }
[email protected]d8e41ed2008-09-11 15:22:32264 bookmark_bar_model_.reset(new BookmarkModel(this));
[email protected]90ef13132008-08-27 03:27:46265 if (history_service_.get()) {
266 history_service_->history_backend_->bookmark_service_ =
267 bookmark_bar_model_.get();
268 history_service_->history_backend_->expirer_.bookmark_service_ =
269 bookmark_bar_model_.get();
270 }
271 bookmark_bar_model_->Load();
[email protected]4d0cd7ce2008-08-11 16:40:57272}
[email protected]d2c017a2008-08-13 21:51:45273
[email protected]69c579e2010-04-23 20:01:00274void TestingProfile::CreateAutocompleteClassifier() {
275 autocomplete_classifier_.reset(new AutocompleteClassifier(this));
276}
277
[email protected]a6d36cc2011-02-23 00:39:48278void TestingProfile::CreateProtocolHandlerRegistry() {
279 protocol_handler_registry_ = new ProtocolHandlerRegistry(this);
280}
281
[email protected]2609bc12010-01-24 08:32:55282void TestingProfile::CreateWebDataService(bool delete_file) {
283 if (web_data_service_.get())
284 web_data_service_->Shutdown();
285
286 if (delete_file) {
287 FilePath path = GetPath();
288 path = path.Append(chrome::kWebDataFilename);
289 file_util::Delete(path, false);
290 }
291
292 web_data_service_ = new WebDataService;
293 if (web_data_service_.get())
294 web_data_service_->Init(GetPath());
295}
296
[email protected]d364c652008-08-29 19:46:56297void TestingProfile::BlockUntilBookmarkModelLoaded() {
298 DCHECK(bookmark_bar_model_.get());
299 if (bookmark_bar_model_->IsLoaded())
300 return;
301 BookmarkLoadObserver observer;
302 bookmark_bar_model_->AddObserver(&observer);
303 MessageLoop::current()->Run();
304 bookmark_bar_model_->RemoveObserver(&observer);
305 DCHECK(bookmark_bar_model_->IsLoaded());
306}
307
[email protected]809cc4d2010-10-27 15:22:54308void TestingProfile::BlockUntilTopSitesLoaded() {
309 if (!GetHistoryService(Profile::EXPLICIT_ACCESS))
310 GetTopSites()->HistoryLoaded();
311 ui_test_utils::WaitForNotification(NotificationType::TOP_SITES_LOADED);
312}
313
[email protected]fb9d1f42010-10-06 23:17:59314void TestingProfile::CreateTemplateURLFetcher() {
315 template_url_fetcher_.reset(new TemplateURLFetcher(this));
316}
317
[email protected]d2c017a2008-08-13 21:51:45318void TestingProfile::CreateTemplateURLModel() {
[email protected]fb9d1f42010-10-06 23:17:59319 SetTemplateURLModel(new TemplateURLModel(this));
320}
321
322void TestingProfile::SetTemplateURLModel(TemplateURLModel* model) {
323 template_url_model_.reset(model);
[email protected]d2c017a2008-08-13 21:51:45324}
[email protected]0bfc29a2009-04-27 16:15:44325
[email protected]9a8c4022011-01-25 14:25:33326ExtensionService* TestingProfile::CreateExtensionService(
[email protected]2fb7dc982010-09-29 12:24:28327 const CommandLine* command_line,
328 const FilePath& install_directory) {
[email protected]9a8c4022011-01-25 14:25:33329 // Extension pref store, created for use by |extension_prefs_|.
330
331 extension_pref_value_map_.reset(new ExtensionPrefValueMap);
332 // Note that the GetPrefs() creates a TestingPrefService, therefore
333 // the extension controlled pref values set in extension_prefs_
334 // are not reflected in the pref service. One would need to
335 // inject a new ExtensionPrefStore(extension_pref_value_map_.get(), false).
336 extension_prefs_.reset(
337 new ExtensionPrefs(GetPrefs(),
338 install_directory,
339 extension_pref_value_map_.get()));
[email protected]eaa7dd182010-12-14 11:09:00340 extensions_service_ = new ExtensionService(this,
[email protected]9a8c4022011-01-25 14:25:33341 command_line,
342 install_directory,
343 extension_prefs_.get(),
344 false);
[email protected]2fb7dc982010-09-29 12:24:28345 return extensions_service_;
346}
347
[email protected]f9dec9482010-08-20 20:42:19348FilePath TestingProfile::GetPath() {
349 DCHECK(temp_dir_.IsValid()); // TODO(phajdan.jr): do it better.
350 return temp_dir_.path();
351}
352
[email protected]dbbad7a2010-08-13 18:18:36353TestingPrefService* TestingProfile::GetTestingPrefService() {
[email protected]2fb7dc982010-09-29 12:24:28354 if (!prefs_.get())
355 CreateTestingPrefService();
356 DCHECK(testing_prefs_);
357 return testing_prefs_;
[email protected]dbbad7a2010-08-13 18:18:36358}
359
[email protected]fadc607b62011-02-07 17:55:50360ProfileId TestingProfile::GetRuntimeId() {
361 return reinterpret_cast<ProfileId>(this);
362 }
363
364bool TestingProfile::IsOffTheRecord() {
[email protected]5bb2f522011-03-25 19:04:44365 return incognito_;
[email protected]fadc607b62011-02-07 17:55:50366}
367
[email protected]93dba942011-02-23 22:45:01368void TestingProfile::SetOffTheRecordProfile(Profile* profile) {
[email protected]5bb2f522011-03-25 19:04:44369 incognito_profile_.reset(profile);
[email protected]93dba942011-02-23 22:45:01370}
371
[email protected]fadc607b62011-02-07 17:55:50372Profile* TestingProfile::GetOffTheRecordProfile() {
[email protected]5bb2f522011-03-25 19:04:44373 return incognito_profile_.get();
[email protected]fadc607b62011-02-07 17:55:50374}
375
376bool TestingProfile::HasOffTheRecordProfile() {
[email protected]5bb2f522011-03-25 19:04:44377 return incognito_profile_.get() != NULL;
[email protected]fadc607b62011-02-07 17:55:50378}
379
380Profile* TestingProfile::GetOriginalProfile() {
381 return this;
382}
383
384ChromeAppCacheService* TestingProfile::GetAppCacheService() {
385 return NULL;
386}
387
[email protected]2f351cb2009-11-09 23:43:34388webkit_database::DatabaseTracker* TestingProfile::GetDatabaseTracker() {
[email protected]19eb80152011-02-26 00:28:43389 if (!db_tracker_) {
390 db_tracker_ = new webkit_database::DatabaseTracker(
391 GetPath(), false, GetExtensionSpecialStoragePolicy());
392 }
[email protected]2f351cb2009-11-09 23:43:34393 return db_tracker_;
394}
395
[email protected]fadc607b62011-02-07 17:55:50396VisitedLinkMaster* TestingProfile::GetVisitedLinkMaster() {
397 return NULL;
398}
399
[email protected]eaa7dd182010-12-14 11:09:00400ExtensionService* TestingProfile::GetExtensionService() {
[email protected]2fb7dc982010-09-29 12:24:28401 return extensions_service_.get();
402}
403
[email protected]fadc607b62011-02-07 17:55:50404UserScriptMaster* TestingProfile::GetUserScriptMaster() {
405 return NULL;
406}
407
408ExtensionDevToolsManager* TestingProfile::GetExtensionDevToolsManager() {
409 return NULL;
410}
411
412ExtensionProcessManager* TestingProfile::GetExtensionProcessManager() {
413 return NULL;
414}
415
416ExtensionMessageService* TestingProfile::GetExtensionMessageService() {
417 return NULL;
418}
419
420ExtensionEventRouter* TestingProfile::GetExtensionEventRouter() {
421 return NULL;
422}
423
[email protected]19eb80152011-02-26 00:28:43424ExtensionSpecialStoragePolicy*
425TestingProfile::GetExtensionSpecialStoragePolicy() {
426 if (!extension_special_storage_policy_)
427 extension_special_storage_policy_ = new ExtensionSpecialStoragePolicy();
428 return extension_special_storage_policy_;
429}
430
[email protected]fadc607b62011-02-07 17:55:50431SSLHostState* TestingProfile::GetSSLHostState() {
432 return NULL;
433}
434
435net::TransportSecurityState* TestingProfile::GetTransportSecurityState() {
436 return NULL;
437}
438
439FaviconService* TestingProfile::GetFaviconService(ServiceAccessType access) {
440 return favicon_service_.get();
441}
442
443HistoryService* TestingProfile::GetHistoryService(ServiceAccessType access) {
444 return history_service_.get();
445}
446
447HistoryService* TestingProfile::GetHistoryServiceWithoutCreating() {
448 return history_service_.get();
449}
450
[email protected]dbbad7a2010-08-13 18:18:36451net::CookieMonster* TestingProfile::GetCookieMonster() {
452 if (!GetRequestContext())
453 return NULL;
454 return GetRequestContext()->GetCookieStore()->GetCookieMonster();
455}
456
[email protected]fadc607b62011-02-07 17:55:50457AutocompleteClassifier* TestingProfile::GetAutocompleteClassifier() {
458 return autocomplete_classifier_.get();
459}
460
461WebDataService* TestingProfile::GetWebDataService(ServiceAccessType access) {
462 return web_data_service_.get();
463}
464
465WebDataService* TestingProfile::GetWebDataServiceWithoutCreating() {
466 return web_data_service_.get();
467}
468
469PasswordStore* TestingProfile::GetPasswordStore(ServiceAccessType access) {
470 return NULL;
471}
472
[email protected]2fb7dc982010-09-29 12:24:28473void TestingProfile::SetPrefService(PrefService* prefs) {
474 DCHECK(!prefs_.get());
475 prefs_.reset(prefs);
476}
477
478void TestingProfile::CreateTestingPrefService() {
479 DCHECK(!prefs_.get());
480 testing_prefs_ = new TestingPrefService();
481 prefs_.reset(testing_prefs_);
482 Profile::RegisterUserPrefs(prefs_.get());
[email protected]2f9d81322011-02-21 09:55:43483 browser::RegisterUserPrefs(prefs_.get());
[email protected]2fb7dc982010-09-29 12:24:28484}
485
[email protected]dbbad7a2010-08-13 18:18:36486PrefService* TestingProfile::GetPrefs() {
487 if (!prefs_.get()) {
[email protected]2fb7dc982010-09-29 12:24:28488 CreateTestingPrefService();
[email protected]dbbad7a2010-08-13 18:18:36489 }
490 return prefs_.get();
491}
492
[email protected]fadc607b62011-02-07 17:55:50493TemplateURLModel* TestingProfile::GetTemplateURLModel() {
494 return template_url_model_.get();
495}
496
497TemplateURLFetcher* TestingProfile::GetTemplateURLFetcher() {
498 return template_url_fetcher_.get();
499}
500
[email protected]dbbad7a2010-08-13 18:18:36501history::TopSites* TestingProfile::GetTopSites() {
[email protected]809cc4d2010-10-27 15:22:54502 return top_sites_.get();
[email protected]dbbad7a2010-08-13 18:18:36503}
504
[email protected]fadc607b62011-02-07 17:55:50505history::TopSites* TestingProfile::GetTopSitesWithoutCreating() {
506 return top_sites_.get();
507}
508
509DownloadManager* TestingProfile::GetDownloadManager() {
510 return NULL;
511}
512
513PersonalDataManager* TestingProfile::GetPersonalDataManager() {
514 return NULL;
515}
516
[email protected]397281f2011-02-14 05:15:53517fileapi::FileSystemContext* TestingProfile::GetFileSystemContext() {
[email protected]fadc607b62011-02-07 17:55:50518 return NULL;
519}
520
521BrowserSignin* TestingProfile::GetBrowserSignin() {
522 return NULL;
523}
524
525bool TestingProfile::HasCreatedDownloadManager() const {
526 return false;
527}
528
[email protected]812b3a32010-01-08 05:36:04529URLRequestContextGetter* TestingProfile::GetRequestContext() {
530 return request_context_.get();
531}
532
[email protected]d9696672011-03-15 22:45:09533URLRequestContextGetter* TestingProfile::GetRequestContextForPossibleApp(
534 const Extension* installed_app) {
535 if (installed_app != NULL && installed_app->is_storage_isolated())
536 return GetRequestContextForIsolatedApp(installed_app->id());
537
538 return GetRequestContext();
539}
540
[email protected]812b3a32010-01-08 05:36:04541void TestingProfile::CreateRequestContext() {
542 if (!request_context_)
543 request_context_ = new TestURLRequestContextGetter();
544}
545
[email protected]7c893202010-10-07 20:18:02546void TestingProfile::ResetRequestContext() {
547 request_context_ = NULL;
548}
549
[email protected]fadc607b62011-02-07 17:55:50550URLRequestContextGetter* TestingProfile::GetRequestContextForMedia() {
551 return NULL;
552}
553
[email protected]c10da4b02010-03-25 14:38:32554URLRequestContextGetter* TestingProfile::GetRequestContextForExtensions() {
555 if (!extensions_request_context_)
556 extensions_request_context_ = new TestExtensionURLRequestContextGetter();
557 return extensions_request_context_.get();
558}
559
[email protected]fadc607b62011-02-07 17:55:50560net::SSLConfigService* TestingProfile::GetSSLConfigService() {
561 return NULL;
562}
563
564UserStyleSheetWatcher* TestingProfile::GetUserStyleSheetWatcher() {
565 return NULL;
566}
567
[email protected]d9696672011-03-15 22:45:09568URLRequestContextGetter* TestingProfile::GetRequestContextForIsolatedApp(
569 const std::string& app_id) {
570 // We don't test isolated app storage here yet, so returning the same dummy
571 // context is sufficient for now.
572 return GetRequestContext();
573}
574
[email protected]dbbad7a2010-08-13 18:18:36575FindBarState* TestingProfile::GetFindBarState() {
576 if (!find_bar_state_.get())
577 find_bar_state_.reset(new FindBarState());
578 return find_bar_state_.get();
579}
580
581HostContentSettingsMap* TestingProfile::GetHostContentSettingsMap() {
582 if (!host_content_settings_map_.get())
583 host_content_settings_map_ = new HostContentSettingsMap(this);
584 return host_content_settings_map_.get();
585}
586
587GeolocationContentSettingsMap*
588TestingProfile::GetGeolocationContentSettingsMap() {
589 if (!geolocation_content_settings_map_.get()) {
590 geolocation_content_settings_map_ =
591 new GeolocationContentSettingsMap(this);
592 }
593 return geolocation_content_settings_map_.get();
594}
595
596GeolocationPermissionContext*
597TestingProfile::GetGeolocationPermissionContext() {
598 if (!geolocation_permission_context_.get()) {
599 geolocation_permission_context_ =
600 new GeolocationPermissionContext(this);
601 }
602 return geolocation_permission_context_.get();
603}
604
[email protected]fadc607b62011-02-07 17:55:50605HostZoomMap* TestingProfile::GetHostZoomMap() {
606 return NULL;
607}
608
609SessionService* TestingProfile::GetSessionService() {
610 return session_service_.get();
611}
612
613bool TestingProfile::HasSessionService() const {
614 return (session_service_.get() != NULL);
615}
616
617bool TestingProfile::HasProfileSyncService() const {
618 return (profile_sync_service_.get() != NULL);
619}
620
621std::wstring TestingProfile::GetName() {
622 return std::wstring();
623}
624
625std::wstring TestingProfile::GetID() {
626 return id_;
627}
628
629void TestingProfile::SetID(const std::wstring& id) {
630 id_ = id;
631}
632
633bool TestingProfile::DidLastSessionExitCleanly() {
634 return last_session_exited_cleanly_;
635}
636
637BookmarkModel* TestingProfile::GetBookmarkModel() {
638 return bookmark_bar_model_.get();
639}
640
641bool TestingProfile::IsSameProfile(Profile *p) {
642 return this == p;
643}
644
645base::Time TestingProfile::GetStartTime() const {
646 return start_time_;
647}
648
649TabRestoreService* TestingProfile::GetTabRestoreService() {
650 return NULL;
651}
652
[email protected]a6d36cc2011-02-23 00:39:48653ProtocolHandlerRegistry* TestingProfile::GetProtocolHandlerRegistry() {
654 return protocol_handler_registry_.get();
655}
656
[email protected]fadc607b62011-02-07 17:55:50657SpellCheckHost* TestingProfile::GetSpellCheckHost() {
658 return NULL;
659}
660
[email protected]8cb5d5b2010-02-09 11:36:16661void TestingProfile::set_session_service(SessionService* session_service) {
662 session_service_ = session_service;
663}
664
[email protected]dbbad7a2010-08-13 18:18:36665WebKitContext* TestingProfile::GetWebKitContext() {
666 if (webkit_context_ == NULL)
[email protected]5134417a2010-11-30 13:57:24667 webkit_context_ = new WebKitContext(this, false);
[email protected]dbbad7a2010-08-13 18:18:36668 return webkit_context_;
669}
670
[email protected]fadc607b62011-02-07 17:55:50671WebKitContext* TestingProfile::GetOffTheRecordWebKitContext() {
672 return NULL;
673}
674
[email protected]156ed27b2009-11-23 18:31:25675NTPResourceCache* TestingProfile::GetNTPResourceCache() {
676 if (!ntp_resource_cache_.get())
677 ntp_resource_cache_.reset(new NTPResourceCache(this));
678 return ntp_resource_cache_.get();
679}
680
[email protected]dbbad7a2010-08-13 18:18:36681DesktopNotificationService* TestingProfile::GetDesktopNotificationService() {
[email protected]0c7d74f2010-10-11 11:55:26682 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]dbbad7a2010-08-13 18:18:36683 if (!desktop_notification_service_.get()) {
684 desktop_notification_service_.reset(new DesktopNotificationService(
685 this, NULL));
686 }
687 return desktop_notification_service_.get();
688}
689
[email protected]fadc607b62011-02-07 17:55:50690BackgroundContentsService*
691TestingProfile::GetBackgroundContentsService() const {
692 return NULL;
693}
694
695StatusTray* TestingProfile::GetStatusTray() {
696 return NULL;
697}
698
699FilePath TestingProfile::last_selected_directory() {
700 return last_selected_directory_;
701}
702
703void TestingProfile::set_last_selected_directory(const FilePath& path) {
704 last_selected_directory_ = path;
705}
706
[email protected]cc5bfd42010-11-24 14:44:02707PrefProxyConfigTracker* TestingProfile::GetProxyConfigTracker() {
708 if (!pref_proxy_config_tracker_)
709 pref_proxy_config_tracker_ = new PrefProxyConfigTracker(GetPrefs());
710
711 return pref_proxy_config_tracker_;
712}
713
[email protected]0bfc29a2009-04-27 16:15:44714void TestingProfile::BlockUntilHistoryProcessesPendingRequests() {
715 DCHECK(history_service_.get());
716 DCHECK(MessageLoop::current());
717
718 CancelableRequestConsumer consumer;
719 history_service_->ScheduleDBTask(new QuittingHistoryDBTask(), &consumer);
720 MessageLoop::current()->Run();
721}
[email protected]345a8b72009-09-29 09:11:44722
[email protected]8e4c29612010-07-14 01:24:45723TokenService* TestingProfile::GetTokenService() {
724 if (!token_service_.get()) {
725 token_service_.reset(new TokenService());
726 }
727 return token_service_.get();
728}
729
[email protected]345a8b72009-09-29 09:11:44730ProfileSyncService* TestingProfile::GetProfileSyncService() {
[email protected]e8234d32010-09-09 20:36:39731 return GetProfileSyncService("");
732}
733
734ProfileSyncService* TestingProfile::GetProfileSyncService(
735 const std::string& cros_user) {
[email protected]4772b072010-03-30 17:45:46736 if (!profile_sync_service_.get()) {
[email protected]3c887412010-04-19 20:30:23737 // Use a NiceMock here since we are really using the mock as a
738 // fake. Test cases that want to set expectations on a
739 // ProfileSyncService should use the ProfileMock and have this
740 // method return their own mock instance.
741 profile_sync_service_.reset(new NiceMock<ProfileSyncServiceMock>());
[email protected]4772b072010-03-30 17:45:46742 }
[email protected]345a8b72009-09-29 09:11:44743 return profile_sync_service_.get();
[email protected]345a8b72009-09-29 09:11:44744}
[email protected]2609bc12010-01-24 08:32:55745
[email protected]fadc607b62011-02-07 17:55:50746CloudPrintProxyService* TestingProfile::GetCloudPrintProxyService() {
747 return NULL;
748}
749
750ChromeBlobStorageContext* TestingProfile::GetBlobStorageContext() {
751 return NULL;
752}
753
754ExtensionInfoMap* TestingProfile::GetExtensionInfoMap() {
755 return NULL;
756}
757
758PromoCounter* TestingProfile::GetInstantPromoCounter() {
759 return NULL;
760}
761
[email protected]985655a2011-02-23 09:54:25762policy::ProfilePolicyConnector* TestingProfile::GetPolicyConnector() {
[email protected]fadc607b62011-02-07 17:55:50763 return NULL;
764}
765
[email protected]248ce192011-02-10 15:26:34766ChromeURLDataManager* TestingProfile::GetChromeURLDataManager() {
767 if (!chrome_url_data_manager_.get())
768 chrome_url_data_manager_.reset(new ChromeURLDataManager(this));
769 return chrome_url_data_manager_.get();
770}
771
[email protected]4c154ff82011-02-15 11:23:59772prerender::PrerenderManager* TestingProfile::GetPrerenderManager() {
[email protected]4850a7f2011-03-08 23:36:59773 if (!prerender::PrerenderManager::IsPrerenderingEnabled())
774 return NULL;
775 if (!prerender_manager_)
776 prerender_manager_ = new prerender::PrerenderManager(this);
777 return prerender_manager_;
[email protected]fadc607b62011-02-07 17:55:50778}
779
780PrefService* TestingProfile::GetOffTheRecordPrefs() {
781 return NULL;
782}
783
[email protected]2609bc12010-01-24 08:32:55784void TestingProfile::DestroyWebDataService() {
785 if (!web_data_service_.get())
786 return;
787
788 web_data_service_->Shutdown();
789}
[email protected]a5add2c2011-02-14 23:54:47790
791DerivedTestingProfile::DerivedTestingProfile(Profile* profile)
792 : original_profile_(profile) {}
793
794DerivedTestingProfile::~DerivedTestingProfile() {}
795
796ProfileId DerivedTestingProfile::GetRuntimeId() {
797 return original_profile_->GetRuntimeId();
798}