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

Side by Side Diff: components/password_manager/core/browser/password_form_manager_unittest.cc

Issue 866983003: GetLoginsRequest: Use ScopedVector to express ownership of forms (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@324291_scopedvector
Patch Set: Fix Mac unittest Created 5 years, 10 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 (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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 p->best_matches_[match->username_value] = match; 219 p->best_matches_[match->username_value] = match;
220 p->preferred_match_ = match; 220 p->preferred_match_ = match;
221 } 221 }
222 222
223 void SimulateFetchMatchingLoginsFromPasswordStore( 223 void SimulateFetchMatchingLoginsFromPasswordStore(
224 PasswordFormManager* manager) { 224 PasswordFormManager* manager) {
225 // Just need to update the internal states. 225 // Just need to update the internal states.
226 manager->state_ = PasswordFormManager::MATCHING_PHASE; 226 manager->state_ = PasswordFormManager::MATCHING_PHASE;
227 } 227 }
228 228
229 void SimulateResponseFromPasswordStore(
230 PasswordFormManager* manager,
231 const std::vector<PasswordForm*>& result) {
232 // Simply call the callback method when request done. This will transfer
233 // the ownership of the objects in |result| to the |manager|.
234 manager->OnGetPasswordStoreResults(result);
235 }
236
237 void SanitizePossibleUsernames(PasswordFormManager* p, PasswordForm* form) { 229 void SanitizePossibleUsernames(PasswordFormManager* p, PasswordForm* form) {
238 p->SanitizePossibleUsernames(form); 230 p->SanitizePossibleUsernames(form);
239 } 231 }
240 232
241 bool IgnoredResult(PasswordFormManager* p, PasswordForm* form) { 233 bool IgnoredResult(PasswordFormManager* p, PasswordForm* form) {
242 return p->ShouldIgnoreResult(*form); 234 return p->ShouldIgnoreResult(*form);
243 } 235 }
244 236
245 PasswordForm* observed_form() { return &observed_form_; } 237 PasswordForm* observed_form() { return &observed_form_; }
246 PasswordForm* saved_match() { return &saved_match_; } 238 PasswordForm* saved_match() { return &saved_match_; }
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 TestPasswordManager password_manager(client()); 754 TestPasswordManager password_manager(client());
763 PasswordFormManager manager_no_creds( 755 PasswordFormManager manager_no_creds(
764 &password_manager, client(), client()->driver(), *observed_form(), false); 756 &password_manager, client(), client()->driver(), *observed_form(), false);
765 757
766 // First time sign-up attempt. Password store does not contain matching 758 // First time sign-up attempt. Password store does not contain matching
767 // credentials. AllowPasswordGenerationForForm should be called to send the 759 // credentials. AllowPasswordGenerationForForm should be called to send the
768 // "not blacklisted" message. 760 // "not blacklisted" message.
769 EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_)) 761 EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_))
770 .Times(1); 762 .Times(1);
771 SimulateFetchMatchingLoginsFromPasswordStore(&manager_no_creds); 763 SimulateFetchMatchingLoginsFromPasswordStore(&manager_no_creds);
772 std::vector<PasswordForm*> result; 764 manager_no_creds.OnGetPasswordStoreResults(ScopedVector<PasswordForm>());
773 SimulateResponseFromPasswordStore(&manager_no_creds, result);
774 Mock::VerifyAndClearExpectations(client()->mock_driver()); 765 Mock::VerifyAndClearExpectations(client()->mock_driver());
775 766
776 // Signing up on a previously visited site. Credentials are found in the 767 // Signing up on a previously visited site. Credentials are found in the
777 // password store, and are not blacklisted. AllowPasswordGenerationForForm 768 // password store, and are not blacklisted. AllowPasswordGenerationForForm
778 // should be called to send the "not blacklisted" message. 769 // should be called to send the "not blacklisted" message.
779 PasswordFormManager manager_creds( 770 PasswordFormManager manager_creds(
780 &password_manager, client(), client()->driver(), *observed_form(), false); 771 &password_manager, client(), client()->driver(), *observed_form(), false);
781 EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_)) 772 EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_))
782 .Times(1); 773 .Times(1);
783 EXPECT_CALL(*(client()->mock_driver()), IsOffTheRecord()) 774 EXPECT_CALL(*(client()->mock_driver()), IsOffTheRecord())
784 .WillRepeatedly(Return(false)); 775 .WillRepeatedly(Return(false));
785 SimulateFetchMatchingLoginsFromPasswordStore(&manager_creds); 776 SimulateFetchMatchingLoginsFromPasswordStore(&manager_creds);
786 // We need add heap allocated objects to result. 777 ScopedVector<PasswordForm> simulated_results;
787 result.push_back(CreateSavedMatch(false)); 778 simulated_results.push_back(CreateSavedMatch(false));
788 SimulateResponseFromPasswordStore(&manager_creds, result); 779 manager_creds.OnGetPasswordStoreResults(simulated_results.Pass());
789 Mock::VerifyAndClearExpectations(client()->mock_driver()); 780 Mock::VerifyAndClearExpectations(client()->mock_driver());
790 781
791 // There are cases, such as when a form is explicitly for creating a new 782 // 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 783 // password, where we may ignore saved credentials. Make sure that we still
793 // allow generation in that case. 784 // allow generation in that case.
794 PasswordForm signup_form(*observed_form()); 785 PasswordForm signup_form(*observed_form());
795 signup_form.new_password_element = base::ASCIIToUTF16("new_password_field"); 786 signup_form.new_password_element = base::ASCIIToUTF16("new_password_field");
796 787
797 PasswordFormManager manager_dropped_creds( 788 PasswordFormManager manager_dropped_creds(
798 &password_manager, client(), client()->driver(), signup_form, false); 789 &password_manager, client(), client()->driver(), signup_form, false);
799 EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_)) 790 EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_))
800 .Times(1); 791 .Times(1);
801 EXPECT_CALL(*(client()->mock_driver()), IsOffTheRecord()) 792 EXPECT_CALL(*(client()->mock_driver()), IsOffTheRecord())
802 .WillRepeatedly(Return(false)); 793 .WillRepeatedly(Return(false));
803 SimulateFetchMatchingLoginsFromPasswordStore(&manager_dropped_creds); 794 SimulateFetchMatchingLoginsFromPasswordStore(&manager_dropped_creds);
804 result.clear(); 795 simulated_results.push_back(CreateSavedMatch(false));
805 result.push_back(CreateSavedMatch(false)); 796 manager_dropped_creds.OnGetPasswordStoreResults(simulated_results.Pass());
806 SimulateResponseFromPasswordStore(&manager_dropped_creds, result);
807 Mock::VerifyAndClearExpectations(client()->mock_driver()); 797 Mock::VerifyAndClearExpectations(client()->mock_driver());
808 798
809 // Signing up on a previously visited site. Credentials are found in the 799 // Signing up on a previously visited site. Credentials are found in the
810 // password store, but they are blacklisted. AllowPasswordGenerationForForm 800 // password store, but they are blacklisted. AllowPasswordGenerationForForm
811 // should not be called and no "not blacklisted" message sent. 801 // should not be called and no "not blacklisted" message sent.
812 PasswordFormManager manager_blacklisted( 802 PasswordFormManager manager_blacklisted(
813 &password_manager, client(), client()->driver(), *observed_form(), false); 803 &password_manager, client(), client()->driver(), *observed_form(), false);
814 EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_)) 804 EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_))
815 .Times(0); 805 .Times(0);
816 SimulateFetchMatchingLoginsFromPasswordStore(&manager_blacklisted); 806 SimulateFetchMatchingLoginsFromPasswordStore(&manager_blacklisted);
817 result.clear(); 807 simulated_results.push_back(CreateSavedMatch(true));
818 result.push_back(CreateSavedMatch(true)); 808 manager_blacklisted.OnGetPasswordStoreResults(simulated_results.Pass());
819 SimulateResponseFromPasswordStore(&manager_blacklisted, result);
820 Mock::VerifyAndClearExpectations(client()->mock_driver()); 809 Mock::VerifyAndClearExpectations(client()->mock_driver());
821 } 810 }
822 811
823 TEST_F(PasswordFormManagerTest, TestForceInclusionOfGeneratedPasswords) { 812 TEST_F(PasswordFormManagerTest, TestForceInclusionOfGeneratedPasswords) {
824 // 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
825 // with different HTML tags for elements. Because of scoring differences, 814 // with different HTML tags for elements. Because of scoring differences,
826 // only the first form will be sent to Autofill(). 815 // only the first form will be sent to Autofill().
827 TestPasswordManager password_manager(client()); 816 TestPasswordManager password_manager(client());
828 PasswordFormManager manager_match( 817 PasswordFormManager manager_match(
829 &password_manager, client(), client()->driver(), *observed_form(), false); 818 &password_manager, client(), client()->driver(), *observed_form(), false);
830 EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_)) 819 EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_))
831 .Times(1); 820 .Times(1);
832 EXPECT_CALL(*(client()->mock_driver()), IsOffTheRecord()) 821 EXPECT_CALL(*(client()->mock_driver()), IsOffTheRecord())
833 .WillRepeatedly(Return(false)); 822 .WillRepeatedly(Return(false));
834 823
835 std::vector<PasswordForm*> results; 824 ScopedVector<PasswordForm> simulated_results;
836 results.push_back(CreateSavedMatch(false)); 825 simulated_results.push_back(CreateSavedMatch(false));
837 results.push_back(CreateSavedMatch(false)); 826 simulated_results.push_back(CreateSavedMatch(false));
838 results[1]->username_value = ASCIIToUTF16("other@gmail.com"); 827 simulated_results[1]->username_value = ASCIIToUTF16("other@gmail.com");
839 results[1]->password_element = ASCIIToUTF16("signup_password"); 828 simulated_results[1]->password_element = ASCIIToUTF16("signup_password");
840 results[1]->username_element = ASCIIToUTF16("signup_username"); 829 simulated_results[1]->username_element = ASCIIToUTF16("signup_username");
841 SimulateFetchMatchingLoginsFromPasswordStore(&manager_match); 830 SimulateFetchMatchingLoginsFromPasswordStore(&manager_match);
842 SimulateResponseFromPasswordStore(&manager_match, results); 831 manager_match.OnGetPasswordStoreResults(simulated_results.Pass());
843 EXPECT_EQ(1u, password_manager.GetLatestBestMatches().size()); 832 EXPECT_EQ(1u, password_manager.GetLatestBestMatches().size());
844 results.clear();
845 833
846 // Same thing, except this time the credentials that don't match quite as 834 // Same thing, except this time the credentials that don't match quite as
847 // well are generated. They should now be sent to Autofill(). 835 // well are generated. They should now be sent to Autofill().
848 PasswordFormManager manager_no_match( 836 PasswordFormManager manager_no_match(
849 &password_manager, client(), client()->driver(), *observed_form(), false); 837 &password_manager, client(), client()->driver(), *observed_form(), false);
850 EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_)) 838 EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_))
851 .Times(1); 839 .Times(1);
852 840
853 results.push_back(CreateSavedMatch(false)); 841 simulated_results.push_back(CreateSavedMatch(false));
854 results.push_back(CreateSavedMatch(false)); 842 simulated_results.push_back(CreateSavedMatch(false));
855 results[1]->username_value = ASCIIToUTF16("other@gmail.com"); 843 simulated_results[1]->username_value = ASCIIToUTF16("other@gmail.com");
856 results[1]->password_element = ASCIIToUTF16("signup_password"); 844 simulated_results[1]->password_element = ASCIIToUTF16("signup_password");
857 results[1]->username_element = ASCIIToUTF16("signup_username"); 845 simulated_results[1]->username_element = ASCIIToUTF16("signup_username");
858 results[1]->type = PasswordForm::TYPE_GENERATED; 846 simulated_results[1]->type = PasswordForm::TYPE_GENERATED;
859 SimulateFetchMatchingLoginsFromPasswordStore(&manager_no_match); 847 SimulateFetchMatchingLoginsFromPasswordStore(&manager_no_match);
860 SimulateResponseFromPasswordStore(&manager_no_match, results); 848 manager_no_match.OnGetPasswordStoreResults(simulated_results.Pass());
861 EXPECT_EQ(2u, password_manager.GetLatestBestMatches().size()); 849 EXPECT_EQ(2u, password_manager.GetLatestBestMatches().size());
862 } 850 }
863 851
864 TEST_F(PasswordFormManagerTest, TestSanitizePossibleUsernames) { 852 TEST_F(PasswordFormManagerTest, TestSanitizePossibleUsernames) {
865 PasswordFormManager manager(NULL, client(), kNoDriver, *observed_form(), 853 PasswordFormManager manager(NULL, client(), kNoDriver, *observed_form(),
866 false); 854 false);
867 PasswordForm credentials(*observed_form()); 855 PasswordForm credentials(*observed_form());
868 credentials.other_possible_usernames.push_back(ASCIIToUTF16("543-43-1234")); 856 credentials.other_possible_usernames.push_back(ASCIIToUTF16("543-43-1234"));
869 credentials.other_possible_usernames.push_back( 857 credentials.other_possible_usernames.push_back(
870 ASCIIToUTF16("378282246310005")); 858 ASCIIToUTF16("378282246310005"));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 client_with_store.driver(), encountered_form, 906 client_with_store.driver(), encountered_form,
919 false); 907 false);
920 908
921 const PasswordStore::AuthorizationPromptPolicy auth_policy = 909 const PasswordStore::AuthorizationPromptPolicy auth_policy =
922 PasswordStore::DISALLOW_PROMPT; 910 PasswordStore::DISALLOW_PROMPT;
923 EXPECT_CALL(*mock_store(), 911 EXPECT_CALL(*mock_store(),
924 GetLogins(encountered_form, auth_policy, &form_manager)); 912 GetLogins(encountered_form, auth_policy, &form_manager));
925 form_manager.FetchMatchingLoginsFromPasswordStore(auth_policy); 913 form_manager.FetchMatchingLoginsFromPasswordStore(auth_policy);
926 914
927 // Password store only has these incomplete credentials. 915 // Password store only has these incomplete credentials.
928 PasswordForm* incomplete_form = new PasswordForm(); 916 scoped_ptr<PasswordForm> incomplete_form(new PasswordForm());
929 incomplete_form->origin = GURL("http://accounts.google.com/LoginAuth"); 917 incomplete_form->origin = GURL("http://accounts.google.com/LoginAuth");
930 incomplete_form->signon_realm = "http://accounts.google.com/"; 918 incomplete_form->signon_realm = "http://accounts.google.com/";
931 incomplete_form->password_value = ASCIIToUTF16("my_password"); 919 incomplete_form->password_value = ASCIIToUTF16("my_password");
932 incomplete_form->username_value = ASCIIToUTF16("my_username"); 920 incomplete_form->username_value = ASCIIToUTF16("my_username");
933 incomplete_form->preferred = true; 921 incomplete_form->preferred = true;
934 incomplete_form->ssl_valid = false; 922 incomplete_form->ssl_valid = false;
935 incomplete_form->scheme = PasswordForm::SCHEME_HTML; 923 incomplete_form->scheme = PasswordForm::SCHEME_HTML;
936 924
937 // We expect to see this form eventually sent to the Password store. It 925 // We expect to see this form eventually sent to the Password store. It
938 // has password/username values from the store and 'username_element', 926 // has password/username values from the store and 'username_element',
939 // 'password_element', 'submit_element' and 'action' fields copied from 927 // 'password_element', 'submit_element' and 'action' fields copied from
940 // the encountered form. 928 // the encountered form.
941 PasswordForm complete_form(*incomplete_form); 929 PasswordForm complete_form(*incomplete_form);
942 complete_form.action = encountered_form.action; 930 complete_form.action = encountered_form.action;
943 complete_form.password_element = encountered_form.password_element; 931 complete_form.password_element = encountered_form.password_element;
944 complete_form.username_element = encountered_form.username_element; 932 complete_form.username_element = encountered_form.username_element;
945 complete_form.submit_element = encountered_form.submit_element; 933 complete_form.submit_element = encountered_form.submit_element;
946 934
947 PasswordForm obsolete_form(*incomplete_form); 935 PasswordForm obsolete_form(*incomplete_form);
948 obsolete_form.action = encountered_form.action; 936 obsolete_form.action = encountered_form.action;
949 937
950 // Feed the incomplete credentials to the manager. 938 // Feed the incomplete credentials to the manager.
951 std::vector<PasswordForm*> results; 939 ScopedVector<PasswordForm> simulated_results;
952 results.push_back(incomplete_form); // Takes ownership. 940 simulated_results.push_back(incomplete_form.release());
953 form_manager.OnGetPasswordStoreResults(results); 941 form_manager.OnGetPasswordStoreResults(simulated_results.Pass());
954 942
955 form_manager.ProvisionallySave( 943 form_manager.ProvisionallySave(
956 complete_form, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); 944 complete_form, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES);
957 // By now that form has been used once. 945 // By now that form has been used once.
958 complete_form.times_used = 1; 946 complete_form.times_used = 1;
959 obsolete_form.times_used = 1; 947 obsolete_form.times_used = 1;
960 948
961 // Check that PasswordStore receives an update request with the complete form. 949 // Check that PasswordStore receives an update request with the complete form.
962 EXPECT_CALL(*mock_store(), RemoveLogin(obsolete_form)); 950 EXPECT_CALL(*mock_store(), RemoveLogin(obsolete_form));
963 EXPECT_CALL(*mock_store(), AddLogin(complete_form)); 951 EXPECT_CALL(*mock_store(), AddLogin(complete_form));
964 form_manager.Save(); 952 form_manager.Save();
965 } 953 }
966 954
967 TEST_F(PasswordFormManagerTest, TestScoringPublicSuffixMatch) { 955 TEST_F(PasswordFormManagerTest, TestScoringPublicSuffixMatch) {
968 EXPECT_CALL(*(client()->mock_driver()), IsOffTheRecord()) 956 EXPECT_CALL(*(client()->mock_driver()), IsOffTheRecord())
969 .WillRepeatedly(Return(false)); 957 .WillRepeatedly(Return(false));
970 EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_)); 958 EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_));
971 959
972 TestPasswordManager password_manager(client()); 960 TestPasswordManager password_manager(client());
973 PasswordFormManager manager(&password_manager, client(), client()->driver(), 961 PasswordFormManager manager(&password_manager, client(), client()->driver(),
974 *observed_form(), false); 962 *observed_form(), false);
975 963
976 // Simulate having two matches for this form, first comes from different 964 // Simulate having two matches for this form, first comes from different
977 // signon realm, but reports the same origin and action as matched form. 965 // signon realm, but reports the same origin and action as matched form.
978 // Second candidate has the same signon realm as the form, but has a different 966 // Second candidate has the same signon realm as the form, but has a different
979 // origin and action. Public suffix match is the most important criterion so 967 // origin and action. Public suffix match is the most important criterion so
980 // the second candidate should be selected. 968 // the second candidate should be selected.
981 std::vector<PasswordForm*> results; 969 ScopedVector<PasswordForm> simulated_results;
982 results.push_back(CreateSavedMatch(false)); 970 simulated_results.push_back(CreateSavedMatch(false));
983 results.push_back(CreateSavedMatch(false)); 971 simulated_results.push_back(CreateSavedMatch(false));
984 results[0]->original_signon_realm = "http://accounts2.google.com"; 972 simulated_results[0]->original_signon_realm = "http://accounts2.google.com";
985 results[1]->origin = GURL("http://accounts.google.com/a/ServiceLoginAuth2"); 973 simulated_results[1]->origin =
986 results[1]->action = GURL("http://accounts.google.com/a/ServiceLogin2"); 974 GURL("http://accounts.google.com/a/ServiceLoginAuth2");
975 simulated_results[1]->action =
976 GURL("http://accounts.google.com/a/ServiceLogin2");
987 SimulateFetchMatchingLoginsFromPasswordStore(&manager); 977 SimulateFetchMatchingLoginsFromPasswordStore(&manager);
988 SimulateResponseFromPasswordStore(&manager, results); 978 manager.OnGetPasswordStoreResults(simulated_results.Pass());
989 EXPECT_EQ(1u, password_manager.GetLatestBestMatches().size()); 979 EXPECT_EQ(1u, password_manager.GetLatestBestMatches().size());
990 EXPECT_EQ("", password_manager.GetLatestBestMatches() 980 EXPECT_EQ("", password_manager.GetLatestBestMatches()
991 .begin() 981 .begin()
992 ->second->original_signon_realm); 982 ->second->original_signon_realm);
993 } 983 }
994 984
995 TEST_F(PasswordFormManagerTest, InvalidActionURLsDoNotMatch) { 985 TEST_F(PasswordFormManagerTest, InvalidActionURLsDoNotMatch) {
996 PasswordFormManager manager(NULL, client(), kNoDriver, *observed_form(), 986 PasswordFormManager manager(NULL, client(), kNoDriver, *observed_form(),
997 false); 987 false);
998 988
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 field.form_control_type = "text"; 1212 field.form_control_type = "text";
1223 form.form_data.fields.push_back(field); 1213 form.form_data.fields.push_back(field);
1224 1214
1225 field.label = ASCIIToUTF16("password"); 1215 field.label = ASCIIToUTF16("password");
1226 field.name = ASCIIToUTF16("password"); 1216 field.name = ASCIIToUTF16("password");
1227 field.form_control_type = "password"; 1217 field.form_control_type = "password";
1228 form.form_data.fields.push_back(field); 1218 form.form_data.fields.push_back(field);
1229 1219
1230 PasswordFormManager form_manager(&password_manager, &client_with_store, 1220 PasswordFormManager form_manager(&password_manager, &client_with_store,
1231 client_with_store.driver(), form, false); 1221 client_with_store.driver(), form, false);
1232 std::vector<PasswordForm*> result; 1222 ScopedVector<PasswordForm> simulated_results;
1233 result.push_back(CreateSavedMatch(false)); 1223 simulated_results.push_back(CreateSavedMatch(false));
1234 1224
1235 field.label = ASCIIToUTF16("full_name"); 1225 field.label = ASCIIToUTF16("full_name");
1236 field.name = ASCIIToUTF16("full_name"); 1226 field.name = ASCIIToUTF16("full_name");
1237 field.form_control_type = "text"; 1227 field.form_control_type = "text";
1238 result[0]->form_data.fields.push_back(field); 1228 simulated_results[0]->form_data.fields.push_back(field);
1239 1229
1240 field.label = ASCIIToUTF16("Email"); 1230 field.label = ASCIIToUTF16("Email");
1241 field.name = ASCIIToUTF16("Email"); 1231 field.name = ASCIIToUTF16("Email");
1242 field.form_control_type = "text"; 1232 field.form_control_type = "text";
1243 result[0]->form_data.fields.push_back(field); 1233 simulated_results[0]->form_data.fields.push_back(field);
1244 1234
1245 field.label = ASCIIToUTF16("password"); 1235 field.label = ASCIIToUTF16("password");
1246 field.name = ASCIIToUTF16("password"); 1236 field.name = ASCIIToUTF16("password");
1247 field.form_control_type = "password"; 1237 field.form_control_type = "password";
1248 result[0]->form_data.fields.push_back(field); 1238 simulated_results[0]->form_data.fields.push_back(field);
1249 1239
1250 PasswordForm form_to_save(form); 1240 PasswordForm form_to_save(form);
1251 form_to_save.preferred = true; 1241 form_to_save.preferred = true;
1252 form_to_save.username_value = result[0]->username_value; 1242 form_to_save.username_value = simulated_results[0]->username_value;
1253 form_to_save.password_value = result[0]->password_value; 1243 form_to_save.password_value = simulated_results[0]->password_value;
1254 1244
1255 SimulateFetchMatchingLoginsFromPasswordStore(&form_manager); 1245 SimulateFetchMatchingLoginsFromPasswordStore(&form_manager);
1256 SimulateResponseFromPasswordStore(&form_manager, result); 1246 form_manager.OnGetPasswordStoreResults(simulated_results.Pass());
1257 1247
1258 EXPECT_CALL(*client_with_store.mock_driver()->mock_autofill_manager(), 1248 EXPECT_CALL(*client_with_store.mock_driver()->mock_autofill_manager(),
1259 UploadPasswordForm(_, autofill::ACCOUNT_CREATION_PASSWORD)) 1249 UploadPasswordForm(_, autofill::ACCOUNT_CREATION_PASSWORD))
1260 .Times(1); 1250 .Times(1);
1261 form_manager.ProvisionallySave( 1251 form_manager.ProvisionallySave(
1262 form_to_save, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); 1252 form_to_save, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES);
1263 form_manager.Save(); 1253 form_manager.Save();
1264 } 1254 }
1265 1255
1266 TEST_F(PasswordFormManagerTest, CorrectlySavePasswordWithoutUsernameFields) { 1256 TEST_F(PasswordFormManagerTest, CorrectlySavePasswordWithoutUsernameFields) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1331 client_with_store.driver(), *form, false); 1321 client_with_store.driver(), *form, false);
1332 1322
1333 const PasswordStore::AuthorizationPromptPolicy auth_policy = 1323 const PasswordStore::AuthorizationPromptPolicy auth_policy =
1334 PasswordStore::DISALLOW_PROMPT; 1324 PasswordStore::DISALLOW_PROMPT;
1335 EXPECT_CALL(*mock_store(), GetLogins(*form, auth_policy, &form_manager)); 1325 EXPECT_CALL(*mock_store(), GetLogins(*form, auth_policy, &form_manager));
1336 form_manager.FetchMatchingLoginsFromPasswordStore(auth_policy); 1326 form_manager.FetchMatchingLoginsFromPasswordStore(auth_policy);
1337 1327
1338 // Suddenly, the frame and its driver disappear. 1328 // Suddenly, the frame and its driver disappear.
1339 client_with_store.KillDriver(); 1329 client_with_store.KillDriver();
1340 1330
1341 std::vector<PasswordForm*> results; 1331 ScopedVector<PasswordForm> simulated_results;
1342 results.push_back(form.release()); 1332 simulated_results.push_back(form.release());
1343 form_manager.OnGetPasswordStoreResults(results); 1333 form_manager.OnGetPasswordStoreResults(simulated_results.Pass());
1344 } 1334 }
1345 1335
1346 } // namespace password_manager 1336 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698