Commit 38f9189f authored by Vidhan's avatar Vidhan Committed by Commit Bot

[Autofill] Refactoring autofill_metrics_unittest.cc

Bug: 1127001
Change-Id: Ic565865326ca4d75ed5c21e34bc2ca207f1f5c2f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2404640Reviewed-by: default avatarChristoph Schwering <schwering@google.com>
Commit-Queue: Vidhan Jain <vidhanj@google.com>
Cr-Commit-Position: refs/heads/master@{#820448}
parent f06606a7
...@@ -48,6 +48,10 @@ FormFieldData CreateFieldByRole(ServerFieldType role) { ...@@ -48,6 +48,10 @@ FormFieldData CreateFieldByRole(ServerFieldType role) {
field.label = ASCIIToUTF16("E-mail address"); field.label = ASCIIToUTF16("E-mail address");
field.name = ASCIIToUTF16("email"); field.name = ASCIIToUTF16("email");
break; break;
case ServerFieldType::ADDRESS_HOME_LINE1:
field.label = ASCIIToUTF16("Address");
field.name = ASCIIToUTF16("home_line_one");
break;
case ServerFieldType::ADDRESS_HOME_CITY: case ServerFieldType::ADDRESS_HOME_CITY:
field.label = ASCIIToUTF16("City"); field.label = ASCIIToUTF16("City");
field.name = ASCIIToUTF16("city"); field.name = ASCIIToUTF16("city");
...@@ -84,11 +88,18 @@ FormFieldData CreateFieldByRole(ServerFieldType role) { ...@@ -84,11 +88,18 @@ FormFieldData CreateFieldByRole(ServerFieldType role) {
return field; return field;
} }
FormData GetFormData(const FormAttributes& form_attributes) { FormData GetFormData(const TestFormAttributes& test_form_attributes) {
FormData form_data; FormData form_data;
form_data.url = GURL(form_attributes.form_url); form_data.url = GURL(test_form_attributes.url);
for (const FieldDataDescription& field_description : form_attributes.fields) { form_data.action = GURL(test_form_attributes.action);
form_data.name = ASCIIToUTF16(test_form_attributes.name);
if (test_form_attributes.unique_renderer_id)
form_data.unique_renderer_id = *test_form_attributes.unique_renderer_id;
if (test_form_attributes.main_frame_origin)
form_data.main_frame_origin = *test_form_attributes.main_frame_origin;
for (const FieldDataDescription& field_description :
test_form_attributes.fields) {
FormFieldData field = CreateFieldByRole(field_description.role); FormFieldData field = CreateFieldByRole(field_description.role);
field.form_control_type = field_description.form_control_type; field.form_control_type = field_description.form_control_type;
field.is_focusable = field_description.is_focusable; field.is_focusable = field_description.is_focusable;
...@@ -98,11 +109,15 @@ FormData GetFormData(const FormAttributes& form_attributes) { ...@@ -98,11 +109,15 @@ FormData GetFormData(const FormAttributes& form_attributes) {
field.label = ASCIIToUTF16(field_description.label); field.label = ASCIIToUTF16(field_description.label);
if (ASCIIToUTF16(field_description.name) != ASCIIToUTF16(kNameText)) if (ASCIIToUTF16(field_description.name) != ASCIIToUTF16(kNameText))
field.name = ASCIIToUTF16(field_description.name); field.name = ASCIIToUTF16(field_description.name);
if (field_description.value)
field.value = ASCIIToUTF16(*field_description.value);
if (field_description.is_autofilled)
field.is_autofilled = *field_description.is_autofilled;
field.should_autocomplete = field_description.should_autocomplete; field.should_autocomplete = field_description.should_autocomplete;
form_data.fields.push_back(field); form_data.fields.push_back(field);
} }
form_data.is_formless_checkout = form_attributes.is_formless_checkout; form_data.is_formless_checkout = test_form_attributes.is_formless_checkout;
form_data.is_form_tag = form_attributes.is_form_tag; form_data.is_form_tag = test_form_attributes.is_form_tag;
return form_data; return form_data;
} }
......
...@@ -26,7 +26,10 @@ constexpr char kLabelText[] = "label"; ...@@ -26,7 +26,10 @@ constexpr char kLabelText[] = "label";
constexpr char kNameText[] = "name"; constexpr char kNameText[] = "name";
// Default form url. // Default form url.
constexpr char kFormUrl[] = "http://www.foo.com/"; constexpr char kFormUrl[] = "http://example.com/form.html";
// Default form action url.
constexpr char kFormActionUrl[] = "http://example.com/submit.html";
} // namespace } // namespace
...@@ -39,17 +42,23 @@ struct FieldDataDescription { ...@@ -39,17 +42,23 @@ struct FieldDataDescription {
bool is_focusable = true; bool is_focusable = true;
const char* label = kLabelText; const char* label = kLabelText;
const char* name = kNameText; const char* name = kNameText;
base::Optional<const char*> value = base::nullopt;
const char* autocomplete_attribute = nullptr; const char* autocomplete_attribute = nullptr;
const char* form_control_type = "text"; const char* form_control_type = "text";
bool should_autocomplete = true; bool should_autocomplete = true;
base::Optional<bool> is_autofilled = base::nullopt;
}; };
// Attributes provided to the test form. // Attributes provided to the test form.
template <typename = void> template <typename = void>
struct FormAttributes { struct TestFormAttributes {
const char* description_for_logging = ""; const char* description_for_logging;
std::vector<FieldDataDescription<>> fields = {}; std::vector<FieldDataDescription<>> fields;
const char* form_url = kFormUrl; base::Optional<FormRendererId> unique_renderer_id = base::nullopt;
const char* name = "TestForm";
const char* url = kFormUrl;
const char* action = kFormActionUrl;
base::Optional<url::Origin> main_frame_origin = base::nullopt;
bool is_formless_checkout = false; bool is_formless_checkout = false;
bool is_form_tag = true; bool is_form_tag = true;
}; };
...@@ -57,7 +66,7 @@ struct FormAttributes { ...@@ -57,7 +66,7 @@ struct FormAttributes {
// Flags determining whether the corresponding check should be run on the test // Flags determining whether the corresponding check should be run on the test
// form. // form.
template <typename = void> template <typename = void>
struct FormFlags { struct TestFormFlags {
// false means the function is not to be called. // false means the function is not to be called.
bool determine_heuristic_type = false; bool determine_heuristic_type = false;
bool parse_query_response = false; bool parse_query_response = false;
...@@ -90,15 +99,15 @@ struct ExpectedFieldTypeValues { ...@@ -90,15 +99,15 @@ struct ExpectedFieldTypeValues {
// Describes a test case for the parser. // Describes a test case for the parser.
template <typename = void> template <typename = void>
struct FormStructureTestCase { struct FormStructureTestCase {
FormAttributes<> form_attributes; TestFormAttributes<> form_attributes;
FormFlags<> form_flags; TestFormFlags<> form_flags;
ExpectedFieldTypeValues<> expected_field_types; ExpectedFieldTypeValues<> expected_field_types;
}; };
} // namespace internal } // namespace internal
using FieldDataDescription = internal::FieldDataDescription<>; using FieldDataDescription = internal::FieldDataDescription<>;
using FormAttributes = internal::FormAttributes<>; using TestFormAttributes = internal::TestFormAttributes<>;
using FormStructureTestCase = internal::FormStructureTestCase<>; using FormStructureTestCase = internal::FormStructureTestCase<>;
// Describes the |form_data|. Use this in SCOPED_TRACE if other logging // Describes the |form_data|. Use this in SCOPED_TRACE if other logging
...@@ -109,7 +118,7 @@ testing::Message DescribeFormData(const FormData& form_data); ...@@ -109,7 +118,7 @@ testing::Message DescribeFormData(const FormData& form_data);
FormFieldData CreateFieldByRole(ServerFieldType role); FormFieldData CreateFieldByRole(ServerFieldType role);
// Creates a FormData to be fed to the parser. // Creates a FormData to be fed to the parser.
FormData GetFormData(const FormAttributes& form_attributes); FormData GetFormData(const TestFormAttributes& test_form_attributes);
class FormStructureTest : public testing::Test { class FormStructureTest : public testing::Test {
protected: protected:
......
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