Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(262)

Side by Side Diff: components/sync_preferences/pref_model_associator_unittest.cc

Issue 2459823002: [Sync] Rename syncable_prefs to sync_preferences. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/syncable_prefs/pref_model_associator.h" 5 #include "components/sync_preferences/pref_model_associator.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "components/prefs/scoped_user_pref_update.h" 12 #include "components/prefs/scoped_user_pref_update.h"
13 #include "components/syncable_prefs/pref_model_associator_client.h" 13 #include "components/sync_preferences/pref_model_associator_client.h"
14 #include "components/syncable_prefs/pref_service_mock_factory.h" 14 #include "components/sync_preferences/pref_service_mock_factory.h"
15 #include "components/syncable_prefs/pref_service_syncable.h" 15 #include "components/sync_preferences/pref_service_syncable.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 namespace syncable_prefs { 18 namespace sync_preferences {
19 19
20 namespace { 20 namespace {
21 21
22 const char kStringPrefName[] = "pref.string"; 22 const char kStringPrefName[] = "pref.string";
23 const char kListPrefName[] = "pref.list"; 23 const char kListPrefName[] = "pref.list";
24 const char kDictionaryPrefName[] = "pref.dictionary"; 24 const char kDictionaryPrefName[] = "pref.dictionary";
25 25
26 class TestPrefModelAssociatorClient : public PrefModelAssociatorClient { 26 class TestPrefModelAssociatorClient : public PrefModelAssociatorClient {
27 public: 27 public:
28 TestPrefModelAssociatorClient() {} 28 TestPrefModelAssociatorClient() {}
(...skipping 14 matching lines...) Expand all
43 }; 43 };
44 44
45 class AbstractPreferenceMergeTest : public testing::Test { 45 class AbstractPreferenceMergeTest : public testing::Test {
46 protected: 46 protected:
47 AbstractPreferenceMergeTest() { 47 AbstractPreferenceMergeTest() {
48 PrefServiceMockFactory factory; 48 PrefServiceMockFactory factory;
49 factory.SetPrefModelAssociatorClient(&client_); 49 factory.SetPrefModelAssociatorClient(&client_);
50 scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry( 50 scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry(
51 new user_prefs::PrefRegistrySyncable); 51 new user_prefs::PrefRegistrySyncable);
52 pref_registry->RegisterStringPref( 52 pref_registry->RegisterStringPref(
53 kStringPrefName, 53 kStringPrefName, std::string(),
54 std::string(),
55 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 54 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
56 pref_registry->RegisterListPref( 55 pref_registry->RegisterListPref(
57 kListPrefName, 56 kListPrefName, user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
58 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
59 pref_registry->RegisterDictionaryPref( 57 pref_registry->RegisterDictionaryPref(
60 kDictionaryPrefName, 58 kDictionaryPrefName, user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
61 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
62 pref_service_ = factory.CreateSyncable(pref_registry.get()); 59 pref_service_ = factory.CreateSyncable(pref_registry.get());
63 pref_sync_service_ = static_cast<PrefModelAssociator*>( 60 pref_sync_service_ = static_cast<PrefModelAssociator*>(
64 pref_service_->GetSyncableService(syncer::PREFERENCES)); 61 pref_service_->GetSyncableService(syncer::PREFERENCES));
65 } 62 }
66 63
67 void SetContentPattern(base::DictionaryValue* patterns_dict, 64 void SetContentPattern(base::DictionaryValue* patterns_dict,
68 const std::string& expression, 65 const std::string& expression,
69 int setting) { 66 int setting) {
70 base::DictionaryValue* expression_dict; 67 base::DictionaryValue* expression_dict;
71 bool found = 68 bool found = patterns_dict->GetDictionaryWithoutPathExpansion(
72 patterns_dict->GetDictionaryWithoutPathExpansion(expression, 69 expression, &expression_dict);
73 &expression_dict);
74 if (!found) { 70 if (!found) {
75 expression_dict = new base::DictionaryValue; 71 expression_dict = new base::DictionaryValue;
76 patterns_dict->SetWithoutPathExpansion(expression, expression_dict); 72 patterns_dict->SetWithoutPathExpansion(expression, expression_dict);
77 } 73 }
78 expression_dict->SetWithoutPathExpansion( 74 expression_dict->SetWithoutPathExpansion(
79 "setting", new base::FundamentalValue(setting)); 75 "setting", new base::FundamentalValue(setting));
80 } 76 }
81 77
82 void SetPrefToEmpty(const std::string& pref_name) { 78 void SetPrefToEmpty(const std::string& pref_name) {
83 std::unique_ptr<base::Value> empty_value; 79 std::unique_ptr<base::Value> empty_value;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 ListPrefUpdate update(pref_service_.get(), kListPrefName); 139 ListPrefUpdate update(pref_service_.get(), kListPrefName);
144 base::ListValue* local_list_value = update.Get(); 140 base::ListValue* local_list_value = update.Get();
145 local_list_value->AppendString(local_url0_); 141 local_list_value->AppendString(local_url0_);
146 } 142 }
147 143
148 const PrefService::Preference* pref = 144 const PrefService::Preference* pref =
149 pref_service_->FindPreference(kListPrefName); 145 pref_service_->FindPreference(kListPrefName);
150 std::unique_ptr<base::Value> merged_value(pref_sync_service_->MergePreference( 146 std::unique_ptr<base::Value> merged_value(pref_sync_service_->MergePreference(
151 pref->name(), *pref->GetValue(), *null_value)); 147 pref->name(), *pref->GetValue(), *null_value));
152 const base::ListValue* local_list_value = 148 const base::ListValue* local_list_value =
153 pref_service_->GetList(kListPrefName); 149 pref_service_->GetList(kListPrefName);
154 EXPECT_TRUE(merged_value->Equals(local_list_value)); 150 EXPECT_TRUE(merged_value->Equals(local_list_value));
155 } 151 }
156 152
157 TEST_F(ListPreferenceMergeTest, ServerEmpty) { 153 TEST_F(ListPreferenceMergeTest, ServerEmpty) {
158 std::unique_ptr<base::Value> empty_value(new base::ListValue); 154 std::unique_ptr<base::Value> empty_value(new base::ListValue);
159 { 155 {
160 ListPrefUpdate update(pref_service_.get(), kListPrefName); 156 ListPrefUpdate update(pref_service_.get(), kListPrefName);
161 base::ListValue* local_list_value = update.Get(); 157 base::ListValue* local_list_value = update.Get();
162 local_list_value->AppendString(local_url0_); 158 local_list_value->AppendString(local_url0_);
163 } 159 }
164 160
165 const PrefService::Preference* pref = 161 const PrefService::Preference* pref =
166 pref_service_->FindPreference(kListPrefName); 162 pref_service_->FindPreference(kListPrefName);
167 std::unique_ptr<base::Value> merged_value(pref_sync_service_->MergePreference( 163 std::unique_ptr<base::Value> merged_value(pref_sync_service_->MergePreference(
168 pref->name(), *pref->GetValue(), *empty_value)); 164 pref->name(), *pref->GetValue(), *empty_value));
169 const base::ListValue* local_list_value = 165 const base::ListValue* local_list_value =
170 pref_service_->GetList(kListPrefName); 166 pref_service_->GetList(kListPrefName);
171 EXPECT_TRUE(merged_value->Equals(local_list_value)); 167 EXPECT_TRUE(merged_value->Equals(local_list_value));
172 } 168 }
173 169
174 TEST_F(ListPreferenceMergeTest, Merge) { 170 TEST_F(ListPreferenceMergeTest, Merge) {
175 { 171 {
176 ListPrefUpdate update(pref_service_.get(), kListPrefName); 172 ListPrefUpdate update(pref_service_.get(), kListPrefName);
177 base::ListValue* local_list_value = update.Get(); 173 base::ListValue* local_list_value = update.Get();
178 local_list_value->AppendString(local_url0_); 174 local_list_value->AppendString(local_url0_);
179 local_list_value->AppendString(local_url1_); 175 local_list_value->AppendString(local_url1_);
180 } 176 }
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 base::ListValue server_url_list_; 431 base::ListValue server_url_list_;
436 base::DictionaryValue server_patterns_; 432 base::DictionaryValue server_patterns_;
437 }; 433 };
438 434
439 TEST_F(IndividualPreferenceMergeTest, ListPreference) { 435 TEST_F(IndividualPreferenceMergeTest, ListPreference) {
440 EXPECT_TRUE(MergeListPreference(kListPrefName)); 436 EXPECT_TRUE(MergeListPreference(kListPrefName));
441 } 437 }
442 438
443 } // namespace 439 } // namespace
444 440
445 } // namespace syncable_prefs 441 } // namespace sync_preferences
OLDNEW
« no previous file with comments | « components/sync_preferences/pref_model_associator_client.h ('k') | components/sync_preferences/pref_service_mock_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698