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_impl.h" | 5 #include "components/password_manager/content/browser/credential_manager_impl.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> |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include "content/public/browser/web_contents.h" | 33 #include "content/public/browser/web_contents.h" |
34 #include "content/public/test/mock_render_process_host.h" | 34 #include "content/public/test/mock_render_process_host.h" |
35 #include "content/public/test/test_renderer_host.h" | 35 #include "content/public/test/test_renderer_host.h" |
36 #include "testing/gmock/include/gmock/gmock.h" | 36 #include "testing/gmock/include/gmock/gmock.h" |
37 #include "testing/gtest/include/gtest/gtest.h" | 37 #include "testing/gtest/include/gtest/gtest.h" |
38 | 38 |
39 using content::BrowserContext; | 39 using content::BrowserContext; |
40 using content::WebContents; | 40 using content::WebContents; |
41 | 41 |
42 using testing::_; | 42 using testing::_; |
| 43 using testing::Pointee; |
| 44 using testing::UnorderedElementsAre; |
43 | 45 |
44 namespace password_manager { | 46 namespace password_manager { |
45 | 47 |
46 namespace { | 48 namespace { |
47 | 49 |
48 const char kTestWebOrigin[] = "https://example.com/"; | 50 const char kTestWebOrigin[] = "https://example.com/"; |
49 const char kTestAndroidRealm1[] = "android://hash@com.example.one.android/"; | 51 const char kTestAndroidRealm1[] = "android://hash@com.example.one.android/"; |
50 const char kTestAndroidRealm2[] = "android://hash@com.example.two.android/"; | 52 const char kTestAndroidRealm2[] = "android://hash@com.example.two.android/"; |
51 | 53 |
52 class MockPasswordManagerClient : public StubPasswordManagerClient { | 54 class MockPasswordManagerClient : public StubPasswordManagerClient { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 } | 92 } |
91 | 93 |
92 PasswordStore* GetPasswordStore() const override { return store_; } | 94 PasswordStore* GetPasswordStore() const override { return store_; } |
93 | 95 |
94 PrefService* GetPrefs() override { return &prefs_; } | 96 PrefService* GetPrefs() override { return &prefs_; } |
95 | 97 |
96 bool PromptUserToChooseCredentials( | 98 bool PromptUserToChooseCredentials( |
97 ScopedVector<autofill::PasswordForm> local_forms, | 99 ScopedVector<autofill::PasswordForm> local_forms, |
98 ScopedVector<autofill::PasswordForm> federated_forms, | 100 ScopedVector<autofill::PasswordForm> federated_forms, |
99 const GURL& origin, | 101 const GURL& origin, |
100 const CredentialsCallback& callback) { | 102 const CredentialsCallback& callback) override { |
101 EXPECT_FALSE(local_forms.empty() && federated_forms.empty()); | 103 EXPECT_FALSE(local_forms.empty() && federated_forms.empty()); |
102 const autofill::PasswordForm* form = | 104 const autofill::PasswordForm* form = |
103 local_forms.empty() ? federated_forms[0] : local_forms[0]; | 105 local_forms.empty() ? federated_forms[0] : local_forms[0]; |
104 base::ThreadTaskRunnerHandle::Get()->PostTask( | 106 base::ThreadTaskRunnerHandle::Get()->PostTask( |
105 FROM_HERE, | 107 FROM_HERE, |
106 base::Bind(callback, base::Owned(new autofill::PasswordForm(*form)))); | 108 base::Bind(callback, base::Owned(new autofill::PasswordForm(*form)))); |
107 PromptUserToChooseCredentialsPtr(local_forms.get(), federated_forms.get(), | 109 PromptUserToChooseCredentialsPtr(local_forms.get(), federated_forms.get(), |
108 origin, callback); | 110 origin, callback); |
109 return true; | 111 return true; |
110 } | 112 } |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | 690 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
689 .Times(testing::Exactly(0)); | 691 .Times(testing::Exactly(0)); |
690 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | 692 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); |
691 | 693 |
692 std::vector<GURL> federations; | 694 std::vector<GURL> federations; |
693 ExpectCredentialType(false, true, federations, | 695 ExpectCredentialType(false, true, federations, |
694 CredentialType::CREDENTIAL_TYPE_EMPTY); | 696 CredentialType::CREDENTIAL_TYPE_EMPTY); |
695 } | 697 } |
696 | 698 |
697 TEST_F(CredentialManagerImplTest, | 699 TEST_F(CredentialManagerImplTest, |
698 CredentialManagerOnRequestCredentialWithEmptyAndNonUsernames) { | 700 CredentialManagerOnRequestCredentialWithEmptyAndNonemptyUsernames) { |
699 store_->AddLogin(form_); | 701 store_->AddLogin(form_); |
700 autofill::PasswordForm empty = form_; | 702 autofill::PasswordForm empty = form_; |
701 empty.username_value.clear(); | 703 empty.username_value.clear(); |
702 store_->AddLogin(empty); | 704 store_->AddLogin(empty); |
| 705 autofill::PasswordForm duplicate = form_; |
| 706 duplicate.username_element = base::ASCIIToUTF16("different_username_element"); |
| 707 store_->AddLogin(duplicate); |
703 | 708 |
704 std::vector<GURL> federations; | 709 std::vector<GURL> federations; |
705 ExpectZeroClickSignInSuccess(false, true, federations, | 710 ExpectZeroClickSignInSuccess(false, true, federations, |
706 CredentialType::CREDENTIAL_TYPE_PASSWORD); | 711 CredentialType::CREDENTIAL_TYPE_PASSWORD); |
707 } | 712 } |
708 | 713 |
709 TEST_F(CredentialManagerImplTest, | 714 TEST_F(CredentialManagerImplTest, |
| 715 CredentialManagerOnRequestCredentialWithDuplicates) { |
| 716 // Add 7 credentials. Two buckets of duplicates and one empty username. There |
| 717 // should be just two in the account chooser. |
| 718 form_.preferred = true; |
| 719 form_.username_element = base::ASCIIToUTF16("username_element"); |
| 720 store_->AddLogin(form_); |
| 721 autofill::PasswordForm empty = form_; |
| 722 empty.username_value.clear(); |
| 723 store_->AddLogin(empty); |
| 724 autofill::PasswordForm duplicate = form_; |
| 725 duplicate.username_element = base::ASCIIToUTF16("username_element1"); |
| 726 duplicate.is_public_suffix_match = true; |
| 727 store_->AddLogin(duplicate); |
| 728 duplicate = form_; |
| 729 duplicate.username_element = base::ASCIIToUTF16("username_element2"); |
| 730 duplicate.preferred = false; |
| 731 store_->AddLogin(duplicate); |
| 732 |
| 733 origin_path_form_.preferred = true; |
| 734 store_->AddLogin(origin_path_form_); |
| 735 duplicate = origin_path_form_; |
| 736 duplicate.username_element = base::ASCIIToUTF16("username_element3"); |
| 737 duplicate.is_public_suffix_match = true; |
| 738 store_->AddLogin(duplicate); |
| 739 duplicate = origin_path_form_; |
| 740 duplicate.username_element = base::ASCIIToUTF16("username_element4"); |
| 741 duplicate.preferred = false; |
| 742 store_->AddLogin(duplicate); |
| 743 |
| 744 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr( |
| 745 UnorderedElementsAre(Pointee(form_), |
| 746 Pointee(origin_path_form_)), |
| 747 testing::IsEmpty(), _, _)); |
| 748 |
| 749 bool called = false; |
| 750 mojom::CredentialManagerError error; |
| 751 base::Optional<CredentialInfo> credential; |
| 752 std::vector<GURL> federations; |
| 753 CallGet(false, true, federations, |
| 754 base::Bind(&GetCredentialCallback, &called, &error, &credential)); |
| 755 |
| 756 RunAllPendingTasks(); |
| 757 } |
| 758 |
| 759 TEST_F(CredentialManagerImplTest, |
710 CredentialManagerOnRequestCredentialWithCrossOriginPasswordStore) { | 760 CredentialManagerOnRequestCredentialWithCrossOriginPasswordStore) { |
711 store_->AddLogin(cross_origin_form_); | 761 store_->AddLogin(cross_origin_form_); |
712 | 762 |
713 std::vector<GURL> federations; | 763 std::vector<GURL> federations; |
714 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( | 764 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( |
715 _, CredentialSourceType::CREDENTIAL_SOURCE_API)) | 765 _, CredentialSourceType::CREDENTIAL_SOURCE_API)) |
716 .Times(testing::Exactly(0)); | 766 .Times(testing::Exactly(0)); |
717 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | 767 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
718 .Times(testing::Exactly(0)); | 768 .Times(testing::Exactly(0)); |
719 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | 769 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); |
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1315 _, CredentialSourceType::CREDENTIAL_SOURCE_API)); | 1365 _, CredentialSourceType::CREDENTIAL_SOURCE_API)); |
1316 CallStore(info, base::Bind(&RespondCallback, &called)); | 1366 CallStore(info, base::Bind(&RespondCallback, &called)); |
1317 // Allow the PasswordFormManager to talk to the password store | 1367 // Allow the PasswordFormManager to talk to the password store |
1318 RunAllPendingTasks(); | 1368 RunAllPendingTasks(); |
1319 | 1369 |
1320 ASSERT_TRUE(client_->pending_manager()); | 1370 ASSERT_TRUE(client_->pending_manager()); |
1321 EXPECT_TRUE(client_->pending_manager()->IsBlacklisted()); | 1371 EXPECT_TRUE(client_->pending_manager()->IsBlacklisted()); |
1322 } | 1372 } |
1323 | 1373 |
1324 } // namespace password_manager | 1374 } // namespace password_manager |
OLD | NEW |