| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/strings/utf_string_conversions.h" | 5 #include "base/strings/utf_string_conversions.h" |
| 6 #include "base/values.h" | 6 #include "base/values.h" |
| 7 #include "components/autofill/content/browser/wallet/instrument.h" | 7 #include "components/autofill/content/browser/wallet/instrument.h" |
| 8 #include "components/autofill/content/browser/wallet/wallet_address.h" | 8 #include "components/autofill/content/browser/wallet/wallet_address.h" |
| 9 #include "components/autofill/content/browser/wallet/wallet_test_util.h" | 9 #include "components/autofill/content/browser/wallet/wallet_test_util.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 TEST(Instrument, LastFourDigits) { | 23 TEST(Instrument, LastFourDigits) { |
| 24 Instrument instrument(ASCIIToUTF16(kPrimaryAccountNumber), | 24 Instrument instrument(ASCIIToUTF16(kPrimaryAccountNumber), |
| 25 ASCIIToUTF16(kCardVerificationNumber), | 25 ASCIIToUTF16(kCardVerificationNumber), |
| 26 12, | 26 12, |
| 27 2015, | 27 2015, |
| 28 Instrument::VISA, | 28 Instrument::VISA, |
| 29 GetTestShippingAddress().Pass()); | 29 GetTestShippingAddress().Pass()); |
| 30 | 30 |
| 31 EXPECT_EQ(ASCIIToUTF16(kLastFourDigits), instrument.last_four_digits()); | 31 EXPECT_EQ(ASCIIToUTF16(kLastFourDigits), instrument.last_four_digits()); |
| 32 EXPECT_TRUE(instrument.IsValid()); | |
| 33 } | |
| 34 | |
| 35 TEST(Instrument, NoPrimaryAccountNumberIsInvalid) { | |
| 36 Instrument instrument(base::string16(), | |
| 37 ASCIIToUTF16(kCardVerificationNumber), | |
| 38 12, | |
| 39 2015, | |
| 40 Instrument::VISA, | |
| 41 GetTestShippingAddress().Pass()); | |
| 42 | |
| 43 EXPECT_FALSE(instrument.IsValid()); | |
| 44 } | |
| 45 | |
| 46 TEST(Instrument, TooShortPrimaryAccountNumberIsInvalid) { | |
| 47 Instrument instrument(ASCIIToUTF16("44447"), | |
| 48 ASCIIToUTF16(kCardVerificationNumber), | |
| 49 12, | |
| 50 2015, | |
| 51 Instrument::VISA, | |
| 52 GetTestShippingAddress().Pass()); | |
| 53 | |
| 54 EXPECT_FALSE(instrument.IsValid()); | |
| 55 } | |
| 56 | |
| 57 TEST(Instrument, TooLongPrimaryAccountNumberIsInvalid) { | |
| 58 Instrument instrument(ASCIIToUTF16("44444444444444444448"), | |
| 59 ASCIIToUTF16(kCardVerificationNumber), | |
| 60 12, | |
| 61 2015, | |
| 62 Instrument::VISA, | |
| 63 GetTestShippingAddress().Pass()); | |
| 64 | |
| 65 EXPECT_FALSE(instrument.IsValid()); | |
| 66 } | |
| 67 | |
| 68 TEST(Instrument, PrimaryAccountNumberNotPassingLuhnIsInvalid) { | |
| 69 Instrument instrument(ASCIIToUTF16("4444444444444444"), | |
| 70 ASCIIToUTF16(kCardVerificationNumber), | |
| 71 12, | |
| 72 2015, | |
| 73 Instrument::VISA, | |
| 74 GetTestShippingAddress().Pass()); | |
| 75 | |
| 76 EXPECT_FALSE(instrument.IsValid()); | |
| 77 } | |
| 78 | |
| 79 TEST(Instrument, NoCardVerificationNumberIsInvalid) { | |
| 80 Instrument instrument(ASCIIToUTF16(kPrimaryAccountNumber), | |
| 81 base::string16(), | |
| 82 12, | |
| 83 2015, | |
| 84 Instrument::VISA, | |
| 85 GetTestShippingAddress().Pass()); | |
| 86 | |
| 87 EXPECT_FALSE(instrument.IsValid()); | |
| 88 } | |
| 89 | |
| 90 TEST(Instrument, TooShortCardVerificationNumberIsInvalid) { | |
| 91 Instrument instrument(ASCIIToUTF16(kPrimaryAccountNumber), | |
| 92 ASCIIToUTF16("12"), | |
| 93 12, | |
| 94 2015, | |
| 95 Instrument::VISA, | |
| 96 GetTestShippingAddress().Pass()); | |
| 97 | |
| 98 EXPECT_FALSE(instrument.IsValid()); | |
| 99 } | |
| 100 | |
| 101 TEST(Instrument, TooLongCardVerificationNumberIsInvalid) { | |
| 102 Instrument instrument(ASCIIToUTF16(kPrimaryAccountNumber), | |
| 103 ASCIIToUTF16("12345"), | |
| 104 12, | |
| 105 2015, | |
| 106 Instrument::VISA, | |
| 107 GetTestShippingAddress().Pass()); | |
| 108 | |
| 109 EXPECT_FALSE(instrument.IsValid()); | |
| 110 } | |
| 111 | |
| 112 TEST(Instrument, ZeroAsExpirationMonthIsInvalid) { | |
| 113 Instrument instrument(ASCIIToUTF16(kPrimaryAccountNumber), | |
| 114 ASCIIToUTF16(kCardVerificationNumber), | |
| 115 0, | |
| 116 2015, | |
| 117 Instrument::VISA, | |
| 118 GetTestShippingAddress().Pass()); | |
| 119 | |
| 120 EXPECT_FALSE(instrument.IsValid()); | |
| 121 } | |
| 122 | |
| 123 TEST(Instrument, TooLargeExpirationMonthIsInvalid) { | |
| 124 Instrument instrument(ASCIIToUTF16(kPrimaryAccountNumber), | |
| 125 ASCIIToUTF16(kCardVerificationNumber), | |
| 126 13, | |
| 127 2015, | |
| 128 Instrument::VISA, | |
| 129 GetTestShippingAddress().Pass()); | |
| 130 | |
| 131 EXPECT_FALSE(instrument.IsValid()); | |
| 132 } | |
| 133 | |
| 134 TEST(Instrument, TooSmallExpirationYearIsInvalid) { | |
| 135 Instrument instrument(ASCIIToUTF16(kPrimaryAccountNumber), | |
| 136 ASCIIToUTF16(kCardVerificationNumber), | |
| 137 12, | |
| 138 999, | |
| 139 Instrument::VISA, | |
| 140 GetTestShippingAddress().Pass()); | |
| 141 | |
| 142 EXPECT_FALSE(instrument.IsValid()); | |
| 143 } | |
| 144 | |
| 145 TEST(Instrument, TooLargeExpirationYearIsInvalid) { | |
| 146 Instrument instrument(ASCIIToUTF16(kPrimaryAccountNumber), | |
| 147 ASCIIToUTF16(kCardVerificationNumber), | |
| 148 12, | |
| 149 10000, | |
| 150 Instrument::VISA, | |
| 151 GetTestShippingAddress().Pass()); | |
| 152 | |
| 153 EXPECT_FALSE(instrument.IsValid()); | |
| 154 } | 32 } |
| 155 | 33 |
| 156 TEST(Instrument, ToDictionary) { | 34 TEST(Instrument, ToDictionary) { |
| 157 base::DictionaryValue expected; | 35 base::DictionaryValue expected; |
| 158 expected.SetString("type", "CREDIT_CARD"); | 36 expected.SetString("type", "CREDIT_CARD"); |
| 159 expected.SetInteger("credit_card.exp_month", 12); | 37 expected.SetInteger("credit_card.exp_month", 12); |
| 160 expected.SetInteger("credit_card.exp_year", 2015); | 38 expected.SetInteger("credit_card.exp_year", 2015); |
| 161 expected.SetString("credit_card.last_4_digits", kLastFourDigits); | 39 expected.SetString("credit_card.last_4_digits", kLastFourDigits); |
| 162 expected.SetString("credit_card.fop_type", "VISA"); | 40 expected.SetString("credit_card.fop_type", "VISA"); |
| 163 expected.SetString("credit_card.address.country_name_code", "US"); | 41 expected.SetString("credit_card.address.country_name_code", "US"); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 179 12, | 57 12, |
| 180 2015, | 58 2015, |
| 181 Instrument::VISA, | 59 Instrument::VISA, |
| 182 GetTestShippingAddress().Pass()); | 60 GetTestShippingAddress().Pass()); |
| 183 | 61 |
| 184 EXPECT_TRUE(expected.Equals(instrument.ToDictionary().get())); | 62 EXPECT_TRUE(expected.Equals(instrument.ToDictionary().get())); |
| 185 } | 63 } |
| 186 | 64 |
| 187 } // namespace wallet | 65 } // namespace wallet |
| 188 } // namespace autofill | 66 } // namespace autofill |
| OLD | NEW |