[GTK] Enable navigation swipe layout tests
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 20 Jun 2019 17:05:19 +0000 (17:05 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 20 Jun 2019 17:05:19 +0000 (17:05 +0000)
https://bugs.webkit.org/show_bug.cgi?id=198995

Patch by Alexander Mikhaylenko <exalm7659@gmail.com> on 2019-06-20
Reviewed by Michael Catanzaro.

Source/WebKit:

Implement API for enabling and controlling swipes from WebKitTestRunner.

Implement beginSimulatedSwipeInDirectionForTesting() and completeSimulatedSwipeInDirectionForTesting()
in ViewGestureController for controlling the test swipes. Add functions in WebKitWebViewBase for calling
them.

Simulate the gesture by generating two scroll events: one to begin the gesture and one to complete it.

Since there's no reliable way to set source device type of the generated events to touchpad, don't check
source device type for simulated swipes.

* UIProcess/API/C/gtk/WKView.cpp:
(WKViewSetEnableBackForwardNavigationGesture): Added.
(WKViewBeginBackSwipeForTesting): Added.
(WKViewCompleteBackSwipeForTesting): Added.
* UIProcess/API/C/gtk/WKViewPrivate.h:
* UIProcess/API/gtk/WebKitWebViewBase.cpp:
(webkitWebViewBaseBeginBackSwipeForTesting): Added.
(webkitWebViewBaseCompleteBackSwipeForTesting): Added.
* UIProcess/API/gtk/WebKitWebViewBasePrivate.h:
* UIProcess/ViewGestureController.h:
* UIProcess/gtk/ViewGestureControllerGtk.cpp:
(WebKit::ViewGestureController::PendingSwipeTracker::scrollEventCanInfluenceSwipe):
Skip source device type check for simulated swipes. Also, remove an incorrect FIXME.
(WebKit::createScrollEvent): Added.
(WebKit::ViewGestureController::beginSimulatedSwipeInDirectionForTesting): Implemented.
(WebKit::ViewGestureController::completeSimulatedSwipeInDirectionForTesting): Implemented.

Tools:

Add a way for tests to enable and then control swipe gesture on GTK.

* TestRunnerShared/UIScriptContext/UIScriptController.cpp: Hide
empty implementations of beginBackSwipe() and completeBackSwipe() for GTK.
* WebKitTestRunner/PlatformGTK.cmake:
* WebKitTestRunner/gtk/PlatformWebViewGtk.cpp:
(WTR::PlatformWebView::setNavigationGesturesEnabled): Implemented.
* WebKitTestRunner/gtk/UIScriptControllerGtk.cpp: Added.
(WTR::UIScriptController::beginBackSwipe):
(WTR::UIScriptController::completeBackSwipe):

LayoutTests:

Enable the existing tests for the swipe gesture.

swipe/pushState-programmatic-back-while-swiping-crash.html is not applicable because
it deals with NSEvents directly, skip it.

swipe/main-frame-pinning-requirement.html is flaky, same as on Mac.

swipe/pushstate-with-manual-scrollrestoration.html passes, don't mark it as failure.

* platform/gtk/TestExpectations:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@246639 268f45cc-cd09-0410-ab3c-d52691b4dbfc

14 files changed:
LayoutTests/ChangeLog
LayoutTests/platform/gtk/TestExpectations
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/C/gtk/WKView.cpp
Source/WebKit/UIProcess/API/C/gtk/WKViewPrivate.h
Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp
Source/WebKit/UIProcess/API/gtk/WebKitWebViewBasePrivate.h
Source/WebKit/UIProcess/ViewGestureController.h
Source/WebKit/UIProcess/gtk/ViewGestureControllerGtk.cpp
Tools/ChangeLog
Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp
Tools/WebKitTestRunner/PlatformGTK.cmake
Tools/WebKitTestRunner/gtk/PlatformWebViewGtk.cpp
Tools/WebKitTestRunner/gtk/UIScriptControllerGtk.cpp [new file with mode: 0644]

index b5a4d4f..1f21160 100644 (file)
@@ -1,5 +1,23 @@
 2019-06-20  Alexander Mikhaylenko  <exalm7659@gmail.com>
 
+        [GTK] Enable navigation swipe layout tests
+        https://bugs.webkit.org/show_bug.cgi?id=198995
+
+        Reviewed by Michael Catanzaro.
+
+        Enable the existing tests for the swipe gesture.
+
+        swipe/pushState-programmatic-back-while-swiping-crash.html is not applicable because
+        it deals with NSEvents directly, skip it.
+
+        swipe/main-frame-pinning-requirement.html is flaky, same as on Mac.
+
+        swipe/pushstate-with-manual-scrollrestoration.html passes, don't mark it as failure.
+
+        * platform/gtk/TestExpectations:
+
+2019-06-20  Alexander Mikhaylenko  <exalm7659@gmail.com>
+
         [GTK] HTTP layout tests don't run in flatpak
         https://bugs.webkit.org/show_bug.cgi?id=199067
 
index 4343727..6bda70d 100644 (file)
@@ -21,6 +21,7 @@
 
 accessibility/gtk [ Pass ]
 editing/pasteboard/gtk [ Pass ]
+swipe [ Pass ]
 
 #//////////////////////////////////////////////////////////////////////////////////////////
 # End platform-specific directories.
@@ -1220,6 +1221,9 @@ fast/mediastream/screencapture-user-gesture.html [ Skip ]
 # No different rendering for text-rendering: optimizeLegibility
 fast/text/variations/optical-sizing-trak-2.html [ Skip ]
 
+# The test directly sends Cocoa events
+swipe/pushState-programmatic-back-while-swiping-crash.html [ Skip ]
+
 #////////////////////////////////////////////////////////////////////////////////////////
 # End of Expected failures.
 #
@@ -2254,6 +2258,8 @@ webkit.org/b/198830 media/video-src.html [ Crash Pass ]
 webkit.org/b/198830 media/video-timeupdate-reverse-play.html [ Crash Pass ]
 webkit.org/b/198830 media/video-trackmenu-selection.html [ Crash Timeout ]
 
+webkit.org/b/170484 swipe/main-frame-pinning-requirement.html [ Pass Failure ]
+
 #////////////////////////////////////////////////////////////////////////////////////////
 # End of Flaky tests
 #////////////////////////////////////////////////////////////////////////////////////////
index 0ea420f..4d853a1 100644 (file)
@@ -1,3 +1,38 @@
+2019-06-20  Alexander Mikhaylenko  <exalm7659@gmail.com>
+
+        [GTK] Enable navigation swipe layout tests
+        https://bugs.webkit.org/show_bug.cgi?id=198995
+
+        Reviewed by Michael Catanzaro.
+
+        Implement API for enabling and controlling swipes from WebKitTestRunner.
+
+        Implement beginSimulatedSwipeInDirectionForTesting() and completeSimulatedSwipeInDirectionForTesting()
+        in ViewGestureController for controlling the test swipes. Add functions in WebKitWebViewBase for calling
+        them.
+
+        Simulate the gesture by generating two scroll events: one to begin the gesture and one to complete it.
+
+        Since there's no reliable way to set source device type of the generated events to touchpad, don't check
+        source device type for simulated swipes.
+
+        * UIProcess/API/C/gtk/WKView.cpp:
+        (WKViewSetEnableBackForwardNavigationGesture): Added.
+        (WKViewBeginBackSwipeForTesting): Added.
+        (WKViewCompleteBackSwipeForTesting): Added.
+        * UIProcess/API/C/gtk/WKViewPrivate.h:
+        * UIProcess/API/gtk/WebKitWebViewBase.cpp:
+        (webkitWebViewBaseBeginBackSwipeForTesting): Added.
+        (webkitWebViewBaseCompleteBackSwipeForTesting): Added.
+        * UIProcess/API/gtk/WebKitWebViewBasePrivate.h:
+        * UIProcess/ViewGestureController.h:
+        * UIProcess/gtk/ViewGestureControllerGtk.cpp:
+        (WebKit::ViewGestureController::PendingSwipeTracker::scrollEventCanInfluenceSwipe):
+        Skip source device type check for simulated swipes. Also, remove an incorrect FIXME.
+        (WebKit::createScrollEvent): Added.
+        (WebKit::ViewGestureController::beginSimulatedSwipeInDirectionForTesting): Implemented.
+        (WebKit::ViewGestureController::completeSimulatedSwipeInDirectionForTesting): Implemented.
+
 2019-06-20  Charlie Turner  <cturner@igalia.com>
 
         [GTK] Make startup pause available in DEVELOPER_MODE rather than DEBUG.
index 48c41ac..501c164 100644 (file)
@@ -48,3 +48,18 @@ void WKViewSetFocus(WKViewRef viewRef, bool focused)
 {
     webkitWebViewBaseSetFocus(toImpl(viewRef), focused);
 }
+
+void WKViewSetEnableBackForwardNavigationGesture(WKViewRef viewRef, bool enabled)
+{
+    webkitWebViewBaseSetEnableBackForwardNavigationGesture(toImpl(viewRef), enabled);
+}
+
+bool WKViewBeginBackSwipeForTesting(WKViewRef viewRef)
+{
+    return webkitWebViewBaseBeginBackSwipeForTesting(toImpl(viewRef));
+}
+
+bool WKViewCompleteBackSwipeForTesting(WKViewRef viewRef)
+{
+    return webkitWebViewBaseCompleteBackSwipeForTesting(toImpl(viewRef));
+}
index acabfd3..aafd657 100644 (file)
@@ -34,6 +34,12 @@ extern "C" {
 
 WK_EXPORT void WKViewSetFocus(WKViewRef viewRef, bool focused);
 
+WK_EXPORT void WKViewSetEnableBackForwardNavigationGesture(WKViewRef viewRef, bool enabled);
+
+WK_EXPORT bool WKViewBeginBackSwipeForTesting(WKViewRef viewRef);
+
+WK_EXPORT bool WKViewCompleteBackSwipeForTesting(WKViewRef viewRef);
+
 #ifdef __cplusplus
 }
 #endif
index d8db109..9be93ca 100644 (file)
@@ -1263,6 +1263,22 @@ ViewGestureController* webkitWebViewBaseViewGestureController(WebKitWebViewBase*
     return webViewBase->priv->viewGestureController.get();
 }
 
+bool webkitWebViewBaseBeginBackSwipeForTesting(WebKitWebViewBase* webViewBase)
+{
+    if (auto* gestureController = webkitWebViewBaseViewGestureController(webViewBase))
+        return gestureController->beginSimulatedSwipeInDirectionForTesting(ViewGestureController::SwipeDirection::Back);
+
+    return FALSE;
+}
+
+bool webkitWebViewBaseCompleteBackSwipeForTesting(WebKitWebViewBase* webViewBase)
+{
+    if (auto* gestureController = webkitWebViewBaseViewGestureController(webViewBase))
+        return gestureController->completeSimulatedSwipeInDirectionForTesting(ViewGestureController::SwipeDirection::Back);
+
+    return FALSE;
+}
+
 static gboolean webkitWebViewBaseQueryTooltip(GtkWidget* widget, gint /* x */, gint /* y */, gboolean keyboardMode, GtkTooltip* tooltip)
 {
     WebKitWebViewBasePrivate* priv = WEBKIT_WEB_VIEW_BASE(widget)->priv;
index d1a6f02..33cf7c5 100644 (file)
@@ -89,6 +89,9 @@ RefPtr<WebKit::ViewSnapshot> webkitWebViewBaseTakeViewSnapshot(WebKitWebViewBase
 void webkitWebViewBaseSetEnableBackForwardNavigationGesture(WebKitWebViewBase*, bool enabled);
 WebKit::ViewGestureController* webkitWebViewBaseViewGestureController(WebKitWebViewBase*);
 
+bool webkitWebViewBaseBeginBackSwipeForTesting(WebKitWebViewBase*);
+bool webkitWebViewBaseCompleteBackSwipeForTesting(WebKitWebViewBase*);
+
 void webkitWebViewBaseDidStartProvisionalLoadForMainFrame(WebKitWebViewBase*);
 void webkitWebViewBaseDidFirstVisuallyNonEmptyLayoutForMainFrame(WebKitWebViewBase*);
 void webkitWebViewBaseDidFinishLoadForMainFrame(WebKitWebViewBase*);
index c1670d3..f3df32f 100644 (file)
@@ -409,6 +409,8 @@ private:
     SwipeProgressTracker m_swipeProgressTracker;
 
     RefPtr<cairo_pattern_t> m_currentSwipeSnapshotPattern;
+
+    bool m_isSimulatedSwipe { false };
 #endif
 
     bool m_isConnectedToProcess { false };
index 597cea1..aeae32b 100644 (file)
@@ -84,9 +84,9 @@ bool ViewGestureController::PendingSwipeTracker::scrollEventCanInfluenceSwipe(Gd
     GdkDevice* device = gdk_event_get_source_device(reinterpret_cast<GdkEvent*>(event));
     GdkInputSource source = gdk_device_get_source(device);
 
-    // FIXME: Should it maybe be allowed on mice/trackpoints as well? The GDK_SCROLL_SMOOTH
-    // requirement already filters out most mice, and it works pretty well on a trackpoint
-    return gdk_event_get_scroll_deltas(reinterpret_cast<GdkEvent*>(event), nullptr, nullptr) && (source == GDK_SOURCE_TOUCHPAD || source == GDK_SOURCE_TOUCHSCREEN);
+    bool isDeviceAllowed = source == GDK_SOURCE_TOUCHPAD || source == GDK_SOURCE_TOUCHSCREEN || m_viewGestureController.m_isSimulatedSwipe;
+
+    return gdk_event_get_scroll_deltas(reinterpret_cast<GdkEvent*>(event), nullptr, nullptr) && isDeviceAllowed;
 }
 
 static bool isTouchEvent(GdkEventScroll* event)
@@ -412,14 +412,63 @@ void ViewGestureController::removeSwipeSnapshot()
     m_swipeProgressTracker.reset();
 }
 
-bool ViewGestureController::beginSimulatedSwipeInDirectionForTesting(SwipeDirection)
+static GUniquePtr<GdkEvent> createScrollEvent(GtkWidget* widget, double xDelta, double yDelta)
 {
-    return false;
+    GdkWindow* window = gtk_widget_get_window(widget);
+
+    int x, y;
+    gdk_window_get_root_origin(window, &x, &y);
+
+    int width = gdk_window_get_width(window);
+    int height = gdk_window_get_height(window);
+
+    GUniquePtr<GdkEvent> event(gdk_event_new(GDK_SCROLL));
+    event->scroll.time = GDK_CURRENT_TIME;
+    event->scroll.x = width / 2;
+    event->scroll.y = height / 2;
+    event->scroll.x_root = x + width / 2;
+    event->scroll.y_root = y + height / 2;
+    event->scroll.direction = GDK_SCROLL_SMOOTH;
+    event->scroll.delta_x = xDelta;
+    event->scroll.delta_y = yDelta;
+    event->scroll.state = 0;
+#if GTK_CHECK_VERSION(3, 20, 0)
+    event->scroll.is_stop = !xDelta && !yDelta;
+#endif
+    event->scroll.window = GDK_WINDOW(g_object_ref(window));
+    gdk_event_set_screen(event.get(), gdk_window_get_screen(window));
+    gdk_event_set_device(event.get(), gdk_device_manager_get_client_pointer(gdk_display_get_device_manager(gdk_window_get_display(window))));
+    gdk_event_set_source_device(event.get(), gdk_device_manager_get_client_pointer(gdk_display_get_device_manager(gdk_window_get_display(window))));
+
+    return event;
+}
+
+bool ViewGestureController::beginSimulatedSwipeInDirectionForTesting(SwipeDirection direction)
+{
+    if (!canSwipeInDirection(direction))
+        return false;
+
+    m_isSimulatedSwipe = true;
+
+    double delta = swipeTouchpadBaseWidth / gtkScrollDeltaMultiplier * 0.75;
+
+    if (isPhysicallySwipingLeft(direction))
+        delta = -delta;
+
+    GUniquePtr<GdkEvent> event = createScrollEvent(m_webPageProxy.viewWidget(), delta, 0);
+    gtk_widget_event(m_webPageProxy.viewWidget(), event.get());
+
+    return true;
 }
 
 bool ViewGestureController::completeSimulatedSwipeInDirectionForTesting(SwipeDirection)
 {
-    return false;
+    GUniquePtr<GdkEvent> event = createScrollEvent(m_webPageProxy.viewWidget(), 0, 0);
+    gtk_widget_event(m_webPageProxy.viewWidget(), event.get());
+
+    m_isSimulatedSwipe = false;
+
+    return true;
 }
 
 } // namespace WebKit
index 389d14d..3225151 100644 (file)
@@ -1,5 +1,23 @@
 2019-06-20  Alexander Mikhaylenko  <exalm7659@gmail.com>
 
+        [GTK] Enable navigation swipe layout tests
+        https://bugs.webkit.org/show_bug.cgi?id=198995
+
+        Reviewed by Michael Catanzaro.
+
+        Add a way for tests to enable and then control swipe gesture on GTK.
+
+        * TestRunnerShared/UIScriptContext/UIScriptController.cpp: Hide
+        empty implementations of beginBackSwipe() and completeBackSwipe() for GTK.
+        * WebKitTestRunner/PlatformGTK.cmake:
+        * WebKitTestRunner/gtk/PlatformWebViewGtk.cpp:
+        (WTR::PlatformWebView::setNavigationGesturesEnabled): Implemented.
+        * WebKitTestRunner/gtk/UIScriptControllerGtk.cpp: Added.
+        (WTR::UIScriptController::beginBackSwipe):
+        (WTR::UIScriptController::completeBackSwipe):
+
+2019-06-20  Alexander Mikhaylenko  <exalm7659@gmail.com>
+
         [GTK] HTTP layout tests don't run in flatpak
         https://bugs.webkit.org/show_bug.cgi?id=199067
 
index 39efca1..1bedd7e 100644 (file)
@@ -671,6 +671,7 @@ void UIScriptController::addViewToWindow(JSValueRef)
 {
 }
 
+#if !PLATFORM(GTK)
 void UIScriptController::beginBackSwipe(JSValueRef callback)
 {
 }
@@ -678,6 +679,7 @@ void UIScriptController::beginBackSwipe(JSValueRef callback)
 void UIScriptController::completeBackSwipe(JSValueRef callback)
 {
 }
+#endif
 
 void UIScriptController::setShareSheetCompletesImmediatelyWithResolution(bool)
 {
index 2029fb0..43b9869 100644 (file)
@@ -10,6 +10,7 @@ list(APPEND WebKitTestRunner_SOURCES
     ${WEBKIT_TESTRUNNER_DIR}/gtk/EventSenderProxyGtk.cpp
     ${WEBKIT_TESTRUNNER_DIR}/gtk/PlatformWebViewGtk.cpp
     ${WEBKIT_TESTRUNNER_DIR}/gtk/TestControllerGtk.cpp
+    ${WEBKIT_TESTRUNNER_DIR}/gtk/UIScriptControllerGtk.cpp
     ${WEBKIT_TESTRUNNER_DIR}/gtk/main.cpp
 )
 
index b366844..d4a2629 100644 (file)
@@ -185,8 +185,9 @@ void PlatformWebView::dismissAllPopupMenus()
     }, nullptr);
 }
 
