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

Unified Diff: components/autofill/content/renderer/password_form_conversion_utils_browsertest.cc

Issue 1286593003: [Password Manager] Store forms with field name and id attributes missing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed mac bot failure. Created 5 years, 3 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/content/renderer/password_form_conversion_utils_browsertest.cc
diff --git a/components/autofill/content/renderer/password_form_conversion_utils_browsertest.cc b/components/autofill/content/renderer/password_form_conversion_utils_browsertest.cc
index 771cdc7284ff8b2b5e7e56ba6855ca2d5e2046a1..fe2a3920e5fd2bdebec2afab1817a83c212222d9 100644
--- a/components/autofill/content/renderer/password_form_conversion_utils_browsertest.cc
+++ b/components/autofill/content/renderer/password_form_conversion_utils_browsertest.cc
@@ -110,6 +110,14 @@ class PasswordFormBuilder {
return html_ + "</FORM>";
}
+ // Appends a field of |type| without name or id attribute at the end of the
+ // form.
+ void AddAnonymousInputField(const char* type) {
+ std::string type_attribute(type ? base::StringPrintf("type=\"%s\"", type)
+ : "");
+ base::StringAppendF(&html_, "<INPUT %s/>", type_attribute.c_str());
+ }
+
private:
std::string html_;
@@ -982,4 +990,68 @@ TEST_F(MAYBE_PasswordFormConversionUtilsTest, IsGaiaReauthFormIgnored) {
GURL("https://google.com"), control_elements));
}
+TEST_F(MAYBE_PasswordFormConversionUtilsTest,
+ IdentifyingFieldsWithoutNameOrIdAttributes) {
+ const char* kEmpty = nullptr;
+ const struct {
+ const char* username_fieldname;
+ const char* password_fieldname;
+ const char* new_password_fieldname;
+ const char* expected_username_element;
+ const char* expected_password_element;
+ const char* expected_new_password_element;
+ } test_cases[] = {
+ {"username", "password", "new_password", "username", "password",
+ "new_password"},
+ {"username", "password", kEmpty, "username", "password",
+ "anonymous_new_password"},
+ {"username", kEmpty, kEmpty, "username", "anonymous_password",
+ "anonymous_new_password"},
+ {kEmpty, kEmpty, kEmpty, "anonymous_username", "anonymous_password",
+ "anonymous_new_password"},
+ };
+
+ for (size_t i = 0; i < arraysize(test_cases); ++i) {
+ SCOPED_TRACE(testing::Message()
+ << "Iteration " << i << ", expected_username "
+ << test_cases[i].expected_username_element
+ << ", expected_password"
+ << test_cases[i].expected_password_element
+ << ", expected_new_password "
+ << test_cases[i].expected_new_password_element);
+
+ PasswordFormBuilder builder(kTestFormActionURL);
+ if (test_cases[i].username_fieldname == kEmpty) {
+ builder.AddAnonymousInputField("text");
+ } else {
+ builder.AddTextField(test_cases[i].username_fieldname, "", kEmpty);
+ }
+
+ if (test_cases[i].password_fieldname == kEmpty) {
+ builder.AddAnonymousInputField("password");
+ } else {
+ builder.AddPasswordField(test_cases[i].password_fieldname, "", kEmpty);
+ }
+
+ if (test_cases[i].new_password_fieldname == kEmpty) {
+ builder.AddAnonymousInputField("password");
+ } else {
+ builder.AddPasswordField(test_cases[i].new_password_fieldname, "",
+ kEmpty);
+ }
+ std::string html = builder.ProduceHTML();
+
+ scoped_ptr<PasswordForm> password_form;
+ LoadHTMLAndConvertForm(html, &password_form, nullptr);
+ EXPECT_TRUE(password_form);
+
+ EXPECT_EQ(base::UTF8ToUTF16(test_cases[i].expected_username_element),
+ password_form->username_element);
+ EXPECT_EQ(base::UTF8ToUTF16(test_cases[i].expected_password_element),
+ password_form->password_element);
+ EXPECT_EQ(base::UTF8ToUTF16(test_cases[i].expected_new_password_element),
+ password_form->new_password_element);
+ }
+}
+
} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698