diff options
Diffstat (limited to 'chrome/test')
-rw-r--r-- | chrome/test/testing_profile.cc | 97 | ||||
-rw-r--r-- | chrome/test/testing_profile.h | 118 |
2 files changed, 130 insertions, 85 deletions
diff --git a/chrome/test/testing_profile.cc b/chrome/test/testing_profile.cc index 6292079..2cdf40f 100644 --- a/chrome/test/testing_profile.cc +++ b/chrome/test/testing_profile.cc @@ -5,19 +5,39 @@ #include "chrome/test/testing_profile.h" #include "build/build_config.h" + +#include "base/base_paths.h" #include "base/command_line.h" +#include "base/file_util.h" #include "base/message_loop_proxy.h" +#include "base/path_service.h" #include "base/string_number_conversions.h" -#include "chrome/common/url_constants.h" +#include "chrome/browser/autocomplete/autocomplete_classifier.h" #include "chrome/browser/bookmarks/bookmark_model.h" +#include "chrome/browser/browser_prefs.h" +#include "chrome/browser/browser_theme_provider.h" +#include "chrome/browser/chrome_thread.h" #include "chrome/browser/dom_ui/ntp_resource_cache.h" +#include "chrome/browser/favicon_service.h" +#include "chrome/browser/find_bar_state.h" +#include "chrome/browser/geolocation/geolocation_content_settings_map.h" +#include "chrome/browser/geolocation/geolocation_permission_context.h" +#include "chrome/browser/history/history.h" #include "chrome/browser/history/history_backend.h" +#include "chrome/browser/history/top_sites.h" +#include "chrome/browser/in_process_webkit/webkit_context.h" +#include "chrome/browser/host_content_settings_map.h" #include "chrome/browser/net/gaia/token_service.h" +#include "chrome/browser/notifications/desktop_notification_service.h" +#include "chrome/browser/search_engines/template_url_model.h" #include "chrome/browser/sessions/session_service.h" #include "chrome/browser/sync/profile_sync_service_mock.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/net/url_request_context_getter.h" #include "chrome/common/notification_service.h" +#include "chrome/common/url_constants.h" +#include "chrome/test/testing_pref_service.h" +#include "net/base/cookie_monster.h" #include "net/url_request/url_request_context.h" #include "testing/gmock/include/gmock/gmock.h" #include "webkit/database/database_tracker.h" @@ -300,12 +320,22 @@ void TestingProfile::UseThemeProvider(BrowserThemeProvider* theme_provider) { theme_provider_.reset(theme_provider); } +TestingPrefService* TestingProfile::GetTestingPrefService() { + return static_cast<TestingPrefService*>(GetPrefs()); +} + webkit_database::DatabaseTracker* TestingProfile::GetDatabaseTracker() { if (!db_tracker_) db_tracker_ = new webkit_database::DatabaseTracker(GetPath(), false); return db_tracker_; } +net::CookieMonster* TestingProfile::GetCookieMonster() { + if (!GetRequestContext()) + return NULL; + return GetRequestContext()->GetCookieStore()->GetCookieMonster(); +} + void TestingProfile::InitThemes() { if (!created_theme_provider_) { #if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS) @@ -318,6 +348,26 @@ void TestingProfile::InitThemes() { } } +PrefService* TestingProfile::GetPrefs() { + if (!prefs_.get()) { + prefs_.reset(new TestingPrefService()); + Profile::RegisterUserPrefs(prefs_.get()); + browser::RegisterAllPrefs(prefs_.get(), prefs_.get()); + } + return prefs_.get(); +} + +history::TopSites* TestingProfile::GetTopSites() { + if (!top_sites_.get()) { + top_sites_ = new history::TopSites(this); + if (!temp_dir_.CreateUniqueTempDir()) + return NULL; + FilePath file_name = temp_dir_.path().AppendASCII("TopSites.db"); + top_sites_->Init(file_name); + } + return top_sites_; +} + URLRequestContextGetter* TestingProfile::GetRequestContext() { return request_context_.get(); } @@ -333,16 +383,61 @@ URLRequestContextGetter* TestingProfile::GetRequestContextForExtensions() { return extensions_request_context_.get(); } +FindBarState* TestingProfile::GetFindBarState() { + if (!find_bar_state_.get()) + find_bar_state_.reset(new FindBarState()); + return find_bar_state_.get(); +} + +HostContentSettingsMap* TestingProfile::GetHostContentSettingsMap() { + if (!host_content_settings_map_.get()) + host_content_settings_map_ = new HostContentSettingsMap(this); + return host_content_settings_map_.get(); +} + +GeolocationContentSettingsMap* +TestingProfile::GetGeolocationContentSettingsMap() { + if (!geolocation_content_settings_map_.get()) { + geolocation_content_settings_map_ = + new GeolocationContentSettingsMap(this); + } + return geolocation_content_settings_map_.get(); +} + +GeolocationPermissionContext* +TestingProfile::GetGeolocationPermissionContext() { + if (!geolocation_permission_context_.get()) { + geolocation_permission_context_ = + new GeolocationPermissionContext(this); + } + return geolocation_permission_context_.get(); +} + void TestingProfile::set_session_service(SessionService* session_service) { session_service_ = session_service; } +WebKitContext* TestingProfile::GetWebKitContext() { + if (webkit_context_ == NULL) + webkit_context_ = new WebKitContext(this); + return webkit_context_; +} + NTPResourceCache* TestingProfile::GetNTPResourceCache() { if (!ntp_resource_cache_.get()) ntp_resource_cache_.reset(new NTPResourceCache(this)); return ntp_resource_cache_.get(); } +DesktopNotificationService* TestingProfile::GetDesktopNotificationService() { + DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); + if (!desktop_notification_service_.get()) { + desktop_notification_service_.reset(new DesktopNotificationService( + this, NULL)); + } + return desktop_notification_service_.get(); +} + void TestingProfile::BlockUntilHistoryProcessesPendingRequests() { DCHECK(history_service_.get()); DCHECK(MessageLoop::current()); diff --git a/chrome/test/testing_profile.h b/chrome/test/testing_profile.h index 1e39f8a..a4814f5 100644 --- a/chrome/test/testing_profile.h +++ b/chrome/test/testing_profile.h @@ -6,35 +6,34 @@ #define CHROME_TEST_TESTING_PROFILE_H_ #pragma once -#include "base/base_paths.h" -#include "base/file_util.h" -#include "base/path_service.h" #include "base/scoped_temp_dir.h" -#include "chrome/browser/autocomplete/autocomplete_classifier.h" -#include "chrome/browser/bookmarks/bookmark_model.h" -#include "chrome/browser/browser_prefs.h" -#include "chrome/browser/browser_theme_provider.h" -#include "chrome/browser/chrome_thread.h" -#include "chrome/browser/favicon_service.h" -#include "chrome/browser/find_bar_state.h" -#include "chrome/browser/geolocation/geolocation_content_settings_map.h" -#include "chrome/browser/geolocation/geolocation_permission_context.h" -#include "chrome/browser/host_content_settings_map.h" -#include "chrome/browser/history/history.h" -#include "chrome/browser/history/top_sites.h" -#include "chrome/browser/in_process_webkit/webkit_context.h" -#include "chrome/browser/notifications/desktop_notification_service.h" -#include "chrome/browser/pref_service.h" -#include "chrome/browser/pref_value_store.h" #include "chrome/browser/profile.h" -#include "chrome/browser/search_engines/template_url_model.h" -#include "chrome/common/json_pref_store.h" -#include "chrome/common/net/url_request_context_getter.h" -#include "chrome/test/testing_pref_service.h" -#include "net/base/cookie_monster.h" +namespace history { +class TopSites; +} + +namespace net { +class CookieMonster; +} + +class AutocompleteClassifier; +class BookmarkModel; +class BrowserThemeProvider; +class DesktopNotificationService; +class FaviconService; +class FindBarState; +class GeolocationContentSettingsMap; +class GeolocationPermissionContext; +class HistoryService; +class HostContentSettingsMap; +class PrefService; class ProfileSyncService; class SessionService; +class TemplateURLModel; +class TestingPrefService; +class URLRequestContextGetter; +class WebKitContext; class TestingProfile : public Profile { public: @@ -95,6 +94,8 @@ class TestingProfile : public Profile { // ownership of |theme_provider|. void UseThemeProvider(BrowserThemeProvider* theme_provider); + TestingPrefService* GetTestingPrefService(); + virtual ProfileId GetRuntimeId() { return reinterpret_cast<ProfileId>(this); } @@ -143,11 +144,7 @@ class TestingProfile : public Profile { // The CookieMonster will only be returned if a Context has been created. Do // this by calling CreateRequestContext(). See the note at GetRequestContext // for more information. - net::CookieMonster* GetCookieMonster() { - if (!GetRequestContext()) - return NULL; - return GetRequestContext()->GetCookieStore()->GetCookieMonster(); - } + net::CookieMonster* GetCookieMonster(); virtual AutocompleteClassifier* GetAutocompleteClassifier() { return autocomplete_classifier_.get(); } @@ -160,28 +157,12 @@ class TestingProfile : public Profile { virtual PasswordStore* GetPasswordStore(ServiceAccessType access) { return NULL; } - virtual TestingPrefService* GetPrefs() { - if (!prefs_.get()) { - prefs_.reset(new TestingPrefService()); - Profile::RegisterUserPrefs(prefs_.get()); - browser::RegisterAllPrefs(prefs_.get(), prefs_.get()); - } - return prefs_.get(); - } + virtual PrefService* GetPrefs(); virtual TemplateURLModel* GetTemplateURLModel() { return template_url_model_.get(); } virtual TemplateURLFetcher* GetTemplateURLFetcher() { return NULL; } - virtual history::TopSites* GetTopSites() { - if (!top_sites_.get()) { - top_sites_ = new history::TopSites(this); - if (!temp_dir_.CreateUniqueTempDir()) - return NULL; - FilePath file_name = temp_dir_.path().AppendASCII("TopSites.db"); - top_sites_->Init(file_name); - } - return top_sites_; - } + virtual history::TopSites* GetTopSites(); virtual DownloadManager* GetDownloadManager() { return NULL; } virtual PersonalDataManager* GetPersonalDataManager() { return NULL; } virtual bool HasCreatedDownloadManager() const { return false; } @@ -211,30 +192,10 @@ class TestingProfile : public Profile { virtual net::SSLConfigService* GetSSLConfigService() { return NULL; } virtual UserStyleSheetWatcher* GetUserStyleSheetWatcher() { return NULL; } - virtual FindBarState* GetFindBarState() { - if (!find_bar_state_.get()) - find_bar_state_.reset(new FindBarState()); - return find_bar_state_.get(); - } - virtual HostContentSettingsMap* GetHostContentSettingsMap() { - if (!host_content_settings_map_.get()) - host_content_settings_map_ = new HostContentSettingsMap(this); - return host_content_settings_map_.get(); - } - virtual GeolocationContentSettingsMap* GetGeolocationContentSettingsMap() { - if (!geolocation_content_settings_map_.get()) { - geolocation_content_settings_map_ = - new GeolocationContentSettingsMap(this); - } - return geolocation_content_settings_map_.get(); - } - virtual GeolocationPermissionContext* GetGeolocationPermissionContext() { - if (!geolocation_permission_context_.get()) { - geolocation_permission_context_ = - new GeolocationPermissionContext(this); - } - return geolocation_permission_context_.get(); - } + virtual FindBarState* GetFindBarState(); + virtual HostContentSettingsMap* GetHostContentSettingsMap(); + virtual GeolocationContentSettingsMap* GetGeolocationContentSettingsMap(); + virtual GeolocationPermissionContext* GetGeolocationPermissionContext(); virtual HostZoomMap* GetHostZoomMap() { return NULL; } void set_session_service(SessionService* session_service); virtual SessionService* GetSessionService() { return session_service_.get(); } @@ -265,24 +226,13 @@ class TestingProfile : public Profile { virtual void ResetTabRestoreService() {} virtual SpellCheckHost* GetSpellCheckHost() { return NULL; } virtual void ReinitializeSpellCheckHost(bool force) { } - virtual WebKitContext* GetWebKitContext() { - if (webkit_context_ == NULL) - webkit_context_ = new WebKitContext(this); - return webkit_context_; - } + virtual WebKitContext* GetWebKitContext(); virtual WebKitContext* GetOffTheRecordWebKitContext() { return NULL; } virtual void MarkAsCleanShutdown() {} virtual void InitExtensions() {} virtual void InitWebResources() {} virtual NTPResourceCache* GetNTPResourceCache(); - virtual DesktopNotificationService* GetDesktopNotificationService() { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); - if (!desktop_notification_service_.get()) { - desktop_notification_service_.reset(new DesktopNotificationService( - this, NULL)); - } - return desktop_notification_service_.get(); - } + virtual DesktopNotificationService* GetDesktopNotificationService(); virtual BackgroundContentsService* GetBackgroundContentsService() { return NULL; } |