REGRESSION (r243347) Layout tests fast/events/touch/ios/drag-block-without-overflow-scroll-and-passive-observer-on* are flakey
https://bugs.webkit.org/show_bug.cgi?id=203122
rdar://problem/50058173

Reviewed by Wenson Hsieh.

Rewrite these tests to wait for scrolling to finish, since the overflow is now accelerated and we need
to wait for momentum to end.

Also have them use UIHelper, factoring a function to work with overflow as well as document scroll.

* fast/events/touch/ios/drag-block-without-overflow-scroll-and-passive-observer-on-block-expected.txt:
* fast/events/touch/ios/drag-block-without-overflow-scroll-and-passive-observer-on-block.html:
* fast/events/touch/ios/drag-block-without-overflow-scroll-and-passive-observer-on-document-expected.txt:
* fast/events/touch/ios/drag-block-without-overflow-scroll-and-passive-observer-on-document.html:
* resources/ui-helper.js:
(window.UIHelper.callFunctionAndWaitForEvent):
(window.UIHelper.callFunctionAndWaitForScrollToFinish):
(window.UIHelper.callFunctionAndWaitForTargetScrollToFinish.return.new.Promise):
(window.UIHelper.callFunctionAndWaitForTargetScrollToFinish):
(window.UIHelper.callFunctionAndWaitForScrollToFinish.return.new.Promise): Deleted.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@251272 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 654ea6b..e691220 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,27 @@
+2019-10-17  Simon Fraser  <simon.fraser@apple.com>
+
+        REGRESSION (r243347) Layout tests fast/events/touch/ios/drag-block-without-overflow-scroll-and-passive-observer-on* are flakey
+        https://bugs.webkit.org/show_bug.cgi?id=203122
+        rdar://problem/50058173
+
+        Reviewed by Wenson Hsieh.
+        
+        Rewrite these tests to wait for scrolling to finish, since the overflow is now accelerated and we need
+        to wait for momentum to end.
+
+        Also have them use UIHelper, factoring a function to work with overflow as well as document scroll.
+
+        * fast/events/touch/ios/drag-block-without-overflow-scroll-and-passive-observer-on-block-expected.txt:
+        * fast/events/touch/ios/drag-block-without-overflow-scroll-and-passive-observer-on-block.html:
+        * fast/events/touch/ios/drag-block-without-overflow-scroll-and-passive-observer-on-document-expected.txt:
+        * fast/events/touch/ios/drag-block-without-overflow-scroll-and-passive-observer-on-document.html:
+        * resources/ui-helper.js:
+        (window.UIHelper.callFunctionAndWaitForEvent):
+        (window.UIHelper.callFunctionAndWaitForScrollToFinish):
+        (window.UIHelper.callFunctionAndWaitForTargetScrollToFinish.return.new.Promise):
+        (window.UIHelper.callFunctionAndWaitForTargetScrollToFinish):
+        (window.UIHelper.callFunctionAndWaitForScrollToFinish.return.new.Promise): Deleted.
+
 2019-10-17  Dean Jackson  <dino@apple.com>
 
         ctx.font = "" asserts in CSS parser
diff --git a/LayoutTests/fast/events/touch/ios/drag-block-without-overflow-scroll-and-passive-observer-on-block-expected.txt b/LayoutTests/fast/events/touch/ios/drag-block-without-overflow-scroll-and-passive-observer-on-block-expected.txt
index 202fe03..2c3ae17 100644
--- a/LayoutTests/fast/events/touch/ios/drag-block-without-overflow-scroll-and-passive-observer-on-block-expected.txt
+++ b/LayoutTests/fast/events/touch/ios/drag-block-without-overflow-scroll-and-passive-observer-on-block-expected.txt
@@ -13,7 +13,6 @@
 Received event touchstart at 50, 150
 Received event touchmove at 50, 50
 Received event touchend
-Dispatched Drag
 PASS window.scrollX is 0
 PASS window.scrollY is 0
 PASS document.documentElement.scrollTop is 0
diff --git a/LayoutTests/fast/events/touch/ios/drag-block-without-overflow-scroll-and-passive-observer-on-block.html b/LayoutTests/fast/events/touch/ios/drag-block-without-overflow-scroll-and-passive-observer-on-block.html
index 0084df4..94b2086 100644
--- a/LayoutTests/fast/events/touch/ios/drag-block-without-overflow-scroll-and-passive-observer-on-block.html
+++ b/LayoutTests/fast/events/touch/ios/drag-block-without-overflow-scroll-and-passive-observer-on-block.html
@@ -1,13 +1,14 @@
 <!DOCTYPE html> <!-- webkit-test-runner [ internal:AsyncOverflowScrollingEnabled=true ] -->
 <html>
 <head>
