Source/WebKit/chromium: Use new type-specific WebGestureEvent fields
[WebKit-https.git] / Source / WebKit / chromium / tests / WebCompositorInputHandlerImplTest.cpp
index 902fac9..82e3b54 100644 (file)
 
 #include "WebCompositorInputHandlerImpl.h"
 
+#include "CCActiveGestureAnimation.h"
+#include "CCInputHandler.h"
+#include "CCSingleThreadProxy.h"
 #include "WebCompositorInputHandlerClient.h"
 #include "WebInputEvent.h"
-#include "cc/CCActiveGestureAnimation.h"
-#include "cc/CCInputHandler.h"
-#include "cc/CCSingleThreadProxy.h"
 #include <public/WebCompositor.h>
 #include <public/WebFloatPoint.h>
 #include <public/WebPoint.h>
@@ -60,7 +60,7 @@ public:
     MOCK_METHOD0(scheduleAnimation, void());
 
     MOCK_METHOD2(scrollBegin, ScrollStatus(const WebCore::IntPoint&, WebCore::CCInputHandlerClient::ScrollInputType));
-    MOCK_METHOD1(scrollBy, void(const WebCore::IntSize&));
+    MOCK_METHOD2(scrollBy, void(const WebCore::IntPoint&, const WebCore::IntSize&));
     MOCK_METHOD0(scrollEnd, void());
 
 private:
@@ -117,12 +117,24 @@ TEST(WebCompositorInputHandlerImpl, fromIdentifier)
     WebCompositor::shutdown();
 }
 
+class WebCompositorInitializer {
+public:
+    WebCompositorInitializer()
+    {
+        WebCompositor::initialize(0);
+    }
+
+    ~WebCompositorInitializer()
+    {
+        WebCompositor::shutdown();
+    }
+};
+
 class WebCompositorInputHandlerImplTest : public testing::Test {
 public:
     WebCompositorInputHandlerImplTest()
         : m_expectedDisposition(DidHandle)
     {
-        WebCompositor::initialize(0);
         m_inputHandler = WebCompositorInputHandlerImpl::create(&m_mockCCInputHandlerClient);
         m_inputHandler->setClient(&m_mockClient);
     }
@@ -131,7 +143,6 @@ public:
     {
         m_inputHandler->setClient(0);
         m_inputHandler.clear();
-        WebCompositor::shutdown();
     }
 
     // This is defined as a macro because when an expectation is not satisfied the only output you get
@@ -166,12 +177,11 @@ protected:
     OwnPtr<WebCompositorInputHandlerImpl> m_inputHandler;
     MockWebCompositorInputHandlerClient m_mockClient;
     WebGestureEvent gesture;
+    WebCore::DebugScopedSetImplThread alwaysImplThread;
+    WebCompositorInitializer initializer;
 
     enum ExpectedDisposition { DidHandle, DidNotHandle, DropEvent };
     ExpectedDisposition m_expectedDisposition;
-
-private:
-    WebCore::DebugScopedSetImplThread m_alwaysImplThread;
 };
 
 
@@ -190,14 +200,14 @@ TEST_F(WebCompositorInputHandlerImplTest, gestureScrollStarted)
     VERIFY_AND_RESET_MOCKS();
 
     gesture.type = WebInputEvent::GestureScrollUpdate;
-    gesture.deltaY = -40; // -Y means scroll down - i.e. in the +Y direction.
-    EXPECT_CALL(m_mockCCInputHandlerClient, scrollBy(testing::Property(&WebCore::IntSize::height, testing::Gt(0))));
+    gesture.data.scrollUpdate.deltaY = -40; // -Y means scroll down - i.e. in the +Y direction.
+    EXPECT_CALL(m_mockCCInputHandlerClient, scrollBy(testing::_, testing::Property(&WebCore::IntSize::height, testing::Gt(0))));
     m_inputHandler->handleInputEvent(gesture);
 
     VERIFY_AND_RESET_MOCKS();
 
     gesture.type = WebInputEvent::GestureScrollEnd;
-    gesture.deltaY = 0;
+    gesture.data.scrollUpdate.deltaY = 0;
     EXPECT_CALL(m_mockCCInputHandlerClient, scrollEnd());
     m_inputHandler->handleInputEvent(gesture);
 }
@@ -217,13 +227,13 @@ TEST_F(WebCompositorInputHandlerImplTest, gestureScrollOnMainThread)
     VERIFY_AND_RESET_MOCKS();
 
     gesture.type = WebInputEvent::GestureScrollUpdate;
