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

Unified Diff: components/autofill/core/browser/credit_card_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 inputs. Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: components/autofill/core/browser/credit_card_field_unittest.cc
diff --git a/components/autofill/core/browser/credit_card_field_unittest.cc b/components/autofill/core/browser/credit_card_field_unittest.cc
index 39e222f305da271cfe17b9d420fdc2135257b2a2..fbf2f97a5073d5afe1352189eff40124d7b32bea 100644
--- a/components/autofill/core/browser/credit_card_field_unittest.cc
+++ b/components/autofill/core/browser/credit_card_field_unittest.cc
@@ -21,7 +21,7 @@ class CreditCardFieldTest : public testing::Test {
virtual ~CreditCardFieldTest() {}
protected:
- ScopedVector<const AutofillField> list_;
+ ScopedVector<AutofillField> list_;
scoped_ptr<const CreditCardField> field_;
ServerFieldTypeMap field_type_map_;
@@ -380,4 +380,116 @@ TEST_F(CreditCardFieldTest, ParseCreditCardExpYear_2DigitMaxLength) {
field_type_map_[ASCIIToUTF16("year")]);
}
+TEST_F(CreditCardFieldTest, ParseCreditCardNumberWithSplit) {
+ FormFieldData field;
+ field.form_control_type = "text";
+
+ field.label = ASCIIToUTF16("Card Number");
+ field.name = ASCIIToUTF16("card_number_q1");
+ field.max_length = 4;
+ list_.push_back(new AutofillField(field, ASCIIToUTF16("number1")));
+
+ field.label = ASCIIToUTF16("Card Number");
+ field.name = ASCIIToUTF16("card_number_q2");
+ field.max_length = 4;
+ list_.push_back(new AutofillField(field, ASCIIToUTF16("number2")));
+
+ field.label = ASCIIToUTF16("Card Number");
+ field.name = ASCIIToUTF16("card_number_q3");
+ field.max_length = 4;
+ list_.push_back(new AutofillField(field, ASCIIToUTF16("number3")));
+
+ // For last credit card number input field it simply ignores the |max_length|
+ // attribute. So even having a very big number, does not conside it an invalid
+ // split for autofilling.
+ field.label = ASCIIToUTF16("Card Number");
+ field.name = ASCIIToUTF16("card_number_q4");
+ field.max_length = 20;
+ list_.push_back(new AutofillField(field, ASCIIToUTF16("number4")));
+
+ field.label = ASCIIToUTF16("Exp Month");
+ field.name = ASCIIToUTF16("ccmonth");
+ list_.push_back(new AutofillField(field, ASCIIToUTF16("month5")));
+
+ field.label = ASCIIToUTF16("Exp Year");
+ field.name = ASCIIToUTF16("ccyear");
+ list_.push_back(new AutofillField(field, ASCIIToUTF16("year6")));
+
+ Parse();
+ ASSERT_NE(static_cast<CreditCardField*>(NULL), field_.get());
+ EXPECT_TRUE(ClassifyField());
+
+ ASSERT_TRUE(field_type_map_.find(ASCIIToUTF16("number1")) !=
+ field_type_map_.end());
+ EXPECT_EQ(CREDIT_CARD_NUMBER, field_type_map_[ASCIIToUTF16("number1")]);
+ EXPECT_EQ(0U, list_[0]->credit_card_number_offset());
+
+ ASSERT_TRUE(field_type_map_.find(ASCIIToUTF16("number2")) !=
+ field_type_map_.end());
+ EXPECT_EQ(CREDIT_CARD_NUMBER, field_type_map_[ASCIIToUTF16("number2")]);
+ EXPECT_EQ(4U, list_[1]->credit_card_number_offset());
+
+ ASSERT_TRUE(field_type_map_.find(ASCIIToUTF16("number3")) !=
+ field_type_map_.end());
+ EXPECT_EQ(CREDIT_CARD_NUMBER, field_type_map_[ASCIIToUTF16("number3")]);
+ EXPECT_EQ(8U, list_[2]->credit_card_number_offset());
+
+ ASSERT_TRUE(field_type_map_.find(ASCIIToUTF16("number4")) !=
+ field_type_map_.end());
+ EXPECT_EQ(CREDIT_CARD_NUMBER, field_type_map_[ASCIIToUTF16("number4")]);
+ EXPECT_EQ(12U, list_[3]->credit_card_number_offset());
+
+ ASSERT_TRUE(field_type_map_.find(ASCIIToUTF16("month5")) !=
+ field_type_map_.end());
+ EXPECT_EQ(CREDIT_CARD_EXP_MONTH, field_type_map_[ASCIIToUTF16("month5")]);
+ ASSERT_TRUE(field_type_map_.find(ASCIIToUTF16("year6")) !=
+ field_type_map_.end());
+ EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR,
+ field_type_map_[ASCIIToUTF16("year6")]);
+}
+
+TEST_F(CreditCardFieldTest, ParseCreditCardNumberWithInvalidSplit) {
+ FormFieldData field;
+ field.form_control_type = "text";
+
+ field.label = ASCIIToUTF16("Name on Card");
+ field.name = ASCIIToUTF16("name_on_card");
+ list_.push_back(new AutofillField(field, ASCIIToUTF16("name1")));
+
+ field.label = ASCIIToUTF16("Card Number");
+ field.name = ASCIIToUTF16("card_number");
+ list_.push_back(new AutofillField(field, ASCIIToUTF16("number2")));
+
+ field.label = ASCIIToUTF16("Not Card Number");
+ field.name = ASCIIToUTF16("not_card_number");
+ list_.push_back(new AutofillField(field, ASCIIToUTF16("number3")));
+
+ field.label = ASCIIToUTF16("Exp Month");
+ field.name = ASCIIToUTF16("ccmonth");
+ list_.push_back(new AutofillField(field, ASCIIToUTF16("month4")));
+
+ field.label = ASCIIToUTF16("Exp Year");
+ field.name = ASCIIToUTF16("ccyear");
+ list_.push_back(new AutofillField(field, ASCIIToUTF16("year5")));
+
+ Parse();
+ ASSERT_NE(static_cast<CreditCardField*>(NULL), field_.get());
+ EXPECT_TRUE(ClassifyField());
+
+ ASSERT_TRUE(field_type_map_.find(ASCIIToUTF16("name1")) !=
+ field_type_map_.end());
+ EXPECT_EQ(CREDIT_CARD_NAME, field_type_map_[ASCIIToUTF16("name1")]);
+ ASSERT_TRUE(field_type_map_.find(ASCIIToUTF16("number2")) ==
+ field_type_map_.end());
+ ASSERT_TRUE(field_type_map_.find(ASCIIToUTF16("number3")) ==
+ field_type_map_.end());
+ ASSERT_TRUE(field_type_map_.find(ASCIIToUTF16("month4")) !=
+ field_type_map_.end());
+ EXPECT_EQ(CREDIT_CARD_EXP_MONTH, field_type_map_[ASCIIToUTF16("month4")]);
+ ASSERT_TRUE(field_type_map_.find(ASCIIToUTF16("year5")) !=
+ field_type_map_.end());
+ EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR,
+ field_type_map_[ASCIIToUTF16("year5")]);
+}
+
} // namespace autofill
« no previous file with comments | « components/autofill/core/browser/credit_card_field.cc ('k') | components/autofill/core/browser/email_field.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698