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

Side by Side Diff: device/wake_lock/wake_lock_service_context_unittest.cc

Issue 2734943003: Device Service: Decouple Wake Lock from //content (Closed)
Patch Set: Rebase Created 3 years, 8 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 unified diff | Download patch
OLDNEW
(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
OLDNEW
« no previous file with comments | « device/wake_lock/wake_lock_service_context.cc ('k') | device/wake_lock/wake_lock_service_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698