Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Side by Side Diff: components/autofill/core/browser/personal_data_manager_unittest.cc

Issue 2711543002: Experiment to add bank name in autofill ui. (Closed)
Patch Set: Address comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 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.
jiahuiguo 2017/06/14 05:51:28 fix indentation
Shanfeng 2017/06/14 17:48:25 Done.
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
3926 // Tests that only the full server card is kept when deduping with a local 3995 // Tests that only the full server card is kept when deduping with a local
3927 // duplicate of it. 3996 // duplicate of it.
3928 TEST_F(PersonalDataManagerTest, 3997 TEST_F(PersonalDataManagerTest,
3929 DedupeCreditCardToSuggest_FullServerShadowsLocal) { 3998 DedupeCreditCardToSuggest_FullServerShadowsLocal) {
3930 std::list<CreditCard*> credit_cards; 3999 std::list<CreditCard*> credit_cards;
3931 4000
3932 // Create 3 different local credit cards. 4001 // Create 3 different local credit cards.
3933 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15", 4002 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15",
3934 "https://www.example.com"); 4003 "https://www.example.com");
3935 test::SetCreditCardInfo(&local_card, "Homer Simpson", 4004 test::SetCreditCardInfo(&local_card, "Homer Simpson",
(...skipping 2566 matching lines...) Expand 10 before | Expand all | Expand 10 after
6502 EXPECT_EQ("", card->billing_address_id()); 6571 EXPECT_EQ("", card->billing_address_id());
6503 } else { 6572 } else {
6504 // The billing address of local_card1 and server_card1 should still refer 6573 // The billing address of local_card1 and server_card1 should still refer
6505 // to profile1. 6574 // to profile1.
6506 EXPECT_EQ(profile1.guid(), card->billing_address_id()); 6575 EXPECT_EQ(profile1.guid(), card->billing_address_id());
6507 } 6576 }
6508 } 6577 }
6509 } 6578 }
6510 6579
6511 } // namespace autofill 6580 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698