EXPECT_THAT(fields[0],
test::FormFieldDescriptionEq({.label = u"John",
.name = u"firstname",
.id_attribute = u"firstname",
.value = u"John"}));
EXPECT_THAT(fields[1],
test::FormFieldDescriptionEq({.label = u"Smith",
.name = u"lastname",
.id_attribute = u"lastname",
.value = u"Smith"}));
EXPECT_THAT(fields[2], test::FormFieldDescriptionEq(
{.label = u"jo...@example.com",
.name = u"email",
.id_attribute = u"email",
.value = u"jo...@example.com",
.autocomplete_attribute = "off"}));
EXPECT_THAT(fields[3],
test::FormFieldDescriptionEq({.label = u"1.800.555.1234",
.name = u"phone",
.id_attribute = u"phone",
.value = u"1.800.555.1234",
.autocomplete_attribute = {}}));You can do:
EXPECT_THAT(form.fields(), testing::ElementsAre(
test::FormFieldDescriptionEq({...}),
test::FormFieldDescriptionEq({...}),
test::FormFieldDescriptionEq({...})
));
(Same below)
EXPECT_THAT(
fields[1],
test::FormFieldDescriptionEq(
{.label = initial_lastname
? ASCIIToUTF16(initial_lastname)
: (placeholder_lastname ? std::optional(ASCIIToUTF16(
placeholder_lastname))
: std::nullopt),
.name = u"lastname",
.id_attribute = u"lastname",
.value = initial_lastname
? std::optional(ASCIIToUTF16(initial_lastname))
: (placeholder_lastname ? std::optional(ASCIIToUTF16(
placeholder_lastname))
: std::nullopt),
.placeholder =
!initial_lastname && placeholder_lastname
? std::optional(ASCIIToUTF16(placeholder_lastname))
: std::nullopt,
.is_autofilled_according_to_renderer = false}));
EXPECT_THAT(
fields[2],
test::FormFieldDescriptionEq(
{.label = initial_email
? ASCIIToUTF16(initial_email)
: (placeholder_email ? std::optional(ASCIIToUTF16(
placeholder_email))
: std::nullopt),
.name = u"email",
.id_attribute = u"email",
.value = initial_email
? ASCIIToUTF16(initial_email)
: (placeholder_email ? std::optional(ASCIIToUTF16(
placeholder_email))
: std::nullopt),
.placeholder = !initial_email && placeholder_email
? std::optional(ASCIIToUTF16(placeholder_email))
: std::nullopt,
.is_autofilled_according_to_renderer = false}));Opt: Consider some of the labels and values into local variables to make things more readable.
EXPECT_EQ(result.selected_option_text(), u"California");
ASSERT_EQ(2U, result.options().size());Isn't this checked above?
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Tamino BauknechtHey Norge, do you have time to take a look at these CLs for the second approval? It's probably best to start here to see how the newly introduced function of the other CL is used :)
Mark as resolved.
EXPECT_THAT(fields[0],
test::FormFieldDescriptionEq({.label = u"John",
.name = u"firstname",
.id_attribute = u"firstname",
.value = u"John"}));
EXPECT_THAT(fields[1],
test::FormFieldDescriptionEq({.label = u"Smith",
.name = u"lastname",
.id_attribute = u"lastname",
.value = u"Smith"}));
EXPECT_THAT(fields[2], test::FormFieldDescriptionEq(
{.label = u"jo...@example.com",
.name = u"email",
.id_attribute = u"email",
.value = u"jo...@example.com",
.autocomplete_attribute = "off"}));
EXPECT_THAT(fields[3],
test::FormFieldDescriptionEq({.label = u"1.800.555.1234",
.name = u"phone",
.id_attribute = u"phone",
.value = u"1.800.555.1234",
.autocomplete_attribute = {}}));You can do:
EXPECT_THAT(form.fields(), testing::ElementsAre(
test::FormFieldDescriptionEq({...}),
test::FormFieldDescriptionEq({...}),
test::FormFieldDescriptionEq({...})
));(Same below)
Done, good idea - thanks :) Sorry that it caused a pretty huge diff again :|
EXPECT_THAT(Opt: Consider some of the labels and values into local variables to make things more readable.
Done. I will also refactor these test functions in a future follow-up - this test file is simply too large to refactor everything in one go :) (reviewing it is probably already horrible as-is, sorry about that :| )
EXPECT_EQ(result.selected_option_text(), u"California");
ASSERT_EQ(2U, result.options().size());Isn't this checked above?
Done - you are right, it should be safe to assume that `value()` matches the corresponding `selected_option_text()` here.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +1 |
{.label = {},Do we need to manually define empty values?
std::vector<test::CommonFieldDescription> fields;
fields.push_back({.label = u"* First Name",
.name = u"firstname",
.name_attribute = u"",
.id_attribute = u"firstname",
.value = u"John",
.form_control_type = FormControlType::kInputText});
fields.push_back({.label = u"* Middle Name",
.name = u"middlename",
.name_attribute = u"",
.id_attribute = u"middlename",
.value = u"Joe",
.form_control_type = FormControlType::kInputText});
fields.push_back({.label = u"* Last Name",
.name = u"lastname",
.name_attribute = u"",
.id_attribute = u"lastname",
.value = u"Smith",
.form_control_type = FormControlType::kInputText});
fields.push_back({.label = u"* Country",
.name = u"country",
.name_attribute = u"",
.id_attribute = u"country",
.value = u"US",
.max_length = 0,
.form_control_type = FormControlType::kSelectOne});
fields.push_back({.label = u"* Email",
.name = u"email",
.name_attribute = u"",
.id_attribute = u"email",
.value = u"jo...@example.com",
.form_control_type = FormControlType::kInputText});Can we use an initializer list here? e.g.
```
const std::vector<test::CommonFieldDescription> fields = {
{.label = u"* First Name",
.name = u"firstname",
.name_attribute = u"",
.id_attribute = u"firstname",
.value = u"John",
.form_control_type = FormControlType::kInputText},
{.label = u"* Middle Name",
.name = u"middlename",
// ...
.form_control_type = FormControlType::kInputText},
// ...
};
```
?
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
FormFieldData expected;
expected.set_form_control_type(FormControlType::kInputText);
expected.set_max_length(FormFieldData::kDefaultMaxLength);Jihad HannaThese were dropped in the expectations since I don't think they need to be checked here. This was done for most of the `form_control_type`s and `max_length`s.
Tamino BauknechtAcknowledged
Marked as resolved.
{.label = {},Do we need to manually define empty values?
Great that you caught these, thanks - yes, I think we do want to set the fields here to an empty value because they won't be checked otherwise, but you are completely right that we want to set it to an empty string and not `std::nullopt`. I (hopefully) replaced all of these mistakes.
: std::nullopt,Jihad HannaThis is a change in logic since it will no longer check that the label is empty (same below). However, I think this is acceptable for these test cases considering the HTML used when calling this function.
In a follow-up, I would also like to refactor all of these functions anyway or at least replace all of these `const char*` by e.g. `std::string_view`.
Tamino BauknechtAcknowledged
Marked as resolved.
expected.set_should_autocomplete(false);Jihad HannaThis line was intentionally not transferred to the new implementation since it should be `true` and the test only passed because `EXPECT_FORM_FIELD_DATA_EQUALS` did not check `should_autocomplete`.
Tamino BauknechtAcknowledged
Marked as resolved.
std::vector<test::CommonFieldDescription> fields;Can we use an initializer list here? e.g.
```
const std::vector<test::CommonFieldDescription> fields = {
{.label = u"* First Name",
.name = u"firstname",
.name_attribute = u"",
.id_attribute = u"firstname",
.value = u"John",
.form_control_type = FormControlType::kInputText},
{.label = u"* Middle Name",
.name = u"middlename",
// ...
.form_control_type = FormControlType::kInputText},
// ...
};
```
?
Done, good point :)
expected.set_form_control_type(FormControlType::kInputText);
expected.set_max_length(FormFieldData::kDefaultMaxLength);Jihad HannaAlthough these are explicitly defined for each expectation, I don't think the test actually wants to check for the type of input field for the first two fields. Thus, I think it is fine to omit them in the refactoring (in other places I transferred them to the new `EXPECT`s if it was explicit).
Tamino BauknechtAcknowledged
Marked as resolved.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +1 |
{.label = {},Tamino BauknechtDo we need to manually define empty values?
Great that you caught these, thanks - yes, I think we do want to set the fields here to an empty value because they won't be checked otherwise, but you are completely right that we want to set it to an empty string and not `std::nullopt`. I (hopefully) replaced all of these mistakes.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
autofill: Refactor EXPECT_FORM_FIELD_DATA_EQUALS
This refactors the C-style macro `EXPECT_FORM_FIELD_DATA_EQUALS` in
`form_autofill_browsertest.cc` to use `EXPECT_THAT` instead and the
matcher `test::FormFieldDescriptionEq`.
Unfortunately, `test::FormFieldDataEq` cannot be used because even with
`test::WithoutUnserializedData`, too many fields are compared which are
not equal, namely `renderer_id`, `host_form_id`, `should_complete`,
`text_direction` and `bounds` are not equal for multiple fields. Since
manually setting these expectations would add a lot of additional code,
the introduction of `test::FormFieldDescriptionEq` is proposed,
implemented in a separate CL.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |