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

Side by Side Diff: chrome/browser/autofill/wallet/instrument_unittest.cc

Issue 12434004: Move remaining Autofill code to //components/autofill. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix long lines Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 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 "base/utf_string_conversions.h"
6 #include "base/values.h"
7 #include "chrome/browser/autofill/wallet/instrument.h"
8 #include "chrome/browser/autofill/wallet/wallet_address.h"
9 #include "chrome/browser/autofill/wallet/wallet_test_util.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace {
13
14 const char kPrimaryAccountNumber[] = "4444444444444448";
15 const char kCardVerificationNumber[] = "123";
16 const char kLastFourDigits[] = "4448";
17
18 }
19
20 namespace autofill {
21 namespace wallet {
22
23 TEST(Instrument, LastFourDigits) {
24 Instrument instrument(ASCIIToUTF16(kPrimaryAccountNumber),
25 ASCIIToUTF16(kCardVerificationNumber),
26 12,
27 2015,
28 Instrument::VISA,
29 GetTestShippingAddress().Pass());
30
31 EXPECT_EQ(ASCIIToUTF16(kLastFourDigits), instrument.last_four_digits());
32 EXPECT_TRUE(instrument.IsValid());
33 }
34
35 TEST(Instrument, NoPrimaryAccountNumberIsInvalid) {
36 Instrument instrument(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 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 }
155
156 TEST(Instrument, ToDictionary) {
157 base::DictionaryValue expected;
158 expected.SetString("type", "CREDIT_CARD");
159 expected.SetInteger("credit_card.exp_month", 12);
160 expected.SetInteger("credit_card.exp_year", 2015);
161 expected.SetString("credit_card.last_4_digits", kLastFourDigits);
162 expected.SetString("credit_card.fop_type", "VISA");
163 expected.SetString("credit_card.address.country_name_code",
164 "ship_country_name_code");
165 expected.SetString("credit_card.address.recipient_name",
166 "ship_recipient_name");
167 expected.SetString("credit_card.address.locality_name",
168 "ship_locality_name");
169 expected.SetString("credit_card.address.administrative_area_name",
170 "ship_admin_area_name");
171 expected.SetString("credit_card.address.postal_code_number",
172 "ship_postal_code_number");
173 base::ListValue* address_lines = new base::ListValue();
174 address_lines->AppendString("ship_address_line_1");
175 address_lines->AppendString("ship_address_line_2");
176 expected.Set("credit_card.address.address_line", address_lines);
177
178 Instrument instrument(ASCIIToUTF16(kPrimaryAccountNumber),
179 ASCIIToUTF16(kCardVerificationNumber),
180 12,
181 2015,
182 Instrument::VISA,
183 GetTestShippingAddress().Pass());
184
185 EXPECT_TRUE(expected.Equals(instrument.ToDictionary().get()));
186 }
187
188 } // namespace wallet
189 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/autofill/wallet/instrument.cc ('k') | chrome/browser/autofill/wallet/required_action.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698