-void PlatformWebView::setNavigationGesturesEnabled(bool)
+void PlatformWebView::setNavigationGesturesEnabled(bool enabled)
 {
+    WKViewSetEnableBackForwardNavigationGesture(platformView(), enabled);
 }
 
 bool PlatformWebView::drawsBackground() const
diff --git a/Tools/WebKitTestRunner/gtk/UIScriptControllerGtk.cpp b/Tools/WebKitTestRunner/gtk/UIScriptControllerGtk.cpp
new file mode 100644 (file)
index 0000000..6321cce
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2019 Alexander Mikhaylenko <exalm7659@gmail.com>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "UIScriptController.h"
+
+#include "PlatformWebView.h"
+#include "TestController.h"
+#include <WebKit/WKViewPrivate.h>
+
+namespace WTR {
+
+void UIScriptController::beginBackSwipe(JSValueRef callback)
+{
+    auto* webView = TestController::singleton().mainWebView()->platformView();
+
+    WKViewBeginBackSwipeForTesting(webView);
+}
+
+void UIScriptController::completeBackSwipe(JSValueRef callback)
+{
+    auto* webView = TestController::singleton().mainWebView()->platformView();
+
+    WKViewCompleteBackSwipeForTesting(webView);
+}
+
+} // namespace WTR