OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 return false; | 73 return false; |
74 } | 74 } |
75 | 75 |
76 bool RemoveLoginsSyncedBetween( | 76 bool RemoveLoginsSyncedBetween( |
77 base::Time delete_begin, | 77 base::Time delete_begin, |
78 base::Time delete_end, | 78 base::Time delete_end, |
79 password_manager::PasswordStoreChangeList* changes) override { | 79 password_manager::PasswordStoreChangeList* changes) override { |
80 return false; | 80 return false; |
81 } | 81 } |
82 | 82 |
| 83 // Use this as a landmine to check whether results of failed Get*Logins calls |
| 84 // get ignored. |
| 85 static ScopedVector<autofill::PasswordForm> CreateTrashForms() { |
| 86 ScopedVector<autofill::PasswordForm> forms; |
| 87 PasswordForm trash; |
| 88 trash.username_element = base::ASCIIToUTF16("trash u. element"); |
| 89 trash.username_value = base::ASCIIToUTF16("trash u. value"); |
| 90 trash.password_element = base::ASCIIToUTF16("trash p. element"); |
| 91 trash.password_value = base::ASCIIToUTF16("trash p. value"); |
| 92 for (size_t i = 0; i < 3; ++i) { |
| 93 trash.origin = GURL(base::StringPrintf("http://trash%zu.com", i)); |
| 94 forms.push_back(new PasswordForm(trash)); |
| 95 } |
| 96 return forms.Pass(); |
| 97 } |
| 98 |
83 bool GetLogins(const PasswordForm& form, | 99 bool GetLogins(const PasswordForm& form, |
84 ScopedVector<autofill::PasswordForm>* forms) override { | 100 ScopedVector<autofill::PasswordForm>* forms) override { |
| 101 *forms = CreateTrashForms(); |
85 return false; | 102 return false; |
86 } | 103 } |
87 | 104 |
88 bool GetAutofillableLogins( | 105 bool GetAutofillableLogins( |
89 ScopedVector<autofill::PasswordForm>* forms) override { | 106 ScopedVector<autofill::PasswordForm>* forms) override { |
| 107 *forms = CreateTrashForms(); |
90 return false; | 108 return false; |
91 } | 109 } |
92 bool GetBlacklistLogins( | 110 bool GetBlacklistLogins( |
93 ScopedVector<autofill::PasswordForm>* forms) override { | 111 ScopedVector<autofill::PasswordForm>* forms) override { |
| 112 *forms = CreateTrashForms(); |
94 return false; | 113 return false; |
95 } | 114 } |
96 }; | 115 }; |
97 | 116 |
98 class MockBackend : public PasswordStoreX::NativeBackend { | 117 class MockBackend : public PasswordStoreX::NativeBackend { |
99 public: | 118 public: |
100 bool Init() override { return true; } | 119 bool Init() override { return true; } |
101 | 120 |
102 PasswordStoreChangeList AddLogin(const PasswordForm& form) override { | 121 PasswordStoreChangeList AddLogin(const PasswordForm& form) override { |
103 all_forms_.push_back(form); | 122 all_forms_.push_back(form); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 public: | 219 public: |
201 MOCK_METHOD1(OnLoginDatabaseQueryDone, | 220 MOCK_METHOD1(OnLoginDatabaseQueryDone, |
202 void(const std::vector<PasswordForm*>&)); | 221 void(const std::vector<PasswordForm*>&)); |
203 }; | 222 }; |
204 | 223 |
205 void LoginDatabaseQueryCallback(password_manager::LoginDatabase* login_db, | 224 void LoginDatabaseQueryCallback(password_manager::LoginDatabase* login_db, |
206 bool autofillable, | 225 bool autofillable, |
207 MockLoginDatabaseReturn* mock_return) { | 226 MockLoginDatabaseReturn* mock_return) { |
208 ScopedVector<autofill::PasswordForm> forms; | 227 ScopedVector<autofill::PasswordForm> forms; |
209 if (autofillable) | 228 if (autofillable) |
210 login_db->GetAutofillableLogins(&forms); | 229 EXPECT_TRUE(login_db->GetAutofillableLogins(&forms)); |
211 else | 230 else |
212 login_db->GetBlacklistLogins(&forms); | 231 EXPECT_TRUE(login_db->GetBlacklistLogins(&forms)); |
213 mock_return->OnLoginDatabaseQueryDone(forms.get()); | 232 mock_return->OnLoginDatabaseQueryDone(forms.get()); |
214 } | 233 } |
215 | 234 |
216 // Generate |count| expected logins, either auto-fillable or blacklisted. | 235 // Generate |count| expected logins, either auto-fillable or blacklisted. |
217 void InitExpectedForms(bool autofillable, | 236 void InitExpectedForms(bool autofillable, |
218 size_t count, | 237 size_t count, |
219 ScopedVector<autofill::PasswordForm>* forms) { | 238 ScopedVector<autofill::PasswordForm>* forms) { |
220 const char* domain = autofillable ? "example" : "blacklisted"; | 239 const char* domain = autofillable ? "example" : "blacklisted"; |
221 for (size_t i = 0; i < count; ++i) { | 240 for (size_t i = 0; i < count; ++i) { |
222 std::string realm = base::StringPrintf("http://%zu.%s.com", i, domain); | 241 std::string realm = base::StringPrintf("http://%zu.%s.com", i, domain); |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 | 478 |
460 INSTANTIATE_TEST_CASE_P(NoBackend, | 479 INSTANTIATE_TEST_CASE_P(NoBackend, |
461 PasswordStoreXTest, | 480 PasswordStoreXTest, |
462 testing::Values(NO_BACKEND)); | 481 testing::Values(NO_BACKEND)); |
463 INSTANTIATE_TEST_CASE_P(FailingBackend, | 482 INSTANTIATE_TEST_CASE_P(FailingBackend, |
464 PasswordStoreXTest, | 483 PasswordStoreXTest, |
465 testing::Values(FAILING_BACKEND)); | 484 testing::Values(FAILING_BACKEND)); |
466 INSTANTIATE_TEST_CASE_P(WorkingBackend, | 485 INSTANTIATE_TEST_CASE_P(WorkingBackend, |
467 PasswordStoreXTest, | 486 PasswordStoreXTest, |
468 testing::Values(WORKING_BACKEND)); | 487 testing::Values(WORKING_BACKEND)); |
OLD | NEW |