[atf] integrate a new atf lib which provides namespace URI for a fix
1. Integrate with a new ATF lib which provides namespace URIL for a fix
and getDescription method of FixSuggestion will return a string
without markup.
2. only allow fixes are provided for A11y check results which are
generated by a pre-defined AccessibilityHierarchyChecks.
Test: tested locally
Change-Id: Id2b199606a8ed55aca341e3688877ec7ef540ef8
diff --git a/Android.bp b/Android.bp
index 17b77d6..048b78e 100644
--- a/Android.bp
+++ b/Android.bp
@@ -53,7 +53,7 @@
tools: ["layoutlib_create"],
out: ["temp_layoutlib.jar"],
srcs: [
- ":atf-prebuilt-357817562{.jar}",
+ ":atf-prebuilt{.jar}",
":core-icu4j-for-host{.jar}",
":core-libart-for-host{.jar}",
":framework-all{.jar}",
diff --git a/bridge/tests/src/com/android/tools/idea/validator/AccessibilityValidatorTests.java b/bridge/tests/src/com/android/tools/idea/validator/AccessibilityValidatorTests.java
index 9f4f83c..dc3c444 100644
--- a/bridge/tests/src/com/android/tools/idea/validator/AccessibilityValidatorTests.java
+++ b/bridge/tests/src/com/android/tools/idea/validator/AccessibilityValidatorTests.java
@@ -153,7 +153,7 @@
ExpectedLevels expectedLevels = new ExpectedLevels();
expectedLevels.expectedVerboses = 1;
expectedLevels.expectedErrors = 1;
- expectedLevels.expectedFixes = 1;
+ expectedLevels.expectedFixes = 0;
expectedLevels.check(speakableCheck);
// Make sure no other errors in the system.
diff --git a/validator/src/com/android/tools/idea/validator/ValidatorData.java b/validator/src/com/android/tools/idea/validator/ValidatorData.java
index 956f7eb..167cab1 100644
--- a/validator/src/com/android/tools/idea/validator/ValidatorData.java
+++ b/validator/src/com/android/tools/idea/validator/ValidatorData.java
@@ -182,13 +182,18 @@
* Represents a view attribute which contains a namespace and an attribute name.
*/
public static class ViewAttribute {
- //TODO: Consider adding uri info as well for xml modifications.
+ /** The namespace used in XML files for this view attribute. */
+ @NotNull public final String mNamespaceUri;
/** The namespace of this view attribute. */
@NotNull public final String mNamespace;
/** The attribute name of this view attribute. */
@NotNull public final String mAttributeName;
- public ViewAttribute(@NotNull String namespace, @NotNull String attributeName) {
+ public ViewAttribute(
+ @NotNull String namespaceUri,
+ @NotNull String namespace,
+ @NotNull String attributeName) {
+ mNamespaceUri = namespaceUri;
mNamespace = namespace;
mAttributeName = attributeName;
}
diff --git a/validator/src/com/android/tools/idea/validator/ValidatorUtil.java b/validator/src/com/android/tools/idea/validator/ValidatorUtil.java
index 51c341a..63bea1b 100644
--- a/validator/src/com/android/tools/idea/validator/ValidatorUtil.java
+++ b/validator/src/com/android/tools/idea/validator/ValidatorUtil.java
@@ -51,6 +51,10 @@
import com.google.android.apps.common.testing.accessibility.framework.AccessibilityHierarchyCheck;
import com.google.android.apps.common.testing.accessibility.framework.AccessibilityHierarchyCheckResult;
import com.google.android.apps.common.testing.accessibility.framework.Parameters;
+import com.google.android.apps.common.testing.accessibility.framework.checks.EditableContentDescCheck;
+import com.google.android.apps.common.testing.accessibility.framework.checks.RedundantDescriptionCheck;
+import com.google.android.apps.common.testing.accessibility.framework.checks.TextContrastCheck;
+import com.google.android.apps.common.testing.accessibility.framework.checks.TouchTargetSizeCheck;
import com.google.android.apps.common.testing.accessibility.framework.strings.StringManager;
import com.google.android.apps.common.testing.accessibility.framework.suggestions.CompoundFixSuggestions;
import com.google.android.apps.common.testing.accessibility.framework.suggestions.FixSuggestion;
@@ -64,6 +68,7 @@
import com.google.android.apps.common.testing.accessibility.framework.uielement.DefaultCustomViewBuilderAndroid;
import com.google.android.apps.common.testing.accessibility.framework.uielement.ViewHierarchyElementAndroid;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
public class ValidatorUtil {
@@ -88,6 +93,15 @@
new DefaultCustomViewBuilderAndroid();
/**
+ * Fixes could be only provided for a {@link AccessibilityHierarchyCheckResult}s generated by
+ * a predefined set of {@link AccessibilityHierarchyCheck}s.
+ */
+ private final static ImmutableSet<Class<? extends AccessibilityHierarchyCheck>>
+ sAllowedCheckResultClassSet4Fix = ImmutableSet.of(TextContrastCheck.class,
+ TouchTargetSizeCheck.class, RedundantDescriptionCheck.class,
+ EditableContentDescCheck.class);
+
+ /**s
* @param policy policy to apply for the hierarchy
* @param view root view to build hierarchy from
* @param image screenshot image that matches the view
@@ -301,9 +315,12 @@
@NotNull AccessibilityHierarchyCheckResult result,
@NotNull AccessibilityHierarchy hierarchy,
@Nullable Parameters parameters) {
- ImmutableList<FixSuggestion> fixSuggestions =
- FixSuggestionPreset.provideFixSuggestions(result, hierarchy, parameters);
- return fixSuggestions.isEmpty() ? null : convertFix(fixSuggestions.get(0));
+ if (sAllowedCheckResultClassSet4Fix.contains(result.getSourceCheckClass())) {
+ ImmutableList<FixSuggestion> fixSuggestions =
+ FixSuggestionPreset.provideFixSuggestions(result, hierarchy, parameters);
+ return fixSuggestions.isEmpty() ? null : convertFix(fixSuggestions.get(0));
+ }
+ return null;
}
/** Convert {@link FixSuggestion} to {@link ValidatorData.Fix} */
@@ -319,35 +336,31 @@
.collect(Collectors.toList());
return new CompoundFix(
fixes,
- convertHtml(compoundFixSuggestions.getDescription(Locale.ENGLISH)));
+ compoundFixSuggestions.getDescription(Locale.ENGLISH));
} else if (fixSuggestion instanceof RemoveViewAttributeFixSuggestion) {
RemoveViewAttributeFixSuggestion removeViewAttributeFix =
(RemoveViewAttributeFixSuggestion)fixSuggestion;
return new RemoveViewAttributeFix(
convertViewAttribute(removeViewAttributeFix.getViewAttribute()),
- convertHtml(removeViewAttributeFix.getDescription(Locale.ENGLISH)));
+ removeViewAttributeFix.getDescription(Locale.ENGLISH));
} else if (fixSuggestion instanceof SetViewAttributeFixSuggestion) {
SetViewAttributeFixSuggestion setViewAttributeFixSuggestion =
(SetViewAttributeFixSuggestion)fixSuggestion;
return new SetViewAttributeFix(
convertViewAttribute(setViewAttributeFixSuggestion.getViewAttribute()),
setViewAttributeFixSuggestion.getSuggestedValue(),
- convertHtml(setViewAttributeFixSuggestion.getDescription(Locale.ENGLISH)));
+ setViewAttributeFixSuggestion.getDescription(Locale.ENGLISH));
}
return null;
}
- @NotNull
- private static String convertHtml(CharSequence html) {
- //TODO: Provide descriptions without formatting markup in ATF
- return Jsoup.parse(html.toString()).text();
- }
-
/** Convert {@link ViewAttribute} to {@link ValidatorData.ViewAttribute} */
@NotNull
private static ValidatorData.ViewAttribute convertViewAttribute(
@NotNull ViewAttribute viewAttribute) {
- return new ValidatorData.ViewAttribute(viewAttribute.getNamespace(),
+ return new ValidatorData.ViewAttribute(
+ viewAttribute.getNamespaceUri(),
+ viewAttribute.getNamespace(),
viewAttribute.getAttributeName());
}
}