OLD | NEW |
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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
7 #include "base/prefs/pref_registry_simple.h" | 7 #include "base/prefs/pref_registry_simple.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/prefs/testing_pref_service.h" | 9 #include "base/prefs/testing_pref_service.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 100 |
101 virtual bool ShouldFilterAutofillResult( | 101 virtual bool ShouldFilterAutofillResult( |
102 const autofill::PasswordForm& form) override { | 102 const autofill::PasswordForm& form) override { |
103 if (form == form_to_filter_) | 103 if (form == form_to_filter_) |
104 return true; | 104 return true; |
105 return false; | 105 return false; |
106 } | 106 } |
107 | 107 |
108 virtual PrefService* GetPrefs() override { return &prefs_; } | 108 virtual PrefService* GetPrefs() override { return &prefs_; } |
109 virtual PasswordStore* GetPasswordStore() override { return password_store_; } | 109 virtual PasswordStore* GetPasswordStore() override { return password_store_; } |
110 virtual PasswordManagerDriver* GetDriver() override { return &driver_; } | |
111 | 110 |
112 void SetFormToFilter(const autofill::PasswordForm& form) { | 111 void SetFormToFilter(const autofill::PasswordForm& form) { |
113 form_to_filter_ = form; | 112 form_to_filter_ = form; |
114 } | 113 } |
115 | 114 |
116 MockPasswordManagerDriver* mock_driver() { return &driver_; } | 115 MockPasswordManagerDriver* mock_driver() { return &driver_; } |
117 | 116 |
118 private: | 117 private: |
119 autofill::PasswordForm form_to_filter_; | 118 autofill::PasswordForm form_to_filter_; |
120 | 119 |
121 TestingPrefServiceSimple prefs_; | 120 TestingPrefServiceSimple prefs_; |
122 PasswordStore* password_store_; | 121 PasswordStore* password_store_; |
123 NiceMock<MockPasswordManagerDriver> driver_; | 122 NiceMock<MockPasswordManagerDriver> driver_; |
124 }; | 123 }; |
125 | 124 |
126 class TestPasswordManager : public PasswordManager { | 125 class TestPasswordManager : public PasswordManager { |
127 public: | 126 public: |
128 explicit TestPasswordManager(PasswordManagerClient* client) | 127 explicit TestPasswordManager(TestPasswordManagerClient* client) |
129 : PasswordManager(client) {} | 128 : PasswordManager(client) {} |
130 | 129 |
131 void Autofill(const autofill::PasswordForm& form_for_autofill, | 130 void Autofill(password_manager::PasswordManagerDriver* driver, |
| 131 const autofill::PasswordForm& form_for_autofill, |
132 const autofill::PasswordFormMap& best_matches, | 132 const autofill::PasswordFormMap& best_matches, |
133 const autofill::PasswordForm& preferred_match, | 133 const autofill::PasswordForm& preferred_match, |
134 bool wait_for_username) const override { | 134 bool wait_for_username) const override { |
135 best_matches_ = best_matches; | 135 best_matches_ = best_matches; |
136 } | 136 } |
137 | 137 |
138 const autofill::PasswordFormMap& GetLatestBestMatches() { | 138 const autofill::PasswordFormMap& GetLatestBestMatches() { |
139 return best_matches_; | 139 return best_matches_; |
140 } | 140 } |
141 | 141 |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 EXPECT_TRUE(manager.IsNewLogin()); | 337 EXPECT_TRUE(manager.IsNewLogin()); |
338 EXPECT_FALSE(manager.IsPendingCredentialsPublicSuffixMatch()); | 338 EXPECT_FALSE(manager.IsPendingCredentialsPublicSuffixMatch()); |
339 } | 339 } |
340 | 340 |
341 TEST_F(PasswordFormManagerTest, PSLMatchedCredentialsMetadataUpdated) { | 341 TEST_F(PasswordFormManagerTest, PSLMatchedCredentialsMetadataUpdated) { |
342 TestPasswordManagerClient client_with_store(mock_store()); | 342 TestPasswordManagerClient client_with_store(mock_store()); |
343 EXPECT_CALL(*(client_with_store.mock_driver()), IsOffTheRecord()) | 343 EXPECT_CALL(*(client_with_store.mock_driver()), IsOffTheRecord()) |
344 .WillRepeatedly(Return(false)); | 344 .WillRepeatedly(Return(false)); |
345 | 345 |
346 TestPasswordManager manager(&client_with_store); | 346 TestPasswordManager manager(&client_with_store); |
347 PasswordFormManager form_manager(&manager, | 347 PasswordFormManager form_manager(&manager, &client_with_store, |
348 &client_with_store, | |
349 client_with_store.mock_driver(), | 348 client_with_store.mock_driver(), |
350 *observed_form(), | 349 *observed_form(), false); |
351 false); | |
352 | 350 |
353 // The suggestion needs to be PSL-matched. | 351 // The suggestion needs to be PSL-matched. |
354 saved_match()->original_signon_realm = "www.example.org"; | 352 saved_match()->original_signon_realm = "www.example.org"; |
355 SimulateMatchingPhase(&form_manager, RESULT_MATCH_FOUND); | 353 SimulateMatchingPhase(&form_manager, RESULT_MATCH_FOUND); |
356 | 354 |
357 PasswordForm submitted_form(*observed_form()); | 355 PasswordForm submitted_form(*observed_form()); |
358 submitted_form.preferred = true; | 356 submitted_form.preferred = true; |
359 submitted_form.username_value = saved_match()->username_value; | 357 submitted_form.username_value = saved_match()->username_value; |
360 submitted_form.password_value = saved_match()->password_value; | 358 submitted_form.password_value = saved_match()->password_value; |
361 submitted_form.origin = saved_match()->origin; | 359 submitted_form.origin = saved_match()->origin; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 // Given that |observed_form| was most likely a change password form, it | 461 // Given that |observed_form| was most likely a change password form, it |
464 // should not serve as a source for updating meta-information stored with the | 462 // should not serve as a source for updating meta-information stored with the |
465 // old credentials, such as element names, as they are likely going to be | 463 // old credentials, such as element names, as they are likely going to be |
466 // different between change password and login forms. To test this in depth, | 464 // different between change password and login forms. To test this in depth, |
467 // forcibly wipe |submit_element|, which should normally trigger updating this | 465 // forcibly wipe |submit_element|, which should normally trigger updating this |
468 // field from |observed_form| in the UpdateLogin() step as a special case. We | 466 // field from |observed_form| in the UpdateLogin() step as a special case. We |
469 // will verify in the end that this did not happen. | 467 // will verify in the end that this did not happen. |
470 saved_match()->submit_element.clear(); | 468 saved_match()->submit_element.clear(); |
471 | 469 |
472 TestPasswordManagerClient client_with_store(mock_store()); | 470 TestPasswordManagerClient client_with_store(mock_store()); |
473 PasswordFormManager manager(NULL, | 471 PasswordFormManager manager(NULL, &client_with_store, |
474 &client_with_store, | 472 client_with_store.mock_driver(), *observed_form(), |
475 client_with_store.GetDriver(), | |
476 *observed_form(), | |
477 false); | 473 false); |
478 EXPECT_CALL(*client_with_store.mock_driver(), IsOffTheRecord()) | 474 EXPECT_CALL(*client_with_store.mock_driver(), IsOffTheRecord()) |
479 .WillRepeatedly(Return(false)); | 475 .WillRepeatedly(Return(false)); |
480 SimulateMatchingPhase(&manager, RESULT_MATCH_FOUND); | 476 SimulateMatchingPhase(&manager, RESULT_MATCH_FOUND); |
481 | 477 |
482 // User submits current and new credentials to the observed form. | 478 // User submits current and new credentials to the observed form. |
483 PasswordForm credentials(*observed_form()); | 479 PasswordForm credentials(*observed_form()); |
484 credentials.username_value = saved_match()->username_value; | 480 credentials.username_value = saved_match()->username_value; |
485 credentials.password_value = saved_match()->password_value; | 481 credentials.password_value = saved_match()->password_value; |
486 credentials.new_password_value = ASCIIToUTF16("test2"); | 482 credentials.new_password_value = ASCIIToUTF16("test2"); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 // action URL, not the one observed on page load. | 581 // action URL, not the one observed on page load. |
586 EXPECT_EQ(new_action, GetPendingCredentials(&manager)->action); | 582 EXPECT_EQ(new_action, GetPendingCredentials(&manager)->action); |
587 } | 583 } |
588 | 584 |
589 TEST_F(PasswordFormManagerTest, TestAlternateUsername) { | 585 TEST_F(PasswordFormManagerTest, TestAlternateUsername) { |
590 scoped_refptr<TestPasswordStore> password_store = new TestPasswordStore; | 586 scoped_refptr<TestPasswordStore> password_store = new TestPasswordStore; |
591 CHECK(password_store->Init(syncer::SyncableService::StartSyncFlare())); | 587 CHECK(password_store->Init(syncer::SyncableService::StartSyncFlare())); |
592 | 588 |
593 TestPasswordManagerClient client_with_store(password_store.get()); | 589 TestPasswordManagerClient client_with_store(password_store.get()); |
594 TestPasswordManager password_manager(&client_with_store); | 590 TestPasswordManager password_manager(&client_with_store); |
595 PasswordFormManager manager(&password_manager, | 591 PasswordFormManager manager(&password_manager, &client_with_store, |
596 &client_with_store, | 592 client_with_store.mock_driver(), *observed_form(), |
597 client_with_store.GetDriver(), | |
598 *observed_form(), | |
599 false); | 593 false); |
600 EXPECT_CALL(*client_with_store.mock_driver(), | 594 EXPECT_CALL(*client_with_store.mock_driver(), |
601 AllowPasswordGenerationForForm(_)).Times(1); | 595 AllowPasswordGenerationForForm(_)).Times(1); |
602 EXPECT_CALL(*client_with_store.mock_driver(), IsOffTheRecord()) | 596 EXPECT_CALL(*client_with_store.mock_driver(), IsOffTheRecord()) |
603 .WillRepeatedly(Return(false)); | 597 .WillRepeatedly(Return(false)); |
604 | 598 |
605 password_store->AddLogin(*saved_match()); | 599 password_store->AddLogin(*saved_match()); |
606 manager.FetchMatchingLoginsFromPasswordStore(PasswordStore::ALLOW_PROMPT); | 600 manager.FetchMatchingLoginsFromPasswordStore(PasswordStore::ALLOW_PROMPT); |
607 RunAllPendingTasks(); | 601 RunAllPendingTasks(); |
608 | 602 |
(...skipping 14 matching lines...) Expand all Loading... |
623 TestPasswordStore::PasswordMap passwords = password_store->stored_passwords(); | 617 TestPasswordStore::PasswordMap passwords = password_store->stored_passwords(); |
624 EXPECT_EQ(1U, passwords.size()); | 618 EXPECT_EQ(1U, passwords.size()); |
625 ASSERT_EQ(1U, passwords[saved_match()->signon_realm].size()); | 619 ASSERT_EQ(1U, passwords[saved_match()->signon_realm].size()); |
626 EXPECT_EQ(saved_match()->username_value, | 620 EXPECT_EQ(saved_match()->username_value, |
627 passwords[saved_match()->signon_realm][0].username_value); | 621 passwords[saved_match()->signon_realm][0].username_value); |
628 EXPECT_EQ(0U, | 622 EXPECT_EQ(0U, |
629 passwords[saved_match()->signon_realm][0] | 623 passwords[saved_match()->signon_realm][0] |
630 .other_possible_usernames.size()); | 624 .other_possible_usernames.size()); |
631 | 625 |
632 // This time use an alternate username | 626 // This time use an alternate username |
633 PasswordFormManager manager_alt(&password_manager, | 627 PasswordFormManager manager_alt(&password_manager, &client_with_store, |
634 &client_with_store, | 628 client_with_store.mock_driver(), |
635 client_with_store.GetDriver(), | 629 *observed_form(), false); |
636 *observed_form(), | |
637 false); | |
638 EXPECT_CALL(*client_with_store.mock_driver(), | 630 EXPECT_CALL(*client_with_store.mock_driver(), |
639 AllowPasswordGenerationForForm(_)).Times(1); | 631 AllowPasswordGenerationForForm(_)).Times(1); |
640 password_store->Clear(); | 632 password_store->Clear(); |
641 password_store->AddLogin(*saved_match()); | 633 password_store->AddLogin(*saved_match()); |
642 manager_alt.FetchMatchingLoginsFromPasswordStore(PasswordStore::ALLOW_PROMPT); | 634 manager_alt.FetchMatchingLoginsFromPasswordStore(PasswordStore::ALLOW_PROMPT); |
643 RunAllPendingTasks(); | 635 RunAllPendingTasks(); |
644 | 636 |
645 base::string16 new_username = saved_match()->other_possible_usernames[0]; | 637 base::string16 new_username = saved_match()->other_possible_usernames[0]; |
646 login.username_value = new_username; | 638 login.username_value = new_username; |
647 manager_alt.ProvisionallySave( | 639 manager_alt.ProvisionallySave( |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 // Form with neither a password_element nor a username_element. | 739 // Form with neither a password_element nor a username_element. |
748 credentials.username_element.clear(); | 740 credentials.username_element.clear(); |
749 credentials.password_element.clear(); | 741 credentials.password_element.clear(); |
750 PasswordFormManager manager4(NULL, NULL, NULL, credentials, false); | 742 PasswordFormManager manager4(NULL, NULL, NULL, credentials, false); |
751 SimulateMatchingPhase(&manager4, RESULT_NO_MATCH); | 743 SimulateMatchingPhase(&manager4, RESULT_NO_MATCH); |
752 EXPECT_TRUE(manager4.HasValidPasswordForm()); | 744 EXPECT_TRUE(manager4.HasValidPasswordForm()); |
753 } | 745 } |
754 | 746 |
755 TEST_F(PasswordFormManagerTest, TestSendNotBlacklistedMessage) { | 747 TEST_F(PasswordFormManagerTest, TestSendNotBlacklistedMessage) { |
756 TestPasswordManager password_manager(client()); | 748 TestPasswordManager password_manager(client()); |
757 PasswordFormManager manager_no_creds(&password_manager, | 749 PasswordFormManager manager_no_creds(&password_manager, client(), |
758 client(), | 750 client()->mock_driver(), |
759 client()->GetDriver(), | 751 *observed_form(), false); |
760 *observed_form(), | |
761 false); | |
762 | 752 |
763 // First time sign-up attempt. Password store does not contain matching | 753 // First time sign-up attempt. Password store does not contain matching |
764 // credentials. AllowPasswordGenerationForForm should be called to send the | 754 // credentials. AllowPasswordGenerationForForm should be called to send the |
765 // "not blacklisted" message. | 755 // "not blacklisted" message. |
766 EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_)) | 756 EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_)) |
767 .Times(1); | 757 .Times(1); |
768 SimulateFetchMatchingLoginsFromPasswordStore(&manager_no_creds); | 758 SimulateFetchMatchingLoginsFromPasswordStore(&manager_no_creds); |
769 std::vector<PasswordForm*> result; | 759 std::vector<PasswordForm*> result; |
770 SimulateResponseFromPasswordStore(&manager_no_creds, result); | 760 SimulateResponseFromPasswordStore(&manager_no_creds, result); |
771 Mock::VerifyAndClearExpectations(client()->mock_driver()); | 761 Mock::VerifyAndClearExpectations(client()->mock_driver()); |
772 | 762 |
773 // Signing up on a previously visited site. Credentials are found in the | 763 // Signing up on a previously visited site. Credentials are found in the |
774 // password store, and are not blacklisted. AllowPasswordGenerationForForm | 764 // password store, and are not blacklisted. AllowPasswordGenerationForForm |
775 // should be called to send the "not blacklisted" message. | 765 // should be called to send the "not blacklisted" message. |
776 PasswordFormManager manager_creds(&password_manager, | 766 PasswordFormManager manager_creds(&password_manager, client(), |
777 client(), | 767 client()->mock_driver(), *observed_form(), |
778 client()->GetDriver(), | |
779 *observed_form(), | |
780 false); | 768 false); |
781 EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_)) | 769 EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_)) |
782 .Times(1); | 770 .Times(1); |
783 EXPECT_CALL(*(client()->mock_driver()), IsOffTheRecord()) | 771 EXPECT_CALL(*(client()->mock_driver()), IsOffTheRecord()) |
784 .WillRepeatedly(Return(false)); | 772 .WillRepeatedly(Return(false)); |
785 SimulateFetchMatchingLoginsFromPasswordStore(&manager_creds); | 773 SimulateFetchMatchingLoginsFromPasswordStore(&manager_creds); |
786 // We need add heap allocated objects to result. | 774 // We need add heap allocated objects to result. |
787 result.push_back(CreateSavedMatch(false)); | 775 result.push_back(CreateSavedMatch(false)); |
788 SimulateResponseFromPasswordStore(&manager_creds, result); | 776 SimulateResponseFromPasswordStore(&manager_creds, result); |
789 Mock::VerifyAndClearExpectations(client()->mock_driver()); | 777 Mock::VerifyAndClearExpectations(client()->mock_driver()); |
790 | 778 |
791 // There are cases, such as when a form is explicitly for creating a new | 779 // There are cases, such as when a form is explicitly for creating a new |
792 // password, where we may ignore saved credentials. Make sure that we still | 780 // password, where we may ignore saved credentials. Make sure that we still |
793 // allow generation in that case. | 781 // allow generation in that case. |
794 PasswordForm signup_form(*observed_form()); | 782 PasswordForm signup_form(*observed_form()); |
795 signup_form.new_password_element = base::ASCIIToUTF16("new_password_field"); | 783 signup_form.new_password_element = base::ASCIIToUTF16("new_password_field"); |
796 | 784 |
797 PasswordFormManager manager_dropped_creds(&password_manager, | 785 PasswordFormManager manager_dropped_creds( |
798 client(), | 786 &password_manager, client(), client()->mock_driver(), signup_form, false); |
799 client()->GetDriver(), | |
800 signup_form, | |
801 false); | |
802 EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_)) | 787 EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_)) |
803 .Times(1); | 788 .Times(1); |
804 EXPECT_CALL(*(client()->mock_driver()), IsOffTheRecord()) | 789 EXPECT_CALL(*(client()->mock_driver()), IsOffTheRecord()) |
805 .WillRepeatedly(Return(false)); | 790 .WillRepeatedly(Return(false)); |
806 SimulateFetchMatchingLoginsFromPasswordStore(&manager_dropped_creds); | 791 SimulateFetchMatchingLoginsFromPasswordStore(&manager_dropped_creds); |
807 result.clear(); | 792 result.clear(); |
808 result.push_back(CreateSavedMatch(false)); | 793 result.push_back(CreateSavedMatch(false)); |
809 SimulateResponseFromPasswordStore(&manager_dropped_creds, result); | 794 SimulateResponseFromPasswordStore(&manager_dropped_creds, result); |
810 Mock::VerifyAndClearExpectations(client()->mock_driver()); | 795 Mock::VerifyAndClearExpectations(client()->mock_driver()); |
811 | 796 |
812 // Signing up on a previously visited site. Credentials are found in the | 797 // Signing up on a previously visited site. Credentials are found in the |
813 // password store, but they are blacklisted. AllowPasswordGenerationForForm | 798 // password store, but they are blacklisted. AllowPasswordGenerationForForm |
814 // should not be called and no "not blacklisted" message sent. | 799 // should not be called and no "not blacklisted" message sent. |
815 PasswordFormManager manager_blacklisted(&password_manager, | 800 PasswordFormManager manager_blacklisted(&password_manager, client(), |
816 client(), | 801 client()->mock_driver(), |
817 client()->GetDriver(), | 802 *observed_form(), false); |
818 *observed_form(), | |
819 false); | |
820 EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_)) | 803 EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_)) |
821 .Times(0); | 804 .Times(0); |
822 SimulateFetchMatchingLoginsFromPasswordStore(&manager_blacklisted); | 805 SimulateFetchMatchingLoginsFromPasswordStore(&manager_blacklisted); |
823 result.clear(); | 806 result.clear(); |
824 result.push_back(CreateSavedMatch(true)); | 807 result.push_back(CreateSavedMatch(true)); |
825 SimulateResponseFromPasswordStore(&manager_blacklisted, result); | 808 SimulateResponseFromPasswordStore(&manager_blacklisted, result); |
826 Mock::VerifyAndClearExpectations(client()->mock_driver()); | 809 Mock::VerifyAndClearExpectations(client()->mock_driver()); |
827 } | 810 } |
828 | 811 |
829 TEST_F(PasswordFormManagerTest, TestForceInclusionOfGeneratedPasswords) { | 812 TEST_F(PasswordFormManagerTest, TestForceInclusionOfGeneratedPasswords) { |
830 // Simulate having two matches for this origin, one of which was from a form | 813 // Simulate having two matches for this origin, one of which was from a form |
831 // with different HTML tags for elements. Because of scoring differences, | 814 // with different HTML tags for elements. Because of scoring differences, |
832 // only the first form will be sent to Autofill(). | 815 // only the first form will be sent to Autofill(). |
833 TestPasswordManager password_manager(client()); | 816 TestPasswordManager password_manager(client()); |
834 PasswordFormManager manager_match(&password_manager, | 817 PasswordFormManager manager_match(&password_manager, client(), |
835 client(), | 818 client()->mock_driver(), *observed_form(), |
836 client()->GetDriver(), | |
837 *observed_form(), | |
838 false); | 819 false); |
839 EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_)) | 820 EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_)) |
840 .Times(1); | 821 .Times(1); |
841 EXPECT_CALL(*(client()->mock_driver()), IsOffTheRecord()) | 822 EXPECT_CALL(*(client()->mock_driver()), IsOffTheRecord()) |
842 .WillRepeatedly(Return(false)); | 823 .WillRepeatedly(Return(false)); |
843 | 824 |
844 std::vector<PasswordForm*> results; | 825 std::vector<PasswordForm*> results; |
845 results.push_back(CreateSavedMatch(false)); | 826 results.push_back(CreateSavedMatch(false)); |
846 results.push_back(CreateSavedMatch(false)); | 827 results.push_back(CreateSavedMatch(false)); |
847 results[1]->username_value = ASCIIToUTF16("other@gmail.com"); | 828 results[1]->username_value = ASCIIToUTF16("other@gmail.com"); |
848 results[1]->password_element = ASCIIToUTF16("signup_password"); | 829 results[1]->password_element = ASCIIToUTF16("signup_password"); |
849 results[1]->username_element = ASCIIToUTF16("signup_username"); | 830 results[1]->username_element = ASCIIToUTF16("signup_username"); |
850 SimulateFetchMatchingLoginsFromPasswordStore(&manager_match); | 831 SimulateFetchMatchingLoginsFromPasswordStore(&manager_match); |
851 SimulateResponseFromPasswordStore(&manager_match, results); | 832 SimulateResponseFromPasswordStore(&manager_match, results); |
852 EXPECT_EQ(1u, password_manager.GetLatestBestMatches().size()); | 833 EXPECT_EQ(1u, password_manager.GetLatestBestMatches().size()); |
853 results.clear(); | 834 results.clear(); |
854 | 835 |
855 // Same thing, except this time the credentials that don't match quite as | 836 // Same thing, except this time the credentials that don't match quite as |
856 // well are generated. They should now be sent to Autofill(). | 837 // well are generated. They should now be sent to Autofill(). |
857 PasswordFormManager manager_no_match(&password_manager, | 838 PasswordFormManager manager_no_match(&password_manager, client(), |
858 client(), | 839 client()->mock_driver(), |
859 client()->GetDriver(), | 840 *observed_form(), false); |
860 *observed_form(), | |
861 false); | |
862 EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_)) | 841 EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_)) |
863 .Times(1); | 842 .Times(1); |
864 | 843 |
865 results.push_back(CreateSavedMatch(false)); | 844 results.push_back(CreateSavedMatch(false)); |
866 results.push_back(CreateSavedMatch(false)); | 845 results.push_back(CreateSavedMatch(false)); |
867 results[1]->username_value = ASCIIToUTF16("other@gmail.com"); | 846 results[1]->username_value = ASCIIToUTF16("other@gmail.com"); |
868 results[1]->password_element = ASCIIToUTF16("signup_password"); | 847 results[1]->password_element = ASCIIToUTF16("signup_password"); |
869 results[1]->username_element = ASCIIToUTF16("signup_username"); | 848 results[1]->username_element = ASCIIToUTF16("signup_username"); |
870 results[1]->type = PasswordForm::TYPE_GENERATED; | 849 results[1]->type = PasswordForm::TYPE_GENERATED; |
871 SimulateFetchMatchingLoginsFromPasswordStore(&manager_no_match); | 850 SimulateFetchMatchingLoginsFromPasswordStore(&manager_no_match); |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1137 first.action = observed_form()->action; | 1116 first.action = observed_form()->action; |
1138 first.password_value = ASCIIToUTF16("first"); | 1117 first.password_value = ASCIIToUTF16("first"); |
1139 password_store->AddLogin(first); | 1118 password_store->AddLogin(first); |
1140 | 1119 |
1141 PasswordForm second(first); | 1120 PasswordForm second(first); |
1142 second.origin = GURL("http://accounts.google.com/a/AddLogin"); | 1121 second.origin = GURL("http://accounts.google.com/a/AddLogin"); |
1143 second.password_value = ASCIIToUTF16("second"); | 1122 second.password_value = ASCIIToUTF16("second"); |
1144 second.preferred = false; | 1123 second.preferred = false; |
1145 password_store->AddLogin(second); | 1124 password_store->AddLogin(second); |
1146 | 1125 |
1147 PasswordFormManager storing_manager(&password_manager, | 1126 PasswordFormManager storing_manager(&password_manager, &client_with_store, |
1148 &client_with_store, | 1127 client_with_store.mock_driver(), |
1149 client_with_store.GetDriver(), | 1128 *observed_form(), false); |
1150 *observed_form(), | |
1151 false); | |
1152 storing_manager.FetchMatchingLoginsFromPasswordStore( | 1129 storing_manager.FetchMatchingLoginsFromPasswordStore( |
1153 PasswordStore::ALLOW_PROMPT); | 1130 PasswordStore::ALLOW_PROMPT); |
1154 RunAllPendingTasks(); | 1131 RunAllPendingTasks(); |
1155 | 1132 |
1156 // We always take the last credential with a particular username, regardless | 1133 // We always take the last credential with a particular username, regardless |
1157 // of which ones are labeled preferred. | 1134 // of which ones are labeled preferred. |
1158 EXPECT_EQ(ASCIIToUTF16("second"), | 1135 EXPECT_EQ(ASCIIToUTF16("second"), |
1159 storing_manager.preferred_match()->password_value); | 1136 storing_manager.preferred_match()->password_value); |
1160 | 1137 |
1161 PasswordForm login(*observed_form()); | 1138 PasswordForm login(*observed_form()); |
1162 login.username_value = saved_match()->username_value; | 1139 login.username_value = saved_match()->username_value; |
1163 login.password_value = ASCIIToUTF16("third"); | 1140 login.password_value = ASCIIToUTF16("third"); |
1164 login.preferred = true; | 1141 login.preferred = true; |
1165 storing_manager.ProvisionallySave( | 1142 storing_manager.ProvisionallySave( |
1166 login, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); | 1143 login, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); |
1167 | 1144 |
1168 EXPECT_FALSE(storing_manager.IsNewLogin()); | 1145 EXPECT_FALSE(storing_manager.IsNewLogin()); |
1169 storing_manager.Save(); | 1146 storing_manager.Save(); |
1170 RunAllPendingTasks(); | 1147 RunAllPendingTasks(); |
1171 | 1148 |
1172 PasswordFormManager retrieving_manager(&password_manager, | 1149 PasswordFormManager retrieving_manager(&password_manager, &client_with_store, |
1173 &client_with_store, | 1150 client_with_store.mock_driver(), |
1174 client_with_store.GetDriver(), | 1151 *observed_form(), false); |
1175 *observed_form(), | |
1176 false); | |
1177 | 1152 |
1178 retrieving_manager.FetchMatchingLoginsFromPasswordStore( | 1153 retrieving_manager.FetchMatchingLoginsFromPasswordStore( |
1179 PasswordStore::ALLOW_PROMPT); | 1154 PasswordStore::ALLOW_PROMPT); |
1180 RunAllPendingTasks(); | 1155 RunAllPendingTasks(); |
1181 | 1156 |
1182 // Make sure that the preferred match is updated appropriately. | 1157 // Make sure that the preferred match is updated appropriately. |
1183 EXPECT_EQ(ASCIIToUTF16("third"), | 1158 EXPECT_EQ(ASCIIToUTF16("third"), |
1184 retrieving_manager.preferred_match()->password_value); | 1159 retrieving_manager.preferred_match()->password_value); |
1185 password_store->Shutdown(); | 1160 password_store->Shutdown(); |
1186 } | 1161 } |
1187 | 1162 |
1188 TEST_F(PasswordFormManagerTest, UploadFormData_NewPassword) { | 1163 TEST_F(PasswordFormManagerTest, UploadFormData_NewPassword) { |
1189 TestPasswordManagerClient client_with_store(mock_store()); | 1164 TestPasswordManagerClient client_with_store(mock_store()); |
1190 TestPasswordManager password_manager(&client_with_store); | 1165 TestPasswordManager password_manager(&client_with_store); |
1191 EXPECT_CALL(*client_with_store.mock_driver(), IsOffTheRecord()) | 1166 EXPECT_CALL(*client_with_store.mock_driver(), IsOffTheRecord()) |
1192 .WillRepeatedly(Return(false)); | 1167 .WillRepeatedly(Return(false)); |
1193 | 1168 |
1194 // For newly saved passwords, upload a vote for autofill::PASSWORD. | 1169 // For newly saved passwords, upload a vote for autofill::PASSWORD. |
1195 PasswordFormManager form_manager(&password_manager, | 1170 PasswordFormManager form_manager(&password_manager, &client_with_store, |
1196 &client_with_store, | 1171 client_with_store.mock_driver(), |
1197 client_with_store.GetDriver(), | 1172 *saved_match(), false); |
1198 *saved_match(), | |
1199 false); | |
1200 SimulateMatchingPhase(&form_manager, RESULT_NO_MATCH); | 1173 SimulateMatchingPhase(&form_manager, RESULT_NO_MATCH); |
1201 | 1174 |
1202 PasswordForm form_to_save(*saved_match()); | 1175 PasswordForm form_to_save(*saved_match()); |
1203 form_to_save.preferred = true; | 1176 form_to_save.preferred = true; |
1204 form_to_save.username_value = ASCIIToUTF16("username"); | 1177 form_to_save.username_value = ASCIIToUTF16("username"); |
1205 form_to_save.password_value = ASCIIToUTF16("1234"); | 1178 form_to_save.password_value = ASCIIToUTF16("1234"); |
1206 | 1179 |
1207 EXPECT_CALL(*client_with_store.mock_driver()->mock_autofill_manager(), | 1180 EXPECT_CALL(*client_with_store.mock_driver()->mock_autofill_manager(), |
1208 UploadPasswordForm(_, autofill::PASSWORD)).Times(1); | 1181 UploadPasswordForm(_, autofill::PASSWORD)).Times(1); |
1209 form_manager.ProvisionallySave( | 1182 form_manager.ProvisionallySave( |
1210 form_to_save, | 1183 form_to_save, |
1211 PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); | 1184 PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); |
1212 form_manager.Save(); | 1185 form_manager.Save(); |
1213 Mock::VerifyAndClearExpectations(&form_manager); | 1186 Mock::VerifyAndClearExpectations(&form_manager); |
1214 | 1187 |
1215 // Do not upload a vote if the user is blacklisting the form. | 1188 // Do not upload a vote if the user is blacklisting the form. |
1216 PasswordFormManager blacklist_form_manager(&password_manager, | 1189 PasswordFormManager blacklist_form_manager( |
1217 &client_with_store, | 1190 &password_manager, &client_with_store, client_with_store.mock_driver(), |
1218 client_with_store.GetDriver(), | 1191 *saved_match(), false); |
1219 *saved_match(), | |
1220 false); | |
1221 SimulateMatchingPhase(&blacklist_form_manager, RESULT_NO_MATCH); | 1192 SimulateMatchingPhase(&blacklist_form_manager, RESULT_NO_MATCH); |
1222 | 1193 |
1223 EXPECT_CALL(*client_with_store.mock_driver()->mock_autofill_manager(), | 1194 EXPECT_CALL(*client_with_store.mock_driver()->mock_autofill_manager(), |
1224 UploadPasswordForm(_, autofill::PASSWORD)).Times(0); | 1195 UploadPasswordForm(_, autofill::PASSWORD)).Times(0); |
1225 blacklist_form_manager.PermanentlyBlacklist(); | 1196 blacklist_form_manager.PermanentlyBlacklist(); |
1226 Mock::VerifyAndClearExpectations(&blacklist_form_manager); | 1197 Mock::VerifyAndClearExpectations(&blacklist_form_manager); |
1227 } | 1198 } |
1228 | 1199 |
1229 TEST_F(PasswordFormManagerTest, UploadFormData_AccountCreationPassword) { | 1200 TEST_F(PasswordFormManagerTest, UploadFormData_AccountCreationPassword) { |
1230 TestPasswordManagerClient client_with_store(mock_store()); | 1201 TestPasswordManagerClient client_with_store(mock_store()); |
1231 TestPasswordManager password_manager(&client_with_store); | 1202 TestPasswordManager password_manager(&client_with_store); |
1232 EXPECT_CALL(*client_with_store.mock_driver(), IsOffTheRecord()) | 1203 EXPECT_CALL(*client_with_store.mock_driver(), IsOffTheRecord()) |
1233 .WillRepeatedly(Return(false)); | 1204 .WillRepeatedly(Return(false)); |
1234 | 1205 |
1235 PasswordForm form(*observed_form()); | 1206 PasswordForm form(*observed_form()); |
1236 | 1207 |
1237 autofill::FormFieldData field; | 1208 autofill::FormFieldData field; |
1238 field.label = ASCIIToUTF16("Email"); | 1209 field.label = ASCIIToUTF16("Email"); |
1239 field.name = ASCIIToUTF16("Email"); | 1210 field.name = ASCIIToUTF16("Email"); |
1240 field.form_control_type = "text"; | 1211 field.form_control_type = "text"; |
1241 form.form_data.fields.push_back(field); | 1212 form.form_data.fields.push_back(field); |
1242 | 1213 |
1243 field.label = ASCIIToUTF16("password"); | 1214 field.label = ASCIIToUTF16("password"); |
1244 field.name = ASCIIToUTF16("password"); | 1215 field.name = ASCIIToUTF16("password"); |
1245 field.form_control_type = "password"; | 1216 field.form_control_type = "password"; |
1246 form.form_data.fields.push_back(field); | 1217 form.form_data.fields.push_back(field); |
1247 | 1218 |
1248 PasswordFormManager form_manager(&password_manager, | 1219 PasswordFormManager form_manager(&password_manager, &client_with_store, |
1249 &client_with_store, | 1220 client_with_store.mock_driver(), form, |
1250 client_with_store.GetDriver(), | |
1251 form, | |
1252 false); | 1221 false); |
1253 std::vector<PasswordForm*> result; | 1222 std::vector<PasswordForm*> result; |
1254 result.push_back(CreateSavedMatch(false)); | 1223 result.push_back(CreateSavedMatch(false)); |
1255 | 1224 |
1256 field.label = ASCIIToUTF16("full_name"); | 1225 field.label = ASCIIToUTF16("full_name"); |
1257 field.name = ASCIIToUTF16("full_name"); | 1226 field.name = ASCIIToUTF16("full_name"); |
1258 field.form_control_type = "text"; | 1227 field.form_control_type = "text"; |
1259 result[0]->form_data.fields.push_back(field); | 1228 result[0]->form_data.fields.push_back(field); |
1260 | 1229 |
1261 field.label = ASCIIToUTF16("Email"); | 1230 field.label = ASCIIToUTF16("Email"); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1294 EXPECT_CALL(*client_with_store.mock_driver(), | 1263 EXPECT_CALL(*client_with_store.mock_driver(), |
1295 AllowPasswordGenerationForForm(_)).Times(2); | 1264 AllowPasswordGenerationForForm(_)).Times(2); |
1296 EXPECT_CALL(*client_with_store.mock_driver(), IsOffTheRecord()) | 1265 EXPECT_CALL(*client_with_store.mock_driver(), IsOffTheRecord()) |
1297 .WillRepeatedly(Return(false)); | 1266 .WillRepeatedly(Return(false)); |
1298 | 1267 |
1299 PasswordForm form(*observed_form()); | 1268 PasswordForm form(*observed_form()); |
1300 form.username_element.clear(); | 1269 form.username_element.clear(); |
1301 form.password_value = ASCIIToUTF16("password"); | 1270 form.password_value = ASCIIToUTF16("password"); |
1302 form.preferred = true; | 1271 form.preferred = true; |
1303 | 1272 |
1304 PasswordFormManager storing_manager(&password_manager, | 1273 PasswordFormManager storing_manager(&password_manager, &client_with_store, |
1305 &client_with_store, | 1274 client_with_store.mock_driver(), |
1306 client_with_store.GetDriver(), | 1275 *observed_form(), false); |
1307 *observed_form(), | |
1308 false); | |
1309 storing_manager.FetchMatchingLoginsFromPasswordStore( | 1276 storing_manager.FetchMatchingLoginsFromPasswordStore( |
1310 PasswordStore::ALLOW_PROMPT); | 1277 PasswordStore::ALLOW_PROMPT); |
1311 RunAllPendingTasks(); | 1278 RunAllPendingTasks(); |
1312 | 1279 |
1313 storing_manager.ProvisionallySave( | 1280 storing_manager.ProvisionallySave( |
1314 form, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); | 1281 form, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); |
1315 | 1282 |
1316 EXPECT_TRUE(storing_manager.IsNewLogin()); | 1283 EXPECT_TRUE(storing_manager.IsNewLogin()); |
1317 storing_manager.Save(); | 1284 storing_manager.Save(); |
1318 RunAllPendingTasks(); | 1285 RunAllPendingTasks(); |
1319 | 1286 |
1320 PasswordFormManager retrieving_manager(&password_manager, | 1287 PasswordFormManager retrieving_manager(&password_manager, &client_with_store, |
1321 &client_with_store, | 1288 client_with_store.mock_driver(), |
1322 client_with_store.GetDriver(), | 1289 *observed_form(), false); |
1323 *observed_form(), | |
1324 false); | |
1325 | 1290 |
1326 retrieving_manager.FetchMatchingLoginsFromPasswordStore( | 1291 retrieving_manager.FetchMatchingLoginsFromPasswordStore( |
1327 PasswordStore::ALLOW_PROMPT); | 1292 PasswordStore::ALLOW_PROMPT); |
1328 RunAllPendingTasks(); | 1293 RunAllPendingTasks(); |
1329 | 1294 |
1330 // Make sure that the preferred match is updated appropriately. | 1295 // Make sure that the preferred match is updated appropriately. |
1331 EXPECT_EQ(ASCIIToUTF16("password"), | 1296 EXPECT_EQ(ASCIIToUTF16("password"), |
1332 retrieving_manager.preferred_match()->password_value); | 1297 retrieving_manager.preferred_match()->password_value); |
1333 password_store->Shutdown(); | 1298 password_store->Shutdown(); |
1334 } | 1299 } |
1335 | 1300 |
1336 } // namespace password_manager | 1301 } // namespace password_manager |
OLD | NEW |