Skip to content

Commit a6117fe

Browse files
Accessibility Test Framework v3.0
Major updates: - 'uielement' package for generic UI representation - 'checks' package and AccessibilityHierarchyCheck for consolidated evaluation logic - New check: ClassNameCheck - New check: TraversalOrderCheck - Localized result strings - Protocol buffer representations for UI hierarchy, results, and Android constructs - Build switched to gradle
1 parent dafd7ed commit a6117fe

File tree

123 files changed

+17697
-2203
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+17697
-2203
lines changed

README

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,37 @@ contentDescription. Other rules require human judgment, such as whether or not
77
a contentDescription makes sense to all users.
88

99
For more information about Mobile Accessibility, see:
10-
http://www.w3.org/WAI/mobile/
10+
https://www.w3.org/WAI/mobile/
11+
12+
For more information about accessibility testing for Android applications, see:
13+
https://developer.android.com/training/accessibility/testing.html
1114

1215
This library collects various accessibility-related checks on View objects as
1316
well as AccessibilityNodeInfo objects (which the Android framework derives from
1417
Views and sends to AccessibilityServices).
1518

1619
Building the Library
1720
--------------------
18-
Use maven to build the library. You will need to install Android 5.0 (API 21)
19-
or higher to build the library. We used the Maven Android SDK Deployer to build:
20-
https://github.com/mosabua/maven-android-sdk-deployer
21+
The supplied build.gradle file can be used to build the Accessibility Test
22+
Framework with gradle. The build.gradle file can also be used to import the
23+
project to Android Studio.
2124

2225
Sample Usage
2326
------------
2427
Given a view, the following code runs all accessibility checks on all views in the
2528
hierarchy rooted at that view and throws an exception if any errors are found:
2629

27-
Set<AccessibilityViewHierarchyCheck> checks = getViewChecksForPreset(LATEST);
28-
List<AccessibilityViewCheckResult> results = new LinkedList<AccessibilityViewCheckResult>();
29-
for (AccessibilityViewHierarchyCheck check : checks) {
30-
results.addAll(check.runCheckOnViewHierarchy(rootView));
30+
Set<AccessibilityHierarchyCheck> checks =
31+
AccessibilityCheckPreset.getAccessibilityHierarchyChecksForPreset(
32+
AccessibilityCheckPreset.LATEST);
33+
AccessibilityHierarchy hierarchy = AccessibilityHierarchy.newBuilder(node, context).build();
34+
List<AccessibilityHierarchyCheckResult> results = new ArrayList<>();
35+
for (AccessibilityHierarchyCheck check : checks) {
36+
results.addAll(check.runCheckOnHierarchy(hierarchy));
3137
}
32-
List<AccessibilityViewCheckResult> errors = AccessibilityCheckResultUtils.getResultsForType(
38+
List<AccessibilityHierarchyCheckResult> errors =
39+
AccessibilityCheckResultUtils.getResultsForType(
3340
results, AccessibilityCheckResultType.ERROR);
3441
if (errors.size() > 0) {
3542
throw new RuntimeException(errors.get(0).getMessage().toString());
36-
}
43+
}

build.gradle

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
buildscript {
2+
repositories {
3+
jcenter()
4+
google()
5+
}
6+
dependencies {
7+
classpath 'com.android.tools.build:gradle:3.0.1'
8+
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.4'
9+
}
10+
}
11+
12+
13+
allprojects {
14+
repositories {
15+
jcenter()
16+
google()
17+
}
18+
}
19+
20+
apply plugin: 'com.android.library'
21+
apply plugin: 'com.google.protobuf'
22+
23+
android {
24+
compileSdkVersion "android-27"
25+
buildToolsVersion '27.0.3'
26+
defaultConfig {
27+
minSdkVersion 14
28+
targetSdkVersion 27
29+
}
30+
sourceSets {
31+
main {
32+
manifest.srcFile 'src/main/java/com/google/android/apps/common/testing/accessibility/framework/AndroidManifest.xml'
33+
}
34+
}
35+
lintOptions {
36+
abortOnError false
37+
}
38+
compileOptions {
39+
targetCompatibility 1.8
40+
sourceCompatibility 1.8
41+
}
42+
}
43+
44+
protobuf {
45+
protoc {
46+
artifact = 'com.google.protobuf:protoc:3.5.1'
47+
}
48+
plugins {
49+
javalite {
50+
// The codegen for lite comes as a separate artifact
51+
artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
52+
}
53+
}
54+
generateProtoTasks {
55+
all().each { task ->
56+
task.builtins {
57+
// In most cases you don't need the full Java output
58+
// if you use the lite output.
59+
remove java
60+
}
61+
task.plugins {
62+
javalite {}
63+
}
64+
}
65+
}
66+
}
67+
68+
dependencies {
69+
compile 'com.google.protobuf:protobuf-lite:3.0.1'
70+
compile 'com.android.support:support-v4:27.1.0'
71+
compile 'com.google.guava:guava:24.0-android'
72+
compile 'org.checkerframework:checker:2.3.2'
73+
compile 'org.hamcrest:hamcrest-library:1.3'
74+
compile 'org.hamcrest:hamcrest-core:1.3'
75+
}
76+
77+
clean {
78+
delete 'src/main/generated'
79+
}

pom.xml

Lines changed: 0 additions & 165 deletions
This file was deleted.

src/main/java/com/google/android/apps/common/testing/accessibility/framework/AccessibilityCheck.java

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,39 @@
1717
package com.google.android.apps.common.testing.accessibility.framework;
1818

1919
/**
20-
* Abstract base class for all accessibility checks. Abstract subclasses include
21-
* {@code AccessibilityViewCheck}, the base class for all that run against {@code View}s, and
22-
* {@code AccessibilityInfoCheck}, the base class for checks that run against
23-
* {@code AccessibilityNodeInfo}s.
20+
* Abstract base class for all accessibility checks. Abstract subclasses include:
21+
* <ul>
22+
* <li>{@link AccessibilityHierarchyCheck} - the base class for all checks that run against
23+
* {@code AccessibilityHierarchy}</li>
24+
* <li>{@link AccessibilityEventCheck} - the base class for all checks that that run against
25+
* {@code AccessibilityEvent}</li>
26+
* <li>Deprecated {@link AccessibilityViewHierarchyCheck} - the base class for all checks that run
27+
* against {@code View}s</li>
28+
* <li>Deprecated {@link AccessibilityInfoHierarchyCheck} - the base class for all checks that run
29+
* against {@code AccessibilityNodeInfo}s</li>
30+
* </ul>
2431
*
2532
* <p>Classes extending this one must implement {@code runCheck...} that return {@code List}s of
2633
* a subclass of {@code AccessibilityCheckResult}.
2734
*/
2835
public abstract class AccessibilityCheck {
36+
37+
/** Categories of accessibility checks. */
38+
public enum Category {
39+
40+
/** Checks for controls whose content labels are missing or confusing. */
41+
CONTENT_LABELING,
42+
43+
/** Checks for touch targets that could cause difficulty for users with motor impairments. */
44+
TOUCH_TARGET_SIZE,
45+
46+
/** Checks for elements that may be difficult to see due to low contrast. */
47+
LOW_CONTRAST,
48+
49+
/**
50+
* Checks for conditions that impact accessibility due to the way a UI presents itself to
51+
* accessibility services.
52+
*/
53+
IMPLEMENTATION;
54+
}
2955
}

0 commit comments

Comments
 (0)