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 36a29f66cda20faf58b14da4bd43b80faade5e36..4ef8c97846c12ac639f61736f8260ea49d4a2705 100644 |
--- a/chrome/renderer/autofill/password_autofill_agent_browsertest.cc |
+++ b/chrome/renderer/autofill/password_autofill_agent_browsertest.cc |
@@ -3028,4 +3028,87 @@ TEST_F(PasswordAutofillAgentTest, NoForm_MultipleAJAXEventsWithoutSubmission) { |
ASSERT_FALSE(static_cast<bool>(fake_driver_.password_form_submitted())); |
} |
+TEST_F(PasswordAutofillAgentTest, ManualFallbackForSaving) { |
+ scoped_feature_list_.InitAndEnableFeature( |
+ password_manager::features::kEnableManualFallbackForSaving); |
+ |
+ // The users enters a username. No password - no fallback. |
+ SimulateUsernameChange(kUsernameName); |
+ EXPECT_EQ(0, fake_driver_.called_show_manual_fallback_cnt()); |
+ |
+ // The user enters a password. |
+ SimulatePasswordChange(kPasswordName); |
+ // SimulateUsernameChange/SimulatePasswordChange calls |
+ // PasswordAutofillAgent::UpdateStateForTextChange only once. |
+ EXPECT_EQ(1, fake_driver_.called_show_manual_fallback_cnt()); |
+ |
+ // Remove one character from the password value. |
+ SimulateUserTypingASCIICharacter(ui::VKEY_BACK, true); |
+ EXPECT_EQ(2, fake_driver_.called_show_manual_fallback_cnt()); |
+ |
+ // Add one character to the username value. |
+ SetFocused(username_element_); |
+ SimulateUserTypingASCIICharacter('a', true); |
+ EXPECT_EQ(3, fake_driver_.called_show_manual_fallback_cnt()); |
+ |
+ // Remove username value. |
+ SimulateUsernameChange(""); |
+ EXPECT_EQ(4, fake_driver_.called_show_manual_fallback_cnt()); |
+ |
+ // Change the password. Despite of empty username the fallback is still |
+ // there. |
+ SetFocused(password_element_); |
+ SimulateUserTypingASCIICharacter('a', true); |
+ EXPECT_EQ(5, fake_driver_.called_show_manual_fallback_cnt()); |
+ |
+ // Remove password value. The fallback should be disabled. |
+ SimulatePasswordChange(""); |
+ EXPECT_EQ(0, fake_driver_.called_show_manual_fallback_cnt()); |
+ |
+ // The user enters new password. Show the fallback again. |
+ SimulateUserTypingASCIICharacter('a', true); |
+ EXPECT_EQ(1, fake_driver_.called_show_manual_fallback_cnt()); |
+} |
+ |
+TEST_F(PasswordAutofillAgentTest, ManualFallbackForSaving_PasswordChangeForm) { |
+ scoped_feature_list_.InitAndEnableFeature( |
+ password_manager::features::kEnableManualFallbackForSaving); |
+ |
+ LoadHTML(kPasswordChangeFormHTML); |
+ UpdateOriginForHTML(kPasswordChangeFormHTML); |
+ UpdateUsernameAndPasswordElements(); |
+ |
+ // No password to save yet - no fallback. |
+ SimulateUsernameChange(kUsernameName); |
+ EXPECT_EQ(0, fake_driver_.called_show_manual_fallback_cnt()); |
+ |
+ // The user enters in the current password field. The fallback should be |
+ // available to save the entered value. It's a subject to re-consider. |
vasilii
2017/07/21 12:48:20
Why do we need to reconsider it?
kolos1
2017/07/24 15:33:30
Below the user types into the new password field.
|
+ SimulatePasswordChange(kPasswordName); |
+ // SimulateUsernameChange/SimulatePasswordChange calls |
+ // PasswordAutofillAgent::UpdateStateForTextChange only once. |
+ EXPECT_EQ(1, fake_driver_.called_show_manual_fallback_cnt()); |
+ |
+ // The user types into the new password field. The fallback should be updated. |
+ WebInputElement new_password = GetInputElementByID("newpassword"); |
+ ASSERT_FALSE(new_password.IsNull()); |
+ SetFocused(new_password); |
+ SimulateUserTypingASCIICharacter('a', true); |
+ EXPECT_EQ(2, fake_driver_.called_show_manual_fallback_cnt()); |
+ |
+ // Edits of the confirmation password field trigger fallback updates. |
+ WebInputElement confirmation_password = |
+ GetInputElementByID("confirmpassword"); |
+ ASSERT_FALSE(confirmation_password.IsNull()); |
+ SetFocused(confirmation_password); |
+ SimulateUserTypingASCIICharacter('a', true); |
+ EXPECT_EQ(3, fake_driver_.called_show_manual_fallback_cnt()); |
+ |
+ // Clear all password fields. The fallback should be disabled. |
vasilii
2017/07/21 12:48:20
What happens if you have two password fields. The
kolos1
2017/07/24 15:33:30
The manual fallback relies on what GetPasswordForm
|
+ SimulatePasswordChange(""); |
+ SimulateUserInputChangeForElement(&new_password, ""); |
+ SimulateUserInputChangeForElement(&confirmation_password, ""); |
+ EXPECT_EQ(0, fake_driver_.called_show_manual_fallback_cnt()); |
+} |
+ |
} // namespace autofill |