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