OLD | NEW |
| (Empty) |
1 // Copyright 2015 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 "device/wake_lock/wake_lock_service_context.h" | |
6 | |
7 #include <memory> | |
8 | |
9 #include "base/message_loop/message_loop.h" | |
10 #include "base/process/kill.h" | |
11 #include "base/threading/thread_task_runner_handle.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | |
13 | |
14 namespace device { | |
15 | |
16 class WakeLockServiceContextTest : public testing::Test { | |
17 public: | |
18 WakeLockServiceContextTest() | |
19 : wake_lock_service_context_( | |
20 base::ThreadTaskRunnerHandle::Get(), | |
21 base::Bind(&WakeLockServiceContextTest::GetNativeView, | |
22 base::Unretained(this))) {} | |
23 | |
24 protected: | |
25 void RequestWakeLock() { GetWakeLockServiceContext()->RequestWakeLock(); } | |
26 | |
27 void CancelWakeLock() { GetWakeLockServiceContext()->CancelWakeLock(); } | |
28 | |
29 WakeLockServiceContext* GetWakeLockServiceContext() { | |
30 return &wake_lock_service_context_; | |
31 } | |
32 | |
33 bool HasWakeLock() { | |
34 return GetWakeLockServiceContext()->HasWakeLockForTests(); | |
35 } | |
36 | |
37 private: | |
38 gfx::NativeView GetNativeView() { return nullptr; } | |
39 | |
40 base::MessageLoop message_loop_; | |
41 WakeLockServiceContext wake_lock_service_context_; | |
42 }; | |
43 | |
44 TEST_F(WakeLockServiceContextTest, NoLockInitially) { | |
45 EXPECT_FALSE(HasWakeLock()); | |
46 } | |
47 | |
48 TEST_F(WakeLockServiceContextTest, LockUnlock) { | |
49 ASSERT_TRUE(GetWakeLockServiceContext()); | |
50 | |
51 // Request wake lock. | |
52 RequestWakeLock(); | |
53 | |
54 // Should set the blocker. | |
55 EXPECT_TRUE(HasWakeLock()); | |
56 | |
57 // Remove wake lock request. | |
58 CancelWakeLock(); | |
59 | |
60 // Should remove the blocker. | |
61 EXPECT_FALSE(HasWakeLock()); | |
62 } | |
63 | |
64 } // namespace device | |
OLD | NEW |