test_password_store.cc revision c5cede9ae108bb15f6b7a8aea21c7e1fefa2834c
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#include "components/password_manager/core/browser/test_password_store.h" 6 7#include "components/autofill/core/common/password_form.h" 8 9namespace password_manager { 10 11TestPasswordStore::TestPasswordStore() 12 : PasswordStore(base::MessageLoopProxy::current(), 13 base::MessageLoopProxy::current()) { 14} 15 16TestPasswordStore::~TestPasswordStore() {} 17 18TestPasswordStore::PasswordMap TestPasswordStore::stored_passwords() { 19 return stored_passwords_; 20} 21 22void TestPasswordStore::Clear() { 23 stored_passwords_.clear(); 24} 25 26bool 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; 33} 34 35void TestPasswordStore::WrapModificationTask(ModificationTask task) { 36 task.Run(); 37} 38 39PasswordStoreChangeList TestPasswordStore::AddLoginImpl( 40 const autofill::PasswordForm& form) { 41 PasswordStoreChangeList changes; 42 stored_passwords_[form.signon_realm].push_back(form); 43 changes.push_back(PasswordStoreChange(PasswordStoreChange::ADD, form)); 44 return changes; 45} 46 47PasswordStoreChangeList TestPasswordStore::UpdateLoginImpl( 48 const autofill::PasswordForm& form) { 49 PasswordStoreChangeList changes; 50 std::vector<autofill::PasswordForm>& forms = 51 stored_passwords_[form.signon_realm]; 52 for (std::vector<autofill::PasswordForm>::iterator it = forms.begin(); 53 it != forms.end(); ++it) { 54 if (FormsAreEquivalent(form, *it)) { 55 *it = form; 56 changes.push_back( 57 PasswordStoreChange(PasswordStoreChange::UPDATE, form)); 58 } 59 } 60 return changes; 61} 62 63PasswordStoreChangeList TestPasswordStore::RemoveLoginImpl( 64 const autofill::PasswordForm& form) { 65 PasswordStoreChangeList changes; 66 std::vector<autofill::PasswordForm>& forms = 67 stored_passwords_[form.signon_realm]; 68 std::vector<autofill::PasswordForm>::iterator it = forms.begin(); 69 while (it != forms.end()) { 70 if (FormsAreEquivalent(form, *it)) { 71 it = forms.erase(it); 72 changes.push_back( 73 PasswordStoreChange(PasswordStoreChange::REMOVE, form)); 74 } else { 75 ++it; 76 } 77 } 78 return changes; 79} 80 81void TestPasswordStore::GetLoginsImpl( 82 const autofill::PasswordForm& form, 83 PasswordStore::AuthorizationPromptPolicy prompt_policy, 84 const PasswordStore::ConsumerCallbackRunner& runner) { 85 std::vector<autofill::PasswordForm*> matched_forms; 86 std::vector<autofill::PasswordForm> forms = 87 stored_passwords_[form.signon_realm]; 88 for (std::vector<autofill::PasswordForm>::iterator it = forms.begin(); 89 it != forms.end(); ++it) { 90 matched_forms.push_back(new autofill::PasswordForm(*it)); 91 } 92 runner.Run(matched_forms); 93} 94 95PasswordStoreChangeList TestPasswordStore::RemoveLoginsCreatedBetweenImpl( 96 const base::Time& begin, const base::Time& end) { 97 PasswordStoreChangeList changes; 98 return changes; 99} 100 101bool TestPasswordStore::FillAutofillableLogins( 102 std::vector<autofill::PasswordForm*>* forms) { 103 return true; 104} 105 106bool TestPasswordStore::FillBlacklistLogins( 107 std::vector<autofill::PasswordForm*>* forms) { 108 return true; 109} 110 111} // namespace password_manager 112