-    gesture.deltaY = 40;
+    gesture.data.scrollUpdate.deltaY = 40;
     m_inputHandler->handleInputEvent(gesture);
 
     VERIFY_AND_RESET_MOCKS();
 
     gesture.type = WebInputEvent::GestureScrollEnd;
-    gesture.deltaY = 0;
+    gesture.data.scrollUpdate.deltaY = 0;
     m_inputHandler->handleInputEvent(gesture);
 }
 
@@ -256,7 +266,7 @@ TEST_F(WebCompositorInputHandlerImplTest, gesturePinch)
     VERIFY_AND_RESET_MOCKS();
 
     gesture.type = WebInputEvent::GesturePinchUpdate;
-    gesture.deltaX = 1.5;
+    gesture.data.pinchUpdate.scale = 1.5;
     gesture.x = 7;
     gesture.y = 13;
     EXPECT_CALL(m_mockCCInputHandlerClient, pinchGestureUpdate(1.5, WebCore::IntPoint(7, 13)));
@@ -265,7 +275,7 @@ TEST_F(WebCompositorInputHandlerImplTest, gesturePinch)
     VERIFY_AND_RESET_MOCKS();
 
     gesture.type = WebInputEvent::GesturePinchUpdate;
-    gesture.deltaX = 0.5;
+    gesture.data.pinchUpdate.scale = 0.5;
     gesture.x = 9;
     gesture.y = 6;
     EXPECT_CALL(m_mockCCInputHandlerClient, pinchGestureUpdate(.5, WebCore::IntPoint(9, 6)));
@@ -288,7 +298,7 @@ TEST_F(WebCompositorInputHandlerImplTest, gestureFlingStarted)
         .WillOnce(testing::Return(WebCore::CCInputHandlerClient::ScrollStarted));
 
     gesture.type = WebInputEvent::GestureFlingStart;
-    gesture.deltaX = 10;
+    gesture.data.flingStart.velocityX = 10;
     EXPECT_CALL(m_mockCCInputHandlerClient, scheduleAnimation());
     m_inputHandler->handleInputEvent(gesture);
 
@@ -349,8 +359,8 @@ TEST_F(WebCompositorInputHandlerImplTest, gestureFlingAnimates)
     WebPoint flingPoint = WebPoint(7, 13);
     WebPoint flingGlobalPoint = WebPoint(17, 23);
     int modifiers = 7;
-    gesture.deltaX = flingDelta.x;
-    gesture.deltaY = flingDelta.y;
+    gesture.data.flingStart.velocityX = flingDelta.x;
+    gesture.data.flingStart.velocityY = flingDelta.y;
     gesture.x = flingPoint.x;
     gesture.y = flingPoint.y;
     gesture.globalX = flingGlobalPoint.x;
@@ -376,7 +386,7 @@ TEST_F(WebCompositorInputHandlerImplTest, gestureFlingAnimates)
     EXPECT_CALL(m_mockCCInputHandlerClient, scheduleAnimation());
     EXPECT_CALL(m_mockCCInputHandlerClient, scrollBegin(testing::_, testing::_))
         .WillOnce(testing::Return(WebCore::CCInputHandlerClient::ScrollStarted));
-    EXPECT_CALL(m_mockCCInputHandlerClient, scrollBy(testing::Property(&WebCore::IntSize::width, testing::Lt(0))));
+    EXPECT_CALL(m_mockCCInputHandlerClient, scrollBy(testing::_, testing::Property(&WebCore::IntSize::width, testing::Lt(0))));
     EXPECT_CALL(m_mockCCInputHandlerClient, scrollEnd());
     m_inputHandler->animate(10.1);
 
@@ -388,7 +398,7 @@ TEST_F(WebCompositorInputHandlerImplTest, gestureFlingAnimates)
     EXPECT_CALL(m_mockCCInputHandlerClient, scheduleAnimation());
     EXPECT_CALL(m_mockCCInputHandlerClient, scrollBegin(testing::_, testing::_))
         .WillOnce(testing::Return(WebCore::CCInputHandlerClient::ScrollOnMainThread));
-    EXPECT_CALL(m_mockCCInputHandlerClient, scrollBy(testing::_)).Times(0);
+    EXPECT_CALL(m_mockCCInputHandlerClient, scrollBy(testing::_, testing::_)).Times(0);
     EXPECT_CALL(m_mockCCInputHandlerClient, scrollEnd()).Times(0);
 
     // Expected wheel fling animation parameters:
@@ -433,8 +443,8 @@ TEST_F(WebCompositorInputHandlerImplTest, gestureFlingTransferResets)
     WebPoint flingPoint = WebPoint(7, 13);
     WebPoint flingGlobalPoint = WebPoint(17, 23);
     int modifiers = 1;
