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

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

Issue 2906383003: Teach PasswordAutofillAgent sometimes match prefixes of usernames (Closed)
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 | components/autofill/content/renderer/password_autofill_agent.cc » ('j') | 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 699 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 AutocompletePasswordForReadonlyUsernameMatched) { 710 AutocompletePasswordForReadonlyUsernameMatched) {
711 username_element_.SetValue(WebString::FromUTF16(username3_)); 711 username_element_.SetValue(WebString::FromUTF16(username3_));
712 SetElementReadOnly(username_element_, true); 712 SetElementReadOnly(username_element_, true);
713 713
714 // Filled even though username is not the preferred match. 714 // Filled even though username is not the preferred match.
715 SimulateOnFillPasswordForm(fill_data_); 715 SimulateOnFillPasswordForm(fill_data_);
716 CheckTextFieldsState(UTF16ToUTF8(username3_), false, 716 CheckTextFieldsState(UTF16ToUTF8(username3_), false,
717 UTF16ToUTF8(password3_), true); 717 UTF16ToUTF8(password3_), true);
718 } 718 }
719 719
720 // Fill a password field if the stored username is a prefix of username in
721 // read-only field.
722 TEST_F(PasswordAutofillAgentTest,
723 AutocompletePasswordForReadonlyUsernamePrefixMatched) {
724 base::string16 username_at = username3_ + base::UTF8ToUTF16("@example.com");
725 username_element_.SetValue(WebString::FromUTF16(username_at));
726 SetElementReadOnly(username_element_, true);
727
728 // Filled even though the username in the form is only a proper prefix of the
729 // stored username.
730 SimulateOnFillPasswordForm(fill_data_);
731 CheckTextFieldsState(UTF16ToUTF8(username_at), false, UTF16ToUTF8(password3_),
732 true);
733 }
734
735 // Do not fill a password field if the stored username is a prefix without @
736 // of username in read-only field.
737 TEST_F(PasswordAutofillAgentTest,
738 DontAutocompletePasswordForReadonlyUsernamePrefixMatched) {
739 base::string16 prefilled_username =
740 username3_ + base::UTF8ToUTF16("example.com");
741 username_element_.SetValue(WebString::FromUTF16(prefilled_username));
742 SetElementReadOnly(username_element_, true);
743
744 // Filled even though the username in the form is only a proper prefix of the
745 // stored username.
746 SimulateOnFillPasswordForm(fill_data_);
747 CheckTextFieldsState(UTF16ToUTF8(prefilled_username), false, std::string(),
748 false);
749 }
750
751 // Do not fill a password field if the field isn't readonly despite the stored
752 // username is a prefix without @ of username in read-only field.
753 TEST_F(
754 PasswordAutofillAgentTest,
755 DontAutocompletePasswordForNotReadonlyUsernameFieldEvenWhenPrefixMatched) {
756 base::string16 prefilled_username =
757 username3_ + base::UTF8ToUTF16("@example.com");
758 username_element_.SetValue(WebString::FromUTF16(prefilled_username));
759
760 // Filled even though the username in the form is only a proper prefix of the
761 // stored username.
762 SimulateOnFillPasswordForm(fill_data_);
763 CheckTextFieldsState(UTF16ToUTF8(prefilled_username), false, std::string(),
764 false);
765 }
766
720 // If a username field is empty and readonly, don't autofill. 767 // If a username field is empty and readonly, don't autofill.
721 TEST_F(PasswordAutofillAgentTest, 768 TEST_F(PasswordAutofillAgentTest,
722 NoAutocompletePasswordForReadonlyUsernameUnmatched) { 769 NoAutocompletePasswordForReadonlyUsernameUnmatched) {
723 username_element_.SetValue(WebString::FromUTF8("")); 770 username_element_.SetValue(WebString::FromUTF8(""));
724 SetElementReadOnly(username_element_, true); 771 SetElementReadOnly(username_element_, true);
725 772
726 SimulateOnFillPasswordForm(fill_data_); 773 SimulateOnFillPasswordForm(fill_data_);
727 CheckTextFieldsState(std::string(), false, std::string(), false); 774 CheckTextFieldsState(std::string(), false, std::string(), false);
728 } 775 }
729 776
(...skipping 2245 matching lines...) Expand 10 before | Expand all | Expand 10 after
2975 // Repeatedly occurring AJAX events without removing the input elements 3022 // Repeatedly occurring AJAX events without removing the input elements
2976 // shouldn't be treated as a password submission. 3023 // shouldn't be treated as a password submission.
2977 password_autofill_agent_->AJAXSucceeded(); 3024 password_autofill_agent_->AJAXSucceeded();
2978 base::RunLoop().RunUntilIdle(); 3025 base::RunLoop().RunUntilIdle();
2979 3026
2980 ASSERT_FALSE(fake_driver_.called_password_form_submitted()); 3027 ASSERT_FALSE(fake_driver_.called_password_form_submitted());
2981 ASSERT_FALSE(static_cast<bool>(fake_driver_.password_form_submitted())); 3028 ASSERT_FALSE(static_cast<bool>(fake_driver_.password_form_submitted()));
2982 } 3029 }
2983 3030
2984 } // namespace autofill 3031 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | components/autofill/content/renderer/password_autofill_agent.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698