| Index: components/autofill/core/browser/autofill_field_unittest.cc
|
| diff --git a/components/autofill/core/browser/autofill_field_unittest.cc b/components/autofill/core/browser/autofill_field_unittest.cc
|
| index 9d0f3ac3ae77f8a6f714fa431a99ced4add3481b..0f46bdd8deed20d41cddfa593bc12fc42d615b14 100644
|
| --- a/components/autofill/core/browser/autofill_field_unittest.cc
|
| +++ b/components/autofill/core/browser/autofill_field_unittest.cc
|
| @@ -34,6 +34,13 @@ FormFieldData GenerateSelectFieldWithOptions(const char* const* options,
|
| return form_field;
|
| }
|
|
|
| +struct TestCase {
|
| + std::string card_number_;
|
| + int total_spilts_;
|
| + std::vector<int> spilts_;
|
| + std::vector<std::string> expected_results_;
|
| +};
|
| +
|
| TEST(AutofillFieldTest, Type) {
|
| AutofillField field;
|
| ASSERT_EQ(NO_SERVER_DATA, field.server_type());
|
| @@ -503,5 +510,109 @@ TEST(AutofillFieldTest, FillStreetAddressTextField) {
|
| EXPECT_EQ(UTF8ToUTF16("桜丘町26-1セルリアンタワー6階"), field.value);
|
| }
|
|
|
| +TEST(AutofillFieldTest, FillCreditCardNumber) {
|
| + // Populate test cases.
|
| + std::vector<TestCase> test_cases;
|
| +
|
| + // Case 1: card number without any spilts.
|
| + TestCase test1;
|
| + test1.card_number_ = "4111111111111111";
|
| + test1.total_spilts_ = 0;
|
| + test_cases.push_back(test1);
|
| +
|
| + // Case 2: card number without delimiters, and broken up into four equal
|
| + // groups, of length 4.
|
| + test1.card_number_ = "4111111111111111";
|
| + test1.total_spilts_ = 4;
|
| + int splits1[] = {4, 4, 4, 4};
|
| + test1.spilts_ =
|
| + std::vector<int>(splits1, splits1 + sizeof(splits1) / sizeof(int));
|
| + std::string results1[] = {"4111", "1111", "1111", "1111"};
|
| + test1.expected_results_ = std::vector<std::string>(
|
| + results1, results1 + sizeof(results1) / sizeof(std::string));
|
| + test_cases.push_back(test1);
|
| +
|
| + // Case 3: card number with white-space as delimiters, and broken up into four
|
| + // equal groups, of length 4.
|
| + test1.card_number_ = "4111 1111 1111 1111";
|
| + test1.total_spilts_ = 4;
|
| + int splits2[] = {4, 4, 4, 4};
|
| + test1.spilts_ =
|
| + std::vector<int>(splits2, splits2 + sizeof(splits2) / sizeof(int));
|
| + std::string results2[] = {"4111", "1111", "1111", "1111"};
|
| + test1.expected_results_ = std::vector<std::string>(
|
| + results2, results2 + sizeof(results2) / sizeof(std::string));
|
| + test_cases.push_back(test1);
|
| +
|
| + // Case 4: card number with '-' as delimiters, and broken up into four equal
|
| + // groups, of length 4.
|
| + test1.card_number_ = "4111-1111-1111-1111";
|
| + test1.total_spilts_ = 4;
|
| + int splits3[] = {4, 4, 4, 4};
|
| + test1.spilts_ =
|
| + std::vector<int>(splits3, splits3 + sizeof(splits3) / sizeof(int));
|
| + std::string results3[] = {"4111", "1111", "1111", "1111"};
|
| + test1.expected_results_ = std::vector<std::string>(
|
| + results3, results3 + sizeof(results3) / sizeof(std::string));
|
| + test_cases.push_back(test1);
|
| +
|
| + // Case 5: card with 15 digits number, broken up into three unequal groups, of
|
| + // lengths 4, 6, and 5.
|
| + test1.card_number_ = "4111-111111-11111";
|
| + test1.total_spilts_ = 3;
|
| + int splits4[] = {4, 6, 5};
|
| + test1.spilts_ =
|
| + std::vector<int>(splits4, splits4 + sizeof(splits4) / sizeof(int));
|
| + std::string results4[] = {"4111", "111111", "11111"};
|
| + test1.expected_results_ = std::vector<std::string>(
|
| + results4, results4 + sizeof(results4) / sizeof(std::string));
|
| + test_cases.push_back(test1);
|
| +
|
| + // Start executing test cases to verify parts and full credit card number.
|
| + for (std::vector<TestCase>::iterator it = test_cases.begin();
|
| + it != test_cases.end();
|
| + ++it) {
|
| + TestCase current_case = *it;
|
| +
|
| + for (int i = 0; i < current_case.total_spilts_; i++) {
|
| + AutofillField cc_number_part;
|
| + cc_number_part.SetHtmlType(HTML_TYPE_UNKNOWN, HtmlFieldMode());
|
| + cc_number_part.set_heuristic_type(CREDIT_CARD_NUMBER);
|
| + cc_number_part.label = ASCIIToUTF16("Card Number");
|
| + std::ostringstream str;
|
| + str << "card_number_part" << i;
|
| + cc_number_part.name = ASCIIToUTF16(str.str());
|
| + cc_number_part.max_length = current_case.spilts_[i];
|
| + AutofillField::CreditCardNumberInfo* number_info =
|
| + new AutofillField::CreditCardNumberInfo;
|
| + number_info->part_ = i + 1;
|
| + number_info->start_index_ = (i == 0) ? 0 : current_case.spilts_[i - 1];
|
| + cc_number_part.set_credit_card_number_info(number_info);
|
| +
|
| + // Fill with a card-number; should fill just the card_number_part.
|
| + AutofillField::FillFormField(cc_number_part,
|
| + ASCIIToUTF16(current_case.card_number_),
|
| + "en-US",
|
| + "en-US",
|
| + &cc_number_part);
|
| + EXPECT_EQ(ASCIIToUTF16(current_case.expected_results_[i]),
|
| + cc_number_part.value);
|
| + }
|
| +
|
| + // Verify that full card-number shall get fill properly as well.
|
| + AutofillField cc_number_full;
|
| + cc_number_full.SetHtmlType(HTML_TYPE_UNKNOWN, HtmlFieldMode());
|
| + cc_number_full.set_heuristic_type(CREDIT_CARD_NUMBER);
|
| + cc_number_full.label = ASCIIToUTF16("Card Number");
|
| + cc_number_full.name = ASCIIToUTF16("card_number");
|
| + AutofillField::FillFormField(cc_number_full,
|
| + ASCIIToUTF16(current_case.card_number_),
|
| + "en-US",
|
| + "en-US",
|
| + &cc_number_full);
|
| + EXPECT_EQ(ASCIIToUTF16(current_case.card_number_), cc_number_full.value);
|
| + }
|
| +}
|
| +
|
| } // namespace
|
| } // namespace autofill
|
|
|