summaryrefslogtreecommitdiffstats
path: root/components/autofill/content/browser/wallet/instrument_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'components/autofill/content/browser/wallet/instrument_unittest.cc')
-rw-r--r--components/autofill/content/browser/wallet/instrument_unittest.cc188
1 files changed, 188 insertions, 0 deletions
diff --git a/components/autofill/content/browser/wallet/instrument_unittest.cc b/components/autofill/content/browser/wallet/instrument_unittest.cc
new file mode 100644
index 0000000..f4b9ee8
--- /dev/null
+++ b/components/autofill/content/browser/wallet/instrument_unittest.cc
@@ -0,0 +1,188 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/strings/utf_string_conversions.h"
+#include "base/values.h"
+#include "components/autofill/content/browser/wallet/instrument.h"
+#include "components/autofill/content/browser/wallet/wallet_address.h"
+#include "components/autofill/content/browser/wallet/wallet_test_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+const char kPrimaryAccountNumber[] = "4444444444444448";
+const char kCardVerificationNumber[] = "123";
+const char kLastFourDigits[] = "4448";
+
+}
+
+namespace autofill {
+namespace wallet {
+
+TEST(Instrument, LastFourDigits) {
+ Instrument instrument(ASCIIToUTF16(kPrimaryAccountNumber),
+ ASCIIToUTF16(kCardVerificationNumber),
+ 12,
+ 2015,
+ Instrument::VISA,
+ GetTestShippingAddress().Pass());
+
+ EXPECT_EQ(ASCIIToUTF16(kLastFourDigits), instrument.last_four_digits());
+ EXPECT_TRUE(instrument.IsValid());
+}
+
+TEST(Instrument, NoPrimaryAccountNumberIsInvalid) {
+ Instrument instrument(base::string16(),
+ ASCIIToUTF16(kCardVerificationNumber),
+ 12,
+ 2015,
+ Instrument::VISA,
+ GetTestShippingAddress().Pass());
+
+ EXPECT_FALSE(instrument.IsValid());
+}
+
+TEST(Instrument, TooShortPrimaryAccountNumberIsInvalid) {
+ Instrument instrument(ASCIIToUTF16("44447"),
+ ASCIIToUTF16(kCardVerificationNumber),
+ 12,
+ 2015,
+ Instrument::VISA,
+ GetTestShippingAddress().Pass());
+
+ EXPECT_FALSE(instrument.IsValid());
+}
+
+TEST(Instrument, TooLongPrimaryAccountNumberIsInvalid) {
+ Instrument instrument(ASCIIToUTF16("44444444444444444448"),
+ ASCIIToUTF16(kCardVerificationNumber),
+ 12,
+ 2015,
+ Instrument::VISA,
+ GetTestShippingAddress().Pass());
+
+ EXPECT_FALSE(instrument.IsValid());
+}
+
+TEST(Instrument, PrimaryAccountNumberNotPassingLuhnIsInvalid) {
+ Instrument instrument(ASCIIToUTF16("4444444444444444"),
+ ASCIIToUTF16(kCardVerificationNumber),
+ 12,
+ 2015,
+ Instrument::VISA,
+ GetTestShippingAddress().Pass());
+
+ EXPECT_FALSE(instrument.IsValid());
+}
+
+TEST(Instrument, NoCardVerificationNumberIsInvalid) {
+ Instrument instrument(ASCIIToUTF16(kPrimaryAccountNumber),
+ base::string16(),
+ 12,
+ 2015,
+ Instrument::VISA,
+ GetTestShippingAddress().Pass());
+
+ EXPECT_FALSE(instrument.IsValid());
+}
+
+TEST(Instrument, TooShortCardVerificationNumberIsInvalid) {
+ Instrument instrument(ASCIIToUTF16(kPrimaryAccountNumber),
+ ASCIIToUTF16("12"),
+ 12,
+ 2015,
+ Instrument::VISA,
+ GetTestShippingAddress().Pass());
+
+ EXPECT_FALSE(instrument.IsValid());
+}
+
+TEST(Instrument, TooLongCardVerificationNumberIsInvalid) {
+ Instrument instrument(ASCIIToUTF16(kPrimaryAccountNumber),
+ ASCIIToUTF16("12345"),
+ 12,
+ 2015,
+ Instrument::VISA,
+ GetTestShippingAddress().Pass());
+
+ EXPECT_FALSE(instrument.IsValid());
+}
+
+TEST(Instrument, ZeroAsExpirationMonthIsInvalid) {
+ Instrument instrument(ASCIIToUTF16(kPrimaryAccountNumber),
+ ASCIIToUTF16(kCardVerificationNumber),
+ 0,
+ 2015,
+ Instrument::VISA,
+ GetTestShippingAddress().Pass());
+
+ EXPECT_FALSE(instrument.IsValid());
+}
+
+TEST(Instrument, TooLargeExpirationMonthIsInvalid) {
+ Instrument instrument(ASCIIToUTF16(kPrimaryAccountNumber),
+ ASCIIToUTF16(kCardVerificationNumber),
+ 13,
+ 2015,
+ Instrument::VISA,
+ GetTestShippingAddress().Pass());
+
+ EXPECT_FALSE(instrument.IsValid());
+}
+
+TEST(Instrument, TooSmallExpirationYearIsInvalid) {
+ Instrument instrument(ASCIIToUTF16(kPrimaryAccountNumber),
+ ASCIIToUTF16(kCardVerificationNumber),
+ 12,
+ 999,
+ Instrument::VISA,
+ GetTestShippingAddress().Pass());
+
+ EXPECT_FALSE(instrument.IsValid());
+}
+
+TEST(Instrument, TooLargeExpirationYearIsInvalid) {
+ Instrument instrument(ASCIIToUTF16(kPrimaryAccountNumber),
+ ASCIIToUTF16(kCardVerificationNumber),
+ 12,
+ 10000,
+ Instrument::VISA,
+ GetTestShippingAddress().Pass());
+
+ EXPECT_FALSE(instrument.IsValid());
+}
+
+TEST(Instrument, ToDictionary) {
+ base::DictionaryValue expected;
+ expected.SetString("type", "CREDIT_CARD");
+ expected.SetInteger("credit_card.exp_month", 12);
+ expected.SetInteger("credit_card.exp_year", 2015);
+ expected.SetString("credit_card.last_4_digits", kLastFourDigits);
+ expected.SetString("credit_card.fop_type", "VISA");
+ expected.SetString("credit_card.address.country_name_code", "US");
+ expected.SetString("credit_card.address.recipient_name",
+ "ship_recipient_name");
+ expected.SetString("credit_card.address.locality_name",
+ "ship_locality_name");
+ expected.SetString("credit_card.address.administrative_area_name",
+ "ship_admin_area_name");
+ expected.SetString("credit_card.address.postal_code_number",
+ "ship_postal_code_number");
+ base::ListValue* address_lines = new base::ListValue();
+ address_lines->AppendString("ship_address_line_1");
+ address_lines->AppendString("ship_address_line_2");
+ expected.Set("credit_card.address.address_line", address_lines);
+
+ Instrument instrument(ASCIIToUTF16(kPrimaryAccountNumber),
+ ASCIIToUTF16(kCardVerificationNumber),
+ 12,
+ 2015,
+ Instrument::VISA,
+ GetTestShippingAddress().Pass());
+
+ EXPECT_TRUE(expected.Equals(instrument.ToDictionary().get()));
+}
+
+} // namespace wallet
+} // namespace autofill