+    <meta name="viewport" content="initial-scale=1">
+    <script src="../../../../resources/ui-helper.js"></script>
     <script src="../../../../resources/js-test-pre.js"></script>
     <style>
         body {
             margin: 0;
         }
     </style>
-    <meta name="viewport" content="initial-scale=1">
 </head>
 <body>
     <div id="eventTarget" style="overflow: scroll; height: 200px">
@@ -20,29 +21,9 @@
         description("Test scrolling on a block without -webkit-overflow-scrolling.");
         window.jsTestIsAsync = true;
 
-        function getDragUIScript(startX, startY, endX, endY)
+        async function runTest()
         {
-            return `
-            (function() {
-                uiController.dragFromPointToPoint(${startX}, ${startY}, ${endX}, ${endY}, 0.15, function() {
-                    uiController.uiScriptComplete("Dispatched Drag");
-                });
-            })();`
-        }
-
-        function runTest()
-        {
-            function scrollEventHandler(event) {
-                shouldBe("window.scrollX", "0");
-                shouldBe("window.scrollY", "0");
-                shouldBe("document.documentElement.scrollTop", "0");
-                shouldBe("document.documentElement.scrollLeft", "0");
-                shouldBeTrue("document.getElementById('eventTarget').scrollTop > 0");
-                shouldBe("document.getElementById('eventTarget').scrollLeft", "0");
-                finishJSTest();
-            }
             let eventTarget = document.getElementById("eventTarget");
-            eventTarget.addEventListener("scroll", scrollEventHandler);
 
             function touchEventHandler(event) {
                 if (event.touches.length)
@@ -55,18 +36,24 @@
             eventTarget.addEventListener('touchend', touchEventHandler, { 'passive': true });
             eventTarget.addEventListener('touchcancel', touchEventHandler, { 'passive': true });
 
-            if (window.testRunner) {
-                testRunner.runUIScript(getDragUIScript(50, 150, 50, 50), function(result) {
-                    debug(result);
-                });
-            }
-
             shouldBe("window.scrollX", "0");
             shouldBe("window.scrollY", "0");
             shouldBe("document.documentElement.scrollTop", "0");
             shouldBe("document.documentElement.scrollLeft", "0");
             shouldBe("document.getElementById('eventTarget').scrollTop", "0");
             shouldBe("document.getElementById('eventTarget').scrollLeft", "0");
+
+            await UIHelper.callFunctionAndWaitForTargetScrollToFinish(eventTarget, async () => {
+                await UIHelper.dragFromPointToPoint(50, 150, 50, 50, 0.15);
+            });
+
+            shouldBe("window.scrollX", "0");
+            shouldBe("window.scrollY", "0");
+            shouldBe("document.documentElement.scrollTop", "0");
+            shouldBe("document.documentElement.scrollLeft", "0");
+            shouldBeTrue("document.getElementById('eventTarget').scrollTop > 0");
+            shouldBe("document.getElementById('eventTarget').scrollLeft", "0");
+            finishJSTest();
         }
 
         window.addEventListener('load', runTest, false);
diff --git a/LayoutTests/fast/events/touch/ios/drag-block-without-overflow-scroll-and-passive-observer-on-document-expected.txt b/LayoutTests/fast/events/touch/ios/drag-block-without-overflow-scroll-and-passive-observer-on-document-expected.txt
index 202fe03..2c3ae17 100644
--- a/LayoutTests/fast/events/touch/ios/drag-block-without-overflow-scroll-and-passive-observer-on-document-expected.txt
+++ b/LayoutTests/fast/events/touch/ios/drag-block-without-overflow-scroll-and-passive-observer-on-document-expected.txt
@@ -13,7 +13,6 @@
 Received event touchstart at 50, 150
 Received event touchmove at 50, 50
 Received event touchend
-Dispatched Drag
 PASS window.scrollX is 0
 PASS window.scrollY is 0
 PASS document.documentElement.scrollTop is 0
diff --git a/LayoutTests/fast/events/touch/ios/drag-block-without-overflow-scroll-and-passive-observer-on-document.html b/LayoutTests/fast/events/touch/ios/drag-block-without-overflow-scroll-and-passive-observer-on-document.html
index 8acaf97..93615f8 100644
--- a/LayoutTests/fast/events/touch/ios/drag-block-without-overflow-scroll-and-passive-observer-on-document.html
+++ b/LayoutTests/fast/events/touch/ios/drag-block-without-overflow-scroll-and-passive-observer-on-document.html
@@ -1,13 +1,14 @@
 <!DOCTYPE html> <!-- webkit-test-runner [ internal:AsyncOverflowScrollingEnabled=true ] -->
 <html>
 <head>
+    <meta name="viewport" content="initial-scale=1">
     <script src="../../../../resources/js-test-pre.js"></script>
+    <script src="../../../../resources/ui-helper.js"></script>
     <style>
         body {
             margin: 0;
         }
     </style>
-    <meta name="viewport" content="initial-scale=1">
 </head>
 <body>
     <div id="eventTarget" style="overflow: scroll; height: 200px">
@@ -20,29 +21,9 @@
         description("Test scrolling on a block without -webkit-overflow-scrolling.");
         window.jsTestIsAsync = true;
 
-        function getDragUIScript(startX, startY, endX, endY)
+        async function runTest()
         {
-            return `
-            (function() {
-                uiController.dragFromPointToPoint(${startX}, ${startY}, ${endX}, ${endY}, 0.15, function() {
-                    uiController.uiScriptComplete("Dispatched Drag");
-                });
-            })();`
-        }
-
-        function runTest()
-        {
-            function scrollEventHandler(event) {
-                shouldBe("window.scrollX", "0");
-                shouldBe("window.scrollY", "0");
-                shouldBe("document.documentElement.scrollTop", "0");
-                shouldBe("document.documentElement.scrollLeft", "0");
-                shouldBeTrue("document.getElementById('eventTarget').scrollTop > 0");
-                shouldBe("document.getElementById('eventTarget').scrollLeft", "0");
-                finishJSTest();
-            }
             let eventTarget = document.getElementById("eventTarget");
-            eventTarget.addEventListener("scroll", scrollEventHandler);
 
             function touchEventHandler(event) {
                 if (event.touches.length)
@@ -50,23 +31,30 @@
                 else
                     debug("Received" + (event.cancelable ? " cancelable" : "") + " event " + event.type);
             }
+
             document.addEventListener('touchstart', touchEventHandler, { 'passive': true });
             document.addEventListener('touchmove', touchEventHandler, { 'passive': true });
             document.addEventListener('touchend', touchEventHandler, { 'passive': true });
             document.addEventListener('touchcancel', touchEventHandler, { 'passive': true });
 
-            if (window.testRunner) {
-                testRunner.runUIScript(getDragUIScript(50, 150, 50, 50), function(result) {
-                    debug(result);
-                });
-            }
-
             shouldBe("window.scrollX", "0");
             shouldBe("window.scrollY", "0");
             shouldBe("document.documentElement.scrollTop", "0");
             shouldBe("document.documentElement.scrollLeft", "0");
             shouldBe("document.getElementById('eventTarget').scrollTop", "0");
             shouldBe("document.getElementById('eventTarget').scrollLeft", "0");
+
+            await UIHelper.callFunctionAndWaitForTargetScrollToFinish(eventTarget, async () => {
+                await UIHelper.dragFromPointToPoint(50, 150, 50, 50, 0.15);
+            });
+
+            shouldBe("window.scrollX", "0");
+            shouldBe("window.scrollY", "0");
+            shouldBe("document.documentElement.scrollTop", "0");
+            shouldBe("document.documentElement.scrollLeft", "0");
+            shouldBeTrue("document.getElementById('eventTarget').scrollTop > 0");
+            shouldBe("document.getElementById('eventTarget').scrollLeft", "0");
+            finishJSTest();
         }
 
         window.addEventListener('load', runTest, false);
diff --git a/LayoutTests/resources/ui-helper.js b/LayoutTests/resources/ui-helper.js
index 5af9744..c010612 100644
--- a/LayoutTests/resources/ui-helper.js
+++ b/LayoutTests/resources/ui-helper.js
@@ -942,14 +942,18 @@
             target.addEventListener(eventName, resolve, { once: true });
             functionToCall();
         });
-
     }
 
     static callFunctionAndWaitForScrollToFinish(functionToCall, ...theArguments)
     {
+        return UIHelper.callFunctionAndWaitForTargetScrollToFinish(window, functionToCall, theArguments)
+    }
+
+    static callFunctionAndWaitForTargetScrollToFinish(scrollTarget, functionToCall, ...theArguments)
+    {
         return new Promise((resolved) => {
             function scrollDidFinish() {
-                window.removeEventListener("scroll", handleScroll, true);
+                scrollTarget.removeEventListener("scroll", handleScroll, true);
                 resolved();
             }
 
@@ -961,7 +965,7 @@
                 }
                 lastScrollTimerId = window.setTimeout(scrollDidFinish, 300); // Over 250ms to give some room for error.
             }
-            window.addEventListener("scroll", handleScroll, true);
+            scrollTarget.addEventListener("scroll", handleScroll, true);
 
             functionToCall.apply(this, theArguments);
         });