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" | |
28 #include "base/test/simple_test_clock.h" | 27 #include "base/test/simple_test_clock.h" |
29 #include "base/threading/thread_task_runner_handle.h" | 28 #include "base/threading/thread_task_runner_handle.h" |
30 #include "base/time/time.h" | 29 #include "base/time/time.h" |
31 #include "build/build_config.h" | 30 #include "build/build_config.h" |
32 #include "components/autofill/core/browser/autofill_experiments.h" | 31 #include "components/autofill/core/browser/autofill_experiments.h" |
33 #include "components/autofill/core/browser/autofill_metrics.h" | 32 #include "components/autofill/core/browser/autofill_metrics.h" |
34 #include "components/autofill/core/browser/autofill_profile.h" | 33 #include "components/autofill/core/browser/autofill_profile.h" |
35 #include "components/autofill/core/browser/autofill_test_utils.h" | 34 #include "components/autofill/core/browser/autofill_test_utils.h" |
36 #include "components/autofill/core/browser/field_types.h" | 35 #include "components/autofill/core/browser/field_types.h" |
37 #include "components/autofill/core/browser/form_structure.h" | 36 #include "components/autofill/core/browser/form_structure.h" |
(...skipping 3591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3629 "2999", "1"); | 3628 "2999", "1"); |
3630 server_cards.back().SetNetworkForMaskedCard(kVisaCard); | 3629 server_cards.back().SetNetworkForMaskedCard(kVisaCard); |
3631 | 3630 |
3632 test::SetServerCreditCards(autofill_table_, server_cards); | 3631 test::SetServerCreditCards(autofill_table_, server_cards); |
3633 personal_data_->Refresh(); | 3632 personal_data_->Refresh(); |
3634 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3633 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
3635 .WillOnce(QuitMainMessageLoop()); | 3634 .WillOnce(QuitMainMessageLoop()); |
3636 base::RunLoop().Run(); | 3635 base::RunLoop().Run(); |
3637 | 3636 |
3638 std::vector<Suggestion> suggestions = | 3637 std::vector<Suggestion> suggestions = |
3639 personal_data_->GetCreditCardSuggestions( | 3638 personal_data_->GetCreditCardSuggestions(AutofillType(CREDIT_CARD_NUMBER), |
3640 AutofillType(CREDIT_CARD_NUMBER), base::ASCIIToUTF16("12345678")); | 3639 base::ASCIIToUTF16("12345678")); |
3641 | 3640 |
3642 // There should be no suggestions. | 3641 // There should be no suggestions. |
3643 ASSERT_EQ(0U, suggestions.size()); | 3642 ASSERT_EQ(0U, suggestions.size()); |
3644 } | 3643 } |
3645 | 3644 |
3646 // Test that local credit cards are ordered as expected. | 3645 // Test that local credit cards are ordered as expected. |
3647 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_LocalCardsRanking) { | 3646 TEST_F(PersonalDataManagerTest, GetCreditCardSuggestions_LocalCardsRanking) { |
3648 SetupReferenceLocalCreditCards(); | 3647 SetupReferenceLocalCreditCards(); |
3649 | 3648 |
3650 // Sublabel is card number when filling name (exact format depends on | 3649 // Sublabel is card number when filling name (exact format depends on |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3917 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3916 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
3918 .WillOnce(QuitMainMessageLoop()); | 3917 .WillOnce(QuitMainMessageLoop()); |
3919 base::RunLoop().Run(); | 3918 base::RunLoop().Run(); |
3920 | 3919 |
3921 suggestions = personal_data_->GetCreditCardSuggestions( | 3920 suggestions = personal_data_->GetCreditCardSuggestions( |
3922 AutofillType(CREDIT_CARD_NAME_FULL), | 3921 AutofillType(CREDIT_CARD_NAME_FULL), |
3923 /* field_contents= */ base::string16()); | 3922 /* field_contents= */ base::string16()); |
3924 ASSERT_EQ(3U, suggestions.size()); | 3923 ASSERT_EQ(3U, suggestions.size()); |
3925 } | 3924 } |
3926 | 3925 |
3927 // Tests that server cards will shown bank name when bank name available and | |
3928 // feature flag on. | |
3929 TEST_F(PersonalDataManagerTest, | |
3930 GetCreditCardSuggestions_ShowBankNameOfServerCards) { | |
3931 // Turn on feature flag. | |
3932 base::test::ScopedFeatureList scoped_feature_list_; | |
3933 scoped_feature_list_.InitAndEnableFeature(kAutofillCreditCardBankNameDisplay); | |
3934 | |
3935 EnableWalletCardImport(); | |
3936 | |
3937 // Add a local card. | |
3938 CreditCard credit_card0("287151C8-6AB1-487C-9095-28E80BE5DA15", | |
3939 "https://www.example.com"); | |
3940 test::SetCreditCardInfo(&credit_card0, "Clyde Barrow", | |
3941 "347666888555" /* American Express */, "04", "2999", | |
3942 "1"); | |
3943 credit_card0.set_use_count(3); | |
3944 credit_card0.set_use_date(AutofillClock::Now() - | |
3945 base::TimeDelta::FromDays(1)); | |
3946 personal_data_->AddCreditCard(credit_card0); | |
3947 | |
3948 std::vector<CreditCard> server_cards; | |
3949 | |
3950 // Add a server card without bank name. | |
3951 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b459")); | |
3952 test::SetCreditCardInfo(&server_cards.back(), "Emmet Dalton", "2110", "12", | |
3953 "2999", "1"); | |
3954 server_cards.back().set_use_count(2); | |
3955 server_cards.back().set_use_date(AutofillClock::Now() - | |
3956 base::TimeDelta::FromDays(1)); | |
3957 server_cards.back().SetNetworkForMaskedCard(kVisaCard); | |
3958 | |
3959 // Add a server card with bank name. | |
3960 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b460")); | |
3961 test::SetCreditCardInfo(&server_cards.back(), "Emmet Dalton", "2111", "12", | |
3962 "2999", "1"); | |
3963 server_cards.back().set_use_count(1); | |
3964 server_cards.back().set_use_date(AutofillClock::Now() - | |
3965 base::TimeDelta::FromDays(1)); | |
3966 server_cards.back().SetNetworkForMaskedCard(kVisaCard); | |
3967 server_cards.back().set_bank_name("Chase"); | |
3968 | |
3969 test::SetServerCreditCards(autofill_table_, server_cards); | |
3970 | |
3971 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | |
3972 .WillOnce(QuitMainMessageLoop()); | |
3973 base::RunLoop().Run(); | |
3974 | |
3975 std::vector<Suggestion> suggestions = | |
3976 personal_data_->GetCreditCardSuggestions( | |
3977 AutofillType(CREDIT_CARD_NUMBER), | |
3978 /* field_contents= */ base::string16()); | |
3979 ASSERT_EQ(3U, suggestions.size()); | |
3980 | |
3981 // Local cards will show network. | |
3982 EXPECT_EQ( | |
3983 base::UTF8ToUTF16(std::string("Amex") + kUTF8MidlineEllipsis + "8555"), | |
3984 suggestions[0].value); | |
3985 // Server card without bank name will show network. | |
3986 EXPECT_EQ( | |
3987 base::UTF8ToUTF16(std::string("Visa") + kUTF8MidlineEllipsis + "2110"), | |
3988 suggestions[1].value); | |
3989 // Server card with bank name will show bank name. | |
3990 EXPECT_EQ( | |
3991 base::UTF8ToUTF16(std::string("Chase") + kUTF8MidlineEllipsis + "2111"), | |
3992 suggestions[2].value); | |
3993 } | |
3994 | |
3995 // Tests that only the full server card is kept when deduping with a local | 3926 // Tests that only the full server card is kept when deduping with a local |
3996 // duplicate of it. | 3927 // duplicate of it. |
3997 TEST_F(PersonalDataManagerTest, | 3928 TEST_F(PersonalDataManagerTest, |
3998 DedupeCreditCardToSuggest_FullServerShadowsLocal) { | 3929 DedupeCreditCardToSuggest_FullServerShadowsLocal) { |
3999 std::list<CreditCard*> credit_cards; | 3930 std::list<CreditCard*> credit_cards; |
4000 | 3931 |
4001 // Create 3 different local credit cards. | 3932 // Create 3 different local credit cards. |
4002 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15", | 3933 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15", |
4003 "https://www.example.com"); | 3934 "https://www.example.com"); |
4004 test::SetCreditCardInfo(&local_card, "Homer Simpson", | 3935 test::SetCreditCardInfo(&local_card, "Homer Simpson", |
(...skipping 2566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6571 EXPECT_EQ("", card->billing_address_id()); | 6502 EXPECT_EQ("", card->billing_address_id()); |
6572 } else { | 6503 } else { |
6573 // The billing address of local_card1 and server_card1 should still refer | 6504 // The billing address of local_card1 and server_card1 should still refer |
6574 // to profile1. | 6505 // to profile1. |
6575 EXPECT_EQ(profile1.guid(), card->billing_address_id()); | 6506 EXPECT_EQ(profile1.guid(), card->billing_address_id()); |
6576 } | 6507 } |
6577 } | 6508 } |
6578 } | 6509 } |
6579 | 6510 |
6580 } // namespace autofill | 6511 } // namespace autofill |
OLD | NEW |