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. 4 5 #include "chrome/browser/password_manager/test_password_store.h" 6 7 #include "content/public/common/password_form.h" 8 9 // static 10 scoped_refptr<RefcountedBrowserContextKeyedService> TestPasswordStore::Create( 11 content::BrowserContext* profile) { 12 return make_scoped_refptr(new TestPasswordStore); 13 } 14 15 TestPasswordStore::TestPasswordStore() : PasswordStore() {} 16 TestPasswordStore::~TestPasswordStore() {} 17 18 TestPasswordStore::PasswordMap TestPasswordStore::stored_passwords() { 19 return stored_passwords_; 20 } 21 22 void TestPasswordStore::Clear() { 23 stored_passwords_.clear(); 24 } 25 26 bool TestPasswordStore::FormsAreEquivalent(const content::PasswordForm& lhs, 27 const content::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 35 bool TestPasswordStore::ScheduleTask(const base::Closure& task) { 36 task.Run(); 37 return true; 38 } 39 40 void TestPasswordStore::WrapModificationTask(base::Closure task) { 41 task.Run(); 42 } 43 44 void TestPasswordStore::AddLoginImpl(const content::PasswordForm& form) { 45 stored_passwords_[form.signon_realm].push_back(form); 46 } 47 48 void TestPasswordStore::UpdateLoginImpl(const content::PasswordForm& form) { 49 std::vector<content::PasswordForm>& forms = 50 stored_passwords_[form.signon_realm]; 51 for (std::vector<content::PasswordForm>::iterator it = forms.begin(); 52 it != forms.end(); ++it) { 53 if (FormsAreEquivalent(form, *it)) { 54 *it = form; 55 } 56 } 57 } 58 59 void TestPasswordStore::RemoveLoginImpl(const content::PasswordForm& form) { 60 std::vector<content::PasswordForm>& forms = 61 stored_passwords_[form.signon_realm]; 62 for (std::vector<content::PasswordForm>::iterator it = forms.begin(); 63 it != forms.end(); ++it) { 64 if (FormsAreEquivalent(form, *it)) { 65 forms.erase(it); 66 return; 67 } 68 } 69 } 70 71 void TestPasswordStore::GetLoginsImpl( 72 const content::PasswordForm& form, 73 const PasswordStore::ConsumerCallbackRunner& runner) { 74 std::vector<content::PasswordForm*> matched_forms; 75 std::vector<content::PasswordForm> forms = 76 stored_passwords_[form.signon_realm]; 77 for (std::vector<content::PasswordForm>::iterator it = forms.begin(); 78 it != forms.end(); ++it) { 79 matched_forms.push_back(new content::PasswordForm(*it)); 80 } 81 runner.Run(matched_forms); 82 } 83 84 bool TestPasswordStore::FillAutofillableLogins( 85 std::vector<content::PasswordForm*>* forms) { 86 return true; 87 } 88 89 bool TestPasswordStore::FillBlacklistLogins( 90 std::vector<content::PasswordForm*>* forms) { 91 return true; 92 } 93