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/run_loop.h" | 22 #include "base/run_loop.h" |
23 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
24 #include "base/synchronization/waitable_event.h" | 24 #include "base/synchronization/waitable_event.h" |
25 #include "base/test/histogram_tester.h" | 25 #include "base/test/histogram_tester.h" |
| 26 #include "base/test/scoped_feature_list.h" |
26 #include "base/test/simple_test_clock.h" | 27 #include "base/test/simple_test_clock.h" |
27 #include "base/threading/thread_task_runner_handle.h" | 28 #include "base/threading/thread_task_runner_handle.h" |
28 #include "base/time/time.h" | 29 #include "base/time/time.h" |
29 #include "build/build_config.h" | 30 #include "build/build_config.h" |
30 #include "components/autofill/core/browser/autofill_experiments.h" | 31 #include "components/autofill/core/browser/autofill_experiments.h" |
31 #include "components/autofill/core/browser/autofill_metrics.h" | 32 #include "components/autofill/core/browser/autofill_metrics.h" |
32 #include "components/autofill/core/browser/autofill_profile.h" | 33 #include "components/autofill/core/browser/autofill_profile.h" |
33 #include "components/autofill/core/browser/autofill_test_utils.h" | 34 #include "components/autofill/core/browser/autofill_test_utils.h" |
34 #include "components/autofill/core/browser/field_types.h" | 35 #include "components/autofill/core/browser/field_types.h" |
35 #include "components/autofill/core/browser/form_structure.h" | 36 #include "components/autofill/core/browser/form_structure.h" |
(...skipping 3724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3760 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3761 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
3761 .WillOnce(QuitMainMessageLoop()); | 3762 .WillOnce(QuitMainMessageLoop()); |
3762 base::RunLoop().Run(); | 3763 base::RunLoop().Run(); |
3763 | 3764 |
3764 suggestions = personal_data_->GetCreditCardSuggestions( | 3765 suggestions = personal_data_->GetCreditCardSuggestions( |
3765 AutofillType(CREDIT_CARD_NAME_FULL), | 3766 AutofillType(CREDIT_CARD_NAME_FULL), |
3766 /* field_contents= */ base::string16()); | 3767 /* field_contents= */ base::string16()); |
3767 ASSERT_EQ(3U, suggestions.size()); | 3768 ASSERT_EQ(3U, suggestions.size()); |
3768 } | 3769 } |
3769 | 3770 |
| 3771 // Tests that server cards have bank name when feature flag on. |
| 3772 TEST_F(PersonalDataManagerTest, |
| 3773 GetCreditCardSuggestions_ShowBankNameOfServerCards) { |
| 3774 // Turn on feature flag. |
| 3775 base::test::ScopedFeatureList scoped_feature_list_; |
| 3776 scoped_feature_list_.InitAndEnableFeature(kAutofillCreditCardBankNameDisplay); |
| 3777 |
| 3778 EnableWalletCardImport(); |
| 3779 SetupReferenceLocalCreditCards(); |
| 3780 |
| 3781 // Add some server cards. |
| 3782 std::vector<CreditCard> server_cards; |
| 3783 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b459")); |
| 3784 test::SetCreditCardInfo(&server_cards.back(), "Emmet Dalton", "2110", "12", |
| 3785 "2999"); |
| 3786 server_cards.back().set_use_count(2); |
| 3787 server_cards.back().set_use_date(AutofillClock::Now() - |
| 3788 base::TimeDelta::FromDays(1)); |
| 3789 server_cards.back().SetTypeForMaskedCard(kVisaCard); |
| 3790 server_cards.back().SetBankName("Chase"); |
| 3791 |
| 3792 test::SetServerCreditCards(autofill_table_, server_cards); |
| 3793 personal_data_->Refresh(); |
| 3794 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 3795 .WillOnce(QuitMainMessageLoop()); |
| 3796 base::RunLoop().Run(); |
| 3797 |
| 3798 std::vector<Suggestion> suggestions = |
| 3799 personal_data_->GetCreditCardSuggestions( |
| 3800 AutofillType(CREDIT_CARD_NUMBER), |
| 3801 /* field_contents= */ base::string16()); |
| 3802 ASSERT_EQ(4U, suggestions.size()); |
| 3803 |
| 3804 // All cards should be ordered as expected. |
| 3805 EXPECT_EQ(UTF8ToUTF16("Visa" + kUTF8MidlineEllipsis + "9012"), |
| 3806 suggestions[0].value); |
| 3807 EXPECT_EQ(UTF8ToUTF16("Amex" + kUTF8MidlineEllipsis + "8555"), |
| 3808 suggestions[1].value); |
| 3809 EXPECT_EQ(UTF8ToUTF16("Chase" + kUTF8MidlineEllipsis + "2110"), |
| 3810 suggestions[2].value); |
| 3811 EXPECT_EQ(UTF8ToUTF16("MasterCard" + kUTF8MidlineEllipsis + "2109"), |
| 3812 suggestions[3].value); |
| 3813 } |
| 3814 |
3770 // Tests that only the full server card is kept when deduping with a local | 3815 // Tests that only the full server card is kept when deduping with a local |
3771 // duplicate of it. | 3816 // duplicate of it. |
3772 TEST_F(PersonalDataManagerTest, | 3817 TEST_F(PersonalDataManagerTest, |
3773 DedupeCreditCardToSuggest_FullServerShadowsLocal) { | 3818 DedupeCreditCardToSuggest_FullServerShadowsLocal) { |
3774 std::list<CreditCard*> credit_cards; | 3819 std::list<CreditCard*> credit_cards; |
3775 | 3820 |
3776 // Create 3 different local credit cards. | 3821 // Create 3 different local credit cards. |
3777 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15", | 3822 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15", |
3778 "https://www.example.com"); | 3823 "https://www.example.com"); |
3779 test::SetCreditCardInfo(&local_card, "Homer Simpson", | 3824 test::SetCreditCardInfo(&local_card, "Homer Simpson", |
(...skipping 2220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6000 | 6045 |
6001 // Make sure that the billing address id of the two cards now point to the | 6046 // Make sure that the billing address id of the two cards now point to the |
6002 // converted profile. | 6047 // converted profile. |
6003 EXPECT_EQ(profiles[0]->guid(), | 6048 EXPECT_EQ(profiles[0]->guid(), |
6004 personal_data_->GetCreditCards()[0]->billing_address_id()); | 6049 personal_data_->GetCreditCards()[0]->billing_address_id()); |
6005 EXPECT_EQ(profiles[0]->guid(), | 6050 EXPECT_EQ(profiles[0]->guid(), |
6006 personal_data_->GetCreditCards()[1]->billing_address_id()); | 6051 personal_data_->GetCreditCards()[1]->billing_address_id()); |
6007 } | 6052 } |
6008 | 6053 |
6009 } // namespace autofill | 6054 } // namespace autofill |
OLD | NEW |