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

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

Issue 1735013004: CREDENTIAL: Only toggle 'skip_zero_click' state if API is used. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Ugh. Created 4 years, 9 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_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 <vector> 10 #include <vector>
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 const char kTestAndroidRealm1[] = "android://hash@com.example.one.android/"; 49 const char kTestAndroidRealm1[] = "android://hash@com.example.one.android/";
50 const char kTestAndroidRealm2[] = "android://hash@com.example.two.android/"; 50 const char kTestAndroidRealm2[] = "android://hash@com.example.two.android/";
51 51
52 class MockPasswordManagerClient : public StubPasswordManagerClient { 52 class MockPasswordManagerClient : public StubPasswordManagerClient {
53 public: 53 public:
54 MOCK_CONST_METHOD0(IsSavingAndFillingEnabledForCurrentPage, bool()); 54 MOCK_CONST_METHOD0(IsSavingAndFillingEnabledForCurrentPage, bool());
55 MOCK_CONST_METHOD0(IsOffTheRecord, bool()); 55 MOCK_CONST_METHOD0(IsOffTheRecord, bool());
56 MOCK_CONST_METHOD0(DidLastPageLoadEncounterSSLErrors, bool()); 56 MOCK_CONST_METHOD0(DidLastPageLoadEncounterSSLErrors, bool());
57 MOCK_METHOD1(NotifyUserAutoSigninPtr, 57 MOCK_METHOD1(NotifyUserAutoSigninPtr,
58 bool(const std::vector<autofill::PasswordForm*>& local_forms)); 58 bool(const std::vector<autofill::PasswordForm*>& local_forms));
59 MOCK_METHOD1(NotifyUserAutoSigninBlockedOnFirstRunPtr, 59 MOCK_METHOD1(NotifyUserCouldBeAutoSignedInPtr,
60 bool(autofill::PasswordForm* form)); 60 bool(autofill::PasswordForm* form));
61 MOCK_METHOD2(PromptUserToSavePasswordPtr, 61 MOCK_METHOD2(PromptUserToSavePasswordPtr,
62 void(PasswordFormManager*, CredentialSourceType type)); 62 void(PasswordFormManager*, CredentialSourceType type));
63 MOCK_METHOD4(PromptUserToChooseCredentialsPtr, 63 MOCK_METHOD4(PromptUserToChooseCredentialsPtr,
64 bool(const std::vector<autofill::PasswordForm*>& local_forms, 64 bool(const std::vector<autofill::PasswordForm*>& local_forms,
65 const std::vector<autofill::PasswordForm*>& federated_forms, 65 const std::vector<autofill::PasswordForm*>& federated_forms,
66 const GURL& origin, 66 const GURL& origin,
67 base::Callback<void(const CredentialInfo&)> callback)); 67 base::Callback<void(const CredentialInfo&)> callback));
68 68
69 explicit MockPasswordManagerClient(PasswordStore* store) : store_(store) { 69 explicit MockPasswordManagerClient(PasswordStore* store) : store_(store) {
70 prefs_.registry()->RegisterBooleanPref(prefs::kCredentialsEnableAutosignin, 70 prefs_.registry()->RegisterBooleanPref(prefs::kCredentialsEnableAutosignin,
71 true); 71 true);
72 prefs_.registry()->RegisterBooleanPref( 72 prefs_.registry()->RegisterBooleanPref(
73 prefs::kWasAutoSignInFirstRunExperienceShown, true); 73 prefs::kWasAutoSignInFirstRunExperienceShown, true);
74 } 74 }
75 ~MockPasswordManagerClient() override {} 75 ~MockPasswordManagerClient() override {}
76 76
77 bool PromptUserToSaveOrUpdatePassword(scoped_ptr<PasswordFormManager> manager, 77 bool PromptUserToSaveOrUpdatePassword(scoped_ptr<PasswordFormManager> manager,
78 CredentialSourceType type, 78 CredentialSourceType type,
79 bool update_password) override { 79 bool update_password) override {
80 manager_.swap(manager); 80 manager_.swap(manager);
81 PromptUserToSavePasswordPtr(manager_.get(), type); 81 PromptUserToSavePasswordPtr(manager_.get(), type);
82 return true; 82 return true;
83 } 83 }
84 84
85 void NotifyUserAutoSigninBlockedOnFirstRun( 85 void NotifyUserCouldBeAutoSignedIn(
86 scoped_ptr<autofill::PasswordForm> form) override { 86 scoped_ptr<autofill::PasswordForm> form) override {
87 NotifyUserAutoSigninBlockedOnFirstRunPtr(form.get()); 87 NotifyUserCouldBeAutoSignedInPtr(form.get());
88 } 88 }
89 89
90 PasswordStore* GetPasswordStore() const override { return store_; } 90 PasswordStore* GetPasswordStore() const override { return store_; }
91 91
92 PrefService* GetPrefs() override { return &prefs_; } 92 PrefService* GetPrefs() override { return &prefs_; }
93 93
94 bool PromptUserToChooseCredentials( 94 bool PromptUserToChooseCredentials(
95 ScopedVector<autofill::PasswordForm> local_forms, 95 ScopedVector<autofill::PasswordForm> local_forms,
96 ScopedVector<autofill::PasswordForm> federated_forms, 96 ScopedVector<autofill::PasswordForm> federated_forms,
97 const GURL& origin, 97 const GURL& origin,
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 base::get<1>(send_param).type); 619 base::get<1>(send_param).type);
620 } 620 }
621 621
622 TEST_F(CredentialManagerDispatcherTest, 622 TEST_F(CredentialManagerDispatcherTest,
623 CredentialManagerOnRequestCredentialWithZeroClickOnlyFullPasswordStore) { 623 CredentialManagerOnRequestCredentialWithZeroClickOnlyFullPasswordStore) {
624 store_->AddLogin(form_); 624 store_->AddLogin(form_);
625 client_->set_first_run_seen(true); 625 client_->set_first_run_seen(true);
626 626
627 std::vector<GURL> federations; 627 std::vector<GURL> federations;
628 628
629 EXPECT_CALL(*client_, NotifyUserAutoSigninBlockedOnFirstRunPtr(_)).Times(0); 629 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0);
630 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); 630 dispatcher()->OnRequestCredential(kRequestId, true, true, federations);
631 631
632 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_PASSWORD); 632 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_PASSWORD);
633 } 633 }
634 634
635 TEST_F(CredentialManagerDispatcherTest, 635 TEST_F(CredentialManagerDispatcherTest,
636 CredentialManagerOnRequestCredentialWithoutPasswords) { 636 CredentialManagerOnRequestCredentialWithoutPasswords) {
637 store_->AddLogin(form_); 637 store_->AddLogin(form_);
638 client_->set_first_run_seen(true); 638 client_->set_first_run_seen(true);
639 639
640 std::vector<GURL> federations; 640 std::vector<GURL> federations;
641 641
642 EXPECT_CALL(*client_, NotifyUserAutoSigninBlockedOnFirstRunPtr(_)).Times(0); 642 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0);
643 dispatcher()->OnRequestCredential(kRequestId, true, false, federations); 643 dispatcher()->OnRequestCredential(kRequestId, true, false, federations);
644 644
645 ExpectZeroClickSignInFailure(); 645 ExpectZeroClickSignInFailure();
646 } 646 }
647 647
648 TEST_F(CredentialManagerDispatcherTest, 648 TEST_F(CredentialManagerDispatcherTest,
649 CredentialManagerOnRequestCredentialFederatedMatch) { 649 CredentialManagerOnRequestCredentialFederatedMatch) {
650 form_.federation_origin = url::Origin(GURL("https://example.com/")); 650 form_.federation_origin = url::Origin(GURL("https://example.com/"));
651 store_->AddLogin(form_); 651 store_->AddLogin(form_);
652 client_->set_first_run_seen(true); 652 client_->set_first_run_seen(true);
653 653
654 std::vector<GURL> federations; 654 std::vector<GURL> federations;
655 federations.push_back(GURL("https://example.com/")); 655 federations.push_back(GURL("https://example.com/"));
656 656
657 EXPECT_CALL(*client_, NotifyUserAutoSigninBlockedOnFirstRunPtr(_)).Times(0); 657 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0);
658 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); 658 dispatcher()->OnRequestCredential(kRequestId, true, true, federations);
659 659
660 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_FEDERATED); 660 ExpectZeroClickSignInSuccess(CredentialType::CREDENTIAL_TYPE_FEDERATED);
661 } 661 }
662 662
663 TEST_F(CredentialManagerDispatcherTest, 663 TEST_F(CredentialManagerDispatcherTest,
664 CredentialManagerOnRequestCredentialFederatedNoMatch) { 664 CredentialManagerOnRequestCredentialFederatedNoMatch) {
665 form_.federation_origin = url::Origin(GURL("https://example.com/")); 665 form_.federation_origin = url::Origin(GURL("https://example.com/"));
666 store_->AddLogin(form_); 666 store_->AddLogin(form_);
667 client_->set_first_run_seen(true); 667 client_->set_first_run_seen(true);
668 668
669 std::vector<GURL> federations; 669 std::vector<GURL> federations;
670 federations.push_back(GURL("https://not-example.com/")); 670 federations.push_back(GURL("https://not-example.com/"));
671 671
672 EXPECT_CALL(*client_, NotifyUserAutoSigninBlockedOnFirstRunPtr(_)).Times(0); 672 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0);
673 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); 673 dispatcher()->OnRequestCredential(kRequestId, true, true, federations);
674 674
675 ExpectZeroClickSignInFailure(); 675 ExpectZeroClickSignInFailure();
676 } 676 }
677 677
678 TEST_F(CredentialManagerDispatcherTest, 678 TEST_F(CredentialManagerDispatcherTest,
679 CredentialManagerOnRequestCredentialAffiliatedPasswordMatch) { 679 CredentialManagerOnRequestCredentialAffiliatedPasswordMatch) {
680 store_->AddLogin(affiliated_form1_); 680 store_->AddLogin(affiliated_form1_);
681 client_->set_first_run_seen(true); 681 client_->set_first_run_seen(true);
682 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper); 682 auto mock_helper = make_scoped_ptr(new MockAffiliatedMatchHelper);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 ExpectZeroClickSignInFailure(); 763 ExpectZeroClickSignInFailure();
764 } 764 }
765 765
766 TEST_F(CredentialManagerDispatcherTest, RequestCredentialWithoutFirstRun) { 766 TEST_F(CredentialManagerDispatcherTest, RequestCredentialWithoutFirstRun) {
767 client_->set_first_run_seen(false); 767 client_->set_first_run_seen(false);
768 768
769 store_->AddLogin(form_); 769 store_->AddLogin(form_);
770 770
771 std::vector<GURL> federations; 771 std::vector<GURL> federations;
772 EXPECT_CALL(*client_, 772 EXPECT_CALL(*client_,
773 NotifyUserAutoSigninBlockedOnFirstRunPtr(testing::Pointee(form_))) 773 NotifyUserCouldBeAutoSignedInPtr(testing::Pointee(form_)))
774 .Times(1); 774 .Times(1);
775 dispatcher()->OnRequestCredential(kRequestId, true, true, federations); 775 dispatcher()->OnRequestCredential(kRequestId, true, true, federations);
776 776
777 ExpectZeroClickSignInFailure();
778 }
779
780 TEST_F(CredentialManagerDispatcherTest, RequestCredentialWithFirstRunAndSkip) {
781 client_->set_first_run_seen(true);
782
783 form_.skip_zero_click = true;
784 store_->AddLogin(form_);
785
786 std::vector<GURL> federations;
787 EXPECT_CALL(*client_,
788 NotifyUserCouldBeAutoSignedInPtr(testing::Pointee(form_)))
789 .Times(1);
790 dispatcher()->OnRequestCredential(kRequestId, true, true, federations);
791
777 ExpectZeroClickSignInFailure(); 792 ExpectZeroClickSignInFailure();
778 } 793 }
779 794
780 TEST_F(CredentialManagerDispatcherTest, RequestCredentialWithTLSErrors) { 795 TEST_F(CredentialManagerDispatcherTest, RequestCredentialWithTLSErrors) {
781 // If we encounter TLS errors, we won't return credentials. 796 // If we encounter TLS errors, we won't return credentials.
782 EXPECT_CALL(*client_, DidLastPageLoadEncounterSSLErrors()) 797 EXPECT_CALL(*client_, DidLastPageLoadEncounterSSLErrors())
783 .WillRepeatedly(testing::Return(true)); 798 .WillRepeatedly(testing::Return(true));
784 799
785 store_->AddLogin(form_); 800 store_->AddLogin(form_);
786 801
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 TEST_F(CredentialManagerDispatcherTest, GetSynthesizedFormForOrigin) { 1120 TEST_F(CredentialManagerDispatcherTest, GetSynthesizedFormForOrigin) {
1106 autofill::PasswordForm synthesized = 1121 autofill::PasswordForm synthesized =
1107 dispatcher_->GetSynthesizedFormForOrigin(); 1122 dispatcher_->GetSynthesizedFormForOrigin();
1108 EXPECT_EQ(kTestWebOrigin, synthesized.origin.spec()); 1123 EXPECT_EQ(kTestWebOrigin, synthesized.origin.spec());
1109 EXPECT_EQ(kTestWebOrigin, synthesized.signon_realm); 1124 EXPECT_EQ(kTestWebOrigin, synthesized.signon_realm);
1110 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, synthesized.scheme); 1125 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, synthesized.scheme);
1111 EXPECT_TRUE(synthesized.ssl_valid); 1126 EXPECT_TRUE(synthesized.ssl_valid);
1112 } 1127 }
1113 1128
1114 } // namespace password_manager 1129 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698