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

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, 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/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());
mlamouri (slow - plz ping) 2015/08/31 14:59:15 nit: I don't think you need that. This is a test a
alogvinov 2015/09/02 17:06:22 Done.
21 GetWakeLockServiceContext()->RequestWakeLock(rfh);
22 }
23
24 void CancelWakeLock(RenderFrameHost* rfh) {
25 ASSERT_TRUE(GetWakeLockServiceContext());
mlamouri (slow - plz ping) 2015/08/31 14:59:15 ditto
alogvinov 2015/09/02 17:06:23 Done.
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 bool HasWakeLock() {
36 return GetWakeLockServiceContext()->wake_lock_;
37 }
38 };
39
40 TEST_F(WakeLockServiceContextTest, NoLockInitially) {
41 EXPECT_FALSE(HasWakeLock());
42 }
43
44 TEST_F(WakeLockServiceContextTest, LockUnlock) {
45 ASSERT_TRUE(web_contents());
46 ASSERT_TRUE(main_rfh());
47 // Request wake lock for main frame
48 RequestWakeLock(main_rfh());
49 // Should set the blocker
50 EXPECT_TRUE(HasWakeLock());
51 // Remove wake lock request for main frame
52 CancelWakeLock(main_rfh());
53 // Should remove the blocker
54 EXPECT_FALSE(HasWakeLock());
mlamouri (slow - plz ping) 2015/08/31 14:59:15 nit: could you add some empty lines to make this m
alogvinov 2015/09/02 17:06:22 Done.
55 }
56
57 TEST_F(WakeLockServiceContextTest, RenderFrameDeleted) {
58 ASSERT_TRUE(GetWakeLockServiceContext());
59 ASSERT_TRUE(web_contents());
60 ASSERT_TRUE(main_rfh());
61 // Request wake lock for main frame
62 RequestWakeLock(main_rfh());
63 // Should set the blocker
64 EXPECT_TRUE(HasWakeLock());
65 // Simulate render frame deletion
66 GetWakeLockServiceContext()->RenderFrameDeleted(main_rfh());
67 // Should remove the blocker
68 EXPECT_FALSE(HasWakeLock());
mlamouri (slow - plz ping) 2015/08/31 14:59:15 ditto
alogvinov 2015/09/02 17:06:23 Done.
69 }
70
71 TEST_F(WakeLockServiceContextTest, RenderFrameHostChanged) {
72 ASSERT_TRUE(GetWakeLockServiceContext());
73 ASSERT_TRUE(web_contents());
74 ASSERT_TRUE(main_rfh());
75 // Request wake lock for main frame
76 RequestWakeLock(main_rfh());
77 // Should set the blocker
78 EXPECT_TRUE(HasWakeLock());
79 // Simulate render frame host change
80 GetWakeLockServiceContext()->RenderFrameHostChanged(main_rfh(), nullptr);
81 // Should remove the blocker
82 EXPECT_FALSE(HasWakeLock());
mlamouri (slow - plz ping) 2015/08/31 14:59:15 ditto
alogvinov 2015/09/02 17:06:22 Done.
83 }
84
85 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698