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 3 // found in the LICENSE file. 4 5 #ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_STUB_PASSWORD_MANAGER_CLIENT_H_ 6 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_STUB_PASSWORD_MANAGER_CLIENT_H_ 7 8 #include "base/macros.h" 9 #include "base/optional.h" 10 #include "components/autofill/core/browser/logging/stub_log_manager.h" 11 #include "components/password_manager/core/browser/mock_password_feature_manager.h" 12 #include "components/password_manager/core/browser/password_manager_client.h" 13 #include "components/password_manager/core/browser/password_manager_metrics_recorder.h" 14 #include "components/password_manager/core/browser/password_manager_metrics_util.h" 15 #include "components/password_manager/core/browser/password_reuse_detector.h" 16 #include "components/password_manager/core/browser/stub_credentials_filter.h" 17 #include "testing/gmock/include/gmock/gmock.h" 18 19 namespace password_manager { 20 21 // Use this class as a base for mock or test clients to avoid stubbing 22 // uninteresting pure virtual methods. All the implemented methods are just 23 // trivial stubs. Do NOT use in production, only use in tests. 24 class StubPasswordManagerClient : public PasswordManagerClient { 25 public: 26 StubPasswordManagerClient(); 27 ~StubPasswordManagerClient() override; 28 29 // PasswordManagerClient: 30 bool PromptUserToSaveOrUpdatePassword( 31 std::unique_ptr<PasswordFormManagerForUI> form_to_save, 32 bool update_password) override; 33 bool ShowOnboarding( 34 std::unique_ptr<PasswordFormManagerForUI> form_to_save) override; 35 void ShowManualFallbackForSaving( 36 std::unique_ptr<PasswordFormManagerForUI> form_to_save, 37 bool has_generated_password, 38 bool update_password) override; 39 void HideManualFallbackForSaving() override; 40 void FocusedInputChanged( 41 password_manager::PasswordManagerDriver* driver, 42 autofill::mojom::FocusedFieldType focused_field_type) override; 43 bool PromptUserToChooseCredentials( 44 std::vector<std::unique_ptr<autofill::PasswordForm>> local_forms, 45 const GURL& origin, 46 const CredentialsCallback& callback) override; 47 void NotifyUserAutoSignin( 48 std::vector<std::unique_ptr<autofill::PasswordForm>> local_forms, 49 const GURL& origin) override; 50 void NotifyUserCouldBeAutoSignedIn( 51 std::unique_ptr<autofill::PasswordForm>) override; 52 void NotifySuccessfulLoginWithExistingPassword( 53 const autofill::PasswordForm& form) override; 54 void NotifyStorePasswordCalled() override; 55 void AutomaticPasswordSave( 56 std::unique_ptr<PasswordFormManagerForUI> saved_manager) override; 57 PrefService* GetPrefs() const override; 58 PasswordStore* GetProfilePasswordStore() const override; 59 PasswordStore* GetAccountPasswordStore() const override; 60 const GURL& GetLastCommittedEntryURL() const override; 61 const CredentialsFilter* GetStoreResultFilter() const override; 62 const autofill::LogManager* GetLogManager() const override; 63 const MockPasswordFeatureManager* GetPasswordFeatureManager() const override; 64 MockPasswordFeatureManager* GetPasswordFeatureManager(); 65 66 #if defined(ON_FOCUS_PING_ENABLED) || \ 67 defined(SYNC_PASSWORD_REUSE_DETECTION_ENABLED) 68 safe_browsing::PasswordProtectionService* GetPasswordProtectionService() 69 const override; 70 #endif 71 72 #if defined(ON_FOCUS_PING_ENABLED) 73 void CheckSafeBrowsingReputation(const GURL& form_action, 74 const GURL& frame_url) override; 75 #endif 76 77 #if defined(SYNC_PASSWORD_REUSE_DETECTION_ENABLED) 78 void CheckProtectedPasswordEntry( 79 metrics_util::PasswordType reused_password_type, 80 const std::string& username, 81 const std::vector<MatchingReusedCredential>& matching_reused_credentials, 82 bool password_field_exists) override; 83 #endif 84 85 #if defined(SYNC_PASSWORD_REUSE_WARNING_ENABLED) 86 void LogPasswordReuseDetectedEvent() override; 87 #endif 88 89 ukm::SourceId GetUkmSourceId() override; 90 PasswordManagerMetricsRecorder* GetMetricsRecorder() override; 91 signin::IdentityManager* GetIdentityManager() override; 92 scoped_refptr<network::SharedURLLoaderFactory> GetURLLoaderFactory() override; 93 bool IsIsolationForPasswordSitesEnabled() const override; 94 bool IsNewTabPage() const override; 95 FieldInfoManager* GetFieldInfoManager() const override; 96 97 private: 98 const StubCredentialsFilter credentials_filter_; 99 testing::NiceMock<MockPasswordFeatureManager> password_feature_manager_; 100 autofill::StubLogManager log_manager_; 101 ukm::SourceId ukm_source_id_; 102 base::Optional<PasswordManagerMetricsRecorder> metrics_recorder_; 103 104 DISALLOW_COPY_AND_ASSIGN(StubPasswordManagerClient); 105 }; 106 107 } // namespace password_manager 108 109 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_STUB_PASSWORD_MANAGER_CLIENT_H_ 110