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

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

Issue 2892813003: Add MATCH_NUMBER to match types when parsing expiration date form field. (Closed)
Patch Set: adds unit-test. Created 3 years, 7 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
« no previous file with comments | « components/autofill/core/browser/credit_card_field.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "components/autofill/core/browser/credit_card_field.h" 5 #include "components/autofill/core/browser/credit_card_field.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 field_candidates_map_.end()); 295 field_candidates_map_.end());
296 EXPECT_EQ(CREDIT_CARD_EXP_MONTH, 296 EXPECT_EQ(CREDIT_CARD_EXP_MONTH,
297 field_candidates_map_[ASCIIToUTF16("month3")].BestHeuristicType()); 297 field_candidates_map_[ASCIIToUTF16("month3")].BestHeuristicType());
298 ASSERT_TRUE(field_candidates_map_.find(ASCIIToUTF16("year4")) != 298 ASSERT_TRUE(field_candidates_map_.find(ASCIIToUTF16("year4")) !=
299 field_candidates_map_.end()); 299 field_candidates_map_.end());
300 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR, 300 EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR,
301 field_candidates_map_[ASCIIToUTF16("year4")].BestHeuristicType()); 301 field_candidates_map_[ASCIIToUTF16("year4")].BestHeuristicType());
302 } 302 }
303 303
304 typedef struct { 304 typedef struct {
305 const std::string cc_fields_form_control_type;
305 const std::string label; 306 const std::string label;
306 const int max_length; 307 const int max_length;
307 const ServerFieldType expected_prediction; 308 const ServerFieldType expected_prediction;
308 } ParseExpFieldTestCase; 309 } ParseExpFieldTestCase;
309 310
310 class ParseExpFieldTest : public CreditCardFieldTestBase, 311 class ParseExpFieldTest : public CreditCardFieldTestBase,
311 public testing::TestWithParam<ParseExpFieldTestCase> { 312 public testing::TestWithParam<ParseExpFieldTestCase> {
312 }; 313 };
313 314
314 TEST_P(ParseExpFieldTest, ParseExpField) { 315 TEST_P(ParseExpFieldTest, ParseExpField) {
315 auto test_case = GetParam(); 316 auto test_case = GetParam();
316 // Clean up after previous test cases. 317 // Clean up after previous test cases.
317 list_.clear(); 318 list_.clear();
318 field_.reset(); 319 field_.reset();
319 field_candidates_map_.clear(); 320 field_candidates_map_.clear();
320 321
321 FormFieldData field; 322 FormFieldData field;
322 field.form_control_type = "text"; 323 field.form_control_type = "text";
323 324
324 field.label = ASCIIToUTF16("Name on Card"); 325 field.label = ASCIIToUTF16("Name on Card");
325 field.name = ASCIIToUTF16("name_on_card"); 326 field.name = ASCIIToUTF16("name_on_card");
326 list_.push_back( 327 list_.push_back(
327 base::MakeUnique<AutofillField>(field, ASCIIToUTF16("name1"))); 328 base::MakeUnique<AutofillField>(field, ASCIIToUTF16("name1")));
328 329
330 field.form_control_type = test_case.cc_fields_form_control_type;
329 field.label = ASCIIToUTF16("Card Number"); 331 field.label = ASCIIToUTF16("Card Number");
330 field.name = ASCIIToUTF16("card_number"); 332 field.name = ASCIIToUTF16("card_number");
331 list_.push_back(base::MakeUnique<AutofillField>(field, ASCIIToUTF16("num2"))); 333 list_.push_back(base::MakeUnique<AutofillField>(field, ASCIIToUTF16("num2")));
332 334
333 field.label = ASCIIToUTF16(test_case.label); 335 field.label = ASCIIToUTF16(test_case.label);
334 if (test_case.max_length != 0) { 336 if (test_case.max_length != 0) {
335 field.max_length = test_case.max_length; 337 field.max_length = test_case.max_length;
336 } 338 }
337 field.name = ASCIIToUTF16("cc_exp"); 339 field.name = ASCIIToUTF16("cc_exp");
338 list_.push_back(base::MakeUnique<AutofillField>(field, ASCIIToUTF16("exp3"))); 340 list_.push_back(base::MakeUnique<AutofillField>(field, ASCIIToUTF16("exp3")));
(...skipping 29 matching lines...) Expand all
368 ASSERT_TRUE(field_candidates_map_.find(ASCIIToUTF16("exp3")) != 370 ASSERT_TRUE(field_candidates_map_.find(ASCIIToUTF16("exp3")) !=
369 field_candidates_map_.end()); 371 field_candidates_map_.end());
370 EXPECT_EQ(test_case.expected_prediction, 372 EXPECT_EQ(test_case.expected_prediction,
371 field_candidates_map_[ASCIIToUTF16("exp3")].BestHeuristicType()); 373 field_candidates_map_[ASCIIToUTF16("exp3")].BestHeuristicType());
372 } 374 }
373 375
374 INSTANTIATE_TEST_CASE_P( 376 INSTANTIATE_TEST_CASE_P(
375 CreditCardFieldTest, 377 CreditCardFieldTest,
376 ParseExpFieldTest, 378 ParseExpFieldTest,
377 testing::Values( 379 testing::Values(
380 // CC fields input_type="text"
378 // General label, no maxlength. 381 // General label, no maxlength.
379 ParseExpFieldTestCase{"Expiration Date", 0, 382 ParseExpFieldTestCase{"text", "Expiration Date", 0,
380 CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR}, 383 CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR},
381 // General label, maxlength 4. 384 // General label, maxlength 4.
382 ParseExpFieldTestCase{"Expiration Date", 4, 385 ParseExpFieldTestCase{"text", "Expiration Date", 4,
383 CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR}, 386 CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR},
384 // General label, maxlength 5. 387 // General label, maxlength 5.
385 ParseExpFieldTestCase{"Expiration Date", 5, 388 ParseExpFieldTestCase{"text", "Expiration Date", 5,
386 CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR}, 389 CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR},
387 // General label, maxlength 6. 390 // General label, maxlength 6.
388 ParseExpFieldTestCase{"Expiration Date", 6, 391 ParseExpFieldTestCase{"text", "Expiration Date", 6,
389 CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR}, 392 CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR},
390 // General label, maxlength 7. 393 // General label, maxlength 7.
391 ParseExpFieldTestCase{"Expiration Date", 7, 394 ParseExpFieldTestCase{"text", "Expiration Date", 7,
392 CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR}, 395 CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR},
393 // General label, large maxlength. 396 // General label, large maxlength.
394 ParseExpFieldTestCase{"Expiration Date", 12, 397 ParseExpFieldTestCase{"text", "Expiration Date", 12,
395 CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR}, 398 CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR},
396 399
397 // Unsupported maxlength, general label. 400 // Unsupported maxlength, general label.
398 ParseExpFieldTestCase{"Expiration Date", 3, UNKNOWN_TYPE}, 401 ParseExpFieldTestCase{"text", "Expiration Date", 3, UNKNOWN_TYPE},
399 // Unsupported maxlength, two digit year label. 402 // Unsupported maxlength, two digit year label.
400 ParseExpFieldTestCase{"Expiration Date (MM/YY)", 3, UNKNOWN_TYPE}, 403 ParseExpFieldTestCase{"text", "Expiration Date (MM/YY)", 3,
404 UNKNOWN_TYPE},
401 // Unsupported maxlength, four digit year label. 405 // Unsupported maxlength, four digit year label.
402 ParseExpFieldTestCase{"Expiration Date (MM/YYYY)", 3, UNKNOWN_TYPE}, 406 ParseExpFieldTestCase{"text", "Expiration Date (MM/YYYY)", 3,
407 UNKNOWN_TYPE},
403 408
404 // Two digit year, simple label. 409 // Two digit year, simple label.
405 ParseExpFieldTestCase{"MM / YY", 0, CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR}, 410 ParseExpFieldTestCase{"text", "MM / YY", 0,
411 CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR},
406 // Two digit year, with slash (MM/YY). 412 // Two digit year, with slash (MM/YY).
407 ParseExpFieldTestCase{"Expiration Date (MM/YY)", 0, 413 ParseExpFieldTestCase{"text", "Expiration Date (MM/YY)", 0,
408 CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR}, 414 CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR},
409 // Two digit year, no slash (MMYY). 415 // Two digit year, no slash (MMYY).
410 ParseExpFieldTestCase{"Expiration Date (MMYY)", 4, 416 ParseExpFieldTestCase{"text", "Expiration Date (MMYY)", 4,
411 CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR}, 417 CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR},
412 // Two digit year, with slash and maxlength (MM/YY). 418 // Two digit year, with slash and maxlength (MM/YY).
413 ParseExpFieldTestCase{"Expiration Date (MM/YY)", 5, 419 ParseExpFieldTestCase{"text", "Expiration Date (MM/YY)", 5,
414 CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR}, 420 CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR},
415 // Two digit year, with slash and large maxlength (MM/YY). 421 // Two digit year, with slash and large maxlength (MM/YY).
416 ParseExpFieldTestCase{"Expiration Date (MM/YY)", 12, 422 ParseExpFieldTestCase{"text", "Expiration Date (MM/YY)", 12,
417 CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR}, 423 CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR},
418 424
419 // Four digit year, simple label. 425 // Four digit year, simple label.
420 ParseExpFieldTestCase{"MM / YYYY", 0, 426 ParseExpFieldTestCase{"text", "MM / YYYY", 0,
421 CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR}, 427 CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR},
422 // Four digit year, with slash (MM/YYYY). 428 // Four digit year, with slash (MM/YYYY).
423 ParseExpFieldTestCase{"Expiration Date (MM/YYYY)", 0, 429 ParseExpFieldTestCase{"text", "Expiration Date (MM/YYYY)", 0,
424 CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR}, 430 CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR},
425 // Four digit year, no slash (MMYYYY). 431 // Four digit year, no slash (MMYYYY).
426 ParseExpFieldTestCase{"Expiration Date (MMYYYY)", 6, 432 ParseExpFieldTestCase{"text", "Expiration Date (MMYYYY)", 6,
427 CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR}, 433 CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR},
428 // Four digit year, with slash and maxlength (MM/YYYY). 434 // Four digit year, with slash and maxlength (MM/YYYY).
429 ParseExpFieldTestCase{"Expiration Date (MM/YYYY)", 7, 435 ParseExpFieldTestCase{"text", "Expiration Date (MM/YYYY)", 7,
430 CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR}, 436 CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR},
431 // Four digit year, with slash and large maxlength (MM/YYYY). 437 // Four digit year, with slash and large maxlength (MM/YYYY).
432 ParseExpFieldTestCase{"Expiration Date (MM/YYYY)", 12, 438 ParseExpFieldTestCase{"text", "Expiration Date (MM/YYYY)", 12,
433 CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR}, 439 CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR},
434 440
435 // Four digit year label with restrictive maxlength (4). 441 // Four digit year label with restrictive maxlength (4).
436 ParseExpFieldTestCase{"Expiration Date (MM/YYYY)", 4, 442 ParseExpFieldTestCase{"text", "Expiration Date (MM/YYYY)", 4,
437 CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR}, 443 CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR},
438 // Four digit year label with restrictive maxlength (5). 444 // Four digit year label with restrictive maxlength (5).
439 ParseExpFieldTestCase{"Expiration Date (MM/YYYY)", 5, 445 ParseExpFieldTestCase{"text", "Expiration Date (MM/YYYY)", 5,
446 CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR},
447
448 // CC fields input_type="number"
449 // General label, no maxlength.
450 ParseExpFieldTestCase{"number", "Expiration Date", 0,
451 CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR},
452 // General label, maxlength 4.
453 ParseExpFieldTestCase{"number", "Expiration Date", 4,
454 CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR},
455 // General label, maxlength 5.
456 ParseExpFieldTestCase{"number", "Expiration Date", 5,
457 CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR},
458 // General label, maxlength 6.
459 ParseExpFieldTestCase{"number", "Expiration Date", 6,
460 CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR},
461 // General label, maxlength 7.
462 ParseExpFieldTestCase{"number", "Expiration Date", 7,
463 CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR},
464 // General label, large maxlength.
465 ParseExpFieldTestCase{"number", "Expiration Date", 12,
466 CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR},
467
468 // Unsupported maxlength, general label.
469 ParseExpFieldTestCase{"number", "Expiration Date", 3, UNKNOWN_TYPE},
470 // Unsupported maxlength, two digit year label.
471 ParseExpFieldTestCase{"number", "Expiration Date (MM/YY)", 3,
472 UNKNOWN_TYPE},
473 // Unsupported maxlength, four digit year label.
474 ParseExpFieldTestCase{"number", "Expiration Date (MM/YYYY)", 3,
475 UNKNOWN_TYPE},
476
477 // Two digit year, simple label.
478 ParseExpFieldTestCase{"number", "MM / YY", 0,
479 CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR},
480 // Two digit year, with slash (MM/YY).
481 ParseExpFieldTestCase{"number", "Expiration Date (MM/YY)", 0,
482 CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR},
483 // Two digit year, no slash (MMYY).
484 ParseExpFieldTestCase{"number", "Expiration Date (MMYY)", 4,
485 CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR},
486 // Two digit year, with slash and maxlength (MM/YY).
487 ParseExpFieldTestCase{"number", "Expiration Date (MM/YY)", 5,
488 CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR},
489 // Two digit year, with slash and large maxlength (MM/YY).
490 ParseExpFieldTestCase{"number", "Expiration Date (MM/YY)", 12,
491 CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR},
492
493 // Four digit year, simple label.
494 ParseExpFieldTestCase{"number", "MM / YYYY", 0,
495 CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR},
496 // Four digit year, with slash (MM/YYYY).
497 ParseExpFieldTestCase{"number", "Expiration Date (MM/YYYY)", 0,
498 CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR},
499 // Four digit year, no slash (MMYYYY).
500 ParseExpFieldTestCase{"number", "Expiration Date (MMYYYY)", 6,
501 CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR},
502 // Four digit year, with slash and maxlength (MM/YYYY).
503 ParseExpFieldTestCase{"number", "Expiration Date (MM/YYYY)", 7,
504 CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR},
505 // Four digit year, with slash and large maxlength (MM/YYYY).
506 ParseExpFieldTestCase{"number", "Expiration Date (MM/YYYY)", 12,
507 CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR},
508
509 // Four digit year label with restrictive maxlength (4).
510 ParseExpFieldTestCase{"number", "Expiration Date (MM/YYYY)", 4,
511 CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR},
512 // Four digit year label with restrictive maxlength (5).
513 ParseExpFieldTestCase{"number", "Expiration Date (MM/YYYY)", 5,
440 CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR})); 514 CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR}));
441 515
442 TEST_F(CreditCardFieldTest, ParseCreditCardHolderNameWithCCFullName) { 516 TEST_F(CreditCardFieldTest, ParseCreditCardHolderNameWithCCFullName) {
443 FormFieldData field; 517 FormFieldData field;
444 field.form_control_type = "text"; 518 field.form_control_type = "text";
445 519
446 field.label = ASCIIToUTF16("Name"); 520 field.label = ASCIIToUTF16("Name");
447 field.name = ASCIIToUTF16("ccfullname"); 521 field.name = ASCIIToUTF16("ccfullname");
448 list_.push_back( 522 list_.push_back(
449 base::MakeUnique<AutofillField>(field, ASCIIToUTF16("name1"))); 523 base::MakeUnique<AutofillField>(field, ASCIIToUTF16("name1")));
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 field_candidates_map_.end()); 901 field_candidates_map_.end());
828 EXPECT_EQ(CREDIT_CARD_VERIFICATION_CODE, 902 EXPECT_EQ(CREDIT_CARD_VERIFICATION_CODE,
829 field_candidates_map_[ASCIIToUTF16("cvc")].BestHeuristicType()); 903 field_candidates_map_[ASCIIToUTF16("cvc")].BestHeuristicType());
830 ASSERT_TRUE(field_candidates_map_.find(ASCIIToUTF16("unknown")) == 904 ASSERT_TRUE(field_candidates_map_.find(ASCIIToUTF16("unknown")) ==
831 field_candidates_map_.end()); 905 field_candidates_map_.end());
832 ASSERT_TRUE(field_candidates_map_.find(ASCIIToUTF16("cvc2")) == 906 ASSERT_TRUE(field_candidates_map_.find(ASCIIToUTF16("cvc2")) ==
833 field_candidates_map_.end()); 907 field_candidates_map_.end());
834 } 908 }
835 909
836 } // namespace autofill 910 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/credit_card_field.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698