Index: content/browser/wake_lock/wake_lock_state_unittest.cc |
diff --git a/content/browser/wake_lock/wake_lock_state_unittest.cc b/content/browser/wake_lock/wake_lock_state_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..22192263490bfdf665f68f6e6568432177a0c20a |
--- /dev/null |
+++ b/content/browser/wake_lock/wake_lock_state_unittest.cc |
@@ -0,0 +1,76 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/browser/wake_lock/wake_lock_state.h" |
+ |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace content { |
+ |
+class WakeLockStateTest : public testing::Test { |
+protected: |
+ void SetUp() override { |
+ rfh1_ = MakeFakeRFHPtr(0xdeadbeef); |
+ rfh2_ = MakeFakeRFHPtr(0xbaadf00d); |
+ } |
+ |
+ const RenderFrameHost* rfh1_; |
+ const RenderFrameHost* rfh2_; |
+ WakeLockState state_; |
+ |
+private: |
+ static const RenderFrameHost* MakeFakeRFHPtr(int fake_ptr_value) { |
+ return reinterpret_cast<RenderFrameHost*>(fake_ptr_value); |
+ } |
+}; |
+ |
+TEST_F(WakeLockStateTest, InitialState) { |
+ EXPECT_FALSE(state_.GetLockState()); |
+} |
+ |
+TEST_F(WakeLockStateTest, AddFrame) { |
+ state_.AddFrame(rfh1_); |
+ EXPECT_TRUE(state_.GetLockState()); |
+} |
+ |
+TEST_F(WakeLockStateTest, AddFrameTwice) { |
+ state_.AddFrame(rfh1_); |
+ state_.AddFrame(rfh1_); |
+ EXPECT_TRUE(state_.GetLockState()); |
+} |
+ |
+TEST_F(WakeLockStateTest, AddFrameTwiceRemoveOnce) { |
+ state_.AddFrame(rfh1_); |
+ state_.AddFrame(rfh1_); |
+ state_.RemoveFrame(rfh1_); |
+ EXPECT_FALSE(state_.GetLockState()); |
+} |
+ |
+TEST_F(WakeLockStateTest, AddFrameThenRemove) { |
+ state_.AddFrame(rfh1_); |
+ state_.RemoveFrame(rfh1_); |
+ EXPECT_FALSE(state_.GetLockState()); |
+} |
+ |
+TEST_F(WakeLockStateTest, AddTwoFramesRemoveSingle) { |
+ state_.AddFrame(rfh1_); |
+ state_.AddFrame(rfh2_); |
+ state_.RemoveFrame(rfh1_); |
+ EXPECT_TRUE(state_.GetLockState()); |
+} |
+ |
+TEST_F(WakeLockStateTest, AddTwoFramesRemoveAll) { |
+ state_.AddFrame(rfh1_); |
+ state_.AddFrame(rfh2_); |
+ state_.RemoveAllFrames(); |
+ EXPECT_FALSE(state_.GetLockState()); |
+} |
+ |
+TEST_F(WakeLockStateTest, RemoveNonExistent) { |
+ state_.AddFrame(rfh1_); |
+ state_.RemoveFrame(rfh2_); |
+ EXPECT_TRUE(state_.GetLockState()); |
+} |
+ |
+} // namespace content |