Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #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.
| |
| 6 #include "testing/gtest/include/gtest/gtest.h" | |
| 7 | |
| 8 namespace remoting { | |
| 9 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
| |
| 10 public: | |
| 11 void SetWatcher(CertificateWatcher* watcher) { watcher_ = watcher; } | |
| 12 void Start() override { | |
| 13 start_count++; | |
| 14 started_ = true; | |
| 15 } | |
| 16 void Stop() override { | |
| 17 stop_count++; | |
| 18 started_ = false; | |
| 19 } | |
| 20 void ScheduleSuicide() override { suicide_count++; } | |
| 21 void TriggerUpdate() { if (started_) watcher_->OnUpdate(); } | |
| 22 int start_count = 0; | |
| 23 int stop_count = 0; | |
| 24 int suicide_count = 0; | |
| 25 private: | |
|
Sergey Ulanov
2016/03/29 19:40:05
empty line above this one.
Yuwei
2016/03/29 19:57:02
Acknowledged.
| |
| 26 CertificateWatcher* watcher_; | |
| 27 bool started_ = false; | |
| 28 }; | |
| 29 | |
| 30 void CreateTestWatcher(MockCertificateWatcherImpl** pImpl, | |
| 31 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.
| |
| 32 MockCertificateWatcherImpl *impl = new MockCertificateWatcherImpl(); | |
| 33 CertificateWatcher* watcher = new CertificateWatcher(impl); | |
| 34 impl->SetWatcher(watcher); | |
| 35 *pImpl = impl; | |
| 36 *pWatcher = watcher; | |
| 37 } | |
| 38 | |
| 39 TEST(CertificateWatcherTest, StartAndStop) { | |
| 40 MockCertificateWatcherImpl* impl = nullptr; | |
| 41 CertificateWatcher* watcher = nullptr; | |
| 42 CreateTestWatcher(&impl, &watcher); | |
| 43 | |
| 44 EXPECT_EQ(0, impl->suicide_count); | |
| 45 impl->TriggerUpdate(); | |
| 46 EXPECT_EQ(0, impl->suicide_count); | |
| 47 watcher->Start(); | |
| 48 EXPECT_EQ(0, impl->suicide_count); | |
| 49 impl->TriggerUpdate(); | |
| 50 EXPECT_EQ(1, impl->suicide_count); | |
| 51 watcher->Stop(); | |
| 52 EXPECT_EQ(1, impl->suicide_count); | |
| 53 impl->TriggerUpdate(); | |
| 54 EXPECT_EQ(1, impl->suicide_count); | |
| 55 | |
| 56 EXPECT_EQ(1, impl->start_count); | |
| 57 EXPECT_EQ(1, impl->stop_count); | |
| 58 | |
| 59 delete watcher; | |
| 60 } | |
| 61 | |
| 62 TEST(CertificateWatcherTest, InhibitDeferSuicide) { | |
| 63 MockCertificateWatcherImpl* impl = nullptr; | |
| 64 CertificateWatcher* watcher = nullptr; | |
| 65 CreateTestWatcher(&impl, &watcher); | |
| 66 | |
| 67 watcher->Start(); | |
| 68 EXPECT_EQ(0, impl->suicide_count); | |
| 69 watcher->Inhibit(); | |
| 70 EXPECT_EQ(0, impl->suicide_count); | |
| 71 impl->TriggerUpdate(); | |
| 72 EXPECT_EQ(0, impl->suicide_count); | |
| 73 watcher->Uninhibit(); | |
| 74 EXPECT_EQ(1, impl->suicide_count); | |
| 75 | |
| 76 delete watcher; | |
| 77 } | |
| 78 | |
| 79 TEST(CertificateWatcherTest, UninhibitAndSuicide) { | |
| 80 MockCertificateWatcherImpl* impl = nullptr; | |
| 81 CertificateWatcher* watcher = nullptr; | |
| 82 CreateTestWatcher(&impl, &watcher); | |
| 83 | |
| 84 watcher->Start(); | |
| 85 EXPECT_EQ(0, impl->suicide_count); | |
| 86 watcher->Inhibit(); | |
| 87 EXPECT_EQ(0, impl->suicide_count); | |
| 88 watcher->Uninhibit(); | |
| 89 EXPECT_EQ(0, impl->suicide_count); | |
| 90 impl->TriggerUpdate(); | |
| 91 EXPECT_EQ(1, impl->suicide_count); | |
| 92 | |
| 93 delete watcher; | |
| 94 } | |
| 95 | |
| 96 TEST(CertificateWatcherTest, SuicideScheduleOnlyOnce) { | |
| 97 MockCertificateWatcherImpl* impl = nullptr; | |
| 98 CertificateWatcher* watcher = nullptr; | |
| 99 CreateTestWatcher(&impl, &watcher); | |
| 100 | |
| 101 watcher->Start(); | |
| 102 EXPECT_EQ(0, impl->suicide_count); | |
| 103 impl->TriggerUpdate(); | |
| 104 EXPECT_EQ(1, impl->suicide_count); | |
| 105 impl->TriggerUpdate(); | |
| 106 EXPECT_EQ(1, impl->suicide_count); | |
| 107 | |
| 108 delete watcher; | |
| 109 } | |
| 110 } | |
| OLD | NEW |