OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/password_manager/test_password_store.h" | 5 #include "chrome/browser/password_manager/test_password_store.h" |
6 | 6 |
7 #include "content/public/common/password_form.h" | 7 #include "components/autofill/core/common/password_form.h" |
8 | 8 |
9 // static | 9 // static |
10 scoped_refptr<RefcountedBrowserContextKeyedService> TestPasswordStore::Create( | 10 scoped_refptr<RefcountedBrowserContextKeyedService> TestPasswordStore::Create( |
11 content::BrowserContext* profile) { | 11 content::BrowserContext* profile) { |
12 return make_scoped_refptr(new TestPasswordStore); | 12 return make_scoped_refptr(new TestPasswordStore); |
13 } | 13 } |
14 | 14 |
15 TestPasswordStore::TestPasswordStore() : PasswordStore() {} | 15 TestPasswordStore::TestPasswordStore() : PasswordStore() {} |
16 TestPasswordStore::~TestPasswordStore() {} | 16 TestPasswordStore::~TestPasswordStore() {} |
17 | 17 |
18 TestPasswordStore::PasswordMap TestPasswordStore::stored_passwords() { | 18 TestPasswordStore::PasswordMap TestPasswordStore::stored_passwords() { |
19 return stored_passwords_; | 19 return stored_passwords_; |
20 } | 20 } |
21 | 21 |
22 void TestPasswordStore::Clear() { | 22 void TestPasswordStore::Clear() { |
23 stored_passwords_.clear(); | 23 stored_passwords_.clear(); |
24 } | 24 } |
25 | 25 |
26 bool TestPasswordStore::FormsAreEquivalent(const content::PasswordForm& lhs, | 26 bool TestPasswordStore::FormsAreEquivalent(const autofill::PasswordForm& lhs, |
27 const content::PasswordForm& rhs) { | 27 const autofill::PasswordForm& rhs) { |
28 return lhs.origin == rhs.origin && | 28 return lhs.origin == rhs.origin && |
29 lhs.username_element == rhs.username_element && | 29 lhs.username_element == rhs.username_element && |
30 lhs.username_value == rhs.username_value && | 30 lhs.username_value == rhs.username_value && |
31 lhs.password_element == rhs.password_element && | 31 lhs.password_element == rhs.password_element && |
32 lhs.signon_realm == rhs.signon_realm; | 32 lhs.signon_realm == rhs.signon_realm; |
33 } | 33 } |
34 | 34 |
35 bool TestPasswordStore::ScheduleTask(const base::Closure& task) { | 35 bool TestPasswordStore::ScheduleTask(const base::Closure& task) { |
36 task.Run(); | 36 task.Run(); |
37 return true; | 37 return true; |
38 } | 38 } |
39 | 39 |
40 void TestPasswordStore::WrapModificationTask(base::Closure task) { | 40 void TestPasswordStore::WrapModificationTask(base::Closure task) { |
41 task.Run(); | 41 task.Run(); |
42 } | 42 } |
43 | 43 |
44 void TestPasswordStore::AddLoginImpl(const content::PasswordForm& form) { | 44 void TestPasswordStore::AddLoginImpl(const autofill::PasswordForm& form) { |
45 stored_passwords_[form.signon_realm].push_back(form); | 45 stored_passwords_[form.signon_realm].push_back(form); |
46 } | 46 } |
47 | 47 |
48 void TestPasswordStore::UpdateLoginImpl(const content::PasswordForm& form) { | 48 void TestPasswordStore::UpdateLoginImpl(const autofill::PasswordForm& form) { |
49 std::vector<content::PasswordForm>& forms = | 49 std::vector<autofill::PasswordForm>& forms = |
50 stored_passwords_[form.signon_realm]; | 50 stored_passwords_[form.signon_realm]; |
51 for (std::vector<content::PasswordForm>::iterator it = forms.begin(); | 51 for (std::vector<autofill::PasswordForm>::iterator it = forms.begin(); |
52 it != forms.end(); ++it) { | 52 it != forms.end(); ++it) { |
53 if (FormsAreEquivalent(form, *it)) { | 53 if (FormsAreEquivalent(form, *it)) { |
54 *it = form; | 54 *it = form; |
55 } | 55 } |
56 } | 56 } |
57 } | 57 } |
58 | 58 |
59 void TestPasswordStore::RemoveLoginImpl(const content::PasswordForm& form) { | 59 void TestPasswordStore::RemoveLoginImpl(const autofill::PasswordForm& form) { |
60 std::vector<content::PasswordForm>& forms = | 60 std::vector<autofill::PasswordForm>& forms = |
61 stored_passwords_[form.signon_realm]; | 61 stored_passwords_[form.signon_realm]; |
62 for (std::vector<content::PasswordForm>::iterator it = forms.begin(); | 62 for (std::vector<autofill::PasswordForm>::iterator it = forms.begin(); |
63 it != forms.end(); ++it) { | 63 it != forms.end(); ++it) { |
64 if (FormsAreEquivalent(form, *it)) { | 64 if (FormsAreEquivalent(form, *it)) { |
65 forms.erase(it); | 65 forms.erase(it); |
66 return; | 66 return; |
67 } | 67 } |
68 } | 68 } |
69 } | 69 } |
70 | 70 |
71 void TestPasswordStore::GetLoginsImpl( | 71 void TestPasswordStore::GetLoginsImpl( |
72 const content::PasswordForm& form, | 72 const autofill::PasswordForm& form, |
73 const PasswordStore::ConsumerCallbackRunner& runner) { | 73 const PasswordStore::ConsumerCallbackRunner& runner) { |
74 std::vector<content::PasswordForm*> matched_forms; | 74 std::vector<autofill::PasswordForm*> matched_forms; |
75 std::vector<content::PasswordForm> forms = | 75 std::vector<autofill::PasswordForm> forms = |
76 stored_passwords_[form.signon_realm]; | 76 stored_passwords_[form.signon_realm]; |
77 for (std::vector<content::PasswordForm>::iterator it = forms.begin(); | 77 for (std::vector<autofill::PasswordForm>::iterator it = forms.begin(); |
78 it != forms.end(); ++it) { | 78 it != forms.end(); ++it) { |
79 matched_forms.push_back(new content::PasswordForm(*it)); | 79 matched_forms.push_back(new autofill::PasswordForm(*it)); |
80 } | 80 } |
81 runner.Run(matched_forms); | 81 runner.Run(matched_forms); |
82 } | 82 } |
83 | 83 |
84 bool TestPasswordStore::FillAutofillableLogins( | 84 bool TestPasswordStore::FillAutofillableLogins( |
85 std::vector<content::PasswordForm*>* forms) { | 85 std::vector<autofill::PasswordForm*>* forms) { |
86 return true; | 86 return true; |
87 } | 87 } |
88 | 88 |
89 bool TestPasswordStore::FillBlacklistLogins( | 89 bool TestPasswordStore::FillBlacklistLogins( |
90 std::vector<content::PasswordForm*>* forms) { | 90 std::vector<autofill::PasswordForm*>* forms) { |
91 return true; | 91 return true; |
92 } | 92 } |
OLD | NEW |