| 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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 | 170 |
| 171 const sync_pb::PreferenceSpecifics& specifics( | 171 const sync_pb::PreferenceSpecifics& specifics( |
| 172 node.GetEntitySpecifics().preference()); | 172 node.GetEntitySpecifics().preference()); |
| 173 | 173 |
| 174 return base::JSONReader::Read(specifics.value()); | 174 return base::JSONReader::Read(specifics.value()); |
| 175 } | 175 } |
| 176 | 176 |
| 177 int64 WriteSyncedValue(const std::string& name, | 177 int64 WriteSyncedValue(const std::string& name, |
| 178 const Value& value, | 178 const Value& value, |
| 179 csync::WriteNode* node) { | 179 csync::WriteNode* node) { |
| 180 SyncData sync_data; | 180 csync::SyncData sync_data; |
| 181 if (!PrefModelAssociator::CreatePrefSyncData(name, | 181 if (!PrefModelAssociator::CreatePrefSyncData(name, |
| 182 value, | 182 value, |
| 183 &sync_data)) { | 183 &sync_data)) { |
| 184 return csync::kInvalidId; | 184 return csync::kInvalidId; |
| 185 } | 185 } |
| 186 node->SetEntitySpecifics(sync_data.GetSpecifics()); | 186 node->SetEntitySpecifics(sync_data.GetSpecifics()); |
| 187 return node->GetId(); | 187 return node->GetId(); |
| 188 } | 188 } |
| 189 | 189 |
| 190 bool IsSynced(const std::string& pref_name) { | 190 bool IsSynced(const std::string& pref_name) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 }; | 246 }; |
| 247 | 247 |
| 248 TEST_F(ProfileSyncServicePreferenceTest, CreatePrefSyncData) { | 248 TEST_F(ProfileSyncServicePreferenceTest, CreatePrefSyncData) { |
| 249 prefs_->SetString(prefs::kHomePage, example_url0_); | 249 prefs_->SetString(prefs::kHomePage, example_url0_); |
| 250 CreateRootHelper create_root(this, syncable::PREFERENCES); | 250 CreateRootHelper create_root(this, syncable::PREFERENCES); |
| 251 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); | 251 ASSERT_TRUE(StartSyncService(create_root.callback(), false)); |
| 252 ASSERT_TRUE(create_root.success()); | 252 ASSERT_TRUE(create_root.success()); |
| 253 | 253 |
| 254 const PrefService::Preference* pref = | 254 const PrefService::Preference* pref = |
| 255 prefs_->FindPreference(prefs::kHomePage); | 255 prefs_->FindPreference(prefs::kHomePage); |
| 256 SyncData sync_data; | 256 csync::SyncData sync_data; |
| 257 EXPECT_TRUE(PrefModelAssociator::CreatePrefSyncData(pref->name(), | 257 EXPECT_TRUE(PrefModelAssociator::CreatePrefSyncData(pref->name(), |
| 258 *pref->GetValue(), &sync_data)); | 258 *pref->GetValue(), &sync_data)); |
| 259 EXPECT_EQ(std::string(prefs::kHomePage), sync_data.GetTag()); | 259 EXPECT_EQ(std::string(prefs::kHomePage), sync_data.GetTag()); |
| 260 const sync_pb::PreferenceSpecifics& specifics(sync_data.GetSpecifics(). | 260 const sync_pb::PreferenceSpecifics& specifics(sync_data.GetSpecifics(). |
| 261 preference()); | 261 preference()); |
| 262 EXPECT_EQ(std::string(prefs::kHomePage), specifics.name()); | 262 EXPECT_EQ(std::string(prefs::kHomePage), specifics.name()); |
| 263 | 263 |
| 264 scoped_ptr<Value> value(base::JSONReader::Read(specifics.value())); | 264 scoped_ptr<Value> value(base::JSONReader::Read(specifics.value())); |
| 265 EXPECT_TRUE(pref->GetValue()->Equals(value.get())); | 265 EXPECT_TRUE(pref->GetValue()->Equals(value.get())); |
| 266 } | 266 } |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 EXPECT_FALSE(pref->IsDefaultValue()); | 575 EXPECT_FALSE(pref->IsDefaultValue()); |
| 576 // There should be no synced value. | 576 // There should be no synced value. |
| 577 EXPECT_TRUE(GetSyncedValue(prefs::kHomePage) == NULL); | 577 EXPECT_TRUE(GetSyncedValue(prefs::kHomePage) == NULL); |
| 578 // Switch kHomePage back to unmanaged. | 578 // Switch kHomePage back to unmanaged. |
| 579 profile_->GetTestingPrefService()->RemoveManagedPref(prefs::kHomePage); | 579 profile_->GetTestingPrefService()->RemoveManagedPref(prefs::kHomePage); |
| 580 // The original value should be picked up. | 580 // The original value should be picked up. |
| 581 EXPECT_TRUE(pref->IsDefaultValue()); | 581 EXPECT_TRUE(pref->IsDefaultValue()); |
| 582 // There should still be no synced value. | 582 // There should still be no synced value. |
| 583 EXPECT_TRUE(GetSyncedValue(prefs::kHomePage) == NULL); | 583 EXPECT_TRUE(GetSyncedValue(prefs::kHomePage) == NULL); |
| 584 } | 584 } |
| OLD | NEW |