Index: components/payments/core/autofill_payment_instrument_unittest.cc |
diff --git a/components/payments/core/autofill_payment_instrument_unittest.cc b/components/payments/core/autofill_payment_instrument_unittest.cc |
index 7b9db0be6a96b1a828190e7f22a80fa3dcd7c1a8..2ed53ad05a6364d60ce35ac64a62636778be25c7 100644 |
--- a/components/payments/core/autofill_payment_instrument_unittest.cc |
+++ b/components/payments/core/autofill_payment_instrument_unittest.cc |
@@ -5,11 +5,14 @@ |
#include "components/payments/core/autofill_payment_instrument.h" |
#include "base/macros.h" |
+#include "base/strings/string16.h" |
#include "base/strings/utf_string_conversions.h" |
#include "components/autofill/core/browser/autofill_profile.h" |
#include "components/autofill/core/browser/autofill_test_utils.h" |
#include "components/autofill/core/browser/credit_card.h" |
+#include "components/strings/grit/components_strings.h" |
#include "testing/gtest/include/gtest/gtest.h" |
+#include "ui/base/l10n/l10n_util.h" |
namespace payments { |
@@ -39,7 +42,12 @@ class AutofillPaymentInstrumentTest : public testing::Test { |
TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment) { |
AutofillPaymentInstrument instrument("visa", local_credit_card(), |
billing_profiles(), "en-US", nullptr); |
- EXPECT_TRUE(instrument.IsCompleteForPayment()); |
+ base::string16 missing_info; |
+ EXPECT_TRUE(instrument.IsCompleteForPayment(/*missing_info=*/&missing_info)); |
+ EXPECT_TRUE(missing_info.empty()); |
+ |
+ // Passing /*missing_info=*/nullptr doesn't crash. |
+ EXPECT_TRUE(instrument.IsCompleteForPayment(/*missing_info=*/nullptr)); |
} |
// An expired local card is not a valid instrument for payment. |
@@ -48,7 +56,11 @@ TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_Expired) { |
card.SetExpirationYear(2016); // Expired. |
AutofillPaymentInstrument instrument("visa", card, billing_profiles(), |
"en-US", nullptr); |
- EXPECT_FALSE(instrument.IsCompleteForPayment()); |
+ base::string16 missing_info; |
+ EXPECT_FALSE(instrument.IsCompleteForPayment(/*missing_info=*/&missing_info)); |
+ EXPECT_EQ(l10n_util::GetStringUTF16( |
+ IDS_PAYMENTS_VALIDATION_INVALID_CREDIT_CARD_EXPIRED), |
+ missing_info); |
} |
// A local card with no name is not a valid instrument for payment. |
@@ -56,18 +68,41 @@ TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_NoName) { |
autofill::CreditCard& card = local_credit_card(); |
card.SetInfo(autofill::AutofillType(autofill::CREDIT_CARD_NAME_FULL), |
base::ASCIIToUTF16(""), "en-US"); |
+ base::string16 missing_info; |
AutofillPaymentInstrument instrument("visa", card, billing_profiles(), |
"en-US", nullptr); |
- EXPECT_FALSE(instrument.IsCompleteForPayment()); |
+ EXPECT_FALSE(instrument.IsCompleteForPayment(/*missing_info=*/&missing_info)); |
+ EXPECT_EQ(l10n_util::GetStringUTF16(IDS_PAYMENTS_NAME_ON_CARD_REQUIRED), |
+ missing_info); |
} |
// A local card with no name is not a valid instrument for payment. |
TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_NoNumber) { |
autofill::CreditCard& card = local_credit_card(); |
card.SetNumber(base::ASCIIToUTF16("")); |
+ base::string16 missing_info; |
+ AutofillPaymentInstrument instrument("visa", card, billing_profiles(), |
+ "en-US", nullptr); |
+ EXPECT_FALSE(instrument.IsCompleteForPayment(/*missing_info=*/&missing_info)); |
+ EXPECT_EQ(l10n_util::GetStringUTF16( |
+ IDS_PAYMENTS_CARD_NUMBER_INVALID_VALIDATION_MESSAGE), |
+ missing_info); |
+} |
+ |
+// A local card with no name and no number is not a valid instrument for |
+// payment. |
+TEST_F(AutofillPaymentInstrumentTest, |
+ IsCompleteForPayment_MultipleThingsMissing) { |
+ autofill::CreditCard& card = local_credit_card(); |
+ card.SetNumber(base::ASCIIToUTF16("")); |
+ card.SetInfo(autofill::AutofillType(autofill::CREDIT_CARD_NAME_FULL), |
+ base::ASCIIToUTF16(""), "en-US"); |
+ base::string16 missing_info; |
AutofillPaymentInstrument instrument("visa", card, billing_profiles(), |
"en-US", nullptr); |
- EXPECT_FALSE(instrument.IsCompleteForPayment()); |
+ EXPECT_FALSE(instrument.IsCompleteForPayment(/*missing_info=*/&missing_info)); |
+ EXPECT_EQ(l10n_util::GetStringUTF16(IDS_PAYMENTS_MORE_INFORMATION_REQUIRED), |
+ missing_info); |
} |
// A Masked (server) card is a valid instrument for payment. |
@@ -75,7 +110,12 @@ TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_MaskedCard) { |
autofill::CreditCard card = autofill::test::GetMaskedServerCard(); |
AutofillPaymentInstrument instrument("visa", card, billing_profiles(), |
"en-US", nullptr); |
- EXPECT_TRUE(instrument.IsCompleteForPayment()); |
+ base::string16 missing_info; |
+ EXPECT_TRUE(instrument.IsCompleteForPayment(/*missing_info=*/&missing_info)); |
+ EXPECT_TRUE(missing_info.empty()); |
+ |
+ // Passing /*missing_info=*/nullptr doesn't crash. |
+ EXPECT_TRUE(instrument.IsCompleteForPayment(/*missing_info=*/nullptr)); |
} |
// An expired masked (server) card is not a valid instrument for payment. |
@@ -84,7 +124,11 @@ TEST_F(AutofillPaymentInstrumentTest, IsCompleteForPayment_ExpiredMaskedCard) { |
card.SetExpirationYear(2016); // Expired. |
AutofillPaymentInstrument instrument("visa", card, billing_profiles(), |
"en-US", nullptr); |
- EXPECT_FALSE(instrument.IsCompleteForPayment()); |
+ base::string16 missing_info; |
+ EXPECT_FALSE(instrument.IsCompleteForPayment(/*missing_info=*/&missing_info)); |
+ EXPECT_EQ(l10n_util::GetStringUTF16( |
+ IDS_PAYMENTS_VALIDATION_INVALID_CREDIT_CARD_EXPIRED), |
+ missing_info); |
} |
// An expired card is a valid instrument for canMakePayment. |