Skip to content

Commit

Permalink
Add AccessibilityChecks for tests on Android
Browse files Browse the repository at this point in the history
This CL adds AccessibilityChecks from the Accessibility Test Framework
to all potential tests in Android.

We enable the AccessibilityChecks in the BaseActivityTestRule so that
they will be run on each test that uses this type of rule between each
"user" interaction. The tests check basic accessibility functionality
and give early warnings of potential issues.

AX-Relnotes: N/A
Bug: 1258230
Change-Id: I1bde86994d58981ad0cd7431421030fafb1df252
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3283189
Commit-Queue: Mark Schillaci <mschillaci@google.com>
Reviewed-by: Scott Little <sclittle@chromium.org>
Reviewed-by: Yaron Friedman <yfriedman@chromium.org>
Reviewed-by: Peter Wen <wnwen@chromium.org>
Reviewed-by: Theresa Sullivan <twellington@chromium.org>
Reviewed-by: Ryan Hamilton <rch@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1073650}
  • Loading branch information
mschillaci authored and Chromium LUCI CQ committed Nov 19, 2022
1 parent 069f6d0 commit 72d8815
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 5 deletions.
21 changes: 20 additions & 1 deletion base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -4385,13 +4385,31 @@ if (is_android) {
sources = [ "android/javatests/src/org/chromium/base/library_loader/EarlyNativeTest.java" ]
}

android_library("base_java_url_utils_for_test") {
testonly = true
sources = [
"test/android/javatests/src/org/chromium/base/test/util/UrlUtils.java",
]

deps = [
":base_java",
"//base:jni_java",
"//build/android:build_java",
"//third_party/androidx:androidx_annotation_annotation_java",
"//third_party/junit:junit",
]
annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ]
}

