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

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

Issue 8274012: Wait for URLBlacklist update tasks on automation tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added BrowserThread::WaitForPendingTasksOn, removed SignalingTask Created 9 years, 2 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 | 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/file_util.h" 7 #include "base/file_util.h"
8 #include "base/platform_file.h" 8 #include "base/platform_file.h"
9 #include "base/scoped_temp_dir.h" 9 #include "base/scoped_temp_dir.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
13 #include "base/synchronization/waitable_event.h"
14 #include "base/time.h" 13 #include "base/time.h"
15 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
16 #include "chrome/browser/password_manager/password_form_data.h" 15 #include "chrome/browser/password_manager/password_form_data.h"
17 #include "chrome/browser/password_manager/password_store_change.h" 16 #include "chrome/browser/password_manager/password_store_change.h"
18 #include "chrome/browser/password_manager/password_store_consumer.h" 17 #include "chrome/browser/password_manager/password_store_consumer.h"
19 #include "chrome/browser/password_manager/password_store_x.h" 18 #include "chrome/browser/password_manager/password_store_x.h"
20 #include "chrome/browser/prefs/pref_service.h" 19 #include "chrome/browser/prefs/pref_service.h"
21 #include "chrome/browser/webdata/web_data_service.h" 20 #include "chrome/browser/webdata/web_data_service.h"
22 #include "chrome/common/chrome_notification_types.h" 21 #include "chrome/common/chrome_notification_types.h"
23 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
24 #include "chrome/test/base/signaling_task.h"
25 #include "chrome/test/base/testing_browser_process.h" 23 #include "chrome/test/base/testing_browser_process.h"
26 #include "chrome/test/base/testing_profile.h" 24 #include "chrome/test/base/testing_profile.h"
27 #include "content/common/notification_details.h" 25 #include "content/common/notification_details.h"
28 #include "content/common/notification_observer_mock.h" 26 #include "content/common/notification_observer_mock.h"
29 #include "content/common/notification_registrar.h" 27 #include "content/common/notification_registrar.h"
30 #include "content/common/notification_source.h" 28 #include "content/common/notification_source.h"
31 #include "testing/gmock/include/gmock/gmock.h" 29 #include "testing/gmock/include/gmock/gmock.h"
32 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
33 31
34 using base::WaitableEvent;
35 using testing::_; 32 using testing::_;
36 using testing::DoAll; 33 using testing::DoAll;
37 using testing::ElementsAreArray; 34 using testing::ElementsAreArray;
38 using testing::Pointee; 35 using testing::Pointee;
39 using testing::Property; 36 using testing::Property;
40 using testing::WithArg; 37 using testing::WithArg;
41 using webkit_glue::PasswordForm; 38 using webkit_glue::PasswordForm;
42 39
43 typedef std::vector<PasswordForm*> VectorOfForms; 40 typedef std::vector<PasswordForm*> VectorOfForms;
44 41
(...skipping 11 matching lines...) Expand all
56 MOCK_METHOD2(OnWebDataServiceRequestDone, void(WebDataService::Handle, 53 MOCK_METHOD2(OnWebDataServiceRequestDone, void(WebDataService::Handle,
57 const WDTypedResult*)); 54 const WDTypedResult*));
58 }; 55 };
59 56
60 // This class will add and remove a mock notification observer from 57 // This class will add and remove a mock notification observer from
61 // the DB thread. 58 // the DB thread.
62 class DBThreadObserverHelper 59 class DBThreadObserverHelper
63 : public base::RefCountedThreadSafe<DBThreadObserverHelper, 60 : public base::RefCountedThreadSafe<DBThreadObserverHelper,
64 BrowserThread::DeleteOnDBThread> { 61 BrowserThread::DeleteOnDBThread> {
65 public: 62 public:
66 DBThreadObserverHelper() : done_event_(true, false) {} 63 DBThreadObserverHelper() {}
67 64
68 void Init(PasswordStore* password_store) { 65 void Init(PasswordStore* password_store) {
69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
70 BrowserThread::PostTask( 67 BrowserThread::PostTask(
71 BrowserThread::DB, 68 BrowserThread::DB,
72 FROM_HERE, 69 FROM_HERE,
73 base::Bind(&DBThreadObserverHelper::AddObserverTask, 70 base::Bind(&DBThreadObserverHelper::AddObserverTask,
74 this, make_scoped_refptr(password_store))); 71 this, make_scoped_refptr(password_store)));
75 done_event_.Wait(); 72 CHECK(BrowserThread::WaitForPendingTasksOn(BrowserThread::DB));
76 } 73 }
77 74
78 virtual ~DBThreadObserverHelper() { 75 virtual ~DBThreadObserverHelper() {
79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
80 registrar_.RemoveAll(); 77 registrar_.RemoveAll();
81 } 78 }
82 79
83 NotificationObserverMock& observer() { 80 NotificationObserverMock& observer() {
84 return observer_; 81 return observer_;
85 } 82 }
86 83
87 protected: 84 protected:
88 friend class base::RefCountedThreadSafe<DBThreadObserverHelper>; 85 friend class base::RefCountedThreadSafe<DBThreadObserverHelper>;
89 86
90 void AddObserverTask(PasswordStore* password_store) { 87 void AddObserverTask(PasswordStore* password_store) {
91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
92 registrar_.Add(&observer_, 89 registrar_.Add(&observer_,
93 chrome::NOTIFICATION_LOGINS_CHANGED, 90 chrome::NOTIFICATION_LOGINS_CHANGED,
94 Source<PasswordStore>(password_store)); 91 Source<PasswordStore>(password_store));
95 done_event_.Signal();
96 } 92 }
97 93
98 WaitableEvent done_event_;
99 NotificationRegistrar registrar_; 94 NotificationRegistrar registrar_;
100 NotificationObserverMock observer_; 95 NotificationObserverMock observer_;
101 }; 96 };
102 97
103 class FailingBackend : public PasswordStoreX::NativeBackend { 98 class FailingBackend : public PasswordStoreX::NativeBackend {
104 public: 99 public:
105 virtual bool Init() { return true; } 100 virtual bool Init() { return true; }
106 101
107 virtual bool AddLogin(const PasswordForm& form) { return false; } 102 virtual bool AddLogin(const PasswordForm& form) { return false; }
108 virtual bool UpdateLogin(const PasswordForm& form) { return false; } 103 virtual bool UpdateLogin(const PasswordForm& form) { return false; }
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 it != expected_autofillable.end(); ++it) { 343 it != expected_autofillable.end(); ++it) {
349 wds_->AddLogin(**it); 344 wds_->AddLogin(**it);
350 } 345 }
351 for (VectorOfForms::iterator it = expected_blacklisted.begin(); 346 for (VectorOfForms::iterator it = expected_blacklisted.begin();
352 it != expected_blacklisted.end(); ++it) { 347 it != expected_blacklisted.end(); ++it) {
353 wds_->AddLogin(**it); 348 wds_->AddLogin(**it);
354 } 349 }
355 350
356 // The WDS schedules tasks to run on the DB thread so we schedule yet another 351 // The WDS schedules tasks to run on the DB thread so we schedule yet another
357 // task to notify us that it's safe to carry on with the test. 352 // task to notify us that it's safe to carry on with the test.
358 WaitableEvent done(false, false); 353 CHECK(BrowserThread::WaitForPendingTasksOn(BrowserThread::DB));
359 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
360 new SignalingTask(&done));
361 done.Wait();
362 354
363 // Initializing the PasswordStore should trigger a migration. 355 // Initializing the PasswordStore should trigger a migration.
364 scoped_refptr<PasswordStoreX> store( 356 scoped_refptr<PasswordStoreX> store(
365 new PasswordStoreX(login_db_.release(), 357 new PasswordStoreX(login_db_.release(),
366 profile_.get(), 358 profile_.get(),
367 wds_.get(), 359 wds_.get(),
368 GetBackend())); 360 GetBackend()));
369 store->Init(); 361 store->Init();
370 362
371 // Check that the migration preference has not been initialized. 363 // Check that the migration preference has not been initialized.
372 ASSERT_TRUE(NULL == profile_->GetPrefs()->FindPreference( 364 ASSERT_TRUE(NULL == profile_->GetPrefs()->FindPreference(
373 prefs::kLoginDatabaseMigrated)); 365 prefs::kLoginDatabaseMigrated));
374 366
375 // Again, the WDS schedules tasks to run on the DB thread, so schedule a task 367 // Again, the WDS schedules tasks to run on the DB thread, so schedule a task
376 // to signal us when it is safe to continue. 368 // to signal us when it is safe to continue.
377 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 369 CHECK(BrowserThread::WaitForPendingTasksOn(BrowserThread::DB));
378 new SignalingTask(&done));
379 done.Wait();
380 370
381 // Let the WDS callbacks proceed so the logins can be migrated. 371 // Let the WDS callbacks proceed so the logins can be migrated.
382 MessageLoop::current()->RunAllPending(); 372 MessageLoop::current()->RunAllPending();
383 373
384 MockPasswordStoreConsumer consumer; 374 MockPasswordStoreConsumer consumer;
385 375
386 // Make sure we quit the MessageLoop even if the test fails. 376 // Make sure we quit the MessageLoop even if the test fails.
387 ON_CALL(consumer, OnPasswordStoreRequestDone(_, _)) 377 ON_CALL(consumer, OnPasswordStoreRequestDone(_, _))
388 .WillByDefault(QuitUIMessageLoop()); 378 .WillByDefault(QuitUIMessageLoop());
389 379
(...skipping 22 matching lines...) Expand all
412 402
413 MockWebDataServiceConsumer wds_consumer; 403 MockWebDataServiceConsumer wds_consumer;
414 404
415 // No autofillable logins should be left in the WDS. 405 // No autofillable logins should be left in the WDS.
416 EXPECT_CALL(wds_consumer, 406 EXPECT_CALL(wds_consumer,
417 OnWebDataServiceRequestDone(_, EmptyWDResult())); 407 OnWebDataServiceRequestDone(_, EmptyWDResult()));
418 408
419 wds_->GetAutofillableLogins(&wds_consumer); 409 wds_->GetAutofillableLogins(&wds_consumer);
420 410
421 // Wait for the WDS methods to execute on the DB thread. 411 // Wait for the WDS methods to execute on the DB thread.
422 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 412 CHECK(BrowserThread::WaitForPendingTasksOn(BrowserThread::DB));
423 new SignalingTask(&done));
424 done.Wait();
425 413
426 // Handle the callback from the WDS. 414 // Handle the callback from the WDS.
427 MessageLoop::current()->RunAllPending(); 415 MessageLoop::current()->RunAllPending();
428 416
429 // Likewise, no blacklisted logins should be left in the WDS. 417 // Likewise, no blacklisted logins should be left in the WDS.
430 EXPECT_CALL(wds_consumer, 418 EXPECT_CALL(wds_consumer,
431 OnWebDataServiceRequestDone(_, EmptyWDResult())); 419 OnWebDataServiceRequestDone(_, EmptyWDResult()));
432 420
433 wds_->GetBlacklistLogins(&wds_consumer); 421 wds_->GetBlacklistLogins(&wds_consumer);
434 422
435 // Wait for the WDS methods to execute on the DB thread. 423 // Wait for the WDS methods to execute on the DB thread.
436 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 424 CHECK(BrowserThread::WaitForPendingTasksOn(BrowserThread::DB));
437 new SignalingTask(&done));
438 done.Wait();
439 425
440 // Handle the callback from the WDS. 426 // Handle the callback from the WDS.
441 MessageLoop::current()->RunAllPending(); 427 MessageLoop::current()->RunAllPending();
442 428
443 STLDeleteElements(&expected_autofillable); 429 STLDeleteElements(&expected_autofillable);
444 STLDeleteElements(&expected_blacklisted); 430 STLDeleteElements(&expected_blacklisted);
445 431
446 // Public in PasswordStore, protected in PasswordStoreX. 432 // Public in PasswordStore, protected in PasswordStoreX.
447 static_cast<PasswordStore*>(store)->Shutdown(); 433 static_cast<PasswordStore*>(store)->Shutdown();
448 } 434 }
(...skipping 19 matching lines...) Expand all
468 } 454 }
469 455
470 // Populate the WDS with logins that should be migrated. 456 // Populate the WDS with logins that should be migrated.
471 for (VectorOfForms::iterator it = unexpected_autofillable.begin(); 457 for (VectorOfForms::iterator it = unexpected_autofillable.begin();
472 it != unexpected_autofillable.end(); ++it) { 458 it != unexpected_autofillable.end(); ++it) {
473 wds_->AddLogin(**it); 459 wds_->AddLogin(**it);
474 } 460 }
475 461
476 // The WDS schedules tasks to run on the DB thread so we schedule yet another 462 // The WDS schedules tasks to run on the DB thread so we schedule yet another
477 // task to notify us that it's safe to carry on with the test. 463 // task to notify us that it's safe to carry on with the test.
478 WaitableEvent done(false, false); 464 CHECK(BrowserThread::WaitForPendingTasksOn(BrowserThread::DB));
479 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
480 new SignalingTask(&done));
481 done.Wait();
482 465
483 // Pretend that the migration has already taken place. 466 // Pretend that the migration has already taken place.
484 profile_->GetPrefs()->RegisterBooleanPref(prefs::kLoginDatabaseMigrated, 467 profile_->GetPrefs()->RegisterBooleanPref(prefs::kLoginDatabaseMigrated,
485 true, 468 true,
486 PrefService::UNSYNCABLE_PREF); 469 PrefService::UNSYNCABLE_PREF);
487 470
488 // Initializing the PasswordStore shouldn't trigger a migration. 471 // Initializing the PasswordStore shouldn't trigger a migration.
489 scoped_refptr<PasswordStoreX> store( 472 scoped_refptr<PasswordStoreX> store(
490 new PasswordStoreX(login_db_.release(), 473 new PasswordStoreX(login_db_.release(),
491 profile_.get(), 474 profile_.get(),
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 Source<PasswordStore>(store), 536 Source<PasswordStore>(store),
554 Property(&Details<const PasswordStoreChangeList>::ptr, 537 Property(&Details<const PasswordStoreChangeList>::ptr,
555 Pointee(ElementsAreArray( 538 Pointee(ElementsAreArray(
556 expected_add_changes))))); 539 expected_add_changes)))));
557 540
558 // Adding a login should trigger a notification. 541 // Adding a login should trigger a notification.
559 store->AddLogin(*form); 542 store->AddLogin(*form);
560 543
561 // The PasswordStore schedules tasks to run on the DB thread so we schedule 544 // The PasswordStore schedules tasks to run on the DB thread so we schedule
562 // yet another task to notify us that it's safe to carry on with the test. 545 // yet another task to notify us that it's safe to carry on with the test.
563 WaitableEvent done(false, false); 546 CHECK(BrowserThread::WaitForPendingTasksOn(BrowserThread::DB));
564 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
565 new SignalingTask(&done));
566 done.Wait();
567 547
568 // Change the password. 548 // Change the password.
569 form->password_value = WideToUTF16(L"a different password"); 549 form->password_value = WideToUTF16(L"a different password");
570 550
571 const PasswordStoreChange expected_update_changes[] = { 551 const PasswordStoreChange expected_update_changes[] = {
572 PasswordStoreChange(PasswordStoreChange::UPDATE, *form), 552 PasswordStoreChange(PasswordStoreChange::UPDATE, *form),
573 }; 553 };
574 554
575 EXPECT_CALL(helper->observer(), 555 EXPECT_CALL(helper->observer(),
576 Observe(int(chrome::NOTIFICATION_LOGINS_CHANGED), 556 Observe(int(chrome::NOTIFICATION_LOGINS_CHANGED),
577 Source<PasswordStore>(store), 557 Source<PasswordStore>(store),
578 Property(&Details<const PasswordStoreChangeList>::ptr, 558 Property(&Details<const PasswordStoreChangeList>::ptr,
579 Pointee(ElementsAreArray( 559 Pointee(ElementsAreArray(
580 expected_update_changes))))); 560 expected_update_changes)))));
581 561
582 // Updating the login with the new password should trigger a notification. 562 // Updating the login with the new password should trigger a notification.
583 store->UpdateLogin(*form); 563 store->UpdateLogin(*form);
584 564
585 // Wait for PasswordStore to send the notification. 565 // Wait for PasswordStore to send the notification.
586 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 566 CHECK(BrowserThread::WaitForPendingTasksOn(BrowserThread::DB));
587 new SignalingTask(&done));
588 done.Wait();
589 567
590 const PasswordStoreChange expected_delete_changes[] = { 568 const PasswordStoreChange expected_delete_changes[] = {
591 PasswordStoreChange(PasswordStoreChange::REMOVE, *form), 569 PasswordStoreChange(PasswordStoreChange::REMOVE, *form),
592 }; 570 };
593 571
594 EXPECT_CALL(helper->observer(), 572 EXPECT_CALL(helper->observer(),
595 Observe(int(chrome::NOTIFICATION_LOGINS_CHANGED), 573 Observe(int(chrome::NOTIFICATION_LOGINS_CHANGED),
596 Source<PasswordStore>(store), 574 Source<PasswordStore>(store),
597 Property(&Details<const PasswordStoreChangeList>::ptr, 575 Property(&Details<const PasswordStoreChangeList>::ptr,
598 Pointee(ElementsAreArray( 576 Pointee(ElementsAreArray(
599 expected_delete_changes))))); 577 expected_delete_changes)))));
600 578
601 // Deleting the login should trigger a notification. 579 // Deleting the login should trigger a notification.
602 store->RemoveLogin(*form); 580 store->RemoveLogin(*form);
603 581
604 // Wait for PasswordStore to send the notification. 582 // Wait for PasswordStore to send the notification.
605 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 583 CHECK(BrowserThread::WaitForPendingTasksOn(BrowserThread::DB));
606 new SignalingTask(&done));
607 done.Wait();
608 584
609 // Public in PasswordStore, protected in PasswordStoreX. 585 // Public in PasswordStore, protected in PasswordStoreX.
610 static_cast<PasswordStore*>(store)->Shutdown(); 586 static_cast<PasswordStore*>(store)->Shutdown();
611 } 587 }
612 588
613 TEST_P(PasswordStoreXTest, NativeMigration) { 589 TEST_P(PasswordStoreXTest, NativeMigration) {
614 VectorOfForms expected_autofillable; 590 VectorOfForms expected_autofillable;
615 InitExpectedForms(true, 50, &expected_autofillable); 591 InitExpectedForms(true, 50, &expected_autofillable);
616 592
617 VectorOfForms expected_blacklisted; 593 VectorOfForms expected_blacklisted;
(...skipping 18 matching lines...) Expand all
636 for (VectorOfForms::iterator it = expected_blacklisted.begin(); 612 for (VectorOfForms::iterator it = expected_blacklisted.begin();
637 it != expected_blacklisted.end(); ++it) { 613 it != expected_blacklisted.end(); ++it) {
638 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 614 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
639 base::IgnoreReturn(base::Callback<bool(void)>( 615 base::IgnoreReturn(base::Callback<bool(void)>(
640 base::Bind(&LoginDatabase::AddLogin, 616 base::Bind(&LoginDatabase::AddLogin,
641 base::Unretained(login_db), **it)))); 617 base::Unretained(login_db), **it))));
642 } 618 }
643 619
644 // Schedule another task on the DB thread to notify us that it's safe to 620 // Schedule another task on the DB thread to notify us that it's safe to
645 // carry on with the test. 621 // carry on with the test.
646 WaitableEvent done(false, false); 622 CHECK(BrowserThread::WaitForPendingTasksOn(BrowserThread::DB));
647 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
648 new SignalingTask(&done));
649 done.Wait();
650 623
651 // Get the new size of the login DB file. We expect it to be larger. 624 // Get the new size of the login DB file. We expect it to be larger.
652 base::PlatformFileInfo db_file_full_info; 625 base::PlatformFileInfo db_file_full_info;
653 ASSERT_TRUE(file_util::GetFileInfo(login_db_file, &db_file_full_info)); 626 ASSERT_TRUE(file_util::GetFileInfo(login_db_file, &db_file_full_info));
654 EXPECT_GT(db_file_full_info.size, db_file_start_info.size); 627 EXPECT_GT(db_file_full_info.size, db_file_start_info.size);
655 628
656 // Pretend that the WDS migration has already taken place. 629 // Pretend that the WDS migration has already taken place.
657 profile_->GetPrefs()->RegisterBooleanPref(prefs::kLoginDatabaseMigrated, 630 profile_->GetPrefs()->RegisterBooleanPref(prefs::kLoginDatabaseMigrated,
658 true, 631 true,
659 PrefService::UNSYNCABLE_PREF); 632 PrefService::UNSYNCABLE_PREF);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 EXPECT_CALL(ld_return, 675 EXPECT_CALL(ld_return,
703 OnLoginDatabaseQueryDone( 676 OnLoginDatabaseQueryDone(
704 ContainsAllPasswordForms(expected_autofillable))) 677 ContainsAllPasswordForms(expected_autofillable)))
705 .WillOnce(WithArg<0>(STLDeleteElements0())); 678 .WillOnce(WithArg<0>(STLDeleteElements0()));
706 } 679 }
707 680
708 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 681 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
709 new LoginDatabaseQueryTask(login_db, true, &ld_return)); 682 new LoginDatabaseQueryTask(login_db, true, &ld_return));
710 683
711 // Wait for the login DB methods to execute on the DB thread. 684 // Wait for the login DB methods to execute on the DB thread.
712 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 685 CHECK(BrowserThread::WaitForPendingTasksOn(BrowserThread::DB));
713 new SignalingTask(&done));
714 done.Wait();
715 686
716 if (GetParam() == WORKING_BACKEND) { 687 if (GetParam() == WORKING_BACKEND) {
717 // Likewise, no blacklisted logins should be left in the login DB. 688 // Likewise, no blacklisted logins should be left in the login DB.
718 EXPECT_CALL(ld_return, 689 EXPECT_CALL(ld_return,
719 OnLoginDatabaseQueryDone(ContainsAllPasswordForms(empty))); 690 OnLoginDatabaseQueryDone(ContainsAllPasswordForms(empty)));
720 } else { 691 } else {
721 // The blacklisted logins should still be in the login DB. 692 // The blacklisted logins should still be in the login DB.
722 EXPECT_CALL(ld_return, 693 EXPECT_CALL(ld_return,
723 OnLoginDatabaseQueryDone( 694 OnLoginDatabaseQueryDone(
724 ContainsAllPasswordForms(expected_blacklisted))) 695 ContainsAllPasswordForms(expected_blacklisted)))
725 .WillOnce(WithArg<0>(STLDeleteElements0())); 696 .WillOnce(WithArg<0>(STLDeleteElements0()));
726 } 697 }
727 698
728 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 699 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
729 new LoginDatabaseQueryTask(login_db, false, &ld_return)); 700 new LoginDatabaseQueryTask(login_db, false, &ld_return));
730 701
731 // Wait for the login DB methods to execute on the DB thread. 702 // Wait for the login DB methods to execute on the DB thread.
732 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 703 CHECK(BrowserThread::WaitForPendingTasksOn(BrowserThread::DB));
733 new SignalingTask(&done));
734 done.Wait();
735 704
736 if (GetParam() == WORKING_BACKEND) { 705 if (GetParam() == WORKING_BACKEND) {
737 // If the migration succeeded, then not only should there be no logins left 706 // If the migration succeeded, then not only should there be no logins left
738 // in the login DB, but also the file should have been deleted and then 707 // in the login DB, but also the file should have been deleted and then
739 // recreated. We approximate checking for this by checking that the file 708 // recreated. We approximate checking for this by checking that the file
740 // size is equal to the size before we populated it, even though it was 709 // size is equal to the size before we populated it, even though it was
741 // larger after populating it. 710 // larger after populating it.
742 base::PlatformFileInfo db_file_end_info; 711 base::PlatformFileInfo db_file_end_info;
743 ASSERT_TRUE(file_util::GetFileInfo(login_db_file, &db_file_end_info)); 712 ASSERT_TRUE(file_util::GetFileInfo(login_db_file, &db_file_end_info));
744 EXPECT_EQ(db_file_start_info.size, db_file_end_info.size); 713 EXPECT_EQ(db_file_start_info.size, db_file_end_info.size);
745 } 714 }
746 715
747 STLDeleteElements(&expected_autofillable); 716 STLDeleteElements(&expected_autofillable);
748 STLDeleteElements(&expected_blacklisted); 717 STLDeleteElements(&expected_blacklisted);
749 718
750 // Public in PasswordStore, protected in PasswordStoreX. 719 // Public in PasswordStore, protected in PasswordStoreX.
751 static_cast<PasswordStore*>(store)->Shutdown(); 720 static_cast<PasswordStore*>(store)->Shutdown();
752 } 721 }
753 722
754 INSTANTIATE_TEST_CASE_P(NoBackend, 723 INSTANTIATE_TEST_CASE_P(NoBackend,
755 PasswordStoreXTest, 724 PasswordStoreXTest,
756 testing::Values(NO_BACKEND)); 725 testing::Values(NO_BACKEND));
757 INSTANTIATE_TEST_CASE_P(FailingBackend, 726 INSTANTIATE_TEST_CASE_P(FailingBackend,
758 PasswordStoreXTest, 727 PasswordStoreXTest,
759 testing::Values(FAILING_BACKEND)); 728 testing::Values(FAILING_BACKEND));
760 INSTANTIATE_TEST_CASE_P(WorkingBackend, 729 INSTANTIATE_TEST_CASE_P(WorkingBackend,
761 PasswordStoreXTest, 730 PasswordStoreXTest,
762 testing::Values(WORKING_BACKEND)); 731 testing::Values(WORKING_BACKEND));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698