Chromium Code Reviews| Index: chrome/browser/password_manager/password_manager_unittest.cc |
| diff --git a/chrome/browser/password_manager/password_manager_unittest.cc b/chrome/browser/password_manager/password_manager_unittest.cc |
| index dba4fb766f54c63e8948c84ca28260cdde6df388..0ff7b9a0ece5ea69355cdf6f70ca1c1ff119e003 100644 |
| --- a/chrome/browser/password_manager/password_manager_unittest.cc |
| +++ b/chrome/browser/password_manager/password_manager_unittest.cc |
| @@ -10,6 +10,7 @@ |
| #include "chrome/browser/password_manager/mock_password_store.h" |
| #include "chrome/browser/password_manager/password_manager.h" |
| #include "chrome/browser/password_manager/password_manager_delegate.h" |
| +#include "chrome/browser/password_manager/password_manager_driver.h" |
| #include "chrome/browser/password_manager/password_store.h" |
| #include "chrome/browser/password_manager/password_store_factory.h" |
| #include "chrome/common/pref_names.h" |
| @@ -23,6 +24,8 @@ |
| #include "testing/gmock/include/gmock/gmock.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| +class PasswordManagerDriver; |
|
Patrick Dubroy
2014/02/03 13:15:08
Not needed.
blundell
2014/02/03 14:37:59
Done.
|
| + |
| using autofill::PasswordForm; |
| using base::ASCIIToUTF16; |
| using testing::_; |
| @@ -35,9 +38,14 @@ namespace { |
| class MockPasswordManagerDelegate : public PasswordManagerDelegate { |
| public: |
| - MOCK_METHOD1(FillPasswordForm, void(const autofill::PasswordFormFillData&)); |
| MOCK_METHOD1(AddSavePasswordInfoBarIfPermitted, void(PasswordFormManager*)); |
| MOCK_METHOD0(GetProfile, Profile*()); |
| + MOCK_METHOD0(GetDriver, PasswordManagerDriver*()); |
| +}; |
| + |
| +class MockPasswordManagerDriver : public PasswordManagerDriver { |
| + public: |
| + MOCK_METHOD1(FillPasswordForm, void(const autofill::PasswordFormFillData&)); |
| MOCK_METHOD0(DidLastPageLoadEncounterSSLErrors, bool()); |
| }; |
| @@ -83,9 +91,10 @@ class PasswordManagerTest : public ChromeRenderViewHostTestHarness { |
| profile(), MockPasswordStore::Build).get()); |
| EXPECT_CALL(delegate_, GetProfile()).WillRepeatedly(Return(profile())); |
| + EXPECT_CALL(delegate_, GetDriver()).WillRepeatedly(Return(&driver_)); |
| manager_ = TestPasswordManager::CreateForWebContentsAndDelegate( |
| web_contents(), &delegate_); |
| - EXPECT_CALL(delegate_, DidLastPageLoadEncounterSSLErrors()) |
| + EXPECT_CALL(driver_, DidLastPageLoadEncounterSSLErrors()) |
| .WillRepeatedly(Return(false)); |
| } |
| @@ -183,6 +192,7 @@ class PasswordManagerTest : public ChromeRenderViewHostTestHarness { |
| scoped_refptr<MockPasswordStore> store_; |
| TestPasswordManager* manager_; |
| MockPasswordManagerDelegate delegate_; // Owned by manager_. |
| + MockPasswordManagerDriver driver_; |
| PasswordForm submitted_form_; |
| }; |
| @@ -200,7 +210,7 @@ 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. |
| - EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); |
| + EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
| EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| std::vector<PasswordForm> observed; |
| @@ -232,7 +242,7 @@ TEST_F(PasswordManagerTest, GeneratedPasswordFormSubmitEmptyStore) { |
| // This test is the same FormSubmitEmptyStore, except that it simulates the |
| // user generating the password through the browser. |
| std::vector<PasswordForm*> result; // Empty password store. |
| - EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); |
| + EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
| EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| std::vector<PasswordForm> observed; |
| @@ -266,7 +276,7 @@ TEST_F(PasswordManagerTest, FormSubmitNoGoodMatch) { |
| PasswordForm* existing_different = new PasswordForm(MakeSimpleForm()); |
| existing_different->username_value = ASCIIToUTF16("google2"); |
| result.push_back(existing_different); |
| - EXPECT_CALL(delegate_, FillPasswordForm(_)); |
| + EXPECT_CALL(driver_, FillPasswordForm(_)); |
| EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| @@ -296,7 +306,7 @@ TEST_F(PasswordManagerTest, FormSubmitNoGoodMatch) { |
| TEST_F(PasswordManagerTest, FormSeenThenLeftPage) { |
| std::vector<PasswordForm*> result; // Empty password store. |
| - EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); |
| + EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
| EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| std::vector<PasswordForm> observed; |
| @@ -317,7 +327,7 @@ TEST_F(PasswordManagerTest, FormSubmitAfterNavigateSubframe) { |
| // Test that navigating a subframe does not prevent us from showing the save |
| // password infobar. |
| std::vector<PasswordForm*> result; // Empty password store. |
| - EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); |
| + EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
| EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| std::vector<PasswordForm> observed; |
| @@ -353,7 +363,7 @@ TEST_F(PasswordManagerTest, FormSubmitAfterNavigateSubframe) { |
| // This test verifies a fix for http://crbug.com/236673 |
| TEST_F(PasswordManagerTest, FormSubmitWithFormOnPreviousPage) { |
| std::vector<PasswordForm*> result; // Empty password store. |
| - EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); |
| + EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
| EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| PasswordForm first_form(MakeSimpleForm()); |
| @@ -405,7 +415,7 @@ TEST_F(PasswordManagerTest, FormSubmitWithFormOnPreviousPage) { |
| TEST_F(PasswordManagerTest, FormSubmitFailedLogin) { |
| std::vector<PasswordForm*> result; // Empty password store. |
| - EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); |
| + EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
| EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| std::vector<PasswordForm> observed; |
| @@ -426,7 +436,7 @@ 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. |
| - EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); |
| + EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
| EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| std::vector<PasswordForm> observed; |
| @@ -459,7 +469,7 @@ TEST_F(PasswordManagerTest, InitiallyInvisibleForm) { |
| std::vector<PasswordForm*> result; |
| PasswordForm* existing = new PasswordForm(MakeSimpleForm()); |
| result.push_back(existing); |
| - EXPECT_CALL(delegate_, FillPasswordForm(_)); |
| + EXPECT_CALL(driver_, FillPasswordForm(_)); |
| EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| std::vector<PasswordForm> observed; |
| @@ -494,7 +504,7 @@ TEST_F(PasswordManagerTest, FillPasswordsOnDisabledManager) { |
| TestingPrefServiceSyncable* prefService = profile()->GetTestingPrefService(); |
| prefService->SetUserPref(prefs::kPasswordManagerEnabled, |
| base::Value::CreateBooleanValue(false)); |
| - EXPECT_CALL(delegate_, FillPasswordForm(_)); |
| + EXPECT_CALL(driver_, FillPasswordForm(_)); |
| EXPECT_CALL(*store_.get(), |
| GetLogins(_, testing::Eq(PasswordStore::DISALLOW_PROMPT), _)) |
| .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| @@ -508,7 +518,7 @@ TEST_F(PasswordManagerTest, FormNotSavedAutocompleteOff) { |
| // Test password form with non-generated password will not be saved if |
| // autocomplete=off. |
| std::vector<PasswordForm*> result; // Empty password store. |
| - EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); |
| + EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
| EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| std::vector<PasswordForm> observed; |
| @@ -536,7 +546,7 @@ TEST_F(PasswordManagerTest, GeneratedPasswordFormSavedAutocompleteOff) { |
| // Test password form with generated password will still be saved if |
| // autocomplete=off. |
| std::vector<PasswordForm*> result; // Empty password store. |
| - EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(Exactly(0)); |
| + EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0)); |
| EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| .WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| std::vector<PasswordForm> observed; |
| @@ -576,7 +586,7 @@ TEST_F(PasswordManagerTest, PasswordFormReappearance) { |
| // 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. |
| - EXPECT_CALL(delegate_, FillPasswordForm(_)).Times(0); |
| + EXPECT_CALL(driver_, FillPasswordForm(_)).Times(0); |
| EXPECT_CALL(*store_.get(), GetLogins(_, _, _)) |
| .WillRepeatedly(DoAll(WithArg<2>(InvokeConsumer(result)), Return())); |
| std::vector<PasswordForm> observed; |