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

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

Issue 2844463004: Rename card 'type' into 'issuer network.' (Closed)
Patch Set: read -> use Created 3 years, 8 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>
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 #include "components/signin/core/browser/account_tracker_service.h" 47 #include "components/signin/core/browser/account_tracker_service.h"
48 #include "components/signin/core/browser/fake_signin_manager.h" 48 #include "components/signin/core/browser/fake_signin_manager.h"
49 #include "components/signin/core/browser/test_signin_client.h" 49 #include "components/signin/core/browser/test_signin_client.h"
50 #include "components/signin/core/common/signin_pref_names.h" 50 #include "components/signin/core/common/signin_pref_names.h"
51 #include "components/variations/variations_params_manager.h" 51 #include "components/variations/variations_params_manager.h"
52 #include "components/webdata/common/web_data_service_base.h" 52 #include "components/webdata/common/web_data_service_base.h"
53 #include "components/webdata/common/web_database_service.h" 53 #include "components/webdata/common/web_database_service.h"
54 #include "testing/gmock/include/gmock/gmock.h" 54 #include "testing/gmock/include/gmock/gmock.h"
55 #include "testing/gtest/include/gtest/gtest.h" 55 #include "testing/gtest/include/gtest/gtest.h"
56 56
57 using base::ASCIIToUTF16;
58 using base::UTF8ToUTF16;
59
60 namespace autofill { 57 namespace autofill {
61 namespace { 58 namespace {
62 59
63 enum UserMode { USER_MODE_NORMAL, USER_MODE_INCOGNITO }; 60 enum UserMode { USER_MODE_NORMAL, USER_MODE_INCOGNITO };
64 61
65 const std::string kUTF8MidlineEllipsis = 62 const char kUTF8MidlineEllipsis[] =
66 " " 63 " "
67 "\xE2\x80\xA2\xE2\x80\x86" 64 "\xE2\x80\xA2\xE2\x80\x86"
68 "\xE2\x80\xA2\xE2\x80\x86" 65 "\xE2\x80\xA2\xE2\x80\x86"
69 "\xE2\x80\xA2\xE2\x80\x86" 66 "\xE2\x80\xA2\xE2\x80\x86"
70 "\xE2\x80\xA2\xE2\x80\x86"; 67 "\xE2\x80\xA2\xE2\x80\x86";
71 68
72 const base::Time kArbitraryTime = base::Time::FromDoubleT(25); 69 const base::Time kArbitraryTime = base::Time::FromDoubleT(25);
73 const base::Time kSomeLaterTime = base::Time::FromDoubleT(1000); 70 const base::Time kSomeLaterTime = base::Time::FromDoubleT(1000);
74 const base::Time kMuchLaterTime = base::Time::FromDoubleT(5000); 71 const base::Time kMuchLaterTime = base::Time::FromDoubleT(5000);
75 72
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 signin_client_.reset(); 347 signin_client_.reset();
351 348
352 test::DisableSystemServices(prefs_.get()); 349 test::DisableSystemServices(prefs_.get());
353 OSCryptMocker::TearDown(); 350 OSCryptMocker::TearDown();
354 } 351 }
355 }; 352 };
356 353
357 TEST_F(PersonalDataManagerTest, AddProfile) { 354 TEST_F(PersonalDataManagerTest, AddProfile) {
358 // Add profile0 to the database. 355 // Add profile0 to the database.
359 AutofillProfile profile0(test::GetFullProfile()); 356 AutofillProfile profile0(test::GetFullProfile());
360 profile0.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("j@s.com")); 357 profile0.SetRawInfo(EMAIL_ADDRESS, base::ASCIIToUTF16("j@s.com"));
361 personal_data_->AddProfile(profile0); 358 personal_data_->AddProfile(profile0);
362 359
363 // Reload the database. 360 // Reload the database.
364 ResetPersonalDataManager(USER_MODE_NORMAL); 361 ResetPersonalDataManager(USER_MODE_NORMAL);
365 362
366 // Verify the addition. 363 // Verify the addition.
367 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); 364 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles();
368 ASSERT_EQ(1U, results1.size()); 365 ASSERT_EQ(1U, results1.size());
369 EXPECT_EQ(0, profile0.Compare(*results1[0])); 366 EXPECT_EQ(0, profile0.Compare(*results1[0]));
370 367
371 // Add profile with identical values. Duplicates should not get saved. 368 // Add profile with identical values. Duplicates should not get saved.
372 AutofillProfile profile0a = profile0; 369 AutofillProfile profile0a = profile0;
373 profile0a.set_guid(base::GenerateGUID()); 370 profile0a.set_guid(base::GenerateGUID());
374 personal_data_->AddProfile(profile0a); 371 personal_data_->AddProfile(profile0a);
375 372
376 // Reload the database. 373 // Reload the database.
377 ResetPersonalDataManager(USER_MODE_NORMAL); 374 ResetPersonalDataManager(USER_MODE_NORMAL);
378 375
379 // Verify the non-addition. 376 // Verify the non-addition.
380 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); 377 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
381 ASSERT_EQ(1U, results2.size()); 378 ASSERT_EQ(1U, results2.size());
382 EXPECT_EQ(0, profile0.Compare(*results2[0])); 379 EXPECT_EQ(0, profile0.Compare(*results2[0]));
383 380
384 // New profile with different email. 381 // New profile with different email.
385 AutofillProfile profile1 = profile0; 382 AutofillProfile profile1 = profile0;
386 profile1.set_guid(base::GenerateGUID()); 383 profile1.set_guid(base::GenerateGUID());
387 profile1.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("john@smith.com")); 384 profile1.SetRawInfo(EMAIL_ADDRESS, base::ASCIIToUTF16("john@smith.com"));
388 385
389 // Add the different profile. This should save as a separate profile. 386 // Add the different profile. This should save as a separate profile.
390 // Note that if this same profile was "merged" it would collapse to one 387 // Note that if this same profile was "merged" it would collapse to one
391 // profile with a multi-valued entry for email. 388 // profile with a multi-valued entry for email.
392 personal_data_->AddProfile(profile1); 389 personal_data_->AddProfile(profile1);
393 390
394 // Reload the database. 391 // Reload the database.
395 ResetPersonalDataManager(USER_MODE_NORMAL); 392 ResetPersonalDataManager(USER_MODE_NORMAL);
396 393
397 // Verify the addition. 394 // Verify the addition.
398 std::vector<AutofillProfile*> profiles; 395 std::vector<AutofillProfile*> profiles;
399 profiles.push_back(&profile0); 396 profiles.push_back(&profile0);
400 profiles.push_back(&profile1); 397 profiles.push_back(&profile1);
401 ExpectSameElements(profiles, personal_data_->GetProfiles()); 398 ExpectSameElements(profiles, personal_data_->GetProfiles());
402 } 399 }
403 400
404 // Test that a new profile has its basic information set. 401 // Test that a new profile has its basic information set.
405 TEST_F(PersonalDataManagerTest, AddProfile_BasicInformation) { 402 TEST_F(PersonalDataManagerTest, AddProfile_BasicInformation) {
406 // Create the test clock and set the time to a specific value. 403 // Create the test clock and set the time to a specific value.
407 TestAutofillClock test_clock; 404 TestAutofillClock test_clock;
408 test_clock.SetNow(kArbitraryTime); 405 test_clock.SetNow(kArbitraryTime);
409 406
410 // Add a profile to the database. 407 // Add a profile to the database.
411 AutofillProfile profile(test::GetFullProfile()); 408 AutofillProfile profile(test::GetFullProfile());
412 profile.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("j@s.com")); 409 profile.SetRawInfo(EMAIL_ADDRESS, base::ASCIIToUTF16("j@s.com"));
413 personal_data_->AddProfile(profile); 410 personal_data_->AddProfile(profile);
414 411
415 // Reload the database. 412 // Reload the database.
416 ResetPersonalDataManager(USER_MODE_NORMAL); 413 ResetPersonalDataManager(USER_MODE_NORMAL);
417 414
418 // Verify the addition. 415 // Verify the addition.
419 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); 416 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles();
420 ASSERT_EQ(1U, results.size()); 417 ASSERT_EQ(1U, results.size());
421 EXPECT_EQ(0, profile.Compare(*results[0])); 418 EXPECT_EQ(0, profile.Compare(*results[0]));
422 419
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 462 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
466 .WillOnce(QuitMainMessageLoop()); 463 .WillOnce(QuitMainMessageLoop());
467 base::RunLoop().Run(); 464 base::RunLoop().Run();
468 465
469 std::vector<AutofillProfile*> profiles; 466 std::vector<AutofillProfile*> profiles;
470 profiles.push_back(&profile0); 467 profiles.push_back(&profile0);
471 profiles.push_back(&profile1); 468 profiles.push_back(&profile1);
472 ExpectSameElements(profiles, personal_data_->GetProfiles()); 469 ExpectSameElements(profiles, personal_data_->GetProfiles());
473 470
474 // Update, remove, and add. 471 // Update, remove, and add.
475 profile0.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); 472 profile0.SetRawInfo(NAME_FIRST, base::ASCIIToUTF16("John"));
476 personal_data_->UpdateProfile(profile0); 473 personal_data_->UpdateProfile(profile0);
477 personal_data_->RemoveByGUID(profile1.guid()); 474 personal_data_->RemoveByGUID(profile1.guid());
478 personal_data_->AddProfile(profile2); 475 personal_data_->AddProfile(profile2);
479 476
480 // Verify that the web database has been updated and the notification sent. 477 // Verify that the web database has been updated and the notification sent.
481 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 478 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
482 .WillOnce(QuitMainMessageLoop()); 479 .WillOnce(QuitMainMessageLoop());
483 base::RunLoop().Run(); 480 base::RunLoop().Run();
484 481
485 profiles.clear(); 482 profiles.clear();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 515 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
519 .WillOnce(QuitMainMessageLoop()); 516 .WillOnce(QuitMainMessageLoop());
520 base::RunLoop().Run(); 517 base::RunLoop().Run();
521 518
522 std::vector<CreditCard*> cards; 519 std::vector<CreditCard*> cards;
523 cards.push_back(&credit_card0); 520 cards.push_back(&credit_card0);
524 cards.push_back(&credit_card1); 521 cards.push_back(&credit_card1);
525 ExpectSameElements(cards, personal_data_->GetCreditCards()); 522 ExpectSameElements(cards, personal_data_->GetCreditCards());
526 523
527 // Update, remove, and add. 524 // Update, remove, and add.
528 credit_card0.SetRawInfo(CREDIT_CARD_NAME_FULL, ASCIIToUTF16("Joe")); 525 credit_card0.SetRawInfo(CREDIT_CARD_NAME_FULL, base::ASCIIToUTF16("Joe"));
529 personal_data_->UpdateCreditCard(credit_card0); 526 personal_data_->UpdateCreditCard(credit_card0);
530 personal_data_->RemoveByGUID(credit_card1.guid()); 527 personal_data_->RemoveByGUID(credit_card1.guid());
531 personal_data_->AddCreditCard(credit_card2); 528 personal_data_->AddCreditCard(credit_card2);
532 529
533 // Verify that the web database has been updated and the notification sent. 530 // Verify that the web database has been updated and the notification sent.
534 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 531 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
535 .WillOnce(QuitMainMessageLoop()); 532 .WillOnce(QuitMainMessageLoop());
536 base::RunLoop().Run(); 533 base::RunLoop().Run();
537 534
538 cards.clear(); 535 cards.clear();
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 personal_data_->GetProfiles(); 657 personal_data_->GetProfiles();
661 const std::vector<CreditCard*>& cards2 = personal_data_->GetCreditCards(); 658 const std::vector<CreditCard*>& cards2 = personal_data_->GetCreditCards();
662 ASSERT_EQ(1U, profiles2.size()); 659 ASSERT_EQ(1U, profiles2.size());
663 ASSERT_EQ(1U, cards2.size()); 660 ASSERT_EQ(1U, cards2.size());
664 EXPECT_NE(profile.origin(), profiles2[0]->origin()); 661 EXPECT_NE(profile.origin(), profiles2[0]->origin());
665 EXPECT_NE(credit_card.origin(), cards2[0]->origin()); 662 EXPECT_NE(credit_card.origin(), cards2[0]->origin());
666 EXPECT_EQ(original_profile.origin(), profiles2[0]->origin()); 663 EXPECT_EQ(original_profile.origin(), profiles2[0]->origin());
667 EXPECT_EQ(original_credit_card.origin(), cards2[0]->origin()); 664 EXPECT_EQ(original_credit_card.origin(), cards2[0]->origin());
668 665
669 // Try to update with data changed as well. 666 // Try to update with data changed as well.
670 profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); 667 profile.SetRawInfo(NAME_FIRST, base::ASCIIToUTF16("John"));
671 credit_card.SetRawInfo(CREDIT_CARD_NAME_FULL, ASCIIToUTF16("Joe")); 668 credit_card.SetRawInfo(CREDIT_CARD_NAME_FULL, base::ASCIIToUTF16("Joe"));
672 669
673 personal_data_->UpdateProfile(profile); 670 personal_data_->UpdateProfile(profile);
674 personal_data_->UpdateCreditCard(credit_card); 671 personal_data_->UpdateCreditCard(credit_card);
675 672
676 // Verify that the web database has been updated and the notification sent. 673 // Verify that the web database has been updated and the notification sent.
677 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 674 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
678 .WillOnce(QuitMainMessageLoop()); 675 .WillOnce(QuitMainMessageLoop());
679 base::RunLoop().Run(); 676 base::RunLoop().Run();
680 677
681 const std::vector<AutofillProfile*>& profiles3 = 678 const std::vector<AutofillProfile*>& profiles3 =
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 } 754 }
758 755
759 // Tests that UpdateServerCreditCard can be used to mask or unmask server cards. 756 // Tests that UpdateServerCreditCard can be used to mask or unmask server cards.
760 TEST_F(PersonalDataManagerTest, UpdateServerCreditCards) { 757 TEST_F(PersonalDataManagerTest, UpdateServerCreditCards) {
761 EnableWalletCardImport(); 758 EnableWalletCardImport();
762 759
763 std::vector<CreditCard> server_cards; 760 std::vector<CreditCard> server_cards;
764 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); 761 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123"));
765 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", 762 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger",
766 "9012" /* Visa */, "01", "2999"); 763 "9012" /* Visa */, "01", "2999");
767 server_cards.back().SetTypeForMaskedCard(kVisaCard); 764 server_cards.back().SetNetworkForMaskedCard(kVisaCard);
768 765
769 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b456")); 766 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b456"));
770 test::SetCreditCardInfo(&server_cards.back(), "Bonnie Parker", 767 test::SetCreditCardInfo(&server_cards.back(), "Bonnie Parker",
771 "2109" /* Mastercard */, "12", "2999"); 768 "2109" /* Mastercard */, "12", "2999");
772 server_cards.back().SetTypeForMaskedCard(kMasterCard); 769 server_cards.back().SetNetworkForMaskedCard(kMasterCard);
773 770
774 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); 771 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789"));
775 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", 772 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow",
776 "347666888555" /* American Express */, "04", "2999"); 773 "347666888555" /* American Express */, "04", "2999");
777 774
778 test::SetServerCreditCards(autofill_table_, server_cards); 775 test::SetServerCreditCards(autofill_table_, server_cards);
779 personal_data_->Refresh(); 776 personal_data_->Refresh();
780 777
781 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 778 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
782 .WillOnce(QuitMainMessageLoop()); 779 .WillOnce(QuitMainMessageLoop());
783 base::RunLoop().Run(); 780 base::RunLoop().Run();
784 781
785 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); 782 ASSERT_EQ(3U, personal_data_->GetCreditCards().size());
786 783
787 if (!OfferStoreUnmaskedCards()) { 784 if (!OfferStoreUnmaskedCards()) {
788 for (CreditCard* card : personal_data_->GetCreditCards()) { 785 for (CreditCard* card : personal_data_->GetCreditCards()) {
789 EXPECT_EQ(CreditCard::MASKED_SERVER_CARD, card->record_type()); 786 EXPECT_EQ(CreditCard::MASKED_SERVER_CARD, card->record_type());
790 } 787 }
791 // The rest of this test doesn't work if we're force-masking all unmasked 788 // The rest of this test doesn't work if we're force-masking all unmasked
792 // cards. 789 // cards.
793 return; 790 return;
794 } 791 }
795 792
796 // The GUIDs will be different, so just compare the data. 793 // The GUIDs will be different, so just compare the data.
797 for (size_t i = 0; i < 3; ++i) 794 for (size_t i = 0; i < 3; ++i)
798 EXPECT_EQ(0, server_cards[i].Compare(*personal_data_->GetCreditCards()[i])); 795 EXPECT_EQ(0, server_cards[i].Compare(*personal_data_->GetCreditCards()[i]));
799 796
800 CreditCard* unmasked_card = &server_cards.front(); 797 CreditCard* unmasked_card = &server_cards.front();
801 unmasked_card->set_record_type(CreditCard::FULL_SERVER_CARD); 798 unmasked_card->set_record_type(CreditCard::FULL_SERVER_CARD);
802 unmasked_card->SetNumber(ASCIIToUTF16("423456789012")); 799 unmasked_card->SetNumber(base::ASCIIToUTF16("423456789012"));
803 EXPECT_NE(0, server_cards.front().Compare( 800 EXPECT_NE(0, server_cards.front().Compare(
804 *personal_data_->GetCreditCards().front())); 801 *personal_data_->GetCreditCards().front()));
805 personal_data_->UpdateServerCreditCard(*unmasked_card); 802 personal_data_->UpdateServerCreditCard(*unmasked_card);
806 803
807 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 804 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
808 .WillOnce(QuitMainMessageLoop()); 805 .WillOnce(QuitMainMessageLoop());
809 base::RunLoop().Run(); 806 base::RunLoop().Run();
810 807
811 for (size_t i = 0; i < 3; ++i) 808 for (size_t i = 0; i < 3; ++i)
812 EXPECT_EQ(0, server_cards[i].Compare(*personal_data_->GetCreditCards()[i])); 809 EXPECT_EQ(0, server_cards[i].Compare(*personal_data_->GetCreditCards()[i]));
813 810
814 CreditCard* remasked_card = &server_cards.back(); 811 CreditCard* remasked_card = &server_cards.back();
815 remasked_card->set_record_type(CreditCard::MASKED_SERVER_CARD); 812 remasked_card->set_record_type(CreditCard::MASKED_SERVER_CARD);
816 remasked_card->SetNumber(ASCIIToUTF16("8555")); 813 remasked_card->SetNumber(base::ASCIIToUTF16("8555"));
817 EXPECT_NE( 814 EXPECT_NE(
818 0, server_cards.back().Compare(*personal_data_->GetCreditCards().back())); 815 0, server_cards.back().Compare(*personal_data_->GetCreditCards().back()));
819 personal_data_->UpdateServerCreditCard(*remasked_card); 816 personal_data_->UpdateServerCreditCard(*remasked_card);
820 817
821 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 818 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
822 .WillOnce(QuitMainMessageLoop()); 819 .WillOnce(QuitMainMessageLoop());
823 base::RunLoop().Run(); 820 base::RunLoop().Run();
824 821
825 for (size_t i = 0; i < 3; ++i) 822 for (size_t i = 0; i < 3; ++i)
826 EXPECT_EQ(0, server_cards[i].Compare(*personal_data_->GetCreditCards()[i])); 823 EXPECT_EQ(0, server_cards[i].Compare(*personal_data_->GetCreditCards()[i]));
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 // Make sure the two profiles have different GUIDs, both valid. 916 // Make sure the two profiles have different GUIDs, both valid.
920 const std::vector<AutofillProfile*>& results3 = personal_data_->GetProfiles(); 917 const std::vector<AutofillProfile*>& results3 = personal_data_->GetProfiles();
921 ASSERT_EQ(2U, results3.size()); 918 ASSERT_EQ(2U, results3.size());
922 EXPECT_NE(results3[0]->guid(), results3[1]->guid()); 919 EXPECT_NE(results3[0]->guid(), results3[1]->guid());
923 EXPECT_TRUE(base::IsValidGUID(results3[0]->guid())); 920 EXPECT_TRUE(base::IsValidGUID(results3[0]->guid()));
924 EXPECT_TRUE(base::IsValidGUID(results3[1]->guid())); 921 EXPECT_TRUE(base::IsValidGUID(results3[1]->guid()));
925 } 922 }
926 923
927 TEST_F(PersonalDataManagerTest, SetUniqueCreditCardLabels) { 924 TEST_F(PersonalDataManagerTest, SetUniqueCreditCardLabels) {
928 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com"); 925 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com");
929 credit_card0.SetRawInfo(CREDIT_CARD_NAME_FULL, ASCIIToUTF16("John")); 926 credit_card0.SetRawInfo(CREDIT_CARD_NAME_FULL, base::ASCIIToUTF16("John"));
930 CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com"); 927 CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com");
931 credit_card1.SetRawInfo(CREDIT_CARD_NAME_FULL, ASCIIToUTF16("Paul")); 928 credit_card1.SetRawInfo(CREDIT_CARD_NAME_FULL, base::ASCIIToUTF16("Paul"));
932 CreditCard credit_card2(base::GenerateGUID(), "https://www.example.com"); 929 CreditCard credit_card2(base::GenerateGUID(), "https://www.example.com");
933 credit_card2.SetRawInfo(CREDIT_CARD_NAME_FULL, ASCIIToUTF16("Ringo")); 930 credit_card2.SetRawInfo(CREDIT_CARD_NAME_FULL, base::ASCIIToUTF16("Ringo"));
934 CreditCard credit_card3(base::GenerateGUID(), "https://www.example.com"); 931 CreditCard credit_card3(base::GenerateGUID(), "https://www.example.com");
935 credit_card3.SetRawInfo(CREDIT_CARD_NAME_FULL, ASCIIToUTF16("Other")); 932 credit_card3.SetRawInfo(CREDIT_CARD_NAME_FULL, base::ASCIIToUTF16("Other"));
936 CreditCard credit_card4(base::GenerateGUID(), "https://www.example.com"); 933 CreditCard credit_card4(base::GenerateGUID(), "https://www.example.com");
937 credit_card4.SetRawInfo(CREDIT_CARD_NAME_FULL, ASCIIToUTF16("Ozzy")); 934 credit_card4.SetRawInfo(CREDIT_CARD_NAME_FULL, base::ASCIIToUTF16("Ozzy"));
938 CreditCard credit_card5(base::GenerateGUID(), "https://www.example.com"); 935 CreditCard credit_card5(base::GenerateGUID(), "https://www.example.com");
939 credit_card5.SetRawInfo(CREDIT_CARD_NAME_FULL, ASCIIToUTF16("Dio")); 936 credit_card5.SetRawInfo(CREDIT_CARD_NAME_FULL, base::ASCIIToUTF16("Dio"));
940 937
941 // Add the test credit cards to the database. 938 // Add the test credit cards to the database.
942 personal_data_->AddCreditCard(credit_card0); 939 personal_data_->AddCreditCard(credit_card0);
943 personal_data_->AddCreditCard(credit_card1); 940 personal_data_->AddCreditCard(credit_card1);
944 personal_data_->AddCreditCard(credit_card2); 941 personal_data_->AddCreditCard(credit_card2);
945 personal_data_->AddCreditCard(credit_card3); 942 personal_data_->AddCreditCard(credit_card3);
946 personal_data_->AddCreditCard(credit_card4); 943 personal_data_->AddCreditCard(credit_card4);
947 personal_data_->AddCreditCard(credit_card5); 944 personal_data_->AddCreditCard(credit_card5);
948 945
949 // Reset the PersonalDataManager. This tests that the personal data was saved 946 // Reset the PersonalDataManager. This tests that the personal data was saved
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 ExpectSameElements(profiles, personal_data_->GetProfiles()); 1046 ExpectSameElements(profiles, personal_data_->GetProfiles());
1050 1047
1051 autofill_database_service_->RemoveAutofillProfile(profile1.guid()); 1048 autofill_database_service_->RemoveAutofillProfile(profile1.guid());
1052 autofill_database_service_->RemoveAutofillProfile(profile2.guid()); 1049 autofill_database_service_->RemoveAutofillProfile(profile2.guid());
1053 1050
1054 // Before telling the PDM to refresh, simulate an edit to one of the deleted 1051 // Before telling the PDM to refresh, simulate an edit to one of the deleted
1055 // profiles via a SetProfile update (this would happen if the Autofill window 1052 // profiles via a SetProfile update (this would happen if the Autofill window
1056 // was open with a previous snapshot of the profiles, and something 1053 // was open with a previous snapshot of the profiles, and something
1057 // [e.g. sync] removed a profile from the browser. In this edge case, we will 1054 // [e.g. sync] removed a profile from the browser. In this edge case, we will
1058 // end up in a consistent state by dropping the write). 1055 // end up in a consistent state by dropping the write).
1059 profile0.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Mar")); 1056 profile0.SetRawInfo(NAME_FIRST, base::ASCIIToUTF16("Mar"));
1060 profile2.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Jo")); 1057 profile2.SetRawInfo(NAME_FIRST, base::ASCIIToUTF16("Jo"));
1061 personal_data_->UpdateProfile(profile0); 1058 personal_data_->UpdateProfile(profile0);
1062 personal_data_->AddProfile(profile1); 1059 personal_data_->AddProfile(profile1);
1063 personal_data_->AddProfile(profile2); 1060 personal_data_->AddProfile(profile2);
1064 1061
1065 // 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.
1066 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1063 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1067 .WillOnce(QuitMainMessageLoop()); 1064 .WillOnce(QuitMainMessageLoop());
1068 base::RunLoop().Run(); 1065 base::RunLoop().Run();
1069 1066
1070 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); 1067 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles();
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
1777 EXPECT_TRUE(ImportAddressProfiles(form_structure2)); 1774 EXPECT_TRUE(ImportAddressProfiles(form_structure2));
1778 1775
1779 // 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.
1780 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1777 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1781 .WillOnce(QuitMainMessageLoop()); 1778 .WillOnce(QuitMainMessageLoop());
1782 base::RunLoop().Run(); 1779 base::RunLoop().Run();
1783 1780
1784 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); 1781 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
1785 1782
1786 // Full name, phone formatting and country are updated. 1783 // Full name, phone formatting and country are updated.
1787 expected.SetRawInfo(NAME_FULL, ASCIIToUTF16("George Washington")); 1784 expected.SetRawInfo(NAME_FULL, base::ASCIIToUTF16("George Washington"));
1788 expected.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("+1 650-555-6666")); 1785 expected.SetRawInfo(PHONE_HOME_WHOLE_NUMBER,
1789 expected.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); 1786 base::ASCIIToUTF16("+1 650-555-6666"));
1787 expected.SetRawInfo(ADDRESS_HOME_COUNTRY, base::ASCIIToUTF16("US"));
1790 ASSERT_EQ(1U, results2.size()); 1788 ASSERT_EQ(1U, results2.size());
1791 EXPECT_EQ(0, expected.Compare(*results2[0])); 1789 EXPECT_EQ(0, expected.Compare(*results2[0]));
1792 } 1790 }
1793 1791
1794 TEST_F(PersonalDataManagerTest, ImportAddressProfiles_MissingInfoInOld) { 1792 TEST_F(PersonalDataManagerTest, ImportAddressProfiles_MissingInfoInOld) {
1795 FormData form1; 1793 FormData form1;
1796 FormFieldData field; 1794 FormFieldData field;
1797 test::CreateTestFormField( 1795 test::CreateTestFormField(
1798 "First name:", "first_name", "George", "text", &field); 1796 "First name:", "first_name", "George", "text", &field);
1799 form1.fields.push_back(field); 1797 form1.fields.push_back(field);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1856 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1854 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1857 .WillOnce(QuitMainMessageLoop()); 1855 .WillOnce(QuitMainMessageLoop());
1858 base::RunLoop().Run(); 1856 base::RunLoop().Run();
1859 1857
1860 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); 1858 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
1861 1859
1862 AutofillProfile expected2(base::GenerateGUID(), "https://www.example.com"); 1860 AutofillProfile expected2(base::GenerateGUID(), "https://www.example.com");
1863 test::SetProfileInfo(&expected2, "George", NULL, 1861 test::SetProfileInfo(&expected2, "George", NULL,
1864 "Washington", "theprez@gmail.com", NULL, "190 High Street", NULL, 1862 "Washington", "theprez@gmail.com", NULL, "190 High Street", NULL,
1865 "Philadelphia", "Pennsylvania", "19106", NULL, NULL); 1863 "Philadelphia", "Pennsylvania", "19106", NULL, NULL);
1866 expected2.SetRawInfo(NAME_FULL, ASCIIToUTF16("George Washington")); 1864 expected2.SetRawInfo(NAME_FULL, base::ASCIIToUTF16("George Washington"));
1867 ASSERT_EQ(1U, results2.size()); 1865 ASSERT_EQ(1U, results2.size());
1868 EXPECT_EQ(0, expected2.Compare(*results2[0])); 1866 EXPECT_EQ(0, expected2.Compare(*results2[0]));
1869 } 1867 }
1870 1868
1871 TEST_F(PersonalDataManagerTest, ImportAddressProfiles_MissingInfoInNew) { 1869 TEST_F(PersonalDataManagerTest, ImportAddressProfiles_MissingInfoInNew) {
1872 FormData form1; 1870 FormData form1;
1873 FormFieldData field; 1871 FormFieldData field;
1874 test::CreateTestFormField( 1872 test::CreateTestFormField(
1875 "First name:", "first_name", "George", "text", &field); 1873 "First name:", "first_name", "George", "text", &field);
1876 form1.fields.push_back(field); 1874 form1.fields.push_back(field);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1937 EXPECT_TRUE(ImportAddressProfiles(form_structure2)); 1935 EXPECT_TRUE(ImportAddressProfiles(form_structure2));
1938 1936
1939 // Verify that the web database has been updated and the notification sent. 1937 // Verify that the web database has been updated and the notification sent.
1940 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 1938 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
1941 .WillOnce(QuitMainMessageLoop()); 1939 .WillOnce(QuitMainMessageLoop());
1942 base::RunLoop().Run(); 1940 base::RunLoop().Run();
1943 1941
1944 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); 1942 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
1945 1943
1946 // The merge operation will populate the full name if it's empty. 1944 // The merge operation will populate the full name if it's empty.
1947 expected.SetRawInfo(NAME_FULL, ASCIIToUTF16("George Washington")); 1945 expected.SetRawInfo(NAME_FULL, base::ASCIIToUTF16("George Washington"));
1948 ASSERT_EQ(1U, results2.size()); 1946 ASSERT_EQ(1U, results2.size());
1949 EXPECT_EQ(0, expected.Compare(*results2[0])); 1947 EXPECT_EQ(0, expected.Compare(*results2[0]));
1950 } 1948 }
1951 1949
1952 TEST_F(PersonalDataManagerTest, ImportAddressProfiles_InsufficientAddress) { 1950 TEST_F(PersonalDataManagerTest, ImportAddressProfiles_InsufficientAddress) {
1953 FormData form1; 1951 FormData form1;
1954 FormFieldData field; 1952 FormFieldData field;
1955 test::CreateTestFormField( 1953 test::CreateTestFormField(
1956 "First name:", "first_name", "George", "text", &field); 1954 "First name:", "first_name", "George", "text", &field);
1957 form1.fields.push_back(field); 1955 form1.fields.push_back(field);
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
2243 } 2241 }
2244 2242
2245 // Tests that a valid credit card is extracted when the option text for month 2243 // Tests that a valid credit card is extracted when the option text for month
2246 // select can't be parsed but its value can. 2244 // select can't be parsed but its value can.
2247 TEST_F(PersonalDataManagerTest, ImportCreditCard_MonthSelectInvalidText) { 2245 TEST_F(PersonalDataManagerTest, ImportCreditCard_MonthSelectInvalidText) {
2248 // Add a single valid credit card form with an invalid option value. 2246 // Add a single valid credit card form with an invalid option value.
2249 FormData form; 2247 FormData form;
2250 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111", 2248 AddFullCreditCardForm(&form, "Biggie Smalls", "4111-1111-1111-1111",
2251 "Feb (2)", "2999"); 2249 "Feb (2)", "2999");
2252 // Add option values and contents to the expiration month field. 2250 // Add option values and contents to the expiration month field.
2253 ASSERT_EQ(ASCIIToUTF16("exp_month"), form.fields[2].name); 2251 ASSERT_EQ(base::ASCIIToUTF16("exp_month"), form.fields[2].name);
2254 std::vector<base::string16> values; 2252 std::vector<base::string16> values;
2255 values.push_back(ASCIIToUTF16("1")); 2253 values.push_back(base::ASCIIToUTF16("1"));
2256 values.push_back(ASCIIToUTF16("2")); 2254 values.push_back(base::ASCIIToUTF16("2"));
2257 values.push_back(ASCIIToUTF16("3")); 2255 values.push_back(base::ASCIIToUTF16("3"));
2258 std::vector<base::string16> contents; 2256 std::vector<base::string16> contents;
2259 contents.push_back(ASCIIToUTF16("Jan (1)")); 2257 contents.push_back(base::ASCIIToUTF16("Jan (1)"));
2260 contents.push_back(ASCIIToUTF16("Feb (2)")); 2258 contents.push_back(base::ASCIIToUTF16("Feb (2)"));
2261 contents.push_back(ASCIIToUTF16("Mar (3)")); 2259 contents.push_back(base::ASCIIToUTF16("Mar (3)"));
2262 form.fields[2].option_values = values; 2260 form.fields[2].option_values = values;
2263 form.fields[2].option_contents = contents; 2261 form.fields[2].option_contents = contents;
2264 2262
2265 FormStructure form_structure(form); 2263 FormStructure form_structure(form);
2266 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */); 2264 form_structure.DetermineHeuristicTypes(nullptr /* ukm_service */);
2267 std::unique_ptr<CreditCard> imported_credit_card; 2265 std::unique_ptr<CreditCard> imported_credit_card;
2268 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card)); 2266 EXPECT_TRUE(ImportCreditCard(form_structure, false, &imported_credit_card));
2269 ASSERT_TRUE(imported_credit_card); 2267 ASSERT_TRUE(imported_credit_card);
2270 personal_data_->SaveImportedCreditCard(*imported_credit_card); 2268 personal_data_->SaveImportedCreditCard(*imported_credit_card);
2271 2269
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
2410 2408
2411 // Tests that a credit card is extracted because it only matches a masked server 2409 // Tests that a credit card is extracted because it only matches a masked server
2412 // card. 2410 // card.
2413 TEST_F(PersonalDataManagerTest, 2411 TEST_F(PersonalDataManagerTest,
2414 ImportCreditCard_DuplicateServerCards_MaskedCard) { 2412 ImportCreditCard_DuplicateServerCards_MaskedCard) {
2415 // Add a masked server card. 2413 // Add a masked server card.
2416 std::vector<CreditCard> server_cards; 2414 std::vector<CreditCard> server_cards;
2417 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); 2415 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123"));
2418 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", 2416 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger",
2419 "1111" /* Visa */, "01", "2999"); 2417 "1111" /* Visa */, "01", "2999");
2420 server_cards.back().SetTypeForMaskedCard(kVisaCard); 2418 server_cards.back().SetNetworkForMaskedCard(kVisaCard);
2421 test::SetServerCreditCards(autofill_table_, server_cards); 2419 test::SetServerCreditCards(autofill_table_, server_cards);
2422 2420
2423 // Type the same data as the masked card into a form. 2421 // Type the same data as the masked card into a form.
2424 FormData form; 2422 FormData form;
2425 AddFullCreditCardForm(&form, "John Dillinger", "4111111111111111", "01", 2423 AddFullCreditCardForm(&form, "John Dillinger", "4111111111111111", "01",
2426 "2999"); 2424 "2999");
2427 2425
2428 // The card should be offered to be saved locally because it only matches the 2426 // The card should be offered to be saved locally because it only matches the
2429 // masked server card. 2427 // masked server card.
2430 FormStructure form_structure(form); 2428 FormStructure form_structure(form);
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
2970 2968
2971 // Verify that the web database has been updated and the notification sent. 2969 // Verify that the web database has been updated and the notification sent.
2972 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2970 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2973 .WillOnce(QuitMainMessageLoop()); 2971 .WillOnce(QuitMainMessageLoop());
2974 base::RunLoop().Run(); 2972 base::RunLoop().Run();
2975 2973
2976 AutofillProfile new_verified_profile = profile; 2974 AutofillProfile new_verified_profile = profile;
2977 new_verified_profile.set_guid(base::GenerateGUID()); 2975 new_verified_profile.set_guid(base::GenerateGUID());
2978 new_verified_profile.set_origin(kSettingsOrigin); 2976 new_verified_profile.set_origin(kSettingsOrigin);
2979 new_verified_profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, 2977 new_verified_profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER,
2980 ASCIIToUTF16("1 234 567-8910")); 2978 base::ASCIIToUTF16("1 234 567-8910"));
2981 EXPECT_TRUE(new_verified_profile.IsVerified()); 2979 EXPECT_TRUE(new_verified_profile.IsVerified());
2982 2980
2983 personal_data_->SaveImportedProfile(new_verified_profile); 2981 personal_data_->SaveImportedProfile(new_verified_profile);
2984 2982
2985 // Verify that the web database has been updated and the notification sent. 2983 // Verify that the web database has been updated and the notification sent.
2986 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 2984 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
2987 .WillOnce(QuitMainMessageLoop()); 2985 .WillOnce(QuitMainMessageLoop());
2988 base::RunLoop().Run(); 2986 base::RunLoop().Run();
2989 2987
2990 // The new profile should be merged into the existing one. 2988 // The new profile should be merged into the existing one.
2991 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); 2989 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles();
2992 ASSERT_EQ(1U, results.size()); 2990 ASSERT_EQ(1U, results.size());
2993 AutofillProfile expected(new_verified_profile); 2991 AutofillProfile expected(new_verified_profile);
2994 expected.SetRawInfo(NAME_FULL, ASCIIToUTF16("Marion Mitchell Morrison")); 2992 expected.SetRawInfo(NAME_FULL,
2995 expected.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, ASCIIToUTF16("+1 234-567-8910")); 2993 base::ASCIIToUTF16("Marion Mitchell Morrison"));
2994 expected.SetRawInfo(PHONE_HOME_WHOLE_NUMBER,
2995 base::ASCIIToUTF16("+1 234-567-8910"));
2996 EXPECT_EQ(0, expected.Compare(*results[0])) 2996 EXPECT_EQ(0, expected.Compare(*results[0]))
2997 << "result = {" << *results[0] << "} | expected = {" << expected << "}"; 2997 << "result = {" << *results[0] << "} | expected = {" << expected << "}";
2998 } 2998 }
2999 2999
3000 // Ensure that verified credit cards can be saved via SaveImportedCreditCard. 3000 // Ensure that verified credit cards can be saved via SaveImportedCreditCard.
3001 TEST_F(PersonalDataManagerTest, SaveImportedCreditCardWithVerifiedData) { 3001 TEST_F(PersonalDataManagerTest, SaveImportedCreditCardWithVerifiedData) {
3002 // Start with a verified credit card. 3002 // Start with a verified credit card.
3003 CreditCard credit_card(base::GenerateGUID(), kSettingsOrigin); 3003 CreditCard credit_card(base::GenerateGUID(), kSettingsOrigin);
3004 test::SetCreditCardInfo(&credit_card, 3004 test::SetCreditCardInfo(&credit_card,
3005 "Biggie Smalls", "4111 1111 1111 1111" /* Visa */, "01", "2999"); 3005 "Biggie Smalls", "4111 1111 1111 1111" /* Visa */, "01", "2999");
3006 EXPECT_TRUE(credit_card.IsVerified()); 3006 EXPECT_TRUE(credit_card.IsVerified());
3007 3007
3008 // Add the credit card to the database. 3008 // Add the credit card to the database.
3009 personal_data_->AddCreditCard(credit_card); 3009 personal_data_->AddCreditCard(credit_card);
3010 3010
3011 // Verify that the web database has been updated and the notification sent. 3011 // Verify that the web database has been updated and the notification sent.
3012 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 3012 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
3013 .WillOnce(QuitMainMessageLoop()); 3013 .WillOnce(QuitMainMessageLoop());
3014 base::RunLoop().Run(); 3014 base::RunLoop().Run();
3015 3015
3016 CreditCard new_verified_card = credit_card; 3016 CreditCard new_verified_card = credit_card;
3017 new_verified_card.set_guid(base::GenerateGUID()); 3017 new_verified_card.set_guid(base::GenerateGUID());
3018 new_verified_card.SetRawInfo(CREDIT_CARD_NAME_FULL, ASCIIToUTF16("B. Small")); 3018 new_verified_card.SetRawInfo(CREDIT_CARD_NAME_FULL,
3019 base::ASCIIToUTF16("B. Small"));
3019 EXPECT_TRUE(new_verified_card.IsVerified()); 3020 EXPECT_TRUE(new_verified_card.IsVerified());
3020 3021
3021 personal_data_->SaveImportedCreditCard(new_verified_card); 3022 personal_data_->SaveImportedCreditCard(new_verified_card);
3022 3023
3023 // Verify that the web database has been updated and the notification sent. 3024 // Verify that the web database has been updated and the notification sent.
3024 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 3025 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
3025 .WillOnce(QuitMainMessageLoop()); 3026 .WillOnce(QuitMainMessageLoop());
3026 base::RunLoop().Run(); 3027 base::RunLoop().Run();
3027 3028
3028 // Expect that the saved credit card is updated. 3029 // Expect that the saved credit card is updated.
3029 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards(); 3030 const std::vector<CreditCard*>& results = personal_data_->GetCreditCards();
3030 ASSERT_EQ(1U, results.size()); 3031 ASSERT_EQ(1U, results.size());
3031 EXPECT_EQ(ASCIIToUTF16("B. Small"), 3032 EXPECT_EQ(base::ASCIIToUTF16("B. Small"),
3032 results[0]->GetRawInfo(CREDIT_CARD_NAME_FULL)); 3033 results[0]->GetRawInfo(CREDIT_CARD_NAME_FULL));
3033 } 3034 }
3034 3035
3035 TEST_F(PersonalDataManagerTest, GetNonEmptyTypes) { 3036 TEST_F(PersonalDataManagerTest, GetNonEmptyTypes) {
3036 // Check that there are no available types with no profiles stored. 3037 // Check that there are no available types with no profiles stored.
3037 ServerFieldTypeSet non_empty_types; 3038 ServerFieldTypeSet non_empty_types;
3038 personal_data_->GetNonEmptyTypes(&non_empty_types); 3039 personal_data_->GetNonEmptyTypes(&non_empty_types);
3039 EXPECT_EQ(0U, non_empty_types.size()); 3040 EXPECT_EQ(0U, non_empty_types.size());
3040 3041
3041 // Test with one profile stored. 3042 // Test with one profile stored.
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
3188 CreditCard larry_page(base::GenerateGUID(), "https://www.example.com"); 3189 CreditCard larry_page(base::GenerateGUID(), "https://www.example.com");
3189 test::SetCreditCardInfo( 3190 test::SetCreditCardInfo(
3190 &larry_page, "Lawrence Page", "4111111111111111", "10", "2025"); 3191 &larry_page, "Lawrence Page", "4111111111111111", "10", "2025");
3191 personal_data_->AddCreditCard(larry_page); 3192 personal_data_->AddCreditCard(larry_page);
3192 3193
3193 ResetPersonalDataManager(USER_MODE_INCOGNITO); 3194 ResetPersonalDataManager(USER_MODE_INCOGNITO);
3194 EXPECT_EQ(1U, personal_data_->GetProfiles().size()); 3195 EXPECT_EQ(1U, personal_data_->GetProfiles().size());
3195 EXPECT_EQ(1U, personal_data_->GetCreditCards().size()); 3196 EXPECT_EQ(1U, personal_data_->GetCreditCards().size());
3196 3197
3197 // Saving or creating profiles from imported profiles shouldn't work. 3198 // Saving or creating profiles from imported profiles shouldn't work.
3198 steve_jobs.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Steve")); 3199 steve_jobs.SetRawInfo(NAME_FIRST, base::ASCIIToUTF16("Steve"));
3199 personal_data_->SaveImportedProfile(steve_jobs); 3200 personal_data_->SaveImportedProfile(steve_jobs);
3200 3201
3201 bill_gates.SetRawInfo(CREDIT_CARD_NAME_FULL, ASCIIToUTF16("Bill Gates")); 3202 bill_gates.SetRawInfo(CREDIT_CARD_NAME_FULL,
3203 base::ASCIIToUTF16("Bill Gates"));
3202 personal_data_->SaveImportedCreditCard(bill_gates); 3204 personal_data_->SaveImportedCreditCard(bill_gates);
3203 3205
3204 ResetPersonalDataManager(USER_MODE_INCOGNITO); 3206 ResetPersonalDataManager(USER_MODE_INCOGNITO);
3205 EXPECT_EQ(ASCIIToUTF16("Steven"), 3207 EXPECT_EQ(base::ASCIIToUTF16("Steven"),
3206 personal_data_->GetProfiles()[0]->GetRawInfo(NAME_FIRST)); 3208 personal_data_->GetProfiles()[0]->GetRawInfo(NAME_FIRST));
3207 EXPECT_EQ( 3209 EXPECT_EQ(
3208 ASCIIToUTF16("William H. Gates"), 3210 base::ASCIIToUTF16("William H. Gates"),
3209 personal_data_->GetCreditCards()[0]->GetRawInfo(CREDIT_CARD_NAME_FULL)); 3211 personal_data_->GetCreditCards()[0]->GetRawInfo(CREDIT_CARD_NAME_FULL));
3210 3212
3211 // Updating existing profiles shouldn't work. 3213 // Updating existing profiles shouldn't work.
3212 steve_jobs.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Steve")); 3214 steve_jobs.SetRawInfo(NAME_FIRST, base::ASCIIToUTF16("Steve"));
3213 personal_data_->UpdateProfile(steve_jobs); 3215 personal_data_->UpdateProfile(steve_jobs);
3214 3216
3215 bill_gates.SetRawInfo(CREDIT_CARD_NAME_FULL, ASCIIToUTF16("Bill Gates")); 3217 bill_gates.SetRawInfo(CREDIT_CARD_NAME_FULL,
3218 base::ASCIIToUTF16("Bill Gates"));
3216 personal_data_->UpdateCreditCard(bill_gates); 3219 personal_data_->UpdateCreditCard(bill_gates);
3217 3220
3218 ResetPersonalDataManager(USER_MODE_INCOGNITO); 3221 ResetPersonalDataManager(USER_MODE_INCOGNITO);
3219 EXPECT_EQ(ASCIIToUTF16("Steven"), 3222 EXPECT_EQ(base::ASCIIToUTF16("Steven"),
3220 personal_data_->GetProfiles()[0]->GetRawInfo(NAME_FIRST)); 3223 personal_data_->GetProfiles()[0]->GetRawInfo(NAME_FIRST));
3221 EXPECT_EQ( 3224 EXPECT_EQ(
3222 ASCIIToUTF16("William H. Gates"), 3225 base::ASCIIToUTF16("William H. Gates"),
3223 personal_data_->GetCreditCards()[0]->GetRawInfo(CREDIT_CARD_NAME_FULL)); 3226 personal_data_->GetCreditCards()[0]->GetRawInfo(CREDIT_CARD_NAME_FULL));
3224 3227
3225 // Removing shouldn't work. 3228 // Removing shouldn't work.
3226 personal_data_->RemoveByGUID(steve_jobs.guid()); 3229 personal_data_->RemoveByGUID(steve_jobs.guid());
3227 personal_data_->RemoveByGUID(bill_gates.guid()); 3230 personal_data_->RemoveByGUID(bill_gates.guid());
3228 3231
3229 ResetPersonalDataManager(USER_MODE_INCOGNITO); 3232 ResetPersonalDataManager(USER_MODE_INCOGNITO);
3230 EXPECT_EQ(1U, personal_data_->GetProfiles().size()); 3233 EXPECT_EQ(1U, personal_data_->GetProfiles().size());
3231 EXPECT_EQ(1U, personal_data_->GetCreditCards().size()); 3234 EXPECT_EQ(1U, personal_data_->GetCreditCards().size());
3232 } 3235 }
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
3539 // been typed in the field. 3542 // been typed in the field.
3540 TEST_F(PersonalDataManagerTest, 3543 TEST_F(PersonalDataManagerTest,
3541 GetCreditCardSuggestions_MaskedCardWithMoreThan6Numbers) { 3544 GetCreditCardSuggestions_MaskedCardWithMoreThan6Numbers) {
3542 EnableWalletCardImport(); 3545 EnableWalletCardImport();
3543 3546
3544 // Add a masked server card. 3547 // Add a masked server card.
3545 std::vector<CreditCard> server_cards; 3548 std::vector<CreditCard> server_cards;
3546 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b459")); 3549 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b459"));
3547 test::SetCreditCardInfo(&server_cards.back(), "Emmet Dalton", "2110", "12", 3550 test::SetCreditCardInfo(&server_cards.back(), "Emmet Dalton", "2110", "12",
3548 "2999"); 3551 "2999");
3549 server_cards.back().SetTypeForMaskedCard(kVisaCard); 3552 server_cards.back().SetNetworkForMaskedCard(kVisaCard);
3550 3553
3551 test::SetServerCreditCards(autofill_table_, server_cards); 3554 test::SetServerCreditCards(autofill_table_, server_cards);
3552 personal_data_->Refresh(); 3555 personal_data_->Refresh();
3553 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 3556 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
3554 .WillOnce(QuitMainMessageLoop()); 3557 .WillOnce(QuitMainMessageLoop());
3555 base::RunLoop().Run(); 3558 base::RunLoop().Run();
3556 3559
3557 std::vector<Suggestion> suggestions = 3560 std::vector<Suggestion> suggestions =
3558 personal_data_->GetCreditCardSuggestions(AutofillType(CREDIT_CARD_NUMBER), 3561 personal_data_->GetCreditCardSuggestions(AutofillType(CREDIT_CARD_NUMBER),
3559 ASCIIToUTF16("12345678")); 3562 base::ASCIIToUTF16("12345678"));
3560 3563
3561 // There should be no suggestions. 3564 // There should be no suggestions.
3562 ASSERT_EQ(0U, suggestions.size()); 3565 ASSERT_EQ(0U, suggestions.size());
3563 } 3566 }
3564 3567
3565 // Test that local credit cards are ordered as expected. 3568 // Test that local credit cards are ordered as expected.
3566 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_LocalCardsRanking) { 3569 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_LocalCardsRanking) {
3567 SetupReferenceLocalCreditCards(); 3570 SetupReferenceLocalCreditCards();
3568 3571
3569 // Sublabel is card number when filling name (exact format depends on 3572 // Sublabel is card number when filling name (exact format depends on
3570 // the platform, but the last 4 digits should appear). 3573 // the platform, but the last 4 digits should appear).
3571 std::vector<Suggestion> suggestions = 3574 std::vector<Suggestion> suggestions =
3572 personal_data_->GetCreditCardSuggestions( 3575 personal_data_->GetCreditCardSuggestions(
3573 AutofillType(CREDIT_CARD_NAME_FULL), 3576 AutofillType(CREDIT_CARD_NAME_FULL),
3574 /* field_contents= */ base::string16()); 3577 /* field_contents= */ base::string16());
3575 ASSERT_EQ(3U, suggestions.size()); 3578 ASSERT_EQ(3U, suggestions.size());
3576 3579
3577 // Ordered as expected. 3580 // Ordered as expected.
3578 EXPECT_EQ(ASCIIToUTF16("John Dillinger"), suggestions[0].value); 3581 EXPECT_EQ(base::ASCIIToUTF16("John Dillinger"), suggestions[0].value);
3579 EXPECT_TRUE(suggestions[0].label.find(ASCIIToUTF16("9012")) != 3582 EXPECT_TRUE(suggestions[0].label.find(base::ASCIIToUTF16("9012")) !=
3580 base::string16::npos); 3583 base::string16::npos);
3581 EXPECT_EQ(ASCIIToUTF16("Clyde Barrow"), suggestions[1].value); 3584 EXPECT_EQ(base::ASCIIToUTF16("Clyde Barrow"), suggestions[1].value);
3582 EXPECT_TRUE(suggestions[1].label.find(ASCIIToUTF16("8555")) != 3585 EXPECT_TRUE(suggestions[1].label.find(base::ASCIIToUTF16("8555")) !=
3583 base::string16::npos); 3586 base::string16::npos);
3584 EXPECT_EQ(ASCIIToUTF16("Bonnie Parker"), suggestions[2].value); 3587 EXPECT_EQ(base::ASCIIToUTF16("Bonnie Parker"), suggestions[2].value);
3585 EXPECT_TRUE(suggestions[2].label.find(ASCIIToUTF16("2109")) != 3588 EXPECT_TRUE(suggestions[2].label.find(base::ASCIIToUTF16("2109")) !=
3586 base::string16::npos); 3589 base::string16::npos);
3587 } 3590 }
3588 3591
3589 // Test that local and server cards are ordered as expected. 3592 // Test that local and server cards are ordered as expected.
3590 TEST_F(PersonalDataManagerTest, 3593 TEST_F(PersonalDataManagerTest,
3591 GetCreditCardSuggestions_LocalAndServerCardsRanking) { 3594 GetCreditCardSuggestions_LocalAndServerCardsRanking) {
3592 EnableWalletCardImport(); 3595 EnableWalletCardImport();
3593 SetupReferenceLocalCreditCards(); 3596 SetupReferenceLocalCreditCards();
3594 3597
3595 // Add some server cards. 3598 // Add some server cards.
3596 std::vector<CreditCard> server_cards; 3599 std::vector<CreditCard> server_cards;
3597 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b459")); 3600 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b459"));
3598 test::SetCreditCardInfo(&server_cards.back(), "Emmet Dalton", "2110", "12", 3601 test::SetCreditCardInfo(&server_cards.back(), "Emmet Dalton", "2110", "12",
3599 "2999"); 3602 "2999");
3600 server_cards.back().set_use_count(2); 3603 server_cards.back().set_use_count(2);
3601 server_cards.back().set_use_date(AutofillClock::Now() - 3604 server_cards.back().set_use_date(AutofillClock::Now() -
3602 base::TimeDelta::FromDays(1)); 3605 base::TimeDelta::FromDays(1));
3603 server_cards.back().SetTypeForMaskedCard(kVisaCard); 3606 server_cards.back().SetNetworkForMaskedCard(kVisaCard);
3604 3607
3605 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "b460")); 3608 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "b460"));
3606 test::SetCreditCardInfo(&server_cards.back(), "Jesse James", "2109", "12", 3609 test::SetCreditCardInfo(&server_cards.back(), "Jesse James", "2109", "12",
3607 "2999"); 3610 "2999");
3608 server_cards.back().set_use_count(6); 3611 server_cards.back().set_use_count(6);
3609 server_cards.back().set_use_date(AutofillClock::Now() - 3612 server_cards.back().set_use_date(AutofillClock::Now() -
3610 base::TimeDelta::FromDays(1)); 3613 base::TimeDelta::FromDays(1));
3611 3614
3612 test::SetServerCreditCards(autofill_table_, server_cards); 3615 test::SetServerCreditCards(autofill_table_, server_cards);
3613 personal_data_->Refresh(); 3616 personal_data_->Refresh();
3614 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 3617 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
3615 .WillOnce(QuitMainMessageLoop()); 3618 .WillOnce(QuitMainMessageLoop());
3616 base::RunLoop().Run(); 3619 base::RunLoop().Run();
3617 3620
3618 std::vector<Suggestion> suggestions = 3621 std::vector<Suggestion> suggestions =
3619 personal_data_->GetCreditCardSuggestions( 3622 personal_data_->GetCreditCardSuggestions(
3620 AutofillType(CREDIT_CARD_NAME_FULL), 3623 AutofillType(CREDIT_CARD_NAME_FULL),
3621 /* field_contents= */ base::string16()); 3624 /* field_contents= */ base::string16());
3622 ASSERT_EQ(5U, suggestions.size()); 3625 ASSERT_EQ(5U, suggestions.size());
3623 3626
3624 // All cards should be ordered as expected. 3627 // All cards should be ordered as expected.
3625 EXPECT_EQ(ASCIIToUTF16("Jesse James"), suggestions[0].value); 3628 EXPECT_EQ(base::ASCIIToUTF16("Jesse James"), suggestions[0].value);
3626 EXPECT_EQ(ASCIIToUTF16("John Dillinger"), suggestions[1].value); 3629 EXPECT_EQ(base::ASCIIToUTF16("John Dillinger"), suggestions[1].value);
3627 EXPECT_EQ(ASCIIToUTF16("Clyde Barrow"), suggestions[2].value); 3630 EXPECT_EQ(base::ASCIIToUTF16("Clyde Barrow"), suggestions[2].value);
3628 EXPECT_EQ(ASCIIToUTF16("Emmet Dalton"), suggestions[3].value); 3631 EXPECT_EQ(base::ASCIIToUTF16("Emmet Dalton"), suggestions[3].value);
3629 EXPECT_EQ(ASCIIToUTF16("Bonnie Parker"), suggestions[4].value); 3632 EXPECT_EQ(base::ASCIIToUTF16("Bonnie Parker"), suggestions[4].value);
3630 } 3633 }
3631 3634
3632 // Test that expired cards are ordered by frecency and are always suggested 3635 // Test that expired cards are ordered by frecency and are always suggested
3633 // after non expired cards even if they have a higher frecency score. 3636 // after non expired cards even if they have a higher frecency score.
3634 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_ExpiredCards) { 3637 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_ExpiredCards) {
3635 ASSERT_EQ(0U, personal_data_->GetCreditCards().size()); 3638 ASSERT_EQ(0U, personal_data_->GetCreditCards().size());
3636 3639
3637 // Add a never used non expired credit card. 3640 // Add a never used non expired credit card.
3638 CreditCard credit_card0("002149C1-EE28-4213-A3B9-DA243FFF021B", 3641 CreditCard credit_card0("002149C1-EE28-4213-A3B9-DA243FFF021B",
3639 "https://www.example.com"); 3642 "https://www.example.com");
(...skipping 27 matching lines...) Expand all
3667 3670
3668 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); 3671 ASSERT_EQ(3U, personal_data_->GetCreditCards().size());
3669 3672
3670 std::vector<Suggestion> suggestions = 3673 std::vector<Suggestion> suggestions =
3671 personal_data_->GetCreditCardSuggestions( 3674 personal_data_->GetCreditCardSuggestions(
3672 AutofillType(CREDIT_CARD_NAME_FULL), 3675 AutofillType(CREDIT_CARD_NAME_FULL),
3673 /* field_contents= */ base::string16()); 3676 /* field_contents= */ base::string16());
3674 ASSERT_EQ(3U, suggestions.size()); 3677 ASSERT_EQ(3U, suggestions.size());
3675 3678
3676 // The never used non expired card should be suggested first. 3679 // The never used non expired card should be suggested first.
3677 EXPECT_EQ(ASCIIToUTF16("Bonnie Parker"), suggestions[0].value); 3680 EXPECT_EQ(base::ASCIIToUTF16("Bonnie Parker"), suggestions[0].value);
3678 3681
3679 // The expired cards should be sorted by frecency 3682 // The expired cards should be sorted by frecency
3680 EXPECT_EQ(ASCIIToUTF16("Clyde Barrow"), suggestions[1].value); 3683 EXPECT_EQ(base::ASCIIToUTF16("Clyde Barrow"), suggestions[1].value);
3681 EXPECT_EQ(ASCIIToUTF16("John Dillinger"), suggestions[2].value); 3684 EXPECT_EQ(base::ASCIIToUTF16("John Dillinger"), suggestions[2].value);
3682 } 3685 }
3683 3686
3684 // Test that a card that doesn't have a number is not shown in the suggestions 3687 // Test that a card that doesn't have a number is not shown in the suggestions
3685 // when querying credit cards by their number. 3688 // when querying credit cards by their number.
3686 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_NumberMissing) { 3689 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_NumberMissing) {
3687 // Create one normal credit card and one credit card with the number missing. 3690 // Create one normal credit card and one credit card with the number missing.
3688 ASSERT_EQ(0U, personal_data_->GetCreditCards().size()); 3691 ASSERT_EQ(0U, personal_data_->GetCreditCards().size());
3689 3692
3690 CreditCard credit_card0("287151C8-6AB1-487C-9095-28E80BE5DA15", 3693 CreditCard credit_card0("287151C8-6AB1-487C-9095-28E80BE5DA15",
3691 "https://www.example.com"); 3694 "https://www.example.com");
(...skipping 18 matching lines...) Expand all
3710 3713
3711 ASSERT_EQ(2U, personal_data_->GetCreditCards().size()); 3714 ASSERT_EQ(2U, personal_data_->GetCreditCards().size());
3712 3715
3713 // Sublabel is expiration date when filling card number. The second card 3716 // Sublabel is expiration date when filling card number. The second card
3714 // doesn't have a number so it should not be included in the suggestions. 3717 // doesn't have a number so it should not be included in the suggestions.
3715 std::vector<Suggestion> suggestions = 3718 std::vector<Suggestion> suggestions =
3716 personal_data_->GetCreditCardSuggestions( 3719 personal_data_->GetCreditCardSuggestions(
3717 AutofillType(CREDIT_CARD_NUMBER), 3720 AutofillType(CREDIT_CARD_NUMBER),
3718 /* field_contents= */ base::string16()); 3721 /* field_contents= */ base::string16());
3719 ASSERT_EQ(1U, suggestions.size()); 3722 ASSERT_EQ(1U, suggestions.size());
3720 EXPECT_EQ(UTF8ToUTF16("Amex" + kUTF8MidlineEllipsis + "8555"), 3723 EXPECT_EQ(
3721 suggestions[0].value); 3724 base::UTF8ToUTF16(std::string("Amex") + kUTF8MidlineEllipsis + "8555"),
3722 EXPECT_EQ(ASCIIToUTF16("04/99"), suggestions[0].label); 3725 suggestions[0].value);
3726 EXPECT_EQ(base::ASCIIToUTF16("04/99"), suggestions[0].label);
3723 } 3727 }
3724 3728
3725 // Tests the suggestions of duplicate local and server credit cards. 3729 // Tests the suggestions of duplicate local and server credit cards.
3726 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_ServerDuplicates) { 3730 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_ServerDuplicates) {
3727 EnableWalletCardImport(); 3731 EnableWalletCardImport();
3728 SetupReferenceLocalCreditCards(); 3732 SetupReferenceLocalCreditCards();
3729 3733
3730 // Add some server cards. If there are local dupes, the locals should be 3734 // Add some server cards. If there are local dupes, the locals should be
3731 // hidden. 3735 // hidden.
3732 std::vector<CreditCard> server_cards; 3736 std::vector<CreditCard> server_cards;
3733 // This server card matches a local card, except the local card is missing the 3737 // This server card matches a local card, except the local card is missing the
3734 // number. This should count as a dupe and thus not be shown in the 3738 // number. This should count as a dupe and thus not be shown in the
3735 // suggestions since the locally saved card takes precedence. 3739 // suggestions since the locally saved card takes precedence.
3736 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); 3740 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123"));
3737 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", 3741 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger",
3738 "9012" /* Visa */, "01", "2999"); 3742 "9012" /* Visa */, "01", "2999");
3739 server_cards.back().set_use_count(2); 3743 server_cards.back().set_use_count(2);
3740 server_cards.back().set_use_date(AutofillClock::Now() - 3744 server_cards.back().set_use_date(AutofillClock::Now() -
3741 base::TimeDelta::FromDays(15)); 3745 base::TimeDelta::FromDays(15));
3742 server_cards.back().SetTypeForMaskedCard(kVisaCard); 3746 server_cards.back().SetNetworkForMaskedCard(kVisaCard);
3743 3747
3744 // This server card is identical to a local card, but has a different 3748 // This server card is identical to a local card, but has a different
3745 // card type. Not a dupe and therefore both should appear in the suggestions. 3749 // card type. Not a dupe and therefore both should appear in the suggestions.
3746 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b456")); 3750 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b456"));
3747 test::SetCreditCardInfo(&server_cards.back(), "Bonnie Parker", "2109", "12", 3751 test::SetCreditCardInfo(&server_cards.back(), "Bonnie Parker", "2109", "12",
3748 "2999"); 3752 "2999");
3749 server_cards.back().set_use_count(3); 3753 server_cards.back().set_use_count(3);
3750 server_cards.back().set_use_date(AutofillClock::Now() - 3754 server_cards.back().set_use_date(AutofillClock::Now() -
3751 base::TimeDelta::FromDays(15)); 3755 base::TimeDelta::FromDays(15));
3752 server_cards.back().SetTypeForMaskedCard(kVisaCard); 3756 server_cards.back().SetNetworkForMaskedCard(kVisaCard);
3753 3757
3754 // This unmasked server card is an exact dupe of a local card. Therefore only 3758 // This unmasked server card is an exact dupe of a local card. Therefore only
3755 // this card should appear in the suggestions as full server cards have 3759 // this card should appear in the suggestions as full server cards have
3756 // precedence over local cards. 3760 // precedence over local cards.
3757 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); 3761 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789"));
3758 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", 3762 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow",
3759 "347666888555" /* American Express */, "04", "2999"); 3763 "347666888555" /* American Express */, "04", "2999");
3760 server_cards.back().set_use_count(1); 3764 server_cards.back().set_use_count(1);
3761 server_cards.back().set_use_date(AutofillClock::Now() - 3765 server_cards.back().set_use_date(AutofillClock::Now() -
3762 base::TimeDelta::FromDays(15)); 3766 base::TimeDelta::FromDays(15));
3763 3767
3764 test::SetServerCreditCards(autofill_table_, server_cards); 3768 test::SetServerCreditCards(autofill_table_, server_cards);
3765 personal_data_->Refresh(); 3769 personal_data_->Refresh();
3766 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 3770 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
3767 .WillOnce(QuitMainMessageLoop()); 3771 .WillOnce(QuitMainMessageLoop());
3768 base::RunLoop().Run(); 3772 base::RunLoop().Run();
3769 3773
3770 std::vector<Suggestion> suggestions = 3774 std::vector<Suggestion> suggestions =
3771 personal_data_->GetCreditCardSuggestions( 3775 personal_data_->GetCreditCardSuggestions(
3772 AutofillType(CREDIT_CARD_NAME_FULL), 3776 AutofillType(CREDIT_CARD_NAME_FULL),
3773 /* field_contents= */ base::string16()); 3777 /* field_contents= */ base::string16());
3774 ASSERT_EQ(4U, suggestions.size()); 3778 ASSERT_EQ(4U, suggestions.size());
3775 EXPECT_EQ(ASCIIToUTF16("John Dillinger"), suggestions[0].value); 3779 EXPECT_EQ(base::ASCIIToUTF16("John Dillinger"), suggestions[0].value);
3776 EXPECT_EQ(ASCIIToUTF16("Clyde Barrow"), suggestions[1].value); 3780 EXPECT_EQ(base::ASCIIToUTF16("Clyde Barrow"), suggestions[1].value);
3777 EXPECT_EQ(ASCIIToUTF16("Bonnie Parker"), suggestions[2].value); 3781 EXPECT_EQ(base::ASCIIToUTF16("Bonnie Parker"), suggestions[2].value);
3778 EXPECT_EQ(ASCIIToUTF16("Bonnie Parker"), suggestions[3].value); 3782 EXPECT_EQ(base::ASCIIToUTF16("Bonnie Parker"), suggestions[3].value);
3779 3783
3780 suggestions = personal_data_->GetCreditCardSuggestions( 3784 suggestions = personal_data_->GetCreditCardSuggestions(
3781 AutofillType(CREDIT_CARD_NUMBER), /* field_contents= */ base::string16()); 3785 AutofillType(CREDIT_CARD_NUMBER), /* field_contents= */ base::string16());
3782 ASSERT_EQ(4U, suggestions.size()); 3786 ASSERT_EQ(4U, suggestions.size());
3783 EXPECT_EQ(UTF8ToUTF16("Visa" + kUTF8MidlineEllipsis + "9012"), 3787 EXPECT_EQ(
3784 suggestions[0].value); 3788 base::UTF8ToUTF16(std::string("Visa") + kUTF8MidlineEllipsis + "9012"),
3785 EXPECT_EQ(UTF8ToUTF16("Amex" + kUTF8MidlineEllipsis + "8555"), 3789 suggestions[0].value);
3786 suggestions[1].value); 3790 EXPECT_EQ(
3787 EXPECT_EQ(UTF8ToUTF16("MasterCard" + kUTF8MidlineEllipsis + "2109"), 3791 base::UTF8ToUTF16(std::string("Amex") + kUTF8MidlineEllipsis + "8555"),
3792 suggestions[1].value);
3793 EXPECT_EQ(base::UTF8ToUTF16(std::string("MasterCard") + kUTF8MidlineEllipsis +
3794 "2109"),
3788 suggestions[2].value); 3795 suggestions[2].value);
3789 EXPECT_EQ(UTF8ToUTF16("Visa" + kUTF8MidlineEllipsis + "2109"), 3796 EXPECT_EQ(
3790 suggestions[3].value); 3797 base::UTF8ToUTF16(std::string("Visa") + kUTF8MidlineEllipsis + "2109"),
3798 suggestions[3].value);
3791 } 3799 }
3792 3800
3793 // Tests that a full server card can be a dupe of more than one local card. 3801 // Tests that a full server card can be a dupe of more than one local card.
3794 TEST_F(PersonalDataManagerTest, 3802 TEST_F(PersonalDataManagerTest,
3795 GetCreditCardSuggestions_ServerCardDuplicateOfMultipleLocalCards) { 3803 GetCreditCardSuggestions_ServerCardDuplicateOfMultipleLocalCards) {
3796 EnableWalletCardImport(); 3804 EnableWalletCardImport();
3797 SetupReferenceLocalCreditCards(); 3805 SetupReferenceLocalCreditCards();
3798 3806
3799 // Add a duplicate server card. 3807 // Add a duplicate server card.
3800 std::vector<CreditCard> server_cards; 3808 std::vector<CreditCard> server_cards;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
3877 "423456789012" /* Visa */, "01", "2999"); 3885 "423456789012" /* Visa */, "01", "2999");
3878 credit_cards.push_back(&local_card); 3886 credit_cards.push_back(&local_card);
3879 3887
3880 // Create a masked server card that is a duplicate of a local card. 3888 // Create a masked server card that is a duplicate of a local card.
3881 CreditCard masked_card(CreditCard::MASKED_SERVER_CARD, "a123"); 3889 CreditCard masked_card(CreditCard::MASKED_SERVER_CARD, "a123");
3882 test::SetCreditCardInfo(&masked_card, "Homer Simpson", "9012" /* Visa */, 3890 test::SetCreditCardInfo(&masked_card, "Homer Simpson", "9012" /* Visa */,
3883 "01", "2999"); 3891 "01", "2999");
3884 masked_card.set_use_count(2); 3892 masked_card.set_use_count(2);
3885 masked_card.set_use_date(AutofillClock::Now() - 3893 masked_card.set_use_date(AutofillClock::Now() -
3886 base::TimeDelta::FromDays(15)); 3894 base::TimeDelta::FromDays(15));
3887 masked_card.SetTypeForMaskedCard(kVisaCard); 3895 masked_card.SetNetworkForMaskedCard(kVisaCard);
3888 credit_cards.push_back(&masked_card); 3896 credit_cards.push_back(&masked_card);
3889 3897
3890 PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards); 3898 PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards);
3891 ASSERT_EQ(1U, credit_cards.size()); 3899 ASSERT_EQ(1U, credit_cards.size());
3892 3900
3893 const CreditCard* deduped_card(credit_cards.front()); 3901 const CreditCard* deduped_card(credit_cards.front());
3894 EXPECT_TRUE(*deduped_card == local_card); 3902 EXPECT_TRUE(*deduped_card == local_card);
3895 } 3903 }
3896 3904
3897 // Tests that identical full server and masked credit cards are not deduped. 3905 // Tests that identical full server and masked credit cards are not deduped.
3898 TEST_F(PersonalDataManagerTest, DedupeCreditCardToSuggest_FullServerAndMasked) { 3906 TEST_F(PersonalDataManagerTest, DedupeCreditCardToSuggest_FullServerAndMasked) {
3899 std::list<CreditCard*> credit_cards; 3907 std::list<CreditCard*> credit_cards;
3900 3908
3901 // Create a full server card that is a duplicate of one of the local cards. 3909 // Create a full server card that is a duplicate of one of the local cards.
3902 CreditCard full_server_card(CreditCard::FULL_SERVER_CARD, "c789"); 3910 CreditCard full_server_card(CreditCard::FULL_SERVER_CARD, "c789");
3903 test::SetCreditCardInfo(&full_server_card, "Homer Simpson", 3911 test::SetCreditCardInfo(&full_server_card, "Homer Simpson",
3904 "423456789012" /* Visa */, "01", "2999"); 3912 "423456789012" /* Visa */, "01", "2999");
3905 full_server_card.set_use_count(1); 3913 full_server_card.set_use_count(1);
3906 full_server_card.set_use_date(AutofillClock::Now() - 3914 full_server_card.set_use_date(AutofillClock::Now() -
3907 base::TimeDelta::FromDays(15)); 3915 base::TimeDelta::FromDays(15));
3908 credit_cards.push_back(&full_server_card); 3916 credit_cards.push_back(&full_server_card);
3909 3917
3910 // Create a masked server card that is a duplicate of a local card. 3918 // Create a masked server card that is a duplicate of a local card.
3911 CreditCard masked_card(CreditCard::MASKED_SERVER_CARD, "a123"); 3919 CreditCard masked_card(CreditCard::MASKED_SERVER_CARD, "a123");
3912 test::SetCreditCardInfo(&masked_card, "Homer Simpson", "9012" /* Visa */, 3920 test::SetCreditCardInfo(&masked_card, "Homer Simpson", "9012" /* Visa */,
3913 "01", "2999"); 3921 "01", "2999");
3914 masked_card.set_use_count(2); 3922 masked_card.set_use_count(2);
3915 masked_card.set_use_date(AutofillClock::Now() - 3923 masked_card.set_use_date(AutofillClock::Now() -
3916 base::TimeDelta::FromDays(15)); 3924 base::TimeDelta::FromDays(15));
3917 masked_card.SetTypeForMaskedCard(kVisaCard); 3925 masked_card.SetNetworkForMaskedCard(kVisaCard);
3918 credit_cards.push_back(&masked_card); 3926 credit_cards.push_back(&masked_card);
3919 3927
3920 PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards); 3928 PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards);
3921 EXPECT_EQ(2U, credit_cards.size()); 3929 EXPECT_EQ(2U, credit_cards.size());
3922 } 3930 }
3923 3931
3924 // Tests that slightly different local, full server, and masked credit cards are 3932 // Tests that slightly different local, full server, and masked credit cards are
3925 // not deduped. 3933 // not deduped.
3926 TEST_F(PersonalDataManagerTest, DedupeCreditCardToSuggest_DifferentCards) { 3934 TEST_F(PersonalDataManagerTest, DedupeCreditCardToSuggest_DifferentCards) {
3927 std::list<CreditCard*> credit_cards; 3935 std::list<CreditCard*> credit_cards;
3928 3936
3929 CreditCard credit_card2("002149C1-EE28-4213-A3B9-DA243FFF021B", 3937 CreditCard credit_card2("002149C1-EE28-4213-A3B9-DA243FFF021B",
3930 "https://www.example.com"); 3938 "https://www.example.com");
3931 credit_card2.set_use_count(1); 3939 credit_card2.set_use_count(1);
3932 credit_card2.set_use_date(AutofillClock::Now() - 3940 credit_card2.set_use_date(AutofillClock::Now() -
3933 base::TimeDelta::FromDays(1)); 3941 base::TimeDelta::FromDays(1));
3934 test::SetCreditCardInfo(&credit_card2, "Homer Simpson", 3942 test::SetCreditCardInfo(&credit_card2, "Homer Simpson",
3935 "518765432109" /* Mastercard */, "", ""); 3943 "518765432109" /* Mastercard */, "", "");
3936 credit_cards.push_back(&credit_card2); 3944 credit_cards.push_back(&credit_card2);
3937 3945
3938 // Create a masked server card that is slightly different of the local card. 3946 // Create a masked server card that is slightly different of the local card.
3939 CreditCard credit_card4(CreditCard::MASKED_SERVER_CARD, "b456"); 3947 CreditCard credit_card4(CreditCard::MASKED_SERVER_CARD, "b456");
3940 test::SetCreditCardInfo(&credit_card4, "Homer Simpson", "2109", "12", "2999"); 3948 test::SetCreditCardInfo(&credit_card4, "Homer Simpson", "2109", "12", "2999");
3941 credit_card4.set_use_count(3); 3949 credit_card4.set_use_count(3);
3942 credit_card4.set_use_date(AutofillClock::Now() - 3950 credit_card4.set_use_date(AutofillClock::Now() -
3943 base::TimeDelta::FromDays(15)); 3951 base::TimeDelta::FromDays(15));
3944 credit_card4.SetTypeForMaskedCard(kVisaCard); 3952 credit_card4.SetNetworkForMaskedCard(kVisaCard);
3945 credit_cards.push_back(&credit_card4); 3953 credit_cards.push_back(&credit_card4);
3946 3954
3947 // Create a full server card that is slightly different of the two other 3955 // Create a full server card that is slightly different of the two other
3948 // cards. 3956 // cards.
3949 CreditCard credit_card5(CreditCard::FULL_SERVER_CARD, "c789"); 3957 CreditCard credit_card5(CreditCard::FULL_SERVER_CARD, "c789");
3950 test::SetCreditCardInfo(&credit_card5, "Homer Simpson", 3958 test::SetCreditCardInfo(&credit_card5, "Homer Simpson",
3951 "347666888555" /* American Express */, "04", "2999"); 3959 "347666888555" /* American Express */, "04", "2999");
3952 credit_card5.set_use_count(1); 3960 credit_card5.set_use_count(1);
3953 credit_card5.set_use_date(AutofillClock::Now() - 3961 credit_card5.set_use_date(AutofillClock::Now() -
3954 base::TimeDelta::FromDays(15)); 3962 base::TimeDelta::FromDays(15));
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
4021 EXPECT_EQ(kArbitraryTime, added_card->modification_date()); 4029 EXPECT_EQ(kArbitraryTime, added_card->modification_date());
4022 } 4030 }
4023 4031
4024 TEST_F(PersonalDataManagerTest, UpdateServerCreditCardUsageStats) { 4032 TEST_F(PersonalDataManagerTest, UpdateServerCreditCardUsageStats) {
4025 EnableWalletCardImport(); 4033 EnableWalletCardImport();
4026 4034
4027 std::vector<CreditCard> server_cards; 4035 std::vector<CreditCard> server_cards;
4028 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); 4036 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123"));
4029 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", 4037 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger",
4030 "9012" /* Visa */, "01", "2999"); 4038 "9012" /* Visa */, "01", "2999");
4031 server_cards.back().SetTypeForMaskedCard(kVisaCard); 4039 server_cards.back().SetNetworkForMaskedCard(kVisaCard);
4032 4040
4033 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b456")); 4041 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b456"));
4034 test::SetCreditCardInfo(&server_cards.back(), "Bonnie Parker", 4042 test::SetCreditCardInfo(&server_cards.back(), "Bonnie Parker",
4035 "4444" /* Mastercard */, "12", "2999"); 4043 "4444" /* Mastercard */, "12", "2999");
4036 server_cards.back().SetTypeForMaskedCard(kMasterCard); 4044 server_cards.back().SetNetworkForMaskedCard(kMasterCard);
4037 4045
4038 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); 4046 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789"));
4039 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", 4047 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow",
4040 "347666888555" /* American Express */, "04", "2999"); 4048 "347666888555" /* American Express */, "04", "2999");
4041 4049
4042 // Create the test clock and set the time to a specific value. 4050 // Create the test clock and set the time to a specific value.
4043 TestAutofillClock test_clock; 4051 TestAutofillClock test_clock;
4044 test_clock.SetNow(kArbitraryTime); 4052 test_clock.SetNow(kArbitraryTime);
4045 4053
4046 test::SetServerCreditCards(autofill_table_, server_cards); 4054 test::SetServerCreditCards(autofill_table_, server_cards);
(...skipping 13 matching lines...) Expand all
4060 // cards. 4068 // cards.
4061 return; 4069 return;
4062 } 4070 }
4063 4071
4064 // The GUIDs will be different, so just compare the data. 4072 // The GUIDs will be different, so just compare the data.
4065 for (size_t i = 0; i < 3; ++i) 4073 for (size_t i = 0; i < 3; ++i)
4066 EXPECT_EQ(0, server_cards[i].Compare(*personal_data_->GetCreditCards()[i])); 4074 EXPECT_EQ(0, server_cards[i].Compare(*personal_data_->GetCreditCards()[i]));
4067 4075
4068 CreditCard* unmasked_card = &server_cards.front(); 4076 CreditCard* unmasked_card = &server_cards.front();
4069 unmasked_card->set_record_type(CreditCard::FULL_SERVER_CARD); 4077 unmasked_card->set_record_type(CreditCard::FULL_SERVER_CARD);
4070 unmasked_card->SetNumber(ASCIIToUTF16("423456789012")); 4078 unmasked_card->SetNumber(base::ASCIIToUTF16("423456789012"));
4071 EXPECT_NE(0, unmasked_card->Compare( 4079 EXPECT_NE(0, unmasked_card->Compare(
4072 *personal_data_->GetCreditCards().front())); 4080 *personal_data_->GetCreditCards().front()));
4073 personal_data_->UpdateServerCreditCard(*unmasked_card); 4081 personal_data_->UpdateServerCreditCard(*unmasked_card);
4074 4082
4075 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 4083 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
4076 .WillOnce(QuitMainMessageLoop()); 4084 .WillOnce(QuitMainMessageLoop());
4077 base::RunLoop().Run(); 4085 base::RunLoop().Run();
4078 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); 4086 ASSERT_EQ(3U, personal_data_->GetCreditCards().size());
4079 4087
4080 for (size_t i = 0; i < 3; ++i) 4088 for (size_t i = 0; i < 3; ++i)
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
4124 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); 4132 ASSERT_EQ(3U, personal_data_->GetCreditCards().size());
4125 EXPECT_EQ(2U, personal_data_->GetCreditCards()[1]->use_count()); 4133 EXPECT_EQ(2U, personal_data_->GetCreditCards()[1]->use_count());
4126 EXPECT_EQ(kSomeLaterTime, personal_data_->GetCreditCards()[1]->use_date()); 4134 EXPECT_EQ(kSomeLaterTime, personal_data_->GetCreditCards()[1]->use_date());
4127 4135
4128 // Change Now()'s return value for a third time. 4136 // Change Now()'s return value for a third time.
4129 test_clock.SetNow(kMuchLaterTime); 4137 test_clock.SetNow(kMuchLaterTime);
4130 4138
4131 // Upgrading to unmasked retains the usage stats (and increments them). 4139 // Upgrading to unmasked retains the usage stats (and increments them).
4132 CreditCard* unmasked_card2 = &server_cards[1]; 4140 CreditCard* unmasked_card2 = &server_cards[1];
4133 unmasked_card2->set_record_type(CreditCard::FULL_SERVER_CARD); 4141 unmasked_card2->set_record_type(CreditCard::FULL_SERVER_CARD);
4134 unmasked_card2->SetNumber(ASCIIToUTF16("5555555555554444")); 4142 unmasked_card2->SetNumber(base::ASCIIToUTF16("5555555555554444"));
4135 personal_data_->UpdateServerCreditCard(*unmasked_card2); 4143 personal_data_->UpdateServerCreditCard(*unmasked_card2);
4136 4144
4137 server_cards[1].set_guid(personal_data_->GetCreditCards()[1]->guid()); 4145 server_cards[1].set_guid(personal_data_->GetCreditCards()[1]->guid());
4138 personal_data_->RecordUseOf(server_cards[1]); 4146 personal_data_->RecordUseOf(server_cards[1]);
4139 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 4147 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
4140 .WillOnce(QuitMainMessageLoop()); 4148 .WillOnce(QuitMainMessageLoop());
4141 base::RunLoop().Run(); 4149 base::RunLoop().Run();
4142 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); 4150 ASSERT_EQ(3U, personal_data_->GetCreditCards().size());
4143 EXPECT_EQ(3U, personal_data_->GetCreditCards()[1]->use_count()); 4151 EXPECT_EQ(3U, personal_data_->GetCreditCards()[1]->use_count());
4144 EXPECT_EQ(kMuchLaterTime, personal_data_->GetCreditCards()[1]->use_date()); 4152 EXPECT_EQ(kMuchLaterTime, personal_data_->GetCreditCards()[1]->use_date());
4145 } 4153 }
4146 4154
4147 TEST_F(PersonalDataManagerTest, ClearAllServerData) { 4155 TEST_F(PersonalDataManagerTest, ClearAllServerData) {
4148 // Add a server card. 4156 // Add a server card.
4149 std::vector<CreditCard> server_cards; 4157 std::vector<CreditCard> server_cards;
4150 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); 4158 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123"));
4151 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", 4159 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger",
4152 "9012" /* Visa */, "01", "2999"); 4160 "9012" /* Visa */, "01", "2999");
4153 server_cards.back().SetTypeForMaskedCard(kVisaCard); 4161 server_cards.back().SetNetworkForMaskedCard(kVisaCard);
4154 test::SetServerCreditCards(autofill_table_, server_cards); 4162 test::SetServerCreditCards(autofill_table_, server_cards);
4155 personal_data_->Refresh(); 4163 personal_data_->Refresh();
4156 4164
4157 // Need to set the google services username 4165 // Need to set the google services username
4158 EnableWalletCardImport(); 4166 EnableWalletCardImport();
4159 4167
4160 // The card and profile should be there. 4168 // The card and profile should be there.
4161 ResetPersonalDataManager(USER_MODE_NORMAL); 4169 ResetPersonalDataManager(USER_MODE_NORMAL);
4162 EXPECT_FALSE(personal_data_->GetCreditCards().empty()); 4170 EXPECT_FALSE(personal_data_->GetCreditCards().empty());
4163 4171
4164 personal_data_->ClearAllServerData(); 4172 personal_data_->ClearAllServerData();
4165 4173
4166 // Reload the database, everything should be gone. 4174 // Reload the database, everything should be gone.
4167 ResetPersonalDataManager(USER_MODE_NORMAL); 4175 ResetPersonalDataManager(USER_MODE_NORMAL);
4168 EXPECT_TRUE(personal_data_->GetCreditCards().empty()); 4176 EXPECT_TRUE(personal_data_->GetCreditCards().empty());
4169 } 4177 }
4170 4178
4171 TEST_F(PersonalDataManagerTest, DontDuplicateServerCard) { 4179 TEST_F(PersonalDataManagerTest, DontDuplicateServerCard) {
4172 EnableWalletCardImport(); 4180 EnableWalletCardImport();
4173 4181
4174 std::vector<CreditCard> server_cards; 4182 std::vector<CreditCard> server_cards;
4175 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); 4183 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123"));
4176 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", 4184 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger",
4177 "1881" /* Visa */, "01", "2999"); 4185 "1881" /* Visa */, "01", "2999");
4178 server_cards.back().SetTypeForMaskedCard(kVisaCard); 4186 server_cards.back().SetNetworkForMaskedCard(kVisaCard);
4179 4187
4180 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); 4188 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789"));
4181 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", 4189 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow",
4182 "347666888555" /* American Express */, "04", "2999"); 4190 "347666888555" /* American Express */, "04", "2999");
4183 4191
4184 test::SetServerCreditCards(autofill_table_, server_cards); 4192 test::SetServerCreditCards(autofill_table_, server_cards);
4185 personal_data_->Refresh(); 4193 personal_data_->Refresh();
4186 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 4194 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
4187 .WillOnce(QuitMainMessageLoop()); 4195 .WillOnce(QuitMainMessageLoop());
4188 base::RunLoop().Run(); 4196 base::RunLoop().Run();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
4232 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2, false, 4240 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2, false,
4233 &imported_credit_card2)); 4241 &imported_credit_card2));
4234 EXPECT_FALSE(imported_credit_card2); 4242 EXPECT_FALSE(imported_credit_card2);
4235 } 4243 }
4236 4244
4237 // Tests the SaveImportedProfile method with different profiles to make sure the 4245 // Tests the SaveImportedProfile method with different profiles to make sure the
4238 // merge logic works correctly. 4246 // merge logic works correctly.
4239 typedef struct { 4247 typedef struct {
4240 autofill::ServerFieldType field_type; 4248 autofill::ServerFieldType field_type;
4241 std::string field_value; 4249 std::string field_value;
4242 } ProfileField; 4250 } ProfileField;
4243 4251
4244 typedef std::vector<ProfileField> ProfileFields; 4252 typedef std::vector<ProfileField> ProfileFields;
4245 4253
4246 typedef struct { 4254 typedef struct {
4247 // Each test starts with a default pre-existing profile and applies these 4255 // Each test starts with a default pre-existing profile and applies these
4248 // changes to it. 4256 // changes to it.
4249 ProfileFields changes_to_original; 4257 ProfileFields changes_to_original;
4250 // Each test saves a second profile. Applies these changes to the default 4258 // Each test saves a second profile. Applies these changes to the default
4251 // values before saving. 4259 // values before saving.
4252 ProfileFields changes_to_new; 4260 ProfileFields changes_to_new;
4253 // For tests with profile merging, makes sure that these fields' values are 4261 // For tests with profile merging, makes sure that these fields' values are
4254 // the ones we expect (depending on the test). 4262 // the ones we expect (depending on the test).
4255 ProfileFields changed_field_values; 4263 ProfileFields changed_field_values;
4256 } SaveImportedProfileTestCase; 4264 } SaveImportedProfileTestCase;
4257 4265
4258 class SaveImportedProfileTest 4266 class SaveImportedProfileTest
4259 : public PersonalDataManagerTestBase, 4267 : public PersonalDataManagerTestBase,
4260 public testing::TestWithParam<SaveImportedProfileTestCase> { 4268 public testing::TestWithParam<SaveImportedProfileTestCase> {
4261 public: 4269 public:
4262 SaveImportedProfileTest() {} 4270 SaveImportedProfileTest() {}
4263 ~SaveImportedProfileTest() override {} 4271 ~SaveImportedProfileTest() override {}
4264 4272
4265 void SetUp() override { 4273 void SetUp() override {
4266 OSCryptMocker::SetUpWithSingleton(); 4274 OSCryptMocker::SetUpWithSingleton();
4267 prefs_ = test::PrefServiceForTesting(); 4275 prefs_ = test::PrefServiceForTesting();
4268 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 4276 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
4269 base::FilePath path = temp_dir_.GetPath().AppendASCII("TestWebDB"); 4277 base::FilePath path = temp_dir_.GetPath().AppendASCII("TestWebDB");
4270 web_database_ = 4278 web_database_ =
4271 new WebDatabaseService(path, base::ThreadTaskRunnerHandle::Get(), 4279 new WebDatabaseService(path, base::ThreadTaskRunnerHandle::Get(),
4272 base::ThreadTaskRunnerHandle::Get()); 4280 base::ThreadTaskRunnerHandle::Get());
4273 4281
4274 // Setup account tracker. 4282 // Setup account tracker.
4275 signin_client_.reset(new TestSigninClient(prefs_.get())); 4283 signin_client_.reset(new TestSigninClient(prefs_.get()));
4276 account_tracker_.reset(new AccountTrackerService()); 4284 account_tracker_.reset(new AccountTrackerService());
4277 account_tracker_->Initialize(signin_client_.get()); 4285 account_tracker_->Initialize(signin_client_.get());
4278 signin_manager_.reset(new FakeSigninManagerBase(signin_client_.get(), 4286 signin_manager_.reset(new FakeSigninManagerBase(signin_client_.get(),
4279 account_tracker_.get())); 4287 account_tracker_.get()));
4280 signin_manager_->Initialize(prefs_.get()); 4288 signin_manager_->Initialize(prefs_.get());
4281 4289
4282 // Hacky: hold onto a pointer but pass ownership. 4290 // Hacky: hold onto a pointer but pass ownership.
4283 autofill_table_ = new AutofillTable; 4291 autofill_table_ = new AutofillTable;
4284 web_database_->AddTable( 4292 web_database_->AddTable(std::unique_ptr<WebDatabaseTable>(autofill_table_));
4285 std::unique_ptr<WebDatabaseTable>(autofill_table_)); 4293 web_database_->LoadDatabase();
4286 web_database_->LoadDatabase(); 4294 autofill_database_service_ = new AutofillWebDataService(
4287 autofill_database_service_ = new AutofillWebDataService( 4295 web_database_, base::ThreadTaskRunnerHandle::Get(),
4288 web_database_, base::ThreadTaskRunnerHandle::Get(), 4296 base::ThreadTaskRunnerHandle::Get(),
4289 base::ThreadTaskRunnerHandle::Get(), 4297 WebDataServiceBase::ProfileErrorCallback());
4290 WebDataServiceBase::ProfileErrorCallback()); 4298 autofill_database_service_->Init();
4291 autofill_database_service_->Init(); 4299
4292 4300 test::DisableSystemServices(prefs_.get());
4293 test::DisableSystemServices(prefs_.get()); 4301 ResetPersonalDataManager(USER_MODE_NORMAL);
4294 ResetPersonalDataManager(USER_MODE_NORMAL); 4302
4295 4303 // Reset the deduping pref to its default value.
4296 // Reset the deduping pref to its default value. 4304 personal_data_->pref_service_->SetInteger(
4297 personal_data_->pref_service_->SetInteger( 4305 prefs::kAutofillLastVersionDeduped, 0);
4298 prefs::kAutofillLastVersionDeduped, 0); 4306 personal_data_->pref_service_->SetBoolean(
4299 personal_data_->pref_service_->SetBoolean( 4307 prefs::kAutofillProfileUseDatesFixed, false);
4300 prefs::kAutofillProfileUseDatesFixed, false); 4308 }
4309
4310 void TearDown() override {
4311 // Order of destruction is important as AutofillManager relies on
4312 // PersonalDataManager to be around when it gets destroyed.
4313 signin_manager_->Shutdown();
4314 signin_manager_.reset();
4315
4316 account_tracker_->Shutdown();
4317 account_tracker_.reset();
4318 signin_client_.reset();
4319
4320 test::DisableSystemServices(prefs_.get());
4321 OSCryptMocker::TearDown();
4322 }
4323 };
4324
4325 TEST_P(SaveImportedProfileTest, SaveImportedProfile) {
4326 // Create the test clock.
4327 TestAutofillClock test_clock;
4328 auto test_case = GetParam();
4329 // Set the time to a specific value.
4330 test_clock.SetNow(kArbitraryTime);
4331
4332 SetupReferenceProfile();
4333 const std::vector<AutofillProfile*>& initial_profiles =
4334 personal_data_->GetProfiles();
4335
4336 // Apply changes to the original profile (if applicable).
4337 for (ProfileField change : test_case.changes_to_original) {
4338 initial_profiles.front()->SetRawInfo(change.field_type,
4339 base::UTF8ToUTF16(change.field_value));
4340 }
4341
4342 // Set the time to a bigger value.
4343 test_clock.SetNow(kSomeLaterTime);
4344
4345 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com");
4346 test::SetProfileInfo(&profile2, "Marion", "Mitchell", "Morrison",
4347 "johnwayne@me.xyz", "Fox", "123 Zoo St", "unit 5",
4348 "Hollywood", "CA", "91601", "US", "12345678910");
4349
4350 // Apply changes to the second profile (if applicable).
4351 for (ProfileField change : test_case.changes_to_new) {
4352 profile2.SetRawInfo(change.field_type,
4353 base::UTF8ToUTF16(change.field_value));
4354 }
4355
4356 personal_data_->SaveImportedProfile(profile2);
4357
4358 const std::vector<AutofillProfile*>& saved_profiles =
4359 personal_data_->GetProfiles();
4360
4361 // If there are no merge changes to verify, make sure that two profiles were
4362 // saved.
4363 if (test_case.changed_field_values.empty()) {
4364 EXPECT_EQ(2U, saved_profiles.size());
4365 } else {
4366 EXPECT_EQ(1U, saved_profiles.size());
4367
4368 // Make sure the new information was merged correctly.
4369 for (ProfileField changed_field : test_case.changed_field_values) {
4370 EXPECT_EQ(base::UTF8ToUTF16(changed_field.field_value),
4371 saved_profiles.front()->GetRawInfo(changed_field.field_type));
4301 } 4372 }
4302 4373 // Verify that the merged profile's use count, use date and modification
4303 void TearDown() override { 4374 // date were properly updated.
4304 // Order of destruction is important as AutofillManager relies on 4375 EXPECT_EQ(1U, saved_profiles.front()->use_count());
4305 // PersonalDataManager to be around when it gets destroyed. 4376 EXPECT_EQ(kSomeLaterTime, saved_profiles.front()->use_date());
4306 signin_manager_->Shutdown(); 4377 EXPECT_EQ(kSomeLaterTime, saved_profiles.front()->modification_date());
4307 signin_manager_.reset();
4308
4309 account_tracker_->Shutdown();
4310 account_tracker_.reset();
4311 signin_client_.reset();
4312
4313 test::DisableSystemServices(prefs_.get());
4314 OSCryptMocker::TearDown();
4315 }
4316 };
4317
4318 TEST_P(SaveImportedProfileTest, SaveImportedProfile) {
4319 // Create the test clock.
4320 TestAutofillClock test_clock;
4321 auto test_case = GetParam();
4322 // Set the time to a specific value.
4323 test_clock.SetNow(kArbitraryTime);
4324
4325 SetupReferenceProfile();
4326 const std::vector<AutofillProfile*>& initial_profiles =
4327 personal_data_->GetProfiles();
4328
4329 // Apply changes to the original profile (if applicable).
4330 for (ProfileField change : test_case.changes_to_original) {
4331 initial_profiles.front()->SetRawInfo(
4332 change.field_type, base::UTF8ToUTF16(change.field_value));
4333 }
4334
4335 // Set the time to a bigger value.
4336 test_clock.SetNow(kSomeLaterTime);
4337
4338 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com");
4339 test::SetProfileInfo(&profile2, "Marion", "Mitchell", "Morrison",
4340 "johnwayne@me.xyz", "Fox", "123 Zoo St", "unit 5",
4341 "Hollywood", "CA", "91601", "US", "12345678910");
4342
4343 // Apply changes to the second profile (if applicable).
4344 for (ProfileField change : test_case.changes_to_new) {
4345 profile2.SetRawInfo(change.field_type,
4346 base::UTF8ToUTF16(change.field_value));
4347 }
4348
4349 personal_data_->SaveImportedProfile(profile2);
4350
4351 const std::vector<AutofillProfile*>& saved_profiles =
4352 personal_data_->GetProfiles();
4353
4354 // If there are no merge changes to verify, make sure that two profiles were
4355 // saved.
4356 if (test_case.changed_field_values.empty()) {
4357 EXPECT_EQ(2U, saved_profiles.size());
4358 } else {
4359 EXPECT_EQ(1U, saved_profiles.size());
4360
4361 // Make sure the new information was merged correctly.
4362 for (ProfileField changed_field : test_case.changed_field_values) {
4363 EXPECT_EQ(base::UTF8ToUTF16(changed_field.field_value),
4364 saved_profiles.front()->GetRawInfo(changed_field.field_type));
4365 }
4366 // Verify that the merged profile's use count, use date and modification
4367 // date were properly updated.
4368 EXPECT_EQ(1U, saved_profiles.front()->use_count());
4369 EXPECT_EQ(kSomeLaterTime, saved_profiles.front()->use_date());
4370 EXPECT_EQ(kSomeLaterTime, saved_profiles.front()->modification_date());
4371 }
4372
4373 // Erase the profiles for the next test.
4374 ResetProfiles();
4375 } 4378 }
4376 4379
4377 INSTANTIATE_TEST_CASE_P( 4380 // Erase the profiles for the next test.
4378 PersonalDataManagerTest, 4381 ResetProfiles();
4379 SaveImportedProfileTest,
4380 testing::Values(
4381 // Test that saving an identical profile except for the name results
4382 // in two profiles being saved.
4383 SaveImportedProfileTestCase{ProfileFields(),
4384 {{NAME_FIRST, "Marionette"}}},
4385
4386 // Test that saving an identical profile except with the middle name
4387 // initial instead of the full middle name results in the profiles
4388 // getting merged and the full middle name being kept.
4389 SaveImportedProfileTestCase{
4390 ProfileFields(),
4391 {{NAME_MIDDLE, "M"}},
4392 {{NAME_MIDDLE, "Mitchell"},
4393 {NAME_FULL, "Marion Mitchell Morrison"}}},
4394
4395 // Test that saving an identical profile except with the full middle
4396 // name instead of the middle name initial results in the profiles
4397 // getting merged and the full middle name replacing the initial.
4398 SaveImportedProfileTestCase{{{NAME_MIDDLE, "M"}},
4399 {{NAME_MIDDLE, "Mitchell"}},
4400 {{NAME_MIDDLE, "Mitchell"}}},
4401
4402 // Test that saving an identical profile except with no middle name
4403 // results in the profiles getting merged and the full middle name
4404 // being kept.
4405 SaveImportedProfileTestCase{ProfileFields(),
4406 {{NAME_MIDDLE, ""}},
4407 {{NAME_MIDDLE, "Mitchell"}}},
4408
4409 // Test that saving an identical profile except with a middle name
4410 // initial results in the profiles getting merged and the middle name
4411 // initial being saved.
4412 SaveImportedProfileTestCase{{{NAME_MIDDLE, ""}},
4413 {{NAME_MIDDLE, "M"}},
4414 {{NAME_MIDDLE, "M"}}},
4415
4416 // Test that saving an identical profile except with a middle name
4417 // results in the profiles getting merged and the full middle name
4418 // being saved.
4419 SaveImportedProfileTestCase{{{NAME_MIDDLE, ""}},
4420 {{NAME_MIDDLE, "Mitchell"}},
4421 {{NAME_MIDDLE, "Mitchell"}}},
4422
4423 // Test that saving a identical profile except with the full name set
4424 // instead of the name parts results in the two profiles being merged
4425 // and all the name parts kept and the full name being added.
4426 SaveImportedProfileTestCase{
4427 {
4428 {NAME_FIRST, "Marion"},
4429 {NAME_MIDDLE, "Mitchell"},
4430 {NAME_LAST, "Morrison"},
4431 {NAME_FULL, ""},
4432 },
4433 {
4434 {NAME_FIRST, ""},
4435 {NAME_MIDDLE, ""},
4436 {NAME_LAST, ""},
4437 {NAME_FULL, "Marion Mitchell Morrison"},
4438 },
4439 {
4440 {NAME_FIRST, "Marion"},
4441 {NAME_MIDDLE, "Mitchell"},
4442 {NAME_LAST, "Morrison"},
4443 {NAME_FULL, "Marion Mitchell Morrison"},
4444 },
4445 },
4446
4447 // Test that saving a identical profile except with the name parts set
4448 // instead of the full name results in the two profiles being merged
4449 // and the full name being kept and all the name parts being added.
4450 SaveImportedProfileTestCase{
4451 {
4452 {NAME_FIRST, ""},
4453 {NAME_MIDDLE, ""},
4454 {NAME_LAST, ""},
4455 {NAME_FULL, "Marion Mitchell Morrison"},
4456 },
4457 {
4458 {NAME_FIRST, "Marion"},
4459 {NAME_MIDDLE, "Mitchell"},
4460 {NAME_LAST, "Morrison"},
4461 {NAME_FULL, ""},
4462 },
4463 {
4464 {NAME_FIRST, "Marion"},
4465 {NAME_MIDDLE, "Mitchell"},
4466 {NAME_LAST, "Morrison"},
4467 {NAME_FULL, "Marion Mitchell Morrison"},
4468 },
4469 },
4470
4471 // Test that saving a profile that has only a full name set does not
4472 // get merged with a profile with only the name parts set if the names
4473 // are different.
4474 SaveImportedProfileTestCase{
4475 {
4476 {NAME_FIRST, "Marion"},
4477 {NAME_MIDDLE, "Mitchell"},
4478 {NAME_LAST, "Morrison"},
4479 {NAME_FULL, ""},
4480 },
4481 {
4482 {NAME_FIRST, ""},
4483 {NAME_MIDDLE, ""},
4484 {NAME_LAST, ""},
4485 {NAME_FULL, "John Thompson Smith"},
4486 },
4487 },
4488
4489 // Test that saving a profile that has only the name parts set does
4490 // not get merged with a profile with only the full name set if the
4491 // names are different.
4492 SaveImportedProfileTestCase{
4493 {
4494 {NAME_FIRST, ""},
4495 {NAME_MIDDLE, ""},
4496 {NAME_LAST, ""},
4497 {NAME_FULL, "John Thompson Smith"},
4498 },
4499 {
4500 {NAME_FIRST, "Marion"},
4501 {NAME_MIDDLE, "Mitchell"},
4502 {NAME_LAST, "Morrison"},
4503 {NAME_FULL, ""},
4504 },
4505 },
4506
4507 // Test that saving an identical profile except for the first address
4508 // line results in two profiles being saved.
4509 SaveImportedProfileTestCase{
4510 ProfileFields(),
4511 {{ADDRESS_HOME_LINE1, "123 Aquarium St."}}},
4512
4513 // Test that saving an identical profile except for the second address
4514 // line results in two profiles being saved.
4515 SaveImportedProfileTestCase{ProfileFields(),
4516 {{ADDRESS_HOME_LINE2, "unit 7"}}},
4517
4518 // Tests that saving an identical profile that has a new piece of
4519 // information (company name) results in a merge and that the original
4520 // empty value gets overwritten by the new information.
4521 SaveImportedProfileTestCase{{{COMPANY_NAME, ""}},
4522 ProfileFields(),
4523 {{COMPANY_NAME, "Fox"}}},
4524
4525 // Tests that saving an identical profile except a loss of information
4526 // results in a merge but the original value is not overwritten (no
4527 // information loss).
4528 SaveImportedProfileTestCase{ProfileFields(),
4529 {{COMPANY_NAME, ""}},
4530 {{COMPANY_NAME, "Fox"}}},
4531
4532 // Tests that saving an identical profile except a slightly different
4533 // postal code results in a merge with the new value kept.
4534 SaveImportedProfileTestCase{{{ADDRESS_HOME_ZIP, "R2C 0A1"}},
4535 {{ADDRESS_HOME_ZIP, "R2C0A1"}},
4536 {{ADDRESS_HOME_ZIP, "R2C0A1"}}},
4537 SaveImportedProfileTestCase{{{ADDRESS_HOME_ZIP, "R2C0A1"}},
4538 {{ADDRESS_HOME_ZIP, "R2C 0A1"}},
4539 {{ADDRESS_HOME_ZIP, "R2C 0A1"}}},
4540 SaveImportedProfileTestCase{{{ADDRESS_HOME_ZIP, "r2c 0a1"}},
4541 {{ADDRESS_HOME_ZIP, "R2C0A1"}},
4542 {{ADDRESS_HOME_ZIP, "R2C0A1"}}},
4543
4544 // Tests that saving an identical profile plus a new piece of
4545 // information on the address line 2 results in a merge and that the
4546 // original empty value gets overwritten by the new information.
4547 SaveImportedProfileTestCase{{{ADDRESS_HOME_LINE2, ""}},
4548 ProfileFields(),
4549 {{ADDRESS_HOME_LINE2, "unit 5"}}},
4550
4551 // Tests that saving an identical profile except a loss of information
4552 // on the address line 2 results in a merge but that the original
4553 // value gets not overwritten (no information loss).
4554 SaveImportedProfileTestCase{ProfileFields(),
4555 {{ADDRESS_HOME_LINE2, ""}},
4556 {{ADDRESS_HOME_LINE2, "unit 5"}}},
4557
4558 // Tests that saving an identical except with more punctuation in the
4559 // fist address line, while the second is empty, results in a merge
4560 // and that the original address gets overwritten.
4561 SaveImportedProfileTestCase{
4562 {{ADDRESS_HOME_LINE2, ""}},
4563 {{ADDRESS_HOME_LINE2, ""}, {ADDRESS_HOME_LINE1, "123, Zoo St."}},
4564 {{ADDRESS_HOME_LINE1, "123, Zoo St."}}},
4565
4566 // Tests that saving an identical profile except with less punctuation
4567 // in the fist address line, while the second is empty, results in a
4568 // merge and that the longer address is retained.
4569 SaveImportedProfileTestCase{
4570 {{ADDRESS_HOME_LINE2, ""}, {ADDRESS_HOME_LINE1, "123, Zoo St."}},
4571 {{ADDRESS_HOME_LINE2, ""}},
4572 {{ADDRESS_HOME_LINE1, "123 Zoo St"}}},
4573
4574 // Tests that saving an identical profile except additional
4575 // punctuation in the two address lines results in a merge and that
4576 // the newer address is retained.
4577 SaveImportedProfileTestCase{ProfileFields(),
4578 {{ADDRESS_HOME_LINE1, "123, Zoo St."},
4579 {ADDRESS_HOME_LINE2, "unit. 5"}},
4580 {{ADDRESS_HOME_LINE1, "123, Zoo St."},
4581 {ADDRESS_HOME_LINE2, "unit. 5"}}},
4582
4583 // Tests that saving an identical profile except less punctuation in
4584 // the two address lines results in a merge and that the newer address
4585 // is retained.
4586 SaveImportedProfileTestCase{{{ADDRESS_HOME_LINE1, "123, Zoo St."},
4587 {ADDRESS_HOME_LINE2, "unit. 5"}},
4588 ProfileFields(),
4589 {{ADDRESS_HOME_LINE1, "123 Zoo St"},
4590 {ADDRESS_HOME_LINE2, "unit 5"}}},
4591
4592 // Tests that saving an identical profile with accented characters in
4593 // the two address lines results in a merge and that the newer address
4594 // is retained.
4595 SaveImportedProfileTestCase{ProfileFields(),
4596 {{ADDRESS_HOME_LINE1, "123 Zôö St"},
4597 {ADDRESS_HOME_LINE2, "üñìt 5"}},
4598 {{ADDRESS_HOME_LINE1, "123 Zôö St"},
4599 {ADDRESS_HOME_LINE2, "üñìt 5"}}},
4600
4601 // Tests that saving an identical profile without accented characters
4602 // in the two address lines results in a merge and that the newer
4603 // address is retained.
4604 SaveImportedProfileTestCase{{{ADDRESS_HOME_LINE1, "123 Zôö St"},
4605 {ADDRESS_HOME_LINE2, "üñìt 5"}},
4606 ProfileFields(),
4607 {{ADDRESS_HOME_LINE1, "123 Zoo St"},
4608 {ADDRESS_HOME_LINE2, "unit 5"}}},
4609
4610 // Tests that saving an identical profile except that the address line
4611 // 1 is in the address line 2 results in a merge and that the
4612 // multi-lne address is retained.
4613 SaveImportedProfileTestCase{
4614 ProfileFields(),
4615 {{ADDRESS_HOME_LINE1, "123 Zoo St, unit 5"},
4616 {ADDRESS_HOME_LINE2, ""}},
4617 {{ADDRESS_HOME_LINE1, "123 Zoo St"},
4618 {ADDRESS_HOME_LINE2, "unit 5"}}},
4619
4620 // Tests that saving an identical profile except that the address line
4621 // 2 contains part of the old address line 1 results in a merge and
4622 // that the original address lines of the reference profile get
4623 // overwritten.
4624 SaveImportedProfileTestCase{
4625 {{ADDRESS_HOME_LINE1, "123 Zoo St, unit 5"},
4626 {ADDRESS_HOME_LINE2, ""}},
4627 ProfileFields(),
4628 {{ADDRESS_HOME_LINE1, "123 Zoo St"},
4629 {ADDRESS_HOME_LINE2, "unit 5"}}},
4630
4631 // Tests that saving an identical profile except that the state is the
4632 // abbreviation instead of the full form results in a merge and that
4633 // the original state gets overwritten.
4634 SaveImportedProfileTestCase{{{ADDRESS_HOME_STATE, "California"}},
4635 ProfileFields(),
4636 {{ADDRESS_HOME_STATE, "CA"}}},
4637
4638 // Tests that saving an identical profile except that the state is the
4639 // full form instead of the abbreviation results in a merge and that
4640 // the abbreviated state is retained.
4641 SaveImportedProfileTestCase{ProfileFields(),
4642 {{ADDRESS_HOME_STATE, "California"}},
4643 {{ADDRESS_HOME_STATE, "CA"}}},
4644
4645 // Tests that saving and identical profile except that the company
4646 // name has different punctuation and case results in a merge and that
4647 // the syntax of the new profile replaces the old one.
4648 SaveImportedProfileTestCase{{{COMPANY_NAME, "Stark inc"}},
4649 {{COMPANY_NAME, "Stark Inc."}},
4650 {{COMPANY_NAME, "Stark Inc."}}}));
4651
4652 // Tests that MergeProfile tries to merge the imported profile into the
4653 // existing profile in decreasing order of frecency.
4654 TEST_F(PersonalDataManagerTest, MergeProfile_Frecency) {
4655 // Create two very similar profiles except with different company names.
4656 std::unique_ptr<AutofillProfile> profile1 =
4657 base::MakeUnique<AutofillProfile>(base::GenerateGUID(),
4658 "https://www.example.com");
4659 test::SetProfileInfo(profile1.get(), "Homer", "Jay", "Simpson",
4660 "homer.simpson@abc.com", "SNP",
4661 "742 Evergreen Terrace", "", "Springfield", "IL",
4662 "91601", "US", "12345678910");
4663 AutofillProfile* profile2 =
4664 new AutofillProfile(base::GenerateGUID(), "https://www.example.com");
4665 test::SetProfileInfo(profile2, "Homer", "Jay", "Simpson",
4666 "homer.simpson@abc.com", "Fox",
4667 "742 Evergreen Terrace", "", "Springfield", "IL",
4668 "91601", "US", "12345678910");
4669
4670 // Give the "Fox" profile a bigger frecency score.
4671 profile2->set_use_count(15);
4672
4673 // Create the |existing_profiles| vector.
4674 std::vector<std::unique_ptr<AutofillProfile>> existing_profiles;
4675 existing_profiles.push_back(std::move(profile1));
4676 existing_profiles.push_back(base::WrapUnique(profile2));
4677
4678 // Create a new imported profile with no company name.
4679 AutofillProfile imported_profile(base::GenerateGUID(),
4680 "https://www.example.com");
4681 test::SetProfileInfo(&imported_profile, "Homer", "Jay", "Simpson",
4682 "homer.simpson@abc.com", "", "742 Evergreen Terrace",
4683 "", "Springfield", "IL", "91601", "US", "12345678910");
4684
4685 // Merge the imported profile into the existing profiles.
4686 std::vector<AutofillProfile> profiles;
4687 std::string guid = personal_data_->MergeProfile(
4688 imported_profile, &existing_profiles, "US-EN", &profiles);
4689
4690 // The new profile should be merged into the "fox" profile.
4691 EXPECT_EQ(profile2->guid(), guid);
4692 } 4382 }
4693 4383
4384 INSTANTIATE_TEST_CASE_P(
4385 PersonalDataManagerTest,
4386 SaveImportedProfileTest,
4387 testing::Values(
4388 // Test that saving an identical profile except for the name results
4389 // in two profiles being saved.
4390 SaveImportedProfileTestCase{ProfileFields(),
4391 {{NAME_FIRST, "Marionette"}}},
4392
4393 // Test that saving an identical profile except with the middle name
4394 // initial instead of the full middle name results in the profiles
4395 // getting merged and the full middle name being kept.
4396 SaveImportedProfileTestCase{ProfileFields(),
4397 {{NAME_MIDDLE, "M"}},
4398 {{NAME_MIDDLE, "Mitchell"},
4399 {NAME_FULL, "Marion Mitchell Morrison"}}},
4400
4401 // Test that saving an identical profile except with the full middle
4402 // name instead of the middle name initial results in the profiles
4403 // getting merged and the full middle name replacing the initial.
4404 SaveImportedProfileTestCase{{{NAME_MIDDLE, "M"}},
4405 {{NAME_MIDDLE, "Mitchell"}},
4406 {{NAME_MIDDLE, "Mitchell"}}},
4407
4408 // Test that saving an identical profile except with no middle name
4409 // results in the profiles getting merged and the full middle name
4410 // being kept.
4411 SaveImportedProfileTestCase{ProfileFields(),
4412 {{NAME_MIDDLE, ""}},
4413 {{NAME_MIDDLE, "Mitchell"}}},
4414
4415 // Test that saving an identical profile except with a middle name
4416 // initial results in the profiles getting merged and the middle name
4417 // initial being saved.
4418 SaveImportedProfileTestCase{{{NAME_MIDDLE, ""}},
4419 {{NAME_MIDDLE, "M"}},
4420 {{NAME_MIDDLE, "M"}}},
4421
4422 // Test that saving an identical profile except with a middle name
4423 // results in the profiles getting merged and the full middle name
4424 // being saved.
4425 SaveImportedProfileTestCase{{{NAME_MIDDLE, ""}},
4426 {{NAME_MIDDLE, "Mitchell"}},
4427 {{NAME_MIDDLE, "Mitchell"}}},
4428
4429 // Test that saving a identical profile except with the full name set
4430 // instead of the name parts results in the two profiles being merged
4431 // and all the name parts kept and the full name being added.
4432 SaveImportedProfileTestCase{
4433 {
4434 {NAME_FIRST, "Marion"},
4435 {NAME_MIDDLE, "Mitchell"},
4436 {NAME_LAST, "Morrison"},
4437 {NAME_FULL, ""},
4438 },
4439 {
4440 {NAME_FIRST, ""},
4441 {NAME_MIDDLE, ""},
4442 {NAME_LAST, ""},
4443 {NAME_FULL, "Marion Mitchell Morrison"},
4444 },
4445 {
4446 {NAME_FIRST, "Marion"},
4447 {NAME_MIDDLE, "Mitchell"},
4448 {NAME_LAST, "Morrison"},
4449 {NAME_FULL, "Marion Mitchell Morrison"},
4450 },
4451 },
4452
4453 // Test that saving a identical profile except with the name parts set
4454 // instead of the full name results in the two profiles being merged
4455 // and the full name being kept and all the name parts being added.
4456 SaveImportedProfileTestCase{
4457 {
4458 {NAME_FIRST, ""},
4459 {NAME_MIDDLE, ""},
4460 {NAME_LAST, ""},
4461 {NAME_FULL, "Marion Mitchell Morrison"},
4462 },
4463 {
4464 {NAME_FIRST, "Marion"},
4465 {NAME_MIDDLE, "Mitchell"},
4466 {NAME_LAST, "Morrison"},
4467 {NAME_FULL, ""},
4468 },
4469 {
4470 {NAME_FIRST, "Marion"},
4471 {NAME_MIDDLE, "Mitchell"},
4472 {NAME_LAST, "Morrison"},
4473 {NAME_FULL, "Marion Mitchell Morrison"},
4474 },
4475 },
4476
4477 // Test that saving a profile that has only a full name set does not
4478 // get merged with a profile with only the name parts set if the names
4479 // are different.
4480 SaveImportedProfileTestCase{
4481 {
4482 {NAME_FIRST, "Marion"},
4483 {NAME_MIDDLE, "Mitchell"},
4484 {NAME_LAST, "Morrison"},
4485 {NAME_FULL, ""},
4486 },
4487 {
4488 {NAME_FIRST, ""},
4489 {NAME_MIDDLE, ""},
4490 {NAME_LAST, ""},
4491 {NAME_FULL, "John Thompson Smith"},
4492 },
4493 },
4494
4495 // Test that saving a profile that has only the name parts set does
4496 // not get merged with a profile with only the full name set if the
4497 // names are different.
4498 SaveImportedProfileTestCase{
4499 {
4500 {NAME_FIRST, ""},
4501 {NAME_MIDDLE, ""},
4502 {NAME_LAST, ""},
4503 {NAME_FULL, "John Thompson Smith"},
4504 },
4505 {
4506 {NAME_FIRST, "Marion"},
4507 {NAME_MIDDLE, "Mitchell"},
4508 {NAME_LAST, "Morrison"},
4509 {NAME_FULL, ""},
4510 },
4511 },
4512
4513 // Test that saving an identical profile except for the first address
4514 // line results in two profiles being saved.
4515 SaveImportedProfileTestCase{ProfileFields(),
4516 {{ADDRESS_HOME_LINE1, "123 Aquarium St."}}},
4517
4518 // Test that saving an identical profile except for the second address
4519 // line results in two profiles being saved.
4520 SaveImportedProfileTestCase{ProfileFields(),
4521 {{ADDRESS_HOME_LINE2, "unit 7"}}},
4522
4523 // Tests that saving an identical profile that has a new piece of
4524 // information (company name) results in a merge and that the original
4525 // empty value gets overwritten by the new information.
4526 SaveImportedProfileTestCase{{{COMPANY_NAME, ""}},
4527 ProfileFields(),
4528 {{COMPANY_NAME, "Fox"}}},
4529
4530 // Tests that saving an identical profile except a loss of information
4531 // results in a merge but the original value is not overwritten (no
4532 // information loss).
4533 SaveImportedProfileTestCase{ProfileFields(),
4534 {{COMPANY_NAME, ""}},
4535 {{COMPANY_NAME, "Fox"}}},
4536
4537 // Tests that saving an identical profile except a slightly different
4538 // postal code results in a merge with the new value kept.
4539 SaveImportedProfileTestCase{{{ADDRESS_HOME_ZIP, "R2C 0A1"}},
4540 {{ADDRESS_HOME_ZIP, "R2C0A1"}},
4541 {{ADDRESS_HOME_ZIP, "R2C0A1"}}},
4542 SaveImportedProfileTestCase{{{ADDRESS_HOME_ZIP, "R2C0A1"}},
4543 {{ADDRESS_HOME_ZIP, "R2C 0A1"}},
4544 {{ADDRESS_HOME_ZIP, "R2C 0A1"}}},
4545 SaveImportedProfileTestCase{{{ADDRESS_HOME_ZIP, "r2c 0a1"}},
4546 {{ADDRESS_HOME_ZIP, "R2C0A1"}},
4547 {{ADDRESS_HOME_ZIP, "R2C0A1"}}},
4548
4549 // Tests that saving an identical profile plus a new piece of
4550 // information on the address line 2 results in a merge and that the
4551 // original empty value gets overwritten by the new information.
4552 SaveImportedProfileTestCase{{{ADDRESS_HOME_LINE2, ""}},
4553 ProfileFields(),
4554 {{ADDRESS_HOME_LINE2, "unit 5"}}},
4555
4556 // Tests that saving an identical profile except a loss of information
4557 // on the address line 2 results in a merge but that the original
4558 // value gets not overwritten (no information loss).
4559 SaveImportedProfileTestCase{ProfileFields(),
4560 {{ADDRESS_HOME_LINE2, ""}},
4561 {{ADDRESS_HOME_LINE2, "unit 5"}}},
4562
4563 // Tests that saving an identical except with more punctuation in the
4564 // fist address line, while the second is empty, results in a merge
4565 // and that the original address gets overwritten.
4566 SaveImportedProfileTestCase{
4567 {{ADDRESS_HOME_LINE2, ""}},
4568 {{ADDRESS_HOME_LINE2, ""}, {ADDRESS_HOME_LINE1, "123, Zoo St."}},
4569 {{ADDRESS_HOME_LINE1, "123, Zoo St."}}},
4570
4571 // Tests that saving an identical profile except with less punctuation
4572 // in the fist address line, while the second is empty, results in a
4573 // merge and that the longer address is retained.
4574 SaveImportedProfileTestCase{
4575 {{ADDRESS_HOME_LINE2, ""}, {ADDRESS_HOME_LINE1, "123, Zoo St."}},
4576 {{ADDRESS_HOME_LINE2, ""}},
4577 {{ADDRESS_HOME_LINE1, "123 Zoo St"}}},
4578
4579 // Tests that saving an identical profile except additional
4580 // punctuation in the two address lines results in a merge and that
4581 // the newer address is retained.
4582 SaveImportedProfileTestCase{ProfileFields(),
4583 {{ADDRESS_HOME_LINE1, "123, Zoo St."},
4584 {ADDRESS_HOME_LINE2, "unit. 5"}},
4585 {{ADDRESS_HOME_LINE1, "123, Zoo St."},
4586 {ADDRESS_HOME_LINE2, "unit. 5"}}},
4587
4588 // Tests that saving an identical profile except less punctuation in
4589 // the two address lines results in a merge and that the newer address
4590 // is retained.
4591 SaveImportedProfileTestCase{{{ADDRESS_HOME_LINE1, "123, Zoo St."},
4592 {ADDRESS_HOME_LINE2, "unit. 5"}},
4593 ProfileFields(),
4594 {{ADDRESS_HOME_LINE1, "123 Zoo St"},
4595 {ADDRESS_HOME_LINE2, "unit 5"}}},
4596
4597 // Tests that saving an identical profile with accented characters in
4598 // the two address lines results in a merge and that the newer address
4599 // is retained.
4600 SaveImportedProfileTestCase{ProfileFields(),
4601 {{ADDRESS_HOME_LINE1, "123 Zôö St"},
4602 {ADDRESS_HOME_LINE2, "üñìt 5"}},
4603 {{ADDRESS_HOME_LINE1, "123 Zôö St"},
4604 {ADDRESS_HOME_LINE2, "üñìt 5"}}},
4605
4606 // Tests that saving an identical profile without accented characters
4607 // in the two address lines results in a merge and that the newer
4608 // address is retained.
4609 SaveImportedProfileTestCase{{{ADDRESS_HOME_LINE1, "123 Zôö St"},
4610 {ADDRESS_HOME_LINE2, "üñìt 5"}},
4611 ProfileFields(),
4612 {{ADDRESS_HOME_LINE1, "123 Zoo St"},
4613 {ADDRESS_HOME_LINE2, "unit 5"}}},
4614
4615 // Tests that saving an identical profile except that the address line
4616 // 1 is in the address line 2 results in a merge and that the
4617 // multi-lne address is retained.
4618 SaveImportedProfileTestCase{ProfileFields(),
4619 {{ADDRESS_HOME_LINE1, "123 Zoo St, unit 5"},
4620 {ADDRESS_HOME_LINE2, ""}},
4621 {{ADDRESS_HOME_LINE1, "123 Zoo St"},
4622 {ADDRESS_HOME_LINE2, "unit 5"}}},
4623
4624 // Tests that saving an identical profile except that the address line
4625 // 2 contains part of the old address line 1 results in a merge and
4626 // that the original address lines of the reference profile get
4627 // overwritten.
4628 SaveImportedProfileTestCase{{{ADDRESS_HOME_LINE1, "123 Zoo St, unit 5"},
4629 {ADDRESS_HOME_LINE2, ""}},
4630 ProfileFields(),
4631 {{ADDRESS_HOME_LINE1, "123 Zoo St"},
4632 {ADDRESS_HOME_LINE2, "unit 5"}}},
4633
4634 // Tests that saving an identical profile except that the state is the
4635 // abbreviation instead of the full form results in a merge and that
4636 // the original state gets overwritten.
4637 SaveImportedProfileTestCase{{{ADDRESS_HOME_STATE, "California"}},
4638 ProfileFields(),
4639 {{ADDRESS_HOME_STATE, "CA"}}},
4640
4641 // Tests that saving an identical profile except that the state is the
4642 // full form instead of the abbreviation results in a merge and that
4643 // the abbreviated state is retained.
4644 SaveImportedProfileTestCase{ProfileFields(),
4645 {{ADDRESS_HOME_STATE, "California"}},
4646 {{ADDRESS_HOME_STATE, "CA"}}},
4647
4648 // Tests that saving and identical profile except that the company
4649 // name has different punctuation and case results in a merge and that
4650 // the syntax of the new profile replaces the old one.
4651 SaveImportedProfileTestCase{{{COMPANY_NAME, "Stark inc"}},
4652 {{COMPANY_NAME, "Stark Inc."}},
4653 {{COMPANY_NAME, "Stark Inc."}}}));
4654
4655 // Tests that MergeProfile tries to merge the imported profile into the
4656 // existing profile in decreasing order of frecency.
4657 TEST_F(PersonalDataManagerTest, MergeProfile_Frecency) {
4658 // Create two very similar profiles except with different company names.
4659 std::unique_ptr<AutofillProfile> profile1 = base::MakeUnique<AutofillProfile>(
4660 base::GenerateGUID(), "https://www.example.com");
4661 test::SetProfileInfo(profile1.get(), "Homer", "Jay", "Simpson",
4662 "homer.simpson@abc.com", "SNP", "742 Evergreen Terrace",
4663 "", "Springfield", "IL", "91601", "US", "12345678910");
4664 AutofillProfile* profile2 =
4665 new AutofillProfile(base::GenerateGUID(), "https://www.example.com");
4666 test::SetProfileInfo(profile2, "Homer", "Jay", "Simpson",
4667 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace",
4668 "", "Springfield", "IL", "91601", "US", "12345678910");
4669
4670 // Give the "Fox" profile a bigger frecency score.
4671 profile2->set_use_count(15);
4672
4673 // Create the |existing_profiles| vector.
4674 std::vector<std::unique_ptr<AutofillProfile>> existing_profiles;
4675 existing_profiles.push_back(std::move(profile1));
4676 existing_profiles.push_back(base::WrapUnique(profile2));
4677
4678 // Create a new imported profile with no company name.
4679 AutofillProfile imported_profile(base::GenerateGUID(),
4680 "https://www.example.com");
4681 test::SetProfileInfo(&imported_profile, "Homer", "Jay", "Simpson",
4682 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "",
4683 "Springfield", "IL", "91601", "US", "12345678910");
4684
4685 // Merge the imported profile into the existing profiles.
4686 std::vector<AutofillProfile> profiles;
4687 std::string guid = personal_data_->MergeProfile(
4688 imported_profile, &existing_profiles, "US-EN", &profiles);
4689
4690 // The new profile should be merged into the "fox" profile.
4691 EXPECT_EQ(profile2->guid(), guid);
4692 }
4693
4694 // Tests that MergeProfile produces a merged profile with the expected usage 4694 // Tests that MergeProfile produces a merged profile with the expected usage
4695 // statistics. 4695 // statistics.
4696 // Flaky on TSan, see crbug.com/686226. 4696 // Flaky on TSan, see crbug.com/686226.
4697 #if defined(THREAD_SANITIZER) 4697 #if defined(THREAD_SANITIZER)
4698 #define MAYBE_MergeProfile_UsageStats DISABLED_MergeProfile_UsageStats 4698 #define MAYBE_MergeProfile_UsageStats DISABLED_MergeProfile_UsageStats
4699 #else 4699 #else
4700 #define MAYBE_MergeProfile_UsageStats MergeProfile_UsageStats 4700 #define MAYBE_MergeProfile_UsageStats MergeProfile_UsageStats
4701 #endif 4701 #endif
4702 TEST_F(PersonalDataManagerTest, MAYBE_MergeProfile_UsageStats) { 4702 TEST_F(PersonalDataManagerTest, MAYBE_MergeProfile_UsageStats) {
4703 // Create the test clock and set the time to a specific value. 4703 // Create the test clock and set the time to a specific value.
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
5163 // 2 profiles were removed (profiles 1 and 2). 5163 // 2 profiles were removed (profiles 1 and 2).
5164 histogram_tester.ExpectUniqueSample( 5164 histogram_tester.ExpectUniqueSample(
5165 "Autofill.NumberOfProfilesRemovedDuringDedupe", 2, 1); 5165 "Autofill.NumberOfProfilesRemovedDuringDedupe", 2, 1);
5166 5166
5167 // Since profiles with higher frecency scores are merged into profiles with 5167 // Since profiles with higher frecency scores are merged into profiles with
5168 // lower frecency scores, the result of the merge should be contained in 5168 // lower frecency scores, the result of the merge should be contained in
5169 // profile3 since it had a lower frecency score compared to profile1. 5169 // profile3 since it had a lower frecency score compared to profile1.
5170 EXPECT_EQ(profile3.guid(), profiles[0]->guid()); 5170 EXPECT_EQ(profile3.guid(), profiles[0]->guid());
5171 // The address syntax that results from the merge should be the one from the 5171 // The address syntax that results from the merge should be the one from the
5172 // imported profile (highest frecency). 5172 // imported profile (highest frecency).
5173 EXPECT_EQ(UTF8ToUTF16("742. Evergreen Terrace"), 5173 EXPECT_EQ(base::UTF8ToUTF16("742. Evergreen Terrace"),
5174 profiles[0]->GetRawInfo(ADDRESS_HOME_LINE1)); 5174 profiles[0]->GetRawInfo(ADDRESS_HOME_LINE1));
5175 // The middle name should be full, even if the profile with the higher 5175 // The middle name should be full, even if the profile with the higher
5176 // frecency only had an initial (no loss of information). 5176 // frecency only had an initial (no loss of information).
5177 EXPECT_EQ(UTF8ToUTF16("Jay"), profiles[0]->GetRawInfo(NAME_MIDDLE)); 5177 EXPECT_EQ(base::UTF8ToUTF16("Jay"), profiles[0]->GetRawInfo(NAME_MIDDLE));
5178 // The specified phone number from profile1 should be kept (no loss of 5178 // The specified phone number from profile1 should be kept (no loss of
5179 // information). 5179 // information).
5180 EXPECT_EQ(UTF8ToUTF16("12345678910"), 5180 EXPECT_EQ(base::UTF8ToUTF16("12345678910"),
5181 profiles[0]->GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); 5181 profiles[0]->GetRawInfo(PHONE_HOME_WHOLE_NUMBER));
5182 // The specified company name from profile2 should be kept (no loss of 5182 // The specified company name from profile2 should be kept (no loss of
5183 // information). 5183 // information).
5184 EXPECT_EQ(UTF8ToUTF16("Fox"), profiles[0]->GetRawInfo(COMPANY_NAME)); 5184 EXPECT_EQ(base::UTF8ToUTF16("Fox"), profiles[0]->GetRawInfo(COMPANY_NAME));
5185 // The specified country from the imported profile shoudl be kept (no loss of 5185 // The specified country from the imported profile shoudl be kept (no loss of
5186 // information). 5186 // information).
5187 EXPECT_EQ(UTF8ToUTF16("US"), profiles[0]->GetRawInfo(ADDRESS_HOME_COUNTRY)); 5187 EXPECT_EQ(base::UTF8ToUTF16("US"),
5188 profiles[0]->GetRawInfo(ADDRESS_HOME_COUNTRY));
5188 // The use count that results from the merge should be the max of all the 5189 // The use count that results from the merge should be the max of all the
5189 // profiles use counts. 5190 // profiles use counts.
5190 EXPECT_EQ(10U, profiles[0]->use_count()); 5191 EXPECT_EQ(10U, profiles[0]->use_count());
5191 // The use date that results from the merge should be the one from the 5192 // The use date that results from the merge should be the one from the
5192 // profile1 since it was the most recently used profile. 5193 // profile1 since it was the most recently used profile.
5193 EXPECT_LT(profile1.use_date() - base::TimeDelta::FromSeconds(10), 5194 EXPECT_LT(profile1.use_date() - base::TimeDelta::FromSeconds(10),
5194 profiles[0]->use_date()); 5195 profiles[0]->use_date());
5195 } 5196 }
5196 5197
5197 // Tests that ApplyDedupingRoutine only keeps the verified profile with its 5198 // Tests that ApplyDedupingRoutine only keeps the verified profile with its
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
5622 // The remaining profiles should be |Homer3|, |Marge1|, |Homer4| and |Barney| 5623 // The remaining profiles should be |Homer3|, |Marge1|, |Homer4| and |Barney|
5623 // in this order of frecency. 5624 // in this order of frecency.
5624 EXPECT_EQ(Homer3.guid(), profiles[0]->guid()); 5625 EXPECT_EQ(Homer3.guid(), profiles[0]->guid());
5625 EXPECT_EQ(Marge1.guid(), profiles[1]->guid()); 5626 EXPECT_EQ(Marge1.guid(), profiles[1]->guid());
5626 EXPECT_EQ(Homer4.guid(), profiles[2]->guid()); 5627 EXPECT_EQ(Homer4.guid(), profiles[2]->guid());
5627 EXPECT_EQ(Barney.guid(), profiles[3]->guid()); 5628 EXPECT_EQ(Barney.guid(), profiles[3]->guid());
5628 5629
5629 // |Homer3|'s data: 5630 // |Homer3|'s data:
5630 // The address should be saved with the syntax of |Homer1| since it has the 5631 // The address should be saved with the syntax of |Homer1| since it has the
5631 // highest frecency score. 5632 // highest frecency score.
5632 EXPECT_EQ(UTF8ToUTF16("742. Evergreen Terrace"), 5633 EXPECT_EQ(base::UTF8ToUTF16("742. Evergreen Terrace"),
5633 profiles[0]->GetRawInfo(ADDRESS_HOME_LINE1)); 5634 profiles[0]->GetRawInfo(ADDRESS_HOME_LINE1));
5634 // The middle name should be the full version found in |Homer2|, 5635 // The middle name should be the full version found in |Homer2|,
5635 EXPECT_EQ(UTF8ToUTF16("Jay"), profiles[0]->GetRawInfo(NAME_MIDDLE)); 5636 EXPECT_EQ(base::UTF8ToUTF16("Jay"), profiles[0]->GetRawInfo(NAME_MIDDLE));
5636 // The phone number from |Homer2| should be kept (no loss of information). 5637 // The phone number from |Homer2| should be kept (no loss of information).
5637 EXPECT_EQ(UTF8ToUTF16("12345678910"), 5638 EXPECT_EQ(base::UTF8ToUTF16("12345678910"),
5638 profiles[0]->GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); 5639 profiles[0]->GetRawInfo(PHONE_HOME_WHOLE_NUMBER));
5639 // The company name from |Homer3| should be kept (no loss of information). 5640 // The company name from |Homer3| should be kept (no loss of information).
5640 EXPECT_EQ(UTF8ToUTF16("Fox"), profiles[0]->GetRawInfo(COMPANY_NAME)); 5641 EXPECT_EQ(base::UTF8ToUTF16("Fox"), profiles[0]->GetRawInfo(COMPANY_NAME));
5641 // The country from |Homer1| profile should be kept (no loss of information). 5642 // The country from |Homer1| profile should be kept (no loss of information).
5642 EXPECT_EQ(UTF8ToUTF16("US"), profiles[0]->GetRawInfo(ADDRESS_HOME_COUNTRY)); 5643 EXPECT_EQ(base::UTF8ToUTF16("US"),
5644 profiles[0]->GetRawInfo(ADDRESS_HOME_COUNTRY));
5643 // The use count that results from the merge should be the max of Homer 1, 2 5645 // The use count that results from the merge should be the max of Homer 1, 2
5644 // and 3's respective use counts. 5646 // and 3's respective use counts.
5645 EXPECT_EQ(10U, profiles[0]->use_count()); 5647 EXPECT_EQ(10U, profiles[0]->use_count());
5646 // The use date that results from the merge should be the one from the 5648 // The use date that results from the merge should be the one from the
5647 // |Homer1| since it was the most recently used profile. 5649 // |Homer1| since it was the most recently used profile.
5648 EXPECT_LT(Homer1.use_date() - base::TimeDelta::FromSeconds(5), 5650 EXPECT_LT(Homer1.use_date() - base::TimeDelta::FromSeconds(5),
5649 profiles[0]->use_date()); 5651 profiles[0]->use_date());
5650 EXPECT_GT(Homer1.use_date() + base::TimeDelta::FromSeconds(5), 5652 EXPECT_GT(Homer1.use_date() + base::TimeDelta::FromSeconds(5),
5651 profiles[0]->use_date()); 5653 profiles[0]->use_date());
5652 5654
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
5706 base::RunLoop().Run(); 5708 base::RunLoop().Run();
5707 5709
5708 EXPECT_EQ(1U, personal_data_->GetProfiles().size()); 5710 EXPECT_EQ(1U, personal_data_->GetProfiles().size());
5709 5711
5710 // Enable the profile cleanup now. Otherwise it would be triggered by the 5712 // Enable the profile cleanup now. Otherwise it would be triggered by the
5711 // calls to AddProfile. 5713 // calls to AddProfile.
5712 EnableAutofillProfileCleanup(); 5714 EnableAutofillProfileCleanup();
5713 EXPECT_FALSE(personal_data_->ApplyDedupingRoutine()); 5715 EXPECT_FALSE(personal_data_->ApplyDedupingRoutine());
5714 } 5716 }
5715 5717
5716
5717 // Tests that ApplyDedupingRoutine is not run a second time on the same major 5718 // Tests that ApplyDedupingRoutine is not run a second time on the same major
5718 // version. 5719 // version.
5719 TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_OncePerVersion) { 5720 TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_OncePerVersion) {
5720 // Create a profile to dedupe. 5721 // Create a profile to dedupe.
5721 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); 5722 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com");
5722 test::SetProfileInfo(&profile1, "Homer", "J", "Simpson", 5723 test::SetProfileInfo(&profile1, "Homer", "J", "Simpson",
5723 "homer.simpson@abc.com", "", "742. Evergreen Terrace", 5724 "homer.simpson@abc.com", "", "742. Evergreen Terrace",
5724 "", "Springfield", "IL", "91601", "US", ""); 5725 "", "Springfield", "IL", "91601", "US", "");
5725 5726
5726 // Create a similar profile. 5727 // Create a similar profile.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
5801 5802
5802 // Add a different server profile. 5803 // Add a different server profile.
5803 std::vector<AutofillProfile> GetServerProfiles; 5804 std::vector<AutofillProfile> GetServerProfiles;
5804 GetServerProfiles.push_back( 5805 GetServerProfiles.push_back(
5805 AutofillProfile(AutofillProfile::SERVER_PROFILE, kServerAddressId)); 5806 AutofillProfile(AutofillProfile::SERVER_PROFILE, kServerAddressId));
5806 test::SetProfileInfo(&GetServerProfiles.back(), "John", "", "Doe", "", 5807 test::SetProfileInfo(&GetServerProfiles.back(), "John", "", "Doe", "",
5807 "ACME Corp", "500 Oak View", "Apt 8", "Houston", "TX", 5808 "ACME Corp", "500 Oak View", "Apt 8", "Houston", "TX",
5808 "77401", "US", ""); 5809 "77401", "US", "");
5809 // Wallet only provides a full name, so the above first and last names 5810 // Wallet only provides a full name, so the above first and last names
5810 // will be ignored when the profile is written to the DB. 5811 // will be ignored when the profile is written to the DB.
5811 GetServerProfiles.back().SetRawInfo(NAME_FULL, ASCIIToUTF16("John Doe")); 5812 GetServerProfiles.back().SetRawInfo(NAME_FULL,
5813 base::ASCIIToUTF16("John Doe"));
5812 GetServerProfiles.back().set_use_count(100); 5814 GetServerProfiles.back().set_use_count(100);
5813 autofill_table_->SetServerProfiles(GetServerProfiles); 5815 autofill_table_->SetServerProfiles(GetServerProfiles);
5814 5816
5815 // Add a server and a local card that have the server address as billing 5817 // Add a server and a local card that have the server address as billing
5816 // address. 5818 // address.
5817 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15", 5819 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15",
5818 "https://www.example.com"); 5820 "https://www.example.com");
5819 test::SetCreditCardInfo(&local_card, "Clyde Barrow", 5821 test::SetCreditCardInfo(&local_card, "Clyde Barrow",
5820 "347666888555" /* American Express */, "04", "2999"); 5822 "347666888555" /* American Express */, "04", "2999");
5821 local_card.set_billing_address_id(kServerAddressId); 5823 local_card.set_billing_address_id(kServerAddressId);
5822 personal_data_->AddCreditCard(local_card); 5824 personal_data_->AddCreditCard(local_card);
5823 5825
5824 std::vector<CreditCard> server_cards; 5826 std::vector<CreditCard> server_cards;
5825 server_cards.push_back( 5827 server_cards.push_back(
5826 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card1")); 5828 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card1"));
5827 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", 5829 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger",
5828 "1111" /* Visa */, "01", "2999"); 5830 "1111" /* Visa */, "01", "2999");
5829 server_cards.back().SetTypeForMaskedCard(kVisaCard); 5831 server_cards.back().SetNetworkForMaskedCard(kVisaCard);
5830 server_cards.back().set_billing_address_id(kServerAddressId); 5832 server_cards.back().set_billing_address_id(kServerAddressId);
5831 test::SetServerCreditCards(autofill_table_, server_cards); 5833 test::SetServerCreditCards(autofill_table_, server_cards);
5832 5834
5833 // Make sure everything is setup correctly. 5835 // Make sure everything is setup correctly.
5834 personal_data_->Refresh(); 5836 personal_data_->Refresh();
5835 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 5837 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
5836 .WillOnce(QuitMainMessageLoop()); 5838 .WillOnce(QuitMainMessageLoop());
5837 base::RunLoop().Run(); 5839 base::RunLoop().Run();
5838 EXPECT_EQ(1U, personal_data_->web_profiles().size()); 5840 EXPECT_EQ(1U, personal_data_->web_profiles().size());
5839 EXPECT_EQ(1U, personal_data_->GetServerProfiles().size()); 5841 EXPECT_EQ(1U, personal_data_->GetServerProfiles().size());
(...skipping 20 matching lines...) Expand all
5860 5862
5861 // The conversion should be recorded in the Wallet address. 5863 // The conversion should be recorded in the Wallet address.
5862 EXPECT_TRUE(personal_data_->GetServerProfiles().back()->has_converted()); 5864 EXPECT_TRUE(personal_data_->GetServerProfiles().back()->has_converted());
5863 5865
5864 // Get the profiles, sorted by frecency to have a deterministic order. 5866 // Get the profiles, sorted by frecency to have a deterministic order.
5865 std::vector<AutofillProfile*> profiles = 5867 std::vector<AutofillProfile*> profiles =
5866 personal_data_->GetProfilesToSuggest(); 5868 personal_data_->GetProfilesToSuggest();
5867 5869
5868 // Make sure that the two profiles have not merged. 5870 // Make sure that the two profiles have not merged.
5869 ASSERT_EQ(2U, profiles.size()); 5871 ASSERT_EQ(2U, profiles.size());
5870 EXPECT_EQ(UTF8ToUTF16("John"), profiles[0]->GetRawInfo(NAME_FIRST)); 5872 EXPECT_EQ(base::UTF8ToUTF16("John"), profiles[0]->GetRawInfo(NAME_FIRST));
5871 EXPECT_EQ(local_profile, *profiles[1]); 5873 EXPECT_EQ(local_profile, *profiles[1]);
5872 5874
5873 // Make sure that the billing address id of the two cards now point to the 5875 // Make sure that the billing address id of the two cards now point to the
5874 // converted profile. 5876 // converted profile.
5875 EXPECT_EQ(profiles[0]->guid(), 5877 EXPECT_EQ(profiles[0]->guid(),
5876 personal_data_->GetCreditCards()[0]->billing_address_id()); 5878 personal_data_->GetCreditCards()[0]->billing_address_id());
5877 EXPECT_EQ(profiles[0]->guid(), 5879 EXPECT_EQ(profiles[0]->guid(),
5878 personal_data_->GetCreditCards()[1]->billing_address_id()); 5880 personal_data_->GetCreditCards()[1]->billing_address_id());
5879 5881
5880 // Make sure that the added address has the email address of the currently 5882 // Make sure that the added address has the email address of the currently
5881 // signed-in user. 5883 // signed-in user.
5882 EXPECT_EQ(UTF8ToUTF16("syncuser@example.com"), 5884 EXPECT_EQ(base::UTF8ToUTF16("syncuser@example.com"),
5883 profiles[0]->GetRawInfo(EMAIL_ADDRESS)); 5885 profiles[0]->GetRawInfo(EMAIL_ADDRESS));
5884 } 5886 }
5885 5887
5886 // Tests that the converted wallet address is merged into an existing local 5888 // Tests that the converted wallet address is merged into an existing local
5887 // profile if they are considered equivalent. Also tests that the billing 5889 // profile if they are considered equivalent. Also tests that the billing
5888 // address relationship was transferred to the converted address. 5890 // address relationship was transferred to the converted address.
5889 TEST_F(PersonalDataManagerTest, 5891 TEST_F(PersonalDataManagerTest,
5890 ConvertWalletAddressesAndUpdateWalletCards_MergedProfile) { 5892 ConvertWalletAddressesAndUpdateWalletCards_MergedProfile) {
5891 /////////////////////////////////////////////////////////////////////// 5893 ///////////////////////////////////////////////////////////////////////
5892 // Setup. 5894 // Setup.
(...skipping 15 matching lines...) Expand all
5908 personal_data_->AddProfile(local_profile); 5910 personal_data_->AddProfile(local_profile);
5909 5911
5910 // Add a different server profile. 5912 // Add a different server profile.
5911 std::vector<AutofillProfile> GetServerProfiles; 5913 std::vector<AutofillProfile> GetServerProfiles;
5912 GetServerProfiles.push_back( 5914 GetServerProfiles.push_back(
5913 AutofillProfile(AutofillProfile::SERVER_PROFILE, kServerAddressId)); 5915 AutofillProfile(AutofillProfile::SERVER_PROFILE, kServerAddressId));
5914 test::SetProfileInfo(&GetServerProfiles.back(), "John", "", "Doe", "", "Fox", 5916 test::SetProfileInfo(&GetServerProfiles.back(), "John", "", "Doe", "", "Fox",
5915 "1212 Center", "Bld. 5", "Orlando", "FL", "", "US", ""); 5917 "1212 Center", "Bld. 5", "Orlando", "FL", "", "US", "");
5916 // Wallet only provides a full name, so the above first and last names 5918 // Wallet only provides a full name, so the above first and last names
5917 // will be ignored when the profile is written to the DB. 5919 // will be ignored when the profile is written to the DB.
5918 GetServerProfiles.back().SetRawInfo(NAME_FULL, ASCIIToUTF16("John Doe")); 5920 GetServerProfiles.back().SetRawInfo(NAME_FULL,
5921 base::ASCIIToUTF16("John Doe"));
5919 GetServerProfiles.back().set_use_count(100); 5922 GetServerProfiles.back().set_use_count(100);
5920 autofill_table_->SetServerProfiles(GetServerProfiles); 5923 autofill_table_->SetServerProfiles(GetServerProfiles);
5921 5924
5922 // Add a server and a local card that have the server address as billing 5925 // Add a server and a local card that have the server address as billing
5923 // address. 5926 // address.
5924 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15", 5927 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15",
5925 "https://www.example.com"); 5928 "https://www.example.com");
5926 test::SetCreditCardInfo(&local_card, "Clyde Barrow", 5929 test::SetCreditCardInfo(&local_card, "Clyde Barrow",
5927 "347666888555" /* American Express */, "04", "2999"); 5930 "347666888555" /* American Express */, "04", "2999");
5928 local_card.set_billing_address_id(kServerAddressId); 5931 local_card.set_billing_address_id(kServerAddressId);
5929 personal_data_->AddCreditCard(local_card); 5932 personal_data_->AddCreditCard(local_card);
5930 5933
5931 std::vector<CreditCard> server_cards; 5934 std::vector<CreditCard> server_cards;
5932 server_cards.push_back( 5935 server_cards.push_back(
5933 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card1")); 5936 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card1"));
5934 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", 5937 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger",
5935 "1111" /* Visa */, "01", "2999"); 5938 "1111" /* Visa */, "01", "2999");
5936 server_cards.back().SetTypeForMaskedCard(kVisaCard); 5939 server_cards.back().SetNetworkForMaskedCard(kVisaCard);
5937 server_cards.back().set_billing_address_id(kServerAddressId); 5940 server_cards.back().set_billing_address_id(kServerAddressId);
5938 test::SetServerCreditCards(autofill_table_, server_cards); 5941 test::SetServerCreditCards(autofill_table_, server_cards);
5939 5942
5940 // Make sure everything is setup correctly. 5943 // Make sure everything is setup correctly.
5941 personal_data_->Refresh(); 5944 personal_data_->Refresh();
5942 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 5945 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
5943 .WillOnce(QuitMainMessageLoop()); 5946 .WillOnce(QuitMainMessageLoop());
5944 base::RunLoop().Run(); 5947 base::RunLoop().Run();
5945 EXPECT_EQ(1U, personal_data_->web_profiles().size()); 5948 EXPECT_EQ(1U, personal_data_->web_profiles().size());
5946 EXPECT_EQ(1U, personal_data_->GetServerProfiles().size()); 5949 EXPECT_EQ(1U, personal_data_->GetServerProfiles().size());
(...skipping 22 matching lines...) Expand all
5969 EXPECT_TRUE(personal_data_->GetServerProfiles().back()->has_converted()); 5972 EXPECT_TRUE(personal_data_->GetServerProfiles().back()->has_converted());
5970 5973
5971 // Get the profiles, sorted by frecency to have a deterministic order. 5974 // Get the profiles, sorted by frecency to have a deterministic order.
5972 std::vector<AutofillProfile*> profiles = 5975 std::vector<AutofillProfile*> profiles =
5973 personal_data_->GetProfilesToSuggest(); 5976 personal_data_->GetProfilesToSuggest();
5974 5977
5975 // Make sure that the two profiles have merged. 5978 // Make sure that the two profiles have merged.
5976 ASSERT_EQ(1U, profiles.size()); 5979 ASSERT_EQ(1U, profiles.size());
5977 5980
5978 // Check that the values were merged. 5981 // Check that the values were merged.
5979 EXPECT_EQ(UTF8ToUTF16("john@doe.com"), 5982 EXPECT_EQ(base::UTF8ToUTF16("john@doe.com"),
5980 profiles[0]->GetRawInfo(EMAIL_ADDRESS)); 5983 profiles[0]->GetRawInfo(EMAIL_ADDRESS));
5981 EXPECT_EQ(UTF8ToUTF16("Fox"), profiles[0]->GetRawInfo(COMPANY_NAME)); 5984 EXPECT_EQ(base::UTF8ToUTF16("Fox"), profiles[0]->GetRawInfo(COMPANY_NAME));
5982 EXPECT_EQ(UTF8ToUTF16("32801"), profiles[0]->GetRawInfo(ADDRESS_HOME_ZIP)); 5985 EXPECT_EQ(base::UTF8ToUTF16("32801"),
5986 profiles[0]->GetRawInfo(ADDRESS_HOME_ZIP));
5983 5987
5984 // Make sure that the billing address id of the two cards now point to the 5988 // Make sure that the billing address id of the two cards now point to the
5985 // converted profile. 5989 // converted profile.
5986 EXPECT_EQ(profiles[0]->guid(), 5990 EXPECT_EQ(profiles[0]->guid(),
5987 personal_data_->GetCreditCards()[0]->billing_address_id()); 5991 personal_data_->GetCreditCards()[0]->billing_address_id());
5988 EXPECT_EQ(profiles[0]->guid(), 5992 EXPECT_EQ(profiles[0]->guid(),
5989 personal_data_->GetCreditCards()[1]->billing_address_id()); 5993 personal_data_->GetCreditCards()[1]->billing_address_id());
5990 } 5994 }
5991 5995
5992 // Tests that a Wallet address that has already converted does not get converted 5996 // Tests that a Wallet address that has already converted does not get converted
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
6069 6073
6070 // Add a server profile. 6074 // Add a server profile.
6071 std::vector<AutofillProfile> GetServerProfiles; 6075 std::vector<AutofillProfile> GetServerProfiles;
6072 GetServerProfiles.push_back( 6076 GetServerProfiles.push_back(
6073 AutofillProfile(AutofillProfile::SERVER_PROFILE, kServerAddressId)); 6077 AutofillProfile(AutofillProfile::SERVER_PROFILE, kServerAddressId));
6074 test::SetProfileInfo(&GetServerProfiles.back(), "John", "", "Doe", "", "", 6078 test::SetProfileInfo(&GetServerProfiles.back(), "John", "", "Doe", "", "",
6075 "1212 Center", "Bld. 5", "Orlando", "FL", "32801", "US", 6079 "1212 Center", "Bld. 5", "Orlando", "FL", "32801", "US",
6076 ""); 6080 "");
6077 // Wallet only provides a full name, so the above first and last names 6081 // Wallet only provides a full name, so the above first and last names
6078 // will be ignored when the profile is written to the DB. 6082 // will be ignored when the profile is written to the DB.
6079 GetServerProfiles.back().SetRawInfo(NAME_FULL, ASCIIToUTF16("John Doe")); 6083 GetServerProfiles.back().SetRawInfo(NAME_FULL,
6084 base::ASCIIToUTF16("John Doe"));
6080 GetServerProfiles.back().set_use_count(100); 6085 GetServerProfiles.back().set_use_count(100);
6081 6086
6082 // Add a similar server profile. 6087 // Add a similar server profile.
6083 GetServerProfiles.push_back( 6088 GetServerProfiles.push_back(
6084 AutofillProfile(AutofillProfile::SERVER_PROFILE, kServerAddressId2)); 6089 AutofillProfile(AutofillProfile::SERVER_PROFILE, kServerAddressId2));
6085 test::SetProfileInfo(&GetServerProfiles.back(), "John", "", "Doe", 6090 test::SetProfileInfo(&GetServerProfiles.back(), "John", "", "Doe",
6086 "john@doe.com", "Fox", "1212 Center", "Bld. 5", 6091 "john@doe.com", "Fox", "1212 Center", "Bld. 5",
6087 "Orlando", "FL", "", "US", ""); 6092 "Orlando", "FL", "", "US", "");
6088 // Wallet only provides a full name, so the above first and last names 6093 // Wallet only provides a full name, so the above first and last names
6089 // will be ignored when the profile is written to the DB. 6094 // will be ignored when the profile is written to the DB.
6090 GetServerProfiles.back().SetRawInfo(NAME_FULL, ASCIIToUTF16("John Doe")); 6095 GetServerProfiles.back().SetRawInfo(NAME_FULL,
6096 base::ASCIIToUTF16("John Doe"));
6091 GetServerProfiles.back().set_use_count(200); 6097 GetServerProfiles.back().set_use_count(200);
6092 autofill_table_->SetServerProfiles(GetServerProfiles); 6098 autofill_table_->SetServerProfiles(GetServerProfiles);
6093 6099
6094 // Add a server and a local card that have the first and second Wallet address 6100 // Add a server and a local card that have the first and second Wallet address
6095 // as a billing address. 6101 // as a billing address.
6096 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15", 6102 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15",
6097 "https://www.example.com"); 6103 "https://www.example.com");
6098 test::SetCreditCardInfo(&local_card, "Clyde Barrow", 6104 test::SetCreditCardInfo(&local_card, "Clyde Barrow",
6099 "347666888555" /* American Express */, "04", "2999"); 6105 "347666888555" /* American Express */, "04", "2999");
6100 local_card.set_billing_address_id(kServerAddressId); 6106 local_card.set_billing_address_id(kServerAddressId);
6101 personal_data_->AddCreditCard(local_card); 6107 personal_data_->AddCreditCard(local_card);
6102 6108
6103 std::vector<CreditCard> server_cards; 6109 std::vector<CreditCard> server_cards;
6104 server_cards.push_back( 6110 server_cards.push_back(
6105 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card1")); 6111 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card1"));
6106 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", 6112 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger",
6107 "1111" /* Visa */, "01", "2999"); 6113 "1111" /* Visa */, "01", "2999");
6108 server_cards.back().SetTypeForMaskedCard(kVisaCard); 6114 server_cards.back().SetNetworkForMaskedCard(kVisaCard);
6109 server_cards.back().set_billing_address_id(kServerAddressId2); 6115 server_cards.back().set_billing_address_id(kServerAddressId2);
6110 test::SetServerCreditCards(autofill_table_, server_cards); 6116 test::SetServerCreditCards(autofill_table_, server_cards);
6111 6117
6112 // Make sure everything is setup correctly. 6118 // Make sure everything is setup correctly.
6113 personal_data_->Refresh(); 6119 personal_data_->Refresh();
6114 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 6120 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
6115 .WillOnce(QuitMainMessageLoop()); 6121 .WillOnce(QuitMainMessageLoop());
6116 base::RunLoop().Run(); 6122 base::RunLoop().Run();
6117 EXPECT_EQ(1U, personal_data_->web_profiles().size()); 6123 EXPECT_EQ(1U, personal_data_->web_profiles().size());
6118 EXPECT_EQ(2U, personal_data_->GetServerProfiles().size()); 6124 EXPECT_EQ(2U, personal_data_->GetServerProfiles().size());
(...skipping 26 matching lines...) Expand all
6145 EXPECT_TRUE(personal_data_->GetServerProfiles()[0]->has_converted()); 6151 EXPECT_TRUE(personal_data_->GetServerProfiles()[0]->has_converted());
6146 EXPECT_TRUE(personal_data_->GetServerProfiles()[1]->has_converted()); 6152 EXPECT_TRUE(personal_data_->GetServerProfiles()[1]->has_converted());
6147 6153
6148 // Get the profiles, sorted by frecency to have a deterministic order. 6154 // Get the profiles, sorted by frecency to have a deterministic order.
6149 std::vector<AutofillProfile*> profiles = 6155 std::vector<AutofillProfile*> profiles =
6150 personal_data_->GetProfilesToSuggest(); 6156 personal_data_->GetProfilesToSuggest();
6151 6157
6152 // Make sure that the two Wallet addresses merged together and were added as 6158 // Make sure that the two Wallet addresses merged together and were added as
6153 // a new local profile. 6159 // a new local profile.
6154 ASSERT_EQ(2U, profiles.size()); 6160 ASSERT_EQ(2U, profiles.size());
6155 EXPECT_EQ(UTF8ToUTF16("John"), profiles[0]->GetRawInfo(NAME_FIRST)); 6161 EXPECT_EQ(base::UTF8ToUTF16("John"), profiles[0]->GetRawInfo(NAME_FIRST));
6156 EXPECT_EQ(local_profile, *profiles[1]); 6162 EXPECT_EQ(local_profile, *profiles[1]);
6157 6163
6158 // Check that the values were merged. 6164 // Check that the values were merged.
6159 EXPECT_EQ(UTF8ToUTF16("Fox"), profiles[0]->GetRawInfo(COMPANY_NAME)); 6165 EXPECT_EQ(base::UTF8ToUTF16("Fox"), profiles[0]->GetRawInfo(COMPANY_NAME));
6160 EXPECT_EQ(UTF8ToUTF16("32801"), profiles[0]->GetRawInfo(ADDRESS_HOME_ZIP)); 6166 EXPECT_EQ(base::UTF8ToUTF16("32801"),
6167 profiles[0]->GetRawInfo(ADDRESS_HOME_ZIP));
6161 6168
6162 // Make sure that the billing address id of the two cards now point to the 6169 // Make sure that the billing address id of the two cards now point to the
6163 // converted profile. 6170 // converted profile.
6164 EXPECT_EQ(profiles[0]->guid(), 6171 EXPECT_EQ(profiles[0]->guid(),
6165 personal_data_->GetCreditCards()[0]->billing_address_id()); 6172 personal_data_->GetCreditCards()[0]->billing_address_id());
6166 EXPECT_EQ(profiles[0]->guid(), 6173 EXPECT_EQ(profiles[0]->guid(),
6167 personal_data_->GetCreditCards()[1]->billing_address_id()); 6174 personal_data_->GetCreditCards()[1]->billing_address_id());
6168 } 6175 }
6169 6176
6170 // Tests a new server card's billing address is updated propely even if the 6177 // Tests a new server card's billing address is updated propely even if the
6171 // address was already converted in the past. 6178 // address was already converted in the past.
6172 TEST_F( 6179 TEST_F(
6173 PersonalDataManagerTest, 6180 PersonalDataManagerTest,
6174 ConvertWalletAddressesAndUpdateWalletCards_NewCard_AddressAlreadyConverted) { 6181 ConvertWalletAddressesAndUpdateWalletCards_NewCrd_AddressAlreadyConverted) {
6175 /////////////////////////////////////////////////////////////////////// 6182 ///////////////////////////////////////////////////////////////////////
6176 // Setup. 6183 // Setup.
6177 /////////////////////////////////////////////////////////////////////// 6184 ///////////////////////////////////////////////////////////////////////
6178 // Go through the conversion process for a server address and card. Then add 6185 // Go through the conversion process for a server address and card. Then add
6179 // a new server card that refers to the already converted server address as 6186 // a new server card that refers to the already converted server address as
6180 // its billing address. 6187 // its billing address.
6181 EnableWalletCardImport(); 6188 EnableWalletCardImport();
6182 base::HistogramTester histogram_tester; 6189 base::HistogramTester histogram_tester;
6183 const std::string kServerAddressId("server_address1"); 6190 const std::string kServerAddressId("server_address1");
6184 6191
6185 // Add a server profile. 6192 // Add a server profile.
6186 std::vector<AutofillProfile> GetServerProfiles; 6193 std::vector<AutofillProfile> GetServerProfiles;
6187 GetServerProfiles.push_back( 6194 GetServerProfiles.push_back(
6188 AutofillProfile(AutofillProfile::SERVER_PROFILE, kServerAddressId)); 6195 AutofillProfile(AutofillProfile::SERVER_PROFILE, kServerAddressId));
6189 test::SetProfileInfo(&GetServerProfiles.back(), "John", "", "Doe", "", "Fox", 6196 test::SetProfileInfo(&GetServerProfiles.back(), "John", "", "Doe", "", "Fox",
6190 "1212 Center", "Bld. 5", "Orlando", "FL", "", "US", ""); 6197 "1212 Center", "Bld. 5", "Orlando", "FL", "", "US", "");
6191 // Wallet only provides a full name, so the above first and last names 6198 // Wallet only provides a full name, so the above first and last names
6192 // will be ignored when the profile is written to the DB. 6199 // will be ignored when the profile is written to the DB.
6193 GetServerProfiles.back().SetRawInfo(NAME_FULL, ASCIIToUTF16("John Doe")); 6200 GetServerProfiles.back().SetRawInfo(NAME_FULL,
6201 base::ASCIIToUTF16("John Doe"));
6194 GetServerProfiles.back().set_use_count(100); 6202 GetServerProfiles.back().set_use_count(100);
6195 autofill_table_->SetServerProfiles(GetServerProfiles); 6203 autofill_table_->SetServerProfiles(GetServerProfiles);
6196 6204
6197 // Add a server card that have the server address as billing address. 6205 // Add a server card that have the server address as billing address.
6198 std::vector<CreditCard> server_cards; 6206 std::vector<CreditCard> server_cards;
6199 server_cards.push_back( 6207 server_cards.push_back(
6200 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card1")); 6208 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card1"));
6201 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", 6209 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger",
6202 "1111" /* Visa */, "01", "2999"); 6210 "1111" /* Visa */, "01", "2999");
6203 server_cards.back().SetTypeForMaskedCard(kVisaCard); 6211 server_cards.back().SetNetworkForMaskedCard(kVisaCard);
6204 server_cards.back().set_billing_address_id(kServerAddressId); 6212 server_cards.back().set_billing_address_id(kServerAddressId);
6205 test::SetServerCreditCards(autofill_table_, server_cards); 6213 test::SetServerCreditCards(autofill_table_, server_cards);
6206 6214
6207 // Make sure everything is setup correctly. 6215 // Make sure everything is setup correctly.
6208 personal_data_->Refresh(); 6216 personal_data_->Refresh();
6209 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 6217 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
6210 .WillOnce(QuitMainMessageLoop()); 6218 .WillOnce(QuitMainMessageLoop());
6211 base::RunLoop().Run(); 6219 base::RunLoop().Run();
6212 EXPECT_EQ(1U, personal_data_->GetServerProfiles().size()); 6220 EXPECT_EQ(1U, personal_data_->GetServerProfiles().size());
6213 EXPECT_EQ(1U, personal_data_->GetCreditCards().size()); 6221 EXPECT_EQ(1U, personal_data_->GetCreditCards().size());
(...skipping 17 matching lines...) Expand all
6231 personal_data_->GetProfilesToSuggest(); 6239 personal_data_->GetProfilesToSuggest();
6232 ASSERT_EQ(1U, profiles.size()); 6240 ASSERT_EQ(1U, profiles.size());
6233 EXPECT_EQ(profiles[0]->guid(), 6241 EXPECT_EQ(profiles[0]->guid(),
6234 personal_data_->GetCreditCards()[0]->billing_address_id()); 6242 personal_data_->GetCreditCards()[0]->billing_address_id());
6235 6243
6236 // Add a new server card that has the same billing address as the old one. 6244 // Add a new server card that has the same billing address as the old one.
6237 server_cards.push_back( 6245 server_cards.push_back(
6238 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card2")); 6246 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card2"));
6239 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", 6247 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger",
6240 "1112" /* Visa */, "01", "2888"); 6248 "1112" /* Visa */, "01", "2888");
6241 server_cards.back().SetTypeForMaskedCard(kVisaCard); 6249 server_cards.back().SetNetworkForMaskedCard(kVisaCard);
6242 server_cards.back().set_billing_address_id(kServerAddressId); 6250 server_cards.back().set_billing_address_id(kServerAddressId);
6243 test::SetServerCreditCards(autofill_table_, server_cards); 6251 test::SetServerCreditCards(autofill_table_, server_cards);
6244 6252
6245 // Make sure everything is setup correctly. 6253 // Make sure everything is setup correctly.
6246 personal_data_->Refresh(); 6254 personal_data_->Refresh();
6247 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 6255 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
6248 .WillOnce(QuitMainMessageLoop()); 6256 .WillOnce(QuitMainMessageLoop());
6249 base::RunLoop().Run(); 6257 base::RunLoop().Run();
6250 EXPECT_EQ(1U, personal_data_->web_profiles().size()); 6258 EXPECT_EQ(1U, personal_data_->web_profiles().size());
6251 EXPECT_EQ(2U, personal_data_->GetCreditCards().size()); 6259 EXPECT_EQ(2U, personal_data_->GetCreditCards().size());
(...skipping 23 matching lines...) Expand all
6275 // to the converted address. 6283 // to the converted address.
6276 EXPECT_EQ(profiles[0]->guid(), 6284 EXPECT_EQ(profiles[0]->guid(),
6277 personal_data_->GetCreditCards()[0]->billing_address_id()); 6285 personal_data_->GetCreditCards()[0]->billing_address_id());
6278 // Make sure that the billing address id of the new server card still refers 6286 // Make sure that the billing address id of the new server card still refers
6279 // to the converted address. 6287 // to the converted address.
6280 EXPECT_EQ(profiles[0]->guid(), 6288 EXPECT_EQ(profiles[0]->guid(),
6281 personal_data_->GetCreditCards()[1]->billing_address_id()); 6289 personal_data_->GetCreditCards()[1]->billing_address_id());
6282 } 6290 }
6283 6291
6284 } // namespace autofill 6292 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698