Title: [264206] trunk
Revision
264206
Author
[email protected]
Date
2020-07-09 18:27:19 -0700 (Thu, 09 Jul 2020)

Log Message

Make accessibility/Mac/selected-visible-position-range.html time-deterministic.
https://bugs.webkit.org/show_bug.cgi?id=214154

Reviewed by Chris Fleizach.

Tools:

* WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm:
(WTR::AccessibilityUIElement::setSelectedVisibleTextRange):
Check passed parameter for null.

(WTR::AccessibilityUIElement::selectedTextMarkerRange):
Use attributeValue to run on secondary AX thread.

LayoutTests:

[WebAccessibilityObjectWrapper accessibilitySetValue] sets the selection
range and other properties asynchronously by dispatching the call to
another cycle of the run loop using callOnMainThread. thus for the JS to
retrieve the new value, it is necessary to wait until the value is
updated. this is even more so in isolated tree mode where all wrapper
calls come on the secondary AX thread. JS setTimeout doesn't help with
synchronizing these calls, so instead we are using Promises in the
function waitFor in accessibility-helper.js (thanks to Geoff Garen for
showing the way).

* accessibility/mac/selected-visible-position-range-expected.txt:
* accessibility/mac/selected-visible-position-range.html:

MOved waitFor(condition) to the accessibility-helper.js file to be used
in multiple tests.
* accessibility/textarea-selected-text-range.html:
* resources/accessibility-helper.js:
(waitFor):

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (264205 => 264206)


--- trunk/LayoutTests/ChangeLog	2020-07-10 00:07:02 UTC (rev 264205)
+++ trunk/LayoutTests/ChangeLog	2020-07-10 01:27:19 UTC (rev 264206)
@@ -1,3 +1,29 @@
+2020-07-09  Andres Gonzalez  <[email protected]>
+
+        Make accessibility/Mac/selected-visible-position-range.html time-deterministic.
+        https://bugs.webkit.org/show_bug.cgi?id=214154
+
+        Reviewed by Chris Fleizach.
+
+        [WebAccessibilityObjectWrapper accessibilitySetValue] sets the selection
+        range and other properties asynchronously by dispatching the call to
+        another cycle of the run loop using callOnMainThread. thus for the JS to
+        retrieve the new value, it is necessary to wait until the value is
+        updated. this is even more so in isolated tree mode where all wrapper
+        calls come on the secondary AX thread. JS setTimeout doesn't help with
+        synchronizing these calls, so instead we are using Promises in the
+        function waitFor in accessibility-helper.js (thanks to Geoff Garen for
+        showing the way).
+
+        * accessibility/mac/selected-visible-position-range-expected.txt:
+        * accessibility/mac/selected-visible-position-range.html:
+
+        MOved waitFor(condition) to the accessibility-helper.js file to be used
+        in multiple tests.
+        * accessibility/textarea-selected-text-range.html:
+        * resources/accessibility-helper.js:
+        (waitFor):
+
 2020-07-09  Simon Fraser  <[email protected]>
 
         [macOS] Stuttery scrolling on tesla.com

Modified: trunk/LayoutTests/accessibility/mac/selected-visible-position-range-expected.txt (264205 => 264206)


--- trunk/LayoutTests/accessibility/mac/selected-visible-position-range-expected.txt	2020-07-10 00:07:02 UTC (rev 264205)
+++ trunk/LayoutTests/accessibility/mac/selected-visible-position-range-expected.txt	2020-07-10 01:27:19 UTC (rev 264206)
@@ -7,12 +7,12 @@
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
 
-PASS selectedString is 'Last paragraph.'
-selectedString must be the text of the first paragraph: First paragraph.
+PASS current selection is 'Last paragraph.'
+PASS current selection is 'First paragraph.
 
-
-selectedString must be an empty string: 
-selectedString must be an empty string: 
+'
+PASS current selection is ''
+PASS current selection is ''
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/accessibility/mac/selected-visible-position-range.html (264205 => 264206)


