Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / components / autofill / core / browser / credit_card_field_unittest.cc
blob1297175635ca0232899768344b4ea8e437d6bd9f
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;
16 namespace autofill {
18 class CreditCardFieldTest : public testing::Test {
19 public:
20 CreditCardFieldTest() {}
21 ~CreditCardFieldTest() override {}
23 protected:
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
29 // |field_|.
30 void Parse() {
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
37 // call to Parse().
38 bool ClassifyField() {
39 return field_->ClassifyField(&field_type_map_);
42 private:
43 DISALLOW_COPY_AND_ASSIGN(CreditCardFieldTest);
46 TEST_F(CreditCardFieldTest, Empty) {
47 Parse();
48 ASSERT_EQ(nullptr, field_.get());
51 TEST_F(CreditCardFieldTest, NonParse) {
52 list_.push_back(new AutofillField);
53 Parse();
54 ASSERT_EQ(nullptr, field_.get());
57 TEST_F(CreditCardFieldTest, ParseCreditCardNoNumber) {
58 FormFieldData field;
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")));
69 Parse();
70 ASSERT_EQ(nullptr, field_.get());
73 TEST_F(CreditCardFieldTest, ParseCreditCardNoDate) {
74 FormFieldData field;
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")));
81 Parse();
82 ASSERT_EQ(nullptr, field_.get());
85 TEST_F(CreditCardFieldTest, ParseMiniumCreditCard) {
86 FormFieldData field;
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")));
101 Parse();
102 ASSERT_NE(nullptr, field_.get());
103 EXPECT_TRUE(ClassifyField());
104 ASSERT_TRUE(
105 field_type_map_.find(ASCIIToUTF16("number1")) != field_type_map_.end());
106 EXPECT_EQ(CREDIT_CARD_NUMBER, field_type_map_[ASCIIToUTF16("number1")]);
107 ASSERT_TRUE(
108 field_type_map_.find(ASCIIToUTF16("month2")) != field_type_map_.end());
109 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, field_type_map_[ASCIIToUTF16("month2")]);
110 ASSERT_TRUE(
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) {
117 FormFieldData field;
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")));
147 Parse();
148 ASSERT_NE(nullptr, field_.get());
149 EXPECT_TRUE(ClassifyField());
150 ASSERT_TRUE(
151 field_type_map_.find(ASCIIToUTF16("type")) != field_type_map_.end());
152 EXPECT_EQ(CREDIT_CARD_TYPE, field_type_map_[ASCIIToUTF16("type")]);
153 ASSERT_TRUE(
154 field_type_map_.find(ASCIIToUTF16("name")) != field_type_map_.end());
155 EXPECT_EQ(CREDIT_CARD_NAME, field_type_map_[ASCIIToUTF16("name")]);
156 ASSERT_TRUE(
157 field_type_map_.find(ASCIIToUTF16("number")) != field_type_map_.end());
158 EXPECT_EQ(CREDIT_CARD_NUMBER, field_type_map_[ASCIIToUTF16("number")]);
159 ASSERT_TRUE(
160 field_type_map_.find(ASCIIToUTF16("month")) != field_type_map_.end());
161 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, field_type_map_[ASCIIToUTF16("month")]);
162 ASSERT_TRUE(
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")]);
166 ASSERT_TRUE(
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) {
173 FormFieldData field;
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")));
192 Parse();
193 ASSERT_NE(nullptr, field_.get());
194 EXPECT_TRUE(ClassifyField());
195 ASSERT_TRUE(
196 field_type_map_.find(ASCIIToUTF16("name1")) != field_type_map_.end());
197 EXPECT_EQ(CREDIT_CARD_NAME, field_type_map_[ASCIIToUTF16("name1")]);
198 ASSERT_TRUE(
199 field_type_map_.find(ASCIIToUTF16("number2")) != field_type_map_.end());
200 EXPECT_EQ(CREDIT_CARD_NUMBER, field_type_map_[ASCIIToUTF16("number2")]);
201 ASSERT_TRUE(
202 field_type_map_.find(ASCIIToUTF16("month3")) != field_type_map_.end());
203 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, field_type_map_[ASCIIToUTF16("month3")]);
204 ASSERT_TRUE(
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) {
211 FormFieldData field;
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")));
230 Parse();
231 ASSERT_NE(nullptr, field_.get());
232 EXPECT_TRUE(ClassifyField());
233 ASSERT_TRUE(
234 field_type_map_.find(ASCIIToUTF16("name1")) != field_type_map_.end());
235 EXPECT_EQ(CREDIT_CARD_NAME, field_type_map_[ASCIIToUTF16("name1")]);
236 ASSERT_TRUE(
237 field_type_map_.find(ASCIIToUTF16("number2")) != field_type_map_.end());
238 EXPECT_EQ(CREDIT_CARD_NUMBER, field_type_map_[ASCIIToUTF16("number2")]);
239 ASSERT_TRUE(
240 field_type_map_.find(ASCIIToUTF16("month3")) != field_type_map_.end());
241 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, field_type_map_[ASCIIToUTF16("month3")]);
242 ASSERT_TRUE(
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) {
249 FormFieldData field;
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")));
264 Parse();
265 ASSERT_NE(nullptr, field_.get());
266 EXPECT_TRUE(ClassifyField());
267 ASSERT_TRUE(
268 field_type_map_.find(ASCIIToUTF16("name1")) != field_type_map_.end());
269 EXPECT_EQ(CREDIT_CARD_NAME, field_type_map_[ASCIIToUTF16("name1")]);
270 ASSERT_TRUE(
271 field_type_map_.find(ASCIIToUTF16("number2")) != field_type_map_.end());
272 EXPECT_EQ(CREDIT_CARD_NUMBER, field_type_map_[ASCIIToUTF16("number2")]);
273 ASSERT_TRUE(
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) {
280 FormFieldData field;
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")));
295 Parse();
296 ASSERT_NE(nullptr, field_.get());
297 EXPECT_TRUE(ClassifyField());
298 ASSERT_TRUE(
299 field_type_map_.find(ASCIIToUTF16("name1")) != field_type_map_.end());
300 EXPECT_EQ(CREDIT_CARD_NAME, field_type_map_[ASCIIToUTF16("name1")]);
301 ASSERT_TRUE(
302 field_type_map_.find(ASCIIToUTF16("number2")) != field_type_map_.end());
303 EXPECT_EQ(CREDIT_CARD_NUMBER, field_type_map_[ASCIIToUTF16("number2")]);
304 ASSERT_TRUE(
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) {
311 FormFieldData field;
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")));
327 Parse();
328 ASSERT_NE(nullptr, field_.get());
329 EXPECT_TRUE(ClassifyField());
330 ASSERT_TRUE(
331 field_type_map_.find(ASCIIToUTF16("name1")) != field_type_map_.end());
332 EXPECT_EQ(CREDIT_CARD_NAME, field_type_map_[ASCIIToUTF16("name1")]);
333 ASSERT_TRUE(
334 field_type_map_.find(ASCIIToUTF16("number2")) != field_type_map_.end());
335 EXPECT_EQ(CREDIT_CARD_NUMBER, field_type_map_[ASCIIToUTF16("number2")]);
336 ASSERT_TRUE(
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) {
343 FormFieldData field;
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")));
358 Parse();
359 ASSERT_NE(nullptr, field_.get());
360 EXPECT_TRUE(ClassifyField());
361 ASSERT_TRUE(
362 field_type_map_.find(ASCIIToUTF16("name1")) != field_type_map_.end());
363 EXPECT_EQ(CREDIT_CARD_NAME, field_type_map_[ASCIIToUTF16("name1")]);
364 ASSERT_TRUE(
365 field_type_map_.find(ASCIIToUTF16("number2")) != field_type_map_.end());
366 EXPECT_EQ(CREDIT_CARD_NUMBER, field_type_map_[ASCIIToUTF16("number2")]);
367 ASSERT_TRUE(
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) {
374 FormFieldData field;
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")));
381 Parse();
382 ASSERT_NE(nullptr, field_.get());
383 EXPECT_TRUE(ClassifyField());
384 ASSERT_TRUE(
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) {
391 FormFieldData field;
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")));
403 Parse();
404 ASSERT_NE(nullptr, field_.get());
405 EXPECT_TRUE(ClassifyField());
406 ASSERT_TRUE(
407 field_type_map_.find(ASCIIToUTF16("number1")) != field_type_map_.end());
408 EXPECT_EQ(CREDIT_CARD_NUMBER,
409 field_type_map_[ASCIIToUTF16("number1")]);
410 ASSERT_TRUE(
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) {
419 FormFieldData field;
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")));
434 Parse();
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) {
450 FormFieldData field;
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")));
484 Parse();
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) {
518 FormFieldData field;
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")));
541 Parse();
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