| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/scoped_temp_dir.h" | 6 #include "base/scoped_temp_dir.h" |
| 7 #include "base/stl_util-inl.h" | 7 #include "base/stl_util-inl.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "base/waitable_event.h" | 10 #include "base/waitable_event.h" |
| (...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 TEST_P(PasswordStoreXTest, NativeMigration) { | 593 TEST_P(PasswordStoreXTest, NativeMigration) { |
| 594 VectorOfForms expected_autofillable; | 594 VectorOfForms expected_autofillable; |
| 595 InitExpectedForms(true, 50, &expected_autofillable); | 595 InitExpectedForms(true, 50, &expected_autofillable); |
| 596 | 596 |
| 597 VectorOfForms expected_blacklisted; | 597 VectorOfForms expected_blacklisted; |
| 598 InitExpectedForms(false, 50, &expected_blacklisted); | 598 InitExpectedForms(false, 50, &expected_blacklisted); |
| 599 | 599 |
| 600 // Get the initial size of the login DB file, before we populate it. | 600 // Get the initial size of the login DB file, before we populate it. |
| 601 // This will be used later to make sure it gets back to this size. | 601 // This will be used later to make sure it gets back to this size. |
| 602 const FilePath login_db_file = temp_dir_.path().Append("login_test"); | 602 const FilePath login_db_file = temp_dir_.path().Append("login_test"); |
| 603 file_util::FileInfo db_file_start_info; | 603 base::PlatformFileInfo db_file_start_info; |
| 604 ASSERT_TRUE(file_util::GetFileInfo(login_db_file, &db_file_start_info)); | 604 ASSERT_TRUE(file_util::GetFileInfo(login_db_file, &db_file_start_info)); |
| 605 | 605 |
| 606 LoginDatabase* login_db = login_db_.get(); | 606 LoginDatabase* login_db = login_db_.get(); |
| 607 | 607 |
| 608 // Populate the login DB with logins that should be migrated. | 608 // Populate the login DB with logins that should be migrated. |
| 609 for (VectorOfForms::iterator it = expected_autofillable.begin(); | 609 for (VectorOfForms::iterator it = expected_autofillable.begin(); |
| 610 it != expected_autofillable.end(); ++it) { | 610 it != expected_autofillable.end(); ++it) { |
| 611 ChromeThread::PostTask(ChromeThread::DB, | 611 ChromeThread::PostTask(ChromeThread::DB, |
| 612 FROM_HERE, | 612 FROM_HERE, |
| 613 NewRunnableMethod(login_db, | 613 NewRunnableMethod(login_db, |
| 614 &LoginDatabase::AddLogin, | 614 &LoginDatabase::AddLogin, |
| 615 **it)); | 615 **it)); |
| 616 } | 616 } |
| 617 for (VectorOfForms::iterator it = expected_blacklisted.begin(); | 617 for (VectorOfForms::iterator it = expected_blacklisted.begin(); |
| 618 it != expected_blacklisted.end(); ++it) { | 618 it != expected_blacklisted.end(); ++it) { |
| 619 ChromeThread::PostTask(ChromeThread::DB, | 619 ChromeThread::PostTask(ChromeThread::DB, |
| 620 FROM_HERE, | 620 FROM_HERE, |
| 621 NewRunnableMethod(login_db, | 621 NewRunnableMethod(login_db, |
| 622 &LoginDatabase::AddLogin, | 622 &LoginDatabase::AddLogin, |
| 623 **it)); | 623 **it)); |
| 624 } | 624 } |
| 625 | 625 |
| 626 // Schedule another task on the DB thread to notify us that it's safe to | 626 // Schedule another task on the DB thread to notify us that it's safe to |
| 627 // carry on with the test. | 627 // carry on with the test. |
| 628 WaitableEvent done(false, false); | 628 WaitableEvent done(false, false); |
| 629 ChromeThread::PostTask(ChromeThread::DB, FROM_HERE, new SignalingTask(&done)); | 629 ChromeThread::PostTask(ChromeThread::DB, FROM_HERE, new SignalingTask(&done)); |
| 630 done.Wait(); | 630 done.Wait(); |
| 631 | 631 |
| 632 // Get the new size of the login DB file. We expect it to be larger. | 632 // Get the new size of the login DB file. We expect it to be larger. |
| 633 file_util::FileInfo db_file_full_info; | 633 base::PlatformFileInfo db_file_full_info; |
| 634 ASSERT_TRUE(file_util::GetFileInfo(login_db_file, &db_file_full_info)); | 634 ASSERT_TRUE(file_util::GetFileInfo(login_db_file, &db_file_full_info)); |
| 635 EXPECT_GT(db_file_full_info.size, db_file_start_info.size); | 635 EXPECT_GT(db_file_full_info.size, db_file_start_info.size); |
| 636 | 636 |
| 637 // Pretend that the WDS migration has already taken place. | 637 // Pretend that the WDS migration has already taken place. |
| 638 profile_->GetPrefs()->RegisterBooleanPref(prefs::kLoginDatabaseMigrated, | 638 profile_->GetPrefs()->RegisterBooleanPref(prefs::kLoginDatabaseMigrated, |
| 639 true); | 639 true); |
| 640 | 640 |
| 641 // Initializing the PasswordStore shouldn't trigger a native migration (yet). | 641 // Initializing the PasswordStore shouldn't trigger a native migration (yet). |
| 642 scoped_refptr<PasswordStoreX> store( | 642 scoped_refptr<PasswordStoreX> store( |
| 643 new PasswordStoreX(login_db_.release(), | 643 new PasswordStoreX(login_db_.release(), |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 // Wait for the login DB methods to execute on the DB thread. | 710 // Wait for the login DB methods to execute on the DB thread. |
| 711 ChromeThread::PostTask(ChromeThread::DB, FROM_HERE, new SignalingTask(&done)); | 711 ChromeThread::PostTask(ChromeThread::DB, FROM_HERE, new SignalingTask(&done)); |
| 712 done.Wait(); | 712 done.Wait(); |
| 713 | 713 |
| 714 if (GetParam() == WORKING_BACKEND) { | 714 if (GetParam() == WORKING_BACKEND) { |
| 715 // If the migration succeeded, then not only should there be no logins left | 715 // If the migration succeeded, then not only should there be no logins left |
| 716 // in the login DB, but also the file should have been deleted and then | 716 // in the login DB, but also the file should have been deleted and then |
| 717 // recreated. We approximate checking for this by checking that the file | 717 // recreated. We approximate checking for this by checking that the file |
| 718 // size is equal to the size before we populated it, even though it was | 718 // size is equal to the size before we populated it, even though it was |
| 719 // larger after populating it. | 719 // larger after populating it. |
| 720 file_util::FileInfo db_file_end_info; | 720 base::PlatformFileInfo db_file_end_info; |
| 721 ASSERT_TRUE(file_util::GetFileInfo(login_db_file, &db_file_end_info)); | 721 ASSERT_TRUE(file_util::GetFileInfo(login_db_file, &db_file_end_info)); |
| 722 EXPECT_EQ(db_file_start_info.size, db_file_end_info.size); | 722 EXPECT_EQ(db_file_start_info.size, db_file_end_info.size); |
| 723 } | 723 } |
| 724 | 724 |
| 725 STLDeleteElements(&expected_autofillable); | 725 STLDeleteElements(&expected_autofillable); |
| 726 STLDeleteElements(&expected_blacklisted); | 726 STLDeleteElements(&expected_blacklisted); |
| 727 } | 727 } |
| 728 | 728 |
| 729 INSTANTIATE_TEST_CASE_P(NoBackend, | 729 INSTANTIATE_TEST_CASE_P(NoBackend, |
| 730 PasswordStoreXTest, | 730 PasswordStoreXTest, |
| 731 testing::Values(NO_BACKEND)); | 731 testing::Values(NO_BACKEND)); |
| 732 INSTANTIATE_TEST_CASE_P(FailingBackend, | 732 INSTANTIATE_TEST_CASE_P(FailingBackend, |
| 733 PasswordStoreXTest, | 733 PasswordStoreXTest, |
| 734 testing::Values(FAILING_BACKEND)); | 734 testing::Values(FAILING_BACKEND)); |
| 735 INSTANTIATE_TEST_CASE_P(WorkingBackend, | 735 INSTANTIATE_TEST_CASE_P(WorkingBackend, |
| 736 PasswordStoreXTest, | 736 PasswordStoreXTest, |
| 737 testing::Values(WORKING_BACKEND)); | 737 testing::Values(WORKING_BACKEND)); |
| OLD | NEW |