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

Side by Side Diff: components/autofill/core/browser/personal_data_manager_unittest.cc

Issue 2082333002: Remove calls to deprecated MessageLoop methods in components. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/personal_data_manager.h" 5 #include "components/autofill/core/browser/personal_data_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <list> 10 #include <list>
11 #include <map> 11 #include <map>
12 #include <memory> 12 #include <memory>
13 #include <string> 13 #include <string>
14 #include <utility> 14 #include <utility>
15 #include <vector> 15 #include <vector>
16 16
17 #include "base/command_line.h" 17 #include "base/command_line.h"
18 #include "base/feature_list.h" 18 #include "base/feature_list.h"
19 #include "base/files/scoped_temp_dir.h" 19 #include "base/files/scoped_temp_dir.h"
20 #include "base/guid.h" 20 #include "base/guid.h"
21 #include "base/metrics/field_trial.h" 21 #include "base/metrics/field_trial.h"
22 #include "base/run_loop.h"
22 #include "base/strings/utf_string_conversions.h" 23 #include "base/strings/utf_string_conversions.h"
23 #include "base/synchronization/waitable_event.h" 24 #include "base/synchronization/waitable_event.h"
24 #include "base/test/histogram_tester.h" 25 #include "base/test/histogram_tester.h"
25 #include "base/threading/thread_task_runner_handle.h" 26 #include "base/threading/thread_task_runner_handle.h"
26 #include "base/time/time.h" 27 #include "base/time/time.h"
27 #include "build/build_config.h" 28 #include "build/build_config.h"
28 #include "components/autofill/core/browser/autofill_experiments.h" 29 #include "components/autofill/core/browser/autofill_experiments.h"
29 #include "components/autofill/core/browser/autofill_profile.h" 30 #include "components/autofill/core/browser/autofill_profile.h"
30 #include "components/autofill/core/browser/autofill_test_utils.h" 31 #include "components/autofill/core/browser/autofill_test_utils.h"
31 #include "components/autofill/core/browser/field_types.h" 32 #include "components/autofill/core/browser/field_types.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 scoped_refptr<AutofillWebDataService>(autofill_database_service_), 173 scoped_refptr<AutofillWebDataService>(autofill_database_service_),
173 prefs_.get(), 174 prefs_.get(),
174 account_tracker_.get(), 175 account_tracker_.get(),
175 signin_manager_.get(), 176 signin_manager_.get(),
176 is_incognito); 177 is_incognito);
177 personal_data_->AddObserver(&personal_data_observer_); 178 personal_data_->AddObserver(&personal_data_observer_);
178 179
179 // Verify that the web database has been updated and the notification sent. 180 // Verify that the web database has been updated and the notification sent.
180 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 181 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
181 .WillOnce(QuitMainMessageLoop()); 182 .WillOnce(QuitMainMessageLoop());
182 base::MessageLoop::current()->Run(); 183 base::RunLoop().Run();
183 } 184 }
184 185
185 void ResetProfiles() { 186 void ResetProfiles() {
186 std::vector<AutofillProfile> empty_profiles; 187 std::vector<AutofillProfile> empty_profiles;
187 personal_data_->SetProfiles(&empty_profiles); 188 personal_data_->SetProfiles(&empty_profiles);
188 } 189 }
189 190
190 void EnableWalletCardImport() { 191 void EnableWalletCardImport() {
191 signin_manager_->SetAuthenticatedAccountInfo("12345", 192 signin_manager_->SetAuthenticatedAccountInfo("12345",
192 "syncuser@example.com"); 193 "syncuser@example.com");
(...skipping 13 matching lines...) Expand all
206 ASSERT_EQ(0U, personal_data_->GetProfiles().size()); 207 ASSERT_EQ(0U, personal_data_->GetProfiles().size());
207 208
208 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com"); 209 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com");
209 test::SetProfileInfo(&profile, "Marion", "Mitchell", "Morrison", 210 test::SetProfileInfo(&profile, "Marion", "Mitchell", "Morrison",
210 "johnwayne@me.xyz", "Fox", "123 Zoo St", "unit 5", 211 "johnwayne@me.xyz", "Fox", "123 Zoo St", "unit 5",
211 "Hollywood", "CA", "91601", "US", "12345678910"); 212 "Hollywood", "CA", "91601", "US", "12345678910");
212 personal_data_->AddProfile(profile); 213 personal_data_->AddProfile(profile);
213 214
214 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 215 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
215 .WillOnce(QuitMainMessageLoop()); 216 .WillOnce(QuitMainMessageLoop());
216 base::MessageLoop::current()->Run(); 217 base::RunLoop().Run();
217 218
218 ASSERT_EQ(1U, personal_data_->GetProfiles().size()); 219 ASSERT_EQ(1U, personal_data_->GetProfiles().size());
219 } 220 }
220 221
221 // Helper method that will add credit card fields in |form|, according to the 222 // Helper method that will add credit card fields in |form|, according to the
222 // specified values. If a value is nullptr, the corresponding field won't get 223 // specified values. If a value is nullptr, the corresponding field won't get
223 // added (empty string will add a field with an empty string as the value). 224 // added (empty string will add a field with an empty string as the value).
224 void AddFullCreditCardForm(FormData* form, 225 void AddFullCreditCardForm(FormData* form,
225 const char* name, 226 const char* name,
226 const char* number, 227 const char* number,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 CreditCard credit_card2("002149C1-EE28-4213-A3B9-DA243FFF021B", 277 CreditCard credit_card2("002149C1-EE28-4213-A3B9-DA243FFF021B",
277 "https://www.example.com"); 278 "https://www.example.com");
278 credit_card2.set_use_count(1); 279 credit_card2.set_use_count(1);
279 credit_card2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1)); 280 credit_card2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1));
280 test::SetCreditCardInfo(&credit_card2, "Bonnie Parker", 281 test::SetCreditCardInfo(&credit_card2, "Bonnie Parker",
281 "518765432109" /* Mastercard */, "12", "3999"); 282 "518765432109" /* Mastercard */, "12", "3999");
282 personal_data_->AddCreditCard(credit_card2); 283 personal_data_->AddCreditCard(credit_card2);
283 284
284 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 285 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
285 .WillOnce(QuitMainMessageLoop()); 286 .WillOnce(QuitMainMessageLoop());
286 base::MessageLoop::current()->Run(); 287 base::RunLoop().Run();
287 288
288 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); 289 ASSERT_EQ(3U, personal_data_->GetCreditCards().size());
289 } 290 }
290 291
291 // Helper methods that simply forward the call to the private member (to avoid 292 // Helper methods that simply forward the call to the private member (to avoid
292 // having to friend every test that needs to access the private 293 // having to friend every test that needs to access the private
293 // PersonalDataManager::ImportAddressProfile or ImportCreditCard). 294 // PersonalDataManager::ImportAddressProfile or ImportCreditCard).
294 bool ImportAddressProfiles(const FormStructure& form) { 295 bool ImportAddressProfiles(const FormStructure& form) {
295 return personal_data_->ImportAddressProfiles(form); 296 return personal_data_->ImportAddressProfiles(form);
296 } 297 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 test::SetProfileInfo(&server_profiles.back(), "John", "", "Doe", "", 418 test::SetProfileInfo(&server_profiles.back(), "John", "", "Doe", "",
418 "ACME Corp", "500 Oak View", "Apt 8", "Houston", "TX", 419 "ACME Corp", "500 Oak View", "Apt 8", "Houston", "TX",
419 "77401", "US", ""); 420 "77401", "US", "");
420 // Wallet only provides a full name, so the above first and last names 421 // Wallet only provides a full name, so the above first and last names
421 // will be ignored when the profile is written to the DB. 422 // will be ignored when the profile is written to the DB.
422 server_profiles.back().SetRawInfo(NAME_FULL, ASCIIToUTF16("John Doe")); 423 server_profiles.back().SetRawInfo(NAME_FULL, ASCIIToUTF16("John Doe"));
423 autofill_table_->SetServerProfiles(server_profiles); 424 autofill_table_->SetServerProfiles(server_profiles);
424 personal_data_->Refresh(); 425 personal_data_->Refresh();
425 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 426 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
426 .WillOnce(QuitMainMessageLoop()); 427 .WillOnce(QuitMainMessageLoop());
427 base::MessageLoop::current()->Run(); 428 base::RunLoop().Run();
428 EXPECT_EQ(1U, personal_data_->GetProfiles().size()); 429 EXPECT_EQ(1U, personal_data_->GetProfiles().size());
429 430
430 // Add profile with identical values. Duplicates should not get saved. 431 // Add profile with identical values. Duplicates should not get saved.
431 AutofillProfile scraped_profile(base::GenerateGUID(), 432 AutofillProfile scraped_profile(base::GenerateGUID(),
432 "https://www.example.com"); 433 "https://www.example.com");
433 test::SetProfileInfo(&scraped_profile, "John", "", "Doe", "", "ACME Corp", 434 test::SetProfileInfo(&scraped_profile, "John", "", "Doe", "", "ACME Corp",
434 "500 Oak View", "Apt 8", "Houston", "TX", "77401", "US", 435 "500 Oak View", "Apt 8", "Houston", "TX", "77401", "US",
435 ""); 436 "");
436 EXPECT_TRUE(scraped_profile.IsSubsetOf(server_profiles.back(), "en-US")); 437 EXPECT_TRUE(scraped_profile.IsSubsetOf(server_profiles.back(), "en-US"));
437 std::string saved_guid = personal_data_->SaveImportedProfile(scraped_profile); 438 std::string saved_guid = personal_data_->SaveImportedProfile(scraped_profile);
438 EXPECT_NE(scraped_profile.guid(), saved_guid); 439 EXPECT_NE(scraped_profile.guid(), saved_guid);
439 440
440 personal_data_->Refresh(); 441 personal_data_->Refresh();
441 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 442 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
442 .WillOnce(QuitMainMessageLoop()); 443 .WillOnce(QuitMainMessageLoop());
443 base::MessageLoop::current()->Run(); 444 base::RunLoop().Run();
444 445
445 // Verify the non-addition. 446 // Verify the non-addition.
446 EXPECT_EQ(0U, personal_data_->web_profiles().size()); 447 EXPECT_EQ(0U, personal_data_->web_profiles().size());
447 ASSERT_EQ(1U, personal_data_->GetProfiles().size()); 448 ASSERT_EQ(1U, personal_data_->GetProfiles().size());
448 449
449 // Verify that the server profile's use date was updated. 450 // Verify that the server profile's use date was updated.
450 const AutofillProfile* server_profile = personal_data_->GetProfiles()[0]; 451 const AutofillProfile* server_profile = personal_data_->GetProfiles()[0];
451 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), 452 EXPECT_GT(base::TimeDelta::FromMilliseconds(500),
452 base::Time::Now() - server_profile->use_date()); 453 base::Time::Now() - server_profile->use_date());
453 } 454 }
(...skipping 29 matching lines...) Expand all
483 "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", 484 "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL",
484 "32801", "US", "19482937549"); 485 "32801", "US", "19482937549");
485 486
486 // Add two test profiles to the database. 487 // Add two test profiles to the database.
487 personal_data_->AddProfile(profile0); 488 personal_data_->AddProfile(profile0);
488 personal_data_->AddProfile(profile1); 489 personal_data_->AddProfile(profile1);
489 490
490 // Verify that the web database has been updated and the notification sent. 491 // Verify that the web database has been updated and the notification sent.
491 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 492 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
492 .WillOnce(QuitMainMessageLoop()); 493 .WillOnce(QuitMainMessageLoop());
493 base::MessageLoop::current()->Run(); 494 base::RunLoop().Run();
494 495
495 std::vector<AutofillProfile*> profiles; 496 std::vector<AutofillProfile*> profiles;
496 profiles.push_back(&profile0); 497 profiles.push_back(&profile0);
497 profiles.push_back(&profile1); 498 profiles.push_back(&profile1);
498 ExpectSameElements(profiles, personal_data_->GetProfiles()); 499 ExpectSameElements(profiles, personal_data_->GetProfiles());
499 500
500 // Update, remove, and add. 501 // Update, remove, and add.
501 profile0.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); 502 profile0.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John"));
502 personal_data_->UpdateProfile(profile0); 503 personal_data_->UpdateProfile(profile0);
503 personal_data_->RemoveByGUID(profile1.guid()); 504 personal_data_->RemoveByGUID(profile1.guid());
504 personal_data_->AddProfile(profile2); 505 personal_data_->AddProfile(profile2);
505 506
506 // Verify that the web database has been updated and the notification sent. 507 // Verify that the web database has been updated and the notification sent.
507 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 508 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
508 .WillOnce(QuitMainMessageLoop()); 509 .WillOnce(QuitMainMessageLoop());
509 base::MessageLoop::current()->Run(); 510 base::RunLoop().Run();
510 511
511 profiles.clear(); 512 profiles.clear();
512 profiles.push_back(&profile0); 513 profiles.push_back(&profile0);
513 profiles.push_back(&profile2); 514 profiles.push_back(&profile2);
514 ExpectSameElements(profiles, personal_data_->GetProfiles()); 515 ExpectSameElements(profiles, personal_data_->GetProfiles());
515 516
516 // Reset the PersonalDataManager. This tests that the personal data was saved 517 // Reset the PersonalDataManager. This tests that the personal data was saved
517 // to the web database, and that we can load the profiles from the web 518 // to the web database, and that we can load the profiles from the web
518 // database. 519 // database.
519 ResetPersonalDataManager(USER_MODE_NORMAL); 520 ResetPersonalDataManager(USER_MODE_NORMAL);
(...skipping 15 matching lines...) Expand all
535 test::SetCreditCardInfo(&credit_card2, 536 test::SetCreditCardInfo(&credit_card2,
536 "Clyde Barrow", "347666888555" /* American Express */, "04", "3999"); 537 "Clyde Barrow", "347666888555" /* American Express */, "04", "3999");
537 538
538 // Add two test credit cards to the database. 539 // Add two test credit cards to the database.
539 personal_data_->AddCreditCard(credit_card0); 540 personal_data_->AddCreditCard(credit_card0);
540 personal_data_->AddCreditCard(credit_card1); 541 personal_data_->AddCreditCard(credit_card1);
541 542
542 // Verify that the web database has been updated and the notification sent. 543 // Verify that the web database has been updated and the notification sent.
543 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 544 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
544 .WillOnce(QuitMainMessageLoop()); 545 .WillOnce(QuitMainMessageLoop());
545 base::MessageLoop::current()->Run(); 546 base::RunLoop().Run();
546 547
547 std::vector<CreditCard*> cards; 548 std::vector<CreditCard*> cards;
548 cards.push_back(&credit_card0); 549 cards.push_back(&credit_card0);
549 cards.push_back(&credit_card1); 550 cards.push_back(&credit_card1);
550 ExpectSameElements(cards, personal_data_->GetCreditCards()); 551 ExpectSameElements(cards, personal_data_->GetCreditCards());
551 552
552 // Update, remove, and add. 553 // Update, remove, and add.
553 credit_card0.SetRawInfo(CREDIT_CARD_NAME_FULL, ASCIIToUTF16("Joe")); 554 credit_card0.SetRawInfo(CREDIT_CARD_NAME_FULL, ASCIIToUTF16("Joe"));
554 personal_data_->UpdateCreditCard(credit_card0); 555 personal_data_->UpdateCreditCard(credit_card0);
555 personal_data_->RemoveByGUID(credit_card1.guid()); 556 personal_data_->RemoveByGUID(credit_card1.guid());
556 personal_data_->AddCreditCard(credit_card2); 557 personal_data_->AddCreditCard(credit_card2);
557 558
558 // Verify that the web database has been updated and the notification sent. 559 // Verify that the web database has been updated and the notification sent.
559 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 560 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
560 .WillOnce(QuitMainMessageLoop()); 561 .WillOnce(QuitMainMessageLoop());
561 base::MessageLoop::current()->Run(); 562 base::RunLoop().Run();
562 563
563 cards.clear(); 564 cards.clear();
564 cards.push_back(&credit_card0); 565 cards.push_back(&credit_card0);
565 cards.push_back(&credit_card2); 566 cards.push_back(&credit_card2);
566 ExpectSameElements(cards, personal_data_->GetCreditCards()); 567 ExpectSameElements(cards, personal_data_->GetCreditCards());
567 568
568 // Reset the PersonalDataManager. This tests that the personal data was saved 569 // Reset the PersonalDataManager. This tests that the personal data was saved
569 // to the web database, and that we can load the credit cards from the web 570 // to the web database, and that we can load the credit cards from the web
570 // database. 571 // database.
571 ResetPersonalDataManager(USER_MODE_NORMAL); 572 ResetPersonalDataManager(USER_MODE_NORMAL);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 "John Dillinger", "423456789012" /* Visa */, "01", "2999"); 614 "John Dillinger", "423456789012" /* Visa */, "01", "2999");
614 EXPECT_FALSE(credit_card.IsVerified()); 615 EXPECT_FALSE(credit_card.IsVerified());
615 616
616 // Add the data to the database. 617 // Add the data to the database.
617 personal_data_->AddProfile(profile); 618 personal_data_->AddProfile(profile);
618 personal_data_->AddCreditCard(credit_card); 619 personal_data_->AddCreditCard(credit_card);
619 620
620 // Verify that the web database has been updated and the notification sent. 621 // Verify that the web database has been updated and the notification sent.
621 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 622 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
622 .WillOnce(QuitMainMessageLoop()); 623 .WillOnce(QuitMainMessageLoop());
623 base::MessageLoop::current()->Run(); 624 base::RunLoop().Run();
624 625
625 const std::vector<AutofillProfile*>& profiles1 = 626 const std::vector<AutofillProfile*>& profiles1 =
626 personal_data_->GetProfiles(); 627 personal_data_->GetProfiles();
627 const std::vector<CreditCard*>& cards1 = personal_data_->GetCreditCards(); 628 const std::vector<CreditCard*>& cards1 = personal_data_->GetCreditCards();
628 ASSERT_EQ(1U, profiles1.size()); 629 ASSERT_EQ(1U, profiles1.size());
629 ASSERT_EQ(1U, cards1.size()); 630 ASSERT_EQ(1U, cards1.size());
630 EXPECT_EQ(0, profile.Compare(*profiles1[0])); 631 EXPECT_EQ(0, profile.Compare(*profiles1[0]));
631 EXPECT_EQ(0, credit_card.Compare(*cards1[0])); 632 EXPECT_EQ(0, credit_card.Compare(*cards1[0]));
632 633
633 // Try to update with just the origin changed. 634 // Try to update with just the origin changed.
(...skipping 23 matching lines...) Expand all
657 // Try to update with data changed as well. 658 // Try to update with data changed as well.
658 profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); 659 profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John"));
659 credit_card.SetRawInfo(CREDIT_CARD_NAME_FULL, ASCIIToUTF16("Joe")); 660 credit_card.SetRawInfo(CREDIT_CARD_NAME_FULL, ASCIIToUTF16("Joe"));
660 661
661 personal_data_->UpdateProfile(profile); 662 personal_data_->UpdateProfile(profile);
662 personal_data_->UpdateCreditCard(credit_card); 663 personal_data_->UpdateCreditCard(credit_card);
663 664
664 // Verify that the web database has been updated and the notification sent. 665 // Verify that the web database has been updated and the notification sent.
665 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 666 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
666 .WillOnce(QuitMainMessageLoop()); 667 .WillOnce(QuitMainMessageLoop());
667 base::MessageLoop::current()->Run(); 668 base::RunLoop().Run();
668 669
669 const std::vector<AutofillProfile*>& profiles3 = 670 const std::vector<AutofillProfile*>& profiles3 =
670 personal_data_->GetProfiles(); 671 personal_data_->GetProfiles();
671 const std::vector<CreditCard*>& cards3 = personal_data_->GetCreditCards(); 672 const std::vector<CreditCard*>& cards3 = personal_data_->GetCreditCards();
672 ASSERT_EQ(1U, profiles3.size()); 673 ASSERT_EQ(1U, profiles3.size());
673 ASSERT_EQ(1U, cards3.size()); 674 ASSERT_EQ(1U, cards3.size());
674 EXPECT_EQ(0, profile.Compare(*profiles3[0])); 675 EXPECT_EQ(0, profile.Compare(*profiles3[0]));
675 EXPECT_EQ(0, credit_card.Compare(*cards3[0])); 676 EXPECT_EQ(0, credit_card.Compare(*cards3[0]));
676 EXPECT_EQ(profile.origin(), profiles3[0]->origin()); 677 EXPECT_EQ(profile.origin(), profiles3[0]->origin());
677 EXPECT_EQ(credit_card.origin(), cards3[0]->origin()); 678 EXPECT_EQ(credit_card.origin(), cards3[0]->origin());
(...skipping 13 matching lines...) Expand all
691 692
692 std::vector<CreditCard> server_cards; 693 std::vector<CreditCard> server_cards;
693 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); 694 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789"));
694 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", 695 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow",
695 "347666888555" /* American Express */, "04", "3999"); 696 "347666888555" /* American Express */, "04", "3999");
696 test::SetServerCreditCards(autofill_table_, server_cards); 697 test::SetServerCreditCards(autofill_table_, server_cards);
697 personal_data_->Refresh(); 698 personal_data_->Refresh();
698 699
699 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 700 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
700 .WillOnce(QuitMainMessageLoop()); 701 .WillOnce(QuitMainMessageLoop());
701 base::MessageLoop::current()->Run(); 702 base::RunLoop().Run();
702 703
703 ASSERT_EQ(1U, personal_data_->GetCreditCards().size()); 704 ASSERT_EQ(1U, personal_data_->GetCreditCards().size());
704 EXPECT_EQ(CreditCard::MASKED_SERVER_CARD, 705 EXPECT_EQ(CreditCard::MASKED_SERVER_CARD,
705 personal_data_->GetCreditCards()[0]->record_type()); 706 personal_data_->GetCreditCards()[0]->record_type());
706 } 707 }
707 708
708 TEST_F(PersonalDataManagerTest, OfferStoreUnmaskedCards) { 709 TEST_F(PersonalDataManagerTest, OfferStoreUnmaskedCards) {
709 #if defined(OS_CHROMEOS) || defined(OS_WIN) || defined(OS_MACOSX) || \ 710 #if defined(OS_CHROMEOS) || defined(OS_WIN) || defined(OS_MACOSX) || \
710 defined(OS_IOS) || defined(OS_ANDROID) 711 defined(OS_IOS) || defined(OS_ANDROID)
711 bool should_offer = true; 712 bool should_offer = true;
(...skipping 20 matching lines...) Expand all
732 733
733 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); 734 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789"));
734 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", 735 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow",
735 "347666888555" /* American Express */, "04", "3999"); 736 "347666888555" /* American Express */, "04", "3999");
736 737
737 test::SetServerCreditCards(autofill_table_, server_cards); 738 test::SetServerCreditCards(autofill_table_, server_cards);
738 personal_data_->Refresh(); 739 personal_data_->Refresh();
739 740
740 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 741 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
741 .WillOnce(QuitMainMessageLoop()); 742 .WillOnce(QuitMainMessageLoop());
742 base::MessageLoop::current()->Run(); 743 base::RunLoop().Run();
743 744
744 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); 745 ASSERT_EQ(3U, personal_data_->GetCreditCards().size());
745 746
746 if (!OfferStoreUnmaskedCards()) { 747 if (!OfferStoreUnmaskedCards()) {
747 for (CreditCard* card : personal_data_->GetCreditCards()) { 748 for (CreditCard* card : personal_data_->GetCreditCards()) {
748 EXPECT_EQ(CreditCard::MASKED_SERVER_CARD, card->record_type()); 749 EXPECT_EQ(CreditCard::MASKED_SERVER_CARD, card->record_type());
749 } 750 }
750 // The rest of this test doesn't work if we're force-masking all unmasked 751 // The rest of this test doesn't work if we're force-masking all unmasked
751 // cards. 752 // cards.
752 return; 753 return;
753 } 754 }
754 755
755 // The GUIDs will be different, so just compare the data. 756 // The GUIDs will be different, so just compare the data.
756 for (size_t i = 0; i < 3; ++i) 757 for (size_t i = 0; i < 3; ++i)
757 EXPECT_EQ(0, server_cards[i].Compare(*personal_data_->GetCreditCards()[i])); 758 EXPECT_EQ(0, server_cards[i].Compare(*personal_data_->GetCreditCards()[i]));
758 759
759 CreditCard* unmasked_card = &server_cards.front(); 760 CreditCard* unmasked_card = &server_cards.front();
760 unmasked_card->set_record_type(CreditCard::FULL_SERVER_CARD); 761 unmasked_card->set_record_type(CreditCard::FULL_SERVER_CARD);
761 unmasked_card->SetNumber(ASCIIToUTF16("423456789012")); 762 unmasked_card->SetNumber(ASCIIToUTF16("423456789012"));
762 EXPECT_NE(0, server_cards.front().Compare( 763 EXPECT_NE(0, server_cards.front().Compare(
763 *personal_data_->GetCreditCards().front())); 764 *personal_data_->GetCreditCards().front()));
764 personal_data_->UpdateServerCreditCard(*unmasked_card); 765 personal_data_->UpdateServerCreditCard(*unmasked_card);
765 766
766 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 767 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
767 .WillOnce(QuitMainMessageLoop()); 768 .WillOnce(QuitMainMessageLoop());
768 base::MessageLoop::current()->Run(); 769 base::RunLoop().Run();
769 770
770 for (size_t i = 0; i < 3; ++i) 771 for (size_t i = 0; i < 3; ++i)
771 EXPECT_EQ(0, server_cards[i].Compare(*personal_data_->GetCreditCards()[i])); 772 EXPECT_EQ(0, server_cards[i].Compare(*personal_data_->GetCreditCards()[i]));
772 773
773 CreditCard* remasked_card = &server_cards.back(); 774 CreditCard* remasked_card = &server_cards.back();
774 remasked_card->set_record_type(CreditCard::MASKED_SERVER_CARD); 775 remasked_card->set_record_type(CreditCard::MASKED_SERVER_CARD);
775 remasked_card->SetNumber(ASCIIToUTF16("8555")); 776 remasked_card->SetNumber(ASCIIToUTF16("8555"));
776 EXPECT_NE( 777 EXPECT_NE(
777 0, server_cards.back().Compare(*personal_data_->GetCreditCards().back())); 778 0, server_cards.back().Compare(*personal_data_->GetCreditCards().back()));
778 personal_data_->UpdateServerCreditCard(*remasked_card); 779 personal_data_->UpdateServerCreditCard(*remasked_card);
779 780
780 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 781 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
781 .WillOnce(QuitMainMessageLoop()); 782 .WillOnce(QuitMainMessageLoop());
782 base::MessageLoop::current()->Run(); 783 base::RunLoop().Run();
783 784
784 for (size_t i = 0; i < 3; ++i) 785 for (size_t i = 0; i < 3; ++i)
785 EXPECT_EQ(0, server_cards[i].Compare(*personal_data_->GetCreditCards()[i])); 786 EXPECT_EQ(0, server_cards[i].Compare(*personal_data_->GetCreditCards()[i]));
786 } 787 }
787 788
788 TEST_F(PersonalDataManagerTest, AddProfilesAndCreditCards) { 789 TEST_F(PersonalDataManagerTest, AddProfilesAndCreditCards) {
789 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com"); 790 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com");
790 test::SetProfileInfo(&profile0, 791 test::SetProfileInfo(&profile0,
791 "Marion", "Mitchell", "Morrison", 792 "Marion", "Mitchell", "Morrison",
792 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", 793 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA",
(...skipping 13 matching lines...) Expand all
806 test::SetCreditCardInfo(&credit_card1, 807 test::SetCreditCardInfo(&credit_card1,
807 "Bonnie Parker", "518765432109" /* Mastercard */, "12", "3999"); 808 "Bonnie Parker", "518765432109" /* Mastercard */, "12", "3999");
808 809
809 // Add two test profiles to the database. 810 // Add two test profiles to the database.
810 personal_data_->AddProfile(profile0); 811 personal_data_->AddProfile(profile0);
811 personal_data_->AddProfile(profile1); 812 personal_data_->AddProfile(profile1);
812 813
813 // Verify that the web database has been updated and the notification sent. 814 // Verify that the web database has been updated and the notification sent.
814 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 815 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
815 .WillOnce(QuitMainMessageLoop()); 816 .WillOnce(QuitMainMessageLoop());
816 base::MessageLoop::current()->Run(); 817 base::RunLoop().Run();
817 818
818 std::vector<AutofillProfile*> profiles; 819 std::vector<AutofillProfile*> profiles;
819 profiles.push_back(&profile0); 820 profiles.push_back(&profile0);
820 profiles.push_back(&profile1); 821 profiles.push_back(&profile1);
821 ExpectSameElements(profiles, personal_data_->GetProfiles()); 822 ExpectSameElements(profiles, personal_data_->GetProfiles());
822 823
823 // Add two test credit cards to the database. 824 // Add two test credit cards to the database.
824 personal_data_->AddCreditCard(credit_card0); 825 personal_data_->AddCreditCard(credit_card0);
825 personal_data_->AddCreditCard(credit_card1); 826 personal_data_->AddCreditCard(credit_card1);
826 827
827 // Verify that the web database has been updated and the notification sent. 828 // Verify that the web database has been updated and the notification sent.
828 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 829 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
829 .WillOnce(QuitMainMessageLoop()); 830 .WillOnce(QuitMainMessageLoop());
830 base::MessageLoop::current()->Run(); 831 base::RunLoop().Run();
831 832
832 std::vector<CreditCard*> cards; 833 std::vector<CreditCard*> cards;
833 cards.push_back(&credit_card0); 834 cards.push_back(&credit_card0);
834 cards.push_back(&credit_card1); 835 cards.push_back(&credit_card1);
835 ExpectSameElements(cards, personal_data_->GetCreditCards()); 836 ExpectSameElements(cards, personal_data_->GetCreditCards());
836 837
837 // Determine uniqueness by inserting all of the GUIDs into a set and verifying 838 // Determine uniqueness by inserting all of the GUIDs into a set and verifying
838 // the size of the set matches the number of GUIDs. 839 // the size of the set matches the number of GUIDs.
839 std::set<std::string> guids; 840 std::set<std::string> guids;
840 guids.insert(profile0.guid()); 841 guids.insert(profile0.guid());
841 guids.insert(profile1.guid()); 842 guids.insert(profile1.guid());
842 guids.insert(credit_card0.guid()); 843 guids.insert(credit_card0.guid());
843 guids.insert(credit_card1.guid()); 844 guids.insert(credit_card1.guid());
844 EXPECT_EQ(4U, guids.size()); 845 EXPECT_EQ(4U, guids.size());
845 } 846 }
846 847
847 // Test for http://crbug.com/50047. Makes sure that guids are populated 848 // Test for http://crbug.com/50047. Makes sure that guids are populated
848 // correctly on load. 849 // correctly on load.
849 TEST_F(PersonalDataManagerTest, PopulateUniqueIDsOnLoad) { 850 TEST_F(PersonalDataManagerTest, PopulateUniqueIDsOnLoad) {
850 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com"); 851 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com");
851 test::SetProfileInfo(&profile0, 852 test::SetProfileInfo(&profile0,
852 "y", "", "", "", "", "", "", "", "", "", "", ""); 853 "y", "", "", "", "", "", "", "", "", "", "", "");
853 854
854 // Add the profile0 to the db. 855 // Add the profile0 to the db.
855 personal_data_->AddProfile(profile0); 856 personal_data_->AddProfile(profile0);
856 857
857 // Verify that the web database has been updated and the notification sent. 858 // Verify that the web database has been updated and the notification sent.
858 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 859 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
859 .WillOnce(QuitMainMessageLoop()); 860 .WillOnce(QuitMainMessageLoop());
860 base::MessageLoop::current()->Run(); 861 base::RunLoop().Run();
861 862
862 // Verify that we've loaded the profiles from the web database. 863 // Verify that we've loaded the profiles from the web database.
863 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); 864 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
864 ASSERT_EQ(1U, results2.size()); 865 ASSERT_EQ(1U, results2.size());
865 EXPECT_EQ(0, profile0.Compare(*results2[0])); 866 EXPECT_EQ(0, profile0.Compare(*results2[0]));
866 867
867 // Add a new profile. 868 // Add a new profile.
868 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); 869 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com");
869 test::SetProfileInfo(&profile1, 870 test::SetProfileInfo(&profile1,
870 "z", "", "", "", "", "", "", "", "", "", "", ""); 871 "z", "", "", "", "", "", "", "", "", "", "", "");
871 personal_data_->AddProfile(profile1); 872 personal_data_->AddProfile(profile1);
872 873
873 // Verify that the web database has been updated and the notification sent. 874 // Verify that the web database has been updated and the notification sent.
874 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 875 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
875 .WillOnce(QuitMainMessageLoop()); 876 .WillOnce(QuitMainMessageLoop());
876 base::MessageLoop::current()->Run(); 877 base::RunLoop().Run();
877 878
878 // Make sure the two profiles have different GUIDs, both valid. 879 // Make sure the two profiles have different GUIDs, both valid.
879 const std::vector<AutofillProfile*>& results3 = personal_data_->GetProfiles(); 880 const std::vector<AutofillProfile*>& results3 = personal_data_->GetProfiles();
880 ASSERT_EQ(2U, results3.size()); 881 ASSERT_EQ(2U, results3.size());
881 EXPECT_NE(results3[0]->guid(), results3[1]->guid()); 882 EXPECT_NE(results3[0]->guid(), results3[1]->guid());
882 EXPECT_TRUE(base::IsValidGUID(results3[0]->guid())); 883 EXPECT_TRUE(base::IsValidGUID(results3[0]->guid()));
883 EXPECT_TRUE(base::IsValidGUID(results3[1]->guid())); 884 EXPECT_TRUE(base::IsValidGUID(results3[1]->guid()));
884 } 885 }
885 886
886 TEST_F(PersonalDataManagerTest, SetUniqueCreditCardLabels) { 887 TEST_F(PersonalDataManagerTest, SetUniqueCreditCardLabels) {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 "joewayne@me.xyz", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801", 973 "joewayne@me.xyz", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801",
973 "US", "19482937549"); 974 "US", "19482937549");
974 975
975 // Add the test profiles to the database. 976 // Add the test profiles to the database.
976 personal_data_->AddProfile(profile0); 977 personal_data_->AddProfile(profile0);
977 personal_data_->AddProfile(profile1); 978 personal_data_->AddProfile(profile1);
978 979
979 // Verify that the web database has been updated and the notification sent. 980 // Verify that the web database has been updated and the notification sent.
980 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 981 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
981 .WillOnce(QuitMainMessageLoop()); 982 .WillOnce(QuitMainMessageLoop());
982 base::MessageLoop::current()->Run(); 983 base::RunLoop().Run();
983 984
984 std::vector<AutofillProfile*> profiles; 985 std::vector<AutofillProfile*> profiles;
985 profiles.push_back(&profile0); 986 profiles.push_back(&profile0);
986 profiles.push_back(&profile1); 987 profiles.push_back(&profile1);
987 ExpectSameElements(profiles, personal_data_->GetProfiles()); 988 ExpectSameElements(profiles, personal_data_->GetProfiles());
988 989
989 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); 990 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com");
990 test::SetProfileInfo(&profile2, 991 test::SetProfileInfo(&profile2,
991 "Josephine", "Alicia", "Saenz", 992 "Josephine", "Alicia", "Saenz",
992 "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", 993 "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL",
993 "32801", "US", "19482937549"); 994 "32801", "US", "19482937549");
994 995
995 autofill_database_service_->AddAutofillProfile(profile2); 996 autofill_database_service_->AddAutofillProfile(profile2);
996 997
997 personal_data_->Refresh(); 998 personal_data_->Refresh();
998 999
999 // Verify that the web database has been updated and the notification sent. 1000 // Verify that the web database has been updated and the notification sent.
1000 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1001 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1001 .WillOnce(QuitMainMessageLoop()); 1002 .WillOnce(QuitMainMessageLoop());
1002 base::MessageLoop::current()->Run(); 1003 base::RunLoop().Run();
1003 1004
1004 profiles.clear(); 1005 profiles.clear();
1005 profiles.push_back(&profile0); 1006 profiles.push_back(&profile0);
1006 profiles.push_back(&profile1); 1007 profiles.push_back(&profile1);
1007 profiles.push_back(&profile2); 1008 profiles.push_back(&profile2);
1008 ExpectSameElements(profiles, personal_data_->GetProfiles()); 1009 ExpectSameElements(profiles, personal_data_->GetProfiles());
1009 1010
1010 autofill_database_service_->RemoveAutofillProfile(profile1.guid()); 1011 autofill_database_service_->RemoveAutofillProfile(profile1.guid());
1011 autofill_database_service_->RemoveAutofillProfile(profile2.guid()); 1012 autofill_database_service_->RemoveAutofillProfile(profile2.guid());
1012 1013
1013 // Before telling the PDM to refresh, simulate an edit to one of the deleted 1014 // Before telling the PDM to refresh, simulate an edit to one of the deleted
1014 // profiles via a SetProfile update (this would happen if the Autofill window 1015 // profiles via a SetProfile update (this would happen if the Autofill window
1015 // was open with a previous snapshot of the profiles, and something 1016 // was open with a previous snapshot of the profiles, and something
1016 // [e.g. sync] removed a profile from the browser. In this edge case, we will 1017 // [e.g. sync] removed a profile from the browser. In this edge case, we will
1017 // end up in a consistent state by dropping the write). 1018 // end up in a consistent state by dropping the write).
1018 profile0.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Mar")); 1019 profile0.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Mar"));
1019 profile2.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Jo")); 1020 profile2.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Jo"));
1020 personal_data_->UpdateProfile(profile0); 1021 personal_data_->UpdateProfile(profile0);
1021 personal_data_->AddProfile(profile1); 1022 personal_data_->AddProfile(profile1);
1022 personal_data_->AddProfile(profile2); 1023 personal_data_->AddProfile(profile2);
1023 1024
1024 // Verify that the web database has been updated and the notification sent. 1025 // Verify that the web database has been updated and the notification sent.
1025 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1026 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1026 .WillOnce(QuitMainMessageLoop()); 1027 .WillOnce(QuitMainMessageLoop());
1027 base::MessageLoop::current()->Run(); 1028 base::RunLoop().Run();
1028 1029
1029 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); 1030 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles();
1030 ASSERT_EQ(1U, results.size()); 1031 ASSERT_EQ(1U, results.size());
1031 EXPECT_EQ(profile0, *results[0]); 1032 EXPECT_EQ(profile0, *results[0]);
1032 } 1033 }
1033 1034
1034 // ImportAddressProfiles tests. 1035 // ImportAddressProfiles tests.
1035 1036
1036 TEST_F(PersonalDataManagerTest, ImportAddressProfiles) { 1037 TEST_F(PersonalDataManagerTest, ImportAddressProfiles) {
1037 FormData form; 1038 FormData form;
(...skipping 16 matching lines...) Expand all
1054 form.fields.push_back(field); 1055 form.fields.push_back(field);
1055 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); 1056 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field);
1056 form.fields.push_back(field); 1057 form.fields.push_back(field);
1057 FormStructure form_structure(form); 1058 FormStructure form_structure(form);
1058 form_structure.DetermineHeuristicTypes(); 1059 form_structure.DetermineHeuristicTypes();
1059 EXPECT_TRUE(ImportAddressProfiles(form_structure)); 1060 EXPECT_TRUE(ImportAddressProfiles(form_structure));
1060 1061
1061 // Verify that the web database has been updated and the notification sent. 1062 // Verify that the web database has been updated and the notification sent.
1062 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1063 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1063 .WillOnce(QuitMainMessageLoop()); 1064 .WillOnce(QuitMainMessageLoop());
1064 base::MessageLoop::current()->Run(); 1065 base::RunLoop().Run();
1065 1066
1066 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); 1067 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com");
1067 test::SetProfileInfo(&expected, "George", NULL, 1068 test::SetProfileInfo(&expected, "George", NULL,
1068 "Washington", "theprez@gmail.com", NULL, "21 Laussat St", NULL, 1069 "Washington", "theprez@gmail.com", NULL, "21 Laussat St", NULL,
1069 "San Francisco", "California", "94102", NULL, NULL); 1070 "San Francisco", "California", "94102", NULL, NULL);
1070 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); 1071 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles();
1071 ASSERT_EQ(1U, results.size()); 1072 ASSERT_EQ(1U, results.size());
1072 EXPECT_EQ(0, expected.Compare(*results[0])); 1073 EXPECT_EQ(0, expected.Compare(*results[0]));
1073 } 1074 }
1074 1075
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1282 form.fields.push_back(field); 1283 form.fields.push_back(field);
1283 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); 1284 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field);
1284 form.fields.push_back(field); 1285 form.fields.push_back(field);
1285 FormStructure form_structure(form); 1286 FormStructure form_structure(form);
1286 form_structure.DetermineHeuristicTypes(); 1287 form_structure.DetermineHeuristicTypes();
1287 EXPECT_TRUE(ImportAddressProfiles(form_structure)); 1288 EXPECT_TRUE(ImportAddressProfiles(form_structure));
1288 1289
1289 // Verify that the web database has been updated and the notification sent. 1290 // Verify that the web database has been updated and the notification sent.
1290 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1291 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1291 .WillOnce(QuitMainMessageLoop()); 1292 .WillOnce(QuitMainMessageLoop());
1292 base::MessageLoop::current()->Run(); 1293 base::RunLoop().Run();
1293 1294
1294 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); 1295 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com");
1295 test::SetProfileInfo(&expected, "George", NULL, 1296 test::SetProfileInfo(&expected, "George", NULL,
1296 "Washington", NULL, NULL, "21 Laussat St", NULL, 1297 "Washington", NULL, NULL, "21 Laussat St", NULL,
1297 "San Francisco", "California", "94102", NULL, "(650) 555-0000"); 1298 "San Francisco", "California", "94102", NULL, "(650) 555-0000");
1298 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); 1299 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles();
1299 ASSERT_EQ(1U, results.size()); 1300 ASSERT_EQ(1U, results.size());
1300 EXPECT_EQ(0, expected.Compare(*results[0])); 1301 EXPECT_EQ(0, expected.Compare(*results[0]));
1301 } 1302 }
1302 1303
(...skipping 23 matching lines...) Expand all
1326 form.fields.push_back(field); 1327 form.fields.push_back(field);
1327 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); 1328 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field);
1328 form.fields.push_back(field); 1329 form.fields.push_back(field);
1329 FormStructure form_structure(form); 1330 FormStructure form_structure(form);
1330 form_structure.DetermineHeuristicTypes(); 1331 form_structure.DetermineHeuristicTypes();
1331 EXPECT_TRUE(ImportAddressProfiles(form_structure)); 1332 EXPECT_TRUE(ImportAddressProfiles(form_structure));
1332 1333
1333 // Verify that the web database has been updated and the notification sent. 1334 // Verify that the web database has been updated and the notification sent.
1334 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1335 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1335 .WillOnce(QuitMainMessageLoop()); 1336 .WillOnce(QuitMainMessageLoop());
1336 base::MessageLoop::current()->Run(); 1337 base::RunLoop().Run();
1337 1338
1338 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); 1339 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com");
1339 test::SetProfileInfo(&expected, "George", NULL, 1340 test::SetProfileInfo(&expected, "George", NULL,
1340 "Washington", "theprez@gmail.com", NULL, "21 Laussat St", "Apt. #42", 1341 "Washington", "theprez@gmail.com", NULL, "21 Laussat St", "Apt. #42",
1341 "San Francisco", "California", "94102", NULL, NULL); 1342 "San Francisco", "California", "94102", NULL, NULL);
1342 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); 1343 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles();
1343 ASSERT_EQ(1U, results.size()); 1344 ASSERT_EQ(1U, results.size());
1344 EXPECT_EQ(0, expected.Compare(*results[0])); 1345 EXPECT_EQ(0, expected.Compare(*results[0]));
1345 } 1346 }
1346 1347
(...skipping 20 matching lines...) Expand all
1367 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); 1368 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field);
1368 form1.fields.push_back(field); 1369 form1.fields.push_back(field);
1369 1370
1370 FormStructure form_structure1(form1); 1371 FormStructure form_structure1(form1);
1371 form_structure1.DetermineHeuristicTypes(); 1372 form_structure1.DetermineHeuristicTypes();
1372 EXPECT_TRUE(ImportAddressProfiles(form_structure1)); 1373 EXPECT_TRUE(ImportAddressProfiles(form_structure1));
1373 1374
1374 // Verify that the web database has been updated and the notification sent. 1375 // Verify that the web database has been updated and the notification sent.
1375 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1376 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1376 .WillOnce(QuitMainMessageLoop()); 1377 .WillOnce(QuitMainMessageLoop());
1377 base::MessageLoop::current()->Run(); 1378 base::RunLoop().Run();
1378 1379
1379 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); 1380 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com");
1380 test::SetProfileInfo(&expected, "George", NULL, 1381 test::SetProfileInfo(&expected, "George", NULL,
1381 "Washington", "theprez@gmail.com", NULL, "21 Laussat St", NULL, 1382 "Washington", "theprez@gmail.com", NULL, "21 Laussat St", NULL,
1382 "San Francisco", "California", "94102", NULL, NULL); 1383 "San Francisco", "California", "94102", NULL, NULL);
1383 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); 1384 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles();
1384 ASSERT_EQ(1U, results1.size()); 1385 ASSERT_EQ(1U, results1.size());
1385 EXPECT_EQ(0, expected.Compare(*results1[0])); 1386 EXPECT_EQ(0, expected.Compare(*results1[0]));
1386 1387
1387 // Now create a completely different profile. 1388 // Now create a completely different profile.
(...skipping 17 matching lines...) Expand all
1405 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); 1406 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field);
1406 form2.fields.push_back(field); 1407 form2.fields.push_back(field);
1407 1408
1408 FormStructure form_structure2(form2); 1409 FormStructure form_structure2(form2);
1409 form_structure2.DetermineHeuristicTypes(); 1410 form_structure2.DetermineHeuristicTypes();
1410 EXPECT_TRUE(ImportAddressProfiles(form_structure2)); 1411 EXPECT_TRUE(ImportAddressProfiles(form_structure2));
1411 1412
1412 // Verify that the web database has been updated and the notification sent. 1413 // Verify that the web database has been updated and the notification sent.
1413 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1414 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1414 .WillOnce(QuitMainMessageLoop()); 1415 .WillOnce(QuitMainMessageLoop());
1415 base::MessageLoop::current()->Run(); 1416 base::RunLoop().Run();
1416 1417
1417 AutofillProfile expected2(base::GenerateGUID(), "https://www.example.com"); 1418 AutofillProfile expected2(base::GenerateGUID(), "https://www.example.com");
1418 test::SetProfileInfo(&expected2, "John", NULL, 1419 test::SetProfileInfo(&expected2, "John", NULL,
1419 "Adams", "second@gmail.com", NULL, "22 Laussat St", NULL, 1420 "Adams", "second@gmail.com", NULL, "22 Laussat St", NULL,
1420 "San Francisco", "California", "94102", NULL, NULL); 1421 "San Francisco", "California", "94102", NULL, NULL);
1421 std::vector<AutofillProfile*> profiles; 1422 std::vector<AutofillProfile*> profiles;
1422 profiles.push_back(&expected); 1423 profiles.push_back(&expected);
1423 profiles.push_back(&expected2); 1424 profiles.push_back(&expected2);
1424 ExpectSameElements(profiles, personal_data_->GetProfiles()); 1425 ExpectSameElements(profiles, personal_data_->GetProfiles());
1425 } 1426 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1466 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); 1467 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field);
1467 form.fields.push_back(field); 1468 form.fields.push_back(field);
1468 1469
1469 FormStructure form_structure(form); 1470 FormStructure form_structure(form);
1470 form_structure.DetermineHeuristicTypes(); 1471 form_structure.DetermineHeuristicTypes();
1471 EXPECT_TRUE(ImportAddressProfiles(form_structure)); 1472 EXPECT_TRUE(ImportAddressProfiles(form_structure));
1472 1473
1473 // Verify that the web database has been updated and the notification sent. 1474 // Verify that the web database has been updated and the notification sent.
1474 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1475 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1475 .WillOnce(QuitMainMessageLoop()); 1476 .WillOnce(QuitMainMessageLoop());
1476 base::MessageLoop::current()->Run(); 1477 base::RunLoop().Run();
1477 1478
1478 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); 1479 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com");
1479 test::SetProfileInfo(&expected, "George", NULL, "Washington", 1480 test::SetProfileInfo(&expected, "George", NULL, "Washington",
1480 "theprez@gmail.com", NULL, "21 Laussat St", NULL, 1481 "theprez@gmail.com", NULL, "21 Laussat St", NULL,
1481 "San Francisco", "California", "94102", NULL, NULL); 1482 "San Francisco", "California", "94102", NULL, NULL);
1482 AutofillProfile expected2(base::GenerateGUID(), "https://www.example.com"); 1483 AutofillProfile expected2(base::GenerateGUID(), "https://www.example.com");
1483 test::SetProfileInfo(&expected2, "John", NULL, "Adams", "second@gmail.com", 1484 test::SetProfileInfo(&expected2, "John", NULL, "Adams", "second@gmail.com",
1484 NULL, "22 Laussat St", NULL, "San Francisco", 1485 NULL, "22 Laussat St", NULL, "San Francisco",
1485 "California", "94102", NULL, NULL); 1486 "California", "94102", NULL, NULL);
1486 1487
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1544 form.fields.push_back(field); 1545 form.fields.push_back(field);
1545 1546
1546 // Still able to do the import. 1547 // Still able to do the import.
1547 FormStructure form_structure(form); 1548 FormStructure form_structure(form);
1548 form_structure.DetermineHeuristicTypes(); 1549 form_structure.DetermineHeuristicTypes();
1549 EXPECT_TRUE(ImportAddressProfiles(form_structure)); 1550 EXPECT_TRUE(ImportAddressProfiles(form_structure));
1550 1551
1551 // Verify that the web database has been updated and the notification sent. 1552 // Verify that the web database has been updated and the notification sent.
1552 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1553 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1553 .WillOnce(QuitMainMessageLoop()); 1554 .WillOnce(QuitMainMessageLoop());
1554 base::MessageLoop::current()->Run(); 1555 base::RunLoop().Run();
1555 1556
1556 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); 1557 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com");
1557 test::SetProfileInfo(&expected, "George", NULL, "Washington", 1558 test::SetProfileInfo(&expected, "George", NULL, "Washington",
1558 "theprez@gmail.com", NULL, "21 Laussat St", NULL, 1559 "theprez@gmail.com", NULL, "21 Laussat St", NULL,
1559 "San Francisco", "California", "94102", NULL, NULL); 1560 "San Francisco", "California", "94102", NULL, NULL);
1560 1561
1561 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); 1562 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles();
1562 ASSERT_EQ(1U, results.size()); 1563 ASSERT_EQ(1U, results.size());
1563 1564
1564 std::vector<AutofillProfile*> profiles; 1565 std::vector<AutofillProfile*> profiles;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1628 &field); 1629 &field);
1629 form.fields.push_back(field); 1630 form.fields.push_back(field);
1630 1631
1631 FormStructure form_structure(form); 1632 FormStructure form_structure(form);
1632 form_structure.DetermineHeuristicTypes(); 1633 form_structure.DetermineHeuristicTypes();
1633 EXPECT_TRUE(ImportAddressProfiles(form_structure)); 1634 EXPECT_TRUE(ImportAddressProfiles(form_structure));
1634 1635
1635 // Verify that the web database has been updated and the notification sent. 1636 // Verify that the web database has been updated and the notification sent.
1636 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1637 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1637 .WillOnce(QuitMainMessageLoop()); 1638 .WillOnce(QuitMainMessageLoop());
1638 base::MessageLoop::current()->Run(); 1639 base::RunLoop().Run();
1639 1640
1640 // Only two are saved. 1641 // Only two are saved.
1641 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); 1642 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com");
1642 test::SetProfileInfo(&expected, "George", NULL, "Washington", 1643 test::SetProfileInfo(&expected, "George", NULL, "Washington",
1643 "theprez@gmail.com", NULL, "21 Laussat St", NULL, 1644 "theprez@gmail.com", NULL, "21 Laussat St", NULL,
1644 "San Francisco", "California", "94102", NULL, NULL); 1645 "San Francisco", "California", "94102", NULL, NULL);
1645 AutofillProfile expected2(base::GenerateGUID(), "https://www.example.com"); 1646 AutofillProfile expected2(base::GenerateGUID(), "https://www.example.com");
1646 test::SetProfileInfo(&expected2, "John", NULL, "Adams", "second@gmail.com", 1647 test::SetProfileInfo(&expected2, "John", NULL, "Adams", "second@gmail.com",
1647 NULL, "22 Laussat St", NULL, "San Francisco", 1648 NULL, "22 Laussat St", NULL, "San Francisco",
1648 "California", "94102", NULL, NULL); 1649 "California", "94102", NULL, NULL);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1683 test::CreateTestFormField("Phone:", "phone", "6505556666", "text", &field); 1684 test::CreateTestFormField("Phone:", "phone", "6505556666", "text", &field);
1684 form1.fields.push_back(field); 1685 form1.fields.push_back(field);
1685 1686
1686 FormStructure form_structure1(form1); 1687 FormStructure form_structure1(form1);
1687 form_structure1.DetermineHeuristicTypes(); 1688 form_structure1.DetermineHeuristicTypes();
1688 EXPECT_TRUE(ImportAddressProfiles(form_structure1)); 1689 EXPECT_TRUE(ImportAddressProfiles(form_structure1));
1689 1690
1690 // Verify that the web database has been updated and the notification sent. 1691 // Verify that the web database has been updated and the notification sent.
1691 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1692 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1692 .WillOnce(QuitMainMessageLoop()); 1693 .WillOnce(QuitMainMessageLoop());
1693 base::MessageLoop::current()->Run(); 1694 base::RunLoop().Run();
1694 1695
1695 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); 1696 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com");
1696 test::SetProfileInfo(&expected, "George", nullptr, "Washington", 1697 test::SetProfileInfo(&expected, "George", nullptr, "Washington",
1697 "theprez@gmail.com", nullptr, "1600 Pennsylvania Avenue", 1698 "theprez@gmail.com", nullptr, "1600 Pennsylvania Avenue",
1698 "Suite A", "San Francisco", "California", "94102", 1699 "Suite A", "San Francisco", "California", "94102",
1699 nullptr, "(650) 555-6666"); 1700 nullptr, "(650) 555-6666");
1700 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); 1701 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles();
1701 ASSERT_EQ(1U, results1.size()); 1702 ASSERT_EQ(1U, results1.size());
1702 EXPECT_EQ(0, expected.Compare(*results1[0])); 1703 EXPECT_EQ(0, expected.Compare(*results1[0]));
1703 1704
(...skipping 27 matching lines...) Expand all
1731 test::CreateTestFormField("Phone:", "phone", "650-555-6666", "text", &field); 1732 test::CreateTestFormField("Phone:", "phone", "650-555-6666", "text", &field);
1732 form2.fields.push_back(field); 1733 form2.fields.push_back(field);
1733 1734
1734 FormStructure form_structure2(form2); 1735 FormStructure form_structure2(form2);
1735 form_structure2.DetermineHeuristicTypes(); 1736 form_structure2.DetermineHeuristicTypes();
1736 EXPECT_TRUE(ImportAddressProfiles(form_structure2)); 1737 EXPECT_TRUE(ImportAddressProfiles(form_structure2));
1737 1738
1738 // Verify that the web database has been updated and the notification sent. 1739 // Verify that the web database has been updated and the notification sent.
1739 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1740 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1740 .WillOnce(QuitMainMessageLoop()); 1741 .WillOnce(QuitMainMessageLoop());
1741 base::MessageLoop::current()->Run(); 1742 base::RunLoop().Run();
1742 1743
1743 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); 1744 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
1744 1745
1745 // Phone formatting is updated. Also, country gets added. 1746 // Phone formatting is updated. Also, country gets added.
1746 expected.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("650-555-6666")); 1747 expected.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("650-555-6666"));
1747 expected.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); 1748 expected.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US"));
1748 ASSERT_EQ(1U, results2.size()); 1749 ASSERT_EQ(1U, results2.size());
1749 EXPECT_EQ(0, expected.Compare(*results2[0])); 1750 EXPECT_EQ(0, expected.Compare(*results2[0]));
1750 } 1751 }
1751 1752
(...skipping 16 matching lines...) Expand all
1768 test::CreateTestFormField("Zip:", "zipcode", "19106", "text", &field); 1769 test::CreateTestFormField("Zip:", "zipcode", "19106", "text", &field);
1769 form1.fields.push_back(field); 1770 form1.fields.push_back(field);
1770 1771
1771 FormStructure form_structure1(form1); 1772 FormStructure form_structure1(form1);
1772 form_structure1.DetermineHeuristicTypes(); 1773 form_structure1.DetermineHeuristicTypes();
1773 EXPECT_TRUE(ImportAddressProfiles(form_structure1)); 1774 EXPECT_TRUE(ImportAddressProfiles(form_structure1));
1774 1775
1775 // Verify that the web database has been updated and the notification sent. 1776 // Verify that the web database has been updated and the notification sent.
1776 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1777 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1777 .WillOnce(QuitMainMessageLoop()); 1778 .WillOnce(QuitMainMessageLoop());
1778 base::MessageLoop::current()->Run(); 1779 base::RunLoop().Run();
1779 1780
1780 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); 1781 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com");
1781 test::SetProfileInfo(&expected, "George", NULL, 1782 test::SetProfileInfo(&expected, "George", NULL,
1782 "Washington", NULL, NULL, "190 High Street", NULL, 1783 "Washington", NULL, NULL, "190 High Street", NULL,
1783 "Philadelphia", "Pennsylvania", "19106", NULL, NULL); 1784 "Philadelphia", "Pennsylvania", "19106", NULL, NULL);
1784 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); 1785 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles();
1785 ASSERT_EQ(1U, results1.size()); 1786 ASSERT_EQ(1U, results1.size());
1786 EXPECT_EQ(0, expected.Compare(*results1[0])); 1787 EXPECT_EQ(0, expected.Compare(*results1[0]));
1787 1788
1788 // Submit a form with new data for the first profile. 1789 // Submit a form with new data for the first profile.
(...skipping 17 matching lines...) Expand all
1806 test::CreateTestFormField("Zip:", "zipcode", "19106", "text", &field); 1807 test::CreateTestFormField("Zip:", "zipcode", "19106", "text", &field);
1807 form2.fields.push_back(field); 1808 form2.fields.push_back(field);
1808 1809
1809 FormStructure form_structure2(form2); 1810 FormStructure form_structure2(form2);
1810 form_structure2.DetermineHeuristicTypes(); 1811 form_structure2.DetermineHeuristicTypes();
1811 EXPECT_TRUE(ImportAddressProfiles(form_structure2)); 1812 EXPECT_TRUE(ImportAddressProfiles(form_structure2));
1812 1813
1813 // Verify that the web database has been updated and the notification sent. 1814 // Verify that the web database has been updated and the notification sent.
1814 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1815 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1815 .WillOnce(QuitMainMessageLoop()); 1816 .WillOnce(QuitMainMessageLoop());
1816 base::MessageLoop::current()->Run(); 1817 base::RunLoop().Run();
1817 1818
1818 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); 1819 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
1819 1820
1820 AutofillProfile expected2(base::GenerateGUID(), "https://www.example.com"); 1821 AutofillProfile expected2(base::GenerateGUID(), "https://www.example.com");
1821 test::SetProfileInfo(&expected2, "George", NULL, 1822 test::SetProfileInfo(&expected2, "George", NULL,
1822 "Washington", "theprez@gmail.com", NULL, "190 High Street", NULL, 1823 "Washington", "theprez@gmail.com", NULL, "190 High Street", NULL,
1823 "Philadelphia", "Pennsylvania", "19106", NULL, NULL); 1824 "Philadelphia", "Pennsylvania", "19106", NULL, NULL);
1824 ASSERT_EQ(1U, results2.size()); 1825 ASSERT_EQ(1U, results2.size());
1825 EXPECT_EQ(0, expected2.Compare(*results2[0])); 1826 EXPECT_EQ(0, expected2.Compare(*results2[0]));
1826 } 1827 }
(...skipping 23 matching lines...) Expand all
1850 test::CreateTestFormField("Zip:", "zipcode", "19106", "text", &field); 1851 test::CreateTestFormField("Zip:", "zipcode", "19106", "text", &field);
1851 form1.fields.push_back(field); 1852 form1.fields.push_back(field);
1852 1853
1853 FormStructure form_structure1(form1); 1854 FormStructure form_structure1(form1);
1854 form_structure1.DetermineHeuristicTypes(); 1855 form_structure1.DetermineHeuristicTypes();
1855 EXPECT_TRUE(ImportAddressProfiles(form_structure1)); 1856 EXPECT_TRUE(ImportAddressProfiles(form_structure1));
1856 1857
1857 // Verify that the web database has been updated and the notification sent. 1858 // Verify that the web database has been updated and the notification sent.
1858 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1859 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1859 .WillOnce(QuitMainMessageLoop()); 1860 .WillOnce(QuitMainMessageLoop());
1860 base::MessageLoop::current()->Run(); 1861 base::RunLoop().Run();
1861 1862
1862 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com"); 1863 AutofillProfile expected(base::GenerateGUID(), "https://www.example.com");
1863 test::SetProfileInfo(&expected, "George", NULL, 1864 test::SetProfileInfo(&expected, "George", NULL,
1864 "Washington", "theprez@gmail.com", "Government", "190 High Street", NULL, 1865 "Washington", "theprez@gmail.com", "Government", "190 High Street", NULL,
1865 "Philadelphia", "Pennsylvania", "19106", NULL, NULL); 1866 "Philadelphia", "Pennsylvania", "19106", NULL, NULL);
1866 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); 1867 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles();
1867 ASSERT_EQ(1U, results1.size()); 1868 ASSERT_EQ(1U, results1.size());
1868 EXPECT_EQ(0, expected.Compare(*results1[0])); 1869 EXPECT_EQ(0, expected.Compare(*results1[0]));
1869 1870
1870 // Submit a form with new data for the first profile. 1871 // Submit a form with new data for the first profile.
(...skipping 18 matching lines...) Expand all
1889 test::CreateTestFormField("Zip:", "zipcode", "19106", "text", &field); 1890 test::CreateTestFormField("Zip:", "zipcode", "19106", "text", &field);
1890 form2.fields.push_back(field); 1891 form2.fields.push_back(field);
1891 1892
1892 FormStructure form_structure2(form2); 1893 FormStructure form_structure2(form2);
1893 form_structure2.DetermineHeuristicTypes(); 1894 form_structure2.DetermineHeuristicTypes();
1894 EXPECT_TRUE(ImportAddressProfiles(form_structure2)); 1895 EXPECT_TRUE(ImportAddressProfiles(form_structure2));
1895 1896
1896 // Verify that the web database has been updated and the notification sent. 1897 // Verify that the web database has been updated and the notification sent.
1897 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1898 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1898 .WillOnce(QuitMainMessageLoop()); 1899 .WillOnce(QuitMainMessageLoop());
1899 base::MessageLoop::current()->Run(); 1900 base::RunLoop().Run();
1900 1901
1901 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); 1902 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
1902 1903
1903 // Expect no change. 1904 // Expect no change.
1904 ASSERT_EQ(1U, results2.size()); 1905 ASSERT_EQ(1U, results2.size());
1905 EXPECT_EQ(0, expected.Compare(*results2[0])); 1906 EXPECT_EQ(0, expected.Compare(*results2[0]));
1906 } 1907 }
1907 1908
1908 TEST_F(PersonalDataManagerTest, ImportAddressProfiles_InsufficientAddress) { 1909 TEST_F(PersonalDataManagerTest, ImportAddressProfiles_InsufficientAddress) {
1909 FormData form1; 1910 FormData form1;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1952 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", 1953 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5",
1953 "Hollywood", "CA", "91601", "US", "12345678910"); 1954 "Hollywood", "CA", "91601", "US", "12345678910");
1954 EXPECT_TRUE(profile.IsVerified()); 1955 EXPECT_TRUE(profile.IsVerified());
1955 1956
1956 // Add the profile to the database. 1957 // Add the profile to the database.
1957 personal_data_->AddProfile(profile); 1958 personal_data_->AddProfile(profile);
1958 1959
1959 // Verify that the web database has been updated and the notification sent. 1960 // Verify that the web database has been updated and the notification sent.
1960 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1961 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1961 .WillOnce(QuitMainMessageLoop()); 1962 .WillOnce(QuitMainMessageLoop());
1962 base::MessageLoop::current()->Run(); 1963 base::RunLoop().Run();
1963 1964
1964 // Simulate a form submission with conflicting info. 1965 // Simulate a form submission with conflicting info.
1965 FormData form; 1966 FormData form;
1966 FormFieldData field; 1967 FormFieldData field;
1967 test::CreateTestFormField("First name:", "first_name", "Marion Mitchell", 1968 test::CreateTestFormField("First name:", "first_name", "Marion Mitchell",
1968 "text", &field); 1969 "text", &field);
1969 form.fields.push_back(field); 1970 form.fields.push_back(field);
1970 test::CreateTestFormField("Last name:", "last_name", "Morrison", "text", 1971 test::CreateTestFormField("Last name:", "last_name", "Morrison", "text",
1971 &field); 1972 &field);
1972 form.fields.push_back(field); 1973 form.fields.push_back(field);
(...skipping 10 matching lines...) Expand all
1983 test::CreateTestFormField("Zip:", "zip", "91601", "text", &field); 1984 test::CreateTestFormField("Zip:", "zip", "91601", "text", &field);
1984 form.fields.push_back(field); 1985 form.fields.push_back(field);
1985 1986
1986 FormStructure form_structure(form); 1987 FormStructure form_structure(form);
1987 form_structure.DetermineHeuristicTypes(); 1988 form_structure.DetermineHeuristicTypes();
1988 EXPECT_TRUE(ImportAddressProfiles(form_structure)); 1989 EXPECT_TRUE(ImportAddressProfiles(form_structure));
1989 1990
1990 // Wait for the refresh, which in this case is a no-op. 1991 // Wait for the refresh, which in this case is a no-op.
1991 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1992 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1992 .WillOnce(QuitMainMessageLoop()); 1993 .WillOnce(QuitMainMessageLoop());
1993 base::MessageLoop::current()->Run(); 1994 base::RunLoop().Run();
1994 1995
1995 // Expect that no new profile is saved. 1996 // Expect that no new profile is saved.
1996 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); 1997 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles();
1997 ASSERT_EQ(1U, results.size()); 1998 ASSERT_EQ(1U, results.size());
1998 EXPECT_EQ(0, profile.Compare(*results[0])); 1999 EXPECT_EQ(0, profile.Compare(*results[0]));
1999 2000
2000 // Try the same thing, but without "Mitchell". The profiles should still match 2001 // Try the same thing, but without "Mitchell". The profiles should still match
2001 // because the non empty name pieces (first and last) match that stored in the 2002 // because the non empty name pieces (first and last) match that stored in the
2002 // profile. 2003 // profile.
2003 test::CreateTestFormField("First name:", "first_name", "Marion", "text", 2004 test::CreateTestFormField("First name:", "first_name", "Marion", "text",
2004 &field); 2005 &field);
2005 form.fields[0] = field; 2006 form.fields[0] = field;
2006 2007
2007 FormStructure form_structure2(form); 2008 FormStructure form_structure2(form);
2008 form_structure2.DetermineHeuristicTypes(); 2009 form_structure2.DetermineHeuristicTypes();
2009 EXPECT_TRUE(ImportAddressProfiles(form_structure2)); 2010 EXPECT_TRUE(ImportAddressProfiles(form_structure2));
2010 2011
2011 // Wait for the refresh, which in this case is a no-op. 2012 // Wait for the refresh, which in this case is a no-op.
2012 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2013 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2013 .WillOnce(QuitMainMessageLoop()); 2014 .WillOnce(QuitMainMessageLoop());
2014 base::MessageLoop::current()->Run(); 2015 base::RunLoop().Run();
2015 2016
2016 // Expect that no new profile is saved. 2017 // Expect that no new profile is saved.
2017 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); 2018 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
2018 ASSERT_EQ(1U, results2.size()); 2019 ASSERT_EQ(1U, results2.size());
2019 EXPECT_EQ(0, profile.Compare(*results2[0])); 2020 EXPECT_EQ(0, profile.Compare(*results2[0]));
2020 } 2021 }
2021 2022
2022 // ImportCreditCard tests. 2023 // ImportCreditCard tests.
2023 2024
2024 // Tests that a valid credit card is extracted. 2025 // Tests that a valid credit card is extracted.
2025 TEST_F(PersonalDataManagerTest, ImportCreditCard_Valid) { 2026 TEST_F(PersonalDataManagerTest, ImportCreditCard_Valid) {
2026 // Add a single valid credit card form. 2027 // Add a single valid credit card form.
2027 FormData form; 2028 FormData form;
2028 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01", 2029 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01",
2029 "2999"); 2030 "2999");
2030 2031
2031 FormStructure form_structure(form); 2032 FormStructure form_structure(form);
2032 form_structure.DetermineHeuristicTypes(); 2033 form_structure.DetermineHeuristicTypes();
2033 std::unique_ptr<CreditCard> imported_credit_card; 2034 std::unique_ptr<CreditCard> imported_credit_card;
2034 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); 2035 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card));
2035 ASSERT_TRUE(imported_credit_card); 2036 ASSERT_TRUE(imported_credit_card);
2036 personal_data_->SaveImportedCreditCard(*imported_credit_card); 2037 personal_data_->SaveImportedCreditCard(*imported_credit_card);
2037 2038
2038 // Verify that the web database has been updated and the notification sent. 2039 // Verify that the web database has been updated and the notification sent.
2039 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2040 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2040 .WillOnce(QuitMainMessageLoop()); 2041 .WillOnce(QuitMainMessageLoop());
2041 base::MessageLoop::current()->Run(); 2042 base::RunLoop().Run();
2042 2043
2043 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); 2044 CreditCard expected(base::GenerateGUID(), "https://www.example.com");
2044 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", 2045 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01",
2045 "2999"); 2046 "2999");
2046 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); 2047 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards();
2047 ASSERT_EQ(1U, results.size()); 2048 ASSERT_EQ(1U, results.size());
2048 EXPECT_EQ(0, expected.Compare(*results[0])); 2049 EXPECT_EQ(0, expected.Compare(*results[0]));
2049 } 2050 }
2050 2051
2051 // Tests that an invalid credit card is not extracted. 2052 // Tests that an invalid credit card is not extracted.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
2091 FormStructure form_structure(form); 2092 FormStructure form_structure(form);
2092 form_structure.DetermineHeuristicTypes(); 2093 form_structure.DetermineHeuristicTypes();
2093 std::unique_ptr<CreditCard> imported_credit_card; 2094 std::unique_ptr<CreditCard> imported_credit_card;
2094 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); 2095 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card));
2095 ASSERT_TRUE(imported_credit_card); 2096 ASSERT_TRUE(imported_credit_card);
2096 personal_data_->SaveImportedCreditCard(*imported_credit_card); 2097 personal_data_->SaveImportedCreditCard(*imported_credit_card);
2097 2098
2098 // Verify that the web database has been updated and the notification sent. 2099 // Verify that the web database has been updated and the notification sent.
2099 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2100 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2100 .WillOnce(QuitMainMessageLoop()); 2101 .WillOnce(QuitMainMessageLoop());
2101 base::MessageLoop::current()->Run(); 2102 base::RunLoop().Run();
2102 2103
2103 // See that the invalid option text was converted to the right value. 2104 // See that the invalid option text was converted to the right value.
2104 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); 2105 CreditCard expected(base::GenerateGUID(), "https://www.example.com");
2105 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "02", 2106 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "02",
2106 "2999"); 2107 "2999");
2107 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); 2108 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards();
2108 ASSERT_EQ(1U, results.size()); 2109 ASSERT_EQ(1U, results.size());
2109 EXPECT_EQ(0, expected.Compare(*results[0])); 2110 EXPECT_EQ(0, expected.Compare(*results[0]));
2110 } 2111 }
2111 2112
2112 TEST_F(PersonalDataManagerTest, ImportCreditCard_TwoValidCards) { 2113 TEST_F(PersonalDataManagerTest, ImportCreditCard_TwoValidCards) {
2113 // Start with a single valid credit card form. 2114 // Start with a single valid credit card form.
2114 FormData form1; 2115 FormData form1;
2115 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", 2116 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01",
2116 "2999"); 2117 "2999");
2117 2118
2118 FormStructure form_structure1(form1); 2119 FormStructure form_structure1(form1);
2119 form_structure1.DetermineHeuristicTypes(); 2120 form_structure1.DetermineHeuristicTypes();
2120 std::unique_ptr<CreditCard> imported_credit_card; 2121 std::unique_ptr<CreditCard> imported_credit_card;
2121 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); 2122 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card));
2122 ASSERT_TRUE(imported_credit_card); 2123 ASSERT_TRUE(imported_credit_card);
2123 personal_data_->SaveImportedCreditCard(*imported_credit_card); 2124 personal_data_->SaveImportedCreditCard(*imported_credit_card);
2124 2125
2125 // Verify that the web database has been updated and the notification sent. 2126 // Verify that the web database has been updated and the notification sent.
2126 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2127 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2127 .WillOnce(QuitMainMessageLoop()); 2128 .WillOnce(QuitMainMessageLoop());
2128 base::MessageLoop::current()->Run(); 2129 base::RunLoop().Run();
2129 2130
2130 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); 2131 CreditCard expected(base::GenerateGUID(), "https://www.example.com");
2131 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01", 2132 test::SetCreditCardInfo(&expected, "Biggie Smalls", "4111111111111111", "01",
2132 "2999"); 2133 "2999");
2133 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); 2134 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards();
2134 ASSERT_EQ(1U, results.size()); 2135 ASSERT_EQ(1U, results.size());
2135 EXPECT_EQ(0, expected.Compare(*results[0])); 2136 EXPECT_EQ(0, expected.Compare(*results[0]));
2136 2137
2137 // Add a second different valid credit card. 2138 // Add a second different valid credit card.
2138 FormData form2; 2139 FormData form2;
2139 AddFullCreditCardForm(&form2, "", "5500 0000 0000 0004", "02", "3999"); 2140 AddFullCreditCardForm(&form2, "", "5500 0000 0000 0004", "02", "3999");
2140 2141
2141 FormStructure form_structure2(form2); 2142 FormStructure form_structure2(form2);
2142 form_structure2.DetermineHeuristicTypes(); 2143 form_structure2.DetermineHeuristicTypes();
2143 std::unique_ptr<CreditCard> imported_credit_card2; 2144 std::unique_ptr<CreditCard> imported_credit_card2;
2144 EXPECT_TRUE(ImportCreditCard(form_structure2, false, &imported_credit_card2)); 2145 EXPECT_TRUE(ImportCreditCard(form_structure2, false, &imported_credit_card2));
2145 ASSERT_TRUE(imported_credit_card2); 2146 ASSERT_TRUE(imported_credit_card2);
2146 personal_data_->SaveImportedCreditCard(*imported_credit_card2); 2147 personal_data_->SaveImportedCreditCard(*imported_credit_card2);
2147 2148
2148 // Verify that the web database has been updated and the notification sent. 2149 // Verify that the web database has been updated and the notification sent.
2149 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2150 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2150 .WillOnce(QuitMainMessageLoop()); 2151 .WillOnce(QuitMainMessageLoop());
2151 base::MessageLoop::current()->Run(); 2152 base::RunLoop().Run();
2152 2153
2153 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); 2154 CreditCard expected2(base::GenerateGUID(), "https://www.example.com");
2154 test::SetCreditCardInfo(&expected2, "", "5500000000000004", "02", "3999"); 2155 test::SetCreditCardInfo(&expected2, "", "5500000000000004", "02", "3999");
2155 std::vector<CreditCard*> cards; 2156 std::vector<CreditCard*> cards;
2156 cards.push_back(&expected); 2157 cards.push_back(&expected);
2157 cards.push_back(&expected2); 2158 cards.push_back(&expected2);
2158 ExpectSameElements(cards, personal_data_->GetCreditCards()); 2159 ExpectSameElements(cards, personal_data_->GetCreditCards());
2159 } 2160 }
2160 2161
2161 // Tests that a credit card is extracted because it only matches a masked server 2162 // Tests that a credit card is extracted because it only matches a masked server
(...skipping 18 matching lines...) Expand all
2180 FormStructure form_structure(form); 2181 FormStructure form_structure(form);
2181 form_structure.DetermineHeuristicTypes(); 2182 form_structure.DetermineHeuristicTypes();
2182 std::unique_ptr<CreditCard> imported_credit_card; 2183 std::unique_ptr<CreditCard> imported_credit_card;
2183 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); 2184 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card));
2184 ASSERT_TRUE(imported_credit_card); 2185 ASSERT_TRUE(imported_credit_card);
2185 personal_data_->SaveImportedCreditCard(*imported_credit_card); 2186 personal_data_->SaveImportedCreditCard(*imported_credit_card);
2186 2187
2187 // Verify that the web database has been updated and the notification sent. 2188 // Verify that the web database has been updated and the notification sent.
2188 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2189 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2189 .WillOnce(QuitMainMessageLoop()); 2190 .WillOnce(QuitMainMessageLoop());
2190 base::MessageLoop::current()->Run(); 2191 base::RunLoop().Run();
2191 } 2192 }
2192 2193
2193 // Tests that a credit card is not extracted because it matches a full server 2194 // Tests that a credit card is not extracted because it matches a full server
2194 // card. 2195 // card.
2195 TEST_F(PersonalDataManagerTest, 2196 TEST_F(PersonalDataManagerTest,
2196 ImportCreditCard_DuplicateServerCards_FullCard) { 2197 ImportCreditCard_DuplicateServerCards_FullCard) {
2197 // Add a full server card. 2198 // Add a full server card.
2198 std::vector<CreditCard> server_cards; 2199 std::vector<CreditCard> server_cards;
2199 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); 2200 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789"));
2200 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", 2201 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow",
(...skipping 22 matching lines...) Expand all
2223 FormStructure form_structure1(form1); 2224 FormStructure form_structure1(form1);
2224 form_structure1.DetermineHeuristicTypes(); 2225 form_structure1.DetermineHeuristicTypes();
2225 std::unique_ptr<CreditCard> imported_credit_card; 2226 std::unique_ptr<CreditCard> imported_credit_card;
2226 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); 2227 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card));
2227 ASSERT_TRUE(imported_credit_card); 2228 ASSERT_TRUE(imported_credit_card);
2228 personal_data_->SaveImportedCreditCard(*imported_credit_card); 2229 personal_data_->SaveImportedCreditCard(*imported_credit_card);
2229 2230
2230 // Verify that the web database has been updated and the notification sent. 2231 // Verify that the web database has been updated and the notification sent.
2231 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2232 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2232 .WillOnce(QuitMainMessageLoop()); 2233 .WillOnce(QuitMainMessageLoop());
2233 base::MessageLoop::current()->Run(); 2234 base::RunLoop().Run();
2234 2235
2235 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); 2236 CreditCard expected(base::GenerateGUID(), "https://www.example.com");
2236 test::SetCreditCardInfo(&expected, 2237 test::SetCreditCardInfo(&expected,
2237 "Biggie Smalls", "4111111111111111", "01", "2999"); 2238 "Biggie Smalls", "4111111111111111", "01", "2999");
2238 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); 2239 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards();
2239 ASSERT_EQ(1U, results.size()); 2240 ASSERT_EQ(1U, results.size());
2240 EXPECT_EQ(0, expected.Compare(*results[0])); 2241 EXPECT_EQ(0, expected.Compare(*results[0]));
2241 2242
2242 // Add a second different valid credit card where the year is different but 2243 // Add a second different valid credit card where the year is different but
2243 // the credit card number matches. 2244 // the credit card number matches.
2244 FormData form2; 2245 FormData form2;
2245 AddFullCreditCardForm(&form2, "Biggie Smalls", "4111 1111 1111 1111", "01", 2246 AddFullCreditCardForm(&form2, "Biggie Smalls", "4111 1111 1111 1111", "01",
2246 /* different year */ "3999"); 2247 /* different year */ "3999");
2247 2248
2248 FormStructure form_structure2(form2); 2249 FormStructure form_structure2(form2);
2249 form_structure2.DetermineHeuristicTypes(); 2250 form_structure2.DetermineHeuristicTypes();
2250 std::unique_ptr<CreditCard> imported_credit_card2; 2251 std::unique_ptr<CreditCard> imported_credit_card2;
2251 EXPECT_TRUE(ImportCreditCard(form_structure2, false, &imported_credit_card2)); 2252 EXPECT_TRUE(ImportCreditCard(form_structure2, false, &imported_credit_card2));
2252 EXPECT_FALSE(imported_credit_card2); 2253 EXPECT_FALSE(imported_credit_card2);
2253 2254
2254 // Verify that the web database has been updated and the notification sent. 2255 // Verify that the web database has been updated and the notification sent.
2255 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2256 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2256 .WillOnce(QuitMainMessageLoop()); 2257 .WillOnce(QuitMainMessageLoop());
2257 base::MessageLoop::current()->Run(); 2258 base::RunLoop().Run();
2258 2259
2259 // Expect that the newer information is saved. In this case the year is 2260 // Expect that the newer information is saved. In this case the year is
2260 // updated to "3999". 2261 // updated to "3999".
2261 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); 2262 CreditCard expected2(base::GenerateGUID(), "https://www.example.com");
2262 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01", 2263 test::SetCreditCardInfo(&expected2, "Biggie Smalls", "4111111111111111", "01",
2263 "3999"); 2264 "3999");
2264 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); 2265 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards();
2265 ASSERT_EQ(1U, results2.size()); 2266 ASSERT_EQ(1U, results2.size());
2266 EXPECT_EQ(0, expected2.Compare(*results2[0])); 2267 EXPECT_EQ(0, expected2.Compare(*results2[0]));
2267 } 2268 }
2268 2269
2269 TEST_F(PersonalDataManagerTest, ImportCreditCard_ShouldReturnLocalCard) { 2270 TEST_F(PersonalDataManagerTest, ImportCreditCard_ShouldReturnLocalCard) {
2270 // Start with a single valid credit card form. 2271 // Start with a single valid credit card form.
2271 FormData form1; 2272 FormData form1;
2272 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", 2273 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01",
2273 "2999"); 2274 "2999");
2274 2275
2275 FormStructure form_structure1(form1); 2276 FormStructure form_structure1(form1);
2276 form_structure1.DetermineHeuristicTypes(); 2277 form_structure1.DetermineHeuristicTypes();
2277 std::unique_ptr<CreditCard> imported_credit_card; 2278 std::unique_ptr<CreditCard> imported_credit_card;
2278 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); 2279 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card));
2279 ASSERT_TRUE(imported_credit_card); 2280 ASSERT_TRUE(imported_credit_card);
2280 personal_data_->SaveImportedCreditCard(*imported_credit_card); 2281 personal_data_->SaveImportedCreditCard(*imported_credit_card);
2281 2282
2282 // Verify that the web database has been updated and the notification sent. 2283 // Verify that the web database has been updated and the notification sent.
2283 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2284 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2284 .WillOnce(QuitMainMessageLoop()); 2285 .WillOnce(QuitMainMessageLoop());
2285 base::MessageLoop::current()->Run(); 2286 base::RunLoop().Run();
2286 2287
2287 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); 2288 CreditCard expected(base::GenerateGUID(), "https://www.example.com");
2288 test::SetCreditCardInfo(&expected, 2289 test::SetCreditCardInfo(&expected,
2289 "Biggie Smalls", "4111111111111111", "01", "2999"); 2290 "Biggie Smalls", "4111111111111111", "01", "2999");
2290 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); 2291 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards();
2291 ASSERT_EQ(1U, results.size()); 2292 ASSERT_EQ(1U, results.size());
2292 EXPECT_EQ(0, expected.Compare(*results[0])); 2293 EXPECT_EQ(0, expected.Compare(*results[0]));
2293 2294
2294 // Add a second different valid credit card where the year is different but 2295 // Add a second different valid credit card where the year is different but
2295 // the credit card number matches. 2296 // the credit card number matches.
2296 FormData form2; 2297 FormData form2;
2297 AddFullCreditCardForm(&form2, "Biggie Smalls", "4111 1111 1111 1111", "01", 2298 AddFullCreditCardForm(&form2, "Biggie Smalls", "4111 1111 1111 1111", "01",
2298 /* different year */ "3999"); 2299 /* different year */ "3999");
2299 2300
2300 FormStructure form_structure2(form2); 2301 FormStructure form_structure2(form2);
2301 form_structure2.DetermineHeuristicTypes(); 2302 form_structure2.DetermineHeuristicTypes();
2302 std::unique_ptr<CreditCard> imported_credit_card2; 2303 std::unique_ptr<CreditCard> imported_credit_card2;
2303 EXPECT_TRUE(ImportCreditCard(form_structure2, 2304 EXPECT_TRUE(ImportCreditCard(form_structure2,
2304 /* should_return_local_card= */ true, 2305 /* should_return_local_card= */ true,
2305 &imported_credit_card2)); 2306 &imported_credit_card2));
2306 // The local card is returned after an update. 2307 // The local card is returned after an update.
2307 EXPECT_TRUE(imported_credit_card2); 2308 EXPECT_TRUE(imported_credit_card2);
2308 2309
2309 // Verify that the web database has been updated and the notification sent. 2310 // Verify that the web database has been updated and the notification sent.
2310 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2311 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2311 .WillOnce(QuitMainMessageLoop()); 2312 .WillOnce(QuitMainMessageLoop());
2312 base::MessageLoop::current()->Run(); 2313 base::RunLoop().Run();
2313 2314
2314 // Expect that the newer information is saved. In this case the year is 2315 // Expect that the newer information is saved. In this case the year is
2315 // updated to "3999". 2316 // updated to "3999".
2316 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); 2317 CreditCard expected2(base::GenerateGUID(), "https://www.example.com");
2317 test::SetCreditCardInfo(&expected2, 2318 test::SetCreditCardInfo(&expected2,
2318 "Biggie Smalls", "4111111111111111", "01", "3999"); 2319 "Biggie Smalls", "4111111111111111", "01", "3999");
2319 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); 2320 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards();
2320 ASSERT_EQ(1U, results2.size()); 2321 ASSERT_EQ(1U, results2.size());
2321 EXPECT_EQ(0, expected2.Compare(*results2[0])); 2322 EXPECT_EQ(0, expected2.Compare(*results2[0]));
2322 } 2323 }
2323 2324
2324 TEST_F(PersonalDataManagerTest, ImportCreditCard_EmptyCardWithConflict) { 2325 TEST_F(PersonalDataManagerTest, ImportCreditCard_EmptyCardWithConflict) {
2325 // Start with a single valid credit card form. 2326 // Start with a single valid credit card form.
2326 FormData form1; 2327 FormData form1;
2327 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01", 2328 AddFullCreditCardForm(&form1, "Biggie Smalls", "4111-1111-1111-1111", "01",
2328 "2999"); 2329 "2999");
2329 2330
2330 FormStructure form_structure1(form1); 2331 FormStructure form_structure1(form1);
2331 form_structure1.DetermineHeuristicTypes(); 2332 form_structure1.DetermineHeuristicTypes();
2332 std::unique_ptr<CreditCard> imported_credit_card; 2333 std::unique_ptr<CreditCard> imported_credit_card;
2333 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); 2334 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card));
2334 ASSERT_TRUE(imported_credit_card); 2335 ASSERT_TRUE(imported_credit_card);
2335 personal_data_->SaveImportedCreditCard(*imported_credit_card); 2336 personal_data_->SaveImportedCreditCard(*imported_credit_card);
2336 2337
2337 // Verify that the web database has been updated and the notification sent. 2338 // Verify that the web database has been updated and the notification sent.
2338 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2339 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2339 .WillOnce(QuitMainMessageLoop()); 2340 .WillOnce(QuitMainMessageLoop());
2340 base::MessageLoop::current()->Run(); 2341 base::RunLoop().Run();
2341 2342
2342 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); 2343 CreditCard expected(base::GenerateGUID(), "https://www.example.com");
2343 test::SetCreditCardInfo(&expected, 2344 test::SetCreditCardInfo(&expected,
2344 "Biggie Smalls", "4111111111111111", "01", "2999"); 2345 "Biggie Smalls", "4111111111111111", "01", "2999");
2345 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); 2346 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards();
2346 ASSERT_EQ(1U, results.size()); 2347 ASSERT_EQ(1U, results.size());
2347 EXPECT_EQ(0, expected.Compare(*results[0])); 2348 EXPECT_EQ(0, expected.Compare(*results[0]));
2348 2349
2349 // Add a second credit card with no number. 2350 // Add a second credit card with no number.
2350 FormData form2; 2351 FormData form2;
(...skipping 29 matching lines...) Expand all
2380 FormStructure form_structure1(form1); 2381 FormStructure form_structure1(form1);
2381 form_structure1.DetermineHeuristicTypes(); 2382 form_structure1.DetermineHeuristicTypes();
2382 std::unique_ptr<CreditCard> imported_credit_card; 2383 std::unique_ptr<CreditCard> imported_credit_card;
2383 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card)); 2384 EXPECT_TRUE(ImportCreditCard(form_structure1, false, &imported_credit_card));
2384 ASSERT_TRUE(imported_credit_card); 2385 ASSERT_TRUE(imported_credit_card);
2385 personal_data_->SaveImportedCreditCard(*imported_credit_card); 2386 personal_data_->SaveImportedCreditCard(*imported_credit_card);
2386 2387
2387 // Verify that the web database has been updated and the notification sent. 2388 // Verify that the web database has been updated and the notification sent.
2388 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2389 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2389 .WillOnce(QuitMainMessageLoop()); 2390 .WillOnce(QuitMainMessageLoop());
2390 base::MessageLoop::current()->Run(); 2391 base::RunLoop().Run();
2391 2392
2392 CreditCard expected(base::GenerateGUID(), "https://www.example.com"); 2393 CreditCard expected(base::GenerateGUID(), "https://www.example.com");
2393 test::SetCreditCardInfo(&expected, 2394 test::SetCreditCardInfo(&expected,
2394 "Biggie Smalls", "4111111111111111", "01", "2999"); 2395 "Biggie Smalls", "4111111111111111", "01", "2999");
2395 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); 2396 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards();
2396 ASSERT_EQ(1U, results.size()); 2397 ASSERT_EQ(1U, results.size());
2397 EXPECT_EQ(0, expected.Compare(*results[0])); 2398 EXPECT_EQ(0, expected.Compare(*results[0]));
2398 2399
2399 // Add a second different valid credit card where the name is missing but 2400 // Add a second different valid credit card where the name is missing but
2400 // the credit card number matches. 2401 // the credit card number matches.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
2450 // Start with a single valid credit card stored via the preferences. 2451 // Start with a single valid credit card stored via the preferences.
2451 // Note the empty name. 2452 // Note the empty name.
2452 CreditCard saved_credit_card(base::GenerateGUID(), "https://www.example.com"); 2453 CreditCard saved_credit_card(base::GenerateGUID(), "https://www.example.com");
2453 test::SetCreditCardInfo(&saved_credit_card, 2454 test::SetCreditCardInfo(&saved_credit_card,
2454 "", "4111111111111111" /* Visa */, "01", "2999"); 2455 "", "4111111111111111" /* Visa */, "01", "2999");
2455 personal_data_->AddCreditCard(saved_credit_card); 2456 personal_data_->AddCreditCard(saved_credit_card);
2456 2457
2457 // Verify that the web database has been updated and the notification sent. 2458 // Verify that the web database has been updated and the notification sent.
2458 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2459 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2459 .WillOnce(QuitMainMessageLoop()); 2460 .WillOnce(QuitMainMessageLoop());
2460 base::MessageLoop::current()->Run(); 2461 base::RunLoop().Run();
2461 2462
2462 const std::vector<CreditCard*>& results1 = personal_data_->GetCreditCards(); 2463 const std::vector<CreditCard*>& results1 = personal_data_->GetCreditCards();
2463 ASSERT_EQ(1U, results1.size()); 2464 ASSERT_EQ(1U, results1.size());
2464 EXPECT_EQ(saved_credit_card, *results1[0]); 2465 EXPECT_EQ(saved_credit_card, *results1[0]);
2465 2466
2466 // Add a second different valid credit card where the year is different but 2467 // Add a second different valid credit card where the year is different but
2467 // the credit card number matches. 2468 // the credit card number matches.
2468 FormData form; 2469 FormData form;
2469 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01", 2470 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01",
2470 /* different year */ "3999"); 2471 /* different year */ "3999");
2471 2472
2472 FormStructure form_structure(form); 2473 FormStructure form_structure(form);
2473 form_structure.DetermineHeuristicTypes(); 2474 form_structure.DetermineHeuristicTypes();
2474 std::unique_ptr<CreditCard> imported_credit_card; 2475 std::unique_ptr<CreditCard> imported_credit_card;
2475 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); 2476 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card));
2476 EXPECT_FALSE(imported_credit_card); 2477 EXPECT_FALSE(imported_credit_card);
2477 2478
2478 // Verify that the web database has been updated and the notification sent. 2479 // Verify that the web database has been updated and the notification sent.
2479 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2480 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2480 .WillOnce(QuitMainMessageLoop()); 2481 .WillOnce(QuitMainMessageLoop());
2481 base::MessageLoop::current()->Run(); 2482 base::RunLoop().Run();
2482 2483
2483 // Expect that the newer information is saved. In this case the year is 2484 // Expect that the newer information is saved. In this case the year is
2484 // added to the existing credit card. 2485 // added to the existing credit card.
2485 CreditCard expected2(base::GenerateGUID(), "https://www.example.com"); 2486 CreditCard expected2(base::GenerateGUID(), "https://www.example.com");
2486 test::SetCreditCardInfo(&expected2, 2487 test::SetCreditCardInfo(&expected2,
2487 "Biggie Smalls", "4111111111111111", "01", "3999"); 2488 "Biggie Smalls", "4111111111111111", "01", "3999");
2488 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards(); 2489 const std::vector<CreditCard*>& results2 = personal_data_->GetCreditCards();
2489 ASSERT_EQ(1U, results2.size()); 2490 ASSERT_EQ(1U, results2.size());
2490 EXPECT_EQ(0, expected2.Compare(*results2[0])); 2491 EXPECT_EQ(0, expected2.Compare(*results2[0]));
2491 } 2492 }
2492 2493
2493 // We allow the user to store a credit card number with separators via the UI. 2494 // We allow the user to store a credit card number with separators via the UI.
2494 // We should not try to re-aggregate the same card with the separators stripped. 2495 // We should not try to re-aggregate the same card with the separators stripped.
2495 TEST_F(PersonalDataManagerTest, ImportCreditCard_SameCardWithSeparators) { 2496 TEST_F(PersonalDataManagerTest, ImportCreditCard_SameCardWithSeparators) {
2496 // Start with a single valid credit card stored via the preferences. 2497 // Start with a single valid credit card stored via the preferences.
2497 // Note the separators in the credit card number. 2498 // Note the separators in the credit card number.
2498 CreditCard saved_credit_card(base::GenerateGUID(), "https://www.example.com"); 2499 CreditCard saved_credit_card(base::GenerateGUID(), "https://www.example.com");
2499 test::SetCreditCardInfo(&saved_credit_card, 2500 test::SetCreditCardInfo(&saved_credit_card,
2500 "Biggie Smalls", "4111 1111 1111 1111" /* Visa */, "01", "2999"); 2501 "Biggie Smalls", "4111 1111 1111 1111" /* Visa */, "01", "2999");
2501 personal_data_->AddCreditCard(saved_credit_card); 2502 personal_data_->AddCreditCard(saved_credit_card);
2502 2503
2503 // Verify that the web database has been updated and the notification sent. 2504 // Verify that the web database has been updated and the notification sent.
2504 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2505 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2505 .WillOnce(QuitMainMessageLoop()); 2506 .WillOnce(QuitMainMessageLoop());
2506 base::MessageLoop::current()->Run(); 2507 base::RunLoop().Run();
2507 2508
2508 const std::vector<CreditCard*>& results1 = personal_data_->GetCreditCards(); 2509 const std::vector<CreditCard*>& results1 = personal_data_->GetCreditCards();
2509 ASSERT_EQ(1U, results1.size()); 2510 ASSERT_EQ(1U, results1.size());
2510 EXPECT_EQ(0, saved_credit_card.Compare(*results1[0])); 2511 EXPECT_EQ(0, saved_credit_card.Compare(*results1[0]));
2511 2512
2512 // Import the same card info, but with different separators in the number. 2513 // Import the same card info, but with different separators in the number.
2513 FormData form; 2514 FormData form;
2514 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01", 2515 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", "01",
2515 "2999"); 2516 "2999");
2516 2517
(...skipping 22 matching lines...) Expand all
2539 test::SetCreditCardInfo(&credit_card, "Biggie Smalls", 2540 test::SetCreditCardInfo(&credit_card, "Biggie Smalls",
2540 "4111 1111 1111 1111" /* Visa */, "01", "2999"); 2541 "4111 1111 1111 1111" /* Visa */, "01", "2999");
2541 EXPECT_TRUE(credit_card.IsVerified()); 2542 EXPECT_TRUE(credit_card.IsVerified());
2542 2543
2543 // Add the credit card to the database. 2544 // Add the credit card to the database.
2544 personal_data_->AddCreditCard(credit_card); 2545 personal_data_->AddCreditCard(credit_card);
2545 2546
2546 // Verify that the web database has been updated and the notification sent. 2547 // Verify that the web database has been updated and the notification sent.
2547 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2548 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2548 .WillOnce(QuitMainMessageLoop()); 2549 .WillOnce(QuitMainMessageLoop());
2549 base::MessageLoop::current()->Run(); 2550 base::RunLoop().Run();
2550 2551
2551 // Simulate a form submission with conflicting expiration year. 2552 // Simulate a form submission with conflicting expiration year.
2552 FormData form; 2553 FormData form;
2553 AddFullCreditCardForm(&form, "Biggie Smalls", "4111 1111 1111 1111", "01", 2554 AddFullCreditCardForm(&form, "Biggie Smalls", "4111 1111 1111 1111", "01",
2554 /* different year */ "3999"); 2555 /* different year */ "3999");
2555 2556
2556 FormStructure form_structure(form); 2557 FormStructure form_structure(form);
2557 form_structure.DetermineHeuristicTypes(); 2558 form_structure.DetermineHeuristicTypes();
2558 std::unique_ptr<CreditCard> imported_credit_card; 2559 std::unique_ptr<CreditCard> imported_credit_card;
2559 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); 2560 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2604 form_structure.DetermineHeuristicTypes(); 2605 form_structure.DetermineHeuristicTypes();
2605 std::unique_ptr<CreditCard> imported_credit_card; 2606 std::unique_ptr<CreditCard> imported_credit_card;
2606 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, false, 2607 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, false,
2607 &imported_credit_card)); 2608 &imported_credit_card));
2608 ASSERT_TRUE(imported_credit_card); 2609 ASSERT_TRUE(imported_credit_card);
2609 personal_data_->SaveImportedCreditCard(*imported_credit_card); 2610 personal_data_->SaveImportedCreditCard(*imported_credit_card);
2610 2611
2611 // Verify that the web database has been updated and the notification sent. 2612 // Verify that the web database has been updated and the notification sent.
2612 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2613 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2613 .WillOnce(QuitMainMessageLoop()); 2614 .WillOnce(QuitMainMessageLoop());
2614 base::MessageLoop::current()->Run(); 2615 base::RunLoop().Run();
2615 2616
2616 // Test that the address has been saved. 2617 // Test that the address has been saved.
2617 AutofillProfile expected_address(base::GenerateGUID(), 2618 AutofillProfile expected_address(base::GenerateGUID(),
2618 "https://www.example.com"); 2619 "https://www.example.com");
2619 test::SetProfileInfo(&expected_address, "George", NULL, "Washington", 2620 test::SetProfileInfo(&expected_address, "George", NULL, "Washington",
2620 "theprez@gmail.com", NULL, "21 Laussat St", NULL, 2621 "theprez@gmail.com", NULL, "21 Laussat St", NULL,
2621 "San Francisco", "California", "94102", NULL, NULL); 2622 "San Francisco", "California", "94102", NULL, NULL);
2622 const std::vector<AutofillProfile*>& results_addr = 2623 const std::vector<AutofillProfile*>& results_addr =
2623 personal_data_->GetProfiles(); 2624 personal_data_->GetProfiles();
2624 ASSERT_EQ(1U, results_addr.size()); 2625 ASSERT_EQ(1U, results_addr.size());
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2683 std::unique_ptr<CreditCard> imported_credit_card; 2684 std::unique_ptr<CreditCard> imported_credit_card;
2684 // Still returns true because the credit card import was successful. 2685 // Still returns true because the credit card import was successful.
2685 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, false, 2686 EXPECT_TRUE(personal_data_->ImportFormData(form_structure, false,
2686 &imported_credit_card)); 2687 &imported_credit_card));
2687 ASSERT_TRUE(imported_credit_card); 2688 ASSERT_TRUE(imported_credit_card);
2688 personal_data_->SaveImportedCreditCard(*imported_credit_card); 2689 personal_data_->SaveImportedCreditCard(*imported_credit_card);
2689 2690
2690 // Verify that the web database has been updated and the notification sent. 2691 // Verify that the web database has been updated and the notification sent.
2691 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2692 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2692 .WillOnce(QuitMainMessageLoop()); 2693 .WillOnce(QuitMainMessageLoop());
2693 base::MessageLoop::current()->Run(); 2694 base::RunLoop().Run();
2694 2695
2695 // Test that both addresses have been saved. 2696 // Test that both addresses have been saved.
2696 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); 2697 EXPECT_EQ(2U, personal_data_->GetProfiles().size());
2697 2698
2698 // Test that the credit card has been saved. 2699 // Test that the credit card has been saved.
2699 CreditCard expected_card(base::GenerateGUID(), "https://www.example.com"); 2700 CreditCard expected_card(base::GenerateGUID(), "https://www.example.com");
2700 test::SetCreditCardInfo(&expected_card, "Biggie Smalls", "4111111111111111", 2701 test::SetCreditCardInfo(&expected_card, "Biggie Smalls", "4111111111111111",
2701 "01", "2999"); 2702 "01", "2999");
2702 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); 2703 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards();
2703 ASSERT_EQ(1U, results.size()); 2704 ASSERT_EQ(1U, results.size());
(...skipping 10 matching lines...) Expand all
2714 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", 2715 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA",
2715 "91601", "US", "12345678910"); 2716 "91601", "US", "12345678910");
2716 EXPECT_FALSE(profile.IsVerified()); 2717 EXPECT_FALSE(profile.IsVerified());
2717 2718
2718 // Add the profile to the database. 2719 // Add the profile to the database.
2719 personal_data_->AddProfile(profile); 2720 personal_data_->AddProfile(profile);
2720 2721
2721 // Verify that the web database has been updated and the notification sent. 2722 // Verify that the web database has been updated and the notification sent.
2722 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2723 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2723 .WillOnce(QuitMainMessageLoop()); 2724 .WillOnce(QuitMainMessageLoop());
2724 base::MessageLoop::current()->Run(); 2725 base::RunLoop().Run();
2725 2726
2726 AutofillProfile new_verified_profile = profile; 2727 AutofillProfile new_verified_profile = profile;
2727 new_verified_profile.set_guid(base::GenerateGUID()); 2728 new_verified_profile.set_guid(base::GenerateGUID());
2728 new_verified_profile.set_origin(kSettingsOrigin); 2729 new_verified_profile.set_origin(kSettingsOrigin);
2729 new_verified_profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, 2730 new_verified_profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER,
2730 ASCIIToUTF16("1 234 567-8910")); 2731 ASCIIToUTF16("1 234 567-8910"));
2731 EXPECT_TRUE(new_verified_profile.IsVerified()); 2732 EXPECT_TRUE(new_verified_profile.IsVerified());
2732 2733
2733 personal_data_->SaveImportedProfile(new_verified_profile); 2734 personal_data_->SaveImportedProfile(new_verified_profile);
2734 2735
2735 // Verify that the web database has been updated and the notification sent. 2736 // Verify that the web database has been updated and the notification sent.
2736 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2737 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2737 .WillOnce(QuitMainMessageLoop()); 2738 .WillOnce(QuitMainMessageLoop());
2738 base::MessageLoop::current()->Run(); 2739 base::RunLoop().Run();
2739 2740
2740 // The new profile should be merged into the existing one. 2741 // The new profile should be merged into the existing one.
2741 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); 2742 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles();
2742 ASSERT_EQ(1U, results.size()); 2743 ASSERT_EQ(1U, results.size());
2743 EXPECT_EQ(0, new_verified_profile.Compare(*results[0])); 2744 EXPECT_EQ(0, new_verified_profile.Compare(*results[0]));
2744 } 2745 }
2745 2746
2746 // Ensure that verified credit cards can be saved via SaveImportedCreditCard. 2747 // Ensure that verified credit cards can be saved via SaveImportedCreditCard.
2747 TEST_F(PersonalDataManagerTest, SaveImportedCreditCardWithVerifiedData) { 2748 TEST_F(PersonalDataManagerTest, SaveImportedCreditCardWithVerifiedData) {
2748 // Start with a verified credit card. 2749 // Start with a verified credit card.
2749 CreditCard credit_card(base::GenerateGUID(), kSettingsOrigin); 2750 CreditCard credit_card(base::GenerateGUID(), kSettingsOrigin);
2750 test::SetCreditCardInfo(&credit_card, 2751 test::SetCreditCardInfo(&credit_card,
2751 "Biggie Smalls", "4111 1111 1111 1111" /* Visa */, "01", "2999"); 2752 "Biggie Smalls", "4111 1111 1111 1111" /* Visa */, "01", "2999");
2752 EXPECT_TRUE(credit_card.IsVerified()); 2753 EXPECT_TRUE(credit_card.IsVerified());
2753 2754
2754 // Add the credit card to the database. 2755 // Add the credit card to the database.
2755 personal_data_->AddCreditCard(credit_card); 2756 personal_data_->AddCreditCard(credit_card);
2756 2757
2757 // Verify that the web database has been updated and the notification sent. 2758 // Verify that the web database has been updated and the notification sent.
2758 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2759 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2759 .WillOnce(QuitMainMessageLoop()); 2760 .WillOnce(QuitMainMessageLoop());
2760 base::MessageLoop::current()->Run(); 2761 base::RunLoop().Run();
2761 2762
2762 CreditCard new_verified_card = credit_card; 2763 CreditCard new_verified_card = credit_card;
2763 new_verified_card.set_guid(base::GenerateGUID()); 2764 new_verified_card.set_guid(base::GenerateGUID());
2764 new_verified_card.SetRawInfo(CREDIT_CARD_NAME_FULL, ASCIIToUTF16("B. Small")); 2765 new_verified_card.SetRawInfo(CREDIT_CARD_NAME_FULL, ASCIIToUTF16("B. Small"));
2765 EXPECT_TRUE(new_verified_card.IsVerified()); 2766 EXPECT_TRUE(new_verified_card.IsVerified());
2766 2767
2767 personal_data_->SaveImportedCreditCard(new_verified_card); 2768 personal_data_->SaveImportedCreditCard(new_verified_card);
2768 2769
2769 // Verify that the web database has been updated and the notification sent. 2770 // Verify that the web database has been updated and the notification sent.
2770 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2771 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2771 .WillOnce(QuitMainMessageLoop()); 2772 .WillOnce(QuitMainMessageLoop());
2772 base::MessageLoop::current()->Run(); 2773 base::RunLoop().Run();
2773 2774
2774 // Expect that the saved credit card is updated. 2775 // Expect that the saved credit card is updated.
2775 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); 2776 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards();
2776 ASSERT_EQ(1U, results.size()); 2777 ASSERT_EQ(1U, results.size());
2777 EXPECT_EQ(ASCIIToUTF16("B. Small"), 2778 EXPECT_EQ(ASCIIToUTF16("B. Small"),
2778 results[0]->GetRawInfo(CREDIT_CARD_NAME_FULL)); 2779 results[0]->GetRawInfo(CREDIT_CARD_NAME_FULL));
2779 } 2780 }
2780 2781
2781 TEST_F(PersonalDataManagerTest, GetNonEmptyTypes) { 2782 TEST_F(PersonalDataManagerTest, GetNonEmptyTypes) {
2782 // Check that there are no available types with no profiles stored. 2783 // Check that there are no available types with no profiles stored.
2783 ServerFieldTypeSet non_empty_types; 2784 ServerFieldTypeSet non_empty_types;
2784 personal_data_->GetNonEmptyTypes(&non_empty_types); 2785 personal_data_->GetNonEmptyTypes(&non_empty_types);
2785 EXPECT_EQ(0U, non_empty_types.size()); 2786 EXPECT_EQ(0U, non_empty_types.size());
2786 2787
2787 // Test with one profile stored. 2788 // Test with one profile stored.
2788 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com"); 2789 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com");
2789 test::SetProfileInfo(&profile0, 2790 test::SetProfileInfo(&profile0,
2790 "Marion", NULL, "Morrison", 2791 "Marion", NULL, "Morrison",
2791 "johnwayne@me.xyz", NULL, "123 Zoo St.", NULL, "Hollywood", "CA", 2792 "johnwayne@me.xyz", NULL, "123 Zoo St.", NULL, "Hollywood", "CA",
2792 "91601", "US", "14155678910"); 2793 "91601", "US", "14155678910");
2793 2794
2794 personal_data_->AddProfile(profile0); 2795 personal_data_->AddProfile(profile0);
2795 2796
2796 // Verify that the web database has been updated and the notification sent. 2797 // Verify that the web database has been updated and the notification sent.
2797 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2798 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2798 .WillOnce(QuitMainMessageLoop()); 2799 .WillOnce(QuitMainMessageLoop());
2799 base::MessageLoop::current()->Run(); 2800 base::RunLoop().Run();
2800 2801
2801 personal_data_->GetNonEmptyTypes(&non_empty_types); 2802 personal_data_->GetNonEmptyTypes(&non_empty_types);
2802 EXPECT_EQ(15U, non_empty_types.size()); 2803 EXPECT_EQ(15U, non_empty_types.size());
2803 EXPECT_TRUE(non_empty_types.count(NAME_FIRST)); 2804 EXPECT_TRUE(non_empty_types.count(NAME_FIRST));
2804 EXPECT_TRUE(non_empty_types.count(NAME_LAST)); 2805 EXPECT_TRUE(non_empty_types.count(NAME_LAST));
2805 EXPECT_TRUE(non_empty_types.count(NAME_FULL)); 2806 EXPECT_TRUE(non_empty_types.count(NAME_FULL));
2806 EXPECT_TRUE(non_empty_types.count(EMAIL_ADDRESS)); 2807 EXPECT_TRUE(non_empty_types.count(EMAIL_ADDRESS));
2807 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_LINE1)); 2808 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_LINE1));
2808 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_STREET_ADDRESS)); 2809 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_STREET_ADDRESS));
2809 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_CITY)); 2810 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_CITY));
(...skipping 18 matching lines...) Expand all
2828 "Josephine", "Alicia", "Saenz", 2829 "Josephine", "Alicia", "Saenz",
2829 "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", 2830 "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL",
2830 "32801", "US", "16502937549"); 2831 "32801", "US", "16502937549");
2831 2832
2832 personal_data_->AddProfile(profile1); 2833 personal_data_->AddProfile(profile1);
2833 personal_data_->AddProfile(profile2); 2834 personal_data_->AddProfile(profile2);
2834 2835
2835 // Verify that the web database has been updated and the notification sent. 2836 // Verify that the web database has been updated and the notification sent.
2836 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2837 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2837 .WillOnce(QuitMainMessageLoop()); 2838 .WillOnce(QuitMainMessageLoop());
2838 base::MessageLoop::current()->Run(); 2839 base::RunLoop().Run();
2839 2840
2840 personal_data_->GetNonEmptyTypes(&non_empty_types); 2841 personal_data_->GetNonEmptyTypes(&non_empty_types);
2841 EXPECT_EQ(19U, non_empty_types.size()); 2842 EXPECT_EQ(19U, non_empty_types.size());
2842 EXPECT_TRUE(non_empty_types.count(NAME_FIRST)); 2843 EXPECT_TRUE(non_empty_types.count(NAME_FIRST));
2843 EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE)); 2844 EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE));
2844 EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE_INITIAL)); 2845 EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE_INITIAL));
2845 EXPECT_TRUE(non_empty_types.count(NAME_LAST)); 2846 EXPECT_TRUE(non_empty_types.count(NAME_LAST));
2846 EXPECT_TRUE(non_empty_types.count(NAME_FULL)); 2847 EXPECT_TRUE(non_empty_types.count(NAME_FULL));
2847 EXPECT_TRUE(non_empty_types.count(EMAIL_ADDRESS)); 2848 EXPECT_TRUE(non_empty_types.count(EMAIL_ADDRESS));
2848 EXPECT_TRUE(non_empty_types.count(COMPANY_NAME)); 2849 EXPECT_TRUE(non_empty_types.count(COMPANY_NAME));
(...skipping 13 matching lines...) Expand all
2862 // Test with credit card information also stored. 2863 // Test with credit card information also stored.
2863 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com"); 2864 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com");
2864 test::SetCreditCardInfo(&credit_card, 2865 test::SetCreditCardInfo(&credit_card,
2865 "John Dillinger", "423456789012" /* Visa */, 2866 "John Dillinger", "423456789012" /* Visa */,
2866 "01", "2999"); 2867 "01", "2999");
2867 personal_data_->AddCreditCard(credit_card); 2868 personal_data_->AddCreditCard(credit_card);
2868 2869
2869 // Verify that the web database has been updated and the notification sent. 2870 // Verify that the web database has been updated and the notification sent.
2870 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2871 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2871 .WillOnce(QuitMainMessageLoop()); 2872 .WillOnce(QuitMainMessageLoop());
2872 base::MessageLoop::current()->Run(); 2873 base::RunLoop().Run();
2873 2874
2874 personal_data_->GetNonEmptyTypes(&non_empty_types); 2875 personal_data_->GetNonEmptyTypes(&non_empty_types);
2875 EXPECT_EQ(29U, non_empty_types.size()); 2876 EXPECT_EQ(29U, non_empty_types.size());
2876 EXPECT_TRUE(non_empty_types.count(NAME_FIRST)); 2877 EXPECT_TRUE(non_empty_types.count(NAME_FIRST));
2877 EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE)); 2878 EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE));
2878 EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE_INITIAL)); 2879 EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE_INITIAL));
2879 EXPECT_TRUE(non_empty_types.count(NAME_LAST)); 2880 EXPECT_TRUE(non_empty_types.count(NAME_LAST));
2880 EXPECT_TRUE(non_empty_types.count(NAME_FULL)); 2881 EXPECT_TRUE(non_empty_types.count(NAME_FULL));
2881 EXPECT_TRUE(non_empty_types.count(EMAIL_ADDRESS)); 2882 EXPECT_TRUE(non_empty_types.count(EMAIL_ADDRESS));
2882 EXPECT_TRUE(non_empty_types.count(COMPANY_NAME)); 2883 EXPECT_TRUE(non_empty_types.count(COMPANY_NAME));
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
2983 personal_data_->GetDefaultCountryCodeForNewAddress(); 2984 personal_data_->GetDefaultCountryCodeForNewAddress();
2984 EXPECT_EQ(2U, default_country.size()); 2985 EXPECT_EQ(2U, default_country.size());
2985 2986
2986 AutofillProfile moose(base::GenerateGUID(), kSettingsOrigin); 2987 AutofillProfile moose(base::GenerateGUID(), kSettingsOrigin);
2987 test::SetProfileInfo(&moose, "Moose", "P", "McMahon", "mpm@example.com", 2988 test::SetProfileInfo(&moose, "Moose", "P", "McMahon", "mpm@example.com",
2988 "", "1 Taiga TKTR", "", "Calgary", "AB", "T2B 2K2", 2989 "", "1 Taiga TKTR", "", "Calgary", "AB", "T2B 2K2",
2989 "CA", "(800) 555-9000"); 2990 "CA", "(800) 555-9000");
2990 personal_data_->AddProfile(moose); 2991 personal_data_->AddProfile(moose);
2991 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2992 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2992 .WillOnce(QuitMainMessageLoop()); 2993 .WillOnce(QuitMainMessageLoop());
2993 base::MessageLoop::current()->Run(); 2994 base::RunLoop().Run();
2994 // The value is cached and doesn't change even after adding an address. 2995 // The value is cached and doesn't change even after adding an address.
2995 EXPECT_EQ(default_country, 2996 EXPECT_EQ(default_country,
2996 personal_data_->GetDefaultCountryCodeForNewAddress()); 2997 personal_data_->GetDefaultCountryCodeForNewAddress());
2997 2998
2998 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()).Times(2); 2999 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()).Times(2);
2999 3000
3000 // Disabling Autofill blows away this cache and shouldn't account for Autofill 3001 // Disabling Autofill blows away this cache and shouldn't account for Autofill
3001 // profiles. 3002 // profiles.
3002 prefs_->SetBoolean(prefs::kAutofillEnabled, false); 3003 prefs_->SetBoolean(prefs::kAutofillEnabled, false);
3003 EXPECT_EQ(default_country, 3004 EXPECT_EQ(default_country,
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
3067 TEST_F(PersonalDataManagerTest, UpdateLanguageCodeInProfile) { 3068 TEST_F(PersonalDataManagerTest, UpdateLanguageCodeInProfile) {
3068 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com"); 3069 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com");
3069 test::SetProfileInfo(&profile, 3070 test::SetProfileInfo(&profile,
3070 "Marion", "Mitchell", "Morrison", 3071 "Marion", "Mitchell", "Morrison",
3071 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", 3072 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA",
3072 "91601", "US", "12345678910"); 3073 "91601", "US", "12345678910");
3073 personal_data_->AddProfile(profile); 3074 personal_data_->AddProfile(profile);
3074 3075
3075 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 3076 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
3076 .WillOnce(QuitMainMessageLoop()); 3077 .WillOnce(QuitMainMessageLoop());
3077 base::MessageLoop::current()->Run(); 3078 base::RunLoop().Run();
3078 3079
3079 profile.set_language_code("en"); 3080 profile.set_language_code("en");
3080 personal_data_->UpdateProfile(profile); 3081 personal_data_->UpdateProfile(profile);
3081 3082
3082 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 3083 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
3083 .WillOnce(QuitMainMessageLoop()); 3084 .WillOnce(QuitMainMessageLoop());
3084 base::MessageLoop::current()->Run(); 3085 base::RunLoop().Run();
3085 3086
3086 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); 3087 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles();
3087 ASSERT_EQ(1U, results.size()); 3088 ASSERT_EQ(1U, results.size());
3088 EXPECT_EQ(0, profile.Compare(*results[0])); 3089 EXPECT_EQ(0, profile.Compare(*results[0]));
3089 EXPECT_EQ("en", results[0]->language_code()); 3090 EXPECT_EQ("en", results[0]->language_code());
3090 } 3091 }
3091 3092
3092 TEST_F(PersonalDataManagerTest, GetProfileSuggestions) { 3093 TEST_F(PersonalDataManagerTest, GetProfileSuggestions) {
3093 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com"); 3094 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com");
3094 test::SetProfileInfo(&profile, 3095 test::SetProfileInfo(&profile,
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
3289 std::vector<CreditCard> server_cards; 3290 std::vector<CreditCard> server_cards;
3290 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b459")); 3291 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b459"));
3291 test::SetCreditCardInfo(&server_cards.back(), "Emmet Dalton", "2110", "12", 3292 test::SetCreditCardInfo(&server_cards.back(), "Emmet Dalton", "2110", "12",
3292 "3999"); 3293 "3999");
3293 server_cards.back().SetTypeForMaskedCard(kVisaCard); 3294 server_cards.back().SetTypeForMaskedCard(kVisaCard);
3294 3295
3295 test::SetServerCreditCards(autofill_table_, server_cards); 3296 test::SetServerCreditCards(autofill_table_, server_cards);
3296 personal_data_->Refresh(); 3297 personal_data_->Refresh();
3297 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 3298 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
3298 .WillOnce(QuitMainMessageLoop()); 3299 .WillOnce(QuitMainMessageLoop());
3299 base::MessageLoop::current()->Run(); 3300 base::RunLoop().Run();
3300 3301
3301 std::vector<Suggestion> suggestions = 3302 std::vector<Suggestion> suggestions =
3302 personal_data_->GetCreditCardSuggestions(AutofillType(CREDIT_CARD_NUMBER), 3303 personal_data_->GetCreditCardSuggestions(AutofillType(CREDIT_CARD_NUMBER),
3303 ASCIIToUTF16("12345678")); 3304 ASCIIToUTF16("12345678"));
3304 3305
3305 // There should be no suggestions. 3306 // There should be no suggestions.
3306 ASSERT_EQ(0U, suggestions.size()); 3307 ASSERT_EQ(0U, suggestions.size());
3307 } 3308 }
3308 3309
3309 // Test that local credit cards are ordered as expected. 3310 // Test that local credit cards are ordered as expected.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
3350 test::SetCreditCardInfo(&server_cards.back(), "Jesse James", "2109", "12", 3351 test::SetCreditCardInfo(&server_cards.back(), "Jesse James", "2109", "12",
3351 "3999"); 3352 "3999");
3352 server_cards.back().set_use_count(6); 3353 server_cards.back().set_use_count(6);
3353 server_cards.back().set_use_date(base::Time::Now() - 3354 server_cards.back().set_use_date(base::Time::Now() -
3354 base::TimeDelta::FromDays(1)); 3355 base::TimeDelta::FromDays(1));
3355 3356
3356 test::SetServerCreditCards(autofill_table_, server_cards); 3357 test::SetServerCreditCards(autofill_table_, server_cards);
3357 personal_data_->Refresh(); 3358 personal_data_->Refresh();
3358 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 3359 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
3359 .WillOnce(QuitMainMessageLoop()); 3360 .WillOnce(QuitMainMessageLoop());
3360 base::MessageLoop::current()->Run(); 3361 base::RunLoop().Run();
3361 3362
3362 std::vector<Suggestion> suggestions = 3363 std::vector<Suggestion> suggestions =
3363 personal_data_->GetCreditCardSuggestions( 3364 personal_data_->GetCreditCardSuggestions(
3364 AutofillType(CREDIT_CARD_NAME_FULL), 3365 AutofillType(CREDIT_CARD_NAME_FULL),
3365 /* field_contents= */ base::string16()); 3366 /* field_contents= */ base::string16());
3366 ASSERT_EQ(5U, suggestions.size()); 3367 ASSERT_EQ(5U, suggestions.size());
3367 3368
3368 // All cards should be ordered as expected. 3369 // All cards should be ordered as expected.
3369 EXPECT_EQ(ASCIIToUTF16("Jesse James"), suggestions[0].value); 3370 EXPECT_EQ(ASCIIToUTF16("Jesse James"), suggestions[0].value);
3370 EXPECT_EQ(ASCIIToUTF16("John Dillinger"), suggestions[1].value); 3371 EXPECT_EQ(ASCIIToUTF16("John Dillinger"), suggestions[1].value);
(...skipping 27 matching lines...) Expand all
3398 CreditCard credit_card2("1141084B-72D7-4B73-90CF-3D6AC154673B", 3399 CreditCard credit_card2("1141084B-72D7-4B73-90CF-3D6AC154673B",
3399 "https://www.example.com"); 3400 "https://www.example.com");
3400 credit_card2.set_use_count(3); 3401 credit_card2.set_use_count(3);
3401 credit_card2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1)); 3402 credit_card2.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(1));
3402 test::SetCreditCardInfo(&credit_card2, "John Dillinger", 3403 test::SetCreditCardInfo(&credit_card2, "John Dillinger",
3403 "423456789012" /* Visa */, "01", "1998"); 3404 "423456789012" /* Visa */, "01", "1998");
3404 personal_data_->AddCreditCard(credit_card2); 3405 personal_data_->AddCreditCard(credit_card2);
3405 3406
3406 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 3407 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
3407 .WillOnce(QuitMainMessageLoop()); 3408 .WillOnce(QuitMainMessageLoop());
3408 base::MessageLoop::current()->Run(); 3409 base::RunLoop().Run();
3409 3410
3410 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); 3411 ASSERT_EQ(3U, personal_data_->GetCreditCards().size());
3411 3412
3412 std::vector<Suggestion> suggestions = 3413 std::vector<Suggestion> suggestions =
3413 personal_data_->GetCreditCardSuggestions( 3414 personal_data_->GetCreditCardSuggestions(
3414 AutofillType(CREDIT_CARD_NAME_FULL), 3415 AutofillType(CREDIT_CARD_NAME_FULL),
3415 /* field_contents= */ base::string16()); 3416 /* field_contents= */ base::string16());
3416 ASSERT_EQ(3U, suggestions.size()); 3417 ASSERT_EQ(3U, suggestions.size());
3417 3418
3418 // The never used non expired card should be suggested first. 3419 // The never used non expired card should be suggested first.
(...skipping 20 matching lines...) Expand all
3439 3440
3440 CreditCard credit_card1("1141084B-72D7-4B73-90CF-3D6AC154673B", 3441 CreditCard credit_card1("1141084B-72D7-4B73-90CF-3D6AC154673B",
3441 "https://www.example.com"); 3442 "https://www.example.com");
3442 credit_card1.set_use_count(300); 3443 credit_card1.set_use_count(300);
3443 credit_card1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(10)); 3444 credit_card1.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(10));
3444 test::SetCreditCardInfo(&credit_card1, "John Dillinger", "", "01", "2999"); 3445 test::SetCreditCardInfo(&credit_card1, "John Dillinger", "", "01", "2999");
3445 personal_data_->AddCreditCard(credit_card1); 3446 personal_data_->AddCreditCard(credit_card1);
3446 3447
3447 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 3448 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
3448 .WillOnce(QuitMainMessageLoop()); 3449 .WillOnce(QuitMainMessageLoop());
3449 base::MessageLoop::current()->Run(); 3450 base::RunLoop().Run();
3450 3451
3451 ASSERT_EQ(2U, personal_data_->GetCreditCards().size()); 3452 ASSERT_EQ(2U, personal_data_->GetCreditCards().size());
3452 3453
3453 // Sublabel is expiration date when filling card number. The second card 3454 // Sublabel is expiration date when filling card number. The second card
3454 // doesn't have a number so it should not be included in the suggestions. 3455 // doesn't have a number so it should not be included in the suggestions.
3455 std::vector<Suggestion> suggestions = 3456 std::vector<Suggestion> suggestions =
3456 personal_data_->GetCreditCardSuggestions( 3457 personal_data_->GetCreditCardSuggestions(
3457 AutofillType(CREDIT_CARD_NUMBER), 3458 AutofillType(CREDIT_CARD_NUMBER),
3458 /* field_contents= */ base::string16()); 3459 /* field_contents= */ base::string16());
3459 ASSERT_EQ(1U, suggestions.size()); 3460 ASSERT_EQ(1U, suggestions.size());
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
3499 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", 3500 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow",
3500 "347666888555" /* American Express */, "04", "3999"); 3501 "347666888555" /* American Express */, "04", "3999");
3501 server_cards.back().set_use_count(1); 3502 server_cards.back().set_use_count(1);
3502 server_cards.back().set_use_date(base::Time::Now() - 3503 server_cards.back().set_use_date(base::Time::Now() -
3503 base::TimeDelta::FromDays(15)); 3504 base::TimeDelta::FromDays(15));
3504 3505
3505 test::SetServerCreditCards(autofill_table_, server_cards); 3506 test::SetServerCreditCards(autofill_table_, server_cards);
3506 personal_data_->Refresh(); 3507 personal_data_->Refresh();
3507 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 3508 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
3508 .WillOnce(QuitMainMessageLoop()); 3509 .WillOnce(QuitMainMessageLoop());
3509 base::MessageLoop::current()->Run(); 3510 base::RunLoop().Run();
3510 3511
3511 std::vector<Suggestion> suggestions = 3512 std::vector<Suggestion> suggestions =
3512 personal_data_->GetCreditCardSuggestions( 3513 personal_data_->GetCreditCardSuggestions(
3513 AutofillType(CREDIT_CARD_NAME_FULL), 3514 AutofillType(CREDIT_CARD_NAME_FULL),
3514 /* field_contents= */ base::string16()); 3515 /* field_contents= */ base::string16());
3515 ASSERT_EQ(4U, suggestions.size()); 3516 ASSERT_EQ(4U, suggestions.size());
3516 EXPECT_EQ(ASCIIToUTF16("John Dillinger"), suggestions[0].value); 3517 EXPECT_EQ(ASCIIToUTF16("John Dillinger"), suggestions[0].value);
3517 EXPECT_EQ(ASCIIToUTF16("Clyde Barrow"), suggestions[1].value); 3518 EXPECT_EQ(ASCIIToUTF16("Clyde Barrow"), suggestions[1].value);
3518 EXPECT_EQ(ASCIIToUTF16("Bonnie Parker"), suggestions[2].value); 3519 EXPECT_EQ(ASCIIToUTF16("Bonnie Parker"), suggestions[2].value);
3519 EXPECT_EQ(ASCIIToUTF16("Bonnie Parker"), suggestions[3].value); 3520 EXPECT_EQ(ASCIIToUTF16("Bonnie Parker"), suggestions[3].value);
(...skipping 26 matching lines...) Expand all
3546 // This unmasked server card is an exact dupe of a local card. Therefore only 3547 // This unmasked server card is an exact dupe of a local card. Therefore only
3547 // the local card should appear in the suggestions. 3548 // the local card should appear in the suggestions.
3548 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); 3549 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789"));
3549 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", 3550 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow",
3550 "347666888555" /* American Express */, "04", "3999"); 3551 "347666888555" /* American Express */, "04", "3999");
3551 3552
3552 test::SetServerCreditCards(autofill_table_, server_cards); 3553 test::SetServerCreditCards(autofill_table_, server_cards);
3553 personal_data_->Refresh(); 3554 personal_data_->Refresh();
3554 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 3555 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
3555 .WillOnce(QuitMainMessageLoop()); 3556 .WillOnce(QuitMainMessageLoop());
3556 base::MessageLoop::current()->Run(); 3557 base::RunLoop().Run();
3557 3558
3558 std::vector<Suggestion> suggestions = 3559 std::vector<Suggestion> suggestions =
3559 personal_data_->GetCreditCardSuggestions( 3560 personal_data_->GetCreditCardSuggestions(
3560 AutofillType(CREDIT_CARD_NAME_FULL), 3561 AutofillType(CREDIT_CARD_NAME_FULL),
3561 /* field_contents= */ base::string16()); 3562 /* field_contents= */ base::string16());
3562 ASSERT_EQ(3U, suggestions.size()); 3563 ASSERT_EQ(3U, suggestions.size());
3563 3564
3564 // Add a second dupe local card to make sure a full server card can be a dupe 3565 // Add a second dupe local card to make sure a full server card can be a dupe
3565 // of more than one local card. 3566 // of more than one local card.
3566 CreditCard credit_card3("4141084B-72D7-4B73-90CF-3D6AC154673B", 3567 CreditCard credit_card3("4141084B-72D7-4B73-90CF-3D6AC154673B",
3567 "https://www.example.com"); 3568 "https://www.example.com");
3568 test::SetCreditCardInfo(&credit_card3, "Clyde Barrow", "", "04", ""); 3569 test::SetCreditCardInfo(&credit_card3, "Clyde Barrow", "", "04", "");
3569 personal_data_->AddCreditCard(credit_card3); 3570 personal_data_->AddCreditCard(credit_card3);
3570 3571
3571 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 3572 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
3572 .WillOnce(QuitMainMessageLoop()); 3573 .WillOnce(QuitMainMessageLoop());
3573 base::MessageLoop::current()->Run(); 3574 base::RunLoop().Run();
3574 3575
3575 suggestions = personal_data_->GetCreditCardSuggestions( 3576 suggestions = personal_data_->GetCreditCardSuggestions(
3576 AutofillType(CREDIT_CARD_NAME_FULL), 3577 AutofillType(CREDIT_CARD_NAME_FULL),
3577 /* field_contents= */ base::string16()); 3578 /* field_contents= */ base::string16());
3578 ASSERT_EQ(3U, suggestions.size()); 3579 ASSERT_EQ(3U, suggestions.size());
3579 } 3580 }
3580 3581
3581 // Tests that only the full server card is kept when deduping with a local 3582 // Tests that only the full server card is kept when deduping with a local
3582 // duplicate of it. 3583 // duplicate of it.
3583 TEST_F(PersonalDataManagerTest, 3584 TEST_F(PersonalDataManagerTest,
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
3714 "423456789012" /* Visa */, "01", "2999"); 3715 "423456789012" /* Visa */, "01", "2999");
3715 credit_card.set_use_date(creation_time); 3716 credit_card.set_use_date(creation_time);
3716 credit_card.set_modification_date(creation_time); 3717 credit_card.set_modification_date(creation_time);
3717 EXPECT_EQ(1U, credit_card.use_count()); 3718 EXPECT_EQ(1U, credit_card.use_count());
3718 EXPECT_EQ(creation_time, credit_card.use_date()); 3719 EXPECT_EQ(creation_time, credit_card.use_date());
3719 EXPECT_EQ(creation_time, credit_card.modification_date()); 3720 EXPECT_EQ(creation_time, credit_card.modification_date());
3720 personal_data_->AddCreditCard(credit_card); 3721 personal_data_->AddCreditCard(credit_card);
3721 3722
3722 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 3723 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
3723 .WillOnce(QuitMainMessageLoop()); 3724 .WillOnce(QuitMainMessageLoop());
3724 base::MessageLoop::current()->Run(); 3725 base::RunLoop().Run();
3725 3726
3726 // Notify the PDM that the profile and credit card were used. 3727 // Notify the PDM that the profile and credit card were used.
3727 AutofillProfile* added_profile = 3728 AutofillProfile* added_profile =
3728 personal_data_->GetProfileByGUID(profile.guid()); 3729 personal_data_->GetProfileByGUID(profile.guid());
3729 ASSERT_TRUE(added_profile); 3730 ASSERT_TRUE(added_profile);
3730 EXPECT_EQ(*added_profile, profile); 3731 EXPECT_EQ(*added_profile, profile);
3731 EXPECT_EQ(1U, added_profile->use_count()); 3732 EXPECT_EQ(1U, added_profile->use_count());
3732 EXPECT_EQ(creation_time, added_profile->use_date()); 3733 EXPECT_EQ(creation_time, added_profile->use_date());
3733 EXPECT_NE(creation_time, added_profile->modification_date()); 3734 EXPECT_NE(creation_time, added_profile->modification_date());
3734 personal_data_->RecordUseOf(profile); 3735 personal_data_->RecordUseOf(profile);
3735 3736
3736 CreditCard* added_card = 3737 CreditCard* added_card =
3737 personal_data_->GetCreditCardByGUID(credit_card.guid()); 3738 personal_data_->GetCreditCardByGUID(credit_card.guid());
3738 ASSERT_TRUE(added_card); 3739 ASSERT_TRUE(added_card);
3739 EXPECT_EQ(*added_card, credit_card); 3740 EXPECT_EQ(*added_card, credit_card);
3740 EXPECT_EQ(1U, added_card->use_count()); 3741 EXPECT_EQ(1U, added_card->use_count());
3741 EXPECT_EQ(creation_time, added_card->use_date()); 3742 EXPECT_EQ(creation_time, added_card->use_date());
3742 EXPECT_NE(creation_time, added_card->modification_date()); 3743 EXPECT_NE(creation_time, added_card->modification_date());
3743 personal_data_->RecordUseOf(credit_card); 3744 personal_data_->RecordUseOf(credit_card);
3744 3745
3745 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 3746 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
3746 .WillOnce(QuitMainMessageLoop()); 3747 .WillOnce(QuitMainMessageLoop());
3747 base::MessageLoop::current()->Run(); 3748 base::RunLoop().Run();
3748 3749
3749 // Verify usage stats are updated. 3750 // Verify usage stats are updated.
3750 added_profile = personal_data_->GetProfileByGUID(profile.guid()); 3751 added_profile = personal_data_->GetProfileByGUID(profile.guid());
3751 ASSERT_TRUE(added_profile); 3752 ASSERT_TRUE(added_profile);
3752 EXPECT_EQ(2U, added_profile->use_count()); 3753 EXPECT_EQ(2U, added_profile->use_count());
3753 EXPECT_NE(creation_time, added_profile->use_date()); 3754 EXPECT_NE(creation_time, added_profile->use_date());
3754 EXPECT_NE(creation_time, added_profile->modification_date()); 3755 EXPECT_NE(creation_time, added_profile->modification_date());
3755 3756
3756 added_card = personal_data_->GetCreditCardByGUID(credit_card.guid()); 3757 added_card = personal_data_->GetCreditCardByGUID(credit_card.guid());
3757 ASSERT_TRUE(added_card); 3758 ASSERT_TRUE(added_card);
(...skipping 18 matching lines...) Expand all
3776 3777
3777 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); 3778 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789"));
3778 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", 3779 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow",
3779 "347666888555" /* American Express */, "04", "3999"); 3780 "347666888555" /* American Express */, "04", "3999");
3780 3781
3781 test::SetServerCreditCards(autofill_table_, server_cards); 3782 test::SetServerCreditCards(autofill_table_, server_cards);
3782 personal_data_->Refresh(); 3783 personal_data_->Refresh();
3783 3784
3784 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 3785 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
3785 .WillOnce(QuitMainMessageLoop()); 3786 .WillOnce(QuitMainMessageLoop());
3786 base::MessageLoop::current()->Run(); 3787 base::RunLoop().Run();
3787 3788
3788 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); 3789 ASSERT_EQ(3U, personal_data_->GetCreditCards().size());
3789 3790
3790 if (!OfferStoreUnmaskedCards()) { 3791 if (!OfferStoreUnmaskedCards()) {
3791 for (CreditCard* card : personal_data_->GetCreditCards()) { 3792 for (CreditCard* card : personal_data_->GetCreditCards()) {
3792 EXPECT_EQ(CreditCard::MASKED_SERVER_CARD, card->record_type()); 3793 EXPECT_EQ(CreditCard::MASKED_SERVER_CARD, card->record_type());
3793 } 3794 }
3794 // The rest of this test doesn't work if we're force-masking all unmasked 3795 // The rest of this test doesn't work if we're force-masking all unmasked
3795 // cards. 3796 // cards.
3796 return; 3797 return;
3797 } 3798 }
3798 3799
3799 // The GUIDs will be different, so just compare the data. 3800 // The GUIDs will be different, so just compare the data.
3800 for (size_t i = 0; i < 3; ++i) 3801 for (size_t i = 0; i < 3; ++i)
3801 EXPECT_EQ(0, server_cards[i].Compare(*personal_data_->GetCreditCards()[i])); 3802 EXPECT_EQ(0, server_cards[i].Compare(*personal_data_->GetCreditCards()[i]));
3802 3803
3803 CreditCard* unmasked_card = &server_cards.front(); 3804 CreditCard* unmasked_card = &server_cards.front();
3804 unmasked_card->set_record_type(CreditCard::FULL_SERVER_CARD); 3805 unmasked_card->set_record_type(CreditCard::FULL_SERVER_CARD);
3805 unmasked_card->SetNumber(ASCIIToUTF16("423456789012")); 3806 unmasked_card->SetNumber(ASCIIToUTF16("423456789012"));
3806 EXPECT_NE(0, unmasked_card->Compare( 3807 EXPECT_NE(0, unmasked_card->Compare(
3807 *personal_data_->GetCreditCards().front())); 3808 *personal_data_->GetCreditCards().front()));
3808 personal_data_->UpdateServerCreditCard(*unmasked_card); 3809 personal_data_->UpdateServerCreditCard(*unmasked_card);
3809 3810
3810 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 3811 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
3811 .WillOnce(QuitMainMessageLoop()); 3812 .WillOnce(QuitMainMessageLoop());
3812 base::MessageLoop::current()->Run(); 3813 base::RunLoop().Run();
3813 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); 3814 ASSERT_EQ(3U, personal_data_->GetCreditCards().size());
3814 3815
3815 for (size_t i = 0; i < 3; ++i) 3816 for (size_t i = 0; i < 3; ++i)
3816 EXPECT_EQ(0, server_cards[i].Compare(*personal_data_->GetCreditCards()[i])); 3817 EXPECT_EQ(0, server_cards[i].Compare(*personal_data_->GetCreditCards()[i]));
3817 3818
3818 // For an unmasked card, usage data starts out as 2 because of the unmasking 3819 // For an unmasked card, usage data starts out as 2 because of the unmasking
3819 // which is considered a use. 3820 // which is considered a use.
3820 EXPECT_EQ(2U, personal_data_->GetCreditCards()[0]->use_count()); 3821 EXPECT_EQ(2U, personal_data_->GetCreditCards()[0]->use_count());
3821 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[0]->use_date()); 3822 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[0]->use_date());
3822 3823
3823 EXPECT_EQ(1U, personal_data_->GetCreditCards()[1]->use_count()); 3824 EXPECT_EQ(1U, personal_data_->GetCreditCards()[1]->use_count());
3824 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[1]->use_date()); 3825 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[1]->use_date());
3825 3826
3826 // Having unmasked this card, usage stats should be 2 and Now(). 3827 // Having unmasked this card, usage stats should be 2 and Now().
3827 EXPECT_EQ(2U, personal_data_->GetCreditCards()[2]->use_count()); 3828 EXPECT_EQ(2U, personal_data_->GetCreditCards()[2]->use_count());
3828 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[2]->use_date()); 3829 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[2]->use_date());
3829 base::Time initial_use_date = personal_data_->GetCreditCards()[2]->use_date(); 3830 base::Time initial_use_date = personal_data_->GetCreditCards()[2]->use_date();
3830 3831
3831 server_cards.back().set_guid(personal_data_->GetCreditCards()[2]->guid()); 3832 server_cards.back().set_guid(personal_data_->GetCreditCards()[2]->guid());
3832 personal_data_->RecordUseOf(server_cards.back()); 3833 personal_data_->RecordUseOf(server_cards.back());
3833 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 3834 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
3834 .WillOnce(QuitMainMessageLoop()); 3835 .WillOnce(QuitMainMessageLoop());
3835 base::MessageLoop::current()->Run(); 3836 base::RunLoop().Run();
3836 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); 3837 ASSERT_EQ(3U, personal_data_->GetCreditCards().size());
3837 3838
3838 EXPECT_EQ(2U, personal_data_->GetCreditCards()[0]->use_count()); 3839 EXPECT_EQ(2U, personal_data_->GetCreditCards()[0]->use_count());
3839 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[0]->use_date()); 3840 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[0]->use_date());
3840 3841
3841 EXPECT_EQ(1U, personal_data_->GetCreditCards()[1]->use_count()); 3842 EXPECT_EQ(1U, personal_data_->GetCreditCards()[1]->use_count());
3842 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[1]->use_date()); 3843 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[1]->use_date());
3843 3844
3844 EXPECT_EQ(3U, personal_data_->GetCreditCards()[2]->use_count()); 3845 EXPECT_EQ(3U, personal_data_->GetCreditCards()[2]->use_count());
3845 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[2]->use_date()); 3846 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[2]->use_date());
3846 // Time may or may not have elapsed between unmasking and RecordUseOf. 3847 // Time may or may not have elapsed between unmasking and RecordUseOf.
3847 EXPECT_LE(initial_use_date, personal_data_->GetCreditCards()[2]->use_date()); 3848 EXPECT_LE(initial_use_date, personal_data_->GetCreditCards()[2]->use_date());
3848 3849
3849 // Can record usage stats on masked cards. 3850 // Can record usage stats on masked cards.
3850 server_cards[1].set_guid(personal_data_->GetCreditCards()[1]->guid()); 3851 server_cards[1].set_guid(personal_data_->GetCreditCards()[1]->guid());
3851 personal_data_->RecordUseOf(server_cards[1]); 3852 personal_data_->RecordUseOf(server_cards[1]);
3852 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 3853 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
3853 .WillOnce(QuitMainMessageLoop()); 3854 .WillOnce(QuitMainMessageLoop());
3854 base::MessageLoop::current()->Run(); 3855 base::RunLoop().Run();
3855 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); 3856 ASSERT_EQ(3U, personal_data_->GetCreditCards().size());
3856 EXPECT_EQ(2U, personal_data_->GetCreditCards()[1]->use_count()); 3857 EXPECT_EQ(2U, personal_data_->GetCreditCards()[1]->use_count());
3857 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[1]->use_date()); 3858 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[1]->use_date());
3858 3859
3859 // Upgrading to unmasked retains the usage stats (and increments them). 3860 // Upgrading to unmasked retains the usage stats (and increments them).
3860 CreditCard* unmasked_card2 = &server_cards[1]; 3861 CreditCard* unmasked_card2 = &server_cards[1];
3861 unmasked_card2->set_record_type(CreditCard::FULL_SERVER_CARD); 3862 unmasked_card2->set_record_type(CreditCard::FULL_SERVER_CARD);
3862 unmasked_card2->SetNumber(ASCIIToUTF16("5555555555554444")); 3863 unmasked_card2->SetNumber(ASCIIToUTF16("5555555555554444"));
3863 personal_data_->UpdateServerCreditCard(*unmasked_card2); 3864 personal_data_->UpdateServerCreditCard(*unmasked_card2);
3864 3865
3865 server_cards[1].set_guid(personal_data_->GetCreditCards()[1]->guid()); 3866 server_cards[1].set_guid(personal_data_->GetCreditCards()[1]->guid());
3866 personal_data_->RecordUseOf(server_cards[1]); 3867 personal_data_->RecordUseOf(server_cards[1]);
3867 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 3868 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
3868 .WillOnce(QuitMainMessageLoop()); 3869 .WillOnce(QuitMainMessageLoop());
3869 base::MessageLoop::current()->Run(); 3870 base::RunLoop().Run();
3870 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); 3871 ASSERT_EQ(3U, personal_data_->GetCreditCards().size());
3871 EXPECT_EQ(3U, personal_data_->GetCreditCards()[1]->use_count()); 3872 EXPECT_EQ(3U, personal_data_->GetCreditCards()[1]->use_count());
3872 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[1]->use_date()); 3873 EXPECT_NE(base::Time(), personal_data_->GetCreditCards()[1]->use_date());
3873 } 3874 }
3874 3875
3875 TEST_F(PersonalDataManagerTest, ClearAllServerData) { 3876 TEST_F(PersonalDataManagerTest, ClearAllServerData) {
3876 // Add a server card. 3877 // Add a server card.
3877 std::vector<CreditCard> server_cards; 3878 std::vector<CreditCard> server_cards;
3878 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); 3879 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123"));
3879 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", 3880 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger",
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
3917 server_cards.back().SetTypeForMaskedCard(kVisaCard); 3918 server_cards.back().SetTypeForMaskedCard(kVisaCard);
3918 3919
3919 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); 3920 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789"));
3920 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", 3921 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow",
3921 "347666888555" /* American Express */, "04", "3999"); 3922 "347666888555" /* American Express */, "04", "3999");
3922 3923
3923 test::SetServerCreditCards(autofill_table_, server_cards); 3924 test::SetServerCreditCards(autofill_table_, server_cards);
3924 personal_data_->Refresh(); 3925 personal_data_->Refresh();
3925 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 3926 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
3926 .WillOnce(QuitMainMessageLoop()); 3927 .WillOnce(QuitMainMessageLoop());
3927 base::MessageLoop::current()->Run(); 3928 base::RunLoop().Run();
3928 3929
3929 // A valid credit card form. A user re-enters one of their masked cards. 3930 // A valid credit card form. A user re-enters one of their masked cards.
3930 // We shouldn't offer to save. It's possible this is actually a different card 3931 // We shouldn't offer to save. It's possible this is actually a different card
3931 // but it's very unlikely. And these circumstances will also arise if the user 3932 // but it's very unlikely. And these circumstances will also arise if the user
3932 // has the same card available locally and synced from payments. 3933 // has the same card available locally and synced from payments.
3933 FormData form1; 3934 FormData form1;
3934 FormFieldData field; 3935 FormFieldData field;
3935 test::CreateTestFormField("Name on card:", "name_on_card", "John Dillinger", 3936 test::CreateTestFormField("Name on card:", "name_on_card", "John Dillinger",
3936 "text", &field); 3937 "text", &field);
3937 form1.fields.push_back(field); 3938 form1.fields.push_back(field);
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
4473 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.", 4474 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.",
4474 "", "Springfield", "IL", "91601", "", ""); 4475 "", "Springfield", "IL", "91601", "", "");
4475 profile3.set_use_count(3); 4476 profile3.set_use_count(3);
4476 profile3.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5)); 4477 profile3.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5));
4477 4478
4478 personal_data_->AddProfile(profile1); 4479 personal_data_->AddProfile(profile1);
4479 personal_data_->AddProfile(profile2); 4480 personal_data_->AddProfile(profile2);
4480 personal_data_->AddProfile(profile3); 4481 personal_data_->AddProfile(profile3);
4481 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 4482 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
4482 .WillOnce(QuitMainMessageLoop()); 4483 .WillOnce(QuitMainMessageLoop());
4483 base::MessageLoop::current()->Run(); 4484 base::RunLoop().Run();
4484 4485
4485 // Make sure the 3 profiles were saved; 4486 // Make sure the 3 profiles were saved;
4486 EXPECT_EQ(3U, personal_data_->GetProfiles().size()); 4487 EXPECT_EQ(3U, personal_data_->GetProfiles().size());
4487 4488
4488 // Enable the profile cleanup now. Otherwise it would be triggered by the 4489 // Enable the profile cleanup now. Otherwise it would be triggered by the
4489 // calls to AddProfile. 4490 // calls to AddProfile.
4490 EnableAutofillProfileCleanup(); 4491 EnableAutofillProfileCleanup();
4491 4492
4492 base::HistogramTester histogram_tester; 4493 base::HistogramTester histogram_tester;
4493 4494
4494 personal_data_->ApplyDedupingRoutine(); 4495 personal_data_->ApplyDedupingRoutine();
4495 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 4496 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
4496 .WillOnce(QuitMainMessageLoop()); 4497 .WillOnce(QuitMainMessageLoop());
4497 base::MessageLoop::current()->Run(); 4498 base::RunLoop().Run();
4498 4499
4499 std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles(); 4500 std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles();
4500 4501
4501 // |profile1| should have been merged into |profile2| which should then have 4502 // |profile1| should have been merged into |profile2| which should then have
4502 // been merged into |profile3|. Therefore there should only be 1 saved 4503 // been merged into |profile3|. Therefore there should only be 1 saved
4503 // profile. 4504 // profile.
4504 ASSERT_EQ(1U, profiles.size()); 4505 ASSERT_EQ(1U, profiles.size());
4505 // 3 profiles were considered for dedupe. 4506 // 3 profiles were considered for dedupe.
4506 histogram_tester.ExpectUniqueSample( 4507 histogram_tester.ExpectUniqueSample(
4507 "Autofill.NumberOfProfilesConsideredForDedupe", 3, 1); 4508 "Autofill.NumberOfProfilesConsideredForDedupe", 3, 1);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
4566 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.", 4567 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.",
4567 "", "Springfield", "IL", "91601", "", ""); 4568 "", "Springfield", "IL", "91601", "", "");
4568 profile3.set_use_count(3); 4569 profile3.set_use_count(3);
4569 profile3.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5)); 4570 profile3.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5));
4570 4571
4571 personal_data_->AddProfile(profile1); 4572 personal_data_->AddProfile(profile1);
4572 personal_data_->AddProfile(profile2); 4573 personal_data_->AddProfile(profile2);
4573 personal_data_->AddProfile(profile3); 4574 personal_data_->AddProfile(profile3);
4574 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 4575 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
4575 .WillOnce(QuitMainMessageLoop()); 4576 .WillOnce(QuitMainMessageLoop());
4576 base::MessageLoop::current()->Run(); 4577 base::RunLoop().Run();
4577 4578
4578 // Make sure the 3 profiles were saved. 4579 // Make sure the 3 profiles were saved.
4579 EXPECT_EQ(3U, personal_data_->GetProfiles().size()); 4580 EXPECT_EQ(3U, personal_data_->GetProfiles().size());
4580 4581
4581 // Enable the profile cleanup now. Otherwise it would be triggered by the 4582 // Enable the profile cleanup now. Otherwise it would be triggered by the
4582 // calls to AddProfile. 4583 // calls to AddProfile.
4583 EnableAutofillProfileCleanup(); 4584 EnableAutofillProfileCleanup();
4584 4585
4585 base::HistogramTester histogram_tester; 4586 base::HistogramTester histogram_tester;
4586 4587
4587 personal_data_->ApplyDedupingRoutine(); 4588 personal_data_->ApplyDedupingRoutine();
4588 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 4589 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
4589 .WillOnce(QuitMainMessageLoop()); 4590 .WillOnce(QuitMainMessageLoop());
4590 base::MessageLoop::current()->Run(); 4591 base::RunLoop().Run();
4591 4592
4592 std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles(); 4593 std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles();
4593 4594
4594 // |profile2| should have merged with |profile3|. |profile3| 4595 // |profile2| should have merged with |profile3|. |profile3|
4595 // should then have been discarded because it is similar to the verified 4596 // should then have been discarded because it is similar to the verified
4596 // |profile1|. 4597 // |profile1|.
4597 ASSERT_EQ(1U, profiles.size()); 4598 ASSERT_EQ(1U, profiles.size());
4598 // 3 profiles were considered for dedupe. 4599 // 3 profiles were considered for dedupe.
4599 histogram_tester.ExpectUniqueSample( 4600 histogram_tester.ExpectUniqueSample(
4600 "Autofill.NumberOfProfilesConsideredForDedupe", 3, 1); 4601 "Autofill.NumberOfProfilesConsideredForDedupe", 3, 1);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
4638 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", 4639 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "",
4639 "Springfield", "IL", "91601", "", "12345678910"); 4640 "Springfield", "IL", "91601", "", "12345678910");
4640 profile3.set_use_count(3); 4641 profile3.set_use_count(3);
4641 profile3.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5)); 4642 profile3.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5));
4642 4643
4643 personal_data_->AddProfile(profile1); 4644 personal_data_->AddProfile(profile1);
4644 personal_data_->AddProfile(profile2); 4645 personal_data_->AddProfile(profile2);
4645 personal_data_->AddProfile(profile3); 4646 personal_data_->AddProfile(profile3);
4646 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 4647 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
4647 .WillOnce(QuitMainMessageLoop()); 4648 .WillOnce(QuitMainMessageLoop());
4648 base::MessageLoop::current()->Run(); 4649 base::RunLoop().Run();
4649 4650
4650 // Make sure the 3 profiles were saved. 4651 // Make sure the 3 profiles were saved.
4651 EXPECT_EQ(3U, personal_data_->GetProfiles().size()); 4652 EXPECT_EQ(3U, personal_data_->GetProfiles().size());
4652 4653
4653 // Enable the profile cleanup now. Otherwise it would be triggered by the 4654 // Enable the profile cleanup now. Otherwise it would be triggered by the
4654 // calls to AddProfile. 4655 // calls to AddProfile.
4655 EnableAutofillProfileCleanup(); 4656 EnableAutofillProfileCleanup();
4656 4657
4657 base::HistogramTester histogram_tester; 4658 base::HistogramTester histogram_tester;
4658 4659
4659 personal_data_->ApplyDedupingRoutine(); 4660 personal_data_->ApplyDedupingRoutine();
4660 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 4661 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
4661 .WillOnce(QuitMainMessageLoop()); 4662 .WillOnce(QuitMainMessageLoop());
4662 base::MessageLoop::current()->Run(); 4663 base::RunLoop().Run();
4663 4664
4664 std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles(); 4665 std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles();
4665 4666
4666 // |profile1| should have merged with |profile2|. |profile2| 4667 // |profile1| should have merged with |profile2|. |profile2|
4667 // should then have been discarded because it is similar to the verified 4668 // should then have been discarded because it is similar to the verified
4668 // |profile3|. 4669 // |profile3|.
4669 ASSERT_EQ(1U, profiles.size()); 4670 ASSERT_EQ(1U, profiles.size());
4670 // 3 profiles were considered for dedupe. 4671 // 3 profiles were considered for dedupe.
4671 histogram_tester.ExpectUniqueSample( 4672 histogram_tester.ExpectUniqueSample(
4672 "Autofill.NumberOfProfilesConsideredForDedupe", 3, 1); 4673 "Autofill.NumberOfProfilesConsideredForDedupe", 3, 1);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
4709 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", 4710 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "",
4710 "Springfield", "IL", "91601", "", "12345678910"); 4711 "Springfield", "IL", "91601", "", "12345678910");
4711 profile3.set_use_count(3); 4712 profile3.set_use_count(3);
4712 profile3.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5)); 4713 profile3.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(5));
4713 4714
4714 personal_data_->AddProfile(profile1); 4715 personal_data_->AddProfile(profile1);
4715 personal_data_->AddProfile(profile2); 4716 personal_data_->AddProfile(profile2);
4716 personal_data_->AddProfile(profile3); 4717 personal_data_->AddProfile(profile3);
4717 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 4718 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
4718 .WillOnce(QuitMainMessageLoop()); 4719 .WillOnce(QuitMainMessageLoop());
4719 base::MessageLoop::current()->Run(); 4720 base::RunLoop().Run();
4720 4721
4721 // Make sure the 3 profiles were saved. 4722 // Make sure the 3 profiles were saved.
4722 EXPECT_EQ(3U, personal_data_->GetProfiles().size()); 4723 EXPECT_EQ(3U, personal_data_->GetProfiles().size());
4723 4724
4724 // Enable the profile cleanup now. Otherwise it would be triggered by the 4725 // Enable the profile cleanup now. Otherwise it would be triggered by the
4725 // calls to AddProfile. 4726 // calls to AddProfile.
4726 EnableAutofillProfileCleanup(); 4727 EnableAutofillProfileCleanup();
4727 4728
4728 base::HistogramTester histogram_tester; 4729 base::HistogramTester histogram_tester;
4729 4730
4730 personal_data_->ApplyDedupingRoutine(); 4731 personal_data_->ApplyDedupingRoutine();
4731 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 4732 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
4732 .WillOnce(QuitMainMessageLoop()); 4733 .WillOnce(QuitMainMessageLoop());
4733 base::MessageLoop::current()->Run(); 4734 base::RunLoop().Run();
4734 4735
4735 // Get the profiles, sorted by frecency to have a deterministic order. 4736 // Get the profiles, sorted by frecency to have a deterministic order.
4736 std::vector<AutofillProfile*> profiles = 4737 std::vector<AutofillProfile*> profiles =
4737 personal_data_->GetProfilesToSuggest(); 4738 personal_data_->GetProfilesToSuggest();
4738 4739
4739 // |profile1| should have been discarded because the saved profile with the 4740 // |profile1| should have been discarded because the saved profile with the
4740 // highest frecency score is verified (|profile2|). Therefore, |profile1|'s 4741 // highest frecency score is verified (|profile2|). Therefore, |profile1|'s
4741 // data should not have been merged with |profile2|'s data. Then |profile2| 4742 // data should not have been merged with |profile2|'s data. Then |profile2|
4742 // should have been compared to |profile3| but they should not have merged 4743 // should have been compared to |profile3| but they should not have merged
4743 // because both profiles are verified. 4744 // because both profiles are verified.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
4785 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); 4786 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com");
4786 test::SetProfileInfo(&profile2, "Marge", "", "Simpson", 4787 test::SetProfileInfo(&profile2, "Marge", "", "Simpson",
4787 "homer.simpson@abc.com", "SNP", "742 Evergreen Terrace", 4788 "homer.simpson@abc.com", "SNP", "742 Evergreen Terrace",
4788 "", "Springfield", "IL", "91601", "US", "12345678910"); 4789 "", "Springfield", "IL", "91601", "US", "12345678910");
4789 profile2.set_use_date(base::Time()); 4790 profile2.set_use_date(base::Time());
4790 4791
4791 personal_data_->AddProfile(profile1); 4792 personal_data_->AddProfile(profile1);
4792 personal_data_->AddProfile(profile2); 4793 personal_data_->AddProfile(profile2);
4793 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 4794 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
4794 .WillOnce(QuitMainMessageLoop()); 4795 .WillOnce(QuitMainMessageLoop());
4795 base::MessageLoop::current()->Run(); 4796 base::RunLoop().Run();
4796 4797
4797 // Get a sorted list of profiles. |profile1| will be first and |profile2| will 4798 // Get a sorted list of profiles. |profile1| will be first and |profile2| will
4798 // be second. 4799 // be second.
4799 std::vector<AutofillProfile*> saved_profiles = 4800 std::vector<AutofillProfile*> saved_profiles =
4800 personal_data_->GetProfilesToSuggest(); 4801 personal_data_->GetProfilesToSuggest();
4801 4802
4802 ASSERT_EQ(2U, saved_profiles.size()); 4803 ASSERT_EQ(2U, saved_profiles.size());
4803 4804
4804 // The use dates should not have been modified. 4805 // The use dates should not have been modified.
4805 EXPECT_LE(base::Time::Now() - base::TimeDelta::FromDays(1), 4806 EXPECT_LE(base::Time::Now() - base::TimeDelta::FromDays(1),
4806 saved_profiles[0]->use_date()); 4807 saved_profiles[0]->use_date());
4807 EXPECT_EQ(base::Time(), saved_profiles[1]->use_date()); 4808 EXPECT_EQ(base::Time(), saved_profiles[1]->use_date());
4808 4809
4809 // Set the pref to false to indicate the fix has never been run. 4810 // Set the pref to false to indicate the fix has never been run.
4810 personal_data_->pref_service_->SetBoolean( 4811 personal_data_->pref_service_->SetBoolean(
4811 prefs::kAutofillProfileUseDatesFixed, false); 4812 prefs::kAutofillProfileUseDatesFixed, false);
4812 4813
4813 personal_data_->ApplyProfileUseDatesFix(); 4814 personal_data_->ApplyProfileUseDatesFix();
4814 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 4815 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
4815 .WillOnce(QuitMainMessageLoop()); 4816 .WillOnce(QuitMainMessageLoop());
4816 base::MessageLoop::current()->Run(); 4817 base::RunLoop().Run();
4817 4818
4818 // Get a sorted list of profiles. 4819 // Get a sorted list of profiles.
4819 saved_profiles = personal_data_->GetProfilesToSuggest(); 4820 saved_profiles = personal_data_->GetProfilesToSuggest();
4820 4821
4821 ASSERT_EQ(2U, saved_profiles.size()); 4822 ASSERT_EQ(2U, saved_profiles.size());
4822 4823
4823 // |profile1|'s use date should not have been modified. 4824 // |profile1|'s use date should not have been modified.
4824 EXPECT_LE(base::Time::Now() - base::TimeDelta::FromDays(1), 4825 EXPECT_LE(base::Time::Now() - base::TimeDelta::FromDays(1),
4825 saved_profiles[0]->use_date()); 4826 saved_profiles[0]->use_date());
4826 // |profile2|'s use date should have been set to two weeks before now. 4827 // |profile2|'s use date should have been set to two weeks before now.
(...skipping 20 matching lines...) Expand all
4847 test::SetProfileInfo(&profile2, "Marge", "", "Simpson", 4848 test::SetProfileInfo(&profile2, "Marge", "", "Simpson",
4848 "homer.simpson@abc.com", "SNP", "742 Evergreen Terrace", 4849 "homer.simpson@abc.com", "SNP", "742 Evergreen Terrace",
4849 "", "Springfield", "IL", "91601", "US", "12345678910"); 4850 "", "Springfield", "IL", "91601", "US", "12345678910");
4850 profile2.set_use_date(base::Time()); 4851 profile2.set_use_date(base::Time());
4851 4852
4852 personal_data_->AddProfile(profile1); 4853 personal_data_->AddProfile(profile1);
4853 personal_data_->AddProfile(profile2); 4854 personal_data_->AddProfile(profile2);
4854 4855
4855 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 4856 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
4856 .WillOnce(QuitMainMessageLoop()); 4857 .WillOnce(QuitMainMessageLoop());
4857 base::MessageLoop::current()->Run(); 4858 base::RunLoop().Run();
4858 4859
4859 // Get a sorted list of profiles. |profile1| will be first and |profile2| will 4860 // Get a sorted list of profiles. |profile1| will be first and |profile2| will
4860 // be second. 4861 // be second.
4861 std::vector<AutofillProfile*> saved_profiles = 4862 std::vector<AutofillProfile*> saved_profiles =
4862 personal_data_->GetProfilesToSuggest(); 4863 personal_data_->GetProfilesToSuggest();
4863 4864
4864 ASSERT_EQ(2U, saved_profiles.size()); 4865 ASSERT_EQ(2U, saved_profiles.size());
4865 // The use dates should not have been modified. 4866 // The use dates should not have been modified.
4866 EXPECT_LE(base::Time::Now() - base::TimeDelta::FromDays(1), 4867 EXPECT_LE(base::Time::Now() - base::TimeDelta::FromDays(1),
4867 saved_profiles[0]->use_date()); 4868 saved_profiles[0]->use_date());
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
5106 EnableAutofillProfileCleanup(); 5107 EnableAutofillProfileCleanup();
5107 5108
5108 // The deduping routine should not be run. 5109 // The deduping routine should not be run.
5109 EXPECT_FALSE(personal_data_->ApplyDedupingRoutine()); 5110 EXPECT_FALSE(personal_data_->ApplyDedupingRoutine());
5110 5111
5111 // The two duplicate profiles should still be present. 5112 // The two duplicate profiles should still be present.
5112 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); 5113 EXPECT_EQ(2U, personal_data_->GetProfiles().size());
5113 } 5114 }
5114 5115
5115 } // namespace autofill 5116 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698