summaryrefslogtreecommitdiff
path: root/Source/WebKit/chromium/tests/WebCompositorInputHandlerImplTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebKit/chromium/tests/WebCompositorInputHandlerImplTest.cpp')
-rw-r--r--Source/WebKit/chromium/tests/WebCompositorInputHandlerImplTest.cpp221
1 files changed, 217 insertions, 4 deletions
diff --git a/Source/WebKit/chromium/tests/WebCompositorInputHandlerImplTest.cpp b/Source/WebKit/chromium/tests/WebCompositorInputHandlerImplTest.cpp
index f207c06a2..ad5810524 100644
--- a/Source/WebKit/chromium/tests/WebCompositorInputHandlerImplTest.cpp
+++ b/Source/WebKit/chromium/tests/WebCompositorInputHandlerImplTest.cpp
@@ -28,6 +28,9 @@
#include "WebCompositorInputHandlerImpl.h"
#include "WebCompositor.h"
+#include "WebCompositorInputHandlerClient.h"
+#include "WebInputEvent.h"
+#include "cc/CCInputHandler.h"
#include "cc/CCSingleThreadProxy.h"
#include <gtest/gtest.h>
@@ -38,6 +41,98 @@ using WebKit::WebCompositorInputHandlerImpl;
namespace {
+class MockInputHandlerClient : public WebCore::CCInputHandlerClient {
+ WTF_MAKE_NONCOPYABLE(MockInputHandlerClient);
+public:
+ MockInputHandlerClient()
+ : m_scrollStatus(ScrollStarted)
+ , m_pinchStarted(false)
+ , m_pinchEnded(false)
+ , m_pinchMagnification(0)
+ {
+ }
+ virtual ~MockInputHandlerClient() { }
+
+ void setScrollStatus(ScrollStatus status) { m_scrollStatus = status; }
+
+ bool pinchStarted() const { return m_pinchStarted; }
+ bool pinchEnded() const { return m_pinchEnded; }
+ float pinchMaginifcation() const { return m_pinchMagnification; }
+
+ void resetPinch()
+ {
+ m_pinchStarted = m_pinchEnded = false;
+ m_pinchMagnification = 0;
+ }
+
+private:
+ virtual void setNeedsRedraw() OVERRIDE { }
+ virtual ScrollStatus scrollBegin(const WebCore::IntPoint&) OVERRIDE
+ {
+ return m_scrollStatus;
+ }
+ virtual void scrollBy(const WebCore::IntSize&) OVERRIDE { }
+ virtual void scrollEnd() OVERRIDE { }
+
+ virtual bool haveWheelEventHandlers() OVERRIDE { return false; }
+ virtual void pinchGestureBegin() OVERRIDE
+ {
+ m_pinchStarted = true;
+ }
+ virtual void pinchGestureUpdate(float magnifyDelta, const WebCore::IntPoint& anchor) OVERRIDE
+ {
+ m_pinchMagnification = magnifyDelta;
+ }
+ virtual void pinchGestureEnd() OVERRIDE
+ {
+ m_pinchEnded = true;
+ }
+ virtual void startPageScaleAnimation(const WebCore::IntSize& targetPosition,
+ bool anchorPoint,
+ float pageScale,
+ double startTimeMs,
+ double durationMs) OVERRIDE { }
+
+ ScrollStatus m_scrollStatus;
+ bool m_pinchStarted;
+ bool m_pinchEnded;
+ float m_pinchMagnification;
+};
+
+class MockWebCompositorInputHandlerClient : public WebKit::WebCompositorInputHandlerClient {
+ WTF_MAKE_NONCOPYABLE(MockWebCompositorInputHandlerClient);
+public:
+ MockWebCompositorInputHandlerClient()
+ : m_handled(false)
+ , m_sendToWidget(false)
+ {
+ }
+ virtual ~MockWebCompositorInputHandlerClient() { }
+
+ void reset()
+ {
+ m_handled = false;
+ m_sendToWidget = false;
+ }
+
+ bool handled() const { return m_handled; }
+ bool sendToWidget() const { return m_sendToWidget; }
+
+private:
+ virtual void willShutdown() OVERRIDE { }
+ virtual void didHandleInputEvent() OVERRIDE
+ {
+ m_handled = true;
+ }
+ virtual void didNotHandleInputEvent(bool sendToWidget) OVERRIDE
+ {
+ m_sendToWidget = sendToWidget;
+ }
+
+ bool m_handled;
+ bool m_sendToWidget;
+};
+
TEST(WebCompositorInputHandlerImpl, fromIdentifier)
{
WebKit::WebCompositor::initialize(0);
@@ -53,13 +148,13 @@ TEST(WebCompositorInputHandlerImpl, fromIdentifier)
int compositorIdentifier = -1;
{
- OwnPtr<WebCompositorInputHandlerImpl> comp = WebCompositorInputHandlerImpl::create(0);
- compositorIdentifier = comp->identifier();
+ OwnPtr<WebCompositorInputHandlerImpl> inputHandler = WebCompositorInputHandlerImpl::create(0);
+ compositorIdentifier = inputHandler->identifier();
// The compositor we just created should be locatable.
- EXPECT_EQ(comp.get(), WebCompositorInputHandler::fromIdentifier(compositorIdentifier));
+ EXPECT_EQ(inputHandler.get(), WebCompositorInputHandler::fromIdentifier(compositorIdentifier));
// But nothing else.
- EXPECT_EQ(0, WebCompositorInputHandler::fromIdentifier(comp->identifier() + 10));
+ EXPECT_EQ(0, WebCompositorInputHandler::fromIdentifier(inputHandler->identifier() + 10));
}
// After the compositor is destroyed, its entry should be removed from the map.
@@ -68,4 +163,122 @@ TEST(WebCompositorInputHandlerImpl, fromIdentifier)
WebKit::WebCompositor::shutdown();
}
+TEST(WebCompositorInputHandlerImpl, gestureScroll)
+{
+ WebKit::WebCompositor::initialize(0);
+#ifndef NDEBUG
+ // WebCompositorInputHandler APIs can only be called from the compositor thread.
+ WebCore::DebugScopedSetImplThread alwaysImplThread;
+#endif
+
+ MockInputHandlerClient mockInputHandler;
+ OwnPtr<WebCompositorInputHandlerImpl> inputHandler = WebCompositorInputHandlerImpl::create(&mockInputHandler);
+ MockWebCompositorInputHandlerClient mockClient;
+ inputHandler->setClient(&mockClient);
+
+ WebKit::WebGestureEvent gesture;
+
+ gesture.type = WebKit::WebInputEvent::GestureScrollBegin;
+ inputHandler->handleInputEvent(gesture);
+ EXPECT_TRUE(mockClient.handled());
+ EXPECT_FALSE(mockClient.sendToWidget());
+ mockClient.reset();
+
+ gesture.type = WebKit::WebInputEvent::GestureScrollUpdate;
+ gesture.deltaY = 40;
+ inputHandler->handleInputEvent(gesture);
+ EXPECT_TRUE(mockClient.handled());
+ EXPECT_FALSE(mockClient.sendToWidget());
+ mockClient.reset();
+
+ gesture.type = WebKit::WebInputEvent::GestureScrollEnd;
+ gesture.deltaY = 0;
+ inputHandler->handleInputEvent(gesture);
+ EXPECT_TRUE(mockClient.handled());
+ EXPECT_FALSE(mockClient.sendToWidget());
+ mockClient.reset();
+
+ mockInputHandler.setScrollStatus(WebCore::CCInputHandlerClient::ScrollFailed);
+
+ gesture.type = WebKit::WebInputEvent::GestureScrollBegin;
+ inputHandler->handleInputEvent(gesture);
+ EXPECT_FALSE(mockClient.handled());
+ EXPECT_TRUE(mockClient.sendToWidget());
+ mockClient.reset();
+
+ gesture.type = WebKit::WebInputEvent::GestureScrollUpdate;
+ gesture.deltaY = 40;
+ inputHandler->handleInputEvent(gesture);
+ EXPECT_FALSE(mockClient.handled());
+ EXPECT_TRUE(mockClient.sendToWidget());
+ mockClient.reset();
+
+ gesture.type = WebKit::WebInputEvent::GestureScrollEnd;
+ gesture.deltaY = 0;
+ inputHandler->handleInputEvent(gesture);
+ EXPECT_FALSE(mockClient.handled());
+ EXPECT_TRUE(mockClient.sendToWidget());
+ mockClient.reset();
+
+ inputHandler->setClient(0);
+
+ WebKit::WebCompositor::shutdown();
+}
+
+TEST(WebCompositorInputHandlerImpl, gesturePinch)
+{
+ WebKit::WebCompositor::initialize(0);
+#ifndef NDEBUG
+ // WebCompositorInputHandler APIs can only be called from the compositor thread.
+ WebCore::DebugScopedSetImplThread alwaysImplThread;
+#endif
+
+ MockInputHandlerClient mockInputHandler;
+ OwnPtr<WebCompositorInputHandlerImpl> inputHandler = WebCompositorInputHandlerImpl::create(&mockInputHandler);
+ MockWebCompositorInputHandlerClient mockClient;
+ inputHandler->setClient(&mockClient);
+
+ WebKit::WebGestureEvent gesture;
+
+ gesture.type = WebKit::WebInputEvent::GesturePinchBegin;
+ inputHandler->handleInputEvent(gesture);
+ EXPECT_TRUE(mockClient.handled());
+ EXPECT_FALSE(mockClient.sendToWidget());
+ EXPECT_TRUE(mockInputHandler.pinchStarted());
+ mockClient.reset();
+ mockInputHandler.resetPinch();
+
+ gesture.type = WebKit::WebInputEvent::GesturePinchUpdate;
+ gesture.deltaX = 1.5;
+ inputHandler->handleInputEvent(gesture);
+ EXPECT_TRUE(mockClient.handled());
+ EXPECT_FALSE(mockClient.sendToWidget());
+ EXPECT_FALSE(mockInputHandler.pinchEnded());
+ EXPECT_EQ(1.5, mockInputHandler.pinchMaginifcation());
+ mockClient.reset();
+ mockInputHandler.resetPinch();
+
+ gesture.type = WebKit::WebInputEvent::GesturePinchUpdate;
+ gesture.deltaX = 0.5;
+ inputHandler->handleInputEvent(gesture);
+ EXPECT_TRUE(mockClient.handled());
+ EXPECT_FALSE(mockClient.sendToWidget());
+ EXPECT_FALSE(mockInputHandler.pinchEnded());
+ EXPECT_EQ(0.5, mockInputHandler.pinchMaginifcation());
+ mockClient.reset();
+ mockInputHandler.resetPinch();
+
+ gesture.type = WebKit::WebInputEvent::GesturePinchEnd;
+ inputHandler->handleInputEvent(gesture);
+ EXPECT_TRUE(mockClient.handled());
+ EXPECT_FALSE(mockClient.sendToWidget());
+ EXPECT_TRUE(mockInputHandler.pinchEnded());
+ mockClient.reset();
+ mockInputHandler.resetPinch();
+
+ inputHandler->setClient(0);
+
+ WebKit::WebCompositor::shutdown();
+}
+
}