Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(230)

Unified Diff: remoting/host/linux/certificate_watcher_unittest.cc

Issue 1838313002: Restart the host when the third party auth certificate changes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698