| OLD | NEW |
| 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/syncable_prefs/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" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 PrefModelAssociator* pref_sync_service_; | 99 PrefModelAssociator* pref_sync_service_; |
| 100 }; | 100 }; |
| 101 | 101 |
| 102 class ListPreferenceMergeTest : public AbstractPreferenceMergeTest { | 102 class ListPreferenceMergeTest : public AbstractPreferenceMergeTest { |
| 103 protected: | 103 protected: |
| 104 ListPreferenceMergeTest() | 104 ListPreferenceMergeTest() |
| 105 : server_url0_("http://example.com/server0"), | 105 : server_url0_("http://example.com/server0"), |
| 106 server_url1_("http://example.com/server1"), | 106 server_url1_("http://example.com/server1"), |
| 107 local_url0_("http://example.com/local0"), | 107 local_url0_("http://example.com/local0"), |
| 108 local_url1_("http://example.com/local1") { | 108 local_url1_("http://example.com/local1") { |
| 109 server_url_list_.Append(new base::StringValue(server_url0_)); | 109 server_url_list_.AppendString(server_url0_); |
| 110 server_url_list_.Append(new base::StringValue(server_url1_)); | 110 server_url_list_.AppendString(server_url1_); |
| 111 } | 111 } |
| 112 | 112 |
| 113 std::string server_url0_; | 113 std::string server_url0_; |
| 114 std::string server_url1_; | 114 std::string server_url1_; |
| 115 std::string local_url0_; | 115 std::string local_url0_; |
| 116 std::string local_url1_; | 116 std::string local_url1_; |
| 117 base::ListValue server_url_list_; | 117 base::ListValue server_url_list_; |
| 118 }; | 118 }; |
| 119 | 119 |
| 120 TEST_F(ListPreferenceMergeTest, NotListOrDictionary) { | 120 TEST_F(ListPreferenceMergeTest, NotListOrDictionary) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 135 std::unique_ptr<base::Value> merged_value(pref_sync_service_->MergePreference( | 135 std::unique_ptr<base::Value> merged_value(pref_sync_service_->MergePreference( |
| 136 pref->name(), *pref->GetValue(), server_url_list_)); | 136 pref->name(), *pref->GetValue(), server_url_list_)); |
| 137 EXPECT_TRUE(merged_value->Equals(&server_url_list_)); | 137 EXPECT_TRUE(merged_value->Equals(&server_url_list_)); |
| 138 } | 138 } |
| 139 | 139 |
| 140 TEST_F(ListPreferenceMergeTest, ServerNull) { | 140 TEST_F(ListPreferenceMergeTest, ServerNull) { |
| 141 std::unique_ptr<base::Value> null_value = base::Value::CreateNullValue(); | 141 std::unique_ptr<base::Value> null_value = base::Value::CreateNullValue(); |
| 142 { | 142 { |
| 143 ListPrefUpdate update(pref_service_.get(), kListPrefName); | 143 ListPrefUpdate update(pref_service_.get(), kListPrefName); |
| 144 base::ListValue* local_list_value = update.Get(); | 144 base::ListValue* local_list_value = update.Get(); |
| 145 local_list_value->Append(new base::StringValue(local_url0_)); | 145 local_list_value->AppendString(local_url0_); |
| 146 } | 146 } |
| 147 | 147 |
| 148 const PrefService::Preference* pref = | 148 const PrefService::Preference* pref = |
| 149 pref_service_->FindPreference(kListPrefName); | 149 pref_service_->FindPreference(kListPrefName); |
| 150 std::unique_ptr<base::Value> merged_value(pref_sync_service_->MergePreference( | 150 std::unique_ptr<base::Value> merged_value(pref_sync_service_->MergePreference( |
| 151 pref->name(), *pref->GetValue(), *null_value)); | 151 pref->name(), *pref->GetValue(), *null_value)); |
| 152 const base::ListValue* local_list_value = | 152 const base::ListValue* local_list_value = |
| 153 pref_service_->GetList(kListPrefName); | 153 pref_service_->GetList(kListPrefName); |
| 154 EXPECT_TRUE(merged_value->Equals(local_list_value)); | 154 EXPECT_TRUE(merged_value->Equals(local_list_value)); |
| 155 } | 155 } |
| 156 | 156 |
| 157 TEST_F(ListPreferenceMergeTest, ServerEmpty) { | 157 TEST_F(ListPreferenceMergeTest, ServerEmpty) { |
| 158 std::unique_ptr<base::Value> empty_value(new base::ListValue); | 158 std::unique_ptr<base::Value> empty_value(new base::ListValue); |
| 159 { | 159 { |
| 160 ListPrefUpdate update(pref_service_.get(), kListPrefName); | 160 ListPrefUpdate update(pref_service_.get(), kListPrefName); |
| 161 base::ListValue* local_list_value = update.Get(); | 161 base::ListValue* local_list_value = update.Get(); |
| 162 local_list_value->Append(new base::StringValue(local_url0_)); | 162 local_list_value->AppendString(local_url0_); |
| 163 } | 163 } |
| 164 | 164 |
| 165 const PrefService::Preference* pref = | 165 const PrefService::Preference* pref = |
| 166 pref_service_->FindPreference(kListPrefName); | 166 pref_service_->FindPreference(kListPrefName); |
| 167 std::unique_ptr<base::Value> merged_value(pref_sync_service_->MergePreference( | 167 std::unique_ptr<base::Value> merged_value(pref_sync_service_->MergePreference( |
| 168 pref->name(), *pref->GetValue(), *empty_value)); | 168 pref->name(), *pref->GetValue(), *empty_value)); |
| 169 const base::ListValue* local_list_value = | 169 const base::ListValue* local_list_value = |
| 170 pref_service_->GetList(kListPrefName); | 170 pref_service_->GetList(kListPrefName); |
| 171 EXPECT_TRUE(merged_value->Equals(local_list_value)); | 171 EXPECT_TRUE(merged_value->Equals(local_list_value)); |
| 172 } | 172 } |
| 173 | 173 |
| 174 TEST_F(ListPreferenceMergeTest, Merge) { | 174 TEST_F(ListPreferenceMergeTest, Merge) { |
| 175 { | 175 { |
| 176 ListPrefUpdate update(pref_service_.get(), kListPrefName); | 176 ListPrefUpdate update(pref_service_.get(), kListPrefName); |
| 177 base::ListValue* local_list_value = update.Get(); | 177 base::ListValue* local_list_value = update.Get(); |
| 178 local_list_value->Append(new base::StringValue(local_url0_)); | 178 local_list_value->AppendString(local_url0_); |
| 179 local_list_value->Append(new base::StringValue(local_url1_)); | 179 local_list_value->AppendString(local_url1_); |
| 180 } | 180 } |
| 181 | 181 |
| 182 const PrefService::Preference* pref = | 182 const PrefService::Preference* pref = |
| 183 pref_service_->FindPreference(kListPrefName); | 183 pref_service_->FindPreference(kListPrefName); |
| 184 std::unique_ptr<base::Value> merged_value(pref_sync_service_->MergePreference( | 184 std::unique_ptr<base::Value> merged_value(pref_sync_service_->MergePreference( |
| 185 pref->name(), *pref->GetValue(), server_url_list_)); | 185 pref->name(), *pref->GetValue(), server_url_list_)); |
| 186 | 186 |
| 187 base::ListValue expected; | 187 base::ListValue expected; |
| 188 expected.Append(new base::StringValue(server_url0_)); | 188 expected.AppendString(server_url0_); |
| 189 expected.Append(new base::StringValue(server_url1_)); | 189 expected.AppendString(server_url1_); |
| 190 expected.Append(new base::StringValue(local_url0_)); | 190 expected.AppendString(local_url0_); |
| 191 expected.Append(new base::StringValue(local_url1_)); | 191 expected.AppendString(local_url1_); |
| 192 EXPECT_TRUE(merged_value->Equals(&expected)); | 192 EXPECT_TRUE(merged_value->Equals(&expected)); |
| 193 } | 193 } |
| 194 | 194 |
| 195 TEST_F(ListPreferenceMergeTest, Duplicates) { | 195 TEST_F(ListPreferenceMergeTest, Duplicates) { |
| 196 { | 196 { |
| 197 ListPrefUpdate update(pref_service_.get(), kListPrefName); | 197 ListPrefUpdate update(pref_service_.get(), kListPrefName); |
| 198 base::ListValue* local_list_value = update.Get(); | 198 base::ListValue* local_list_value = update.Get(); |
| 199 local_list_value->Append(new base::StringValue(local_url0_)); | 199 local_list_value->AppendString(local_url0_); |
| 200 local_list_value->Append(new base::StringValue(server_url0_)); | 200 local_list_value->AppendString(server_url0_); |
| 201 local_list_value->Append(new base::StringValue(server_url1_)); | 201 local_list_value->AppendString(server_url1_); |
| 202 } | 202 } |
| 203 | 203 |
| 204 const PrefService::Preference* pref = | 204 const PrefService::Preference* pref = |
| 205 pref_service_->FindPreference(kListPrefName); | 205 pref_service_->FindPreference(kListPrefName); |
| 206 std::unique_ptr<base::Value> merged_value(pref_sync_service_->MergePreference( | 206 std::unique_ptr<base::Value> merged_value(pref_sync_service_->MergePreference( |
| 207 pref->name(), *pref->GetValue(), server_url_list_)); | 207 pref->name(), *pref->GetValue(), server_url_list_)); |
| 208 | 208 |
| 209 base::ListValue expected; | 209 base::ListValue expected; |
| 210 expected.Append(new base::StringValue(server_url0_)); | 210 expected.AppendString(server_url0_); |
| 211 expected.Append(new base::StringValue(server_url1_)); | 211 expected.AppendString(server_url1_); |
| 212 expected.Append(new base::StringValue(local_url0_)); | 212 expected.AppendString(local_url0_); |
| 213 EXPECT_TRUE(merged_value->Equals(&expected)); | 213 EXPECT_TRUE(merged_value->Equals(&expected)); |
| 214 } | 214 } |
| 215 | 215 |
| 216 TEST_F(ListPreferenceMergeTest, Equals) { | 216 TEST_F(ListPreferenceMergeTest, Equals) { |
| 217 { | 217 { |
| 218 ListPrefUpdate update(pref_service_.get(), kListPrefName); | 218 ListPrefUpdate update(pref_service_.get(), kListPrefName); |
| 219 base::ListValue* local_list_value = update.Get(); | 219 base::ListValue* local_list_value = update.Get(); |
| 220 local_list_value->Append(new base::StringValue(server_url0_)); | 220 local_list_value->AppendString(server_url0_); |
| 221 local_list_value->Append(new base::StringValue(server_url1_)); | 221 local_list_value->AppendString(server_url1_); |
| 222 } | 222 } |
| 223 | 223 |
| 224 std::unique_ptr<base::Value> original(server_url_list_.DeepCopy()); | 224 std::unique_ptr<base::Value> original(server_url_list_.DeepCopy()); |
| 225 const PrefService::Preference* pref = | 225 const PrefService::Preference* pref = |
| 226 pref_service_->FindPreference(kListPrefName); | 226 pref_service_->FindPreference(kListPrefName); |
| 227 std::unique_ptr<base::Value> merged_value(pref_sync_service_->MergePreference( | 227 std::unique_ptr<base::Value> merged_value(pref_sync_service_->MergePreference( |
| 228 pref->name(), *pref->GetValue(), server_url_list_)); | 228 pref->name(), *pref->GetValue(), server_url_list_)); |
| 229 EXPECT_TRUE(merged_value->Equals(original.get())); | 229 EXPECT_TRUE(merged_value->Equals(original.get())); |
| 230 } | 230 } |
| 231 | 231 |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 EXPECT_TRUE(merged_value->Equals(&server_patterns_)); | 382 EXPECT_TRUE(merged_value->Equals(&server_patterns_)); |
| 383 } | 383 } |
| 384 | 384 |
| 385 class IndividualPreferenceMergeTest : public AbstractPreferenceMergeTest { | 385 class IndividualPreferenceMergeTest : public AbstractPreferenceMergeTest { |
| 386 protected: | 386 protected: |
| 387 IndividualPreferenceMergeTest() | 387 IndividualPreferenceMergeTest() |
| 388 : url0_("http://example.com/server0"), | 388 : url0_("http://example.com/server0"), |
| 389 url1_("http://example.com/server1"), | 389 url1_("http://example.com/server1"), |
| 390 expression0_("expression0"), | 390 expression0_("expression0"), |
| 391 expression1_("expression1") { | 391 expression1_("expression1") { |
| 392 server_url_list_.Append(new base::StringValue(url0_)); | 392 server_url_list_.AppendString(url0_); |
| 393 SetContentPattern(&server_patterns_, expression0_, 1); | 393 SetContentPattern(&server_patterns_, expression0_, 1); |
| 394 } | 394 } |
| 395 | 395 |
| 396 bool MergeListPreference(const char* pref) { | 396 bool MergeListPreference(const char* pref) { |
| 397 { | 397 { |
| 398 ListPrefUpdate update(pref_service_.get(), pref); | 398 ListPrefUpdate update(pref_service_.get(), pref); |
| 399 base::ListValue* local_list_value = update.Get(); | 399 base::ListValue* local_list_value = update.Get(); |
| 400 local_list_value->Append(new base::StringValue(url1_)); | 400 local_list_value->AppendString(url1_); |
| 401 } | 401 } |
| 402 | 402 |
| 403 std::unique_ptr<base::Value> merged_value( | 403 std::unique_ptr<base::Value> merged_value( |
| 404 pref_sync_service_->MergePreference( | 404 pref_sync_service_->MergePreference( |
| 405 pref, *pref_service_->GetUserPrefValue(pref), server_url_list_)); | 405 pref, *pref_service_->GetUserPrefValue(pref), server_url_list_)); |
| 406 | 406 |
| 407 base::ListValue expected; | 407 base::ListValue expected; |
| 408 expected.Append(new base::StringValue(url0_)); | 408 expected.AppendString(url0_); |
| 409 expected.Append(new base::StringValue(url1_)); | 409 expected.AppendString(url1_); |
| 410 return merged_value->Equals(&expected); | 410 return merged_value->Equals(&expected); |
| 411 } | 411 } |
| 412 | 412 |
| 413 bool MergeDictionaryPreference(const char* pref) { | 413 bool MergeDictionaryPreference(const char* pref) { |
| 414 { | 414 { |
| 415 DictionaryPrefUpdate update(pref_service_.get(), pref); | 415 DictionaryPrefUpdate update(pref_service_.get(), pref); |
| 416 base::DictionaryValue* local_dict_value = update.Get(); | 416 base::DictionaryValue* local_dict_value = update.Get(); |
| 417 SetContentPattern(local_dict_value, expression1_, 1); | 417 SetContentPattern(local_dict_value, expression1_, 1); |
| 418 } | 418 } |
| 419 | 419 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 436 base::DictionaryValue server_patterns_; | 436 base::DictionaryValue server_patterns_; |
| 437 }; | 437 }; |
| 438 | 438 |
| 439 TEST_F(IndividualPreferenceMergeTest, ListPreference) { | 439 TEST_F(IndividualPreferenceMergeTest, ListPreference) { |
| 440 EXPECT_TRUE(MergeListPreference(kListPrefName)); | 440 EXPECT_TRUE(MergeListPreference(kListPrefName)); |
| 441 } | 441 } |
| 442 | 442 |
| 443 } // namespace | 443 } // namespace |
| 444 | 444 |
| 445 } // namespace syncable_prefs | 445 } // namespace syncable_prefs |
| OLD | NEW |