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_state.h" |
| 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 |
| 9 namespace content { |
| 10 |
| 11 class WakeLockStateTest : public testing::Test { |
| 12 protected: |
| 13 void SetUp() override { |
| 14 rfh1_ = MakeFakeRFHPtr(0xdeadbeef); |
| 15 rfh2_ = MakeFakeRFHPtr(0xbaadf00d); |
| 16 } |
| 17 |
| 18 const RenderFrameHost* rfh1_; |
| 19 const RenderFrameHost* rfh2_; |
| 20 WakeLockState state_; |
| 21 |
| 22 private: |
| 23 static const RenderFrameHost* MakeFakeRFHPtr(int fake_ptr_value) { |
| 24 return reinterpret_cast<RenderFrameHost*>(fake_ptr_value); |
| 25 } |
| 26 }; |
| 27 |
| 28 TEST_F(WakeLockStateTest, InitialState) { |
| 29 EXPECT_FALSE(state_.GetLockState()); |
| 30 } |
| 31 |
| 32 TEST_F(WakeLockStateTest, AddFrame) { |
| 33 state_.AddFrame(rfh1_); |
| 34 EXPECT_TRUE(state_.GetLockState()); |
| 35 } |
| 36 |
| 37 TEST_F(WakeLockStateTest, AddFrameTwice) { |
| 38 state_.AddFrame(rfh1_); |
| 39 state_.AddFrame(rfh1_); |
| 40 EXPECT_TRUE(state_.GetLockState()); |
| 41 } |
| 42 |
| 43 TEST_F(WakeLockStateTest, AddFrameTwiceRemoveOnce) { |
| 44 state_.AddFrame(rfh1_); |
| 45 state_.AddFrame(rfh1_); |
| 46 state_.RemoveFrame(rfh1_); |
| 47 EXPECT_FALSE(state_.GetLockState()); |
| 48 } |
| 49 |
| 50 TEST_F(WakeLockStateTest, AddFrameThenRemove) { |
| 51 state_.AddFrame(rfh1_); |
| 52 state_.RemoveFrame(rfh1_); |
| 53 EXPECT_FALSE(state_.GetLockState()); |
| 54 } |
| 55 |
| 56 TEST_F(WakeLockStateTest, AddTwoFramesRemoveSingle) { |
| 57 state_.AddFrame(rfh1_); |
| 58 state_.AddFrame(rfh2_); |
| 59 state_.RemoveFrame(rfh1_); |
| 60 EXPECT_TRUE(state_.GetLockState()); |
| 61 } |
| 62 |
| 63 TEST_F(WakeLockStateTest, AddTwoFramesRemoveAll) { |
| 64 state_.AddFrame(rfh1_); |
| 65 state_.AddFrame(rfh2_); |
| 66 state_.RemoveAllFrames(); |
| 67 EXPECT_FALSE(state_.GetLockState()); |
| 68 } |
| 69 |
| 70 TEST_F(WakeLockStateTest, RemoveNonExistent) { |
| 71 state_.AddFrame(rfh1_); |
| 72 state_.RemoveFrame(rfh2_); |
| 73 EXPECT_TRUE(state_.GetLockState()); |
| 74 } |
| 75 |
| 76 } // namespace content |
OLD | NEW |