blob: 606bfcb65acbac1ace7b54227d67fd4ffe89b82d [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]d2fad142011-04-15 10:18:4416#include "chrome/browser/background_contents_service_factory.h"
[email protected]a9afddb2009-02-12 17:49:4217#include "chrome/browser/bookmarks/bookmark_model.h"
[email protected]9d01a6a2010-11-30 12:03:3318#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]a6d36cc2011-02-23 00:39:4819#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
[email protected]2bb51302011-02-18 22:39:2720#include "chrome/browser/extensions/extension_pref_value_map.h"
[email protected]2f69b382011-02-19 00:34:2521#include "chrome/browser/extensions/extension_service.h"
[email protected]19eb80152011-02-26 00:28:4322#include "chrome/browser/extensions/extension_special_storage_policy.h"
[email protected]dbbad7a2010-08-13 18:18:3623#include "chrome/browser/favicon_service.h"
[email protected]dbbad7a2010-08-13 18:18:3624#include "chrome/browser/geolocation/geolocation_content_settings_map.h"
[email protected]dbbad7a2010-08-13 18:18:3625#include "chrome/browser/history/history.h"
[email protected]075ae732009-02-11 23:58:3126#include "chrome/browser/history/history_backend.h"
[email protected]dbbad7a2010-08-13 18:18:3627#include "chrome/browser/history/top_sites.h"
[email protected]8e4c29612010-07-14 01:24:4528#include "chrome/browser/net/gaia/token_service.h"
[email protected]cc5bfd42010-11-24 14:44:0229#include "chrome/browser/net/pref_proxy_config_service.h"
[email protected]dbbad7a2010-08-13 18:18:3630#include "chrome/browser/notifications/desktop_notification_service.h"
[email protected]dcb72d52011-04-13 12:36:5331#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]37858e52010-08-26 00:22:0232#include "chrome/browser/prefs/browser_prefs.h"
[email protected]9a8c4022011-01-25 14:25:3333#include "chrome/browser/prefs/testing_pref_store.h"
[email protected]4850a7f2011-03-08 23:36:5934#include "chrome/browser/prerender/prerender_manager.h"
[email protected]5cdcd152011-03-31 22:48:5235#include "chrome/browser/profiles/profile_dependency_manager.h"
[email protected]fb9d1f42010-10-06 23:17:5936#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]dbbad7a2010-08-13 18:18:3637#include "chrome/browser/search_engines/template_url_model.h"
[email protected]8cb5d5b2010-02-09 11:36:1638#include "chrome/browser/sessions/session_service.h"
[email protected]4772b072010-03-30 17:45:4639#include "chrome/browser/sync/profile_sync_service_mock.h"
[email protected]45300ad42010-12-02 15:51:1440#include "chrome/browser/ui/find_bar/find_bar_state.h"
[email protected]fd42ac30f2011-02-27 19:33:3641#include "chrome/browser/ui/webui/chrome_url_data_manager.h"
42#include "chrome/browser/ui/webui/ntp_resource_cache.h"
[email protected]a9afddb2009-02-12 17:49:4243#include "chrome/common/chrome_constants.h"
[email protected]dbbad7a2010-08-13 18:18:3644#include "chrome/common/url_constants.h"
[email protected]5138bbff2010-12-08 09:41:4445#include "chrome/test/test_url_request_context_getter.h"
[email protected]93270d002011-01-19 22:32:5946#include "chrome/test/testing_pref_service.h"
[email protected]809cc4d2010-10-27 15:22:5447#include "chrome/test/ui_test_utils.h"
[email protected]567812d2011-02-24 17:40:5048#include "content/browser/browser_thread.h"
[email protected]87678d992011-02-28 17:33:3049#include "content/browser/geolocation/geolocation_permission_context.h"
[email protected]567812d2011-02-24 17:40:5050#include "content/browser/in_process_webkit/webkit_context.h"
[email protected]e89b77d2011-04-15 18:58:1051#include "content/browser/mock_resource_context.h"
[email protected]7f070d42011-03-09 20:25:3252#include "content/common/notification_service.h"
[email protected]dbbad7a2010-08-13 18:18:3653#include "net/base/cookie_monster.h"
[email protected]812b3a32010-01-08 05:36:0454#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:3455#include "net/url_request/url_request_context_getter.h"
[email protected]d2db0292011-01-26 20:23:4456#include "net/url_request/url_request_test_util.h"
[email protected]4772b072010-03-30 17:45:4657#include "testing/gmock/include/gmock/gmock.h"
[email protected]2f351cb2009-11-09 23:43:3458#include "webkit/database/database_tracker.h"
[email protected]248ce192011-02-10 15:26:3459
[email protected]e1acf6f2008-10-27 20:43:3360using base::Time;
[email protected]3c887412010-04-19 20:30:2361using testing::NiceMock;
[email protected]4772b072010-03-30 17:45:4662using testing::Return;
[email protected]e1acf6f2008-10-27 20:43:3363
[email protected]d364c652008-08-29 19:46:5664namespace {
65
[email protected]0bfc29a2009-04-27 16:15:4466// Task used to make sure history has finished processing a request. Intended
67// for use with BlockUntilHistoryProcessesPendingRequests.
68
69class QuittingHistoryDBTask : public HistoryDBTask {
70 public:
71 QuittingHistoryDBTask() {}
72
73 virtual bool RunOnDBThread(history::HistoryBackend* backend,
74 history::HistoryDatabase* db) {
75 return true;
76 }
77
78 virtual void DoneRunOnMainThread() {
79 MessageLoop::current()->Quit();
80 }
81
82 private:
[email protected]7991a232009-11-06 01:55:4883 ~QuittingHistoryDBTask() {}
84
[email protected]0bfc29a2009-04-27 16:15:4485 DISALLOW_COPY_AND_ASSIGN(QuittingHistoryDBTask);
86};
87
[email protected]d8e41ed2008-09-11 15:22:3288// BookmarkLoadObserver is used when blocking until the BookmarkModel
89// finishes loading. As soon as the BookmarkModel finishes loading the message
90// loop is quit.
91class BookmarkLoadObserver : public BookmarkModelObserver {
[email protected]d364c652008-08-29 19:46:5692 public:
93 BookmarkLoadObserver() {}
[email protected]d8e41ed2008-09-11 15:22:3294 virtual void Loaded(BookmarkModel* model) {
[email protected]d364c652008-08-29 19:46:5695 MessageLoop::current()->Quit();
96 }
97
[email protected]d8e41ed2008-09-11 15:22:3298 virtual void BookmarkNodeMoved(BookmarkModel* model,
[email protected]b3c33d462009-06-26 22:29:2099 const BookmarkNode* old_parent,
[email protected]d364c652008-08-29 19:46:56100 int old_index,
[email protected]b3c33d462009-06-26 22:29:20101 const BookmarkNode* new_parent,
[email protected]d364c652008-08-29 19:46:56102 int new_index) {}
[email protected]d8e41ed2008-09-11 15:22:32103 virtual void BookmarkNodeAdded(BookmarkModel* model,
[email protected]b3c33d462009-06-26 22:29:20104 const BookmarkNode* parent,
[email protected]d364c652008-08-29 19:46:56105 int index) {}
[email protected]d8e41ed2008-09-11 15:22:32106 virtual void BookmarkNodeRemoved(BookmarkModel* model,
[email protected]b3c33d462009-06-26 22:29:20107 const BookmarkNode* parent,
[email protected]66965022009-07-15 17:20:01108 int old_index,
109 const BookmarkNode* node) {}
[email protected]d8e41ed2008-09-11 15:22:32110 virtual void BookmarkNodeChanged(BookmarkModel* model,
[email protected]b3c33d462009-06-26 22:29:20111 const BookmarkNode* node) {}
[email protected]58b359d2009-02-27 22:05:08112 virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
[email protected]b3c33d462009-06-26 22:29:20113 const BookmarkNode* node) {}
[email protected]abc2f262011-03-15 21:15:44114 virtual void BookmarkNodeFaviconLoaded(BookmarkModel* model,
[email protected]b3c33d462009-06-26 22:29:20115 const BookmarkNode* node) {}
[email protected]d364c652008-08-29 19:46:56116
117 private:
118 DISALLOW_COPY_AND_ASSIGN(BookmarkLoadObserver);
119};
120
[email protected]aeb53f02011-01-15 00:21:34121class TestExtensionURLRequestContext : public net::URLRequestContext {
[email protected]c10da4b02010-03-25 14:38:32122 public:
123 TestExtensionURLRequestContext() {
124 net::CookieMonster* cookie_monster = new net::CookieMonster(NULL, NULL);
125 const char* schemes[] = {chrome::kExtensionScheme};
126 cookie_monster->SetCookieableSchemes(schemes, 1);
[email protected]f6c21cb2011-02-16 19:45:41127 set_cookie_store(cookie_monster);
[email protected]c10da4b02010-03-25 14:38:32128 }
129};
130
[email protected]abe2c032011-03-31 18:49:34131class TestExtensionURLRequestContextGetter
132 : public net::URLRequestContextGetter {
[email protected]c10da4b02010-03-25 14:38:32133 public:
[email protected]aeb53f02011-01-15 00:21:34134 virtual net::URLRequestContext* GetURLRequestContext() {
[email protected]c10da4b02010-03-25 14:38:32135 if (!context_)
136 context_ = new TestExtensionURLRequestContext();
137 return context_.get();
138 }
[email protected]00ed48f2010-10-22 22:19:24139 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const {
[email protected]0c7d74f2010-10-11 11:55:26140 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
[email protected]83a7d2eb2010-05-03 21:46:19141 }
[email protected]c10da4b02010-03-25 14:38:32142
143 private:
[email protected]aeb53f02011-01-15 00:21:34144 scoped_refptr<net::URLRequestContext> context_;
[email protected]c10da4b02010-03-25 14:38:32145};
146
[email protected]dcb72d52011-04-13 12:36:53147ProfileKeyedService* CreateTestDesktopNotificationService(Profile* profile) {
148 return new DesktopNotificationService(profile, NULL);
149}
150
[email protected]d364c652008-08-29 19:46:56151} // namespace
152
[email protected]f25387b2008-08-21 15:20:33153TestingProfile::TestingProfile()
[email protected]ea6f76572008-12-18 00:09:55154 : start_time_(Time::Now()),
[email protected]2fb7dc982010-09-29 12:24:28155 testing_prefs_(NULL),
[email protected]5bb2f522011-03-25 19:04:44156 incognito_(false),
[email protected]5cdcd152011-03-31 22:48:52157 last_session_exited_cleanly_(true),
158 profile_dependency_manager_(ProfileDependencyManager::GetInstance()) {
[email protected]f9dec9482010-08-20 20:42:19159 if (!temp_dir_.CreateUniqueTempDir()) {
160 LOG(ERROR) << "Failed to create unique temporary directory.";
initial.commit09911bf2008-07-26 23:55:29161
[email protected]f9dec9482010-08-20 20:42:19162 // Fallback logic in case we fail to create unique temporary directory.
163 FilePath system_tmp_dir;
164 bool success = PathService::Get(base::DIR_TEMP, &system_tmp_dir);
[email protected]848cd05e2008-09-19 18:33:48165
[email protected]f9dec9482010-08-20 20:42:19166 // We're severly screwed if we can't get the system temporary
167 // directory. Die now to avoid writing to the filesystem root
168 // or other bad places.
169 CHECK(success);
170
171 FilePath fallback_dir(system_tmp_dir.AppendASCII("TestingProfilePath"));
172 file_util::Delete(fallback_dir, true);
173 file_util::CreateDirectory(fallback_dir);
174 if (!temp_dir_.Set(fallback_dir)) {
175 // That shouldn't happen, but if it does, try to recover.
176 LOG(ERROR) << "Failed to use a fallback temporary directory.";
177
178 // We're screwed if this fails, see CHECK above.
179 CHECK(temp_dir_.Set(system_tmp_dir));
180 }
181 }
[email protected]dcb72d52011-04-13 12:36:53182
183 // Install profile keyed service factory hooks for dummy/test services
[email protected]d2fad142011-04-15 10:18:44184 BackgroundContentsServiceFactory::GetInstance()->ForceAssociationBetween(
185 this, NULL);
[email protected]dcb72d52011-04-13 12:36:53186 DesktopNotificationServiceFactory::GetInstance()->set_test_factory(
187 &CreateTestDesktopNotificationService);
188 DesktopNotificationServiceFactory::GetInstance()->ForceAssociationBetween(
189 this, NULL);
[email protected]ab23dbe2010-08-12 02:10:46190}
191
[email protected]f25387b2008-08-21 15:20:33192TestingProfile::~TestingProfile() {
[email protected]d2879af2010-02-08 16:02:56193 NotificationService::current()->Notify(
194 NotificationType::PROFILE_DESTROYED,
[email protected]5cdcd152011-03-31 22:48:52195 Source<Profile>(static_cast<Profile*>(this)),
[email protected]d2879af2010-02-08 16:02:56196 NotificationService::NoDetails());
[email protected]5cdcd152011-03-31 22:48:52197
198 profile_dependency_manager_->DestroyProfileServices(this);
199
[email protected]809cc4d2010-10-27 15:22:54200 DestroyTopSites();
[email protected]f25387b2008-08-21 15:20:33201 DestroyHistoryService();
[email protected]d2879af2010-02-08 16:02:56202 // FaviconService depends on HistoryServce so destroying it later.
203 DestroyFaviconService();
[email protected]2609bc12010-01-24 08:32:55204 DestroyWebDataService();
[email protected]2fb7dc982010-09-29 12:24:28205 if (extensions_service_.get()) {
206 extensions_service_->DestroyingProfile();
207 extensions_service_ = NULL;
208 }
[email protected]cc5bfd42010-11-24 14:44:02209 if (pref_proxy_config_tracker_.get())
210 pref_proxy_config_tracker_->DetachFromPrefService();
[email protected]f25387b2008-08-21 15:20:33211}
initial.commit09911bf2008-07-26 23:55:29212
[email protected]d2879af2010-02-08 16:02:56213void TestingProfile::CreateFaviconService() {
214 favicon_service_ = NULL;
215 favicon_service_ = new FaviconService(this);
216}
217
[email protected]d486a0852009-11-02 21:40:00218void TestingProfile::CreateHistoryService(bool delete_file, bool no_db) {
[email protected]809cc4d2010-10-27 15:22:54219 DestroyHistoryService();
[email protected]f25387b2008-08-21 15:20:33220 if (delete_file) {
[email protected]f7011fcb2009-01-28 21:54:32221 FilePath path = GetPath();
222 path = path.Append(chrome::kHistoryFilename);
[email protected]f25387b2008-08-21 15:20:33223 file_util::Delete(path, false);
224 }
[email protected]90ef13132008-08-27 03:27:46225 history_service_ = new HistoryService(this);
[email protected]d486a0852009-11-02 21:40:00226 history_service_->Init(GetPath(), bookmark_bar_model_.get(), no_db);
initial.commit09911bf2008-07-26 23:55:29227}
228
229void TestingProfile::DestroyHistoryService() {
230 if (!history_service_.get())
231 return;
232
233 history_service_->NotifyRenderProcessHostDestruction(0);
234 history_service_->SetOnBackendDestroyTask(new MessageLoop::QuitTask);
235 history_service_->Cleanup();
236 history_service_ = NULL;
237
238 // Wait for the backend class to terminate before deleting the files and
239 // moving to the next test. Note: if this never terminates, somebody is
240 // probably leaking a reference to the history backend, so it never calls
241 // our destroy task.
242 MessageLoop::current()->Run();
243
initial.commit09911bf2008-07-26 23:55:29244 // Make sure we don't have any event pending that could disrupt the next
245 // test.
246 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask);
247 MessageLoop::current()->Run();
248}
[email protected]4d0cd7ce2008-08-11 16:40:57249
[email protected]809cc4d2010-10-27 15:22:54250void TestingProfile::CreateTopSites() {
251 DestroyTopSites();
252 top_sites_ = new history::TopSites(this);
[email protected]73c47932010-12-06 18:13:43253 FilePath file_name = GetPath().Append(chrome::kTopSitesFilename);
[email protected]809cc4d2010-10-27 15:22:54254 top_sites_->Init(file_name);
255}
256
257void TestingProfile::DestroyTopSites() {
258 if (top_sites_.get()) {
259 top_sites_->Shutdown();
260 top_sites_ = NULL;
261 // TopSites::Shutdown schedules some tasks (from TopSitesBackend) that need
262 // to be run to properly shutdown. Run all pending tasks now. This is
263 // normally handled by browser_process shutdown.
264 if (MessageLoop::current())
265 MessageLoop::current()->RunAllPending();
266 }
267}
268
269void TestingProfile::DestroyFaviconService() {
270 if (!favicon_service_.get())
271 return;
272 favicon_service_ = NULL;
273}
274
[email protected]d8e41ed2008-09-11 15:22:32275void TestingProfile::CreateBookmarkModel(bool delete_file) {
[email protected]90ef13132008-08-27 03:27:46276 // Nuke the model first, that way we're sure it's done writing to disk.
277 bookmark_bar_model_.reset(NULL);
278
279 if (delete_file) {
[email protected]f7011fcb2009-01-28 21:54:32280 FilePath path = GetPath();
281 path = path.Append(chrome::kBookmarksFileName);
[email protected]90ef13132008-08-27 03:27:46282 file_util::Delete(path, false);
283 }
[email protected]d8e41ed2008-09-11 15:22:32284 bookmark_bar_model_.reset(new BookmarkModel(this));
[email protected]90ef13132008-08-27 03:27:46285 if (history_service_.get()) {
286 history_service_->history_backend_->bookmark_service_ =
287 bookmark_bar_model_.get();
288 history_service_->history_backend_->expirer_.bookmark_service_ =
289 bookmark_bar_model_.get();
290 }
291 bookmark_bar_model_->Load();
[email protected]4d0cd7ce2008-08-11 16:40:57292}
[email protected]d2c017a2008-08-13 21:51:45293
[email protected]69c579e2010-04-23 20:01:00294void TestingProfile::CreateAutocompleteClassifier() {
295 autocomplete_classifier_.reset(new AutocompleteClassifier(this));
296}
297
[email protected]a6d36cc2011-02-23 00:39:48298void TestingProfile::CreateProtocolHandlerRegistry() {
[email protected]66904272011-04-14 06:06:14299 protocol_handler_registry_ = new ProtocolHandlerRegistry(this);
[email protected]a6d36cc2011-02-23 00:39:48300}
301
[email protected]2609bc12010-01-24 08:32:55302void TestingProfile::CreateWebDataService(bool delete_file) {
303 if (web_data_service_.get())
304 web_data_service_->Shutdown();
305
306 if (delete_file) {
307 FilePath path = GetPath();
308 path = path.Append(chrome::kWebDataFilename);
309 file_util::Delete(path, false);
310 }
311
312 web_data_service_ = new WebDataService;
313 if (web_data_service_.get())
314 web_data_service_->Init(GetPath());
315}
316
[email protected]d364c652008-08-29 19:46:56317void TestingProfile::BlockUntilBookmarkModelLoaded() {
318 DCHECK(bookmark_bar_model_.get());
319 if (bookmark_bar_model_->IsLoaded())
320 return;
321 BookmarkLoadObserver observer;
322 bookmark_bar_model_->AddObserver(&observer);
323 MessageLoop::current()->Run();
324 bookmark_bar_model_->RemoveObserver(&observer);
325 DCHECK(bookmark_bar_model_->IsLoaded());
326}
327
[email protected]809cc4d2010-10-27 15:22:54328void TestingProfile::BlockUntilTopSitesLoaded() {
329 if (!GetHistoryService(Profile::EXPLICIT_ACCESS))
330 GetTopSites()->HistoryLoaded();
331 ui_test_utils::WaitForNotification(NotificationType::TOP_SITES_LOADED);
332}
333
[email protected]fb9d1f42010-10-06 23:17:59334void TestingProfile::CreateTemplateURLFetcher() {
335 template_url_fetcher_.reset(new TemplateURLFetcher(this));
336}
337
[email protected]d2c017a2008-08-13 21:51:45338void TestingProfile::CreateTemplateURLModel() {
[email protected]fb9d1f42010-10-06 23:17:59339 SetTemplateURLModel(new TemplateURLModel(this));
340}
341
342void TestingProfile::SetTemplateURLModel(TemplateURLModel* model) {
343 template_url_model_.reset(model);
[email protected]d2c017a2008-08-13 21:51:45344}
[email protected]0bfc29a2009-04-27 16:15:44345
[email protected]9a8c4022011-01-25 14:25:33346ExtensionService* TestingProfile::CreateExtensionService(
[email protected]2fb7dc982010-09-29 12:24:28347 const CommandLine* command_line,
[email protected]90310d92011-04-17 07:35:04348 const FilePath& install_directory,
349 bool autoupdate_enabled) {
[email protected]9a8c4022011-01-25 14:25:33350 // Extension pref store, created for use by |extension_prefs_|.
351
352 extension_pref_value_map_.reset(new ExtensionPrefValueMap);
353 // Note that the GetPrefs() creates a TestingPrefService, therefore
354 // the extension controlled pref values set in extension_prefs_
355 // are not reflected in the pref service. One would need to
356 // inject a new ExtensionPrefStore(extension_pref_value_map_.get(), false).
357 extension_prefs_.reset(
358 new ExtensionPrefs(GetPrefs(),
359 install_directory,
360 extension_pref_value_map_.get()));
[email protected]eaa7dd182010-12-14 11:09:00361 extensions_service_ = new ExtensionService(this,
[email protected]9a8c4022011-01-25 14:25:33362 command_line,
363 install_directory,
364 extension_prefs_.get(),
[email protected]90310d92011-04-17 07:35:04365 autoupdate_enabled,
[email protected]0436b102011-04-15 18:30:03366 true);
[email protected]2fb7dc982010-09-29 12:24:28367 return extensions_service_;
368}
369
[email protected]f9dec9482010-08-20 20:42:19370FilePath TestingProfile::GetPath() {
371 DCHECK(temp_dir_.IsValid()); // TODO(phajdan.jr): do it better.
372 return temp_dir_.path();
373}
374
[email protected]dbbad7a2010-08-13 18:18:36375TestingPrefService* TestingProfile::GetTestingPrefService() {
[email protected]2fb7dc982010-09-29 12:24:28376 if (!prefs_.get())
377 CreateTestingPrefService();
378 DCHECK(testing_prefs_);
379 return testing_prefs_;
[email protected]dbbad7a2010-08-13 18:18:36380}
381
[email protected]fadc607b62011-02-07 17:55:50382ProfileId TestingProfile::GetRuntimeId() {
383 return reinterpret_cast<ProfileId>(this);
384 }
385
386bool TestingProfile::IsOffTheRecord() {
[email protected]5bb2f522011-03-25 19:04:44387 return incognito_;
[email protected]fadc607b62011-02-07 17:55:50388}
389
[email protected]93dba942011-02-23 22:45:01390void TestingProfile::SetOffTheRecordProfile(Profile* profile) {
[email protected]5bb2f522011-03-25 19:04:44391 incognito_profile_.reset(profile);
[email protected]93dba942011-02-23 22:45:01392}
393
[email protected]fadc607b62011-02-07 17:55:50394Profile* TestingProfile::GetOffTheRecordProfile() {
[email protected]5bb2f522011-03-25 19:04:44395 return incognito_profile_.get();
[email protected]fadc607b62011-02-07 17:55:50396}
397
398bool TestingProfile::HasOffTheRecordProfile() {
[email protected]5bb2f522011-03-25 19:04:44399 return incognito_profile_.get() != NULL;
[email protected]fadc607b62011-02-07 17:55:50400}
401
402Profile* TestingProfile::GetOriginalProfile() {
403 return this;
404}
405
406ChromeAppCacheService* TestingProfile::GetAppCacheService() {
407 return NULL;
408}
409
[email protected]2f351cb2009-11-09 23:43:34410webkit_database::DatabaseTracker* TestingProfile::GetDatabaseTracker() {
[email protected]19eb80152011-02-26 00:28:43411 if (!db_tracker_) {
412 db_tracker_ = new webkit_database::DatabaseTracker(
413 GetPath(), false, GetExtensionSpecialStoragePolicy());
414 }
[email protected]2f351cb2009-11-09 23:43:34415 return db_tracker_;
416}
417
[email protected]fadc607b62011-02-07 17:55:50418VisitedLinkMaster* TestingProfile::GetVisitedLinkMaster() {
419 return NULL;
420}
421
[email protected]eaa7dd182010-12-14 11:09:00422ExtensionService* TestingProfile::GetExtensionService() {
[email protected]2fb7dc982010-09-29 12:24:28423 return extensions_service_.get();
424}
425
[email protected]fadc607b62011-02-07 17:55:50426UserScriptMaster* TestingProfile::GetUserScriptMaster() {
427 return NULL;
428}
429
430ExtensionDevToolsManager* TestingProfile::GetExtensionDevToolsManager() {
431 return NULL;
432}
433
434ExtensionProcessManager* TestingProfile::GetExtensionProcessManager() {
435 return NULL;
436}
437
438ExtensionMessageService* TestingProfile::GetExtensionMessageService() {
439 return NULL;
440}
441
442ExtensionEventRouter* TestingProfile::GetExtensionEventRouter() {
443 return NULL;
444}
445
[email protected]19eb80152011-02-26 00:28:43446ExtensionSpecialStoragePolicy*
447TestingProfile::GetExtensionSpecialStoragePolicy() {
448 if (!extension_special_storage_policy_)
449 extension_special_storage_policy_ = new ExtensionSpecialStoragePolicy();
450 return extension_special_storage_policy_;
451}
452
[email protected]fadc607b62011-02-07 17:55:50453SSLHostState* TestingProfile::GetSSLHostState() {
454 return NULL;
455}
456
457net::TransportSecurityState* TestingProfile::GetTransportSecurityState() {
458 return NULL;
459}
460
461FaviconService* TestingProfile::GetFaviconService(ServiceAccessType access) {
462 return favicon_service_.get();
463}
464
465HistoryService* TestingProfile::GetHistoryService(ServiceAccessType access) {
466 return history_service_.get();
467}
468
469HistoryService* TestingProfile::GetHistoryServiceWithoutCreating() {
470 return history_service_.get();
471}
472
[email protected]dbbad7a2010-08-13 18:18:36473net::CookieMonster* TestingProfile::GetCookieMonster() {
474 if (!GetRequestContext())
475 return NULL;
[email protected]277ec262011-03-30 21:09:40476 return GetRequestContext()->GetURLRequestContext()->cookie_store()->
477 GetCookieMonster();
[email protected]dbbad7a2010-08-13 18:18:36478}
479
[email protected]fadc607b62011-02-07 17:55:50480AutocompleteClassifier* TestingProfile::GetAutocompleteClassifier() {
481 return autocomplete_classifier_.get();
482}
483
484WebDataService* TestingProfile::GetWebDataService(ServiceAccessType access) {
485 return web_data_service_.get();
486}
487
488WebDataService* TestingProfile::GetWebDataServiceWithoutCreating() {
489 return web_data_service_.get();
490}
491
492PasswordStore* TestingProfile::GetPasswordStore(ServiceAccessType access) {
493 return NULL;
494}
495
[email protected]2fb7dc982010-09-29 12:24:28496void TestingProfile::SetPrefService(PrefService* prefs) {
497 DCHECK(!prefs_.get());
498 prefs_.reset(prefs);
499}
500
501void TestingProfile::CreateTestingPrefService() {
502 DCHECK(!prefs_.get());
503 testing_prefs_ = new TestingPrefService();
504 prefs_.reset(testing_prefs_);
505 Profile::RegisterUserPrefs(prefs_.get());
[email protected]2f9d81322011-02-21 09:55:43506 browser::RegisterUserPrefs(prefs_.get());
[email protected]2fb7dc982010-09-29 12:24:28507}
508
[email protected]dbbad7a2010-08-13 18:18:36509PrefService* TestingProfile::GetPrefs() {
510 if (!prefs_.get()) {
[email protected]2fb7dc982010-09-29 12:24:28511 CreateTestingPrefService();
[email protected]dbbad7a2010-08-13 18:18:36512 }
513 return prefs_.get();
514}
515
[email protected]fadc607b62011-02-07 17:55:50516TemplateURLModel* TestingProfile::GetTemplateURLModel() {
517 return template_url_model_.get();
518}
519
520TemplateURLFetcher* TestingProfile::GetTemplateURLFetcher() {
521 return template_url_fetcher_.get();
522}
523
[email protected]dbbad7a2010-08-13 18:18:36524history::TopSites* TestingProfile::GetTopSites() {
[email protected]809cc4d2010-10-27 15:22:54525 return top_sites_.get();
[email protected]dbbad7a2010-08-13 18:18:36526}
527
[email protected]fadc607b62011-02-07 17:55:50528history::TopSites* TestingProfile::GetTopSitesWithoutCreating() {
529 return top_sites_.get();
530}
531
532DownloadManager* TestingProfile::GetDownloadManager() {
533 return NULL;
534}
535
536PersonalDataManager* TestingProfile::GetPersonalDataManager() {
537 return NULL;
538}
539
[email protected]397281f2011-02-14 05:15:53540fileapi::FileSystemContext* TestingProfile::GetFileSystemContext() {
[email protected]fadc607b62011-02-07 17:55:50541 return NULL;
542}
543
544BrowserSignin* TestingProfile::GetBrowserSignin() {
545 return NULL;
546}
547
548bool TestingProfile::HasCreatedDownloadManager() const {
549 return false;
550}
551
[email protected]abe2c032011-03-31 18:49:34552net::URLRequestContextGetter* TestingProfile::GetRequestContext() {
[email protected]812b3a32010-01-08 05:36:04553 return request_context_.get();
554}
555
[email protected]abe2c032011-03-31 18:49:34556net::URLRequestContextGetter* TestingProfile::GetRequestContextForPossibleApp(
[email protected]d9696672011-03-15 22:45:09557 const Extension* installed_app) {
558 if (installed_app != NULL && installed_app->is_storage_isolated())
559 return GetRequestContextForIsolatedApp(installed_app->id());
560
561 return GetRequestContext();
562}
563
[email protected]812b3a32010-01-08 05:36:04564void TestingProfile::CreateRequestContext() {
565 if (!request_context_)
566 request_context_ = new TestURLRequestContextGetter();
567}
568
[email protected]7c893202010-10-07 20:18:02569void TestingProfile::ResetRequestContext() {
570 request_context_ = NULL;
571}
572
[email protected]abe2c032011-03-31 18:49:34573net::URLRequestContextGetter* TestingProfile::GetRequestContextForMedia() {
[email protected]fadc607b62011-02-07 17:55:50574 return NULL;
575}
576
[email protected]abe2c032011-03-31 18:49:34577net::URLRequestContextGetter* TestingProfile::GetRequestContextForExtensions() {
[email protected]c10da4b02010-03-25 14:38:32578 if (!extensions_request_context_)
579 extensions_request_context_ = new TestExtensionURLRequestContextGetter();
580 return extensions_request_context_.get();
581}
582
[email protected]fadc607b62011-02-07 17:55:50583net::SSLConfigService* TestingProfile::GetSSLConfigService() {
584 return NULL;
585}
586
587UserStyleSheetWatcher* TestingProfile::GetUserStyleSheetWatcher() {
588 return NULL;
589}
590
[email protected]abe2c032011-03-31 18:49:34591net::URLRequestContextGetter* TestingProfile::GetRequestContextForIsolatedApp(
[email protected]d9696672011-03-15 22:45:09592 const std::string& app_id) {
593 // We don't test isolated app storage here yet, so returning the same dummy
594 // context is sufficient for now.
595 return GetRequestContext();
596}
597
[email protected]e89b77d2011-04-15 18:58:10598const content::ResourceContext& TestingProfile::GetResourceContext() {
599 return content::MockResourceContext::GetInstance();
600}
601
[email protected]dbbad7a2010-08-13 18:18:36602FindBarState* TestingProfile::GetFindBarState() {
603 if (!find_bar_state_.get())
604 find_bar_state_.reset(new FindBarState());
605 return find_bar_state_.get();
606}
607
608HostContentSettingsMap* TestingProfile::GetHostContentSettingsMap() {
609 if (!host_content_settings_map_.get())
610 host_content_settings_map_ = new HostContentSettingsMap(this);
611 return host_content_settings_map_.get();
612}
613
614GeolocationContentSettingsMap*
615TestingProfile::GetGeolocationContentSettingsMap() {
616 if (!geolocation_content_settings_map_.get()) {
617 geolocation_content_settings_map_ =
618 new GeolocationContentSettingsMap(this);
619 }
620 return geolocation_content_settings_map_.get();
621}
622
623GeolocationPermissionContext*
624TestingProfile::GetGeolocationPermissionContext() {
625 if (!geolocation_permission_context_.get()) {
626 geolocation_permission_context_ =
627 new GeolocationPermissionContext(this);
628 }
629 return geolocation_permission_context_.get();
630}
631
[email protected]fadc607b62011-02-07 17:55:50632HostZoomMap* TestingProfile::GetHostZoomMap() {
633 return NULL;
634}
635
636SessionService* TestingProfile::GetSessionService() {
637 return session_service_.get();
638}
639
640bool TestingProfile::HasSessionService() const {
641 return (session_service_.get() != NULL);
642}
643
644bool TestingProfile::HasProfileSyncService() const {
645 return (profile_sync_service_.get() != NULL);
646}
647
648std::wstring TestingProfile::GetName() {
649 return std::wstring();
650}
651
652std::wstring TestingProfile::GetID() {
653 return id_;
654}
655
656void TestingProfile::SetID(const std::wstring& id) {
657 id_ = id;
658}
659
660bool TestingProfile::DidLastSessionExitCleanly() {
661 return last_session_exited_cleanly_;
662}
663
664BookmarkModel* TestingProfile::GetBookmarkModel() {
665 return bookmark_bar_model_.get();
666}
667
668bool TestingProfile::IsSameProfile(Profile *p) {
669 return this == p;
670}
671
672base::Time TestingProfile::GetStartTime() const {
673 return start_time_;
674}
675
676TabRestoreService* TestingProfile::GetTabRestoreService() {
677 return NULL;
678}
679
[email protected]a6d36cc2011-02-23 00:39:48680ProtocolHandlerRegistry* TestingProfile::GetProtocolHandlerRegistry() {
681 return protocol_handler_registry_.get();
682}
683
[email protected]fadc607b62011-02-07 17:55:50684SpellCheckHost* TestingProfile::GetSpellCheckHost() {
685 return NULL;
686}
687
[email protected]8cb5d5b2010-02-09 11:36:16688void TestingProfile::set_session_service(SessionService* session_service) {
689 session_service_ = session_service;
690}
691
[email protected]dbbad7a2010-08-13 18:18:36692WebKitContext* TestingProfile::GetWebKitContext() {
[email protected]228d06592011-04-01 20:38:59693 if (webkit_context_ == NULL) {
694 webkit_context_ = new WebKitContext(
695 IsOffTheRecord(), GetPath(),
696 GetExtensionSpecialStoragePolicy(),
697 false);
698 }
[email protected]dbbad7a2010-08-13 18:18:36699 return webkit_context_;
700}
701
[email protected]fadc607b62011-02-07 17:55:50702WebKitContext* TestingProfile::GetOffTheRecordWebKitContext() {
703 return NULL;
704}
705
[email protected]156ed27b2009-11-23 18:31:25706NTPResourceCache* TestingProfile::GetNTPResourceCache() {
707 if (!ntp_resource_cache_.get())
708 ntp_resource_cache_.reset(new NTPResourceCache(this));
709 return ntp_resource_cache_.get();
710}
711
[email protected]fadc607b62011-02-07 17:55:50712StatusTray* TestingProfile::GetStatusTray() {
713 return NULL;
714}
715
716FilePath TestingProfile::last_selected_directory() {
717 return last_selected_directory_;
718}
719
720void TestingProfile::set_last_selected_directory(const FilePath& path) {
721 last_selected_directory_ = path;
722}
723
[email protected]cc5bfd42010-11-24 14:44:02724PrefProxyConfigTracker* TestingProfile::GetProxyConfigTracker() {
725 if (!pref_proxy_config_tracker_)
726 pref_proxy_config_tracker_ = new PrefProxyConfigTracker(GetPrefs());
727
728 return pref_proxy_config_tracker_;
729}
730
[email protected]0bfc29a2009-04-27 16:15:44731void TestingProfile::BlockUntilHistoryProcessesPendingRequests() {
732 DCHECK(history_service_.get());
733 DCHECK(MessageLoop::current());
734
735 CancelableRequestConsumer consumer;
736 history_service_->ScheduleDBTask(new QuittingHistoryDBTask(), &consumer);
737 MessageLoop::current()->Run();
738}
[email protected]345a8b72009-09-29 09:11:44739
[email protected]8e4c29612010-07-14 01:24:45740TokenService* TestingProfile::GetTokenService() {
741 if (!token_service_.get()) {
742 token_service_.reset(new TokenService());
743 }
744 return token_service_.get();
745}
746
[email protected]345a8b72009-09-29 09:11:44747ProfileSyncService* TestingProfile::GetProfileSyncService() {
[email protected]e8234d32010-09-09 20:36:39748 return GetProfileSyncService("");
749}
750
751ProfileSyncService* TestingProfile::GetProfileSyncService(
752 const std::string& cros_user) {
[email protected]4772b072010-03-30 17:45:46753 if (!profile_sync_service_.get()) {
[email protected]3c887412010-04-19 20:30:23754 // Use a NiceMock here since we are really using the mock as a
755 // fake. Test cases that want to set expectations on a
756 // ProfileSyncService should use the ProfileMock and have this
757 // method return their own mock instance.
758 profile_sync_service_.reset(new NiceMock<ProfileSyncServiceMock>());
[email protected]4772b072010-03-30 17:45:46759 }
[email protected]345a8b72009-09-29 09:11:44760 return profile_sync_service_.get();
[email protected]345a8b72009-09-29 09:11:44761}
[email protected]2609bc12010-01-24 08:32:55762
[email protected]fadc607b62011-02-07 17:55:50763CloudPrintProxyService* TestingProfile::GetCloudPrintProxyService() {
764 return NULL;
765}
766
767ChromeBlobStorageContext* TestingProfile::GetBlobStorageContext() {
768 return NULL;
769}
770
771ExtensionInfoMap* TestingProfile::GetExtensionInfoMap() {
772 return NULL;
773}
774
775PromoCounter* TestingProfile::GetInstantPromoCounter() {
776 return NULL;
777}
778
[email protected]985655a2011-02-23 09:54:25779policy::ProfilePolicyConnector* TestingProfile::GetPolicyConnector() {
[email protected]fadc607b62011-02-07 17:55:50780 return NULL;
781}
782
[email protected]248ce192011-02-10 15:26:34783ChromeURLDataManager* TestingProfile::GetChromeURLDataManager() {
784 if (!chrome_url_data_manager_.get())
785 chrome_url_data_manager_.reset(new ChromeURLDataManager(this));
786 return chrome_url_data_manager_.get();
787}
788
[email protected]4c154ff82011-02-15 11:23:59789prerender::PrerenderManager* TestingProfile::GetPrerenderManager() {
[email protected]503c1cf2011-03-31 12:36:34790 if (!prerender::PrerenderManager::IsPrerenderingPossible())
[email protected]4850a7f2011-03-08 23:36:59791 return NULL;
792 if (!prerender_manager_)
793 prerender_manager_ = new prerender::PrerenderManager(this);
794 return prerender_manager_;
[email protected]fadc607b62011-02-07 17:55:50795}
796
797PrefService* TestingProfile::GetOffTheRecordPrefs() {
798 return NULL;
799}
800
[email protected]36fb2c7c2011-04-04 15:49:08801quota::SpecialStoragePolicy* TestingProfile::GetSpecialStoragePolicy() {
802 return GetExtensionSpecialStoragePolicy();
803}
804
[email protected]2609bc12010-01-24 08:32:55805void TestingProfile::DestroyWebDataService() {
806 if (!web_data_service_.get())
807 return;
808
809 web_data_service_->Shutdown();
810}
[email protected]a5add2c2011-02-14 23:54:47811
812DerivedTestingProfile::DerivedTestingProfile(Profile* profile)
813 : original_profile_(profile) {}
814
815DerivedTestingProfile::~DerivedTestingProfile() {}
816
817ProfileId DerivedTestingProfile::GetRuntimeId() {
818 return original_profile_->GetRuntimeId();
819}