Commit 7beaf449 authored by Vaclav Brozek's avatar Vaclav Brozek Committed by Commit Bot

Clean-up password manager's form_parser.*

This CL replaces a redundant type mention with 'auto' in form_parser.cc
makes the use of trailing ',' consistent and removes unnecessary {} from
form_parser_unittest.cc.

Bug: 845426
Change-Id: I292af1e436d9b7e98880b3392f0232d88a81e84b
Reviewed-on: https://chromium-review.googlesource.com/1087267Reviewed-by: default avatarVadym Doroshenko <dvadym@chromium.org>
Commit-Queue: Vaclav Brozek <vabr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#564834}
parent 0d298d15
......@@ -168,7 +168,7 @@ bool HasPasswordField(const std::vector<const FormFieldData*>& fields) {
std::unique_ptr<ParseResult> ParseUsingAutocomplete(
const std::vector<const FormFieldData*>& fields,
const AutocompleteCache& autocomplete_cache) {
std::unique_ptr<ParseResult> result = std::make_unique<ParseResult>();
auto result = std::make_unique<ParseResult>();
for (const FormFieldData* field : fields) {
AutocompleteFlag flag = autocomplete_cache.RetrieveFor(field);
const bool is_password = field->form_control_type == "password";
......
......@@ -283,10 +283,12 @@ TEST(FormParserTest, SkipNotTextFields) {
CheckTestData({
{
"Select between username and password fields",
{{.role = ElementRole::USERNAME},
{.form_control_type = "select"},
{.role = ElementRole::CURRENT_PASSWORD,
.form_control_type = "password"}},
{
{.role = ElementRole::USERNAME},
{.form_control_type = "select"},
{.role = ElementRole::CURRENT_PASSWORD,
.form_control_type = "password"},
},
},
});
}
......@@ -470,72 +472,90 @@ TEST(FormParserTest, TextAndPasswordFields) {
"Simple empty sign-in form",
// Forms with empty fields cannot be saved, so the parsing result for
// saving is empty.
{{.role = ElementRole::USERNAME_FILLING,
.form_control_type = "text",
.value = ""},
{.role = ElementRole::CURRENT_PASSWORD_FILLING,
.form_control_type = "password",
.value = ""}},
{
{.role = ElementRole::USERNAME_FILLING,
.form_control_type = "text",
.value = ""},
{.role = ElementRole::CURRENT_PASSWORD_FILLING,
.form_control_type = "password",
.value = ""},
},
},
{
"Simple sign-in form with filled data",
{{.role = ElementRole::USERNAME, .form_control_type = "text"},
{.role = ElementRole::CURRENT_PASSWORD,
.form_control_type = "password"}},
{
{.role = ElementRole::USERNAME, .form_control_type = "text"},
{.role = ElementRole::CURRENT_PASSWORD,
.form_control_type = "password"},
},
},
{
"Empty sign-in form with an extra text field",
{{.form_control_type = "text", .value = ""},
{.role = ElementRole::USERNAME_FILLING,
.form_control_type = "text",
.value = ""},
{.role = ElementRole::CURRENT_PASSWORD_FILLING,
.form_control_type = "password",
.value = ""}},
{
{.form_control_type = "text", .value = ""},
{.role = ElementRole::USERNAME_FILLING,
.form_control_type = "text",
.value = ""},
{.role = ElementRole::CURRENT_PASSWORD_FILLING,
.form_control_type = "password",
.value = ""},
},
},
{
"Non-empty sign-in form with an extra text field",
{{.role = ElementRole::USERNAME_SAVING, .form_control_type = "text"},
{.role = ElementRole::USERNAME_FILLING,
.form_control_type = "text",
.value = ""},
{.role = ElementRole::CURRENT_PASSWORD,
.form_control_type = "password"}},
{
{.role = ElementRole::USERNAME_SAVING,
.form_control_type = "text"},
{.role = ElementRole::USERNAME_FILLING,
.form_control_type = "text",
.value = ""},
{.role = ElementRole::CURRENT_PASSWORD,
.form_control_type = "password"},
},
},
{
"Empty sign-in form with an extra invisible text field",
{{.role = ElementRole::USERNAME_FILLING,
.form_control_type = "text",
.value = ""},
{.form_control_type = "text", .is_focusable = false, .value = ""},
{.role = ElementRole::CURRENT_PASSWORD_FILLING,
.form_control_type = "password",
.value = ""}},
{
{.role = ElementRole::USERNAME_FILLING,
.form_control_type = "text",
.value = ""},
{.form_control_type = "text", .is_focusable = false, .value = ""},
{.role = ElementRole::CURRENT_PASSWORD_FILLING,
.form_control_type = "password",
.value = ""},
},
},
{
"Non-empty sign-in form with an extra invisible text field",
{{.role = ElementRole::USERNAME, .form_control_type = "text"},
{.form_control_type = "text", .is_focusable = false},
{.role = ElementRole::CURRENT_PASSWORD,
.form_control_type = "password"}},
{
{.role = ElementRole::USERNAME, .form_control_type = "text"},
{.form_control_type = "text", .is_focusable = false},
{.role = ElementRole::CURRENT_PASSWORD,
.form_control_type = "password"},
},
},
{
"Simple empty sign-in form with empty username",
// Filled forms with a username field which is left empty are
// suspicious. The parser will just omit the username altogether.
{{.role = ElementRole::USERNAME_FILLING,
.form_control_type = "text",
.value = ""},
{.role = ElementRole::CURRENT_PASSWORD,
.form_control_type = "password"}},
{
{.role = ElementRole::USERNAME_FILLING,
.form_control_type = "text",
.value = ""},
{.role = ElementRole::CURRENT_PASSWORD,
.form_control_type = "password"},
},
},
{
"Simple empty sign-in form with empty password",
// Empty password, nothing to save.
{{.role = ElementRole::USERNAME_FILLING, .form_control_type = "text"},
{.role = ElementRole::CURRENT_PASSWORD_FILLING,
.form_control_type = "password",
.value = ""}},
{
{.role = ElementRole::USERNAME_FILLING,
.form_control_type = "text"},
{.role = ElementRole::CURRENT_PASSWORD_FILLING,
.form_control_type = "password",
.value = ""},
},
},
});
}
......@@ -753,55 +773,55 @@ TEST(FormParserTest, ReadonlyFields) {
{
"For usernames, readonly does not matter",
{
{{.role = ElementRole::USERNAME,
.form_control_type = "text",
.is_readonly = true},
{.role = ElementRole::CURRENT_PASSWORD,
.form_control_type = "password"}},
{.role = ElementRole::USERNAME,
.form_control_type = "text",
.is_readonly = true},
{.role = ElementRole::CURRENT_PASSWORD,
.form_control_type = "password"},
},
},
{
"For passwords, readonly means: 'give up', perhaps there is a "
"virtual keyboard, filling might be ignored",
{
{{.form_control_type = "text"},
{.form_control_type = "password", .is_readonly = true}},
{.form_control_type = "text"},
{.form_control_type = "password", .is_readonly = true},
},
},
{
"But correctly marked passwords are accepted even if readonly",
{
{{.role = ElementRole::USERNAME,
.form_control_type = "text",
.autocomplete_attribute = "username"},
{.role = ElementRole::NEW_PASSWORD,
.autocomplete_attribute = "new-password",
.form_control_type = "password",
.is_readonly = true},
{.role = ElementRole::CONFIRMATION_PASSWORD,
.autocomplete_attribute = "new-password",
.form_control_type = "password",
.is_readonly = true},
{.role = ElementRole::CURRENT_PASSWORD,
.autocomplete_attribute = "current-password",
.form_control_type = "password",
.is_readonly = true}},
{.role = ElementRole::USERNAME,
.form_control_type = "text",
.autocomplete_attribute = "username"},
{.role = ElementRole::NEW_PASSWORD,
.autocomplete_attribute = "new-password",
.form_control_type = "password",
.is_readonly = true},
{.role = ElementRole::CONFIRMATION_PASSWORD,
.autocomplete_attribute = "new-password",
.form_control_type = "password",
.is_readonly = true},
{.role = ElementRole::CURRENT_PASSWORD,
.autocomplete_attribute = "current-password",
.form_control_type = "password",
.is_readonly = true},
},
},
{
"And passwords already filled by user or Chrome are accepted even if "
"readonly",
{
{{.role = ElementRole::USERNAME, .form_control_type = "text"},
{.role = ElementRole::CURRENT_PASSWORD,
.properties_mask = FieldPropertiesFlags::AUTOFILLED,
.form_control_type = "password",
.is_readonly = true},
{.role = ElementRole::NEW_PASSWORD,
.properties_mask = FieldPropertiesFlags::USER_TYPED,
.form_control_type = "password",
.is_readonly = true},
{.form_control_type = "password", .is_readonly = true}},
{.role = ElementRole::USERNAME, .form_control_type = "text"},
{.role = ElementRole::CURRENT_PASSWORD,
.properties_mask = FieldPropertiesFlags::AUTOFILLED,
.form_control_type = "password",
.is_readonly = true},
{.role = ElementRole::NEW_PASSWORD,
.properties_mask = FieldPropertiesFlags::USER_TYPED,
.form_control_type = "password",
.is_readonly = true},
{.form_control_type = "password", .is_readonly = true},
},
},
});
......
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