summaryrefslogtreecommitdiffstats
path: root/chrome/test
diff options
context:
space:
mode:
authordanno@chromium.org <danno@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-29 12:24:28 +0000
committerdanno@chromium.org <danno@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-29 12:24:28 +0000
commit2fb7dc983456e980d631501f4a120eb091d197e7 (patch)
treefa96aef59bf1900f56ae1b0457c4f9d36e0fb38e /chrome/test
parent0ce04e5a148136f3849e8a8b0dd351a0fc4798b5 (diff)
downloadchromium_src-2fb7dc983456e980d631501f4a120eb091d197e7.zip
chromium_src-2fb7dc983456e980d631501f4a120eb091d197e7.tar.gz
chromium_src-2fb7dc983456e980d631501f4a120eb091d197e7.tar.bz2
Use PrefChangeRegistrar everywhere
BUG=54955 TEST=PrefChangeRegistrarTest.* Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=60169 Review URL: http://codereview.chromium.org/3304015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60935 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r--chrome/test/testing_profile.cc42
-rw-r--r--chrome/test/testing_profile.h26
2 files changed, 62 insertions, 6 deletions
diff --git a/chrome/test/testing_profile.cc b/chrome/test/testing_profile.cc
index 6fd04fc..359f64d 100644
--- a/chrome/test/testing_profile.cc
+++ b/chrome/test/testing_profile.cc
@@ -16,6 +16,7 @@
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/dom_ui/ntp_resource_cache.h"
+#include "chrome/browser/extensions/extensions_service.h"
#include "chrome/browser/favicon_service.h"
#include "chrome/browser/find_bar_state.h"
#include "chrome/browser/geolocation/geolocation_content_settings_map.h"
@@ -166,6 +167,7 @@ class TestExtensionURLRequestContextGetter : public URLRequestContextGetter {
TestingProfile::TestingProfile()
: start_time_(Time::Now()),
+ testing_prefs_(NULL),
created_theme_provider_(false),
has_history_service_(false),
off_the_record_(false),
@@ -207,6 +209,10 @@ TestingProfile::~TestingProfile() {
if (top_sites_.get())
top_sites_->ClearProfile();
history::TopSites::DeleteTopSites(top_sites_);
+ if (extensions_service_.get()) {
+ extensions_service_->DestroyingProfile();
+ extensions_service_ = NULL;
+ }
}
void TestingProfile::CreateFaviconService() {
@@ -315,13 +321,26 @@ void TestingProfile::UseThemeProvider(BrowserThemeProvider* theme_provider) {
theme_provider_.reset(theme_provider);
}
+scoped_refptr<ExtensionsService> TestingProfile::CreateExtensionsService(
+ const CommandLine* command_line,
+ const FilePath& install_directory) {
+ extensions_service_ = new ExtensionsService(this,
+ command_line,
+ install_directory,
+ false);
+ return extensions_service_;
+}
+
FilePath TestingProfile::GetPath() {
DCHECK(temp_dir_.IsValid()); // TODO(phajdan.jr): do it better.
return temp_dir_.path();
}
TestingPrefService* TestingProfile::GetTestingPrefService() {
- return static_cast<TestingPrefService*>(GetPrefs());
+ if (!prefs_.get())
+ CreateTestingPrefService();
+ DCHECK(testing_prefs_);
+ return testing_prefs_;
}
webkit_database::DatabaseTracker* TestingProfile::GetDatabaseTracker() {
@@ -330,6 +349,10 @@ webkit_database::DatabaseTracker* TestingProfile::GetDatabaseTracker() {
return db_tracker_;
}
+ExtensionsService* TestingProfile::GetExtensionsService() {
+ return extensions_service_.get();
+}
+
net::CookieMonster* TestingProfile::GetCookieMonster() {
if (!GetRequestContext())
return NULL;
@@ -348,11 +371,22 @@ void TestingProfile::InitThemes() {
}
}
+void TestingProfile::SetPrefService(PrefService* prefs) {
+ DCHECK(!prefs_.get());
+ prefs_.reset(prefs);
+}
+
+void TestingProfile::CreateTestingPrefService() {
+ DCHECK(!prefs_.get());
+ testing_prefs_ = new TestingPrefService();
+ prefs_.reset(testing_prefs_);
+ Profile::RegisterUserPrefs(prefs_.get());
+ browser::RegisterAllPrefs(prefs_.get(), prefs_.get());
+}
+
PrefService* TestingProfile::GetPrefs() {
if (!prefs_.get()) {
- prefs_.reset(new TestingPrefService());
- Profile::RegisterUserPrefs(prefs_.get());
- browser::RegisterAllPrefs(prefs_.get(), prefs_.get());
+ CreateTestingPrefService();
}
return prefs_.get();
}
diff --git a/chrome/test/testing_profile.h b/chrome/test/testing_profile.h
index d75b7c1..b1e466d 100644
--- a/chrome/test/testing_profile.h
+++ b/chrome/test/testing_profile.h
@@ -23,6 +23,7 @@ class CookieMonster;
class AutocompleteClassifier;
class BookmarkModel;
class BrowserThemeProvider;
+class CommandLine;
class DesktopNotificationService;
class FaviconService;
class FindBarState;
@@ -86,6 +87,14 @@ class TestingProfile : public Profile {
// ownership of |theme_provider|.
void UseThemeProvider(BrowserThemeProvider* theme_provider);
+ // Creates an ExtensionsService initialized with the testing profile and
+ // returns it. The profile keeps its own copy of a scoped_refptr to the
+ // ExtensionsService to make sure that is still alive to be notified when the
+ // profile is destroyed.
+ scoped_refptr<ExtensionsService> CreateExtensionsService(
+ const CommandLine* command_line,
+ const FilePath& install_directory);
+
TestingPrefService* GetTestingPrefService();
virtual ProfileId GetRuntimeId() {
@@ -109,7 +118,7 @@ class TestingProfile : public Profile {
virtual ChromeAppCacheService* GetAppCacheService() { return NULL; }
virtual webkit_database::DatabaseTracker* GetDatabaseTracker();
virtual VisitedLinkMaster* GetVisitedLinkMaster() { return NULL; }
- virtual ExtensionsService* GetExtensionsService() { return NULL; }
+ virtual ExtensionsService* GetExtensionsService();
virtual UserScriptMaster* GetUserScriptMaster() { return NULL; }
virtual ExtensionDevToolsManager* GetExtensionDevToolsManager() {
return NULL;
@@ -148,6 +157,10 @@ class TestingProfile : public Profile {
virtual PasswordStore* GetPasswordStore(ServiceAccessType access) {
return NULL;
}
+ // Initialized the profile's PrefService with an explicity specified
+ // PrefService. Must be called before the TestingProfile.
+ // The profile takes ownership of |pref|.
+ void SetPrefService(PrefService* prefs);
virtual PrefService* GetPrefs();
virtual TemplateURLModel* GetTemplateURLModel() {
return template_url_model_.get();
@@ -263,7 +276,9 @@ class TestingProfile : public Profile {
protected:
base::Time start_time_;
- scoped_ptr<TestingPrefService> prefs_;
+ scoped_ptr<PrefService> prefs_;
+ // ref only for right type, lifecycle is managed by prefs_
+ TestingPrefService* testing_prefs_;
private:
// Destroys favicon service if it has been created.
@@ -277,6 +292,9 @@ class TestingProfile : public Profile {
// from the destructor.
void DestroyWebDataService();
+ // Creates a TestingPrefService and associates it with the TestingProfile
+ void CreateTestingPrefService();
+
// The favicon service. Only created if CreateFaviconService is invoked.
scoped_refptr<FaviconService> favicon_service_;
@@ -346,6 +364,10 @@ class TestingProfile : public Profile {
FilePath last_selected_directory_;
scoped_refptr<history::TopSites> top_sites_; // For history and thumbnails.
+ // For properly notifying the ExtensionsService when the profile
+ // is disposed.
+ scoped_refptr<ExtensionsService> extensions_service_;
+
// We use a temporary directory to store testing profile data.
ScopedTempDir temp_dir_;
};