Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(650)

Side by Side Diff: chrome/browser/password_manager/password_store_x_unittest.cc

Issue 906973007: PasswordStore: Clean up expectations about rewriting vectors of forms (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove clear() Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 // Inserts some unexpected values into |forms|. Useful as a landmine to check
84 // whether results of failed Get*Logins calls get ignored.
85 static InsertTrashForms(ScopedVector<autofill::PasswordForm>* forms) {
86 PasswordForm trash;
87 trash.username_element = base::ASCIIToUTF16("trash u. element");
88 trash.username_value = base::ASCIIToUTF16("trash u. value");
89 trash.password_element = base::ASCIIToUTF16("trash p. element");
90 trash.password_value = base::ASCIIToUTF16("trash p. value");
91 for (size_t i = 0; i < 3; ++i) {
92 trash.origin = base::StringPrintf("http://trash%zu.com", i);
93 forms->push_back(new PasswordForm(trash));
94 }
95 }
96
83 bool GetLogins(const PasswordForm& form, 97 bool GetLogins(const PasswordForm& form,
84 ScopedVector<autofill::PasswordForm>* forms) override { 98 ScopedVector<autofill::PasswordForm>* forms) override {
99 InsertTrashForms(forms);
85 return false; 100 return false;
86 } 101 }
87 102
88 bool GetAutofillableLogins( 103 bool GetAutofillableLogins(
89 ScopedVector<autofill::PasswordForm>* forms) override { 104 ScopedVector<autofill::PasswordForm>* forms) override {
105 InsertTrashForms(forms);
90 return false; 106 return false;
91 } 107 }
92 bool GetBlacklistLogins( 108 bool GetBlacklistLogins(
93 ScopedVector<autofill::PasswordForm>* forms) override { 109 ScopedVector<autofill::PasswordForm>* forms) override {
110 InsertTrashForms(forms);
94 return false; 111 return false;
95 } 112 }
96 }; 113 };
97 114
98 class MockBackend : public PasswordStoreX::NativeBackend { 115 class MockBackend : public PasswordStoreX::NativeBackend {
99 public: 116 public:
100 bool Init() override { return true; } 117 bool Init() override { return true; }
101 118
102 PasswordStoreChangeList AddLogin(const PasswordForm& form) override { 119 PasswordStoreChangeList AddLogin(const PasswordForm& form) override {
103 all_forms_.push_back(form); 120 all_forms_.push_back(form);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 public: 217 public:
201 MOCK_METHOD1(OnLoginDatabaseQueryDone, 218 MOCK_METHOD1(OnLoginDatabaseQueryDone,
202 void(const std::vector<PasswordForm*>&)); 219 void(const std::vector<PasswordForm*>&));
203 }; 220 };
204 221
205 void LoginDatabaseQueryCallback(password_manager::LoginDatabase* login_db, 222 void LoginDatabaseQueryCallback(password_manager::LoginDatabase* login_db,
206 bool autofillable, 223 bool autofillable,
207 MockLoginDatabaseReturn* mock_return) { 224 MockLoginDatabaseReturn* mock_return) {
208 ScopedVector<autofill::PasswordForm> forms; 225 ScopedVector<autofill::PasswordForm> forms;
209 if (autofillable) 226 if (autofillable)
210 login_db->GetAutofillableLogins(&forms); 227 EXPECT_TRUE(login_db->GetAutofillableLogins(&forms));
211 else 228 else
212 login_db->GetBlacklistLogins(&forms); 229 EXPECT_TRUE(login_db->GetBlacklistLogins(&forms));
213 mock_return->OnLoginDatabaseQueryDone(forms.get()); 230 mock_return->OnLoginDatabaseQueryDone(forms.get());
214 } 231 }
215 232
216 // Generate |count| expected logins, either auto-fillable or blacklisted. 233 // Generate |count| expected logins, either auto-fillable or blacklisted.
217 void InitExpectedForms(bool autofillable, 234 void InitExpectedForms(bool autofillable,
218 size_t count, 235 size_t count,
219 ScopedVector<autofill::PasswordForm>* forms) { 236 ScopedVector<autofill::PasswordForm>* forms) {
220 const char* domain = autofillable ? "example" : "blacklisted"; 237 const char* domain = autofillable ? "example" : "blacklisted";
221 for (size_t i = 0; i < count; ++i) { 238 for (size_t i = 0; i < count; ++i) {
222 std::string realm = base::StringPrintf("http://%zu.%s.com", i, domain); 239 std::string realm = base::StringPrintf("http://%zu.%s.com", i, domain);
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 476
460 INSTANTIATE_TEST_CASE_P(NoBackend, 477 INSTANTIATE_TEST_CASE_P(NoBackend,
461 PasswordStoreXTest, 478 PasswordStoreXTest,
462 testing::Values(NO_BACKEND)); 479 testing::Values(NO_BACKEND));
463 INSTANTIATE_TEST_CASE_P(FailingBackend, 480 INSTANTIATE_TEST_CASE_P(FailingBackend,
464 PasswordStoreXTest, 481 PasswordStoreXTest,
465 testing::Values(FAILING_BACKEND)); 482 testing::Values(FAILING_BACKEND));
466 INSTANTIATE_TEST_CASE_P(WorkingBackend, 483 INSTANTIATE_TEST_CASE_P(WorkingBackend,
467 PasswordStoreXTest, 484 PasswordStoreXTest,
468 testing::Values(WORKING_BACKEND)); 485 testing::Values(WORKING_BACKEND));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698