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> |
11 #include <map> | 11 #include <map> |
12 #include <memory> | 12 #include <memory> |
13 #include <string> | 13 #include <string> |
14 #include <utility> | 14 #include <utility> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
18 #include "base/files/scoped_temp_dir.h" | 18 #include "base/files/scoped_temp_dir.h" |
19 #include "base/guid.h" | 19 #include "base/guid.h" |
20 #include "base/i18n/time_formatting.h" | 20 #include "base/i18n/time_formatting.h" |
21 #include "base/memory/ptr_util.h" | 21 #include "base/memory/ptr_util.h" |
22 #include "base/message_loop/message_loop.h" | 22 #include "base/message_loop/message_loop.h" |
23 #include "base/run_loop.h" | 23 #include "base/run_loop.h" |
24 #include "base/strings/utf_string_conversions.h" | 24 #include "base/strings/utf_string_conversions.h" |
25 #include "base/synchronization/waitable_event.h" | 25 #include "base/synchronization/waitable_event.h" |
26 #include "base/test/histogram_tester.h" | 26 #include "base/test/histogram_tester.h" |
27 #include "base/test/scoped_feature_list.h" | |
27 #include "base/test/simple_test_clock.h" | 28 #include "base/test/simple_test_clock.h" |
28 #include "base/threading/thread_task_runner_handle.h" | 29 #include "base/threading/thread_task_runner_handle.h" |
29 #include "base/time/time.h" | 30 #include "base/time/time.h" |
30 #include "build/build_config.h" | 31 #include "build/build_config.h" |
31 #include "components/autofill/core/browser/autofill_experiments.h" | 32 #include "components/autofill/core/browser/autofill_experiments.h" |
32 #include "components/autofill/core/browser/autofill_metrics.h" | 33 #include "components/autofill/core/browser/autofill_metrics.h" |
33 #include "components/autofill/core/browser/autofill_profile.h" | 34 #include "components/autofill/core/browser/autofill_profile.h" |
34 #include "components/autofill/core/browser/autofill_test_utils.h" | 35 #include "components/autofill/core/browser/autofill_test_utils.h" |
35 #include "components/autofill/core/browser/field_types.h" | 36 #include "components/autofill/core/browser/field_types.h" |
36 #include "components/autofill/core/browser/form_structure.h" | 37 #include "components/autofill/core/browser/form_structure.h" |
(...skipping 3590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3627 test::SetCreditCardInfo(&server_cards.back(), "Emmet Dalton", "2110", "12", | 3628 test::SetCreditCardInfo(&server_cards.back(), "Emmet Dalton", "2110", "12", |
3628 "2999", "1"); | 3629 "2999", "1"); |
3629 server_cards.back().SetNetworkForMaskedCard(kVisaCard); | 3630 server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
3630 | 3631 |
3631 test::SetServerCreditCards(autofill_table_, server_cards); | 3632 test::SetServerCreditCards(autofill_table_, server_cards); |
3632 personal_data_->Refresh(); | 3633 personal_data_->Refresh(); |
3633 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3634 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
3634 .WillOnce(QuitMainMessageLoop()); | 3635 .WillOnce(QuitMainMessageLoop()); |
3635 base::RunLoop().Run(); | 3636 base::RunLoop().Run(); |
3636 | 3637 |
3638 bool isBankNameAvailable; | |
3637 std::vector<Suggestion> suggestions = | 3639 std::vector<Suggestion> suggestions = |
3638 personal_data_->GetCreditCardSuggestions(AutofillType(CREDIT_CARD_NUMBER), | 3640 personal_data_->GetCreditCardSuggestions( |
3639 base::ASCIIToUTF16("12345678")); | 3641 AutofillType(CREDIT_CARD_NUMBER), base::ASCIIToUTF16("12345678"), |
3642 isBankNameAvailable); | |
3640 | 3643 |
3641 // There should be no suggestions. | 3644 // There should be no suggestions. |
3642 ASSERT_EQ(0U, suggestions.size()); | 3645 ASSERT_EQ(0U, suggestions.size()); |
3643 } | 3646 } |
3644 | 3647 |
3645 // Test that local credit cards are ordered as expected. | 3648 // Test that local credit cards are ordered as expected. |
3646 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_LocalCardsRanking) { | 3649 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_LocalCardsRanking) { |
3647 SetupReferenceLocalCreditCards(); | 3650 SetupReferenceLocalCreditCards(); |
3648 | 3651 |
3652 bool isBankNameAvailable; | |
3649 // Sublabel is card number when filling name (exact format depends on | 3653 // Sublabel is card number when filling name (exact format depends on |
3650 // the platform, but the last 4 digits should appear). | 3654 // the platform, but the last 4 digits should appear). |
3651 std::vector<Suggestion> suggestions = | 3655 std::vector<Suggestion> suggestions = |
3652 personal_data_->GetCreditCardSuggestions( | 3656 personal_data_->GetCreditCardSuggestions( |
3653 AutofillType(CREDIT_CARD_NAME_FULL), | 3657 AutofillType(CREDIT_CARD_NAME_FULL), |
3654 /* field_contents= */ base::string16()); | 3658 /* field_contents= */ base::string16(), |
3659 isBankNameAvailable); | |
3655 ASSERT_EQ(3U, suggestions.size()); | 3660 ASSERT_EQ(3U, suggestions.size()); |
3656 | 3661 |
3657 // Ordered as expected. | 3662 // Ordered as expected. |
3658 EXPECT_EQ(base::ASCIIToUTF16("John Dillinger"), suggestions[0].value); | 3663 EXPECT_EQ(base::ASCIIToUTF16("John Dillinger"), suggestions[0].value); |
3659 EXPECT_TRUE(suggestions[0].label.find(base::ASCIIToUTF16("9012")) != | 3664 EXPECT_TRUE(suggestions[0].label.find(base::ASCIIToUTF16("9012")) != |
3660 base::string16::npos); | 3665 base::string16::npos); |
3661 EXPECT_EQ(base::ASCIIToUTF16("Clyde Barrow"), suggestions[1].value); | 3666 EXPECT_EQ(base::ASCIIToUTF16("Clyde Barrow"), suggestions[1].value); |
3662 EXPECT_TRUE(suggestions[1].label.find(base::ASCIIToUTF16("8555")) != | 3667 EXPECT_TRUE(suggestions[1].label.find(base::ASCIIToUTF16("8555")) != |
3663 base::string16::npos); | 3668 base::string16::npos); |
3664 EXPECT_EQ(base::ASCIIToUTF16("Bonnie Parker"), suggestions[2].value); | 3669 EXPECT_EQ(base::ASCIIToUTF16("Bonnie Parker"), suggestions[2].value); |
(...skipping 23 matching lines...) Expand all Loading... | |
3688 server_cards.back().set_use_count(6); | 3693 server_cards.back().set_use_count(6); |
3689 server_cards.back().set_use_date(AutofillClock::Now() - | 3694 server_cards.back().set_use_date(AutofillClock::Now() - |
3690 base::TimeDelta::FromDays(1)); | 3695 base::TimeDelta::FromDays(1)); |
3691 | 3696 |
3692 test::SetServerCreditCards(autofill_table_, server_cards); | 3697 test::SetServerCreditCards(autofill_table_, server_cards); |
3693 personal_data_->Refresh(); | 3698 personal_data_->Refresh(); |
3694 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3699 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
3695 .WillOnce(QuitMainMessageLoop()); | 3700 .WillOnce(QuitMainMessageLoop()); |
3696 base::RunLoop().Run(); | 3701 base::RunLoop().Run(); |
3697 | 3702 |
3703 bool isBankNameAvailable; | |
3698 std::vector<Suggestion> suggestions = | 3704 std::vector<Suggestion> suggestions = |
3699 personal_data_->GetCreditCardSuggestions( | 3705 personal_data_->GetCreditCardSuggestions( |
3700 AutofillType(CREDIT_CARD_NAME_FULL), | 3706 AutofillType(CREDIT_CARD_NAME_FULL), |
3701 /* field_contents= */ base::string16()); | 3707 /* field_contents= */ base::string16(), |
3708 isBankNameAvailable); | |
3702 ASSERT_EQ(5U, suggestions.size()); | 3709 ASSERT_EQ(5U, suggestions.size()); |
3703 | 3710 |
3704 // All cards should be ordered as expected. | 3711 // All cards should be ordered as expected. |
3705 EXPECT_EQ(base::ASCIIToUTF16("Jesse James"), suggestions[0].value); | 3712 EXPECT_EQ(base::ASCIIToUTF16("Jesse James"), suggestions[0].value); |
3706 EXPECT_EQ(base::ASCIIToUTF16("John Dillinger"), suggestions[1].value); | 3713 EXPECT_EQ(base::ASCIIToUTF16("John Dillinger"), suggestions[1].value); |
3707 EXPECT_EQ(base::ASCIIToUTF16("Clyde Barrow"), suggestions[2].value); | 3714 EXPECT_EQ(base::ASCIIToUTF16("Clyde Barrow"), suggestions[2].value); |
3708 EXPECT_EQ(base::ASCIIToUTF16("Emmet Dalton"), suggestions[3].value); | 3715 EXPECT_EQ(base::ASCIIToUTF16("Emmet Dalton"), suggestions[3].value); |
3709 EXPECT_EQ(base::ASCIIToUTF16("Bonnie Parker"), suggestions[4].value); | 3716 EXPECT_EQ(base::ASCIIToUTF16("Bonnie Parker"), suggestions[4].value); |
3710 } | 3717 } |
3711 | 3718 |
(...skipping 29 matching lines...) Expand all Loading... | |
3741 test::SetCreditCardInfo(&credit_card2, "John Dillinger", | 3748 test::SetCreditCardInfo(&credit_card2, "John Dillinger", |
3742 "423456789012" /* Visa */, "01", "1998", "1"); | 3749 "423456789012" /* Visa */, "01", "1998", "1"); |
3743 personal_data_->AddCreditCard(credit_card2); | 3750 personal_data_->AddCreditCard(credit_card2); |
3744 | 3751 |
3745 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3752 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
3746 .WillOnce(QuitMainMessageLoop()); | 3753 .WillOnce(QuitMainMessageLoop()); |
3747 base::RunLoop().Run(); | 3754 base::RunLoop().Run(); |
3748 | 3755 |
3749 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); | 3756 ASSERT_EQ(3U, personal_data_->GetCreditCards().size()); |
3750 | 3757 |
3758 bool isBankNameAvailable; | |
3751 std::vector<Suggestion> suggestions = | 3759 std::vector<Suggestion> suggestions = |
3752 personal_data_->GetCreditCardSuggestions( | 3760 personal_data_->GetCreditCardSuggestions( |
3753 AutofillType(CREDIT_CARD_NAME_FULL), | 3761 AutofillType(CREDIT_CARD_NAME_FULL), |
3754 /* field_contents= */ base::string16()); | 3762 /* field_contents= */ base::string16(), |
3763 isBankNameAvailable); | |
3755 ASSERT_EQ(3U, suggestions.size()); | 3764 ASSERT_EQ(3U, suggestions.size()); |
3756 | 3765 |
3757 // The never used non expired card should be suggested first. | 3766 // The never used non expired card should be suggested first. |
3758 EXPECT_EQ(base::ASCIIToUTF16("Bonnie Parker"), suggestions[0].value); | 3767 EXPECT_EQ(base::ASCIIToUTF16("Bonnie Parker"), suggestions[0].value); |
3759 | 3768 |
3760 // The expired cards should be sorted by frecency | 3769 // The expired cards should be sorted by frecency |
3761 EXPECT_EQ(base::ASCIIToUTF16("Clyde Barrow"), suggestions[1].value); | 3770 EXPECT_EQ(base::ASCIIToUTF16("Clyde Barrow"), suggestions[1].value); |
3762 EXPECT_EQ(base::ASCIIToUTF16("John Dillinger"), suggestions[2].value); | 3771 EXPECT_EQ(base::ASCIIToUTF16("John Dillinger"), suggestions[2].value); |
3763 } | 3772 } |
3764 | 3773 |
(...skipping 23 matching lines...) Expand all Loading... | |
3788 personal_data_->AddCreditCard(credit_card1); | 3797 personal_data_->AddCreditCard(credit_card1); |
3789 | 3798 |
3790 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3799 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
3791 .WillOnce(QuitMainMessageLoop()); | 3800 .WillOnce(QuitMainMessageLoop()); |
3792 base::RunLoop().Run(); | 3801 base::RunLoop().Run(); |
3793 | 3802 |
3794 ASSERT_EQ(2U, personal_data_->GetCreditCards().size()); | 3803 ASSERT_EQ(2U, personal_data_->GetCreditCards().size()); |
3795 | 3804 |
3796 // Sublabel is expiration date when filling card number. The second card | 3805 // Sublabel is expiration date when filling card number. The second card |
3797 // doesn't have a number so it should not be included in the suggestions. | 3806 // doesn't have a number so it should not be included in the suggestions. |
3807 bool isBankNameAvailable; | |
3798 std::vector<Suggestion> suggestions = | 3808 std::vector<Suggestion> suggestions = |
3799 personal_data_->GetCreditCardSuggestions( | 3809 personal_data_->GetCreditCardSuggestions( |
3800 AutofillType(CREDIT_CARD_NUMBER), | 3810 AutofillType(CREDIT_CARD_NUMBER), |
3801 /* field_contents= */ base::string16()); | 3811 /* field_contents= */ base::string16(), |
3812 isBankNameAvailable); | |
3802 ASSERT_EQ(1U, suggestions.size()); | 3813 ASSERT_EQ(1U, suggestions.size()); |
3803 EXPECT_EQ( | 3814 EXPECT_EQ( |
3804 base::UTF8ToUTF16(std::string("Amex") + kUTF8MidlineEllipsis + "8555"), | 3815 base::UTF8ToUTF16(std::string("Amex") + kUTF8MidlineEllipsis + "8555"), |
3805 suggestions[0].value); | 3816 suggestions[0].value); |
3806 EXPECT_EQ(base::ASCIIToUTF16("04/99"), suggestions[0].label); | 3817 EXPECT_EQ(base::ASCIIToUTF16("04/99"), suggestions[0].label); |
3807 } | 3818 } |
3808 | 3819 |
3809 // Tests the suggestions of duplicate local and server credit cards. | 3820 // Tests the suggestions of duplicate local and server credit cards. |
3810 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_ServerDuplicates) { | 3821 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_ServerDuplicates) { |
3811 EnableWalletCardImport(); | 3822 EnableWalletCardImport(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3845 server_cards.back().set_use_count(1); | 3856 server_cards.back().set_use_count(1); |
3846 server_cards.back().set_use_date(AutofillClock::Now() - | 3857 server_cards.back().set_use_date(AutofillClock::Now() - |
3847 base::TimeDelta::FromDays(15)); | 3858 base::TimeDelta::FromDays(15)); |
3848 | 3859 |
3849 test::SetServerCreditCards(autofill_table_, server_cards); | 3860 test::SetServerCreditCards(autofill_table_, server_cards); |
3850 personal_data_->Refresh(); | 3861 personal_data_->Refresh(); |
3851 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3862 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
3852 .WillOnce(QuitMainMessageLoop()); | 3863 .WillOnce(QuitMainMessageLoop()); |
3853 base::RunLoop().Run(); | 3864 base::RunLoop().Run(); |
3854 | 3865 |
3866 bool isBankNameAvailable; | |
3855 std::vector<Suggestion> suggestions = | 3867 std::vector<Suggestion> suggestions = |
3856 personal_data_->GetCreditCardSuggestions( | 3868 personal_data_->GetCreditCardSuggestions( |
3857 AutofillType(CREDIT_CARD_NAME_FULL), | 3869 AutofillType(CREDIT_CARD_NAME_FULL), |
3858 /* field_contents= */ base::string16()); | 3870 /* field_contents= */ base::string16(), |
3871 isBankNameAvailable); | |
3859 ASSERT_EQ(4U, suggestions.size()); | 3872 ASSERT_EQ(4U, suggestions.size()); |
3860 EXPECT_EQ(base::ASCIIToUTF16("John Dillinger"), suggestions[0].value); | 3873 EXPECT_EQ(base::ASCIIToUTF16("John Dillinger"), suggestions[0].value); |
3861 EXPECT_EQ(base::ASCIIToUTF16("Clyde Barrow"), suggestions[1].value); | 3874 EXPECT_EQ(base::ASCIIToUTF16("Clyde Barrow"), suggestions[1].value); |
3862 EXPECT_EQ(base::ASCIIToUTF16("Bonnie Parker"), suggestions[2].value); | 3875 EXPECT_EQ(base::ASCIIToUTF16("Bonnie Parker"), suggestions[2].value); |
3863 EXPECT_EQ(base::ASCIIToUTF16("Bonnie Parker"), suggestions[3].value); | 3876 EXPECT_EQ(base::ASCIIToUTF16("Bonnie Parker"), suggestions[3].value); |
3864 | 3877 |
3865 suggestions = personal_data_->GetCreditCardSuggestions( | 3878 suggestions = personal_data_->GetCreditCardSuggestions( |
3866 AutofillType(CREDIT_CARD_NUMBER), /* field_contents= */ base::string16()); | 3879 AutofillType(CREDIT_CARD_NUMBER), /* field_contents= */ base::string16(), |
3880 isBankNameAvailable); | |
3867 ASSERT_EQ(4U, suggestions.size()); | 3881 ASSERT_EQ(4U, suggestions.size()); |
3868 EXPECT_EQ( | 3882 EXPECT_EQ( |
3869 base::UTF8ToUTF16(std::string("Visa") + kUTF8MidlineEllipsis + "9012"), | 3883 base::UTF8ToUTF16(std::string("Visa") + kUTF8MidlineEllipsis + "9012"), |
3870 suggestions[0].value); | 3884 suggestions[0].value); |
3871 EXPECT_EQ( | 3885 EXPECT_EQ( |
3872 base::UTF8ToUTF16(std::string("Amex") + kUTF8MidlineEllipsis + "8555"), | 3886 base::UTF8ToUTF16(std::string("Amex") + kUTF8MidlineEllipsis + "8555"), |
3873 suggestions[1].value); | 3887 suggestions[1].value); |
3874 EXPECT_EQ(base::UTF8ToUTF16(std::string("Mastercard") + kUTF8MidlineEllipsis + | 3888 EXPECT_EQ(base::UTF8ToUTF16(std::string("Mastercard") + kUTF8MidlineEllipsis + |
3875 "2109"), | 3889 "2109"), |
3876 suggestions[2].value); | 3890 suggestions[2].value); |
(...skipping 16 matching lines...) Expand all Loading... | |
3893 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", | 3907 test::SetCreditCardInfo(&server_cards.back(), "Clyde Barrow", |
3894 "347666888555" /* American Express */, "04", "2999", | 3908 "347666888555" /* American Express */, "04", "2999", |
3895 "1"); | 3909 "1"); |
3896 | 3910 |
3897 test::SetServerCreditCards(autofill_table_, server_cards); | 3911 test::SetServerCreditCards(autofill_table_, server_cards); |
3898 personal_data_->Refresh(); | 3912 personal_data_->Refresh(); |
3899 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3913 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
3900 .WillOnce(QuitMainMessageLoop()); | 3914 .WillOnce(QuitMainMessageLoop()); |
3901 base::RunLoop().Run(); | 3915 base::RunLoop().Run(); |
3902 | 3916 |
3917 bool isBankNameAvailable; | |
3903 std::vector<Suggestion> suggestions = | 3918 std::vector<Suggestion> suggestions = |
3904 personal_data_->GetCreditCardSuggestions( | 3919 personal_data_->GetCreditCardSuggestions( |
3905 AutofillType(CREDIT_CARD_NAME_FULL), | 3920 AutofillType(CREDIT_CARD_NAME_FULL), |
3906 /* field_contents= */ base::string16()); | 3921 /* field_contents= */ base::string16(), |
3922 isBankNameAvailable); | |
3907 ASSERT_EQ(3U, suggestions.size()); | 3923 ASSERT_EQ(3U, suggestions.size()); |
3908 | 3924 |
3909 // Add a second dupe local card to make sure a full server card can be a dupe | 3925 // Add a second dupe local card to make sure a full server card can be a dupe |
3910 // of more than one local card. | 3926 // of more than one local card. |
3911 CreditCard credit_card3("4141084B-72D7-4B73-90CF-3D6AC154673B", | 3927 CreditCard credit_card3("4141084B-72D7-4B73-90CF-3D6AC154673B", |
3912 "https://www.example.com"); | 3928 "https://www.example.com"); |
3913 test::SetCreditCardInfo(&credit_card3, "Clyde Barrow", "", "04", "", ""); | 3929 test::SetCreditCardInfo(&credit_card3, "Clyde Barrow", "", "04", "", ""); |
3914 personal_data_->AddCreditCard(credit_card3); | 3930 personal_data_->AddCreditCard(credit_card3); |
3915 | 3931 |
3916 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3932 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
3917 .WillOnce(QuitMainMessageLoop()); | 3933 .WillOnce(QuitMainMessageLoop()); |
3918 base::RunLoop().Run(); | 3934 base::RunLoop().Run(); |
3919 | 3935 |
3920 suggestions = personal_data_->GetCreditCardSuggestions( | 3936 suggestions = personal_data_->GetCreditCardSuggestions( |
3921 AutofillType(CREDIT_CARD_NAME_FULL), | 3937 AutofillType(CREDIT_CARD_NAME_FULL), |
3922 /* field_contents= */ base::string16()); | 3938 /* field_contents= */ base::string16(), |
3939 isBankNameAvailable); | |
3923 ASSERT_EQ(3U, suggestions.size()); | 3940 ASSERT_EQ(3U, suggestions.size()); |
3924 } | 3941 } |
3925 | 3942 |
3943 // Tests that server cards have bank name when feature flag on. | |
3944 TEST_F(PersonalDataManagerTest, | |
3945 GetCreditCardSuggestions_ShowBankNameOfServerCards) { | |
3946 // Turn on feature flag. | |
3947 base::test::ScopedFeatureList scoped_feature_list_; | |
3948 scoped_feature_list_.InitAndEnableFeature(kAutofillCreditCardBankNameDisplay); | |
3949 | |
3950 EnableWalletCardImport(); | |
3951 SetupReferenceLocalCreditCards(); | |
3952 | |
3953 // Add some server cards. | |
3954 std::vector<CreditCard> server_cards; | |
3955 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b459")); | |
3956 test::SetCreditCardInfo(&server_cards.back(), "Emmet Dalton", "2110", "12", | |
3957 "2999", "1"); | |
3958 server_cards.back().set_use_count(2); | |
3959 server_cards.back().set_use_date(AutofillClock::Now() - | |
3960 base::TimeDelta::FromDays(1)); | |
3961 server_cards.back().SetNetworkForMaskedCard(kVisaCard); | |
3962 server_cards.back().set_bank_name("Chase"); | |
3963 | |
3964 test::SetServerCreditCards(autofill_table_, server_cards); | |
3965 personal_data_->Refresh(); | |
3966 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | |
3967 .WillOnce(QuitMainMessageLoop()); | |
3968 base::RunLoop().Run(); | |
3969 | |
3970 bool isBankNameAvailable; | |
3971 std::vector<Suggestion> suggestions = | |
3972 personal_data_->GetCreditCardSuggestions( | |
3973 AutofillType(CREDIT_CARD_NUMBER), | |
3974 /* field_contents= */ base::string16(), | |
3975 isBankNameAvailable); | |
3976 EXPECT_TRUE(isBankNameAvailable); | |
3977 ASSERT_EQ(4U, suggestions.size()); | |
3978 | |
3979 // All cards should be ordered as expected. | |
3980 EXPECT_EQ( | |
3981 base::UTF8ToUTF16(std::string("Visa") + kUTF8MidlineEllipsis + "9012"), | |
3982 suggestions[0].value); | |
3983 EXPECT_EQ( | |
3984 base::UTF8ToUTF16(std::string("Amex") + kUTF8MidlineEllipsis + "8555"), | |
3985 suggestions[1].value); | |
3986 EXPECT_EQ( | |
3987 base::UTF8ToUTF16(std::string("Chase") + kUTF8MidlineEllipsis + "2110"), | |
3988 suggestions[2].value); | |
3989 EXPECT_EQ(base::UTF8ToUTF16(std::string("Mastercard") + kUTF8MidlineEllipsis + | |
3990 "2109"), | |
3991 suggestions[3].value); | |
3992 } | |
3993 | |
sebsg
2017/06/12 21:17:00
Can you add a test where the feature is enabled bu
Shanfeng
2017/06/12 23:34:58
Done.
| |
3994 // Tests that isBankNameAvailable is true even feature flag off. | |
3995 TEST_F(PersonalDataManagerTest, | |
3996 GetCreditCardSuggestions_IsBankNameAvailableTrueEvenIfFeatureOff) { | |
3997 EnableWalletCardImport(); | |
3998 SetupReferenceLocalCreditCards(); | |
3999 | |
4000 // Add some server cards. | |
4001 std::vector<CreditCard> server_cards; | |
4002 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b459")); | |
4003 test::SetCreditCardInfo(&server_cards.back(), "Emmet Dalton", "2110", "12", | |
4004 "2999", "1"); | |
4005 server_cards.back().set_use_count(2); | |
4006 server_cards.back().set_use_date(AutofillClock::Now() - | |
4007 base::TimeDelta::FromDays(1)); | |
4008 server_cards.back().SetNetworkForMaskedCard(kVisaCard); | |
4009 server_cards.back().set_bank_name("Chase"); | |
4010 | |
4011 test::SetServerCreditCards(autofill_table_, server_cards); | |
4012 personal_data_->Refresh(); | |
4013 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | |
4014 .WillOnce(QuitMainMessageLoop()); | |
4015 base::RunLoop().Run(); | |
4016 | |
4017 bool isBankNameAvailable; | |
4018 std::vector<Suggestion> suggestions = | |
4019 personal_data_->GetCreditCardSuggestions( | |
4020 AutofillType(CREDIT_CARD_NUMBER), | |
4021 /* field_contents= */ base::string16(), | |
4022 isBankNameAvailable); | |
4023 ASSERT_EQ(4U, suggestions.size()); | |
4024 } | |
4025 | |
3926 // Tests that only the full server card is kept when deduping with a local | 4026 // Tests that only the full server card is kept when deduping with a local |
3927 // duplicate of it. | 4027 // duplicate of it. |
3928 TEST_F(PersonalDataManagerTest, | 4028 TEST_F(PersonalDataManagerTest, |
3929 DedupeCreditCardToSuggest_FullServerShadowsLocal) { | 4029 DedupeCreditCardToSuggest_FullServerShadowsLocal) { |
3930 std::list<CreditCard*> credit_cards; | 4030 std::list<CreditCard*> credit_cards; |
3931 | 4031 |
3932 // Create 3 different local credit cards. | 4032 // Create 3 different local credit cards. |
3933 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15", | 4033 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15", |
3934 "https://www.example.com"); | 4034 "https://www.example.com"); |
3935 test::SetCreditCardInfo(&local_card, "Homer Simpson", | 4035 test::SetCreditCardInfo(&local_card, "Homer Simpson", |
(...skipping 2566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6502 EXPECT_EQ("", card->billing_address_id()); | 6602 EXPECT_EQ("", card->billing_address_id()); |
6503 } else { | 6603 } else { |
6504 // The billing address of local_card1 and server_card1 should still refer | 6604 // The billing address of local_card1 and server_card1 should still refer |
6505 // to profile1. | 6605 // to profile1. |
6506 EXPECT_EQ(profile1.guid(), card->billing_address_id()); | 6606 EXPECT_EQ(profile1.guid(), card->billing_address_id()); |
6507 } | 6607 } |
6508 } | 6608 } |
6509 } | 6609 } |
6510 | 6610 |
6511 } // namespace autofill | 6611 } // namespace autofill |
OLD | NEW |