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

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

Issue 2849523003: Add billing address as a mandatory field of Payments credit cards. (Closed)
Patch Set: Components Unittests fix Created 3 years, 7 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/string16.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "components/autofill/core/browser/autofill_profile.h" 10 #include "components/autofill/core/browser/autofill_profile.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 card.SetExpirationYear(2016); // Expired. 85 card.SetExpirationYear(2016); // Expired.
86 AutofillPaymentInstrument instrument("visa", card, billing_profiles(), 86 AutofillPaymentInstrument instrument("visa", card, billing_profiles(),
87 "en-US", nullptr); 87 "en-US", nullptr);
88 EXPECT_FALSE(instrument.IsCompleteForPayment()); 88 EXPECT_FALSE(instrument.IsCompleteForPayment());
89 EXPECT_EQ(l10n_util::GetStringUTF16( 89 EXPECT_EQ(l10n_util::GetStringUTF16(
90 IDS_PAYMENTS_VALIDATION_INVALID_CREDIT_CARD_EXPIRED), 90 IDS_PAYMENTS_VALIDATION_INVALID_CREDIT_CARD_EXPIRED),
91 instrument.GetMissingInfoLabel()); 91 instrument.GetMissingInfoLabel());
92 } 92 }
93 93
94 // A local card with no name is not a valid instrument for payment. 94 // A local card with no name is not a valid instrument for payment.
95 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_NoName) { 95 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_NoName) {
Mathieu 2017/05/04 20:29:19 can we have a test for when there is no billing ad
MAD 2017/05/05 00:50:07 Done.
96 autofill::CreditCard& card = local_credit_card(); 96 autofill::CreditCard& card = local_credit_card();
97 card.SetInfo(autofill::AutofillType(autofill::CREDIT_CARD_NAME_FULL), 97 card.SetInfo(autofill::AutofillType(autofill::CREDIT_CARD_NAME_FULL),
98 base::ASCIIToUTF16(""), "en-US"); 98 base::ASCIIToUTF16(""), "en-US");
99 base::string16 missing_info; 99 base::string16 missing_info;
100 AutofillPaymentInstrument instrument("visa", card, billing_profiles(), 100 AutofillPaymentInstrument instrument("visa", card, billing_profiles(),
101 "en-US", nullptr); 101 "en-US", nullptr);
102 EXPECT_FALSE(instrument.IsCompleteForPayment()); 102 EXPECT_FALSE(instrument.IsCompleteForPayment());
103 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_PAYMENTS_NAME_ON_CARD_REQUIRED), 103 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_PAYMENTS_NAME_ON_CARD_REQUIRED),
104 instrument.GetMissingInfoLabel()); 104 instrument.GetMissingInfoLabel());
105 } 105 }
(...skipping 22 matching lines...) Expand all
128 AutofillPaymentInstrument instrument("visa", card, billing_profiles(), 128 AutofillPaymentInstrument instrument("visa", card, billing_profiles(),
129 "en-US", nullptr); 129 "en-US", nullptr);
130 EXPECT_FALSE(instrument.IsCompleteForPayment()); 130 EXPECT_FALSE(instrument.IsCompleteForPayment());
131 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_PAYMENTS_MORE_INFORMATION_REQUIRED), 131 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_PAYMENTS_MORE_INFORMATION_REQUIRED),
132 instrument.GetMissingInfoLabel()); 132 instrument.GetMissingInfoLabel());
133 } 133 }
134 134
135 // A Masked (server) card is a valid instrument for payment. 135 // A Masked (server) card is a valid instrument for payment.
136 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_MaskedCard) { 136 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_MaskedCard) {
137 autofill::CreditCard card = autofill::test::GetMaskedServerCard(); 137 autofill::CreditCard card = autofill::test::GetMaskedServerCard();
138 ASSERT_GT(billing_profiles().size(), 0UL);
139 card.set_billing_address_id(billing_profiles()[0]->guid());
138 AutofillPaymentInstrument instrument("visa", card, billing_profiles(), 140 AutofillPaymentInstrument instrument("visa", card, billing_profiles(),
139 "en-US", nullptr); 141 "en-US", nullptr);
140 EXPECT_TRUE(instrument.IsCompleteForPayment()); 142 EXPECT_TRUE(instrument.IsCompleteForPayment());
141 EXPECT_TRUE(instrument.GetMissingInfoLabel().empty()); 143 EXPECT_TRUE(instrument.GetMissingInfoLabel().empty());
142 } 144 }
143 145
144 // An expired masked (server) card is not a valid instrument for payment. 146 // An expired masked (server) card is not a valid instrument for payment.
145 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_ExpiredMaskedCard) { 147 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_ExpiredMaskedCard) {
146 autofill::CreditCard card = autofill::test::GetMaskedServerCard(); 148 autofill::CreditCard card = autofill::test::GetMaskedServerCard();
149 ASSERT_GT(billing_profiles().size(), 0UL);
150 card.set_billing_address_id(billing_profiles()[0]->guid());
147 card.SetExpirationYear(2016); // Expired. 151 card.SetExpirationYear(2016); // Expired.
148 AutofillPaymentInstrument instrument("visa", card, billing_profiles(), 152 AutofillPaymentInstrument instrument("visa", card, billing_profiles(),
149 "en-US", nullptr); 153 "en-US", nullptr);
150 EXPECT_FALSE(instrument.IsCompleteForPayment()); 154 EXPECT_FALSE(instrument.IsCompleteForPayment());
151 EXPECT_EQ(l10n_util::GetStringUTF16( 155 EXPECT_EQ(l10n_util::GetStringUTF16(
152 IDS_PAYMENTS_VALIDATION_INVALID_CREDIT_CARD_EXPIRED), 156 IDS_PAYMENTS_VALIDATION_INVALID_CREDIT_CARD_EXPIRED),
153 instrument.GetMissingInfoLabel()); 157 instrument.GetMissingInfoLabel());
154 } 158 }
155 159
156 // An expired card is a valid instrument for canMakePayment. 160 // An expired card is a valid instrument for canMakePayment.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 delegate.CompleteFullCardRequest(); 244 delegate.CompleteFullCardRequest();
241 EXPECT_FALSE(instrument_delegate.WasOnInstrumentDetailsReadyCalled()); 245 EXPECT_FALSE(instrument_delegate.WasOnInstrumentDetailsReadyCalled());
242 EXPECT_FALSE(instrument_delegate.WasOnInstrumentDetailsErrorCalled()); 246 EXPECT_FALSE(instrument_delegate.WasOnInstrumentDetailsErrorCalled());
243 247
244 delegate.test_address_normalizer()->CompleteAddressNormalization(); 248 delegate.test_address_normalizer()->CompleteAddressNormalization();
245 EXPECT_TRUE(instrument_delegate.WasOnInstrumentDetailsReadyCalled()); 249 EXPECT_TRUE(instrument_delegate.WasOnInstrumentDetailsReadyCalled());
246 EXPECT_FALSE(instrument_delegate.WasOnInstrumentDetailsErrorCalled()); 250 EXPECT_FALSE(instrument_delegate.WasOnInstrumentDetailsErrorCalled());
247 } 251 }
248 252
249 } // namespace payments 253 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698