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

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

Issue 8696001: Removing SignalingTask and replace with base::Bind(&WaitableEvent::Signal, ...) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/file_util.h" 8 #include "base/file_util.h"
8 #include "base/platform_file.h" 9 #include "base/platform_file.h"
9 #include "base/scoped_temp_dir.h" 10 #include "base/scoped_temp_dir.h"
10 #include "base/stl_util.h" 11 #include "base/stl_util.h"
11 #include "base/string_util.h" 12 #include "base/string_util.h"
12 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
13 #include "base/synchronization/waitable_event.h" 14 #include "base/synchronization/waitable_event.h"
14 #include "base/test/signaling_task.h"
15 #include "base/time.h" 15 #include "base/time.h"
16 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
17 #include "chrome/browser/password_manager/password_form_data.h" 17 #include "chrome/browser/password_manager/password_form_data.h"
18 #include "chrome/browser/password_manager/password_store_change.h" 18 #include "chrome/browser/password_manager/password_store_change.h"
19 #include "chrome/browser/password_manager/password_store_consumer.h" 19 #include "chrome/browser/password_manager/password_store_consumer.h"
20 #include "chrome/browser/password_manager/password_store_x.h" 20 #include "chrome/browser/password_manager/password_store_x.h"
21 #include "chrome/browser/prefs/pref_service.h" 21 #include "chrome/browser/prefs/pref_service.h"
22 #include "chrome/browser/webdata/web_data_service.h" 22 #include "chrome/browser/webdata/web_data_service.h"
23 #include "chrome/common/chrome_notification_types.h" 23 #include "chrome/common/chrome_notification_types.h"
24 #include "chrome/common/pref_names.h" 24 #include "chrome/common/pref_names.h"
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 } 353 }
354 for (VectorOfForms::iterator it = expected_blacklisted.begin(); 354 for (VectorOfForms::iterator it = expected_blacklisted.begin();
355 it != expected_blacklisted.end(); ++it) { 355 it != expected_blacklisted.end(); ++it) {
356 wds_->AddLogin(**it); 356 wds_->AddLogin(**it);
357 } 357 }
358 358
359 // The WDS schedules tasks to run on the DB thread so we schedule yet another 359 // The WDS schedules tasks to run on the DB thread so we schedule yet another
360 // task to notify us that it's safe to carry on with the test. 360 // task to notify us that it's safe to carry on with the test.
361 WaitableEvent done(false, false); 361 WaitableEvent done(false, false);
362 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 362 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
363 new base::SignalingTask(&done)); 363 base::Bind(&WaitableEvent::Signal, base::Unretained(&done)));
364 done.Wait(); 364 done.Wait();
365 365
366 // Initializing the PasswordStore should trigger a migration. 366 // Initializing the PasswordStore should trigger a migration.
367 scoped_refptr<PasswordStoreX> store( 367 scoped_refptr<PasswordStoreX> store(
368 new PasswordStoreX(login_db_.release(), 368 new PasswordStoreX(login_db_.release(),
369 profile_.get(), 369 profile_.get(),
370 wds_.get(), 370 wds_.get(),
371 GetBackend())); 371 GetBackend()));
372 store->Init(); 372 store->Init();
373 373
374 // Check that the migration preference has not been initialized. 374 // Check that the migration preference has not been initialized.
375 ASSERT_TRUE(NULL == profile_->GetPrefs()->FindPreference( 375 ASSERT_TRUE(NULL == profile_->GetPrefs()->FindPreference(
376 prefs::kLoginDatabaseMigrated)); 376 prefs::kLoginDatabaseMigrated));
377 377
378 // Again, the WDS schedules tasks to run on the DB thread, so schedule a task 378 // Again, the WDS schedules tasks to run on the DB thread, so schedule a task
379 // to signal us when it is safe to continue. 379 // to signal us when it is safe to continue.
380 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 380 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
381 new base::SignalingTask(&done)); 381 base::Bind(&WaitableEvent::Signal, base::Unretained(&done)));
382 done.Wait(); 382 done.Wait();
383 383
384 // Let the WDS callbacks proceed so the logins can be migrated. 384 // Let the WDS callbacks proceed so the logins can be migrated.
385 MessageLoop::current()->RunAllPending(); 385 MessageLoop::current()->RunAllPending();
386 386
387 MockPasswordStoreConsumer consumer; 387 MockPasswordStoreConsumer consumer;
388 388
389 // Make sure we quit the MessageLoop even if the test fails. 389 // Make sure we quit the MessageLoop even if the test fails.
390 ON_CALL(consumer, OnPasswordStoreRequestDone(_, _)) 390 ON_CALL(consumer, OnPasswordStoreRequestDone(_, _))
391 .WillByDefault(QuitUIMessageLoop()); 391 .WillByDefault(QuitUIMessageLoop());
(...skipping 24 matching lines...) Expand all
416 MockWebDataServiceConsumer wds_consumer; 416 MockWebDataServiceConsumer wds_consumer;
417 417
418 // No autofillable logins should be left in the WDS. 418 // No autofillable logins should be left in the WDS.
419 EXPECT_CALL(wds_consumer, 419 EXPECT_CALL(wds_consumer,
420 OnWebDataServiceRequestDone(_, EmptyWDResult())); 420 OnWebDataServiceRequestDone(_, EmptyWDResult()));
421 421
422 wds_->GetAutofillableLogins(&wds_consumer); 422 wds_->GetAutofillableLogins(&wds_consumer);
423 423
424 // Wait for the WDS methods to execute on the DB thread. 424 // Wait for the WDS methods to execute on the DB thread.
425 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 425 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
426 new base::SignalingTask(&done)); 426 base::Bind(&WaitableEvent::Signal, base::Unretained(&done)));
427 done.Wait(); 427 done.Wait();
428 428
429 // Handle the callback from the WDS. 429 // Handle the callback from the WDS.
430 MessageLoop::current()->RunAllPending(); 430 MessageLoop::current()->RunAllPending();
431 431
432 // Likewise, no blacklisted logins should be left in the WDS. 432 // Likewise, no blacklisted logins should be left in the WDS.
433 EXPECT_CALL(wds_consumer, 433 EXPECT_CALL(wds_consumer,
434 OnWebDataServiceRequestDone(_, EmptyWDResult())); 434 OnWebDataServiceRequestDone(_, EmptyWDResult()));
435 435
436 wds_->GetBlacklistLogins(&wds_consumer); 436 wds_->GetBlacklistLogins(&wds_consumer);
437 437
438 // Wait for the WDS methods to execute on the DB thread. 438 // Wait for the WDS methods to execute on the DB thread.
439 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 439 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
440 new base::SignalingTask(&done)); 440 base::Bind(&WaitableEvent::Signal, base::Unretained(&done)));
441 done.Wait(); 441 done.Wait();
442 442
443 // Handle the callback from the WDS. 443 // Handle the callback from the WDS.
444 MessageLoop::current()->RunAllPending(); 444 MessageLoop::current()->RunAllPending();
445 445
446 STLDeleteElements(&expected_autofillable); 446 STLDeleteElements(&expected_autofillable);
447 STLDeleteElements(&expected_blacklisted); 447 STLDeleteElements(&expected_blacklisted);
448 448
449 // Public in PasswordStore, protected in PasswordStoreX. 449 // Public in PasswordStore, protected in PasswordStoreX.
450 static_cast<PasswordStore*>(store)->Shutdown(); 450 static_cast<PasswordStore*>(store)->Shutdown();
(...skipping 22 matching lines...) Expand all
473 // Populate the WDS with logins that should be migrated. 473 // Populate the WDS with logins that should be migrated.
474 for (VectorOfForms::iterator it = unexpected_autofillable.begin(); 474 for (VectorOfForms::iterator it = unexpected_autofillable.begin();
475 it != unexpected_autofillable.end(); ++it) { 475 it != unexpected_autofillable.end(); ++it) {
476 wds_->AddLogin(**it); 476 wds_->AddLogin(**it);
477 } 477 }
478 478
479 // The WDS schedules tasks to run on the DB thread so we schedule yet another 479 // The WDS schedules tasks to run on the DB thread so we schedule yet another
480 // task to notify us that it's safe to carry on with the test. 480 // task to notify us that it's safe to carry on with the test.
481 WaitableEvent done(false, false); 481 WaitableEvent done(false, false);
482 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 482 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
483 new base::SignalingTask(&done)); 483 base::Bind(&WaitableEvent::Signal, base::Unretained(&done)));
484 done.Wait(); 484 done.Wait();
485 485
486 // Pretend that the migration has already taken place. 486 // Pretend that the migration has already taken place.
487 profile_->GetPrefs()->RegisterBooleanPref(prefs::kLoginDatabaseMigrated, 487 profile_->GetPrefs()->RegisterBooleanPref(prefs::kLoginDatabaseMigrated,
488 true, 488 true,
489 PrefService::UNSYNCABLE_PREF); 489 PrefService::UNSYNCABLE_PREF);
490 490
491 // Initializing the PasswordStore shouldn't trigger a migration. 491 // Initializing the PasswordStore shouldn't trigger a migration.
492 scoped_refptr<PasswordStoreX> store( 492 scoped_refptr<PasswordStoreX> store(
493 new PasswordStoreX(login_db_.release(), 493 new PasswordStoreX(login_db_.release(),
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 Pointee(ElementsAreArray( 558 Pointee(ElementsAreArray(
559 expected_add_changes))))); 559 expected_add_changes)))));
560 560
561 // Adding a login should trigger a notification. 561 // Adding a login should trigger a notification.
562 store->AddLogin(*form); 562 store->AddLogin(*form);
563 563
564 // The PasswordStore schedules tasks to run on the DB thread so we schedule 564 // The PasswordStore schedules tasks to run on the DB thread so we schedule
565 // yet another task to notify us that it's safe to carry on with the test. 565 // yet another task to notify us that it's safe to carry on with the test.
566 WaitableEvent done(false, false); 566 WaitableEvent done(false, false);
567 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 567 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
568 new base::SignalingTask(&done)); 568 base::Bind(&WaitableEvent::Signal, base::Unretained(&done)));
569 done.Wait(); 569 done.Wait();
570 570
571 // Change the password. 571 // Change the password.
572 form->password_value = WideToUTF16(L"a different password"); 572 form->password_value = WideToUTF16(L"a different password");
573 573
574 const PasswordStoreChange expected_update_changes[] = { 574 const PasswordStoreChange expected_update_changes[] = {
575 PasswordStoreChange(PasswordStoreChange::UPDATE, *form), 575 PasswordStoreChange(PasswordStoreChange::UPDATE, *form),
576 }; 576 };
577 577
578 EXPECT_CALL(helper->observer(), 578 EXPECT_CALL(helper->observer(),
579 Observe(int(chrome::NOTIFICATION_LOGINS_CHANGED), 579 Observe(int(chrome::NOTIFICATION_LOGINS_CHANGED),
580 content::Source<PasswordStore>(store), 580 content::Source<PasswordStore>(store),
581 Property(&content::Details<const PasswordStoreChangeList>::ptr, 581 Property(&content::Details<const PasswordStoreChangeList>::ptr,
582 Pointee(ElementsAreArray( 582 Pointee(ElementsAreArray(
583 expected_update_changes))))); 583 expected_update_changes)))));
584 584
585 // Updating the login with the new password should trigger a notification. 585 // Updating the login with the new password should trigger a notification.
586 store->UpdateLogin(*form); 586 store->UpdateLogin(*form);
587 587
588 // Wait for PasswordStore to send the notification. 588 // Wait for PasswordStore to send the notification.
589 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 589 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
590 new base::SignalingTask(&done)); 590 base::Bind(&WaitableEvent::Signal, base::Unretained(&done)));
591 done.Wait(); 591 done.Wait();
592 592
593 const PasswordStoreChange expected_delete_changes[] = { 593 const PasswordStoreChange expected_delete_changes[] = {
594 PasswordStoreChange(PasswordStoreChange::REMOVE, *form), 594 PasswordStoreChange(PasswordStoreChange::REMOVE, *form),
595 }; 595 };
596 596
597 EXPECT_CALL(helper->observer(), 597 EXPECT_CALL(helper->observer(),
598 Observe(int(chrome::NOTIFICATION_LOGINS_CHANGED), 598 Observe(int(chrome::NOTIFICATION_LOGINS_CHANGED),
599 content::Source<PasswordStore>(store), 599 content::Source<PasswordStore>(store),
600 Property(&content::Details<const PasswordStoreChangeList>::ptr, 600 Property(&content::Details<const PasswordStoreChangeList>::ptr,
601 Pointee(ElementsAreArray( 601 Pointee(ElementsAreArray(
602 expected_delete_changes))))); 602 expected_delete_changes)))));
603 603
604 // Deleting the login should trigger a notification. 604 // Deleting the login should trigger a notification.
605 store->RemoveLogin(*form); 605 store->RemoveLogin(*form);
606 606
607 // Wait for PasswordStore to send the notification. 607 // Wait for PasswordStore to send the notification.
608 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 608 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
609 new base::SignalingTask(&done)); 609 base::Bind(&WaitableEvent::Signal, base::Unretained(&done)));
610 done.Wait(); 610 done.Wait();
611 611
612 // Public in PasswordStore, protected in PasswordStoreX. 612 // Public in PasswordStore, protected in PasswordStoreX.
613 static_cast<PasswordStore*>(store)->Shutdown(); 613 static_cast<PasswordStore*>(store)->Shutdown();
614 } 614 }
615 615
616 TEST_P(PasswordStoreXTest, NativeMigration) { 616 TEST_P(PasswordStoreXTest, NativeMigration) {
617 VectorOfForms expected_autofillable; 617 VectorOfForms expected_autofillable;
618 InitExpectedForms(true, 50, &expected_autofillable); 618 InitExpectedForms(true, 50, &expected_autofillable);
619 619
(...skipping 21 matching lines...) Expand all
641 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 641 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
642 base::IgnoreReturn<bool>(base::Bind( 642 base::IgnoreReturn<bool>(base::Bind(
643 &LoginDatabase::AddLogin, 643 &LoginDatabase::AddLogin,
644 base::Unretained(login_db), **it))); 644 base::Unretained(login_db), **it)));
645 } 645 }
646 646
647 // Schedule another task on the DB thread to notify us that it's safe to 647 // Schedule another task on the DB thread to notify us that it's safe to
648 // carry on with the test. 648 // carry on with the test.
649 WaitableEvent done(false, false); 649 WaitableEvent done(false, false);
650 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 650 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
651 new base::SignalingTask(&done)); 651 base::Bind(&WaitableEvent::Signal, base::Unretained(&done)));
652 done.Wait(); 652 done.Wait();
653 653
654 // Get the new size of the login DB file. We expect it to be larger. 654 // Get the new size of the login DB file. We expect it to be larger.
655 base::PlatformFileInfo db_file_full_info; 655 base::PlatformFileInfo db_file_full_info;
656 ASSERT_TRUE(file_util::GetFileInfo(login_db_file, &db_file_full_info)); 656 ASSERT_TRUE(file_util::GetFileInfo(login_db_file, &db_file_full_info));
657 EXPECT_GT(db_file_full_info.size, db_file_start_info.size); 657 EXPECT_GT(db_file_full_info.size, db_file_start_info.size);
658 658
659 // Pretend that the WDS migration has already taken place. 659 // Pretend that the WDS migration has already taken place.
660 profile_->GetPrefs()->RegisterBooleanPref(prefs::kLoginDatabaseMigrated, 660 profile_->GetPrefs()->RegisterBooleanPref(prefs::kLoginDatabaseMigrated,
661 true, 661 true,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 OnLoginDatabaseQueryDone( 706 OnLoginDatabaseQueryDone(
707 ContainsAllPasswordForms(expected_autofillable))) 707 ContainsAllPasswordForms(expected_autofillable)))
708 .WillOnce(WithArg<0>(STLDeleteElements0())); 708 .WillOnce(WithArg<0>(STLDeleteElements0()));
709 } 709 }
710 710
711 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 711 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
712 new LoginDatabaseQueryTask(login_db, true, &ld_return)); 712 new LoginDatabaseQueryTask(login_db, true, &ld_return));
713 713
714 // Wait for the login DB methods to execute on the DB thread. 714 // Wait for the login DB methods to execute on the DB thread.
715 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 715 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
716 new base::SignalingTask(&done)); 716 base::Bind(&WaitableEvent::Signal, base::Unretained(&done)));
717 done.Wait(); 717 done.Wait();
718 718
719 if (GetParam() == WORKING_BACKEND) { 719 if (GetParam() == WORKING_BACKEND) {
720 // Likewise, no blacklisted logins should be left in the login DB. 720 // Likewise, no blacklisted logins should be left in the login DB.
721 EXPECT_CALL(ld_return, 721 EXPECT_CALL(ld_return,
722 OnLoginDatabaseQueryDone(ContainsAllPasswordForms(empty))); 722 OnLoginDatabaseQueryDone(ContainsAllPasswordForms(empty)));
723 } else { 723 } else {
724 // The blacklisted logins should still be in the login DB. 724 // The blacklisted logins should still be in the login DB.
725 EXPECT_CALL(ld_return, 725 EXPECT_CALL(ld_return,
726 OnLoginDatabaseQueryDone( 726 OnLoginDatabaseQueryDone(
727 ContainsAllPasswordForms(expected_blacklisted))) 727 ContainsAllPasswordForms(expected_blacklisted)))
728 .WillOnce(WithArg<0>(STLDeleteElements0())); 728 .WillOnce(WithArg<0>(STLDeleteElements0()));
729 } 729 }
730 730
731 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 731 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
732 new LoginDatabaseQueryTask(login_db, false, &ld_return)); 732 new LoginDatabaseQueryTask(login_db, false, &ld_return));
733 733
734 // Wait for the login DB methods to execute on the DB thread. 734 // Wait for the login DB methods to execute on the DB thread.
735 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 735 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
736 new base::SignalingTask(&done)); 736 base::Bind(&WaitableEvent::Signal, base::Unretained(&done)));
737 done.Wait(); 737 done.Wait();
738 738
739 if (GetParam() == WORKING_BACKEND) { 739 if (GetParam() == WORKING_BACKEND) {
740 // If the migration succeeded, then not only should there be no logins left 740 // If the migration succeeded, then not only should there be no logins left
741 // in the login DB, but also the file should have been deleted and then 741 // in the login DB, but also the file should have been deleted and then
742 // recreated. We approximate checking for this by checking that the file 742 // recreated. We approximate checking for this by checking that the file
743 // size is equal to the size before we populated it, even though it was 743 // size is equal to the size before we populated it, even though it was
744 // larger after populating it. 744 // larger after populating it.
745 base::PlatformFileInfo db_file_end_info; 745 base::PlatformFileInfo db_file_end_info;
746 ASSERT_TRUE(file_util::GetFileInfo(login_db_file, &db_file_end_info)); 746 ASSERT_TRUE(file_util::GetFileInfo(login_db_file, &db_file_end_info));
747 EXPECT_EQ(db_file_start_info.size, db_file_end_info.size); 747 EXPECT_EQ(db_file_start_info.size, db_file_end_info.size);
748 } 748 }
749 749
750 STLDeleteElements(&expected_autofillable); 750 STLDeleteElements(&expected_autofillable);
751 STLDeleteElements(&expected_blacklisted); 751 STLDeleteElements(&expected_blacklisted);
752 752
753 // Public in PasswordStore, protected in PasswordStoreX. 753 // Public in PasswordStore, protected in PasswordStoreX.
754 static_cast<PasswordStore*>(store)->Shutdown(); 754 static_cast<PasswordStore*>(store)->Shutdown();
755 } 755 }
756 756
757 INSTANTIATE_TEST_CASE_P(NoBackend, 757 INSTANTIATE_TEST_CASE_P(NoBackend,
758 PasswordStoreXTest, 758 PasswordStoreXTest,
759 testing::Values(NO_BACKEND)); 759 testing::Values(NO_BACKEND));
760 INSTANTIATE_TEST_CASE_P(FailingBackend, 760 INSTANTIATE_TEST_CASE_P(FailingBackend,
761 PasswordStoreXTest, 761 PasswordStoreXTest,
762 testing::Values(FAILING_BACKEND)); 762 testing::Values(FAILING_BACKEND));
763 INSTANTIATE_TEST_CASE_P(WorkingBackend, 763 INSTANTIATE_TEST_CASE_P(WorkingBackend,
764 PasswordStoreXTest, 764 PasswordStoreXTest,
765 testing::Values(WORKING_BACKEND)); 765 testing::Values(WORKING_BACKEND));
OLDNEW
« no previous file with comments | « chrome/browser/password_manager/password_store_win_unittest.cc ('k') | chrome/browser/sync/signin_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698