Title: [282096] trunk
Revision
282096
Author
[email protected]
Date
2021-09-07 11:00:38 -0700 (Tue, 07 Sep 2021)

Log Message

Rewrite long press and drag tests to be more robust.
https://bugs.webkit.org/show_bug.cgi?id=229779
rdar://40917203

Reviewed by Wenson Hsieh.

Tools:

Found a crash when bad data was entered for gesture emulation.

* WebKitTestRunner/ios/UIScriptControllerIOS.mm:
(WTR::convertCoordinates):

LayoutTests:

Rewrite long press and drag tests to use more modern methods and make the test more
robust to small changes in UIKit's selection code.

* fast/events/touch/ios/long-press-on-editable-content-then-drag-down-to-change-selected-text-expected.txt:
* fast/events/touch/ios/long-press-on-editable-content-then-drag-down-to-change-selected-text.html:
* fast/events/touch/ios/long-press-on-editable-content-then-drag-left-to-change-selected-text-expected.txt:
* fast/events/touch/ios/long-press-on-editable-content-then-drag-left-to-change-selected-text.html:
* fast/events/touch/ios/long-press-on-editable-content-then-drag-right-to-change-selected-text-expected.txt:
* fast/events/touch/ios/long-press-on-editable-content-then-drag-right-to-change-selected-text.html:
* fast/events/touch/ios/long-press-on-editable-content-then-drag-up-to-change-selected-text-expected.txt:
* fast/events/touch/ios/long-press-on-editable-content-then-drag-up-to-change-selected-text.html:
* resources/ui-helper.js:
(window.UIHelper.midPointOfRect):

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (282095 => 282096)


--- trunk/LayoutTests/ChangeLog	2021-09-07 17:54:59 UTC (rev 282095)
+++ trunk/LayoutTests/ChangeLog	2021-09-07 18:00:38 UTC (rev 282096)
@@ -1,3 +1,25 @@
+2021-09-07  Megan Gardner  <[email protected]>
+
+        Rewrite long press and drag tests to be more robust.
+        https://bugs.webkit.org/show_bug.cgi?id=229779
+        rdar://40917203
+
+        Reviewed by Wenson Hsieh.
+
+        Rewrite long press and drag tests to use more modern methods and make the test more
+        robust to small changes in UIKit's selection code. 
+
+        * fast/events/touch/ios/long-press-on-editable-content-then-drag-down-to-change-selected-text-expected.txt:
+        * fast/events/touch/ios/long-press-on-editable-content-then-drag-down-to-change-selected-text.html:
+        * fast/events/touch/ios/long-press-on-editable-content-then-drag-left-to-change-selected-text-expected.txt:
+        * fast/events/touch/ios/long-press-on-editable-content-then-drag-left-to-change-selected-text.html:
+        * fast/events/touch/ios/long-press-on-editable-content-then-drag-right-to-change-selected-text-expected.txt:
+        * fast/events/touch/ios/long-press-on-editable-content-then-drag-right-to-change-selected-text.html:
+        * fast/events/touch/ios/long-press-on-editable-content-then-drag-up-to-change-selected-text-expected.txt:
+        * fast/events/touch/ios/long-press-on-editable-content-then-drag-up-to-change-selected-text.html:
+        * resources/ui-helper.js:
+        (window.UIHelper.midPointOfRect):
+
 2021-09-07  Ayumi Kojima  <[email protected]>
 
         [ iOS EWS ] imported/w3c/web-platform-tests/html/cross-origin-opener-policy/resource-popup.https.html is flaky.

Modified: trunk/LayoutTests/fast/events/touch/ios/long-press-on-editable-content-then-drag-down-to-change-selected-text-expected.txt (282095 => 282096)


--- trunk/LayoutTests/fast/events/touch/ios/long-press-on-editable-content-then-drag-down-to-change-selected-text-expected.txt	2021-09-07 17:54:59 UTC (rev 282095)
+++ trunk/LayoutTests/fast/events/touch/ios/long-press-on-editable-content-then-drag-down-to-change-selected-text-expected.txt	2021-09-07 18:00:38 UTC (rev 282096)
@@ -1,7 +1,5 @@
-PASS: Correct Selection
-PASS: Correct Selection
-PASS: Correct Selection
-PASS: Correct Selection
-PASS: Correct Selection
-PASS: Correct Selection
+PASS: Has Selection
+PASS: Selection Changed
+PASS: Selection Changed
+PASS: Selection Did Not Change
 

Modified: trunk/LayoutTests/fast/events/touch/ios/long-press-on-editable-content-then-drag-down-to-change-selected-text.html (282095 => 282096)


--- trunk/LayoutTests/fast/events/touch/ios/long-press-on-editable-content-then-drag-down-to-change-selected-text.html	2021-09-07 17:54:59 UTC (rev 282095)
+++ trunk/LayoutTests/fast/events/touch/ios/long-press-on-editable-content-then-drag-down-to-change-selected-text.html	2021-09-07 18:00:38 UTC (rev 282096)
@@ -1,90 +1,78 @@
 <!DOCTYPE html>
-
 <html>
 <head>
     <script src=""
+    <script src=""
     <script>
         if (window.testRunner) {
             testRunner.dumpAsText();
             testRunner.waitUntilDone();
         }
