diff options
author | mnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-21 13:54:08 +0000 |
---|---|---|
committer | mnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-21 13:54:08 +0000 |
commit | 74379bc51320fd98a47c98053a056b4ddd7271a7 (patch) | |
tree | 721fb4cbad36a304162745d8a0a5ee0930f054f0 /chrome/test | |
parent | 7082b2329218da9a77fd6bc9587e86d0ed817196 (diff) | |
download | chromium_src-74379bc51320fd98a47c98053a056b4ddd7271a7.zip chromium_src-74379bc51320fd98a47c98053a056b4ddd7271a7.tar.gz chromium_src-74379bc51320fd98a47c98053a056b4ddd7271a7.tar.bz2 |
Adjust preference sync code to only sync user modifiable preferences.
Switch to the new preference value source checkers in Preference. While at it,
add a unit test and better test infrastructure for controlling preference
values in tests. Convert existing unit tests where appropriate.
BUG=48952
TEST=ProfileSyncServicePreferenceTest.ManagedPreferences
Review URL: http://codereview.chromium.org/3051001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53179 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r-- | chrome/test/data/profiles/chrome_prefs/History | 0 | ||||
-rw-r--r-- | chrome/test/data/profiles/chrome_prefs/Preferences | 20 | ||||
-rw-r--r-- | chrome/test/testing_pref_service.cc | 60 | ||||
-rw-r--r-- | chrome/test/testing_pref_service.h | 51 | ||||
-rw-r--r-- | chrome/test/testing_profile.h | 10 |
5 files changed, 115 insertions, 26 deletions
diff --git a/chrome/test/data/profiles/chrome_prefs/History b/chrome/test/data/profiles/chrome_prefs/History deleted file mode 100644 index e69de29..0000000 --- a/chrome/test/data/profiles/chrome_prefs/History +++ /dev/null diff --git a/chrome/test/data/profiles/chrome_prefs/Preferences b/chrome/test/data/profiles/chrome_prefs/Preferences deleted file mode 100644 index 4510e2f..0000000 --- a/chrome/test/data/profiles/chrome_prefs/Preferences +++ /dev/null @@ -1,20 +0,0 @@ -{
- "extensions": {
- "theme": {
- "use_system": false
- }
- },
- "intl": {
- "charset_default": "utf8"
- },
- "webkit": {
- "webprefs": {
- "default_font_size": 20,
- "text_areas_are_resizable": false,
- "uses_universal_detector": true,
-
- "foo": "bar",
- "standard_font_family": true
- }
- }
-}
diff --git a/chrome/test/testing_pref_service.cc b/chrome/test/testing_pref_service.cc new file mode 100644 index 0000000..e6dde83 --- /dev/null +++ b/chrome/test/testing_pref_service.cc @@ -0,0 +1,60 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/test/testing_pref_service.h" + +#include "chrome/browser/dummy_pref_store.h" +#include "chrome/browser/pref_value_store.h" + +TestingPrefService::TestingPrefService() + : PrefService(new PrefValueStore( + managed_prefs_ = new DummyPrefStore(), + NULL, + NULL, + user_prefs_ = new DummyPrefStore(), + NULL)) { +} + +const Value* TestingPrefService::GetManagedPref(const wchar_t* path) { + return GetPref(managed_prefs_, path); +} + +void TestingPrefService::SetManagedPref(const wchar_t* path, Value* value) { + SetPref(managed_prefs_, path, value); +} + +void TestingPrefService::RemoveManagedPref(const wchar_t* path) { + RemovePref(managed_prefs_, path); +} + +const Value* TestingPrefService::GetUserPref(const wchar_t* path) { + return GetPref(user_prefs_, path); +} + +void TestingPrefService::SetUserPref(const wchar_t* path, Value* value) { + SetPref(user_prefs_, path, value); +} + +void TestingPrefService::RemoveUserPref(const wchar_t* path) { + RemovePref(user_prefs_, path); +} + +const Value* TestingPrefService::GetPref(PrefStore* pref_store, + const wchar_t* path) { + Value* result; + return pref_store->prefs()->Get(path, &result) ? result : NULL; +} + +void TestingPrefService::SetPref(PrefStore* pref_store, + const wchar_t* path, + Value* value) { + pref_store->prefs()->Set(path, value); + FireObservers(path); +} + +void TestingPrefService::RemovePref(PrefStore* pref_store, + const wchar_t* path) { + pref_store->prefs()->Remove(path, NULL); + FireObservers(path); +} diff --git a/chrome/test/testing_pref_service.h b/chrome/test/testing_pref_service.h new file mode 100644 index 0000000..8155a84 --- /dev/null +++ b/chrome/test/testing_pref_service.h @@ -0,0 +1,51 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_TEST_TESTING_PREF_SERVICE_H_ +#define CHROME_TEST_TESTING_PREF_SERVICE_H_ + +#include <chrome/browser/pref_service.h> + +// A PrefService subclass for testing. It operates totally in memory and +// provides additional API for manipulating preferences at the different levels +// (managed, extension, user) conveniently. +class TestingPrefService : public PrefService { + public: + // Create an empty instance. + TestingPrefService(); + + // Read the value of a preference from the managed layer. Returns NULL if the + // preference is not defined at the managed layer. + const Value* GetManagedPref(const wchar_t* path); + + // Set a preference on the managed layer and fire observers if the preference + // changed. Assumes ownership of |value|. + void SetManagedPref(const wchar_t* path, Value* value); + + // Clear the preference on the managed layer and fire observers if the + // preference has been defined previously. + void RemoveManagedPref(const wchar_t* path); + + // Similar to the above, but for user preferences. + const Value* GetUserPref(const wchar_t* path); + void SetUserPref(const wchar_t* path, Value* value); + void RemoveUserPref(const wchar_t* path); + + private: + // Reads the value of the preference indicated by |path| from |pref_store|. + // Returns NULL if the preference was not found. + const Value* GetPref(PrefStore* pref_store, const wchar_t* path); + + // Sets the value for |path| in |pref_store|. + void SetPref(PrefStore* pref_store, const wchar_t* path, Value* value); + + // Removes the preference identified by |path| from |pref_store|. + void RemovePref(PrefStore* pref_store, const wchar_t* path); + + // Pointers to the pref stores our value store uses. + PrefStore* managed_prefs_; + PrefStore* user_prefs_; +}; + +#endif // CHROME_TEST_TESTING_PREF_SERVICE_H_ diff --git a/chrome/test/testing_profile.h b/chrome/test/testing_profile.h index 8421570..b23435e 100644 --- a/chrome/test/testing_profile.h +++ b/chrome/test/testing_profile.h @@ -27,6 +27,7 @@ #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" class ProfileSyncService; @@ -149,12 +150,9 @@ class TestingProfile : public Profile { virtual PasswordStore* GetPasswordStore(ServiceAccessType access) { return NULL; } - virtual PrefService* GetPrefs() { + virtual TestingPrefService* GetPrefs() { if (!prefs_.get()) { - FilePath prefs_filename = - path_.Append(FILE_PATH_LITERAL("TestPreferences")); - - prefs_.reset(PrefService::CreateUserPrefService(prefs_filename)); + prefs_.reset(new TestingPrefService()); Profile::RegisterUserPrefs(prefs_.get()); browser::RegisterAllPrefs(prefs_.get(), prefs_.get()); } @@ -292,7 +290,7 @@ class TestingProfile : public Profile { // to this. FilePath path_; base::Time start_time_; - scoped_ptr<PrefService> prefs_; + scoped_ptr<TestingPrefService> prefs_; private: // Destroys favicon service if it has been created. |