Chromium Code Reviews| Index: content/browser/wake_lock/wake_lock_service_context_unittest.cc |
| diff --git a/content/browser/wake_lock/wake_lock_service_context_unittest.cc b/content/browser/wake_lock/wake_lock_service_context_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d5a32665527571235a21c104d5ea670a3d501ae3 |
| --- /dev/null |
| +++ b/content/browser/wake_lock/wake_lock_service_context_unittest.cc |
| @@ -0,0 +1,85 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/browser/wake_lock/wake_lock_service_context.h" |
| + |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/process/kill.h" |
| +#include "content/browser/web_contents/web_contents_impl.h" |
| +#include "content/public/browser/web_contents.h" |
| +#include "content/public/test/test_renderer_host.h" |
| + |
| +namespace content { |
| + |
| +class RenderFrameHost; |
| + |
| +class WakeLockServiceContextTest : public RenderViewHostTestHarness { |
| + protected: |
| + void RequestWakeLock(RenderFrameHost* rfh) { |
| + 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.
|
| + GetWakeLockServiceContext()->RequestWakeLock(rfh); |
| + } |
| + |
| + void CancelWakeLock(RenderFrameHost* rfh) { |
| + ASSERT_TRUE(GetWakeLockServiceContext()); |
|
mlamouri (slow - plz ping)
2015/08/31 14:59:15
ditto
alogvinov
2015/09/02 17:06:23
Done.
|
| + GetWakeLockServiceContext()->CancelWakeLock(rfh); |
| + } |
| + |
| + WakeLockServiceContext* GetWakeLockServiceContext() { |
| + WebContentsImpl* web_contents_impl = |
| + static_cast<WebContentsImpl*>(web_contents()); |
| + return web_contents_impl->wake_lock_service_context(); |
| + } |
| + |
| + bool HasWakeLock() { |
| + return GetWakeLockServiceContext()->wake_lock_; |
| + } |
| +}; |
| + |
| +TEST_F(WakeLockServiceContextTest, NoLockInitially) { |
| + EXPECT_FALSE(HasWakeLock()); |
| +} |
| + |
| +TEST_F(WakeLockServiceContextTest, LockUnlock) { |
| + ASSERT_TRUE(web_contents()); |
| + ASSERT_TRUE(main_rfh()); |
| + // Request wake lock for main frame |
| + RequestWakeLock(main_rfh()); |
| + // Should set the blocker |
| + EXPECT_TRUE(HasWakeLock()); |
| + // Remove wake lock request for main frame |
| + CancelWakeLock(main_rfh()); |
| + // Should remove the blocker |
| + 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.
|
| +} |
| + |
| +TEST_F(WakeLockServiceContextTest, RenderFrameDeleted) { |
| + ASSERT_TRUE(GetWakeLockServiceContext()); |
| + ASSERT_TRUE(web_contents()); |
| + ASSERT_TRUE(main_rfh()); |
| + // Request wake lock for main frame |
| + RequestWakeLock(main_rfh()); |
| + // Should set the blocker |
| + EXPECT_TRUE(HasWakeLock()); |
| + // Simulate render frame deletion |
| + GetWakeLockServiceContext()->RenderFrameDeleted(main_rfh()); |
| + // Should remove the blocker |
| + EXPECT_FALSE(HasWakeLock()); |
|
mlamouri (slow - plz ping)
2015/08/31 14:59:15
ditto
alogvinov
2015/09/02 17:06:23
Done.
|
| +} |
| + |
| +TEST_F(WakeLockServiceContextTest, RenderFrameHostChanged) { |
| + ASSERT_TRUE(GetWakeLockServiceContext()); |
| + ASSERT_TRUE(web_contents()); |
| + ASSERT_TRUE(main_rfh()); |
| + // Request wake lock for main frame |
| + RequestWakeLock(main_rfh()); |
| + // Should set the blocker |
| + EXPECT_TRUE(HasWakeLock()); |
| + // Simulate render frame host change |
| + GetWakeLockServiceContext()->RenderFrameHostChanged(main_rfh(), nullptr); |
| + // Should remove the blocker |
| + EXPECT_FALSE(HasWakeLock()); |
|
mlamouri (slow - plz ping)
2015/08/31 14:59:15
ditto
alogvinov
2015/09/02 17:06:22
Done.
|
| +} |
| + |
| +} // namespace content |