OLD | NEW |
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 Loading... |
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 |
| 60 using ::base::ASCIIToUTF16; |
| 61 using ::base::UTF8ToUTF16; |
| 62 |
63 enum UserMode { USER_MODE_NORMAL, USER_MODE_INCOGNITO }; | 63 enum UserMode { USER_MODE_NORMAL, USER_MODE_INCOGNITO }; |
64 | 64 |
65 const std::string kUTF8MidlineEllipsis = | 65 const char kUTF8MidlineEllipsis[] = |
66 " " | 66 " " |
67 "\xE2\x80\xA2\xE2\x80\x86" | 67 "\xE2\x80\xA2\xE2\x80\x86" |
68 "\xE2\x80\xA2\xE2\x80\x86" | 68 "\xE2\x80\xA2\xE2\x80\x86" |
69 "\xE2\x80\xA2\xE2\x80\x86" | 69 "\xE2\x80\xA2\xE2\x80\x86" |
70 "\xE2\x80\xA2\xE2\x80\x86"; | 70 "\xE2\x80\xA2\xE2\x80\x86"; |
71 | 71 |
72 const base::Time kArbitraryTime = base::Time::FromDoubleT(25); | 72 const base::Time kArbitraryTime = base::Time::FromDoubleT(25); |
73 const base::Time kSomeLaterTime = base::Time::FromDoubleT(1000); | 73 const base::Time kSomeLaterTime = base::Time::FromDoubleT(1000); |
74 const base::Time kMuchLaterTime = base::Time::FromDoubleT(5000); | 74 const base::Time kMuchLaterTime = base::Time::FromDoubleT(5000); |
75 | 75 |
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 } | 757 } |
758 | 758 |
759 // Tests that UpdateServerCreditCard can be used to mask or unmask server cards. | 759 // Tests that UpdateServerCreditCard can be used to mask or unmask server cards. |
760 TEST_F(PersonalDataManagerTest, UpdateServerCreditCards) { | 760 TEST_F(PersonalDataManagerTest, UpdateServerCreditCards) { |
761 EnableWalletCardImport(); | 761 EnableWalletCardImport(); |
762 | 762 |
763 std::vector<CreditCard> server_cards; | 763 std::vector<CreditCard> server_cards; |
764 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); | 764 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); |
765 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", | 765 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
766 "9012" /* Visa */, "01", "2999"); | 766 "9012" /* Visa */, "01", "2999"); |
767 server_cards.back().SetTypeForMaskedCard(kVisaCard); | 767 server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
768 | 768 |
769 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b456")); | 769 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b456")); |
770 test::SetCreditCardInfo(&server_cards.back(), "Bonnie Parker", | 770 test::SetCreditCardInfo(&server_cards.back(), "Bonnie Parker", |
771 "2109" /* Mastercard */, "12", "2999"); | 771 "2109" /* Mastercard */, "12", "2999"); |
772 server_cards.back().SetTypeForMaskedCard(kMasterCard); | 772 server_cards.back().SetNetworkForMaskedCard(kMasterCard); |
773 | 773 |
774 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); | 774 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); |
775 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", | 775 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", |
776 "347666888555" /* American Express */, "04", "2999"); | 776 "347666888555" /* American Express */, "04", "2999"); |
777 | 777 |
778 test::SetServerCreditCards(autofill_table_, server_cards); | 778 test::SetServerCreditCards(autofill_table_, server_cards); |
779 personal_data_->Refresh(); | 779 personal_data_->Refresh(); |
780 | 780 |
781 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 781 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
782 .WillOnce(QuitMainMessageLoop()); | 782 .WillOnce(QuitMainMessageLoop()); |
(...skipping 1627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2410 | 2410 |
2411 // Tests that a credit card is extracted because it only matches a masked server | 2411 // Tests that a credit card is extracted because it only matches a masked server |
2412 // card. | 2412 // card. |
2413 TEST_F(PersonalDataManagerTest, | 2413 TEST_F(PersonalDataManagerTest, |
2414 ImportCreditCard_DuplicateServerCards_MaskedCard) { | 2414 ImportCreditCard_DuplicateServerCards_MaskedCard) { |
2415 // Add a masked server card. | 2415 // Add a masked server card. |
2416 std::vector<CreditCard> server_cards; | 2416 std::vector<CreditCard> server_cards; |
2417 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); | 2417 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); |
2418 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", | 2418 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
2419 "1111" /* Visa */, "01", "2999"); | 2419 "1111" /* Visa */, "01", "2999"); |
2420 server_cards.back().SetTypeForMaskedCard(kVisaCard); | 2420 server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
2421 test::SetServerCreditCards(autofill_table_, server_cards); | 2421 test::SetServerCreditCards(autofill_table_, server_cards); |
2422 | 2422 |
2423 // Type the same data as the masked card into a form. | 2423 // Type the same data as the masked card into a form. |
2424 FormData form; | 2424 FormData form; |
2425 AddFullCreditCardForm(&form, "John Dillinger", "4111111111111111", "01", | 2425 AddFullCreditCardForm(&form, "John Dillinger", "4111111111111111", "01", |
2426 "2999"); | 2426 "2999"); |
2427 | 2427 |
2428 // The card should be offered to be saved locally because it only matches the | 2428 // The card should be offered to be saved locally because it only matches the |
2429 // masked server card. | 2429 // masked server card. |
2430 FormStructure form_structure(form); | 2430 FormStructure form_structure(form); |
(...skipping 1108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3539 // been typed in the field. | 3539 // been typed in the field. |
3540 TEST_F(PersonalDataManagerTest, | 3540 TEST_F(PersonalDataManagerTest, |
3541 GetCreditCardSuggestions_MaskedCardWithMoreThan6Numbers) { | 3541 GetCreditCardSuggestions_MaskedCardWithMoreThan6Numbers) { |
3542 EnableWalletCardImport(); | 3542 EnableWalletCardImport(); |
3543 | 3543 |
3544 // Add a masked server card. | 3544 // Add a masked server card. |
3545 std::vector<CreditCard> server_cards; | 3545 std::vector<CreditCard> server_cards; |
3546 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b459")); | 3546 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b459")); |
3547 test::SetCreditCardInfo(&server_cards.back(), "Emmet Dalton", "2110", "12", | 3547 test::SetCreditCardInfo(&server_cards.back(), "Emmet Dalton", "2110", "12", |
3548 "2999"); | 3548 "2999"); |
3549 server_cards.back().SetTypeForMaskedCard(kVisaCard); | 3549 server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
3550 | 3550 |
3551 test::SetServerCreditCards(autofill_table_, server_cards); | 3551 test::SetServerCreditCards(autofill_table_, server_cards); |
3552 personal_data_->Refresh(); | 3552 personal_data_->Refresh(); |
3553 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3553 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
3554 .WillOnce(QuitMainMessageLoop()); | 3554 .WillOnce(QuitMainMessageLoop()); |
3555 base::RunLoop().Run(); | 3555 base::RunLoop().Run(); |
3556 | 3556 |
3557 std::vector<Suggestion> suggestions = | 3557 std::vector<Suggestion> suggestions = |
3558 personal_data_->GetCreditCardSuggestions(AutofillType(CREDIT_CARD_NUMBER), | 3558 personal_data_->GetCreditCardSuggestions(AutofillType(CREDIT_CARD_NUMBER), |
3559 ASCIIToUTF16("12345678")); | 3559 ASCIIToUTF16("12345678")); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3593 SetupReferenceLocalCreditCards(); | 3593 SetupReferenceLocalCreditCards(); |
3594 | 3594 |
3595 // Add some server cards. | 3595 // Add some server cards. |
3596 std::vector<CreditCard> server_cards; | 3596 std::vector<CreditCard> server_cards; |
3597 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b459")); | 3597 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b459")); |
3598 test::SetCreditCardInfo(&server_cards.back(), "Emmet Dalton", "2110", "12", | 3598 test::SetCreditCardInfo(&server_cards.back(), "Emmet Dalton", "2110", "12", |
3599 "2999"); | 3599 "2999"); |
3600 server_cards.back().set_use_count(2); | 3600 server_cards.back().set_use_count(2); |
3601 server_cards.back().set_use_date(AutofillClock::Now() - | 3601 server_cards.back().set_use_date(AutofillClock::Now() - |
3602 base::TimeDelta::FromDays(1)); | 3602 base::TimeDelta::FromDays(1)); |
3603 server_cards.back().SetTypeForMaskedCard(kVisaCard); | 3603 server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
3604 | 3604 |
3605 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "b460")); | 3605 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "b460")); |
3606 test::SetCreditCardInfo(&server_cards.back(), "Jesse James", "2109", "12", | 3606 test::SetCreditCardInfo(&server_cards.back(), "Jesse James", "2109", "12", |
3607 "2999"); | 3607 "2999"); |
3608 server_cards.back().set_use_count(6); | 3608 server_cards.back().set_use_count(6); |
3609 server_cards.back().set_use_date(AutofillClock::Now() - | 3609 server_cards.back().set_use_date(AutofillClock::Now() - |
3610 base::TimeDelta::FromDays(1)); | 3610 base::TimeDelta::FromDays(1)); |
3611 | 3611 |
3612 test::SetServerCreditCards(autofill_table_, server_cards); | 3612 test::SetServerCreditCards(autofill_table_, server_cards); |
3613 personal_data_->Refresh(); | 3613 personal_data_->Refresh(); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3710 | 3710 |
3711 ASSERT_EQ(2U, personal_data_->GetCreditCards().size()); | 3711 ASSERT_EQ(2U, personal_data_->GetCreditCards().size()); |
3712 | 3712 |
3713 // Sublabel is expiration date when filling card number. The second card | 3713 // 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. | 3714 // doesn't have a number so it should not be included in the suggestions. |
3715 std::vector<Suggestion> suggestions = | 3715 std::vector<Suggestion> suggestions = |
3716 personal_data_->GetCreditCardSuggestions( | 3716 personal_data_->GetCreditCardSuggestions( |
3717 AutofillType(CREDIT_CARD_NUMBER), | 3717 AutofillType(CREDIT_CARD_NUMBER), |
3718 /* field_contents= */ base::string16()); | 3718 /* field_contents= */ base::string16()); |
3719 ASSERT_EQ(1U, suggestions.size()); | 3719 ASSERT_EQ(1U, suggestions.size()); |
3720 EXPECT_EQ(UTF8ToUTF16("Amex" + kUTF8MidlineEllipsis + "8555"), | 3720 EXPECT_EQ(UTF8ToUTF16(std::string("Amex") + kUTF8MidlineEllipsis + "8555"), |
3721 suggestions[0].value); | 3721 suggestions[0].value); |
3722 EXPECT_EQ(ASCIIToUTF16("04/99"), suggestions[0].label); | 3722 EXPECT_EQ(ASCIIToUTF16("04/99"), suggestions[0].label); |
3723 } | 3723 } |
3724 | 3724 |
3725 // Tests the suggestions of duplicate local and server credit cards. | 3725 // Tests the suggestions of duplicate local and server credit cards. |
3726 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_ServerDuplicates) { | 3726 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_ServerDuplicates) { |
3727 EnableWalletCardImport(); | 3727 EnableWalletCardImport(); |
3728 SetupReferenceLocalCreditCards(); | 3728 SetupReferenceLocalCreditCards(); |
3729 | 3729 |
3730 // Add some server cards. If there are local dupes, the locals should be | 3730 // Add some server cards. If there are local dupes, the locals should be |
3731 // hidden. | 3731 // hidden. |
3732 std::vector<CreditCard> server_cards; | 3732 std::vector<CreditCard> server_cards; |
3733 // This server card matches a local card, except the local card is missing the | 3733 // 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 | 3734 // number. This should count as a dupe and thus not be shown in the |
3735 // suggestions since the locally saved card takes precedence. | 3735 // suggestions since the locally saved card takes precedence. |
3736 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); | 3736 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); |
3737 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", | 3737 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
3738 "9012" /* Visa */, "01", "2999"); | 3738 "9012" /* Visa */, "01", "2999"); |
3739 server_cards.back().set_use_count(2); | 3739 server_cards.back().set_use_count(2); |
3740 server_cards.back().set_use_date(AutofillClock::Now() - | 3740 server_cards.back().set_use_date(AutofillClock::Now() - |
3741 base::TimeDelta::FromDays(15)); | 3741 base::TimeDelta::FromDays(15)); |
3742 server_cards.back().SetTypeForMaskedCard(kVisaCard); | 3742 server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
3743 | 3743 |
3744 // This server card is identical to a local card, but has a different | 3744 // 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. | 3745 // card type. Not a dupe and therefore both should appear in the suggestions. |
3746 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b456")); | 3746 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b456")); |
3747 test::SetCreditCardInfo(&server_cards.back(), "Bonnie Parker", "2109", "12", | 3747 test::SetCreditCardInfo(&server_cards.back(), "Bonnie Parker", "2109", "12", |
3748 "2999"); | 3748 "2999"); |
3749 server_cards.back().set_use_count(3); | 3749 server_cards.back().set_use_count(3); |
3750 server_cards.back().set_use_date(AutofillClock::Now() - | 3750 server_cards.back().set_use_date(AutofillClock::Now() - |
3751 base::TimeDelta::FromDays(15)); | 3751 base::TimeDelta::FromDays(15)); |
3752 server_cards.back().SetTypeForMaskedCard(kVisaCard); | 3752 server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
3753 | 3753 |
3754 // This unmasked server card is an exact dupe of a local card. Therefore only | 3754 // 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 | 3755 // this card should appear in the suggestions as full server cards have |
3756 // precedence over local cards. | 3756 // precedence over local cards. |
3757 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); | 3757 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); |
3758 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", | 3758 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", |
3759 "347666888555" /* American Express */, "04", "2999"); | 3759 "347666888555" /* American Express */, "04", "2999"); |
3760 server_cards.back().set_use_count(1); | 3760 server_cards.back().set_use_count(1); |
3761 server_cards.back().set_use_date(AutofillClock::Now() - | 3761 server_cards.back().set_use_date(AutofillClock::Now() - |
3762 base::TimeDelta::FromDays(15)); | 3762 base::TimeDelta::FromDays(15)); |
(...skipping 10 matching lines...) Expand all Loading... |
3773 /* field_contents= */ base::string16()); | 3773 /* field_contents= */ base::string16()); |
3774 ASSERT_EQ(4U, suggestions.size()); | 3774 ASSERT_EQ(4U, suggestions.size()); |
3775 EXPECT_EQ(ASCIIToUTF16("John Dillinger"), suggestions[0].value); | 3775 EXPECT_EQ(ASCIIToUTF16("John Dillinger"), suggestions[0].value); |
3776 EXPECT_EQ(ASCIIToUTF16("Clyde Barrow"), suggestions[1].value); | 3776 EXPECT_EQ(ASCIIToUTF16("Clyde Barrow"), suggestions[1].value); |
3777 EXPECT_EQ(ASCIIToUTF16("Bonnie Parker"), suggestions[2].value); | 3777 EXPECT_EQ(ASCIIToUTF16("Bonnie Parker"), suggestions[2].value); |
3778 EXPECT_EQ(ASCIIToUTF16("Bonnie Parker"), suggestions[3].value); | 3778 EXPECT_EQ(ASCIIToUTF16("Bonnie Parker"), suggestions[3].value); |
3779 | 3779 |
3780 suggestions = personal_data_->GetCreditCardSuggestions( | 3780 suggestions = personal_data_->GetCreditCardSuggestions( |
3781 AutofillType(CREDIT_CARD_NUMBER), /* field_contents= */ base::string16()); | 3781 AutofillType(CREDIT_CARD_NUMBER), /* field_contents= */ base::string16()); |
3782 ASSERT_EQ(4U, suggestions.size()); | 3782 ASSERT_EQ(4U, suggestions.size()); |
3783 EXPECT_EQ(UTF8ToUTF16("Visa" + kUTF8MidlineEllipsis + "9012"), | 3783 EXPECT_EQ(UTF8ToUTF16(std::string("Visa") + kUTF8MidlineEllipsis + "9012"), |
3784 suggestions[0].value); | 3784 suggestions[0].value); |
3785 EXPECT_EQ(UTF8ToUTF16("Amex" + kUTF8MidlineEllipsis + "8555"), | 3785 EXPECT_EQ(UTF8ToUTF16(std::string("Amex") + kUTF8MidlineEllipsis + "8555"), |
3786 suggestions[1].value); | 3786 suggestions[1].value); |
3787 EXPECT_EQ(UTF8ToUTF16("MasterCard" + kUTF8MidlineEllipsis + "2109"), | 3787 EXPECT_EQ( |
3788 suggestions[2].value); | 3788 UTF8ToUTF16(std::string("MasterCard") + kUTF8MidlineEllipsis + "2109"), |
3789 EXPECT_EQ(UTF8ToUTF16("Visa" + kUTF8MidlineEllipsis + "2109"), | 3789 suggestions[2].value); |
| 3790 EXPECT_EQ(UTF8ToUTF16(std::string("Visa") + kUTF8MidlineEllipsis + "2109"), |
3790 suggestions[3].value); | 3791 suggestions[3].value); |
3791 } | 3792 } |
3792 | 3793 |
3793 // Tests that a full server card can be a dupe of more than one local card. | 3794 // Tests that a full server card can be a dupe of more than one local card. |
3794 TEST_F(PersonalDataManagerTest, | 3795 TEST_F(PersonalDataManagerTest, |
3795 GetCreditCardSuggestions_ServerCardDuplicateOfMultipleLocalCards) { | 3796 GetCreditCardSuggestions_ServerCardDuplicateOfMultipleLocalCards) { |
3796 EnableWalletCardImport(); | 3797 EnableWalletCardImport(); |
3797 SetupReferenceLocalCreditCards(); | 3798 SetupReferenceLocalCreditCards(); |
3798 | 3799 |
3799 // Add a duplicate server card. | 3800 // Add a duplicate server card. |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3877 "423456789012" /* Visa */, "01", "2999"); | 3878 "423456789012" /* Visa */, "01", "2999"); |
3878 credit_cards.push_back(&local_card); | 3879 credit_cards.push_back(&local_card); |
3879 | 3880 |
3880 // Create a masked server card that is a duplicate of a local card. | 3881 // Create a masked server card that is a duplicate of a local card. |
3881 CreditCard masked_card(CreditCard::MASKED_SERVER_CARD, "a123"); | 3882 CreditCard masked_card(CreditCard::MASKED_SERVER_CARD, "a123"); |
3882 test::SetCreditCardInfo(&masked_card, "Homer Simpson", "9012" /* Visa */, | 3883 test::SetCreditCardInfo(&masked_card, "Homer Simpson", "9012" /* Visa */, |
3883 "01", "2999"); | 3884 "01", "2999"); |
3884 masked_card.set_use_count(2); | 3885 masked_card.set_use_count(2); |
3885 masked_card.set_use_date(AutofillClock::Now() - | 3886 masked_card.set_use_date(AutofillClock::Now() - |
3886 base::TimeDelta::FromDays(15)); | 3887 base::TimeDelta::FromDays(15)); |
3887 masked_card.SetTypeForMaskedCard(kVisaCard); | 3888 masked_card.SetNetworkForMaskedCard(kVisaCard); |
3888 credit_cards.push_back(&masked_card); | 3889 credit_cards.push_back(&masked_card); |
3889 | 3890 |
3890 PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards); | 3891 PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards); |
3891 ASSERT_EQ(1U, credit_cards.size()); | 3892 ASSERT_EQ(1U, credit_cards.size()); |
3892 | 3893 |
3893 const CreditCard* deduped_card(credit_cards.front()); | 3894 const CreditCard* deduped_card(credit_cards.front()); |
3894 EXPECT_TRUE(*deduped_card == local_card); | 3895 EXPECT_TRUE(*deduped_card == local_card); |
3895 } | 3896 } |
3896 | 3897 |
3897 // Tests that identical full server and masked credit cards are not deduped. | 3898 // Tests that identical full server and masked credit cards are not deduped. |
3898 TEST_F(PersonalDataManagerTest, DedupeCreditCardToSuggest_FullServerAndMasked) { | 3899 TEST_F(PersonalDataManagerTest, DedupeCreditCardToSuggest_FullServerAndMasked) { |
3899 std::list<CreditCard*> credit_cards; | 3900 std::list<CreditCard*> credit_cards; |
3900 | 3901 |
3901 // Create a full server card that is a duplicate of one of the local cards. | 3902 // 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"); | 3903 CreditCard full_server_card(CreditCard::FULL_SERVER_CARD, "c789"); |
3903 test::SetCreditCardInfo(&full_server_card, "Homer Simpson", | 3904 test::SetCreditCardInfo(&full_server_card, "Homer Simpson", |
3904 "423456789012" /* Visa */, "01", "2999"); | 3905 "423456789012" /* Visa */, "01", "2999"); |
3905 full_server_card.set_use_count(1); | 3906 full_server_card.set_use_count(1); |
3906 full_server_card.set_use_date(AutofillClock::Now() - | 3907 full_server_card.set_use_date(AutofillClock::Now() - |
3907 base::TimeDelta::FromDays(15)); | 3908 base::TimeDelta::FromDays(15)); |
3908 credit_cards.push_back(&full_server_card); | 3909 credit_cards.push_back(&full_server_card); |
3909 | 3910 |
3910 // Create a masked server card that is a duplicate of a local card. | 3911 // Create a masked server card that is a duplicate of a local card. |
3911 CreditCard masked_card(CreditCard::MASKED_SERVER_CARD, "a123"); | 3912 CreditCard masked_card(CreditCard::MASKED_SERVER_CARD, "a123"); |
3912 test::SetCreditCardInfo(&masked_card, "Homer Simpson", "9012" /* Visa */, | 3913 test::SetCreditCardInfo(&masked_card, "Homer Simpson", "9012" /* Visa */, |
3913 "01", "2999"); | 3914 "01", "2999"); |
3914 masked_card.set_use_count(2); | 3915 masked_card.set_use_count(2); |
3915 masked_card.set_use_date(AutofillClock::Now() - | 3916 masked_card.set_use_date(AutofillClock::Now() - |
3916 base::TimeDelta::FromDays(15)); | 3917 base::TimeDelta::FromDays(15)); |
3917 masked_card.SetTypeForMaskedCard(kVisaCard); | 3918 masked_card.SetNetworkForMaskedCard(kVisaCard); |
3918 credit_cards.push_back(&masked_card); | 3919 credit_cards.push_back(&masked_card); |
3919 | 3920 |
3920 PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards); | 3921 PersonalDataManager::DedupeCreditCardToSuggest(&credit_cards); |
3921 EXPECT_EQ(2U, credit_cards.size()); | 3922 EXPECT_EQ(2U, credit_cards.size()); |
3922 } | 3923 } |
3923 | 3924 |
3924 // Tests that slightly different local, full server, and masked credit cards are | 3925 // Tests that slightly different local, full server, and masked credit cards are |
3925 // not deduped. | 3926 // not deduped. |
3926 TEST_F(PersonalDataManagerTest, DedupeCreditCardToSuggest_DifferentCards) { | 3927 TEST_F(PersonalDataManagerTest, DedupeCreditCardToSuggest_DifferentCards) { |
3927 std::list<CreditCard*> credit_cards; | 3928 std::list<CreditCard*> credit_cards; |
3928 | 3929 |
3929 CreditCard credit_card2("002149C1-EE28-4213-A3B9-DA243FFF021B", | 3930 CreditCard credit_card2("002149C1-EE28-4213-A3B9-DA243FFF021B", |
3930 "https://www.example.com"); | 3931 "https://www.example.com"); |
3931 credit_card2.set_use_count(1); | 3932 credit_card2.set_use_count(1); |
3932 credit_card2.set_use_date(AutofillClock::Now() - | 3933 credit_card2.set_use_date(AutofillClock::Now() - |
3933 base::TimeDelta::FromDays(1)); | 3934 base::TimeDelta::FromDays(1)); |
3934 test::SetCreditCardInfo(&credit_card2, "Homer Simpson", | 3935 test::SetCreditCardInfo(&credit_card2, "Homer Simpson", |
3935 "518765432109" /* Mastercard */, "", ""); | 3936 "518765432109" /* Mastercard */, "", ""); |
3936 credit_cards.push_back(&credit_card2); | 3937 credit_cards.push_back(&credit_card2); |
3937 | 3938 |
3938 // Create a masked server card that is slightly different of the local card. | 3939 // Create a masked server card that is slightly different of the local card. |
3939 CreditCard credit_card4(CreditCard::MASKED_SERVER_CARD, "b456"); | 3940 CreditCard credit_card4(CreditCard::MASKED_SERVER_CARD, "b456"); |
3940 test::SetCreditCardInfo(&credit_card4, "Homer Simpson", "2109", "12", "2999"); | 3941 test::SetCreditCardInfo(&credit_card4, "Homer Simpson", "2109", "12", "2999"); |
3941 credit_card4.set_use_count(3); | 3942 credit_card4.set_use_count(3); |
3942 credit_card4.set_use_date(AutofillClock::Now() - | 3943 credit_card4.set_use_date(AutofillClock::Now() - |
3943 base::TimeDelta::FromDays(15)); | 3944 base::TimeDelta::FromDays(15)); |
3944 credit_card4.SetTypeForMaskedCard(kVisaCard); | 3945 credit_card4.SetNetworkForMaskedCard(kVisaCard); |
3945 credit_cards.push_back(&credit_card4); | 3946 credit_cards.push_back(&credit_card4); |
3946 | 3947 |
3947 // Create a full server card that is slightly different of the two other | 3948 // Create a full server card that is slightly different of the two other |
3948 // cards. | 3949 // cards. |
3949 CreditCard credit_card5(CreditCard::FULL_SERVER_CARD, "c789"); | 3950 CreditCard credit_card5(CreditCard::FULL_SERVER_CARD, "c789"); |
3950 test::SetCreditCardInfo(&credit_card5, "Homer Simpson", | 3951 test::SetCreditCardInfo(&credit_card5, "Homer Simpson", |
3951 "347666888555" /* American Express */, "04", "2999"); | 3952 "347666888555" /* American Express */, "04", "2999"); |
3952 credit_card5.set_use_count(1); | 3953 credit_card5.set_use_count(1); |
3953 credit_card5.set_use_date(AutofillClock::Now() - | 3954 credit_card5.set_use_date(AutofillClock::Now() - |
3954 base::TimeDelta::FromDays(15)); | 3955 base::TimeDelta::FromDays(15)); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4021 EXPECT_EQ(kArbitraryTime, added_card->modification_date()); | 4022 EXPECT_EQ(kArbitraryTime, added_card->modification_date()); |
4022 } | 4023 } |
4023 | 4024 |
4024 TEST_F(PersonalDataManagerTest, UpdateServerCreditCardUsageStats) { | 4025 TEST_F(PersonalDataManagerTest, UpdateServerCreditCardUsageStats) { |
4025 EnableWalletCardImport(); | 4026 EnableWalletCardImport(); |
4026 | 4027 |
4027 std::vector<CreditCard> server_cards; | 4028 std::vector<CreditCard> server_cards; |
4028 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); | 4029 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); |
4029 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", | 4030 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
4030 "9012" /* Visa */, "01", "2999"); | 4031 "9012" /* Visa */, "01", "2999"); |
4031 server_cards.back().SetTypeForMaskedCard(kVisaCard); | 4032 server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
4032 | 4033 |
4033 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b456")); | 4034 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b456")); |
4034 test::SetCreditCardInfo(&server_cards.back(), "Bonnie Parker", | 4035 test::SetCreditCardInfo(&server_cards.back(), "Bonnie Parker", |
4035 "4444" /* Mastercard */, "12", "2999"); | 4036 "4444" /* Mastercard */, "12", "2999"); |
4036 server_cards.back().SetTypeForMaskedCard(kMasterCard); | 4037 server_cards.back().SetNetworkForMaskedCard(kMasterCard); |
4037 | 4038 |
4038 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); | 4039 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); |
4039 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", | 4040 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", |
4040 "347666888555" /* American Express */, "04", "2999"); | 4041 "347666888555" /* American Express */, "04", "2999"); |
4041 | 4042 |
4042 // Create the test clock and set the time to a specific value. | 4043 // Create the test clock and set the time to a specific value. |
4043 TestAutofillClock test_clock; | 4044 TestAutofillClock test_clock; |
4044 test_clock.SetNow(kArbitraryTime); | 4045 test_clock.SetNow(kArbitraryTime); |
4045 | 4046 |
4046 test::SetServerCreditCards(autofill_table_, server_cards); | 4047 test::SetServerCreditCards(autofill_table_, server_cards); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4143 EXPECT_EQ(3U, personal_data_->GetCreditCards()[1]->use_count()); | 4144 EXPECT_EQ(3U, personal_data_->GetCreditCards()[1]->use_count()); |
4144 EXPECT_EQ(kMuchLaterTime, personal_data_->GetCreditCards()[1]->use_date()); | 4145 EXPECT_EQ(kMuchLaterTime, personal_data_->GetCreditCards()[1]->use_date()); |
4145 } | 4146 } |
4146 | 4147 |
4147 TEST_F(PersonalDataManagerTest, ClearAllServerData) { | 4148 TEST_F(PersonalDataManagerTest, ClearAllServerData) { |
4148 // Add a server card. | 4149 // Add a server card. |
4149 std::vector<CreditCard> server_cards; | 4150 std::vector<CreditCard> server_cards; |
4150 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); | 4151 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); |
4151 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", | 4152 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
4152 "9012" /* Visa */, "01", "2999"); | 4153 "9012" /* Visa */, "01", "2999"); |
4153 server_cards.back().SetTypeForMaskedCard(kVisaCard); | 4154 server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
4154 test::SetServerCreditCards(autofill_table_, server_cards); | 4155 test::SetServerCreditCards(autofill_table_, server_cards); |
4155 personal_data_->Refresh(); | 4156 personal_data_->Refresh(); |
4156 | 4157 |
4157 // Need to set the google services username | 4158 // Need to set the google services username |
4158 EnableWalletCardImport(); | 4159 EnableWalletCardImport(); |
4159 | 4160 |
4160 // The card and profile should be there. | 4161 // The card and profile should be there. |
4161 ResetPersonalDataManager(USER_MODE_NORMAL); | 4162 ResetPersonalDataManager(USER_MODE_NORMAL); |
4162 EXPECT_FALSE(personal_data_->GetCreditCards().empty()); | 4163 EXPECT_FALSE(personal_data_->GetCreditCards().empty()); |
4163 | 4164 |
4164 personal_data_->ClearAllServerData(); | 4165 personal_data_->ClearAllServerData(); |
4165 | 4166 |
4166 // Reload the database, everything should be gone. | 4167 // Reload the database, everything should be gone. |
4167 ResetPersonalDataManager(USER_MODE_NORMAL); | 4168 ResetPersonalDataManager(USER_MODE_NORMAL); |
4168 EXPECT_TRUE(personal_data_->GetCreditCards().empty()); | 4169 EXPECT_TRUE(personal_data_->GetCreditCards().empty()); |
4169 } | 4170 } |
4170 | 4171 |
4171 TEST_F(PersonalDataManagerTest, DontDuplicateServerCard) { | 4172 TEST_F(PersonalDataManagerTest, DontDuplicateServerCard) { |
4172 EnableWalletCardImport(); | 4173 EnableWalletCardImport(); |
4173 | 4174 |
4174 std::vector<CreditCard> server_cards; | 4175 std::vector<CreditCard> server_cards; |
4175 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); | 4176 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "a123")); |
4176 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", | 4177 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
4177 "1881" /* Visa */, "01", "2999"); | 4178 "1881" /* Visa */, "01", "2999"); |
4178 server_cards.back().SetTypeForMaskedCard(kVisaCard); | 4179 server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
4179 | 4180 |
4180 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); | 4181 server_cards.push_back(CreditCard(CreditCard::FULL_SERVER_CARD, "c789")); |
4181 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", | 4182 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", |
4182 "347666888555" /* American Express */, "04", "2999"); | 4183 "347666888555" /* American Express */, "04", "2999"); |
4183 | 4184 |
4184 test::SetServerCreditCards(autofill_table_, server_cards); | 4185 test::SetServerCreditCards(autofill_table_, server_cards); |
4185 personal_data_->Refresh(); | 4186 personal_data_->Refresh(); |
4186 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 4187 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
4187 .WillOnce(QuitMainMessageLoop()); | 4188 .WillOnce(QuitMainMessageLoop()); |
4188 base::RunLoop().Run(); | 4189 base::RunLoop().Run(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4232 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2, false, | 4233 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2, false, |
4233 &imported_credit_card2)); | 4234 &imported_credit_card2)); |
4234 EXPECT_FALSE(imported_credit_card2); | 4235 EXPECT_FALSE(imported_credit_card2); |
4235 } | 4236 } |
4236 | 4237 |
4237 // Tests the SaveImportedProfile method with different profiles to make sure the | 4238 // Tests the SaveImportedProfile method with different profiles to make sure the |
4238 // merge logic works correctly. | 4239 // merge logic works correctly. |
4239 typedef struct { | 4240 typedef struct { |
4240 autofill::ServerFieldType field_type; | 4241 autofill::ServerFieldType field_type; |
4241 std::string field_value; | 4242 std::string field_value; |
4242 } ProfileField; | 4243 } ProfileField; |
4243 | 4244 |
4244 typedef std::vector<ProfileField> ProfileFields; | 4245 typedef std::vector<ProfileField> ProfileFields; |
4245 | 4246 |
4246 typedef struct { | 4247 typedef struct { |
4247 // Each test starts with a default pre-existing profile and applies these | 4248 // Each test starts with a default pre-existing profile and applies these |
4248 // changes to it. | 4249 // changes to it. |
4249 ProfileFields changes_to_original; | 4250 ProfileFields changes_to_original; |
4250 // Each test saves a second profile. Applies these changes to the default | 4251 // Each test saves a second profile. Applies these changes to the default |
4251 // values before saving. | 4252 // values before saving. |
4252 ProfileFields changes_to_new; | 4253 ProfileFields changes_to_new; |
4253 // For tests with profile merging, makes sure that these fields' values are | 4254 // For tests with profile merging, makes sure that these fields' values are |
4254 // the ones we expect (depending on the test). | 4255 // the ones we expect (depending on the test). |
4255 ProfileFields changed_field_values; | 4256 ProfileFields changed_field_values; |
4256 } SaveImportedProfileTestCase; | 4257 } SaveImportedProfileTestCase; |
4257 | 4258 |
4258 class SaveImportedProfileTest | 4259 class SaveImportedProfileTest |
4259 : public PersonalDataManagerTestBase, | 4260 : public PersonalDataManagerTestBase, |
4260 public testing::TestWithParam<SaveImportedProfileTestCase> { | 4261 public testing::TestWithParam<SaveImportedProfileTestCase> { |
4261 public: | 4262 public: |
4262 SaveImportedProfileTest() {} | 4263 SaveImportedProfileTest() {} |
4263 ~SaveImportedProfileTest() override {} | 4264 ~SaveImportedProfileTest() override {} |
4264 | 4265 |
4265 void SetUp() override { | 4266 void SetUp() override { |
4266 OSCryptMocker::SetUpWithSingleton(); | 4267 OSCryptMocker::SetUpWithSingleton(); |
4267 prefs_ = test::PrefServiceForTesting(); | 4268 prefs_ = test::PrefServiceForTesting(); |
4268 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 4269 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
4269 base::FilePath path = temp_dir_.GetPath().AppendASCII("TestWebDB"); | 4270 base::FilePath path = temp_dir_.GetPath().AppendASCII("TestWebDB"); |
4270 web_database_ = | 4271 web_database_ = |
4271 new WebDatabaseService(path, base::ThreadTaskRunnerHandle::Get(), | 4272 new WebDatabaseService(path, base::ThreadTaskRunnerHandle::Get(), |
4272 base::ThreadTaskRunnerHandle::Get()); | 4273 base::ThreadTaskRunnerHandle::Get()); |
4273 | 4274 |
4274 // Setup account tracker. | 4275 // Setup account tracker. |
4275 signin_client_.reset(new TestSigninClient(prefs_.get())); | 4276 signin_client_.reset(new TestSigninClient(prefs_.get())); |
4276 account_tracker_.reset(new AccountTrackerService()); | 4277 account_tracker_.reset(new AccountTrackerService()); |
4277 account_tracker_->Initialize(signin_client_.get()); | 4278 account_tracker_->Initialize(signin_client_.get()); |
4278 signin_manager_.reset(new FakeSigninManagerBase(signin_client_.get(), | 4279 signin_manager_.reset(new FakeSigninManagerBase(signin_client_.get(), |
4279 account_tracker_.get())); | 4280 account_tracker_.get())); |
4280 signin_manager_->Initialize(prefs_.get()); | 4281 signin_manager_->Initialize(prefs_.get()); |
4281 | 4282 |
4282 // Hacky: hold onto a pointer but pass ownership. | 4283 // Hacky: hold onto a pointer but pass ownership. |
4283 autofill_table_ = new AutofillTable; | 4284 autofill_table_ = new AutofillTable; |
4284 web_database_->AddTable( | 4285 web_database_->AddTable(std::unique_ptr<WebDatabaseTable>(autofill_table_)); |
4285 std::unique_ptr<WebDatabaseTable>(autofill_table_)); | 4286 web_database_->LoadDatabase(); |
4286 web_database_->LoadDatabase(); | 4287 autofill_database_service_ = new AutofillWebDataService( |
4287 autofill_database_service_ = new AutofillWebDataService( | 4288 web_database_, base::ThreadTaskRunnerHandle::Get(), |
4288 web_database_, base::ThreadTaskRunnerHandle::Get(), | 4289 base::ThreadTaskRunnerHandle::Get(), |
4289 base::ThreadTaskRunnerHandle::Get(), | 4290 WebDataServiceBase::ProfileErrorCallback()); |
4290 WebDataServiceBase::ProfileErrorCallback()); | 4291 autofill_database_service_->Init(); |
4291 autofill_database_service_->Init(); | 4292 |
4292 | 4293 test::DisableSystemServices(prefs_.get()); |
4293 test::DisableSystemServices(prefs_.get()); | 4294 ResetPersonalDataManager(USER_MODE_NORMAL); |
4294 ResetPersonalDataManager(USER_MODE_NORMAL); | 4295 |
4295 | 4296 // Reset the deduping pref to its default value. |
4296 // Reset the deduping pref to its default value. | 4297 personal_data_->pref_service_->SetInteger( |
4297 personal_data_->pref_service_->SetInteger( | 4298 prefs::kAutofillLastVersionDeduped, 0); |
4298 prefs::kAutofillLastVersionDeduped, 0); | 4299 personal_data_->pref_service_->SetBoolean( |
4299 personal_data_->pref_service_->SetBoolean( | 4300 prefs::kAutofillProfileUseDatesFixed, false); |
4300 prefs::kAutofillProfileUseDatesFixed, false); | 4301 } |
| 4302 |
| 4303 void TearDown() override { |
| 4304 // Order of destruction is important as AutofillManager relies on |
| 4305 // PersonalDataManager to be around when it gets destroyed. |
| 4306 signin_manager_->Shutdown(); |
| 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(change.field_type, |
| 4332 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)); |
4301 } | 4365 } |
4302 | 4366 // Verify that the merged profile's use count, use date and modification |
4303 void TearDown() override { | 4367 // date were properly updated. |
4304 // Order of destruction is important as AutofillManager relies on | 4368 EXPECT_EQ(1U, saved_profiles.front()->use_count()); |
4305 // PersonalDataManager to be around when it gets destroyed. | 4369 EXPECT_EQ(kSomeLaterTime, saved_profiles.front()->use_date()); |
4306 signin_manager_->Shutdown(); | 4370 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 } | 4371 } |
4376 | 4372 |
4377 INSTANTIATE_TEST_CASE_P( | 4373 // Erase the profiles for the next test. |
4378 PersonalDataManagerTest, | 4374 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 } | 4375 } |
4693 | 4376 |
| 4377 INSTANTIATE_TEST_CASE_P( |
| 4378 PersonalDataManagerTest, |
| 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{ProfileFields(), |
| 4390 {{NAME_MIDDLE, "M"}}, |
| 4391 {{NAME_MIDDLE, "Mitchell"}, |
| 4392 {NAME_FULL, "Marion Mitchell Morrison"}}}, |
| 4393 |
| 4394 // Test that saving an identical profile except with the full middle |
| 4395 // name instead of the middle name initial results in the profiles |
| 4396 // getting merged and the full middle name replacing the initial. |
| 4397 SaveImportedProfileTestCase{{{NAME_MIDDLE, "M"}}, |
| 4398 {{NAME_MIDDLE, "Mitchell"}}, |
| 4399 {{NAME_MIDDLE, "Mitchell"}}}, |
| 4400 |
| 4401 // Test that saving an identical profile except with no middle name |
| 4402 // results in the profiles getting merged and the full middle name |
| 4403 // being kept. |
| 4404 SaveImportedProfileTestCase{ProfileFields(), |
| 4405 {{NAME_MIDDLE, ""}}, |
| 4406 {{NAME_MIDDLE, "Mitchell"}}}, |
| 4407 |
| 4408 // Test that saving an identical profile except with a middle name |
| 4409 // initial results in the profiles getting merged and the middle name |
| 4410 // initial being saved. |
| 4411 SaveImportedProfileTestCase{{{NAME_MIDDLE, ""}}, |
| 4412 {{NAME_MIDDLE, "M"}}, |
| 4413 {{NAME_MIDDLE, "M"}}}, |
| 4414 |
| 4415 // Test that saving an identical profile except with a middle name |
| 4416 // results in the profiles getting merged and the full middle name |
| 4417 // being saved. |
| 4418 SaveImportedProfileTestCase{{{NAME_MIDDLE, ""}}, |
| 4419 {{NAME_MIDDLE, "Mitchell"}}, |
| 4420 {{NAME_MIDDLE, "Mitchell"}}}, |
| 4421 |
| 4422 // Test that saving a identical profile except with the full name set |
| 4423 // instead of the name parts results in the two profiles being merged |
| 4424 // and all the name parts kept and the full name being added. |
| 4425 SaveImportedProfileTestCase{ |
| 4426 { |
| 4427 {NAME_FIRST, "Marion"}, |
| 4428 {NAME_MIDDLE, "Mitchell"}, |
| 4429 {NAME_LAST, "Morrison"}, |
| 4430 {NAME_FULL, ""}, |
| 4431 }, |
| 4432 { |
| 4433 {NAME_FIRST, ""}, |
| 4434 {NAME_MIDDLE, ""}, |
| 4435 {NAME_LAST, ""}, |
| 4436 {NAME_FULL, "Marion Mitchell Morrison"}, |
| 4437 }, |
| 4438 { |
| 4439 {NAME_FIRST, "Marion"}, |
| 4440 {NAME_MIDDLE, "Mitchell"}, |
| 4441 {NAME_LAST, "Morrison"}, |
| 4442 {NAME_FULL, "Marion Mitchell Morrison"}, |
| 4443 }, |
| 4444 }, |
| 4445 |
| 4446 // Test that saving a identical profile except with the name parts set |
| 4447 // instead of the full name results in the two profiles being merged |
| 4448 // and the full name being kept and all the name parts being added. |
| 4449 SaveImportedProfileTestCase{ |
| 4450 { |
| 4451 {NAME_FIRST, ""}, |
| 4452 {NAME_MIDDLE, ""}, |
| 4453 {NAME_LAST, ""}, |
| 4454 {NAME_FULL, "Marion Mitchell Morrison"}, |
| 4455 }, |
| 4456 { |
| 4457 {NAME_FIRST, "Marion"}, |
| 4458 {NAME_MIDDLE, "Mitchell"}, |
| 4459 {NAME_LAST, "Morrison"}, |
| 4460 {NAME_FULL, ""}, |
| 4461 }, |
| 4462 { |
| 4463 {NAME_FIRST, "Marion"}, |
| 4464 {NAME_MIDDLE, "Mitchell"}, |
| 4465 {NAME_LAST, "Morrison"}, |
| 4466 {NAME_FULL, "Marion Mitchell Morrison"}, |
| 4467 }, |
| 4468 }, |
| 4469 |
| 4470 // Test that saving a profile that has only a full name set does not |
| 4471 // get merged with a profile with only the name parts set if the names |
| 4472 // are different. |
| 4473 SaveImportedProfileTestCase{ |
| 4474 { |
| 4475 {NAME_FIRST, "Marion"}, |
| 4476 {NAME_MIDDLE, "Mitchell"}, |
| 4477 {NAME_LAST, "Morrison"}, |
| 4478 {NAME_FULL, ""}, |
| 4479 }, |
| 4480 { |
| 4481 {NAME_FIRST, ""}, |
| 4482 {NAME_MIDDLE, ""}, |
| 4483 {NAME_LAST, ""}, |
| 4484 {NAME_FULL, "John Thompson Smith"}, |
| 4485 }, |
| 4486 }, |
| 4487 |
| 4488 // Test that saving a profile that has only the name parts set does |
| 4489 // not get merged with a profile with only the full name set if the |
| 4490 // names are different. |
| 4491 SaveImportedProfileTestCase{ |
| 4492 { |
| 4493 {NAME_FIRST, ""}, |
| 4494 {NAME_MIDDLE, ""}, |
| 4495 {NAME_LAST, ""}, |
| 4496 {NAME_FULL, "John Thompson Smith"}, |
| 4497 }, |
| 4498 { |
| 4499 {NAME_FIRST, "Marion"}, |
| 4500 {NAME_MIDDLE, "Mitchell"}, |
| 4501 {NAME_LAST, "Morrison"}, |
| 4502 {NAME_FULL, ""}, |
| 4503 }, |
| 4504 }, |
| 4505 |
| 4506 // Test that saving an identical profile except for the first address |
| 4507 // line results in two profiles being saved. |
| 4508 SaveImportedProfileTestCase{ProfileFields(), |
| 4509 {{ADDRESS_HOME_LINE1, "123 Aquarium St."}}}, |
| 4510 |
| 4511 // Test that saving an identical profile except for the second address |
| 4512 // line results in two profiles being saved. |
| 4513 SaveImportedProfileTestCase{ProfileFields(), |
| 4514 {{ADDRESS_HOME_LINE2, "unit 7"}}}, |
| 4515 |
| 4516 // Tests that saving an identical profile that has a new piece of |
| 4517 // information (company name) results in a merge and that the original |
| 4518 // empty value gets overwritten by the new information. |
| 4519 SaveImportedProfileTestCase{{{COMPANY_NAME, ""}}, |
| 4520 ProfileFields(), |
| 4521 {{COMPANY_NAME, "Fox"}}}, |
| 4522 |
| 4523 // Tests that saving an identical profile except a loss of information |
| 4524 // results in a merge but the original value is not overwritten (no |
| 4525 // information loss). |
| 4526 SaveImportedProfileTestCase{ProfileFields(), |
| 4527 {{COMPANY_NAME, ""}}, |
| 4528 {{COMPANY_NAME, "Fox"}}}, |
| 4529 |
| 4530 // Tests that saving an identical profile except a slightly different |
| 4531 // postal code results in a merge with the new value kept. |
| 4532 SaveImportedProfileTestCase{{{ADDRESS_HOME_ZIP, "R2C 0A1"}}, |
| 4533 {{ADDRESS_HOME_ZIP, "R2C0A1"}}, |
| 4534 {{ADDRESS_HOME_ZIP, "R2C0A1"}}}, |
| 4535 SaveImportedProfileTestCase{{{ADDRESS_HOME_ZIP, "R2C0A1"}}, |
| 4536 {{ADDRESS_HOME_ZIP, "R2C 0A1"}}, |
| 4537 {{ADDRESS_HOME_ZIP, "R2C 0A1"}}}, |
| 4538 SaveImportedProfileTestCase{{{ADDRESS_HOME_ZIP, "r2c 0a1"}}, |
| 4539 {{ADDRESS_HOME_ZIP, "R2C0A1"}}, |
| 4540 {{ADDRESS_HOME_ZIP, "R2C0A1"}}}, |
| 4541 |
| 4542 // Tests that saving an identical profile plus a new piece of |
| 4543 // information on the address line 2 results in a merge and that the |
| 4544 // original empty value gets overwritten by the new information. |
| 4545 SaveImportedProfileTestCase{{{ADDRESS_HOME_LINE2, ""}}, |
| 4546 ProfileFields(), |
| 4547 {{ADDRESS_HOME_LINE2, "unit 5"}}}, |
| 4548 |
| 4549 // Tests that saving an identical profile except a loss of information |
| 4550 // on the address line 2 results in a merge but that the original |
| 4551 // value gets not overwritten (no information loss). |
| 4552 SaveImportedProfileTestCase{ProfileFields(), |
| 4553 {{ADDRESS_HOME_LINE2, ""}}, |
| 4554 {{ADDRESS_HOME_LINE2, "unit 5"}}}, |
| 4555 |
| 4556 // Tests that saving an identical except with more punctuation in the |
| 4557 // fist address line, while the second is empty, results in a merge |
| 4558 // and that the original address gets overwritten. |
| 4559 SaveImportedProfileTestCase{ |
| 4560 {{ADDRESS_HOME_LINE2, ""}}, |
| 4561 {{ADDRESS_HOME_LINE2, ""}, {ADDRESS_HOME_LINE1, "123, Zoo St."}}, |
| 4562 {{ADDRESS_HOME_LINE1, "123, Zoo St."}}}, |
| 4563 |
| 4564 // Tests that saving an identical profile except with less punctuation |
| 4565 // in the fist address line, while the second is empty, results in a |
| 4566 // merge and that the longer address is retained. |
| 4567 SaveImportedProfileTestCase{ |
| 4568 {{ADDRESS_HOME_LINE2, ""}, {ADDRESS_HOME_LINE1, "123, Zoo St."}}, |
| 4569 {{ADDRESS_HOME_LINE2, ""}}, |
| 4570 {{ADDRESS_HOME_LINE1, "123 Zoo St"}}}, |
| 4571 |
| 4572 // Tests that saving an identical profile except additional |
| 4573 // punctuation in the two address lines results in a merge and that |
| 4574 // the newer address is retained. |
| 4575 SaveImportedProfileTestCase{ProfileFields(), |
| 4576 {{ADDRESS_HOME_LINE1, "123, Zoo St."}, |
| 4577 {ADDRESS_HOME_LINE2, "unit. 5"}}, |
| 4578 {{ADDRESS_HOME_LINE1, "123, Zoo St."}, |
| 4579 {ADDRESS_HOME_LINE2, "unit. 5"}}}, |
| 4580 |
| 4581 // Tests that saving an identical profile except less punctuation in |
| 4582 // the two address lines results in a merge and that the newer address |
| 4583 // is retained. |
| 4584 SaveImportedProfileTestCase{{{ADDRESS_HOME_LINE1, "123, Zoo St."}, |
| 4585 {ADDRESS_HOME_LINE2, "unit. 5"}}, |
| 4586 ProfileFields(), |
| 4587 {{ADDRESS_HOME_LINE1, "123 Zoo St"}, |
| 4588 {ADDRESS_HOME_LINE2, "unit 5"}}}, |
| 4589 |
| 4590 // Tests that saving an identical profile with accented characters in |
| 4591 // the two address lines results in a merge and that the newer address |
| 4592 // is retained. |
| 4593 SaveImportedProfileTestCase{ProfileFields(), |
| 4594 {{ADDRESS_HOME_LINE1, "123 Zôö St"}, |
| 4595 {ADDRESS_HOME_LINE2, "üñìt 5"}}, |
| 4596 {{ADDRESS_HOME_LINE1, "123 Zôö St"}, |
| 4597 {ADDRESS_HOME_LINE2, "üñìt 5"}}}, |
| 4598 |
| 4599 // Tests that saving an identical profile without accented characters |
| 4600 // in the two address lines results in a merge and that the newer |
| 4601 // address is retained. |
| 4602 SaveImportedProfileTestCase{{{ADDRESS_HOME_LINE1, "123 Zôö St"}, |
| 4603 {ADDRESS_HOME_LINE2, "üñìt 5"}}, |
| 4604 ProfileFields(), |
| 4605 {{ADDRESS_HOME_LINE1, "123 Zoo St"}, |
| 4606 {ADDRESS_HOME_LINE2, "unit 5"}}}, |
| 4607 |
| 4608 // Tests that saving an identical profile except that the address line |
| 4609 // 1 is in the address line 2 results in a merge and that the |
| 4610 // multi-lne address is retained. |
| 4611 SaveImportedProfileTestCase{ProfileFields(), |
| 4612 {{ADDRESS_HOME_LINE1, "123 Zoo St, unit 5"}, |
| 4613 {ADDRESS_HOME_LINE2, ""}}, |
| 4614 {{ADDRESS_HOME_LINE1, "123 Zoo St"}, |
| 4615 {ADDRESS_HOME_LINE2, "unit 5"}}}, |
| 4616 |
| 4617 // Tests that saving an identical profile except that the address line |
| 4618 // 2 contains part of the old address line 1 results in a merge and |
| 4619 // that the original address lines of the reference profile get |
| 4620 // overwritten. |
| 4621 SaveImportedProfileTestCase{{{ADDRESS_HOME_LINE1, "123 Zoo St, unit 5"}, |
| 4622 {ADDRESS_HOME_LINE2, ""}}, |
| 4623 ProfileFields(), |
| 4624 {{ADDRESS_HOME_LINE1, "123 Zoo St"}, |
| 4625 {ADDRESS_HOME_LINE2, "unit 5"}}}, |
| 4626 |
| 4627 // Tests that saving an identical profile except that the state is the |
| 4628 // abbreviation instead of the full form results in a merge and that |
| 4629 // the original state gets overwritten. |
| 4630 SaveImportedProfileTestCase{{{ADDRESS_HOME_STATE, "California"}}, |
| 4631 ProfileFields(), |
| 4632 {{ADDRESS_HOME_STATE, "CA"}}}, |
| 4633 |
| 4634 // Tests that saving an identical profile except that the state is the |
| 4635 // full form instead of the abbreviation results in a merge and that |
| 4636 // the abbreviated state is retained. |
| 4637 SaveImportedProfileTestCase{ProfileFields(), |
| 4638 {{ADDRESS_HOME_STATE, "California"}}, |
| 4639 {{ADDRESS_HOME_STATE, "CA"}}}, |
| 4640 |
| 4641 // Tests that saving and identical profile except that the company |
| 4642 // name has different punctuation and case results in a merge and that |
| 4643 // the syntax of the new profile replaces the old one. |
| 4644 SaveImportedProfileTestCase{{{COMPANY_NAME, "Stark inc"}}, |
| 4645 {{COMPANY_NAME, "Stark Inc."}}, |
| 4646 {{COMPANY_NAME, "Stark Inc."}}})); |
| 4647 |
| 4648 // Tests that MergeProfile tries to merge the imported profile into the |
| 4649 // existing profile in decreasing order of frecency. |
| 4650 TEST_F(PersonalDataManagerTest, MergeProfile_Frecency) { |
| 4651 // Create two very similar profiles except with different company names. |
| 4652 std::unique_ptr<AutofillProfile> profile1 = base::MakeUnique<AutofillProfile>( |
| 4653 base::GenerateGUID(), "https://www.example.com"); |
| 4654 test::SetProfileInfo(profile1.get(), "Homer", "Jay", "Simpson", |
| 4655 "homer.simpson@abc.com", "SNP", "742 Evergreen Terrace", |
| 4656 "", "Springfield", "IL", "91601", "US", "12345678910"); |
| 4657 AutofillProfile* profile2 = |
| 4658 new AutofillProfile(base::GenerateGUID(), "https://www.example.com"); |
| 4659 test::SetProfileInfo(profile2, "Homer", "Jay", "Simpson", |
| 4660 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace", |
| 4661 "", "Springfield", "IL", "91601", "US", "12345678910"); |
| 4662 |
| 4663 // Give the "Fox" profile a bigger frecency score. |
| 4664 profile2->set_use_count(15); |
| 4665 |
| 4666 // Create the |existing_profiles| vector. |
| 4667 std::vector<std::unique_ptr<AutofillProfile>> existing_profiles; |
| 4668 existing_profiles.push_back(std::move(profile1)); |
| 4669 existing_profiles.push_back(base::WrapUnique(profile2)); |
| 4670 |
| 4671 // Create a new imported profile with no company name. |
| 4672 AutofillProfile imported_profile(base::GenerateGUID(), |
| 4673 "https://www.example.com"); |
| 4674 test::SetProfileInfo(&imported_profile, "Homer", "Jay", "Simpson", |
| 4675 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", |
| 4676 "Springfield", "IL", "91601", "US", "12345678910"); |
| 4677 |
| 4678 // Merge the imported profile into the existing profiles. |
| 4679 std::vector<AutofillProfile> profiles; |
| 4680 std::string guid = personal_data_->MergeProfile( |
| 4681 imported_profile, &existing_profiles, "US-EN", &profiles); |
| 4682 |
| 4683 // The new profile should be merged into the "fox" profile. |
| 4684 EXPECT_EQ(profile2->guid(), guid); |
| 4685 } |
| 4686 |
4694 // Tests that MergeProfile produces a merged profile with the expected usage | 4687 // Tests that MergeProfile produces a merged profile with the expected usage |
4695 // statistics. | 4688 // statistics. |
4696 // Flaky on TSan, see crbug.com/686226. | 4689 // Flaky on TSan, see crbug.com/686226. |
4697 #if defined(THREAD_SANITIZER) | 4690 #if defined(THREAD_SANITIZER) |
4698 #define MAYBE_MergeProfile_UsageStats DISABLED_MergeProfile_UsageStats | 4691 #define MAYBE_MergeProfile_UsageStats DISABLED_MergeProfile_UsageStats |
4699 #else | 4692 #else |
4700 #define MAYBE_MergeProfile_UsageStats MergeProfile_UsageStats | 4693 #define MAYBE_MergeProfile_UsageStats MergeProfile_UsageStats |
4701 #endif | 4694 #endif |
4702 TEST_F(PersonalDataManagerTest, MAYBE_MergeProfile_UsageStats) { | 4695 TEST_F(PersonalDataManagerTest, MAYBE_MergeProfile_UsageStats) { |
4703 // Create the test clock and set the time to a specific value. | 4696 // Create the test clock and set the time to a specific value. |
(...skipping 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5706 base::RunLoop().Run(); | 5699 base::RunLoop().Run(); |
5707 | 5700 |
5708 EXPECT_EQ(1U, personal_data_->GetProfiles().size()); | 5701 EXPECT_EQ(1U, personal_data_->GetProfiles().size()); |
5709 | 5702 |
5710 // Enable the profile cleanup now. Otherwise it would be triggered by the | 5703 // Enable the profile cleanup now. Otherwise it would be triggered by the |
5711 // calls to AddProfile. | 5704 // calls to AddProfile. |
5712 EnableAutofillProfileCleanup(); | 5705 EnableAutofillProfileCleanup(); |
5713 EXPECT_FALSE(personal_data_->ApplyDedupingRoutine()); | 5706 EXPECT_FALSE(personal_data_->ApplyDedupingRoutine()); |
5714 } | 5707 } |
5715 | 5708 |
5716 | |
5717 // Tests that ApplyDedupingRoutine is not run a second time on the same major | 5709 // Tests that ApplyDedupingRoutine is not run a second time on the same major |
5718 // version. | 5710 // version. |
5719 TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_OncePerVersion) { | 5711 TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_OncePerVersion) { |
5720 // Create a profile to dedupe. | 5712 // Create a profile to dedupe. |
5721 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); | 5713 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); |
5722 test::SetProfileInfo(&profile1, "Homer", "J", "Simpson", | 5714 test::SetProfileInfo(&profile1, "Homer", "J", "Simpson", |
5723 "homer.simpson@abc.com", "", "742. Evergreen Terrace", | 5715 "homer.simpson@abc.com", "", "742. Evergreen Terrace", |
5724 "", "Springfield", "IL", "91601", "US", ""); | 5716 "", "Springfield", "IL", "91601", "US", ""); |
5725 | 5717 |
5726 // Create a similar profile. | 5718 // Create a similar profile. |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5819 test::SetCreditCardInfo(&local_card, "Clyde Barrow", | 5811 test::SetCreditCardInfo(&local_card, "Clyde Barrow", |
5820 "347666888555" /* American Express */, "04", "2999"); | 5812 "347666888555" /* American Express */, "04", "2999"); |
5821 local_card.set_billing_address_id(kServerAddressId); | 5813 local_card.set_billing_address_id(kServerAddressId); |
5822 personal_data_->AddCreditCard(local_card); | 5814 personal_data_->AddCreditCard(local_card); |
5823 | 5815 |
5824 std::vector<CreditCard> server_cards; | 5816 std::vector<CreditCard> server_cards; |
5825 server_cards.push_back( | 5817 server_cards.push_back( |
5826 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card1")); | 5818 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card1")); |
5827 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", | 5819 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
5828 "1111" /* Visa */, "01", "2999"); | 5820 "1111" /* Visa */, "01", "2999"); |
5829 server_cards.back().SetTypeForMaskedCard(kVisaCard); | 5821 server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
5830 server_cards.back().set_billing_address_id(kServerAddressId); | 5822 server_cards.back().set_billing_address_id(kServerAddressId); |
5831 test::SetServerCreditCards(autofill_table_, server_cards); | 5823 test::SetServerCreditCards(autofill_table_, server_cards); |
5832 | 5824 |
5833 // Make sure everything is setup correctly. | 5825 // Make sure everything is setup correctly. |
5834 personal_data_->Refresh(); | 5826 personal_data_->Refresh(); |
5835 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 5827 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
5836 .WillOnce(QuitMainMessageLoop()); | 5828 .WillOnce(QuitMainMessageLoop()); |
5837 base::RunLoop().Run(); | 5829 base::RunLoop().Run(); |
5838 EXPECT_EQ(1U, personal_data_->web_profiles().size()); | 5830 EXPECT_EQ(1U, personal_data_->web_profiles().size()); |
5839 EXPECT_EQ(1U, personal_data_->GetServerProfiles().size()); | 5831 EXPECT_EQ(1U, personal_data_->GetServerProfiles().size()); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5926 test::SetCreditCardInfo(&local_card, "Clyde Barrow", | 5918 test::SetCreditCardInfo(&local_card, "Clyde Barrow", |
5927 "347666888555" /* American Express */, "04", "2999"); | 5919 "347666888555" /* American Express */, "04", "2999"); |
5928 local_card.set_billing_address_id(kServerAddressId); | 5920 local_card.set_billing_address_id(kServerAddressId); |
5929 personal_data_->AddCreditCard(local_card); | 5921 personal_data_->AddCreditCard(local_card); |
5930 | 5922 |
5931 std::vector<CreditCard> server_cards; | 5923 std::vector<CreditCard> server_cards; |
5932 server_cards.push_back( | 5924 server_cards.push_back( |
5933 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card1")); | 5925 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card1")); |
5934 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", | 5926 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
5935 "1111" /* Visa */, "01", "2999"); | 5927 "1111" /* Visa */, "01", "2999"); |
5936 server_cards.back().SetTypeForMaskedCard(kVisaCard); | 5928 server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
5937 server_cards.back().set_billing_address_id(kServerAddressId); | 5929 server_cards.back().set_billing_address_id(kServerAddressId); |
5938 test::SetServerCreditCards(autofill_table_, server_cards); | 5930 test::SetServerCreditCards(autofill_table_, server_cards); |
5939 | 5931 |
5940 // Make sure everything is setup correctly. | 5932 // Make sure everything is setup correctly. |
5941 personal_data_->Refresh(); | 5933 personal_data_->Refresh(); |
5942 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 5934 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
5943 .WillOnce(QuitMainMessageLoop()); | 5935 .WillOnce(QuitMainMessageLoop()); |
5944 base::RunLoop().Run(); | 5936 base::RunLoop().Run(); |
5945 EXPECT_EQ(1U, personal_data_->web_profiles().size()); | 5937 EXPECT_EQ(1U, personal_data_->web_profiles().size()); |
5946 EXPECT_EQ(1U, personal_data_->GetServerProfiles().size()); | 5938 EXPECT_EQ(1U, personal_data_->GetServerProfiles().size()); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6098 test::SetCreditCardInfo(&local_card, "Clyde Barrow", | 6090 test::SetCreditCardInfo(&local_card, "Clyde Barrow", |
6099 "347666888555" /* American Express */, "04", "2999"); | 6091 "347666888555" /* American Express */, "04", "2999"); |
6100 local_card.set_billing_address_id(kServerAddressId); | 6092 local_card.set_billing_address_id(kServerAddressId); |
6101 personal_data_->AddCreditCard(local_card); | 6093 personal_data_->AddCreditCard(local_card); |
6102 | 6094 |
6103 std::vector<CreditCard> server_cards; | 6095 std::vector<CreditCard> server_cards; |
6104 server_cards.push_back( | 6096 server_cards.push_back( |
6105 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card1")); | 6097 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card1")); |
6106 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", | 6098 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
6107 "1111" /* Visa */, "01", "2999"); | 6099 "1111" /* Visa */, "01", "2999"); |
6108 server_cards.back().SetTypeForMaskedCard(kVisaCard); | 6100 server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
6109 server_cards.back().set_billing_address_id(kServerAddressId2); | 6101 server_cards.back().set_billing_address_id(kServerAddressId2); |
6110 test::SetServerCreditCards(autofill_table_, server_cards); | 6102 test::SetServerCreditCards(autofill_table_, server_cards); |
6111 | 6103 |
6112 // Make sure everything is setup correctly. | 6104 // Make sure everything is setup correctly. |
6113 personal_data_->Refresh(); | 6105 personal_data_->Refresh(); |
6114 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 6106 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
6115 .WillOnce(QuitMainMessageLoop()); | 6107 .WillOnce(QuitMainMessageLoop()); |
6116 base::RunLoop().Run(); | 6108 base::RunLoop().Run(); |
6117 EXPECT_EQ(1U, personal_data_->web_profiles().size()); | 6109 EXPECT_EQ(1U, personal_data_->web_profiles().size()); |
6118 EXPECT_EQ(2U, personal_data_->GetServerProfiles().size()); | 6110 EXPECT_EQ(2U, personal_data_->GetServerProfiles().size()); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6164 EXPECT_EQ(profiles[0]->guid(), | 6156 EXPECT_EQ(profiles[0]->guid(), |
6165 personal_data_->GetCreditCards()[0]->billing_address_id()); | 6157 personal_data_->GetCreditCards()[0]->billing_address_id()); |
6166 EXPECT_EQ(profiles[0]->guid(), | 6158 EXPECT_EQ(profiles[0]->guid(), |
6167 personal_data_->GetCreditCards()[1]->billing_address_id()); | 6159 personal_data_->GetCreditCards()[1]->billing_address_id()); |
6168 } | 6160 } |
6169 | 6161 |
6170 // Tests a new server card's billing address is updated propely even if the | 6162 // Tests a new server card's billing address is updated propely even if the |
6171 // address was already converted in the past. | 6163 // address was already converted in the past. |
6172 TEST_F( | 6164 TEST_F( |
6173 PersonalDataManagerTest, | 6165 PersonalDataManagerTest, |
6174 ConvertWalletAddressesAndUpdateWalletCards_NewCard_AddressAlreadyConverted)
{ | 6166 ConvertWalletAddressesAndUpdateWalletCards_NewCrd_AddressAlreadyConverted) { |
6175 /////////////////////////////////////////////////////////////////////// | 6167 /////////////////////////////////////////////////////////////////////// |
6176 // Setup. | 6168 // Setup. |
6177 /////////////////////////////////////////////////////////////////////// | 6169 /////////////////////////////////////////////////////////////////////// |
6178 // Go through the conversion process for a server address and card. Then add | 6170 // 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 | 6171 // a new server card that refers to the already converted server address as |
6180 // its billing address. | 6172 // its billing address. |
6181 EnableWalletCardImport(); | 6173 EnableWalletCardImport(); |
6182 base::HistogramTester histogram_tester; | 6174 base::HistogramTester histogram_tester; |
6183 const std::string kServerAddressId("server_address1"); | 6175 const std::string kServerAddressId("server_address1"); |
6184 | 6176 |
6185 // Add a server profile. | 6177 // Add a server profile. |
6186 std::vector<AutofillProfile> GetServerProfiles; | 6178 std::vector<AutofillProfile> GetServerProfiles; |
6187 GetServerProfiles.push_back( | 6179 GetServerProfiles.push_back( |
6188 AutofillProfile(AutofillProfile::SERVER_PROFILE, kServerAddressId)); | 6180 AutofillProfile(AutofillProfile::SERVER_PROFILE, kServerAddressId)); |
6189 test::SetProfileInfo(&GetServerProfiles.back(), "John", "", "Doe", "", "Fox", | 6181 test::SetProfileInfo(&GetServerProfiles.back(), "John", "", "Doe", "", "Fox", |
6190 "1212 Center", "Bld. 5", "Orlando", "FL", "", "US", ""); | 6182 "1212 Center", "Bld. 5", "Orlando", "FL", "", "US", ""); |
6191 // Wallet only provides a full name, so the above first and last names | 6183 // 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. | 6184 // will be ignored when the profile is written to the DB. |
6193 GetServerProfiles.back().SetRawInfo(NAME_FULL, ASCIIToUTF16("John Doe")); | 6185 GetServerProfiles.back().SetRawInfo(NAME_FULL, ASCIIToUTF16("John Doe")); |
6194 GetServerProfiles.back().set_use_count(100); | 6186 GetServerProfiles.back().set_use_count(100); |
6195 autofill_table_->SetServerProfiles(GetServerProfiles); | 6187 autofill_table_->SetServerProfiles(GetServerProfiles); |
6196 | 6188 |
6197 // Add a server card that have the server address as billing address. | 6189 // Add a server card that have the server address as billing address. |
6198 std::vector<CreditCard> server_cards; | 6190 std::vector<CreditCard> server_cards; |
6199 server_cards.push_back( | 6191 server_cards.push_back( |
6200 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card1")); | 6192 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card1")); |
6201 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", | 6193 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
6202 "1111" /* Visa */, "01", "2999"); | 6194 "1111" /* Visa */, "01", "2999"); |
6203 server_cards.back().SetTypeForMaskedCard(kVisaCard); | 6195 server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
6204 server_cards.back().set_billing_address_id(kServerAddressId); | 6196 server_cards.back().set_billing_address_id(kServerAddressId); |
6205 test::SetServerCreditCards(autofill_table_, server_cards); | 6197 test::SetServerCreditCards(autofill_table_, server_cards); |
6206 | 6198 |
6207 // Make sure everything is setup correctly. | 6199 // Make sure everything is setup correctly. |
6208 personal_data_->Refresh(); | 6200 personal_data_->Refresh(); |
6209 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 6201 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
6210 .WillOnce(QuitMainMessageLoop()); | 6202 .WillOnce(QuitMainMessageLoop()); |
6211 base::RunLoop().Run(); | 6203 base::RunLoop().Run(); |
6212 EXPECT_EQ(1U, personal_data_->GetServerProfiles().size()); | 6204 EXPECT_EQ(1U, personal_data_->GetServerProfiles().size()); |
6213 EXPECT_EQ(1U, personal_data_->GetCreditCards().size()); | 6205 EXPECT_EQ(1U, personal_data_->GetCreditCards().size()); |
(...skipping 17 matching lines...) Expand all Loading... |
6231 personal_data_->GetProfilesToSuggest(); | 6223 personal_data_->GetProfilesToSuggest(); |
6232 ASSERT_EQ(1U, profiles.size()); | 6224 ASSERT_EQ(1U, profiles.size()); |
6233 EXPECT_EQ(profiles[0]->guid(), | 6225 EXPECT_EQ(profiles[0]->guid(), |
6234 personal_data_->GetCreditCards()[0]->billing_address_id()); | 6226 personal_data_->GetCreditCards()[0]->billing_address_id()); |
6235 | 6227 |
6236 // Add a new server card that has the same billing address as the old one. | 6228 // Add a new server card that has the same billing address as the old one. |
6237 server_cards.push_back( | 6229 server_cards.push_back( |
6238 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card2")); | 6230 CreditCard(CreditCard::MASKED_SERVER_CARD, "server_card2")); |
6239 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", | 6231 test::SetCreditCardInfo(&server_cards.back(), "John Dillinger", |
6240 "1112" /* Visa */, "01", "2888"); | 6232 "1112" /* Visa */, "01", "2888"); |
6241 server_cards.back().SetTypeForMaskedCard(kVisaCard); | 6233 server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
6242 server_cards.back().set_billing_address_id(kServerAddressId); | 6234 server_cards.back().set_billing_address_id(kServerAddressId); |
6243 test::SetServerCreditCards(autofill_table_, server_cards); | 6235 test::SetServerCreditCards(autofill_table_, server_cards); |
6244 | 6236 |
6245 // Make sure everything is setup correctly. | 6237 // Make sure everything is setup correctly. |
6246 personal_data_->Refresh(); | 6238 personal_data_->Refresh(); |
6247 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 6239 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
6248 .WillOnce(QuitMainMessageLoop()); | 6240 .WillOnce(QuitMainMessageLoop()); |
6249 base::RunLoop().Run(); | 6241 base::RunLoop().Run(); |
6250 EXPECT_EQ(1U, personal_data_->web_profiles().size()); | 6242 EXPECT_EQ(1U, personal_data_->web_profiles().size()); |
6251 EXPECT_EQ(2U, personal_data_->GetCreditCards().size()); | 6243 EXPECT_EQ(2U, personal_data_->GetCreditCards().size()); |
(...skipping 23 matching lines...) Expand all Loading... |
6275 // to the converted address. | 6267 // to the converted address. |
6276 EXPECT_EQ(profiles[0]->guid(), | 6268 EXPECT_EQ(profiles[0]->guid(), |
6277 personal_data_->GetCreditCards()[0]->billing_address_id()); | 6269 personal_data_->GetCreditCards()[0]->billing_address_id()); |
6278 // Make sure that the billing address id of the new server card still refers | 6270 // Make sure that the billing address id of the new server card still refers |
6279 // to the converted address. | 6271 // to the converted address. |
6280 EXPECT_EQ(profiles[0]->guid(), | 6272 EXPECT_EQ(profiles[0]->guid(), |
6281 personal_data_->GetCreditCards()[1]->billing_address_id()); | 6273 personal_data_->GetCreditCards()[1]->billing_address_id()); |
6282 } | 6274 } |
6283 | 6275 |
6284 } // namespace autofill | 6276 } // namespace autofill |
OLD | NEW |