Chromium Code Reviews| Index: chrome/browser/password_manager/password_store_mac_unittest.cc |
| diff --git a/chrome/browser/password_manager/password_store_mac_unittest.cc b/chrome/browser/password_manager/password_store_mac_unittest.cc |
| index 996adef9f00ce3b7fb9d8e08f720d365aa852566..bd98b8e0f9c14cf7c2ab7ba09a503ee792a4cc7e 100644 |
| --- a/chrome/browser/password_manager/password_store_mac_unittest.cc |
| +++ b/chrome/browser/password_manager/password_store_mac_unittest.cc |
| @@ -21,6 +21,7 @@ |
| #include "components/password_manager/core/browser/login_database.h" |
| #include "components/password_manager/core/browser/password_manager_test_utils.h" |
| #include "components/password_manager/core/browser/password_store_consumer.h" |
| +#include "components/password_manager/core/browser/password_store_origin_unittest.h" |
| #include "content/public/test/test_browser_thread.h" |
| #include "content/public/test/test_utils.h" |
| #include "crypto/mock_apple_keychain.h" |
| @@ -76,12 +77,6 @@ class MockPasswordStoreConsumer : public PasswordStoreConsumer { |
| } |
| }; |
| -class MockPasswordStoreObserver : public PasswordStore::Observer { |
| - public: |
| - MOCK_METHOD1(OnLoginsChanged, |
| - void(const password_manager::PasswordStoreChangeList& changes)); |
| -}; |
| - |
| // A LoginDatabase that simulates an Init() method that takes a long time. |
| class SlowToInitLoginDatabase : public password_manager::LoginDatabase { |
| public: |
| @@ -174,8 +169,78 @@ PasswordStoreChangeList AddChangeForForm(const PasswordForm& form) { |
| 1, PasswordStoreChange(PasswordStoreChange::ADD, form)); |
| } |
| +class PasswordStoreMacTestDelegate { |
| + public: |
| + PasswordStoreMacTestDelegate(); |
| + ~PasswordStoreMacTestDelegate(); |
| + |
| + PasswordStoreMac* store() { return store_.get(); } |
| + |
| + static void FinishAsyncProcessing(); |
| + |
| + private: |
| + void Initialize(); |
| + |
| + void ClosePasswordStore(); |
| + |
| + base::FilePath test_login_db_file_path() const; |
| + |
| + base::MessageLoopForUI message_loop_; |
| + base::ScopedTempDir db_dir_; |
| + scoped_ptr<LoginDatabase> login_db_; |
| + scoped_refptr<PasswordStoreMac> store_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(PasswordStoreMacTestDelegate); |
| +}; |
| + |
| +PasswordStoreMacTestDelegate::PasswordStoreMacTestDelegate() { |
| + Initialize(); |
| +} |
| + |
| +PasswordStoreMacTestDelegate::~PasswordStoreMacTestDelegate() { |
| + ClosePasswordStore(); |
| + login_db_.reset(); |
|
vasilii
2015/11/26 11:03:38
You don't need it. Also I think that |login_db_| s
Timo Reimann
2015/11/26 14:38:29
Removed.
|
| +} |
| + |
| +void PasswordStoreMacTestDelegate::Initialize() { |
| + ASSERT_TRUE(db_dir_.CreateUniqueTempDir()); |
| + |
| + // Ensure that LoginDatabase will use the mock keychain if it needs to |
| + // encrypt/decrypt a password. |
| + OSCrypt::UseMockKeychain(true); |
| + login_db_.reset(new LoginDatabase(test_login_db_file_path())); |
| + ASSERT_TRUE(login_db_->Init()); |
| + |
| + // Create and initialize the password store. |
| + store_ = new PasswordStoreMac(base::ThreadTaskRunnerHandle::Get(), |
| + base::ThreadTaskRunnerHandle::Get(), |
| + make_scoped_ptr(new MockAppleKeychain)); |
| + store_->set_login_metadata_db(login_db_.get()); |
| +} |
| + |
| +base::FilePath PasswordStoreMacTestDelegate::test_login_db_file_path() const { |
|
vasilii
2015/11/26 11:03:38
Declaration order should match definition order.
Timo Reimann
2015/11/26 14:38:29
Updated.
|
| + return db_dir_.path().Append(FILE_PATH_LITERAL("login.db")); |
| +} |
| + |
| +void PasswordStoreMacTestDelegate::ClosePasswordStore() { |
| + store_->ShutdownOnUIThread(); |
| + FinishAsyncProcessing(); |
| +} |
| + |
| +void PasswordStoreMacTestDelegate::FinishAsyncProcessing() { |
| + base::MessageLoop::current()->RunUntilIdle(); |
| +} |
| + |
| } // namespace |
| +namespace password_manager { |
|
vasilii
2015/11/26 11:03:38
We shouldn't declare namespace password_manager in
Timo Reimann
2015/11/26 14:38:29
I tried to keep the typed test case instantiations
vasilii
2015/11/26 14:53:39
Try to write 'using password_manager::PasswordStor
|
| + |
| +INSTANTIATE_TYPED_TEST_CASE_P(Mac, |
| + PasswordStoreOriginTest, |
| + PasswordStoreMacTestDelegate); |
| + |
| +} // namespace password_manager |
| + |
| #pragma mark - |
| class PasswordStoreMacInternalsTest : public testing::Test { |
| @@ -1676,7 +1741,8 @@ TEST_F(PasswordStoreMacTest, TestRemoveLoginsMultiProfile) { |
| // implicitly deleted. However, the observers shouldn't get notified about |
| // deletion of non-existent forms like m.facebook.com. |
| TEST_F(PasswordStoreMacTest, SilentlyRemoveOrphanedForm) { |
| - testing::StrictMock<MockPasswordStoreObserver> mock_observer; |
| + testing::StrictMock<password_manager::MockPasswordStoreObserver> |
| + mock_observer; |
| store()->AddObserver(&mock_observer); |
| // 1. Add a password for www.facebook.com to the LoginDatabase. |