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

Side by Side Diff: content/browser/wake_lock/wake_lock_service_context_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, 4 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/web_contents/web_contents_impl.h"
10 #include "content/public/browser/web_contents.h"
11 #include "content/public/test/test_renderer_host.h"
12
13 namespace content {
14
15 class RenderFrameHost;
16
17 class WakeLockServiceContextTest : public RenderViewHostTestHarness {
18 protected:
19 void RequestWakeLock(RenderFrameHost* rfh) {
20 ASSERT_TRUE(GetWakeLockServiceContext());
21 GetWakeLockServiceContext()->RequestWakeLock(rfh);
22 }
23
24 void CancelWakeLock(RenderFrameHost* rfh) {
25 ASSERT_TRUE(GetWakeLockServiceContext());
26 GetWakeLockServiceContext()->CancelWakeLock(rfh);
27 }
28
29 WakeLockServiceContext* GetWakeLockServiceContext() {
30 WebContentsImpl* web_contents_impl =
31 static_cast<WebContentsImpl*>(web_contents());
32 return web_contents_impl->wake_lock_service_context();
33 }
34 };
35
36 TEST_F(WakeLockServiceContextTest, NoLockInitially) {
37 ASSERT_TRUE(GetWakeLockServiceContext());
38 EXPECT_FALSE(GetWakeLockServiceContext()->has_blocker_for_testing());
39 }
40
41 TEST_F(WakeLockServiceContextTest, LockUnlock) {
42 ASSERT_TRUE(GetWakeLockServiceContext());
43 ASSERT_TRUE(web_contents());
44 ASSERT_TRUE(main_rfh());
45 // Request wake lock for main frame
46 RequestWakeLock(main_rfh());
47 // Should set the blocker
48 EXPECT_TRUE(GetWakeLockServiceContext()->has_blocker_for_testing());
49 // Remove wake lock request for main frame
50 CancelWakeLock(main_rfh());
51 // Should remove the blocker
52 EXPECT_FALSE(GetWakeLockServiceContext()->has_blocker_for_testing());
53 }
54
55 TEST_F(WakeLockServiceContextTest, RenderFrameDeleted) {
56 ASSERT_TRUE(GetWakeLockServiceContext());
57 ASSERT_TRUE(web_contents());
58 ASSERT_TRUE(main_rfh());
59 // Request wake lock for main frame
60 RequestWakeLock(main_rfh());
61 // Should set the blocker
62 EXPECT_TRUE(GetWakeLockServiceContext()->has_blocker_for_testing());
63 // Simulate render frame deletion
64 GetWakeLockServiceContext()->RenderFrameDeleted(main_rfh());
65 // Should remove the blocker
66 EXPECT_FALSE(GetWakeLockServiceContext()->has_blocker_for_testing());
67 }
68
69 TEST_F(WakeLockServiceContextTest, RenderFrameHostChanged) {
70 ASSERT_TRUE(GetWakeLockServiceContext());
71 ASSERT_TRUE(web_contents());
72 ASSERT_TRUE(main_rfh());
73 // Request wake lock for main frame
74 RequestWakeLock(main_rfh());
75 // Should set the blocker
76 EXPECT_TRUE(GetWakeLockServiceContext()->has_blocker_for_testing());
77 // Simulate render frame host change
78 GetWakeLockServiceContext()->RenderFrameHostChanged(main_rfh(), nullptr);
79 // Should remove the blocker
80 EXPECT_FALSE(GetWakeLockServiceContext()->has_blocker_for_testing());
81 }
82
83 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698