Index: chrome/browser/password_manager/chrome_password_manager_client_unittest.cc |
diff --git a/chrome/browser/password_manager/chrome_password_manager_client_unittest.cc b/chrome/browser/password_manager/chrome_password_manager_client_unittest.cc |
index 6f192d31a98d1cff2a878e939f98c740c00e2049..d539399cf4eeca1c6bb83415367495a2ade35801 100644 |
--- a/chrome/browser/password_manager/chrome_password_manager_client_unittest.cc |
+++ b/chrome/browser/password_manager/chrome_password_manager_client_unittest.cc |
@@ -28,6 +28,7 @@ |
using content::BrowserContext; |
using content::WebContents; |
using testing::Return; |
+using testing::_; |
namespace { |
@@ -38,26 +39,18 @@ class MockLogReceiver : public password_manager::LogReceiver { |
MOCK_METHOD1(LogSavePasswordProgress, void(const std::string&)); |
}; |
-class TestChromePasswordManagerClient : public ChromePasswordManagerClient { |
+class MockChromePasswordManagerClient : public ChromePasswordManagerClient { |
public: |
- explicit TestChromePasswordManagerClient(content::WebContents* web_contents) |
- : ChromePasswordManagerClient(web_contents, nullptr), |
- is_sync_account_credential_(false) {} |
- ~TestChromePasswordManagerClient() override {} |
+ MOCK_CONST_METHOD2(IsSyncAccountCredential, |
+ bool(const std::string& username, |
+ const std::string& origin)); |
- bool IsSyncAccountCredential(const std::string& username, |
- const std::string& origin) const override { |
- return is_sync_account_credential_; |
- } |
- |
- void set_is_sync_account_credential(bool is_sync_account_credential) { |
- is_sync_account_credential_ = is_sync_account_credential; |
- } |
+ explicit MockChromePasswordManagerClient(content::WebContents* web_contents) |
+ : ChromePasswordManagerClient(web_contents, nullptr) {} |
+ ~MockChromePasswordManagerClient() override {} |
private: |
- bool is_sync_account_credential_; |
- |
- DISALLOW_COPY_AND_ASSIGN(TestChromePasswordManagerClient); |
+ DISALLOW_COPY_AND_ASSIGN(MockChromePasswordManagerClient); |
}; |
} // namespace |
@@ -228,16 +221,18 @@ TEST_F(ChromePasswordManagerClientTest, ShouldFilterAutofillResult_Reauth) { |
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
command_line->AppendSwitch( |
password_manager::switches::kDisallowAutofillSyncCredentialForReauth); |
- scoped_ptr<TestChromePasswordManagerClient> client( |
- new TestChromePasswordManagerClient(web_contents())); |
+ scoped_ptr<MockChromePasswordManagerClient> client( |
+ new MockChromePasswordManagerClient(web_contents())); |
autofill::PasswordForm form; |
- client->set_is_sync_account_credential(false); |
+ EXPECT_CALL(*client, IsSyncAccountCredential(_, _)) |
+ .WillRepeatedly(Return(false)); |
NavigateAndCommit( |
GURL("https://accounts.google.com/login?rart=123&continue=blah")); |
EXPECT_FALSE(client->ShouldFilterAutofillResult(form)); |
- client->set_is_sync_account_credential(true); |
+ EXPECT_CALL(*client, IsSyncAccountCredential(_, _)) |
+ .WillRepeatedly(Return(true)); |
NavigateAndCommit( |
GURL("https://accounts.google.com/login?rart=123&continue=blah")); |
EXPECT_TRUE(client->ShouldFilterAutofillResult(form)); |
@@ -257,10 +252,11 @@ TEST_F(ChromePasswordManagerClientTest, ShouldFilterAutofillResult_Reauth) { |
TEST_F(ChromePasswordManagerClientTest, ShouldFilterAutofillResult) { |
// Normally the client should allow any credentials through, even if they |
// are the sync credential. |
- scoped_ptr<TestChromePasswordManagerClient> client( |
- new TestChromePasswordManagerClient(web_contents())); |
+ scoped_ptr<MockChromePasswordManagerClient> client( |
+ new MockChromePasswordManagerClient(web_contents())); |
autofill::PasswordForm form; |
- client->set_is_sync_account_credential(true); |
+ EXPECT_CALL(*client, IsSyncAccountCredential(_, _)) |
+ .WillRepeatedly(Return(true)); |
NavigateAndCommit(GURL("https://accounts.google.com/Login")); |
EXPECT_FALSE(client->ShouldFilterAutofillResult(form)); |
@@ -268,8 +264,9 @@ TEST_F(ChromePasswordManagerClientTest, ShouldFilterAutofillResult) { |
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
command_line->AppendSwitch( |
password_manager::switches::kDisallowAutofillSyncCredential); |
- client.reset(new TestChromePasswordManagerClient(web_contents())); |
- client->set_is_sync_account_credential(true); |
+ client.reset(new MockChromePasswordManagerClient(web_contents())); |
+ EXPECT_CALL(*client, IsSyncAccountCredential(_, _)) |
+ .WillRepeatedly(Return(true)); |
NavigateAndCommit(GURL("https://accounts.google.com/Login")); |
EXPECT_TRUE(client->ShouldFilterAutofillResult(form)); |
} |