Add user_prefs::TestPrefServiceSyncable

BUG=386246
TEST=unit_tests

Review URL: https://codereview.chromium.org/340703002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278292 0039d316-1c4b-4281-b951-d872f2087c98
parent 09406320
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
#include "chrome/browser/search_engines/default_search_manager.h" #include "chrome/browser/search_engines/default_search_manager.h"
#include "chrome/browser/search_engines/template_url_prepopulate_data.h" #include "chrome/browser/search_engines/template_url_prepopulate_data.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_pref_service_syncable.h"
#include "components/pref_registry/pref_registry_syncable.h" #include "components/pref_registry/pref_registry_syncable.h"
#include "components/pref_registry/testing_pref_service_syncable.h"
#include "components/search_engines/template_url_data.h" #include "components/search_engines/template_url_data.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -44,7 +44,7 @@ void ExpectSimilar(const TemplateURLData* expected, ...@@ -44,7 +44,7 @@ void ExpectSimilar(const TemplateURLData* expected,
} }
// TODO(caitkp): TemplateURLData-ify this. // TODO(caitkp): TemplateURLData-ify this.
void SetOverrides(TestingPrefServiceSyncable* prefs, bool update) { void SetOverrides(user_prefs::TestingPrefServiceSyncable* prefs, bool update) {
prefs->SetUserPref(prefs::kSearchProviderOverridesVersion, prefs->SetUserPref(prefs::kSearchProviderOverridesVersion,
base::Value::CreateIntegerValue(1)); base::Value::CreateIntegerValue(1));
base::ListValue* overrides = new base::ListValue; base::ListValue* overrides = new base::ListValue;
...@@ -78,7 +78,7 @@ void SetOverrides(TestingPrefServiceSyncable* prefs, bool update) { ...@@ -78,7 +78,7 @@ void SetOverrides(TestingPrefServiceSyncable* prefs, bool update) {
prefs->SetUserPref(prefs::kSearchProviderOverrides, overrides); prefs->SetUserPref(prefs::kSearchProviderOverrides, overrides);
} }
void SetPolicy(TestingPrefServiceSyncable* prefs, void SetPolicy(user_prefs::TestingPrefServiceSyncable* prefs,
bool enabled, bool enabled,
TemplateURLData* data) { TemplateURLData* data) {
if (enabled) { if (enabled) {
...@@ -142,15 +142,17 @@ class DefaultSearchManagerTest : public testing::Test { ...@@ -142,15 +142,17 @@ class DefaultSearchManagerTest : public testing::Test {
DefaultSearchManagerTest() {}; DefaultSearchManagerTest() {};
virtual void SetUp() OVERRIDE { virtual void SetUp() OVERRIDE {
pref_service_.reset(new TestingPrefServiceSyncable); pref_service_.reset(new user_prefs::TestingPrefServiceSyncable);
DefaultSearchManager::RegisterProfilePrefs(pref_service_->registry()); DefaultSearchManager::RegisterProfilePrefs(pref_service_->registry());
TemplateURLPrepopulateData::RegisterProfilePrefs(pref_service_->registry()); TemplateURLPrepopulateData::RegisterProfilePrefs(pref_service_->registry());
} }
TestingPrefServiceSyncable* pref_service() { return pref_service_.get(); } user_prefs::TestingPrefServiceSyncable* pref_service() {
return pref_service_.get();
}
private: private:
scoped_ptr<TestingPrefServiceSyncable> pref_service_; scoped_ptr<user_prefs::TestingPrefServiceSyncable> pref_service_;
DISALLOW_COPY_AND_ASSIGN(DefaultSearchManagerTest); DISALLOW_COPY_AND_ASSIGN(DefaultSearchManagerTest);
}; };
......
...@@ -11,9 +11,8 @@ ...@@ -11,9 +11,8 @@
#include "chrome/browser/search_engines/template_url_service.h" #include "chrome/browser/search_engines/template_url_service.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_pref_service_syncable.h"
#include "chrome/test/base/testing_profile.h"
#include "components/google/core/browser/google_switches.h" #include "components/google/core/browser/google_switches.h"
#include "components/pref_registry/testing_pref_service_syncable.h"
#include "components/search_engines/prepopulated_engines.h" #include "components/search_engines/prepopulated_engines.h"
#include "components/search_engines/search_terms_data.h" #include "components/search_engines/search_terms_data.h"
#include "grit/generated_resources.h" #include "grit/generated_resources.h"
...@@ -37,11 +36,19 @@ std::string GetHostFromTemplateURLData(const TemplateURLData& data) { ...@@ -37,11 +36,19 @@ std::string GetHostFromTemplateURLData(const TemplateURLData& data) {
} // namespace } // namespace
typedef testing::Test TemplateURLPrepopulateDataTest; class TemplateURLPrepopulateDataTest : public testing::Test {
public:
virtual void SetUp() OVERRIDE {
TemplateURLPrepopulateData::RegisterProfilePrefs(prefs_.registry());
}
protected:
user_prefs::TestingPrefServiceSyncable prefs_;
};
// Verifies the set of prepopulate data doesn't contain entries with duplicate // Verifies the set of prepopulate data doesn't contain entries with duplicate
// ids. // ids.
TEST(TemplateURLPrepopulateDataTest, UniqueIDs) { TEST_F(TemplateURLPrepopulateDataTest, UniqueIDs) {
const int kCountryIds[] = { const int kCountryIds[] = {
'A'<<8|'D', 'A'<<8|'E', 'A'<<8|'F', 'A'<<8|'G', 'A'<<8|'I', 'A'<<8|'D', 'A'<<8|'E', 'A'<<8|'F', 'A'<<8|'G', 'A'<<8|'I',
'A'<<8|'L', 'A'<<8|'M', 'A'<<8|'N', 'A'<<8|'O', 'A'<<8|'Q', 'A'<<8|'L', 'A'<<8|'M', 'A'<<8|'N', 'A'<<8|'O', 'A'<<8|'Q',
...@@ -93,12 +100,11 @@ TEST(TemplateURLPrepopulateDataTest, UniqueIDs) { ...@@ -93,12 +100,11 @@ TEST(TemplateURLPrepopulateDataTest, UniqueIDs) {
'V'<<8|'N', 'V'<<8|'U', 'W'<<8|'F', 'W'<<8|'S', 'Y'<<8|'E', 'V'<<8|'N', 'V'<<8|'U', 'W'<<8|'F', 'W'<<8|'S', 'Y'<<8|'E',
'Y'<<8|'T', 'Z'<<8|'A', 'Z'<<8|'M', 'Z'<<8|'W', -1 }; 'Y'<<8|'T', 'Z'<<8|'A', 'Z'<<8|'M', 'Z'<<8|'W', -1 };
TestingProfile profile;
for (size_t i = 0; i < arraysize(kCountryIds); ++i) { for (size_t i = 0; i < arraysize(kCountryIds); ++i) {
profile.GetPrefs()->SetInteger(prefs::kCountryIDAtInstall, kCountryIds[i]); prefs_.SetInteger(prefs::kCountryIDAtInstall, kCountryIds[i]);
size_t default_index; size_t default_index;
ScopedVector<TemplateURLData> urls = ScopedVector<TemplateURLData> urls =
TemplateURLPrepopulateData::GetPrepopulatedEngines(profile.GetPrefs(), TemplateURLPrepopulateData::GetPrepopulatedEngines(&prefs_,
&default_index); &default_index);
std::set<int> unique_ids; std::set<int> unique_ids;
for (size_t turl_i = 0; turl_i < urls.size(); ++turl_i) { for (size_t turl_i = 0; turl_i < urls.size(); ++turl_i) {
...@@ -111,10 +117,8 @@ TEST(TemplateURLPrepopulateDataTest, UniqueIDs) { ...@@ -111,10 +117,8 @@ TEST(TemplateURLPrepopulateDataTest, UniqueIDs) {
// Verifies that default search providers from the preferences file // Verifies that default search providers from the preferences file
// override the built-in ones. // override the built-in ones.
TEST(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) { TEST_F(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) {
TestingProfile profile; prefs_.SetUserPref(prefs::kSearchProviderOverridesVersion,
TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
prefs->SetUserPref(prefs::kSearchProviderOverridesVersion,
base::Value::CreateIntegerValue(1)); base::Value::CreateIntegerValue(1));
base::ListValue* overrides = new base::ListValue; base::ListValue* overrides = new base::ListValue;
scoped_ptr<base::DictionaryValue> entry(new base::DictionaryValue); scoped_ptr<base::DictionaryValue> entry(new base::DictionaryValue);
...@@ -126,14 +130,15 @@ TEST(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) { ...@@ -126,14 +130,15 @@ TEST(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) {
entry->SetString("encoding", "UTF-8"); entry->SetString("encoding", "UTF-8");
entry->SetInteger("id", 1001); entry->SetInteger("id", 1001);
overrides->Append(entry->DeepCopy()); overrides->Append(entry->DeepCopy());
prefs->SetUserPref(prefs::kSearchProviderOverrides, overrides); prefs_.SetUserPref(prefs::kSearchProviderOverrides, overrides);
int version = TemplateURLPrepopulateData::GetDataVersion(prefs); int version = TemplateURLPrepopulateData::GetDataVersion(&prefs_);
EXPECT_EQ(1, version); EXPECT_EQ(1, version);
size_t default_index; size_t default_index;
ScopedVector<TemplateURLData> t_urls = ScopedVector<TemplateURLData> t_urls =
TemplateURLPrepopulateData::GetPrepopulatedEngines(prefs, &default_index); TemplateURLPrepopulateData::GetPrepopulatedEngines(&prefs_,
&default_index);
ASSERT_EQ(1u, t_urls.size()); ASSERT_EQ(1u, t_urls.size());
EXPECT_EQ(ASCIIToUTF16("foo"), t_urls[0]->short_name); EXPECT_EQ(ASCIIToUTF16("foo"), t_urls[0]->short_name);
...@@ -156,10 +161,10 @@ TEST(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) { ...@@ -156,10 +161,10 @@ TEST(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) {
entry->SetString("search_terms_replacement_key", "espv"); entry->SetString("search_terms_replacement_key", "espv");
overrides = new base::ListValue; overrides = new base::ListValue;
overrides->Append(entry->DeepCopy()); overrides->Append(entry->DeepCopy());
prefs->SetUserPref(prefs::kSearchProviderOverrides, overrides); prefs_.SetUserPref(prefs::kSearchProviderOverrides, overrides);
t_urls = TemplateURLPrepopulateData::GetPrepopulatedEngines( t_urls = TemplateURLPrepopulateData::GetPrepopulatedEngines(
profile.GetPrefs(), &default_index); &prefs_, &default_index);
ASSERT_EQ(1u, t_urls.size()); ASSERT_EQ(1u, t_urls.size());
EXPECT_EQ(ASCIIToUTF16("foo"), t_urls[0]->short_name); EXPECT_EQ(ASCIIToUTF16("foo"), t_urls[0]->short_name);
EXPECT_EQ(ASCIIToUTF16("fook"), t_urls[0]->keyword()); EXPECT_EQ(ASCIIToUTF16("fook"), t_urls[0]->keyword());
...@@ -190,17 +195,16 @@ TEST(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) { ...@@ -190,17 +195,16 @@ TEST(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) {
entry->SetString("keyword", "bazk"); entry->SetString("keyword", "bazk");
entry->SetString("encoding", "UTF-8"); entry->SetString("encoding", "UTF-8");
overrides->Append(entry->DeepCopy()); overrides->Append(entry->DeepCopy());
prefs->SetUserPref(prefs::kSearchProviderOverrides, overrides); prefs_.SetUserPref(prefs::kSearchProviderOverrides, overrides);
t_urls = t_urls =
TemplateURLPrepopulateData::GetPrepopulatedEngines(prefs, &default_index); TemplateURLPrepopulateData::GetPrepopulatedEngines(&prefs_,
&default_index);
EXPECT_EQ(2u, t_urls.size()); EXPECT_EQ(2u, t_urls.size());
} }
TEST(TemplateURLPrepopulateDataTest, ClearProvidersFromPrefs) { TEST_F(TemplateURLPrepopulateDataTest, ClearProvidersFromPrefs) {
TestingProfile profile; prefs_.SetUserPref(prefs::kSearchProviderOverridesVersion,
TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
prefs->SetUserPref(prefs::kSearchProviderOverridesVersion,
base::Value::CreateIntegerValue(1)); base::Value::CreateIntegerValue(1));
base::ListValue* overrides = new base::ListValue; base::ListValue* overrides = new base::ListValue;
base::DictionaryValue* entry(new base::DictionaryValue); base::DictionaryValue* entry(new base::DictionaryValue);
...@@ -212,20 +216,21 @@ TEST(TemplateURLPrepopulateDataTest, ClearProvidersFromPrefs) { ...@@ -212,20 +216,21 @@ TEST(TemplateURLPrepopulateDataTest, ClearProvidersFromPrefs) {
entry->SetString("encoding", "UTF-8"); entry->SetString("encoding", "UTF-8");
entry->SetInteger("id", 1001); entry->SetInteger("id", 1001);
overrides->Append(entry); overrides->Append(entry);
prefs->SetUserPref(prefs::kSearchProviderOverrides, overrides); prefs_.SetUserPref(prefs::kSearchProviderOverrides, overrides);
int version = TemplateURLPrepopulateData::GetDataVersion(prefs); int version = TemplateURLPrepopulateData::GetDataVersion(&prefs_);
EXPECT_EQ(1, version); EXPECT_EQ(1, version);
// This call removes the above search engine. // This call removes the above search engine.
TemplateURLPrepopulateData::ClearPrepopulatedEnginesInPrefs(prefs); TemplateURLPrepopulateData::ClearPrepopulatedEnginesInPrefs(&prefs_);
version = TemplateURLPrepopulateData::GetDataVersion(prefs); version = TemplateURLPrepopulateData::GetDataVersion(&prefs_);
EXPECT_EQ(TemplateURLPrepopulateData::kCurrentDataVersion, version); EXPECT_EQ(TemplateURLPrepopulateData::kCurrentDataVersion, version);
size_t default_index; size_t default_index;
ScopedVector<TemplateURLData> t_urls = ScopedVector<TemplateURLData> t_urls =
TemplateURLPrepopulateData::GetPrepopulatedEngines(prefs, &default_index); TemplateURLPrepopulateData::GetPrepopulatedEngines(&prefs_,
&default_index);
ASSERT_FALSE(t_urls.empty()); ASSERT_FALSE(t_urls.empty());
for (size_t i = 0; i < t_urls.size(); ++i) { for (size_t i = 0; i < t_urls.size(); ++i) {
EXPECT_NE(ASCIIToUTF16("foo"), t_urls[i]->short_name); EXPECT_NE(ASCIIToUTF16("foo"), t_urls[i]->short_name);
...@@ -249,13 +254,12 @@ TEST(TemplateURLPrepopulateDataTest, ClearProvidersFromPrefs) { ...@@ -249,13 +254,12 @@ TEST(TemplateURLPrepopulateDataTest, ClearProvidersFromPrefs) {
} }
// Verifies that built-in search providers are processed correctly. // Verifies that built-in search providers are processed correctly.
TEST(TemplateURLPrepopulateDataTest, ProvidersFromPrepopulated) { TEST_F(TemplateURLPrepopulateDataTest, ProvidersFromPrepopulated) {
TestingProfile profile;
// Use United States. // Use United States.
profile.GetPrefs()->SetInteger(prefs::kCountryIDAtInstall, 'U'<<8|'S'); prefs_.SetInteger(prefs::kCountryIDAtInstall, 'U'<<8|'S');
size_t default_index; size_t default_index;
ScopedVector<TemplateURLData> t_urls = ScopedVector<TemplateURLData> t_urls =
TemplateURLPrepopulateData::GetPrepopulatedEngines(profile.GetPrefs(), TemplateURLPrepopulateData::GetPrepopulatedEngines(&prefs_,
&default_index); &default_index);
// Ensure all the URLs have the required fields populated. // Ensure all the URLs have the required fields populated.
...@@ -289,14 +293,14 @@ TEST(TemplateURLPrepopulateDataTest, ProvidersFromPrepopulated) { ...@@ -289,14 +293,14 @@ TEST(TemplateURLPrepopulateDataTest, ProvidersFromPrepopulated) {
EXPECT_FALSE(t_urls[default_index]->search_terms_replacement_key.empty()); EXPECT_FALSE(t_urls[default_index]->search_terms_replacement_key.empty());
} }
TEST(TemplateURLPrepopulateDataTest, GetEngineTypeBasic) { TEST_F(TemplateURLPrepopulateDataTest, GetEngineTypeBasic) {
EXPECT_EQ(SEARCH_ENGINE_OTHER, GetEngineType("http://example.com/")); EXPECT_EQ(SEARCH_ENGINE_OTHER, GetEngineType("http://example.com/"));
EXPECT_EQ(SEARCH_ENGINE_ASK, GetEngineType("http://www.ask.com/")); EXPECT_EQ(SEARCH_ENGINE_ASK, GetEngineType("http://www.ask.com/"));
EXPECT_EQ(SEARCH_ENGINE_OTHER, GetEngineType("http://search.atlas.cz/")); EXPECT_EQ(SEARCH_ENGINE_OTHER, GetEngineType("http://search.atlas.cz/"));
EXPECT_EQ(SEARCH_ENGINE_GOOGLE, GetEngineType("http://www.google.com/")); EXPECT_EQ(SEARCH_ENGINE_GOOGLE, GetEngineType("http://www.google.com/"));
} }
TEST(TemplateURLPrepopulateDataTest, GetEngineTypeAdvanced) { TEST_F(TemplateURLPrepopulateDataTest, GetEngineTypeAdvanced) {
// Google URLs in different forms. // Google URLs in different forms.
const char* kGoogleURLs[] = { const char* kGoogleURLs[] = {
// Original with google:baseURL: // Original with google:baseURL:
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
'../components/components.gyp:invalidation_test_support', '../components/components.gyp:invalidation_test_support',
'../components/components.gyp:metrics_test_support', '../components/components.gyp:metrics_test_support',
'../components/components.gyp:password_manager_core_browser_test_support', '../components/components.gyp:password_manager_core_browser_test_support',
'../components/components.gyp:pref_registry_test_support',
'../components/components.gyp:signin_core_browser_test_support', '../components/components.gyp:signin_core_browser_test_support',
'../components/components.gyp:sync_driver_test_support', '../components/components.gyp:sync_driver_test_support',
'../content/content.gyp:content_app_both', '../content/content.gyp:content_app_both',
......
...@@ -310,6 +310,9 @@ ...@@ -310,6 +310,9 @@
'components.gyp:password_manager_core_browser', 'components.gyp:password_manager_core_browser',
'components.gyp:precache_core', 'components.gyp:precache_core',
# Dependencies of pref_registry
'components.gyp:pref_registry_test_support',
# Dependencies of query_parser # Dependencies of query_parser
'components.gyp:query_parser', 'components.gyp:query_parser',
......
...@@ -25,5 +25,19 @@ ...@@ -25,5 +25,19 @@
'pref_registry/pref_registry_syncable.h', 'pref_registry/pref_registry_syncable.h',
], ],
}, },
{
'target_name': 'pref_registry_test_support',
'type': 'static_library',
'dependencies': [
'pref_registry',
],
'include_dirs': [
'..',
],
'sources': [
'pref_registry/testing_pref_service_syncable.cc',
'pref_registry/testing_pref_service_syncable.h',
],
},
], ],
} }
// Copyright 2014 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 "components/pref_registry/testing_pref_service_syncable.h"
#include "base/bind.h"
#include "base/prefs/pref_notifier_impl.h"
#include "base/prefs/pref_value_store.h"
#include "components/pref_registry/pref_registry_syncable.h"
template <>
TestingPrefServiceBase<PrefService, user_prefs::PrefRegistrySyncable>::
TestingPrefServiceBase(TestingPrefStore* managed_prefs,
TestingPrefStore* user_prefs,
TestingPrefStore* recommended_prefs,
user_prefs::PrefRegistrySyncable* pref_registry,
PrefNotifierImpl* pref_notifier)
: PrefService(pref_notifier,
new PrefValueStore(managed_prefs,
NULL, // supervised_user_prefs
NULL, // extension_prefs
NULL, // command_line_prefs
user_prefs,
recommended_prefs,
pref_registry->defaults().get(),
pref_notifier),
user_prefs,
pref_registry,
base::Bind(&TestingPrefServiceBase<
PrefService,
user_prefs::PrefRegistrySyncable>::HandleReadError),
false),
managed_prefs_(managed_prefs),
user_prefs_(user_prefs),
recommended_prefs_(recommended_prefs) {}
namespace user_prefs {
TestingPrefServiceSyncable::TestingPrefServiceSyncable()
: TestingPrefServiceBase<PrefService, PrefRegistrySyncable>(
new TestingPrefStore(),
new TestingPrefStore(),
new TestingPrefStore(),
new PrefRegistrySyncable(),
new PrefNotifierImpl()) {
}
TestingPrefServiceSyncable::TestingPrefServiceSyncable(
TestingPrefStore* managed_prefs,
TestingPrefStore* user_prefs,
TestingPrefStore* recommended_prefs,
PrefRegistrySyncable* pref_registry,
PrefNotifierImpl* pref_notifier)
: TestingPrefServiceBase<PrefService, PrefRegistrySyncable>(
managed_prefs,
user_prefs,
recommended_prefs,
pref_registry,
pref_notifier) {
}
TestingPrefServiceSyncable::~TestingPrefServiceSyncable() {
}
PrefRegistrySyncable* TestingPrefServiceSyncable::registry() {
return static_cast<PrefRegistrySyncable*>(DeprecatedGetPrefRegistry());
}
} // namespace user_prefs
// Copyright 2014 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 COMPONENTS_PERF_REGISTRY_TESTING_PREF_SERVICE_SYNCABLE_H_
#define COMPONENTS_PERF_REGISTRY_TESTING_PREF_SERVICE_SYNCABLE_H_
#include "base/basictypes.h"
#include "base/prefs/testing_pref_service.h"
namespace user_prefs {
class PrefRegistrySyncable;
// Test version of PrefServiceSyncable.
class TestingPrefServiceSyncable
: public TestingPrefServiceBase<PrefService, PrefRegistrySyncable> {
public:
TestingPrefServiceSyncable();
TestingPrefServiceSyncable(TestingPrefStore* managed_prefs,
TestingPrefStore* user_prefs,
TestingPrefStore* recommended_prefs,
PrefRegistrySyncable* pref_registry,
PrefNotifierImpl* pref_notifier);
virtual ~TestingPrefServiceSyncable();
// This is provided as a convenience; on a production PrefService
// you would do all registrations before constructing it, passing it
// a PrefRegistry via its constructor (or via e.g. PrefServiceFactory).
PrefRegistrySyncable* registry();
private:
DISALLOW_COPY_AND_ASSIGN(TestingPrefServiceSyncable);
};
} // namespace user_prefs
#endif // COMPONENTS_PERF_REGISTRY_TESTING_PREF_SERVICE_SYNCABLE_H_
include_rules = [ include_rules = [
"+components/os_crypt", "+components/os_crypt",
"+components/pref_registry/pref_registry_syncable.h", "+components/pref_registry",
"+sync", "+sync",
] ]
...@@ -10,39 +10,12 @@ ...@@ -10,39 +10,12 @@
#include "base/prefs/pref_value_store.h" #include "base/prefs/pref_value_store.h"
#include "base/prefs/testing_pref_service.h" #include "base/prefs/testing_pref_service.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "components/pref_registry/pref_registry_syncable.h" #include "components/pref_registry/testing_pref_service_syncable.h"
#include "components/sync_driver/pref_names.h" #include "components/sync_driver/pref_names.h"
#include "sync/internal_api/public/base/model_type.h" #include "sync/internal_api/public/base/model_type.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
template <>
TestingPrefServiceBase<PrefService, user_prefs::PrefRegistrySyncable>::
TestingPrefServiceBase(TestingPrefStore* managed_prefs,
TestingPrefStore* user_prefs,
TestingPrefStore* recommended_prefs,
user_prefs::PrefRegistrySyncable* pref_registry,
PrefNotifierImpl* pref_notifier)
: PrefService(
pref_notifier,
new PrefValueStore(managed_prefs,
NULL, // supervised_user_prefs
NULL, // extension_prefs
NULL, // command_line_prefs
user_prefs,
recommended_prefs,
pref_registry->defaults().get(),
pref_notifier),
user_prefs,
pref_registry,
base::Bind(&TestingPrefServiceBase<
PrefService,
user_prefs::PrefRegistrySyncable>::HandleReadError),
false),
managed_prefs_(managed_prefs),
user_prefs_(user_prefs),
recommended_prefs_(recommended_prefs) {}
namespace sync_driver { namespace sync_driver {
namespace { namespace {
...@@ -50,42 +23,13 @@ namespace { ...@@ -50,42 +23,13 @@ namespace {
using ::testing::InSequence; using ::testing::InSequence;
using ::testing::StrictMock; using ::testing::StrictMock;
// Test version of PrefServiceSyncable.
class TestingPrefServiceSyncable
: public TestingPrefServiceBase<PrefService,
user_prefs::PrefRegistrySyncable> {
public:
TestingPrefServiceSyncable();
virtual ~TestingPrefServiceSyncable();
user_prefs::PrefRegistrySyncable* registry();
private:
DISALLOW_COPY_AND_ASSIGN(TestingPrefServiceSyncable);
};
TestingPrefServiceSyncable::TestingPrefServiceSyncable()
: TestingPrefServiceBase<PrefService, user_prefs::PrefRegistrySyncable>(
new TestingPrefStore(),
new TestingPrefStore(),
new TestingPrefStore(),
new user_prefs::PrefRegistrySyncable(),
new PrefNotifierImpl()) {}
TestingPrefServiceSyncable::~TestingPrefServiceSyncable() {}
user_prefs::PrefRegistrySyncable* TestingPrefServiceSyncable::registry() {
return static_cast<user_prefs::PrefRegistrySyncable*>(
DeprecatedGetPrefRegistry());
}
class SyncPrefsTest : public testing::Test { class SyncPrefsTest : public testing::Test {
protected: protected:
virtual void SetUp() OVERRIDE { virtual void SetUp() OVERRIDE {
SyncPrefs::RegisterProfilePrefs(pref_service_.registry()); SyncPrefs::RegisterProfilePrefs(pref_service_.registry());
} }
TestingPrefServiceSyncable pref_service_; user_prefs::TestingPrefServiceSyncable pref_service_;
private: private:
base::MessageLoop loop_; base::MessageLoop loop_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment