blob: cff223a7f09c5381a7e07142c523a961ee1e70ce [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"
24#include "chrome/browser/geolocation/geolocation_permission_context.h"
25#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]37858e52010-08-26 00:22:0231#include "chrome/browser/prefs/browser_prefs.h"
[email protected]9a8c4022011-01-25 14:25:3332#include "chrome/browser/prefs/testing_pref_store.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]b071b6c2010-08-25 20:28:0337#include "chrome/browser/themes/browser_theme_provider.h"
[email protected]45300ad42010-12-02 15:51:1438#include "chrome/browser/ui/find_bar/find_bar_state.h"
[email protected]fd42ac30f2011-02-27 19:33:3639#include "chrome/browser/ui/webui/chrome_url_data_manager.h"
40#include "chrome/browser/ui/webui/ntp_resource_cache.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]567812d2011-02-24 17:40:5048#include "content/browser/browser_thread.h"
49#include "content/browser/in_process_webkit/webkit_context.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]a42b5592009-09-03 16:52:2356#if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS)
[email protected]93270d002011-01-19 22:32:5957#include "chrome/browser/ui/gtk/gtk_theme_provider.h"
[email protected]a42b5592009-09-03 16:52:2358#endif
59
[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]d8e41ed2008-09-11 15:22:32114 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
131class TestExtensionURLRequestContextGetter : public URLRequestContextGetter {
132 public:
[email protected]aeb53f02011-01-15 00:21:34133 virtual net::URLRequestContext* GetURLRequestContext() {
[email protected]c10da4b02010-03-25 14:38:32134 if (!context_)
135 context_ = new TestExtensionURLRequestContext();
136 return context_.get();
137 }
[email protected]00ed48f2010-10-22 22:19:24138 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const {
[email protected]0c7d74f2010-10-11 11:55:26139 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
[email protected]83a7d2eb2010-05-03 21:46:19140 }
[email protected]c10da4b02010-03-25 14:38:32141
142 private:
[email protected]aeb53f02011-01-15 00:21:34143 scoped_refptr<net::URLRequestContext> context_;
[email protected]c10da4b02010-03-25 14:38:32144};
145
[email protected]d364c652008-08-29 19:46:56146} // namespace
147
[email protected]f25387b2008-08-21 15:20:33148TestingProfile::TestingProfile()
[email protected]ea6f76572008-12-18 00:09:55149 : start_time_(Time::Now()),
[email protected]2fb7dc982010-09-29 12:24:28150 testing_prefs_(NULL),
[email protected]a42b5592009-09-03 16:52:23151 created_theme_provider_(false),
[email protected]ea6f76572008-12-18 00:09:55152 has_history_service_(false),
153 off_the_record_(false),
154 last_session_exited_cleanly_(true) {
[email protected]f9dec9482010-08-20 20:42:19155 if (!temp_dir_.CreateUniqueTempDir()) {
156 LOG(ERROR) << "Failed to create unique temporary directory.";
initial.commit09911bf2008-07-26 23:55:29157
[email protected]f9dec9482010-08-20 20:42:19158 // Fallback logic in case we fail to create unique temporary directory.
159 FilePath system_tmp_dir;
160 bool success = PathService::Get(base::DIR_TEMP, &system_tmp_dir);
[email protected]848cd05e2008-09-19 18:33:48161
[email protected]f9dec9482010-08-20 20:42:19162 // We're severly screwed if we can't get the system temporary
163 // directory. Die now to avoid writing to the filesystem root
164 // or other bad places.
165 CHECK(success);
166
167 FilePath fallback_dir(system_tmp_dir.AppendASCII("TestingProfilePath"));
168 file_util::Delete(fallback_dir, true);
169 file_util::CreateDirectory(fallback_dir);
170 if (!temp_dir_.Set(fallback_dir)) {
171 // That shouldn't happen, but if it does, try to recover.
172 LOG(ERROR) << "Failed to use a fallback temporary directory.";
173
174 // We're screwed if this fails, see CHECK above.
175 CHECK(temp_dir_.Set(system_tmp_dir));
176 }
177 }
[email protected]ab23dbe2010-08-12 02:10:46178}
179
[email protected]f25387b2008-08-21 15:20:33180TestingProfile::~TestingProfile() {
[email protected]d2879af2010-02-08 16:02:56181 NotificationService::current()->Notify(
182 NotificationType::PROFILE_DESTROYED,
183 Source<Profile>(this),
184 NotificationService::NoDetails());
[email protected]809cc4d2010-10-27 15:22:54185 DestroyTopSites();
[email protected]f25387b2008-08-21 15:20:33186 DestroyHistoryService();
[email protected]d2879af2010-02-08 16:02:56187 // FaviconService depends on HistoryServce so destroying it later.
188 DestroyFaviconService();
[email protected]2609bc12010-01-24 08:32:55189 DestroyWebDataService();
[email protected]2fb7dc982010-09-29 12:24:28190 if (extensions_service_.get()) {
191 extensions_service_->DestroyingProfile();
192 extensions_service_ = NULL;
193 }
[email protected]cc5bfd42010-11-24 14:44:02194 if (pref_proxy_config_tracker_.get())
195 pref_proxy_config_tracker_->DetachFromPrefService();
[email protected]f25387b2008-08-21 15:20:33196}
initial.commit09911bf2008-07-26 23:55:29197
[email protected]d2879af2010-02-08 16:02:56198void TestingProfile::CreateFaviconService() {
199 favicon_service_ = NULL;
200 favicon_service_ = new FaviconService(this);
201}
202
[email protected]d486a0852009-11-02 21:40:00203void TestingProfile::CreateHistoryService(bool delete_file, bool no_db) {
[email protected]809cc4d2010-10-27 15:22:54204 DestroyHistoryService();
[email protected]f25387b2008-08-21 15:20:33205 if (delete_file) {
[email protected]f7011fcb2009-01-28 21:54:32206 FilePath path = GetPath();
207 path = path.Append(chrome::kHistoryFilename);
[email protected]f25387b2008-08-21 15:20:33208 file_util::Delete(path, false);
209 }
[email protected]90ef13132008-08-27 03:27:46210 history_service_ = new HistoryService(this);
[email protected]d486a0852009-11-02 21:40:00211 history_service_->Init(GetPath(), bookmark_bar_model_.get(), no_db);
initial.commit09911bf2008-07-26 23:55:29212}
213
214void TestingProfile::DestroyHistoryService() {
215 if (!history_service_.get())
216 return;
217
218 history_service_->NotifyRenderProcessHostDestruction(0);
219 history_service_->SetOnBackendDestroyTask(new MessageLoop::QuitTask);
220 history_service_->Cleanup();
221 history_service_ = NULL;
222
223 // Wait for the backend class to terminate before deleting the files and
224 // moving to the next test. Note: if this never terminates, somebody is
225 // probably leaking a reference to the history backend, so it never calls
226 // our destroy task.
227 MessageLoop::current()->Run();
228
initial.commit09911bf2008-07-26 23:55:29229 // Make sure we don't have any event pending that could disrupt the next
230 // test.
231 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask);
232 MessageLoop::current()->Run();
233}
[email protected]4d0cd7ce2008-08-11 16:40:57234
[email protected]809cc4d2010-10-27 15:22:54235void TestingProfile::CreateTopSites() {
236 DestroyTopSites();
237 top_sites_ = new history::TopSites(this);
[email protected]73c47932010-12-06 18:13:43238 FilePath file_name = GetPath().Append(chrome::kTopSitesFilename);
[email protected]809cc4d2010-10-27 15:22:54239 top_sites_->Init(file_name);
240}
241
242void TestingProfile::DestroyTopSites() {
243 if (top_sites_.get()) {
244 top_sites_->Shutdown();
245 top_sites_ = NULL;
246 // TopSites::Shutdown schedules some tasks (from TopSitesBackend) that need
247 // to be run to properly shutdown. Run all pending tasks now. This is
248 // normally handled by browser_process shutdown.
249 if (MessageLoop::current())
250 MessageLoop::current()->RunAllPending();
251 }
252}
253
254void TestingProfile::DestroyFaviconService() {
255 if (!favicon_service_.get())
256 return;
257 favicon_service_ = NULL;
258}
259
[email protected]d8e41ed2008-09-11 15:22:32260void TestingProfile::CreateBookmarkModel(bool delete_file) {
[email protected]90ef13132008-08-27 03:27:46261 // Nuke the model first, that way we're sure it's done writing to disk.
262 bookmark_bar_model_.reset(NULL);
263
264 if (delete_file) {
[email protected]f7011fcb2009-01-28 21:54:32265 FilePath path = GetPath();
266 path = path.Append(chrome::kBookmarksFileName);
[email protected]90ef13132008-08-27 03:27:46267 file_util::Delete(path, false);
268 }
[email protected]d8e41ed2008-09-11 15:22:32269 bookmark_bar_model_.reset(new BookmarkModel(this));
[email protected]90ef13132008-08-27 03:27:46270 if (history_service_.get()) {
271 history_service_->history_backend_->bookmark_service_ =
272 bookmark_bar_model_.get();
273 history_service_->history_backend_->expirer_.bookmark_service_ =
274 bookmark_bar_model_.get();
275 }
276 bookmark_bar_model_->Load();
[email protected]4d0cd7ce2008-08-11 16:40:57277}
[email protected]d2c017a2008-08-13 21:51:45278
[email protected]69c579e2010-04-23 20:01:00279void TestingProfile::CreateAutocompleteClassifier() {
280 autocomplete_classifier_.reset(new AutocompleteClassifier(this));
281}
282
[email protected]a6d36cc2011-02-23 00:39:48283void TestingProfile::CreateProtocolHandlerRegistry() {
284 protocol_handler_registry_ = new ProtocolHandlerRegistry(this);
285}
286
[email protected]2609bc12010-01-24 08:32:55287void TestingProfile::CreateWebDataService(bool delete_file) {
288 if (web_data_service_.get())
289 web_data_service_->Shutdown();
290
291 if (delete_file) {
292 FilePath path = GetPath();
293 path = path.Append(chrome::kWebDataFilename);
294 file_util::Delete(path, false);
295 }
296
297 web_data_service_ = new WebDataService;
298 if (web_data_service_.get())
299 web_data_service_->Init(GetPath());
300}
301
[email protected]d364c652008-08-29 19:46:56302void TestingProfile::BlockUntilBookmarkModelLoaded() {
303 DCHECK(bookmark_bar_model_.get());
304 if (bookmark_bar_model_->IsLoaded())
305 return;
306 BookmarkLoadObserver observer;
307 bookmark_bar_model_->AddObserver(&observer);
308 MessageLoop::current()->Run();
309 bookmark_bar_model_->RemoveObserver(&observer);
310 DCHECK(bookmark_bar_model_->IsLoaded());
311}
312
[email protected]809cc4d2010-10-27 15:22:54313void TestingProfile::BlockUntilTopSitesLoaded() {
314 if (!GetHistoryService(Profile::EXPLICIT_ACCESS))
315 GetTopSites()->HistoryLoaded();
316 ui_test_utils::WaitForNotification(NotificationType::TOP_SITES_LOADED);
317}
318
[email protected]fb9d1f42010-10-06 23:17:59319void TestingProfile::CreateTemplateURLFetcher() {
320 template_url_fetcher_.reset(new TemplateURLFetcher(this));
321}
322
[email protected]d2c017a2008-08-13 21:51:45323void TestingProfile::CreateTemplateURLModel() {
[email protected]fb9d1f42010-10-06 23:17:59324 SetTemplateURLModel(new TemplateURLModel(this));
325}
326
327void TestingProfile::SetTemplateURLModel(TemplateURLModel* model) {
328 template_url_model_.reset(model);
[email protected]d2c017a2008-08-13 21:51:45329}
[email protected]0bfc29a2009-04-27 16:15:44330
[email protected]a42b5592009-09-03 16:52:23331void TestingProfile::UseThemeProvider(BrowserThemeProvider* theme_provider) {
332 theme_provider->Init(this);
333 created_theme_provider_ = true;
[email protected]761962c2009-09-25 00:18:15334 theme_provider_.reset(theme_provider);
[email protected]a42b5592009-09-03 16:52:23335}
336
[email protected]9a8c4022011-01-25 14:25:33337ExtensionService* TestingProfile::CreateExtensionService(
[email protected]2fb7dc982010-09-29 12:24:28338 const CommandLine* command_line,
339 const FilePath& install_directory) {
[email protected]9a8c4022011-01-25 14:25:33340 // Extension pref store, created for use by |extension_prefs_|.
341
342 extension_pref_value_map_.reset(new ExtensionPrefValueMap);
343 // Note that the GetPrefs() creates a TestingPrefService, therefore
344 // the extension controlled pref values set in extension_prefs_
345 // are not reflected in the pref service. One would need to
346 // inject a new ExtensionPrefStore(extension_pref_value_map_.get(), false).
347 extension_prefs_.reset(
348 new ExtensionPrefs(GetPrefs(),
349 install_directory,
350 extension_pref_value_map_.get()));
[email protected]eaa7dd182010-12-14 11:09:00351 extensions_service_ = new ExtensionService(this,
[email protected]9a8c4022011-01-25 14:25:33352 command_line,
353 install_directory,
354 extension_prefs_.get(),
355 false);
[email protected]2fb7dc982010-09-29 12:24:28356 return extensions_service_;
357}
358
[email protected]f9dec9482010-08-20 20:42:19359FilePath TestingProfile::GetPath() {
360 DCHECK(temp_dir_.IsValid()); // TODO(phajdan.jr): do it better.
361 return temp_dir_.path();
362}
363
[email protected]dbbad7a2010-08-13 18:18:36364TestingPrefService* TestingProfile::GetTestingPrefService() {
[email protected]2fb7dc982010-09-29 12:24:28365 if (!prefs_.get())
366 CreateTestingPrefService();
367 DCHECK(testing_prefs_);
368 return testing_prefs_;
[email protected]dbbad7a2010-08-13 18:18:36369}
370
[email protected]fadc607b62011-02-07 17:55:50371ProfileId TestingProfile::GetRuntimeId() {
372 return reinterpret_cast<ProfileId>(this);
373 }
374
375bool TestingProfile::IsOffTheRecord() {
376 return off_the_record_;
377}
378
[email protected]93dba942011-02-23 22:45:01379void TestingProfile::SetOffTheRecordProfile(Profile* profile) {
380 off_the_record_profile_.reset(profile);
381}
382
[email protected]fadc607b62011-02-07 17:55:50383Profile* TestingProfile::GetOffTheRecordProfile() {
[email protected]93dba942011-02-23 22:45:01384 return off_the_record_profile_.get();
[email protected]fadc607b62011-02-07 17:55:50385}
386
387bool TestingProfile::HasOffTheRecordProfile() {
[email protected]93dba942011-02-23 22:45:01388 return off_the_record_profile_.get() != NULL;
[email protected]fadc607b62011-02-07 17:55:50389}
390
391Profile* TestingProfile::GetOriginalProfile() {
392 return this;
393}
394
395ChromeAppCacheService* TestingProfile::GetAppCacheService() {
396 return NULL;
397}
398
[email protected]2f351cb2009-11-09 23:43:34399webkit_database::DatabaseTracker* TestingProfile::GetDatabaseTracker() {
[email protected]19eb80152011-02-26 00:28:43400 if (!db_tracker_) {
401 db_tracker_ = new webkit_database::DatabaseTracker(
402 GetPath(), false, GetExtensionSpecialStoragePolicy());
403 }
[email protected]2f351cb2009-11-09 23:43:34404 return db_tracker_;
405}
406
[email protected]fadc607b62011-02-07 17:55:50407VisitedLinkMaster* TestingProfile::GetVisitedLinkMaster() {
408 return NULL;
409}
410
[email protected]eaa7dd182010-12-14 11:09:00411ExtensionService* TestingProfile::GetExtensionService() {
[email protected]2fb7dc982010-09-29 12:24:28412 return extensions_service_.get();
413}
414
[email protected]fadc607b62011-02-07 17:55:50415UserScriptMaster* TestingProfile::GetUserScriptMaster() {
416 return NULL;
417}
418
419ExtensionDevToolsManager* TestingProfile::GetExtensionDevToolsManager() {
420 return NULL;
421}
422
423ExtensionProcessManager* TestingProfile::GetExtensionProcessManager() {
424 return NULL;
425}
426
427ExtensionMessageService* TestingProfile::GetExtensionMessageService() {
428 return NULL;
429}
430
431ExtensionEventRouter* TestingProfile::GetExtensionEventRouter() {
432 return NULL;
433}
434
435ExtensionIOEventRouter* TestingProfile::GetExtensionIOEventRouter() {
436 return NULL;
437}
438
[email protected]19eb80152011-02-26 00:28:43439ExtensionSpecialStoragePolicy*
440TestingProfile::GetExtensionSpecialStoragePolicy() {
441 if (!extension_special_storage_policy_)
442 extension_special_storage_policy_ = new ExtensionSpecialStoragePolicy();
443 return extension_special_storage_policy_;
444}
445
[email protected]fadc607b62011-02-07 17:55:50446SSLHostState* TestingProfile::GetSSLHostState() {
447 return NULL;
448}
449
450net::TransportSecurityState* TestingProfile::GetTransportSecurityState() {
451 return NULL;
452}
453
454FaviconService* TestingProfile::GetFaviconService(ServiceAccessType access) {
455 return favicon_service_.get();
456}
457
458HistoryService* TestingProfile::GetHistoryService(ServiceAccessType access) {
459 return history_service_.get();
460}
461
462HistoryService* TestingProfile::GetHistoryServiceWithoutCreating() {
463 return history_service_.get();
464}
465
[email protected]dbbad7a2010-08-13 18:18:36466net::CookieMonster* TestingProfile::GetCookieMonster() {
467 if (!GetRequestContext())
468 return NULL;
469 return GetRequestContext()->GetCookieStore()->GetCookieMonster();
470}
471
[email protected]fadc607b62011-02-07 17:55:50472AutocompleteClassifier* TestingProfile::GetAutocompleteClassifier() {
473 return autocomplete_classifier_.get();
474}
475
476WebDataService* TestingProfile::GetWebDataService(ServiceAccessType access) {
477 return web_data_service_.get();
478}
479
480WebDataService* TestingProfile::GetWebDataServiceWithoutCreating() {
481 return web_data_service_.get();
482}
483
484PasswordStore* TestingProfile::GetPasswordStore(ServiceAccessType access) {
485 return NULL;
486}
487
[email protected]a42b5592009-09-03 16:52:23488void TestingProfile::InitThemes() {
489 if (!created_theme_provider_) {
490#if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS)
[email protected]761962c2009-09-25 00:18:15491 theme_provider_.reset(new GtkThemeProvider);
[email protected]a42b5592009-09-03 16:52:23492#else
[email protected]761962c2009-09-25 00:18:15493 theme_provider_.reset(new BrowserThemeProvider);
[email protected]a42b5592009-09-03 16:52:23494#endif
[email protected]761962c2009-09-25 00:18:15495 theme_provider_->Init(this);
[email protected]a42b5592009-09-03 16:52:23496 created_theme_provider_ = true;
[email protected]a42b5592009-09-03 16:52:23497 }
[email protected]76688082009-05-16 07:04:42498}
499
[email protected]fadc607b62011-02-07 17:55:50500const Extension* TestingProfile::GetTheme() {
501 return NULL;
502}
503
504BrowserThemeProvider* TestingProfile::GetThemeProvider() {
505 InitThemes();
506 return theme_provider_.get();
507}
508
[email protected]2fb7dc982010-09-29 12:24:28509void TestingProfile::SetPrefService(PrefService* prefs) {
510 DCHECK(!prefs_.get());
511 prefs_.reset(prefs);
512}
513
514void TestingProfile::CreateTestingPrefService() {
515 DCHECK(!prefs_.get());
516 testing_prefs_ = new TestingPrefService();
517 prefs_.reset(testing_prefs_);
518 Profile::RegisterUserPrefs(prefs_.get());
[email protected]2f9d81322011-02-21 09:55:43519 browser::RegisterUserPrefs(prefs_.get());
[email protected]2fb7dc982010-09-29 12:24:28520}
521
[email protected]dbbad7a2010-08-13 18:18:36522PrefService* TestingProfile::GetPrefs() {
523 if (!prefs_.get()) {
[email protected]2fb7dc982010-09-29 12:24:28524 CreateTestingPrefService();
[email protected]dbbad7a2010-08-13 18:18:36525 }
526 return prefs_.get();
527}
528
[email protected]fadc607b62011-02-07 17:55:50529TemplateURLModel* TestingProfile::GetTemplateURLModel() {
530 return template_url_model_.get();
531}
532
533TemplateURLFetcher* TestingProfile::GetTemplateURLFetcher() {
534 return template_url_fetcher_.get();
535}
536
[email protected]dbbad7a2010-08-13 18:18:36537history::TopSites* TestingProfile::GetTopSites() {
[email protected]809cc4d2010-10-27 15:22:54538 return top_sites_.get();
[email protected]dbbad7a2010-08-13 18:18:36539}
540
[email protected]fadc607b62011-02-07 17:55:50541history::TopSites* TestingProfile::GetTopSitesWithoutCreating() {
542 return top_sites_.get();
543}
544
545DownloadManager* TestingProfile::GetDownloadManager() {
546 return NULL;
547}
548
549PersonalDataManager* TestingProfile::GetPersonalDataManager() {
550 return NULL;
551}
552
[email protected]397281f2011-02-14 05:15:53553fileapi::FileSystemContext* TestingProfile::GetFileSystemContext() {
[email protected]fadc607b62011-02-07 17:55:50554 return NULL;
555}
556
557BrowserSignin* TestingProfile::GetBrowserSignin() {
558 return NULL;
559}
560
561bool TestingProfile::HasCreatedDownloadManager() const {
562 return false;
563}
564
[email protected]812b3a32010-01-08 05:36:04565URLRequestContextGetter* TestingProfile::GetRequestContext() {
566 return request_context_.get();
567}
568
569void TestingProfile::CreateRequestContext() {
570 if (!request_context_)
571 request_context_ = new TestURLRequestContextGetter();
572}
573
[email protected]7c893202010-10-07 20:18:02574void TestingProfile::ResetRequestContext() {
575 request_context_ = NULL;
576}
577
[email protected]fadc607b62011-02-07 17:55:50578URLRequestContextGetter* TestingProfile::GetRequestContextForMedia() {
579 return NULL;
580}
581
[email protected]c10da4b02010-03-25 14:38:32582URLRequestContextGetter* TestingProfile::GetRequestContextForExtensions() {
583 if (!extensions_request_context_)
584 extensions_request_context_ = new TestExtensionURLRequestContextGetter();
585 return extensions_request_context_.get();
586}
587
[email protected]fadc607b62011-02-07 17:55:50588net::SSLConfigService* TestingProfile::GetSSLConfigService() {
589 return NULL;
590}
591
592UserStyleSheetWatcher* TestingProfile::GetUserStyleSheetWatcher() {
593 return NULL;
594}
595
[email protected]dbbad7a2010-08-13 18:18:36596FindBarState* TestingProfile::GetFindBarState() {
597 if (!find_bar_state_.get())
598 find_bar_state_.reset(new FindBarState());
599 return find_bar_state_.get();
600}
601
602HostContentSettingsMap* TestingProfile::GetHostContentSettingsMap() {
603 if (!host_content_settings_map_.get())
604 host_content_settings_map_ = new HostContentSettingsMap(this);
605 return host_content_settings_map_.get();
606}
607
608GeolocationContentSettingsMap*
609TestingProfile::GetGeolocationContentSettingsMap() {
610 if (!geolocation_content_settings_map_.get()) {
611 geolocation_content_settings_map_ =
612 new GeolocationContentSettingsMap(this);
613 }
614 return geolocation_content_settings_map_.get();
615}
616
617GeolocationPermissionContext*
618TestingProfile::GetGeolocationPermissionContext() {
619 if (!geolocation_permission_context_.get()) {
620 geolocation_permission_context_ =
621 new GeolocationPermissionContext(this);
622 }
623 return geolocation_permission_context_.get();
624}
625
[email protected]fadc607b62011-02-07 17:55:50626HostZoomMap* TestingProfile::GetHostZoomMap() {
627 return NULL;
628}
629
630SessionService* TestingProfile::GetSessionService() {
631 return session_service_.get();
632}
633
634bool TestingProfile::HasSessionService() const {
635 return (session_service_.get() != NULL);
636}
637
638bool TestingProfile::HasProfileSyncService() const {
639 return (profile_sync_service_.get() != NULL);
640}
641
642std::wstring TestingProfile::GetName() {
643 return std::wstring();
644}
645
646std::wstring TestingProfile::GetID() {
647 return id_;
648}
649
650void TestingProfile::SetID(const std::wstring& id) {
651 id_ = id;
652}
653
654bool TestingProfile::DidLastSessionExitCleanly() {
655 return last_session_exited_cleanly_;
656}
657
658BookmarkModel* TestingProfile::GetBookmarkModel() {
659 return bookmark_bar_model_.get();
660}
661
662bool TestingProfile::IsSameProfile(Profile *p) {
663 return this == p;
664}
665
666base::Time TestingProfile::GetStartTime() const {
667 return start_time_;
668}
669
670TabRestoreService* TestingProfile::GetTabRestoreService() {
671 return NULL;
672}
673
[email protected]a6d36cc2011-02-23 00:39:48674ProtocolHandlerRegistry* TestingProfile::GetProtocolHandlerRegistry() {
675 return protocol_handler_registry_.get();
676}
677
[email protected]fadc607b62011-02-07 17:55:50678SpellCheckHost* TestingProfile::GetSpellCheckHost() {
679 return NULL;
680}
681
[email protected]8cb5d5b2010-02-09 11:36:16682void TestingProfile::set_session_service(SessionService* session_service) {
683 session_service_ = session_service;
684}
685
[email protected]dbbad7a2010-08-13 18:18:36686WebKitContext* TestingProfile::GetWebKitContext() {
687 if (webkit_context_ == NULL)
[email protected]5134417a2010-11-30 13:57:24688 webkit_context_ = new WebKitContext(this, false);
[email protected]dbbad7a2010-08-13 18:18:36689 return webkit_context_;
690}
691
[email protected]fadc607b62011-02-07 17:55:50692WebKitContext* TestingProfile::GetOffTheRecordWebKitContext() {
693 return NULL;
694}
695
[email protected]156ed27b2009-11-23 18:31:25696NTPResourceCache* TestingProfile::GetNTPResourceCache() {
697 if (!ntp_resource_cache_.get())
698 ntp_resource_cache_.reset(new NTPResourceCache(this));
699 return ntp_resource_cache_.get();
700}
701
[email protected]dbbad7a2010-08-13 18:18:36702DesktopNotificationService* TestingProfile::GetDesktopNotificationService() {
[email protected]0c7d74f2010-10-11 11:55:26703 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]dbbad7a2010-08-13 18:18:36704 if (!desktop_notification_service_.get()) {
705 desktop_notification_service_.reset(new DesktopNotificationService(
706 this, NULL));
707 }
708 return desktop_notification_service_.get();
709}
710
[email protected]fadc607b62011-02-07 17:55:50711BackgroundContentsService*
712TestingProfile::GetBackgroundContentsService() const {
713 return NULL;
714}
715
716StatusTray* TestingProfile::GetStatusTray() {
717 return NULL;
718}
719
720FilePath TestingProfile::last_selected_directory() {
721 return last_selected_directory_;
722}
723
724void TestingProfile::set_last_selected_directory(const FilePath& path) {
725 last_selected_directory_ = path;
726}
727
[email protected]cc5bfd42010-11-24 14:44:02728PrefProxyConfigTracker* TestingProfile::GetProxyConfigTracker() {
729 if (!pref_proxy_config_tracker_)
730 pref_proxy_config_tracker_ = new PrefProxyConfigTracker(GetPrefs());
731
732 return pref_proxy_config_tracker_;
733}
734
[email protected]0bfc29a2009-04-27 16:15:44735void TestingProfile::BlockUntilHistoryProcessesPendingRequests() {
736 DCHECK(history_service_.get());
737 DCHECK(MessageLoop::current());
738
739 CancelableRequestConsumer consumer;
740 history_service_->ScheduleDBTask(new QuittingHistoryDBTask(), &consumer);
741 MessageLoop::current()->Run();
742}
[email protected]345a8b72009-09-29 09:11:44743
[email protected]8e4c29612010-07-14 01:24:45744TokenService* TestingProfile::GetTokenService() {
745 if (!token_service_.get()) {
746 token_service_.reset(new TokenService());
747 }
748 return token_service_.get();
749}
750
[email protected]345a8b72009-09-29 09:11:44751ProfileSyncService* TestingProfile::GetProfileSyncService() {
[email protected]e8234d32010-09-09 20:36:39752 return GetProfileSyncService("");
753}
754
755ProfileSyncService* TestingProfile::GetProfileSyncService(
756 const std::string& cros_user) {
[email protected]4772b072010-03-30 17:45:46757 if (!profile_sync_service_.get()) {
[email protected]3c887412010-04-19 20:30:23758 // Use a NiceMock here since we are really using the mock as a
759 // fake. Test cases that want to set expectations on a
760 // ProfileSyncService should use the ProfileMock and have this
761 // method return their own mock instance.
762 profile_sync_service_.reset(new NiceMock<ProfileSyncServiceMock>());
[email protected]4772b072010-03-30 17:45:46763 }
[email protected]345a8b72009-09-29 09:11:44764 return profile_sync_service_.get();
[email protected]345a8b72009-09-29 09:11:44765}
[email protected]2609bc12010-01-24 08:32:55766
[email protected]fadc607b62011-02-07 17:55:50767CloudPrintProxyService* TestingProfile::GetCloudPrintProxyService() {
768 return NULL;
769}
770
771ChromeBlobStorageContext* TestingProfile::GetBlobStorageContext() {
772 return NULL;
773}
774
775ExtensionInfoMap* TestingProfile::GetExtensionInfoMap() {
776 return NULL;
777}
778
779PromoCounter* TestingProfile::GetInstantPromoCounter() {
780 return NULL;
781}
782
[email protected]985655a2011-02-23 09:54:25783policy::ProfilePolicyConnector* TestingProfile::GetPolicyConnector() {
[email protected]fadc607b62011-02-07 17:55:50784 return NULL;
785}
786
[email protected]248ce192011-02-10 15:26:34787ChromeURLDataManager* TestingProfile::GetChromeURLDataManager() {
788 if (!chrome_url_data_manager_.get())
789 chrome_url_data_manager_.reset(new ChromeURLDataManager(this));
790 return chrome_url_data_manager_.get();
791}
792
[email protected]4c154ff82011-02-15 11:23:59793prerender::PrerenderManager* TestingProfile::GetPrerenderManager() {
[email protected]fadc607b62011-02-07 17:55:50794 return NULL;
795}
796
797PrefService* TestingProfile::GetOffTheRecordPrefs() {
798 return NULL;
799}
800
[email protected]2609bc12010-01-24 08:32:55801void TestingProfile::DestroyWebDataService() {
802 if (!web_data_service_.get())
803 return;
804
805 web_data_service_->Shutdown();
806}
[email protected]a5add2c2011-02-14 23:54:47807
808DerivedTestingProfile::DerivedTestingProfile(Profile* profile)
809 : original_profile_(profile) {}
810
811DerivedTestingProfile::~DerivedTestingProfile() {}
812
813ProfileId DerivedTestingProfile::GetRuntimeId() {
814 return original_profile_->GetRuntimeId();
815}