Commit f8ad1a6a authored by Mei Liang's avatar Mei Liang Committed by Commit Bot

Update a11y announcement for selectable tab in TabSelectionEditor

This CL uses AccessibilityNodeInfo to set the checked state of the
selectable tab, so it can be used by the accessibility services.

Bug: 1117205
Change-Id: Ia42b44fc2c280ceb690c2b08114368279a541d68
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2380412
Commit-Queue: Mei Liang <meiliang@chromium.org>
Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#802840}
parent ffe5e9df
......@@ -9,6 +9,7 @@ import android.graphics.drawable.Drawable;
import android.graphics.drawable.InsetDrawable;
import android.util.AttributeSet;
import android.view.View;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.ImageView;
import androidx.core.content.res.ResourcesCompat;
......@@ -69,4 +70,12 @@ public class SelectableTabGridView extends SelectableItemView<Integer> {
@Override
protected void updateView(boolean animate) {}
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(info);
info.setCheckable(true);
info.setChecked(isChecked());
}
}
......@@ -108,7 +108,6 @@ class TabGridViewBinder {
} else if (TabProperties.IS_SELECTED == propertyKey) {
int selectedTabBackground =
model.get(TabProperties.SELECTED_TAB_BACKGROUND_DRAWABLE_ID);
view.setSelected(model.get(TabProperties.IS_SELECTED));
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
if (model.get(TabProperties.IS_SELECTED)) {
view.fastFindViewById(R.id.selected_view_below_lollipop)
......@@ -229,6 +228,8 @@ class TabGridViewBinder {
int iconDrawableId = model.get(TabProperties.SEARCH_CHIP_ICON_DRAWABLE_ID);
boolean shouldTint = iconDrawableId != R.drawable.ic_logo_googleg_24dp;
searchButton.setIcon(iconDrawableId, shouldTint);
} else if (TabProperties.IS_SELECTED == propertyKey) {
view.setSelected(model.get(TabProperties.IS_SELECTED));
}
}
......@@ -264,11 +265,6 @@ class TabGridViewBinder {
model.get(TabProperties.SELECTABLE_TAB_CLICKED_LISTENER).run(tabId);
return ((SelectableTabGridView) view).onLongClick(view);
});
} else if (TabProperties.TITLE == propertyKey) {
String title = model.get(TabProperties.TITLE);
view.fastFindViewById(R.id.action_button)
.setContentDescription(view.getResources().getString(
R.string.accessibility_tabstrip_btn_close_tab, title));
} else if (TabProperties.TAB_SELECTION_DELEGATE == propertyKey) {
assert model.get(TabProperties.TAB_SELECTION_DELEGATE) != null;
......
......@@ -12,7 +12,6 @@ import android.view.LayoutInflater;
import android.view.ViewGroup;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
......@@ -208,8 +207,14 @@ class TabSelectionEditorCoordinator {
/**
* @return The {@link TabSelectionEditorLayout} for testing.
*/
@VisibleForTesting
public TabSelectionEditorLayout getTabSelectionEditorLayoutForTesting() {
TabSelectionEditorLayout getTabSelectionEditorLayoutForTesting() {
return mTabSelectionEditorLayout;
}
/**
* @return The {@link TabListRecyclerView} for testing.
*/
TabListRecyclerView getTabListRecyclerViewForTesting() {
return mTabListCoordinator.getContainerView();
}
}
......@@ -4,8 +4,12 @@
package org.chromium.chrome.browser.tasks.tab_management;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import android.os.Build.VERSION_CODES;
import android.support.test.InstrumentationRegistry;
import android.view.View;
import android.view.ViewGroup;
import androidx.test.filters.MediumTest;
......@@ -486,6 +490,27 @@ public class TabSelectionEditorTest {
CriteriaHelper.pollUiThread(() -> GarbageCollectionTestUtils.canBeGarbageCollected(mRef));
}
@Test
@MediumTest
public void testSelectionTabAccessibilityString() {
prepareBlankTab(2, false);
List<Tab> tabs = getTabsInCurrentTabModel();
String expectedAccessibilityString = "Select about:blank tab";
TestThreadUtils.runOnUiThreadBlocking(() -> mTabSelectionEditorController.show(tabs));
mRobot.resultRobot.verifyTabSelectionEditorIsVisible();
// Test deselected tab
View tabView = mTabSelectionEditorCoordinator.getTabListRecyclerViewForTesting()
.findViewHolderForAdapterPosition(0)
.itemView;
assertFalse(tabView.createAccessibilityNodeInfo().isChecked());
// Test selected tab
mRobot.actionRobot.clickItemAtAdapterPosition(0);
assertTrue(tabView.createAccessibilityNodeInfo().isChecked());
}
private List<Tab> getTabsInCurrentTabModel() {
List<Tab> tabs = new ArrayList<>();
......
......@@ -84,7 +84,7 @@ public class TabSelectionEditorTestingRobot {
protected boolean matchesSafely(SelectableTabGridView selectableTabGridView) {
mSelectableTabGridView = selectableTabGridView;
return mSelectableTabGridView.isSelected() && actionButtonSelected()
return mSelectableTabGridView.isChecked() && actionButtonSelected()
&& highlightIndicatorIsVisible();
}
......
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