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

Unified Diff: remoting/host/host_power_save_blocker_unittest.cc

Issue 2080723008: [Chromoting] Use device::PowerSaveBlocker to block screen saver (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add unittest for HostPowerSaveBlocker Created 4 years, 5 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/host_power_save_blocker_unittest.cc
diff --git a/remoting/host/host_power_save_blocker_unittest.cc b/remoting/host/host_power_save_blocker_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..73bd499eab7ed3cb6eb029a6def90e534a978f81
--- /dev/null
+++ b/remoting/host/host_power_save_blocker_unittest.cc
@@ -0,0 +1,61 @@
+// 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/host_power_save_blocker.h"
+
+#include <memory>
+
+#include "base/logging.h"
+#include "base/threading/thread.h"
+#include "remoting/host/fake_host_status_monitor.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace remoting {
+
+class HostPowerSaveBlockerTest : public testing::Test {
+ public:
+ HostPowerSaveBlockerTest();
+
+ protected:
+ void AssertActivated();
+ void AssertDeactivated();
+
+ private:
Sergey Ulanov 2016/07/14 19:52:48 All of this variables can be protected. There is n
Hzj_jie 2016/07/14 23:20:04 Done.
+ base::Thread ui_thread_;
Sergey Ulanov 2016/07/14 19:52:48 On UI thread must be the main application thread.
Hzj_jie 2016/07/14 23:20:03 Done.
+ base::Thread block_thread_;
Sergey Ulanov 2016/07/14 19:52:48 blocking_io_thread_ or file_thread_?
Hzj_jie 2016/07/14 23:20:03 Follow PowerSaveBlocker definition. It's a little
Sergey Ulanov 2016/07/14 23:30:57 Call it blocking_thread_? block_thread_ is confusi
Hzj_jie 2016/07/15 02:12:00 Oh, sorry, I missed ing.
+ FakeHostStatusMonitor monitor_;
+
+ protected:
+ std::unique_ptr<HostPowerSaveBlocker> blocker_;
+};
+
+HostPowerSaveBlockerTest::HostPowerSaveBlockerTest()
+ : ui_thread_("ui-thread"),
+ block_thread_("block-thread") {
+ DCHECK(ui_thread_.Start());
Sergey Ulanov 2016/07/14 19:52:48 this won't start the thread in release builds. Nev
Hzj_jie 2016/07/14 23:20:03 ASSERT_TRUE won't work in constructor (It returns
Sergey Ulanov 2016/07/14 23:30:57 It should work. It doesn't return any result. It w
Hzj_jie 2016/07/15 02:12:00 Emmm... Here is the error message, ../../remoting/
Sergey Ulanov 2016/07/15 06:15:33 "must not return void expression" gah, C++, this i
+ DCHECK(ui_thread_.WaitUntilThreadStarted());
Sergey Ulanov 2016/07/14 19:52:48 Why? If you really need it then use StartAndWaitFo
Hzj_jie 2016/07/14 23:20:03 Done.
+ DCHECK(block_thread_.StartWithOptions(
+ base::Thread::Options(base::MessageLoop::TYPE_IO, 0)));
+ DCHECK(block_thread_.WaitUntilThreadStarted());
+ blocker_.reset(new HostPowerSaveBlocker(monitor_.AsWeakPtr(),
+ ui_thread_.task_runner(),
+ block_thread_.task_runner()));
+}
+
+void HostPowerSaveBlockerTest::AssertActivated() {
+ ASSERT_TRUE(blocker_->blocker_);
+}
+
+void HostPowerSaveBlockerTest::AssertDeactivated() {
Sergey Ulanov 2016/07/14 19:52:48 You can replaced these two methods with bool is_ac
Hzj_jie 2016/07/14 23:20:04 Done.
+ ASSERT_FALSE(blocker_->blocker_);
+}
+
+TEST_F(HostPowerSaveBlockerTest, Activated) {
+ blocker_->OnClientConnected("jid/jid1@jid2.org");
+ AssertActivated();
+ blocker_->OnClientDisconnected("jid/jid3@jid4.org");
+ AssertDeactivated();
+}
+
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698