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

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_;
Ilya Sherman 2014/08/12 04:23:41 nit: Prefer size_t over int for all of the ints in
Pritam Nikam 2014/08/12 14:00:37 Done.
40 std::vector<int> splits_;
41 std::vector<std::string> expected_results_;
42
43 size_t GetStartIndex(int index) {
44 size_t ret = 0;
45 for (int i = 0; i < index; i++)
Ilya Sherman 2014/08/12 04:23:42 nit: Prefer "++i" to "i++".
Pritam Nikam 2014/08/12 14:00:37 Done.
46 ret += splits_[i];
47 return ret;
48 }
49 };
Ilya Sherman 2014/08/12 04:23:41 It looks like this is only used in a single test,
Pritam Nikam 2014/08/12 14:00:37 Done.
50
37 TEST(AutofillFieldTest, Type) { 51 TEST(AutofillFieldTest, Type) {
38 AutofillField field; 52 AutofillField field;
39 ASSERT_EQ(NO_SERVER_DATA, field.server_type()); 53 ASSERT_EQ(NO_SERVER_DATA, field.server_type());
40 ASSERT_EQ(UNKNOWN_TYPE, field.heuristic_type()); 54 ASSERT_EQ(UNKNOWN_TYPE, field.heuristic_type());
41 55
42 // |server_type_| is NO_SERVER_DATA, so |heuristic_type_| is returned. 56 // |server_type_| is NO_SERVER_DATA, so |heuristic_type_| is returned.
43 EXPECT_EQ(UNKNOWN_TYPE, field.Type().GetStorableType()); 57 EXPECT_EQ(UNKNOWN_TYPE, field.Type().GetStorableType());
44 58
45 // Set the heuristic type and check it. 59 // Set the heuristic type and check it.
46 field.set_heuristic_type(NAME_FIRST); 60 field.set_heuristic_type(NAME_FIRST);
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 510
497 AutofillField::FillFormField(field, 511 AutofillField::FillFormField(field,
498 UTF8ToUTF16("桜丘町26-1\n" 512 UTF8ToUTF16("桜丘町26-1\n"
499 "セルリアンタワー6階"), 513 "セルリアンタワー6階"),
500 "ja-JP", 514 "ja-JP",
501 "en-US", 515 "en-US",
502 &field); 516 &field);
503 EXPECT_EQ(UTF8ToUTF16("桜丘町26-1セルリアンタワー6階"), field.value); 517 EXPECT_EQ(UTF8ToUTF16("桜丘町26-1セルリアンタワー6階"), field.value);
504 } 518 }
505 519
520 TEST(AutofillFieldTest, FillCreditCardNumber) {
521 // Populate test cases.
522 std::vector<TestCase> test_cases;
523
524 // Case 1: card number without any spilt.
525 TestCase test1;
526 test1.card_number_ = "4111111111111111";
527 test1.total_spilts_ = 0;
528 test_cases.push_back(test1);
529
530 // Case 2: card number broken up into four equal groups, of length 4.
531 test1.card_number_ = "5187654321098765";
532 test1.total_spilts_ = 4;
533 int splits1[] = {4, 4, 4, 4};
534 test1.splits_ =
535 std::vector<int>(splits1, splits1 + sizeof(splits1) / sizeof(int));
Ilya Sherman 2014/08/12 04:23:42 nit: Please use the arraysize macro rather than im
Pritam Nikam 2014/08/12 14:00:37 Done.
536 std::string results1[] = {"5187654321098765", "654321098765", "21098765",
537 "8765"};
Ilya Sherman 2014/08/12 04:23:41 Why aren't the expected results four digits each?
Pritam Nikam 2014/08/12 14:00:37 As we are not copying exact size substring, instea
538 test1.expected_results_ = std::vector<std::string>(
539 results1, results1 + sizeof(results1) / sizeof(std::string));
540 test_cases.push_back(test1);
541
542 // Case 3: card with 15 digits number, broken up into three unequal groups, of
543 // lengths 4, 6, and 5.
Ilya Sherman 2014/08/12 04:23:41 Rather than writing a single TEST to cover three d
Pritam Nikam 2014/08/12 14:00:37 Done.
544 test1.card_number_ = "423456789012345";
545 test1.total_spilts_ = 3;
546 int splits4[] = {4, 6, 5};
547 test1.splits_ =
548 std::vector<int>(splits4, splits4 + sizeof(splits4) / sizeof(int));
549 std::string results4[] = {"423456789012345", "56789012345", "12345"};
550 test1.expected_results_ = std::vector<std::string>(
551 results4, results4 + sizeof(results4) / sizeof(std::string));
552 test_cases.push_back(test1);
553
554 // Start executing test cases to verify parts and full credit card number.
555 for (std::vector<TestCase>::iterator it = test_cases.begin();
556 it != test_cases.end();
557 ++it) {
558 TestCase current_case = *it;
559
560 for (int i = 0; i < current_case.total_spilts_; i++) {
Ilya Sherman 2014/08/12 04:23:41 nit: Prefer "++i" to "i++".
Ilya Sherman 2014/08/12 04:23:42 nit: int -> size_t
Pritam Nikam 2014/08/12 14:00:37 Done.
Pritam Nikam 2014/08/12 14:00:37 Done.
561 AutofillField cc_number_part;
562 cc_number_part.SetHtmlType(HTML_TYPE_UNKNOWN, HtmlFieldMode());
Ilya Sherman 2014/08/12 04:23:41 Does the test fail if you omit this line? If not,
Pritam Nikam 2014/08/12 14:00:37 Done.
563 cc_number_part.set_heuristic_type(CREDIT_CARD_NUMBER);
564 cc_number_part.label = ASCIIToUTF16("Card Number");
565 std::ostringstream str;
566 str << "card_number_part" << i;
Ilya Sherman 2014/08/12 04:23:42 If you really need this, please use base::StringPr
Pritam Nikam 2014/08/12 14:00:37 Done.
567 cc_number_part.name = ASCIIToUTF16(str.str());
Ilya Sherman 2014/08/12 04:23:42 Do you really need to set the name or label?
Pritam Nikam 2014/08/12 14:00:37 Done.
568 cc_number_part.max_length = current_case.splits_[i];
569 cc_number_part.set_credit_card_number_start_index(
570 current_case.GetStartIndex(i));
571
572 // Fill with a card-number; should fill just the card_number_part.
573 AutofillField::FillFormField(cc_number_part,
574 ASCIIToUTF16(current_case.card_number_),
575 "en-US",
576 "en-US",
577 &cc_number_part);
578 EXPECT_EQ(ASCIIToUTF16(current_case.expected_results_[i]),
579 cc_number_part.value);
580 }
581
582 // Verify that full card-number shall get fill properly as well.
583 AutofillField cc_number_full;
584 cc_number_full.SetHtmlType(HTML_TYPE_UNKNOWN, HtmlFieldMode());
585 cc_number_full.set_heuristic_type(CREDIT_CARD_NUMBER);
586 cc_number_full.label = ASCIIToUTF16("Card Number");
587 cc_number_full.name = ASCIIToUTF16("card_number");
588 AutofillField::FillFormField(cc_number_full,
589 ASCIIToUTF16(current_case.card_number_),
590 "en-US",
591 "en-US",
592 &cc_number_full);
593 EXPECT_EQ(ASCIIToUTF16(current_case.card_number_), cc_number_full.value);
594 }
595 }
596
506 } // namespace 597 } // namespace
507 } // namespace autofill 598 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698