Commit 1c6c3805 authored by Vaclav Brozek's avatar Vaclav Brozek Committed by Commit Bot

Only consider text fields in password forms

The old (renderer-process) FormData->PasswordForm parser failed to
ignore non-text inputs, such as radio buttons.

This CL adds filtering non-text fields out.

Note that the new parser (browser-process) does filter out non-text
field already.

Bug: 851808
Change-Id: I60b121cb5cc15bdae0d96dba9119c2d704d079b2
Reviewed-on: https://chromium-review.googlesource.com/1111849Reviewed-by: default avatarDominic Battré <battre@chromium.org>
Commit-Queue: Vaclav Brozek <vabr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569591}
parent faa083ee
......@@ -470,11 +470,11 @@ bool GetPasswordForm(
control_elements, form_data, username_detector_cache);
}
// Narrow the scope to enabled inputs.
// Narrow the scope to enabled text inputs.
std::vector<const FormFieldData*> enabled_fields;
enabled_fields.reserve(form_data.fields.size());
for (const FormFieldData& field : form_data.fields) {
if (field.is_enabled)
if (field.is_enabled && field.IsTextInputElement())
enabled_fields.push_back(&field);
}
......
......@@ -155,6 +155,12 @@ class PasswordFormBuilder {
name_and_id, name_and_id, value);
}
// Add a field with a given type. Useful to add non-text fields.
void AddFieldWithType(const char* name_and_id, const char* type) {
base::StringAppendF(&html_, "<INPUT type=\"%s\" name=\"%s\" id=\"%s\"/>",
type, name_and_id, name_and_id);
}
// Appends a new submit-type field at the end of the form with the specified
// |name|.
void AddSubmitButton(const char* name) {
......@@ -2514,4 +2520,24 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, TypedValuePreserved) {
EXPECT_EQ(base::string16(), password_form->form_data.fields[2].typed_value);
}
// Check that non-text fields are ignored.
TEST_F(MAYBE_PasswordFormConversionUtilsTest, NonTextFields) {
PasswordFormBuilder builder(kTestFormActionURL);
// Avoid calling the text fields anything related to "username" to prevent the
// local HTML classifier from influencing the test result.
builder.AddTextField("textField", "", "");
builder.AddFieldWithType("radioInput", "radio");
builder.AddPasswordField("password", "", "");
std::string html = builder.ProduceHTML();
WebFormElement form;
LoadWebFormFromHTML(html, &form, nullptr);
std::unique_ptr<PasswordForm> password_form =
CreatePasswordFormFromWebForm(form, nullptr, nullptr, nullptr);
ASSERT_TRUE(password_form);
EXPECT_EQ(base::UTF8ToUTF16("textField"), password_form->username_element);
}
} // namespace autofill
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment