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 3591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 |
3637 std::vector<Suggestion> suggestions = | 3638 std::vector<Suggestion> suggestions = |
3638 personal_data_->GetCreditCardSuggestions(AutofillType(CREDIT_CARD_NUMBER), | 3639 personal_data_->GetCreditCardSuggestions( |
3639 base::ASCIIToUTF16("12345678")); | 3640 AutofillType(CREDIT_CARD_NUMBER), base::ASCIIToUTF16("12345678")); |
3640 | 3641 |
3641 // There should be no suggestions. | 3642 // There should be no suggestions. |
3642 ASSERT_EQ(0U, suggestions.size()); | 3643 ASSERT_EQ(0U, suggestions.size()); |
3643 } | 3644 } |
3644 | 3645 |
3645 // Test that local credit cards are ordered as expected. | 3646 // Test that local credit cards are ordered as expected. |
3646 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_LocalCardsRanking) { | 3647 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_LocalCardsRanking) { |
3647 SetupReferenceLocalCreditCards(); | 3648 SetupReferenceLocalCreditCards(); |
3648 | 3649 |
3649 // Sublabel is card number when filling name (exact format depends on | 3650 // Sublabel is card number when filling name (exact format depends on |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3916 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3917 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
3917 .WillOnce(QuitMainMessageLoop()); | 3918 .WillOnce(QuitMainMessageLoop()); |
3918 base::RunLoop().Run(); | 3919 base::RunLoop().Run(); |
3919 | 3920 |
3920 suggestions = personal_data_->GetCreditCardSuggestions( | 3921 suggestions = personal_data_->GetCreditCardSuggestions( |
3921 AutofillType(CREDIT_CARD_NAME_FULL), | 3922 AutofillType(CREDIT_CARD_NAME_FULL), |
3922 /* field_contents= */ base::string16()); | 3923 /* field_contents= */ base::string16()); |
3923 ASSERT_EQ(3U, suggestions.size()); | 3924 ASSERT_EQ(3U, suggestions.size()); |
3924 } | 3925 } |
3925 | 3926 |
3927 // Tests that server cards have bank name when feature flag on. | |
3928 TEST_F(PersonalDataManagerTest, | |
3929 GetCreditCardSuggestions_ShowBankNameOfServerCards) { | |
3930 // Turn on feature flag. | |
3931 base::test::ScopedFeatureList scoped_feature_list_; | |
3932 scoped_feature_list_.InitAndEnableFeature(kAutofillCreditCardBankNameDisplay); | |
3933 | |
3934 EnableWalletCardImport(); | |
3935 SetupReferenceLocalCreditCards(); | |
3936 | |
3937 // Add some server cards. | |
3938 std::vector<CreditCard> server_cards; | |
3939 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b459")); | |
3940 test::SetCreditCardInfo(&server_cards.back(), "Emmet Dalton", "2110", "12", | |
3941 "2999", "1"); | |
3942 server_cards.back().set_use_count(2); | |
3943 server_cards.back().set_use_date(AutofillClock::Now() - | |
3944 base::TimeDelta::FromDays(1)); | |
3945 server_cards.back().SetNetworkForMaskedCard(kVisaCard); | |
3946 server_cards.back().set_bank_name("Chase"); | |
3947 | |
3948 test::SetServerCreditCards(autofill_table_, server_cards); | |
3949 personal_data_->Refresh(); | |
3950 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | |
3951 .WillOnce(QuitMainMessageLoop()); | |
3952 base::RunLoop().Run(); | |
3953 | |
3954 std::vector<Suggestion> suggestions = | |
3955 personal_data_->GetCreditCardSuggestions( | |
3956 AutofillType(CREDIT_CARD_NUMBER), | |
3957 /* field_contents= */ base::string16()); | |
3958 ASSERT_EQ(4U, suggestions.size()); | |
3959 | |
3960 // All cards should be ordered as expected. | |
sebsg
2017/06/13 13:36:04
Can you put emphasis on the bank name? Like the fi
Shanfeng
2017/06/13 20:39:58
Done.
| |
3961 EXPECT_EQ( | |
3962 base::UTF8ToUTF16(std::string("Visa") + kUTF8MidlineEllipsis + "9012"), | |
3963 suggestions[0].value); | |
3964 EXPECT_EQ( | |
3965 base::UTF8ToUTF16(std::string("Amex") + kUTF8MidlineEllipsis + "8555"), | |
3966 suggestions[1].value); | |
3967 EXPECT_EQ( | |
3968 base::UTF8ToUTF16(std::string("Chase") + kUTF8MidlineEllipsis + "2110"), | |
3969 suggestions[2].value); | |
3970 EXPECT_EQ(base::UTF8ToUTF16(std::string("Mastercard") + kUTF8MidlineEllipsis + | |
3971 "2109"), | |
3972 suggestions[3].value); | |
3973 } | |
3974 | |
3975 // Tests that will show network if no bank name, | |
3976 TEST_F(PersonalDataManagerTest, | |
3977 GetCreditCardSuggestions_ShowNetworkIfNoBankName) { | |
3978 // Turn on feature flag. | |
3979 base::test::ScopedFeatureList scoped_feature_list_; | |
3980 scoped_feature_list_.InitAndEnableFeature(kAutofillCreditCardBankNameDisplay); | |
3981 | |
3982 EnableWalletCardImport(); | |
3983 SetupReferenceLocalCreditCards(); | |
3984 | |
3985 // Add some server cards. | |
3986 std::vector<CreditCard> server_cards; | |
3987 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b459")); | |
3988 test::SetCreditCardInfo(&server_cards.back(), "Emmet Dalton", "2110", "12", | |
3989 "2999", "1"); | |
3990 server_cards.back().set_use_count(2); | |
3991 server_cards.back().set_use_date(AutofillClock::Now() - | |
3992 base::TimeDelta::FromDays(1)); | |
3993 server_cards.back().SetNetworkForMaskedCard(kVisaCard); | |
3994 | |
3995 test::SetServerCreditCards(autofill_table_, server_cards); | |
3996 personal_data_->Refresh(); | |
3997 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | |
3998 .WillOnce(QuitMainMessageLoop()); | |
3999 base::RunLoop().Run(); | |
4000 | |
4001 std::vector<Suggestion> suggestions = | |
4002 personal_data_->GetCreditCardSuggestions( | |
4003 AutofillType(CREDIT_CARD_NUMBER), | |
4004 /* field_contents= */ base::string16()); | |
4005 ASSERT_EQ(4U, suggestions.size()); | |
4006 | |
4007 // All cards should be ordered as expected. | |
4008 EXPECT_EQ( | |
4009 base::UTF8ToUTF16(std::string("Visa") + kUTF8MidlineEllipsis + "9012"), | |
sebsg
2017/06/13 13:36:04
The test above already tests this right? If you ch
Shanfeng
2017/06/13 20:39:58
Done.
| |
4010 suggestions[0].value); | |
4011 EXPECT_EQ( | |
4012 base::UTF8ToUTF16(std::string("Amex") + kUTF8MidlineEllipsis + "8555"), | |
4013 suggestions[1].value); | |
4014 EXPECT_EQ( | |
4015 base::UTF8ToUTF16(std::string("Visa") + kUTF8MidlineEllipsis + "2110"), | |
4016 suggestions[2].value); | |
4017 EXPECT_EQ(base::UTF8ToUTF16(std::string("Mastercard") + kUTF8MidlineEllipsis + | |
4018 "2109"), | |
4019 suggestions[3].value); | |
4020 } | |
4021 | |
3926 // Tests that only the full server card is kept when deduping with a local | 4022 // Tests that only the full server card is kept when deduping with a local |
3927 // duplicate of it. | 4023 // duplicate of it. |
3928 TEST_F(PersonalDataManagerTest, | 4024 TEST_F(PersonalDataManagerTest, |
3929 DedupeCreditCardToSuggest_FullServerShadowsLocal) { | 4025 DedupeCreditCardToSuggest_FullServerShadowsLocal) { |
3930 std::list<CreditCard*> credit_cards; | 4026 std::list<CreditCard*> credit_cards; |
3931 | 4027 |
3932 // Create 3 different local credit cards. | 4028 // Create 3 different local credit cards. |
3933 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15", | 4029 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15", |
3934 "https://www.example.com"); | 4030 "https://www.example.com"); |
3935 test::SetCreditCardInfo(&local_card, "Homer Simpson", | 4031 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()); | 6598 EXPECT_EQ("", card->billing_address_id()); |
6503 } else { | 6599 } else { |
6504 // The billing address of local_card1 and server_card1 should still refer | 6600 // The billing address of local_card1 and server_card1 should still refer |
6505 // to profile1. | 6601 // to profile1. |
6506 EXPECT_EQ(profile1.guid(), card->billing_address_id()); | 6602 EXPECT_EQ(profile1.guid(), card->billing_address_id()); |
6507 } | 6603 } |
6508 } | 6604 } |
6509 } | 6605 } |
6510 | 6606 |
6511 } // namespace autofill | 6607 } // namespace autofill |
OLD | NEW |