summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/autofill/credit_card_field.cc7
-rw-r--r--chrome/browser/autofill/form_structure_unittest.cc86
2 files changed, 86 insertions, 7 deletions
diff --git a/chrome/browser/autofill/credit_card_field.cc b/chrome/browser/autofill/credit_card_field.cc
index b79467d..95f2f5b 100644
--- a/chrome/browser/autofill/credit_card_field.cc
+++ b/chrome/browser/autofill/credit_card_field.cc
@@ -61,7 +61,7 @@ CreditCardField* CreditCardField::Parse(
} else {
if (fields == 0 || credit_card_field.expiration_month_) {
// at beginning or end
- name_pattern = ASCIIToUTF16("card holder|name on card");
+ name_pattern = ASCIIToUTF16("card holder|name on card|nameoncard");
} else {
name_pattern = ASCIIToUTF16("name");
}
@@ -152,7 +152,10 @@ CreditCardField* CreditCardField::Parse(
// Some pages (e.g. ExpediaBilling.html) have a "card description"
// field; we parse this field but ignore it.
- if (ParseText(&q, ASCIIToUTF16("card description")))
+ // We also ignore any other fields within a credit card block that
+ // start with "card", under the assumption that they are related to
+ // the credit card section being processed but are uninteresting to us.
+ if (ParseText(&q, ASCIIToUTF16("^card")))
continue;
break;
diff --git a/chrome/browser/autofill/form_structure_unittest.cc b/chrome/browser/autofill/form_structure_unittest.cc
index cfc535a..4dc4818 100644
--- a/chrome/browser/autofill/form_structure_unittest.cc
+++ b/chrome/browser/autofill/form_structure_unittest.cc
@@ -445,23 +445,23 @@ TEST(FormStructureTest, HeuristicsCreditCardInfo) {
form.method = ASCIIToUTF16("post");
form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Name on Card"),
- ASCIIToUTF16("name on card"),
+ ASCIIToUTF16("name on card"),
string16(),
ASCIIToUTF16("text")));
form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Card Number"),
- ASCIIToUTF16("card_number"),
+ ASCIIToUTF16("card_number"),
string16(),
ASCIIToUTF16("text")));
form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Exp Month"),
- ASCIIToUTF16("ccmonth"),
+ ASCIIToUTF16("ccmonth"),
string16(),
ASCIIToUTF16("text")));
form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Exp Year"),
- ASCIIToUTF16("ccyear"),
+ ASCIIToUTF16("ccyear"),
string16(),
ASCIIToUTF16("text")));
form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Verification"),
- ASCIIToUTF16("verification"),
+ ASCIIToUTF16("verification"),
string16(),
ASCIIToUTF16("text")));
form.fields.push_back(webkit_glue::FormField(string16(),
@@ -507,4 +507,80 @@ TEST(FormStructureTest, HeuristicsCreditCardInfo) {
form_structure->field(4)->heuristic_type());
}
+TEST(FormStructureTest, HeuristicsCreditCardInfoWithUnknownCardField) {
+ scoped_ptr<FormStructure> form_structure;
+ FormData form;
+
+ form.method = ASCIIToUTF16("post");
+ form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Name on Card"),
+ ASCIIToUTF16("name on card"),
+ string16(),
+ ASCIIToUTF16("text")));
+ // This is not a field we know how to process. But we should skip over it
+ // and process the other fields in the card block.
+ form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Card Type"),
+ ASCIIToUTF16("card_type"),
+ string16(),
+ ASCIIToUTF16("text")));
+ form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Card Number"),
+ ASCIIToUTF16("card_number"),
+ string16(),
+ ASCIIToUTF16("text")));
+ form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Exp Month"),
+ ASCIIToUTF16("ccmonth"),
+ string16(),
+ ASCIIToUTF16("text")));
+ form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Exp Year"),
+ ASCIIToUTF16("ccyear"),
+ string16(),
+ ASCIIToUTF16("text")));
+ form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Verification"),
+ ASCIIToUTF16("verification"),
+ string16(),
+ ASCIIToUTF16("text")));
+ form.fields.push_back(webkit_glue::FormField(string16(),
+ ASCIIToUTF16("Submit"),
+ string16(),
+ ASCIIToUTF16("submit")));
+ form_structure.reset(new FormStructure(form));
+ EXPECT_TRUE(form_structure->IsAutoFillable());
+
+ // Expect the correct number of fields.
+ ASSERT_EQ(6UL, form_structure->field_count());
+
+ // Check that heuristics are initialized as UNKNOWN_TYPE.
+ std::vector<AutoFillField*>::const_iterator iter;
+ size_t i;
+ for (iter = form_structure->begin(), i = 0;
+ iter != form_structure->end();
+ ++iter, ++i) {
+ // Expect last element to be NULL.
+ if (i == form_structure->field_count()) {
+ ASSERT_EQ(static_cast<AutoFillField*>(NULL), *iter);
+ } else {
+ ASSERT_NE(static_cast<AutoFillField*>(NULL), *iter);
+ EXPECT_EQ(UNKNOWN_TYPE, (*iter)->heuristic_type());
+ }
+ }
+
+ // Compute heuristic types.
+ form_structure->GetHeuristicAutoFillTypes();
+ ASSERT_EQ(6UL, form_structure->field_count());
+
+ // Credit card name.
+ EXPECT_EQ(CREDIT_CARD_NAME, form_structure->field(0)->heuristic_type());
+ // Credit card type. This is an unknown type but related to the credit card.
+ EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(1)->heuristic_type());
+ // Credit card number.
+ EXPECT_EQ(CREDIT_CARD_NUMBER, form_structure->field(2)->heuristic_type());
+ // Credit card expiration month.
+ EXPECT_EQ(CREDIT_CARD_EXP_MONTH, form_structure->field(3)->heuristic_type());
+ // Credit card expiration year.
+ EXPECT_EQ(CREDIT_CARD_EXP_4_DIGIT_YEAR,
+ form_structure->field(4)->heuristic_type());
+ // Credit card cvc.
+ EXPECT_EQ(CREDIT_CARD_VERIFICATION_CODE,
+ form_structure->field(5)->heuristic_type());
+}
+
} // namespace