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

Unified Diff: chrome/renderer/autofill/password_autofill_agent_browsertest.cc

Issue 2814093002: [Password Manager] Send a request to the password store if there is a password field on a page (Closed)
Patch Set: Added more tests Created 3 years, 8 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: chrome/renderer/autofill/password_autofill_agent_browsertest.cc
diff --git a/chrome/renderer/autofill/password_autofill_agent_browsertest.cc b/chrome/renderer/autofill/password_autofill_agent_browsertest.cc
index 66529cad25293b47249dabde58cd088f8422040b..4b618b0be2427062996015f68d2dca5737469b68 100644
--- a/chrome/renderer/autofill/password_autofill_agent_browsertest.cc
+++ b/chrome/renderer/autofill/password_autofill_agent_browsertest.cc
@@ -95,6 +95,12 @@ const char kEmptyFormHTML[] =
"<head> <style> form {display: inline;} </style> </head>"
"<body> <form> </form> </body>";
+const char kFormWithoutPasswordsHTML[] =
+ "<FORM>"
+ " <INPUT type='text' id='random_field'/>"
+ " <INPUT type='text' id='username'/>"
+ "</FORM>";
+
const char kNonVisibleFormHTML[] =
"<head> <style> form {visibility: hidden;} </style> </head>"
"<body>"
@@ -857,53 +863,132 @@ TEST_F(PasswordAutofillAgentTest, IsWebElementVisibleTest) {
EXPECT_FALSE(form_util::IsWebElementVisible(web_control_elements[0]));
}
-TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest) {
- fake_driver_.reset_password_forms_rendered();
+TEST_F(PasswordAutofillAgentTest,
+ SendPasswordFormsTest_VisibleFormWithNoUsername) {
+ fake_driver_.reset_password_forms_calls();
LoadHTML(kVisibleFormWithNoUsernameHTML);
base::RunLoop().RunUntilIdle();
+ EXPECT_TRUE(fake_driver_.called_password_forms_parsed());
+ ASSERT_TRUE(fake_driver_.password_forms_parsed());
+ EXPECT_FALSE(fake_driver_.password_forms_parsed()->empty());
EXPECT_TRUE(fake_driver_.called_password_forms_rendered());
- ASSERT_TRUE(static_cast<bool>(fake_driver_.password_forms_rendered()));
+ ASSERT_TRUE(fake_driver_.password_forms_rendered());
EXPECT_FALSE(fake_driver_.password_forms_rendered()->empty());
+}
- fake_driver_.reset_password_forms_rendered();
+TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest_EmptyForm) {
+ fake_driver_.reset_password_forms_calls();
LoadHTML(kEmptyFormHTML);
base::RunLoop().RunUntilIdle();
+ EXPECT_FALSE(fake_driver_.called_password_forms_parsed());
+ EXPECT_TRUE(fake_driver_.called_password_forms_rendered());
+ ASSERT_TRUE(fake_driver_.password_forms_rendered());
+ EXPECT_TRUE(fake_driver_.password_forms_rendered()->empty());
+}
+
+TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest_FormWithoutPasswords) {
+ fake_driver_.reset_password_forms_calls();
+ LoadHTML(kFormWithoutPasswordsHTML);
+ base::RunLoop().RunUntilIdle();
+ EXPECT_FALSE(fake_driver_.called_password_forms_parsed());
EXPECT_TRUE(fake_driver_.called_password_forms_rendered());
- ASSERT_TRUE(static_cast<bool>(fake_driver_.password_forms_rendered()));
+ ASSERT_TRUE(fake_driver_.password_forms_rendered());
EXPECT_TRUE(fake_driver_.password_forms_rendered()->empty());
+}
- fake_driver_.reset_password_forms_rendered();
+TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest_NonDisplayedForm) {
+ fake_driver_.reset_password_forms_calls();
LoadHTML(kNonDisplayedFormHTML);
base::RunLoop().RunUntilIdle();
+ EXPECT_TRUE(fake_driver_.called_password_forms_parsed());
+ ASSERT_TRUE(fake_driver_.password_forms_parsed());
+ EXPECT_FALSE(fake_driver_.password_forms_parsed()->empty());
EXPECT_TRUE(fake_driver_.called_password_forms_rendered());
- ASSERT_TRUE(static_cast<bool>(fake_driver_.password_forms_rendered()));
+ ASSERT_TRUE(fake_driver_.password_forms_rendered());
EXPECT_TRUE(fake_driver_.password_forms_rendered()->empty());
+}
- fake_driver_.reset_password_forms_rendered();
+TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest_NonVisibleForm) {
+ fake_driver_.reset_password_forms_calls();
LoadHTML(kNonVisibleFormHTML);
base::RunLoop().RunUntilIdle();
+ EXPECT_TRUE(fake_driver_.called_password_forms_parsed());
+ ASSERT_TRUE(fake_driver_.password_forms_parsed());
+ EXPECT_FALSE(fake_driver_.password_forms_parsed()->empty());
+ EXPECT_TRUE(fake_driver_.called_password_forms_rendered());
+ ASSERT_TRUE(fake_driver_.password_forms_rendered());
+ EXPECT_TRUE(fake_driver_.password_forms_rendered()->empty());
+}
+
+TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest_PasswordChangeForm) {
+ fake_driver_.reset_password_forms_calls();
+ LoadHTML(kPasswordChangeFormHTML);
+ base::RunLoop().RunUntilIdle();
+ EXPECT_TRUE(fake_driver_.called_password_forms_parsed());
+ ASSERT_TRUE(fake_driver_.password_forms_parsed());
+ EXPECT_FALSE(fake_driver_.password_forms_parsed()->empty());
+ EXPECT_TRUE(fake_driver_.called_password_forms_rendered());
+ ASSERT_TRUE(fake_driver_.password_forms_rendered());
+ EXPECT_FALSE(fake_driver_.password_forms_rendered()->empty());
+}
+
+TEST_F(PasswordAutofillAgentTest,
+ SendPasswordFormsTest_CannotCreatePasswordForm) {
+ // This test checks that a request to the store is sent even if we fail to
+ // create a |PasswordForm|.
+ fake_driver_.reset_password_forms_calls();
+ const char kInvalidFormHTML[] =
+ "<FORM name='ChangeWithUsernameForm' action='http://www.bidule.com'>"
+ " <INPUT type='password' id='pwd1' value='1'/>"
+ " <INPUT type='password' id='pwd1' value='2'/>"
+ " <INPUT type='password' id='pwd2' value='3'/>"
+ " <INPUT type='submit' value='Login'/>"
+ "</FORM>";
+ LoadHTML(kInvalidFormHTML);
+ base::RunLoop().RunUntilIdle();
+ EXPECT_TRUE(fake_driver_.called_password_forms_parsed());
+ ASSERT_TRUE(fake_driver_.password_forms_parsed());
+ EXPECT_FALSE(fake_driver_.password_forms_parsed()->empty());
EXPECT_TRUE(fake_driver_.called_password_forms_rendered());
- ASSERT_TRUE(static_cast<bool>(fake_driver_.password_forms_rendered()));
+ ASSERT_TRUE(fake_driver_.password_forms_rendered());
EXPECT_TRUE(fake_driver_.password_forms_rendered()->empty());
}
+TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest_ReloadTab) {
+ // PasswordAutofillAgent::sent_request_to_store_ disables duplicate requests
+ // to the store. This test checks that new request will be sent if the frame
+ // has been reloaded.
+ fake_driver_.reset_password_forms_calls();
+ LoadHTML(kNonVisibleFormHTML);
+ base::RunLoop().RunUntilIdle();
+ EXPECT_TRUE(fake_driver_.called_password_forms_parsed());
+
+ fake_driver_.reset_password_forms_calls();
+ std::string url_string = "data:text/html;charset=utf-8,";
+ url_string.append(kNonVisibleFormHTML);
+ Reload(GURL(url_string));
+ EXPECT_TRUE(fake_driver_.called_password_forms_parsed());
+ ASSERT_TRUE(fake_driver_.password_forms_parsed());
+ EXPECT_FALSE(fake_driver_.password_forms_parsed()->empty());
+}
+
TEST_F(PasswordAutofillAgentTest, SendPasswordFormsTest_Redirection) {
- fake_driver_.reset_password_forms_rendered();
+ fake_driver_.reset_password_forms_calls();
LoadHTML(kEmptyWebpage);
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(fake_driver_.called_password_forms_rendered());
- fake_driver_.reset_password_forms_rendered();
+ fake_driver_.reset_password_forms_calls();
LoadHTML(kRedirectionWebpage);
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(fake_driver_.called_password_forms_rendered());
- fake_driver_.reset_password_forms_rendered();
+ fake_driver_.reset_password_forms_calls();
LoadHTML(kSimpleWebpage);
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(fake_driver_.called_password_forms_rendered());
- fake_driver_.reset_password_forms_rendered();
+ fake_driver_.reset_password_forms_calls();
LoadHTML(kWebpageWithDynamicContent);
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(fake_driver_.called_password_forms_rendered());

Powered by Google App Engine
This is Rietveld 408576698