Chromium Code Reviews| 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("username_element"); | |
|
vabr (Chromium)
2016/08/24 15:56:17
nit: If this is meant to be different from form_.u
vasilii
2016/08/24 16:51:15
Done.
| |
| 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 5 credentials. Two pairs of duplicates and one empty username. There | |
| 717 // should be just two in the account chooser. | |
| 718 store_->AddLogin(form_); | |
| 719 autofill::PasswordForm empty = form_; | |
| 720 empty.username_value.clear(); | |
| 721 store_->AddLogin(empty); | |
| 722 autofill::PasswordForm duplicate = form_; | |
| 723 duplicate.username_element = base::ASCIIToUTF16("username_element"); | |
| 724 duplicate.is_public_suffix_match = true; | |
| 725 store_->AddLogin(duplicate); | |
| 726 | |
| 727 store_->AddLogin(origin_path_form_); | |
| 728 duplicate = origin_path_form_; | |
| 729 duplicate.username_element = base::ASCIIToUTF16("username_element"); | |
| 730 duplicate.is_public_suffix_match = true; | |
| 731 store_->AddLogin(duplicate); | |
| 732 | |
| 733 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr( | |
| 734 UnorderedElementsAre(Pointee(form_), | |
| 735 Pointee(origin_path_form_)), | |
| 736 testing::IsEmpty(), _, _)) | |
| 737 .Times(testing::Exactly(1)); | |
|
vabr (Chromium)
2016/08/24 15:56:17
optional: This line is not necessary (omitting is
vasilii
2016/08/24 16:51:15
It was copy-paste.
| |
| 738 | |
| 739 bool called = false; | |
| 740 mojom::CredentialManagerError error; | |
| 741 base::Optional<CredentialInfo> credential; | |
| 742 std::vector<GURL> federations; | |
| 743 CallGet(false, true, federations, | |
| 744 base::Bind(&GetCredentialCallback, &called, &error, &credential)); | |
| 745 | |
| 746 RunAllPendingTasks(); | |
| 747 } | |
| 748 | |
| 749 TEST_F(CredentialManagerImplTest, | |
| 710 CredentialManagerOnRequestCredentialWithCrossOriginPasswordStore) { | 750 CredentialManagerOnRequestCredentialWithCrossOriginPasswordStore) { |
| 711 store_->AddLogin(cross_origin_form_); | 751 store_->AddLogin(cross_origin_form_); |
| 712 | 752 |
| 713 std::vector<GURL> federations; | 753 std::vector<GURL> federations; |
| 714 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( | 754 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( |
| 715 _, CredentialSourceType::CREDENTIAL_SOURCE_API)) | 755 _, CredentialSourceType::CREDENTIAL_SOURCE_API)) |
| 716 .Times(testing::Exactly(0)); | 756 .Times(testing::Exactly(0)); |
| 717 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | 757 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 718 .Times(testing::Exactly(0)); | 758 .Times(testing::Exactly(0)); |
| 719 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | 759 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)); | 1355 _, CredentialSourceType::CREDENTIAL_SOURCE_API)); |
| 1316 CallStore(info, base::Bind(&RespondCallback, &called)); | 1356 CallStore(info, base::Bind(&RespondCallback, &called)); |
| 1317 // Allow the PasswordFormManager to talk to the password store | 1357 // Allow the PasswordFormManager to talk to the password store |
| 1318 RunAllPendingTasks(); | 1358 RunAllPendingTasks(); |
| 1319 | 1359 |
| 1320 ASSERT_TRUE(client_->pending_manager()); | 1360 ASSERT_TRUE(client_->pending_manager()); |
| 1321 EXPECT_TRUE(client_->pending_manager()->IsBlacklisted()); | 1361 EXPECT_TRUE(client_->pending_manager()->IsBlacklisted()); |
| 1322 } | 1362 } |
| 1323 | 1363 |
| 1324 } // namespace password_manager | 1364 } // namespace password_manager |
| OLD | NEW |