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

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

Issue 1817483002: [Password Manager] Presave the form with generated password till successful login (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed CPMD_BAD_ORIGIN_UPDATE_PRESAVED_PASSWORD in bad_message.h Created 4 years, 8 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/common/autofill_messages.h » ('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 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 "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/test/histogram_tester.h" 10 #include "base/test/histogram_tester.h"
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 568
569 ExpectGenerationAvailable("first_password", false); 569 ExpectGenerationAvailable("first_password", false);
570 } 570 }
571 571
572 TEST_F(PasswordGenerationAgentTest, ChangePasswordFormDetectionTest) { 572 TEST_F(PasswordGenerationAgentTest, ChangePasswordFormDetectionTest) {
573 // Verify that generation is shown on correct field after message receiving. 573 // Verify that generation is shown on correct field after message receiving.
574 LoadHTMLWithUserGesture(kPasswordChangeFormHTML); 574 LoadHTMLWithUserGesture(kPasswordChangeFormHTML);
575 SetNotBlacklistedMessage(password_generation_, kPasswordChangeFormHTML); 575 SetNotBlacklistedMessage(password_generation_, kPasswordChangeFormHTML);
576 ExpectGenerationAvailable("password", false); 576 ExpectGenerationAvailable("password", false);
577 ExpectGenerationAvailable("newpassword", false); 577 ExpectGenerationAvailable("newpassword", false);
578 ExpectGenerationAvailable("confirmpassword", false);
578 579
579 SetAccountCreationFormsDetectedMessage(password_generation_, 580 SetAccountCreationFormsDetectedMessage(password_generation_,
580 GetMainFrame()->document(), 0, 2); 581 GetMainFrame()->document(), 0, 2);
581 ExpectGenerationAvailable("password", false); 582 ExpectGenerationAvailable("password", false);
582 ExpectGenerationAvailable("newpassword", true); 583 ExpectGenerationAvailable("newpassword", true);
584 ExpectGenerationAvailable("confirmpassword", false);
583 } 585 }
584 586
585 TEST_F(PasswordGenerationAgentTest, ManualGenerationInFormTest) { 587 TEST_F(PasswordGenerationAgentTest, ManualGenerationInFormTest) {
586 LoadHTMLWithUserGesture(kAccountCreationFormHTML); 588 LoadHTMLWithUserGesture(kAccountCreationFormHTML);
587 ShowGenerationPopUpManually("first_password"); 589 ShowGenerationPopUpManually("first_password");
588 ExpectGenerationAvailable("first_password", true); 590 ExpectGenerationAvailable("first_password", true);
589 ExpectGenerationAvailable("second_password", false); 591 ExpectGenerationAvailable("second_password", false);
590 } 592 }
591 593
592 TEST_F(PasswordGenerationAgentTest, ManualGenerationNoFormTest) { 594 TEST_F(PasswordGenerationAgentTest, ManualGenerationNoFormTest) {
593 LoadHTMLWithUserGesture(kAccountCreationNoForm); 595 LoadHTMLWithUserGesture(kAccountCreationNoForm);
594 ShowGenerationPopUpManually("first_password"); 596 ShowGenerationPopUpManually("first_password");
595 ExpectGenerationAvailable("first_password", true); 597 ExpectGenerationAvailable("first_password", true);
596 ExpectGenerationAvailable("second_password", false); 598 ExpectGenerationAvailable("second_password", false);
597 } 599 }
598 600
599 TEST_F(PasswordGenerationAgentTest, ManualGenerationChangeFocusTest) { 601 TEST_F(PasswordGenerationAgentTest, ManualGenerationChangeFocusTest) {
600 // This test simulates focus change after user triggered password generation. 602 // This test simulates focus change after user triggered password generation.
601 // PasswordGenerationAgent should save last focused password element and 603 // PasswordGenerationAgent should save last focused password element and
602 // generate password, even if focused element has changed. 604 // generate password, even if focused element has changed.
603 LoadHTMLWithUserGesture(kAccountCreationFormHTML); 605 LoadHTMLWithUserGesture(kAccountCreationFormHTML);
604 FocusField("first_password"); 606 FocusField("first_password");
605 ShowGenerationPopUpManually("username" /* current focus */); 607 ShowGenerationPopUpManually("username" /* current focus */);
606 ExpectGenerationAvailable("first_password", true); 608 ExpectGenerationAvailable("first_password", true);
607 ExpectGenerationAvailable("second_password", false); 609 ExpectGenerationAvailable("second_password", false);
608 } 610 }
609 611
612 TEST_F(PasswordGenerationAgentTest, PresavingGeneratedPassword) {
613 const struct {
614 const char* form;
615 const char* generation_element;
616 } kTestCases[] = {{kAccountCreationFormHTML, "first_password"},
617 {kAccountCreationNoForm, "first_password"},
618 {kPasswordChangeFormHTML, "newpassword"}};
619 for (auto& test_case : kTestCases) {
620 SCOPED_TRACE(testing::Message("form: ") << test_case.form);
621 LoadHTMLWithUserGesture(test_case.form);
622 // To be able to work with input elements outside <form>'s, use manual
623 // generation.
624 ShowGenerationPopUpManually(test_case.generation_element);
625 ExpectGenerationAvailable(test_case.generation_element, true);
626
627 base::string16 password = base::ASCIIToUTF16("random_password");
628 AutofillMsg_GeneratedPasswordAccepted msg(0, password);
629 password_generation_->OnMessageReceived(msg);
630 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching(
631 AutofillHostMsg_PresaveGeneratedPassword::ID));
632 render_thread_->sink().ClearMessages();
633
634 FocusField(test_case.generation_element);
635 SimulateUserTypingASCIICharacter('a', true);
636 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching(
637 AutofillHostMsg_PresaveGeneratedPassword::ID));
638 render_thread_->sink().ClearMessages();
639
640 for (size_t i = 0; i < password.length(); ++i)
641 SimulateUserTypingASCIICharacter(ui::VKEY_BACK, false);
642 SimulateUserTypingASCIICharacter(ui::VKEY_BACK, true);
643 EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching(
644 AutofillHostMsg_PasswordNoLongerGenerated::ID));
645 render_thread_->sink().ClearMessages();
646 }
647 }
648
610 } // namespace autofill 649 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | components/autofill/content/common/autofill_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698