Chromium Code Reviews| Index: remoting/host/linux/certificate_watcher_unittest.cc |
| diff --git a/remoting/host/linux/certificate_watcher_unittest.cc b/remoting/host/linux/certificate_watcher_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2e23cb5f39837da2e48eb53bb63ae32be8606013 |
| --- /dev/null |
| +++ b/remoting/host/linux/certificate_watcher_unittest.cc |
| @@ -0,0 +1,110 @@ |
| +// Copyright 2016 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 "remoting/host/linux/certificate_watcher.h" |
|
Sergey Ulanov
2016/03/29 19:40:05
nit: emtpy line after this include
Yuwei
2016/03/29 19:57:03
Acknowledged.
Yuwei
2016/03/30 18:47:45
Done.
|
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace remoting { |
| + class MockCertificateWatcherImpl : public CertificateWatcherImplInterface { |
|
Sergey Ulanov
2016/03/29 19:40:04
add empty line after namespace.
indentation.
Sergey Ulanov
2016/03/29 19:40:05
So this test mocks the most interesting part of th
Yuwei
2016/03/29 19:57:02
Acknowledged.
Yuwei
2016/03/29 19:57:02
Acknowledged.
Yuwei
2016/03/30 18:47:45
Class rewritten to test the real situation of watc
|
| + public: |
| + void SetWatcher(CertificateWatcher* watcher) { watcher_ = watcher; } |
| + void Start() override { |
| + start_count++; |
| + started_ = true; |
| + } |
| + void Stop() override { |
| + stop_count++; |
| + started_ = false; |
| + } |
| + void ScheduleSuicide() override { suicide_count++; } |
| + void TriggerUpdate() { if (started_) watcher_->OnUpdate(); } |
| + int start_count = 0; |
| + int stop_count = 0; |
| + int suicide_count = 0; |
| + private: |
|
Sergey Ulanov
2016/03/29 19:40:05
empty line above this one.
Yuwei
2016/03/29 19:57:02
Acknowledged.
|
| + CertificateWatcher* watcher_; |
| + bool started_ = false; |
| + }; |
| + |
| + void CreateTestWatcher(MockCertificateWatcherImpl** pImpl, |
| + CertificateWatcher** pWatcher) { |
|
Sergey Ulanov
2016/03/29 19:40:05
We don't use Hungarian notation, so this should be
Yuwei
2016/03/29 19:57:02
Acknowledged.
|
| + MockCertificateWatcherImpl *impl = new MockCertificateWatcherImpl(); |
| + CertificateWatcher* watcher = new CertificateWatcher(impl); |
| + impl->SetWatcher(watcher); |
| + *pImpl = impl; |
| + *pWatcher = watcher; |
| + } |
| + |
| + TEST(CertificateWatcherTest, StartAndStop) { |
| + MockCertificateWatcherImpl* impl = nullptr; |
| + CertificateWatcher* watcher = nullptr; |
| + CreateTestWatcher(&impl, &watcher); |
| + |
| + EXPECT_EQ(0, impl->suicide_count); |
| + impl->TriggerUpdate(); |
| + EXPECT_EQ(0, impl->suicide_count); |
| + watcher->Start(); |
| + EXPECT_EQ(0, impl->suicide_count); |
| + impl->TriggerUpdate(); |
| + EXPECT_EQ(1, impl->suicide_count); |
| + watcher->Stop(); |
| + EXPECT_EQ(1, impl->suicide_count); |
| + impl->TriggerUpdate(); |
| + EXPECT_EQ(1, impl->suicide_count); |
| + |
| + EXPECT_EQ(1, impl->start_count); |
| + EXPECT_EQ(1, impl->stop_count); |
| + |
| + delete watcher; |
| + } |
| + |
| + TEST(CertificateWatcherTest, InhibitDeferSuicide) { |
| + MockCertificateWatcherImpl* impl = nullptr; |
| + CertificateWatcher* watcher = nullptr; |
| + CreateTestWatcher(&impl, &watcher); |
| + |
| + watcher->Start(); |
| + EXPECT_EQ(0, impl->suicide_count); |
| + watcher->Inhibit(); |
| + EXPECT_EQ(0, impl->suicide_count); |
| + impl->TriggerUpdate(); |
| + EXPECT_EQ(0, impl->suicide_count); |
| + watcher->Uninhibit(); |
| + EXPECT_EQ(1, impl->suicide_count); |
| + |
| + delete watcher; |
| + } |
| + |
| + TEST(CertificateWatcherTest, UninhibitAndSuicide) { |
| + MockCertificateWatcherImpl* impl = nullptr; |
| + CertificateWatcher* watcher = nullptr; |
| + CreateTestWatcher(&impl, &watcher); |
| + |
| + watcher->Start(); |
| + EXPECT_EQ(0, impl->suicide_count); |
| + watcher->Inhibit(); |
| + EXPECT_EQ(0, impl->suicide_count); |
| + watcher->Uninhibit(); |
| + EXPECT_EQ(0, impl->suicide_count); |
| + impl->TriggerUpdate(); |
| + EXPECT_EQ(1, impl->suicide_count); |
| + |
| + delete watcher; |
| + } |
| + |
| + TEST(CertificateWatcherTest, SuicideScheduleOnlyOnce) { |
| + MockCertificateWatcherImpl* impl = nullptr; |
| + CertificateWatcher* watcher = nullptr; |
| + CreateTestWatcher(&impl, &watcher); |
| + |
| + watcher->Start(); |
| + EXPECT_EQ(0, impl->suicide_count); |
| + impl->TriggerUpdate(); |
| + EXPECT_EQ(1, impl->suicide_count); |
| + impl->TriggerUpdate(); |
| + EXPECT_EQ(1, impl->suicide_count); |
| + |
| + delete watcher; |
| + } |
| +} |