blob: 9ddc8d1f86bb4405d0076d2cfe6981fd4dd8eb9b [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]8281e48e2010-10-12 18:54:4917#include "chrome/browser/browser_thread.h"
[email protected]9d01a6a2010-11-30 12:03:3318#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]248ce192011-02-10 15:26:3419#include "chrome/browser/dom_ui/chrome_url_data_manager.h"
[email protected]156ed27b2009-11-23 18:31:2520#include "chrome/browser/dom_ui/ntp_resource_cache.h"
[email protected]eaa7dd182010-12-14 11:09:0021#include "chrome/browser/extensions/extension_service.h"
[email protected]9a8c4022011-01-25 14:25:3322#include "chrome/browser/extensions/extension_pref_value_map.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"
25#include "chrome/browser/geolocation/geolocation_permission_context.h"
26#include "chrome/browser/history/history.h"
[email protected]075ae732009-02-11 23:58:3127#include "chrome/browser/history/history_backend.h"
[email protected]dbbad7a2010-08-13 18:18:3628#include "chrome/browser/history/top_sites.h"
[email protected]b071b6c2010-08-25 20:28:0329#include "chrome/browser/in_process_webkit/webkit_context.h"
[email protected]8e4c29612010-07-14 01:24:4530#include "chrome/browser/net/gaia/token_service.h"
[email protected]cc5bfd42010-11-24 14:44:0231#include "chrome/browser/net/pref_proxy_config_service.h"
[email protected]dbbad7a2010-08-13 18:18:3632#include "chrome/browser/notifications/desktop_notification_service.h"
[email protected]37858e52010-08-26 00:22:0233#include "chrome/browser/prefs/browser_prefs.h"
[email protected]9a8c4022011-01-25 14:25:3334#include "chrome/browser/prefs/testing_pref_store.h"
[email protected]fb9d1f42010-10-06 23:17:5935#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]dbbad7a2010-08-13 18:18:3636#include "chrome/browser/search_engines/template_url_model.h"
[email protected]8cb5d5b2010-02-09 11:36:1637#include "chrome/browser/sessions/session_service.h"
[email protected]4772b072010-03-30 17:45:4638#include "chrome/browser/sync/profile_sync_service_mock.h"
[email protected]b071b6c2010-08-25 20:28:0339#include "chrome/browser/themes/browser_theme_provider.h"
[email protected]45300ad42010-12-02 15:51:1440#include "chrome/browser/ui/find_bar/find_bar_state.h"
[email protected]a9afddb2009-02-12 17:49:4241#include "chrome/common/chrome_constants.h"
[email protected]68d2a05f2010-05-07 21:39:5542#include "chrome/common/net/url_request_context_getter.h"
[email protected]d2879af2010-02-08 16:02:5643#include "chrome/common/notification_service.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]dbbad7a2010-08-13 18:18:3648#include "net/base/cookie_monster.h"
[email protected]812b3a32010-01-08 05:36:0449#include "net/url_request/url_request_context.h"
[email protected]d2db0292011-01-26 20:23:4450#include "net/url_request/url_request_test_util.h"
[email protected]4772b072010-03-30 17:45:4651#include "testing/gmock/include/gmock/gmock.h"
[email protected]2f351cb2009-11-09 23:43:3452#include "webkit/database/database_tracker.h"
[email protected]248ce192011-02-10 15:26:3453
[email protected]a42b5592009-09-03 16:52:2354#if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS)
[email protected]93270d002011-01-19 22:32:5955#include "chrome/browser/ui/gtk/gtk_theme_provider.h"
[email protected]a42b5592009-09-03 16:52:2356#endif
57
[email protected]e1acf6f2008-10-27 20:43:3358using base::Time;
[email protected]3c887412010-04-19 20:30:2359using testing::NiceMock;
[email protected]4772b072010-03-30 17:45:4660using testing::Return;
[email protected]e1acf6f2008-10-27 20:43:3361
[email protected]d364c652008-08-29 19:46:5662namespace {
63
[email protected]0bfc29a2009-04-27 16:15:4464// Task used to make sure history has finished processing a request. Intended
65// for use with BlockUntilHistoryProcessesPendingRequests.
66
67class QuittingHistoryDBTask : public HistoryDBTask {
68 public:
69 QuittingHistoryDBTask() {}
70
71 virtual bool RunOnDBThread(history::HistoryBackend* backend,
72 history::HistoryDatabase* db) {
73 return true;
74 }
75
76 virtual void DoneRunOnMainThread() {
77 MessageLoop::current()->Quit();
78 }
79
80 private:
[email protected]7991a232009-11-06 01:55:4881 ~QuittingHistoryDBTask() {}
82
[email protected]0bfc29a2009-04-27 16:15:4483 DISALLOW_COPY_AND_ASSIGN(QuittingHistoryDBTask);
84};
85
[email protected]d8e41ed2008-09-11 15:22:3286// BookmarkLoadObserver is used when blocking until the BookmarkModel
87// finishes loading. As soon as the BookmarkModel finishes loading the message
88// loop is quit.
89class BookmarkLoadObserver : public BookmarkModelObserver {
[email protected]d364c652008-08-29 19:46:5690 public:
91 BookmarkLoadObserver() {}
[email protected]d8e41ed2008-09-11 15:22:3292 virtual void Loaded(BookmarkModel* model) {
[email protected]d364c652008-08-29 19:46:5693 MessageLoop::current()->Quit();
94 }
95
[email protected]d8e41ed2008-09-11 15:22:3296 virtual void BookmarkNodeMoved(BookmarkModel* model,
[email protected]b3c33d462009-06-26 22:29:2097 const BookmarkNode* old_parent,
[email protected]d364c652008-08-29 19:46:5698 int old_index,
[email protected]b3c33d462009-06-26 22:29:2099 const BookmarkNode* new_parent,
[email protected]d364c652008-08-29 19:46:56100 int new_index) {}
[email protected]d8e41ed2008-09-11 15:22:32101 virtual void BookmarkNodeAdded(BookmarkModel* model,
[email protected]b3c33d462009-06-26 22:29:20102 const BookmarkNode* parent,
[email protected]d364c652008-08-29 19:46:56103 int index) {}
[email protected]d8e41ed2008-09-11 15:22:32104 virtual void BookmarkNodeRemoved(BookmarkModel* model,
[email protected]b3c33d462009-06-26 22:29:20105 const BookmarkNode* parent,
[email protected]66965022009-07-15 17:20:01106 int old_index,
107 const BookmarkNode* node) {}
[email protected]d8e41ed2008-09-11 15:22:32108 virtual void BookmarkNodeChanged(BookmarkModel* model,
[email protected]b3c33d462009-06-26 22:29:20109 const BookmarkNode* node) {}
[email protected]58b359d2009-02-27 22:05:08110 virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
[email protected]b3c33d462009-06-26 22:29:20111 const BookmarkNode* node) {}
[email protected]d8e41ed2008-09-11 15:22:32112 virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
[email protected]b3c33d462009-06-26 22:29:20113 const BookmarkNode* node) {}
[email protected]d364c652008-08-29 19:46:56114
115 private:
116 DISALLOW_COPY_AND_ASSIGN(BookmarkLoadObserver);
117};
118
[email protected]aeb53f02011-01-15 00:21:34119class TestExtensionURLRequestContext : public net::URLRequestContext {
[email protected]c10da4b02010-03-25 14:38:32120 public:
121 TestExtensionURLRequestContext() {
122 net::CookieMonster* cookie_monster = new net::CookieMonster(NULL, NULL);
123 const char* schemes[] = {chrome::kExtensionScheme};
124 cookie_monster->SetCookieableSchemes(schemes, 1);
[email protected]182fe2f2011-02-14 20:35:15125 cookie_store_ = cookie_monster;
[email protected]c10da4b02010-03-25 14:38:32126 }
127};
128
129class TestExtensionURLRequestContextGetter : public URLRequestContextGetter {
130 public:
[email protected]aeb53f02011-01-15 00:21:34131 virtual net::URLRequestContext* GetURLRequestContext() {
[email protected]c10da4b02010-03-25 14:38:32132 if (!context_)
133 context_ = new TestExtensionURLRequestContext();
134 return context_.get();
135 }
[email protected]00ed48f2010-10-22 22:19:24136 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const {
[email protected]0c7d74f2010-10-11 11:55:26137 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
[email protected]83a7d2eb2010-05-03 21:46:19138 }
[email protected]c10da4b02010-03-25 14:38:32139
140 private:
[email protected]aeb53f02011-01-15 00:21:34141 scoped_refptr<net::URLRequestContext> context_;
[email protected]c10da4b02010-03-25 14:38:32142};
143
[email protected]d364c652008-08-29 19:46:56144} // namespace
145
[email protected]f25387b2008-08-21 15:20:33146TestingProfile::TestingProfile()
[email protected]ea6f76572008-12-18 00:09:55147 : start_time_(Time::Now()),
[email protected]2fb7dc982010-09-29 12:24:28148 testing_prefs_(NULL),
[email protected]a42b5592009-09-03 16:52:23149 created_theme_provider_(false),
[email protected]ea6f76572008-12-18 00:09:55150 has_history_service_(false),
151 off_the_record_(false),
152 last_session_exited_cleanly_(true) {
[email protected]f9dec9482010-08-20 20:42:19153 if (!temp_dir_.CreateUniqueTempDir()) {
154 LOG(ERROR) << "Failed to create unique temporary directory.";
initial.commit09911bf2008-07-26 23:55:29155
[email protected]f9dec9482010-08-20 20:42:19156 // Fallback logic in case we fail to create unique temporary directory.
157 FilePath system_tmp_dir;
158 bool success = PathService::Get(base::DIR_TEMP, &system_tmp_dir);
[email protected]848cd05e2008-09-19 18:33:48159
[email protected]f9dec9482010-08-20 20:42:19160 // We're severly screwed if we can't get the system temporary
161 // directory. Die now to avoid writing to the filesystem root
162 // or other bad places.
163 CHECK(success);
164
165 FilePath fallback_dir(system_tmp_dir.AppendASCII("TestingProfilePath"));
166 file_util::Delete(fallback_dir, true);
167 file_util::CreateDirectory(fallback_dir);
168 if (!temp_dir_.Set(fallback_dir)) {
169 // That shouldn't happen, but if it does, try to recover.
170 LOG(ERROR) << "Failed to use a fallback temporary directory.";
171
172 // We're screwed if this fails, see CHECK above.
173 CHECK(temp_dir_.Set(system_tmp_dir));
174 }
175 }
[email protected]ab23dbe2010-08-12 02:10:46176}
177
[email protected]f25387b2008-08-21 15:20:33178TestingProfile::~TestingProfile() {
[email protected]d2879af2010-02-08 16:02:56179 NotificationService::current()->Notify(
180 NotificationType::PROFILE_DESTROYED,
181 Source<Profile>(this),
182 NotificationService::NoDetails());
[email protected]809cc4d2010-10-27 15:22:54183 DestroyTopSites();
[email protected]f25387b2008-08-21 15:20:33184 DestroyHistoryService();
[email protected]d2879af2010-02-08 16:02:56185 // FaviconService depends on HistoryServce so destroying it later.
186 DestroyFaviconService();
[email protected]2609bc12010-01-24 08:32:55187 DestroyWebDataService();
[email protected]2fb7dc982010-09-29 12:24:28188 if (extensions_service_.get()) {
189 extensions_service_->DestroyingProfile();
190 extensions_service_ = NULL;
191 }
[email protected]cc5bfd42010-11-24 14:44:02192 if (pref_proxy_config_tracker_.get())
193 pref_proxy_config_tracker_->DetachFromPrefService();
[email protected]f25387b2008-08-21 15:20:33194}
initial.commit09911bf2008-07-26 23:55:29195
[email protected]d2879af2010-02-08 16:02:56196void TestingProfile::CreateFaviconService() {
197 favicon_service_ = NULL;
198 favicon_service_ = new FaviconService(this);
199}
200
[email protected]d486a0852009-11-02 21:40:00201void TestingProfile::CreateHistoryService(bool delete_file, bool no_db) {
[email protected]809cc4d2010-10-27 15:22:54202 DestroyHistoryService();
[email protected]f25387b2008-08-21 15:20:33203 if (delete_file) {
[email protected]f7011fcb2009-01-28 21:54:32204 FilePath path = GetPath();
205 path = path.Append(chrome::kHistoryFilename);
[email protected]f25387b2008-08-21 15:20:33206 file_util::Delete(path, false);
207 }
[email protected]90ef13132008-08-27 03:27:46208 history_service_ = new HistoryService(this);
[email protected]d486a0852009-11-02 21:40:00209 history_service_->Init(GetPath(), bookmark_bar_model_.get(), no_db);
initial.commit09911bf2008-07-26 23:55:29210}
211
212void TestingProfile::DestroyHistoryService() {
213 if (!history_service_.get())
214 return;
215
216 history_service_->NotifyRenderProcessHostDestruction(0);
217 history_service_->SetOnBackendDestroyTask(new MessageLoop::QuitTask);
218 history_service_->Cleanup();
219 history_service_ = NULL;
220
221 // Wait for the backend class to terminate before deleting the files and
222 // moving to the next test. Note: if this never terminates, somebody is
223 // probably leaking a reference to the history backend, so it never calls
224 // our destroy task.
225 MessageLoop::current()->Run();
226
initial.commit09911bf2008-07-26 23:55:29227 // Make sure we don't have any event pending that could disrupt the next
228 // test.
229 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask);
230 MessageLoop::current()->Run();
231}
[email protected]4d0cd7ce2008-08-11 16:40:57232
[email protected]809cc4d2010-10-27 15:22:54233void TestingProfile::CreateTopSites() {
234 DestroyTopSites();
235 top_sites_ = new history::TopSites(this);
[email protected]73c47932010-12-06 18:13:43236 FilePath file_name = GetPath().Append(chrome::kTopSitesFilename);
[email protected]809cc4d2010-10-27 15:22:54237 top_sites_->Init(file_name);
238}
239
240void TestingProfile::DestroyTopSites() {
241 if (top_sites_.get()) {
242 top_sites_->Shutdown();
243 top_sites_ = NULL;
244 // TopSites::Shutdown schedules some tasks (from TopSitesBackend) that need
245 // to be run to properly shutdown. Run all pending tasks now. This is
246 // normally handled by browser_process shutdown.
247 if (MessageLoop::current())
248 MessageLoop::current()->RunAllPending();
249 }
250}
251
252void TestingProfile::DestroyFaviconService() {
253 if (!favicon_service_.get())
254 return;
255 favicon_service_ = NULL;
256}
257
[email protected]d8e41ed2008-09-11 15:22:32258void TestingProfile::CreateBookmarkModel(bool delete_file) {
[email protected]90ef13132008-08-27 03:27:46259 // Nuke the model first, that way we're sure it's done writing to disk.
260 bookmark_bar_model_.reset(NULL);
261
262 if (delete_file) {
[email protected]f7011fcb2009-01-28 21:54:32263 FilePath path = GetPath();
264 path = path.Append(chrome::kBookmarksFileName);
[email protected]90ef13132008-08-27 03:27:46265 file_util::Delete(path, false);
266 }
[email protected]d8e41ed2008-09-11 15:22:32267 bookmark_bar_model_.reset(new BookmarkModel(this));
[email protected]90ef13132008-08-27 03:27:46268 if (history_service_.get()) {
269 history_service_->history_backend_->bookmark_service_ =
270 bookmark_bar_model_.get();
271 history_service_->history_backend_->expirer_.bookmark_service_ =
272 bookmark_bar_model_.get();
273 }
274 bookmark_bar_model_->Load();
[email protected]4d0cd7ce2008-08-11 16:40:57275}
[email protected]d2c017a2008-08-13 21:51:45276
[email protected]69c579e2010-04-23 20:01:00277void TestingProfile::CreateAutocompleteClassifier() {
278 autocomplete_classifier_.reset(new AutocompleteClassifier(this));
279}
280
[email protected]2609bc12010-01-24 08:32:55281void TestingProfile::CreateWebDataService(bool delete_file) {
282 if (web_data_service_.get())
283 web_data_service_->Shutdown();
284
285 if (delete_file) {
286 FilePath path = GetPath();
287 path = path.Append(chrome::kWebDataFilename);
288 file_util::Delete(path, false);
289 }
290
291 web_data_service_ = new WebDataService;
292 if (web_data_service_.get())
293 web_data_service_->Init(GetPath());
294}
295
[email protected]d364c652008-08-29 19:46:56296void TestingProfile::BlockUntilBookmarkModelLoaded() {
297 DCHECK(bookmark_bar_model_.get());
298 if (bookmark_bar_model_->IsLoaded())
299 return;
300 BookmarkLoadObserver observer;
301 bookmark_bar_model_->AddObserver(&observer);
302 MessageLoop::current()->Run();
303 bookmark_bar_model_->RemoveObserver(&observer);
304 DCHECK(bookmark_bar_model_->IsLoaded());
305}
306
[email protected]809cc4d2010-10-27 15:22:54307void TestingProfile::BlockUntilTopSitesLoaded() {
308 if (!GetHistoryService(Profile::EXPLICIT_ACCESS))
309 GetTopSites()->HistoryLoaded();
310 ui_test_utils::WaitForNotification(NotificationType::TOP_SITES_LOADED);
311}
312
[email protected]fb9d1f42010-10-06 23:17:59313void TestingProfile::CreateTemplateURLFetcher() {
314 template_url_fetcher_.reset(new TemplateURLFetcher(this));
315}
316
[email protected]d2c017a2008-08-13 21:51:45317void TestingProfile::CreateTemplateURLModel() {
[email protected]fb9d1f42010-10-06 23:17:59318 SetTemplateURLModel(new TemplateURLModel(this));
319}
320
321void TestingProfile::SetTemplateURLModel(TemplateURLModel* model) {
322 template_url_model_.reset(model);
[email protected]d2c017a2008-08-13 21:51:45323}
[email protected]0bfc29a2009-04-27 16:15:44324
[email protected]a42b5592009-09-03 16:52:23325void TestingProfile::UseThemeProvider(BrowserThemeProvider* theme_provider) {
326 theme_provider->Init(this);
327 created_theme_provider_ = true;
[email protected]761962c2009-09-25 00:18:15328 theme_provider_.reset(theme_provider);
[email protected]a42b5592009-09-03 16:52:23329}
330
[email protected]9a8c4022011-01-25 14:25:33331ExtensionService* TestingProfile::CreateExtensionService(
[email protected]2fb7dc982010-09-29 12:24:28332 const CommandLine* command_line,
333 const FilePath& install_directory) {
[email protected]9a8c4022011-01-25 14:25:33334 // Extension pref store, created for use by |extension_prefs_|.
335
336 extension_pref_value_map_.reset(new ExtensionPrefValueMap);
337 // Note that the GetPrefs() creates a TestingPrefService, therefore
338 // the extension controlled pref values set in extension_prefs_
339 // are not reflected in the pref service. One would need to
340 // inject a new ExtensionPrefStore(extension_pref_value_map_.get(), false).
341 extension_prefs_.reset(
342 new ExtensionPrefs(GetPrefs(),
343 install_directory,
344 extension_pref_value_map_.get()));
[email protected]eaa7dd182010-12-14 11:09:00345 extensions_service_ = new ExtensionService(this,
[email protected]9a8c4022011-01-25 14:25:33346 command_line,
347 install_directory,
348 extension_prefs_.get(),
349 false);
[email protected]2fb7dc982010-09-29 12:24:28350 return extensions_service_;
351}
352
[email protected]f9dec9482010-08-20 20:42:19353FilePath TestingProfile::GetPath() {
354 DCHECK(temp_dir_.IsValid()); // TODO(phajdan.jr): do it better.
355 return temp_dir_.path();
356}
357
[email protected]dbbad7a2010-08-13 18:18:36358TestingPrefService* TestingProfile::GetTestingPrefService() {
[email protected]2fb7dc982010-09-29 12:24:28359 if (!prefs_.get())
360 CreateTestingPrefService();
361 DCHECK(testing_prefs_);
362 return testing_prefs_;
[email protected]dbbad7a2010-08-13 18:18:36363}
364
[email protected]fadc607b62011-02-07 17:55:50365ProfileId TestingProfile::GetRuntimeId() {
366 return reinterpret_cast<ProfileId>(this);
367 }
368
369bool TestingProfile::IsOffTheRecord() {
370 return off_the_record_;
371}
372
373Profile* TestingProfile::GetOffTheRecordProfile() {
374 return NULL;
375}
376
377bool TestingProfile::HasOffTheRecordProfile() {
378 return false;
379}
380
381Profile* TestingProfile::GetOriginalProfile() {
382 return this;
383}
384
385ChromeAppCacheService* TestingProfile::GetAppCacheService() {
386 return NULL;
387}
388
[email protected]2f351cb2009-11-09 23:43:34389webkit_database::DatabaseTracker* TestingProfile::GetDatabaseTracker() {
390 if (!db_tracker_)
[email protected]fe615f32010-06-13 09:08:41391 db_tracker_ = new webkit_database::DatabaseTracker(GetPath(), false);
[email protected]2f351cb2009-11-09 23:43:34392 return db_tracker_;
393}
394
[email protected]fadc607b62011-02-07 17:55:50395VisitedLinkMaster* TestingProfile::GetVisitedLinkMaster() {
396 return NULL;
397}
398
[email protected]eaa7dd182010-12-14 11:09:00399ExtensionService* TestingProfile::GetExtensionService() {
[email protected]2fb7dc982010-09-29 12:24:28400 return extensions_service_.get();
401}
402
[email protected]fadc607b62011-02-07 17:55:50403UserScriptMaster* TestingProfile::GetUserScriptMaster() {
404 return NULL;
405}
406
407ExtensionDevToolsManager* TestingProfile::GetExtensionDevToolsManager() {
408 return NULL;
409}
410
411ExtensionProcessManager* TestingProfile::GetExtensionProcessManager() {
412 return NULL;
413}
414
415ExtensionMessageService* TestingProfile::GetExtensionMessageService() {
416 return NULL;
417}
418
419ExtensionEventRouter* TestingProfile::GetExtensionEventRouter() {
420 return NULL;
421}
422
423ExtensionIOEventRouter* TestingProfile::GetExtensionIOEventRouter() {
424 return NULL;
425}
426
427SSLHostState* TestingProfile::GetSSLHostState() {
428 return NULL;
429}
430
431net::TransportSecurityState* TestingProfile::GetTransportSecurityState() {
432 return NULL;
433}
434
435FaviconService* TestingProfile::GetFaviconService(ServiceAccessType access) {
436 return favicon_service_.get();
437}
438
439HistoryService* TestingProfile::GetHistoryService(ServiceAccessType access) {
440 return history_service_.get();
441}
442
443HistoryService* TestingProfile::GetHistoryServiceWithoutCreating() {
444 return history_service_.get();
445}
446
[email protected]dbbad7a2010-08-13 18:18:36447net::CookieMonster* TestingProfile::GetCookieMonster() {
448 if (!GetRequestContext())
449 return NULL;
450 return GetRequestContext()->GetCookieStore()->GetCookieMonster();
451}
452
[email protected]fadc607b62011-02-07 17:55:50453AutocompleteClassifier* TestingProfile::GetAutocompleteClassifier() {
454 return autocomplete_classifier_.get();
455}
456
457WebDataService* TestingProfile::GetWebDataService(ServiceAccessType access) {
458 return web_data_service_.get();
459}
460
461WebDataService* TestingProfile::GetWebDataServiceWithoutCreating() {
462 return web_data_service_.get();
463}
464
465PasswordStore* TestingProfile::GetPasswordStore(ServiceAccessType access) {
466 return NULL;
467}
468
[email protected]a42b5592009-09-03 16:52:23469void TestingProfile::InitThemes() {
470 if (!created_theme_provider_) {
471#if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS)
[email protected]761962c2009-09-25 00:18:15472 theme_provider_.reset(new GtkThemeProvider);
[email protected]a42b5592009-09-03 16:52:23473#else
[email protected]761962c2009-09-25 00:18:15474 theme_provider_.reset(new BrowserThemeProvider);
[email protected]a42b5592009-09-03 16:52:23475#endif
[email protected]761962c2009-09-25 00:18:15476 theme_provider_->Init(this);
[email protected]a42b5592009-09-03 16:52:23477 created_theme_provider_ = true;
[email protected]a42b5592009-09-03 16:52:23478 }
[email protected]76688082009-05-16 07:04:42479}
480
[email protected]fadc607b62011-02-07 17:55:50481const Extension* TestingProfile::GetTheme() {
482 return NULL;
483}
484
485BrowserThemeProvider* TestingProfile::GetThemeProvider() {
486 InitThemes();
487 return theme_provider_.get();
488}
489
[email protected]2fb7dc982010-09-29 12:24:28490void TestingProfile::SetPrefService(PrefService* prefs) {
491 DCHECK(!prefs_.get());
492 prefs_.reset(prefs);
493}
494
495void TestingProfile::CreateTestingPrefService() {
496 DCHECK(!prefs_.get());
497 testing_prefs_ = new TestingPrefService();
498 prefs_.reset(testing_prefs_);
499 Profile::RegisterUserPrefs(prefs_.get());
500 browser::RegisterAllPrefs(prefs_.get(), prefs_.get());
501}
502
[email protected]dbbad7a2010-08-13 18:18:36503PrefService* TestingProfile::GetPrefs() {
504 if (!prefs_.get()) {
[email protected]2fb7dc982010-09-29 12:24:28505 CreateTestingPrefService();
[email protected]dbbad7a2010-08-13 18:18:36506 }
507 return prefs_.get();
508}
509
[email protected]fadc607b62011-02-07 17:55:50510TemplateURLModel* TestingProfile::GetTemplateURLModel() {
511 return template_url_model_.get();
512}
513
514TemplateURLFetcher* TestingProfile::GetTemplateURLFetcher() {
515 return template_url_fetcher_.get();
516}
517
[email protected]dbbad7a2010-08-13 18:18:36518history::TopSites* TestingProfile::GetTopSites() {
[email protected]809cc4d2010-10-27 15:22:54519 return top_sites_.get();
[email protected]dbbad7a2010-08-13 18:18:36520}
521
[email protected]fadc607b62011-02-07 17:55:50522history::TopSites* TestingProfile::GetTopSitesWithoutCreating() {
523 return top_sites_.get();
524}
525
526DownloadManager* TestingProfile::GetDownloadManager() {
527 return NULL;
528}
529
530PersonalDataManager* TestingProfile::GetPersonalDataManager() {
531 return NULL;
532}
533
[email protected]397281f2011-02-14 05:15:53534fileapi::FileSystemContext* TestingProfile::GetFileSystemContext() {
[email protected]fadc607b62011-02-07 17:55:50535 return NULL;
536}
537
538BrowserSignin* TestingProfile::GetBrowserSignin() {
539 return NULL;
540}
541
542bool TestingProfile::HasCreatedDownloadManager() const {
543 return false;
544}
545
[email protected]812b3a32010-01-08 05:36:04546URLRequestContextGetter* TestingProfile::GetRequestContext() {
547 return request_context_.get();
548}
549
550void TestingProfile::CreateRequestContext() {
551 if (!request_context_)
552 request_context_ = new TestURLRequestContextGetter();
553}
554
[email protected]7c893202010-10-07 20:18:02555void TestingProfile::ResetRequestContext() {
556 request_context_ = NULL;
557}
558
[email protected]fadc607b62011-02-07 17:55:50559URLRequestContextGetter* TestingProfile::GetRequestContextForMedia() {
560 return NULL;
561}
562
[email protected]c10da4b02010-03-25 14:38:32563URLRequestContextGetter* TestingProfile::GetRequestContextForExtensions() {
564 if (!extensions_request_context_)
565 extensions_request_context_ = new TestExtensionURLRequestContextGetter();
566 return extensions_request_context_.get();
567}
568
[email protected]fadc607b62011-02-07 17:55:50569net::SSLConfigService* TestingProfile::GetSSLConfigService() {
570 return NULL;
571}
572
573UserStyleSheetWatcher* TestingProfile::GetUserStyleSheetWatcher() {
574 return NULL;
575}
576
[email protected]dbbad7a2010-08-13 18:18:36577FindBarState* TestingProfile::GetFindBarState() {
578 if (!find_bar_state_.get())
579 find_bar_state_.reset(new FindBarState());
580 return find_bar_state_.get();
581}
582
583HostContentSettingsMap* TestingProfile::GetHostContentSettingsMap() {
584 if (!host_content_settings_map_.get())
585 host_content_settings_map_ = new HostContentSettingsMap(this);
586 return host_content_settings_map_.get();
587}
588
589GeolocationContentSettingsMap*
590TestingProfile::GetGeolocationContentSettingsMap() {
591 if (!geolocation_content_settings_map_.get()) {
592 geolocation_content_settings_map_ =
593 new GeolocationContentSettingsMap(this);
594 }
595 return geolocation_content_settings_map_.get();
596}
597
598GeolocationPermissionContext*
599TestingProfile::GetGeolocationPermissionContext() {
600 if (!geolocation_permission_context_.get()) {
601 geolocation_permission_context_ =
602 new GeolocationPermissionContext(this);
603 }
604 return geolocation_permission_context_.get();
605}
606
[email protected]fadc607b62011-02-07 17:55:50607HostZoomMap* TestingProfile::GetHostZoomMap() {
608 return NULL;
609}
610
611SessionService* TestingProfile::GetSessionService() {
612 return session_service_.get();
613}
614
615bool TestingProfile::HasSessionService() const {
616 return (session_service_.get() != NULL);
617}
618
619bool TestingProfile::HasProfileSyncService() const {
620 return (profile_sync_service_.get() != NULL);
621}
622
623std::wstring TestingProfile::GetName() {
624 return std::wstring();
625}
626
627std::wstring TestingProfile::GetID() {
628 return id_;
629}
630
631void TestingProfile::SetID(const std::wstring& id) {
632 id_ = id;
633}
634
635bool TestingProfile::DidLastSessionExitCleanly() {
636 return last_session_exited_cleanly_;
637}
638
639BookmarkModel* TestingProfile::GetBookmarkModel() {
640 return bookmark_bar_model_.get();
641}
642
643bool TestingProfile::IsSameProfile(Profile *p) {
644 return this == p;
645}
646
647base::Time TestingProfile::GetStartTime() const {
648 return start_time_;
649}
650
651TabRestoreService* TestingProfile::GetTabRestoreService() {
652 return NULL;
653}
654
655SpellCheckHost* TestingProfile::GetSpellCheckHost() {
656 return NULL;
657}
658
[email protected]8cb5d5b2010-02-09 11:36:16659void TestingProfile::set_session_service(SessionService* session_service) {
660 session_service_ = session_service;
661}
662
[email protected]dbbad7a2010-08-13 18:18:36663WebKitContext* TestingProfile::GetWebKitContext() {
664 if (webkit_context_ == NULL)
[email protected]5134417a2010-11-30 13:57:24665 webkit_context_ = new WebKitContext(this, false);
[email protected]dbbad7a2010-08-13 18:18:36666 return webkit_context_;
667}
668
[email protected]fadc607b62011-02-07 17:55:50669WebKitContext* TestingProfile::GetOffTheRecordWebKitContext() {
670 return NULL;
671}
672
[email protected]156ed27b2009-11-23 18:31:25673NTPResourceCache* TestingProfile::GetNTPResourceCache() {
674 if (!ntp_resource_cache_.get())
675 ntp_resource_cache_.reset(new NTPResourceCache(this));
676 return ntp_resource_cache_.get();
677}
678
[email protected]dbbad7a2010-08-13 18:18:36679DesktopNotificationService* TestingProfile::GetDesktopNotificationService() {
[email protected]0c7d74f2010-10-11 11:55:26680 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]dbbad7a2010-08-13 18:18:36681 if (!desktop_notification_service_.get()) {
682 desktop_notification_service_.reset(new DesktopNotificationService(
683 this, NULL));
684 }
685 return desktop_notification_service_.get();
686}
687
[email protected]fadc607b62011-02-07 17:55:50688BackgroundContentsService*
689TestingProfile::GetBackgroundContentsService() const {
690 return NULL;
691}
692
693StatusTray* TestingProfile::GetStatusTray() {
694 return NULL;
695}
696
697FilePath TestingProfile::last_selected_directory() {
698 return last_selected_directory_;
699}
700
701void TestingProfile::set_last_selected_directory(const FilePath& path) {
702 last_selected_directory_ = path;
703}
704
[email protected]cc5bfd42010-11-24 14:44:02705PrefProxyConfigTracker* TestingProfile::GetProxyConfigTracker() {
706 if (!pref_proxy_config_tracker_)
707 pref_proxy_config_tracker_ = new PrefProxyConfigTracker(GetPrefs());
708
709 return pref_proxy_config_tracker_;
710}
711
[email protected]0bfc29a2009-04-27 16:15:44712void TestingProfile::BlockUntilHistoryProcessesPendingRequests() {
713 DCHECK(history_service_.get());
714 DCHECK(MessageLoop::current());
715
716 CancelableRequestConsumer consumer;
717 history_service_->ScheduleDBTask(new QuittingHistoryDBTask(), &consumer);
718 MessageLoop::current()->Run();
719}
[email protected]345a8b72009-09-29 09:11:44720
[email protected]8e4c29612010-07-14 01:24:45721TokenService* TestingProfile::GetTokenService() {
722 if (!token_service_.get()) {
723 token_service_.reset(new TokenService());
724 }
725 return token_service_.get();
726}
727
[email protected]345a8b72009-09-29 09:11:44728ProfileSyncService* TestingProfile::GetProfileSyncService() {
[email protected]e8234d32010-09-09 20:36:39729 return GetProfileSyncService("");
730}
731
732ProfileSyncService* TestingProfile::GetProfileSyncService(
733 const std::string& cros_user) {
[email protected]4772b072010-03-30 17:45:46734 if (!profile_sync_service_.get()) {
[email protected]3c887412010-04-19 20:30:23735 // Use a NiceMock here since we are really using the mock as a
736 // fake. Test cases that want to set expectations on a
737 // ProfileSyncService should use the ProfileMock and have this
738 // method return their own mock instance.
739 profile_sync_service_.reset(new NiceMock<ProfileSyncServiceMock>());
[email protected]4772b072010-03-30 17:45:46740 }
[email protected]345a8b72009-09-29 09:11:44741 return profile_sync_service_.get();
[email protected]345a8b72009-09-29 09:11:44742}
[email protected]2609bc12010-01-24 08:32:55743
[email protected]fadc607b62011-02-07 17:55:50744CloudPrintProxyService* TestingProfile::GetCloudPrintProxyService() {
745 return NULL;
746}
747
748ChromeBlobStorageContext* TestingProfile::GetBlobStorageContext() {
749 return NULL;
750}
751
752ExtensionInfoMap* TestingProfile::GetExtensionInfoMap() {
753 return NULL;
754}
755
756PromoCounter* TestingProfile::GetInstantPromoCounter() {
757 return NULL;
758}
759
760policy::ProfilePolicyContext* TestingProfile::GetPolicyContext() {
761 return NULL;
762}
763
[email protected]248ce192011-02-10 15:26:34764ChromeURLDataManager* TestingProfile::GetChromeURLDataManager() {
765 if (!chrome_url_data_manager_.get())
766 chrome_url_data_manager_.reset(new ChromeURLDataManager(this));
767 return chrome_url_data_manager_.get();
768}
769
[email protected]4c154ff82011-02-15 11:23:59770prerender::PrerenderManager* TestingProfile::GetPrerenderManager() {
[email protected]fadc607b62011-02-07 17:55:50771 return NULL;
772}
773
774PrefService* TestingProfile::GetOffTheRecordPrefs() {
775 return NULL;
776}
777
[email protected]2609bc12010-01-24 08:32:55778void TestingProfile::DestroyWebDataService() {
779 if (!web_data_service_.get())
780 return;
781
782 web_data_service_->Shutdown();
783}
[email protected]a5add2c2011-02-14 23:54:47784
785DerivedTestingProfile::DerivedTestingProfile(Profile* profile)
786 : original_profile_(profile) {}
787
788DerivedTestingProfile::~DerivedTestingProfile() {}
789
790ProfileId DerivedTestingProfile::GetRuntimeId() {
791 return original_profile_->GetRuntimeId();
792}