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

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

Issue 122313007: [Autofill] Style cleanup: Move AutofillProfileSyncableService into the autofill namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix mysterious Windows compile failure??? Created 6 years, 11 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/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/webdata/autofill_profile_syncable_service.h" 8 #include "chrome/browser/webdata/autofill_profile_syncable_service.h"
9 #include "components/autofill/core/browser/autofill_profile.h" 9 #include "components/autofill/core/browser/autofill_profile.h"
10 #include "components/autofill/core/browser/webdata/autofill_change.h" 10 #include "components/autofill/core/browser/webdata/autofill_change.h"
11 #include "content/public/test/test_browser_thread.h" 11 #include "content/public/test/test_browser_thread.h"
12 #include "sync/api/sync_error_factory.h" 12 #include "sync/api/sync_error_factory.h"
13 #include "sync/api/sync_error_factory_mock.h" 13 #include "sync/api/sync_error_factory_mock.h"
14 #include "sync/protocol/sync.pb.h" 14 #include "sync/protocol/sync.pb.h"
15 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 namespace autofill {
19
18 using ::testing::_; 20 using ::testing::_;
19 using ::testing::DoAll; 21 using ::testing::DoAll;
20 using ::testing::Eq; 22 using ::testing::Eq;
21 using ::testing::Return; 23 using ::testing::Return;
22 using ::testing::Property; 24 using ::testing::Property;
23 using autofill::AutofillProfile;
24 using autofill::AutofillProfileChange;
25 using base::UTF8ToUTF16; 25 using base::UTF8ToUTF16;
26 using content::BrowserThread; 26 using content::BrowserThread;
27 27
28 // Some guids for testing. 28 // Some guids for testing.
29 const char kGuid1[] = "EDC609ED-7EEE-4F27-B00C-423242A9C44B"; 29 const char kGuid1[] = "EDC609ED-7EEE-4F27-B00C-423242A9C44B";
30 const char kGuid2[] = "EDC609ED-7EEE-4F27-B00C-423242A9C44C"; 30 const char kGuid2[] = "EDC609ED-7EEE-4F27-B00C-423242A9C44C";
31 const char kGuid3[] = "EDC609ED-7EEE-4F27-B00C-423242A9C44D"; 31 const char kGuid3[] = "EDC609ED-7EEE-4F27-B00C-423242A9C44D";
32 const char kGuid4[] = "EDC609ED-7EEE-4F27-B00C-423242A9C44E"; 32 const char kGuid4[] = "EDC609ED-7EEE-4F27-B00C-423242A9C44E";
33 const char kHttpOrigin[] = "http://www.example.com/"; 33 const char kHttpOrigin[] = "http://www.example.com/";
34 const char kHttpsOrigin[] = "https://www.example.com/"; 34 const char kHttpsOrigin[] = "https://www.example.com/";
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 std::string guid_present2 = kGuid2; 180 std::string guid_present2 = kGuid2;
181 std::string guid_synced1 = kGuid3; 181 std::string guid_synced1 = kGuid3;
182 std::string guid_synced2 = kGuid4; 182 std::string guid_synced2 = kGuid4;
183 std::string origin_present1 = kHttpOrigin; 183 std::string origin_present1 = kHttpOrigin;
184 std::string origin_present2 = std::string(); 184 std::string origin_present2 = std::string();
185 std::string origin_synced1 = kHttpsOrigin; 185 std::string origin_synced1 = kHttpsOrigin;
186 std::string origin_synced2 = kSettingsOrigin; 186 std::string origin_synced2 = kSettingsOrigin;
187 187
188 profiles_from_web_db.push_back( 188 profiles_from_web_db.push_back(
189 new AutofillProfile(guid_present1, origin_present1)); 189 new AutofillProfile(guid_present1, origin_present1));
190 profiles_from_web_db.back()->SetRawInfo( 190 profiles_from_web_db.back()->SetRawInfo(NAME_FIRST, UTF8ToUTF16("John"));
191 autofill::NAME_FIRST, UTF8ToUTF16("John")); 191 profiles_from_web_db.back()->SetRawInfo(ADDRESS_HOME_LINE1,
192 profiles_from_web_db.back()->SetRawInfo( 192 UTF8ToUTF16("1 1st st"));
193 autofill::ADDRESS_HOME_LINE1, UTF8ToUTF16("1 1st st"));
194 profiles_from_web_db.push_back( 193 profiles_from_web_db.push_back(
195 new AutofillProfile(guid_present2, origin_present2)); 194 new AutofillProfile(guid_present2, origin_present2));
196 profiles_from_web_db.back()->SetRawInfo( 195 profiles_from_web_db.back()->SetRawInfo(NAME_FIRST, UTF8ToUTF16("Tom"));
197 autofill::NAME_FIRST, UTF8ToUTF16("Tom")); 196 profiles_from_web_db.back()->SetRawInfo(ADDRESS_HOME_LINE1,
198 profiles_from_web_db.back()->SetRawInfo( 197 UTF8ToUTF16("2 2nd st"));
199 autofill::ADDRESS_HOME_LINE1, UTF8ToUTF16("2 2nd st"));
200 198
201 syncer::SyncDataList data_list; 199 syncer::SyncDataList data_list;
202 AutofillProfile profile1(guid_synced1, origin_synced1); 200 AutofillProfile profile1(guid_synced1, origin_synced1);
203 profile1.SetRawInfo(autofill::NAME_FIRST, UTF8ToUTF16("Jane")); 201 profile1.SetRawInfo(NAME_FIRST, UTF8ToUTF16("Jane"));
204 data_list.push_back(autofill_syncable_service_.CreateData(profile1)); 202 data_list.push_back(autofill_syncable_service_.CreateData(profile1));
205 AutofillProfile profile2(guid_synced2, origin_synced2); 203 AutofillProfile profile2(guid_synced2, origin_synced2);
206 profile2.SetRawInfo(autofill::NAME_FIRST, UTF8ToUTF16("Harry")); 204 profile2.SetRawInfo(NAME_FIRST, UTF8ToUTF16("Harry"));
207 data_list.push_back(autofill_syncable_service_.CreateData(profile2)); 205 data_list.push_back(autofill_syncable_service_.CreateData(profile2));
208 // This one will have the name and origin updated. 206 // This one will have the name and origin updated.
209 AutofillProfile profile3(guid_present2, origin_synced2); 207 AutofillProfile profile3(guid_present2, origin_synced2);
210 profile3.SetRawInfo(autofill::NAME_FIRST, UTF8ToUTF16("Tom Doe")); 208 profile3.SetRawInfo(NAME_FIRST, UTF8ToUTF16("Tom Doe"));
211 data_list.push_back(autofill_syncable_service_.CreateData(profile3)); 209 data_list.push_back(autofill_syncable_service_.CreateData(profile3));
212 210
213 syncer::SyncChangeList expected_change_list; 211 syncer::SyncChangeList expected_change_list;
214 expected_change_list.push_back( 212 expected_change_list.push_back(
215 syncer::SyncChange(FROM_HERE, 213 syncer::SyncChange(FROM_HERE,
216 syncer::SyncChange::ACTION_ADD, 214 syncer::SyncChange::ACTION_ADD,
217 MockAutofillProfileSyncableService::CreateData( 215 MockAutofillProfileSyncableService::CreateData(
218 *profiles_from_web_db.front()))); 216 *profiles_from_web_db.front())));
219 217
220 MockAutofillProfileSyncableService::DataBundle expected_bundle; 218 MockAutofillProfileSyncableService::DataBundle expected_bundle;
(...skipping 12 matching lines...) Expand all
233 std::string guid_present2 = kGuid2; 231 std::string guid_present2 = kGuid2;
234 std::string guid_synced1 = kGuid3; 232 std::string guid_synced1 = kGuid3;
235 std::string guid_synced2 = kGuid4; 233 std::string guid_synced2 = kGuid4;
236 std::string origin_present1 = kHttpOrigin; 234 std::string origin_present1 = kHttpOrigin;
237 std::string origin_present2 = kSettingsOrigin; 235 std::string origin_present2 = kSettingsOrigin;
238 std::string origin_synced1 = kHttpsOrigin; 236 std::string origin_synced1 = kHttpsOrigin;
239 std::string origin_synced2 = kHttpsOrigin; 237 std::string origin_synced2 = kHttpsOrigin;
240 238
241 profiles_from_web_db.push_back( 239 profiles_from_web_db.push_back(
242 new AutofillProfile(guid_present1, origin_present1)); 240 new AutofillProfile(guid_present1, origin_present1));
243 profiles_from_web_db.back()->SetRawInfo( 241 profiles_from_web_db.back()->SetRawInfo(NAME_FIRST, UTF8ToUTF16("John"));
244 autofill::NAME_FIRST, UTF8ToUTF16("John")); 242 profiles_from_web_db.back()->SetRawInfo(ADDRESS_HOME_LINE1,
245 profiles_from_web_db.back()->SetRawInfo( 243 UTF8ToUTF16("1 1st st"));
246 autofill::ADDRESS_HOME_LINE1, UTF8ToUTF16("1 1st st"));
247 profiles_from_web_db.push_back( 244 profiles_from_web_db.push_back(
248 new AutofillProfile(guid_present2, origin_present2)); 245 new AutofillProfile(guid_present2, origin_present2));
249 profiles_from_web_db.back()->SetRawInfo( 246 profiles_from_web_db.back()->SetRawInfo(NAME_FIRST, UTF8ToUTF16("Tom"));
250 autofill::NAME_FIRST, UTF8ToUTF16("Tom")); 247 profiles_from_web_db.back()->SetRawInfo(ADDRESS_HOME_LINE1,
251 profiles_from_web_db.back()->SetRawInfo( 248 UTF8ToUTF16("2 2nd st"));
252 autofill::ADDRESS_HOME_LINE1, UTF8ToUTF16("2 2nd st"));
253 249
254 // The synced profiles are identical to the local ones, except that the guids 250 // The synced profiles are identical to the local ones, except that the guids
255 // are different. 251 // are different.
256 syncer::SyncDataList data_list; 252 syncer::SyncDataList data_list;
257 AutofillProfile profile1(guid_synced1, origin_synced1); 253 AutofillProfile profile1(guid_synced1, origin_synced1);
258 profile1.SetRawInfo(autofill::NAME_FIRST, UTF8ToUTF16("John")); 254 profile1.SetRawInfo(NAME_FIRST, UTF8ToUTF16("John"));
259 profile1.SetRawInfo(autofill::ADDRESS_HOME_LINE1, UTF8ToUTF16("1 1st st")); 255 profile1.SetRawInfo(ADDRESS_HOME_LINE1, UTF8ToUTF16("1 1st st"));
260 data_list.push_back(autofill_syncable_service_.CreateData(profile1)); 256 data_list.push_back(autofill_syncable_service_.CreateData(profile1));
261 AutofillProfile profile2(guid_synced2, origin_synced2); 257 AutofillProfile profile2(guid_synced2, origin_synced2);
262 profile2.SetRawInfo(autofill::NAME_FIRST, UTF8ToUTF16("Tom")); 258 profile2.SetRawInfo(NAME_FIRST, UTF8ToUTF16("Tom"));
263 profile2.SetRawInfo(autofill::ADDRESS_HOME_LINE1, UTF8ToUTF16("2 2nd st")); 259 profile2.SetRawInfo(ADDRESS_HOME_LINE1, UTF8ToUTF16("2 2nd st"));
264 data_list.push_back(autofill_syncable_service_.CreateData(profile2)); 260 data_list.push_back(autofill_syncable_service_.CreateData(profile2));
265 261
266 AutofillProfile expected_profile(profile2); 262 AutofillProfile expected_profile(profile2);
267 expected_profile.set_origin(kSettingsOrigin); 263 expected_profile.set_origin(kSettingsOrigin);
268 syncer::SyncChangeList expected_change_list; 264 syncer::SyncChangeList expected_change_list;
269 expected_change_list.push_back( 265 expected_change_list.push_back(
270 syncer::SyncChange(FROM_HERE, 266 syncer::SyncChange(FROM_HERE,
271 syncer::SyncChange::ACTION_UPDATE, 267 syncer::SyncChange::ACTION_UPDATE,
272 MockAutofillProfileSyncableService::CreateData( 268 MockAutofillProfileSyncableService::CreateData(
273 expected_profile))); 269 expected_profile)));
(...skipping 15 matching lines...) Expand all
289 std::string guid_present2 = kGuid2; 285 std::string guid_present2 = kGuid2;
290 std::string guid_synced1 = kGuid3; 286 std::string guid_synced1 = kGuid3;
291 std::string guid_synced2 = kGuid4; 287 std::string guid_synced2 = kGuid4;
292 std::string origin_present1 = kHttpOrigin; 288 std::string origin_present1 = kHttpOrigin;
293 std::string origin_present2 = kSettingsOrigin; 289 std::string origin_present2 = kSettingsOrigin;
294 std::string origin_synced1 = kHttpsOrigin; 290 std::string origin_synced1 = kHttpsOrigin;
295 std::string origin_synced2 = kHttpsOrigin; 291 std::string origin_synced2 = kHttpsOrigin;
296 292
297 profiles_from_web_db.push_back( 293 profiles_from_web_db.push_back(
298 new AutofillProfile(guid_present1, origin_present1)); 294 new AutofillProfile(guid_present1, origin_present1));
299 profiles_from_web_db.back()->SetRawInfo( 295 profiles_from_web_db.back()->SetRawInfo(NAME_FIRST, UTF8ToUTF16("John"));
300 autofill::NAME_FIRST, UTF8ToUTF16("John")); 296 profiles_from_web_db.back()->SetRawInfo(ADDRESS_HOME_LINE1,
301 profiles_from_web_db.back()->SetRawInfo( 297 UTF8ToUTF16("1 1st st"));
302 autofill::ADDRESS_HOME_LINE1, UTF8ToUTF16("1 1st st"));
303 profiles_from_web_db.push_back( 298 profiles_from_web_db.push_back(
304 new AutofillProfile(guid_present2, origin_present2)); 299 new AutofillProfile(guid_present2, origin_present2));
305 profiles_from_web_db.back()->SetRawInfo( 300 profiles_from_web_db.back()->SetRawInfo(NAME_FIRST, UTF8ToUTF16("Tom"));
306 autofill::NAME_FIRST, UTF8ToUTF16("Tom")); 301 profiles_from_web_db.back()->SetRawInfo(ADDRESS_HOME_LINE1,
307 profiles_from_web_db.back()->SetRawInfo( 302 UTF8ToUTF16("2 2nd st"));
308 autofill::ADDRESS_HOME_LINE1, UTF8ToUTF16("2 2nd st"));
309 303
310 // The synced profiles are identical to the local ones, except that the guids 304 // The synced profiles are identical to the local ones, except that the guids
311 // are different. 305 // are different.
312 syncer::SyncDataList data_list; 306 syncer::SyncDataList data_list;
313 AutofillProfile profile1(guid_synced1, origin_synced1); 307 AutofillProfile profile1(guid_synced1, origin_synced1);
314 profile1.SetRawInfo(autofill::NAME_FIRST, UTF8ToUTF16("John")); 308 profile1.SetRawInfo(NAME_FIRST, UTF8ToUTF16("John"));
315 profile1.SetRawInfo(autofill::ADDRESS_HOME_LINE1, UTF8ToUTF16("1 1st st")); 309 profile1.SetRawInfo(ADDRESS_HOME_LINE1, UTF8ToUTF16("1 1st st"));
316 profile1.SetRawInfo(autofill::COMPANY_NAME, UTF8ToUTF16("Frobbers, Inc.")); 310 profile1.SetRawInfo(COMPANY_NAME, UTF8ToUTF16("Frobbers, Inc."));
317 data_list.push_back(autofill_syncable_service_.CreateData(profile1)); 311 data_list.push_back(autofill_syncable_service_.CreateData(profile1));
318 AutofillProfile profile2(guid_synced2, origin_synced2); 312 AutofillProfile profile2(guid_synced2, origin_synced2);
319 profile2.SetRawInfo(autofill::NAME_FIRST, UTF8ToUTF16("Tom")); 313 profile2.SetRawInfo(NAME_FIRST, UTF8ToUTF16("Tom"));
320 profile2.SetRawInfo(autofill::ADDRESS_HOME_LINE1, UTF8ToUTF16("2 2nd st")); 314 profile2.SetRawInfo(ADDRESS_HOME_LINE1, UTF8ToUTF16("2 2nd st"));
321 profile2.SetRawInfo(autofill::COMPANY_NAME, UTF8ToUTF16("Fizzbang, LLC.")); 315 profile2.SetRawInfo(COMPANY_NAME, UTF8ToUTF16("Fizzbang, LLC."));
322 data_list.push_back(autofill_syncable_service_.CreateData(profile2)); 316 data_list.push_back(autofill_syncable_service_.CreateData(profile2));
323 317
324 // The first profile should have its origin updated. 318 // The first profile should have its origin updated.
325 // The second profile should remain as-is, because an unverified profile 319 // The second profile should remain as-is, because an unverified profile
326 // should never overwrite a verified one. 320 // should never overwrite a verified one.
327 AutofillProfile expected_profile(profile1); 321 AutofillProfile expected_profile(profile1);
328 expected_profile.set_origin(origin_present1); 322 expected_profile.set_origin(origin_present1);
329 syncer::SyncChangeList expected_change_list; 323 syncer::SyncChangeList expected_change_list;
330 expected_change_list.push_back( 324 expected_change_list.push_back(
331 syncer::SyncChange(FROM_HERE, 325 syncer::SyncChange(FROM_HERE,
(...skipping 17 matching lines...) Expand all
349 } 343 }
350 344
351 // Ensure that no Sync events are generated to fill in missing origins from Sync 345 // Ensure that no Sync events are generated to fill in missing origins from Sync
352 // with explicitly present empty ones. This ensures that the migration to add 346 // with explicitly present empty ones. This ensures that the migration to add
353 // origins to profiles does not generate lots of needless Sync updates. 347 // origins to profiles does not generate lots of needless Sync updates.
354 TEST_F(AutofillProfileSyncableServiceTest, MergeDataEmptyOrigins) { 348 TEST_F(AutofillProfileSyncableServiceTest, MergeDataEmptyOrigins) {
355 std::vector<AutofillProfile*> profiles_from_web_db; 349 std::vector<AutofillProfile*> profiles_from_web_db;
356 350
357 // Create a profile with an empty origin. 351 // Create a profile with an empty origin.
358 AutofillProfile profile(kGuid1, std::string()); 352 AutofillProfile profile(kGuid1, std::string());
359 profile.SetRawInfo(autofill::NAME_FIRST, UTF8ToUTF16("John")); 353 profile.SetRawInfo(NAME_FIRST, UTF8ToUTF16("John"));
360 profile.SetRawInfo(autofill::ADDRESS_HOME_LINE1, UTF8ToUTF16("1 1st st")); 354 profile.SetRawInfo(ADDRESS_HOME_LINE1, UTF8ToUTF16("1 1st st"));
361 355
362 profiles_from_web_db.push_back(new AutofillProfile(profile)); 356 profiles_from_web_db.push_back(new AutofillProfile(profile));
363 357
364 // Create a Sync profile identical to |profile|, except with no origin set. 358 // Create a Sync profile identical to |profile|, except with no origin set.
365 sync_pb::EntitySpecifics specifics; 359 sync_pb::EntitySpecifics specifics;
366 sync_pb::AutofillProfileSpecifics* autofill_specifics = 360 sync_pb::AutofillProfileSpecifics* autofill_specifics =
367 specifics.mutable_autofill_profile(); 361 specifics.mutable_autofill_profile();
368 autofill_specifics->set_guid(profile.guid()); 362 autofill_specifics->set_guid(profile.guid());
369 autofill_specifics->add_name_first("John"); 363 autofill_specifics->add_name_first("John");
370 autofill_specifics->add_name_middle(std::string()); 364 autofill_specifics->add_name_middle(std::string());
(...skipping 27 matching lines...) Expand all
398 autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE); 392 autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE);
399 } 393 }
400 394
401 TEST_F(AutofillProfileSyncableServiceTest, GetAllSyncData) { 395 TEST_F(AutofillProfileSyncableServiceTest, GetAllSyncData) {
402 std::vector<AutofillProfile*> profiles_from_web_db; 396 std::vector<AutofillProfile*> profiles_from_web_db;
403 std::string guid_present1 = kGuid1; 397 std::string guid_present1 = kGuid1;
404 std::string guid_present2 = kGuid2; 398 std::string guid_present2 = kGuid2;
405 399
406 profiles_from_web_db.push_back( 400 profiles_from_web_db.push_back(
407 new AutofillProfile(guid_present1, kHttpOrigin)); 401 new AutofillProfile(guid_present1, kHttpOrigin));
408 profiles_from_web_db.back()->SetRawInfo( 402 profiles_from_web_db.back()->SetRawInfo(NAME_FIRST, UTF8ToUTF16("John"));
409 autofill::NAME_FIRST, UTF8ToUTF16("John"));
410 profiles_from_web_db.push_back( 403 profiles_from_web_db.push_back(
411 new AutofillProfile(guid_present2, kHttpsOrigin)); 404 new AutofillProfile(guid_present2, kHttpsOrigin));
412 profiles_from_web_db.back()->SetRawInfo( 405 profiles_from_web_db.back()->SetRawInfo(NAME_FIRST, UTF8ToUTF16("Jane"));
413 autofill::NAME_FIRST, UTF8ToUTF16("Jane"));
414 406
415 syncer::SyncChangeList expected_change_list; 407 syncer::SyncChangeList expected_change_list;
416 expected_change_list.push_back( 408 expected_change_list.push_back(
417 syncer::SyncChange(FROM_HERE, 409 syncer::SyncChange(FROM_HERE,
418 syncer::SyncChange::ACTION_ADD, 410 syncer::SyncChange::ACTION_ADD,
419 MockAutofillProfileSyncableService::CreateData( 411 MockAutofillProfileSyncableService::CreateData(
420 *profiles_from_web_db.front()))); 412 *profiles_from_web_db.front())));
421 expected_change_list.push_back( 413 expected_change_list.push_back(
422 syncer::SyncChange(FROM_HERE, 414 syncer::SyncChange(FROM_HERE,
423 syncer::SyncChange::ACTION_ADD, 415 syncer::SyncChange::ACTION_ADD,
(...skipping 17 matching lines...) Expand all
441 autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE); 433 autofill_syncable_service_.StopSyncing(syncer::AUTOFILL_PROFILE);
442 } 434 }
443 435
444 TEST_F(AutofillProfileSyncableServiceTest, ProcessSyncChanges) { 436 TEST_F(AutofillProfileSyncableServiceTest, ProcessSyncChanges) {
445 std::vector<AutofillProfile *> profiles_from_web_db; 437 std::vector<AutofillProfile *> profiles_from_web_db;
446 std::string guid_present = kGuid1; 438 std::string guid_present = kGuid1;
447 std::string guid_synced = kGuid2; 439 std::string guid_synced = kGuid2;
448 440
449 syncer::SyncChangeList change_list; 441 syncer::SyncChangeList change_list;
450 AutofillProfile profile(guid_synced, kHttpOrigin); 442 AutofillProfile profile(guid_synced, kHttpOrigin);
451 profile.SetRawInfo(autofill::NAME_FIRST, UTF8ToUTF16("Jane")); 443 profile.SetRawInfo(NAME_FIRST, UTF8ToUTF16("Jane"));
452 change_list.push_back( 444 change_list.push_back(
453 syncer::SyncChange( 445 syncer::SyncChange(
454 FROM_HERE, 446 FROM_HERE,
455 syncer::SyncChange::ACTION_ADD, 447 syncer::SyncChange::ACTION_ADD,
456 MockAutofillProfileSyncableService::CreateData(profile))); 448 MockAutofillProfileSyncableService::CreateData(profile)));
457 AutofillProfile empty_profile(guid_present, kHttpsOrigin); 449 AutofillProfile empty_profile(guid_present, kHttpsOrigin);
458 change_list.push_back( 450 change_list.push_back(
459 syncer::SyncChange( 451 syncer::SyncChange(
460 FROM_HERE, 452 FROM_HERE,
461 syncer::SyncChange::ACTION_DELETE, 453 syncer::SyncChange::ACTION_DELETE,
(...skipping 15 matching lines...) Expand all
477 EXPECT_FALSE(error.IsSet()); 469 EXPECT_FALSE(error.IsSet());
478 } 470 }
479 471
480 TEST_F(AutofillProfileSyncableServiceTest, AutofillProfileAdded) { 472 TEST_F(AutofillProfileSyncableServiceTest, AutofillProfileAdded) {
481 // Will be owned by the syncable service. Keep a reference available here for 473 // Will be owned by the syncable service. Keep a reference available here for
482 // verifying test expectations. 474 // verifying test expectations.
483 TestSyncChangeProcessor* sync_change_processor = new TestSyncChangeProcessor; 475 TestSyncChangeProcessor* sync_change_processor = new TestSyncChangeProcessor;
484 autofill_syncable_service_.set_sync_processor(sync_change_processor); 476 autofill_syncable_service_.set_sync_processor(sync_change_processor);
485 477
486 AutofillProfile profile(kGuid1, kHttpsOrigin); 478 AutofillProfile profile(kGuid1, kHttpsOrigin);
487 profile.SetRawInfo(autofill::NAME_FIRST, UTF8ToUTF16("Jane")); 479 profile.SetRawInfo(NAME_FIRST, UTF8ToUTF16("Jane"));
488 AutofillProfileChange change(AutofillProfileChange::ADD, kGuid1, &profile); 480 AutofillProfileChange change(AutofillProfileChange::ADD, kGuid1, &profile);
489 autofill_syncable_service_.AutofillProfileChanged(change); 481 autofill_syncable_service_.AutofillProfileChanged(change);
490 482
491 ASSERT_EQ(1U, sync_change_processor->changes().size()); 483 ASSERT_EQ(1U, sync_change_processor->changes().size());
492 syncer::SyncChange result = sync_change_processor->changes()[0]; 484 syncer::SyncChange result = sync_change_processor->changes()[0];
493 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, result.change_type()); 485 EXPECT_EQ(syncer::SyncChange::ACTION_ADD, result.change_type());
494 486
495 sync_pb::AutofillProfileSpecifics specifics = 487 sync_pb::AutofillProfileSpecifics specifics =
496 result.sync_data().GetSpecifics().autofill_profile(); 488 result.sync_data().GetSpecifics().autofill_profile();
497 EXPECT_EQ(kGuid1, specifics.guid()); 489 EXPECT_EQ(kGuid1, specifics.guid());
(...skipping 15 matching lines...) Expand all
513 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, result.change_type()); 505 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, result.change_type());
514 sync_pb::AutofillProfileSpecifics specifics = 506 sync_pb::AutofillProfileSpecifics specifics =
515 result.sync_data().GetSpecifics().autofill_profile(); 507 result.sync_data().GetSpecifics().autofill_profile();
516 EXPECT_EQ(kGuid2, specifics.guid()); 508 EXPECT_EQ(kGuid2, specifics.guid());
517 } 509 }
518 510
519 TEST_F(AutofillProfileSyncableServiceTest, UpdateField) { 511 TEST_F(AutofillProfileSyncableServiceTest, UpdateField) {
520 AutofillProfile profile(kGuid1, kSettingsOrigin); 512 AutofillProfile profile(kGuid1, kSettingsOrigin);
521 std::string company1 = "A Company"; 513 std::string company1 = "A Company";
522 std::string company2 = "Another Company"; 514 std::string company2 = "Another Company";
523 profile.SetRawInfo(autofill::COMPANY_NAME, UTF8ToUTF16(company1)); 515 profile.SetRawInfo(COMPANY_NAME, UTF8ToUTF16(company1));
524 EXPECT_FALSE(AutofillProfileSyncableService::UpdateField( 516 EXPECT_FALSE(AutofillProfileSyncableService::UpdateField(
525 autofill::COMPANY_NAME, company1, &profile)); 517 COMPANY_NAME, company1, &profile));
526 EXPECT_EQ(profile.GetRawInfo(autofill::COMPANY_NAME), UTF8ToUTF16(company1)); 518 EXPECT_EQ(profile.GetRawInfo(COMPANY_NAME), UTF8ToUTF16(company1));
527 EXPECT_TRUE(AutofillProfileSyncableService::UpdateField( 519 EXPECT_TRUE(AutofillProfileSyncableService::UpdateField(
528 autofill::COMPANY_NAME, company2, &profile)); 520 COMPANY_NAME, company2, &profile));
529 EXPECT_EQ(profile.GetRawInfo(autofill::COMPANY_NAME), UTF8ToUTF16(company2)); 521 EXPECT_EQ(profile.GetRawInfo(COMPANY_NAME), UTF8ToUTF16(company2));
530 EXPECT_FALSE(AutofillProfileSyncableService::UpdateField( 522 EXPECT_FALSE(AutofillProfileSyncableService::UpdateField(
531 autofill::COMPANY_NAME, company2, &profile)); 523 COMPANY_NAME, company2, &profile));
532 EXPECT_EQ(profile.GetRawInfo(autofill::COMPANY_NAME), UTF8ToUTF16(company2)); 524 EXPECT_EQ(profile.GetRawInfo(COMPANY_NAME), UTF8ToUTF16(company2));
533 } 525 }
534 526
535 TEST_F(AutofillProfileSyncableServiceTest, UpdateMultivaluedField) { 527 TEST_F(AutofillProfileSyncableServiceTest, UpdateMultivaluedField) {
536 AutofillProfile profile(kGuid1, kHttpsOrigin); 528 AutofillProfile profile(kGuid1, kHttpsOrigin);
537 529
538 std::vector<base::string16> values; 530 std::vector<base::string16> values;
539 values.push_back(UTF8ToUTF16("1@1.com")); 531 values.push_back(UTF8ToUTF16("1@1.com"));
540 values.push_back(UTF8ToUTF16("2@1.com")); 532 values.push_back(UTF8ToUTF16("2@1.com"));
541 profile.SetRawMultiInfo(autofill::EMAIL_ADDRESS, values); 533 profile.SetRawMultiInfo(EMAIL_ADDRESS, values);
542 534
543 ::google::protobuf::RepeatedPtrField<std::string> specifics_fields; 535 ::google::protobuf::RepeatedPtrField<std::string> specifics_fields;
544 specifics_fields.AddAllocated(new std::string("2@1.com")); 536 specifics_fields.AddAllocated(new std::string("2@1.com"));
545 specifics_fields.AddAllocated(new std::string("3@1.com")); 537 specifics_fields.AddAllocated(new std::string("3@1.com"));
546 538
547 EXPECT_TRUE(AutofillProfileSyncableService::UpdateMultivaluedField( 539 EXPECT_TRUE(AutofillProfileSyncableService::UpdateMultivaluedField(
548 autofill::EMAIL_ADDRESS, specifics_fields, &profile)); 540 EMAIL_ADDRESS, specifics_fields, &profile));
549 profile.GetRawMultiInfo(autofill::EMAIL_ADDRESS, &values); 541 profile.GetRawMultiInfo(EMAIL_ADDRESS, &values);
550 ASSERT_TRUE(values.size() == 2); 542 ASSERT_TRUE(values.size() == 2);
551 EXPECT_EQ(values[0], UTF8ToUTF16("2@1.com")); 543 EXPECT_EQ(values[0], UTF8ToUTF16("2@1.com"));
552 EXPECT_EQ(values[1], UTF8ToUTF16("3@1.com")); 544 EXPECT_EQ(values[1], UTF8ToUTF16("3@1.com"));
553 545
554 EXPECT_FALSE(AutofillProfileSyncableService::UpdateMultivaluedField( 546 EXPECT_FALSE(AutofillProfileSyncableService::UpdateMultivaluedField(
555 autofill::EMAIL_ADDRESS, specifics_fields, &profile)); 547 EMAIL_ADDRESS, specifics_fields, &profile));
556 profile.GetRawMultiInfo(autofill::EMAIL_ADDRESS, &values); 548 profile.GetRawMultiInfo(EMAIL_ADDRESS, &values);
557 ASSERT_EQ(values.size(), 2U); 549 ASSERT_EQ(values.size(), 2U);
558 EXPECT_EQ(values[0], UTF8ToUTF16("2@1.com")); 550 EXPECT_EQ(values[0], UTF8ToUTF16("2@1.com"));
559 EXPECT_EQ(values[1], UTF8ToUTF16("3@1.com")); 551 EXPECT_EQ(values[1], UTF8ToUTF16("3@1.com"));
560 EXPECT_TRUE(AutofillProfileSyncableService::UpdateMultivaluedField( 552 EXPECT_TRUE(AutofillProfileSyncableService::UpdateMultivaluedField(
561 autofill::EMAIL_ADDRESS, 553 EMAIL_ADDRESS, ::google::protobuf::RepeatedPtrField<std::string>(),
562 ::google::protobuf::RepeatedPtrField<std::string>(),
563 &profile)); 554 &profile));
564 profile.GetRawMultiInfo(autofill::EMAIL_ADDRESS, &values); 555 profile.GetRawMultiInfo(EMAIL_ADDRESS, &values);
565 ASSERT_EQ(values.size(), 1U); // Always have at least an empty string. 556 ASSERT_EQ(values.size(), 1U); // Always have at least an empty string.
566 EXPECT_EQ(values[0], UTF8ToUTF16("")); 557 EXPECT_EQ(values[0], UTF8ToUTF16(""));
567 } 558 }
568 559
569 TEST_F(AutofillProfileSyncableServiceTest, MergeProfile) { 560 TEST_F(AutofillProfileSyncableServiceTest, MergeProfile) {
570 AutofillProfile profile1(kGuid1, kHttpOrigin); 561 AutofillProfile profile1(kGuid1, kHttpOrigin);
571 profile1.SetRawInfo( 562 profile1.SetRawInfo(ADDRESS_HOME_LINE1, UTF8ToUTF16("111 First St."));
572 autofill::ADDRESS_HOME_LINE1, UTF8ToUTF16("111 First St."));
573 563
574 std::vector<base::string16> values; 564 std::vector<base::string16> values;
575 values.push_back(UTF8ToUTF16("1@1.com")); 565 values.push_back(UTF8ToUTF16("1@1.com"));
576 values.push_back(UTF8ToUTF16("2@1.com")); 566 values.push_back(UTF8ToUTF16("2@1.com"));
577 profile1.SetRawMultiInfo(autofill::EMAIL_ADDRESS, values); 567 profile1.SetRawMultiInfo(EMAIL_ADDRESS, values);
578 568
579 AutofillProfile profile2(kGuid2, kHttpsOrigin); 569 AutofillProfile profile2(kGuid2, kHttpsOrigin);
580 profile2.SetRawInfo( 570 profile2.SetRawInfo(ADDRESS_HOME_LINE1, UTF8ToUTF16("111 First St."));
581 autofill::ADDRESS_HOME_LINE1, UTF8ToUTF16("111 First St."));
582 571
583 // |values| now is [ "1@1.com", "2@1.com", "3@1.com" ]. 572 // |values| now is [ "1@1.com", "2@1.com", "3@1.com" ].
584 values.push_back(UTF8ToUTF16("3@1.com")); 573 values.push_back(UTF8ToUTF16("3@1.com"));
585 profile2.SetRawMultiInfo(autofill::EMAIL_ADDRESS, values); 574 profile2.SetRawMultiInfo(EMAIL_ADDRESS, values);
586 575
587 values.clear(); 576 values.clear();
588 values.push_back(UTF8ToUTF16("John")); 577 values.push_back(UTF8ToUTF16("John"));
589 profile1.SetRawMultiInfo(autofill::NAME_FIRST, values); 578 profile1.SetRawMultiInfo(NAME_FIRST, values);
590 values.push_back(UTF8ToUTF16("Jane")); 579 values.push_back(UTF8ToUTF16("Jane"));
591 profile2.SetRawMultiInfo(autofill::NAME_FIRST, values); 580 profile2.SetRawMultiInfo(NAME_FIRST, values);
592 581
593 values.clear(); 582 values.clear();
594 values.push_back(UTF8ToUTF16("Doe")); 583 values.push_back(UTF8ToUTF16("Doe"));
595 profile1.SetRawMultiInfo(autofill::NAME_LAST, values); 584 profile1.SetRawMultiInfo(NAME_LAST, values);
596 values.push_back(UTF8ToUTF16("Other")); 585 values.push_back(UTF8ToUTF16("Other"));
597 profile2.SetRawMultiInfo(autofill::NAME_LAST, values); 586 profile2.SetRawMultiInfo(NAME_LAST, values);
598 587
599 values.clear(); 588 values.clear();
600 values.push_back(UTF8ToUTF16("650234567")); 589 values.push_back(UTF8ToUTF16("650234567"));
601 profile2.SetRawMultiInfo(autofill::PHONE_HOME_WHOLE_NUMBER, values); 590 profile2.SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, values);
602 591
603 EXPECT_FALSE(AutofillProfileSyncableService::MergeProfile(profile2, 592 EXPECT_FALSE(AutofillProfileSyncableService::MergeProfile(profile2,
604 &profile1, 593 &profile1,
605 "en-US")); 594 "en-US"));
606 595
607 profile1.GetRawMultiInfo(autofill::NAME_FIRST, &values); 596 profile1.GetRawMultiInfo(NAME_FIRST, &values);
608 ASSERT_EQ(values.size(), 2U); 597 ASSERT_EQ(values.size(), 2U);
609 EXPECT_EQ(values[0], UTF8ToUTF16("John")); 598 EXPECT_EQ(values[0], UTF8ToUTF16("John"));
610 EXPECT_EQ(values[1], UTF8ToUTF16("Jane")); 599 EXPECT_EQ(values[1], UTF8ToUTF16("Jane"));
611 600
612 profile1.GetRawMultiInfo(autofill::NAME_LAST, &values); 601 profile1.GetRawMultiInfo(NAME_LAST, &values);
613 ASSERT_EQ(values.size(), 2U); 602 ASSERT_EQ(values.size(), 2U);
614 EXPECT_EQ(values[0], UTF8ToUTF16("Doe")); 603 EXPECT_EQ(values[0], UTF8ToUTF16("Doe"));
615 EXPECT_EQ(values[1], UTF8ToUTF16("Other")); 604 EXPECT_EQ(values[1], UTF8ToUTF16("Other"));
616 605
617 profile1.GetRawMultiInfo(autofill::EMAIL_ADDRESS, &values); 606 profile1.GetRawMultiInfo(EMAIL_ADDRESS, &values);
618 ASSERT_EQ(values.size(), 3U); 607 ASSERT_EQ(values.size(), 3U);
619 EXPECT_EQ(values[0], UTF8ToUTF16("1@1.com")); 608 EXPECT_EQ(values[0], UTF8ToUTF16("1@1.com"));
620 EXPECT_EQ(values[1], UTF8ToUTF16("2@1.com")); 609 EXPECT_EQ(values[1], UTF8ToUTF16("2@1.com"));
621 EXPECT_EQ(values[2], UTF8ToUTF16("3@1.com")); 610 EXPECT_EQ(values[2], UTF8ToUTF16("3@1.com"));
622 611
623 profile1.GetRawMultiInfo(autofill::PHONE_HOME_WHOLE_NUMBER, &values); 612 profile1.GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values);
624 ASSERT_EQ(values.size(), 1U); 613 ASSERT_EQ(values.size(), 1U);
625 EXPECT_EQ(values[0], UTF8ToUTF16("650234567")); 614 EXPECT_EQ(values[0], UTF8ToUTF16("650234567"));
626 615
627 EXPECT_EQ(profile2.origin(), profile1.origin()); 616 EXPECT_EQ(profile2.origin(), profile1.origin());
628 617
629 AutofillProfile profile3(kGuid3, kHttpOrigin); 618 AutofillProfile profile3(kGuid3, kHttpOrigin);
630 profile3.SetRawInfo( 619 profile3.SetRawInfo(ADDRESS_HOME_LINE1, UTF8ToUTF16("111 First St."));
631 autofill::ADDRESS_HOME_LINE1, UTF8ToUTF16("111 First St."));
632 620
633 values.clear(); 621 values.clear();
634 values.push_back(UTF8ToUTF16("Jane")); 622 values.push_back(UTF8ToUTF16("Jane"));
635 profile3.SetRawMultiInfo(autofill::NAME_FIRST, values); 623 profile3.SetRawMultiInfo(NAME_FIRST, values);
636 624
637 values.clear(); 625 values.clear();
638 values.push_back(UTF8ToUTF16("Doe")); 626 values.push_back(UTF8ToUTF16("Doe"));
639 profile3.SetRawMultiInfo(autofill::NAME_LAST, values); 627 profile3.SetRawMultiInfo(NAME_LAST, values);
640 628
641 EXPECT_TRUE(AutofillProfileSyncableService::MergeProfile(profile3, 629 EXPECT_TRUE(AutofillProfileSyncableService::MergeProfile(profile3,
642 &profile1, 630 &profile1,
643 "en-US")); 631 "en-US"));
644 632
645 profile1.GetRawMultiInfo(autofill::NAME_FIRST, &values); 633 profile1.GetRawMultiInfo(NAME_FIRST, &values);
646 ASSERT_EQ(values.size(), 3U); 634 ASSERT_EQ(values.size(), 3U);
647 EXPECT_EQ(values[0], UTF8ToUTF16("John")); 635 EXPECT_EQ(values[0], UTF8ToUTF16("John"));
648 EXPECT_EQ(values[1], UTF8ToUTF16("Jane")); 636 EXPECT_EQ(values[1], UTF8ToUTF16("Jane"));
649 EXPECT_EQ(values[2], UTF8ToUTF16("Jane")); 637 EXPECT_EQ(values[2], UTF8ToUTF16("Jane"));
650 638
651 profile1.GetRawMultiInfo(autofill::NAME_LAST, &values); 639 profile1.GetRawMultiInfo(NAME_LAST, &values);
652 ASSERT_EQ(values.size(), 3U); 640 ASSERT_EQ(values.size(), 3U);
653 EXPECT_EQ(values[0], UTF8ToUTF16("Doe")); 641 EXPECT_EQ(values[0], UTF8ToUTF16("Doe"));
654 EXPECT_EQ(values[1], UTF8ToUTF16("Other")); 642 EXPECT_EQ(values[1], UTF8ToUTF16("Other"));
655 EXPECT_EQ(values[2], UTF8ToUTF16("Doe")); 643 EXPECT_EQ(values[2], UTF8ToUTF16("Doe"));
656 644
657 // Middle name should have three entries as well. 645 // Middle name should have three entries as well.
658 profile1.GetRawMultiInfo(autofill::NAME_MIDDLE, &values); 646 profile1.GetRawMultiInfo(NAME_MIDDLE, &values);
659 ASSERT_EQ(values.size(), 3U); 647 ASSERT_EQ(values.size(), 3U);
660 EXPECT_TRUE(values[0].empty()); 648 EXPECT_TRUE(values[0].empty());
661 EXPECT_TRUE(values[1].empty()); 649 EXPECT_TRUE(values[1].empty());
662 EXPECT_TRUE(values[2].empty()); 650 EXPECT_TRUE(values[2].empty());
663 651
664 profile1.GetRawMultiInfo(autofill::EMAIL_ADDRESS, &values); 652 profile1.GetRawMultiInfo(EMAIL_ADDRESS, &values);
665 ASSERT_EQ(values.size(), 3U); 653 ASSERT_EQ(values.size(), 3U);
666 EXPECT_EQ(values[0], UTF8ToUTF16("1@1.com")); 654 EXPECT_EQ(values[0], UTF8ToUTF16("1@1.com"));
667 EXPECT_EQ(values[1], UTF8ToUTF16("2@1.com")); 655 EXPECT_EQ(values[1], UTF8ToUTF16("2@1.com"));
668 EXPECT_EQ(values[2], UTF8ToUTF16("3@1.com")); 656 EXPECT_EQ(values[2], UTF8ToUTF16("3@1.com"));
669 657
670 profile1.GetRawMultiInfo(autofill::PHONE_HOME_WHOLE_NUMBER, &values); 658 profile1.GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values);
671 ASSERT_EQ(values.size(), 1U); 659 ASSERT_EQ(values.size(), 1U);
672 EXPECT_EQ(values[0], UTF8ToUTF16("650234567")); 660 EXPECT_EQ(values[0], UTF8ToUTF16("650234567"));
673 } 661 }
662
663 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/webdata/autofill_profile_syncable_service.cc ('k') | chrome/browser/webdata/web_data_service_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698