--- trunk/LayoutTests/accessibility/mac/selected-visible-position-range.html	2020-07-10 00:07:02 UTC (rev 264205)
+++ trunk/LayoutTests/accessibility/mac/selected-visible-position-range.html	2020-07-10 01:27:19 UTC (rev 264206)
@@ -1,6 +1,7 @@
 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
 <html>
 <head>
+<script src=""
 <script src=""
 <script src=""
 </head>
@@ -17,48 +18,41 @@
 <script>
     description("This tests getting and setting the selected VisiblePosition range.");
 
+    function checkCurrentSelection(accessibleObject, selection)
+    {
+        waitFor(() => {
+            selectedRange = accessibleObject.selectedTextMarkerRange();
+            selectedString = accessibleObject.stringForTextMarkerRange(selectedRange);
+            return selectedString == selection;
+        });
+        debug("PASS current selection is '" + selection + "'");
+    }
+
     if (window.accessibilityController) {
-        window.jsTestIsAsync = true;
-
         // Select the last paragraph using DOM API.
         selectTextInNode("p2");
 
         // Get current selection range via accessibility API.
         var content = accessibilityController.accessibleElementById("content");
-        var selectedRange = content.selectedTextMarkerRange();
-        var selectedString = content.stringForTextMarkerRange(selectedRange);
-        shouldBe("selectedString", "'Last paragraph.'");
+        checkCurrentSelection(content, "Last paragraph.");
 
         // Set the selection to the first paragraph via accessibility API.
-        var startTextMarker = content.startTextMarkerForTextMarkerRange(selectedRange);
-        var previousParagraphStart = content.previousParagraphStartTextMarkerForTextMarker(startTextMarker);
-        var paragraphRange = content.textMarkerRangeForMarkers(previousParagraphStart, startTextMarker);
-        content.setSelectedVisibleTextRange(paragraphRange);
-        setTimeout(function() {
-            selectedRange = content.selectedTextMarkerRange();
-            selectedString = content.stringForTextMarkerRange(selectedRange);
-            debug("selectedString must be the text of the first paragraph: " + selectedString);
+        var lastParagraphRange = content.selectedTextMarkerRange();
+        var lastParagraphStart = content.startTextMarkerForTextMarkerRange(lastParagraphRange);
+        var firstParagraphStart = content.previousParagraphStartTextMarkerForTextMarker(lastParagraphStart);
+        var firstParagraphRange = content.textMarkerRangeForMarkers(firstParagraphStart, lastParagraphStart);
+        content.setSelectedVisibleTextRange(firstParagraphRange);
+        checkCurrentSelection(content, "First paragraph.\n\n");
 
-            // Set the selection range to a collapsed range at the start position of the last paragraph.
-            var nullRange = content.textMarkerRangeForMarkers(startTextMarker, startTextMarker);
-            content.setSelectedVisibleTextRange(nullRange);
-            setTimeout(function() {
-                selectedRange = content.selectedTextMarkerRange();
-                selectedString = content.stringForTextMarkerRange(selectedRange);
-                debug("selectedString must be an empty string: " + selectedString);
+        // Set the selection range to a collapsed range at the start position of the last paragraph.
+        var nullRange = content.textMarkerRangeForMarkers(lastParagraphStart, lastParagraphStart);
+        content.setSelectedVisibleTextRange(nullRange);
+        checkCurrentSelection(content, "");
 
-                // Set the selection range to a collapsed range at the start position of the first paragraph.
-                nullRange = content.textMarkerRangeForMarkers(previousParagraphStart, previousParagraphStart);
-                content.setSelectedVisibleTextRange(nullRange);
-                setTimeout(function() {
-                    selectedRange = content.selectedTextMarkerRange();
-                    selectedString = content.stringForTextMarkerRange(selectedRange);
-                    debug("selectedString must be an empty string: " + selectedString);
-
-                    finishJSTest();
-                }, 10);
-            }, 10);
-        }, 10);
+        // Set the selection range to a collapsed range at the start position of the first paragraph.
+        nullRange = content.textMarkerRangeForMarkers(firstParagraphStart, firstParagraphStart);
+        content.setSelectedVisibleTextRange(nullRange);
+        checkCurrentSelection(content, "");
     }
 </script>
 <script src=""

