| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/password_manager/chrome_password_manager_client.h" | 5 #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
| 6 | 6 |
| 7 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 7 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 8 #include "components/password_manager/core/browser/password_manager_logger.h" | 8 #include "components/password_manager/core/browser/password_manager_logger.h" |
| 9 #include "content/public/browser/browser_context.h" | 9 #include "content/public/browser/browser_context.h" |
| 10 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 using content::BrowserContext; | 14 using content::BrowserContext; |
| 15 using content::WebContents; | 15 using content::WebContents; |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 const char kTestText[] = "abcd1234"; |
| 20 |
| 19 class MockPasswordManagerLogger | 21 class MockPasswordManagerLogger |
| 20 : public password_manager::PasswordManagerLogger { | 22 : public password_manager::PasswordManagerLogger { |
| 21 public: | 23 public: |
| 22 MockPasswordManagerLogger() {} | 24 MockPasswordManagerLogger() {} |
| 23 | 25 |
| 24 MOCK_METHOD1(LogSavePasswordProgress, void(const std::string&)); | 26 MOCK_METHOD1(LogSavePasswordProgress, void(const std::string&)); |
| 25 }; | 27 }; |
| 26 | 28 |
| 27 } // namespace | 29 } // namespace |
| 28 | 30 |
| 29 class ChromePasswordManagerClientTest : public ChromeRenderViewHostTestHarness { | 31 class ChromePasswordManagerClientTest : public ChromeRenderViewHostTestHarness { |
| 30 public: | 32 public: |
| 31 virtual void SetUp() OVERRIDE; | 33 virtual void SetUp() OVERRIDE; |
| 32 | 34 |
| 33 protected: | 35 protected: |
| 34 ChromePasswordManagerClient* GetClient(); | 36 ChromePasswordManagerClient* GetClient(); |
| 37 |
| 38 testing::StrictMock<MockPasswordManagerLogger> logger; |
| 35 }; | 39 }; |
| 36 | 40 |
| 37 void ChromePasswordManagerClientTest::SetUp() { | 41 void ChromePasswordManagerClientTest::SetUp() { |
| 38 ChromeRenderViewHostTestHarness::SetUp(); | 42 ChromeRenderViewHostTestHarness::SetUp(); |
| 39 ChromePasswordManagerClient::CreateForWebContents(web_contents()); | 43 ChromePasswordManagerClient::CreateForWebContents(web_contents()); |
| 40 } | 44 } |
| 41 | 45 |
| 42 ChromePasswordManagerClient* ChromePasswordManagerClientTest::GetClient() { | 46 ChromePasswordManagerClient* ChromePasswordManagerClientTest::GetClient() { |
| 43 return ChromePasswordManagerClient::FromWebContents(web_contents()); | 47 return ChromePasswordManagerClient::FromWebContents(web_contents()); |
| 44 } | 48 } |
| 45 | 49 |
| 46 TEST_F(ChromePasswordManagerClientTest, LogSavePasswordProgress) { | 50 TEST_F(ChromePasswordManagerClientTest, LogSavePasswordProgressNoLogger) { |
| 47 ChromePasswordManagerClient* client = GetClient(); | 51 ChromePasswordManagerClient* client = GetClient(); |
| 48 testing::StrictMock<MockPasswordManagerLogger> logger; | |
| 49 const std::string text("abcd1234"); | |
| 50 | 52 |
| 53 EXPECT_CALL(logger, LogSavePasswordProgress(kTestText)).Times(0); |
| 51 // Before attaching the logger, no text should be passed. | 54 // Before attaching the logger, no text should be passed. |
| 52 client->LogSavePasswordProgress(text); | 55 client->LogSavePasswordProgress(kTestText); |
| 56 EXPECT_FALSE(client->IsLoggingActive()); |
| 57 } |
| 58 |
| 59 TEST_F(ChromePasswordManagerClientTest, LogSavePasswordProgressAttachLogger) { |
| 60 ChromePasswordManagerClient* client = GetClient(); |
| 53 | 61 |
| 54 // After attaching the logger, text should be passed. | 62 // After attaching the logger, text should be passed. |
| 55 client->SetLogger(&logger); | 63 client->SetLogger(&logger); |
| 56 EXPECT_CALL(logger, LogSavePasswordProgress(text)).Times(1); | 64 EXPECT_CALL(logger, LogSavePasswordProgress(kTestText)).Times(1); |
| 57 client->LogSavePasswordProgress(text); | 65 client->LogSavePasswordProgress(kTestText); |
| 66 EXPECT_TRUE(client->IsLoggingActive()); |
| 67 } |
| 58 | 68 |
| 59 // After detaching the logger, no text should be passed again. | 69 TEST_F(ChromePasswordManagerClientTest, LogSavePasswordProgressDetachLogger) { |
| 70 ChromePasswordManagerClient* client = GetClient(); |
| 71 |
| 72 client->SetLogger(&logger); |
| 73 // After detaching the logger, no text should be passed. |
| 60 client->SetLogger(NULL); | 74 client->SetLogger(NULL); |
| 61 client->LogSavePasswordProgress(text); | 75 EXPECT_CALL(logger, LogSavePasswordProgress(kTestText)).Times(0); |
| 76 client->LogSavePasswordProgress(kTestText); |
| 77 EXPECT_FALSE(client->IsLoggingActive()); |
| 62 } | 78 } |
| OLD | NEW |