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 // The users enters a username. No password - no fallback. |
| 3033 SimulateUsernameChange(kUsernameName); |
| 3034 EXPECT_EQ(0, fake_driver_.called_show_manual_fallback_count()); |
| 3035 |
| 3036 // The user enters a password. |
| 3037 SimulatePasswordChange(kPasswordName); |
| 3038 // SimulateUsernameChange/SimulatePasswordChange calls |
| 3039 // PasswordAutofillAgent::UpdateStateForTextChange only once. |
| 3040 EXPECT_EQ(1, fake_driver_.called_show_manual_fallback_count()); |
| 3041 |
| 3042 // Remove one character from the password value. |
| 3043 SimulateUserTypingASCIICharacter(ui::VKEY_BACK, true); |
| 3044 EXPECT_EQ(2, fake_driver_.called_show_manual_fallback_count()); |
| 3045 |
| 3046 // Add one character to the username value. |
| 3047 SetFocused(username_element_); |
| 3048 SimulateUserTypingASCIICharacter('a', true); |
| 3049 EXPECT_EQ(3, fake_driver_.called_show_manual_fallback_count()); |
| 3050 |
| 3051 // Remove username value. |
| 3052 SimulateUsernameChange(""); |
| 3053 EXPECT_EQ(4, fake_driver_.called_show_manual_fallback_count()); |
| 3054 |
| 3055 // Change the password. Despite of empty username the fallback is still |
| 3056 // there. |
| 3057 SetFocused(password_element_); |
| 3058 SimulateUserTypingASCIICharacter('a', true); |
| 3059 EXPECT_EQ(5, fake_driver_.called_show_manual_fallback_count()); |
| 3060 |
| 3061 // Remove password value. The fallback should be disabled. |
| 3062 SimulatePasswordChange(""); |
| 3063 EXPECT_EQ(0, fake_driver_.called_show_manual_fallback_count()); |
| 3064 |
| 3065 // The user enters new password. Show the fallback again. |
| 3066 SimulateUserTypingASCIICharacter('a', true); |
| 3067 EXPECT_EQ(1, fake_driver_.called_show_manual_fallback_count()); |
| 3068 } |
| 3069 |
| 3070 TEST_F(PasswordAutofillAgentTest, ManualFallbackForSaving_PasswordChangeForm) { |
| 3071 LoadHTML(kPasswordChangeFormHTML); |
| 3072 UpdateOriginForHTML(kPasswordChangeFormHTML); |
| 3073 UpdateUsernameAndPasswordElements(); |
| 3074 |
| 3075 // No password to save yet - no fallback. |
| 3076 SimulateUsernameChange(kUsernameName); |
| 3077 EXPECT_EQ(0, fake_driver_.called_show_manual_fallback_count()); |
| 3078 |
| 3079 // The user enters in the current password field. The fallback should be |
| 3080 // available to save the entered value. |
| 3081 SimulatePasswordChange(kPasswordName); |
| 3082 // SimulateUsernameChange/SimulatePasswordChange calls |
| 3083 // PasswordAutofillAgent::UpdateStateForTextChange only once. |
| 3084 EXPECT_EQ(1, fake_driver_.called_show_manual_fallback_count()); |
| 3085 |
| 3086 // The user types into the new password field. The fallback should be updated. |
| 3087 WebInputElement new_password = GetInputElementByID("newpassword"); |
| 3088 ASSERT_FALSE(new_password.IsNull()); |
| 3089 SetFocused(new_password); |
| 3090 SimulateUserTypingASCIICharacter('a', true); |
| 3091 EXPECT_EQ(2, fake_driver_.called_show_manual_fallback_count()); |
| 3092 |
| 3093 // Edits of the confirmation password field trigger fallback updates. |
| 3094 WebInputElement confirmation_password = |
| 3095 GetInputElementByID("confirmpassword"); |
| 3096 ASSERT_FALSE(confirmation_password.IsNull()); |
| 3097 SetFocused(confirmation_password); |
| 3098 SimulateUserTypingASCIICharacter('a', true); |
| 3099 EXPECT_EQ(3, fake_driver_.called_show_manual_fallback_count()); |
| 3100 |
| 3101 // Clear all password fields. The fallback should be disabled. |
| 3102 SimulatePasswordChange(""); |
| 3103 SimulateUserInputChangeForElement(&new_password, ""); |
| 3104 SimulateUserInputChangeForElement(&confirmation_password, ""); |
| 3105 EXPECT_EQ(0, fake_driver_.called_show_manual_fallback_count()); |
| 3106 } |
3031 // Tests that information about Gaia reauthentication form is not sent to the | 3107 // Tests that information about Gaia reauthentication form is not sent to the |
3032 // browser, nor on load nor on user click. | 3108 // browser, nor on load nor on user click. |
3033 TEST_F(PasswordAutofillAgentTest, GaiaReauthenticationFormIgnored) { | 3109 TEST_F(PasswordAutofillAgentTest, GaiaReauthenticationFormIgnored) { |
3034 // HTML is already loaded in test SetUp method, so information about password | 3110 // HTML is already loaded in test SetUp method, so information about password |
3035 // forms was already sent to the |fake_drive_|. Hence it should be reset. | 3111 // forms was already sent to the |fake_drive_|. Hence it should be reset. |
3036 fake_driver_.reset_password_forms_calls(); | 3112 fake_driver_.reset_password_forms_calls(); |
3037 | 3113 |
3038 const char kGaiaReauthenticationFormHTML[] = | 3114 const char kGaiaReauthenticationFormHTML[] = |
3039 "<FORM id='ReauthenticationForm'>" | 3115 "<FORM id='ReauthenticationForm'>" |
3040 " <INPUT type='hidden' name='continue' " | 3116 " <INPUT type='hidden' name='continue' " |
(...skipping 10 matching lines...) Expand all Loading... |
3051 // Simulate a user clicking on the password element. | 3127 // Simulate a user clicking on the password element. |
3052 static_cast<PageClickListener*>(autofill_agent_) | 3128 static_cast<PageClickListener*>(autofill_agent_) |
3053 ->FormControlElementClicked(password_element_, false); | 3129 ->FormControlElementClicked(password_element_, false); |
3054 | 3130 |
3055 // Check that no information about Gaia reauthentication is not sent. | 3131 // Check that no information about Gaia reauthentication is not sent. |
3056 EXPECT_FALSE(fake_driver_.called_password_forms_parsed()); | 3132 EXPECT_FALSE(fake_driver_.called_password_forms_parsed()); |
3057 EXPECT_FALSE(fake_driver_.called_password_forms_rendered()); | 3133 EXPECT_FALSE(fake_driver_.called_password_forms_rendered()); |
3058 } | 3134 } |
3059 | 3135 |
3060 } // namespace autofill | 3136 } // namespace autofill |
OLD | NEW |