Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / password_manager / test_password_store.cc
blob5f8744f0cc829c48746492fa2016ed800f7236ef
1 // Copyright 2013 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.
5 #include "chrome/browser/password_manager/test_password_store.h"
7 #include "components/autofill/core/common/password_form.h"
9 // static
10 scoped_refptr<RefcountedBrowserContextKeyedService> TestPasswordStore::Create(
11 content::BrowserContext* profile) {
12 return make_scoped_refptr(new TestPasswordStore);
15 TestPasswordStore::TestPasswordStore() : PasswordStore() {}
16 TestPasswordStore::~TestPasswordStore() {}
18 TestPasswordStore::PasswordMap TestPasswordStore::stored_passwords() {
19 return stored_passwords_;
22 void TestPasswordStore::Clear() {
23 stored_passwords_.clear();
26 bool TestPasswordStore::FormsAreEquivalent(const autofill::PasswordForm& lhs,
27 const autofill::PasswordForm& rhs) {
28 return lhs.origin == rhs.origin &&
29 lhs.username_element == rhs.username_element &&
30 lhs.username_value == rhs.username_value &&
31 lhs.password_element == rhs.password_element &&
32 lhs.signon_realm == rhs.signon_realm;
35 bool TestPasswordStore::ScheduleTask(const base::Closure& task) {
36 task.Run();
37 return true;
40 void TestPasswordStore::WrapModificationTask(base::Closure task) {
41 task.Run();
44 void TestPasswordStore::AddLoginImpl(const autofill::PasswordForm& form) {
45 stored_passwords_[form.signon_realm].push_back(form);
48 void TestPasswordStore::UpdateLoginImpl(const autofill::PasswordForm& form) {
49 std::vector<autofill::PasswordForm>& forms =
50 stored_passwords_[form.signon_realm];
51 for (std::vector<autofill::PasswordForm>::iterator it = forms.begin();
52 it != forms.end(); ++it) {
53 if (FormsAreEquivalent(form, *it)) {
54 *it = form;
59 void TestPasswordStore::RemoveLoginImpl(const autofill::PasswordForm& form) {
60 std::vector<autofill::PasswordForm>& forms =
61 stored_passwords_[form.signon_realm];
62 for (std::vector<autofill::PasswordForm>::iterator it = forms.begin();
63 it != forms.end(); ++it) {
64 if (FormsAreEquivalent(form, *it)) {
65 forms.erase(it);
66 return;
71 void TestPasswordStore::GetLoginsImpl(
72 const autofill::PasswordForm& form,
73 PasswordStore::AuthorizationPromptPolicy prompt_policy,
74 const PasswordStore::ConsumerCallbackRunner& runner) {
75 std::vector<autofill::PasswordForm*> matched_forms;
76 std::vector<autofill::PasswordForm> forms =
77 stored_passwords_[form.signon_realm];
78 for (std::vector<autofill::PasswordForm>::iterator it = forms.begin();
79 it != forms.end(); ++it) {
80 matched_forms.push_back(new autofill::PasswordForm(*it));
82 runner.Run(matched_forms);
85 bool TestPasswordStore::FillAutofillableLogins(
86 std::vector<autofill::PasswordForm*>* forms) {
87 return true;
90 bool TestPasswordStore::FillBlacklistLogins(
91 std::vector<autofill::PasswordForm*>* forms) {
92 return true;