summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autofill
diff options
context:
space:
mode:
authordhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-05 20:54:13 +0000
committerdhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-05 20:54:13 +0000
commitada32fe1849e988ff0000d493695f94aee184bc4 (patch)
treeae1b285ec1b1bbb2a3a7177c6b9eec8878409ef3 /chrome/browser/autofill
parent30d07443a806097199ff736e2e8009ce1b59a14d (diff)
downloadchromium_src-ada32fe1849e988ff0000d493695f94aee184bc4.zip
chromium_src-ada32fe1849e988ff0000d493695f94aee184bc4.tar.gz
chromium_src-ada32fe1849e988ff0000d493695f94aee184bc4.tar.bz2
AutoFill credit card field filling, with nameoncard field.
Enables credit card filling when "Name on Card" field is present. This adds to existing method of clicking on card number to fill. Note: this fixes up unit test changes with recent migration to FormData from FormFieldValues. BUG=38320 TEST=CreditCardFieldTest, FormStructureTest, manual testing with cc.html (attached). Related to: http://codereview.chromium.org/1518017 http://codereview.chromium.org/1605011 Review URL: http://codereview.chromium.org/1512018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43649 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autofill')
-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