Tools:
fast/forms/ios/zoom-after-input-tap-wide-input.html is timing out
https://bugs.webkit.org/show_bug.cgi?id=206313

Reviewed by Wenson Hsieh.

The timeout was caused by the previous test, fast/forms/ios/validation-bubble-dismiss-on-tap.html,
which puts up a validation bubble whose implementation involves showing a modal UIViewController.
That view controller disappears with an animation, which happened after we're proceeded to the next
test, and the overlay view could intercept touches thus breaking any subsequent touch-based test.

Fix by having platformResetStateToConsistentValues() wait for the presentedViewController to
go to nil, which requires spinning the runloop.

platformResetStateToConsistentValues() will return false if we fail to remove the presented view controller,
which will trigger a timeout with a log.

* WebKitTestRunner/TestController.cpp:
(WTR::TestController::resetStateToConsistentValues):
(WTR::TestController::platformResetStateToConsistentValues):
* WebKitTestRunner/TestController.h:
* WebKitTestRunner/cocoa/TestControllerCocoa.mm:
(WTR::TestController::cocoaResetStateToConsistentValues):
* WebKitTestRunner/ios/TestControllerIOS.mm:
(WTR::TestController::platformResetStateToConsistentValues):
* WebKitTestRunner/mac/TestControllerMac.mm:
(WTR::TestController::platformResetStateToConsistentValues):

LayoutTests:
Some iOS tests using UIHelper.dragFromPointToPoint() are flakey
https://bugs.webkit.org/show_bug.cgi?id=206441

Reviewed by Wenson Hsieh.

Unskip tests.

* platform/ios-wk2/TestExpectations:
* platform/ios/TestExpectations:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@254786 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 2d6b0ad..f372eb1 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,15 @@
+2020-01-17  Simon Fraser  <simon.fraser@apple.com>
+
+        Some iOS tests using UIHelper.dragFromPointToPoint() are flakey
+        https://bugs.webkit.org/show_bug.cgi?id=206441
+
+        Reviewed by Wenson Hsieh.
+
+        Unskip tests.
+
+        * platform/ios-wk2/TestExpectations:
+        * platform/ios/TestExpectations:
+
 2020-01-17  Megan Gardner  <megan_gardner@apple.com>
 
         Use Visible Position to calculate Positions for highlights
diff --git a/LayoutTests/platform/ios-wk2/TestExpectations b/LayoutTests/platform/ios-wk2/TestExpectations
index 5d31d86..290c622 100644
--- a/LayoutTests/platform/ios-wk2/TestExpectations
+++ b/LayoutTests/platform/ios-wk2/TestExpectations
@@ -1339,9 +1339,6 @@
 webkit.org/b/203264 [ Release ] editing/pasteboard/smart-paste-paragraph-003.html [ Pass Failure ]
 webkit.org/b/203264 [ Release ] editing/pasteboard/smart-paste-paragraph-004.html [ Pass Failure ]
 
-# <rdar://problem/56714139> (r251242) [ iOS ]: fast/scrolling/ios/touch-scroll-visibility-hidden.html is a Flaky Timeout (203577)
-webkit.org/b/203577 fast/scrolling/ios/touch-scroll-visibility-hidden.html [ Pass Timeout ]
-
 # Timeout running prompt() because mock implementation is absent.
 webkit.org/b/203572 media/remoteplayback-prompt.html [ Skip ]
 webkit.org/b/203572 media/remoteplayback-target-availability.html [ Skip ]
diff --git a/LayoutTests/platform/ios/TestExpectations b/LayoutTests/platform/ios/TestExpectations
index ef59412..7862b9f 100644
--- a/LayoutTests/platform/ios/TestExpectations
+++ b/LayoutTests/platform/ios/TestExpectations
@@ -3345,10 +3345,6 @@
 fast/text/crash-complex-text-surrogate.html [ Failure ]
 fast/text/international/system-language/system-font-punctuation.html [ Failure ]
 
-# <rdar://problem/51756254>REGRESSION (r244582-r244596) Layout tests fast/scrolling/ios/touch-scroll-visibility-hidden.html fast/scrolling/ios/touch-scroll-pointer-events-none.html are failing
-fast/scrolling/ios/touch-scroll-pointer-events-none.html [ Failure ]
-fast/scrolling/ios/touch-scroll-visibility-hidden.html [ Failure ]
-
 # <rdar://problem/52962272> fast/scrolling/ios/body-overflow-hidden.html is an Image failure
 fast/scrolling/ios/body-overflow-hidden.html [ Pass ImageOnlyFailure ]
 
