Commit eda24dc5 authored by Yeol's avatar Yeol Committed by Commit Bot

[autofill] Refactor FormAutofillTest::ExpectLabelsAndTypes

collection of string vectors.
Instead it should take a single vector of expected value structs.

FormAutofillTest: :ExpectLabelsAndTypes() took an ever expanding
Bug: 896682
Change-Id: I1ddbf1fd27c6f397965292c1685fcceda7c0adae
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1539326Reviewed-by: default avatarRoger McFarlane <rogerm@chromium.org>
Commit-Queue: Yeol Park <peary2@gmail.com>
Cr-Commit-Position: refs/heads/master@{#644650}
parent 001aa0a4
...@@ -301,26 +301,28 @@ class FormAutofillTest : public ChromeRenderViewTest { ...@@ -301,26 +301,28 @@ class FormAutofillTest : public ChromeRenderViewTest {
const std::vector<base::string16>& labels, const std::vector<base::string16>& labels,
const std::vector<base::string16>& names, const std::vector<base::string16>& names,
const std::vector<base::string16>& values) { const std::vector<base::string16>& values) {
std::vector<std::string> control_types(labels.size(), "text");
ExpectLabelsAndTypes(html, id_attributes, name_attributes, labels, names,
values, control_types);
}
// TODO(crbug/896682): Refactor this method signature to take a vector of
// expected {id, name, label, etc} structs.
void ExpectLabelsAndTypes(const char* html,
const std::vector<base::string16>& id_attributes,
const std::vector<base::string16>& name_attributes,
const std::vector<base::string16>& labels,
const std::vector<base::string16>& names,
const std::vector<base::string16>& values,
const std::vector<std::string>& control_types) {
ASSERT_EQ(labels.size(), id_attributes.size()); ASSERT_EQ(labels.size(), id_attributes.size());
ASSERT_EQ(labels.size(), name_attributes.size()); ASSERT_EQ(labels.size(), name_attributes.size());
ASSERT_EQ(labels.size(), names.size()); ASSERT_EQ(labels.size(), names.size());
ASSERT_EQ(labels.size(), values.size()); ASSERT_EQ(labels.size(), values.size());
ASSERT_EQ(labels.size(), control_types.size());
std::vector<FormFieldData> fields;
for (size_t i = 0; i < labels.size(); ++i) {
FormFieldData expected;
expected.id_attribute = id_attributes[i];
expected.name_attribute = name_attributes[i];
expected.label = labels[i];
expected.name = names[i];
expected.value = values[i];
expected.form_control_type = "text";
expected.max_length = WebInputElement::DefaultMaxLength();
fields.push_back(expected);
}
ExpectLabelsAndTypes(html, fields);
}
void ExpectLabelsAndTypes(const char* html,
const std::vector<FormFieldData>& fields) {
LoadHTML(html); LoadHTML(html);
WebLocalFrame* web_frame = GetMainFrame(); WebLocalFrame* web_frame = GetMainFrame();
...@@ -335,22 +337,11 @@ class FormAutofillTest : public ChromeRenderViewTest { ...@@ -335,22 +337,11 @@ class FormAutofillTest : public ChromeRenderViewTest {
EXPECT_EQ(GetCanonicalOriginForDocument(web_frame->GetDocument()), EXPECT_EQ(GetCanonicalOriginForDocument(web_frame->GetDocument()),
form.origin); form.origin);
EXPECT_EQ(GURL("http://cnn.com"), form.action); EXPECT_EQ(GURL("http://cnn.com"), form.action);
ASSERT_EQ(fields.size(), form.fields.size());
const std::vector<FormFieldData>& fields = form.fields; for (size_t i = 0; i < fields.size(); ++i) {
ASSERT_EQ(labels.size(), fields.size());
for (size_t i = 0; i < labels.size(); ++i) {
int max_length =
control_types[i] == "text" ? WebInputElement::DefaultMaxLength() : 0;
FormFieldData expected;
expected.id_attribute = id_attributes[i];
expected.name_attribute = name_attributes[i];
expected.label = labels[i];
expected.name = names[i];
expected.value = values[i];
expected.form_control_type = control_types[i];
expected.max_length = max_length;
SCOPED_TRACE(base::StringPrintf("i: %" PRIuS, i)); SCOPED_TRACE(base::StringPrintf("i: %" PRIuS, i));
EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[i]); EXPECT_FORM_FIELD_DATA_EQUALS(fields[i], form.fields[i]);
} }
} }
...@@ -4194,44 +4185,53 @@ TEST_F(FormAutofillTest, LabelsInferredFromPreviousTD) { ...@@ -4194,44 +4185,53 @@ TEST_F(FormAutofillTest, LabelsInferredFromPreviousTD) {
// inferred. // inferred.
// Also <!-- comment --> is excluded. // Also <!-- comment --> is excluded.
TEST_F(FormAutofillTest, LabelsInferredFromTableWithSpecialElements) { TEST_F(FormAutofillTest, LabelsInferredFromTableWithSpecialElements) {
std::vector<base::string16> id_attributes, name_attributes, labels, names, FormFieldData expected;
values; std::vector<FormFieldData> fields;
std::vector<std::string> control_types;
id_attributes.push_back(ASCIIToUTF16("firstname")); expected.id_attribute = ASCIIToUTF16("firstname");
name_attributes.push_back(ASCIIToUTF16("")); expected.name_attribute = ASCIIToUTF16("");
labels.push_back(ASCIIToUTF16("* First Name")); expected.label = ASCIIToUTF16("* First Name");
names.push_back(id_attributes.back()); expected.name = expected.id_attribute;
values.push_back(ASCIIToUTF16("John")); expected.value = ASCIIToUTF16("John");
control_types.push_back("text"); expected.form_control_type = "text";
expected.max_length = WebInputElement::DefaultMaxLength();
fields.push_back(expected);
id_attributes.push_back(ASCIIToUTF16("middlename")); expected.id_attribute = ASCIIToUTF16("middlename");
name_attributes.push_back(ASCIIToUTF16("")); expected.name_attribute = ASCIIToUTF16("");
labels.push_back(ASCIIToUTF16("* Middle Name")); expected.label = ASCIIToUTF16("* Middle Name");
names.push_back(id_attributes.back()); expected.name = expected.id_attribute;
values.push_back(ASCIIToUTF16("Joe")); expected.value = ASCIIToUTF16("Joe");
control_types.push_back("text"); expected.form_control_type = "text";
expected.max_length = WebInputElement::DefaultMaxLength();
fields.push_back(expected);
id_attributes.push_back(ASCIIToUTF16("lastname")); expected.id_attribute = ASCIIToUTF16("lastname");
name_attributes.push_back(ASCIIToUTF16("")); expected.name_attribute = ASCIIToUTF16("");
labels.push_back(ASCIIToUTF16("* Last Name")); expected.label = ASCIIToUTF16("* Last Name");
names.push_back(id_attributes.back()); expected.name = expected.id_attribute;
values.push_back(ASCIIToUTF16("Smith")); expected.value = ASCIIToUTF16("Smith");
control_types.push_back("text"); expected.form_control_type = "text";
expected.max_length = WebInputElement::DefaultMaxLength();
fields.push_back(expected);
id_attributes.push_back(ASCIIToUTF16("country")); expected.id_attribute = ASCIIToUTF16("country");
name_attributes.push_back(ASCIIToUTF16("")); expected.name_attribute = ASCIIToUTF16("");
labels.push_back(ASCIIToUTF16("* Country")); expected.label = ASCIIToUTF16("* Country");
names.push_back(id_attributes.back()); expected.name = expected.id_attribute;
values.push_back(ASCIIToUTF16("US")); expected.value = ASCIIToUTF16("US");
control_types.push_back("select-one"); expected.form_control_type = "select-one";
expected.max_length = 0;
fields.push_back(expected);
id_attributes.push_back(ASCIIToUTF16("email")); expected.id_attribute = ASCIIToUTF16("email");
name_attributes.push_back(ASCIIToUTF16("")); expected.name_attribute = ASCIIToUTF16("");
labels.push_back(ASCIIToUTF16("* Email")); expected.label = ASCIIToUTF16("* Email");
names.push_back(id_attributes.back()); expected.name = expected.id_attribute;
values.push_back(ASCIIToUTF16("john@example.com")); expected.value = ASCIIToUTF16("john@example.com");
control_types.push_back("text"); expected.form_control_type = "text";
expected.max_length = WebInputElement::DefaultMaxLength();
fields.push_back(expected);
ExpectLabelsAndTypes( ExpectLabelsAndTypes(
"<FORM name='TestForm' action='http://cnn.com' method='post'>" "<FORM name='TestForm' action='http://cnn.com' method='post'>"
...@@ -4299,7 +4299,7 @@ TEST_F(FormAutofillTest, LabelsInferredFromTableWithSpecialElements) { ...@@ -4299,7 +4299,7 @@ TEST_F(FormAutofillTest, LabelsInferredFromTableWithSpecialElements) {
" </TR>" " </TR>"
"</TABLE>" "</TABLE>"
"</FORM>", "</FORM>",
id_attributes, name_attributes, labels, names, values, control_types); fields);
} }
TEST_F(FormAutofillTest, LabelsInferredFromTableLabels) { TEST_F(FormAutofillTest, LabelsInferredFromTableLabels) {
......
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