| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/content/browser/credential_manager_dispatc
her.h" | 5 #include "components/password_manager/content/browser/credential_manager_dispatc
her.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <tuple> | 10 #include <tuple> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ptr_util.h" |
| 16 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 17 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/thread_task_runner_handle.h" | 20 #include "base/thread_task_runner_handle.h" |
| 20 #include "components/password_manager/content/common/credential_manager_messages
.h" | 21 #include "components/password_manager/content/common/credential_manager_messages
.h" |
| 21 #include "components/password_manager/core/browser/credential_manager_password_f
orm_manager.h" | 22 #include "components/password_manager/core/browser/credential_manager_password_f
orm_manager.h" |
| 22 #include "components/password_manager/core/browser/mock_affiliated_match_helper.
h" | 23 #include "components/password_manager/core/browser/mock_affiliated_match_helper.
h" |
| 23 #include "components/password_manager/core/browser/password_manager.h" | 24 #include "components/password_manager/core/browser/password_manager.h" |
| 24 #include "components/password_manager/core/browser/stub_password_manager_client.
h" | 25 #include "components/password_manager/core/browser/stub_password_manager_client.
h" |
| 25 #include "components/password_manager/core/browser/stub_password_manager_driver.
h" | 26 #include "components/password_manager/core/browser/stub_password_manager_driver.
h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 const CredentialsCallback& callback)); | 69 const CredentialsCallback& callback)); |
| 69 | 70 |
| 70 explicit MockPasswordManagerClient(PasswordStore* store) : store_(store) { | 71 explicit MockPasswordManagerClient(PasswordStore* store) : store_(store) { |
| 71 prefs_.registry()->RegisterBooleanPref(prefs::kCredentialsEnableAutosignin, | 72 prefs_.registry()->RegisterBooleanPref(prefs::kCredentialsEnableAutosignin, |
| 72 true); | 73 true); |
| 73 prefs_.registry()->RegisterBooleanPref( | 74 prefs_.registry()->RegisterBooleanPref( |
| 74 prefs::kWasAutoSignInFirstRunExperienceShown, true); | 75 prefs::kWasAutoSignInFirstRunExperienceShown, true); |
| 75 } | 76 } |
| 76 ~MockPasswordManagerClient() override {} | 77 ~MockPasswordManagerClient() override {} |
| 77 | 78 |
| 78 bool PromptUserToSaveOrUpdatePassword(scoped_ptr<PasswordFormManager> manager, | 79 bool PromptUserToSaveOrUpdatePassword( |
| 79 CredentialSourceType type, | 80 std::unique_ptr<PasswordFormManager> manager, |
| 80 bool update_password) override { | 81 CredentialSourceType type, |
| 82 bool update_password) override { |
| 81 manager_.swap(manager); | 83 manager_.swap(manager); |
| 82 PromptUserToSavePasswordPtr(manager_.get(), type); | 84 PromptUserToSavePasswordPtr(manager_.get(), type); |
| 83 return true; | 85 return true; |
| 84 } | 86 } |
| 85 | 87 |
| 86 void NotifyUserCouldBeAutoSignedIn( | 88 void NotifyUserCouldBeAutoSignedIn( |
| 87 scoped_ptr<autofill::PasswordForm> form) override { | 89 std::unique_ptr<autofill::PasswordForm> form) override { |
| 88 NotifyUserCouldBeAutoSignedInPtr(form.get()); | 90 NotifyUserCouldBeAutoSignedInPtr(form.get()); |
| 89 } | 91 } |
| 90 | 92 |
| 91 PasswordStore* GetPasswordStore() const override { return store_; } | 93 PasswordStore* GetPasswordStore() const override { return store_; } |
| 92 | 94 |
| 93 PrefService* GetPrefs() override { return &prefs_; } | 95 PrefService* GetPrefs() override { return &prefs_; } |
| 94 | 96 |
| 95 bool PromptUserToChooseCredentials( | 97 bool PromptUserToChooseCredentials( |
| 96 ScopedVector<autofill::PasswordForm> local_forms, | 98 ScopedVector<autofill::PasswordForm> local_forms, |
| 97 ScopedVector<autofill::PasswordForm> federated_forms, | 99 ScopedVector<autofill::PasswordForm> federated_forms, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 121 } | 123 } |
| 122 | 124 |
| 123 void set_first_run_seen(bool first_run_seen) { | 125 void set_first_run_seen(bool first_run_seen) { |
| 124 prefs_.SetBoolean(prefs::kWasAutoSignInFirstRunExperienceShown, | 126 prefs_.SetBoolean(prefs::kWasAutoSignInFirstRunExperienceShown, |
| 125 first_run_seen); | 127 first_run_seen); |
| 126 } | 128 } |
| 127 | 129 |
| 128 private: | 130 private: |
| 129 TestingPrefServiceSimple prefs_; | 131 TestingPrefServiceSimple prefs_; |
| 130 PasswordStore* store_; | 132 PasswordStore* store_; |
| 131 scoped_ptr<PasswordFormManager> manager_; | 133 std::unique_ptr<PasswordFormManager> manager_; |
| 132 | 134 |
| 133 DISALLOW_COPY_AND_ASSIGN(MockPasswordManagerClient); | 135 DISALLOW_COPY_AND_ASSIGN(MockPasswordManagerClient); |
| 134 }; | 136 }; |
| 135 | 137 |
| 136 class TestCredentialManagerDispatcher : public CredentialManagerDispatcher { | 138 class TestCredentialManagerDispatcher : public CredentialManagerDispatcher { |
| 137 public: | 139 public: |
| 138 TestCredentialManagerDispatcher(content::WebContents* web_contents, | 140 TestCredentialManagerDispatcher(content::WebContents* web_contents, |
| 139 PasswordManagerClient* client, | 141 PasswordManagerClient* client, |
| 140 PasswordManagerDriver* driver); | 142 PasswordManagerDriver* driver); |
| 141 | 143 |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 | 294 |
| 293 CredentialManagerDispatcher* dispatcher() { return dispatcher_.get(); } | 295 CredentialManagerDispatcher* dispatcher() { return dispatcher_.get(); } |
| 294 | 296 |
| 295 protected: | 297 protected: |
| 296 autofill::PasswordForm form_; | 298 autofill::PasswordForm form_; |
| 297 autofill::PasswordForm affiliated_form1_; | 299 autofill::PasswordForm affiliated_form1_; |
| 298 autofill::PasswordForm affiliated_form2_; | 300 autofill::PasswordForm affiliated_form2_; |
| 299 autofill::PasswordForm origin_path_form_; | 301 autofill::PasswordForm origin_path_form_; |
| 300 autofill::PasswordForm cross_origin_form_; | 302 autofill::PasswordForm cross_origin_form_; |
| 301 scoped_refptr<TestPasswordStore> store_; | 303 scoped_refptr<TestPasswordStore> store_; |
| 302 scoped_ptr<testing::NiceMock<MockPasswordManagerClient>> client_; | 304 std::unique_ptr<testing::NiceMock<MockPasswordManagerClient>> client_; |
| 303 scoped_ptr<SlightlyLessStubbyPasswordManagerDriver> stub_driver_; | 305 std::unique_ptr<SlightlyLessStubbyPasswordManagerDriver> stub_driver_; |
| 304 scoped_ptr<CredentialManagerDispatcher> dispatcher_; | 306 std::unique_ptr<CredentialManagerDispatcher> dispatcher_; |
| 305 }; | 307 }; |
| 306 | 308 |
| 307 TEST_F(CredentialManagerDispatcherTest, IsZeroClickAllowed) { | 309 TEST_F(CredentialManagerDispatcherTest, IsZeroClickAllowed) { |
| 308 // IsZeroClickAllowed is uneffected by the first-run status. | 310 // IsZeroClickAllowed is uneffected by the first-run status. |
| 309 client_->set_zero_click_enabled(true); | 311 client_->set_zero_click_enabled(true); |
| 310 client_->set_first_run_seen(true); | 312 client_->set_first_run_seen(true); |
| 311 EXPECT_TRUE(dispatcher()->IsZeroClickAllowed()); | 313 EXPECT_TRUE(dispatcher()->IsZeroClickAllowed()); |
| 312 | 314 |
| 313 client_->set_zero_click_enabled(true); | 315 client_->set_zero_click_enabled(true); |
| 314 client_->set_first_run_seen(false); | 316 client_->set_first_run_seen(false); |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); | 525 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); |
| 524 } | 526 } |
| 525 | 527 |
| 526 TEST_F(CredentialManagerDispatcherTest, | 528 TEST_F(CredentialManagerDispatcherTest, |
| 527 CredentialManagerOnRequireUserMediationWithAffiliation) { | 529 CredentialManagerOnRequireUserMediationWithAffiliation) { |
| 528 store_->AddLogin(form_); | 530 store_->AddLogin(form_); |
| 529 store_->AddLogin(cross_origin_form_); | 531 store_->AddLogin(cross_origin_form_); |
| 530 store_->AddLogin(affiliated_form1_); | 532 store_->AddLogin(affiliated_form1_); |
| 531 store_->AddLogin(affiliated_form2_); | 533 store_->AddLogin(affiliated_form2_); |
| 532 | 534 |
| 533 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper); | 535 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); |
| 534 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); | 536 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 535 | 537 |
| 536 std::vector<GURL> federations; | 538 std::vector<GURL> federations; |
| 537 std::vector<std::string> affiliated_realms; | 539 std::vector<std::string> affiliated_realms; |
| 538 affiliated_realms.push_back(kTestAndroidRealm1); | 540 affiliated_realms.push_back(kTestAndroidRealm1); |
| 539 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) | 541 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) |
| 540 ->ExpectCallToGetAffiliatedAndroidRealms( | 542 ->ExpectCallToGetAffiliatedAndroidRealms( |
| 541 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); | 543 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); |
| 542 RunAllPendingTasks(); | 544 RunAllPendingTasks(); |
| 543 | 545 |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); | 707 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); |
| 706 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | 708 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); |
| 707 | 709 |
| 708 ExpectZeroClickSignInFailure(); | 710 ExpectZeroClickSignInFailure(); |
| 709 } | 711 } |
| 710 | 712 |
| 711 TEST_F(CredentialManagerDispatcherTest, | 713 TEST_F(CredentialManagerDispatcherTest, |
| 712 CredentialManagerOnRequestCredentialAffiliatedPasswordMatch) { | 714 CredentialManagerOnRequestCredentialAffiliatedPasswordMatch) { |
| 713 store_->AddLogin(affiliated_form1_); | 715 store_->AddLogin(affiliated_form1_); |
| 714 client_->set_first_run_seen(true); | 716 client_->set_first_run_seen(true); |
| 715 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper); | 717 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); |
| 716 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); | 718 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 717 | 719 |
| 718 std::vector<GURL> federations; | 720 std::vector<GURL> federations; |
| 719 std::vector<std::string> affiliated_realms; | 721 std::vector<std::string> affiliated_realms; |
| 720 affiliated_realms.push_back(kTestAndroidRealm1); | 722 affiliated_realms.push_back(kTestAndroidRealm1); |
| 721 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) | 723 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) |
| 722 ->ExpectCallToGetAffiliatedAndroidRealms( | 724 ->ExpectCallToGetAffiliatedAndroidRealms( |
| 723 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); | 725 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); |
| 724 | 726 |
| 725 // We pass in 'true' for the 'include_passwords' argument to ensure that | 727 // We pass in 'true' for the 'include_passwords' argument to ensure that |
| 726 // password-type credentials are included as potential matches. | 728 // password-type credentials are included as potential matches. |
| 727 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | 729 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); |
| 728 | 730 |
| 729 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_PASSWORD); | 731 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_PASSWORD); |
| 730 } | 732 } |
| 731 | 733 |
| 732 TEST_F(CredentialManagerDispatcherTest, | 734 TEST_F(CredentialManagerDispatcherTest, |
| 733 CredentialManagerOnRequestCredentialAffiliatedPasswordNoMatch) { | 735 CredentialManagerOnRequestCredentialAffiliatedPasswordNoMatch) { |
| 734 store_->AddLogin(affiliated_form1_); | 736 store_->AddLogin(affiliated_form1_); |
| 735 client_->set_first_run_seen(true); | 737 client_->set_first_run_seen(true); |
| 736 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper); | 738 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); |
| 737 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); | 739 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 738 | 740 |
| 739 std::vector<GURL> federations; | 741 std::vector<GURL> federations; |
| 740 std::vector<std::string> affiliated_realms; | 742 std::vector<std::string> affiliated_realms; |
| 741 affiliated_realms.push_back(kTestAndroidRealm1); | 743 affiliated_realms.push_back(kTestAndroidRealm1); |
| 742 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) | 744 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) |
| 743 ->ExpectCallToGetAffiliatedAndroidRealms( | 745 ->ExpectCallToGetAffiliatedAndroidRealms( |
| 744 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); | 746 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); |
| 745 | 747 |
| 746 // We pass in 'false' for the 'include_passwords' argument to ensure that | 748 // We pass in 'false' for the 'include_passwords' argument to ensure that |
| 747 // password-type credentials are excluded as potential matches. | 749 // password-type credentials are excluded as potential matches. |
| 748 dispatcher()->OnRequestCredential(kRequestId, true, false, federations); | 750 dispatcher()->OnRequestCredential(kRequestId, true, false, federations); |
| 749 | 751 |
| 750 ExpectZeroClickSignInFailure(); | 752 ExpectZeroClickSignInFailure(); |
| 751 } | 753 } |
| 752 | 754 |
| 753 TEST_F(CredentialManagerDispatcherTest, | 755 TEST_F(CredentialManagerDispatcherTest, |
| 754 CredentialManagerOnRequestCredentialAffiliatedFederatedMatch) { | 756 CredentialManagerOnRequestCredentialAffiliatedFederatedMatch) { |
| 755 affiliated_form1_.federation_origin = | 757 affiliated_form1_.federation_origin = |
| 756 url::Origin(GURL("https://example.com/")); | 758 url::Origin(GURL("https://example.com/")); |
| 757 store_->AddLogin(affiliated_form1_); | 759 store_->AddLogin(affiliated_form1_); |
| 758 client_->set_first_run_seen(true); | 760 client_->set_first_run_seen(true); |
| 759 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper); | 761 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); |
| 760 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); | 762 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 761 | 763 |
| 762 std::vector<GURL> federations; | 764 std::vector<GURL> federations; |
| 763 federations.push_back(GURL("https://example.com/")); | 765 federations.push_back(GURL("https://example.com/")); |
| 764 | 766 |
| 765 std::vector<std::string> affiliated_realms; | 767 std::vector<std::string> affiliated_realms; |
| 766 affiliated_realms.push_back(kTestAndroidRealm1); | 768 affiliated_realms.push_back(kTestAndroidRealm1); |
| 767 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) | 769 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) |
| 768 ->ExpectCallToGetAffiliatedAndroidRealms( | 770 ->ExpectCallToGetAffiliatedAndroidRealms( |
| 769 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); | 771 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); |
| 770 | 772 |
| 771 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | 773 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); |
| 772 | 774 |
| 773 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_FEDERATED); | 775 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_FEDERATED); |
| 774 } | 776 } |
| 775 | 777 |
| 776 TEST_F(CredentialManagerDispatcherTest, | 778 TEST_F(CredentialManagerDispatcherTest, |
| 777 CredentialManagerOnRequestCredentialAffiliatedFederatedNoMatch) { | 779 CredentialManagerOnRequestCredentialAffiliatedFederatedNoMatch) { |
| 778 affiliated_form1_.federation_origin = | 780 affiliated_form1_.federation_origin = |
| 779 url::Origin(GURL("https://example.com/")); | 781 url::Origin(GURL("https://example.com/")); |
| 780 store_->AddLogin(affiliated_form1_); | 782 store_->AddLogin(affiliated_form1_); |
| 781 client_->set_first_run_seen(true); | 783 client_->set_first_run_seen(true); |
| 782 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper); | 784 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); |
| 783 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); | 785 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 784 | 786 |
| 785 std::vector<GURL> federations; | 787 std::vector<GURL> federations; |
| 786 federations.push_back(GURL("https://not-example.com/")); | 788 federations.push_back(GURL("https://not-example.com/")); |
| 787 | 789 |
| 788 std::vector<std::string> affiliated_realms; | 790 std::vector<std::string> affiliated_realms; |
| 789 affiliated_realms.push_back(kTestAndroidRealm1); | 791 affiliated_realms.push_back(kTestAndroidRealm1); |
| 790 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) | 792 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) |
| 791 ->ExpectCallToGetAffiliatedAndroidRealms( | 793 ->ExpectCallToGetAffiliatedAndroidRealms( |
| 792 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); | 794 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1062 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, std::get<1>(param).type); | 1064 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, std::get<1>(param).type); |
| 1063 } | 1065 } |
| 1064 | 1066 |
| 1065 TEST_F(CredentialManagerDispatcherTest, | 1067 TEST_F(CredentialManagerDispatcherTest, |
| 1066 ZeroClickWithAffiliatedFormInPasswordStore) { | 1068 ZeroClickWithAffiliatedFormInPasswordStore) { |
| 1067 // Insert the affiliated form into the store, and mock out the association | 1069 // Insert the affiliated form into the store, and mock out the association |
| 1068 // with the current origin. As it's the only form matching the origin, it | 1070 // with the current origin. As it's the only form matching the origin, it |
| 1069 // ought to be returned automagically. | 1071 // ought to be returned automagically. |
| 1070 store_->AddLogin(affiliated_form1_); | 1072 store_->AddLogin(affiliated_form1_); |
| 1071 | 1073 |
| 1072 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper); | 1074 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); |
| 1073 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); | 1075 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 1074 | 1076 |
| 1075 std::vector<GURL> federations; | 1077 std::vector<GURL> federations; |
| 1076 std::vector<std::string> affiliated_realms; | 1078 std::vector<std::string> affiliated_realms; |
| 1077 affiliated_realms.push_back(kTestAndroidRealm1); | 1079 affiliated_realms.push_back(kTestAndroidRealm1); |
| 1078 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) | 1080 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) |
| 1079 ->ExpectCallToGetAffiliatedAndroidRealms( | 1081 ->ExpectCallToGetAffiliatedAndroidRealms( |
| 1080 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); | 1082 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); |
| 1081 | 1083 |
| 1082 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | 1084 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); |
| 1083 | 1085 |
| 1084 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_PASSWORD); | 1086 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_PASSWORD); |
| 1085 } | 1087 } |
| 1086 | 1088 |
| 1087 TEST_F(CredentialManagerDispatcherTest, | 1089 TEST_F(CredentialManagerDispatcherTest, |
| 1088 ZeroClickWithTwoAffiliatedFormsInPasswordStore) { | 1090 ZeroClickWithTwoAffiliatedFormsInPasswordStore) { |
| 1089 // Insert two affiliated forms into the store, and mock out the association | 1091 // Insert two affiliated forms into the store, and mock out the association |
| 1090 // with the current origin. Multiple forms === no zero-click sign in. | 1092 // with the current origin. Multiple forms === no zero-click sign in. |
| 1091 store_->AddLogin(affiliated_form1_); | 1093 store_->AddLogin(affiliated_form1_); |
| 1092 store_->AddLogin(affiliated_form2_); | 1094 store_->AddLogin(affiliated_form2_); |
| 1093 | 1095 |
| 1094 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper); | 1096 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); |
| 1095 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); | 1097 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 1096 | 1098 |
| 1097 std::vector<GURL> federations; | 1099 std::vector<GURL> federations; |
| 1098 std::vector<std::string> affiliated_realms; | 1100 std::vector<std::string> affiliated_realms; |
| 1099 affiliated_realms.push_back(kTestAndroidRealm1); | 1101 affiliated_realms.push_back(kTestAndroidRealm1); |
| 1100 affiliated_realms.push_back(kTestAndroidRealm2); | 1102 affiliated_realms.push_back(kTestAndroidRealm2); |
| 1101 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) | 1103 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) |
| 1102 ->ExpectCallToGetAffiliatedAndroidRealms( | 1104 ->ExpectCallToGetAffiliatedAndroidRealms( |
| 1103 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); | 1105 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); |
| 1104 | 1106 |
| 1105 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | 1107 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); |
| 1106 | 1108 |
| 1107 ExpectZeroClickSignInFailure(); | 1109 ExpectZeroClickSignInFailure(); |
| 1108 } | 1110 } |
| 1109 | 1111 |
| 1110 TEST_F(CredentialManagerDispatcherTest, | 1112 TEST_F(CredentialManagerDispatcherTest, |
| 1111 ZeroClickWithUnaffiliatedFormsInPasswordStore) { | 1113 ZeroClickWithUnaffiliatedFormsInPasswordStore) { |
| 1112 // Insert the affiliated form into the store, but don't mock out the | 1114 // Insert the affiliated form into the store, but don't mock out the |
| 1113 // association with the current origin. No association === no zero-click sign | 1115 // association with the current origin. No association === no zero-click sign |
| 1114 // in. | 1116 // in. |
| 1115 store_->AddLogin(affiliated_form1_); | 1117 store_->AddLogin(affiliated_form1_); |
| 1116 | 1118 |
| 1117 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper); | 1119 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); |
| 1118 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); | 1120 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 1119 | 1121 |
| 1120 std::vector<GURL> federations; | 1122 std::vector<GURL> federations; |
| 1121 std::vector<std::string> affiliated_realms; | 1123 std::vector<std::string> affiliated_realms; |
| 1122 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) | 1124 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) |
| 1123 ->ExpectCallToGetAffiliatedAndroidRealms( | 1125 ->ExpectCallToGetAffiliatedAndroidRealms( |
| 1124 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); | 1126 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); |
| 1125 | 1127 |
| 1126 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | 1128 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); |
| 1127 | 1129 |
| 1128 ExpectZeroClickSignInFailure(); | 1130 ExpectZeroClickSignInFailure(); |
| 1129 } | 1131 } |
| 1130 | 1132 |
| 1131 TEST_F(CredentialManagerDispatcherTest, | 1133 TEST_F(CredentialManagerDispatcherTest, |
| 1132 ZeroClickWithFormAndUnaffiliatedFormsInPasswordStore) { | 1134 ZeroClickWithFormAndUnaffiliatedFormsInPasswordStore) { |
| 1133 // Insert the affiliated form into the store, along with a real form for the | 1135 // Insert the affiliated form into the store, along with a real form for the |
| 1134 // origin, and don't mock out the association with the current origin. No | 1136 // origin, and don't mock out the association with the current origin. No |
| 1135 // association + existing form === zero-click sign in. | 1137 // association + existing form === zero-click sign in. |
| 1136 store_->AddLogin(form_); | 1138 store_->AddLogin(form_); |
| 1137 store_->AddLogin(affiliated_form1_); | 1139 store_->AddLogin(affiliated_form1_); |
| 1138 | 1140 |
| 1139 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper); | 1141 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); |
| 1140 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); | 1142 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); |
| 1141 | 1143 |
| 1142 std::vector<GURL> federations; | 1144 std::vector<GURL> federations; |
| 1143 std::vector<std::string> affiliated_realms; | 1145 std::vector<std::string> affiliated_realms; |
| 1144 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) | 1146 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) |
| 1145 ->ExpectCallToGetAffiliatedAndroidRealms( | 1147 ->ExpectCallToGetAffiliatedAndroidRealms( |
| 1146 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); | 1148 dispatcher_->GetSynthesizedFormForOrigin(), affiliated_realms); |
| 1147 | 1149 |
| 1148 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); | 1150 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); |
| 1149 | 1151 |
| 1150 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_PASSWORD); | 1152 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_PASSWORD); |
| 1151 } | 1153 } |
| 1152 | 1154 |
| 1153 TEST_F(CredentialManagerDispatcherTest, GetSynthesizedFormForOrigin) { | 1155 TEST_F(CredentialManagerDispatcherTest, GetSynthesizedFormForOrigin) { |
| 1154 autofill::PasswordForm synthesized = | 1156 autofill::PasswordForm synthesized = |
| 1155 dispatcher_->GetSynthesizedFormForOrigin(); | 1157 dispatcher_->GetSynthesizedFormForOrigin(); |
| 1156 EXPECT_EQ(kTestWebOrigin, synthesized.origin.spec()); | 1158 EXPECT_EQ(kTestWebOrigin, synthesized.origin.spec()); |
| 1157 EXPECT_EQ(kTestWebOrigin, synthesized.signon_realm); | 1159 EXPECT_EQ(kTestWebOrigin, synthesized.signon_realm); |
| 1158 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, synthesized.scheme); | 1160 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, synthesized.scheme); |
| 1159 EXPECT_TRUE(synthesized.ssl_valid); | 1161 EXPECT_TRUE(synthesized.ssl_valid); |
| 1160 } | 1162 } |
| 1161 | 1163 |
| 1162 } // namespace password_manager | 1164 } // namespace password_manager |
| OLD | NEW |