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

Unified Diff: content/browser/wake_lock/wake_lock_service_context_unittest.cc

Issue 2378033002: Decouple WakeLock from direct //content dependencies (Closed)
Patch Set: Created 4 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 side-by-side diff with in-line comments
Download patch
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
index 4802109dcb5a3272f0de767fade6afcedd7cb2ca..6240132303a2afbc7263cbe74f437466a248a38e 100644
--- a/content/browser/wake_lock/wake_lock_service_context_unittest.cc
+++ b/content/browser/wake_lock/wake_lock_service_context_unittest.cc
@@ -6,38 +6,38 @@
#include <memory>
+#include "base/message_loop/message_loop.h"
#include "base/process/kill.h"
-#include "content/browser/web_contents/web_contents_impl.h"
-#include "content/public/browser/render_frame_host.h"
-#include "content/public/browser/render_process_host.h"
-#include "content/public/browser/web_contents.h"
-#include "content/public/test/test_renderer_host.h"
+#include "testing/gtest/include/gtest/gtest.h"
namespace content {
-class RenderFrameHost;
+class WakeLockServiceContextTest : public testing::Test {
+ public:
+ WakeLockServiceContextTest()
+ : wake_lock_service_context_(
+ base::ThreadTaskRunnerHandle::Get(),
+ base::Bind(&WakeLockServiceContextTest::GetNativeView,
+ base::Unretained(this))) {}
-class WakeLockServiceContextTest : public RenderViewHostTestHarness {
protected:
- void RequestWakeLock(RenderFrameHost* rfh) {
- GetWakeLockServiceContext()->RequestWakeLock(rfh->GetProcess()->GetID(),
- rfh->GetRoutingID());
- }
+ void RequestWakeLock() { GetWakeLockServiceContext()->RequestWakeLock(); }
- void CancelWakeLock(RenderFrameHost* rfh) {
- GetWakeLockServiceContext()->CancelWakeLock(rfh->GetProcess()->GetID(),
- rfh->GetRoutingID());
- }
+ void CancelWakeLock() { GetWakeLockServiceContext()->CancelWakeLock(); }
WakeLockServiceContext* GetWakeLockServiceContext() {
- WebContentsImpl* web_contents_impl =
- static_cast<WebContentsImpl*>(web_contents());
- return web_contents_impl->GetWakeLockServiceContext();
+ return &wake_lock_service_context_;
}
bool HasWakeLock() {
return GetWakeLockServiceContext()->HasWakeLockForTests();
}
+
+ private:
+ gfx::NativeView GetNativeView() { return nullptr; }
+
+ base::MessageLoop message_loop_;
+ WakeLockServiceContext wake_lock_service_context_;
};
TEST_F(WakeLockServiceContextTest, NoLockInitially) {
@@ -46,52 +46,18 @@ TEST_F(WakeLockServiceContextTest, NoLockInitially) {
TEST_F(WakeLockServiceContextTest, LockUnlock) {
ASSERT_TRUE(GetWakeLockServiceContext());
- ASSERT_TRUE(web_contents());
- ASSERT_TRUE(main_rfh());
- // Request wake lock for main frame.
- RequestWakeLock(main_rfh());
+ // Request wake lock.
+ RequestWakeLock();
// Should set the blocker.
EXPECT_TRUE(HasWakeLock());
- // Remove wake lock request for main frame.
- CancelWakeLock(main_rfh());
+ // Remove wake lock request.
+ CancelWakeLock();
// Should remove the blocker.
EXPECT_FALSE(HasWakeLock());
}
-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());
-}
-
-TEST_F(WakeLockServiceContextTest, NoLockForBogusFrameId) {
- ASSERT_TRUE(GetWakeLockServiceContext());
- ASSERT_TRUE(web_contents());
-
- // Request wake lock for non-existent render frame id.
- int non_existent_render_frame_id =
- main_rfh()->GetProcess()->GetNextRoutingID();
- GetWakeLockServiceContext()->RequestWakeLock(
- main_rfh()->GetProcess()->GetID(), non_existent_render_frame_id);
-
- // Should not set the blocker.
- EXPECT_FALSE(HasWakeLock());
-}
-
} // namespace content
« no previous file with comments | « content/browser/wake_lock/wake_lock_service_context.cc ('k') | content/browser/wake_lock/wake_lock_service_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698