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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 const Value* GetSyncedValue(const std::string& name) { | 157 const Value* GetSyncedValue(const std::string& name) { |
158 sync_api::ReadTransaction trans(FROM_HERE, service_->GetUserShare()); | 158 sync_api::ReadTransaction trans(FROM_HERE, service_->GetUserShare()); |
159 sync_api::ReadNode node(&trans); | 159 sync_api::ReadNode node(&trans); |
160 | 160 |
161 if (!node.InitByClientTagLookup(syncable::PREFERENCES, name)) | 161 if (!node.InitByClientTagLookup(syncable::PREFERENCES, name)) |
162 return NULL; | 162 return NULL; |
163 | 163 |
164 const sync_pb::PreferenceSpecifics& specifics( | 164 const sync_pb::PreferenceSpecifics& specifics( |
165 node.GetEntitySpecifics().preference()); | 165 node.GetEntitySpecifics().preference()); |
166 | 166 |
167 JSONReader reader; | 167 return base::JSONReader::Read(specifics.value()); |
168 return reader.JsonToValue(specifics.value(), false, false); | |
169 } | 168 } |
170 | 169 |
171 int64 WriteSyncedValue(const std::string& name, | 170 int64 WriteSyncedValue(const std::string& name, |
172 const Value& value, | 171 const Value& value, |
173 sync_api::WriteNode* node) { | 172 sync_api::WriteNode* node) { |
174 SyncData sync_data; | 173 SyncData sync_data; |
175 if (!PrefModelAssociator::CreatePrefSyncData(name, | 174 if (!PrefModelAssociator::CreatePrefSyncData(name, |
176 value, | 175 value, |
177 &sync_data)) { | 176 &sync_data)) { |
178 return sync_api::kInvalidId; | 177 return sync_api::kInvalidId; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 const PrefService::Preference* pref = | 247 const PrefService::Preference* pref = |
249 prefs_->FindPreference(prefs::kHomePage); | 248 prefs_->FindPreference(prefs::kHomePage); |
250 SyncData sync_data; | 249 SyncData sync_data; |
251 EXPECT_TRUE(PrefModelAssociator::CreatePrefSyncData(pref->name(), | 250 EXPECT_TRUE(PrefModelAssociator::CreatePrefSyncData(pref->name(), |
252 *pref->GetValue(), &sync_data)); | 251 *pref->GetValue(), &sync_data)); |
253 EXPECT_EQ(std::string(prefs::kHomePage), sync_data.GetTag()); | 252 EXPECT_EQ(std::string(prefs::kHomePage), sync_data.GetTag()); |
254 const sync_pb::PreferenceSpecifics& specifics(sync_data.GetSpecifics(). | 253 const sync_pb::PreferenceSpecifics& specifics(sync_data.GetSpecifics(). |
255 preference()); | 254 preference()); |
256 EXPECT_EQ(std::string(prefs::kHomePage), specifics.name()); | 255 EXPECT_EQ(std::string(prefs::kHomePage), specifics.name()); |
257 | 256 |
258 base::JSONReader reader; | 257 scoped_ptr<Value> value(base::JSONReader::Read(specifics.value())); |
259 scoped_ptr<Value> value(reader.JsonToValue(specifics.value(), false, false)); | |
260 EXPECT_TRUE(pref->GetValue()->Equals(value.get())); | 258 EXPECT_TRUE(pref->GetValue()->Equals(value.get())); |
261 } | 259 } |
262 | 260 |
263 TEST_F(ProfileSyncServicePreferenceTest, ModelAssociationDoNotSyncDefaults) { | 261 TEST_F(ProfileSyncServicePreferenceTest, ModelAssociationDoNotSyncDefaults) { |
264 const PrefService::Preference* pref = | 262 const PrefService::Preference* pref = |
265 prefs_->FindPreference(prefs::kHomePage); | 263 prefs_->FindPreference(prefs::kHomePage); |
266 EXPECT_TRUE(pref->IsDefaultValue()); | 264 EXPECT_TRUE(pref->IsDefaultValue()); |
267 CreateRootHelper create_root(this, syncable::PREFERENCES); | 265 CreateRootHelper create_root(this, syncable::PREFERENCES); |
268 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); | 266 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); |
269 ASSERT_TRUE(create_root.success()); | 267 ASSERT_TRUE(create_root.success()); |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 EXPECT_FALSE(pref->IsDefaultValue()); | 568 EXPECT_FALSE(pref->IsDefaultValue()); |
571 // There should be no synced value. | 569 // There should be no synced value. |
572 EXPECT_TRUE(GetSyncedValue(prefs::kHomePage) == NULL); | 570 EXPECT_TRUE(GetSyncedValue(prefs::kHomePage) == NULL); |
573 // Switch kHomePage back to unmanaged. | 571 // Switch kHomePage back to unmanaged. |
574 profile_->GetTestingPrefService()->RemoveManagedPref(prefs::kHomePage); | 572 profile_->GetTestingPrefService()->RemoveManagedPref(prefs::kHomePage); |
575 // The original value should be picked up. | 573 // The original value should be picked up. |
576 EXPECT_TRUE(pref->IsDefaultValue()); | 574 EXPECT_TRUE(pref->IsDefaultValue()); |
577 // There should still be no synced value. | 575 // There should still be no synced value. |
578 EXPECT_TRUE(GetSyncedValue(prefs::kHomePage) == NULL); | 576 EXPECT_TRUE(GetSyncedValue(prefs::kHomePage) == NULL); |
579 } | 577 } |
OLD | NEW |