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

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, 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 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..0266ba9beaa26c9766c9d4d8ea8345144a3b134f
--- /dev/null
+++ b/content/browser/wake_lock/wake_lock_state_unittest.cc
@@ -0,0 +1,91 @@
+// 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 {
+ public:
+ static const RenderFrameHost* MakeFakeRFHPtr(int fake_ptr_value) {
Tom Sepez 2015/04/28 16:22:54 Does this build everywhere without something like
+ return reinterpret_cast<RenderFrameHost*>(fake_ptr_value);
+ }
+
+ protected:
+ WakeLockState state_;
+};
+
+TEST_F(WakeLockStateTest, InitialState) {
+ EXPECT_FALSE(state_.GetLockState());
+}
+
+TEST_F(WakeLockStateTest, SetFrameLockNegative) {
+ const RenderFrameHost* rfh = MakeFakeRFHPtr(0xdeadbeef);
+ state_.SetFrameLock(rfh, false);
+ EXPECT_FALSE(state_.GetLockState());
+}
+
+TEST_F(WakeLockStateTest, SetFrameLockPositive) {
+ const RenderFrameHost* rfh = MakeFakeRFHPtr(0xdeadbeef);
+ state_.SetFrameLock(rfh, true);
+ EXPECT_TRUE(state_.GetLockState());
+}
+
+TEST_F(WakeLockStateTest, SetFrameLockPositiveTwice) {
+ const RenderFrameHost* rfh = MakeFakeRFHPtr(0xdeadbeef);
+ state_.SetFrameLock(rfh, true);
+ state_.SetFrameLock(rfh, true);
+ EXPECT_TRUE(state_.GetLockState());
+}
+
+TEST_F(WakeLockStateTest, MultipleSetSingleRemove) {
+ const RenderFrameHost* rfh = MakeFakeRFHPtr(0xdeadbeef);
+ state_.SetFrameLock(rfh, true);
+ state_.SetFrameLock(rfh, true);
+ state_.SetFrameLock(rfh, false);
+ EXPECT_FALSE(state_.GetLockState());
+}
+
+TEST_F(WakeLockStateTest, SetFrameLockPositiveThenNegative) {
+ const RenderFrameHost* rfh = MakeFakeRFHPtr(0xdeadbeef);
+ state_.SetFrameLock(rfh, true);
+ state_.SetFrameLock(rfh, false);
+ EXPECT_FALSE(state_.GetLockState());
+}
+
+TEST_F(WakeLockStateTest, SetFrameLockPositiveAndRemove) {
+ const RenderFrameHost* rfh = MakeFakeRFHPtr(0xdeadbeef);
+ state_.SetFrameLock(rfh, true);
+ state_.RemoveFrame(rfh);
+ EXPECT_FALSE(state_.GetLockState());
+}
+
+TEST_F(WakeLockStateTest, SetFrameLockNegativeAndPositive) {
+ const RenderFrameHost* rfh1 = MakeFakeRFHPtr(0xdeadbeef);
+ const RenderFrameHost* rfh2 = MakeFakeRFHPtr(0xbaadf00d);
+ state_.SetFrameLock(rfh1, true);
+ state_.SetFrameLock(rfh2, false);
+ EXPECT_TRUE(state_.GetLockState());
+}
+
+TEST_F(WakeLockStateTest, SetFrameLockMultiplePositiveAndRemoveAll) {
+ const RenderFrameHost* rfh1 = MakeFakeRFHPtr(0xdeadbeef);
+ const RenderFrameHost* rfh2 = MakeFakeRFHPtr(0xbaadf00d);
+ state_.SetFrameLock(rfh1, true);
+ state_.SetFrameLock(rfh2, true);
+ state_.RemoveAllFrames();
+ EXPECT_FALSE(state_.GetLockState());
+}
+
+TEST_F(WakeLockStateTest, RemoveNonExistent) {
+ const RenderFrameHost* rfh1 = MakeFakeRFHPtr(0xdeadbeef);
+ const RenderFrameHost* rfh2 = MakeFakeRFHPtr(0xbaadf00d);
+ state_.SetFrameLock(rfh1, true);
+ state_.RemoveFrame(rfh2);
+ EXPECT_TRUE(state_.GetLockState());
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698