-    
+
         async function runTest()
         {
             if (!testRunner.runUIScript)
                 return;
-        
+
             var output = '';
             var editableTargetRect = document.getElementById('editable').getBoundingClientRect();
-            var firstTargetRect = document.getElementById('firstSelection').getBoundingClientRect();
-            var secondTargetRect = document.getElementById('secondSelection').getBoundingClientRect();
-            var thirdTargetRect = document.getElementById('thirdSelection').getBoundingClientRect();
-            var editableToNoneditableOffset = document.getElementById('noneditable').getBoundingClientRect().y - document.getElementById('editable').getBoundingClientRect().y;
-        
-            var pressPointX = firstTargetRect.x + firstTargetRect.width / 2;
-            var pressPointY = firstTargetRect.y + firstTargetRect.height / 2 - editableToNoneditableOffset;
-            var dragY = firstTargetRect.y + firstTargetRect.height - editableToNoneditableOffset;
-            var dragX = firstTargetRect.x + firstTargetRect.width;
-            var dragY2 = secondTargetRect.y + secondTargetRect.height - editableToNoneditableOffset;
-            var dragY3 = thirdTargetRect.y + thirdTargetRect.height - editableToNoneditableOffset;
-            var dragY4 = firstTargetRect.y - firstTargetRect.height - editableToNoneditableOffset;
 
+            var pressPointX = editableTargetRect.x + editableTargetRect.width / 2;
+            var pressPointY = editableTargetRect.y + editableTargetRect.height / 2;
+            
+            var fontHeight = 30;
+
+            var selectionChangedCount = 0;
+            document.addEventListener("selectionchange", () => {
+                selectionChangedCount++;
+            });
+
             await longPressAtPoint(pressPointX, pressPointY);
-            if (document.getSelection().toString() == "sed")
-                output += 'PASS: Correct Selection';
-            else
-                output += 'FAIL: failed to select a word as a result of a long press. Incorrect Selection: ' + document.getSelection().toString();
-            output += '<br>';
 
-            await touchAndDragFromPointToPoint(dragX, dragY, dragX, dragY2);
-            if (document.getSelection().toString() == "sed do eiusmod tempor incididun")
-                output += 'PASS: Correct Selection';
-            else
-                output += 'FAIL: failed to select additional line after a drag. Incorrect Selection: ' + document.getSelection().toString();
-            output += '<br>';
+            await UIHelper.waitForSelectionToAppear();
 
-            await touchAndDragFromPointToPoint(dragX, dragY2, dragX, dragY3);
-            if (document.getSelection().toString() == "sed do eiusmod tempor incididunt ut labore et dolore ma")
-                output += 'PASS: Correct Selection';
+            if (document.getSelection().toString() != "")
+                output += 'PASS: Has Selection';
             else
-                output += 'FAIL: failed to select additional line after a drag. Incorrect Selection: ' + document.getSelection().toString();
+                output += 'FAIL: failed to select a word as a result of a long press.';
             output += '<br>';
 
-            await touchAndDragFromPointToPoint(dragX, dragY3, dragX, dragY2);
-            if (document.getSelection().toString() == "sed do eiusmod tempor incididun")
-                output += 'PASS: Correct Selection';
+            var grabberMidpoint = UIHelper.midPointOfRect(await UIHelper.getSelectionEndGrabberViewRect());
+
+            await touchAndDragFromPointToPoint(grabberMidpoint.x, grabberMidpoint.y, grabberMidpoint.x, grabberMidpoint.y + (fontHeight * 2));
+
+            if (selectionChangedCount == 2)
+                output += 'PASS: Selection Changed </br>';
             else
-                output += 'FAIL: failed to deselect line after a drag. Incorrect Selection: ' + document.getSelection().toString();
-            output += '<br>';
+                output += 'FAIL: Selection did not change <br>' + selectionChangedCount;
 
-            await touchAndDragFromPointToPoint(dragX, dragY2, dragX, dragY);
-            if (document.getSelection().toString() == "sed")
-                output += 'PASS: Correct Selection';
+            grabberMidpoint = UIHelper.midPointOfRect(await UIHelper.getSelectionEndGrabberViewRect());
+            await touchAndDragFromPointToPoint(grabberMidpoint.x, grabberMidpoint.y, grabberMidpoint.x, grabberMidpoint.y - (fontHeight * 2));
+
+            if (selectionChangedCount == 3)
+                output += 'PASS: Selection Changed </br>';
             else
-                output += 'FAIL: failed to deselect line after a drag. Incorrect Selection: ' + document.getSelection().toString();
-            output += '<br>';
+                output += 'FAIL: Selection did not change <br>' + selectionChangedCount;
 
-            var result = await touchAndDragFromPointToPoint(dragX, dragY, dragX, dragY4);
-            if (document.getSelection().toString() == "s")
-                output += 'PASS: Correct Selection';
+            grabberMidpoint = UIHelper.midPointOfRect(await UIHelper.getSelectionEndGrabberViewRect());
+            await touchAndDragFromPointToPoint(grabberMidpoint.x, grabberMidpoint.y, grabberMidpoint.x, grabberMidpoint.y - (fontHeight * 4));
+
+            if (selectionChangedCount == 3)
+                output += 'PASS: Selection Did Not Change </br>';
             else
-                output += 'FAIL: failed to reduce selection to a single character by dragging up. Incorrect Selection: ' + document.getSelection().toString();
-            output += '<br>';
-            output += result;
+                output += 'FAIL: Selection changed <br>' + selectionChangedCount;
 
-            var noneditableElement = document.getElementById('noneditable');
-            noneditableElement.parentNode.removeChild(noneditableElement);
             var editableElement = document.getElementById('editable');
             editableElement.parentNode.removeChild(editableElement);
             document.getElementById('target').innerHTML = output;
             testRunner.notifyDone();
         }
