Index: components/password_manager/core/browser/password_generation_manager_unittest.cc |
diff --git a/components/password_manager/core/browser/password_generation_manager_unittest.cc b/components/password_manager/core/browser/password_generation_manager_unittest.cc |
index a19997842bf8be981054c14e9f7e731fbdc78f91..97913e2dfe4bea533c1f6ddb9254c4e22506539e 100644 |
--- a/components/password_manager/core/browser/password_generation_manager_unittest.cc |
+++ b/components/password_manager/core/browser/password_generation_manager_unittest.cc |
@@ -20,10 +20,12 @@ |
#include "components/password_manager/core/browser/stub_password_manager_driver.h" |
#include "components/password_manager/core/browser/test_password_store.h" |
#include "components/password_manager/core/common/password_manager_pref_names.h" |
+#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
#include "url/gurl.h" |
using base::ASCIIToUTF16; |
+using testing::_; |
namespace password_manager { |
@@ -62,37 +64,26 @@ class TestPasswordManagerDriver : public StubPasswordManagerDriver { |
std::vector<autofill::FormData> found_account_creation_forms_; |
}; |
-class TestPasswordManagerClient : public StubPasswordManagerClient { |
+class MockPasswordManagerClient : public StubPasswordManagerClient { |
public: |
- TestPasswordManagerClient(scoped_ptr<PrefService> prefs) |
- : prefs_(prefs.Pass()), |
- store_(new TestPasswordStore), |
- driver_(this), |
- is_sync_enabled_(false), |
- is_off_the_record_(false) {} |
+ MOCK_CONST_METHOD1(IsPasswordSyncEnabled, bool(CustomPassphraseState)); |
+ MOCK_CONST_METHOD0(IsSavingEnabledForCurrentPage, bool()); |
+ MOCK_CONST_METHOD0(IsOffTheRecord, bool()); |
- ~TestPasswordManagerClient() override { store_->Shutdown(); } |
+ MockPasswordManagerClient(scoped_ptr<PrefService> prefs) |
+ : prefs_(prefs.Pass()), store_(new TestPasswordStore), driver_(this) {} |
+ |
+ ~MockPasswordManagerClient() override { store_->Shutdown(); } |
- bool IsOffTheRecord() const override { return is_off_the_record_; } |
PasswordStore* GetPasswordStore() const override { return store_.get(); } |
PrefService* GetPrefs() override { return prefs_.get(); } |
- bool IsPasswordSyncEnabled(CustomPassphraseState state) const override { |
- return is_sync_enabled_; |
- } |
- |
- void set_is_password_sync_enabled(bool enabled) { |
- is_sync_enabled_ = enabled; |
- } |
TestPasswordManagerDriver* test_driver() { return &driver_; } |
- void set_is_off_the_record(bool is_otr) { is_off_the_record_ = is_otr; } |
private: |
scoped_ptr<PrefService> prefs_; |
scoped_refptr<TestPasswordStore> store_; |
TestPasswordManagerDriver driver_; |
- bool is_sync_enabled_; |
- bool is_off_the_record_; |
}; |
} // anonymous namespace |
@@ -106,7 +97,7 @@ class PasswordGenerationManagerTest : public testing::Test { |
scoped_ptr<TestingPrefServiceSimple> prefs(new TestingPrefServiceSimple()); |
prefs->registry()->RegisterBooleanPref(prefs::kPasswordManagerSavingEnabled, |
true); |
- client_.reset(new TestPasswordManagerClient(prefs.Pass())); |
+ client_.reset(new MockPasswordManagerClient(prefs.Pass())); |
} |
void TearDown() override { client_.reset(); } |
@@ -126,7 +117,7 @@ class PasswordGenerationManagerTest : public testing::Test { |
GetGenerationManager()->DetectAccountCreationForms(forms); |
} |
- scoped_ptr<TestPasswordManagerClient> client_; |
+ scoped_ptr<MockPasswordManagerClient> client_; |
}; |
TEST_F(PasswordGenerationManagerTest, IsGenerationEnabled) { |
@@ -134,17 +125,20 @@ TEST_F(PasswordGenerationManagerTest, IsGenerationEnabled) { |
// be enabled. |
PrefService* prefs = client_->GetPrefs(); |
prefs->SetBoolean(prefs::kPasswordManagerSavingEnabled, true); |
- client_->set_is_password_sync_enabled(true); |
+ EXPECT_CALL(*client_, IsPasswordSyncEnabled(_)) |
+ .WillRepeatedly(testing::Return(true)); |
EXPECT_TRUE(IsGenerationEnabled()); |
// Disabling password syncing should cause generation to be disabled. |
- client_->set_is_password_sync_enabled(false); |
+ EXPECT_CALL(*client_, IsPasswordSyncEnabled(_)) |
+ .WillRepeatedly(testing::Return(false)); |
EXPECT_FALSE(IsGenerationEnabled()); |
// Disabling the PasswordManager should cause generation to be disabled even |
// if syncing is enabled. |
prefs->SetBoolean(prefs::kPasswordManagerSavingEnabled, false); |
- client_->set_is_password_sync_enabled(true); |
+ EXPECT_CALL(*client_, IsPasswordSyncEnabled(_)) |
+ .WillRepeatedly(testing::Return(true)); |
EXPECT_FALSE(IsGenerationEnabled()); |
} |
@@ -152,7 +146,8 @@ TEST_F(PasswordGenerationManagerTest, DetectAccountCreationForms) { |
// Setup so that IsGenerationEnabled() returns true. |
PrefService* prefs = client_->GetPrefs(); |
prefs->SetBoolean(prefs::kPasswordManagerSavingEnabled, true); |
- client_->set_is_password_sync_enabled(true); |
+ EXPECT_CALL(*client_, IsPasswordSyncEnabled(_)) |
+ .WillRepeatedly(testing::Return(true)); |
autofill::FormData login_form; |
login_form.origin = GURL("http://www.yahoo.com/login/"); |
@@ -202,10 +197,11 @@ TEST_F(PasswordGenerationManagerTest, UpdatePasswordSyncStateIncognito) { |
// Disable password manager by going incognito. Even though password |
// syncing is enabled, generation should still |
// be disabled. |
- client_->set_is_off_the_record(true); |
+ EXPECT_CALL(*client_, IsOffTheRecord()).WillRepeatedly(testing::Return(true)); |
PrefService* prefs = client_->GetPrefs(); |
prefs->SetBoolean(prefs::kPasswordManagerSavingEnabled, true); |
- client_->set_is_password_sync_enabled(true); |
+ EXPECT_CALL(*client_, IsPasswordSyncEnabled(_)) |
+ .WillRepeatedly(testing::Return(true)); |
EXPECT_FALSE(IsGenerationEnabled()); |
} |