-    gesture.deltaX = flingDelta.x;
-    gesture.deltaY = flingDelta.y;
+    gesture.data.flingStart.velocityX = flingDelta.x;
+    gesture.data.flingStart.velocityY = flingDelta.y;
     gesture.x = flingPoint.x;
     gesture.y = flingPoint.y;
     gesture.globalX = flingGlobalPoint.x;
@@ -458,7 +468,7 @@ TEST_F(WebCompositorInputHandlerImplTest, gestureFlingTransferResets)
     EXPECT_CALL(m_mockCCInputHandlerClient, scheduleAnimation());
     EXPECT_CALL(m_mockCCInputHandlerClient, scrollBegin(testing::_, testing::_))
         .WillOnce(testing::Return(WebCore::CCInputHandlerClient::ScrollStarted));
-    EXPECT_CALL(m_mockCCInputHandlerClient, scrollBy(testing::Property(&WebCore::IntSize::width, testing::Lt(0))));
+    EXPECT_CALL(m_mockCCInputHandlerClient, scrollBy(testing::_, testing::Property(&WebCore::IntSize::width, testing::Lt(0))));
     EXPECT_CALL(m_mockCCInputHandlerClient, scrollEnd());
     m_inputHandler->animate(10.1);
 
@@ -470,7 +480,7 @@ TEST_F(WebCompositorInputHandlerImplTest, gestureFlingTransferResets)
     EXPECT_CALL(m_mockCCInputHandlerClient, scheduleAnimation());
     EXPECT_CALL(m_mockCCInputHandlerClient, scrollBegin(testing::_, testing::_))
         .WillOnce(testing::Return(WebCore::CCInputHandlerClient::ScrollOnMainThread));
-    EXPECT_CALL(m_mockCCInputHandlerClient, scrollBy(testing::_)).Times(0);
+    EXPECT_CALL(m_mockCCInputHandlerClient, scrollBy(testing::_, testing::_)).Times(0);
     EXPECT_CALL(m_mockCCInputHandlerClient, scrollEnd()).Times(0);
 
     // Expected wheel fling animation parameters:
@@ -512,8 +522,8 @@ TEST_F(WebCompositorInputHandlerImplTest, gestureFlingTransferResets)
     flingPoint = WebPoint(95, 87);
     flingGlobalPoint = WebPoint(32, 71);
     modifiers = 2;
-    gesture.deltaX = flingDelta.x;
-    gesture.deltaY = flingDelta.y;
+    gesture.data.flingStart.velocityX = flingDelta.x;
+    gesture.data.flingStart.velocityY = flingDelta.y;
     gesture.x = flingPoint.x;
     gesture.y = flingPoint.y;
     gesture.globalX = flingGlobalPoint.x;
@@ -537,7 +547,7 @@ TEST_F(WebCompositorInputHandlerImplTest, gestureFlingTransferResets)
     EXPECT_CALL(m_mockCCInputHandlerClient, scheduleAnimation());
     EXPECT_CALL(m_mockCCInputHandlerClient, scrollBegin(testing::_, testing::_))
         .WillOnce(testing::Return(WebCore::CCInputHandlerClient::ScrollStarted));
-    EXPECT_CALL(m_mockCCInputHandlerClient, scrollBy(testing::Property(&WebCore::IntSize::height, testing::Gt(0))));
+    EXPECT_CALL(m_mockCCInputHandlerClient, scrollBy(testing::_, testing::Property(&WebCore::IntSize::height, testing::Gt(0))));
     EXPECT_CALL(m_mockCCInputHandlerClient, scrollEnd());
     m_inputHandler->animate(30.1);
 
@@ -547,7 +557,7 @@ TEST_F(WebCompositorInputHandlerImplTest, gestureFlingTransferResets)
     EXPECT_CALL(m_mockCCInputHandlerClient, scheduleAnimation());
     EXPECT_CALL(m_mockCCInputHandlerClient, scrollBegin(testing::_, testing::_))
         .WillOnce(testing::Return(WebCore::CCInputHandlerClient::ScrollOnMainThread));
-    EXPECT_CALL(m_mockCCInputHandlerClient, scrollBy(testing::_)).Times(0);
+    EXPECT_CALL(m_mockCCInputHandlerClient, scrollBy(testing::_, testing::_)).Times(0);
     EXPECT_CALL(m_mockCCInputHandlerClient, scrollEnd()).Times(0);
 
     // We should get parameters from the second fling, nothing from the first fling should "leak".