-    
+
         window.addEventListener('load', runTest, false);
     </script>
     <style>
-        #noneditable {
-            height: 200px;
+        #target {
+            height: 50px;
             width: 300px;
             background-color: silver;
             font-family: monospace;
@@ -91,31 +79,21 @@
             font-size: 18px;
         }
         #editable {
-            height: 200px;
+            height: 300px;
             width: 300px;
             background-color: silver;
             font-family: monospace;
-            font-size: 18px;
+            font-size: 30px;
         }
-        #target {
-            height: 50px;
-            width: 300px;
-            background-color: silver;
-            font-family: monospace;
-            font-size: 18px;
-        }
     </style>
     <meta name="viewport" content="width=device-width, initial-scale=1">
 </head>
 <body>
-    <div id="editable" contenteditable>
-        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
-    </div> 
-    <div id="noneditable">
-        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, <span id="firstSelection">sed</span> do eiusmod tempor incididun<span id="secondSelection"></span>t ut labore et dolore mag<span id="thirdSelection"></span>na aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
-    </div>
     <div id="target">
         This test requires UIScriptController to run.
     </div>
+    <div id="editable" contenteditable>
+        <p>Here's to the crazy ones. The misfits. The rebels. The troublemakers. The round pegs in the square holes.</p>
+    </div>
 </body>
 </html>

Modified: trunk/LayoutTests/fast/events/touch/ios/long-press-on-editable-content-then-drag-left-to-change-selected-text-expected.txt (282095 => 282096)


--- trunk/LayoutTests/fast/events/touch/ios/long-press-on-editable-content-then-drag-left-to-change-selected-text-expected.txt	2021-09-07 17:54:59 UTC (rev 282095)
+++ trunk/LayoutTests/fast/events/touch/ios/long-press-on-editable-content-then-drag-left-to-change-selected-text-expected.txt	2021-09-07 18:00:38 UTC (rev 282096)
@@ -1,7 +1,5 @@
-PASS: Correct Selection
-PASS: Correct Selection
-PASS: Correct Selection
-PASS: Correct Selection
-PASS: Correct Selection
-PASS: Correct Selection
+PASS: Has Selection
+PASS: Selection Changed
+PASS: Selection Changed
+PASS: Selection Changed
 

Modified: trunk/LayoutTests/fast/events/touch/ios/long-press-on-editable-content-then-drag-left-to-change-selected-text.html (282095 => 282096)


--- trunk/LayoutTests/fast/events/touch/ios/long-press-on-editable-content-then-drag-left-to-change-selected-text.html	2021-09-07 17:54:59 UTC (rev 282095)
+++ trunk/LayoutTests/fast/events/touch/ios/long-press-on-editable-content-then-drag-left-to-change-selected-text.html	2021-09-07 18:00:38 UTC (rev 282096)
@@ -1,90 +1,81 @@
 <!DOCTYPE html>
-
 <html>
 <head>
     <script src=""
+    <script src=""
     <script>
         if (window.testRunner) {
             testRunner.dumpAsText();
             testRunner.waitUntilDone();
         }
