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

Side by Side Diff: components/payments/core/autofill_payment_instrument_unittest.cc

Issue 2813203004: [Payments] Show what's missing for incomplete payment methods. (Closed)
Patch Set: Initial Created 3 years, 8 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/payments/core/autofill_payment_instrument.h" 5 #include "components/payments/core/autofill_payment_instrument.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/strings/string16.h"
8 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
9 #include "components/autofill/core/browser/autofill_profile.h" 10 #include "components/autofill/core/browser/autofill_profile.h"
10 #include "components/autofill/core/browser/autofill_test_utils.h" 11 #include "components/autofill/core/browser/autofill_test_utils.h"
11 #include "components/autofill/core/browser/credit_card.h" 12 #include "components/autofill/core/browser/credit_card.h"
13 #include "components/strings/grit/components_strings.h"
12 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "ui/base/l10n/l10n_util.h"
13 16
14 namespace payments { 17 namespace payments {
15 18
16 class AutofillPaymentInstrumentTest : public testing::Test { 19 class AutofillPaymentInstrumentTest : public testing::Test {
17 protected: 20 protected:
18 AutofillPaymentInstrumentTest() 21 AutofillPaymentInstrumentTest()
19 : address_(autofill::test::GetFullProfile()), 22 : address_(autofill::test::GetFullProfile()),
20 local_card_(autofill::test::GetCreditCard()), 23 local_card_(autofill::test::GetCreditCard()),
21 billing_profiles_({&address_}) { 24 billing_profiles_({&address_}) {
22 local_card_.set_billing_address_id(address_.guid()); 25 local_card_.set_billing_address_id(address_.guid());
23 } 26 }
24 27
25 autofill::CreditCard& local_credit_card() { return local_card_; } 28 autofill::CreditCard& local_credit_card() { return local_card_; }
26 const std::vector<autofill::AutofillProfile*>& billing_profiles() { 29 const std::vector<autofill::AutofillProfile*>& billing_profiles() {
27 return billing_profiles_; 30 return billing_profiles_;
28 } 31 }
29 32
30 private: 33 private:
31 autofill::AutofillProfile address_; 34 autofill::AutofillProfile address_;
32 autofill::CreditCard local_card_; 35 autofill::CreditCard local_card_;
33 std::vector<autofill::AutofillProfile*> billing_profiles_; 36 std::vector<autofill::AutofillProfile*> billing_profiles_;
34 37
35 DISALLOW_COPY_AND_ASSIGN(AutofillPaymentInstrumentTest); 38 DISALLOW_COPY_AND_ASSIGN(AutofillPaymentInstrumentTest);
36 }; 39 };
37 40
38 // A valid local credit card is a valid instrument for payment. 41 // A valid local credit card is a valid instrument for payment.
39 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment) { 42 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment) {
40 AutofillPaymentInstrument instrument("visa", local_credit_card(), 43 AutofillPaymentInstrument instrument("visa", local_credit_card(),
41 billing_profiles(), "en-US", nullptr); 44 billing_profiles(), "en-US", nullptr);
42 EXPECT_TRUE(instrument.IsCompleteForPayment()); 45 base::string16 missing_info;
46 EXPECT_TRUE(instrument.IsCompleteForPayment(/*missing_info=*/&missing_info));
47 EXPECT_TRUE(missing_info.empty());
48
49 // Passing /*missing_info=*/nullptr doesn't crash.
50 EXPECT_TRUE(instrument.IsCompleteForPayment(/*missing_info=*/nullptr));
43 } 51 }
44 52
45 // An expired local card is not a valid instrument for payment. 53 // An expired local card is not a valid instrument for payment.
46 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_Expired) { 54 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_Expired) {
47 autofill::CreditCard& card = local_credit_card(); 55 autofill::CreditCard& card = local_credit_card();
48 card.SetExpirationYear(2016); // Expired. 56 card.SetExpirationYear(2016); // Expired.
49 AutofillPaymentInstrument instrument("visa", card, billing_profiles(), 57 AutofillPaymentInstrument instrument("visa", card, billing_profiles(),
50 "en-US", nullptr); 58 "en-US", nullptr);
51 EXPECT_FALSE(instrument.IsCompleteForPayment()); 59 base::string16 missing_info;
60 EXPECT_FALSE(instrument.IsCompleteForPayment(/*missing_info=*/&missing_info));
61 EXPECT_EQ(l10n_util::GetStringUTF16(
62 IDS_PAYMENTS_VALIDATION_INVALID_CREDIT_CARD_EXPIRED),
63 missing_info);
52 } 64 }
53 65
54 // A local card with no name is not a valid instrument for payment. 66 // A local card with no name is not a valid instrument for payment.
55 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_NoName) { 67 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_NoName) {
56 autofill::CreditCard& card = local_credit_card(); 68 autofill::CreditCard& card = local_credit_card();
57 card.SetInfo(autofill::AutofillType(autofill::CREDIT_CARD_NAME_FULL), 69 card.SetInfo(autofill::AutofillType(autofill::CREDIT_CARD_NAME_FULL),
58 base::ASCIIToUTF16(""), "en-US"); 70 base::ASCIIToUTF16(""), "en-US");
71 base::string16 missing_info;
59 AutofillPaymentInstrument instrument("visa", card, billing_profiles(), 72 AutofillPaymentInstrument instrument("visa", card, billing_profiles(),
60 "en-US", nullptr); 73 "en-US", nullptr);
61 EXPECT_FALSE(instrument.IsCompleteForPayment()); 74 EXPECT_FALSE(instrument.IsCompleteForPayment(/*missing_info=*/&missing_info));
75 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_PAYMENTS_NAME_ON_CARD_REQUIRED),
76 missing_info);
62 } 77 }
63 78
64 // A local card with no name is not a valid instrument for payment. 79 // A local card with no name is not a valid instrument for payment.
65 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_NoNumber) { 80 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_NoNumber) {
66 autofill::CreditCard& card = local_credit_card(); 81 autofill::CreditCard& card = local_credit_card();
67 card.SetNumber(base::ASCIIToUTF16("")); 82 card.SetNumber(base::ASCIIToUTF16(""));
83 base::string16 missing_info;
68 AutofillPaymentInstrument instrument("visa", card, billing_profiles(), 84 AutofillPaymentInstrument instrument("visa", card, billing_profiles(),
69 "en-US", nullptr); 85 "en-US", nullptr);
70 EXPECT_FALSE(instrument.IsCompleteForPayment()); 86 EXPECT_FALSE(instrument.IsCompleteForPayment(/*missing_info=*/&missing_info));
87 EXPECT_EQ(l10n_util::GetStringUTF16(
88 IDS_PAYMENTS_CARD_NUMBER_INVALID_VALIDATION_MESSAGE),
89 missing_info);
90 }
91
92 // A local card with no name and no number is not a valid instrument for
93 // payment.
94 TEST_F(AutofillPaymentInstrumentTest,
95 IsCompleteForPayment_MultipleThingsMissing) {
96 autofill::CreditCard& card = local_credit_card();
97 card.SetNumber(base::ASCIIToUTF16(""));
98 card.SetInfo(autofill::AutofillType(autofill::CREDIT_CARD_NAME_FULL),
99 base::ASCIIToUTF16(""), "en-US");
100 base::string16 missing_info;
101 AutofillPaymentInstrument instrument("visa", card, billing_profiles(),
102 "en-US", nullptr);
103 EXPECT_FALSE(instrument.IsCompleteForPayment(/*missing_info=*/&missing_info));
104 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_PAYMENTS_MORE_INFORMATION_REQUIRED),
105 missing_info);
71 } 106 }
72 107
73 // A Masked (server) card is a valid instrument for payment. 108 // A Masked (server) card is a valid instrument for payment.
74 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_MaskedCard) { 109 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_MaskedCard) {
75 autofill::CreditCard card = autofill::test::GetMaskedServerCard(); 110 autofill::CreditCard card = autofill::test::GetMaskedServerCard();
76 AutofillPaymentInstrument instrument("visa", card, billing_profiles(), 111 AutofillPaymentInstrument instrument("visa", card, billing_profiles(),
77 "en-US", nullptr); 112 "en-US", nullptr);
78 EXPECT_TRUE(instrument.IsCompleteForPayment()); 113 base::string16 missing_info;
114 EXPECT_TRUE(instrument.IsCompleteForPayment(/*missing_info=*/&missing_info));
115 EXPECT_TRUE(missing_info.empty());
116
117 // Passing /*missing_info=*/nullptr doesn't crash.
118 EXPECT_TRUE(instrument.IsCompleteForPayment(/*missing_info=*/nullptr));
79 } 119 }
80 120
81 // An expired masked (server) card is not a valid instrument for payment. 121 // An expired masked (server) card is not a valid instrument for payment.
82 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_ExpiredMaskedCard) { 122 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_ExpiredMaskedCard) {
83 autofill::CreditCard card = autofill::test::GetMaskedServerCard(); 123 autofill::CreditCard card = autofill::test::GetMaskedServerCard();
84 card.SetExpirationYear(2016); // Expired. 124 card.SetExpirationYear(2016); // Expired.
85 AutofillPaymentInstrument instrument("visa", card, billing_profiles(), 125 AutofillPaymentInstrument instrument("visa", card, billing_profiles(),
86 "en-US", nullptr); 126 "en-US", nullptr);
87 EXPECT_FALSE(instrument.IsCompleteForPayment()); 127 base::string16 missing_info;
128 EXPECT_FALSE(instrument.IsCompleteForPayment(/*missing_info=*/&missing_info));
129 EXPECT_EQ(l10n_util::GetStringUTF16(
130 IDS_PAYMENTS_VALIDATION_INVALID_CREDIT_CARD_EXPIRED),
131 missing_info);
88 } 132 }
89 133
90 // An expired card is a valid instrument for canMakePayment. 134 // An expired card is a valid instrument for canMakePayment.
91 TEST_F(AutofillPaymentInstrumentTest, IsValidForCanMakePayment_Minimal) { 135 TEST_F(AutofillPaymentInstrumentTest, IsValidForCanMakePayment_Minimal) {
92 autofill::CreditCard& card = local_credit_card(); 136 autofill::CreditCard& card = local_credit_card();
93 card.SetExpirationYear(2016); // Expired. 137 card.SetExpirationYear(2016); // Expired.
94 AutofillPaymentInstrument instrument("visa", card, billing_profiles(), 138 AutofillPaymentInstrument instrument("visa", card, billing_profiles(),
95 "en-US", nullptr); 139 "en-US", nullptr);
96 EXPECT_TRUE(instrument.IsValidForCanMakePayment()); 140 EXPECT_TRUE(instrument.IsValidForCanMakePayment());
97 } 141 }
(...skipping 20 matching lines...) Expand all
118 // A card with no number is not a valid instrument for canMakePayment. 162 // A card with no number is not a valid instrument for canMakePayment.
119 TEST_F(AutofillPaymentInstrumentTest, IsValidForCanMakePayment_NoNumber) { 163 TEST_F(AutofillPaymentInstrumentTest, IsValidForCanMakePayment_NoNumber) {
120 autofill::CreditCard& card = local_credit_card(); 164 autofill::CreditCard& card = local_credit_card();
121 card.SetNumber(base::ASCIIToUTF16("")); 165 card.SetNumber(base::ASCIIToUTF16(""));
122 AutofillPaymentInstrument instrument("visa", card, billing_profiles(), 166 AutofillPaymentInstrument instrument("visa", card, billing_profiles(),
123 "en-US", nullptr); 167 "en-US", nullptr);
124 EXPECT_FALSE(instrument.IsValidForCanMakePayment()); 168 EXPECT_FALSE(instrument.IsValidForCanMakePayment());
125 } 169 }
126 170
127 } // namespace payments 171 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698