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_TEST_PASSWORD_STORE_H_ 6 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_TEST_PASSWORD_STORE_H_ 7 8 #include <map> 9 #include <string> 10 #include <vector> 11 12 #include "base/memory/ref_counted.h" 13 #include "components/password_manager/core/browser/password_store.h" 14 15 namespace content { 16 class BrowserContext; 17 } 18 19 namespace password_manager { 20 21 // A very simple PasswordStore implementation that keeps all of the passwords 22 // in memory and does all its manipulations on the main thread. Since this 23 // is only used for testing, only the parts of the interface that are needed 24 // for testing have been implemented. 25 class TestPasswordStore : public PasswordStore { 26 public: 27 TestPasswordStore(); 28 29 typedef std::map<std::string /* signon_realm */, 30 std::vector<autofill::PasswordForm> > PasswordMap; 31 32 const PasswordMap& stored_passwords() const; 33 void Clear(); 34 35 // Returns true if no passwords are stored in the store. Note that this is not 36 // as simple as asking whether stored_passwords().empty(), because the map can 37 // have entries of size 0. 38 bool IsEmpty() const; 39 40 protected: 41 virtual ~TestPasswordStore(); 42 43 // Helper function to determine if forms are considered equivalent. 44 bool FormsAreEquivalent(const autofill::PasswordForm& lhs, 45 const autofill::PasswordForm& rhs); 46 47 // PasswordStore interface 48 virtual PasswordStoreChangeList AddLoginImpl( 49 const autofill::PasswordForm& form) OVERRIDE; 50 virtual PasswordStoreChangeList UpdateLoginImpl( 51 const autofill::PasswordForm& form) OVERRIDE; 52 virtual PasswordStoreChangeList RemoveLoginImpl( 53 const autofill::PasswordForm& form) OVERRIDE; 54 virtual void GetLoginsImpl( 55 const autofill::PasswordForm& form, 56 PasswordStore::AuthorizationPromptPolicy prompt_policy, 57 const ConsumerCallbackRunner& runner) OVERRIDE; 58 virtual void WrapModificationTask(ModificationTask task) OVERRIDE; 59 60 // Unused portions of PasswordStore interface 61 virtual void ReportMetricsImpl() OVERRIDE {} 62 virtual PasswordStoreChangeList RemoveLoginsCreatedBetweenImpl( 63 base::Time begin, 64 base::Time end) OVERRIDE; 65 virtual PasswordStoreChangeList RemoveLoginsSyncedBetweenImpl( 66 base::Time delete_begin, 67 base::Time delete_end) OVERRIDE; 68 virtual void GetAutofillableLoginsImpl( 69 PasswordStore::GetLoginsRequest* request) OVERRIDE {} 70 virtual void GetBlacklistLoginsImpl( 71 PasswordStore::GetLoginsRequest* request) OVERRIDE {} 72 virtual bool FillAutofillableLogins( 73 std::vector<autofill::PasswordForm*>* forms) OVERRIDE; 74 virtual bool FillBlacklistLogins( 75 std::vector<autofill::PasswordForm*>* forms) OVERRIDE; 76 77 private: 78 PasswordMap stored_passwords_; 79 80 DISALLOW_COPY_AND_ASSIGN(TestPasswordStore); 81 }; 82 83 } // namespace password_manager 84 85 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_TEST_PASSWORD_STORE_H_ 86