public class AccessibilityUtil
extends java.lang.Object
Utility class for checking Views for accessibility.
This class is used by ShadowView.checkedPerformClick
to check for accessibility problems. There is some subtlety to checking a UI for accessibility when it hasn’t been rendered. The better initialized the View, the more accurate the checking will be. At a minimum, the view should be attached to a proper view hierarchy similar to what’s checked for in:q ShadowView.checkedPerformClick
.
Modifier | Constructor and Description |
---|---|
protected |
AccessibilityUtil() |
Modifier and Type | Method and Description |
---|---|
static java.util.List<com.google.android.apps.common.testing.accessibility.framework.AccessibilityViewCheckResult> |
checkView(android.view.View view)
Check a hierarchy of
View s for accessibility, based on currently set options. |
static java.util.List<com.google.android.apps.common.testing.accessibility.framework.AccessibilityViewCheckResult> |
checkViewIfCheckingEnabled(android.view.View view)
Check a hierarchy of
View s for accessibility. |
static boolean |
passesAccessibilityChecksIfEnabled(android.view.View view)
Deprecated.
|
static void |
setRunChecksForRobolectricVersion(AccessibilityChecks.ForRobolectricVersion forVersion)
Specify that a specific subset of accessibility checks be run.
|
static void |
setRunChecksFromRootView(boolean runChecksFromRootView)
Specify that accessibility checks should be run for all views in the hierarchy whenever a single view’s accessibility is asserted.
|
static void |
setSuppressingResultMatcher(org.hamcrest.Matcher<? super com.google.android.apps.common.testing.accessibility.framework.AccessibilityViewCheckResult> matcher)
Suppress all results that match the given matcher.
|
static void |
setThrowExceptionForErrors(boolean throwExceptionForErrors)
Control whether or not to throw exceptions when accessibility errors are found.
|
public static java.util.List<com.google.android.apps.common.testing.accessibility.framework.AccessibilityViewCheckResult> checkViewIfCheckingEnabled(android.view.View view)
Check a hierarchy of View
s for accessibility. Only performs checks if (in decreasing priority order) accessibility checking is enabled using an AccessibilityChecks
annotation, if the system property robolectric.accessibility.enablechecks
is set to true
, or if the environment variable robolectric.accessibility.enablechecks
is set to true
.
view
- The View
to examinepublic static java.util.List<com.google.android.apps.common.testing.accessibility.framework.AccessibilityViewCheckResult> checkView(android.view.View view)
Check a hierarchy of View
s for accessibility, based on currently set options.
view
- The View
to examine@Deprecated public static boolean passesAccessibilityChecksIfEnabled(android.view.View view)
Check a hierarchy of View
s for accessibility. Only performs checks if (in decreasing priority order) accessibility checking is enabled using an AccessibilityChecks
annotation, if the system property robolectric.accessibility.enablechecks
is set to true
, or if the environment variable robolectric.accessibility.enablechecks
is set to true
.
Implicitly calls {code setThrowExceptionForErrors(false)} to disable exception throwing. This method is deprecated, both because of this side effect and because the other methods offer more control over execution.
view
- The View
to examinepublic static void setRunChecksForRobolectricVersion(AccessibilityChecks.ForRobolectricVersion forVersion)
Specify that a specific subset of accessibility checks be run. The subsets are specified based on which Robolectric version particular checks were released with. By default, all checks are run AccessibilityChecks.ForRobolectricVersion
.
If you call this method, the value you pass will take precedence over any value in any annotations.
forVersion
- The version of checks to run for. If null
, throws away the current value and falls back on the annotation or default.public static void setRunChecksFromRootView(boolean runChecksFromRootView)
Specify that accessibility checks should be run for all views in the hierarchy whenever a single view’s accessibility is asserted.
runChecksFromRootView
- true
if all views in the hierarchy should be checked.public static void setSuppressingResultMatcher(org.hamcrest.Matcher<? super com.google.android.apps.common.testing.accessibility.framework.AccessibilityViewCheckResult> matcher)
Suppress all results that match the given matcher. Suppressed results will not be included in any logs or cause any Exception
to be thrown. This capability is useful if there are known issues, but checks should still look for regressions.
matcher
- A matcher to match a AccessibilityViewCheckResult
. null
disables suppression and is the default.public static void setThrowExceptionForErrors(boolean throwExceptionForErrors)
Control whether or not to throw exceptions when accessibility errors are found.
throwExceptionForErrors
- true
to throw an AccessibilityViewCheckException
when there is at least one error result. Default: true
.