-    
+
         async function runTest()
         {
             if (!testRunner.runUIScript)
                 return;
-        
+
             var output = '';
             var editableTargetRect = document.getElementById('editable').getBoundingClientRect();
-            var firstTargetRect = document.getElementById('firstSelection').getBoundingClientRect();
-            var secondTargetRect = document.getElementById('secondSelection').getBoundingClientRect();
-            var thirdTargetRect = document.getElementById('thirdSelection').getBoundingClientRect();
-            var editableToNoneditableOffset = document.getElementById('noneditable').getBoundingClientRect().y - document.getElementById('editable').getBoundingClientRect().y;
-        
-            var pressPointX = firstTargetRect.x + firstTargetRect.width / 2;
-            var pressPointY = firstTargetRect.y + firstTargetRect.height / 2 - editableToNoneditableOffset;
-            var dragY = firstTargetRect.y - editableToNoneditableOffset;
-            var dragX = firstTargetRect.x;
-            var dragX2 = secondTargetRect.x;
-            var dragX3 = thirdTargetRect.x;
-            var dragX4 = firstTargetRect.x + firstTargetRect.width;
 
+            var pressPointX = editableTargetRect.x + editableTargetRect.width / 2;
+            var pressPointY = editableTargetRect.y + editableTargetRect.height * .65;
+            
+            var dragDistance = 60;
+
+            var selectionChangedCount = 0;
+            var lastSelectionChangeCount;
+            document.addEventListener("selectionchange", () => {
+                selectionChangedCount++;
+            });
+
             await longPressAtPoint(pressPointX, pressPointY);
-            if (document.getSelection().toString() == "aliqua")
-                output += 'PASS: Correct Selection';
-            else
-                output += 'FAIL: failed to select a word as a result of a long press. Incorrect Selection: ' + document.getSelection().toString();
-            output += '<br>';
 
-            await touchAndDragFromPointToPoint(dragX, dragY, dragX2, dragY);
-            if (document.getSelection().toString() == "magna aliqua")
-                output += 'PASS: Correct Selection';
-            else
-                output += 'FAIL: failed to select additional word after a drag. Incorrect Selection: ' + document.getSelection().toString();
-            output += '<br>';
+            await UIHelper.waitForSelectionToAppear();
 
-            await touchAndDragFromPointToPoint(dragX2, dragY, dragX3, dragY);
-            if (document.getSelection().toString() == "dolore magna aliqua")
-                output += 'PASS: Correct Selection';
+            if (document.getSelection().toString() != "")
+                output += 'PASS: Has Selection';
             else
-                output += 'FAIL: failed to select additional word after a drag. Incorrect Selection: ' + document.getSelection().toString();
+                output += 'FAIL: failed to select a word as a result of a long press.';
             output += '<br>';
 
-            await touchAndDragFromPointToPoint(dragX3, dragY, dragX2, dragY);
-            if (document.getSelection().toString() == "magna aliqua")
-                output += 'PASS: Correct Selection';
+            var grabberMidpoint = UIHelper.midPointOfRect(await UIHelper.getSelectionStartGrabberViewRect());
+
+            await touchAndDragFromPointToPoint(grabberMidpoint.x, grabberMidpoint.y, grabberMidpoint.x - dragDistance, grabberMidpoint.y);
+
+            if (selectionChangedCount >= 2)
+                output += 'PASS: Selection Changed </br>';
             else
-                output += 'FAIL: failed to deselect word after a drag. Incorrect Selection: ' + document.getSelection().toString();
-            output += '<br>';
+                output += 'FAIL: Selection did not change <br>' + selectionChangedCount;
+            lastSelectionChangeCount = selectionChangedCount;
 
-            await touchAndDragFromPointToPoint(dragX2, dragY, dragX, dragY);
-            if (document.getSelection().toString() == "aliqua")
-                 output += 'PASS: Correct Selection';
+            grabberMidpoint = UIHelper.midPointOfRect(await UIHelper.getSelectionStartGrabberViewRect());
+            await touchAndDragFromPointToPoint(grabberMidpoint.x, grabberMidpoint.y, grabberMidpoint.x + dragDistance, grabberMidpoint.y);
+
+            if (selectionChangedCount >= lastSelectionChangeCount + 1)
+                output += 'PASS: Selection Changed </br>';
             else
-                output += 'FAIL: failed to deselect word after a drag. Incorrect Selection: ' + document.getSelection().toString();
-            output += '<br>';
+                output += 'FAIL: Selection did not change <br>' + selectionChangedCount;
+            lastSelectionChangeCount = selectionChangedCount;
 
-            var result = await touchAndDragFromPointToPoint(dragX, dragY, dragX4, dragY);
-            if (document.getSelection().toString() == "a")
-                output += 'PASS: Correct Selection';
+            grabberMidpoint = UIHelper.midPointOfRect(await UIHelper.getSelectionStartGrabberViewRect());
+            await touchAndDragFromPointToPoint(grabberMidpoint.x, grabberMidpoint.y, grabberMidpoint.x + dragDistance, grabberMidpoint.y);
+
+            if (selectionChangedCount >= lastSelectionChangeCount + 1)
+                output += 'PASS: Selection Changed </br>';
             else
-                output += 'FAIL: failed to reduce selection to a single character by dragging right. Incorrect Selection: ' + document.getSelection().toString();
-            output += '<br>';
-            output += result;
+                output += 'FAIL: Selection changed <br>' + selectionChangedCount;
 
-            var noneditableElement = document.getElementById('noneditable');
-            noneditableElement.parentNode.removeChild(noneditableElement);
             var editableElement = document.getElementById('editable');
             editableElement.parentNode.removeChild(editableElement);
             document.getElementById('target').innerHTML = output;
             testRunner.notifyDone();
         }
-    
+
         window.addEventListener('load', runTest, false);
     </script>
     <style>
-        #noneditable {
-            height: 200px;
+        #target {
+            height: 50px;
             width: 300px;
             background-color: silver;
             font-family: monospace;
@@ -91,31 +82,21 @@
             font-size: 18px;
         }
         #editable {
-            height: 200px;
+            height: 300px;
             width: 300px;
             background-color: silver;
             font-family: monospace;
-            font-size: 18px;
+            font-size: 30px;
         }
-        #target {
-            height: 50px;
-            width: 300px;
-            background-color: silver;
-            font-family: monospace;
-            font-size: 18px;
-        }
     </style>
     <meta name="viewport" content="width=device-width, initial-scale=1">
 </head>
 <body>
-    <div id="editable" contenteditable>
-        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
-    </div>   
-    <div id="noneditable">
-        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et <span id="thirdSelection"></span>dolore <span id="secondSelection"></span>magna <span id="firstSelection">aliqua</span>. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
-    </div>
     <div id="target">
         This test requires UIScriptController to run.
     </div>
