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

Side by Side Diff: chrome/browser/webdata/autofill_profile_syncable_service_unittest.cc

Issue 10698014: [Sync] Rename csync namespace to syncer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 5 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 | Annotate | Revision Log
OLDNEW
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 "base/location.h" 5 #include "base/location.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/autofill/autofill_profile.h" 8 #include "chrome/browser/autofill/autofill_profile.h"
9 #include "chrome/browser/webdata/autofill_change.h" 9 #include "chrome/browser/webdata/autofill_change.h"
10 #include "chrome/browser/webdata/autofill_profile_syncable_service.h" 10 #include "chrome/browser/webdata/autofill_profile_syncable_service.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 }; 42 };
43 43
44 ACTION_P(CopyData, data) { 44 ACTION_P(CopyData, data) {
45 arg0->resize(data->size()); 45 arg0->resize(data->size());
46 std::copy(data->begin(), data->end(), arg0->begin()); 46 std::copy(data->begin(), data->end(), arg0->begin());
47 } 47 }
48 48
49 MATCHER_P(CheckSyncChanges, n_sync_changes_list, "") { 49 MATCHER_P(CheckSyncChanges, n_sync_changes_list, "") {
50 if (arg.size() != n_sync_changes_list.size()) 50 if (arg.size() != n_sync_changes_list.size())
51 return false; 51 return false;
52 csync::SyncChangeList::const_iterator passed, expected; 52 syncer::SyncChangeList::const_iterator passed, expected;
53 for (passed = arg.begin(), expected = n_sync_changes_list.begin(); 53 for (passed = arg.begin(), expected = n_sync_changes_list.begin();
54 passed != arg.end() && expected != n_sync_changes_list.end(); 54 passed != arg.end() && expected != n_sync_changes_list.end();
55 ++passed, ++expected) { 55 ++passed, ++expected) {
56 DCHECK(passed->IsValid()); 56 DCHECK(passed->IsValid());
57 if (passed->change_type() != expected->change_type()) 57 if (passed->change_type() != expected->change_type())
58 return false; 58 return false;
59 if (passed->sync_data().GetSpecifics().autofill_profile().guid() != 59 if (passed->sync_data().GetSpecifics().autofill_profile().guid() !=
60 expected->sync_data().GetSpecifics().autofill_profile().guid()) { 60 expected->sync_data().GetSpecifics().autofill_profile().guid()) {
61 return false; 61 return false;
62 } 62 }
(...skipping 17 matching lines...) Expand all
80 return false; 80 return false;
81 } 81 }
82 } 82 }
83 for (size_t i = 0; i < arg.profiles_to_add.size(); ++i) { 83 for (size_t i = 0; i < arg.profiles_to_add.size(); ++i) {
84 if (arg.profiles_to_add[i]->Compare(*n_bundle.profiles_to_add[i])) 84 if (arg.profiles_to_add[i]->Compare(*n_bundle.profiles_to_add[i]))
85 return false; 85 return false;
86 } 86 }
87 return true; 87 return true;
88 } 88 }
89 89
90 class MockSyncChangeProcessor : public csync::SyncChangeProcessor { 90 class MockSyncChangeProcessor : public syncer::SyncChangeProcessor {
91 public: 91 public:
92 MockSyncChangeProcessor() {} 92 MockSyncChangeProcessor() {}
93 virtual ~MockSyncChangeProcessor() {} 93 virtual ~MockSyncChangeProcessor() {}
94 94
95 MOCK_METHOD2(ProcessSyncChanges, 95 MOCK_METHOD2(ProcessSyncChanges,
96 csync::SyncError(const tracked_objects::Location&, 96 syncer::SyncError(const tracked_objects::Location&,
97 const csync::SyncChangeList&)); 97 const syncer::SyncChangeList&));
98 }; 98 };
99 99
100 class AutofillProfileSyncableServiceTest : public testing::Test { 100 class AutofillProfileSyncableServiceTest : public testing::Test {
101 public: 101 public:
102 AutofillProfileSyncableServiceTest() 102 AutofillProfileSyncableServiceTest()
103 : ui_thread_(BrowserThread::UI, &message_loop_), 103 : ui_thread_(BrowserThread::UI, &message_loop_),
104 db_thread_(BrowserThread::DB, &message_loop_) {} 104 db_thread_(BrowserThread::DB, &message_loop_) {}
105 105
106 virtual void SetUp() OVERRIDE { 106 virtual void SetUp() OVERRIDE {
107 sync_processor_.reset(new MockSyncChangeProcessor); 107 sync_processor_.reset(new MockSyncChangeProcessor);
(...skipping 16 matching lines...) Expand all
124 124
125 profiles_from_web_db.push_back(new AutofillProfile(guid_present1)); 125 profiles_from_web_db.push_back(new AutofillProfile(guid_present1));
126 profiles_from_web_db.back()->SetInfo(NAME_FIRST, UTF8ToUTF16("John")); 126 profiles_from_web_db.back()->SetInfo(NAME_FIRST, UTF8ToUTF16("John"));
127 profiles_from_web_db.back()->SetInfo(ADDRESS_HOME_LINE1, 127 profiles_from_web_db.back()->SetInfo(ADDRESS_HOME_LINE1,
128 UTF8ToUTF16("1 1st st")); 128 UTF8ToUTF16("1 1st st"));
129 profiles_from_web_db.push_back(new AutofillProfile(guid_present2)); 129 profiles_from_web_db.push_back(new AutofillProfile(guid_present2));
130 profiles_from_web_db.back()->SetInfo(NAME_FIRST, UTF8ToUTF16("Tom")); 130 profiles_from_web_db.back()->SetInfo(NAME_FIRST, UTF8ToUTF16("Tom"));
131 profiles_from_web_db.back()->SetInfo(ADDRESS_HOME_LINE1, 131 profiles_from_web_db.back()->SetInfo(ADDRESS_HOME_LINE1,
132 UTF8ToUTF16("2 2nd st")); 132 UTF8ToUTF16("2 2nd st"));
133 133
134 csync::SyncDataList data_list; 134 syncer::SyncDataList data_list;
135 AutofillProfile profile1(guid_synced1); 135 AutofillProfile profile1(guid_synced1);
136 profile1.SetInfo(NAME_FIRST, UTF8ToUTF16("Jane")); 136 profile1.SetInfo(NAME_FIRST, UTF8ToUTF16("Jane"));
137 data_list.push_back(autofill_syncable_service_.CreateData(profile1)); 137 data_list.push_back(autofill_syncable_service_.CreateData(profile1));
138 AutofillProfile profile2(guid_synced2); 138 AutofillProfile profile2(guid_synced2);
139 profile2.SetInfo(NAME_FIRST, UTF8ToUTF16("Harry")); 139 profile2.SetInfo(NAME_FIRST, UTF8ToUTF16("Harry"));
140 data_list.push_back(autofill_syncable_service_.CreateData(profile2)); 140 data_list.push_back(autofill_syncable_service_.CreateData(profile2));
141 // This one will have the name updated. 141 // This one will have the name updated.
142 AutofillProfile profile3(guid_present2); 142 AutofillProfile profile3(guid_present2);
143 profile3.SetInfo(NAME_FIRST, UTF8ToUTF16("Tom Doe")); 143 profile3.SetInfo(NAME_FIRST, UTF8ToUTF16("Tom Doe"));
144 data_list.push_back(autofill_syncable_service_.CreateData(profile3)); 144 data_list.push_back(autofill_syncable_service_.CreateData(profile3));
145 145
146 csync::SyncChangeList expected_change_list; 146 syncer::SyncChangeList expected_change_list;
147 expected_change_list.push_back( 147 expected_change_list.push_back(
148 csync::SyncChange(csync::SyncChange::ACTION_ADD, 148 syncer::SyncChange(syncer::SyncChange::ACTION_ADD,
149 AutofillProfileSyncableService::CreateData( 149 AutofillProfileSyncableService::CreateData(
150 (*profiles_from_web_db.front())))); 150 (*profiles_from_web_db.front()))));
151 151
152 AutofillProfileSyncableService::DataBundle expected_bundle; 152 AutofillProfileSyncableService::DataBundle expected_bundle;
153 expected_bundle.profiles_to_add.push_back(&profile1); 153 expected_bundle.profiles_to_add.push_back(&profile1);
154 expected_bundle.profiles_to_add.push_back(&profile2); 154 expected_bundle.profiles_to_add.push_back(&profile2);
155 expected_bundle.profiles_to_update.push_back(&profile3); 155 expected_bundle.profiles_to_update.push_back(&profile3);
156 156
157 EXPECT_CALL(autofill_syncable_service_, LoadAutofillData(_)) 157 EXPECT_CALL(autofill_syncable_service_, LoadAutofillData(_))
158 .Times(1) 158 .Times(1)
159 .WillOnce(DoAll(CopyData(&profiles_from_web_db), Return(true))); 159 .WillOnce(DoAll(CopyData(&profiles_from_web_db), Return(true)));
160 EXPECT_CALL(autofill_syncable_service_, 160 EXPECT_CALL(autofill_syncable_service_,
161 SaveChangesToWebData(DataBundleCheck(expected_bundle))) 161 SaveChangesToWebData(DataBundleCheck(expected_bundle)))
162 .Times(1) 162 .Times(1)
163 .WillOnce(Return(true)); 163 .WillOnce(Return(true));
164 ON_CALL(*sync_processor_, ProcessSyncChanges(_, _)) 164 ON_CALL(*sync_processor_, ProcessSyncChanges(_, _))
165 .WillByDefault(Return(csync::SyncError())); 165 .WillByDefault(Return(syncer::SyncError()));
166 EXPECT_CALL(*sync_processor_, 166 EXPECT_CALL(*sync_processor_,
167 ProcessSyncChanges(_, CheckSyncChanges(expected_change_list))) 167 ProcessSyncChanges(_, CheckSyncChanges(expected_change_list)))
168 .Times(1) 168 .Times(1)
169 .WillOnce(Return(csync::SyncError())); 169 .WillOnce(Return(syncer::SyncError()));
170 170
171 // Takes ownership of sync_processor_. 171 // Takes ownership of sync_processor_.
172 autofill_syncable_service_.MergeDataAndStartSyncing( 172 autofill_syncable_service_.MergeDataAndStartSyncing(
173 syncable::AUTOFILL_PROFILE, data_list, 173 syncable::AUTOFILL_PROFILE, data_list,
174 sync_processor_.PassAs<csync::SyncChangeProcessor>(), 174 sync_processor_.PassAs<syncer::SyncChangeProcessor>(),
175 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); 175 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
176 autofill_syncable_service_.StopSyncing(syncable::AUTOFILL_PROFILE); 176 autofill_syncable_service_.StopSyncing(syncable::AUTOFILL_PROFILE);
177 } 177 }
178 178
179 TEST_F(AutofillProfileSyncableServiceTest, GetAllSyncData) { 179 TEST_F(AutofillProfileSyncableServiceTest, GetAllSyncData) {
180 std::vector<AutofillProfile *> profiles_from_web_db; 180 std::vector<AutofillProfile *> profiles_from_web_db;
181 std::string guid_present1 = kGuid1; 181 std::string guid_present1 = kGuid1;
182 std::string guid_present2 = kGuid2; 182 std::string guid_present2 = kGuid2;
183 183
184 profiles_from_web_db.push_back(new AutofillProfile(guid_present1)); 184 profiles_from_web_db.push_back(new AutofillProfile(guid_present1));
185 profiles_from_web_db.back()->SetInfo(NAME_FIRST, UTF8ToUTF16("John")); 185 profiles_from_web_db.back()->SetInfo(NAME_FIRST, UTF8ToUTF16("John"));
186 profiles_from_web_db.push_back(new AutofillProfile(guid_present2)); 186 profiles_from_web_db.push_back(new AutofillProfile(guid_present2));
187 profiles_from_web_db.back()->SetInfo(NAME_FIRST, UTF8ToUTF16("Jane")); 187 profiles_from_web_db.back()->SetInfo(NAME_FIRST, UTF8ToUTF16("Jane"));
188 188
189 EXPECT_CALL(autofill_syncable_service_, LoadAutofillData(_)) 189 EXPECT_CALL(autofill_syncable_service_, LoadAutofillData(_))
190 .Times(1) 190 .Times(1)
191 .WillOnce(DoAll(CopyData(&profiles_from_web_db), Return(true))); 191 .WillOnce(DoAll(CopyData(&profiles_from_web_db), Return(true)));
192 EXPECT_CALL(autofill_syncable_service_, SaveChangesToWebData(_)) 192 EXPECT_CALL(autofill_syncable_service_, SaveChangesToWebData(_))
193 .Times(1) 193 .Times(1)
194 .WillOnce(Return(true)); 194 .WillOnce(Return(true));
195 ON_CALL(*sync_processor_, ProcessSyncChanges(_, _)) 195 ON_CALL(*sync_processor_, ProcessSyncChanges(_, _))
196 .WillByDefault(Return(csync::SyncError())); 196 .WillByDefault(Return(syncer::SyncError()));
197 EXPECT_CALL(*sync_processor_, 197 EXPECT_CALL(*sync_processor_,
198 ProcessSyncChanges( 198 ProcessSyncChanges(
199 _, 199 _,
200 Property(&csync::SyncChangeList::size, Eq(2U)))) 200 Property(&syncer::SyncChangeList::size, Eq(2U))))
201 .Times(1) 201 .Times(1)
202 .WillOnce(Return(csync::SyncError())); 202 .WillOnce(Return(syncer::SyncError()));
203 203
204 csync::SyncDataList data_list; 204 syncer::SyncDataList data_list;
205 // Takes ownership of sync_processor_. 205 // Takes ownership of sync_processor_.
206 autofill_syncable_service_.MergeDataAndStartSyncing( 206 autofill_syncable_service_.MergeDataAndStartSyncing(
207 syncable::AUTOFILL_PROFILE, data_list, 207 syncable::AUTOFILL_PROFILE, data_list,
208 sync_processor_.PassAs<csync::SyncChangeProcessor>(), 208 sync_processor_.PassAs<syncer::SyncChangeProcessor>(),
209 scoped_ptr<csync::SyncErrorFactory>(new csync::SyncErrorFactoryMock())); 209 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
210 210
211 csync::SyncDataList data = 211 syncer::SyncDataList data =
212 autofill_syncable_service_.GetAllSyncData(syncable::AUTOFILL_PROFILE); 212 autofill_syncable_service_.GetAllSyncData(syncable::AUTOFILL_PROFILE);
213 213
214 EXPECT_EQ(2U, data.size()); 214 EXPECT_EQ(2U, data.size());
215 EXPECT_EQ(guid_present1, data.front().GetSpecifics() 215 EXPECT_EQ(guid_present1, data.front().GetSpecifics()
216 .autofill_profile().guid()); 216 .autofill_profile().guid());
217 EXPECT_EQ(guid_present2, data.back().GetSpecifics() 217 EXPECT_EQ(guid_present2, data.back().GetSpecifics()
218 .autofill_profile().guid()); 218 .autofill_profile().guid());
219 } 219 }
220 220
221 TEST_F(AutofillProfileSyncableServiceTest, ProcessSyncChanges) { 221 TEST_F(AutofillProfileSyncableServiceTest, ProcessSyncChanges) {
222 std::vector<AutofillProfile *> profiles_from_web_db; 222 std::vector<AutofillProfile *> profiles_from_web_db;
223 std::string guid_present = kGuid1; 223 std::string guid_present = kGuid1;
224 std::string guid_synced = kGuid2; 224 std::string guid_synced = kGuid2;
225 225
226 csync::SyncChangeList change_list; 226 syncer::SyncChangeList change_list;
227 AutofillProfile profile(guid_synced); 227 AutofillProfile profile(guid_synced);
228 profile.SetInfo(NAME_FIRST, UTF8ToUTF16("Jane")); 228 profile.SetInfo(NAME_FIRST, UTF8ToUTF16("Jane"));
229 change_list.push_back( 229 change_list.push_back(
230 csync::SyncChange(csync::SyncChange::ACTION_ADD, 230 syncer::SyncChange(syncer::SyncChange::ACTION_ADD,
231 AutofillProfileSyncableService::CreateData(profile))); 231 AutofillProfileSyncableService::CreateData(profile)));
232 AutofillProfile empty_profile(guid_present); 232 AutofillProfile empty_profile(guid_present);
233 change_list.push_back( 233 change_list.push_back(
234 csync::SyncChange(csync::SyncChange::ACTION_DELETE, 234 syncer::SyncChange(syncer::SyncChange::ACTION_DELETE,
235 AutofillProfileSyncableService::CreateData(empty_profile))); 235 AutofillProfileSyncableService::CreateData(empty_profile)));
236 236
237 AutofillProfileSyncableService::DataBundle expected_bundle; 237 AutofillProfileSyncableService::DataBundle expected_bundle;
238 expected_bundle.profiles_to_delete.push_back(guid_present); 238 expected_bundle.profiles_to_delete.push_back(guid_present);
239 expected_bundle.profiles_to_add.push_back(&profile); 239 expected_bundle.profiles_to_add.push_back(&profile);
240 240
241 EXPECT_CALL(autofill_syncable_service_, SaveChangesToWebData( 241 EXPECT_CALL(autofill_syncable_service_, SaveChangesToWebData(
242 DataBundleCheck(expected_bundle))) 242 DataBundleCheck(expected_bundle)))
243 .Times(1) 243 .Times(1)
244 .WillOnce(Return(true)); 244 .WillOnce(Return(true));
245 245
246 autofill_syncable_service_.set_sync_processor(sync_processor_.release()); 246 autofill_syncable_service_.set_sync_processor(sync_processor_.release());
247 csync::SyncError error = autofill_syncable_service_.ProcessSyncChanges( 247 syncer::SyncError error = autofill_syncable_service_.ProcessSyncChanges(
248 FROM_HERE, change_list); 248 FROM_HERE, change_list);
249 249
250 EXPECT_FALSE(error.IsSet()); 250 EXPECT_FALSE(error.IsSet());
251 } 251 }
252 252
253 TEST_F(AutofillProfileSyncableServiceTest, ActOnChange) { 253 TEST_F(AutofillProfileSyncableServiceTest, ActOnChange) {
254 AutofillProfile profile(kGuid1); 254 AutofillProfile profile(kGuid1);
255 profile.SetInfo(NAME_FIRST, UTF8ToUTF16("Jane")); 255 profile.SetInfo(NAME_FIRST, UTF8ToUTF16("Jane"));
256 AutofillProfileChange change1(AutofillProfileChange::ADD, kGuid1, &profile); 256 AutofillProfileChange change1(AutofillProfileChange::ADD, kGuid1, &profile);
257 AutofillProfileChange change2(AutofillProfileChange::REMOVE, kGuid2, NULL); 257 AutofillProfileChange change2(AutofillProfileChange::REMOVE, kGuid2, NULL);
258 ON_CALL(*sync_processor_, ProcessSyncChanges(_, _)) 258 ON_CALL(*sync_processor_, ProcessSyncChanges(_, _))
259 .WillByDefault(Return(csync::SyncError(FROM_HERE, std::string("an error"), 259 .WillByDefault(
260 syncable::AUTOFILL_PROFILE))); 260 Return(syncer::SyncError(FROM_HERE, std::string("an error"),
261 syncable::AUTOFILL_PROFILE)));
261 EXPECT_CALL(*sync_processor_, ProcessSyncChanges(_, _)).Times(2); 262 EXPECT_CALL(*sync_processor_, ProcessSyncChanges(_, _)).Times(2);
262 263
263 autofill_syncable_service_.set_sync_processor(sync_processor_.release()); 264 autofill_syncable_service_.set_sync_processor(sync_processor_.release());
264 autofill_syncable_service_.ActOnChange(change1); 265 autofill_syncable_service_.ActOnChange(change1);
265 autofill_syncable_service_.ActOnChange(change2); 266 autofill_syncable_service_.ActOnChange(change2);
266 } 267 }
267 268
268 TEST_F(AutofillProfileSyncableServiceTest, UpdateField) { 269 TEST_F(AutofillProfileSyncableServiceTest, UpdateField) {
269 AutofillProfile profile(kGuid1); 270 AutofillProfile profile(kGuid1);
270 std::string company1 = "A Company"; 271 std::string company1 = "A Company";
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 profile1.GetMultiInfo(EMAIL_ADDRESS, &values); 406 profile1.GetMultiInfo(EMAIL_ADDRESS, &values);
406 ASSERT_EQ(values.size(), 3U); 407 ASSERT_EQ(values.size(), 3U);
407 EXPECT_EQ(values[0], UTF8ToUTF16("1@1.com")); 408 EXPECT_EQ(values[0], UTF8ToUTF16("1@1.com"));
408 EXPECT_EQ(values[1], UTF8ToUTF16("2@1.com")); 409 EXPECT_EQ(values[1], UTF8ToUTF16("2@1.com"));
409 EXPECT_EQ(values[2], UTF8ToUTF16("3@1.com")); 410 EXPECT_EQ(values[2], UTF8ToUTF16("3@1.com"));
410 411
411 profile1.GetMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values); 412 profile1.GetMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values);
412 ASSERT_EQ(values.size(), 1U); 413 ASSERT_EQ(values.size(), 1U);
413 EXPECT_EQ(values[0], UTF8ToUTF16("650234567")); 414 EXPECT_EQ(values[0], UTF8ToUTF16("650234567"));
414 } 415 }
OLDNEW
« no previous file with comments | « chrome/browser/webdata/autofill_profile_syncable_service.cc ('k') | sync/api/fake_syncable_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698