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/host_power_save_blocker.h" | |
| 6 | |
| 7 #include <memory> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "base/threading/thread.h" | |
| 11 #include "remoting/host/fake_host_status_monitor.h" | |
| 12 #include "testing/gtest/include/gtest/gtest.h" | |
| 13 | |
| 14 namespace remoting { | |
| 15 | |
| 16 class HostPowerSaveBlockerTest : public testing::Test { | |
| 17 public: | |
| 18 HostPowerSaveBlockerTest(); | |
| 19 | |
| 20 protected: | |
| 21 void AssertActivated(); | |
| 22 void AssertDeactivated(); | |
| 23 | |
| 24 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.
| |
| 25 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.
| |
| 26 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.
| |
| 27 FakeHostStatusMonitor monitor_; | |
| 28 | |
| 29 protected: | |
| 30 std::unique_ptr<HostPowerSaveBlocker> blocker_; | |
| 31 }; | |
| 32 | |
| 33 HostPowerSaveBlockerTest::HostPowerSaveBlockerTest() | |
| 34 : ui_thread_("ui-thread"), | |
| 35 block_thread_("block-thread") { | |
| 36 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
| |
| 37 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.
| |
| 38 DCHECK(block_thread_.StartWithOptions( | |
| 39 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | |
| 40 DCHECK(block_thread_.WaitUntilThreadStarted()); | |
| 41 blocker_.reset(new HostPowerSaveBlocker(monitor_.AsWeakPtr(), | |
| 42 ui_thread_.task_runner(), | |
| 43 block_thread_.task_runner())); | |
| 44 } | |
| 45 | |
| 46 void HostPowerSaveBlockerTest::AssertActivated() { | |
| 47 ASSERT_TRUE(blocker_->blocker_); | |
| 48 } | |
| 49 | |
| 50 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.
| |
| 51 ASSERT_FALSE(blocker_->blocker_); | |
| 52 } | |
| 53 | |
| 54 TEST_F(HostPowerSaveBlockerTest, Activated) { | |
| 55 blocker_->OnClientConnected("jid/jid1@jid2.org"); | |
| 56 AssertActivated(); | |
| 57 blocker_->OnClientDisconnected("jid/jid3@jid4.org"); | |
| 58 AssertDeactivated(); | |
| 59 } | |
| 60 | |
| 61 } // namespace remoting | |
| OLD | NEW |