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 3727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3763 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | 3764 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
3764 .WillOnce(QuitMainMessageLoop()); | 3765 .WillOnce(QuitMainMessageLoop()); |
3765 base::RunLoop().Run(); | 3766 base::RunLoop().Run(); |
3766 | 3767 |
3767 suggestions = personal_data_->GetCreditCardSuggestions( | 3768 suggestions = personal_data_->GetCreditCardSuggestions( |
3768 AutofillType(CREDIT_CARD_NAME_FULL), | 3769 AutofillType(CREDIT_CARD_NAME_FULL), |
3769 /* field_contents= */ base::string16()); | 3770 /* field_contents= */ base::string16()); |
3770 ASSERT_EQ(3U, suggestions.size()); | 3771 ASSERT_EQ(3U, suggestions.size()); |
3771 } | 3772 } |
3772 | 3773 |
| 3774 // Tests that server cards have bank name when feature flag on. |
| 3775 TEST_F(PersonalDataManagerTest, |
| 3776 GetCreditCardSuggestions_ShowBankNameOfServerCards) { |
| 3777 // Turn on feature flag. |
| 3778 base::test::ScopedFeatureList scoped_feature_list_; |
| 3779 scoped_feature_list_.InitAndEnableFeature(kAutofillCreditCardBankNameDisplay); |
| 3780 |
| 3781 EnableWalletCardImport(); |
| 3782 SetupReferenceLocalCreditCards(); |
| 3783 |
| 3784 // Add some server cards. |
| 3785 std::vector<CreditCard> server_cards; |
| 3786 server_cards.push_back(CreditCard(CreditCard::MASKED_SERVER_CARD, "b459")); |
| 3787 test::SetCreditCardInfo(&server_cards.back(), "Emmet Dalton", "2110", "12", |
| 3788 "2999"); |
| 3789 server_cards.back().set_use_count(2); |
| 3790 server_cards.back().set_use_date(AutofillClock::Now() - |
| 3791 base::TimeDelta::FromDays(1)); |
| 3792 server_cards.back().SetTypeForMaskedCard(kVisaCard); |
| 3793 server_cards.back().SetBankName("Chase"); |
| 3794 |
| 3795 test::SetServerCreditCards(autofill_table_, server_cards); |
| 3796 personal_data_->Refresh(); |
| 3797 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) |
| 3798 .WillOnce(QuitMainMessageLoop()); |
| 3799 base::RunLoop().Run(); |
| 3800 |
| 3801 std::vector<Suggestion> suggestions = |
| 3802 personal_data_->GetCreditCardSuggestions( |
| 3803 AutofillType(CREDIT_CARD_NUMBER), |
| 3804 /* field_contents= */ base::string16()); |
| 3805 ASSERT_EQ(4U, suggestions.size()); |
| 3806 |
| 3807 // All cards should be ordered as expected. |
| 3808 EXPECT_EQ(UTF8ToUTF16("Visa" + kUTF8MidlineEllipsis + "9012"), |
| 3809 suggestions[0].value); |
| 3810 EXPECT_EQ(UTF8ToUTF16("Amex" + kUTF8MidlineEllipsis + "8555"), |
| 3811 suggestions[1].value); |
| 3812 EXPECT_EQ(UTF8ToUTF16("Chase" + kUTF8MidlineEllipsis + "2110"), |
| 3813 suggestions[2].value); |
| 3814 EXPECT_EQ(UTF8ToUTF16("MasterCard" + kUTF8MidlineEllipsis + "2109"), |
| 3815 suggestions[3].value); |
| 3816 } |
| 3817 |
3773 // Tests that only the full server card is kept when deduping with a local | 3818 // Tests that only the full server card is kept when deduping with a local |
3774 // duplicate of it. | 3819 // duplicate of it. |
3775 TEST_F(PersonalDataManagerTest, | 3820 TEST_F(PersonalDataManagerTest, |
3776 DedupeCreditCardToSuggest_FullServerShadowsLocal) { | 3821 DedupeCreditCardToSuggest_FullServerShadowsLocal) { |
3777 std::list<CreditCard*> credit_cards; | 3822 std::list<CreditCard*> credit_cards; |
3778 | 3823 |
3779 // Create 3 different local credit cards. | 3824 // Create 3 different local credit cards. |
3780 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15", | 3825 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15", |
3781 "https://www.example.com"); | 3826 "https://www.example.com"); |
3782 test::SetCreditCardInfo(&local_card, "Homer Simpson", | 3827 test::SetCreditCardInfo(&local_card, "Homer Simpson", |
(...skipping 2429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6212 // to the converted address. | 6257 // to the converted address. |
6213 EXPECT_EQ(profiles[0]->guid(), | 6258 EXPECT_EQ(profiles[0]->guid(), |
6214 personal_data_->GetCreditCards()[0]->billing_address_id()); | 6259 personal_data_->GetCreditCards()[0]->billing_address_id()); |
6215 // Make sure that the billing address id of the new server card still refers | 6260 // Make sure that the billing address id of the new server card still refers |
6216 // to the converted address. | 6261 // to the converted address. |
6217 EXPECT_EQ(profiles[0]->guid(), | 6262 EXPECT_EQ(profiles[0]->guid(), |
6218 personal_data_->GetCreditCards()[1]->billing_address_id()); | 6263 personal_data_->GetCreditCards()[1]->billing_address_id()); |
6219 } | 6264 } |
6220 | 6265 |
6221 } // namespace autofill | 6266 } // namespace autofill |
OLD | NEW |