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

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

Issue 2918133002: [Merge M60][Payments] Refactor the year and month combobox models and preselect. (Closed)
Patch Set: 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
« no previous file with comments | « components/payments/core/autofill_payment_instrument.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 }; 163 };
164 164
165 // A valid local credit card is a valid instrument for payment. 165 // A valid local credit card is a valid instrument for payment.
166 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment) { 166 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment) {
167 AutofillPaymentInstrument instrument("visa", local_credit_card(), 167 AutofillPaymentInstrument instrument("visa", local_credit_card(),
168 billing_profiles(), "en-US", nullptr); 168 billing_profiles(), "en-US", nullptr);
169 EXPECT_TRUE(instrument.IsCompleteForPayment()); 169 EXPECT_TRUE(instrument.IsCompleteForPayment());
170 EXPECT_TRUE(instrument.GetMissingInfoLabel().empty()); 170 EXPECT_TRUE(instrument.GetMissingInfoLabel().empty());
171 } 171 }
172 172
173 // An expired local card is not a valid instrument for payment. 173 // An expired local card is still a valid instrument for payment.
174 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_Expired) { 174 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_Expired) {
175 autofill::CreditCard& card = local_credit_card(); 175 autofill::CreditCard& card = local_credit_card();
176 card.SetExpirationYear(2016); // Expired. 176 card.SetExpirationYear(2016); // Expired.
177 AutofillPaymentInstrument instrument("visa", card, billing_profiles(), 177 AutofillPaymentInstrument instrument("visa", card, billing_profiles(),
178 "en-US", nullptr); 178 "en-US", nullptr);
179 EXPECT_FALSE(instrument.IsCompleteForPayment()); 179 EXPECT_TRUE(instrument.IsCompleteForPayment());
180 EXPECT_EQ(l10n_util::GetStringUTF16( 180 EXPECT_EQ(base::string16(), instrument.GetMissingInfoLabel());
181 IDS_PAYMENTS_VALIDATION_INVALID_CREDIT_CARD_EXPIRED),
182 instrument.GetMissingInfoLabel());
183 } 181 }
184 182
185 // A local card with no name is not a valid instrument for payment. 183 // A local card with no name is not a valid instrument for payment.
186 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_NoName) { 184 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_NoName) {
187 autofill::CreditCard& card = local_credit_card(); 185 autofill::CreditCard& card = local_credit_card();
188 card.SetInfo(autofill::AutofillType(autofill::CREDIT_CARD_NAME_FULL), 186 card.SetInfo(autofill::AutofillType(autofill::CREDIT_CARD_NAME_FULL),
189 base::ASCIIToUTF16(""), "en-US"); 187 base::ASCIIToUTF16(""), "en-US");
190 base::string16 missing_info; 188 base::string16 missing_info;
191 AutofillPaymentInstrument instrument("visa", card, billing_profiles(), 189 AutofillPaymentInstrument instrument("visa", card, billing_profiles(),
192 "en-US", nullptr); 190 "en-US", nullptr);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_MaskedCard) { 254 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_MaskedCard) {
257 autofill::CreditCard card = autofill::test::GetMaskedServerCard(); 255 autofill::CreditCard card = autofill::test::GetMaskedServerCard();
258 ASSERT_GT(billing_profiles().size(), 0UL); 256 ASSERT_GT(billing_profiles().size(), 0UL);
259 card.set_billing_address_id(billing_profiles()[0]->guid()); 257 card.set_billing_address_id(billing_profiles()[0]->guid());
260 AutofillPaymentInstrument instrument("visa", card, billing_profiles(), 258 AutofillPaymentInstrument instrument("visa", card, billing_profiles(),
261 "en-US", nullptr); 259 "en-US", nullptr);
262 EXPECT_TRUE(instrument.IsCompleteForPayment()); 260 EXPECT_TRUE(instrument.IsCompleteForPayment());
263 EXPECT_TRUE(instrument.GetMissingInfoLabel().empty()); 261 EXPECT_TRUE(instrument.GetMissingInfoLabel().empty());
264 } 262 }
265 263
266 // An expired masked (server) card is not a valid instrument for payment. 264 // An expired masked (server) card is still a valid instrument for payment.
267 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_ExpiredMaskedCard) { 265 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_ExpiredMaskedCard) {
268 autofill::CreditCard card = autofill::test::GetMaskedServerCard(); 266 autofill::CreditCard card = autofill::test::GetMaskedServerCard();
269 ASSERT_GT(billing_profiles().size(), 0UL); 267 ASSERT_GT(billing_profiles().size(), 0UL);
270 card.set_billing_address_id(billing_profiles()[0]->guid()); 268 card.set_billing_address_id(billing_profiles()[0]->guid());
271 card.SetExpirationYear(2016); // Expired. 269 card.SetExpirationYear(2016); // Expired.
272 AutofillPaymentInstrument instrument("visa", card, billing_profiles(), 270 AutofillPaymentInstrument instrument("visa", card, billing_profiles(),
273 "en-US", nullptr); 271 "en-US", nullptr);
274 EXPECT_FALSE(instrument.IsCompleteForPayment()); 272 EXPECT_TRUE(instrument.IsCompleteForPayment());
275 EXPECT_EQ(l10n_util::GetStringUTF16( 273 EXPECT_EQ(base::string16(), instrument.GetMissingInfoLabel());
276 IDS_PAYMENTS_VALIDATION_INVALID_CREDIT_CARD_EXPIRED),
277 instrument.GetMissingInfoLabel());
278 } 274 }
279 275
280 // An expired card is a valid instrument for canMakePayment. 276 // An expired card is a valid instrument for canMakePayment.
281 TEST_F(AutofillPaymentInstrumentTest, IsValidForCanMakePayment_Minimal) { 277 TEST_F(AutofillPaymentInstrumentTest, IsValidForCanMakePayment_Minimal) {
282 autofill::CreditCard& card = local_credit_card(); 278 autofill::CreditCard& card = local_credit_card();
283 card.SetExpirationYear(2016); // Expired. 279 card.SetExpirationYear(2016); // Expired.
284 AutofillPaymentInstrument instrument("visa", card, billing_profiles(), 280 AutofillPaymentInstrument instrument("visa", card, billing_profiles(),
285 "en-US", nullptr); 281 "en-US", nullptr);
286 EXPECT_TRUE(instrument.IsValidForCanMakePayment()); 282 EXPECT_TRUE(instrument.IsValidForCanMakePayment());
287 } 283 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 delegate.CompleteFullCardRequest(); 360 delegate.CompleteFullCardRequest();
365 EXPECT_FALSE(instrument_delegate.WasOnInstrumentDetailsReadyCalled()); 361 EXPECT_FALSE(instrument_delegate.WasOnInstrumentDetailsReadyCalled());
366 EXPECT_FALSE(instrument_delegate.WasOnInstrumentDetailsErrorCalled()); 362 EXPECT_FALSE(instrument_delegate.WasOnInstrumentDetailsErrorCalled());
367 363
368 delegate.test_address_normalizer()->CompleteAddressNormalization(); 364 delegate.test_address_normalizer()->CompleteAddressNormalization();
369 EXPECT_TRUE(instrument_delegate.WasOnInstrumentDetailsReadyCalled()); 365 EXPECT_TRUE(instrument_delegate.WasOnInstrumentDetailsReadyCalled());
370 EXPECT_FALSE(instrument_delegate.WasOnInstrumentDetailsErrorCalled()); 366 EXPECT_FALSE(instrument_delegate.WasOnInstrumentDetailsErrorCalled());
371 } 367 }
372 368
373 } // namespace payments 369 } // namespace payments
OLDNEW
« no previous file with comments | « components/payments/core/autofill_payment_instrument.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698