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

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

Issue 2949533002: Test for the autofill login for the form without username field.
Patch Set: Created 3 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 709 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 // If a username field is empty and readonly, don't autofill. 720 // If a username field is empty and readonly, don't autofill.
721 TEST_F(PasswordAutofillAgentTest, 721 TEST_F(PasswordAutofillAgentTest,
722 NoAutocompletePasswordForReadonlyUsernameUnmatched) { 722 NoAutocompletePasswordForReadonlyUsernameUnmatched) {
723 username_element_.SetValue(WebString::FromUTF8("")); 723 username_element_.SetValue(WebString::FromUTF8(""));
724 SetElementReadOnly(username_element_, true); 724 SetElementReadOnly(username_element_, true);
725 725
726 SimulateOnFillPasswordForm(fill_data_); 726 SimulateOnFillPasswordForm(fill_data_);
727 CheckTextFieldsState(std::string(), false, std::string(), false); 727 CheckTextFieldsState(std::string(), false, std::string(), false);
728 } 728 }
729 729
730 // If there is no username field and the saved credentials contain an empty
731 // username, then the password is filled.
732 TEST_F(PasswordAutofillAgentTest, AutocompletePasswordForNoUsername) {
733 // Load a form with no username and update test data.
734 LoadHTML(kVisibleFormWithNoUsernameHTML);
735 UpdateOnlyPasswordElement();
736 UpdateOriginForHTML(kVisibleFormWithNoUsernameHTML);
737
738 SimulateOnFillPasswordForm(fill_data_);
vabr (Chromium) 2017/06/19 13:03:36 Instead of fill_data_, you might need to make a co
739 EXPECT_TRUE(password_element_.IsAutofilled());
740 EXPECT_EQ(UTF16ToUTF8(password_for_empty_username_),
741 password_element_.Value().Utf8());
742 }
743
730 // Tests that having a non-matching username precludes the autocomplete. 744 // Tests that having a non-matching username precludes the autocomplete.
731 TEST_F(PasswordAutofillAgentTest, NoAutocompleteForFilledFieldUnmatched) { 745 TEST_F(PasswordAutofillAgentTest, NoAutocompleteForFilledFieldUnmatched) {
732 username_element_.SetValue(WebString::FromUTF8("bogus")); 746 username_element_.SetValue(WebString::FromUTF8("bogus"));
733 747
734 // Simulate the browser sending back the login info, it triggers the 748 // Simulate the browser sending back the login info, it triggers the
735 // autocomplete. 749 // autocomplete.
736 SimulateOnFillPasswordForm(fill_data_); 750 SimulateOnFillPasswordForm(fill_data_);
737 751
738 // Neither field should be autocompleted. 752 // Neither field should be autocompleted.
739 CheckTextFieldsState("bogus", false, std::string(), false); 753 CheckTextFieldsState("bogus", false, std::string(), false);
(...skipping 2214 matching lines...) Expand 10 before | Expand all | Expand 10 after
2954 TEST_F(PasswordAutofillAgentTest, AutocompleteWhenPageUrlIsChanged) { 2968 TEST_F(PasswordAutofillAgentTest, AutocompleteWhenPageUrlIsChanged) {
2955 // Simulate that JavaScript changes url. 2969 // Simulate that JavaScript changes url.
2956 fill_data_.origin = GURL(fill_data_.origin.possibly_invalid_spec() + "/path"); 2970 fill_data_.origin = GURL(fill_data_.origin.possibly_invalid_spec() + "/path");
2957 2971
2958 SimulateOnFillPasswordForm(fill_data_); 2972 SimulateOnFillPasswordForm(fill_data_);
2959 2973
2960 // The username and password should have been autocompleted. 2974 // The username and password should have been autocompleted.
2961 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true); 2975 CheckTextFieldsState(kAliceUsername, true, kAlicePassword, true);
2962 } 2976 }
2963 } // namespace autofill 2977 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698