summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authordhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-25 21:45:52 +0000
committerdhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-25 21:45:52 +0000
commit424d0f73c86b63c583cf1f27b067bb39ebac5b9f (patch)
tree32efdc56f512d5db3f18ff91e0d15389444fba4a /chrome/browser
parent00f7f6cf366f407ed0915140f86fbaa4e34759e7 (diff)
downloadchromium_src-424d0f73c86b63c583cf1f27b067bb39ebac5b9f.zip
chromium_src-424d0f73c86b63c583cf1f27b067bb39ebac5b9f.tar.gz
chromium_src-424d0f73c86b63c583cf1f27b067bb39ebac5b9f.tar.bz2
AutoFill incorrectly matches a radio control on youtube.com
Changes AutoFill heuristics to match against only form input element types that we actually fill. BUG=47925 TEST=FormStructureTest.MatchSpecificInputTypes Review URL: http://codereview.chromium.org/3153038 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57397 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/autofill/form_field.cc14
-rw-r--r--chrome/browser/autofill/form_field_unittest.cc8
-rw-r--r--chrome/browser/autofill/form_structure_unittest.cc84
3 files changed, 104 insertions, 2 deletions
diff --git a/chrome/browser/autofill/form_field.cc b/chrome/browser/autofill/form_field.cc
index 1eba436..24b45ed 100644
--- a/chrome/browser/autofill/form_field.cc
+++ b/chrome/browser/autofill/form_field.cc
@@ -67,6 +67,12 @@ namespace {
// The name of the hidden form control element.
const char* const kControlTypeHidden = "hidden";
+// The name of the radio form control element.
+const char* const kControlTypeRadio = "radio";
+
+// The name of the checkbox form control element.
+const char* const kControlTypeCheckBox = "checkbox";
+
} // namespace
class EmailField : public FormField {
@@ -271,9 +277,13 @@ FormFieldSet::FormFieldSet(FormStructure* fields) {
// Parse fields.
std::vector<AutoFillField*>::const_iterator field = fields->begin();
while (field != fields->end() && *field != NULL) {
- // Don't parse hidden fields.
+ // Don't parse hidden fields or radio or checkbox controls.
if (LowerCaseEqualsASCII((*field)->form_control_type(),
- kControlTypeHidden)) {
+ kControlTypeHidden) ||
+ LowerCaseEqualsASCII((*field)->form_control_type(),
+ kControlTypeRadio) ||
+ LowerCaseEqualsASCII((*field)->form_control_type(),
+ kControlTypeCheckBox)) {
field++;
continue;
}
diff --git a/chrome/browser/autofill/form_field_unittest.cc b/chrome/browser/autofill/form_field_unittest.cc
index 616525a..965fa70 100644
--- a/chrome/browser/autofill/form_field_unittest.cc
+++ b/chrome/browser/autofill/form_field_unittest.cc
@@ -18,6 +18,14 @@ TEST(FormFieldTest, Match) {
field.set_label(ASCIIToUTF16("a"));
EXPECT_TRUE(FormField::Match(&field, string16(), true));
+ // Strictly empty pattern matches empty string.
+ field.set_label(ASCIIToUTF16(""));
+ EXPECT_TRUE(FormField::Match(&field, ASCIIToUTF16("^$"), true));
+
+ // Strictly empty pattern does not match non-empty string.
+ field.set_label(ASCIIToUTF16("a"));
+ EXPECT_FALSE(FormField::Match(&field, ASCIIToUTF16("^$"), true));
+
// Non-empty pattern doesn't match empty string.
field.set_label(string16());
EXPECT_FALSE(FormField::Match(&field, ASCIIToUTF16("a"), true));
diff --git a/chrome/browser/autofill/form_structure_unittest.cc b/chrome/browser/autofill/form_structure_unittest.cc
index 0a02198..9055578 100644
--- a/chrome/browser/autofill/form_structure_unittest.cc
+++ b/chrome/browser/autofill/form_structure_unittest.cc
@@ -917,4 +917,88 @@ TEST(FormStructureTest, ThreePartPhoneNumber) {
EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(3)->heuristic_type());
}
+TEST(FormStructureTest, MatchSpecificInputTypes) {
+ scoped_ptr<FormStructure> form_structure;
+ FormData form;
+ form.method = ASCIIToUTF16("post");
+ form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("First Name"),
+ ASCIIToUTF16("firstname"),
+ string16(),
+ ASCIIToUTF16("text"),
+ 0));
+ form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"),
+ ASCIIToUTF16("lastname"),
+ string16(),
+ ASCIIToUTF16("text"),
+ 0));
+ form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("EMail"),
+ ASCIIToUTF16("email"),
+ string16(),
+ ASCIIToUTF16("email"),
+ 0));
+ form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Phone"),
+ ASCIIToUTF16("phone"),
+ string16(),
+ ASCIIToUTF16("number"),
+ 0));
+ form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Country"),
+ ASCIIToUTF16("country"),
+ string16(),
+ ASCIIToUTF16("select-one"),
+ 0));
+ form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Fax"),
+ ASCIIToUTF16("fax"),
+ string16(),
+ ASCIIToUTF16("tel"),
+ 0));
+ form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"),
+ ASCIIToUTF16("address"),
+ string16(),
+ ASCIIToUTF16("radio"),
+ 0));
+ form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("City"),
+ ASCIIToUTF16("city"),
+ string16(),
+ ASCIIToUTF16("checkbox"),
+ 0));
+ form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("State"),
+ ASCIIToUTF16("state"),
+ string16(),
+ ASCIIToUTF16("hidden"),
+ 0));
+ form.fields.push_back(webkit_glue::FormField(string16(),
+ ASCIIToUTF16("Submit"),
+ string16(),
+ ASCIIToUTF16("submit"),
+ 0));
+ form_structure.reset(new FormStructure(form));
+ EXPECT_TRUE(form_structure->IsAutoFillable());
+
+ // Expect the correct number of fields.
+ ASSERT_EQ(10U, form_structure->field_count());
+ ASSERT_EQ(6U, form_structure->autofill_count());
+
+ // First name.
+ EXPECT_EQ(NAME_FIRST, form_structure->field(0)->heuristic_type());
+ // Last name.
+ EXPECT_EQ(NAME_LAST, form_structure->field(1)->heuristic_type());
+ // Email.
+ EXPECT_EQ(EMAIL_ADDRESS, form_structure->field(2)->heuristic_type());
+ // Phone.
+ EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER,
+ form_structure->field(3)->heuristic_type());
+ // Country.
+ EXPECT_EQ(ADDRESS_HOME_COUNTRY, form_structure->field(4)->heuristic_type());
+ // Fax.
+ EXPECT_EQ(PHONE_FAX_WHOLE_NUMBER, form_structure->field(5)->heuristic_type());
+ // Address. Invalid input type.
+ EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(6)->heuristic_type());
+ // City. Invalid input type.
+ EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(7)->heuristic_type());
+ // State. Invalid input type.
+ EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(8)->heuristic_type());
+ // Submit. Invalid input type.
+ EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(9)->heuristic_type());
+}
+
} // namespace