test_password_store.h revision 5c02ac1a9c1b504631c0a3d2b6e737b5d738bae1
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
15namespace content {
16class BrowserContext;
17}
18
19namespace 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.
25class TestPasswordStore : public PasswordStore {
26 public:
27  TestPasswordStore();
28
29  typedef std::map<std::string /* signon_realm */,
30                   std::vector<autofill::PasswordForm> > PasswordMap;
31
32  PasswordMap stored_passwords();
33  void Clear();
34
35 protected:
36  virtual ~TestPasswordStore();
37
38  // Helper function to determine if forms are considered equivalent.
39  bool FormsAreEquivalent(const autofill::PasswordForm& lhs,
40                          const autofill::PasswordForm& rhs);
41
42  // PasswordStore interface
43  virtual PasswordStoreChangeList AddLoginImpl(
44      const autofill::PasswordForm& form) OVERRIDE;
45  virtual PasswordStoreChangeList UpdateLoginImpl(
46      const autofill::PasswordForm& form) OVERRIDE;
47  virtual PasswordStoreChangeList RemoveLoginImpl(
48      const autofill::PasswordForm& form) OVERRIDE;
49  virtual void GetLoginsImpl(
50      const autofill::PasswordForm& form,
51      PasswordStore::AuthorizationPromptPolicy prompt_policy,
52      const ConsumerCallbackRunner& runner) OVERRIDE;
53  virtual void WrapModificationTask(ModificationTask task) OVERRIDE;
54
55  // Unused portions of PasswordStore interface
56  virtual void ReportMetricsImpl() OVERRIDE {}
57  virtual PasswordStoreChangeList RemoveLoginsCreatedBetweenImpl(
58      const base::Time& begin, const base::Time& end) OVERRIDE;
59  virtual void GetAutofillableLoginsImpl(
60      PasswordStore::GetLoginsRequest* request) OVERRIDE {}
61  virtual void GetBlacklistLoginsImpl(
62      PasswordStore::GetLoginsRequest* request) OVERRIDE {}
63  virtual bool FillAutofillableLogins(
64      std::vector<autofill::PasswordForm*>* forms) OVERRIDE;
65  virtual bool FillBlacklistLogins(
66      std::vector<autofill::PasswordForm*>* forms) OVERRIDE;
67
68 private:
69  PasswordMap stored_passwords_;
70
71  DISALLOW_COPY_AND_ASSIGN(TestPasswordStore);
72};
73
74}  // namespace password_manager
75
76#endif  // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_TEST_PASSWORD_STORE_H_
77