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

Unified Diff: third_party/WebKit/Source/modules/wake_lock/ScreenWakeLockTest.cpp

Issue 1794553002: [Playground] Onion Soup: moving ScreenWakeLock to Blink modules/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit DEPS Created 4 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: third_party/WebKit/Source/modules/wake_lock/ScreenWakeLockTest.cpp
diff --git a/third_party/WebKit/Source/web/tests/ScreenWakeLockTest.cpp b/third_party/WebKit/Source/modules/wake_lock/ScreenWakeLockTest.cpp
similarity index 59%
rename from third_party/WebKit/Source/web/tests/ScreenWakeLockTest.cpp
rename to third_party/WebKit/Source/modules/wake_lock/ScreenWakeLockTest.cpp
index 6d770ec32ef72d129d27d9ebe6eb583ade8df0e1..ba66d6a4cd28b6e9add2d4516659b184484292b3 100644
--- a/third_party/WebKit/Source/web/tests/ScreenWakeLockTest.cpp
+++ b/third_party/WebKit/Source/modules/wake_lock/ScreenWakeLockTest.cpp
@@ -4,16 +4,17 @@
#include "modules/wake_lock/ScreenWakeLock.h"
+#include "base/run_loop.h"
#include "core/dom/DOMImplementation.h"
#include "core/dom/Document.h"
#include "core/dom/DocumentInit.h"
-#include "core/frame/LocalDOMWindow.h"
-#include "platform/heap/Handle.h"
+#include "mojo/public/cpp/bindings/interface_request.h"
+#include "mojo/public/cpp/bindings/strong_binding.h"
#include "platform/testing/URLTestHelpers.h"
#include "public/platform/Platform.h"
+#include "public/platform/ServiceRegistry.h"
#include "public/platform/WebPageVisibilityState.h"
#include "public/platform/WebURLLoaderMockFactory.h"
-#include "public/platform/modules/wake_lock/WebWakeLockClient.h"
#include "public/web/WebCache.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "web/WebLocalFrameImpl.h"
@@ -22,37 +23,64 @@
namespace {
using blink::ScreenWakeLock;
-using blink::WebWakeLockClient;
+using blink::mojom::WakeLockService;
+using blink::mojom::WakeLockServiceRequest;
-class TestWebWakeLockClient: public WebWakeLockClient {
+// This class allows connecting service requests to a MockWakeLockService.
+class MockServiceRegistry : public blink::ServiceRegistry {
public:
- TestWebWakeLockClient(): m_keepScreenAwake(false) { }
+ MockServiceRegistry() : m_wakeLockStatus(false) {}
+ ~MockServiceRegistry() = default;
- void requestKeepScreenAwake(bool keepScreenAwake) override
- {
- m_keepScreenAwake = keepScreenAwake;
- }
+ void connectToRemoteService(const char* name, mojo::ScopedMessagePipeHandle) override;
- bool keepScreenAwake() const { return m_keepScreenAwake; }
+ bool wakeLockStatus() const { return m_wakeLockStatus; }
+ void setWakeLockStatus(bool status) { m_wakeLockStatus = status; }
private:
- bool m_keepScreenAwake;
+ bool m_wakeLockStatus;
};
-class TestWebFrameClient: public blink::FrameTestHelpers::TestWebFrameClient {
+// This class is a mock WakeLockService to intercept calls to the mojo methods.
+class MockWakeLockService : public WakeLockService {
public:
- WebWakeLockClient* wakeLockClient() override
+ static void Create(MockServiceRegistry* registry, WakeLockServiceRequest request)
{
- return &m_testWebWakeLockClient;
+ // See comment below in |m_binding_| for why this doesn't leak.
+ new MockWakeLockService(registry, std::move(request));
}
+ ~MockWakeLockService() = default;
- const TestWebWakeLockClient& testWebWakeLockClient() const
- {
- return m_testWebWakeLockClient;
- }
+private:
+ MockWakeLockService(MockServiceRegistry* registry, WakeLockServiceRequest request)
+ : m_binding(this, std::move(request))
+ , m_registry(registry) {}
+
+ // mojom::WakeLockService
+ void RequestWakeLock() override { m_registry->setWakeLockStatus(true); }
+ void CancelWakeLock() override { m_registry->setWakeLockStatus(false); }
+
+ // A StrongBinding is just like a Binding, except that it takes ownership of
+ // its bound implementation and deletes itself (and the impl) if and when the
+ // bound pipe encounters an error or is closed on the other end.
+ mojo::StrongBinding<WakeLockService> m_binding;
+ MockServiceRegistry* const m_registry;
+};
+
+// This implementation goes here for MockWakeLockService to be defined.
+void MockServiceRegistry::connectToRemoteService(const char* name, mojo::ScopedMessagePipeHandle handle)
+{
+ MockWakeLockService::Create(this, mojo::MakeRequest<WakeLockService>(std::move(handle)));
+}
+
+// A TestWebFrameClient to allow overriding the serviceRegistry() with a mock.
+class TestWebFrameClient : public blink::FrameTestHelpers::TestWebFrameClient {
+public:
+ ~TestWebFrameClient() override = default;
+ blink::ServiceRegistry* serviceRegistry() override { return &m_serviceRegistry; }
private:
- TestWebWakeLockClient m_testWebWakeLockClient;
+ MockServiceRegistry m_serviceRegistry;
};
class ScreenWakeLockTest: public testing::Test {
@@ -102,13 +130,15 @@ protected:
bool clientKeepScreenAwake()
{
- return m_testWebFrameClient.testWebWakeLockClient().keepScreenAwake();
+ return static_cast<MockServiceRegistry*>(m_testWebFrameClient.serviceRegistry())->wakeLockStatus();
}
void setKeepAwake(bool keepAwake)
{
DCHECK(screen());
ScreenWakeLock::setKeepAwake(*screen(), keepAwake);
+ // Let the notification sink through the mojo pipes.
+ base::RunLoop().RunUntilIdle();
}
void show()
@@ -116,6 +146,8 @@ protected:
DCHECK(m_webViewHelper.webView());
m_webViewHelper.webView()->setVisibilityState(
blink::WebPageVisibilityStateVisible, false);
+ // Let the notification sink through the mojo pipes.
+ base::RunLoop().RunUntilIdle();
}
void hide()
@@ -123,6 +155,8 @@ protected:
DCHECK(m_webViewHelper.webView());
m_webViewHelper.webView()->setVisibilityState(
blink::WebPageVisibilityStateHidden, false);
+ // Let the notification sink through the mojo pipes.
+ base::RunLoop().RunUntilIdle();
}
// Order of these members is important as we need to make sure that
« no previous file with comments | « third_party/WebKit/Source/modules/wake_lock/ScreenWakeLock.cpp ('k') | third_party/WebKit/Source/platform/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698