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

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

Issue 1548203002: Convert Pass()→std::move() in //components/[n-z]* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix bad headers Created 4 years, 12 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 "components/password_manager/core/browser/password_form_manager.h"
6
5 #include <map> 7 #include <map>
8 #include <utility>
6 9
7 #include "base/macros.h" 10 #include "base/macros.h"
8 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
9 #include "base/prefs/pref_registry_simple.h" 12 #include "base/prefs/pref_registry_simple.h"
10 #include "base/prefs/pref_service.h" 13 #include "base/prefs/pref_service.h"
11 #include "base/prefs/testing_pref_service.h" 14 #include "base/prefs/testing_pref_service.h"
12 #include "base/run_loop.h" 15 #include "base/run_loop.h"
13 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
14 #include "base/test/histogram_tester.h" 17 #include "base/test/histogram_tester.h"
15 #include "build/build_config.h" 18 #include "build/build_config.h"
16 #include "components/autofill/core/browser/autofill_manager.h" 19 #include "components/autofill/core/browser/autofill_manager.h"
17 #include "components/autofill/core/browser/test_autofill_client.h" 20 #include "components/autofill/core/browser/test_autofill_client.h"
18 #include "components/autofill/core/browser/test_autofill_driver.h" 21 #include "components/autofill/core/browser/test_autofill_driver.h"
19 #include "components/autofill/core/browser/test_personal_data_manager.h" 22 #include "components/autofill/core/browser/test_personal_data_manager.h"
20 #include "components/autofill/core/common/autofill_pref_names.h" 23 #include "components/autofill/core/common/autofill_pref_names.h"
21 #include "components/autofill/core/common/password_form.h" 24 #include "components/autofill/core/common/password_form.h"
22 #include "components/password_manager/core/browser/credentials_filter.h" 25 #include "components/password_manager/core/browser/credentials_filter.h"
23 #include "components/password_manager/core/browser/mock_password_store.h" 26 #include "components/password_manager/core/browser/mock_password_store.h"
24 #include "components/password_manager/core/browser/password_form_manager.h"
25 #include "components/password_manager/core/browser/password_manager.h" 27 #include "components/password_manager/core/browser/password_manager.h"
26 #include "components/password_manager/core/browser/password_manager_driver.h" 28 #include "components/password_manager/core/browser/password_manager_driver.h"
27 #include "components/password_manager/core/browser/password_manager_metrics_util .h" 29 #include "components/password_manager/core/browser/password_manager_metrics_util .h"
28 #include "components/password_manager/core/browser/password_manager_test_utils.h " 30 #include "components/password_manager/core/browser/password_manager_test_utils.h "
29 #include "components/password_manager/core/browser/password_store.h" 31 #include "components/password_manager/core/browser/password_store.h"
30 #include "components/password_manager/core/browser/statistics_table.h" 32 #include "components/password_manager/core/browser/statistics_table.h"
31 #include "components/password_manager/core/browser/stub_password_manager_client. h" 33 #include "components/password_manager/core/browser/stub_password_manager_client. h"
32 #include "components/password_manager/core/browser/stub_password_manager_driver. h" 34 #include "components/password_manager/core/browser/stub_password_manager_driver. h"
33 #include "components/password_manager/core/common/password_manager_pref_names.h" 35 #include "components/password_manager/core/common/password_manager_pref_names.h"
34 #include "testing/gmock/include/gmock/gmock.h" 36 #include "testing/gmock/include/gmock/gmock.h"
(...skipping 14 matching lines...) Expand all
49 51
50 namespace { 52 namespace {
51 53
52 // Invokes the password store consumer with a copy of all forms. 54 // Invokes the password store consumer with a copy of all forms.
53 ACTION_P4(InvokeConsumer, form1, form2, form3, form4) { 55 ACTION_P4(InvokeConsumer, form1, form2, form3, form4) {
54 ScopedVector<PasswordForm> result; 56 ScopedVector<PasswordForm> result;
55 result.push_back(make_scoped_ptr(new PasswordForm(form1))); 57 result.push_back(make_scoped_ptr(new PasswordForm(form1)));
56 result.push_back(make_scoped_ptr(new PasswordForm(form2))); 58 result.push_back(make_scoped_ptr(new PasswordForm(form2)));
57 result.push_back(make_scoped_ptr(new PasswordForm(form3))); 59 result.push_back(make_scoped_ptr(new PasswordForm(form3)));
58 result.push_back(make_scoped_ptr(new PasswordForm(form4))); 60 result.push_back(make_scoped_ptr(new PasswordForm(form4)));
59 arg0->OnGetPasswordStoreResults(result.Pass()); 61 arg0->OnGetPasswordStoreResults(std::move(result));
60 } 62 }
61 63
62 MATCHER_P(CheckUsername, username_value, "Username incorrect") { 64 MATCHER_P(CheckUsername, username_value, "Username incorrect") {
63 return arg.username_value == username_value; 65 return arg.username_value == username_value;
64 } 66 }
65 67
66 MATCHER_P2(CheckUploadFormStructure, 68 MATCHER_P2(CheckUploadFormStructure,
67 form_signature, 69 form_signature,
68 expected_types, 70 expected_types,
69 "Upload form structure is incorrect") { 71 "Upload form structure is incorrect") {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 133
132 class MockPasswordManagerDriver : public StubPasswordManagerDriver { 134 class MockPasswordManagerDriver : public StubPasswordManagerDriver {
133 public: 135 public:
134 MockPasswordManagerDriver() 136 MockPasswordManagerDriver()
135 : mock_autofill_manager_(&test_autofill_driver_, 137 : mock_autofill_manager_(&test_autofill_driver_,
136 &test_autofill_client_, 138 &test_autofill_client_,
137 &test_personal_data_manager_) { 139 &test_personal_data_manager_) {
138 scoped_ptr<TestingPrefServiceSimple> prefs(new TestingPrefServiceSimple()); 140 scoped_ptr<TestingPrefServiceSimple> prefs(new TestingPrefServiceSimple());
139 prefs->registry()->RegisterBooleanPref(autofill::prefs::kAutofillEnabled, 141 prefs->registry()->RegisterBooleanPref(autofill::prefs::kAutofillEnabled,
140 true); 142 true);
141 test_autofill_client_.SetPrefs(prefs.Pass()); 143 test_autofill_client_.SetPrefs(std::move(prefs));
142 mock_autofill_download_manager_ = new MockAutofillDownloadManager( 144 mock_autofill_download_manager_ = new MockAutofillDownloadManager(
143 &test_autofill_driver_, &mock_autofill_manager_); 145 &test_autofill_driver_, &mock_autofill_manager_);
144 // AutofillManager takes ownership of |mock_autofill_download_manager_|. 146 // AutofillManager takes ownership of |mock_autofill_download_manager_|.
145 mock_autofill_manager_.SetDownloadManager(mock_autofill_download_manager_); 147 mock_autofill_manager_.SetDownloadManager(mock_autofill_download_manager_);
146 } 148 }
147 149
148 ~MockPasswordManagerDriver() {} 150 ~MockPasswordManagerDriver() {}
149 151
150 MOCK_METHOD1(FillPasswordForm, void(const autofill::PasswordFormFillData&)); 152 MOCK_METHOD1(FillPasswordForm, void(const autofill::PasswordFormFillData&));
151 MOCK_METHOD1(AllowPasswordGenerationForForm, 153 MOCK_METHOD1(AllowPasswordGenerationForForm,
(...skipping 21 matching lines...) Expand all
173 MOCK_CONST_METHOD1(FilterResultsPtr, 175 MOCK_CONST_METHOD1(FilterResultsPtr,
174 void(ScopedVector<autofill::PasswordForm>* results)); 176 void(ScopedVector<autofill::PasswordForm>* results));
175 177
176 // This method is not relevant here. 178 // This method is not relevant here.
177 MOCK_CONST_METHOD1(ShouldSave, bool(const autofill::PasswordForm& form)); 179 MOCK_CONST_METHOD1(ShouldSave, bool(const autofill::PasswordForm& form));
178 180
179 // GMock cannot handle move-only arguments. 181 // GMock cannot handle move-only arguments.
180 ScopedVector<autofill::PasswordForm> FilterResults( 182 ScopedVector<autofill::PasswordForm> FilterResults(
181 ScopedVector<autofill::PasswordForm> results) const override { 183 ScopedVector<autofill::PasswordForm> results) const override {
182 FilterResultsPtr(&results); 184 FilterResultsPtr(&results);
183 return results.Pass(); 185 return results;
184 } 186 }
185 }; 187 };
186 188
187 class TestPasswordManagerClient : public StubPasswordManagerClient { 189 class TestPasswordManagerClient : public StubPasswordManagerClient {
188 public: 190 public:
189 explicit TestPasswordManagerClient(PasswordStore* password_store) 191 explicit TestPasswordManagerClient(PasswordStore* password_store)
190 : password_store_(password_store), 192 : password_store_(password_store),
191 driver_(new NiceMock<MockPasswordManagerDriver>), 193 driver_(new NiceMock<MockPasswordManagerDriver>),
192 is_update_password_ui_enabled_(false), 194 is_update_password_ui_enabled_(false),
193 filter_all_results_(false) { 195 filter_all_results_(false) {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 return; 328 return;
327 } 329 }
328 330
329 ScopedVector<PasswordForm> result_form; 331 ScopedVector<PasswordForm> result_form;
330 if (result & RESULT_SAVED_MATCH) { 332 if (result & RESULT_SAVED_MATCH) {
331 result_form.push_back(new PasswordForm(saved_match_)); 333 result_form.push_back(new PasswordForm(saved_match_));
332 } 334 }
333 if (result & RESULT_PSL_MATCH) { 335 if (result & RESULT_PSL_MATCH) {
334 result_form.push_back(new PasswordForm(psl_saved_match_)); 336 result_form.push_back(new PasswordForm(psl_saved_match_));
335 } 337 }
336 p->OnGetPasswordStoreResults(result_form.Pass()); 338 p->OnGetPasswordStoreResults(std::move(result_form));
337 } 339 }
338 340
339 // Save saved_match() for observed_form() where |observed_form_data|, 341 // Save saved_match() for observed_form() where |observed_form_data|,
340 // |times_used|, and |status| are used to overwrite the default values for 342 // |times_used|, and |status| are used to overwrite the default values for
341 // observed_form(). |field_type| is the upload that we expect from saving, 343 // observed_form(). |field_type| is the upload that we expect from saving,
342 // with nullptr meaning no upload expected. 344 // with nullptr meaning no upload expected.
343 void AccountCreationUploadTest(const autofill::FormData& observed_form_data, 345 void AccountCreationUploadTest(const autofill::FormData& observed_form_data,
344 int times_used, 346 int times_used,
345 PasswordForm::GenerationUploadStatus status, 347 PasswordForm::GenerationUploadStatus status,
346 const autofill::ServerFieldType* field_type) { 348 const autofill::ServerFieldType* field_type) {
(...skipping 15 matching lines...) Expand all
362 form_to_save.password_value = result[0]->password_value; 364 form_to_save.password_value = result[0]->password_value;
363 365
364 // When we're voting for an account creation form, we should also vote 366 // When we're voting for an account creation form, we should also vote
365 // for its username field. 367 // for its username field.
366 base::string16 username_vote = 368 base::string16 username_vote =
367 (field_type && *field_type == autofill::ACCOUNT_CREATION_PASSWORD) 369 (field_type && *field_type == autofill::ACCOUNT_CREATION_PASSWORD)
368 ? result[0]->username_element 370 ? result[0]->username_element
369 : base::string16(); 371 : base::string16();
370 372
371 form_manager.SimulateFetchMatchingLoginsFromPasswordStore(); 373 form_manager.SimulateFetchMatchingLoginsFromPasswordStore();
372 form_manager.OnGetPasswordStoreResults(result.Pass()); 374 form_manager.OnGetPasswordStoreResults(std::move(result));
373 std::string expected_login_signature; 375 std::string expected_login_signature;
374 autofill::FormStructure observed_structure(observed_form_data); 376 autofill::FormStructure observed_structure(observed_form_data);
375 autofill::FormStructure pending_structure(saved_match()->form_data); 377 autofill::FormStructure pending_structure(saved_match()->form_data);
376 if (observed_structure.FormSignature() != 378 if (observed_structure.FormSignature() !=
377 pending_structure.FormSignature() && 379 pending_structure.FormSignature() &&
378 times_used == 0) { 380 times_used == 0) {
379 expected_login_signature = observed_structure.FormSignature(); 381 expected_login_signature = observed_structure.FormSignature();
380 } 382 }
381 autofill::ServerFieldTypeSet expected_available_field_types; 383 autofill::ServerFieldTypeSet expected_available_field_types;
382 expected_available_field_types.insert(autofill::USERNAME); 384 expected_available_field_types.insert(autofill::USERNAME);
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 PasswordForm blacklisted_match = *observed_form(); 647 PasswordForm blacklisted_match = *observed_form();
646 blacklisted_match.origin = GURL("http://accounts.google.com/a/LoginAuth1234"); 648 blacklisted_match.origin = GURL("http://accounts.google.com/a/LoginAuth1234");
647 blacklisted_match.blacklisted_by_user = true; 649 blacklisted_match.blacklisted_by_user = true;
648 650
649 ScopedVector<PasswordForm> result; 651 ScopedVector<PasswordForm> result;
650 result.push_back(new PasswordForm(blacklisted_psl)); 652 result.push_back(new PasswordForm(blacklisted_psl));
651 result.push_back(new PasswordForm(blacklisted_not_match)); 653 result.push_back(new PasswordForm(blacklisted_not_match));
652 result.push_back(new PasswordForm(blacklisted_not_match2)); 654 result.push_back(new PasswordForm(blacklisted_not_match2));
653 result.push_back(new PasswordForm(blacklisted_match)); 655 result.push_back(new PasswordForm(blacklisted_match));
654 result.push_back(new PasswordForm(*saved_match())); 656 result.push_back(new PasswordForm(*saved_match()));
655 form_manager.OnGetPasswordStoreResults(result.Pass()); 657 form_manager.OnGetPasswordStoreResults(std::move(result));
656 EXPECT_TRUE(form_manager.IsBlacklisted()); 658 EXPECT_TRUE(form_manager.IsBlacklisted());
657 EXPECT_THAT(form_manager.blacklisted_matches(), 659 EXPECT_THAT(form_manager.blacklisted_matches(),
658 ElementsAre(Pointee(blacklisted_match))); 660 ElementsAre(Pointee(blacklisted_match)));
659 EXPECT_EQ(1u, form_manager.best_matches().size()); 661 EXPECT_EQ(1u, form_manager.best_matches().size());
660 EXPECT_EQ(*saved_match(), *form_manager.preferred_match()); 662 EXPECT_EQ(*saved_match(), *form_manager.preferred_match());
661 } 663 }
662 664
663 TEST_F(PasswordFormManagerTest, AutofillBlacklisted) { 665 TEST_F(PasswordFormManagerTest, AutofillBlacklisted) {
664 // Blacklisted best matches credentials should not be autofilled, but the 666 // Blacklisted best matches credentials should not be autofilled, but the
665 // non-blacklisted should. 667 // non-blacklisted should.
666 PasswordForm saved_form = *observed_form(); 668 PasswordForm saved_form = *observed_form();
667 saved_form.username_value = ASCIIToUTF16("user"); 669 saved_form.username_value = ASCIIToUTF16("user");
668 saved_form.password_value = ASCIIToUTF16("pass"); 670 saved_form.password_value = ASCIIToUTF16("pass");
669 671
670 PasswordForm blacklisted = *observed_form(); 672 PasswordForm blacklisted = *observed_form();
671 blacklisted.blacklisted_by_user = true; 673 blacklisted.blacklisted_by_user = true;
672 blacklisted.username_value.clear(); 674 blacklisted.username_value.clear();
673 675
674 ScopedVector<PasswordForm> result; 676 ScopedVector<PasswordForm> result;
675 result.push_back(new PasswordForm(saved_form)); 677 result.push_back(new PasswordForm(saved_form));
676 result.push_back(new PasswordForm(blacklisted)); 678 result.push_back(new PasswordForm(blacklisted));
677 679
678 form_manager()->SimulateFetchMatchingLoginsFromPasswordStore(); 680 form_manager()->SimulateFetchMatchingLoginsFromPasswordStore();
679 681
680 autofill::PasswordFormFillData fill_data; 682 autofill::PasswordFormFillData fill_data;
681 EXPECT_CALL(*client()->mock_driver(), FillPasswordForm(_)) 683 EXPECT_CALL(*client()->mock_driver(), FillPasswordForm(_))
682 .WillOnce(SaveArg<0>(&fill_data)); 684 .WillOnce(SaveArg<0>(&fill_data));
683 685
684 form_manager()->OnGetPasswordStoreResults(result.Pass()); 686 form_manager()->OnGetPasswordStoreResults(std::move(result));
685 EXPECT_EQ(1u, form_manager()->blacklisted_matches().size()); 687 EXPECT_EQ(1u, form_manager()->blacklisted_matches().size());
686 EXPECT_TRUE(form_manager()->IsBlacklisted()); 688 EXPECT_TRUE(form_manager()->IsBlacklisted());
687 EXPECT_EQ(1u, form_manager()->best_matches().size()); 689 EXPECT_EQ(1u, form_manager()->best_matches().size());
688 EXPECT_TRUE(fill_data.additional_logins.empty()); 690 EXPECT_TRUE(fill_data.additional_logins.empty());
689 } 691 }
690 692
691 // If PSL-matched credentials had been suggested, but the user has overwritten 693 // If PSL-matched credentials had been suggested, but the user has overwritten
692 // the password, the provisionally saved credentials should no longer be 694 // the password, the provisionally saved credentials should no longer be
693 // considered as PSL-matched, so that the exception for not prompting before 695 // considered as PSL-matched, so that the exception for not prompting before
694 // saving PSL-matched credentials should no longer apply. 696 // saving PSL-matched credentials should no longer apply.
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 saved_form.ssl_valid = !kObservedFormSSLValid; 884 saved_form.ssl_valid = !kObservedFormSSLValid;
883 saved_form.username_value = ASCIIToUTF16("test1@gmail.com"); 885 saved_form.username_value = ASCIIToUTF16("test1@gmail.com");
884 ScopedVector<PasswordForm> result; 886 ScopedVector<PasswordForm> result;
885 result.push_back(new PasswordForm(saved_form)); 887 result.push_back(new PasswordForm(saved_form));
886 saved_form.username_value = ASCIIToUTF16("test2@gmail.com"); 888 saved_form.username_value = ASCIIToUTF16("test2@gmail.com");
887 result.push_back(new PasswordForm(saved_form)); 889 result.push_back(new PasswordForm(saved_form));
888 saved_form.username_value = ASCIIToUTF16("test3@gmail.com"); 890 saved_form.username_value = ASCIIToUTF16("test3@gmail.com");
889 saved_form.ssl_valid = kObservedFormSSLValid; 891 saved_form.ssl_valid = kObservedFormSSLValid;
890 result.push_back(new PasswordForm(saved_form)); 892 result.push_back(new PasswordForm(saved_form));
891 form_manager.SimulateFetchMatchingLoginsFromPasswordStore(); 893 form_manager.SimulateFetchMatchingLoginsFromPasswordStore();
892 form_manager.OnGetPasswordStoreResults(result.Pass()); 894 form_manager.OnGetPasswordStoreResults(std::move(result));
893 895
894 // Make sure we don't match a PasswordForm if it was originally saved on 896 // Make sure we don't match a PasswordForm if it was originally saved on
895 // an SSL-valid page and we are now on a page with invalid certificate. 897 // an SSL-valid page and we are now on a page with invalid certificate.
896 EXPECT_EQ(1u, form_manager.best_matches().count(saved_form.username_value)); 898 EXPECT_EQ(1u, form_manager.best_matches().count(saved_form.username_value));
897 EXPECT_EQ(1u, form_manager.best_matches().size()); 899 EXPECT_EQ(1u, form_manager.best_matches().size());
898 } 900 }
899 901
900 TEST_F(PasswordFormManagerTest, TestIgnoreResult_Paths) { 902 TEST_F(PasswordFormManagerTest, TestIgnoreResult_Paths) {
901 PasswordForm observed(*observed_form()); 903 PasswordForm observed(*observed_form());
902 observed.origin = GURL("https://accounts.google.com/a/LoginAuth"); 904 observed.origin = GURL("https://accounts.google.com/a/LoginAuth");
903 observed.action = GURL("https://accounts.google.com/a/Login"); 905 observed.action = GURL("https://accounts.google.com/a/Login");
904 observed.signon_realm = "https://accounts.google.com"; 906 observed.signon_realm = "https://accounts.google.com";
905 907
906 PasswordFormManager form_manager(password_manager(), client(), 908 PasswordFormManager form_manager(password_manager(), client(),
907 client()->driver(), observed, false); 909 client()->driver(), observed, false);
908 910
909 PasswordForm saved_form = observed; 911 PasswordForm saved_form = observed;
910 saved_form.origin = GURL("https://accounts.google.com/a/OtherLoginAuth"); 912 saved_form.origin = GURL("https://accounts.google.com/a/OtherLoginAuth");
911 saved_form.action = GURL("https://accounts.google.com/a/OtherLogin"); 913 saved_form.action = GURL("https://accounts.google.com/a/OtherLogin");
912 ScopedVector<PasswordForm> result; 914 ScopedVector<PasswordForm> result;
913 result.push_back(new PasswordForm(saved_form)); 915 result.push_back(new PasswordForm(saved_form));
914 form_manager.SimulateFetchMatchingLoginsFromPasswordStore(); 916 form_manager.SimulateFetchMatchingLoginsFromPasswordStore();
915 form_manager.OnGetPasswordStoreResults(result.Pass()); 917 form_manager.OnGetPasswordStoreResults(std::move(result));
916 918
917 // Different paths for action / origin are okay. 919 // Different paths for action / origin are okay.
918 EXPECT_FALSE(form_manager.best_matches().empty()); 920 EXPECT_FALSE(form_manager.best_matches().empty());
919 } 921 }
920 922
921 TEST_F(PasswordFormManagerTest, TestIgnoreResult_IgnoredCredentials) { 923 TEST_F(PasswordFormManagerTest, TestIgnoreResult_IgnoredCredentials) {
922 PasswordForm observed(*observed_form()); 924 PasswordForm observed(*observed_form());
923 observed.origin = GURL("https://accounts.google.com/a/LoginAuth"); 925 observed.origin = GURL("https://accounts.google.com/a/LoginAuth");
924 observed.action = GURL("https://accounts.google.com/a/Login"); 926 observed.action = GURL("https://accounts.google.com/a/Login");
925 observed.signon_realm = "https://accounts.google.com"; 927 observed.signon_realm = "https://accounts.google.com";
926 928
927 PasswordFormManager form_manager(password_manager(), client(), 929 PasswordFormManager form_manager(password_manager(), client(),
928 client()->driver(), observed, false); 930 client()->driver(), observed, false);
929 client()->FilterAllResults(); 931 client()->FilterAllResults();
930 932
931 PasswordForm saved_form = observed; 933 PasswordForm saved_form = observed;
932 ScopedVector<PasswordForm> result; 934 ScopedVector<PasswordForm> result;
933 result.push_back(new PasswordForm(saved_form)); 935 result.push_back(new PasswordForm(saved_form));
934 form_manager.SimulateFetchMatchingLoginsFromPasswordStore(); 936 form_manager.SimulateFetchMatchingLoginsFromPasswordStore();
935 form_manager.OnGetPasswordStoreResults(result.Pass()); 937 form_manager.OnGetPasswordStoreResults(std::move(result));
936 938
937 // Results should be ignored if the client requests it. 939 // Results should be ignored if the client requests it.
938 EXPECT_TRUE(form_manager.best_matches().empty()); 940 EXPECT_TRUE(form_manager.best_matches().empty());
939 } 941 }
940 942
941 TEST_F(PasswordFormManagerTest, TestEmptyAction) { 943 TEST_F(PasswordFormManagerTest, TestEmptyAction) {
942 saved_match()->action = GURL(); 944 saved_match()->action = GURL();
943 SimulateMatchingPhase(form_manager(), RESULT_SAVED_MATCH); 945 SimulateMatchingPhase(form_manager(), RESULT_SAVED_MATCH);
944 // User logs in with the autofilled username / password from saved_match. 946 // User logs in with the autofilled username / password from saved_match.
945 PasswordForm login = *observed_form(); 947 PasswordForm login = *observed_form();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 990
989 TEST_F(PasswordFormManagerTest, TestAlternateUsername_NoChange) { 991 TEST_F(PasswordFormManagerTest, TestAlternateUsername_NoChange) {
990 EXPECT_CALL(*client()->mock_driver(), AllowPasswordGenerationForForm(_)); 992 EXPECT_CALL(*client()->mock_driver(), AllowPasswordGenerationForForm(_));
991 993
992 PasswordForm saved_form = *saved_match(); 994 PasswordForm saved_form = *saved_match();
993 ASSERT_FALSE(saved_form.other_possible_usernames.empty()); 995 ASSERT_FALSE(saved_form.other_possible_usernames.empty());
994 996
995 ScopedVector<PasswordForm> result; 997 ScopedVector<PasswordForm> result;
996 result.push_back(new PasswordForm(saved_form)); 998 result.push_back(new PasswordForm(saved_form));
997 form_manager()->SimulateFetchMatchingLoginsFromPasswordStore(); 999 form_manager()->SimulateFetchMatchingLoginsFromPasswordStore();
998 form_manager()->OnGetPasswordStoreResults(result.Pass()); 1000 form_manager()->OnGetPasswordStoreResults(std::move(result));
999 1001
1000 // The saved match has the right username already. 1002 // The saved match has the right username already.
1001 PasswordForm login(*observed_form()); 1003 PasswordForm login(*observed_form());
1002 login.preferred = true; 1004 login.preferred = true;
1003 login.username_value = saved_match()->username_value; 1005 login.username_value = saved_match()->username_value;
1004 login.password_value = saved_match()->password_value; 1006 login.password_value = saved_match()->password_value;
1005 1007
1006 form_manager()->ProvisionallySave( 1008 form_manager()->ProvisionallySave(
1007 login, PasswordFormManager::ALLOW_OTHER_POSSIBLE_USERNAMES); 1009 login, PasswordFormManager::ALLOW_OTHER_POSSIBLE_USERNAMES);
1008 1010
(...skipping 16 matching lines...) Expand all
1025 // This time use an alternate username. 1027 // This time use an alternate username.
1026 1028
1027 EXPECT_CALL(*client()->mock_driver(), AllowPasswordGenerationForForm(_)); 1029 EXPECT_CALL(*client()->mock_driver(), AllowPasswordGenerationForForm(_));
1028 1030
1029 PasswordForm saved_form = *saved_match(); 1031 PasswordForm saved_form = *saved_match();
1030 ASSERT_FALSE(saved_form.other_possible_usernames.empty()); 1032 ASSERT_FALSE(saved_form.other_possible_usernames.empty());
1031 1033
1032 ScopedVector<PasswordForm> result; 1034 ScopedVector<PasswordForm> result;
1033 result.push_back(new PasswordForm(saved_form)); 1035 result.push_back(new PasswordForm(saved_form));
1034 form_manager()->SimulateFetchMatchingLoginsFromPasswordStore(); 1036 form_manager()->SimulateFetchMatchingLoginsFromPasswordStore();
1035 form_manager()->OnGetPasswordStoreResults(result.Pass()); 1037 form_manager()->OnGetPasswordStoreResults(std::move(result));
1036 1038
1037 // The saved match has the right username already. 1039 // The saved match has the right username already.
1038 PasswordForm login(*observed_form()); 1040 PasswordForm login(*observed_form());
1039 login.preferred = true; 1041 login.preferred = true;
1040 login.username_value = saved_match()->other_possible_usernames[0]; 1042 login.username_value = saved_match()->other_possible_usernames[0];
1041 login.password_value = saved_match()->password_value; 1043 login.password_value = saved_match()->password_value;
1042 1044
1043 form_manager()->ProvisionallySave( 1045 form_manager()->ProvisionallySave(
1044 login, PasswordFormManager::ALLOW_OTHER_POSSIBLE_USERNAMES); 1046 login, PasswordFormManager::ALLOW_OTHER_POSSIBLE_USERNAMES);
1045 1047
(...skipping 28 matching lines...) Expand all
1074 1076
1075 TEST_F(PasswordFormManagerTest, TestSendNotBlacklistedMessage_Credentials) { 1077 TEST_F(PasswordFormManagerTest, TestSendNotBlacklistedMessage_Credentials) {
1076 // Signing up on a previously visited site. Credentials are found in the 1078 // Signing up on a previously visited site. Credentials are found in the
1077 // password store, and are not blacklisted. AllowPasswordGenerationForForm 1079 // password store, and are not blacklisted. AllowPasswordGenerationForForm
1078 // should be called to send the "not blacklisted" message. 1080 // should be called to send the "not blacklisted" message.
1079 EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_)) 1081 EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_))
1080 .Times(1); 1082 .Times(1);
1081 form_manager()->SimulateFetchMatchingLoginsFromPasswordStore(); 1083 form_manager()->SimulateFetchMatchingLoginsFromPasswordStore();
1082 ScopedVector<PasswordForm> simulated_results; 1084 ScopedVector<PasswordForm> simulated_results;
1083 simulated_results.push_back(CreateSavedMatch(false)); 1085 simulated_results.push_back(CreateSavedMatch(false));
1084 form_manager()->OnGetPasswordStoreResults(simulated_results.Pass()); 1086 form_manager()->OnGetPasswordStoreResults(std::move(simulated_results));
1085 } 1087 }
1086 1088
1087 TEST_F(PasswordFormManagerTest, 1089 TEST_F(PasswordFormManagerTest,
1088 TestSendNotBlacklistedMessage_DroppedCredentials) { 1090 TestSendNotBlacklistedMessage_DroppedCredentials) {
1089 // There are cases, such as when a form is explicitly for creating a new 1091 // There are cases, such as when a form is explicitly for creating a new
1090 // password, where we may ignore saved credentials. Make sure that we still 1092 // password, where we may ignore saved credentials. Make sure that we still
1091 // allow generation in that case. 1093 // allow generation in that case.
1092 PasswordForm signup_form(*observed_form()); 1094 PasswordForm signup_form(*observed_form());
1093 signup_form.new_password_element = base::ASCIIToUTF16("new_password_field"); 1095 signup_form.new_password_element = base::ASCIIToUTF16("new_password_field");
1094 1096
1095 PasswordFormManager form_manager(password_manager(), client(), 1097 PasswordFormManager form_manager(password_manager(), client(),
1096 client()->driver(), signup_form, false); 1098 client()->driver(), signup_form, false);
1097 EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_)) 1099 EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_))
1098 .Times(1); 1100 .Times(1);
1099 form_manager.SimulateFetchMatchingLoginsFromPasswordStore(); 1101 form_manager.SimulateFetchMatchingLoginsFromPasswordStore();
1100 ScopedVector<PasswordForm> simulated_results; 1102 ScopedVector<PasswordForm> simulated_results;
1101 simulated_results.push_back(CreateSavedMatch(false)); 1103 simulated_results.push_back(CreateSavedMatch(false));
1102 form_manager.OnGetPasswordStoreResults(simulated_results.Pass()); 1104 form_manager.OnGetPasswordStoreResults(std::move(simulated_results));
1103 } 1105 }
1104 1106
1105 TEST_F(PasswordFormManagerTest, 1107 TEST_F(PasswordFormManagerTest,
1106 TestSendNotBlacklistedMessage_BlacklistedCredentials) { 1108 TestSendNotBlacklistedMessage_BlacklistedCredentials) {
1107 // Signing up on a previously visited site. Credentials are found in the 1109 // Signing up on a previously visited site. Credentials are found in the
1108 // password store, but they are blacklisted. AllowPasswordGenerationForForm 1110 // password store, but they are blacklisted. AllowPasswordGenerationForForm
1109 // is still called. 1111 // is still called.
1110 EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_)); 1112 EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_));
1111 form_manager()->SimulateFetchMatchingLoginsFromPasswordStore(); 1113 form_manager()->SimulateFetchMatchingLoginsFromPasswordStore();
1112 ScopedVector<PasswordForm> simulated_results; 1114 ScopedVector<PasswordForm> simulated_results;
1113 simulated_results.push_back(CreateSavedMatch(true)); 1115 simulated_results.push_back(CreateSavedMatch(true));
1114 form_manager()->OnGetPasswordStoreResults(simulated_results.Pass()); 1116 form_manager()->OnGetPasswordStoreResults(std::move(simulated_results));
1115 } 1117 }
1116 1118
1117 TEST_F(PasswordFormManagerTest, TestForceInclusionOfGeneratedPasswords_Match) { 1119 TEST_F(PasswordFormManagerTest, TestForceInclusionOfGeneratedPasswords_Match) {
1118 // Simulate having two matches for this origin, one of which was from a form 1120 // Simulate having two matches for this origin, one of which was from a form
1119 // with different HTML tags for elements. Because of scoring differences, 1121 // with different HTML tags for elements. Because of scoring differences,
1120 // only the first form will be sent to Autofill(). 1122 // only the first form will be sent to Autofill().
1121 EXPECT_CALL(*client()->mock_driver(), AllowPasswordGenerationForForm(_)); 1123 EXPECT_CALL(*client()->mock_driver(), AllowPasswordGenerationForForm(_));
1122 1124
1123 ScopedVector<PasswordForm> simulated_results; 1125 ScopedVector<PasswordForm> simulated_results;
1124 simulated_results.push_back(CreateSavedMatch(false)); 1126 simulated_results.push_back(CreateSavedMatch(false));
1125 simulated_results.push_back(CreateSavedMatch(false)); 1127 simulated_results.push_back(CreateSavedMatch(false));
1126 simulated_results[1]->username_value = ASCIIToUTF16("other@gmail.com"); 1128 simulated_results[1]->username_value = ASCIIToUTF16("other@gmail.com");
1127 simulated_results[1]->password_element = ASCIIToUTF16("signup_password"); 1129 simulated_results[1]->password_element = ASCIIToUTF16("signup_password");
1128 simulated_results[1]->username_element = ASCIIToUTF16("signup_username"); 1130 simulated_results[1]->username_element = ASCIIToUTF16("signup_username");
1129 form_manager()->SimulateFetchMatchingLoginsFromPasswordStore(); 1131 form_manager()->SimulateFetchMatchingLoginsFromPasswordStore();
1130 1132
1131 autofill::PasswordFormFillData fill_data; 1133 autofill::PasswordFormFillData fill_data;
1132 EXPECT_CALL(*client()->mock_driver(), FillPasswordForm(_)) 1134 EXPECT_CALL(*client()->mock_driver(), FillPasswordForm(_))
1133 .WillOnce(SaveArg<0>(&fill_data)); 1135 .WillOnce(SaveArg<0>(&fill_data));
1134 1136
1135 form_manager()->OnGetPasswordStoreResults(simulated_results.Pass()); 1137 form_manager()->OnGetPasswordStoreResults(std::move(simulated_results));
1136 EXPECT_EQ(1u, form_manager()->best_matches().size()); 1138 EXPECT_EQ(1u, form_manager()->best_matches().size());
1137 EXPECT_TRUE(fill_data.additional_logins.empty()); 1139 EXPECT_TRUE(fill_data.additional_logins.empty());
1138 } 1140 }
1139 1141
1140 TEST_F(PasswordFormManagerTest, 1142 TEST_F(PasswordFormManagerTest,
1141 TestForceInclusionOfGeneratedPasswords_NoMatch) { 1143 TestForceInclusionOfGeneratedPasswords_NoMatch) {
1142 // Same thing, except this time the credentials that don't match quite as 1144 // Same thing, except this time the credentials that don't match quite as
1143 // well are generated. They should now be sent to Autofill(). 1145 // well are generated. They should now be sent to Autofill().
1144 EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_)); 1146 EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_));
1145 1147
1146 ScopedVector<PasswordForm> simulated_results; 1148 ScopedVector<PasswordForm> simulated_results;
1147 simulated_results.push_back(CreateSavedMatch(false)); 1149 simulated_results.push_back(CreateSavedMatch(false));
1148 simulated_results.push_back(CreateSavedMatch(false)); 1150 simulated_results.push_back(CreateSavedMatch(false));
1149 simulated_results[0]->username_value = ASCIIToUTF16("other@gmail.com"); 1151 simulated_results[0]->username_value = ASCIIToUTF16("other@gmail.com");
1150 simulated_results[0]->password_element = ASCIIToUTF16("signup_password"); 1152 simulated_results[0]->password_element = ASCIIToUTF16("signup_password");
1151 simulated_results[0]->username_element = ASCIIToUTF16("signup_username"); 1153 simulated_results[0]->username_element = ASCIIToUTF16("signup_username");
1152 simulated_results[0]->type = PasswordForm::TYPE_GENERATED; 1154 simulated_results[0]->type = PasswordForm::TYPE_GENERATED;
1153 form_manager()->SimulateFetchMatchingLoginsFromPasswordStore(); 1155 form_manager()->SimulateFetchMatchingLoginsFromPasswordStore();
1154 1156
1155 autofill::PasswordFormFillData fill_data; 1157 autofill::PasswordFormFillData fill_data;
1156 EXPECT_CALL(*client()->mock_driver(), FillPasswordForm(_)) 1158 EXPECT_CALL(*client()->mock_driver(), FillPasswordForm(_))
1157 .WillOnce(SaveArg<0>(&fill_data)); 1159 .WillOnce(SaveArg<0>(&fill_data));
1158 1160
1159 form_manager()->OnGetPasswordStoreResults(simulated_results.Pass()); 1161 form_manager()->OnGetPasswordStoreResults(std::move(simulated_results));
1160 EXPECT_EQ(2u, form_manager()->best_matches().size()); 1162 EXPECT_EQ(2u, form_manager()->best_matches().size());
1161 EXPECT_EQ(1u, fill_data.additional_logins.size()); 1163 EXPECT_EQ(1u, fill_data.additional_logins.size());
1162 } 1164 }
1163 1165
1164 TEST_F(PasswordFormManagerTest, TestSanitizePossibleUsernames) { 1166 TEST_F(PasswordFormManagerTest, TestSanitizePossibleUsernames) {
1165 const base::string16 kUsernameOther = ASCIIToUTF16("other username"); 1167 const base::string16 kUsernameOther = ASCIIToUTF16("other username");
1166 1168
1167 form_manager()->SimulateFetchMatchingLoginsFromPasswordStore(); 1169 form_manager()->SimulateFetchMatchingLoginsFromPasswordStore();
1168 form_manager()->OnGetPasswordStoreResults(ScopedVector<PasswordForm>()); 1170 form_manager()->OnGetPasswordStoreResults(ScopedVector<PasswordForm>());
1169 1171
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1264 complete_form.action = encountered_form.action; 1266 complete_form.action = encountered_form.action;
1265 complete_form.password_element = encountered_form.password_element; 1267 complete_form.password_element = encountered_form.password_element;
1266 complete_form.username_element = encountered_form.username_element; 1268 complete_form.username_element = encountered_form.username_element;
1267 complete_form.submit_element = encountered_form.submit_element; 1269 complete_form.submit_element = encountered_form.submit_element;
1268 1270
1269 PasswordForm obsolete_form(*incomplete_form); 1271 PasswordForm obsolete_form(*incomplete_form);
1270 obsolete_form.action = encountered_form.action; 1272 obsolete_form.action = encountered_form.action;
1271 1273
1272 // Feed the incomplete credentials to the manager. 1274 // Feed the incomplete credentials to the manager.
1273 ScopedVector<PasswordForm> simulated_results; 1275 ScopedVector<PasswordForm> simulated_results;
1274 simulated_results.push_back(incomplete_form.Pass()); 1276 simulated_results.push_back(std::move(incomplete_form));
1275 form_manager.OnGetPasswordStoreResults(simulated_results.Pass()); 1277 form_manager.OnGetPasswordStoreResults(std::move(simulated_results));
1276 1278
1277 form_manager.ProvisionallySave( 1279 form_manager.ProvisionallySave(
1278 complete_form, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); 1280 complete_form, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES);
1279 // By now that form has been used once. 1281 // By now that form has been used once.
1280 complete_form.times_used = 1; 1282 complete_form.times_used = 1;
1281 obsolete_form.times_used = 1; 1283 obsolete_form.times_used = 1;
1282 1284
1283 // Check that PasswordStore receives an update request with the complete form. 1285 // Check that PasswordStore receives an update request with the complete form.
1284 EXPECT_CALL(*mock_store(), 1286 EXPECT_CALL(*mock_store(),
1285 UpdateLoginWithPrimaryKey(complete_form, obsolete_form)); 1287 UpdateLoginWithPrimaryKey(complete_form, obsolete_form));
(...skipping 15 matching lines...) Expand all
1301 simulated_results[1]->origin = 1303 simulated_results[1]->origin =
1302 GURL("http://accounts.google.com/a/ServiceLoginAuth2"); 1304 GURL("http://accounts.google.com/a/ServiceLoginAuth2");
1303 simulated_results[1]->action = 1305 simulated_results[1]->action =
1304 GURL("http://accounts.google.com/a/ServiceLogin2"); 1306 GURL("http://accounts.google.com/a/ServiceLogin2");
1305 form_manager()->SimulateFetchMatchingLoginsFromPasswordStore(); 1307 form_manager()->SimulateFetchMatchingLoginsFromPasswordStore();
1306 1308
1307 autofill::PasswordFormFillData fill_data; 1309 autofill::PasswordFormFillData fill_data;
1308 EXPECT_CALL(*client()->mock_driver(), FillPasswordForm(_)) 1310 EXPECT_CALL(*client()->mock_driver(), FillPasswordForm(_))
1309 .WillOnce(SaveArg<0>(&fill_data)); 1311 .WillOnce(SaveArg<0>(&fill_data));
1310 1312
1311 form_manager()->OnGetPasswordStoreResults(simulated_results.Pass()); 1313 form_manager()->OnGetPasswordStoreResults(std::move(simulated_results));
1312 EXPECT_TRUE(fill_data.additional_logins.empty()); 1314 EXPECT_TRUE(fill_data.additional_logins.empty());
1313 EXPECT_EQ(1u, form_manager()->best_matches().size()); 1315 EXPECT_EQ(1u, form_manager()->best_matches().size());
1314 EXPECT_TRUE( 1316 EXPECT_TRUE(
1315 !form_manager()->best_matches().begin()->second->is_public_suffix_match); 1317 !form_manager()->best_matches().begin()->second->is_public_suffix_match);
1316 } 1318 }
1317 1319
1318 TEST_F(PasswordFormManagerTest, AndroidCredentialsAreAutofilled) { 1320 TEST_F(PasswordFormManagerTest, AndroidCredentialsAreAutofilled) {
1319 EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_)); 1321 EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_));
1320 1322
1321 // Although Android-based credentials are treated similarly to PSL-matched 1323 // Although Android-based credentials are treated similarly to PSL-matched
1322 // credentials in most respects, they should be autofilled as opposed to be 1324 // credentials in most respects, they should be autofilled as opposed to be
1323 // filled on username-select. 1325 // filled on username-select.
1324 ScopedVector<PasswordForm> simulated_results; 1326 ScopedVector<PasswordForm> simulated_results;
1325 simulated_results.push_back(new PasswordForm()); 1327 simulated_results.push_back(new PasswordForm());
1326 simulated_results[0]->signon_realm = "android://hash@com.google.android"; 1328 simulated_results[0]->signon_realm = "android://hash@com.google.android";
1327 simulated_results[0]->origin = observed_form()->origin; 1329 simulated_results[0]->origin = observed_form()->origin;
1328 simulated_results[0]->username_value = saved_match()->username_value; 1330 simulated_results[0]->username_value = saved_match()->username_value;
1329 simulated_results[0]->password_value = saved_match()->password_value; 1331 simulated_results[0]->password_value = saved_match()->password_value;
1330 1332
1331 form_manager()->SimulateFetchMatchingLoginsFromPasswordStore(); 1333 form_manager()->SimulateFetchMatchingLoginsFromPasswordStore();
1332 1334
1333 autofill::PasswordFormFillData fill_data; 1335 autofill::PasswordFormFillData fill_data;
1334 EXPECT_CALL(*client()->mock_driver(), FillPasswordForm(_)) 1336 EXPECT_CALL(*client()->mock_driver(), FillPasswordForm(_))
1335 .WillOnce(SaveArg<0>(&fill_data)); 1337 .WillOnce(SaveArg<0>(&fill_data));
1336 1338
1337 form_manager()->OnGetPasswordStoreResults(simulated_results.Pass()); 1339 form_manager()->OnGetPasswordStoreResults(std::move(simulated_results));
1338 EXPECT_TRUE(fill_data.additional_logins.empty()); 1340 EXPECT_TRUE(fill_data.additional_logins.empty());
1339 EXPECT_FALSE(fill_data.wait_for_username); 1341 EXPECT_FALSE(fill_data.wait_for_username);
1340 EXPECT_EQ(1u, form_manager()->best_matches().size()); 1342 EXPECT_EQ(1u, form_manager()->best_matches().size());
1341 } 1343 }
1342 1344
1343 // Credentials saved through Android apps should always be shown in the drop- 1345 // Credentials saved through Android apps should always be shown in the drop-
1344 // down menu, unless there is a better-scoring match with the same username. 1346 // down menu, unless there is a better-scoring match with the same username.
1345 TEST_F(PasswordFormManagerTest, AndroidCredentialsAreProtected) { 1347 TEST_F(PasswordFormManagerTest, AndroidCredentialsAreProtected) {
1346 const char kTestUsername1[] = "test-user@gmail.com"; 1348 const char kTestUsername1[] = "test-user@gmail.com";
1347 const char kTestUsername2[] = "test-other-user@gmail.com"; 1349 const char kTestUsername2[] = "test-other-user@gmail.com";
(...skipping 21 matching lines...) Expand all
1369 simulated_results[2]->password_value = ASCIIToUTF16(kTestAndroidPassword2); 1371 simulated_results[2]->password_value = ASCIIToUTF16(kTestAndroidPassword2);
1370 1372
1371 ScopedVector<PasswordForm> expected_matches; 1373 ScopedVector<PasswordForm> expected_matches;
1372 expected_matches.push_back(new PasswordForm(*simulated_results[0])); 1374 expected_matches.push_back(new PasswordForm(*simulated_results[0]));
1373 expected_matches.push_back(new PasswordForm(*simulated_results[2])); 1375 expected_matches.push_back(new PasswordForm(*simulated_results[2]));
1374 1376
1375 autofill::PasswordFormFillData fill_data; 1377 autofill::PasswordFormFillData fill_data;
1376 EXPECT_CALL(*client()->mock_driver(), FillPasswordForm(_)) 1378 EXPECT_CALL(*client()->mock_driver(), FillPasswordForm(_))
1377 .WillOnce(SaveArg<0>(&fill_data)); 1379 .WillOnce(SaveArg<0>(&fill_data));
1378 form_manager()->SimulateFetchMatchingLoginsFromPasswordStore(); 1380 form_manager()->SimulateFetchMatchingLoginsFromPasswordStore();
1379 form_manager()->OnGetPasswordStoreResults(simulated_results.Pass()); 1381 form_manager()->OnGetPasswordStoreResults(std::move(simulated_results));
1380 1382
1381 EXPECT_FALSE(fill_data.wait_for_username); 1383 EXPECT_FALSE(fill_data.wait_for_username);
1382 EXPECT_EQ(1u, fill_data.additional_logins.size()); 1384 EXPECT_EQ(1u, fill_data.additional_logins.size());
1383 1385
1384 std::vector<PasswordForm*> actual_matches; 1386 std::vector<PasswordForm*> actual_matches;
1385 for (const auto& username_match_pair : form_manager()->best_matches()) 1387 for (const auto& username_match_pair : form_manager()->best_matches())
1386 actual_matches.push_back(username_match_pair.second.get()); 1388 actual_matches.push_back(username_match_pair.second.get());
1387 EXPECT_THAT(actual_matches, 1389 EXPECT_THAT(actual_matches,
1388 UnorderedPasswordFormElementsAre(expected_matches.get())); 1390 UnorderedPasswordFormElementsAre(expected_matches.get()));
1389 } 1391 }
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1509 first.preferred = true; 1511 first.preferred = true;
1510 1512
1511 PasswordForm second(first); 1513 PasswordForm second(first);
1512 second.password_value = ASCIIToUTF16("second"); 1514 second.password_value = ASCIIToUTF16("second");
1513 second.preferred = false; 1515 second.preferred = false;
1514 1516
1515 ScopedVector<PasswordForm> result; 1517 ScopedVector<PasswordForm> result;
1516 result.push_back(new PasswordForm(first)); 1518 result.push_back(new PasswordForm(first));
1517 result.push_back(new PasswordForm(second)); 1519 result.push_back(new PasswordForm(second));
1518 form_manager()->SimulateFetchMatchingLoginsFromPasswordStore(); 1520 form_manager()->SimulateFetchMatchingLoginsFromPasswordStore();
1519 form_manager()->OnGetPasswordStoreResults(result.Pass()); 1521 form_manager()->OnGetPasswordStoreResults(std::move(result));
1520 1522
1521 // We always take the first credential with a particular username, regardless 1523 // We always take the first credential with a particular username, regardless
1522 // of which ones are labeled preferred. 1524 // of which ones are labeled preferred.
1523 EXPECT_EQ(ASCIIToUTF16("first"), 1525 EXPECT_EQ(ASCIIToUTF16("first"),
1524 form_manager()->preferred_match()->password_value); 1526 form_manager()->preferred_match()->password_value);
1525 1527
1526 PasswordForm login(*observed_form()); 1528 PasswordForm login(*observed_form());
1527 login.username_value = saved_match()->username_value; 1529 login.username_value = saved_match()->username_value;
1528 login.password_value = ASCIIToUTF16("third"); 1530 login.password_value = ASCIIToUTF16("third");
1529 login.preferred = true; 1531 login.preferred = true;
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1669 1671
1670 const PasswordStore::AuthorizationPromptPolicy auth_policy = 1672 const PasswordStore::AuthorizationPromptPolicy auth_policy =
1671 PasswordStore::DISALLOW_PROMPT; 1673 PasswordStore::DISALLOW_PROMPT;
1672 EXPECT_CALL(*mock_store(), GetLogins(*form, auth_policy, &form_manager)); 1674 EXPECT_CALL(*mock_store(), GetLogins(*form, auth_policy, &form_manager));
1673 form_manager.FetchDataFromPasswordStore(auth_policy); 1675 form_manager.FetchDataFromPasswordStore(auth_policy);
1674 1676
1675 // Suddenly, the frame and its driver disappear. 1677 // Suddenly, the frame and its driver disappear.
1676 client()->KillDriver(); 1678 client()->KillDriver();
1677 1679
1678 ScopedVector<PasswordForm> simulated_results; 1680 ScopedVector<PasswordForm> simulated_results;
1679 simulated_results.push_back(form.Pass()); 1681 simulated_results.push_back(std::move(form));
1680 form_manager.OnGetPasswordStoreResults(simulated_results.Pass()); 1682 form_manager.OnGetPasswordStoreResults(std::move(simulated_results));
1681 } 1683 }
1682 1684
1683 TEST_F(PasswordFormManagerTest, PreferredMatchIsUpToDate) { 1685 TEST_F(PasswordFormManagerTest, PreferredMatchIsUpToDate) {
1684 // Check that preferred_match() is always a member of best_matches(). 1686 // Check that preferred_match() is always a member of best_matches().
1685 const PasswordStore::AuthorizationPromptPolicy auth_policy = 1687 const PasswordStore::AuthorizationPromptPolicy auth_policy =
1686 PasswordStore::DISALLOW_PROMPT; 1688 PasswordStore::DISALLOW_PROMPT;
1687 EXPECT_CALL(*mock_store(), 1689 EXPECT_CALL(*mock_store(),
1688 GetLogins(*observed_form(), auth_policy, form_manager())); 1690 GetLogins(*observed_form(), auth_policy, form_manager()));
1689 form_manager()->FetchDataFromPasswordStore(auth_policy); 1691 form_manager()->FetchDataFromPasswordStore(auth_policy);
1690 1692
1691 ScopedVector<PasswordForm> simulated_results; 1693 ScopedVector<PasswordForm> simulated_results;
1692 scoped_ptr<PasswordForm> form(new PasswordForm(*observed_form())); 1694 scoped_ptr<PasswordForm> form(new PasswordForm(*observed_form()));
1693 form->username_value = ASCIIToUTF16("username"); 1695 form->username_value = ASCIIToUTF16("username");
1694 form->password_value = ASCIIToUTF16("password1"); 1696 form->password_value = ASCIIToUTF16("password1");
1695 form->preferred = false; 1697 form->preferred = false;
1696 1698
1697 scoped_ptr<PasswordForm> generated_form(new PasswordForm(*form)); 1699 scoped_ptr<PasswordForm> generated_form(new PasswordForm(*form));
1698 generated_form->type = PasswordForm::TYPE_GENERATED; 1700 generated_form->type = PasswordForm::TYPE_GENERATED;
1699 generated_form->password_value = ASCIIToUTF16("password2"); 1701 generated_form->password_value = ASCIIToUTF16("password2");
1700 generated_form->preferred = true; 1702 generated_form->preferred = true;
1701 1703
1702 simulated_results.push_back(generated_form.Pass()); 1704 simulated_results.push_back(std::move(generated_form));
1703 simulated_results.push_back(form.Pass()); 1705 simulated_results.push_back(std::move(form));
1704 1706
1705 form_manager()->OnGetPasswordStoreResults(simulated_results.Pass()); 1707 form_manager()->OnGetPasswordStoreResults(std::move(simulated_results));
1706 EXPECT_EQ(1u, form_manager()->best_matches().size()); 1708 EXPECT_EQ(1u, form_manager()->best_matches().size());
1707 EXPECT_EQ(form_manager()->preferred_match(), 1709 EXPECT_EQ(form_manager()->preferred_match(),
1708 form_manager()->best_matches().begin()->second.get()); 1710 form_manager()->best_matches().begin()->second.get());
1709 // Make sure to access all fields of preferred_match; this way if it was 1711 // Make sure to access all fields of preferred_match; this way if it was
1710 // deleted, ASAN might notice it. 1712 // deleted, ASAN might notice it.
1711 PasswordForm dummy(*form_manager()->preferred_match()); 1713 PasswordForm dummy(*form_manager()->preferred_match());
1712 } 1714 }
1713 1715
1714 TEST_F(PasswordFormManagerTest, 1716 TEST_F(PasswordFormManagerTest,
1715 IsIngnorableChangePasswordForm_MatchingUsernameAndPassword) { 1717 IsIngnorableChangePasswordForm_MatchingUsernameAndPassword) {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1817 client()->driver(), 1819 client()->driver(),
1818 observed_change_password_form, false); 1820 observed_change_password_form, false);
1819 manager_creds.SimulateFetchMatchingLoginsFromPasswordStore(); 1821 manager_creds.SimulateFetchMatchingLoginsFromPasswordStore();
1820 ScopedVector<PasswordForm> simulated_results; 1822 ScopedVector<PasswordForm> simulated_results;
1821 simulated_results.push_back(CreateSavedMatch(false)); 1823 simulated_results.push_back(CreateSavedMatch(false));
1822 1824
1823 autofill::PasswordFormFillData fill_data; 1825 autofill::PasswordFormFillData fill_data;
1824 EXPECT_CALL(*client()->mock_driver(), FillPasswordForm(_)) 1826 EXPECT_CALL(*client()->mock_driver(), FillPasswordForm(_))
1825 .WillOnce(SaveArg<0>(&fill_data)); 1827 .WillOnce(SaveArg<0>(&fill_data));
1826 1828
1827 manager_creds.OnGetPasswordStoreResults(simulated_results.Pass()); 1829 manager_creds.OnGetPasswordStoreResults(std::move(simulated_results));
1828 EXPECT_EQ(1u, manager_creds.best_matches().size()); 1830 EXPECT_EQ(1u, manager_creds.best_matches().size());
1829 EXPECT_EQ(0u, fill_data.additional_logins.size()); 1831 EXPECT_EQ(0u, fill_data.additional_logins.size());
1830 EXPECT_TRUE(fill_data.wait_for_username); 1832 EXPECT_TRUE(fill_data.wait_for_username);
1831 } 1833 }
1832 1834
1833 TEST_F(PasswordFormManagerTest, TestUpdateMethod) { 1835 TEST_F(PasswordFormManagerTest, TestUpdateMethod) {
1834 // Add a new password field to the test form. The PasswordFormManager should 1836 // Add a new password field to the test form. The PasswordFormManager should
1835 // save the password from this field, instead of the current password field. 1837 // save the password from this field, instead of the current password field.
1836 observed_form()->new_password_element = ASCIIToUTF16("NewPasswd"); 1838 observed_form()->new_password_element = ASCIIToUTF16("NewPasswd");
1837 autofill::FormFieldData field; 1839 autofill::FormFieldData field;
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
2045 histogram_tester.ExpectUniqueSample("PasswordManager.StoreReadyWhenWiping", 1, 2047 histogram_tester.ExpectUniqueSample("PasswordManager.StoreReadyWhenWiping", 1,
2046 1); 2048 1);
2047 } 2049 }
2048 2050
2049 TEST_F(PasswordFormManagerTest, RemoveNoUsernameAccounts) { 2051 TEST_F(PasswordFormManagerTest, RemoveNoUsernameAccounts) {
2050 PasswordForm saved_form = *saved_match(); 2052 PasswordForm saved_form = *saved_match();
2051 saved_form.username_value.clear(); 2053 saved_form.username_value.clear();
2052 ScopedVector<PasswordForm> result; 2054 ScopedVector<PasswordForm> result;
2053 result.push_back(new PasswordForm(saved_form)); 2055 result.push_back(new PasswordForm(saved_form));
2054 form_manager()->SimulateFetchMatchingLoginsFromPasswordStore(); 2056 form_manager()->SimulateFetchMatchingLoginsFromPasswordStore();
2055 form_manager()->OnGetPasswordStoreResults(result.Pass()); 2057 form_manager()->OnGetPasswordStoreResults(std::move(result));
2056 2058
2057 PasswordForm submitted_form(*observed_form()); 2059 PasswordForm submitted_form(*observed_form());
2058 submitted_form.preferred = true; 2060 submitted_form.preferred = true;
2059 submitted_form.username_value = saved_match()->username_value; 2061 submitted_form.username_value = saved_match()->username_value;
2060 submitted_form.password_value = saved_match()->password_value; 2062 submitted_form.password_value = saved_match()->password_value;
2061 2063
2062 saved_form.preferred = false; 2064 saved_form.preferred = false;
2063 EXPECT_CALL(*mock_store(), 2065 EXPECT_CALL(*mock_store(),
2064 AddLogin(CheckUsername(saved_match()->username_value))); 2066 AddLogin(CheckUsername(saved_match()->username_value)));
2065 EXPECT_CALL(*mock_store(), RemoveLogin(saved_form)); 2067 EXPECT_CALL(*mock_store(), RemoveLogin(saved_form));
2066 2068
2067 form_manager()->ProvisionallySave( 2069 form_manager()->ProvisionallySave(
2068 submitted_form, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); 2070 submitted_form, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES);
2069 form_manager()->Save(); 2071 form_manager()->Save();
2070 } 2072 }
2071 2073
2072 TEST_F(PasswordFormManagerTest, NotRemovePSLNoUsernameAccounts) { 2074 TEST_F(PasswordFormManagerTest, NotRemovePSLNoUsernameAccounts) {
2073 PasswordForm saved_form = *saved_match(); 2075 PasswordForm saved_form = *saved_match();
2074 saved_form.username_value.clear(); 2076 saved_form.username_value.clear();
2075 saved_form.is_public_suffix_match = true; 2077 saved_form.is_public_suffix_match = true;
2076 ScopedVector<PasswordForm> result; 2078 ScopedVector<PasswordForm> result;
2077 result.push_back(new PasswordForm(saved_form)); 2079 result.push_back(new PasswordForm(saved_form));
2078 form_manager()->SimulateFetchMatchingLoginsFromPasswordStore(); 2080 form_manager()->SimulateFetchMatchingLoginsFromPasswordStore();
2079 form_manager()->OnGetPasswordStoreResults(result.Pass()); 2081 form_manager()->OnGetPasswordStoreResults(std::move(result));
2080 2082
2081 PasswordForm submitted_form(*observed_form()); 2083 PasswordForm submitted_form(*observed_form());
2082 submitted_form.preferred = true; 2084 submitted_form.preferred = true;
2083 submitted_form.username_value = saved_match()->username_value; 2085 submitted_form.username_value = saved_match()->username_value;
2084 submitted_form.password_value = saved_match()->password_value; 2086 submitted_form.password_value = saved_match()->password_value;
2085 2087
2086 EXPECT_CALL(*mock_store(), 2088 EXPECT_CALL(*mock_store(),
2087 AddLogin(CheckUsername(saved_match()->username_value))); 2089 AddLogin(CheckUsername(saved_match()->username_value)));
2088 EXPECT_CALL(*mock_store(), RemoveLogin(_)).Times(0); 2090 EXPECT_CALL(*mock_store(), RemoveLogin(_)).Times(0);
2089 2091
2090 form_manager()->ProvisionallySave( 2092 form_manager()->ProvisionallySave(
2091 submitted_form, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); 2093 submitted_form, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES);
2092 form_manager()->Save(); 2094 form_manager()->Save();
2093 } 2095 }
2094 2096
2095 TEST_F(PasswordFormManagerTest, NotRemoveCredentialsWithUsername) { 2097 TEST_F(PasswordFormManagerTest, NotRemoveCredentialsWithUsername) {
2096 PasswordForm saved_form = *saved_match(); 2098 PasswordForm saved_form = *saved_match();
2097 ASSERT_FALSE(saved_form.username_value.empty()); 2099 ASSERT_FALSE(saved_form.username_value.empty());
2098 ScopedVector<PasswordForm> result; 2100 ScopedVector<PasswordForm> result;
2099 result.push_back(new PasswordForm(saved_form)); 2101 result.push_back(new PasswordForm(saved_form));
2100 form_manager()->SimulateFetchMatchingLoginsFromPasswordStore(); 2102 form_manager()->SimulateFetchMatchingLoginsFromPasswordStore();
2101 form_manager()->OnGetPasswordStoreResults(result.Pass()); 2103 form_manager()->OnGetPasswordStoreResults(std::move(result));
2102 2104
2103 PasswordForm submitted_form(*observed_form()); 2105 PasswordForm submitted_form(*observed_form());
2104 submitted_form.preferred = true; 2106 submitted_form.preferred = true;
2105 base::string16 username = saved_form.username_value + ASCIIToUTF16("1"); 2107 base::string16 username = saved_form.username_value + ASCIIToUTF16("1");
2106 submitted_form.username_value = username; 2108 submitted_form.username_value = username;
2107 submitted_form.password_value = saved_match()->password_value; 2109 submitted_form.password_value = saved_match()->password_value;
2108 2110
2109 EXPECT_CALL(*mock_store(), AddLogin(CheckUsername(username))); 2111 EXPECT_CALL(*mock_store(), AddLogin(CheckUsername(username)));
2110 EXPECT_CALL(*mock_store(), RemoveLogin(_)).Times(0); 2112 EXPECT_CALL(*mock_store(), RemoveLogin(_)).Times(0);
2111 2113
2112 form_manager()->ProvisionallySave( 2114 form_manager()->ProvisionallySave(
2113 submitted_form, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); 2115 submitted_form, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES);
2114 form_manager()->Save(); 2116 form_manager()->Save();
2115 } 2117 }
2116 2118
2117 TEST_F(PasswordFormManagerTest, NotRemoveCredentialsWithDiferrentPassword) { 2119 TEST_F(PasswordFormManagerTest, NotRemoveCredentialsWithDiferrentPassword) {
2118 PasswordForm saved_form = *saved_match(); 2120 PasswordForm saved_form = *saved_match();
2119 saved_form.username_value.clear(); 2121 saved_form.username_value.clear();
2120 ScopedVector<PasswordForm> result; 2122 ScopedVector<PasswordForm> result;
2121 result.push_back(new PasswordForm(saved_form)); 2123 result.push_back(new PasswordForm(saved_form));
2122 form_manager()->SimulateFetchMatchingLoginsFromPasswordStore(); 2124 form_manager()->SimulateFetchMatchingLoginsFromPasswordStore();
2123 form_manager()->OnGetPasswordStoreResults(result.Pass()); 2125 form_manager()->OnGetPasswordStoreResults(std::move(result));
2124 2126
2125 PasswordForm submitted_form(*observed_form()); 2127 PasswordForm submitted_form(*observed_form());
2126 submitted_form.preferred = true; 2128 submitted_form.preferred = true;
2127 submitted_form.username_value = saved_match()->username_value; 2129 submitted_form.username_value = saved_match()->username_value;
2128 submitted_form.password_value = saved_form.password_value + ASCIIToUTF16("1"); 2130 submitted_form.password_value = saved_form.password_value + ASCIIToUTF16("1");
2129 2131
2130 EXPECT_CALL(*mock_store(), 2132 EXPECT_CALL(*mock_store(),
2131 AddLogin(CheckUsername(saved_match()->username_value))); 2133 AddLogin(CheckUsername(saved_match()->username_value)));
2132 EXPECT_CALL(*mock_store(), RemoveLogin(_)).Times(0); 2134 EXPECT_CALL(*mock_store(), RemoveLogin(_)).Times(0);
2133 2135
2134 form_manager()->ProvisionallySave( 2136 form_manager()->ProvisionallySave(
2135 submitted_form, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); 2137 submitted_form, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES);
2136 form_manager()->Save(); 2138 form_manager()->Save();
2137 } 2139 }
2138 2140
2139 TEST_F(PasswordFormManagerTest, SaveNoUsernameEvenIfWithUsernamePresent) { 2141 TEST_F(PasswordFormManagerTest, SaveNoUsernameEvenIfWithUsernamePresent) {
2140 PasswordForm* saved_form = saved_match(); 2142 PasswordForm* saved_form = saved_match();
2141 ASSERT_FALSE(saved_match()->username_value.empty()); 2143 ASSERT_FALSE(saved_match()->username_value.empty());
2142 ScopedVector<PasswordForm> result; 2144 ScopedVector<PasswordForm> result;
2143 result.push_back(new PasswordForm(*saved_form)); 2145 result.push_back(new PasswordForm(*saved_form));
2144 form_manager()->SimulateFetchMatchingLoginsFromPasswordStore(); 2146 form_manager()->SimulateFetchMatchingLoginsFromPasswordStore();
2145 form_manager()->OnGetPasswordStoreResults(result.Pass()); 2147 form_manager()->OnGetPasswordStoreResults(std::move(result));
2146 2148
2147 PasswordForm submitted_form(*observed_form()); 2149 PasswordForm submitted_form(*observed_form());
2148 submitted_form.preferred = true; 2150 submitted_form.preferred = true;
2149 submitted_form.username_value.clear(); 2151 submitted_form.username_value.clear();
2150 2152
2151 EXPECT_CALL(*mock_store(), AddLogin(CheckUsername(base::string16()))); 2153 EXPECT_CALL(*mock_store(), AddLogin(CheckUsername(base::string16())));
2152 EXPECT_CALL(*mock_store(), RemoveLogin(_)).Times(0); 2154 EXPECT_CALL(*mock_store(), RemoveLogin(_)).Times(0);
2153 2155
2154 form_manager()->ProvisionallySave( 2156 form_manager()->ProvisionallySave(
2155 submitted_form, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); 2157 submitted_form, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES);
2156 form_manager()->Save(); 2158 form_manager()->Save();
2157 } 2159 }
2158 2160
2159 TEST_F(PasswordFormManagerTest, NotRemoveOnUpdate) { 2161 TEST_F(PasswordFormManagerTest, NotRemoveOnUpdate) {
2160 ScopedVector<PasswordForm> result; 2162 ScopedVector<PasswordForm> result;
2161 PasswordForm saved_form = *saved_match(); 2163 PasswordForm saved_form = *saved_match();
2162 ASSERT_FALSE(saved_form.username_value.empty()); 2164 ASSERT_FALSE(saved_form.username_value.empty());
2163 result.push_back(new PasswordForm(saved_form)); 2165 result.push_back(new PasswordForm(saved_form));
2164 saved_form.username_value.clear(); 2166 saved_form.username_value.clear();
2165 saved_form.preferred = false; 2167 saved_form.preferred = false;
2166 result.push_back(new PasswordForm(saved_form)); 2168 result.push_back(new PasswordForm(saved_form));
2167 form_manager()->SimulateFetchMatchingLoginsFromPasswordStore(); 2169 form_manager()->SimulateFetchMatchingLoginsFromPasswordStore();
2168 form_manager()->OnGetPasswordStoreResults(result.Pass()); 2170 form_manager()->OnGetPasswordStoreResults(std::move(result));
2169 2171
2170 PasswordForm submitted_form(*observed_form()); 2172 PasswordForm submitted_form(*observed_form());
2171 submitted_form.preferred = true; 2173 submitted_form.preferred = true;
2172 submitted_form.username_value = saved_match()->username_value; 2174 submitted_form.username_value = saved_match()->username_value;
2173 submitted_form.password_value = saved_form.password_value + ASCIIToUTF16("1"); 2175 submitted_form.password_value = saved_form.password_value + ASCIIToUTF16("1");
2174 2176
2175 EXPECT_CALL(*mock_store(), 2177 EXPECT_CALL(*mock_store(),
2176 UpdateLogin(CheckUsername(saved_match()->username_value))); 2178 UpdateLogin(CheckUsername(saved_match()->username_value)));
2177 EXPECT_CALL(*mock_store(), RemoveLogin(_)).Times(0); 2179 EXPECT_CALL(*mock_store(), RemoveLogin(_)).Times(0);
2178 2180
(...skipping 12 matching lines...) Expand all
2191 scoped_ptr<PasswordForm> generated_form(new PasswordForm(*observed_form())); 2193 scoped_ptr<PasswordForm> generated_form(new PasswordForm(*observed_form()));
2192 generated_form->type = PasswordForm::TYPE_GENERATED; 2194 generated_form->type = PasswordForm::TYPE_GENERATED;
2193 generated_form->username_value = ASCIIToUTF16("username"); 2195 generated_form->username_value = ASCIIToUTF16("username");
2194 generated_form->password_value = ASCIIToUTF16("password2"); 2196 generated_form->password_value = ASCIIToUTF16("password2");
2195 generated_form->preferred = true; 2197 generated_form->preferred = true;
2196 2198
2197 PasswordForm submitted_form(*generated_form); 2199 PasswordForm submitted_form(*generated_form);
2198 submitted_form.password_value = ASCIIToUTF16("password3"); 2200 submitted_form.password_value = ASCIIToUTF16("password3");
2199 2201
2200 ScopedVector<PasswordForm> simulated_results; 2202 ScopedVector<PasswordForm> simulated_results;
2201 simulated_results.push_back(generated_form.Pass()); 2203 simulated_results.push_back(std::move(generated_form));
2202 form_manager()->OnGetPasswordStoreResults(simulated_results.Pass()); 2204 form_manager()->OnGetPasswordStoreResults(std::move(simulated_results));
2203 2205
2204 form_manager()->ProvisionallySave( 2206 form_manager()->ProvisionallySave(
2205 submitted_form, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); 2207 submitted_form, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES);
2206 2208
2207 PasswordForm new_credentials; 2209 PasswordForm new_credentials;
2208 EXPECT_CALL(*mock_store(), UpdateLogin(_)) 2210 EXPECT_CALL(*mock_store(), UpdateLogin(_))
2209 .WillOnce(testing::SaveArg<0>(&new_credentials)); 2211 .WillOnce(testing::SaveArg<0>(&new_credentials));
2210 form_manager()->Save(); 2212 form_manager()->Save();
2211 2213
2212 EXPECT_EQ(PasswordForm::TYPE_MANUAL, new_credentials.type); 2214 EXPECT_EQ(PasswordForm::TYPE_MANUAL, new_credentials.type);
(...skipping 10 matching lines...) Expand all
2223 2225
2224 scoped_ptr<PasswordForm> generated_form(new PasswordForm(*observed_form())); 2226 scoped_ptr<PasswordForm> generated_form(new PasswordForm(*observed_form()));
2225 generated_form->type = PasswordForm::TYPE_GENERATED; 2227 generated_form->type = PasswordForm::TYPE_GENERATED;
2226 generated_form->username_value = ASCIIToUTF16("username"); 2228 generated_form->username_value = ASCIIToUTF16("username");
2227 generated_form->password_value = ASCIIToUTF16("password2"); 2229 generated_form->password_value = ASCIIToUTF16("password2");
2228 generated_form->preferred = true; 2230 generated_form->preferred = true;
2229 2231
2230 PasswordForm submitted_form(*generated_form); 2232 PasswordForm submitted_form(*generated_form);
2231 2233
2232 ScopedVector<PasswordForm> simulated_results; 2234 ScopedVector<PasswordForm> simulated_results;
2233 simulated_results.push_back(generated_form.Pass()); 2235 simulated_results.push_back(std::move(generated_form));
2234 form_manager()->OnGetPasswordStoreResults(simulated_results.Pass()); 2236 form_manager()->OnGetPasswordStoreResults(std::move(simulated_results));
2235 2237
2236 form_manager()->ProvisionallySave( 2238 form_manager()->ProvisionallySave(
2237 submitted_form, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); 2239 submitted_form, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES);
2238 2240
2239 PasswordForm new_credentials; 2241 PasswordForm new_credentials;
2240 EXPECT_CALL(*mock_store(), UpdateLogin(_)) 2242 EXPECT_CALL(*mock_store(), UpdateLogin(_))
2241 .WillOnce(testing::SaveArg<0>(&new_credentials)); 2243 .WillOnce(testing::SaveArg<0>(&new_credentials));
2242 form_manager()->Save(); 2244 form_manager()->Save();
2243 2245
2244 EXPECT_EQ(PasswordForm::TYPE_GENERATED, new_credentials.type); 2246 EXPECT_EQ(PasswordForm::TYPE_GENERATED, new_credentials.type);
2245 histogram_tester.ExpectBucketCount("PasswordGeneration.SubmissionEvent", 2247 histogram_tester.ExpectBucketCount("PasswordGeneration.SubmissionEvent",
2246 metrics_util::PASSWORD_USED, 1); 2248 metrics_util::PASSWORD_USED, 1);
2247 } 2249 }
2248 2250
2249 TEST_F(PasswordFormManagerTest, 2251 TEST_F(PasswordFormManagerTest,
2250 FetchMatchingLoginsFromPasswordStore_Reentrance) { 2252 FetchMatchingLoginsFromPasswordStore_Reentrance) {
2251 const PasswordStore::AuthorizationPromptPolicy auth_policy = 2253 const PasswordStore::AuthorizationPromptPolicy auth_policy =
2252 PasswordStore::DISALLOW_PROMPT; 2254 PasswordStore::DISALLOW_PROMPT;
2253 EXPECT_CALL(*mock_store(), GetLogins(form_manager()->observed_form(), 2255 EXPECT_CALL(*mock_store(), GetLogins(form_manager()->observed_form(),
2254 auth_policy, form_manager())) 2256 auth_policy, form_manager()))
2255 .Times(2); 2257 .Times(2);
2256 form_manager()->FetchDataFromPasswordStore(auth_policy); 2258 form_manager()->FetchDataFromPasswordStore(auth_policy);
2257 form_manager()->FetchDataFromPasswordStore(auth_policy); 2259 form_manager()->FetchDataFromPasswordStore(auth_policy);
2258 2260
2259 // First response from the store, should be ignored. 2261 // First response from the store, should be ignored.
2260 scoped_ptr<PasswordForm> saved_form(new PasswordForm(*saved_match())); 2262 scoped_ptr<PasswordForm> saved_form(new PasswordForm(*saved_match()));
2261 saved_form->username_value = ASCIIToUTF16("a@gmail.com"); 2263 saved_form->username_value = ASCIIToUTF16("a@gmail.com");
2262 ScopedVector<PasswordForm> results; 2264 ScopedVector<PasswordForm> results;
2263 results.push_back(saved_form.Pass()); 2265 results.push_back(std::move(saved_form));
2264 form_manager()->OnGetPasswordStoreResults(results.Pass()); 2266 form_manager()->OnGetPasswordStoreResults(std::move(results));
2265 EXPECT_TRUE(form_manager()->best_matches().empty()); 2267 EXPECT_TRUE(form_manager()->best_matches().empty());
2266 2268
2267 // Second response from the store should not be ignored. 2269 // Second response from the store should not be ignored.
2268 saved_form.reset(new PasswordForm(*saved_match())); 2270 saved_form.reset(new PasswordForm(*saved_match()));
2269 saved_form->username_value = ASCIIToUTF16("b@gmail.com"); 2271 saved_form->username_value = ASCIIToUTF16("b@gmail.com");
2270 results.push_back(saved_form.Pass()); 2272 results.push_back(std::move(saved_form));
2271 saved_form.reset(new PasswordForm(*saved_match())); 2273 saved_form.reset(new PasswordForm(*saved_match()));
2272 saved_form->username_value = ASCIIToUTF16("c@gmail.com"); 2274 saved_form->username_value = ASCIIToUTF16("c@gmail.com");
2273 results.push_back(saved_form.Pass()); 2275 results.push_back(std::move(saved_form));
2274 form_manager()->OnGetPasswordStoreResults(results.Pass()); 2276 form_manager()->OnGetPasswordStoreResults(std::move(results));
2275 EXPECT_EQ(2U, form_manager()->best_matches().size()); 2277 EXPECT_EQ(2U, form_manager()->best_matches().size());
2276 } 2278 }
2277 2279
2278 TEST_F(PasswordFormManagerTest, ProcessFrame) { 2280 TEST_F(PasswordFormManagerTest, ProcessFrame) {
2279 EXPECT_CALL(*client()->mock_driver(), FillPasswordForm(_)); 2281 EXPECT_CALL(*client()->mock_driver(), FillPasswordForm(_));
2280 SimulateMatchingPhase(form_manager(), RESULT_SAVED_MATCH); 2282 SimulateMatchingPhase(form_manager(), RESULT_SAVED_MATCH);
2281 } 2283 }
2282 2284
2283 TEST_F(PasswordFormManagerTest, ProcessFrame_MoreProcessFrameMoreFill) { 2285 TEST_F(PasswordFormManagerTest, ProcessFrame_MoreProcessFrameMoreFill) {
2284 EXPECT_CALL(*client()->mock_driver(), FillPasswordForm(_)).Times(2); 2286 EXPECT_CALL(*client()->mock_driver(), FillPasswordForm(_)).Times(2);
(...skipping 19 matching lines...) Expand all
2304 EXPECT_CALL(*mock_store(), 2306 EXPECT_CALL(*mock_store(),
2305 GetLogins(form_manager()->observed_form(), _, form_manager())); 2307 GetLogins(form_manager()->observed_form(), _, form_manager()));
2306 form_manager()->FetchDataFromPasswordStore(PasswordStore::DISALLOW_PROMPT); 2308 form_manager()->FetchDataFromPasswordStore(PasswordStore::DISALLOW_PROMPT);
2307 2309
2308 // Now add the extra driver. 2310 // Now add the extra driver.
2309 form_manager()->ProcessFrame(extra_driver.AsWeakPtr()); 2311 form_manager()->ProcessFrame(extra_driver.AsWeakPtr());
2310 2312
2311 // Password store responds. 2313 // Password store responds.
2312 scoped_ptr<PasswordForm> match(new PasswordForm(*saved_match())); 2314 scoped_ptr<PasswordForm> match(new PasswordForm(*saved_match()));
2313 ScopedVector<PasswordForm> result_form; 2315 ScopedVector<PasswordForm> result_form;
2314 result_form.push_back(match.Pass()); 2316 result_form.push_back(std::move(match));
2315 form_manager()->OnGetPasswordStoreResults(result_form.Pass()); 2317 form_manager()->OnGetPasswordStoreResults(std::move(result_form));
2316 } 2318 }
2317 2319
2318 TEST_F(PasswordFormManagerTest, ProcessFrame_StoreUpdatesCausesAutofill) { 2320 TEST_F(PasswordFormManagerTest, ProcessFrame_StoreUpdatesCausesAutofill) {
2319 EXPECT_CALL(*client()->mock_driver(), FillPasswordForm(_)).Times(2); 2321 EXPECT_CALL(*client()->mock_driver(), FillPasswordForm(_)).Times(2);
2320 SimulateMatchingPhase(form_manager(), RESULT_SAVED_MATCH); 2322 SimulateMatchingPhase(form_manager(), RESULT_SAVED_MATCH);
2321 SimulateMatchingPhase(form_manager(), RESULT_SAVED_MATCH); 2323 SimulateMatchingPhase(form_manager(), RESULT_SAVED_MATCH);
2322 } 2324 }
2323 2325
2324 TEST_F(PasswordFormManagerTest, UpdateFormManagers_IsCalled) { 2326 TEST_F(PasswordFormManagerTest, UpdateFormManagers_IsCalled) {
2325 // Let |password_manager()| create one additional PasswordFormManager. 2327 // Let |password_manager()| create one additional PasswordFormManager.
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
2647 EXPECT_EQ(ASCIIToUTF16("new_password"), 2649 EXPECT_EQ(ASCIIToUTF16("new_password"),
2648 form_manager()->pending_credentials().password_value); 2650 form_manager()->pending_credentials().password_value);
2649 EXPECT_EQ(base::string16(), 2651 EXPECT_EQ(base::string16(),
2650 form_manager()->pending_credentials().username_value); 2652 form_manager()->pending_credentials().username_value);
2651 EXPECT_TRUE( 2653 EXPECT_TRUE(
2652 form_manager()->pending_credentials().new_password_element.empty()); 2654 form_manager()->pending_credentials().new_password_element.empty());
2653 EXPECT_TRUE(form_manager()->pending_credentials().new_password_value.empty()); 2655 EXPECT_TRUE(form_manager()->pending_credentials().new_password_value.empty());
2654 } 2656 }
2655 2657
2656 } // namespace password_manager 2658 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698