| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 return *change_processor; | 56 return *change_processor; |
| 57 } | 57 } |
| 58 | 58 |
| 59 // TODO(zea): Refactor to remove the ProfileSyncService usage. | 59 // TODO(zea): Refactor to remove the ProfileSyncService usage. |
| 60 class ProfileSyncServicePreferenceTest | 60 class ProfileSyncServicePreferenceTest |
| 61 : public AbstractProfileSyncServiceTest { | 61 : public AbstractProfileSyncServiceTest { |
| 62 public: | 62 public: |
| 63 int64 SetSyncedValue(const std::string& name, const Value& value) { | 63 int64 SetSyncedValue(const std::string& name, const Value& value) { |
| 64 sync_api::WriteTransaction trans(FROM_HERE, service_->GetUserShare()); | 64 sync_api::WriteTransaction trans(FROM_HERE, service_->GetUserShare()); |
| 65 sync_api::ReadNode root(&trans); | 65 sync_api::ReadNode root(&trans); |
| 66 if (!root.InitByTagLookup( | 66 if (root.InitByTagLookup(syncable::ModelTypeToRootTag( |
| 67 syncable::ModelTypeToRootTag(syncable::PREFERENCES))) { | 67 syncable::PREFERENCES)) != sync_api::BaseNode::INIT_OK) { |
| 68 return sync_api::kInvalidId; | 68 return sync_api::kInvalidId; |
| 69 } | 69 } |
| 70 | 70 |
| 71 sync_api::WriteNode tag_node(&trans); | 71 sync_api::WriteNode tag_node(&trans); |
| 72 sync_api::WriteNode node(&trans); | 72 sync_api::WriteNode node(&trans); |
| 73 | 73 |
| 74 if (tag_node.InitByClientTagLookup(syncable::PREFERENCES, name)) | 74 if (tag_node.InitByClientTagLookup(syncable::PREFERENCES, name) == |
| 75 sync_api::BaseNode::INIT_OK) { |
| 75 return WriteSyncedValue(name, value, &tag_node); | 76 return WriteSyncedValue(name, value, &tag_node); |
| 77 } |
| 76 if (node.InitUniqueByCreation(syncable::PREFERENCES, root, name)) | 78 if (node.InitUniqueByCreation(syncable::PREFERENCES, root, name)) |
| 77 return WriteSyncedValue(name, value, &node); | 79 return WriteSyncedValue(name, value, &node); |
| 78 | 80 |
| 79 return sync_api::kInvalidId; | 81 return sync_api::kInvalidId; |
| 80 } | 82 } |
| 81 | 83 |
| 82 protected: | 84 protected: |
| 83 ProfileSyncServicePreferenceTest() | 85 ProfileSyncServicePreferenceTest() |
| 84 : example_url0_("http://example.com/0"), | 86 : example_url0_("http://example.com/0"), |
| 85 example_url1_("http://example.com/1"), | 87 example_url1_("http://example.com/1"), |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 const PrefService::Preference* preference = | 153 const PrefService::Preference* preference = |
| 152 prefs_->FindPreference(name.c_str()); | 154 prefs_->FindPreference(name.c_str()); |
| 153 return *preference->GetValue(); | 155 return *preference->GetValue(); |
| 154 } | 156 } |
| 155 | 157 |
| 156 // Caller gets ownership of the returned value. | 158 // Caller gets ownership of the returned value. |
| 157 const Value* GetSyncedValue(const std::string& name) { | 159 const Value* GetSyncedValue(const std::string& name) { |
| 158 sync_api::ReadTransaction trans(FROM_HERE, service_->GetUserShare()); | 160 sync_api::ReadTransaction trans(FROM_HERE, service_->GetUserShare()); |
| 159 sync_api::ReadNode node(&trans); | 161 sync_api::ReadNode node(&trans); |
| 160 | 162 |
| 161 if (!node.InitByClientTagLookup(syncable::PREFERENCES, name)) | 163 if (node.InitByClientTagLookup(syncable::PREFERENCES, name) != |
| 164 sync_api::BaseNode::INIT_OK) { |
| 162 return NULL; | 165 return NULL; |
| 166 } |
| 163 | 167 |
| 164 const sync_pb::PreferenceSpecifics& specifics( | 168 const sync_pb::PreferenceSpecifics& specifics( |
| 165 node.GetEntitySpecifics().preference()); | 169 node.GetEntitySpecifics().preference()); |
| 166 | 170 |
| 167 return base::JSONReader::Read(specifics.value()); | 171 return base::JSONReader::Read(specifics.value()); |
| 168 } | 172 } |
| 169 | 173 |
| 170 int64 WriteSyncedValue(const std::string& name, | 174 int64 WriteSyncedValue(const std::string& name, |
| 171 const Value& value, | 175 const Value& value, |
| 172 sync_api::WriteNode* node) { | 176 sync_api::WriteNode* node) { |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 EXPECT_FALSE(pref->IsDefaultValue()); | 572 EXPECT_FALSE(pref->IsDefaultValue()); |
| 569 // There should be no synced value. | 573 // There should be no synced value. |
| 570 EXPECT_TRUE(GetSyncedValue(prefs::kHomePage) == NULL); | 574 EXPECT_TRUE(GetSyncedValue(prefs::kHomePage) == NULL); |
| 571 // Switch kHomePage back to unmanaged. | 575 // Switch kHomePage back to unmanaged. |
| 572 profile_->GetTestingPrefService()->RemoveManagedPref(prefs::kHomePage); | 576 profile_->GetTestingPrefService()->RemoveManagedPref(prefs::kHomePage); |
| 573 // The original value should be picked up. | 577 // The original value should be picked up. |
| 574 EXPECT_TRUE(pref->IsDefaultValue()); | 578 EXPECT_TRUE(pref->IsDefaultValue()); |
| 575 // There should still be no synced value. | 579 // There should still be no synced value. |
| 576 EXPECT_TRUE(GetSyncedValue(prefs::kHomePage) == NULL); | 580 EXPECT_TRUE(GetSyncedValue(prefs::kHomePage) == NULL); |
| 577 } | 581 } |
| OLD | NEW |