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

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: Merge branch 'master' into billing 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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 card.SetNumber(base::ASCIIToUTF16("")); 201 card.SetNumber(base::ASCIIToUTF16(""));
202 base::string16 missing_info; 202 base::string16 missing_info;
203 AutofillPaymentInstrument instrument("visa", card, billing_profiles(), 203 AutofillPaymentInstrument instrument("visa", card, billing_profiles(),
204 "en-US", nullptr); 204 "en-US", nullptr);
205 EXPECT_FALSE(instrument.IsCompleteForPayment()); 205 EXPECT_FALSE(instrument.IsCompleteForPayment());
206 EXPECT_EQ(l10n_util::GetStringUTF16( 206 EXPECT_EQ(l10n_util::GetStringUTF16(
207 IDS_PAYMENTS_CARD_NUMBER_INVALID_VALIDATION_MESSAGE), 207 IDS_PAYMENTS_CARD_NUMBER_INVALID_VALIDATION_MESSAGE),
208 instrument.GetMissingInfoLabel()); 208 instrument.GetMissingInfoLabel());
209 } 209 }
210 210
211 // A local card with no billing address id is not a valid instrument for
212 // payment.
213 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_NoBillinbAddressId) {
214 autofill::CreditCard& card = local_credit_card();
215 card.set_billing_address_id("");
216 base::string16 missing_info;
217 AutofillPaymentInstrument instrument("visa", card, billing_profiles(),
218 "en-US", nullptr);
219 EXPECT_FALSE(instrument.IsCompleteForPayment());
220 EXPECT_EQ(
221 l10n_util::GetStringUTF16(IDS_PAYMENTS_CARD_BILLING_ADDRESS_REQUIRED),
222 instrument.GetMissingInfoLabel());
223 }
224
225 // A local card with an invalid billing address id is not a valid instrument for
226 // payment.
227 TEST_F(AutofillPaymentInstrumentTest,
228 IsCompleteForPayment_InvalidBillinbAddressId) {
229 autofill::CreditCard& card = local_credit_card();
230 card.set_billing_address_id("InvalidBillingAddressId");
231 base::string16 missing_info;
232 AutofillPaymentInstrument instrument("visa", card, billing_profiles(),
233 "en-US", nullptr);
234 EXPECT_FALSE(instrument.IsCompleteForPayment());
235 EXPECT_EQ(
236 l10n_util::GetStringUTF16(IDS_PAYMENTS_CARD_BILLING_ADDRESS_REQUIRED),
237 instrument.GetMissingInfoLabel());
238 }
239
211 // A local card with no name and no number is not a valid instrument for 240 // A local card with no name and no number is not a valid instrument for
212 // payment. 241 // payment.
213 TEST_F(AutofillPaymentInstrumentTest, 242 TEST_F(AutofillPaymentInstrumentTest,
214 IsCompleteForPayment_MultipleThingsMissing) { 243 IsCompleteForPayment_MultipleThingsMissing) {
215 autofill::CreditCard& card = local_credit_card(); 244 autofill::CreditCard& card = local_credit_card();
216 card.SetNumber(base::ASCIIToUTF16("")); 245 card.SetNumber(base::ASCIIToUTF16(""));
217 card.SetInfo(autofill::AutofillType(autofill::CREDIT_CARD_NAME_FULL), 246 card.SetInfo(autofill::AutofillType(autofill::CREDIT_CARD_NAME_FULL),
218 base::ASCIIToUTF16(""), "en-US"); 247 base::ASCIIToUTF16(""), "en-US");
219 AutofillPaymentInstrument instrument("visa", card, billing_profiles(), 248 AutofillPaymentInstrument instrument("visa", card, billing_profiles(),
220 "en-US", nullptr); 249 "en-US", nullptr);
221 EXPECT_FALSE(instrument.IsCompleteForPayment()); 250 EXPECT_FALSE(instrument.IsCompleteForPayment());
222 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_PAYMENTS_MORE_INFORMATION_REQUIRED), 251 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_PAYMENTS_MORE_INFORMATION_REQUIRED),
223 instrument.GetMissingInfoLabel()); 252 instrument.GetMissingInfoLabel());
224 } 253 }
225 254
226 // A Masked (server) card is a valid instrument for payment. 255 // A Masked (server) card is a valid instrument for payment.
227 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_MaskedCard) { 256 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_MaskedCard) {
228 autofill::CreditCard card = autofill::test::GetMaskedServerCard(); 257 autofill::CreditCard card = autofill::test::GetMaskedServerCard();
258 ASSERT_GT(billing_profiles().size(), 0UL);
259 card.set_billing_address_id(billing_profiles()[0]->guid());
229 AutofillPaymentInstrument instrument("visa", card, billing_profiles(), 260 AutofillPaymentInstrument instrument("visa", card, billing_profiles(),
230 "en-US", nullptr); 261 "en-US", nullptr);
231 EXPECT_TRUE(instrument.IsCompleteForPayment()); 262 EXPECT_TRUE(instrument.IsCompleteForPayment());
232 EXPECT_TRUE(instrument.GetMissingInfoLabel().empty()); 263 EXPECT_TRUE(instrument.GetMissingInfoLabel().empty());
233 } 264 }
234 265
235 // An expired masked (server) card is not a valid instrument for payment. 266 // An expired masked (server) card is not a valid instrument for payment.
236 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_ExpiredMaskedCard) { 267 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_ExpiredMaskedCard) {
237 autofill::CreditCard card = autofill::test::GetMaskedServerCard(); 268 autofill::CreditCard card = autofill::test::GetMaskedServerCard();
269 ASSERT_GT(billing_profiles().size(), 0UL);
270 card.set_billing_address_id(billing_profiles()[0]->guid());
238 card.SetExpirationYear(2016); // Expired. 271 card.SetExpirationYear(2016); // Expired.
239 AutofillPaymentInstrument instrument("visa", card, billing_profiles(), 272 AutofillPaymentInstrument instrument("visa", card, billing_profiles(),
240 "en-US", nullptr); 273 "en-US", nullptr);
241 EXPECT_FALSE(instrument.IsCompleteForPayment()); 274 EXPECT_FALSE(instrument.IsCompleteForPayment());
242 EXPECT_EQ(l10n_util::GetStringUTF16( 275 EXPECT_EQ(l10n_util::GetStringUTF16(
243 IDS_PAYMENTS_VALIDATION_INVALID_CREDIT_CARD_EXPIRED), 276 IDS_PAYMENTS_VALIDATION_INVALID_CREDIT_CARD_EXPIRED),
244 instrument.GetMissingInfoLabel()); 277 instrument.GetMissingInfoLabel());
245 } 278 }
246 279
247 // An expired card is a valid instrument for canMakePayment. 280 // An expired card is a valid instrument for canMakePayment.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 delegate.CompleteFullCardRequest(); 364 delegate.CompleteFullCardRequest();
332 EXPECT_FALSE(instrument_delegate.WasOnInstrumentDetailsReadyCalled()); 365 EXPECT_FALSE(instrument_delegate.WasOnInstrumentDetailsReadyCalled());
333 EXPECT_FALSE(instrument_delegate.WasOnInstrumentDetailsErrorCalled()); 366 EXPECT_FALSE(instrument_delegate.WasOnInstrumentDetailsErrorCalled());
334 367
335 delegate.test_address_normalizer()->CompleteAddressNormalization(); 368 delegate.test_address_normalizer()->CompleteAddressNormalization();
336 EXPECT_TRUE(instrument_delegate.WasOnInstrumentDetailsReadyCalled()); 369 EXPECT_TRUE(instrument_delegate.WasOnInstrumentDetailsReadyCalled());
337 EXPECT_FALSE(instrument_delegate.WasOnInstrumentDetailsErrorCalled()); 370 EXPECT_FALSE(instrument_delegate.WasOnInstrumentDetailsErrorCalled());
338 } 371 }
339 372
340 } // namespace payments 373 } // namespace payments
OLDNEW
« no previous file with comments | « components/payments/core/autofill_payment_instrument.cc ('k') | components/payments_strings.grdp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698