+    <div id="editable" contenteditable>
+        <p>Here's to the crazy ones. The misfits. The rebels. The trouble makers. The round pegs in the square holes.</p>
+    </div>
 </body>
 </html>

Modified: trunk/LayoutTests/fast/events/touch/ios/long-press-on-editable-content-then-drag-right-to-change-selected-text-expected.txt (282095 => 282096)


--- trunk/LayoutTests/fast/events/touch/ios/long-press-on-editable-content-then-drag-right-to-change-selected-text-expected.txt	2021-09-07 17:54:59 UTC (rev 282095)
+++ trunk/LayoutTests/fast/events/touch/ios/long-press-on-editable-content-then-drag-right-to-change-selected-text-expected.txt	2021-09-07 18:00:38 UTC (rev 282096)
@@ -1,7 +1,5 @@
-PASS: Correct Selection
-PASS: Correct Selection
-PASS: Correct Selection
-PASS: Correct Selection
-PASS: Correct Selection
-PASS: Correct Selection
+PASS: Has Selection
+PASS: Selection Changed
+PASS: Selection Changed
+PASS: Selection Changed
 

Modified: trunk/LayoutTests/fast/events/touch/ios/long-press-on-editable-content-then-drag-right-to-change-selected-text.html (282095 => 282096)


--- trunk/LayoutTests/fast/events/touch/ios/long-press-on-editable-content-then-drag-right-to-change-selected-text.html	2021-09-07 17:54:59 UTC (rev 282095)
+++ trunk/LayoutTests/fast/events/touch/ios/long-press-on-editable-content-then-drag-right-to-change-selected-text.html	2021-09-07 18:00:38 UTC (rev 282096)
@@ -1,14 +1,14 @@
 <!DOCTYPE html>
-
 <html>
 <head>
     <script src=""
+    <script src=""
     <script>
         if (window.testRunner) {
             testRunner.dumpAsText();
             testRunner.waitUntilDone();
         }
-    
+
         async function runTest()
         {
             if (!testRunner.runUIScript)
@@ -16,64 +16,55 @@
 
             var output = '';
             var editableTargetRect = document.getElementById('editable').getBoundingClientRect();
-            var firstTargetRect = document.getElementById('firstSelection').getBoundingClientRect();
-            var secondTargetRect = document.getElementById('secondSelection').getBoundingClientRect();
-            var thirdTargetRect = document.getElementById('thirdSelection').getBoundingClientRect();
-            var editableToNoneditableOffset = document.getElementById('noneditable').getBoundingClientRect().y - document.getElementById('editable').getBoundingClientRect().y;
 
-            var pressPointX = firstTargetRect.x + firstTargetRect.width / 2;
-            var pressPointY = firstTargetRect.y + firstTargetRect.height / 2 - editableToNoneditableOffset;
-            var dragY = firstTargetRect.y + firstTargetRect.height - editableToNoneditableOffset;
-            var dragX = firstTargetRect.x + firstTargetRect.width;
-            var dragX2 = secondTargetRect.x;
-            var dragX3 = thirdTargetRect.x;
-            var dragX4 = firstTargetRect.x - firstTargetRect.width;
-        
+            var pressPointX = editableTargetRect.x + editableTargetRect.width / 2;
+            var pressPointY = editableTargetRect.y + editableTargetRect.height * .65;
+            
+            var dragDistance = 60;
+
+            var selectionChangedCount = 0;
+            var lastSelectionChangeCount;
+            document.addEventListener("selectionchange", () => {
+                selectionChangedCount++;
+            });
+
             await longPressAtPoint(pressPointX, pressPointY);
-            if (document.getSelection().toString() == "magna")
-                output += 'PASS: Correct Selection';
-            else
-                output += 'FAIL: failed to select a word as a result of a long press. Incorrect Selection: ' + document.getSelection().toString();
-            output += '<br>';
 
-            await touchAndDragFromPointToPoint(dragX, dragY, dragX2, dragY);
-            if (document.getSelection().toString() == "magna aliqua.")
-                output += 'PASS: Correct Selection';
-            else
-                output += 'FAIL: failed to select additional word after a drag. Incorrect Selection: ' + document.getSelection().toString();
-            output += '<br>';
+            await UIHelper.waitForSelectionToAppear();
 
-            await touchAndDragFromPointToPoint(dragX2, dragY, dragX3, dragY);
-            if (document.getSelection().toString() == "magna aliqua. Ut")
-                output += 'PASS: Correct Selection';
+            if (document.getSelection().toString() != "")
+                output += 'PASS: Has Selection';
             else
-                output += 'FAIL: failed to select additional word after a drag. Incorrect Selection: ' + document.getSelection().toString();
+                output += 'FAIL: failed to select a word as a result of a long press.';
             output += '<br>';
 
-            await touchAndDragFromPointToPoint(dragX3, dragY, dragX2, dragY);
-            if (document.getSelection().toString() == "magna aliqua.")
-                output += 'PASS: Correct Selection';
+            var grabberMidpoint = UIHelper.midPointOfRect(await UIHelper.getSelectionEndGrabberViewRect());
+
+            await touchAndDragFromPointToPoint(grabberMidpoint.x, grabberMidpoint.y, grabberMidpoint.x + dragDistance, grabberMidpoint.y);
+
+            if (selectionChangedCount >= 2)
+                output += 'PASS: Selection Changed </br>';
             else
-                output += 'FAIL: failed to deselect word after a drag. Incorrect Selection: ' + document.getSelection().toString();
-            output += '<br>';
+                output += 'FAIL: Selection did not change <br>' + selectionChangedCount;
+            lastSelectionChangeCount = selectionChangedCount;
 
-            await touchAndDragFromPointToPoint(dragX2, dragY, dragX, dragY);
-            if (document.getSelection().toString() == "magna")
-                output += 'PASS: Correct Selection';
+            grabberMidpoint = UIHelper.midPointOfRect(await UIHelper.getSelectionEndGrabberViewRect());
+            await touchAndDragFromPointToPoint(grabberMidpoint.x, grabberMidpoint.y, grabberMidpoint.x - dragDistance, grabberMidpoint.y);
+
+            if (selectionChangedCount >= lastSelectionChangeCount + 1)
+                output += 'PASS: Selection Changed </br>';
             else
-                output += 'FAIL: failed to deselect word after a drag. Incorrect Selection: ' + document.getSelection().toString();
-            output += '<br>';
+                output += 'FAIL: Selection did not change <br>' + selectionChangedCount;
+            lastSelectionChangeCount = selectionChangedCount;
 
-            var result = await touchAndDragFromPointToPoint(dragX, dragY, dragX4, dragY);
-            if (document.getSelection().toString() == "m")
-                output += 'PASS: Correct Selection';
+            grabberMidpoint = UIHelper.midPointOfRect(await UIHelper.getSelectionEndGrabberViewRect());
+            await touchAndDragFromPointToPoint(grabberMidpoint.x, grabberMidpoint.y, grabberMidpoint.x - dragDistance, grabberMidpoint.y);
+
+            if (selectionChangedCount >= lastSelectionChangeCount + 1)
+                output += 'PASS: Selection Changed </br>';
             else
-                output += 'FAIL: failed to reduce selection to a single character by dragging left. Incorrect Selection: ' + document.getSelection().toString();
-            output += '<br>';
-            output += result;
+                output += 'FAIL: Selection changed <br>' + selectionChangedCount;
 
-            var noneditableElement = document.getElementById('noneditable');
-            noneditableElement.parentNode.removeChild(noneditableElement);
             var editableElement = document.getElementById('editable');
             editableElement.parentNode.removeChild(editableElement);
             document.getElementById('target').innerHTML = output;
@@ -82,9 +73,9 @@
 
         window.addEventListener('load', runTest, false);
     </script>
-        <style>
-        #noneditable {
-            height: 200px;
+    <style>
+        #target {
+            height: 50px;
             width: 300px;
             background-color: silver;
             font-family: monospace;
@@ -91,31 +82,21 @@
             font-size: 18px;
         }
         #editable {
