Fix race-condition in fast/forms/ios/ipad/select-form-run-twice.html
authormegan_gardner@apple.com <megan_gardner@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 2 Feb 2018 02:13:40 +0000 (02:13 +0000)
committermegan_gardner@apple.com <megan_gardner@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 2 Feb 2018 02:13:40 +0000 (02:13 +0000)
https://bugs.webkit.org/show_bug.cgi?id=182370

Reviewed by Tim Horton.

There is the potential for multiple button clicks, due to looping function calls that can cause timed functions to
still be running in the next test, causing crashes. Guarding against repeated clicks, and cancelling the timers should
clean up this problem.

* fast/forms/ios/ipad/select-form-run-twice.html:
* fast/forms/ios/ipad/unfocus-inside-fixed-hittest.html:

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

LayoutTests/ChangeLog
LayoutTests/fast/forms/ios/ipad/select-form-run-twice.html
LayoutTests/fast/forms/ios/ipad/unfocus-inside-fixed-hittest.html

index ddf789eb1f5ceaa1575adfba7c16a5ece700619b..b0afa2627b5b3d5e957a1c1845f235678a25f910 100644 (file)
@@ -1,3 +1,17 @@
+2018-02-01  Megan Gardner  <megan_gardner@apple.com>
+
+        Fix race-condition in fast/forms/ios/ipad/select-form-run-twice.html
+        https://bugs.webkit.org/show_bug.cgi?id=182370
+
+        Reviewed by Tim Horton.
+        
+        There is the potential for multiple button clicks, due to looping function calls that can cause timed functions to 
+        still be running in the next test, causing crashes. Guarding against repeated clicks, and cancelling the timers should 
+        clean up this problem.
+
+        * fast/forms/ios/ipad/select-form-run-twice.html:
+        * fast/forms/ios/ipad/unfocus-inside-fixed-hittest.html:
+
 2018-02-01  Matt Lewis  <jlewis3@apple.com>
 
         Skipped http/tests/resourceLoadStatistics/non-prevalent-resource-with-user-interaction.html on macOS WK2.
