From c50d92c48b140eff7102bb782aec6c9b3e5dda17 Mon Sep 17 00:00:00 2001 From: AndriiZaliskyi Date: Mon, 12 Dec 2022 13:26:14 +0200 Subject: [PATCH] Add an API to set custom touch target size --- .../espresso/AccessibilityValidator.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/java/com/google/android/apps/common/testing/accessibility/framework/integrations/espresso/AccessibilityValidator.java b/src/main/java/com/google/android/apps/common/testing/accessibility/framework/integrations/espresso/AccessibilityValidator.java index 56e1b51..af2e480 100644 --- a/src/main/java/com/google/android/apps/common/testing/accessibility/framework/integrations/espresso/AccessibilityValidator.java +++ b/src/main/java/com/google/android/apps/common/testing/accessibility/framework/integrations/espresso/AccessibilityValidator.java @@ -67,6 +67,8 @@ public final class AccessibilityValidator { private @Nullable Boolean saveViewImages; private int screenshotsCaptured = 0; + private @Nullable Integer customTouchTargetSize; + private @Nullable AccessibilityCheckResultType throwExceptionFor = AccessibilityCheckResultType.ERROR; @@ -175,6 +177,19 @@ public AccessibilityValidator setSaveImages(boolean saveScreenshots, boolean sav return this; } + /** + * Sets a user-defined minimum touch target size for use by {@link + * com.google.android.apps.common.testing.accessibility.framework.checks.TouchTargetSizeCheck}. A + * value set here should override the default value used by the check. + * + * @param touchTargetSize a user-defined minimum touch target size in pixels + */ + @CanIgnoreReturnValue + public AccessibilityValidator setCustomTouchTargetSize(int touchTargetSize) { + this.customTouchTargetSize = touchTargetSize; + return this; + } + /** * Suppresses all results that match the given matcher. Suppressed results will not be included in * any logs or cause any {@code Exception} to be thrown @@ -280,6 +295,10 @@ private ImmutableList runAccessibilityChecks(View } } + if (customTouchTargetSize != null) { + parameters.putCustomTouchTargetSize(customTouchTargetSize); + } + return processResults( view.getContext(), viewChecker.runViewChecksOnView(