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

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

Issue 2917933002: [PasswordGeneration] Improve change/confirm password field detection. (Closed)
Patch Set: Address more comments. 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <string.h> 5 #include <string.h>
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 ASSERT_FALSE(element.IsNull()); 84 ASSERT_FALSE(element.IsNull());
85 ExecuteJavaScriptForTests( 85 ExecuteJavaScriptForTests(
86 base::StringPrintf("document.getElementById('%s').focus();", 86 base::StringPrintf("document.getElementById('%s').focus();",
87 element_id).c_str()); 87 element_id).c_str());
88 } 88 }
89 89
90 void ExpectGenerationAvailable(const char* element_id, 90 void ExpectGenerationAvailable(const char* element_id,
91 bool available) { 91 bool available) {
92 FocusField(element_id); 92 FocusField(element_id);
93 base::RunLoop().RunUntilIdle(); 93 base::RunLoop().RunUntilIdle();
94 fake_pw_client_.Flush(); 94 ASSERT_EQ(available, GetCalledShowPasswordGenerationPopup());
95 bool called = fake_pw_client_.called_show_pw_generation_popup();
96 if (available)
97 ASSERT_TRUE(called);
98 else
99 ASSERT_FALSE(called);
100
101 fake_pw_client_.reset_called_show_pw_generation_popup(); 95 fake_pw_client_.reset_called_show_pw_generation_popup();
102 } 96 }
103 97
104 void AllowToRunFormClassifier() { 98 void AllowToRunFormClassifier() {
105 password_generation_->AllowToRunFormClassifier(); 99 password_generation_->AllowToRunFormClassifier();
106 } 100 }
107 101
108 void ExpectFormClassifierVoteReceived( 102 void ExpectFormClassifierVoteReceived(
109 bool received, 103 bool received,
110 const base::string16& expected_generation_element) { 104 const base::string16& expected_generation_element) {
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 const char kNewPasswordAutocompleteAttributeFormHTML[] = 236 const char kNewPasswordAutocompleteAttributeFormHTML[] =
243 "<FORM name = 'blah' action = 'http://www.random.com/'> " 237 "<FORM name = 'blah' action = 'http://www.random.com/'> "
244 " <INPUT type = 'text' id = 'username'/> " 238 " <INPUT type = 'text' id = 'username'/> "
245 " <INPUT type = 'password' id = 'first_password' " 239 " <INPUT type = 'password' id = 'first_password' "
246 " autocomplete='new-password' size = 5/>" 240 " autocomplete='new-password' size = 5/>"
247 " <INPUT type = 'password' id = 'second_password' size = 5/> " 241 " <INPUT type = 'password' id = 'second_password' size = 5/> "
248 " <INPUT type = 'button' id = 'dummy'/> " 242 " <INPUT type = 'button' id = 'dummy'/> "
249 " <INPUT type = 'submit' value = 'LOGIN' />" 243 " <INPUT type = 'submit' value = 'LOGIN' />"
250 "</FORM>"; 244 "</FORM>";
251 245
246 const char kCurrentAndNewPasswordAutocompleteAttributeFormHTML[] =
247 "<FORM name = 'blah' action = 'http://www.random.com/'> "
248 " <INPUT type = 'password' id = 'old_password' "
249 " autocomplete='current-password'/>"
250 " <INPUT type = 'password' id = 'new_password' "
251 " autocomplete='new-password'/>"
252 " <INPUT type = 'password' id = 'confirm_password' "
253 " autocomplete='new-password'/>"
254 " <INPUT type = 'button' id = 'dummy'/> "
255 " <INPUT type = 'submit' value = 'LOGIN' />"
256 "</FORM>";
257
252 const char kPasswordChangeFormHTML[] = 258 const char kPasswordChangeFormHTML[] =
253 "<FORM name = 'ChangeWithUsernameForm' action = 'http://www.bidule.com'> " 259 "<FORM name = 'ChangeWithUsernameForm' action = 'http://www.bidule.com'> "
254 " <INPUT type = 'text' id = 'username'/> " 260 " <INPUT type = 'text' id = 'username'/> "
255 " <INPUT type = 'password' id = 'password'/> " 261 " <INPUT type = 'password' id = 'password'/> "
256 " <INPUT type = 'password' id = 'newpassword'/> " 262 " <INPUT type = 'password' id = 'newpassword'/> "
257 " <INPUT type = 'password' id = 'confirmpassword'/> " 263 " <INPUT type = 'password' id = 'confirmpassword'/> "
258 " <INPUT type = 'button' id = 'dummy'/> " 264 " <INPUT type = 'button' id = 'dummy'/> "
259 " <INPUT type = 'submit' value = 'Login'/> " 265 " <INPUT type = 'submit' value = 'Login'/> "
260 "</FORM>"; 266 "</FORM>";
261 267
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 EXPECT_FALSE(fake_pw_client_.called_generation_available_for_form()); 604 EXPECT_FALSE(fake_pw_client_.called_generation_available_for_form());
599 EXPECT_FALSE(GetCalledShowPasswordGenerationPopup()); 605 EXPECT_FALSE(GetCalledShowPasswordGenerationPopup());
600 } 606 }
601 607
602 TEST_F(PasswordGenerationAgentTest, AutocompleteAttributesTest) { 608 TEST_F(PasswordGenerationAgentTest, AutocompleteAttributesTest) {
603 // Verify that autocomplete attributes can override Autofill to enable 609 // Verify that autocomplete attributes can override Autofill to enable
604 // generation 610 // generation
605 LoadHTMLWithUserGesture(kBothAutocompleteAttributesFormHTML); 611 LoadHTMLWithUserGesture(kBothAutocompleteAttributesFormHTML);
606 SetNotBlacklistedMessage(password_generation_, 612 SetNotBlacklistedMessage(password_generation_,
607 kBothAutocompleteAttributesFormHTML); 613 kBothAutocompleteAttributesFormHTML);
608
609 ExpectGenerationAvailable("first_password", true); 614 ExpectGenerationAvailable("first_password", true);
610 615
611 // Only setting one of the two attributes doesn't trigger generation. 616 // Only username autocomplete attribute enabled doesn't trigger generation.
612 LoadHTMLWithUserGesture(kUsernameAutocompleteAttributeFormHTML); 617 LoadHTMLWithUserGesture(kUsernameAutocompleteAttributeFormHTML);
613 SetNotBlacklistedMessage(password_generation_, 618 SetNotBlacklistedMessage(password_generation_,
614 kUsernameAutocompleteAttributeFormHTML); 619 kUsernameAutocompleteAttributeFormHTML);
615
616 ExpectGenerationAvailable("first_password", false); 620 ExpectGenerationAvailable("first_password", false);
617 621
622 // Only new-password autocomplete attribute enabled does trigger generation.
618 LoadHTMLWithUserGesture(kNewPasswordAutocompleteAttributeFormHTML); 623 LoadHTMLWithUserGesture(kNewPasswordAutocompleteAttributeFormHTML);
619 SetNotBlacklistedMessage(password_generation_, 624 SetNotBlacklistedMessage(password_generation_,
620 kNewPasswordAutocompleteAttributeFormHTML); 625 kNewPasswordAutocompleteAttributeFormHTML);
626 ExpectGenerationAvailable("first_password", true);
621 627
622 ExpectGenerationAvailable("first_password", false); 628 // Generation is triggered if the form has only password fields.
629 LoadHTMLWithUserGesture(kCurrentAndNewPasswordAutocompleteAttributeFormHTML);
630 SetNotBlacklistedMessage(password_generation_,
631 kCurrentAndNewPasswordAutocompleteAttributeFormHTML);
632 ExpectGenerationAvailable("old_password", false);
633 ExpectGenerationAvailable("new_password", true);
634 ExpectGenerationAvailable("confirm_password", false);
623 } 635 }
624 636
625 TEST_F(PasswordGenerationAgentTest, ChangePasswordFormDetectionTest) { 637 TEST_F(PasswordGenerationAgentTest, ChangePasswordFormDetectionTest) {
626 // Verify that generation is shown on correct field after message receiving. 638 // Verify that generation is shown on correct field after message receiving.
627 LoadHTMLWithUserGesture(kPasswordChangeFormHTML); 639 LoadHTMLWithUserGesture(kPasswordChangeFormHTML);
628 SetNotBlacklistedMessage(password_generation_, kPasswordChangeFormHTML); 640 SetNotBlacklistedMessage(password_generation_, kPasswordChangeFormHTML);
629 ExpectGenerationAvailable("password", false); 641 ExpectGenerationAvailable("password", false);
630 ExpectGenerationAvailable("newpassword", false); 642 ExpectGenerationAvailable("newpassword", false);
631 ExpectGenerationAvailable("confirmpassword", false); 643 ExpectGenerationAvailable("confirmpassword", false);
632 644
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 ExpectGenerationAvailable(kGenerationElementId, true); 818 ExpectGenerationAvailable(kGenerationElementId, true);
807 password_generation_->GeneratedPasswordAccepted(base::ASCIIToUTF16("pwd")); 819 password_generation_->GeneratedPasswordAccepted(base::ASCIIToUTF16("pwd"));
808 ExecuteJavaScriptForTests( 820 ExecuteJavaScriptForTests(
809 "document.getElementById('first_password').value = '';"); 821 "document.getElementById('first_password').value = '';");
810 FocusField(kGenerationElementId); 822 FocusField(kGenerationElementId);
811 base::RunLoop().RunUntilIdle(); 823 base::RunLoop().RunUntilIdle();
812 EXPECT_TRUE(fake_driver_.called_password_no_longer_generated()); 824 EXPECT_TRUE(fake_driver_.called_password_no_longer_generated());
813 } 825 }
814 826
815 } // namespace autofill 827 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698