-            height: 200px;
+            height: 300px;
             width: 300px;
             background-color: silver;
             font-family: monospace;
-            font-size: 18px;
+            font-size: 30px;
         }
-        #target {
-            height: 50px;
-            width: 300px;
-            background-color: silver;
-            font-family: monospace;
-            font-size: 18px;
-        }
     </style>
     <meta name="viewport" content="width=device-width, initial-scale=1">
 </head>
 <body>
-    <div id="editable" contenteditable>
-        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
-    </div> 
-    <div id="noneditable">
-        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore <span id="firstSelection">magna</span> aliqua.<span id="secondSelection"></span> Ut<span id="thirdSelection"></span> enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
-    </div>
     <div id="target">
         This test requires UIScriptController to run.
     </div>
+    <div id="editable" contenteditable>
+        <p>Here's to the crazy ones. The misfits. The rebels. The trouble makers. The round pegs in the square holes.</p>
+    </div>
 </body>
 </html>

Modified: trunk/LayoutTests/fast/events/touch/ios/long-press-on-editable-content-then-drag-up-to-change-selected-text-expected.txt (282095 => 282096)


--- trunk/LayoutTests/fast/events/touch/ios/long-press-on-editable-content-then-drag-up-to-change-selected-text-expected.txt	2021-09-07 17:54:59 UTC (rev 282095)
+++ trunk/LayoutTests/fast/events/touch/ios/long-press-on-editable-content-then-drag-up-to-change-selected-text-expected.txt	2021-09-07 18:00:38 UTC (rev 282096)
@@ -1,7 +1,5 @@
-PASS: Correct Selection
-PASS: Correct Selection
-PASS: Correct Selection
-PASS: Correct Selection
-PASS: Correct Selection
-PASS: Correct Selection
+PASS: Has Selection
+PASS: Selection Changed
+PASS: Selection Changed
+PASS: Selection Did Not Change
 

Modified: trunk/LayoutTests/fast/events/touch/ios/long-press-on-editable-content-then-drag-up-to-change-selected-text.html (282095 => 282096)