diff --git a/Tools/ChangeLog b/Tools/ChangeLog
index 8bfc26b..cb4a37a 100644
--- a/Tools/ChangeLog
+++ b/Tools/ChangeLog
@@ -1,3 +1,32 @@
+2020-01-16  Simon Fraser  <simon.fraser@apple.com>
+
+        fast/forms/ios/zoom-after-input-tap-wide-input.html is timing out
+        https://bugs.webkit.org/show_bug.cgi?id=206313
+
+        Reviewed by Wenson Hsieh.
+        
+        The timeout was caused by the previous test, fast/forms/ios/validation-bubble-dismiss-on-tap.html, 
+        which puts up a validation bubble whose implementation involves showing a modal UIViewController.
+        That view controller disappears with an animation, which happened after we're proceeded to the next
+        test, and the overlay view could intercept touches thus breaking any subsequent touch-based test.
+
+        Fix by having platformResetStateToConsistentValues() wait for the presentedViewController to
+        go to nil, which requires spinning the runloop.
+
+        platformResetStateToConsistentValues() will return false if we fail to remove the presented view controller,
+        which will trigger a timeout with a log.
+
+        * WebKitTestRunner/TestController.cpp:
+        (WTR::TestController::resetStateToConsistentValues):
+        (WTR::TestController::platformResetStateToConsistentValues):
+        * WebKitTestRunner/TestController.h:
+        * WebKitTestRunner/cocoa/TestControllerCocoa.mm:
+        (WTR::TestController::cocoaResetStateToConsistentValues):
+        * WebKitTestRunner/ios/TestControllerIOS.mm:
+        (WTR::TestController::platformResetStateToConsistentValues):
+        * WebKitTestRunner/mac/TestControllerMac.mm:
+        (WTR::TestController::platformResetStateToConsistentValues):
+
 2020-01-17  Aakash Jain  <aakash_jain@apple.com>
 
         [EWS] Print disk space usage for windows bots
@@ -134,35 +163,6 @@
         * TestWebKitAPI/Tests/WebKitCocoa/AsyncFunction.mm:
         (TestWebKitAPI::TEST):
 
-2020-01-16  Simon Fraser  <simon.fraser@apple.com>
-
-        fast/forms/ios/zoom-after-input-tap-wide-input.html is timing out
-        https://bugs.webkit.org/show_bug.cgi?id=206313
-
-        Reviewed by Wenson Hsieh.
-        
-        The timeout was caused by the previous test, fast/forms/ios/validation-bubble-dismiss-on-tap.html, 
-        which puts up a validation bubble whose implementation involves showing a modal UIViewController.
-        That view controller disappears with an animation, which happened after we're proceeded to the next
-        test, and the overlay view could intercept touches thus breaking any subsequent touch-based test.
-
-        Fix by having platformResetStateToConsistentValues() wait for the presentedViewController to
-        go to nil, which requires spinning the runloop.
-
-        platformResetStateToConsistentValues() will return false if we fail to remove the presented view controller,
-        which will trigger a timeout with a log.
-
-        * WebKitTestRunner/TestController.cpp:
-        (WTR::TestController::resetStateToConsistentValues):
-        (WTR::TestController::platformResetStateToConsistentValues):
-        * WebKitTestRunner/TestController.h:
-        * WebKitTestRunner/cocoa/TestControllerCocoa.mm:
-        (WTR::TestController::cocoaResetStateToConsistentValues):
-        * WebKitTestRunner/ios/TestControllerIOS.mm:
-        (WTR::TestController::platformResetStateToConsistentValues):
-        * WebKitTestRunner/mac/TestControllerMac.mm:
-        (WTR::TestController::platformResetStateToConsistentValues):
-
 2020-01-16  Philippe Normand  <philn@igalia.com>
 
         [GStreamer][WPE] Client-side video rendering support
@@ -247,6 +247,27 @@
         * Scripts/webkitpy/api_tests/manager.py:
         (Manager._find_test_subset):
 
