Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Unified Diff: components/autofill/core/browser/form_structure_unittest.cc

Issue 659793005: [Password Generation] Always query password forms via Autofill (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/autofill/core/browser/form_structure_unittest.cc
diff --git a/components/autofill/core/browser/form_structure_unittest.cc b/components/autofill/core/browser/form_structure_unittest.cc
index 9d2ccc481b136e02e2ca134a0bfa37799c72c090..897efb679b1bb1748add825452a50076f6dab10a 100644
--- a/components/autofill/core/browser/form_structure_unittest.cc
+++ b/components/autofill/core/browser/form_structure_unittest.cc
@@ -484,6 +484,41 @@ TEST(FormStructureTest, AutocompleteAttributeOverridesOtherHeuristics) {
EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(2)->heuristic_type());
}
+// Even with an 'autocomplete' attribute set, ShouldBeCrowdsourced() should
+// return true if the structure contains a password field, since there are
+// no local heuristics to depend upon in this case. Fields will still not be
+// considered autofillable though.
+TEST(FormStructureTest, PasswordFormShouldBeCrowdsourced) {
+ scoped_ptr<FormStructure> form_structure;
Ilya Sherman 2014/10/24 22:42:31 nit: Why use a scoped_ptr here, rather than stack-
Garrett Casto 2014/10/24 23:19:52 The evils of copy and paste. It is rather common i
+ FormData form;
+
+ // Start with a regular contact form.
+ FormFieldData field;
+ field.form_control_type = "text";
+
+ field.label = ASCIIToUTF16("First Name");
+ field.name = ASCIIToUTF16("firstname");
+ form.fields.push_back(field);
+
+ field.label = ASCIIToUTF16("Last Name");
+ field.name = ASCIIToUTF16("lastname");
+ form.fields.push_back(field);
+
+ field.label = ASCIIToUTF16("Email");
+ field.name = ASCIIToUTF16("email");
+ field.autocomplete_attribute = "username";
+ form.fields.push_back(field);
+
+ field.label = ASCIIToUTF16("Password");
+ field.name = ASCIIToUTF16("Password");
+ field.form_control_type = "password";
+ form.fields.push_back(field);
+
+ form_structure.reset(new FormStructure(form));
+ form_structure->DetermineHeuristicTypes(TestAutofillMetrics());
+ EXPECT_TRUE(form_structure->ShouldBeCrowdsourced());
+}
+
// Verify that we can correctly process sections listed in the |autocomplete|
// attribute.
TEST(FormStructureTest, HeuristicsAutocompleteAttributeWithSections) {
@@ -2347,4 +2382,91 @@ TEST(FormStructureTest, PossibleValues) {
EXPECT_EQ(0U, form_structure2.PossibleValues(ADDRESS_BILLING_COUNTRY).size());
}
+TEST(FormStructureTest, ParseQueryResponse) {
+ FormData form;
+ FormFieldData field;
+ field.form_control_type = "text";
+
+ field.label = ASCIIToUTF16("fullname");
+ field.name = ASCIIToUTF16("fullname");
+ form.fields.push_back(field);
+
+ field.label = ASCIIToUTF16("address");
+ field.name = ASCIIToUTF16("address");
+ form.fields.push_back(field);
+
+ // Checkable fields should be ignored in parsing
+ FormFieldData checkable_field;
+ checkable_field.label = ASCIIToUTF16("radio_button");
+ checkable_field.form_control_type = "radio";
+ checkable_field.is_checkable = true;
+ form.fields.push_back(checkable_field);
+
+ std::vector<FormStructure*> forms;
+ forms.push_back(new FormStructure(form));
+
+ field.label = ASCIIToUTF16("email");
+ field.name = ASCIIToUTF16("email");
+ form.fields.push_back(field);
+
+ field.label = ASCIIToUTF16("password");
+ field.name = ASCIIToUTF16("password");
+ field.form_control_type = "password";
+ form.fields.push_back(field);
+
+ forms.push_back(new FormStructure(form));
+
+ std::string response =
+ "<autofillqueryresponse>"
+ "<field autofilltype=\"7\" />"
+ "<field autofilltype=\"30\" />"
+ "<field autofilltype=\"9\" />"
+ "<field autofilltype=\"0\" />"
+ "</autofillqueryresponse>";
+
+ FormStructure::ParseQueryResponse(response, forms, TestAutofillMetrics());
+
+ EXPECT_EQ(7, forms[0]->field(0)->server_type());
+ EXPECT_EQ(30, forms[0]->field(1)->server_type());
+ EXPECT_EQ(9, forms[1]->field(0)->server_type());
+ EXPECT_EQ(0, forms[1]->field(1)->server_type());
+
+ STLDeleteContainerPointers(forms.begin(), forms.end());
Ilya Sherman 2014/10/24 22:42:31 Oof. Can we use a ScopedVector to control memory
Garrett Casto 2014/10/24 23:19:52 Done.
+}
+
+// If user defined types are present, only parse password fields.
+TEST(FormStructureTest, ParseQueryResponseAuthorDefinedTypes) {
+ FormData form;
+ FormFieldData field;
+
+ field.label = ASCIIToUTF16("email");
+ field.name = ASCIIToUTF16("email");
+ field.form_control_type = "text";
+ field.autocomplete_attribute = "email";
+ form.fields.push_back(field);
+
+ field.label = ASCIIToUTF16("password");
+ field.name = ASCIIToUTF16("password");
+ field.form_control_type = "password";
+ field.autocomplete_attribute = "new-password";
+ form.fields.push_back(field);
+
+ std::vector<FormStructure*> forms;
+ forms.push_back(new FormStructure(form));
+ forms.front()->DetermineHeuristicTypes(TestAutofillMetrics());
+
+ std::string response =
+ "<autofillqueryresponse>"
+ "<field autofilltype=\"9\" />"
+ "<field autofilltype=\"76\" />"
+ "</autofillqueryresponse>";
+
+ FormStructure::ParseQueryResponse(response, forms, TestAutofillMetrics());
+
+ EXPECT_EQ(0, forms[0]->field(0)->server_type());
Ilya Sherman 2014/10/24 22:42:31 nit: I think UNKNOWN_TYPE rather than "0" would be
Garrett Casto 2014/10/24 23:19:52 It's actually NO_SERVER_DATA, but I see your point
+ EXPECT_EQ(76, forms[0]->field(1)->server_type());
+
+ STLDeleteContainerPointers(forms.begin(), forms.end());
+}
+
} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698