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

Unified Diff: content/browser/wake_lock/wake_lock_state_unittest.cc

Issue 1107333002: Wake Lock API implementation (Chromium part) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698