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 @@ ...@@ -4,6 +4,8 @@
package org.chromium.chrome.browser.autofill_assistant.generic_ui; 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.content.Context;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
...@@ -31,7 +33,7 @@ public class AssistantViewFactory { ...@@ -31,7 +33,7 @@ public class AssistantViewFactory {
@CalledByNative @CalledByNative
public static void setViewAttributes(View view, Context context, int paddingStart, public static void setViewAttributes(View view, Context context, int paddingStart,
int paddingTop, int paddingEnd, int paddingBottom, int paddingTop, int paddingEnd, int paddingBottom,
@Nullable AssistantDrawable background) { @Nullable AssistantDrawable background, @Nullable String contentDescription) {
view.setPaddingRelative(AssistantDimension.getPixelSizeDp(context, paddingStart), view.setPaddingRelative(AssistantDimension.getPixelSizeDp(context, paddingStart),
AssistantDimension.getPixelSizeDp(context, paddingTop), AssistantDimension.getPixelSizeDp(context, paddingTop),
AssistantDimension.getPixelSizeDp(context, paddingEnd), AssistantDimension.getPixelSizeDp(context, paddingEnd),
...@@ -43,6 +45,7 @@ public class AssistantViewFactory { ...@@ -43,6 +45,7 @@ public class AssistantViewFactory {
} }
}); });
} }
setAccessibility(view, contentDescription);
} }
/** /**
......
...@@ -18,6 +18,8 @@ import static android.support.test.espresso.matcher.ViewMatchers.withClassName; ...@@ -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.withContentDescription;
import static android.support.test.espresso.matcher.ViewMatchers.withTagValue; import static android.support.test.espresso.matcher.ViewMatchers.withTagValue;
import static android.support.test.espresso.matcher.ViewMatchers.withText; 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.is;
import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.CoreMatchers.not;
...@@ -26,6 +28,7 @@ import static org.hamcrest.Matchers.equalTo; ...@@ -26,6 +28,7 @@ import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.isIn; import static org.hamcrest.Matchers.isIn;
import static org.hamcrest.Matchers.iterableWithSize; 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.startAutofillAssistant;
import static org.chromium.chrome.browser.autofill_assistant.AutofillAssistantUiTestUtil.waitUntilViewMatchesCondition; import static org.chromium.chrome.browser.autofill_assistant.AutofillAssistantUiTestUtil.waitUntilViewMatchesCondition;
...@@ -1133,4 +1136,65 @@ public class AutofillAssistantGenericUiTest { ...@@ -1133,4 +1136,65 @@ public class AutofillAssistantGenericUiTest {
.setDay(13)))) .setDay(13))))
.build())); .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( ...@@ -160,7 +160,11 @@ base::android::ScopedJavaGlobalRef<jobject> CreateJavaView(
env, jview, jcontext, proto.attributes().padding_start(), env, jview, jcontext, proto.attributes().padding_start(),
proto.attributes().padding_top(), proto.attributes().padding_end(), proto.attributes().padding_top(), proto.attributes().padding_end(),
proto.attributes().padding_bottom(), 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()) { if (proto.has_layout_params()) {
Java_AssistantViewFactory_setViewLayoutParams( Java_AssistantViewFactory_setViewLayoutParams(
......
...@@ -86,6 +86,12 @@ message ViewAttributesProto { ...@@ -86,6 +86,12 @@ message ViewAttributesProto {
optional int32 padding_bottom = 4; optional int32 padding_bottom = 4;
optional DrawableProto background = 5; 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. // Parameters configuring how views attach to their parents.
...@@ -184,4 +190,4 @@ message InfoPopupProto { ...@@ -184,4 +190,4 @@ message InfoPopupProto {
optional DialogButton negative_button = 4; optional DialogButton negative_button = 4;
// Optional: adds a neutral button. // Optional: adds a neutral button.
optional DialogButton neutral_button = 5; optional DialogButton neutral_button = 5;
} }
\ No newline at end of file
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