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

Side by Side Diff: components/autofill/browser/credit_card_field_unittest.cc

Issue 17392006: In components/autofill, move browser/ to core/browser/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to fix conflicts Created 7 years, 6 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) 2011 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/memory/scoped_ptr.h"
6 #include "base/memory/scoped_vector.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "components/autofill/browser/autofill_field.h"
9 #include "components/autofill/browser/autofill_scanner.h"
10 #include "components/autofill/browser/credit_card_field.h"
11 #include "components/autofill/core/common/form_field_data.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace autofill {
15
16 class CreditCardFieldTest : public testing::Test {
17 public:
18 CreditCardFieldTest() {}
19
20 protected:
21 ScopedVector<const AutofillField> list_;
22 scoped_ptr<CreditCardField> field_;
23 FieldTypeMap field_type_map_;
24
25 // Downcast for tests.
26 static CreditCardField* Parse(AutofillScanner* scanner) {
27 return static_cast<CreditCardField*>(CreditCardField::Parse(scanner));
28 }
29
30 private:
31 DISALLOW_COPY_AND_ASSIGN(CreditCardFieldTest);
32 };
33
34 TEST_F(CreditCardFieldTest, Empty) {
35 AutofillScanner scanner(list_.get());
36 field_.reset(Parse(&scanner));
37 ASSERT_EQ(static_cast<CreditCardField*>(NULL), field_.get());
38 }
39
40 TEST_F(CreditCardFieldTest, NonParse) {
41 list_.push_back(new AutofillField);
42 AutofillScanner scanner(list_.get());
43 field_.reset(Parse(&scanner));
44 ASSERT_EQ(static_cast<CreditCardField*>(NULL), field_.get());
45 }
46
47 TEST_F(CreditCardFieldTest, ParseCreditCardNoNumber) {
48 FormFieldData field;
49 field.form_control_type = "text";
50
51 field.label = ASCIIToUTF16("Exp Month");
52 field.name = ASCIIToUTF16("ccmonth");
53 list_.push_back(new AutofillField(field, ASCIIToUTF16("month1")));
54
55 field.label = ASCIIToUTF16("Exp Year");
56 field.name = ASCIIToUTF16("ccyear");
57 list_.push_back(new AutofillField(field, ASCIIToUTF16("year2")));
58
59 AutofillScanner scanner(list_.get());
60 field_.reset(Parse(&scanner));
61 ASSERT_EQ(static_cast<CreditCardField*>(NULL), field_.get());
62 }
63
64 TEST_F(CreditCardFieldTest, ParseCreditCardNoDate) {
65 FormFieldData field;
66 field.form_control_type = "text";
67
68 field.label = ASCIIToUTF16("Card Number");
69 field.name = ASCIIToUTF16("card_number");
70 list_.push_back(new AutofillField(field, ASCIIToUTF16("number1")));
71
72 AutofillScanner scanner(list_.get());
73 field_.reset(Parse(&scanner));
74 ASSERT_EQ(static_cast<CreditCardField*>(NULL), field_.get());
75 }
76
77 TEST_F(CreditCardFieldTest, ParseMiniumCreditCard) {
78 FormFieldData field;
79 field.form_control_type = "text";
80
81 field.label = ASCIIToUTF16("Card Number");
82 field.name = ASCIIToUTF16("card_number");
83 list_.push_back(new AutofillField(field, ASCIIToUTF16("number1")));
84
85 field.label = ASCIIToUTF16("Exp Month");
86 field.name = ASCIIToUTF16("ccmonth");
87 list_.push_back(new AutofillField(field, ASCIIToUTF16("month2")));
88
89 field.label = ASCIIToUTF16("Exp Year");
90 field.name = ASCIIToUTF16("ccyear");
91 list_.push_back(new AutofillField(field, ASCIIToUTF16("year3")));
92
93 AutofillScanner scanner(list_.get());
94 field_.reset(Parse(&scanner));
95 ASSERT_NE(static_cast<CreditCardField*>(NULL), field_.get());
96 ASSERT_TRUE(field_->ClassifyField(&field_type_map_));
97 ASSERT_TRUE(
98 field_type_map_.find(ASCIIToUTF16("number1")) != field_type_map_.end());
99 EXPECT_EQ(CREDIT_CARD_NUMBER, field_type_map_[ASCIIToUTF16("number1")]);
100 ASSERT_TRUE(
101 field_type_map_.find(ASCIIToUTF16("month2")) != field_type_map_.end());
102 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, field_type_map_[ASCIIToUTF16("month2")]);
103 ASSERT_TRUE(
104 field_type_map_.find(ASCIIToUTF16("year3")) != field_type_map_.end());
105 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR,
106 field_type_map_[ASCIIToUTF16("year3")]);
107 }
108
109 TEST_F(CreditCardFieldTest, ParseFullCreditCard) {
110 FormFieldData field;
111 field.form_control_type = "text";
112
113 field.label = ASCIIToUTF16("Card Type");
114 field.name = ASCIIToUTF16("card_type");
115 list_.push_back(new AutofillField(field, ASCIIToUTF16("type")));
116
117 field.label = ASCIIToUTF16("Name on Card");
118 field.name = ASCIIToUTF16("name_on_card");
119 list_.push_back(new AutofillField(field, ASCIIToUTF16("name")));
120
121 field.label = ASCIIToUTF16("Card Number");
122 field.name = ASCIIToUTF16("card_number");
123 list_.push_back(new AutofillField(field, ASCIIToUTF16("number")));
124
125 field.label = ASCIIToUTF16("Exp Month");
126 field.name = ASCIIToUTF16("ccmonth");
127 list_.push_back(new AutofillField(field, ASCIIToUTF16("month")));
128
129 field.label = ASCIIToUTF16("Exp Year");
130 field.name = ASCIIToUTF16("ccyear");
131 list_.push_back(new AutofillField(field, ASCIIToUTF16("year")));
132
133 field.label = ASCIIToUTF16("Verification");
134 field.name = ASCIIToUTF16("verification");
135 list_.push_back(new AutofillField(field, ASCIIToUTF16("cvc")));
136
137 AutofillScanner scanner(list_.get());
138 field_.reset(Parse(&scanner));
139 ASSERT_NE(static_cast<CreditCardField*>(NULL), field_.get());
140 ASSERT_TRUE(field_->ClassifyField(&field_type_map_));
141 ASSERT_TRUE(
142 field_type_map_.find(ASCIIToUTF16("type")) != field_type_map_.end());
143 EXPECT_EQ(CREDIT_CARD_TYPE, field_type_map_[ASCIIToUTF16("type")]);
144 ASSERT_TRUE(
145 field_type_map_.find(ASCIIToUTF16("name")) != field_type_map_.end());
146 EXPECT_EQ(CREDIT_CARD_NAME, field_type_map_[ASCIIToUTF16("name")]);
147 ASSERT_TRUE(
148 field_type_map_.find(ASCIIToUTF16("number")) != field_type_map_.end());
149 EXPECT_EQ(CREDIT_CARD_NUMBER, field_type_map_[ASCIIToUTF16("number")]);
150 ASSERT_TRUE(
151 field_type_map_.find(ASCIIToUTF16("month")) != field_type_map_.end());
152 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, field_type_map_[ASCIIToUTF16("month")]);
153 ASSERT_TRUE(
154 field_type_map_.find(ASCIIToUTF16("year")) != field_type_map_.end());
155 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR,
156 field_type_map_[ASCIIToUTF16("year")]);
157 ASSERT_TRUE(
158 field_type_map_.find(ASCIIToUTF16("cvc")) != field_type_map_.end());
159 EXPECT_EQ(CREDIT_CARD_VERIFICATION_CODE,
160 field_type_map_[ASCIIToUTF16("cvc")]);
161 }
162
163 TEST_F(CreditCardFieldTest, ParseExpMonthYear) {
164 FormFieldData field;
165 field.form_control_type = "text";
166
167 field.label = ASCIIToUTF16("Name on Card");
168 field.name = ASCIIToUTF16("name_on_card");
169 list_.push_back(new AutofillField(field, ASCIIToUTF16("name1")));
170
171 field.label = ASCIIToUTF16("Card Number");
172 field.name = ASCIIToUTF16("card_number");
173 list_.push_back(new AutofillField(field, ASCIIToUTF16("number2")));
174
175 field.label = ASCIIToUTF16("ExpDate Month / Year");
176 field.name = ASCIIToUTF16("ExpDate");
177 list_.push_back(new AutofillField(field, ASCIIToUTF16("month3")));
178
179 field.label = ASCIIToUTF16("ExpDate Month / Year");
180 field.name = ASCIIToUTF16("ExpDate");
181 list_.push_back(new AutofillField(field, ASCIIToUTF16("year4")));
182
183 AutofillScanner scanner(list_.get());
184 field_.reset(Parse(&scanner));
185 ASSERT_NE(static_cast<CreditCardField*>(NULL), field_.get());
186 ASSERT_TRUE(field_->ClassifyField(&field_type_map_));
187 ASSERT_TRUE(
188 field_type_map_.find(ASCIIToUTF16("name1")) != field_type_map_.end());
189 EXPECT_EQ(CREDIT_CARD_NAME, field_type_map_[ASCIIToUTF16("name1")]);
190 ASSERT_TRUE(
191 field_type_map_.find(ASCIIToUTF16("number2")) != field_type_map_.end());
192 EXPECT_EQ(CREDIT_CARD_NUMBER, field_type_map_[ASCIIToUTF16("number2")]);
193 ASSERT_TRUE(
194 field_type_map_.find(ASCIIToUTF16("month3")) != field_type_map_.end());
195 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, field_type_map_[ASCIIToUTF16("month3")]);
196 ASSERT_TRUE(
197 field_type_map_.find(ASCIIToUTF16("year4")) != field_type_map_.end());
198 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR,
199 field_type_map_[ASCIIToUTF16("year4")]);
200 }
201
202 TEST_F(CreditCardFieldTest, ParseExpMonthYear2) {
203 FormFieldData field;
204 field.form_control_type = "text";
205
206 field.label = ASCIIToUTF16("Name on Card");
207 field.name = ASCIIToUTF16("name_on_card");
208 list_.push_back(new AutofillField(field, ASCIIToUTF16("name1")));
209
210 field.label = ASCIIToUTF16("Card Number");
211 field.name = ASCIIToUTF16("card_number");
212 list_.push_back(new AutofillField(field, ASCIIToUTF16("number2")));
213
214 field.label = ASCIIToUTF16("Expiration date Month / Year");
215 field.name = ASCIIToUTF16("ExpDate");
216 list_.push_back(new AutofillField(field, ASCIIToUTF16("month3")));
217
218 field.label = ASCIIToUTF16("Expiration date Month / Year");
219 field.name = ASCIIToUTF16("ExpDate");
220 list_.push_back(new AutofillField(field, ASCIIToUTF16("year4")));
221
222 AutofillScanner scanner(list_.get());
223 field_.reset(Parse(&scanner));
224 ASSERT_NE(static_cast<CreditCardField*>(NULL), field_.get());
225 ASSERT_TRUE(field_->ClassifyField(&field_type_map_));
226 ASSERT_TRUE(
227 field_type_map_.find(ASCIIToUTF16("name1")) != field_type_map_.end());
228 EXPECT_EQ(CREDIT_CARD_NAME, field_type_map_[ASCIIToUTF16("name1")]);
229 ASSERT_TRUE(
230 field_type_map_.find(ASCIIToUTF16("number2")) != field_type_map_.end());
231 EXPECT_EQ(CREDIT_CARD_NUMBER, field_type_map_[ASCIIToUTF16("number2")]);
232 ASSERT_TRUE(
233 field_type_map_.find(ASCIIToUTF16("month3")) != field_type_map_.end());
234 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, field_type_map_[ASCIIToUTF16("month3")]);
235 ASSERT_TRUE(
236 field_type_map_.find(ASCIIToUTF16("year4")) != field_type_map_.end());
237 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR,
238 field_type_map_[ASCIIToUTF16("year4")]);
239 }
240
241 TEST_F(CreditCardFieldTest, ParseExpField) {
242 FormFieldData field;
243 field.form_control_type = "text";
244
245 field.label = ASCIIToUTF16("Name on Card");
246 field.name = ASCIIToUTF16("name_on_card");
247 list_.push_back(new AutofillField(field, ASCIIToUTF16("name1")));
248
249 field.label = ASCIIToUTF16("Card Number");
250 field.name = ASCIIToUTF16("card_number");
251 list_.push_back(new AutofillField(field, ASCIIToUTF16("number2")));
252
253 field.label = ASCIIToUTF16("Expiration Date (MM/YYYY)");
254 field.name = ASCIIToUTF16("cc_exp");
255 list_.push_back(new AutofillField(field, ASCIIToUTF16("exp3")));
256
257 AutofillScanner scanner(list_.get());
258 field_.reset(Parse(&scanner));
259 ASSERT_NE(static_cast<CreditCardField*>(NULL), field_.get());
260 ASSERT_TRUE(field_->ClassifyField(&field_type_map_));
261 ASSERT_TRUE(
262 field_type_map_.find(ASCIIToUTF16("name1")) != field_type_map_.end());
263 EXPECT_EQ(CREDIT_CARD_NAME, field_type_map_[ASCIIToUTF16("name1")]);
264 ASSERT_TRUE(
265 field_type_map_.find(ASCIIToUTF16("number2")) != field_type_map_.end());
266 EXPECT_EQ(CREDIT_CARD_NUMBER, field_type_map_[ASCIIToUTF16("number2")]);
267 ASSERT_TRUE(
268 field_type_map_.find(ASCIIToUTF16("exp3")) != field_type_map_.end());
269 EXPECT_EQ(CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR,
270 field_type_map_[ASCIIToUTF16("exp3")]);
271 }
272
273 TEST_F(CreditCardFieldTest, ParseExpField2DigitYear) {
274 FormFieldData field;
275 field.form_control_type = "text";
276
277 field.label = ASCIIToUTF16("Name on Card");
278 field.name = ASCIIToUTF16("name_on_card");
279 list_.push_back(new AutofillField(field, ASCIIToUTF16("name1")));
280
281 field.label = ASCIIToUTF16("Card Number");
282 field.name = ASCIIToUTF16("card_number");
283 list_.push_back(new AutofillField(field, ASCIIToUTF16("number2")));
284
285 field.label = ASCIIToUTF16("Expiration Date (MM/YY)");
286 field.name = ASCIIToUTF16("cc_exp");
287 list_.push_back(new AutofillField(field, ASCIIToUTF16("exp3")));
288
289 AutofillScanner scanner(list_.get());
290 field_.reset(Parse(&scanner));
291 ASSERT_NE(static_cast<CreditCardField*>(NULL), field_.get());
292 ASSERT_TRUE(field_->ClassifyField(&field_type_map_));
293 ASSERT_TRUE(
294 field_type_map_.find(ASCIIToUTF16("name1")) != field_type_map_.end());
295 EXPECT_EQ(CREDIT_CARD_NAME, field_type_map_[ASCIIToUTF16("name1")]);
296 ASSERT_TRUE(
297 field_type_map_.find(ASCIIToUTF16("number2")) != field_type_map_.end());
298 EXPECT_EQ(CREDIT_CARD_NUMBER, field_type_map_[ASCIIToUTF16("number2")]);
299 ASSERT_TRUE(
300 field_type_map_.find(ASCIIToUTF16("exp3")) != field_type_map_.end());
301 EXPECT_EQ(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR,
302 field_type_map_[ASCIIToUTF16("exp3")]);
303 }
304
305 TEST_F(CreditCardFieldTest, ParseCreditCardHolderNameWithCCFullName) {
306 FormFieldData field;
307 field.form_control_type = "text";
308
309 field.label = ASCIIToUTF16("Name");
310 field.name = ASCIIToUTF16("ccfullname");
311 list_.push_back(new AutofillField(field, ASCIIToUTF16("name1")));
312
313 AutofillScanner scanner(list_.get());
314 field_.reset(Parse(&scanner));
315 ASSERT_NE(static_cast<CreditCardField*>(NULL), field_.get());
316 ASSERT_TRUE(field_->ClassifyField(&field_type_map_));
317 ASSERT_TRUE(
318 field_type_map_.find(ASCIIToUTF16("name1")) != field_type_map_.end());
319 EXPECT_EQ(CREDIT_CARD_NAME, field_type_map_[ASCIIToUTF16("name1")]);
320 }
321
322 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/browser/credit_card_field.cc ('k') | components/autofill/browser/credit_card_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698