summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autofill/form_structure_unittest.cc
diff options
context:
space:
mode:
authorisherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-22 03:17:13 +0000
committerisherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-22 03:17:13 +0000
commitf678c1005e3cd343169e5d8a0932ff191d4da740 (patch)
treef48ac29046db65221e08824ebc9ee6824ba3ab8f /chrome/browser/autofill/form_structure_unittest.cc
parentc7c4917431b75788da56cd4ceb0dcaf3449440d4 (diff)
downloadchromium_src-f678c1005e3cd343169e5d8a0932ff191d4da740.zip
chromium_src-f678c1005e3cd343169e5d8a0932ff191d4da740.tar.gz
chromium_src-f678c1005e3cd343169e5d8a0932ff191d4da740.tar.bz2
Disable Autofill server queries for forms with only <select> fields.
BUG=89986 TEST=FormStructureTest.ShouldBeParsed Review URL: http://codereview.chromium.org/7471029 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@93539 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autofill/form_structure_unittest.cc')
-rw-r--r--chrome/browser/autofill/form_structure_unittest.cc78
1 files changed, 78 insertions, 0 deletions
diff --git a/chrome/browser/autofill/form_structure_unittest.cc b/chrome/browser/autofill/form_structure_unittest.cc
index 7f80582..0936300 100644
--- a/chrome/browser/autofill/form_structure_unittest.cc
+++ b/chrome/browser/autofill/form_structure_unittest.cc
@@ -196,6 +196,84 @@ TEST(FormStructureTest, IsAutofillable) {
EXPECT_TRUE(form_structure->IsAutofillable(true));
}
+TEST(FormStructureTest, ShouldBeParsed) {
+ scoped_ptr<FormStructure> form_structure;
+ FormData form;
+
+ // We need at least three text fields to be parseable.
+ form.method = ASCIIToUTF16("post");
+ form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("username"),
+ ASCIIToUTF16("username"),
+ string16(),
+ ASCIIToUTF16("text"),
+ 0,
+ false));
+ form_structure.reset(new FormStructure(form));
+ EXPECT_FALSE(form_structure->ShouldBeParsed(true));
+
+ // We now have three text fields, though only two are auto-fillable.
+ form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("First Name"),
+ ASCIIToUTF16("firstname"),
+ string16(),
+ ASCIIToUTF16("text"),
+ 0,
+ false));
+ form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"),
+ ASCIIToUTF16("lastname"),
+ string16(),
+ ASCIIToUTF16("text"),
+ 0,
+ false));
+ form_structure.reset(new FormStructure(form));
+ EXPECT_TRUE(form_structure->ShouldBeParsed(true));
+
+ // The method must be 'post', though we can intentionally ignore this
+ // criterion for the sake of providing a helpful warning message to the user.
+ form.method = ASCIIToUTF16("get");
+ form_structure.reset(new FormStructure(form));
+ EXPECT_FALSE(form_structure->IsAutofillable(true));
+ EXPECT_TRUE(form_structure->ShouldBeParsed(false));
+
+ // The target cannot include http(s)://*/search...
+ form.method = ASCIIToUTF16("post");
+ form.action = GURL("http://google.com/search?q=hello");
+ form_structure.reset(new FormStructure(form));
+ EXPECT_FALSE(form_structure->ShouldBeParsed(true));
+
+ // But search can be in the URL.
+ form.action = GURL("http://search.com/?q=hello");
+ form_structure.reset(new FormStructure(form));
+ EXPECT_TRUE(form_structure->ShouldBeParsed(true));
+
+ // The form need only have three fields, but at least one must be a text
+ // field.
+ form.fields.clear();
+ form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Email"),
+ ASCIIToUTF16("email"),
+ string16(),
+ ASCIIToUTF16("email"),
+ 0,
+ false));
+ form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("State"),
+ ASCIIToUTF16("state"),
+ string16(),
+ ASCIIToUTF16("select-one"),
+ 0,
+ false));
+ form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Country"),
+ ASCIIToUTF16("country"),
+ string16(),
+ ASCIIToUTF16("select-one"),
+ 0,
+ false));
+ form_structure.reset(new FormStructure(form));
+ EXPECT_TRUE(form_structure->ShouldBeParsed(true));
+
+ form.fields[0].form_control_type = ASCIIToUTF16("select-one");
+ form_structure.reset(new FormStructure(form));
+ EXPECT_FALSE(form_structure->ShouldBeParsed(true));
+}
+
TEST(FormStructureTest, HeuristicsContactInfo) {
scoped_ptr<FormStructure> form_structure;
FormData form;