Commit e9e7065b authored by Vaclav Brozek's avatar Vaclav Brozek Committed by Commit Bot

Check multiple roles in form_parser_unittest.cc

The test expectations for form_parser_unittest.cc contain the expected
roles for form fields (username, new-password, etc.). There can be at
most one of each, so if there are multiple same roles, all but one are
ignored.

This CL adds a DCHECK to guard that there are no multiple same roles
specified, so that the expecations are not described in a confusing
way. It is a DCHECK instead of an ASSERT/EXPECT, because this is
something not depending on the tested code, just the way the test is
written. Hence if it passes when submitting the CL, it will pass until
the next change to the test file.

Bug: 902700
Change-Id: I022daf5a1701f13e7d52c881b60acfc412cd2e96
Reviewed-on: https://chromium-review.googlesource.com/c/1325985Reviewed-by: default avatarVadym Doroshenko <dvadym@chromium.org>
Commit-Queue: Vaclav Brozek <vabr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606414}
parent 79c55bd2
...@@ -124,20 +124,25 @@ struct ParseResultIds { ...@@ -124,20 +124,25 @@ struct ParseResultIds {
void UpdateResultWithIdByRole(ParseResultIds* result, void UpdateResultWithIdByRole(ParseResultIds* result,
uint32_t id, uint32_t id,
ElementRole role) { ElementRole role) {
constexpr uint32_t kUnassigned = FormFieldData::kNotSetFormControlRendererId;
switch (role) { switch (role) {
case ElementRole::NONE: case ElementRole::NONE:
// Nothing to update. // Nothing to update.
break; break;
case ElementRole::USERNAME: case ElementRole::USERNAME:
DCHECK_EQ(kUnassigned, result->username_id);
result->username_id = id; result->username_id = id;
break; break;
case ElementRole::CURRENT_PASSWORD: case ElementRole::CURRENT_PASSWORD:
DCHECK_EQ(kUnassigned, result->password_id);
result->password_id = id; result->password_id = id;
break; break;
case ElementRole::NEW_PASSWORD: case ElementRole::NEW_PASSWORD:
DCHECK_EQ(kUnassigned, result->new_password_id);
result->new_password_id = id; result->new_password_id = id;
break; break;
case ElementRole::CONFIRMATION_PASSWORD: case ElementRole::CONFIRMATION_PASSWORD:
DCHECK_EQ(kUnassigned, result->confirmation_password_id);
result->confirmation_password_id = id; result->confirmation_password_id = id;
break; break;
} }
...@@ -1581,8 +1586,7 @@ TEST(FormParserTest, MultipleUsernames) { ...@@ -1581,8 +1586,7 @@ TEST(FormParserTest, MultipleUsernames) {
{.role_filling = ElementRole::USERNAME, {.role_filling = ElementRole::USERNAME,
.form_control_type = "text", .form_control_type = "text",
.prediction = {.type = autofill::USERNAME}}, .prediction = {.type = autofill::USERNAME}},
{.role = ElementRole::NEW_PASSWORD, {.form_control_type = "password",
.form_control_type = "password",
.prediction = {.type = autofill::ACCOUNT_CREATION_PASSWORD}}, .prediction = {.type = autofill::ACCOUNT_CREATION_PASSWORD}},
{.role = ElementRole::NEW_PASSWORD, {.role = ElementRole::NEW_PASSWORD,
.form_control_type = "password", .form_control_type = "password",
......
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