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

Side by Side Diff: content/browser/wake_lock/wake_lock_service_context_unittest.cc

Issue 1345563002: Revert of Wake Lock API implementation (Chromium part) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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_service_context.h"
6
7 #include "base/memory/scoped_ptr.h"
8 #include "base/process/kill.h"
9 #include "content/browser/frame_host/frame_tree_node.h"
10 #include "content/browser/frame_host/render_frame_host_impl.h"
11 #include "content/browser/web_contents/web_contents_impl.h"
12 #include "content/public/browser/web_contents.h"
13 #include "content/public/test/test_renderer_host.h"
14
15 namespace content {
16
17 class RenderFrameHost;
18
19 class WakeLockServiceContextTest : public RenderViewHostTestHarness {
20 protected:
21 void RequestWakeLock(RenderFrameHost* rfh) {
22 GetWakeLockServiceContext()->RequestWakeLock(RFHToFrameNodeID(rfh));
23 }
24
25 void CancelWakeLock(RenderFrameHost* rfh) {
26 GetWakeLockServiceContext()->CancelWakeLock(RFHToFrameNodeID(rfh));
27 }
28
29 int RFHToFrameNodeID(RenderFrameHost* rfh) {
30 RenderFrameHostImpl* rfh_impl =
31 static_cast<RenderFrameHostImpl*>(rfh);
32 return rfh_impl->frame_tree_node()->frame_tree_node_id();
33 }
34
35 WakeLockServiceContext* GetWakeLockServiceContext() {
36 WebContentsImpl* web_contents_impl =
37 static_cast<WebContentsImpl*>(web_contents());
38 return web_contents_impl->GetWakeLockServiceContext();
39 }
40
41 bool HasWakeLock() {
42 return GetWakeLockServiceContext()->HasWakeLockForTests();
43 }
44 };
45
46 TEST_F(WakeLockServiceContextTest, NoLockInitially) {
47 EXPECT_FALSE(HasWakeLock());
48 }
49
50 TEST_F(WakeLockServiceContextTest, LockUnlock) {
51 ASSERT_TRUE(web_contents());
52 ASSERT_TRUE(main_rfh());
53
54 // Request wake lock for main frame
55 RequestWakeLock(main_rfh());
56
57 // Should set the blocker
58 EXPECT_TRUE(HasWakeLock());
59
60 // Remove wake lock request for main frame
61 CancelWakeLock(main_rfh());
62
63 // Should remove the blocker
64 EXPECT_FALSE(HasWakeLock());
65 }
66
67 TEST_F(WakeLockServiceContextTest, RenderFrameDeleted) {
68 ASSERT_TRUE(GetWakeLockServiceContext());
69 ASSERT_TRUE(web_contents());
70 ASSERT_TRUE(main_rfh());
71
72 // Request wake lock for main frame
73 RequestWakeLock(main_rfh());
74
75 // Should set the blocker
76 EXPECT_TRUE(HasWakeLock());
77
78 // Simulate render frame deletion
79 GetWakeLockServiceContext()->RenderFrameDeleted(main_rfh());
80
81 // Should remove the blocker
82 EXPECT_FALSE(HasWakeLock());
83 }
84
85 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/wake_lock/wake_lock_service_context.cc ('k') | content/browser/wake_lock/wake_lock_service_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698