Chromium Code Reviews| Index: components/password_manager/core/browser/password_store_default_unittest.cc |
| diff --git a/components/password_manager/core/browser/password_store_default_unittest.cc b/components/password_manager/core/browser/password_store_default_unittest.cc |
| index b4d87c35839f8eeb074149f2f2fb542748960c54..582ab3061d21059fd350d107c2aa4bc964241753 100644 |
| --- a/components/password_manager/core/browser/password_store_default_unittest.cc |
| +++ b/components/password_manager/core/browser/password_store_default_unittest.cc |
| @@ -22,6 +22,7 @@ |
| using autofill::PasswordForm; |
| using testing::_; |
| +using testing::ElementsAre; |
| using testing::ElementsAreArray; |
| using testing::WithArg; |
| @@ -31,8 +32,13 @@ namespace { |
| class MockPasswordStoreConsumer : public PasswordStoreConsumer { |
| public: |
| - MOCK_METHOD1(OnGetPasswordStoreResults, |
| + MOCK_METHOD1(OnGetPasswordStoreResultsConstRef, |
| void(const std::vector<PasswordForm*>&)); |
| + |
| + // GMock cannot mock methods with move-only args. |
| + void OnGetPasswordStoreResults(ScopedVector<PasswordForm> results) override { |
| + OnGetPasswordStoreResultsConstRef(results.get()); |
| + } |
| }; |
| class MockPasswordStoreObserver : public PasswordStore::Observer { |
| @@ -114,11 +120,11 @@ TEST_F(PasswordStoreDefaultTest, NonASCIIData) { |
| }; |
| // Build the expected forms vector and add the forms to the store. |
| - std::vector<PasswordForm*> expected_forms; |
| + ScopedVector<PasswordForm> expected_forms; |
| for (unsigned int i = 0; i < arraysize(form_data); ++i) { |
| - PasswordForm* form = CreatePasswordFormFromData(form_data[i]); |
| - expected_forms.push_back(form); |
| - store->AddLogin(*form); |
| + expected_forms.push_back( |
| + CreatePasswordFormFromData(form_data[i]).release()); |
| + store->AddLogin(*expected_forms.back()); |
| } |
| base::MessageLoop::current()->RunUntilIdle(); |
| @@ -126,14 +132,12 @@ TEST_F(PasswordStoreDefaultTest, NonASCIIData) { |
| MockPasswordStoreConsumer consumer; |
| // We expect to get the same data back, even though it's not all ASCII. |
| - EXPECT_CALL(consumer, |
| - OnGetPasswordStoreResults(ContainsAllPasswordForms(expected_forms))) |
| - .WillOnce(WithArg<0>(STLDeleteElements0())); |
| + EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef( |
| + ContainsSamePasswordForms(expected_forms.get()))); |
| store->GetAutofillableLogins(&consumer); |
| base::MessageLoop::current()->RunUntilIdle(); |
| - STLDeleteElements(&expected_forms); |
| store->Shutdown(); |
| base::MessageLoop::current()->RunUntilIdle(); |
| } |
| @@ -144,8 +148,8 @@ TEST_F(PasswordStoreDefaultTest, Notifications) { |
| make_scoped_ptr(new LoginDatabase(test_login_db_file_path())))); |
| store->Init(syncer::SyncableService::StartSyncFlare()); |
| - scoped_ptr<PasswordForm> form( |
| - CreatePasswordFormFromData(CreateTestPasswordFormData())); |
| + scoped_ptr<PasswordForm> form = |
| + CreatePasswordFormFromData(CreateTestPasswordFormData()); |
| MockPasswordStoreObserver observer; |
| store->AddObserver(&observer); |
| @@ -207,8 +211,8 @@ TEST_F(PasswordStoreDefaultTest, OperationsOnABadDatabaseSilentlyFail) { |
| bad_store->AddObserver(&mock_observer); |
| // Add a new autofillable login + a blacklisted login. |
| - scoped_ptr<PasswordForm> form( |
| - CreatePasswordFormFromData(CreateTestPasswordFormData())); |
| + scoped_ptr<PasswordForm> form = |
| + CreatePasswordFormFromData(CreateTestPasswordFormData()); |
| scoped_ptr<PasswordForm> blacklisted_form(new PasswordForm(*form)); |
| blacklisted_form->signon_realm = "http://foo.example.com"; |
| blacklisted_form->origin = GURL("http://foo.example.com/origin"); |
| @@ -220,15 +224,15 @@ TEST_F(PasswordStoreDefaultTest, OperationsOnABadDatabaseSilentlyFail) { |
| // Get all logins; autofillable logins; blacklisted logins. |
| testing::StrictMock<MockPasswordStoreConsumer> mock_consumer; |
| - EXPECT_CALL(mock_consumer, OnGetPasswordStoreResults(testing::ElementsAre())); |
| + EXPECT_CALL(mock_consumer, OnGetPasswordStoreResultsConstRef(ElementsAre())); |
|
vasilii
2015/02/05 19:23:27
What about IsEmpty()?
vabr (Chromium)
2015/02/06 14:16:05
Done.
|
| bad_store->GetLogins(*form, PasswordStore::DISALLOW_PROMPT, &mock_consumer); |
| base::MessageLoop::current()->RunUntilIdle(); |
| testing::Mock::VerifyAndClearExpectations(&mock_consumer); |
| - EXPECT_CALL(mock_consumer, OnGetPasswordStoreResults(testing::ElementsAre())); |
| + EXPECT_CALL(mock_consumer, OnGetPasswordStoreResultsConstRef(ElementsAre())); |
| bad_store->GetAutofillableLogins(&mock_consumer); |
| base::MessageLoop::current()->RunUntilIdle(); |
| testing::Mock::VerifyAndClearExpectations(&mock_consumer); |
| - EXPECT_CALL(mock_consumer, OnGetPasswordStoreResults(testing::ElementsAre())); |
| + EXPECT_CALL(mock_consumer, OnGetPasswordStoreResultsConstRef(ElementsAre())); |
| bad_store->GetBlacklistLogins(&mock_consumer); |
| base::MessageLoop::current()->RunUntilIdle(); |