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

Side by Side Diff: chrome/renderer/autofill/password_autofill_agent_browsertest.cc

Issue 2915763003: [Password Manager] Show omnibox icon and anchored prompt once user start typing password (Closed)
Patch Set: Rebase Created 3 years, 4 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 unified diff | Download patch
OLDNEW
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 3020 matching lines...) Expand 10 before | Expand all | Expand 10 after
3031 3031
3032 // Repeatedly occurring AJAX events without removing the input elements 3032 // Repeatedly occurring AJAX events without removing the input elements
3033 // shouldn't be treated as a password submission. 3033 // shouldn't be treated as a password submission.
3034 password_autofill_agent_->AJAXSucceeded(); 3034 password_autofill_agent_->AJAXSucceeded();
3035 base::RunLoop().RunUntilIdle(); 3035 base::RunLoop().RunUntilIdle();
3036 3036
3037 ASSERT_FALSE(fake_driver_.called_password_form_submitted()); 3037 ASSERT_FALSE(fake_driver_.called_password_form_submitted());
3038 ASSERT_FALSE(static_cast<bool>(fake_driver_.password_form_submitted())); 3038 ASSERT_FALSE(static_cast<bool>(fake_driver_.password_form_submitted()));
3039 } 3039 }
3040 3040
3041 TEST_F(PasswordAutofillAgentTest, ManualFallbackForSaving) {
3042 // The users enters a username. No password - no fallback.
3043 SimulateUsernameChange(kUsernameName);
3044 EXPECT_EQ(0, fake_driver_.called_show_manual_fallback_for_saving_count());
3045
3046 // The user enters a password.
3047 SimulatePasswordChange(kPasswordName);
3048 // SimulateUsernameChange/SimulatePasswordChange calls
3049 // PasswordAutofillAgent::UpdateStateForTextChange only once.
3050 EXPECT_EQ(1, fake_driver_.called_show_manual_fallback_for_saving_count());
3051
3052 // Remove one character from the password value.
3053 SimulateUserTypingASCIICharacter(ui::VKEY_BACK, true);
3054 EXPECT_EQ(2, fake_driver_.called_show_manual_fallback_for_saving_count());
3055
3056 // Add one character to the username value.
3057 SetFocused(username_element_);
3058 SimulateUserTypingASCIICharacter('a', true);
3059 EXPECT_EQ(3, fake_driver_.called_show_manual_fallback_for_saving_count());
3060
3061 // Remove username value.
3062 SimulateUsernameChange("");
3063 EXPECT_EQ(4, fake_driver_.called_show_manual_fallback_for_saving_count());
3064
3065 // Change the password. Despite of empty username the fallback is still
3066 // there.
3067 SetFocused(password_element_);
3068 SimulateUserTypingASCIICharacter('a', true);
3069 EXPECT_EQ(5, fake_driver_.called_show_manual_fallback_for_saving_count());
3070
3071 // Remove password value. The fallback should be disabled.
3072 SimulatePasswordChange("");
3073 EXPECT_EQ(0, fake_driver_.called_show_manual_fallback_for_saving_count());
3074
3075 // The user enters new password. Show the fallback again.
3076 SimulateUserTypingASCIICharacter('a', true);
3077 EXPECT_EQ(1, fake_driver_.called_show_manual_fallback_for_saving_count());
3078 }
3079
3080 TEST_F(PasswordAutofillAgentTest, ManualFallbackForSaving_PasswordChangeForm) {
3081 LoadHTML(kPasswordChangeFormHTML);
3082 UpdateOriginForHTML(kPasswordChangeFormHTML);
3083 UpdateUsernameAndPasswordElements();
3084
3085 // No password to save yet - no fallback.
3086 SimulateUsernameChange(kUsernameName);
3087 EXPECT_EQ(0, fake_driver_.called_show_manual_fallback_for_saving_count());
3088
3089 // The user enters in the current password field. The fallback should be
3090 // available to save the entered value.
3091 SimulatePasswordChange(kPasswordName);
3092 // SimulateUsernameChange/SimulatePasswordChange calls
3093 // PasswordAutofillAgent::UpdateStateForTextChange only once.
3094 EXPECT_EQ(1, fake_driver_.called_show_manual_fallback_for_saving_count());
3095
3096 // The user types into the new password field. The fallback should be updated.
3097 WebInputElement new_password = GetInputElementByID("newpassword");
3098 ASSERT_FALSE(new_password.IsNull());
3099 SetFocused(new_password);
3100 SimulateUserTypingASCIICharacter('a', true);
3101 EXPECT_EQ(2, fake_driver_.called_show_manual_fallback_for_saving_count());
3102
3103 // Edits of the confirmation password field trigger fallback updates.
3104 WebInputElement confirmation_password =
3105 GetInputElementByID("confirmpassword");
3106 ASSERT_FALSE(confirmation_password.IsNull());
3107 SetFocused(confirmation_password);
3108 SimulateUserTypingASCIICharacter('a', true);
3109 EXPECT_EQ(3, fake_driver_.called_show_manual_fallback_for_saving_count());
3110
3111 // Clear all password fields. The fallback should be disabled.
3112 SimulatePasswordChange("");
3113 SimulateUserInputChangeForElement(&new_password, "");
3114 SimulateUserInputChangeForElement(&confirmation_password, "");
3115 EXPECT_EQ(0, fake_driver_.called_show_manual_fallback_for_saving_count());
3116 }
3041 // Tests that information about Gaia reauthentication form is not sent to the 3117 // Tests that information about Gaia reauthentication form is not sent to the
3042 // browser, nor on load nor on user click. 3118 // browser, nor on load nor on user click.
3043 TEST_F(PasswordAutofillAgentTest, GaiaReauthenticationFormIgnored) { 3119 TEST_F(PasswordAutofillAgentTest, GaiaReauthenticationFormIgnored) {
3044 // HTML is already loaded in test SetUp method, so information about password 3120 // HTML is already loaded in test SetUp method, so information about password
3045 // forms was already sent to the |fake_drive_|. Hence it should be reset. 3121 // forms was already sent to the |fake_drive_|. Hence it should be reset.
3046 fake_driver_.reset_password_forms_calls(); 3122 fake_driver_.reset_password_forms_calls();
3047 3123
3048 const char kGaiaReauthenticationFormHTML[] = 3124 const char kGaiaReauthenticationFormHTML[] =
3049 "<FORM id='ReauthenticationForm'>" 3125 "<FORM id='ReauthenticationForm'>"
3050 " <INPUT type='hidden' name='continue' " 3126 " <INPUT type='hidden' name='continue' "
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
3087 LoadHTML(kCreditCardFormHTML); 3163 LoadHTML(kCreditCardFormHTML);
3088 SetFocused(username_element_); 3164 SetFocused(username_element_);
3089 SimulateElementClick("username"); 3165 SimulateElementClick("username");
3090 EXPECT_FALSE(GetCalledShowManualFallbackSuggestion()); 3166 EXPECT_FALSE(GetCalledShowManualFallbackSuggestion());
3091 SetFocused(password_element_); 3167 SetFocused(password_element_);
3092 SimulateElementClick("password"); 3168 SimulateElementClick("password");
3093 EXPECT_FALSE(GetCalledShowManualFallbackSuggestion()); 3169 EXPECT_FALSE(GetCalledShowManualFallbackSuggestion());
3094 } 3170 }
3095 3171
3096 } // namespace autofill 3172 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698