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

Side by Side 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, 7 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 unified diff | Download patch
OLDNEW
(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 public:
13 static const RenderFrameHost* MakeFakeRFHPtr(int fake_ptr_value) {
Tom Sepez 2015/04/28 16:22:54 Does this build everywhere without something like
14 return reinterpret_cast<RenderFrameHost*>(fake_ptr_value);
15 }
16
17 protected:
18 WakeLockState state_;
19 };
20
21 TEST_F(WakeLockStateTest, InitialState) {
22 EXPECT_FALSE(state_.GetLockState());
23 }
24
25 TEST_F(WakeLockStateTest, SetFrameLockNegative) {
26 const RenderFrameHost* rfh = MakeFakeRFHPtr(0xdeadbeef);
27 state_.SetFrameLock(rfh, false);
28 EXPECT_FALSE(state_.GetLockState());
29 }
30
31 TEST_F(WakeLockStateTest, SetFrameLockPositive) {
32 const RenderFrameHost* rfh = MakeFakeRFHPtr(0xdeadbeef);
33 state_.SetFrameLock(rfh, true);
34 EXPECT_TRUE(state_.GetLockState());
35 }
36
37 TEST_F(WakeLockStateTest, SetFrameLockPositiveTwice) {
38 const RenderFrameHost* rfh = MakeFakeRFHPtr(0xdeadbeef);
39 state_.SetFrameLock(rfh, true);
40 state_.SetFrameLock(rfh, true);
41 EXPECT_TRUE(state_.GetLockState());
42 }
43
44 TEST_F(WakeLockStateTest, MultipleSetSingleRemove) {
45 const RenderFrameHost* rfh = MakeFakeRFHPtr(0xdeadbeef);
46 state_.SetFrameLock(rfh, true);
47 state_.SetFrameLock(rfh, true);
48 state_.SetFrameLock(rfh, false);
49 EXPECT_FALSE(state_.GetLockState());
50 }
51
52 TEST_F(WakeLockStateTest, SetFrameLockPositiveThenNegative) {
53 const RenderFrameHost* rfh = MakeFakeRFHPtr(0xdeadbeef);
54 state_.SetFrameLock(rfh, true);
55 state_.SetFrameLock(rfh, false);
56 EXPECT_FALSE(state_.GetLockState());
57 }
58
59 TEST_F(WakeLockStateTest, SetFrameLockPositiveAndRemove) {
60 const RenderFrameHost* rfh = MakeFakeRFHPtr(0xdeadbeef);
61 state_.SetFrameLock(rfh, true);
62 state_.RemoveFrame(rfh);
63 EXPECT_FALSE(state_.GetLockState());
64 }
65
66 TEST_F(WakeLockStateTest, SetFrameLockNegativeAndPositive) {
67 const RenderFrameHost* rfh1 = MakeFakeRFHPtr(0xdeadbeef);
68 const RenderFrameHost* rfh2 = MakeFakeRFHPtr(0xbaadf00d);
69 state_.SetFrameLock(rfh1, true);
70 state_.SetFrameLock(rfh2, false);
71 EXPECT_TRUE(state_.GetLockState());
72 }
73
74 TEST_F(WakeLockStateTest, SetFrameLockMultiplePositiveAndRemoveAll) {
75 const RenderFrameHost* rfh1 = MakeFakeRFHPtr(0xdeadbeef);
76 const RenderFrameHost* rfh2 = MakeFakeRFHPtr(0xbaadf00d);
77 state_.SetFrameLock(rfh1, true);
78 state_.SetFrameLock(rfh2, true);
79 state_.RemoveAllFrames();
80 EXPECT_FALSE(state_.GetLockState());
81 }
82
83 TEST_F(WakeLockStateTest, RemoveNonExistent) {
84 const RenderFrameHost* rfh1 = MakeFakeRFHPtr(0xdeadbeef);
85 const RenderFrameHost* rfh2 = MakeFakeRFHPtr(0xbaadf00d);
86 state_.SetFrameLock(rfh1, true);
87 state_.RemoveFrame(rfh2);
88 EXPECT_TRUE(state_.GetLockState());
89 }
90
91 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698