OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <map> | 5 #include <map> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 | 169 |
170 // Caller gets ownership of the returned value. | 170 // Caller gets ownership of the returned value. |
171 const Value* GetSyncedValue(const std::string& name) { | 171 const Value* GetSyncedValue(const std::string& name) { |
172 sync_api::ReadTransaction trans(FROM_HERE, service_->GetUserShare()); | 172 sync_api::ReadTransaction trans(FROM_HERE, service_->GetUserShare()); |
173 sync_api::ReadNode node(&trans); | 173 sync_api::ReadNode node(&trans); |
174 | 174 |
175 if (!node.InitByClientTagLookup(syncable::PREFERENCES, name)) | 175 if (!node.InitByClientTagLookup(syncable::PREFERENCES, name)) |
176 return NULL; | 176 return NULL; |
177 | 177 |
178 const sync_pb::PreferenceSpecifics& specifics( | 178 const sync_pb::PreferenceSpecifics& specifics( |
179 node.GetEntitySpecifics().GetExtension(sync_pb::preference)); | 179 node.GetEntitySpecifics().preference()); |
180 | 180 |
181 JSONReader reader; | 181 JSONReader reader; |
182 return reader.JsonToValue(specifics.value(), false, false); | 182 return reader.JsonToValue(specifics.value(), false, false); |
183 } | 183 } |
184 | 184 |
185 int64 WriteSyncedValue(const std::string& name, | 185 int64 WriteSyncedValue(const std::string& name, |
186 const Value& value, | 186 const Value& value, |
187 sync_api::WriteNode* node) { | 187 sync_api::WriteNode* node) { |
188 SyncData sync_data; | 188 SyncData sync_data; |
189 if (!PrefModelAssociator::CreatePrefSyncData(name, | 189 if (!PrefModelAssociator::CreatePrefSyncData(name, |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); | 260 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); |
261 ASSERT_TRUE(create_root.success()); | 261 ASSERT_TRUE(create_root.success()); |
262 | 262 |
263 const PrefService::Preference* pref = | 263 const PrefService::Preference* pref = |
264 prefs_->FindPreference(prefs::kHomePage); | 264 prefs_->FindPreference(prefs::kHomePage); |
265 SyncData sync_data; | 265 SyncData sync_data; |
266 EXPECT_TRUE(PrefModelAssociator::CreatePrefSyncData(pref->name(), | 266 EXPECT_TRUE(PrefModelAssociator::CreatePrefSyncData(pref->name(), |
267 *pref->GetValue(), &sync_data)); | 267 *pref->GetValue(), &sync_data)); |
268 EXPECT_EQ(std::string(prefs::kHomePage), sync_data.GetTag()); | 268 EXPECT_EQ(std::string(prefs::kHomePage), sync_data.GetTag()); |
269 const sync_pb::PreferenceSpecifics& specifics(sync_data.GetSpecifics(). | 269 const sync_pb::PreferenceSpecifics& specifics(sync_data.GetSpecifics(). |
270 GetExtension(sync_pb::preference)); | 270 preference()); |
271 EXPECT_EQ(std::string(prefs::kHomePage), specifics.name()); | 271 EXPECT_EQ(std::string(prefs::kHomePage), specifics.name()); |
272 | 272 |
273 base::JSONReader reader; | 273 base::JSONReader reader; |
274 scoped_ptr<Value> value(reader.JsonToValue(specifics.value(), false, false)); | 274 scoped_ptr<Value> value(reader.JsonToValue(specifics.value(), false, false)); |
275 EXPECT_TRUE(pref->GetValue()->Equals(value.get())); | 275 EXPECT_TRUE(pref->GetValue()->Equals(value.get())); |
276 } | 276 } |
277 | 277 |
278 TEST_F(ProfileSyncServicePreferenceTest, ModelAssociationDoNotSyncDefaults) { | 278 TEST_F(ProfileSyncServicePreferenceTest, ModelAssociationDoNotSyncDefaults) { |
279 const PrefService::Preference* pref = | 279 const PrefService::Preference* pref = |
280 prefs_->FindPreference(prefs::kHomePage); | 280 prefs_->FindPreference(prefs::kHomePage); |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 EXPECT_FALSE(pref->IsDefaultValue()); | 585 EXPECT_FALSE(pref->IsDefaultValue()); |
586 // There should be no synced value. | 586 // There should be no synced value. |
587 EXPECT_TRUE(GetSyncedValue(prefs::kHomePage) == NULL); | 587 EXPECT_TRUE(GetSyncedValue(prefs::kHomePage) == NULL); |
588 // Switch kHomePage back to unmanaged. | 588 // Switch kHomePage back to unmanaged. |
589 profile_->GetTestingPrefService()->RemoveManagedPref(prefs::kHomePage); | 589 profile_->GetTestingPrefService()->RemoveManagedPref(prefs::kHomePage); |
590 // The original value should be picked up. | 590 // The original value should be picked up. |
591 EXPECT_TRUE(pref->IsDefaultValue()); | 591 EXPECT_TRUE(pref->IsDefaultValue()); |
592 // There should still be no synced value. | 592 // There should still be no synced value. |
593 EXPECT_TRUE(GetSyncedValue(prefs::kHomePage) == NULL); | 593 EXPECT_TRUE(GetSyncedValue(prefs::kHomePage) == NULL); |
594 } | 594 } |
OLD | NEW |