index ea1c1526125df15b86c96822c1c287344fb08667..b3054732311a4047e549ab4f0bcb7ed96a84d7eb 100644 (file)
                 })();`
         }
 
+        var firstButtonIsClicked = false;
+        var finalButtonIsClicked = false;
+        var firstButtonTimeoutID;
+        var finalButtonTimeoutID;
+        
         function firstButtonClicked()
         {
-            document.getElementById('nextStep').textContent = 'PASS: hit testing found #nextButton after first select interaction';
-            var selectElement = document.getElementsByTagName('select')[0];
-            var point = getPointInsideElement(selectElement, 10, 10);
-            testRunner.runUIScript(getTapOnSelectUIScript(point.x, point.y, 5), function() {
-                document.getElementById('select-value2').textContent = selectElement.value;
-                    tryTapOnButton('finalTarget');
-            });
+            clearTimeout(firstButtonTimeoutID);
+            if (!firstButtonIsClicked) {
+                firstButtonIsClicked = true;
+                
+                document.getElementById('nextStep').textContent = 'PASS: hit testing found #nextButton after first select interaction';
+                var selectElement = document.getElementsByTagName('select')[0];
+                var point = getPointInsideElement(selectElement, 10, 10);
+                testRunner.runUIScript(getTapOnSelectUIScript(point.x, point.y, 5), function() {
+                    document.getElementById('select-value2').textContent = selectElement.value;
+                        tryTapOnFinalButton();
+                });
+            }
         }
     
         function finalButtonClicked()
         {
-            document.getElementById('result').textContent = 'PASS: hit testing found #finalTarget after select interaction';
-            if (window.testRunner)
-                testRunner.notifyDone();
+            clearTimeout(finalButtonTimeoutID);
+            if (!finalButtonIsClicked) {
+                finalButtonIsClicked = true;
+                document.getElementById('result').textContent = 'PASS: hit testing found #finalTarget after select interaction';
+                if (window.testRunner)
+                    testRunner.notifyDone();
+            }
         }
 
-        async function tryTapOnButton(target)
+        async function tryTapOnFirstButton()
+        {
+            var firstPoint = getPointInsideElement(document.getElementById('firstTarget'), 10, 10);
+            await tapAtPoint(firstPoint.x, firstPoint.y);
+            
+            // We have to keep retrying, because the dimming view behind the popover animates out,
+            // and we currently have no callback when that animation completes.
+            if (!firstButtonIsClicked)
+                firstButtonTimeoutID = window.setTimeout(tryTapOnFirstButton, 100);
+        }
+    
+        async function tryTapOnFinalButton()
         {
-            var point = getPointInsideElement(document.getElementById(target), 10, 10);
-            await tapAtPoint(point.x, point.y);
+            var finalPoint = getPointInsideElement(document.getElementById('finalTarget'), 10, 10);
+            await tapAtPoint(finalPoint.x, finalPoint.y);
             
             // We have to keep retrying, because the dimming view behind the popover animates out,
             // and we currently have no callback when that animation completes.
-            window.setTimeout(tryTapOnButton.bind(this, target), 100);
+            if (!finalButtonIsClicked)
+                finalButtonTimeoutID = window.setTimeout(tryTapOnFinalButton, 100);
         }
+    
 
         function doTest()
         {
                 var point = getPointInsideElement(selectElement, 10, 10);
                 testRunner.runUIScript(getTapOnSelectUIScript(point.x, point.y, 2), function() {
                     document.getElementById('select-value').textContent = selectElement.value;
-                    tryTapOnButton('firstTarget');
+                    tryTapOnFirstButton();
                 });
             });
         }
index 86b240564f5461865968b40bc69b428542f971cc..96afc9a2dc1459b14c36533d9bc300b6c36b27b4 100644 (file)
         
     </style>
     <script src="../resources/zooming-test-utils.js"></script>
+    <script src="../../../../resources/basic-gestures.js"></script>
     <script>
         if (window.testRunner)
             testRunner.waitUntilDone();
 
-        function getSingleTapUIScript(x, y)
-        {
-            return `
-                (function() {
-                    uiController.singleTapAtPoint(${x}, ${y}, function() {
-                        uiController.uiScriptComplete('');
-                    });
-                })();`
-        }
-
         function getScrollDownUIScript(x, y)
         {
             return `
         }
 
         var clicked = false;
+        var timeoutID;
         function buttonClicked()
         {
-            document.getElementById('result').textContent = 'PASS: hit testing found #target after select interaction';
-            if (window.testRunner)
-                testRunner.notifyDone();
+            window.clearTimeout(timeoutID);
+            if (!clicked) {
+                clicked = true;
+                document.getElementById('result').textContent = 'PASS: hit testing found #target after select interaction';
+                if (window.testRunner)
+                    testRunner.notifyDone();
+            }
         }
 
-        function tryTapOnButton()
+        async function tryTapOnButton()
         {
             var point = getPointInsideElement(document.getElementById('target'), 10, 10);
-            testRunner.runUIScript(getSingleTapUIScript(point.x, point.y), function() {
-            });
-            
+            await tapAtPoint(point.x, point.y);
+
             // We have to keep retrying, because the dimming view behind the popover animates out,
             // and we currently have no callback when that animation completes.
-            window.setTimeout(tryTapOnButton, 100);
+            if (!clicked)
+                timeoutID = window.setTimeout(tryTapOnButton, 100);
         }
 
         function doTest()
         {
             if (!window.testRunner)
                 return;
-
             testRunner.waitUntilDone();
             testRunner.dumpAsText();
 
         }
         
         window.addEventListener('load', doTest, false);
+        
     </script>
 </head>
 <body>