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( |
67 syncable::ModelTypeToRootTag(syncable::PREFERENCES))) { | 67 syncable::ModelTypeToRootTag(syncable::PREFERENCES)) != |
Nicolas Zea
2012/04/19 23:55:43
nit: move to prev line? (if it fits)
tim (not reviewing)
2012/04/20 18:27:04
Done.
| |
68 sync_api::BaseNode::INIT_OK) { | |
68 return sync_api::kInvalidId; | 69 return sync_api::kInvalidId; |
69 } | 70 } |
70 | 71 |
71 sync_api::WriteNode tag_node(&trans); | 72 sync_api::WriteNode tag_node(&trans); |
72 sync_api::WriteNode node(&trans); | 73 sync_api::WriteNode node(&trans); |
73 | 74 |
74 if (tag_node.InitByClientTagLookup(syncable::PREFERENCES, name)) | 75 if (tag_node.InitByClientTagLookup(syncable::PREFERENCES, name) == |
76 sync_api::BaseNode::INIT_OK) { | |
75 return WriteSyncedValue(name, value, &tag_node); | 77 return WriteSyncedValue(name, value, &tag_node); |
78 } | |
76 if (node.InitUniqueByCreation(syncable::PREFERENCES, root, name)) | 79 if (node.InitUniqueByCreation(syncable::PREFERENCES, root, name)) |
77 return WriteSyncedValue(name, value, &node); | 80 return WriteSyncedValue(name, value, &node); |
78 | 81 |
79 return sync_api::kInvalidId; | 82 return sync_api::kInvalidId; |
80 } | 83 } |
81 | 84 |
82 protected: | 85 protected: |
83 ProfileSyncServicePreferenceTest() | 86 ProfileSyncServicePreferenceTest() |
84 : example_url0_("http://example.com/0"), | 87 : example_url0_("http://example.com/0"), |
85 example_url1_("http://example.com/1"), | 88 example_url1_("http://example.com/1"), |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 const PrefService::Preference* preference = | 154 const PrefService::Preference* preference = |
152 prefs_->FindPreference(name.c_str()); | 155 prefs_->FindPreference(name.c_str()); |
153 return *preference->GetValue(); | 156 return *preference->GetValue(); |
154 } | 157 } |
155 | 158 |
156 // Caller gets ownership of the returned value. | 159 // Caller gets ownership of the returned value. |
157 const Value* GetSyncedValue(const std::string& name) { | 160 const Value* GetSyncedValue(const std::string& name) { |
158 sync_api::ReadTransaction trans(FROM_HERE, service_->GetUserShare()); | 161 sync_api::ReadTransaction trans(FROM_HERE, service_->GetUserShare()); |
159 sync_api::ReadNode node(&trans); | 162 sync_api::ReadNode node(&trans); |
160 | 163 |
161 if (!node.InitByClientTagLookup(syncable::PREFERENCES, name)) | 164 if (node.InitByClientTagLookup(syncable::PREFERENCES, name) != |
165 sync_api::BaseNode::INIT_OK) { | |
162 return NULL; | 166 return NULL; |
167 } | |
163 | 168 |
164 const sync_pb::PreferenceSpecifics& specifics( | 169 const sync_pb::PreferenceSpecifics& specifics( |
165 node.GetEntitySpecifics().preference()); | 170 node.GetEntitySpecifics().preference()); |
166 | 171 |
167 return base::JSONReader::Read(specifics.value()); | 172 return base::JSONReader::Read(specifics.value()); |
168 } | 173 } |
169 | 174 |
170 int64 WriteSyncedValue(const std::string& name, | 175 int64 WriteSyncedValue(const std::string& name, |
171 const Value& value, | 176 const Value& value, |
172 sync_api::WriteNode* node) { | 177 sync_api::WriteNode* node) { |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
568 EXPECT_FALSE(pref->IsDefaultValue()); | 573 EXPECT_FALSE(pref->IsDefaultValue()); |
569 // There should be no synced value. | 574 // There should be no synced value. |
570 EXPECT_TRUE(GetSyncedValue(prefs::kHomePage) == NULL); | 575 EXPECT_TRUE(GetSyncedValue(prefs::kHomePage) == NULL); |
571 // Switch kHomePage back to unmanaged. | 576 // Switch kHomePage back to unmanaged. |
572 profile_->GetTestingPrefService()->RemoveManagedPref(prefs::kHomePage); | 577 profile_->GetTestingPrefService()->RemoveManagedPref(prefs::kHomePage); |
573 // The original value should be picked up. | 578 // The original value should be picked up. |
574 EXPECT_TRUE(pref->IsDefaultValue()); | 579 EXPECT_TRUE(pref->IsDefaultValue()); |
575 // There should still be no synced value. | 580 // There should still be no synced value. |
576 EXPECT_TRUE(GetSyncedValue(prefs::kHomePage) == NULL); | 581 EXPECT_TRUE(GetSyncedValue(prefs::kHomePage) == NULL); |
577 } | 582 } |
OLD | NEW |