Commit be171a09 authored by Clemens Arbesser's avatar Clemens Arbesser Committed by Commit Bot

[Autofill Assistant] Added content description to view attributes.

Bug: b/145043394
Change-Id: Icf1e92c439dc1a8fb502f32f0fff18a325814c3d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2095727
Commit-Queue: Clemens Arbesser <arbesser@google.com>
Reviewed-by: default avatarMathias Carlen <mcarlen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#749781}
parent 89304742
......@@ -4,6 +4,8 @@
package org.chromium.chrome.browser.autofill_assistant.generic_ui;
import static org.chromium.chrome.browser.autofill_assistant.AssistantAccessibilityUtils.setAccessibility;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
......@@ -31,7 +33,7 @@ public class AssistantViewFactory {
@CalledByNative
public static void setViewAttributes(View view, Context context, int paddingStart,
int paddingTop, int paddingEnd, int paddingBottom,
@Nullable AssistantDrawable background) {
@Nullable AssistantDrawable background, @Nullable String contentDescription) {
view.setPaddingRelative(AssistantDimension.getPixelSizeDp(context, paddingStart),
AssistantDimension.getPixelSizeDp(context, paddingTop),
AssistantDimension.getPixelSizeDp(context, paddingEnd),
......@@ -43,6 +45,7 @@ public class AssistantViewFactory {
}
});
}
setAccessibility(view, contentDescription);
}
/**
......
......@@ -18,6 +18,8 @@ import static android.support.test.espresso.matcher.ViewMatchers.withClassName;
import static android.support.test.espresso.matcher.ViewMatchers.withContentDescription;
import static android.support.test.espresso.matcher.ViewMatchers.withTagValue;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static android.view.View.IMPORTANT_FOR_ACCESSIBILITY_NO;
import static android.view.View.IMPORTANT_FOR_ACCESSIBILITY_YES;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
......@@ -26,6 +28,7 @@ import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.isIn;
import static org.hamcrest.Matchers.iterableWithSize;
import static org.chromium.chrome.browser.autofill_assistant.AutofillAssistantUiTestUtil.isImportantForAccessibility;
import static org.chromium.chrome.browser.autofill_assistant.AutofillAssistantUiTestUtil.startAutofillAssistant;
import static org.chromium.chrome.browser.autofill_assistant.AutofillAssistantUiTestUtil.waitUntilViewMatchesCondition;
......@@ -1133,4 +1136,65 @@ public class AutofillAssistantGenericUiTest {
.setDay(13))))
.build()));
}
/**
* Tests custom content descriptions for views.
*/
@Test
@MediumTest
public void testContentDescription() {
GenericUserInterfaceProto genericUserInterface =
(GenericUserInterfaceProto) GenericUserInterfaceProto.newBuilder()
.setRootView(ViewProto.newBuilder().setViewContainer(
ViewContainerProto.newBuilder()
.setLinearLayout(
LinearLayoutProto.newBuilder().setOrientation(
LinearLayoutProto.Orientation.VERTICAL))
.addViews(ViewProto.newBuilder().setTextView(
TextViewProto.newBuilder().setText(
"auto-generated-desc")))
.addViews(
ViewProto.newBuilder()
.setTextView(
TextViewProto.newBuilder().setText(
"no-desc"))
.setAttributes(
ViewAttributesProto.newBuilder()
.setContentDescription("")))
.addViews(
ViewProto.newBuilder()
.setTextView(
TextViewProto.newBuilder().setText(
"custom-desc"))
.setAttributes(
ViewAttributesProto.newBuilder()
.setContentDescription(
"custom")))))
.build();
ArrayList<ActionProto> list = new ArrayList<>();
list.add((ActionProto) ActionProto.newBuilder()
.setShowGenericUi(ShowGenericUiProto.newBuilder().setGenericUserInterface(
genericUserInterface))
.build());
AutofillAssistantTestScript script = new AutofillAssistantTestScript(
(SupportedScriptProto) SupportedScriptProto.newBuilder()
.setPath("form_target_website.html")
.setPresentation(PresentationProto.newBuilder().setAutostart(true).setChip(
ChipProto.newBuilder().setText("Autostart")))
.build(),
list);
AutofillAssistantTestService testService =
new AutofillAssistantTestService(Collections.singletonList(script));
startAutofillAssistant(mTestRule.getActivity(), testService);
waitUntilViewMatchesCondition(withText("auto-generated-desc"), isCompletelyDisplayed());
onView(withText("auto-generated-desc"))
.check(matches(isImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES)));
onView(withText("no-desc"))
.check(matches(isImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO)));
onView(withText("custom-desc")).check(matches(withContentDescription("custom")));
}
}
......@@ -160,7 +160,11 @@ base::android::ScopedJavaGlobalRef<jobject> CreateJavaView(
env, jview, jcontext, proto.attributes().padding_start(),
proto.attributes().padding_top(), proto.attributes().padding_end(),
proto.attributes().padding_bottom(),
CreateJavaDrawable(env, jcontext, proto.attributes().background()));
CreateJavaDrawable(env, jcontext, proto.attributes().background()),
proto.attributes().has_content_description()
? base::android::ConvertUTF8ToJavaString(
env, proto.attributes().content_description())
: nullptr);
}
if (proto.has_layout_params()) {
Java_AssistantViewFactory_setViewLayoutParams(
......
......@@ -86,6 +86,12 @@ message ViewAttributesProto {
optional int32 padding_bottom = 4;
optional DrawableProto background = 5;
// The content description for this view. There are three possible states:
// - unset: content description is auto-inferred by android a11y.
// - set to empty string: this view is not important for a11y.
// - set to non-empty string: the view will have the specified content
// description.
optional string content_description = 6;
}
// Parameters configuring how views attach to their parents.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment