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
3 // found in the LICENSE file.
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/core/browser/autofill_field.h"
9 #include "components/autofill/core/browser/autofill_scanner.h"
10 #include "components/autofill/core/browser/credit_card_field.h"
11 #include "components/autofill/core/common/form_field_data.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 using base::ASCIIToUTF16
;
18 class CreditCardFieldTest
: public testing::Test
{
20 CreditCardFieldTest() {}
21 ~CreditCardFieldTest() override
{}
24 ScopedVector
<AutofillField
> list_
;
25 scoped_ptr
<const CreditCardField
> field_
;
26 ServerFieldTypeMap field_type_map_
;
28 // Parses the contents of |list_| as a form, and stores the result into
31 AutofillScanner
scanner(list_
.get());
32 scoped_ptr
<FormField
> field
= CreditCardField::Parse(&scanner
);
33 field_
= make_scoped_ptr(static_cast<CreditCardField
*>(field
.release()));
36 // Associates fields with their corresponding types, based on the previous
38 bool ClassifyField() {
39 return field_
->ClassifyField(&field_type_map_
);
43 DISALLOW_COPY_AND_ASSIGN(CreditCardFieldTest
);
46 TEST_F(CreditCardFieldTest
, Empty
) {
48 ASSERT_EQ(nullptr, field_
.get());
51 TEST_F(CreditCardFieldTest
, NonParse
) {
52 list_
.push_back(new AutofillField
);
54 ASSERT_EQ(nullptr, field_
.get());
57 TEST_F(CreditCardFieldTest
, ParseCreditCardNoNumber
) {
59 field
.form_control_type
= "text";
61 field
.label
= ASCIIToUTF16("Exp Month");
62 field
.name
= ASCIIToUTF16("ccmonth");
63 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("month1")));
65 field
.label
= ASCIIToUTF16("Exp Year");
66 field
.name
= ASCIIToUTF16("ccyear");
67 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("year2")));
70 ASSERT_EQ(nullptr, field_
.get());
73 TEST_F(CreditCardFieldTest
, ParseCreditCardNoDate
) {
75 field
.form_control_type
= "text";
77 field
.label
= ASCIIToUTF16("Card Number");
78 field
.name
= ASCIIToUTF16("card_number");
79 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("number1")));
82 ASSERT_EQ(nullptr, field_
.get());
85 TEST_F(CreditCardFieldTest
, ParseMiniumCreditCard
) {
87 field
.form_control_type
= "text";
89 field
.label
= ASCIIToUTF16("Card Number");
90 field
.name
= ASCIIToUTF16("card_number");
91 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("number1")));
93 field
.label
= ASCIIToUTF16("Exp Month");
94 field
.name
= ASCIIToUTF16("ccmonth");
95 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("month2")));
97 field
.label
= ASCIIToUTF16("Exp Year");
98 field
.name
= ASCIIToUTF16("ccyear");
99 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("year3")));
102 ASSERT_NE(nullptr, field_
.get());
103 EXPECT_TRUE(ClassifyField());
105 field_type_map_
.find(ASCIIToUTF16("number1")) != field_type_map_
.end());
106 EXPECT_EQ(CREDIT_CARD_NUMBER
, field_type_map_
[ASCIIToUTF16("number1")]);
108 field_type_map_
.find(ASCIIToUTF16("month2")) != field_type_map_
.end());
109 EXPECT_EQ(CREDIT_CARD_EXP_MONTH
, field_type_map_
[ASCIIToUTF16("month2")]);
111 field_type_map_
.find(ASCIIToUTF16("year3")) != field_type_map_
.end());
112 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR
,
113 field_type_map_
[ASCIIToUTF16("year3")]);
116 TEST_F(CreditCardFieldTest
, ParseFullCreditCard
) {
118 field
.form_control_type
= "text";
120 field
.label
= ASCIIToUTF16("Name on Card");
121 field
.name
= ASCIIToUTF16("name_on_card");
122 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("name")));
124 field
.label
= ASCIIToUTF16("Card Number");
125 field
.name
= ASCIIToUTF16("card_number");
126 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("number")));
128 field
.label
= ASCIIToUTF16("Exp Month");
129 field
.name
= ASCIIToUTF16("ccmonth");
130 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("month")));
132 field
.label
= ASCIIToUTF16("Exp Year");
133 field
.name
= ASCIIToUTF16("ccyear");
134 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("year")));
136 field
.label
= ASCIIToUTF16("Verification");
137 field
.name
= ASCIIToUTF16("verification");
138 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("cvc")));
140 field
.form_control_type
= "select-one";
141 field
.label
= ASCIIToUTF16("Card Type");
142 field
.name
= ASCIIToUTF16("card_type");
143 field
.option_contents
.push_back(ASCIIToUTF16("visa"));
144 field
.option_values
.push_back(ASCIIToUTF16("visa"));
145 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("type")));
148 ASSERT_NE(nullptr, field_
.get());
149 EXPECT_TRUE(ClassifyField());
151 field_type_map_
.find(ASCIIToUTF16("type")) != field_type_map_
.end());
152 EXPECT_EQ(CREDIT_CARD_TYPE
, field_type_map_
[ASCIIToUTF16("type")]);
154 field_type_map_
.find(ASCIIToUTF16("name")) != field_type_map_
.end());
155 EXPECT_EQ(CREDIT_CARD_NAME
, field_type_map_
[ASCIIToUTF16("name")]);
157 field_type_map_
.find(ASCIIToUTF16("number")) != field_type_map_
.end());
158 EXPECT_EQ(CREDIT_CARD_NUMBER
, field_type_map_
[ASCIIToUTF16("number")]);
160 field_type_map_
.find(ASCIIToUTF16("month")) != field_type_map_
.end());
161 EXPECT_EQ(CREDIT_CARD_EXP_MONTH
, field_type_map_
[ASCIIToUTF16("month")]);
163 field_type_map_
.find(ASCIIToUTF16("year")) != field_type_map_
.end());
164 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR
,
165 field_type_map_
[ASCIIToUTF16("year")]);
167 field_type_map_
.find(ASCIIToUTF16("cvc")) != field_type_map_
.end());
168 EXPECT_EQ(CREDIT_CARD_VERIFICATION_CODE
,
169 field_type_map_
[ASCIIToUTF16("cvc")]);
172 TEST_F(CreditCardFieldTest
, ParseExpMonthYear
) {
174 field
.form_control_type
= "text";
176 field
.label
= ASCIIToUTF16("Name on Card");
177 field
.name
= ASCIIToUTF16("name_on_card");
178 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("name1")));
180 field
.label
= ASCIIToUTF16("Card Number");
181 field
.name
= ASCIIToUTF16("card_number");
182 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("number2")));
184 field
.label
= ASCIIToUTF16("ExpDate Month / Year");
185 field
.name
= ASCIIToUTF16("ExpDate");
186 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("month3")));
188 field
.label
= ASCIIToUTF16("ExpDate Month / Year");
189 field
.name
= ASCIIToUTF16("ExpDate");
190 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("year4")));
193 ASSERT_NE(nullptr, field_
.get());
194 EXPECT_TRUE(ClassifyField());
196 field_type_map_
.find(ASCIIToUTF16("name1")) != field_type_map_
.end());
197 EXPECT_EQ(CREDIT_CARD_NAME
, field_type_map_
[ASCIIToUTF16("name1")]);
199 field_type_map_
.find(ASCIIToUTF16("number2")) != field_type_map_
.end());
200 EXPECT_EQ(CREDIT_CARD_NUMBER
, field_type_map_
[ASCIIToUTF16("number2")]);
202 field_type_map_
.find(ASCIIToUTF16("month3")) != field_type_map_
.end());
203 EXPECT_EQ(CREDIT_CARD_EXP_MONTH
, field_type_map_
[ASCIIToUTF16("month3")]);
205 field_type_map_
.find(ASCIIToUTF16("year4")) != field_type_map_
.end());
206 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR
,
207 field_type_map_
[ASCIIToUTF16("year4")]);
210 TEST_F(CreditCardFieldTest
, ParseExpMonthYear2
) {
212 field
.form_control_type
= "text";
214 field
.label
= ASCIIToUTF16("Name on Card");
215 field
.name
= ASCIIToUTF16("name_on_card");
216 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("name1")));
218 field
.label
= ASCIIToUTF16("Card Number");
219 field
.name
= ASCIIToUTF16("card_number");
220 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("number2")));
222 field
.label
= ASCIIToUTF16("Expiration date Month / Year");
223 field
.name
= ASCIIToUTF16("ExpDate");
224 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("month3")));
226 field
.label
= ASCIIToUTF16("Expiration date Month / Year");
227 field
.name
= ASCIIToUTF16("ExpDate");
228 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("year4")));
231 ASSERT_NE(nullptr, field_
.get());
232 EXPECT_TRUE(ClassifyField());
234 field_type_map_
.find(ASCIIToUTF16("name1")) != field_type_map_
.end());
235 EXPECT_EQ(CREDIT_CARD_NAME
, field_type_map_
[ASCIIToUTF16("name1")]);
237 field_type_map_
.find(ASCIIToUTF16("number2")) != field_type_map_
.end());
238 EXPECT_EQ(CREDIT_CARD_NUMBER
, field_type_map_
[ASCIIToUTF16("number2")]);
240 field_type_map_
.find(ASCIIToUTF16("month3")) != field_type_map_
.end());
241 EXPECT_EQ(CREDIT_CARD_EXP_MONTH
, field_type_map_
[ASCIIToUTF16("month3")]);
243 field_type_map_
.find(ASCIIToUTF16("year4")) != field_type_map_
.end());
244 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR
,
245 field_type_map_
[ASCIIToUTF16("year4")]);
248 TEST_F(CreditCardFieldTest
, ParseExpField
) {
250 field
.form_control_type
= "text";
252 field
.label
= ASCIIToUTF16("Name on Card");
253 field
.name
= ASCIIToUTF16("name_on_card");
254 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("name1")));
256 field
.label
= ASCIIToUTF16("Card Number");
257 field
.name
= ASCIIToUTF16("card_number");
258 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("number2")));
260 field
.label
= ASCIIToUTF16("Expiration Date (MM/YYYY)");
261 field
.name
= ASCIIToUTF16("cc_exp");
262 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("exp3")));
265 ASSERT_NE(nullptr, field_
.get());
266 EXPECT_TRUE(ClassifyField());
268 field_type_map_
.find(ASCIIToUTF16("name1")) != field_type_map_
.end());
269 EXPECT_EQ(CREDIT_CARD_NAME
, field_type_map_
[ASCIIToUTF16("name1")]);
271 field_type_map_
.find(ASCIIToUTF16("number2")) != field_type_map_
.end());
272 EXPECT_EQ(CREDIT_CARD_NUMBER
, field_type_map_
[ASCIIToUTF16("number2")]);
274 field_type_map_
.find(ASCIIToUTF16("exp3")) != field_type_map_
.end());
275 EXPECT_EQ(CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR
,
276 field_type_map_
[ASCIIToUTF16("exp3")]);
279 TEST_F(CreditCardFieldTest
, ParseExpField2DigitYear
) {
281 field
.form_control_type
= "text";
283 field
.label
= ASCIIToUTF16("Name on Card");
284 field
.name
= ASCIIToUTF16("name_on_card");
285 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("name1")));
287 field
.label
= ASCIIToUTF16("Card Number");
288 field
.name
= ASCIIToUTF16("card_number");
289 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("number2")));
291 field
.label
= ASCIIToUTF16("Expiration Date (MM/YY)");
292 field
.name
= ASCIIToUTF16("cc_exp");
293 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("exp3")));
296 ASSERT_NE(nullptr, field_
.get());
297 EXPECT_TRUE(ClassifyField());
299 field_type_map_
.find(ASCIIToUTF16("name1")) != field_type_map_
.end());
300 EXPECT_EQ(CREDIT_CARD_NAME
, field_type_map_
[ASCIIToUTF16("name1")]);
302 field_type_map_
.find(ASCIIToUTF16("number2")) != field_type_map_
.end());
303 EXPECT_EQ(CREDIT_CARD_NUMBER
, field_type_map_
[ASCIIToUTF16("number2")]);
305 field_type_map_
.find(ASCIIToUTF16("exp3")) != field_type_map_
.end());
306 EXPECT_EQ(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR
,
307 field_type_map_
[ASCIIToUTF16("exp3")]);
310 TEST_F(CreditCardFieldTest
, ParseExpField2DigitYearDueToMaxLength
) {
312 field
.form_control_type
= "text";
314 field
.label
= ASCIIToUTF16("Name on Card");
315 field
.name
= ASCIIToUTF16("name_on_card");
316 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("name1")));
318 field
.label
= ASCIIToUTF16("Card Number");
319 field
.name
= ASCIIToUTF16("card_number");
320 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("number2")));
322 field
.label
= ASCIIToUTF16("Expiration Date");
323 field
.name
= ASCIIToUTF16("cc_exp");
324 field
.max_length
= 6; // Cannot fit YYYY-MM.
325 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("exp3")));
328 ASSERT_NE(nullptr, field_
.get());
329 EXPECT_TRUE(ClassifyField());
331 field_type_map_
.find(ASCIIToUTF16("name1")) != field_type_map_
.end());
332 EXPECT_EQ(CREDIT_CARD_NAME
, field_type_map_
[ASCIIToUTF16("name1")]);
334 field_type_map_
.find(ASCIIToUTF16("number2")) != field_type_map_
.end());
335 EXPECT_EQ(CREDIT_CARD_NUMBER
, field_type_map_
[ASCIIToUTF16("number2")]);
337 field_type_map_
.find(ASCIIToUTF16("exp3")) != field_type_map_
.end());
338 EXPECT_EQ(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR
,
339 field_type_map_
[ASCIIToUTF16("exp3")]);
342 TEST_F(CreditCardFieldTest
, ParseExpField4DigitYear
) {
344 field
.form_control_type
= "text";
346 field
.label
= ASCIIToUTF16("Name on Card");
347 field
.name
= ASCIIToUTF16("name_on_card");
348 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("name1")));
350 field
.label
= ASCIIToUTF16("Card Number");
351 field
.name
= ASCIIToUTF16("card_number");
352 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("number2")));
354 field
.label
= ASCIIToUTF16("MM / YYYY");
355 field
.name
= ASCIIToUTF16("cc_exp");
356 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("exp3")));
359 ASSERT_NE(nullptr, field_
.get());
360 EXPECT_TRUE(ClassifyField());
362 field_type_map_
.find(ASCIIToUTF16("name1")) != field_type_map_
.end());
363 EXPECT_EQ(CREDIT_CARD_NAME
, field_type_map_
[ASCIIToUTF16("name1")]);
365 field_type_map_
.find(ASCIIToUTF16("number2")) != field_type_map_
.end());
366 EXPECT_EQ(CREDIT_CARD_NUMBER
, field_type_map_
[ASCIIToUTF16("number2")]);
368 field_type_map_
.find(ASCIIToUTF16("exp3")) != field_type_map_
.end());
369 EXPECT_EQ(CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR
,
370 field_type_map_
[ASCIIToUTF16("exp3")]);
373 TEST_F(CreditCardFieldTest
, ParseCreditCardHolderNameWithCCFullName
) {
375 field
.form_control_type
= "text";
377 field
.label
= ASCIIToUTF16("Name");
378 field
.name
= ASCIIToUTF16("ccfullname");
379 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("name1")));
382 ASSERT_NE(nullptr, field_
.get());
383 EXPECT_TRUE(ClassifyField());
385 field_type_map_
.find(ASCIIToUTF16("name1")) != field_type_map_
.end());
386 EXPECT_EQ(CREDIT_CARD_NAME
, field_type_map_
[ASCIIToUTF16("name1")]);
389 // Verifies that <input type="month"> controls are able to be parsed correctly.
390 TEST_F(CreditCardFieldTest
, ParseMonthControl
) {
393 field
.form_control_type
= "text";
394 field
.label
= ASCIIToUTF16("Card number:");
395 field
.name
= ASCIIToUTF16("ccnumber");
396 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("number1")));
398 field
.form_control_type
= "month";
399 field
.label
= ASCIIToUTF16("Expiration date:");
400 field
.name
= ASCIIToUTF16("ccexp");
401 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("date2")));
404 ASSERT_NE(nullptr, field_
.get());
405 EXPECT_TRUE(ClassifyField());
407 field_type_map_
.find(ASCIIToUTF16("number1")) != field_type_map_
.end());
408 EXPECT_EQ(CREDIT_CARD_NUMBER
,
409 field_type_map_
[ASCIIToUTF16("number1")]);
411 field_type_map_
.find(ASCIIToUTF16("date2")) != field_type_map_
.end());
412 EXPECT_EQ(CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR
,
413 field_type_map_
[ASCIIToUTF16("date2")]);
416 // Verify that heuristics <input name="ccyear" maxlength="2"/> considers
417 // *maxlength* attribute while parsing 2 Digit expiration year.
418 TEST_F(CreditCardFieldTest
, ParseCreditCardExpYear_2DigitMaxLength
) {
420 field
.form_control_type
= "text";
422 field
.label
= ASCIIToUTF16("Card Number");
423 field
.name
= ASCIIToUTF16("card_number");
424 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("number")));
426 field
.label
= ASCIIToUTF16("Expiration Date");
427 field
.name
= ASCIIToUTF16("ccmonth");
428 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("month")));
430 field
.name
= ASCIIToUTF16("ccyear");
431 field
.max_length
= 2;
432 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("year")));
435 ASSERT_NE(nullptr, field_
.get());
436 EXPECT_TRUE(ClassifyField());
437 ASSERT_TRUE(field_type_map_
.find(ASCIIToUTF16("number")) !=
438 field_type_map_
.end());
439 EXPECT_EQ(CREDIT_CARD_NUMBER
, field_type_map_
[ASCIIToUTF16("number")]);
440 ASSERT_TRUE(field_type_map_
.find(ASCIIToUTF16("month")) !=
441 field_type_map_
.end());
442 EXPECT_EQ(CREDIT_CARD_EXP_MONTH
, field_type_map_
[ASCIIToUTF16("month")]);
443 ASSERT_TRUE(field_type_map_
.find(ASCIIToUTF16("year")) !=
444 field_type_map_
.end());
445 EXPECT_EQ(CREDIT_CARD_EXP_2_DIGIT_YEAR
,
446 field_type_map_
[ASCIIToUTF16("year")]);
449 TEST_F(CreditCardFieldTest
, ParseCreditCardNumberWithSplit
) {
451 field
.form_control_type
= "text";
453 field
.label
= ASCIIToUTF16("Card Number");
454 field
.name
= ASCIIToUTF16("card_number_q1");
455 field
.max_length
= 4;
456 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("number1")));
458 field
.label
= ASCIIToUTF16("Card Number");
459 field
.name
= ASCIIToUTF16("card_number_q2");
460 field
.max_length
= 4;
461 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("number2")));
463 field
.label
= ASCIIToUTF16("Card Number");
464 field
.name
= ASCIIToUTF16("card_number_q3");
465 field
.max_length
= 4;
466 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("number3")));
468 // For last credit card number input field it simply ignores the |max_length|
469 // attribute. So even having a very big number, does not conside it an invalid
470 // split for autofilling.
471 field
.label
= ASCIIToUTF16("Card Number");
472 field
.name
= ASCIIToUTF16("card_number_q4");
473 field
.max_length
= 20;
474 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("number4")));
476 field
.label
= ASCIIToUTF16("Exp Month");
477 field
.name
= ASCIIToUTF16("ccmonth");
478 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("month5")));
480 field
.label
= ASCIIToUTF16("Exp Year");
481 field
.name
= ASCIIToUTF16("ccyear");
482 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("year6")));
485 ASSERT_NE(nullptr, field_
.get());
486 EXPECT_TRUE(ClassifyField());
488 ASSERT_TRUE(field_type_map_
.find(ASCIIToUTF16("number1")) !=
489 field_type_map_
.end());
490 EXPECT_EQ(CREDIT_CARD_NUMBER
, field_type_map_
[ASCIIToUTF16("number1")]);
491 EXPECT_EQ(0U, list_
[0]->credit_card_number_offset());
493 ASSERT_TRUE(field_type_map_
.find(ASCIIToUTF16("number2")) !=
494 field_type_map_
.end());
495 EXPECT_EQ(CREDIT_CARD_NUMBER
, field_type_map_
[ASCIIToUTF16("number2")]);
496 EXPECT_EQ(4U, list_
[1]->credit_card_number_offset());
498 ASSERT_TRUE(field_type_map_
.find(ASCIIToUTF16("number3")) !=
499 field_type_map_
.end());
500 EXPECT_EQ(CREDIT_CARD_NUMBER
, field_type_map_
[ASCIIToUTF16("number3")]);
501 EXPECT_EQ(8U, list_
[2]->credit_card_number_offset());
503 ASSERT_TRUE(field_type_map_
.find(ASCIIToUTF16("number4")) !=
504 field_type_map_
.end());
505 EXPECT_EQ(CREDIT_CARD_NUMBER
, field_type_map_
[ASCIIToUTF16("number4")]);
506 EXPECT_EQ(12U, list_
[3]->credit_card_number_offset());
508 ASSERT_TRUE(field_type_map_
.find(ASCIIToUTF16("month5")) !=
509 field_type_map_
.end());
510 EXPECT_EQ(CREDIT_CARD_EXP_MONTH
, field_type_map_
[ASCIIToUTF16("month5")]);
511 ASSERT_TRUE(field_type_map_
.find(ASCIIToUTF16("year6")) !=
512 field_type_map_
.end());
513 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR
,
514 field_type_map_
[ASCIIToUTF16("year6")]);
517 TEST_F(CreditCardFieldTest
, ParseMultipleCreditCardNumbers
) {
519 field
.form_control_type
= "text";
521 field
.label
= ASCIIToUTF16("Name on Card");
522 field
.name
= ASCIIToUTF16("name_on_card");
523 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("name1")));
525 field
.label
= ASCIIToUTF16("Card Number");
526 field
.name
= ASCIIToUTF16("card_number");
527 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("number2")));
529 field
.label
= ASCIIToUTF16("Confirm Card Number");
530 field
.name
= ASCIIToUTF16("confirm_card_number");
531 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("number3")));
533 field
.label
= ASCIIToUTF16("Exp Month");
534 field
.name
= ASCIIToUTF16("ccmonth");
535 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("month4")));
537 field
.label
= ASCIIToUTF16("Exp Year");
538 field
.name
= ASCIIToUTF16("ccyear");
539 list_
.push_back(new AutofillField(field
, ASCIIToUTF16("year5")));
542 ASSERT_NE(nullptr, field_
.get());
543 EXPECT_TRUE(ClassifyField());
545 ASSERT_TRUE(field_type_map_
.find(ASCIIToUTF16("name1")) !=
546 field_type_map_
.end());
547 EXPECT_EQ(CREDIT_CARD_NAME
, field_type_map_
[ASCIIToUTF16("name1")]);
548 ASSERT_TRUE(field_type_map_
.find(ASCIIToUTF16("number2")) !=
549 field_type_map_
.end());
550 EXPECT_EQ(CREDIT_CARD_NUMBER
, field_type_map_
[ASCIIToUTF16("number2")]);
551 ASSERT_TRUE(field_type_map_
.find(ASCIIToUTF16("number3")) !=
552 field_type_map_
.end());
553 EXPECT_EQ(CREDIT_CARD_NUMBER
, field_type_map_
[ASCIIToUTF16("number3")]);
554 ASSERT_TRUE(field_type_map_
.find(ASCIIToUTF16("month4")) !=
555 field_type_map_
.end());
556 EXPECT_EQ(CREDIT_CARD_EXP_MONTH
, field_type_map_
[ASCIIToUTF16("month4")]);
557 ASSERT_TRUE(field_type_map_
.find(ASCIIToUTF16("year5")) !=
558 field_type_map_
.end());
559 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR
,
560 field_type_map_
[ASCIIToUTF16("year5")]);
563 } // namespace autofill