android_library("base_java_test_support") {
testonly = true

deps = [
":base_java",
"//base:jni_java",
"//build/android:build_java",
"//third_party/accessibility_test_framework:accessibility_test_framework_java",
"//third_party/android_deps:espresso_java",
"//third_party/android_sdk:android_test_base_java",
"//third_party/android_sdk:android_test_mock_java",
"//third_party/android_support_test_runner:runner_java",
Expand All @@ -4402,6 +4420,8 @@ if (is_android) {
"//third_party/junit",
]

public_deps = [ ":base_java_url_utils_for_test" ]

sources = [
"test/android/javatests/src/org/chromium/base/FakeTimeTestRule.java",
"test/android/javatests/src/org/chromium/base/test/BaseActivityTestRule.java",
Expand Down Expand Up @@ -4482,7 +4502,6 @@ if (is_android) {
"test/android/javatests/src/org/chromium/base/test/util/TestFileUtil.java",
"test/android/javatests/src/org/chromium/base/test/util/TimeoutScale.java",
"test/android/javatests/src/org/chromium/base/test/util/TimeoutTimer.java",
"test/android/javatests/src/org/chromium/base/test/util/UrlUtils.java",
"test/android/javatests/src/org/chromium/base/test/util/UserActionTester.java",
]
annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,24 @@

package org.chromium.base.test;

import static com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckResultUtils.matchesCheckNames;

import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.is;

import android.app.Activity;
import android.content.Intent;
import android.support.test.runner.lifecycle.Stage;
import android.text.TextUtils;

import androidx.annotation.CallSuper;
import androidx.annotation.Nullable;
import androidx.test.espresso.contrib.AccessibilityChecks;

import com.google.android.apps.common.testing.accessibility.framework.ClickableSpanViewCheck;
import com.google.android.apps.common.testing.accessibility.framework.DuplicateClickableBoundsViewCheck;
import com.google.android.apps.common.testing.accessibility.framework.EditableContentDescViewCheck;
import com.google.android.apps.common.testing.accessibility.framework.TouchTargetSizeViewCheck;

import org.junit.Assert;
import org.junit.rules.TestRule;
Expand Down Expand Up @@ -39,6 +50,38 @@ public class BaseActivityTestRule<T extends Activity> implements TestRule {
*/
public BaseActivityTestRule(Class<T> activityClass) {
mActivityClass = activityClass;

// Enable accessibility checks, but suppress checks that fit into the following:
//
// TouchTargetSize checks - Many views in Chrome give false positives for the minimum
// target size of 48dp. 100s of tests fail, leave disabled
// until a complete audit can be done.
//
// ClickableSpan checks - Chrome uses ClickableSpan's throughout for in-line links,
// but a URLSpan is considered more accessible, except in the
// case of relative links. Disable until after an audit.
//
// EditableContentDesc checks - Editable TextViews (EditText's) should not have a
// content description and instead have a hint or label.
// Various Autofill tests fail because of this, leave
// disabled until after an audit.
//
// DuplicateClickableBounds checks - Some containers are marked clickable when they do not
// process click events. Two views with the same bounds
// should not both be clickable. Some examples in:
// PageInfoRowView, AutofillAssistant and TabModal.
//
// TODO(AccessibilityChecks): Complete above audits and ideally suppress no checks.
try {
AccessibilityChecks.enable().setSuppressingResultMatcher(anyOf(
matchesCheckNames(is(TouchTargetSizeViewCheck.class.getSimpleName())),
matchesCheckNames(is(ClickableSpanViewCheck.class.getSimpleName())),
matchesCheckNames(is(EditableContentDescViewCheck.class.getSimpleName())),
matchesCheckNames(
is(DuplicateClickableBoundsViewCheck.class.getSimpleName()))));
} catch (IllegalStateException e) {
// Suppress IllegalStateException for AccessibilityChecks already enabled.
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1064,12 +1064,14 @@ public void testTermsAndConditions() throws Exception {
new AutofillAssistantCollectUserDataTestHelper.MockDelegate();

String acceptTermsText = "I accept";
String denyTermsText = "I deny";

// Display terms as 2 radio buttons "I accept" vs "I don't".
TestThreadUtils.runOnUiThreadBlocking(() -> {
model.set(AssistantCollectUserDataModel.DELEGATE, delegate);
model.set(AssistantCollectUserDataModel.ACCEPT_TERMS_AND_CONDITIONS_TEXT,
acceptTermsText);
model.set(AssistantCollectUserDataModel.TERMS_REQUIRE_REVIEW_TEXT, denyTermsText);
model.set(AssistantCollectUserDataModel.SHOW_TERMS_AS_CHECKBOX, false);
model.set(AssistantCollectUserDataModel.VISIBLE, true);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
import androidx.test.espresso.Espresso;
import androidx.test.espresso.NoMatchingViewException;
import androidx.test.espresso.ViewAssertion;
import androidx.test.espresso.contrib.AccessibilityChecks;
import androidx.test.espresso.contrib.RecyclerViewActions;
import androidx.test.filters.LargeTest;
import androidx.test.filters.MediumTest;
Expand Down Expand Up @@ -198,7 +197,6 @@ public static void beforeClass() {

@Before
public void setUp() throws ExecutionException {
AccessibilityChecks.enable();
mTestServer = EmbeddedTestServer.createAndStartServer(InstrumentationRegistry.getContext());
// After setUp, Chrome is launched and has one NTP.
mActivityTestRule.startMainActivityWithURL(NTP_URL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ public void setUpTest() throws Exception {

mIdHomeButton = View.generateViewId();
mHomeButton = new HomeButton(getActivity(), null);
// For a view created in a test, we can make the view not important for accessibility
// to prevent failures from AccessibilityChecks. Do not do this for views outside tests.
mHomeButton.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
ObservableSupplierImpl<Boolean> homepagePolicySupplier = new ObservableSupplierImpl<>();
homepagePolicySupplier.set(false);
mHomeButton.init(new ObservableSupplierImpl<Boolean>(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ private TranslateMessage prepareListMenuButtonForTranslateMessageOnUiThread() {
messageProperties.get(MessageBannerProperties.SECONDARY_ICON_RESOURCE_ID));
listMenuButton.setDelegate(
messageProperties.get(MessageBannerProperties.SECONDARY_MENU_BUTTON_DELEGATE));
// For a view created in a test, we can make the view not important for accessibility
// to prevent failures from AccessibilityChecks. Do not do this for views outside tests.
listMenuButton.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);

sContentView.addView(listMenuButton);

Expand Down
4 changes: 2 additions & 2 deletions net/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ android_library("net_java_test_support") {
":embedded_test_server_aidl_java",
":net_java",
"//base:base_java",
"//base:base_java_test_support",
"//base:base_java_url_utils_for_test",
"//base:jni_java",
"//third_party/android_support_test_runner:rules_java",
"//third_party/android_support_test_runner:runner_java",
Expand All @@ -103,7 +103,7 @@ android_library("net_java_test_support_provider") {
":embedded_test_server_aidl_java",
":net_java",
"//base:base_java",
"//base:base_java_test_support",
"//base:base_java_url_utils_for_test",
"//base:jni_java",
]

Expand Down

0 comments on commit 72d8815

Please sign in to comment.