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

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

Issue 11360055: [Autofill] Rename GetInfo and SetInfo to GetRawInfo and SetRawInfo (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase harder Created 8 years, 1 month 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 }; 116 };
117 117
118 TEST_F(AutofillProfileSyncableServiceTest, MergeDataAndStartSyncing) { 118 TEST_F(AutofillProfileSyncableServiceTest, MergeDataAndStartSyncing) {
119 std::vector<AutofillProfile *> profiles_from_web_db; 119 std::vector<AutofillProfile *> profiles_from_web_db;
120 std::string guid_present1 = kGuid1; 120 std::string guid_present1 = kGuid1;
121 std::string guid_present2 = kGuid2; 121 std::string guid_present2 = kGuid2;
122 std::string guid_synced1 = kGuid3; 122 std::string guid_synced1 = kGuid3;
123 std::string guid_synced2 = kGuid4; 123 std::string guid_synced2 = kGuid4;
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()->SetRawInfo(NAME_FIRST, UTF8ToUTF16("John"));
127 profiles_from_web_db.back()->SetInfo(ADDRESS_HOME_LINE1, 127 profiles_from_web_db.back()->SetRawInfo(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()->SetRawInfo(NAME_FIRST, UTF8ToUTF16("Tom"));
131 profiles_from_web_db.back()->SetInfo(ADDRESS_HOME_LINE1, 131 profiles_from_web_db.back()->SetRawInfo(ADDRESS_HOME_LINE1,
132 UTF8ToUTF16("2 2nd st")); 132 UTF8ToUTF16("2 2nd st"));
133 133
134 syncer::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.SetRawInfo(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.SetRawInfo(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.SetRawInfo(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 syncer::SyncChangeList expected_change_list; 146 syncer::SyncChangeList expected_change_list;
147 expected_change_list.push_back( 147 expected_change_list.push_back(
148 syncer::SyncChange(FROM_HERE, 148 syncer::SyncChange(FROM_HERE,
149 syncer::SyncChange::ACTION_ADD, 149 syncer::SyncChange::ACTION_ADD,
150 AutofillProfileSyncableService::CreateData( 150 AutofillProfileSyncableService::CreateData(
151 (*profiles_from_web_db.front())))); 151 (*profiles_from_web_db.front()))));
152 152
153 AutofillProfileSyncableService::DataBundle expected_bundle; 153 AutofillProfileSyncableService::DataBundle expected_bundle;
(...skipping 22 matching lines...) Expand all
176 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock())); 176 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock()));
177 autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE); 177 autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE);
178 } 178 }
179 179
180 TEST_F(AutofillProfileSyncableServiceTest, GetAllSyncData) { 180 TEST_F(AutofillProfileSyncableServiceTest, GetAllSyncData) {
181 std::vector<AutofillProfile *> profiles_from_web_db; 181 std::vector<AutofillProfile *> profiles_from_web_db;
182 std::string guid_present1 = kGuid1; 182 std::string guid_present1 = kGuid1;
183 std::string guid_present2 = kGuid2; 183 std::string guid_present2 = kGuid2;
184 184
185 profiles_from_web_db.push_back(new AutofillProfile(guid_present1)); 185 profiles_from_web_db.push_back(new AutofillProfile(guid_present1));
186 profiles_from_web_db.back()->SetInfo(NAME_FIRST, UTF8ToUTF16("John")); 186 profiles_from_web_db.back()->SetRawInfo(NAME_FIRST, UTF8ToUTF16("John"));
187 profiles_from_web_db.push_back(new AutofillProfile(guid_present2)); 187 profiles_from_web_db.push_back(new AutofillProfile(guid_present2));
188 profiles_from_web_db.back()->SetInfo(NAME_FIRST, UTF8ToUTF16("Jane")); 188 profiles_from_web_db.back()->SetRawInfo(NAME_FIRST, UTF8ToUTF16("Jane"));
189 189
190 EXPECT_CALL(autofill_syncable_service_, LoadAutofillData(_)) 190 EXPECT_CALL(autofill_syncable_service_, LoadAutofillData(_))
191 .Times(1) 191 .Times(1)
192 .WillOnce(DoAll(CopyData(&profiles_from_web_db), Return(true))); 192 .WillOnce(DoAll(CopyData(&profiles_from_web_db), Return(true)));
193 EXPECT_CALL(autofill_syncable_service_, SaveChangesToWebData(_)) 193 EXPECT_CALL(autofill_syncable_service_, SaveChangesToWebData(_))
194 .Times(1) 194 .Times(1)
195 .WillOnce(Return(true)); 195 .WillOnce(Return(true));
196 ON_CALL(*sync_processor_, ProcessSyncChanges(_, _)) 196 ON_CALL(*sync_processor_, ProcessSyncChanges(_, _))
197 .WillByDefault(Return(syncer::SyncError())); 197 .WillByDefault(Return(syncer::SyncError()));
198 EXPECT_CALL(*sync_processor_, 198 EXPECT_CALL(*sync_processor_,
(...skipping 20 matching lines...) Expand all
219 .autofill_profile().guid()); 219 .autofill_profile().guid());
220 } 220 }
221 221
222 TEST_F(AutofillProfileSyncableServiceTest, ProcessSyncChanges) { 222 TEST_F(AutofillProfileSyncableServiceTest, ProcessSyncChanges) {
223 std::vector<AutofillProfile *> profiles_from_web_db; 223 std::vector<AutofillProfile *> profiles_from_web_db;
224 std::string guid_present = kGuid1; 224 std::string guid_present = kGuid1;
225 std::string guid_synced = kGuid2; 225 std::string guid_synced = kGuid2;
226 226
227 syncer::SyncChangeList change_list; 227 syncer::SyncChangeList change_list;
228 AutofillProfile profile(guid_synced); 228 AutofillProfile profile(guid_synced);
229 profile.SetInfo(NAME_FIRST, UTF8ToUTF16("Jane")); 229 profile.SetRawInfo(NAME_FIRST, UTF8ToUTF16("Jane"));
230 change_list.push_back( 230 change_list.push_back(
231 syncer::SyncChange(FROM_HERE, 231 syncer::SyncChange(FROM_HERE,
232 syncer::SyncChange::ACTION_ADD, 232 syncer::SyncChange::ACTION_ADD,
233 AutofillProfileSyncableService::CreateData(profile))); 233 AutofillProfileSyncableService::CreateData(profile)));
234 AutofillProfile empty_profile(guid_present); 234 AutofillProfile empty_profile(guid_present);
235 change_list.push_back( 235 change_list.push_back(
236 syncer::SyncChange( 236 syncer::SyncChange(
237 FROM_HERE, 237 FROM_HERE,
238 syncer::SyncChange::ACTION_DELETE, 238 syncer::SyncChange::ACTION_DELETE,
239 AutofillProfileSyncableService::CreateData(empty_profile))); 239 AutofillProfileSyncableService::CreateData(empty_profile)));
240 240
241 AutofillProfileSyncableService::DataBundle expected_bundle; 241 AutofillProfileSyncableService::DataBundle expected_bundle;
242 expected_bundle.profiles_to_delete.push_back(guid_present); 242 expected_bundle.profiles_to_delete.push_back(guid_present);
243 expected_bundle.profiles_to_add.push_back(&profile); 243 expected_bundle.profiles_to_add.push_back(&profile);
244 244
245 EXPECT_CALL(autofill_syncable_service_, SaveChangesToWebData( 245 EXPECT_CALL(autofill_syncable_service_, SaveChangesToWebData(
246 DataBundleCheck(expected_bundle))) 246 DataBundleCheck(expected_bundle)))
247 .Times(1) 247 .Times(1)
248 .WillOnce(Return(true)); 248 .WillOnce(Return(true));
249 249
250 autofill_syncable_service_.set_sync_processor(sync_processor_.release()); 250 autofill_syncable_service_.set_sync_processor(sync_processor_.release());
251 syncer::SyncError error = autofill_syncable_service_.ProcessSyncChanges( 251 syncer::SyncError error = autofill_syncable_service_.ProcessSyncChanges(
252 FROM_HERE, change_list); 252 FROM_HERE, change_list);
253 253
254 EXPECT_FALSE(error.IsSet()); 254 EXPECT_FALSE(error.IsSet());
255 } 255 }
256 256
257 TEST_F(AutofillProfileSyncableServiceTest, ActOnChange) { 257 TEST_F(AutofillProfileSyncableServiceTest, ActOnChange) {
258 AutofillProfile profile(kGuid1); 258 AutofillProfile profile(kGuid1);
259 profile.SetInfo(NAME_FIRST, UTF8ToUTF16("Jane")); 259 profile.SetRawInfo(NAME_FIRST, UTF8ToUTF16("Jane"));
260 AutofillProfileChange change1(AutofillProfileChange::ADD, kGuid1, &profile); 260 AutofillProfileChange change1(AutofillProfileChange::ADD, kGuid1, &profile);
261 AutofillProfileChange change2(AutofillProfileChange::REMOVE, kGuid2, NULL); 261 AutofillProfileChange change2(AutofillProfileChange::REMOVE, kGuid2, NULL);
262 ON_CALL(*sync_processor_, ProcessSyncChanges(_, _)) 262 ON_CALL(*sync_processor_, ProcessSyncChanges(_, _))
263 .WillByDefault( 263 .WillByDefault(
264 Return(syncer::SyncError(FROM_HERE, std::string("an error"), 264 Return(syncer::SyncError(FROM_HERE, std::string("an error"),
265 syncer::AUTOFILL_PROFILE))); 265 syncer::AUTOFILL_PROFILE)));
266 EXPECT_CALL(*sync_processor_, ProcessSyncChanges(_, _)).Times(2); 266 EXPECT_CALL(*sync_processor_, ProcessSyncChanges(_, _)).Times(2);
267 267
268 autofill_syncable_service_.set_sync_processor(sync_processor_.release()); 268 autofill_syncable_service_.set_sync_processor(sync_processor_.release());
269 autofill_syncable_service_.ActOnChange(change1); 269 autofill_syncable_service_.ActOnChange(change1);
270 autofill_syncable_service_.ActOnChange(change2); 270 autofill_syncable_service_.ActOnChange(change2);
271 } 271 }
272 272
273 TEST_F(AutofillProfileSyncableServiceTest, UpdateField) { 273 TEST_F(AutofillProfileSyncableServiceTest, UpdateField) {
274 AutofillProfile profile(kGuid1); 274 AutofillProfile profile(kGuid1);
275 std::string company1 = "A Company"; 275 std::string company1 = "A Company";
276 std::string company2 = "Another Company"; 276 std::string company2 = "Another Company";
277 profile.SetInfo(COMPANY_NAME, UTF8ToUTF16(company1)); 277 profile.SetRawInfo(COMPANY_NAME, UTF8ToUTF16(company1));
278 EXPECT_FALSE(AutofillProfileSyncableService::UpdateField( 278 EXPECT_FALSE(AutofillProfileSyncableService::UpdateField(
279 COMPANY_NAME, company1, &profile)); 279 COMPANY_NAME, company1, &profile));
280 EXPECT_EQ(profile.GetInfo(COMPANY_NAME), UTF8ToUTF16(company1)); 280 EXPECT_EQ(profile.GetRawInfo(COMPANY_NAME), UTF8ToUTF16(company1));
281 EXPECT_TRUE(AutofillProfileSyncableService::UpdateField( 281 EXPECT_TRUE(AutofillProfileSyncableService::UpdateField(
282 COMPANY_NAME, company2, &profile)); 282 COMPANY_NAME, company2, &profile));
283 EXPECT_EQ(profile.GetInfo(COMPANY_NAME), UTF8ToUTF16(company2)); 283 EXPECT_EQ(profile.GetRawInfo(COMPANY_NAME), UTF8ToUTF16(company2));
284 EXPECT_FALSE(AutofillProfileSyncableService::UpdateField( 284 EXPECT_FALSE(AutofillProfileSyncableService::UpdateField(
285 COMPANY_NAME, company2, &profile)); 285 COMPANY_NAME, company2, &profile));
286 EXPECT_EQ(profile.GetInfo(COMPANY_NAME), UTF8ToUTF16(company2)); 286 EXPECT_EQ(profile.GetRawInfo(COMPANY_NAME), UTF8ToUTF16(company2));
287 } 287 }
288 288
289 TEST_F(AutofillProfileSyncableServiceTest, UpdateMultivaluedField) { 289 TEST_F(AutofillProfileSyncableServiceTest, UpdateMultivaluedField) {
290 AutofillProfile profile(kGuid1); 290 AutofillProfile profile(kGuid1);
291 291
292 std::vector<string16> values; 292 std::vector<string16> values;
293 values.push_back(UTF8ToUTF16("1@1.com")); 293 values.push_back(UTF8ToUTF16("1@1.com"));
294 values.push_back(UTF8ToUTF16("2@1.com")); 294 values.push_back(UTF8ToUTF16("2@1.com"));
295 profile.SetMultiInfo(EMAIL_ADDRESS, values); 295 profile.SetMultiInfo(EMAIL_ADDRESS, values);
296 296
(...skipping 17 matching lines...) Expand all
314 EXPECT_TRUE(AutofillProfileSyncableService::UpdateMultivaluedField( 314 EXPECT_TRUE(AutofillProfileSyncableService::UpdateMultivaluedField(
315 EMAIL_ADDRESS, ::google::protobuf::RepeatedPtrField<std::string>(), 315 EMAIL_ADDRESS, ::google::protobuf::RepeatedPtrField<std::string>(),
316 &profile)); 316 &profile));
317 profile.GetMultiInfo(EMAIL_ADDRESS, &values); 317 profile.GetMultiInfo(EMAIL_ADDRESS, &values);
318 ASSERT_EQ(values.size(), 1U); // Always have at least an empty string. 318 ASSERT_EQ(values.size(), 1U); // Always have at least an empty string.
319 EXPECT_EQ(values[0], UTF8ToUTF16("")); 319 EXPECT_EQ(values[0], UTF8ToUTF16(""));
320 } 320 }
321 321
322 TEST_F(AutofillProfileSyncableServiceTest, MergeProfile) { 322 TEST_F(AutofillProfileSyncableServiceTest, MergeProfile) {
323 AutofillProfile profile1(kGuid1); 323 AutofillProfile profile1(kGuid1);
324 profile1.SetInfo(ADDRESS_HOME_LINE1, UTF8ToUTF16("111 First St.")); 324 profile1.SetRawInfo(ADDRESS_HOME_LINE1, UTF8ToUTF16("111 First St."));
325 325
326 std::vector<string16> values; 326 std::vector<string16> values;
327 values.push_back(UTF8ToUTF16("1@1.com")); 327 values.push_back(UTF8ToUTF16("1@1.com"));
328 values.push_back(UTF8ToUTF16("2@1.com")); 328 values.push_back(UTF8ToUTF16("2@1.com"));
329 profile1.SetMultiInfo(EMAIL_ADDRESS, values); 329 profile1.SetMultiInfo(EMAIL_ADDRESS, values);
330 330
331 AutofillProfile profile2(kGuid2); 331 AutofillProfile profile2(kGuid2);
332 profile2.SetInfo(ADDRESS_HOME_LINE1, UTF8ToUTF16("111 First St.")); 332 profile2.SetRawInfo(ADDRESS_HOME_LINE1, UTF8ToUTF16("111 First St."));
333 333
334 // |values| now is [ "1@1.com", "2@1.com", "3@1.com" ]. 334 // |values| now is [ "1@1.com", "2@1.com", "3@1.com" ].
335 values.push_back(UTF8ToUTF16("3@1.com")); 335 values.push_back(UTF8ToUTF16("3@1.com"));
336 profile2.SetMultiInfo(EMAIL_ADDRESS, values); 336 profile2.SetMultiInfo(EMAIL_ADDRESS, values);
337 337
338 values.clear(); 338 values.clear();
339 values.push_back(UTF8ToUTF16("John")); 339 values.push_back(UTF8ToUTF16("John"));
340 profile1.SetMultiInfo(NAME_FIRST, values); 340 profile1.SetMultiInfo(NAME_FIRST, values);
341 values.push_back(UTF8ToUTF16("Jane")); 341 values.push_back(UTF8ToUTF16("Jane"));
342 profile2.SetMultiInfo(NAME_FIRST, values); 342 profile2.SetMultiInfo(NAME_FIRST, values);
(...skipping 25 matching lines...) Expand all
368 ASSERT_EQ(values.size(), 3U); 368 ASSERT_EQ(values.size(), 3U);
369 EXPECT_EQ(values[0], UTF8ToUTF16("1@1.com")); 369 EXPECT_EQ(values[0], UTF8ToUTF16("1@1.com"));
370 EXPECT_EQ(values[1], UTF8ToUTF16("2@1.com")); 370 EXPECT_EQ(values[1], UTF8ToUTF16("2@1.com"));
371 EXPECT_EQ(values[2], UTF8ToUTF16("3@1.com")); 371 EXPECT_EQ(values[2], UTF8ToUTF16("3@1.com"));
372 372
373 profile1.GetMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values); 373 profile1.GetMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values);
374 ASSERT_EQ(values.size(), 1U); 374 ASSERT_EQ(values.size(), 1U);
375 EXPECT_EQ(values[0], UTF8ToUTF16("650234567")); 375 EXPECT_EQ(values[0], UTF8ToUTF16("650234567"));
376 376
377 AutofillProfile profile3(kGuid3); 377 AutofillProfile profile3(kGuid3);
378 profile3.SetInfo(ADDRESS_HOME_LINE1, UTF8ToUTF16("111 First St.")); 378 profile3.SetRawInfo(ADDRESS_HOME_LINE1, UTF8ToUTF16("111 First St."));
379 379
380 values.clear(); 380 values.clear();
381 values.push_back(UTF8ToUTF16("Jane")); 381 values.push_back(UTF8ToUTF16("Jane"));
382 profile3.SetMultiInfo(NAME_FIRST, values); 382 profile3.SetMultiInfo(NAME_FIRST, values);
383 383
384 values.clear(); 384 values.clear();
385 values.push_back(UTF8ToUTF16("Doe")); 385 values.push_back(UTF8ToUTF16("Doe"));
386 profile3.SetMultiInfo(NAME_LAST, values); 386 profile3.SetMultiInfo(NAME_LAST, values);
387 387
388 EXPECT_TRUE(AutofillProfileSyncableService::MergeProfile(profile3, 388 EXPECT_TRUE(AutofillProfileSyncableService::MergeProfile(profile3,
(...skipping 21 matching lines...) Expand all
410 profile1.GetMultiInfo(EMAIL_ADDRESS, &values); 410 profile1.GetMultiInfo(EMAIL_ADDRESS, &values);
411 ASSERT_EQ(values.size(), 3U); 411 ASSERT_EQ(values.size(), 3U);
412 EXPECT_EQ(values[0], UTF8ToUTF16("1@1.com")); 412 EXPECT_EQ(values[0], UTF8ToUTF16("1@1.com"));
413 EXPECT_EQ(values[1], UTF8ToUTF16("2@1.com")); 413 EXPECT_EQ(values[1], UTF8ToUTF16("2@1.com"));
414 EXPECT_EQ(values[2], UTF8ToUTF16("3@1.com")); 414 EXPECT_EQ(values[2], UTF8ToUTF16("3@1.com"));
415 415
416 profile1.GetMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values); 416 profile1.GetMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values);
417 ASSERT_EQ(values.size(), 1U); 417 ASSERT_EQ(values.size(), 1U);
418 EXPECT_EQ(values[0], UTF8ToUTF16("650234567")); 418 EXPECT_EQ(values[0], UTF8ToUTF16("650234567"));
419 } 419 }
OLDNEW
« no previous file with comments | « chrome/browser/webdata/autofill_profile_syncable_service.cc ('k') | chrome/browser/webdata/autofill_table.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698