Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(741)

Unified Diff: chrome/renderer/autofill/form_autofill_browsertest.cc

Issue 2640783002: [Password Generation] Send id attribute to server for HTML based form classifier (Closed)
Patch Set: Changes addressed to reviewer comments Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/autofill/form_autofill_browsertest.cc
diff --git a/chrome/renderer/autofill/form_autofill_browsertest.cc b/chrome/renderer/autofill/form_autofill_browsertest.cc
index f793a2f5eb5e0b2cea4ec5a874909f2ad354cf9a..a9b1b08aa2328095c4a189a7f794b17cc1f6af3f 100644
--- a/chrome/renderer/autofill/form_autofill_browsertest.cc
+++ b/chrome/renderer/autofill/form_autofill_browsertest.cc
@@ -2385,6 +2385,38 @@ TEST_F(FormAutofillTest, WebFormElementToFormData_CssClasses) {
EXPECT_EQ(base::string16(), form.fields[2].css_classes);
}
+// Tests id attributes are set.
+TEST_F(FormAutofillTest, WebFormElementToFormData_IdAttributes) {
+ LoadHTML(
+ "<FORM name='TestForm' id='form' action='http://cnn.com' method='post' "
+ "autocomplete='off'>"
+ " <INPUT type='text' name='name1' id='firstname' />"
+ " <INPUT type='text' name='name2' id='lastname' />"
+ " <INPUT type='text' name='same' id='same' />"
+ " <INPUT type='text' id='addressline1' />"
+ "</FORM>");
+
+ WebFrame* frame = GetMainFrame();
+ ASSERT_NE(nullptr, frame);
+
+ WebFormElement web_form =
+ frame->document().getElementById("form").to<WebFormElement>();
+ ASSERT_FALSE(web_form.isNull());
+
+ FormData form;
+ EXPECT_TRUE(WebFormElementToFormData(web_form, WebFormControlElement(),
+ nullptr, EXTRACT_NONE, &form, nullptr));
+
+ EXPECT_EQ(4U, form.fields.size());
+ EXPECT_EQ(ASCIIToUTF16("firstname"), form.fields[0].id);
+ EXPECT_EQ(ASCIIToUTF16("lastname"), form.fields[1].id);
+ // Don't save the id attribute if its value coincides with the name attribute.
+ EXPECT_TRUE(form.fields[2].id.empty());
+ // Don't save the id attribute because it has been saved in the |name| field.
+ EXPECT_TRUE(form.fields[3].id.empty());
+ EXPECT_EQ(base::string16(), form.fields[2].css_classes);
+}
+
TEST_F(FormAutofillTest, ExtractForms) {
ExpectJohnSmithLabels(
"<FORM name='TestForm' action='http://cnn.com' method='post'>"
« no previous file with comments | « chrome/browser/autofill/autofill_server_browsertest.cc ('k') | components/autofill/content/common/autofill_types.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698