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

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: Fix sync issues 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 3879 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 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().SetBankName("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.
3961 EXPECT_EQ(base::UTF8ToUTF16(std::string("Visa") + kUTF8MidlineEllipsis + "9012 "),
Jared Saul 2017/06/07 01:22:59 Looks like these go over 80 chars; wrap?
Shanfeng 2017/06/07 17:20:16 Done.
3962 suggestions[0].value);
3963 EXPECT_EQ(base::UTF8ToUTF16(std::string("Amex") + kUTF8MidlineEllipsis + "8555 "),
3964 suggestions[1].value);
3965 EXPECT_EQ(base::UTF8ToUTF16(std::string("Chase") + kUTF8MidlineEllipsis + "211 0"),
3966 suggestions[2].value);
3967 EXPECT_EQ(base::UTF8ToUTF16(std::string("Mastercard") + kUTF8MidlineEllipsis + "2109"),
3968 suggestions[3].value);
3969 }
3970
3926 // Tests that only the full server card is kept when deduping with a local 3971 // Tests that only the full server card is kept when deduping with a local
3927 // duplicate of it. 3972 // duplicate of it.
3928 TEST_F(PersonalDataManagerTest, 3973 TEST_F(PersonalDataManagerTest,
3929 DedupeCreditCardToSuggest_FullServerShadowsLocal) { 3974 DedupeCreditCardToSuggest_FullServerShadowsLocal) {
3930 std::list<CreditCard*> credit_cards; 3975 std::list<CreditCard*> credit_cards;
3931 3976
3932 // Create 3 different local credit cards. 3977 // Create 3 different local credit cards.
3933 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15", 3978 CreditCard local_card("287151C8-6AB1-487C-9095-28E80BE5DA15",
3934 "https://www.example.com"); 3979 "https://www.example.com");
3935 test::SetCreditCardInfo(&local_card, "Homer Simpson", 3980 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()); 6547 EXPECT_EQ("", card->billing_address_id());
6503 } else { 6548 } else {
6504 // The billing address of local_card1 and server_card1 should still refer 6549 // The billing address of local_card1 and server_card1 should still refer
6505 // to profile1. 6550 // to profile1.
6506 EXPECT_EQ(profile1.guid(), card->billing_address_id()); 6551 EXPECT_EQ(profile1.guid(), card->billing_address_id());
6507 } 6552 }
6508 } 6553 }
6509 } 6554 }
6510 6555
6511 } // namespace autofill 6556 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698