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

Side by Side Diff: components/password_manager/core/browser/password_store_default_unittest.cc

Issue 2053913002: Remove MessageLoop::current()->RunUntilIdle() in components. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 "components/password_manager/core/browser/password_store_default.h" 5 #include "components/password_manager/core/browser/password_store_default.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 std::unique_ptr<LoginDatabase> database) { 116 std::unique_ptr<LoginDatabase> database) {
117 SetupTempDir(); 117 SetupTempDir();
118 store_ = CreateInitializedStore(std::move(database)); 118 store_ = CreateInitializedStore(std::move(database));
119 } 119 }
120 120
121 PasswordStoreDefaultTestDelegate::~PasswordStoreDefaultTestDelegate() { 121 PasswordStoreDefaultTestDelegate::~PasswordStoreDefaultTestDelegate() {
122 ClosePasswordStore(); 122 ClosePasswordStore();
123 } 123 }
124 124
125 void PasswordStoreDefaultTestDelegate::FinishAsyncProcessing() { 125 void PasswordStoreDefaultTestDelegate::FinishAsyncProcessing() {
126 base::MessageLoop::current()->RunUntilIdle(); 126 base::RunLoop().RunUntilIdle();
127 } 127 }
128 128
129 void PasswordStoreDefaultTestDelegate::SetupTempDir() { 129 void PasswordStoreDefaultTestDelegate::SetupTempDir() {
130 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 130 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
131 } 131 }
132 132
133 void PasswordStoreDefaultTestDelegate::ClosePasswordStore() { 133 void PasswordStoreDefaultTestDelegate::ClosePasswordStore() {
134 store_->ShutdownOnUIThread(); 134 store_->ShutdownOnUIThread();
135 base::MessageLoop::current()->RunUntilIdle(); 135 base::RunLoop().RunUntilIdle();
136 ASSERT_TRUE(temp_dir_.Delete()); 136 ASSERT_TRUE(temp_dir_.Delete());
137 } 137 }
138 138
139 scoped_refptr<PasswordStoreDefault> 139 scoped_refptr<PasswordStoreDefault>
140 PasswordStoreDefaultTestDelegate::CreateInitializedStore( 140 PasswordStoreDefaultTestDelegate::CreateInitializedStore(
141 std::unique_ptr<LoginDatabase> database) { 141 std::unique_ptr<LoginDatabase> database) {
142 scoped_refptr<PasswordStoreDefault> store(new PasswordStoreDefault( 142 scoped_refptr<PasswordStoreDefault> store(new PasswordStoreDefault(
143 base::ThreadTaskRunnerHandle::Get(), base::ThreadTaskRunnerHandle::Get(), 143 base::ThreadTaskRunnerHandle::Get(), base::ThreadTaskRunnerHandle::Get(),
144 std::move(database))); 144 std::move(database)));
145 store->Init(syncer::SyncableService::StartSyncFlare()); 145 store->Init(syncer::SyncableService::StartSyncFlare());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 }; 181 };
182 182
183 // Build the expected forms vector and add the forms to the store. 183 // Build the expected forms vector and add the forms to the store.
184 ScopedVector<PasswordForm> expected_forms; 184 ScopedVector<PasswordForm> expected_forms;
185 for (unsigned int i = 0; i < arraysize(form_data); ++i) { 185 for (unsigned int i = 0; i < arraysize(form_data); ++i) {
186 expected_forms.push_back( 186 expected_forms.push_back(
187 CreatePasswordFormFromDataForTesting(form_data[i])); 187 CreatePasswordFormFromDataForTesting(form_data[i]));
188 store->AddLogin(*expected_forms.back()); 188 store->AddLogin(*expected_forms.back());
189 } 189 }
190 190
191 base::MessageLoop::current()->RunUntilIdle(); 191 base::RunLoop().RunUntilIdle();
192 192
193 MockPasswordStoreConsumer consumer; 193 MockPasswordStoreConsumer consumer;
194 194
195 // We expect to get the same data back, even though it's not all ASCII. 195 // We expect to get the same data back, even though it's not all ASCII.
196 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef( 196 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef(
197 password_manager::UnorderedPasswordFormElementsAre( 197 password_manager::UnorderedPasswordFormElementsAre(
198 expected_forms.get()))); 198 expected_forms.get())));
199 store->GetAutofillableLogins(&consumer); 199 store->GetAutofillableLogins(&consumer);
200 200
201 base::MessageLoop::current()->RunUntilIdle(); 201 base::RunLoop().RunUntilIdle();
202 } 202 }
203 203
204 TEST(PasswordStoreDefaultTest, Notifications) { 204 TEST(PasswordStoreDefaultTest, Notifications) {
205 PasswordStoreDefaultTestDelegate delegate; 205 PasswordStoreDefaultTestDelegate delegate;
206 PasswordStoreDefault* store = delegate.store(); 206 PasswordStoreDefault* store = delegate.store();
207 207
208 std::unique_ptr<PasswordForm> form = 208 std::unique_ptr<PasswordForm> form =
209 CreatePasswordFormFromDataForTesting(CreateTestPasswordFormData()); 209 CreatePasswordFormFromDataForTesting(CreateTestPasswordFormData());
210 210
211 MockPasswordStoreObserver observer; 211 MockPasswordStoreObserver observer;
212 store->AddObserver(&observer); 212 store->AddObserver(&observer);
213 213
214 const PasswordStoreChange expected_add_changes[] = { 214 const PasswordStoreChange expected_add_changes[] = {
215 PasswordStoreChange(PasswordStoreChange::ADD, *form), 215 PasswordStoreChange(PasswordStoreChange::ADD, *form),
216 }; 216 };
217 217
218 EXPECT_CALL(observer, 218 EXPECT_CALL(observer,
219 OnLoginsChanged(ElementsAreArray(expected_add_changes))); 219 OnLoginsChanged(ElementsAreArray(expected_add_changes)));
220 220
221 // Adding a login should trigger a notification. 221 // Adding a login should trigger a notification.
222 store->AddLogin(*form); 222 store->AddLogin(*form);
223 base::MessageLoop::current()->RunUntilIdle(); 223 base::RunLoop().RunUntilIdle();
224 224
225 // Change the password. 225 // Change the password.
226 form->password_value = base::ASCIIToUTF16("a different password"); 226 form->password_value = base::ASCIIToUTF16("a different password");
227 227
228 const PasswordStoreChange expected_update_changes[] = { 228 const PasswordStoreChange expected_update_changes[] = {
229 PasswordStoreChange(PasswordStoreChange::UPDATE, *form), 229 PasswordStoreChange(PasswordStoreChange::UPDATE, *form),
230 }; 230 };
231 231
232 EXPECT_CALL(observer, 232 EXPECT_CALL(observer,
233 OnLoginsChanged(ElementsAreArray(expected_update_changes))); 233 OnLoginsChanged(ElementsAreArray(expected_update_changes)));
234 234
235 // Updating the login with the new password should trigger a notification. 235 // Updating the login with the new password should trigger a notification.
236 store->UpdateLogin(*form); 236 store->UpdateLogin(*form);
237 base::MessageLoop::current()->RunUntilIdle(); 237 base::RunLoop().RunUntilIdle();
238 238
239 const PasswordStoreChange expected_delete_changes[] = { 239 const PasswordStoreChange expected_delete_changes[] = {
240 PasswordStoreChange(PasswordStoreChange::REMOVE, *form), 240 PasswordStoreChange(PasswordStoreChange::REMOVE, *form),
241 }; 241 };
242 242
243 EXPECT_CALL(observer, 243 EXPECT_CALL(observer,
244 OnLoginsChanged(ElementsAreArray(expected_delete_changes))); 244 OnLoginsChanged(ElementsAreArray(expected_delete_changes)));
245 245
246 // Deleting the login should trigger a notification. 246 // Deleting the login should trigger a notification.
247 store->RemoveLogin(*form); 247 store->RemoveLogin(*form);
248 base::MessageLoop::current()->RunUntilIdle(); 248 base::RunLoop().RunUntilIdle();
249 249
250 store->RemoveObserver(&observer); 250 store->RemoveObserver(&observer);
251 } 251 }
252 252
253 // Verify that operations on a PasswordStore with a bad database cause no 253 // Verify that operations on a PasswordStore with a bad database cause no
254 // explosions, but fail without side effect, return no data and trigger no 254 // explosions, but fail without side effect, return no data and trigger no
255 // notifications. 255 // notifications.
256 TEST(PasswordStoreDefaultTest, OperationsOnABadDatabaseSilentlyFail) { 256 TEST(PasswordStoreDefaultTest, OperationsOnABadDatabaseSilentlyFail) {
257 PasswordStoreDefaultTestDelegate delegate( 257 PasswordStoreDefaultTestDelegate delegate(
258 base::WrapUnique(new BadLoginDatabase)); 258 base::WrapUnique(new BadLoginDatabase));
259 PasswordStoreDefault* bad_store = delegate.store(); 259 PasswordStoreDefault* bad_store = delegate.store();
260 base::MessageLoop::current()->RunUntilIdle(); 260 base::RunLoop().RunUntilIdle();
261 ASSERT_EQ(nullptr, bad_store->login_db()); 261 ASSERT_EQ(nullptr, bad_store->login_db());
262 262
263 testing::StrictMock<MockPasswordStoreObserver> mock_observer; 263 testing::StrictMock<MockPasswordStoreObserver> mock_observer;
264 bad_store->AddObserver(&mock_observer); 264 bad_store->AddObserver(&mock_observer);
265 265
266 // Add a new autofillable login + a blacklisted login. 266 // Add a new autofillable login + a blacklisted login.
267 std::unique_ptr<PasswordForm> form = 267 std::unique_ptr<PasswordForm> form =
268 CreatePasswordFormFromDataForTesting(CreateTestPasswordFormData()); 268 CreatePasswordFormFromDataForTesting(CreateTestPasswordFormData());
269 std::unique_ptr<PasswordForm> blacklisted_form(new PasswordForm(*form)); 269 std::unique_ptr<PasswordForm> blacklisted_form(new PasswordForm(*form));
270 blacklisted_form->signon_realm = "http://foo.example.com"; 270 blacklisted_form->signon_realm = "http://foo.example.com";
271 blacklisted_form->origin = GURL("http://foo.example.com/origin"); 271 blacklisted_form->origin = GURL("http://foo.example.com/origin");
272 blacklisted_form->action = GURL("http://foo.example.com/action"); 272 blacklisted_form->action = GURL("http://foo.example.com/action");
273 blacklisted_form->blacklisted_by_user = true; 273 blacklisted_form->blacklisted_by_user = true;
274 bad_store->AddLogin(*form); 274 bad_store->AddLogin(*form);
275 bad_store->AddLogin(*blacklisted_form); 275 bad_store->AddLogin(*blacklisted_form);
276 base::MessageLoop::current()->RunUntilIdle(); 276 base::RunLoop().RunUntilIdle();
277 277
278 // Get all logins; autofillable logins; blacklisted logins. 278 // Get all logins; autofillable logins; blacklisted logins.
279 testing::StrictMock<MockPasswordStoreConsumer> mock_consumer; 279 testing::StrictMock<MockPasswordStoreConsumer> mock_consumer;
280 EXPECT_CALL(mock_consumer, OnGetPasswordStoreResultsConstRef(IsEmpty())); 280 EXPECT_CALL(mock_consumer, OnGetPasswordStoreResultsConstRef(IsEmpty()));
281 bad_store->GetLogins(*form, &mock_consumer); 281 bad_store->GetLogins(*form, &mock_consumer);
282 base::MessageLoop::current()->RunUntilIdle(); 282 base::RunLoop().RunUntilIdle();
283 testing::Mock::VerifyAndClearExpectations(&mock_consumer); 283 testing::Mock::VerifyAndClearExpectations(&mock_consumer);
284 EXPECT_CALL(mock_consumer, OnGetPasswordStoreResultsConstRef(IsEmpty())); 284 EXPECT_CALL(mock_consumer, OnGetPasswordStoreResultsConstRef(IsEmpty()));
285 bad_store->GetAutofillableLogins(&mock_consumer); 285 bad_store->GetAutofillableLogins(&mock_consumer);
286 base::MessageLoop::current()->RunUntilIdle(); 286 base::RunLoop().RunUntilIdle();
287 testing::Mock::VerifyAndClearExpectations(&mock_consumer); 287 testing::Mock::VerifyAndClearExpectations(&mock_consumer);
288 EXPECT_CALL(mock_consumer, OnGetPasswordStoreResultsConstRef(IsEmpty())); 288 EXPECT_CALL(mock_consumer, OnGetPasswordStoreResultsConstRef(IsEmpty()));
289 bad_store->GetBlacklistLogins(&mock_consumer); 289 bad_store->GetBlacklistLogins(&mock_consumer);
290 base::MessageLoop::current()->RunUntilIdle(); 290 base::RunLoop().RunUntilIdle();
291 291
292 // Report metrics. 292 // Report metrics.
293 bad_store->ReportMetrics("Test Username", true); 293 bad_store->ReportMetrics("Test Username", true);
294 base::MessageLoop::current()->RunUntilIdle(); 294 base::RunLoop().RunUntilIdle();
295 295
296 // Change the login. 296 // Change the login.
297 form->password_value = base::ASCIIToUTF16("a different password"); 297 form->password_value = base::ASCIIToUTF16("a different password");
298 bad_store->UpdateLogin(*form); 298 bad_store->UpdateLogin(*form);
299 base::MessageLoop::current()->RunUntilIdle(); 299 base::RunLoop().RunUntilIdle();
300 300
301 // Delete one login; a range of logins. 301 // Delete one login; a range of logins.
302 bad_store->RemoveLogin(*form); 302 bad_store->RemoveLogin(*form);
303 base::MessageLoop::current()->RunUntilIdle(); 303 base::RunLoop().RunUntilIdle();
304 base::RunLoop run_loop; 304 base::RunLoop run_loop;
305 bad_store->RemoveLoginsCreatedBetween(base::Time(), base::Time::Max(), 305 bad_store->RemoveLoginsCreatedBetween(base::Time(), base::Time::Max(),
306 run_loop.QuitClosure()); 306 run_loop.QuitClosure());
307 run_loop.Run(); 307 run_loop.Run();
308 308
309 bad_store->RemoveLoginsSyncedBetween(base::Time(), base::Time::Max()); 309 bad_store->RemoveLoginsSyncedBetween(base::Time(), base::Time::Max());
310 base::MessageLoop::current()->RunUntilIdle(); 310 base::RunLoop().RunUntilIdle();
311 311
312 // Ensure no notifications and no explosions during shutdown either. 312 // Ensure no notifications and no explosions during shutdown either.
313 bad_store->RemoveObserver(&mock_observer); 313 bad_store->RemoveObserver(&mock_observer);
314 } 314 }
315 315
316 } // namespace password_manager 316 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698