Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: components/autofill/core/browser/webdata/autocomplete_sync_bridge_unittest.cc

Issue 2923363004: [Sync] Migrate bridge implementations to change list based MergeSyncData (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "components/autofill/core/browser/webdata/autocomplete_sync_bridge.h" 5 #include "components/autofill/core/browser/webdata/autocomplete_sync_bridge.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 25 matching lines...) Expand all
36 using base::TimeDelta; 36 using base::TimeDelta;
37 using sync_pb::AutofillSpecifics; 37 using sync_pb::AutofillSpecifics;
38 using sync_pb::EntityMetadata; 38 using sync_pb::EntityMetadata;
39 using sync_pb::EntitySpecifics; 39 using sync_pb::EntitySpecifics;
40 using sync_pb::ModelTypeState; 40 using sync_pb::ModelTypeState;
41 using syncer::DataBatch; 41 using syncer::DataBatch;
42 using syncer::EntityChange; 42 using syncer::EntityChange;
43 using syncer::EntityChangeList; 43 using syncer::EntityChangeList;
44 using syncer::EntityData; 44 using syncer::EntityData;
45 using syncer::EntityDataPtr; 45 using syncer::EntityDataPtr;
46 using syncer::EntityDataMap;
47 using syncer::FakeModelTypeChangeProcessor; 46 using syncer::FakeModelTypeChangeProcessor;
48 using syncer::KeyAndData; 47 using syncer::KeyAndData;
49 using syncer::ModelError; 48 using syncer::ModelError;
50 using syncer::ModelType; 49 using syncer::ModelType;
51 using syncer::ModelTypeChangeProcessor; 50 using syncer::ModelTypeChangeProcessor;
52 using syncer::ModelTypeSyncBridge; 51 using syncer::ModelTypeSyncBridge;
53 using syncer::RecordingModelTypeChangeProcessor; 52 using syncer::RecordingModelTypeChangeProcessor;
54 53
55 namespace autofill { 54 namespace autofill {
56 55
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 return tag; 186 return tag;
188 } 187 }
189 188
190 std::string GetStorageKey(const AutofillSpecifics& specifics) { 189 std::string GetStorageKey(const AutofillSpecifics& specifics) {
191 std::string key = 190 std::string key =
192 bridge()->GetStorageKey(SpecificsToEntity(specifics).value()); 191 bridge()->GetStorageKey(SpecificsToEntity(specifics).value());
193 EXPECT_FALSE(key.empty()); 192 EXPECT_FALSE(key.empty());
194 return key; 193 return key;
195 } 194 }
196 195
197 EntityChangeList EntityAddList( 196 EntityChangeList CreateEntityAddList(
198 const std::vector<AutofillSpecifics>& specifics_vector) { 197 const std::vector<AutofillSpecifics>& specifics_vector) {
199 EntityChangeList changes; 198 EntityChangeList changes;
200 for (const auto& specifics : specifics_vector) { 199 for (const auto& specifics : specifics_vector) {
201 changes.push_back(EntityChange::CreateAdd(GetStorageKey(specifics), 200 changes.push_back(EntityChange::CreateAdd(GetStorageKey(specifics),
202 SpecificsToEntity(specifics))); 201 SpecificsToEntity(specifics)));
203 } 202 }
204 return changes; 203 return changes;
205 } 204 }
206 205
207 EntityDataMap CreateEntityDataMap( 206 void VerifyApplyChanges(const EntityChangeList& changes) {
208 const std::vector<AutofillSpecifics>& specifics_vector) {
209 EntityDataMap map;
210 for (const auto& specifics : specifics_vector) {
211 map[GetStorageKey(specifics)] = SpecificsToEntity(specifics);
212 }
213 return map;
214 }
215
216 void VerifyApplyChanges(const std::vector<EntityChange>& changes) {
217 const auto error = bridge()->ApplySyncChanges( 207 const auto error = bridge()->ApplySyncChanges(
218 bridge()->CreateMetadataChangeList(), changes); 208 bridge()->CreateMetadataChangeList(), changes);
219 EXPECT_FALSE(error); 209 EXPECT_FALSE(error);
220 } 210 }
221 211
222 void VerifyApplyAdds(const std::vector<AutofillSpecifics>& specifics) { 212 void VerifyApplyAdds(const std::vector<AutofillSpecifics>& specifics) {
223 VerifyApplyChanges(EntityAddList(specifics)); 213 VerifyApplyChanges(CreateEntityAddList(specifics));
224 } 214 }
225 215
226 void VerifyMerge(const std::vector<AutofillSpecifics>& specifics) { 216 void VerifyMerge(const std::vector<AutofillSpecifics>& specifics) {
227 const auto error = bridge()->MergeSyncData( 217 const auto error = bridge()->MergeSyncData(
228 bridge()->CreateMetadataChangeList(), CreateEntityDataMap(specifics)); 218 bridge()->CreateMetadataChangeList(), CreateEntityAddList(specifics));
229 EXPECT_FALSE(error); 219 EXPECT_FALSE(error);
230 } 220 }
231 221
232 std::map<std::string, AutofillSpecifics> ExpectedMap( 222 std::map<std::string, AutofillSpecifics> ExpectedMap(
233 const std::vector<AutofillSpecifics>& specifics_vector) { 223 const std::vector<AutofillSpecifics>& specifics_vector) {
234 std::map<std::string, AutofillSpecifics> map; 224 std::map<std::string, AutofillSpecifics> map;
235 for (const auto& specifics : specifics_vector) { 225 for (const auto& specifics : specifics_vector) {
236 map[GetStorageKey(specifics)] = specifics; 226 map[GetStorageKey(specifics)] = specifics;
237 } 227 }
238 return map; 228 return map;
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 VerifyMerge({remote2, specifics3, remote4}); 669 VerifyMerge({remote2, specifics3, remote4});
680 670
681 VerifyAllData({local1, remote2, specifics3, merged4}); 671 VerifyAllData({local1, remote2, specifics3, merged4});
682 EXPECT_EQ(2u, processor().put_multimap().size()); 672 EXPECT_EQ(2u, processor().put_multimap().size());
683 VerifyProcessorRecordedPut(local1); 673 VerifyProcessorRecordedPut(local1);
684 VerifyProcessorRecordedPut(merged4); 674 VerifyProcessorRecordedPut(merged4);
685 EXPECT_EQ(0u, processor().delete_set().size()); 675 EXPECT_EQ(0u, processor().delete_set().size());
686 } 676 }
687 677
688 } // namespace autofill 678 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698