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

Unified 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, 8 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/wake_lock/wake_lock_dispatcher_host_unittest.cc
diff --git a/content/browser/wake_lock/wake_lock_dispatcher_host_unittest.cc b/content/browser/wake_lock/wake_lock_dispatcher_host_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..19491d6a0edcdb79210893c093c8ea12f597527f
--- /dev/null
+++ b/content/browser/wake_lock/wake_lock_dispatcher_host_unittest.cc
@@ -0,0 +1,78 @@
+// 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_dispatcher_host.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 WakeLockDispatcherHostTest : public RenderViewHostTestHarness {
+ protected:
+ void OnKeepScreenAwake(RenderFrameHost* rfh, bool intention) {
+ ASSERT_TRUE(GetWakeLockDispatcherHost());
+ GetWakeLockDispatcherHost()->OnKeepScreenAwake(rfh, intention);
+ }
+
+ WakeLockDispatcherHost* GetWakeLockDispatcherHost() {
+ WebContentsImpl* web_contents_impl =
+ static_cast<WebContentsImpl*>(web_contents());
+ return web_contents_impl->wake_lock_dispatcher_host();
+ }
+};
+
+TEST_F(WakeLockDispatcherHostTest, NoLockInitially) {
+ ASSERT_TRUE(GetWakeLockDispatcherHost());
+ EXPECT_FALSE(GetWakeLockDispatcherHost()->has_blocker_for_testing());
+}
+
+TEST_F(WakeLockDispatcherHostTest, LockUnlock) {
+ ASSERT_TRUE(GetWakeLockDispatcherHost());
+ ASSERT_TRUE(web_contents());
+ ASSERT_TRUE(main_rfh());
+ // Request wake lock for main frame
+ OnKeepScreenAwake(main_rfh(), true);
+ // Should set the blocker
+ EXPECT_TRUE(GetWakeLockDispatcherHost()->has_blocker_for_testing());
+ // Remove wake lock request for main frame
+ OnKeepScreenAwake(main_rfh(), false);
+ // Should remove the blocker
+ EXPECT_FALSE(GetWakeLockDispatcherHost()->has_blocker_for_testing());
+}
+
+TEST_F(WakeLockDispatcherHostTest, RenderFrameDeleted) {
+ ASSERT_TRUE(GetWakeLockDispatcherHost());
+ ASSERT_TRUE(web_contents());
+ ASSERT_TRUE(main_rfh());
+ // Request wake lock for main frame
+ OnKeepScreenAwake(main_rfh(), true);
+ // Should set the blocker
+ EXPECT_TRUE(GetWakeLockDispatcherHost()->has_blocker_for_testing());
+ // Simulate render frame deletion
+ GetWakeLockDispatcherHost()->RenderFrameDeleted(main_rfh());
+ // Should remove the blocker
+ EXPECT_FALSE(GetWakeLockDispatcherHost()->has_blocker_for_testing());
+}
+
+TEST_F(WakeLockDispatcherHostTest, RenderFrameHostChanged) {
+ ASSERT_TRUE(GetWakeLockDispatcherHost());
+ ASSERT_TRUE(web_contents());
+ ASSERT_TRUE(main_rfh());
+ // Request wake lock for main frame
+ OnKeepScreenAwake(main_rfh(), true);
+ // Should set the blocker
+ EXPECT_TRUE(GetWakeLockDispatcherHost()->has_blocker_for_testing());
+ // Simulate render frame host change
+ GetWakeLockDispatcherHost()->RenderFrameHostChanged(main_rfh(), nullptr);
+ // Should remove the blocker
+ EXPECT_FALSE(GetWakeLockDispatcherHost()->has_blocker_for_testing());
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698