+2020-01-17  Simon Fraser  <simon.fraser@apple.com>
+
+        Some iOS tests using UIHelper.dragFromPointToPoint() are flakey
+        https://bugs.webkit.org/show_bug.cgi?id=206441
+        rdar://problem/56714139
+
+        Reviewed by Wenson Hsieh.
+
+        The way that HIDEventGenerator sends all the generated events in a blocking loop seems to
+        trigger an issue where the events, when received by the scroll view gesture recognizers,
+        don't actually trigger a scroll.
+
+        Attempt to fix by creating an event stream in UIScriptControllerIOS::dragFromPointToPoint,
+        and dispatching via -[HIDEventGenerator sendEventStream:completionBlock:]. This spawns a
+        thread to dispatch the events, which will hopefully be closer to user behavior and more
+        reliably trigger the gesture recognizer.
+
+        * WebKitTestRunner/ios/UIScriptControllerIOS.mm:
+        (WTR::dictionaryForFingerEventWithContentPoint):
+        (WTR::UIScriptControllerIOS::dragFromPointToPoint):
+
 2020-01-15  David Kilzer  <ddkilzer@apple.com>
 
         Enable -Wconditional-uninitialized in DumpRenderTree, WebKitTestRunner
diff --git a/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm b/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm
index 9ba3303..fa54972 100644
--- a/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm
+++ b/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm
@@ -431,18 +431,56 @@
     [[HIDEventGenerator sharedHIDEventGenerator] sendEventStream:eventInfo completionBlock:completion.get()];
 }
 
+static NSDictionary *dictionaryForFingerEventWithContentPoint(CGPoint point, NSString* phase, Seconds timeOffset)
+{
+    return @{
+        HIDEventCoordinateSpaceKey : HIDEventCoordinateSpaceTypeContent,
+        HIDEventTimeOffsetKey : @(timeOffset.seconds()),
+        HIDEventInputType : HIDEventInputTypeHand,
+        HIDEventTouchesKey : @[
+            @{
+                HIDEventTouchIDKey : @1,
+                HIDEventInputType : HIDEventInputTypeFinger,
+                HIDEventPhaseKey : phase,
+                HIDEventXKey : @(point.x),
+                HIDEventYKey : @(point.y),
+            },
+        ],
+    };
+}
+
 void UIScriptControllerIOS::dragFromPointToPoint(long startX, long startY, long endX, long endY, double durationSeconds, JSValueRef callback)
 {
     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
-
+    
     CGPoint startPoint = globalToContentCoordinates(webView(), startX, startY);
     CGPoint endPoint = globalToContentCoordinates(webView(), endX, endY);
-    
-    [[HIDEventGenerator sharedHIDEventGenerator] dragWithStartPoint:startPoint endPoint:endPoint duration:durationSeconds completionBlock:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
+
+    NSDictionary *touchDownInfo = dictionaryForFingerEventWithContentPoint(startPoint, HIDEventPhaseBegan, 0_s);
+    NSDictionary *interpolatedEvents = @{
+        HIDEventInterpolateKey : HIDEventInterpolationTypeLinear,
+        HIDEventCoordinateSpaceKey : HIDEventCoordinateSpaceTypeContent,
+        HIDEventTimestepKey : @(0.016),
+        HIDEventStartEventKey : dictionaryForFingerEventWithContentPoint(startPoint, HIDEventPhaseMoved, 0_s),
+        HIDEventEndEventKey : dictionaryForFingerEventWithContentPoint(endPoint, HIDEventPhaseMoved, Seconds(durationSeconds)),
+    };
+    NSDictionary *liftUpInfo = dictionaryForFingerEventWithContentPoint(endPoint, HIDEventPhaseEnded, Seconds(durationSeconds));
+
+    NSDictionary *eventStream = @{
+        TopLevelEventInfoKey : @[
+            touchDownInfo,
+            interpolatedEvents,
+            liftUpInfo,
+        ],
+    };
+
+    auto completion = makeBlockPtr([this, protectedThis = makeRefPtr(*this), callbackID] {
         if (!m_context)
             return;
         m_context->asyncTaskComplete(callbackID);
-    }).get()];
+    });
+
+    [[HIDEventGenerator sharedHIDEventGenerator] sendEventStream:eventStream completionBlock:completion.get()];
 }
     
 void UIScriptControllerIOS::longPressAtPoint(long x, long y, JSValueRef callback)