Chromium Code Reviews| Index: components/password_manager/core/browser/log_manager_unittest.cc |
| diff --git a/components/password_manager/core/browser/log_manager_unittest.cc b/components/password_manager/core/browser/log_manager_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d8fe4fdc16782e10c76d6c6044f20cc82dab3577 |
| --- /dev/null |
| +++ b/components/password_manager/core/browser/log_manager_unittest.cc |
| @@ -0,0 +1,98 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "components/password_manager/core/browser/log_manager.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/bind_helpers.h" |
| +#include "base/macros.h" |
| +#include "components/password_manager/core/browser/log_receiver.h" |
| +#include "components/password_manager/core/browser/log_router.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +using testing::_; |
| + |
| +namespace password_manager { |
| + |
| +namespace { |
| + |
| +const char kTestText[] = "abcd1234"; |
| + |
| +class MockLogReceiver : public password_manager::LogReceiver { |
| + public: |
| + MockLogReceiver() = default; |
| + MOCK_METHOD1(LogSavePasswordProgress, void(const std::string&)); |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(MockLogReceiver); |
| +}; |
| + |
| +class MockNotifiedObject { |
| + public: |
| + MockNotifiedObject() = default; |
| + MOCK_METHOD1(NotifyAboutLoggingActivity, void(bool)); |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(MockNotifiedObject); |
| +}; |
| + |
| +} // namespace |
| + |
| +class LogManagerTest : public testing::Test { |
| + protected: |
| + void SetUp() override { |
| + manager_ = LogManager::Create( |
| + &router_, |
| + base::Bind(&MockNotifiedObject::NotifyAboutLoggingActivity, |
| + base::Unretained(¬ified_object_))) |
| + .Pass(); |
|
vasilii
2015/11/13 12:17:31
Not needed anymore
vabr (Chromium)
2015/11/13 20:48:18
Done.
|
| + } |
| + |
| + void TearDown() override { |
| + manager_.reset(); // Destruct before LogRouter. |
| + } |
| + |
| + protected: |
| + testing::StrictMock<MockLogReceiver> receiver_; |
| + LogRouter router_; |
| + testing::StrictMock<MockNotifiedObject> notified_object_; |
| + scoped_ptr<LogManager> manager_; |
| +}; |
| + |
| +TEST_F(LogManagerTest, LogSavePasswordProgressNoReceiver) { |
| + EXPECT_CALL(receiver_, LogSavePasswordProgress(_)).Times(0); |
| + // Before attaching the receiver, no text should be passed. |
| + manager_->LogSavePasswordProgress(kTestText); |
| + EXPECT_FALSE(manager_->IsLoggingActive()); |
| +} |
| + |
| +TEST_F(LogManagerTest, LogSavePasswordProgressAttachReceiver) { |
| + EXPECT_FALSE(manager_->IsLoggingActive()); |
| + |
| + EXPECT_CALL(notified_object_, NotifyAboutLoggingActivity(true)); |
| + EXPECT_EQ(std::string(), router_.RegisterReceiver(&receiver_)); |
| + EXPECT_TRUE(manager_->IsLoggingActive()); |
| + // After attaching the logger, text should be passed. |
| + EXPECT_CALL(receiver_, LogSavePasswordProgress(kTestText)); |
| + manager_->LogSavePasswordProgress(kTestText); |
| + EXPECT_CALL(notified_object_, NotifyAboutLoggingActivity(false)); |
| + router_.UnregisterReceiver(&receiver_); |
| + EXPECT_FALSE(manager_->IsLoggingActive()); |
| +} |
| + |
| +TEST_F(LogManagerTest, LogSavePasswordProgressDetachReceiver) { |
| + EXPECT_CALL(notified_object_, NotifyAboutLoggingActivity(true)); |
| + EXPECT_EQ(std::string(), router_.RegisterReceiver(&receiver_)); |
| + EXPECT_TRUE(manager_->IsLoggingActive()); |
| + EXPECT_CALL(notified_object_, NotifyAboutLoggingActivity(false)); |
| + router_.UnregisterReceiver(&receiver_); |
| + EXPECT_FALSE(manager_->IsLoggingActive()); |
| + |
| + // After detaching the logger, no text should be passed. |
| + EXPECT_CALL(receiver_, LogSavePasswordProgress(_)).Times(0); |
| + manager_->LogSavePasswordProgress(kTestText); |
| +} |
| + |
| +} // namespace password_manager |