Bug 1518315 - Clear accessibility focus correctly. r=yzen

Differential Revision: https://phabricator.services.mozilla.com/D15872

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Eitan Isaacson 2019-01-14 20:05:05 +00:00
Родитель 0e42fd473e
Коммит 510d5dc2c3
2 изменённых файлов: 34 добавлений и 7 удалений

Просмотреть файл

@ -93,6 +93,7 @@ class AccessibilityTest : BaseSessionTest() {
private interface EventDelegate {
fun onAccessibilityFocused(event: AccessibilityEvent) { }
fun onAccessibilityFocusCleared(event: AccessibilityEvent) { }
fun onClicked(event: AccessibilityEvent) { }
fun onFocused(event: AccessibilityEvent) { }
fun onSelected(event: AccessibilityEvent) { }
@ -125,6 +126,7 @@ class AccessibilityTest : BaseSessionTest() {
AccessibilityEvent.TYPE_VIEW_FOCUSED -> newDelegate.onFocused(event)
AccessibilityEvent.TYPE_VIEW_CLICKED -> newDelegate.onClicked(event)
AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED -> newDelegate.onAccessibilityFocused(event)
AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED -> newDelegate.onAccessibilityFocusCleared(event)
AccessibilityEvent.TYPE_VIEW_SELECTED -> newDelegate.onSelected(event)
AccessibilityEvent.TYPE_VIEW_SCROLLED -> newDelegate.onScrolled(event)
AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED -> newDelegate.onTextSelectionChanged(event)
@ -192,6 +194,7 @@ class AccessibilityTest : BaseSessionTest() {
assertThat("Label accessibility focused", node.className.toString(),
equalTo("android.view.View"))
assertThat("Text node should not be focusable", node.isFocusable, equalTo(false))
assertThat("Text node should be a11y focused", node.isAccessibilityFocused, equalTo(true))
assertThat("Text node should not be clickable", node.isClickable, equalTo(false))
}
})
@ -207,9 +210,22 @@ class AccessibilityTest : BaseSessionTest() {
assertThat("Editbox accessibility focused", node.className.toString(),
equalTo("android.widget.EditText"))
assertThat("Entry node should be focusable", node.isFocusable, equalTo(true))
assertThat("Entry node should be a11y focused", node.isAccessibilityFocused, equalTo(true))
assertThat("Entry node should be clickable", node.isClickable, equalTo(true))
}
})
provider.performAction(nodeId,
AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS, null)
sessionRule.waitUntilCalled(object : EventDelegate {
@AssertCalled(count = 1)
override fun onAccessibilityFocusCleared(event: AccessibilityEvent) {
assertThat("Accessibility focused node is now cleared", getSourceId(event), equalTo(nodeId))
val node = createNodeInfo(nodeId)
assertThat("Entry node should node be a11y focused", node.isAccessibilityFocused, equalTo(false))
}
})
}
@Test fun testTextEntryNode() {

Просмотреть файл

@ -118,10 +118,6 @@ public class SessionAccessibility {
if (mAttached) {
node = mSession.getSettings().getFullAccessibilityTree() ?
getNodeFromGecko(virtualDescendantId) : getNodeFromCache(virtualDescendantId);
if (node != null) {
node.setAccessibilityFocused(mAccessibilityFocusedNode == virtualDescendantId);
node.setFocused(mFocusedNode == virtualDescendantId);
}
}
if (node == null) {
@ -143,6 +139,9 @@ public class SessionAccessibility {
final GeckoBundle data;
switch (action) {
case AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS:
sendEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED, virtualViewId, CLASSNAME_VIEW, null);
return true;
case AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS:
if (virtualViewId == View.NO_ID) {
sendEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED, View.NO_ID, CLASSNAME_WEBVIEW, null);
@ -296,7 +295,8 @@ public class SessionAccessibility {
return;
}
boolean isRoot = nodeInfo.getInt("id") == View.NO_ID;
final int id = nodeInfo.getInt("id");
boolean isRoot = id == View.NO_ID;
if (isRoot) {
if (Build.VERSION.SDK_INT < 17 || mView.getDisplay() != null) {
// When running junit tests we don't have a display
@ -321,8 +321,6 @@ public class SessionAccessibility {
// Add actions
node.addAction(AccessibilityNodeInfo.ACTION_NEXT_HTML_ELEMENT);
node.addAction(AccessibilityNodeInfo.ACTION_PREVIOUS_HTML_ELEMENT);
node.addAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
node.addAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
node.addAction(AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY);
node.addAction(AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY);
node.setMovementGranularities(AccessibilityNodeInfo.MOVEMENT_GRANULARITY_CHARACTER |
@ -348,6 +346,14 @@ public class SessionAccessibility {
// Other boolean properties to consider later:
// setHeading, setImportantForAccessibility, setScreenReaderFocusable, setShowingHintText, setDismissable
if (mAccessibilityFocusedNode == id) {
node.addAction(AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
node.setAccessibilityFocused(true);
} else {
node.addAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
}
node.setFocused(mFocusedNode == id);
// Bounds
int[] b = nodeInfo.getIntArray("bounds");
if (b != null) {
@ -714,6 +720,11 @@ public class SessionAccessibility {
}
}
break;
case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED:
if (mAccessibilityFocusedNode == sourceId) {
mAccessibilityFocusedNode = 0;
}
break;
case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED:
mAccessibilityFocusedNode = sourceId;
break;