summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-02 00:07:59 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-02 00:07:59 +0000
commitc619032fad7707aee5e9fc8ecaed43419e41165d (patch)
tree4d8e3f4a6de0f00495802bf97ba0e42934101747
parentaa2cf38beabe222641b145e1cf985c72acd46c1e (diff)
downloadchromium_src-c619032fad7707aee5e9fc8ecaed43419e41165d.zip
chromium_src-c619032fad7707aee5e9fc8ecaed43419e41165d.tar.gz
chromium_src-c619032fad7707aee5e9fc8ecaed43419e41165d.tar.bz2
AutoFill: Fix scraping a label from a div table.
BUG=61439 TEST=FormManagerTest.LabelsInferredFromDivTable Review URL: http://codereview.chromium.org/4248002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64691 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/autofill/form_field.h2
-rw-r--r--chrome/renderer/form_manager.cc30
-rw-r--r--chrome/renderer/form_manager_browsertest.cc52
3 files changed, 79 insertions, 5 deletions
diff --git a/chrome/browser/autofill/form_field.h b/chrome/browser/autofill/form_field.h
index cf57350..38b2ec2 100644
--- a/chrome/browser/autofill/form_field.h
+++ b/chrome/browser/autofill/form_field.h
@@ -126,7 +126,7 @@ class FormField {
// Checkout field name limitation. All ECML compliant web forms will be
// recognized correctly as such however the restrictions on having exactly
// ECML compliant names have been loosened to only require that field names
- // be prefixed with an ECML compiant name in order to accommodate checkout.
+ // be prefixed with an ECML compliant name in order to accommodate checkout.
// Additionally we allow the use of '.' as a word delimiter in addition to the
// ECML standard '_' (see FormField::FormField for details).
static string16 GetEcmlPattern(const char* ecml_name);
diff --git a/chrome/renderer/form_manager.cc b/chrome/renderer/form_manager.cc
index 52bc6cf..265d0c2 100644
--- a/chrome/renderer/form_manager.cc
+++ b/chrome/renderer/form_manager.cc
@@ -190,6 +190,26 @@ string16 InferLabelFromTable(
}
// Helper for |InferLabelForElement()| that infers a label, if possible, from
+// a surrounding div table.
+// Eg. <div>Some Text<span><input ...></span></div>
+string16 InferLabelFromDivTable(
+ const WebFormControlElement& element) {
+ WebNode parent = element.parentNode();
+ while (!parent.isNull() && parent.isElementNode() &&
+ !parent.to<WebElement>().hasTagName("div"))
+ parent = parent.parentNode();
+
+ if (parent.isNull() || !parent.isElementNode())
+ return string16();
+
+ WebElement e = parent.to<WebElement>();
+ if (e.isNull() || !e.hasTagName("div"))
+ return string16();
+
+ return FindChildText(e);
+}
+
+// Helper for |InferLabelForElement()| that infers a label, if possible, from
// a surrounding definition list.
// Eg. <dl><dt>Some Text</dt><dd><input ...></dd></dl>
// Eg. <dl><dt><b>Some Text</b></dt><dd><b><input ...></b></dd></dl>
@@ -702,14 +722,16 @@ string16 FormManager::InferLabelForElement(
string16 inferred_label = InferLabelFromPrevious(element);
// If we didn't find a label, check for table cell case.
- if (inferred_label.empty()) {
+ if (inferred_label.empty())
inferred_label = InferLabelFromTable(element);
- }
+
+ // If we didn't find a label, check for div table case.
+ if (inferred_label.empty())
+ inferred_label = InferLabelFromDivTable(element);
// If we didn't find a label, check for definition list case.
- if (inferred_label.empty()) {
+ if (inferred_label.empty())
inferred_label = InferLabelFromDefinitionList(element);
- }
return inferred_label;
}
diff --git a/chrome/renderer/form_manager_browsertest.cc b/chrome/renderer/form_manager_browsertest.cc
index 7e6bc6a..76ff574 100644
--- a/chrome/renderer/form_manager_browsertest.cc
+++ b/chrome/renderer/form_manager_browsertest.cc
@@ -1381,6 +1381,58 @@ TEST_F(FormManagerTest, LabelsInferredWithImageTags) {
fields[5]);
}
+TEST_F(FormManagerTest, LabelsInferredFromDivTable) {
+ LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
+ "<DIV>First Name:<BR>"
+ " <SPAN>"
+ " <INPUT type=\"text\" name=\"firstname\" value=\"John\">"
+ " </SPAN>"
+ "</DIV>"
+ "<DIV>Last Name:<BR>"
+ " <SPAN>"
+ " <INPUT type=\"text\" name=\"lastname\" value=\"Doe\">"
+ " </SPAN>"
+ "</DIV>"
+ "<input type=\"submit\" name=\"reply-send\" value=\"Send\">"
+ "</FORM>");
+
+ WebFrame* web_frame = GetMainFrame();
+ ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
+
+ FormManager form_manager;
+ form_manager.ExtractForms(web_frame);
+
+ std::vector<FormData> forms;
+ form_manager.GetFormsInFrame(web_frame, FormManager::REQUIRE_NONE, &forms);
+ ASSERT_EQ(1U, forms.size());
+
+ const FormData& form = forms[0];
+ EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
+ EXPECT_EQ(GURL(web_frame->url()), form.origin);
+ EXPECT_EQ(GURL("http://cnn.com"), form.action);
+
+ const std::vector<FormField>& fields = form.fields;
+ ASSERT_EQ(3U, fields.size());
+ EXPECT_EQ(FormField(ASCIIToUTF16("First Name:"),
+ ASCIIToUTF16("firstname"),
+ ASCIIToUTF16("John"),
+ ASCIIToUTF16("text"),
+ 20),
+ fields[0]);
+ EXPECT_EQ(FormField(ASCIIToUTF16("Last Name:"),
+ ASCIIToUTF16("lastname"),
+ string16(),
+ ASCIIToUTF16("text"),
+ 20),
+ fields[1]);
+ EXPECT_EQ(FormField(string16(),
+ ASCIIToUTF16("reply-send"),
+ ASCIIToUTF16("Send"),
+ ASCIIToUTF16("submit"),
+ 0),
+ fields[2]);
+}
+
TEST_F(FormManagerTest, FillFormMaxLength) {
LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
" <INPUT type=\"text\" id=\"firstname\" maxlength=\"5\"/>"