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

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

Issue 2947403003: Prefer the exact match over prefix match for the password manager filling.
Patch Set: Prefer the exact match over prefix match. 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 const char kUsernameName[] = "username"; 61 const char kUsernameName[] = "username";
62 const char kPasswordName[] = "password"; 62 const char kPasswordName[] = "password";
63 const char kEmailName[] = "email"; 63 const char kEmailName[] = "email";
64 const char kCreditCardOwnerName[] = "creditcardowner"; 64 const char kCreditCardOwnerName[] = "creditcardowner";
65 const char kCreditCardNumberName[] = "creditcardnumber"; 65 const char kCreditCardNumberName[] = "creditcardnumber";
66 const char kCreditCardVerificationName[] = "cvc"; 66 const char kCreditCardVerificationName[] = "cvc";
67 67
68 const char kAliceUsername[] = "alice"; 68 const char kAliceUsername[] = "alice";
69 const char kAlicePassword[] = "password"; 69 const char kAlicePassword[] = "password";
70 const char kBobUsername[] = "bob"; 70 const char kBobUsername[] = "bob";
71 const char kBobAtUsername[] = "bob@example.com";
71 const char kBobPassword[] = "secret"; 72 const char kBobPassword[] = "secret";
72 const char kCarolUsername[] = "Carol"; 73 const char kCarolUsername[] = "Carol";
73 const char kCarolPassword[] = "test"; 74 const char kCarolPassword[] = "test";
74 const char kCarolAlternateUsername[] = "RealCarolUsername"; 75 const char kCarolAlternateUsername[] = "RealCarolUsername";
75 76
76 const char kFormHTML[] = 77 const char kFormHTML[] =
77 "<FORM id='LoginTestForm' action='http://www.bidule.com'>" 78 "<FORM id='LoginTestForm' action='http://www.bidule.com'>"
78 " <INPUT type='text' id='random_field'/>" 79 " <INPUT type='text' id='random_field'/>"
79 " <INPUT type='text' id='username'/>" 80 " <INPUT type='text' id='username'/>"
80 " <INPUT type='password' id='password'/>" 81 " <INPUT type='password' id='password'/>"
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 } 277 }
277 278
278 void SetUp() override { 279 void SetUp() override {
279 ChromeRenderViewTest::SetUp(); 280 ChromeRenderViewTest::SetUp();
280 281
281 // Add a preferred login and an additional login to the FillData. 282 // Add a preferred login and an additional login to the FillData.
282 username1_ = ASCIIToUTF16(kAliceUsername); 283 username1_ = ASCIIToUTF16(kAliceUsername);
283 password1_ = ASCIIToUTF16(kAlicePassword); 284 password1_ = ASCIIToUTF16(kAlicePassword);
284 username2_ = ASCIIToUTF16(kBobUsername); 285 username2_ = ASCIIToUTF16(kBobUsername);
285 password2_ = ASCIIToUTF16(kBobPassword); 286 password2_ = ASCIIToUTF16(kBobPassword);
287 username2at_ = ASCIIToUTF16(kBobAtUsername);
286 username3_ = ASCIIToUTF16(kCarolUsername); 288 username3_ = ASCIIToUTF16(kCarolUsername);
287 password3_ = ASCIIToUTF16(kCarolPassword); 289 password3_ = ASCIIToUTF16(kCarolPassword);
288 alternate_username3_ = ASCIIToUTF16(kCarolAlternateUsername); 290 alternate_username3_ = ASCIIToUTF16(kCarolAlternateUsername);
289 291
290 FormFieldData username_field; 292 FormFieldData username_field;
291 username_field.name = ASCIIToUTF16(kUsernameName); 293 username_field.name = ASCIIToUTF16(kUsernameName);
292 username_field.value = username1_; 294 username_field.value = username1_;
293 fill_data_.username_field = username_field; 295 fill_data_.username_field = username_field;
294 296
295 FormFieldData password_field; 297 FormFieldData password_field;
296 password_field.name = ASCIIToUTF16(kPasswordName); 298 password_field.name = ASCIIToUTF16(kPasswordName);
297 password_field.value = password1_; 299 password_field.value = password1_;
298 password_field.form_control_type = "password"; 300 password_field.form_control_type = "password";
299 fill_data_.password_field = password_field; 301 fill_data_.password_field = password_field;
300 302
301 PasswordAndRealm password2; 303 PasswordAndRealm password2;
302 password2.password = password2_; 304 password2.password = password2_;
303 fill_data_.additional_logins[username2_] = password2; 305 fill_data_.additional_logins[username2_] = password2;
304 PasswordAndRealm password3; 306 PasswordAndRealm password3;
305 password3.password = password3_; 307 password3.password = password3_;
306 fill_data_.additional_logins[username3_] = password3; 308 fill_data_.additional_logins[username3_] = password3;
309 fill_data_.additional_logins[username2at_] = password3;
307 310
308 UsernamesCollectionKey key; 311 UsernamesCollectionKey key;
309 key.username = username3_; 312 key.username = username3_;
310 key.password = password3_; 313 key.password = password3_;
311 key.realm = "google.com"; 314 key.realm = "google.com";
312 fill_data_.other_possible_usernames[key].push_back(alternate_username3_); 315 fill_data_.other_possible_usernames[key].push_back(alternate_username3_);
313 316
314 // We need to set the origin so it matches the frame URL and the action so 317 // We need to set the origin so it matches the frame URL and the action so
315 // it matches the form action, otherwise we won't autocomplete. 318 // it matches the form action, otherwise we won't autocomplete.
316 UpdateOriginForHTML(kFormHTML); 319 UpdateOriginForHTML(kFormHTML);
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 void BindPasswordManagerClient(mojo::ScopedInterfaceEndpointHandle handle) { 615 void BindPasswordManagerClient(mojo::ScopedInterfaceEndpointHandle handle) {
613 fake_pw_client_.BindRequest( 616 fake_pw_client_.BindRequest(
614 mojom::PasswordManagerClientAssociatedRequest(std::move(handle))); 617 mojom::PasswordManagerClientAssociatedRequest(std::move(handle)));
615 } 618 }
616 619
617 FakeContentPasswordManagerDriver fake_driver_; 620 FakeContentPasswordManagerDriver fake_driver_;
618 FakePasswordManagerClient fake_pw_client_; 621 FakePasswordManagerClient fake_pw_client_;
619 622
620 base::string16 username1_; 623 base::string16 username1_;
621 base::string16 username2_; 624 base::string16 username2_;
625 base::string16 username2at_;
622 base::string16 username3_; 626 base::string16 username3_;
623 base::string16 password1_; 627 base::string16 password1_;
624 base::string16 password2_; 628 base::string16 password2_;
625 base::string16 password3_; 629 base::string16 password3_;
626 base::string16 alternate_username3_; 630 base::string16 alternate_username3_;
627 PasswordFormFillData fill_data_; 631 PasswordFormFillData fill_data_;
628 632
629 WebInputElement username_element_; 633 WebInputElement username_element_;
630 WebInputElement password_element_; 634 WebInputElement password_element_;
631 base::test::ScopedFeatureList scoped_feature_list_; 635 base::test::ScopedFeatureList scoped_feature_list_;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 username3_ + base::UTF8ToUTF16("@example.com"); 761 username3_ + base::UTF8ToUTF16("@example.com");
758 username_element_.SetValue(WebString::FromUTF16(prefilled_username)); 762 username_element_.SetValue(WebString::FromUTF16(prefilled_username));
759 763
760 // Filled even though the username in the form is only a proper prefix of the 764 // Filled even though the username in the form is only a proper prefix of the
761 // stored username. 765 // stored username.
762 SimulateOnFillPasswordForm(fill_data_); 766 SimulateOnFillPasswordForm(fill_data_);
763 CheckTextFieldsState(UTF16ToUTF8(prefilled_username), false, std::string(), 767 CheckTextFieldsState(UTF16ToUTF8(prefilled_username), false, std::string(),
764 false); 768 false);
765 } 769 }
766 770
771 // Tests that the exact match is always preferred.
772 TEST_F(PasswordAutofillAgentTest, TestThatExactMatchIsPreffered) {
773 username_element_.SetValue(WebString::FromUTF16(username2at_));
774
775 SimulateOnFillPasswordForm(fill_data_);
776 CheckTextFieldsState(UTF16ToUTF8(username2at_), false,
vabr (Chromium) 2017/06/23 06:58:11 Yes, these two "false" should be "true" (we expect
777 UTF16ToUTF8(password3_), false);
778 }
779
767 // If a username field is empty and readonly, don't autofill. 780 // If a username field is empty and readonly, don't autofill.
768 TEST_F(PasswordAutofillAgentTest, 781 TEST_F(PasswordAutofillAgentTest,
769 NoAutocompletePasswordForReadonlyUsernameUnmatched) { 782 NoAutocompletePasswordForReadonlyUsernameUnmatched) {
770 username_element_.SetValue(WebString::FromUTF8("")); 783 username_element_.SetValue(WebString::FromUTF8(""));
771 SetElementReadOnly(username_element_, true); 784 SetElementReadOnly(username_element_, true);
772 785
773 SimulateOnFillPasswordForm(fill_data_); 786 SimulateOnFillPasswordForm(fill_data_);
774 CheckTextFieldsState(std::string(), false, std::string(), false); 787 CheckTextFieldsState(std::string(), false, std::string(), false);
775 } 788 }
776 789
(...skipping 2245 matching lines...) Expand 10 before | Expand all | Expand 10 after
3022 // Repeatedly occurring AJAX events without removing the input elements 3035 // Repeatedly occurring AJAX events without removing the input elements
3023 // shouldn't be treated as a password submission. 3036 // shouldn't be treated as a password submission.
3024 password_autofill_agent_->AJAXSucceeded(); 3037 password_autofill_agent_->AJAXSucceeded();
3025 base::RunLoop().RunUntilIdle(); 3038 base::RunLoop().RunUntilIdle();
3026 3039
3027 ASSERT_FALSE(fake_driver_.called_password_form_submitted()); 3040 ASSERT_FALSE(fake_driver_.called_password_form_submitted());
3028 ASSERT_FALSE(static_cast<bool>(fake_driver_.password_form_submitted())); 3041 ASSERT_FALSE(static_cast<bool>(fake_driver_.password_form_submitted()));
3029 } 3042 }
3030 3043
3031 } // namespace autofill 3044 } // 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