OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/payments/core/autofill_payment_instrument.h" |
| 6 |
| 7 #include "base/macros.h" |
| 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "components/autofill/core/browser/autofill_profile.h" |
| 10 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 11 #include "components/autofill/core/browser/credit_card.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 |
| 14 namespace payments { |
| 15 |
| 16 class AutofillPaymentInstrumentTest : public testing::Test { |
| 17 protected: |
| 18 AutofillPaymentInstrumentTest() |
| 19 : address_(autofill::test::GetFullProfile()), |
| 20 local_card_(autofill::test::GetCreditCard()), |
| 21 billing_profiles_({&address_}) { |
| 22 local_card_.set_billing_address_id(address_.guid()); |
| 23 } |
| 24 |
| 25 autofill::CreditCard& local_credit_card() { return local_card_; } |
| 26 const std::vector<autofill::AutofillProfile*>& billing_profiles() { |
| 27 return billing_profiles_; |
| 28 } |
| 29 |
| 30 private: |
| 31 autofill::AutofillProfile address_; |
| 32 autofill::CreditCard local_card_; |
| 33 std::vector<autofill::AutofillProfile*> billing_profiles_; |
| 34 |
| 35 DISALLOW_COPY_AND_ASSIGN(AutofillPaymentInstrumentTest); |
| 36 }; |
| 37 |
| 38 // A valid local credit card is a valid instrument for payment. |
| 39 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment) { |
| 40 AutofillPaymentInstrument instrument("visa", local_credit_card(), |
| 41 billing_profiles(), "en-US", nullptr); |
| 42 EXPECT_TRUE(instrument.IsCompleteForPayment()); |
| 43 } |
| 44 |
| 45 // An expired local card is not a valid instrument for payment. |
| 46 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_Expired) { |
| 47 autofill::CreditCard& card = local_credit_card(); |
| 48 card.SetExpirationYear(2016); // Expired. |
| 49 AutofillPaymentInstrument instrument("visa", card, billing_profiles(), |
| 50 "en-US", nullptr); |
| 51 EXPECT_FALSE(instrument.IsCompleteForPayment()); |
| 52 } |
| 53 |
| 54 // A local card with no name is not a valid instrument for payment. |
| 55 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_NoName) { |
| 56 autofill::CreditCard& card = local_credit_card(); |
| 57 card.SetInfo(autofill::AutofillType(autofill::CREDIT_CARD_NAME_FULL), |
| 58 base::ASCIIToUTF16(""), "en-US"); |
| 59 AutofillPaymentInstrument instrument("visa", card, billing_profiles(), |
| 60 "en-US", nullptr); |
| 61 EXPECT_FALSE(instrument.IsCompleteForPayment()); |
| 62 } |
| 63 |
| 64 // A local card with no name is not a valid instrument for payment. |
| 65 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_NoNumber) { |
| 66 autofill::CreditCard& card = local_credit_card(); |
| 67 card.SetNumber(base::ASCIIToUTF16("")); |
| 68 AutofillPaymentInstrument instrument("visa", card, billing_profiles(), |
| 69 "en-US", nullptr); |
| 70 EXPECT_FALSE(instrument.IsCompleteForPayment()); |
| 71 } |
| 72 |
| 73 // A Masked (server) card is a valid instrument for payment. |
| 74 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_MaskedCard) { |
| 75 autofill::CreditCard card = autofill::test::GetMaskedServerCard(); |
| 76 AutofillPaymentInstrument instrument("visa", card, billing_profiles(), |
| 77 "en-US", nullptr); |
| 78 EXPECT_TRUE(instrument.IsCompleteForPayment()); |
| 79 } |
| 80 |
| 81 // An expired masked (server) card is not a valid instrument for payment. |
| 82 TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_ExpiredMaskedCard) { |
| 83 autofill::CreditCard card = autofill::test::GetMaskedServerCard(); |
| 84 card.SetExpirationYear(2016); // Expired. |
| 85 AutofillPaymentInstrument instrument("visa", card, billing_profiles(), |
| 86 "en-US", nullptr); |
| 87 EXPECT_FALSE(instrument.IsCompleteForPayment()); |
| 88 } |
| 89 |
| 90 // An expired card is a valid instrument for canMakePayment. |
| 91 TEST_F(AutofillPaymentInstrumentTest, IsValidForCanMakePayment_Minimal) { |
| 92 autofill::CreditCard& card = local_credit_card(); |
| 93 card.SetExpirationYear(2016); // Expired. |
| 94 AutofillPaymentInstrument instrument("visa", card, billing_profiles(), |
| 95 "en-US", nullptr); |
| 96 EXPECT_TRUE(instrument.IsValidForCanMakePayment()); |
| 97 } |
| 98 |
| 99 // An expired Masked (server) card is a valid instrument for canMakePayment. |
| 100 TEST_F(AutofillPaymentInstrumentTest, IsValidForCanMakePayment_MaskedCard) { |
| 101 autofill::CreditCard card = autofill::test::GetMaskedServerCard(); |
| 102 card.SetExpirationYear(2016); // Expired. |
| 103 AutofillPaymentInstrument instrument("visa", card, billing_profiles(), |
| 104 "en-US", nullptr); |
| 105 EXPECT_TRUE(instrument.IsValidForCanMakePayment()); |
| 106 } |
| 107 |
| 108 // A card with no name is not a valid instrument for canMakePayment. |
| 109 TEST_F(AutofillPaymentInstrumentTest, IsValidForCanMakePayment_NoName) { |
| 110 autofill::CreditCard& card = local_credit_card(); |
| 111 card.SetInfo(autofill::AutofillType(autofill::CREDIT_CARD_NAME_FULL), |
| 112 base::ASCIIToUTF16(""), "en-US"); |
| 113 AutofillPaymentInstrument instrument("visa", card, billing_profiles(), |
| 114 "en-US", nullptr); |
| 115 EXPECT_FALSE(instrument.IsValidForCanMakePayment()); |
| 116 } |
| 117 |
| 118 // A card with no number is not a valid instrument for canMakePayment. |
| 119 TEST_F(AutofillPaymentInstrumentTest, IsValidForCanMakePayment_NoNumber) { |
| 120 autofill::CreditCard& card = local_credit_card(); |
| 121 card.SetNumber(base::ASCIIToUTF16("")); |
| 122 AutofillPaymentInstrument instrument("visa", card, billing_profiles(), |
| 123 "en-US", nullptr); |
| 124 EXPECT_FALSE(instrument.IsValidForCanMakePayment()); |
| 125 } |
| 126 |
| 127 } // namespace payments |
OLD | NEW |