--- trunk/LayoutTests/fast/events/touch/ios/long-press-on-editable-content-then-drag-up-to-change-selected-text.html	2021-09-07 17:54:59 UTC (rev 282095)
+++ trunk/LayoutTests/fast/events/touch/ios/long-press-on-editable-content-then-drag-up-to-change-selected-text.html	2021-09-07 18:00:38 UTC (rev 282096)
@@ -1,14 +1,14 @@
 <!DOCTYPE html>
-
 <html>
 <head>
     <script src=""
+    <script src=""
     <script>
         if (window.testRunner) {
             testRunner.dumpAsText();
             testRunner.waitUntilDone();
         }
-    
+
         async function runTest()
         {
             if (!testRunner.runUIScript)
@@ -16,64 +16,52 @@
 
             var output = '';
             var editableTargetRect = document.getElementById('editable').getBoundingClientRect();
-            var firstTargetRect = document.getElementById('firstSelection').getBoundingClientRect();
-            var secondTargetRect = document.getElementById('secondSelection').getBoundingClientRect();
-            var thirdTargetRect = document.getElementById('thirdSelection').getBoundingClientRect();
-            var editableToNoneditableOffset = document.getElementById('noneditable').getBoundingClientRect().y - document.getElementById('editable').getBoundingClientRect().y;
-        
-            var pressPointX = firstTargetRect.x + firstTargetRect.width / 2;
-            var pressPointY = firstTargetRect.y + firstTargetRect.height / 2 - editableToNoneditableOffset;
-            var dragY = firstTargetRect.y - editableToNoneditableOffset;
-            var dragX = firstTargetRect.x;
-            var dragY2 = secondTargetRect.y - editableToNoneditableOffset;
-            var dragY3 = thirdTargetRect.y - editableToNoneditableOffset;
-            var dragY4 = firstTargetRect.y + firstTargetRect.height - editableToNoneditableOffset;
-        
+
+            var pressPointX = editableTargetRect.x + editableTargetRect.width / 2;
+            var pressPointY = editableTargetRect.y + editableTargetRect.height * .65;
+            
+            var fontHeight = 30;
+
+            var selectionChangedCount = 0;
+            document.addEventListener("selectionchange", () => {
+                selectionChangedCount++;
+            });
+
             await longPressAtPoint(pressPointX, pressPointY);
-            if (document.getSelection().toString() == "ut")
-                output += 'PASS: Correct Selection';
-            else
-                output += 'FAIL: failed to select a word as a result of a long press. Incorrect Selection: ' + document.getSelection().toString();
-            output += '<br>';
 
-            await touchAndDragFromPointToPoint(dragX, dragY, dragX, dragY2);
-            if (document.getSelection().toString() == "o eiusmod tempor incididunt ut")
-                output += 'PASS: Correct Selection';
-            else
-                output += 'FAIL: failed to select additional line after a drag. Incorrect Selection: ' + document.getSelection().toString();
-            output += '<br>';
+            await UIHelper.waitForSelectionToAppear();
 
-            await touchAndDragFromPointToPoint(dragX, dragY2, dragX, dragY3);
-            if (document.getSelection().toString() == " adipiscing elit, sed do eiusmod tempor incididunt ut")
-                output += 'PASS: Correct Selection';
+            if (document.getSelection().toString() != "")
+                output += 'PASS: Has Selection';
             else
-                output += 'FAIL: failed to select additional line after a drag. Incorrect Selection: ' + document.getSelection().toString();
+                output += 'FAIL: failed to select a word as a result of a long press.';
             output += '<br>';
 
-            await touchAndDragFromPointToPoint(dragX, dragY3, dragX, dragY2);
-            if (document.getSelection().toString() == "o eiusmod tempor incididunt ut")
-                output += 'PASS: Correct Selection';
+            var grabberMidpoint = UIHelper.midPointOfRect(await UIHelper.getSelectionStartGrabberViewRect());
+            await touchAndDragFromPointToPoint(grabberMidpoint.x, grabberMidpoint.y , grabberMidpoint.x, grabberMidpoint.y - (fontHeight * 2));
+
+            if (selectionChangedCount == 3)
+                output += 'PASS: Selection Changed </br>';
             else
-                output += 'FAIL: failed to deselect line after a drag. Incorrect Selection: ' + document.getSelection().toString();
-            output += '<br>';
+                output += 'FAIL: Selection did not change <br>' + selectionChangedCount;
 
-            await touchAndDragFromPointToPoint(dragX, dragY2, dragX, dragY);
-            if (document.getSelection().toString() == "ut")
-                output += 'PASS: Correct Selection';
+            grabberMidpoint = UIHelper.midPointOfRect(await UIHelper.getSelectionStartGrabberViewRect());
+            await touchAndDragFromPointToPoint(grabberMidpoint.x, grabberMidpoint.y , grabberMidpoint.x, grabberMidpoint.y + (fontHeight * 3));
+            await liftUpAtPoint(grabberMidpoint.x, grabberMidpoint.y - (fontHeight * 3));
+
+            if (selectionChangedCount == 5)
+                output += 'PASS: Selection Changed </br>';
             else
-                output += 'FAIL: failed to deselect line after a drag. Incorrect Selection: ' + document.getSelection().toString();
-            output += '<br>';
+                output += 'FAIL: Selection did not change <br>' + selectionChangedCount;
+            
+            grabberMidpoint = UIHelper.midPointOfRect(await UIHelper.getSelectionStartGrabberViewRect());
+            await touchAndDragFromPointToPoint(grabberMidpoint.x, grabberMidpoint.y , grabberMidpoint.x, grabberMidpoint.y + (fontHeight * 2));
 
-            var result = await touchAndDragFromPointToPoint(dragX, dragY, dragX, dragY4);
-            if (document.getSelection().toString() == "ut")
-                output += 'PASS: Correct Selection';
+            if (selectionChangedCount == 5)
+                output += 'PASS: Selection Did Not Change </br>';
             else
-                output += 'FAIL: failed to reduce selection to a single character by dragging down. Incorrect Selection: ' + document.getSelection().toString();
-            output += '<br>';
-            output += result;
+                output += 'FAIL: Selection changed <br>' + selectionChangedCount;
 
-            var noneditableElement = document.getElementById('noneditable');
-            noneditableElement.parentNode.removeChild(noneditableElement);
             var editableElement = document.getElementById('editable');
             editableElement.parentNode.removeChild(editableElement);
             document.getElementById('target').innerHTML = output;
@@ -83,8 +71,8 @@
         window.addEventListener('load', runTest, false);
     </script>
     <style>
-        #noneditable {
-            height: 200px;
+        #target {
+            height: 50px;
             width: 300px;
             background-color: silver;
             font-family: monospace;
@@ -91,31 +79,21 @@
             font-size: 18px;
         }
         #editable {
