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

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

Issue 381613005: [Autofill] Autofill fails to fill credit card number when split across fields. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Incorporated review comments. Created 6 years, 4 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
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/autofill_field.h" 5 #include "components/autofill/core/browser/autofill_field.h"
6 6
7 #include "base/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 16 matching lines...) Expand all
27 options16[i] = ASCIIToUTF16(options[i]); 27 options16[i] = ASCIIToUTF16(options[i]);
28 } 28 }
29 29
30 FormFieldData form_field; 30 FormFieldData form_field;
31 form_field.form_control_type = "select-one"; 31 form_field.form_control_type = "select-one";
32 form_field.option_values = options16; 32 form_field.option_values = options16;
33 form_field.option_contents = options16; 33 form_field.option_contents = options16;
34 return form_field; 34 return form_field;
35 } 35 }
36 36
37 struct TestCase {
38 std::string card_number_;
39 int total_spilts_;
40 std::vector<int> spilts_;
41 std::vector<std::string> expected_results_;
42 };
43
37 TEST(AutofillFieldTest, Type) { 44 TEST(AutofillFieldTest, Type) {
38 AutofillField field; 45 AutofillField field;
39 ASSERT_EQ(NO_SERVER_DATA, field.server_type()); 46 ASSERT_EQ(NO_SERVER_DATA, field.server_type());
40 ASSERT_EQ(UNKNOWN_TYPE, field.heuristic_type()); 47 ASSERT_EQ(UNKNOWN_TYPE, field.heuristic_type());
41 48
42 // |server_type_| is NO_SERVER_DATA, so |heuristic_type_| is returned. 49 // |server_type_| is NO_SERVER_DATA, so |heuristic_type_| is returned.
43 EXPECT_EQ(UNKNOWN_TYPE, field.Type().GetStorableType()); 50 EXPECT_EQ(UNKNOWN_TYPE, field.Type().GetStorableType());
44 51
45 // Set the heuristic type and check it. 52 // Set the heuristic type and check it.
46 field.set_heuristic_type(NAME_FIRST); 53 field.set_heuristic_type(NAME_FIRST);
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 503
497 AutofillField::FillFormField(field, 504 AutofillField::FillFormField(field,
498 UTF8ToUTF16("桜丘町26-1\n" 505 UTF8ToUTF16("桜丘町26-1\n"
499 "セルリアンタワー6階"), 506 "セルリアンタワー6階"),
500 "ja-JP", 507 "ja-JP",
501 "en-US", 508 "en-US",
502 &field); 509 &field);
503 EXPECT_EQ(UTF8ToUTF16("桜丘町26-1セルリアンタワー6階"), field.value); 510 EXPECT_EQ(UTF8ToUTF16("桜丘町26-1セルリアンタワー6階"), field.value);
504 } 511 }
505 512
513 TEST(AutofillFieldTest, FillCreditCardNumber) {
514 // Populate test cases.
515 std::vector<TestCase> test_cases;
516
517 // Case 1: card number without any spilts.
518 TestCase test1;
519 test1.card_number_ = "4111111111111111";
520 test1.total_spilts_ = 0;
521 test_cases.push_back(test1);
522
523 // Case 2: card number without delimiters, and broken up into four equal
524 // groups, of length 4.
525 test1.card_number_ = "4111111111111111";
526 test1.total_spilts_ = 4;
527 int splits1[] = {4, 4, 4, 4};
528 test1.spilts_ =
529 std::vector<int>(splits1, splits1 + sizeof(splits1) / sizeof(int));
530 std::string results1[] = {"4111", "1111", "1111", "1111"};
531 test1.expected_results_ = std::vector<std::string>(
532 results1, results1 + sizeof(results1) / sizeof(std::string));
533 test_cases.push_back(test1);
534
535 // Case 3: card number with white-space as delimiters, and broken up into four
536 // equal groups, of length 4.
537 test1.card_number_ = "4111 1111 1111 1111";
538 test1.total_spilts_ = 4;
539 int splits2[] = {4, 4, 4, 4};
540 test1.spilts_ =
541 std::vector<int>(splits2, splits2 + sizeof(splits2) / sizeof(int));
542 std::string results2[] = {"4111", "1111", "1111", "1111"};
543 test1.expected_results_ = std::vector<std::string>(
544 results2, results2 + sizeof(results2) / sizeof(std::string));
545 test_cases.push_back(test1);
546
547 // Case 4: card number with '-' as delimiters, and broken up into four equal
548 // groups, of length 4.
549 test1.card_number_ = "4111-1111-1111-1111";
550 test1.total_spilts_ = 4;
551 int splits3[] = {4, 4, 4, 4};
552 test1.spilts_ =
553 std::vector<int>(splits3, splits3 + sizeof(splits3) / sizeof(int));
554 std::string results3[] = {"4111", "1111", "1111", "1111"};
555 test1.expected_results_ = std::vector<std::string>(
556 results3, results3 + sizeof(results3) / sizeof(std::string));
557 test_cases.push_back(test1);
558
559 // Case 5: card with 15 digits number, broken up into three unequal groups, of
560 // lengths 4, 6, and 5.
561 test1.card_number_ = "4111-111111-11111";
562 test1.total_spilts_ = 3;
563 int splits4[] = {4, 6, 5};
564 test1.spilts_ =
565 std::vector<int>(splits4, splits4 + sizeof(splits4) / sizeof(int));
566 std::string results4[] = {"4111", "111111", "11111"};
567 test1.expected_results_ = std::vector<std::string>(
568 results4, results4 + sizeof(results4) / sizeof(std::string));
569 test_cases.push_back(test1);
570
571 // Start executing test cases to verify parts and full credit card number.
572 for (std::vector<TestCase>::iterator it = test_cases.begin();
573 it != test_cases.end();
574 ++it) {
575 TestCase current_case = *it;
576
577 for (int i = 0; i < current_case.total_spilts_; i++) {
578 AutofillField cc_number_part;
579 cc_number_part.SetHtmlType(HTML_TYPE_UNKNOWN, HtmlFieldMode());
580 cc_number_part.set_heuristic_type(CREDIT_CARD_NUMBER);
581 cc_number_part.label = ASCIIToUTF16("Card Number");
582 std::ostringstream str;
583 str << "card_number_part" << i;
584 cc_number_part.name = ASCIIToUTF16(str.str());
585 cc_number_part.max_length = current_case.spilts_[i];
586 AutofillField::CreditCardNumberInfo* number_info =
587 new AutofillField::CreditCardNumberInfo;
588 number_info->part_ = i + 1;
589 number_info->start_index_ = (i == 0) ? 0 : current_case.spilts_[i - 1];
590 cc_number_part.set_credit_card_number_info(number_info);
591
592 // Fill with a card-number; should fill just the card_number_part.
593 AutofillField::FillFormField(cc_number_part,
594 ASCIIToUTF16(current_case.card_number_),
595 "en-US",
596 "en-US",
597 &cc_number_part);
598 EXPECT_EQ(ASCIIToUTF16(current_case.expected_results_[i]),
599 cc_number_part.value);
600 }
601
602 // Verify that full card-number shall get fill properly as well.
603 AutofillField cc_number_full;
604 cc_number_full.SetHtmlType(HTML_TYPE_UNKNOWN, HtmlFieldMode());
605 cc_number_full.set_heuristic_type(CREDIT_CARD_NUMBER);
606 cc_number_full.label = ASCIIToUTF16("Card Number");
607 cc_number_full.name = ASCIIToUTF16("card_number");
608 AutofillField::FillFormField(cc_number_full,
609 ASCIIToUTF16(current_case.card_number_),
610 "en-US",
611 "en-US",
612 &cc_number_full);
613 EXPECT_EQ(ASCIIToUTF16(current_case.card_number_), cc_number_full.value);
614 }
615 }
616
506 } // namespace 617 } // namespace
507 } // namespace autofill 618 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698