15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
2a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// found in the LICENSE file.
4a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_TEST_PASSWORD_STORE_H_
65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_TEST_PASSWORD_STORE_H_
7a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
8a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include <map>
9a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include <string>
10a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include <vector>
11a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
12a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "base/memory/ref_counted.h"
135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "components/password_manager/core/browser/password_store.h"
14a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
15a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)namespace content {
16a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)class BrowserContext;
17a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
18a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
19c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochnamespace password_manager {
20c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
21a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// A very simple PasswordStore implementation that keeps all of the passwords
225c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// in memory and does all its manipulations on the main thread. Since this
23a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// is only used for testing, only the parts of the interface that are needed
24a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// for testing have been implemented.
25a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)class TestPasswordStore : public PasswordStore {
26a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) public:
27a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  TestPasswordStore();
28a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
29a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  typedef std::map<std::string /* signon_realm */,
3058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                   std::vector<autofill::PasswordForm> > PasswordMap;
31a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
32010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  const PasswordMap& stored_passwords() const;
33a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  void Clear();
34a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
35010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Returns true if no passwords are stored in the store. Note that this is not
36010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // as simple as asking whether stored_passwords().empty(), because the map can
37010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // have entries of size 0.
38010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  bool IsEmpty() const;
39010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
40a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) protected:
41a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual ~TestPasswordStore();
42a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
43a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // Helper function to determine if forms are considered equivalent.
4458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  bool FormsAreEquivalent(const autofill::PasswordForm& lhs,
4558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                          const autofill::PasswordForm& rhs);
46a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
47a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // PasswordStore interface
485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual PasswordStoreChangeList AddLoginImpl(
495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const autofill::PasswordForm& form) OVERRIDE;
505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual PasswordStoreChangeList UpdateLoginImpl(
515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const autofill::PasswordForm& form) OVERRIDE;
525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual PasswordStoreChangeList RemoveLoginImpl(
535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const autofill::PasswordForm& form) OVERRIDE;
545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void GetLoginsImpl(
555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const autofill::PasswordForm& form,
565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      PasswordStore::AuthorizationPromptPolicy prompt_policy,
575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const ConsumerCallbackRunner& runner) OVERRIDE;
585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void WrapModificationTask(ModificationTask task) OVERRIDE;
59a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
60a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // Unused portions of PasswordStore interface
61116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  virtual void ReportMetricsImpl(const std::string& sync_username) OVERRIDE {}
625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual PasswordStoreChangeList RemoveLoginsCreatedBetweenImpl(
636d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)      base::Time begin,
646d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)      base::Time end) OVERRIDE;
65f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  virtual PasswordStoreChangeList RemoveLoginsSyncedBetweenImpl(
66f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      base::Time delete_begin,
67f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      base::Time delete_end) OVERRIDE;
68a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual void GetAutofillableLoginsImpl(
69a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      PasswordStore::GetLoginsRequest* request) OVERRIDE {}
70a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual void GetBlacklistLoginsImpl(
71a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      PasswordStore::GetLoginsRequest* request) OVERRIDE {}
72a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual bool FillAutofillableLogins(
7358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      std::vector<autofill::PasswordForm*>* forms) OVERRIDE;
74a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual bool FillBlacklistLogins(
7558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      std::vector<autofill::PasswordForm*>* forms) OVERRIDE;
76a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
77a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) private:
78a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  PasswordMap stored_passwords_;
79a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
80a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(TestPasswordStore);
81a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)};
82a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
83c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch}  // namespace password_manager
84c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif  // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_TEST_PASSWORD_STORE_H_
86