-            height: 200px;
+            height: 300px;
             width: 300px;
             background-color: silver;
             font-family: monospace;
-            font-size: 18px;
+            font-size: 30px;
         }
-        #target {
-            height: 50px;
-            width: 300px;
-            background-color: silver;
-            font-family: monospace;
-            font-size: 18px;
-        }
     </style>
-    <meta name="viewport" content="initial-scale=1">
+    <meta name="viewport" content="width=device-width, initial-scale=1">
 </head>
 <body>
-    <div id="editable" contenteditable>
-        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
-    </div> 
-    <div id="noneditable">
-        <p>Lorem ipsum dolor sit amet, consectetur<span id="thirdSelection"></span> adipiscing elit, sed d<span id="secondSelection"></span>o eiusmod tempor incididunt <span id="firstSelection">ut</span> labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
-    </div>
     <div id="target">
         This test requires UIScriptController to run.
     </div>
+    <div id="editable" contenteditable>
+        <p>Here's to the crazy ones. The misfits. The rebels. The trouble makers. The round pegs in the square holes.</p>
+    </div>
 </body>
 </html>

Modified: trunk/LayoutTests/resources/ui-helper.js (282095 => 282096)


--- trunk/LayoutTests/resources/ui-helper.js	2021-09-07 17:54:59 UTC (rev 282095)
+++ trunk/LayoutTests/resources/ui-helper.js	2021-09-07 18:00:38 UTC (rev 282096)
@@ -819,6 +819,10 @@
         });
     }
 
+    static midPointOfRect(rect) {
+        return { x: rect.left + (rect.width / 2), y: rect.top + (rect.height / 2) };
+    }
+
     static selectionCaretBackgroundColor()
     {
         return new Promise(resolve => {

Modified: trunk/Tools/ChangeLog (282095 => 282096)


--- trunk/Tools/ChangeLog	2021-09-07 17:54:59 UTC (rev 282095)
+++ trunk/Tools/ChangeLog	2021-09-07 18:00:38 UTC (rev 282096)
@@ -1,3 +1,16 @@
+2021-09-07  Megan Gardner  <[email protected]>
+
+        Rewrite long press and drag tests to be more robust.
+        https://bugs.webkit.org/show_bug.cgi?id=229779
+        rdar://40917203
+
+        Reviewed by Wenson Hsieh.
+
+        Found a crash when bad data was entered for gesture emulation.
+
+        * WebKitTestRunner/ios/UIScriptControllerIOS.mm:
+        (WTR::convertCoordinates):
+
 2021-09-07  Jonathan Bedard  <[email protected]>
 
         Exception in run-webkit-tests: Bad file descriptor (Part 1)

Modified: trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm (282095 => 282096)


--- trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm	2021-09-07 17:54:59 UTC (rev 282095)
+++ trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm	2021-09-07 18:00:38 UTC (rev 282096)
@@ -404,7 +404,10 @@
 {
     if (event[HIDEventTouchesKey]) {
         for (NSMutableDictionary *touch in event[HIDEventTouchesKey]) {
-            auto location = globalToContentCoordinates(webView, (long)[touch[HIDEventXKey] doubleValue], (long)[touch[HIDEventYKey]doubleValue]);
+            NSNumber *touchX = touch[HIDEventXKey] == [NSNull null] ? nil : touch[HIDEventXKey];
+            NSNumber *touchY = touch[HIDEventYKey] == [NSNull null] ? nil : touch[HIDEventYKey];
+            
+            auto location = globalToContentCoordinates(webView, (long)[touchX doubleValue], (long)[touchY doubleValue]);
             touch[HIDEventXKey] = @(location.x);
             touch[HIDEventYKey] = @(location.y);
         }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to