Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/autofill/content/renderer/password_autofill_agent.h" | 5 #include "components/autofill/content/renderer/password_autofill_agent.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 3010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3021 | 3021 |
| 3022 // Repeatedly occurring AJAX events without removing the input elements | 3022 // Repeatedly occurring AJAX events without removing the input elements |
| 3023 // shouldn't be treated as a password submission. | 3023 // shouldn't be treated as a password submission. |
| 3024 password_autofill_agent_->AJAXSucceeded(); | 3024 password_autofill_agent_->AJAXSucceeded(); |
| 3025 base::RunLoop().RunUntilIdle(); | 3025 base::RunLoop().RunUntilIdle(); |
| 3026 | 3026 |
| 3027 ASSERT_FALSE(fake_driver_.called_password_form_submitted()); | 3027 ASSERT_FALSE(fake_driver_.called_password_form_submitted()); |
| 3028 ASSERT_FALSE(static_cast<bool>(fake_driver_.password_form_submitted())); | 3028 ASSERT_FALSE(static_cast<bool>(fake_driver_.password_form_submitted())); |
| 3029 } | 3029 } |
| 3030 | 3030 |
| 3031 TEST_F(PasswordAutofillAgentTest, ManualFallbackForSaving) { | |
| 3032 scoped_feature_list_.InitAndEnableFeature( | |
| 3033 password_manager::features::kEnableManualFallbackForSaving); | |
| 3034 | |
| 3035 // The users enters a username. No password - no fallback. | |
| 3036 SimulateUsernameChange(kUsernameName); | |
| 3037 EXPECT_EQ(0, fake_driver_.called_show_manual_fallback_cnt()); | |
| 3038 | |
| 3039 // The user enters a password. | |
| 3040 SimulatePasswordChange(kPasswordName); | |
| 3041 // SimulateUsernameChange/SimulatePasswordChange calls | |
| 3042 // PasswordAutofillAgent::UpdateStateForTextChange only once. | |
| 3043 EXPECT_EQ(1, fake_driver_.called_show_manual_fallback_cnt()); | |
| 3044 | |
| 3045 // Remove one character from the password value. | |
| 3046 SimulateUserTypingASCIICharacter(ui::VKEY_BACK, true); | |
| 3047 EXPECT_EQ(2, fake_driver_.called_show_manual_fallback_cnt()); | |
| 3048 | |
| 3049 // Add one character to the username value. | |
| 3050 SetFocused(username_element_); | |
| 3051 SimulateUserTypingASCIICharacter('a', true); | |
| 3052 EXPECT_EQ(3, fake_driver_.called_show_manual_fallback_cnt()); | |
| 3053 | |
| 3054 // Remove username value. | |
| 3055 SimulateUsernameChange(""); | |
| 3056 EXPECT_EQ(4, fake_driver_.called_show_manual_fallback_cnt()); | |
| 3057 | |
| 3058 // Change the password. Despite of empty username the fallback is still | |
| 3059 // there. | |
| 3060 SetFocused(password_element_); | |
| 3061 SimulateUserTypingASCIICharacter('a', true); | |
| 3062 EXPECT_EQ(5, fake_driver_.called_show_manual_fallback_cnt()); | |
| 3063 | |
| 3064 // Remove password value. The fallback should be disabled. | |
| 3065 SimulatePasswordChange(""); | |
| 3066 EXPECT_EQ(0, fake_driver_.called_show_manual_fallback_cnt()); | |
| 3067 | |
| 3068 // The user enters new password. Show the fallback again. | |
| 3069 SimulateUserTypingASCIICharacter('a', true); | |
| 3070 EXPECT_EQ(1, fake_driver_.called_show_manual_fallback_cnt()); | |
| 3071 } | |
| 3072 | |
| 3073 TEST_F(PasswordAutofillAgentTest, ManualFallbackForSaving_PasswordChangeForm) { | |
| 3074 scoped_feature_list_.InitAndEnableFeature( | |
| 3075 password_manager::features::kEnableManualFallbackForSaving); | |
| 3076 | |
| 3077 LoadHTML(kPasswordChangeFormHTML); | |
| 3078 UpdateOriginForHTML(kPasswordChangeFormHTML); | |
| 3079 UpdateUsernameAndPasswordElements(); | |
| 3080 | |
| 3081 // No password to save yet - no fallback. | |
| 3082 SimulateUsernameChange(kUsernameName); | |
| 3083 EXPECT_EQ(0, fake_driver_.called_show_manual_fallback_cnt()); | |
| 3084 | |
| 3085 // The user enters in the current password field. The fallback should be | |
| 3086 // 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.
| |
| 3087 SimulatePasswordChange(kPasswordName); | |
| 3088 // SimulateUsernameChange/SimulatePasswordChange calls | |
| 3089 // PasswordAutofillAgent::UpdateStateForTextChange only once. | |
| 3090 EXPECT_EQ(1, fake_driver_.called_show_manual_fallback_cnt()); | |
| 3091 | |
| 3092 // The user types into the new password field. The fallback should be updated. | |
| 3093 WebInputElement new_password = GetInputElementByID("newpassword"); | |
| 3094 ASSERT_FALSE(new_password.IsNull()); | |
| 3095 SetFocused(new_password); | |
| 3096 SimulateUserTypingASCIICharacter('a', true); | |
| 3097 EXPECT_EQ(2, fake_driver_.called_show_manual_fallback_cnt()); | |
| 3098 | |
| 3099 // Edits of the confirmation password field trigger fallback updates. | |
| 3100 WebInputElement confirmation_password = | |
| 3101 GetInputElementByID("confirmpassword"); | |
| 3102 ASSERT_FALSE(confirmation_password.IsNull()); | |
| 3103 SetFocused(confirmation_password); | |
| 3104 SimulateUserTypingASCIICharacter('a', true); | |
| 3105 EXPECT_EQ(3, fake_driver_.called_show_manual_fallback_cnt()); | |
| 3106 | |
| 3107 // 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
| |
| 3108 SimulatePasswordChange(""); | |
| 3109 SimulateUserInputChangeForElement(&new_password, ""); | |
| 3110 SimulateUserInputChangeForElement(&confirmation_password, ""); | |
| 3111 EXPECT_EQ(0, fake_driver_.called_show_manual_fallback_cnt()); | |
| 3112 } | |
| 3113 | |
| 3031 } // namespace autofill | 3114 } // namespace autofill |
| OLD | NEW |