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

Side by Side Diff: components/password_manager/content/browser/credential_manager_impl_unittest.cc

Issue 2895243002: Rename requireUserMediation to preventSilentAccess in the CM API. (Closed)
Patch Set: merge Created 3 years, 6 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 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 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 } 349 }
350 350
351 CredentialManagerImpl* cm_service_impl() { return cm_service_impl_.get(); } 351 CredentialManagerImpl* cm_service_impl() { return cm_service_impl_.get(); }
352 352
353 // Helpers for testing CredentialManagerImpl methods. 353 // Helpers for testing CredentialManagerImpl methods.
354 void CallStore(const CredentialInfo& info, 354 void CallStore(const CredentialInfo& info,
355 CredentialManagerImpl::StoreCallback callback) { 355 CredentialManagerImpl::StoreCallback callback) {
356 cm_service_impl_->Store(info, std::move(callback)); 356 cm_service_impl_->Store(info, std::move(callback));
357 } 357 }
358 358
359 void CallRequireUserMediation( 359 void CallPreventSilentAccess(
360 CredentialManagerImpl::RequireUserMediationCallback callback) { 360 CredentialManagerImpl::PreventSilentAccessCallback callback) {
361 cm_service_impl_->RequireUserMediation(std::move(callback)); 361 cm_service_impl_->PreventSilentAccess(std::move(callback));
362 } 362 }
363 363
364 void CallGet(CredentialMediationRequirement mediation, 364 void CallGet(CredentialMediationRequirement mediation,
365 bool include_passwords, 365 bool include_passwords,
366 const std::vector<GURL>& federations, 366 const std::vector<GURL>& federations,
367 CredentialManagerImpl::GetCallback callback) { 367 CredentialManagerImpl::GetCallback callback) {
368 cm_service_impl_->Get(mediation, include_passwords, federations, 368 cm_service_impl_->Get(mediation, include_passwords, federations,
369 std::move(callback)); 369 std::move(callback));
370 } 370 }
371 371
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 704
705 bool called = false; 705 bool called = false;
706 CallStore(info, base::Bind(&RespondCallback, &called)); 706 CallStore(info, base::Bind(&RespondCallback, &called));
707 707
708 RunAllPendingTasks(); 708 RunAllPendingTasks();
709 709
710 EXPECT_TRUE(called); 710 EXPECT_TRUE(called);
711 EXPECT_FALSE(client_->pending_manager()); 711 EXPECT_FALSE(client_->pending_manager());
712 } 712 }
713 713
714 TEST_F(CredentialManagerImplTest, CredentialManagerOnRequireUserMediation) { 714 TEST_F(CredentialManagerImplTest, CredentialManagerOnPreventSilentAccess) {
715 store_->AddLogin(form_); 715 store_->AddLogin(form_);
716 store_->AddLogin(subdomain_form_); 716 store_->AddLogin(subdomain_form_);
717 store_->AddLogin(cross_origin_form_); 717 store_->AddLogin(cross_origin_form_);
718 RunAllPendingTasks(); 718 RunAllPendingTasks();
719 719
720 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); 720 TestPasswordStore::PasswordMap passwords = store_->stored_passwords();
721 EXPECT_EQ(3U, passwords.size()); 721 EXPECT_EQ(3U, passwords.size());
722 EXPECT_EQ(1U, passwords[form_.signon_realm].size()); 722 EXPECT_EQ(1U, passwords[form_.signon_realm].size());
723 EXPECT_EQ(1U, passwords[subdomain_form_.signon_realm].size()); 723 EXPECT_EQ(1U, passwords[subdomain_form_.signon_realm].size());
724 EXPECT_EQ(1U, passwords[cross_origin_form_.signon_realm].size()); 724 EXPECT_EQ(1U, passwords[cross_origin_form_.signon_realm].size());
725 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); 725 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click);
726 EXPECT_FALSE(passwords[subdomain_form_.signon_realm][0].skip_zero_click); 726 EXPECT_FALSE(passwords[subdomain_form_.signon_realm][0].skip_zero_click);
727 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); 727 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click);
728 728
729 bool called = false; 729 bool called = false;
730 CallRequireUserMediation(base::Bind(&RespondCallback, &called)); 730 CallPreventSilentAccess(base::Bind(&RespondCallback, &called));
731 731
732 RunAllPendingTasks(); 732 RunAllPendingTasks();
733 733
734 EXPECT_TRUE(called); 734 EXPECT_TRUE(called);
735 735
736 passwords = store_->stored_passwords(); 736 passwords = store_->stored_passwords();
737 EXPECT_EQ(3U, passwords.size()); 737 EXPECT_EQ(3U, passwords.size());
738 EXPECT_EQ(1U, passwords[form_.signon_realm].size()); 738 EXPECT_EQ(1U, passwords[form_.signon_realm].size());
739 EXPECT_EQ(1U, passwords[subdomain_form_.signon_realm].size()); 739 EXPECT_EQ(1U, passwords[subdomain_form_.signon_realm].size());
740 EXPECT_EQ(1U, passwords[cross_origin_form_.signon_realm].size()); 740 EXPECT_EQ(1U, passwords[cross_origin_form_.signon_realm].size());
741 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click); 741 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click);
742 EXPECT_TRUE(passwords[subdomain_form_.signon_realm][0].skip_zero_click); 742 EXPECT_TRUE(passwords[subdomain_form_.signon_realm][0].skip_zero_click);
743 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); 743 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click);
744 } 744 }
745 745
746 TEST_F(CredentialManagerImplTest, 746 TEST_F(CredentialManagerImplTest,
747 CredentialManagerOnRequireUserMediationIncognito) { 747 CredentialManagerOnPreventSilentAccessIncognito) {
748 EXPECT_CALL(*client_, IsSavingAndFillingEnabledForCurrentPage()) 748 EXPECT_CALL(*client_, IsSavingAndFillingEnabledForCurrentPage())
749 .WillRepeatedly(testing::Return(false)); 749 .WillRepeatedly(testing::Return(false));
750 store_->AddLogin(form_); 750 store_->AddLogin(form_);
751 RunAllPendingTasks(); 751 RunAllPendingTasks();
752 752
753 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); 753 TestPasswordStore::PasswordMap passwords = store_->stored_passwords();
754 ASSERT_EQ(1U, passwords.size()); 754 ASSERT_EQ(1U, passwords.size());
755 ASSERT_EQ(1U, passwords[form_.signon_realm].size()); 755 ASSERT_EQ(1U, passwords[form_.signon_realm].size());
756 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); 756 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click);
757 757
758 bool called = false; 758 bool called = false;
759 CallRequireUserMediation(base::Bind(&RespondCallback, &called)); 759 CallPreventSilentAccess(base::Bind(&RespondCallback, &called));
760 RunAllPendingTasks(); 760 RunAllPendingTasks();
761 761
762 EXPECT_TRUE(called); 762 EXPECT_TRUE(called);
763 763
764 passwords = store_->stored_passwords(); 764 passwords = store_->stored_passwords();
765 ASSERT_EQ(1U, passwords.size()); 765 ASSERT_EQ(1U, passwords.size());
766 ASSERT_EQ(1U, passwords[form_.signon_realm].size()); 766 ASSERT_EQ(1U, passwords[form_.signon_realm].size());
767 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); 767 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click);
768 } 768 }
769 769
770 TEST_F(CredentialManagerImplTest, 770 TEST_F(CredentialManagerImplTest,
771 CredentialManagerOnRequireUserMediationWithAffiliation) { 771 CredentialManagerOnPreventSilentAccessWithAffiliation) {
772 store_->AddLogin(form_); 772 store_->AddLogin(form_);
773 store_->AddLogin(cross_origin_form_); 773 store_->AddLogin(cross_origin_form_);
774 store_->AddLogin(affiliated_form1_); 774 store_->AddLogin(affiliated_form1_);
775 store_->AddLogin(affiliated_form2_); 775 store_->AddLogin(affiliated_form2_);
776 776
777 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); 777 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper);
778 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); 778 store_->SetAffiliatedMatchHelper(std::move(mock_helper));
779 779
780 std::vector<GURL> federations; 780 std::vector<GURL> federations;
781 std::vector<std::string> affiliated_realms; 781 std::vector<std::string> affiliated_realms;
782 affiliated_realms.push_back(kTestAndroidRealm1); 782 affiliated_realms.push_back(kTestAndroidRealm1);
783 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) 783 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper())
784 ->ExpectCallToGetAffiliatedAndroidRealms( 784 ->ExpectCallToGetAffiliatedAndroidRealms(
785 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms); 785 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms);
786 RunAllPendingTasks(); 786 RunAllPendingTasks();
787 787
788 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); 788 TestPasswordStore::PasswordMap passwords = store_->stored_passwords();
789 EXPECT_EQ(4U, passwords.size()); 789 EXPECT_EQ(4U, passwords.size());
790 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); 790 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click);
791 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); 791 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click);
792 EXPECT_FALSE(passwords[affiliated_form1_.signon_realm][0].skip_zero_click); 792 EXPECT_FALSE(passwords[affiliated_form1_.signon_realm][0].skip_zero_click);
793 EXPECT_FALSE(passwords[affiliated_form2_.signon_realm][0].skip_zero_click); 793 EXPECT_FALSE(passwords[affiliated_form2_.signon_realm][0].skip_zero_click);
794 794
795 bool called = false; 795 bool called = false;
796 CallRequireUserMediation(base::Bind(&RespondCallback, &called)); 796 CallPreventSilentAccess(base::Bind(&RespondCallback, &called));
797 RunAllPendingTasks(); 797 RunAllPendingTasks();
798 798
799 passwords = store_->stored_passwords(); 799 passwords = store_->stored_passwords();
800 EXPECT_EQ(4U, passwords.size()); 800 EXPECT_EQ(4U, passwords.size());
801 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click); 801 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click);
802 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); 802 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click);
803 EXPECT_TRUE(passwords[affiliated_form1_.signon_realm][0].skip_zero_click); 803 EXPECT_TRUE(passwords[affiliated_form1_.signon_realm][0].skip_zero_click);
804 EXPECT_FALSE(passwords[affiliated_form2_.signon_realm][0].skip_zero_click); 804 EXPECT_FALSE(passwords[affiliated_form2_.signon_realm][0].skip_zero_click);
805 } 805 }
806 806
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after
1621 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_)); 1621 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_));
1622 CallStore(info, base::Bind(&RespondCallback, &called)); 1622 CallStore(info, base::Bind(&RespondCallback, &called));
1623 // Allow the PasswordFormManager to talk to the password store 1623 // Allow the PasswordFormManager to talk to the password store
1624 RunAllPendingTasks(); 1624 RunAllPendingTasks();
1625 1625
1626 ASSERT_TRUE(client_->pending_manager()); 1626 ASSERT_TRUE(client_->pending_manager());
1627 EXPECT_TRUE(client_->pending_manager()->IsBlacklisted()); 1627 EXPECT_TRUE(client_->pending_manager()->IsBlacklisted());
1628 } 1628 }
1629 1629
1630 } // namespace password_manager 1630 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698