Modified: trunk/LayoutTests/accessibility/textarea-selected-text-range.html (264205 => 264206)


--- trunk/LayoutTests/accessibility/textarea-selected-text-range.html	2020-07-10 00:07:02 UTC (rev 264205)
+++ trunk/LayoutTests/accessibility/textarea-selected-text-range.html	2020-07-10 01:27:19 UTC (rev 264206)
@@ -1,4 +1,5 @@
 <html>
+<script src=""
 <script src=""
 <body>
     
@@ -11,18 +12,6 @@
     </textarea>
 
 <script>
-    function waitFor(condition)
-    {
-        return new Promise((resolve, reject) => {
-            let interval = setInterval(() => {
-                if (condition()) {
-                    clearInterval(interval);
-                    resolve();
-                }
-            }, 0);
-        });
-    }
-
     if (window.accessibilityController) {
         window.jsTestIsAsync = true;
         var area1 = document.getElementById("area1");

Modified: trunk/LayoutTests/resources/accessibility-helper.js (264205 => 264206)


--- trunk/LayoutTests/resources/accessibility-helper.js	2020-07-10 00:07:02 UTC (rev 264205)
+++ trunk/LayoutTests/resources/accessibility-helper.js	2020-07-10 01:27:19 UTC (rev 264206)
@@ -89,3 +89,15 @@
     var index = accessibilityController.platformName == "atk" ? 0 : 1;
     return accessibilityObject.childAtIndex(index);
 }
+
+function waitFor(condition)
+{
+    return new Promise((resolve, reject) => {
+        let interval = setInterval(() => {
+            if (condition()) {
+                clearInterval(interval);
+                resolve();
+            }
+        }, 0);
+    });
+}

Modified: trunk/Tools/ChangeLog (264205 => 264206)


--- trunk/Tools/ChangeLog	2020-07-10 00:07:02 UTC (rev 264205)
+++ trunk/Tools/ChangeLog	2020-07-10 01:27:19 UTC (rev 264206)
@@ -1,3 +1,18 @@
+2020-07-09  Andres Gonzalez  <[email protected]>
+
+        Make accessibility/Mac/selected-visible-position-range.html time-deterministic.
+        https://bugs.webkit.org/show_bug.cgi?id=214154
+
+        Reviewed by Chris Fleizach.
+
+
+        * WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm:
+        (WTR::AccessibilityUIElement::setSelectedVisibleTextRange):
+        Check passed parameter for null.
+
+        (WTR::AccessibilityUIElement::selectedTextMarkerRange):
+        Use attributeValue to run on secondary AX thread.
+
 2020-07-09  Per Arne Vollan  <[email protected]>
 
         Move XPCEndpoint and XPCEndpointClient classes from WebCore to WebKit

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm (264205 => 264206)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm	2020-07-10 00:07:02 UTC (rev 264205)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementMac.mm	2020-07-10 01:27:19 UTC (rev 264206)
@@ -1441,6 +1441,9 @@
 
 bool AccessibilityUIElement::setSelectedVisibleTextRange(AccessibilityTextMarkerRange* markerRange)
 {
+    if (!markerRange)
+        return false;
+
     setAttributeValue(m_element.get(), NSAccessibilitySelectedTextMarkerRangeAttribute, markerRange->platformTextMarkerRange());
 
     return true;
@@ -1816,14 +1819,14 @@
     
     return nullptr;
 }
-    
+
 RefPtr<AccessibilityTextMarkerRange> AccessibilityUIElement::selectedTextMarkerRange()
 {
     BEGIN_AX_OBJC_EXCEPTIONS
-    id textMarkerRange = [m_element accessibilityAttributeValue:NSAccessibilitySelectedTextMarkerRangeAttribute];
+    id textMarkerRange = attributeValue(m_element.get(), NSAccessibilitySelectedTextMarkerRangeAttribute);
     return AccessibilityTextMarkerRange::create(textMarkerRange);
     END_AX_OBJC_EXCEPTIONS
-    
+
     return nullptr;
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to