Chromium Code Reviews| Index: components/password_manager/core/browser/password_store_unittest.cc |
| diff --git a/components/password_manager/core/browser/password_store_unittest.cc b/components/password_manager/core/browser/password_store_unittest.cc |
| index 681d0421ef5b5cf854137a2712a6c78eac0b2b2f..f847c3ade422321ffa6e4f28099d00d8d6e3177f 100644 |
| --- a/components/password_manager/core/browser/password_store_unittest.cc |
| +++ b/components/password_manager/core/browser/password_store_unittest.cc |
| @@ -2,6 +2,8 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +#include <queue> |
| + |
| #include "base/basictypes.h" |
| #include "base/bind.h" |
| #include "base/files/scoped_temp_dir.h" |
| @@ -25,10 +27,25 @@ namespace password_manager { |
| namespace { |
| -class MockPasswordStoreConsumer : public PasswordStoreConsumer { |
| +class CheckingPasswordStoreConsumer : public PasswordStoreConsumer { |
| public: |
| - MOCK_METHOD1(OnGetPasswordStoreResults, |
| - void(const std::vector<PasswordForm*>&)); |
| + ~CheckingPasswordStoreConsumer() override { |
| + EXPECT_FALSE(expected_results_.size()); |
|
vasilii
2015/02/03 19:22:17
EXPECT_TRUE(expected_results_.empty());
vabr (Chromium)
2015/02/04 16:13:44
Done.
|
| + } |
| + |
| + void OnGetPasswordStoreResults() override { |
| + ASSERT_TRUE(expected_results_.size()); |
|
vasilii
2015/02/03 19:22:17
empty()
vabr (Chromium)
2015/02/04 16:13:44
Done.
|
| + EXPECT_TRUE(ContainsSamePasswordFormsPtr(*expected_results_.front(), |
| + results()->get())); |
| + expected_results_.pop(); |
| + } |
| + |
| + void AddExpectation(const std::vector<PasswordForm*>* expected_result) { |
| + expected_results_.push(expected_result); |
| + } |
| + |
| + private: |
| + std::queue<const std::vector<PasswordForm*>*> expected_results_; |
| }; |
| class StartSyncFlareMock { |
| @@ -130,11 +147,10 @@ TEST_F(PasswordStoreTest, IgnoreOldWwwGoogleLogins) { |
| }; |
| // Build the forms vector and add the forms to the store. |
| - std::vector<PasswordForm*> all_forms; |
| + ScopedVector<PasswordForm> all_forms; |
| for (size_t i = 0; i < arraysize(form_data); ++i) { |
| - PasswordForm* form = CreatePasswordFormFromData(form_data[i]); |
| - all_forms.push_back(form); |
| - store->AddLogin(*form); |
| + all_forms.push_back(CreatePasswordFormFromData(form_data[i])); |
| + store->AddLogin(*all_forms.back()); |
| } |
| base::MessageLoop::current()->RunUntilIdle(); |
| @@ -163,22 +179,10 @@ TEST_F(PasswordStoreTest, IgnoreOldWwwGoogleLogins) { |
| std::vector<PasswordForm*> bar_example_expected; |
| bar_example_expected.push_back(all_forms[4]); |
| - MockPasswordStoreConsumer consumer; |
| - |
| - // Expect the appropriate replies, as above, in reverse order than we will |
| - // issue the queries. Each retires on saturation to avoid matcher spew. |
| - EXPECT_CALL(consumer, OnGetPasswordStoreResults( |
| - ContainsAllPasswordForms(bar_example_expected))) |
| - .WillOnce(WithArg<0>(STLDeleteElements0())) |
| - .RetiresOnSaturation(); |
| - EXPECT_CALL(consumer, OnGetPasswordStoreResults( |
| - ContainsAllPasswordForms(accounts_google_expected))) |
| - .WillOnce(WithArg<0>(STLDeleteElements0())) |
| - .RetiresOnSaturation(); |
| - EXPECT_CALL(consumer, OnGetPasswordStoreResults( |
| - ContainsAllPasswordForms(www_google_expected))) |
| - .WillOnce(WithArg<0>(STLDeleteElements0())) |
| - .RetiresOnSaturation(); |
| + CheckingPasswordStoreConsumer consumer; |
| + consumer.AddExpectation(&www_google_expected); |
| + consumer.AddExpectation(&accounts_google_expected); |
| + consumer.AddExpectation(&bar_example_expected); |
| store->GetLogins(www_google, PasswordStore::ALLOW_PROMPT, &consumer); |
| store->GetLogins(accounts_google, PasswordStore::ALLOW_PROMPT, &consumer); |
| @@ -186,7 +190,6 @@ TEST_F(PasswordStoreTest, IgnoreOldWwwGoogleLogins) { |
| base::MessageLoop::current()->RunUntilIdle(); |
| - STLDeleteElements(&all_forms); |
| store->Shutdown(); |
| base::MessageLoop::current()->RunUntilIdle(); |
| } |