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

Side by Side Diff: content/browser/wake_lock/wake_lock_dispatcher_host_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_dispatcher_host.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 WakeLockDispatcherHostTest : public RenderViewHostTestHarness {
18 protected:
19 void OnKeepScreenAwake(RenderFrameHost* rfh, bool intention) {
20 ASSERT_TRUE(GetWakeLockDispatcherHost());
21 GetWakeLockDispatcherHost()->OnKeepScreenAwake(rfh, intention);
22 }
23
24 WakeLockDispatcherHost* GetWakeLockDispatcherHost() {
25 WebContentsImpl* web_contents_impl =
26 static_cast<WebContentsImpl*>(web_contents());
27 return web_contents_impl->wake_lock_dispatcher_host();
28 }
29 };
30
31 TEST_F(WakeLockDispatcherHostTest, NoLockInitially) {
32 ASSERT_TRUE(GetWakeLockDispatcherHost());
33 EXPECT_FALSE(GetWakeLockDispatcherHost()->has_blocker_for_testing());
34 }
35
36 TEST_F(WakeLockDispatcherHostTest, LockUnlock) {
37 ASSERT_TRUE(GetWakeLockDispatcherHost());
38 ASSERT_TRUE(web_contents());
39 ASSERT_TRUE(main_rfh());
40 // Request wake lock for main frame
41 OnKeepScreenAwake(main_rfh(), true);
42 // Should set the blocker
43 EXPECT_TRUE(GetWakeLockDispatcherHost()->has_blocker_for_testing());
44 // Remove wake lock request for main frame
45 OnKeepScreenAwake(main_rfh(), false);
46 // Should remove the blocker
47 EXPECT_FALSE(GetWakeLockDispatcherHost()->has_blocker_for_testing());
48 }
49
50 TEST_F(WakeLockDispatcherHostTest, RenderFrameDeleted) {
51 ASSERT_TRUE(GetWakeLockDispatcherHost());
52 ASSERT_TRUE(web_contents());
53 ASSERT_TRUE(main_rfh());
54 // Request wake lock for main frame
55 OnKeepScreenAwake(main_rfh(), true);
56 // Should set the blocker
57 EXPECT_TRUE(GetWakeLockDispatcherHost()->has_blocker_for_testing());
58 // Simulate render frame deletion
59 GetWakeLockDispatcherHost()->RenderFrameDeleted(main_rfh());
60 // Should remove the blocker
61 EXPECT_FALSE(GetWakeLockDispatcherHost()->has_blocker_for_testing());
62 }
63
64 TEST_F(WakeLockDispatcherHostTest, RenderFrameHostChanged) {
65 ASSERT_TRUE(GetWakeLockDispatcherHost());
66 ASSERT_TRUE(web_contents());
67 ASSERT_TRUE(main_rfh());
68 // Request wake lock for main frame
69 OnKeepScreenAwake(main_rfh(), true);
70 // Should set the blocker
71 EXPECT_TRUE(GetWakeLockDispatcherHost()->has_blocker_for_testing());
72 // Simulate render frame host change
73 GetWakeLockDispatcherHost()->RenderFrameHostChanged(main_rfh(), nullptr);
74 // Should remove the blocker
75 EXPECT_FALSE(GetWakeLockDispatcherHost()->has_blocker_for_testing());
76 }
77
78 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698