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

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

Issue 838453003: Open the LoginDatabase on the DB thread, not the UI thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix nits from vabr@. Created 5 years, 11 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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 enum BackendType { 232 enum BackendType {
233 NO_BACKEND, 233 NO_BACKEND,
234 FAILING_BACKEND, 234 FAILING_BACKEND,
235 WORKING_BACKEND 235 WORKING_BACKEND
236 }; 236 };
237 237
238 class PasswordStoreXTest : public testing::TestWithParam<BackendType> { 238 class PasswordStoreXTest : public testing::TestWithParam<BackendType> {
239 protected: 239 protected:
240 void SetUp() override { 240 void SetUp() override {
241 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 241 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
242
243 login_db_.reset(new password_manager::LoginDatabase());
244 ASSERT_TRUE(login_db_->Init(temp_dir_.path().Append("login_test")));
245 } 242 }
246 243
247 void TearDown() override { base::RunLoop().RunUntilIdle(); } 244 void TearDown() override { base::RunLoop().RunUntilIdle(); }
248 245
246 base::FilePath test_login_db_file_path() const {
247 return temp_dir_.path().Append(FILE_PATH_LITERAL("login_test"));
248 }
249
249 PasswordStoreX::NativeBackend* GetBackend() { 250 PasswordStoreX::NativeBackend* GetBackend() {
250 switch (GetParam()) { 251 switch (GetParam()) {
251 case FAILING_BACKEND: 252 case FAILING_BACKEND:
252 return new FailingBackend(); 253 return new FailingBackend();
253 case WORKING_BACKEND: 254 case WORKING_BACKEND:
254 return new MockBackend(); 255 return new MockBackend();
255 default: 256 default:
256 return NULL; 257 return NULL;
257 } 258 }
258 } 259 }
259 260
260 content::TestBrowserThreadBundle thread_bundle_; 261 content::TestBrowserThreadBundle thread_bundle_;
261 262
262 scoped_ptr<password_manager::LoginDatabase> login_db_;
263 base::ScopedTempDir temp_dir_; 263 base::ScopedTempDir temp_dir_;
264 }; 264 };
265 265
266 ACTION(STLDeleteElements0) { 266 ACTION(STLDeleteElements0) {
267 STLDeleteContainerPointers(arg0.begin(), arg0.end()); 267 STLDeleteContainerPointers(arg0.begin(), arg0.end());
268 } 268 }
269 269
270 TEST_P(PasswordStoreXTest, Notifications) { 270 TEST_P(PasswordStoreXTest, Notifications) {
271 scoped_refptr<PasswordStoreX> store( 271 scoped_ptr<password_manager::LoginDatabase> login_db(
272 new PasswordStoreX(base::MessageLoopProxy::current(), 272 new password_manager::LoginDatabase(test_login_db_file_path()));
273 base::MessageLoopProxy::current(), 273 scoped_refptr<PasswordStoreX> store(new PasswordStoreX(
274 login_db_.release(), 274 base::MessageLoopProxy::current(), base::MessageLoopProxy::current(),
275 GetBackend())); 275 login_db.Pass(), GetBackend()));
276 store->Init(syncer::SyncableService::StartSyncFlare()); 276 store->Init(syncer::SyncableService::StartSyncFlare());
277 277
278 password_manager::PasswordFormData form_data = { 278 password_manager::PasswordFormData form_data = {
279 PasswordForm::SCHEME_HTML, "http://bar.example.com", 279 PasswordForm::SCHEME_HTML, "http://bar.example.com",
280 "http://bar.example.com/origin", "http://bar.example.com/action", 280 "http://bar.example.com/origin", "http://bar.example.com/action",
281 L"submit_element", L"username_element", 281 L"submit_element", L"username_element",
282 L"password_element", L"username_value", 282 L"password_element", L"username_value",
283 L"password_value", true, 283 L"password_value", true,
284 false, 1}; 284 false, 1};
285 scoped_ptr<PasswordForm> form(CreatePasswordFormFromData(form_data)); 285 scoped_ptr<PasswordForm> form(CreatePasswordFormFromData(form_data));
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 store->Shutdown(); 338 store->Shutdown();
339 } 339 }
340 340
341 TEST_P(PasswordStoreXTest, NativeMigration) { 341 TEST_P(PasswordStoreXTest, NativeMigration) {
342 VectorOfForms expected_autofillable; 342 VectorOfForms expected_autofillable;
343 InitExpectedForms(true, 50, &expected_autofillable); 343 InitExpectedForms(true, 50, &expected_autofillable);
344 344
345 VectorOfForms expected_blacklisted; 345 VectorOfForms expected_blacklisted;
346 InitExpectedForms(false, 50, &expected_blacklisted); 346 InitExpectedForms(false, 50, &expected_blacklisted);
347 347
348 const base::FilePath login_db_file = test_login_db_file_path();
349 scoped_ptr<password_manager::LoginDatabase> login_db(
350 new password_manager::LoginDatabase(login_db_file));
351 ASSERT_TRUE(login_db->Init());
352
348 // Get the initial size of the login DB file, before we populate it. 353 // Get the initial size of the login DB file, before we populate it.
349 // This will be used later to make sure it gets back to this size. 354 // This will be used later to make sure it gets back to this size.
350 const base::FilePath login_db_file = temp_dir_.path().Append("login_test");
351 base::File::Info db_file_start_info; 355 base::File::Info db_file_start_info;
352 ASSERT_TRUE(base::GetFileInfo(login_db_file, &db_file_start_info)); 356 ASSERT_TRUE(base::GetFileInfo(login_db_file, &db_file_start_info));
353 357
354 password_manager::LoginDatabase* login_db = login_db_.get();
355
356 // Populate the login DB with logins that should be migrated. 358 // Populate the login DB with logins that should be migrated.
357 for (VectorOfForms::iterator it = expected_autofillable.begin(); 359 for (VectorOfForms::iterator it = expected_autofillable.begin();
358 it != expected_autofillable.end(); ++it) { 360 it != expected_autofillable.end(); ++it) {
359 login_db->AddLogin(**it); 361 login_db->AddLogin(**it);
360 } 362 }
361 for (VectorOfForms::iterator it = expected_blacklisted.begin(); 363 for (VectorOfForms::iterator it = expected_blacklisted.begin();
362 it != expected_blacklisted.end(); ++it) { 364 it != expected_blacklisted.end(); ++it) {
363 login_db->AddLogin(**it); 365 login_db->AddLogin(**it);
364 } 366 }
365 367
366 // Get the new size of the login DB file. We expect it to be larger. 368 // Get the new size of the login DB file. We expect it to be larger.
367 base::File::Info db_file_full_info; 369 base::File::Info db_file_full_info;
368 ASSERT_TRUE(base::GetFileInfo(login_db_file, &db_file_full_info)); 370 ASSERT_TRUE(base::GetFileInfo(login_db_file, &db_file_full_info));
369 EXPECT_GT(db_file_full_info.size, db_file_start_info.size); 371 EXPECT_GT(db_file_full_info.size, db_file_start_info.size);
370 372
371 // Initializing the PasswordStore shouldn't trigger a native migration (yet). 373 // Initializing the PasswordStore shouldn't trigger a native migration (yet).
372 scoped_refptr<PasswordStoreX> store( 374 login_db.reset(new password_manager::LoginDatabase(login_db_file));
373 new PasswordStoreX(base::MessageLoopProxy::current(), 375 scoped_refptr<PasswordStoreX> store(new PasswordStoreX(
374 base::MessageLoopProxy::current(), 376 base::MessageLoopProxy::current(), base::MessageLoopProxy::current(),
375 login_db_.release(), 377 login_db.Pass(), GetBackend()));
376 GetBackend()));
377 store->Init(syncer::SyncableService::StartSyncFlare()); 378 store->Init(syncer::SyncableService::StartSyncFlare());
378 379
379 MockPasswordStoreConsumer consumer; 380 MockPasswordStoreConsumer consumer;
380 381
381 // The autofillable forms should have been migrated to the native backend. 382 // The autofillable forms should have been migrated to the native backend.
382 EXPECT_CALL(consumer, 383 EXPECT_CALL(consumer,
383 OnGetPasswordStoreResults( 384 OnGetPasswordStoreResults(
384 ContainsAllPasswordForms(expected_autofillable))) 385 ContainsAllPasswordForms(expected_autofillable)))
385 .WillOnce(WithArg<0>(STLDeleteElements0())); 386 .WillOnce(WithArg<0>(STLDeleteElements0()));
386 387
(...skipping 16 matching lines...) Expand all
403 EXPECT_CALL(ld_return, 404 EXPECT_CALL(ld_return,
404 OnLoginDatabaseQueryDone(ContainsAllPasswordForms(empty))); 405 OnLoginDatabaseQueryDone(ContainsAllPasswordForms(empty)));
405 } else { 406 } else {
406 // The autofillable logins should still be in the login DB. 407 // The autofillable logins should still be in the login DB.
407 EXPECT_CALL(ld_return, 408 EXPECT_CALL(ld_return,
408 OnLoginDatabaseQueryDone( 409 OnLoginDatabaseQueryDone(
409 ContainsAllPasswordForms(expected_autofillable))) 410 ContainsAllPasswordForms(expected_autofillable)))
410 .WillOnce(WithArg<0>(STLDeleteElements0())); 411 .WillOnce(WithArg<0>(STLDeleteElements0()));
411 } 412 }
412 413
413 LoginDatabaseQueryCallback(login_db, true, &ld_return); 414 LoginDatabaseQueryCallback(store->login_db(), true, &ld_return);
414 415
415 // Wait for the login DB methods to execute. 416 // Wait for the login DB methods to execute.
416 base::RunLoop().RunUntilIdle(); 417 base::RunLoop().RunUntilIdle();
417 418
418 if (GetParam() == WORKING_BACKEND) { 419 if (GetParam() == WORKING_BACKEND) {
419 // Likewise, no blacklisted logins should be left in the login DB. 420 // Likewise, no blacklisted logins should be left in the login DB.
420 EXPECT_CALL(ld_return, 421 EXPECT_CALL(ld_return,
421 OnLoginDatabaseQueryDone(ContainsAllPasswordForms(empty))); 422 OnLoginDatabaseQueryDone(ContainsAllPasswordForms(empty)));
422 } else { 423 } else {
423 // The blacklisted logins should still be in the login DB. 424 // The blacklisted logins should still be in the login DB.
424 EXPECT_CALL(ld_return, 425 EXPECT_CALL(ld_return,
425 OnLoginDatabaseQueryDone( 426 OnLoginDatabaseQueryDone(
426 ContainsAllPasswordForms(expected_blacklisted))) 427 ContainsAllPasswordForms(expected_blacklisted)))
427 .WillOnce(WithArg<0>(STLDeleteElements0())); 428 .WillOnce(WithArg<0>(STLDeleteElements0()));
428 } 429 }
429 430
430 LoginDatabaseQueryCallback(login_db, false, &ld_return); 431 LoginDatabaseQueryCallback(store->login_db(), false, &ld_return);
431 432
432 // Wait for the login DB methods to execute. 433 // Wait for the login DB methods to execute.
433 base::RunLoop().RunUntilIdle(); 434 base::RunLoop().RunUntilIdle();
434 435
435 if (GetParam() == WORKING_BACKEND) { 436 if (GetParam() == WORKING_BACKEND) {
436 // If the migration succeeded, then not only should there be no logins left 437 // If the migration succeeded, then not only should there be no logins left
437 // in the login DB, but also the file should have been deleted and then 438 // in the login DB, but also the file should have been deleted and then
438 // recreated. We approximate checking for this by checking that the file 439 // recreated. We approximate checking for this by checking that the file
439 // size is equal to the size before we populated it, even though it was 440 // size is equal to the size before we populated it, even though it was
440 // larger after populating it. 441 // larger after populating it.
(...skipping 10 matching lines...) Expand all
451 452
452 INSTANTIATE_TEST_CASE_P(NoBackend, 453 INSTANTIATE_TEST_CASE_P(NoBackend,
453 PasswordStoreXTest, 454 PasswordStoreXTest,
454 testing::Values(NO_BACKEND)); 455 testing::Values(NO_BACKEND));
455 INSTANTIATE_TEST_CASE_P(FailingBackend, 456 INSTANTIATE_TEST_CASE_P(FailingBackend,
456 PasswordStoreXTest, 457 PasswordStoreXTest,
457 testing::Values(FAILING_BACKEND)); 458 testing::Values(FAILING_BACKEND));
458 INSTANTIATE_TEST_CASE_P(WorkingBackend, 459 INSTANTIATE_TEST_CASE_P(WorkingBackend,
459 PasswordStoreXTest, 460 PasswordStoreXTest,
460 testing::Values(WORKING_BACKEND)); 461 testing::Values(WORKING_BACKEND));
OLDNEW
« no previous file with comments | « chrome/browser/password_manager/password_store_x.cc ('k') | components/password_manager/core/browser/login_database.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698