summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authordhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-12 05:16:29 +0000
committerdhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-12 05:16:29 +0000
commit31548a10135c11ff689074896237d2b7a404959c (patch)
treea72068fe0eefeaebe9b4b2d46faba7e4b1d6f82f /chrome
parentfec7a1b3ed24ace6122c92dd5a7fc1d68bd69bef (diff)
downloadchromium_src-31548a10135c11ff689074896237d2b7a404959c.zip
chromium_src-31548a10135c11ff689074896237d2b7a404959c.tar.gz
chromium_src-31548a10135c11ff689074896237d2b7a404959c.tar.bz2
AutoFill form name matching.
This fixes first name and last name field matching for AutoFill when the form identifies first name and last name using "bill.first" and "bill.last" as seen in the sample8.html form. BUG=37990 TEST=FormStructureTest.HeuristicsSample8 Review URL: http://codereview.chromium.org/900003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41397 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/autofill/form_structure_unittest.cc108
-rw-r--r--chrome/browser/autofill/name_field.cc8
2 files changed, 114 insertions, 2 deletions
diff --git a/chrome/browser/autofill/form_structure_unittest.cc b/chrome/browser/autofill/form_structure_unittest.cc
index 3d7df4c..6c61a158 100644
--- a/chrome/browser/autofill/form_structure_unittest.cc
+++ b/chrome/browser/autofill/form_structure_unittest.cc
@@ -188,4 +188,112 @@ TEST(FormStructureTest, Heuristics) {
EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(7)->heuristic_type());
}
+TEST(FormStructureTest, HeuristicsSample8) {
+ scoped_ptr<FormStructure> form_structure;
+ webkit_glue::FormFieldValues values;
+
+ values.method = ASCIIToUTF16("post");
+ values.elements.push_back(
+ webkit_glue::FormField(ASCIIToUTF16("Your First Name:"),
+ ASCIIToUTF16("bill.first"),
+ string16(),
+ ASCIIToUTF16("text"),
+ WebInputElement::Text));
+ values.elements.push_back(
+ webkit_glue::FormField(ASCIIToUTF16("Your Last Name:"),
+ ASCIIToUTF16("bill.last"),
+ string16(),
+ ASCIIToUTF16("text"),
+ WebInputElement::Text));
+ values.elements.push_back(
+ webkit_glue::FormField(ASCIIToUTF16("Street Address Line 1:"),
+ ASCIIToUTF16("bill.street1"),
+ string16(),
+ ASCIIToUTF16("text"),
+ WebInputElement::Text));
+ values.elements.push_back(
+ webkit_glue::FormField(ASCIIToUTF16("Street Address Line 2:"),
+ ASCIIToUTF16("bill.street2"),
+ string16(),
+ ASCIIToUTF16("text"),
+ WebInputElement::Text));
+ values.elements.push_back(
+ webkit_glue::FormField(ASCIIToUTF16("City:"),
+ ASCIIToUTF16("bill.city"),
+ string16(),
+ ASCIIToUTF16("text"),
+ WebInputElement::Text));
+ values.elements.push_back(
+ webkit_glue::FormField(ASCIIToUTF16("State (U.S.):"),
+ ASCIIToUTF16("bill.state"),
+ string16(),
+ ASCIIToUTF16("text"),
+ WebInputElement::Text));
+ values.elements.push_back(
+ webkit_glue::FormField(ASCIIToUTF16("Zip/Postal Code:"),
+ ASCIIToUTF16("BillTo.PostalCode"),
+ string16(),
+ ASCIIToUTF16("text"),
+ WebInputElement::Text));
+ values.elements.push_back(
+ webkit_glue::FormField(ASCIIToUTF16("Country:"),
+ ASCIIToUTF16("bill.country"),
+ string16(),
+ ASCIIToUTF16("text"),
+ WebInputElement::Text));
+ values.elements.push_back(
+ webkit_glue::FormField(ASCIIToUTF16("Phone Number:"),
+ ASCIIToUTF16("BillTo.Phone"),
+ string16(),
+ ASCIIToUTF16("text"),
+ WebInputElement::Text));
+ values.elements.push_back(
+ webkit_glue::FormField(string16(),
+ ASCIIToUTF16("Submit"),
+ string16(),
+ ASCIIToUTF16("submit"),
+ WebInputElement::Submit));
+ form_structure.reset(new FormStructure(values));
+ EXPECT_TRUE(form_structure->IsAutoFillable());
+
+ // 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();
+
+ // Check that heuristics are no longer UNKNOWN_TYPE.
+ // First name.
+ EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type());
+ // Last name.
+ EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type());
+ // Address.
+ EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(2)->heuristic_type());
+ // Address.
+ EXPECT_EQ(ADDRESS_HOME_LINE2, form_structure->field(3)->heuristic_type());
+ // City.
+ EXPECT_EQ(ADDRESS_HOME_CITY, form_structure->field(4)->heuristic_type());
+ // State.
+ EXPECT_EQ(ADDRESS_HOME_STATE, form_structure->field(5)->heuristic_type());
+ // Zip.
+ EXPECT_EQ(ADDRESS_HOME_ZIP, form_structure->field(6)->heuristic_type());
+ // Zip.
+ EXPECT_EQ(ADDRESS_HOME_COUNTRY, form_structure->field(7)->heuristic_type());
+ // Phone.
+ EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER,
+ form_structure->field(8)->heuristic_type());
+}
+
} // namespace
diff --git a/chrome/browser/autofill/name_field.cc b/chrome/browser/autofill/name_field.cc
index 34264d1..d1e6fb3 100644
--- a/chrome/browser/autofill/name_field.cc
+++ b/chrome/browser/autofill/name_field.cc
@@ -72,7 +72,9 @@ FirstLastNameField* FirstLastNameField::Parse2(
// asks, in stuffy English style, for just initials and a surname,
// so we match "initials" here (and just fill in a first name there,
// American-style).
- if (!ParseText(&q, ASCIIToUTF16("first name|firstname|initials|fname"),
+ // The ".*first$" matches fields ending in "first" (example in sample8.html).
+ if (!ParseText(&q,
+ ASCIIToUTF16("first name|firstname|initials|fname|.*first$"),
&v.first_name_))
return NULL;
@@ -89,7 +91,9 @@ FirstLastNameField* FirstLastNameField::Parse2(
ParseText(&q, ASCIIToUTF16("middle name|mname"), &v.middle_name_);
}
- if (!ParseText(&q, ASCIIToUTF16("last name|lastname|lname|surname"),
+ // The ".*last$" matches fields ending in "last" (example in sample8.html).
+ if (!ParseText(&q,
+ ASCIIToUTF16("last name|lastname|lname|surname|.*last$"),
&v.last_name_))
return NULL;