Chromium Code Reviews| Index: components/password_manager/core/browser/password_manager_unittest.cc |
| diff --git a/components/password_manager/core/browser/password_manager_unittest.cc b/components/password_manager/core/browser/password_manager_unittest.cc |
| index 22169b0eb3d047521aaebca44a459b866f5f800f..e0d81e5c4e2027853af4a3b1e843a41a6927558b 100644 |
| --- a/components/password_manager/core/browser/password_manager_unittest.cc |
| +++ b/components/password_manager/core/browser/password_manager_unittest.cc |
| @@ -67,7 +67,10 @@ class MockPasswordManagerDriver : public StubPasswordManagerDriver { |
| MOCK_METHOD0(GetPasswordAutofillManager, PasswordAutofillManager*()); |
| }; |
| -ACTION_P(InvokeConsumer, forms) { arg0->OnGetPasswordStoreResults(forms); } |
| +ACTION_P(InvokeConsumer, forms) { |
| + arg0->results()->swap(*forms); |
| + arg0->OnGetPasswordStoreResults(); |
| +} |
| ACTION_P(SaveToScopedPtr, scoped) { scoped->reset(arg0); } |
| @@ -242,10 +245,10 @@ MATCHER_P(FormMatches, form, "") { |
| TEST_F(PasswordManagerTest, FormSubmitEmptyStore) { |
| // Test that observing a newly submitted form shows the save password bar. |
| - std::vector<PasswordForm*> result; // Empty password store. |
| + ScopedVector<PasswordForm> result; // Empty password store. |
| EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
| EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
|
vasilii
2015/02/03 19:22:16
*store_?
vabr (Chromium)
2015/02/04 16:13:44
Done.
(I tend not to add independent clean-ups to
|
| - .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| + .WillOnce(DoAll(WithArg<2>(InvokeConsumer(&result)), Return())); |
| std::vector<PasswordForm> observed; |
| PasswordForm form(MakeSimpleForm()); |
| observed.push_back(form); |
| @@ -320,10 +323,10 @@ TEST_F(PasswordManagerTest, FormSubmitWithOnlyNewPasswordField) { |
| TEST_F(PasswordManagerTest, GeneratedPasswordFormSubmitEmptyStore) { |
| // This test is the same as FormSubmitEmptyStore, except that it simulates the |
| // user generating the password through the browser. |
| - std::vector<PasswordForm*> result; // Empty password store. |
| + ScopedVector<PasswordForm> result; // Empty password store. |
| EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
| EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| - .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| + .WillOnce(DoAll(WithArg<2>(InvokeConsumer(&result)), Return())); |
| std::vector<PasswordForm> observed; |
| PasswordForm form(MakeSimpleForm()); |
| observed.push_back(form); |
| @@ -359,13 +362,14 @@ TEST_F(PasswordManagerTest, FormSubmitNoGoodMatch) { |
| // Same as above, except with an existing form for the same signon realm, |
| // but different origin. Detailed cases like this are covered by |
| // PasswordFormManagerTest. |
| - std::vector<PasswordForm*> result; |
| - PasswordForm* existing_different = new PasswordForm(MakeSimpleForm()); |
| + ScopedVector<PasswordForm> result; |
| + scoped_ptr<PasswordForm> existing_different( |
| + new PasswordForm(MakeSimpleForm())); |
| existing_different->username_value = ASCIIToUTF16("google2"); |
| - result.push_back(existing_different); |
| + result.push_back(existing_different.release()); |
| EXPECT_CALL(driver_, FillPasswordForm(_)).Times(2); |
| EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| - .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| + .WillOnce(DoAll(WithArg<2>(InvokeConsumer(&result)), Return())); |
| std::vector<PasswordForm> observed; |
| PasswordForm form(MakeSimpleForm()); |
| @@ -395,10 +399,10 @@ TEST_F(PasswordManagerTest, FormSubmitNoGoodMatch) { |
| } |
| TEST_F(PasswordManagerTest, FormSeenThenLeftPage) { |
| - std::vector<PasswordForm*> result; // Empty password store. |
| + ScopedVector<PasswordForm> result; // Empty password store. |
| EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
| EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| - .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| + .WillOnce(DoAll(WithArg<2>(InvokeConsumer(&result)), Return())); |
| std::vector<PasswordForm> observed; |
| PasswordForm form(MakeSimpleForm()); |
| observed.push_back(form); |
| @@ -419,10 +423,10 @@ TEST_F(PasswordManagerTest, FormSeenThenLeftPage) { |
| TEST_F(PasswordManagerTest, FormSubmitAfterNavigateInPage) { |
| // Test that navigating in the page does not prevent us from showing the save |
| // password infobar. |
| - std::vector<PasswordForm*> result; // Empty password store. |
| + ScopedVector<PasswordForm> result; // Empty password store. |
| EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
| EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| - .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| + .WillOnce(DoAll(WithArg<2>(InvokeConsumer(&result)), Return())); |
| std::vector<PasswordForm> observed; |
| PasswordForm form(MakeSimpleForm()); |
| observed.push_back(form); |
| @@ -453,10 +457,10 @@ TEST_F(PasswordManagerTest, FormSubmitAfterNavigateInPage) { |
| // This test verifies a fix for http://crbug.com/236673 |
| TEST_F(PasswordManagerTest, FormSubmitWithFormOnPreviousPage) { |
| - std::vector<PasswordForm*> result; // Empty password store. |
| + ScopedVector<PasswordForm> result; // Empty password store. |
| EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
| EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| - .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| + .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(&result)), Return())); |
| PasswordForm first_form(MakeSimpleForm()); |
| first_form.origin = GURL("http://www.nytimes.com/"); |
| first_form.action = GURL("https://myaccount.nytimes.com/auth/login"); |
| @@ -502,10 +506,10 @@ TEST_F(PasswordManagerTest, FormSubmitWithFormOnPreviousPage) { |
| } |
| TEST_F(PasswordManagerTest, FormSubmitFailedLogin) { |
| - std::vector<PasswordForm*> result; // Empty password store. |
| + ScopedVector<PasswordForm> result; // Empty password store. |
| EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
| EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| - .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| + .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(&result)), Return())); |
| std::vector<PasswordForm> observed; |
| PasswordForm form(MakeSimpleForm()); |
| observed.push_back(form); |
| @@ -524,10 +528,10 @@ TEST_F(PasswordManagerTest, FormSubmitFailedLogin) { |
| TEST_F(PasswordManagerTest, FormSubmitInvisibleLogin) { |
| // Tests fix of issue 28911: if the login form reappears on the subsequent |
| // page, but is invisible, it shouldn't count as a failed login. |
| - std::vector<PasswordForm*> result; // Empty password store. |
| + ScopedVector<PasswordForm> result; // Empty password store. |
| EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
| EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| - .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| + .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(&result)), Return())); |
| std::vector<PasswordForm> observed; |
| PasswordForm form(MakeSimpleForm()); |
| observed.push_back(form); |
| @@ -556,12 +560,11 @@ TEST_F(PasswordManagerTest, FormSubmitInvisibleLogin) { |
| TEST_F(PasswordManagerTest, InitiallyInvisibleForm) { |
| // Make sure an invisible login form still gets autofilled. |
| - std::vector<PasswordForm*> result; |
| - PasswordForm* existing = new PasswordForm(MakeSimpleForm()); |
| - result.push_back(existing); |
| + ScopedVector<PasswordForm> result; |
| + result.push_back(new PasswordForm(MakeSimpleForm())); |
| EXPECT_CALL(driver_, FillPasswordForm(_)); |
| EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| - .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| + .WillOnce(DoAll(WithArg<2>(InvokeConsumer(&result)), Return())); |
| std::vector<PasswordForm> observed; |
| PasswordForm form(MakeSimpleForm()); |
| observed.push_back(form); |
| @@ -590,15 +593,14 @@ TEST_F(PasswordManagerTest, SavingDependsOnManagerEnabledPreference) { |
| TEST_F(PasswordManagerTest, FillPasswordsOnDisabledManager) { |
| // Test fix for issue 158296: Passwords must be filled even if the password |
| // manager is disabled. |
| - std::vector<PasswordForm*> result; |
| - PasswordForm* existing = new PasswordForm(MakeSimpleForm()); |
| - result.push_back(existing); |
| + ScopedVector<PasswordForm> result; |
| + result.push_back(new PasswordForm(MakeSimpleForm())); |
| prefs_.SetUserPref(prefs::kPasswordManagerSavingEnabled, |
| new base::FundamentalValue(false)); |
| EXPECT_CALL(driver_, FillPasswordForm(_)); |
| EXPECT_CALL(*store_.get(), |
| GetLogins(_, testing::Eq(PasswordStore::DISALLOW_PROMPT), _)) |
| - .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| + .WillOnce(DoAll(WithArg<2>(InvokeConsumer(&result)), Return())); |
| std::vector<PasswordForm> observed; |
| PasswordForm form(MakeSimpleForm()); |
| observed.push_back(form); |
| @@ -608,10 +610,10 @@ TEST_F(PasswordManagerTest, FillPasswordsOnDisabledManager) { |
| TEST_F(PasswordManagerTest, FormSavedWithAutocompleteOff) { |
| // Test password form with non-generated password will be saved even if |
| // autocomplete=off. |
| - std::vector<PasswordForm*> result; // Empty password store. |
| + ScopedVector<PasswordForm> result; // Empty password store. |
| EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
| EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| - .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| + .WillOnce(DoAll(WithArg<2>(InvokeConsumer(&result)), Return())); |
| std::vector<PasswordForm> observed; |
| PasswordForm form(MakeSimpleForm()); |
| form.password_autocomplete_set = false; |
| @@ -643,10 +645,10 @@ TEST_F(PasswordManagerTest, FormSavedWithAutocompleteOff) { |
| TEST_F(PasswordManagerTest, GeneratedPasswordFormSavedAutocompleteOff) { |
| // Test password form with generated password will still be saved if |
| // autocomplete=off. |
| - std::vector<PasswordForm*> result; // Empty password store. |
| + ScopedVector<PasswordForm> result; // Empty password store. |
| EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
| EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| - .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| + .WillOnce(DoAll(WithArg<2>(InvokeConsumer(&result)), Return())); |
| std::vector<PasswordForm> observed; |
| PasswordForm form(MakeSimpleForm()); |
| form.password_autocomplete_set = false; |
| @@ -690,10 +692,10 @@ TEST_F(PasswordManagerTest, PasswordFormReappearance) { |
| // We assume that if we send our credentials and there |
| // is at least one visible password form in the next page that |
| // means that our previous login attempt failed. |
| - std::vector<PasswordForm*> result; // Empty password store. |
| + ScopedVector<PasswordForm> result; // Empty password store. |
| EXPECT_CALL(driver_, FillPasswordForm(_)).Times(0); |
| EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| - .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| + .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(&result)), Return())); |
| std::vector<PasswordForm> observed; |
| PasswordForm login_form(MakeTwitterLoginForm()); |
| observed.push_back(login_form); |
| @@ -759,10 +761,10 @@ TEST_F(PasswordManagerTest, SyncCredentialsNotSaved) { |
| .WillRepeatedly(Return(true)); |
| // Simulate loading a simple form with no existing stored password. |
| - std::vector<PasswordForm*> result; // Empty password store. |
| + ScopedVector<PasswordForm> result; // Empty password store. |
| EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
| EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| - .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| + .WillOnce(DoAll(WithArg<2>(InvokeConsumer(&result)), Return())); |
| std::vector<PasswordForm> observed; |
| PasswordForm form(MakeSimpleForm()); |
| form.password_autocomplete_set = false; |
| @@ -788,10 +790,10 @@ TEST_F(PasswordManagerTest, SyncCredentialsNotSaved) { |
| // failure. |
| TEST_F(PasswordManagerTest, |
| SeeingFormActionWithOnlyHttpHttpsChangeIsLoginFailure) { |
| - std::vector<PasswordForm*> result; // Empty password store. |
| + ScopedVector<PasswordForm> result; // Empty password store. |
| EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
| EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| - .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| + .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(&result)), Return())); |
| PasswordForm first_form(MakeSimpleForm()); |
| first_form.origin = GURL("http://www.xda-developers.com/"); |
| @@ -850,10 +852,10 @@ TEST_F(PasswordManagerTest, FormSubmitWithOnlyPassowrdField) { |
| // Test to verify that on submitting the HTML password form without having |
| // username input filed shows password save promt and saves the password to |
| // store. |
| - std::vector<PasswordForm*> result; // Empty password store. |
| + ScopedVector<PasswordForm> result; // Empty password store. |
| EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
| EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| - .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| + .WillOnce(DoAll(WithArg<2>(InvokeConsumer(&result)), Return())); |
| std::vector<PasswordForm> observed; |
| // Loads passsword form without username input field. |
| @@ -890,11 +892,11 @@ TEST_F(PasswordManagerTest, FillPasswordOnManyFrames) { |
| PasswordForm form(MakeSimpleForm()); // The observed and saved form. |
| // "Save" the form. |
| - std::vector<PasswordForm*> result; |
| - result.push_back(new PasswordForm(form)); // Calee owns the form. |
| + ScopedVector<PasswordForm> result; |
| + result.push_back(new PasswordForm(form)); |
| EXPECT_CALL(*store_.get(), |
| GetLogins(_, testing::Eq(PasswordStore::DISALLOW_PROMPT), _)) |
| - .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| + .WillOnce(DoAll(WithArg<2>(InvokeConsumer(&result)), Return())); |
| // The form will be seen the first time. |
| EXPECT_CALL(driver_, FillPasswordForm(_)).Times(1); |
| @@ -913,10 +915,10 @@ TEST_F(PasswordManagerTest, FillPasswordOnManyFrames) { |
| TEST_F(PasswordManagerTest, InPageNavigation) { |
| // Test that observing a newly submitted form shows the save password bar on |
| // call in page navigation. |
| - std::vector<PasswordForm*> result; // Empty password store. |
| + ScopedVector<PasswordForm> result; // Empty password store. |
| EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
| EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| - .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| + .WillOnce(DoAll(WithArg<2>(InvokeConsumer(&result)), Return())); |
| std::vector<PasswordForm> observed; |
| PasswordForm form(MakeSimpleForm()); |
| observed.push_back(form); |