Commit 592dc9e4 authored by Mei Liang's avatar Mei Liang Committed by Commit Bot

[a11y] Enable GTS for accessibility (2/2)

This CL enables the new Tab Switcher in list version when TalkBack is on
for LowEnd phone.

Change-Id: If8d1f0dd54624be8ec66eeb953fffbc9a30c34a2
Bug: 992134
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2045072
Commit-Queue: Wei-Yin Chen (陳威尹) <wychen@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#747646}
parent 69c86691
......@@ -5,6 +5,7 @@
package org.chromium.chrome.browser.device;
import org.chromium.base.CommandLine;
import org.chromium.base.ContextUtils;
import org.chromium.base.SysUtils;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.flags.ChromeSwitches;
......@@ -44,9 +45,7 @@ public class DeviceClassManager {
// Device based configurations.
if (SysUtils.isLowEndDevice()) {
mEnableLayerDecorationCache = true;
mEnableAccessibilityLayout =
!ChromeFeatureList.isEnabled(ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID)
|| !ChromeFeatureList.isEnabled(ChromeFeatureList.TAB_GROUPS_ANDROID);
mEnableAccessibilityLayout = true;
mEnableAnimations = false;
mEnablePrerendering = false;
mEnableToolbarSwipe = false;
......@@ -87,9 +86,15 @@ public class DeviceClassManager {
* @return Whether or not should use the accessibility tab switcher.
*/
public static boolean enableAccessibilityLayout() {
if (ChromeFeatureList.isEnabled(ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID)) {
if (isPhone()
&& ChromeFeatureList.isEnabled(ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID)
&& (ChromeFeatureList.isEnabled(ChromeFeatureList.TAB_GROUPS_ANDROID)
|| (!SysUtils.isLowEndDevice()
&& ChromeFeatureList.isEnabled(
ChromeFeatureList.TAB_GRID_LAYOUT_ANDROID)))) {
return false;
}
if (getInstance().mEnableAccessibilityLayout) return true;
if (!AccessibilityUtil.isAccessibilityEnabled()) return false;
return SharedPreferencesManager.getInstance().readBoolean(
......@@ -126,4 +131,9 @@ public class DeviceClassManager {
public static boolean enableToolbarSwipe() {
return getInstance().mEnableToolbarSwipe;
}
private static boolean isPhone() {
return !DeviceFormFactor.isNonMultiDisplayContextOnTablet(
ContextUtils.getApplicationContext());
}
}
......@@ -54,6 +54,7 @@ import org.chromium.chrome.browser.util.AccessibilityUtil;
import org.chromium.chrome.features.start_surface.StartSurfaceLayout;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.chrome.test.util.ApplicationTestUtils;
import org.chromium.chrome.test.util.browser.Features;
import org.chromium.chrome.test.util.browser.tabmodel.MockTabModel.MockTabModelDelegate;
import org.chromium.chrome.test.util.browser.tabmodel.MockTabModelSelector;
......@@ -527,61 +528,57 @@ public class LayoutManagerTest implements MockTabModelDelegate {
@Feature({"Android-TabSwitcher"})
// clang-format off
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
@Features.DisableFeatures({ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID})
public void testStartSurfaceLayoutDisabled() {
@Features.EnableFeatures({ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID})
@Features.DisableFeatures({ChromeFeatureList.TAB_GROUPS_ANDROID})
public void testStartSurfaceLayout_Disabled_LowEndPhone() throws Exception {
// clang-format on
CachedFeatureFlags.setForTesting(ChromeFeatureList.TAB_GRID_LAYOUT_ANDROID, false);
launchedChromeAndEnterTabSwitcher();
CachedFeatureFlags.setForTesting(ChromeFeatureList.TAB_GRID_LAYOUT_ANDROID, true);
verifyOverviewListLayoutEnabled();
TestThreadUtils.runOnUiThreadBlocking(() -> {
Layout activeLayout = getActiveLayout();
Assert.assertTrue(activeLayout instanceof OverviewListLayout);
});
ApplicationTestUtils.finishActivity(mActivityTestRule.getActivity());
CachedFeatureFlags.setForTesting(ChromeFeatureList.TAB_GROUPS_ANDROID, false);
verifyOverviewListLayoutEnabled();
// Test accessibility
ApplicationTestUtils.finishActivity(mActivityTestRule.getActivity());
AccessibilityUtil.setAccessibilityEnabledForTesting(true);
verifyOverviewListLayoutEnabled();
}
@Test
@MediumTest
@Restriction({UiRestriction.RESTRICTION_TYPE_PHONE})
@Restriction({UiRestriction.RESTRICTION_TYPE_PHONE, RESTRICTION_TYPE_NON_LOW_END_DEVICE})
@Feature({"Android-TabSwitcher"})
// clang-format off
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
@Features.DisableFeatures({ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID})
public void testStartSurfaceLayoutDisabled_Accessibility() {
@Features.EnableFeatures({ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID})
@Features.DisableFeatures({ChromeFeatureList.TAB_GROUPS_ANDROID,
ChromeFeatureList.TAB_GRID_LAYOUT_ANDROID})
public void testStartSurfaceLayout_Disabled_HighEndPhone() throws Exception {
// clang-format on
CachedFeatureFlags.setForTesting(ChromeFeatureList.TAB_GRID_LAYOUT_ANDROID, true);
CachedFeatureFlags.setForTesting(ChromeFeatureList.TAB_GROUPS_ANDROID, true);
AccessibilityUtil.setAccessibilityEnabledForTesting(true);
launchedChromeAndEnterTabSwitcher();
CachedFeatureFlags.setForTesting(ChromeFeatureList.TAB_GRID_LAYOUT_ANDROID, false);
CachedFeatureFlags.setForTesting(ChromeFeatureList.TAB_GROUPS_ANDROID, false);
verifyStackLayoutEnabled();
TestThreadUtils.runOnUiThreadBlocking(() -> {
Layout activeLayout = getActiveLayout();
Assert.assertTrue(activeLayout instanceof OverviewListLayout);
});
// Verify accessibility
ApplicationTestUtils.finishActivity(mActivityTestRule.getActivity());
AccessibilityUtil.setAccessibilityEnabledForTesting(true);
verifyOverviewListLayoutEnabled();
}
@Test
@MediumTest
@Restriction({UiRestriction.RESTRICTION_TYPE_PHONE, RESTRICTION_TYPE_NON_LOW_END_DEVICE})
@Restriction({UiRestriction.RESTRICTION_TYPE_PHONE})
@Feature({"Android-TabSwitcher"})
// clang-format off
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
@Features.EnableFeatures({ChromeFeatureList.TAB_GRID_LAYOUT_ANDROID})
public void testStartSurfaceLayoutEnabled_Grid() {
@Features.DisableFeatures({ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID})
public void testStartSurfaceLayout_Disabled_AllPhone_Accessibility_WithoutContinuationFlag() {
// clang-format on
CachedFeatureFlags.setForTesting(ChromeFeatureList.TAB_GRID_LAYOUT_ANDROID, true);
launchedChromeAndEnterTabSwitcher();
TestThreadUtils.runOnUiThreadBlocking(() -> {
Layout activeLayout = getActiveLayout();
Assert.assertTrue(activeLayout instanceof StartSurfaceLayout);
StartSurfaceLayout startSurfaceLayout = (StartSurfaceLayout) activeLayout;
Assert.assertEquals(TabListCoordinator.TabListMode.GRID,
startSurfaceLayout.getStartSurfaceForTesting()
.getTabListDelegate()
.getListModeForTesting());
});
CachedFeatureFlags.setForTesting(ChromeFeatureList.TAB_GROUPS_ANDROID, true);
AccessibilityUtil.setAccessibilityEnabledForTesting(true);
verifyOverviewListLayoutEnabled();
}
@Test
......@@ -590,26 +587,21 @@ public class LayoutManagerTest implements MockTabModelDelegate {
@Feature({"Android-TabSwitcher"})
// clang-format off
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
@Features.EnableFeatures({ChromeFeatureList.TAB_GRID_LAYOUT_ANDROID,
ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID})
public void testStartSurfaceLayoutEnabled_Grid_Accessibility() {
@Features.EnableFeatures({ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID})
public void testStartSurfaceLayout_Enabled_HighEndPhone() throws Exception {
// clang-format on
CachedFeatureFlags.setForTesting(ChromeFeatureList.TAB_GRID_LAYOUT_ANDROID, true);
CachedFeatureFlags.setForTesting(ChromeFeatureList.TAB_GROUPS_ANDROID, true);
AccessibilityUtil.setAccessibilityEnabledForTesting(true);
launchedChromeAndEnterTabSwitcher();
TestThreadUtils.runOnUiThreadBlocking(() -> {
Layout activeLayout = getActiveLayout();
Assert.assertTrue(activeLayout instanceof StartSurfaceLayout);
verifyStartSurfaceLayoutEnable(TabListCoordinator.TabListMode.GRID);
StartSurfaceLayout startSurfaceLayout = (StartSurfaceLayout) activeLayout;
ApplicationTestUtils.finishActivity(mActivityTestRule.getActivity());
CachedFeatureFlags.setForTesting(ChromeFeatureList.TAB_GRID_LAYOUT_ANDROID, false);
CachedFeatureFlags.setForTesting(ChromeFeatureList.TAB_GROUPS_ANDROID, true);
verifyStartSurfaceLayoutEnable(TabListCoordinator.TabListMode.GRID);
Assert.assertEquals(TabListCoordinator.TabListMode.GRID,
startSurfaceLayout.getStartSurfaceForTesting()
.getTabListDelegate()
.getListModeForTesting());
});
// Verify accessibility
ApplicationTestUtils.finishActivity(mActivityTestRule.getActivity());
AccessibilityUtil.setAccessibilityEnabledForTesting(true);
verifyStartSurfaceLayoutEnable(TabListCoordinator.TabListMode.GRID);
}
@Test
......@@ -619,24 +611,17 @@ public class LayoutManagerTest implements MockTabModelDelegate {
// clang-format off
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
@Features.EnableFeatures({ChromeFeatureList.TAB_GROUPS_ANDROID,
ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID})
ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID})
@Features.DisableFeatures(ChromeFeatureList.TAB_TO_GTS_ANIMATION)
public void testStartSurfaceLayoutEnabled_List() {
public void testStartSurfaceLayout_Enabled_LowEndPhone() throws Exception {
// clang-format on
CachedFeatureFlags.setForTesting(ChromeFeatureList.TAB_GROUPS_ANDROID, true);
launchedChromeAndEnterTabSwitcher();
TestThreadUtils.runOnUiThreadBlocking(() -> {
Layout activeLayout = getActiveLayout();
Assert.assertTrue(activeLayout instanceof StartSurfaceLayout);
StartSurfaceLayout startSurfaceLayout = (StartSurfaceLayout) activeLayout;
verifyStartSurfaceLayoutEnable(TabListCoordinator.TabListMode.LIST);
Assert.assertEquals(TabListCoordinator.TabListMode.LIST,
startSurfaceLayout.getStartSurfaceForTesting()
.getTabListDelegate()
.getListModeForTesting());
});
// Test Accessibility
ApplicationTestUtils.finishActivity(mActivityTestRule.getActivity());
AccessibilityUtil.setAccessibilityEnabledForTesting(true);
verifyStartSurfaceLayoutEnable(TabListCoordinator.TabListMode.LIST);
}
@Before
......@@ -653,6 +638,49 @@ public class LayoutManagerTest implements MockTabModelDelegate {
AccessibilityUtil.setAccessibilityEnabledForTesting(null);
}
/**
* Verify {@link StackLayout} is in used. The {@link StackLayout} is used when
* ChromeFeatureList.TAB_GROUPS_ANDROID or ChromeFeatureList.TAB_GRID_LAYOUT_ANDROID is disabled
* in high end phone.
*/
private void verifyStackLayoutEnabled() {
launchedChromeAndEnterTabSwitcher();
TestThreadUtils.runOnUiThreadBlocking(() -> {
Layout activeLayout = getActiveLayout();
Assert.assertTrue(activeLayout instanceof StackLayout);
});
}
/**
* Verify the {@link OverviewListLayout} is in used. The {@link OverviewListLayout} is used when
* accessibility is turned on. It is also used for low end device.
*/
private void verifyOverviewListLayoutEnabled() {
launchedChromeAndEnterTabSwitcher();
TestThreadUtils.runOnUiThreadBlocking(() -> {
Layout activeLayout = getActiveLayout();
Assert.assertTrue(activeLayout instanceof OverviewListLayout);
});
}
private void verifyStartSurfaceLayoutEnable(
@TabListCoordinator.TabListMode int expectedTabListMode) {
launchedChromeAndEnterTabSwitcher();
TestThreadUtils.runOnUiThreadBlocking(() -> {
Layout activeLayout = getActiveLayout();
Assert.assertTrue(activeLayout instanceof StartSurfaceLayout);
StartSurfaceLayout startSurfaceLayout = (StartSurfaceLayout) activeLayout;
Assert.assertEquals(expectedTabListMode,
startSurfaceLayout.getStartSurfaceForTesting()
.getTabListDelegate()
.getListModeForTesting());
});
}
private void launchedChromeAndEnterTabSwitcher() {
mActivityTestRule.startMainActivityOnBlankPage();
CriteriaHelper.pollUiThread(Criteria.equals(true,
......
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