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 @@ ...@@ -5,6 +5,7 @@
package org.chromium.chrome.browser.device; package org.chromium.chrome.browser.device;
import org.chromium.base.CommandLine; import org.chromium.base.CommandLine;
import org.chromium.base.ContextUtils;
import org.chromium.base.SysUtils; import org.chromium.base.SysUtils;
import org.chromium.chrome.browser.flags.ChromeFeatureList; import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.flags.ChromeSwitches; import org.chromium.chrome.browser.flags.ChromeSwitches;
...@@ -44,9 +45,7 @@ public class DeviceClassManager { ...@@ -44,9 +45,7 @@ public class DeviceClassManager {
// Device based configurations. // Device based configurations.
if (SysUtils.isLowEndDevice()) { if (SysUtils.isLowEndDevice()) {
mEnableLayerDecorationCache = true; mEnableLayerDecorationCache = true;
mEnableAccessibilityLayout = mEnableAccessibilityLayout = true;
!ChromeFeatureList.isEnabled(ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID)
|| !ChromeFeatureList.isEnabled(ChromeFeatureList.TAB_GROUPS_ANDROID);
mEnableAnimations = false; mEnableAnimations = false;
mEnablePrerendering = false; mEnablePrerendering = false;
mEnableToolbarSwipe = false; mEnableToolbarSwipe = false;
...@@ -87,9 +86,15 @@ public class DeviceClassManager { ...@@ -87,9 +86,15 @@ public class DeviceClassManager {
* @return Whether or not should use the accessibility tab switcher. * @return Whether or not should use the accessibility tab switcher.
*/ */
public static boolean enableAccessibilityLayout() { 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; return false;
} }
if (getInstance().mEnableAccessibilityLayout) return true; if (getInstance().mEnableAccessibilityLayout) return true;
if (!AccessibilityUtil.isAccessibilityEnabled()) return false; if (!AccessibilityUtil.isAccessibilityEnabled()) return false;
return SharedPreferencesManager.getInstance().readBoolean( return SharedPreferencesManager.getInstance().readBoolean(
...@@ -126,4 +131,9 @@ public class DeviceClassManager { ...@@ -126,4 +131,9 @@ public class DeviceClassManager {
public static boolean enableToolbarSwipe() { public static boolean enableToolbarSwipe() {
return getInstance().mEnableToolbarSwipe; return getInstance().mEnableToolbarSwipe;
} }
private static boolean isPhone() {
return !DeviceFormFactor.isNonMultiDisplayContextOnTablet(
ContextUtils.getApplicationContext());
}
} }
...@@ -54,6 +54,7 @@ import org.chromium.chrome.browser.util.AccessibilityUtil; ...@@ -54,6 +54,7 @@ import org.chromium.chrome.browser.util.AccessibilityUtil;
import org.chromium.chrome.features.start_surface.StartSurfaceLayout; import org.chromium.chrome.features.start_surface.StartSurfaceLayout;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule; 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.Features;
import org.chromium.chrome.test.util.browser.tabmodel.MockTabModel.MockTabModelDelegate; import org.chromium.chrome.test.util.browser.tabmodel.MockTabModel.MockTabModelDelegate;
import org.chromium.chrome.test.util.browser.tabmodel.MockTabModelSelector; import org.chromium.chrome.test.util.browser.tabmodel.MockTabModelSelector;
...@@ -527,61 +528,57 @@ public class LayoutManagerTest implements MockTabModelDelegate { ...@@ -527,61 +528,57 @@ public class LayoutManagerTest implements MockTabModelDelegate {
@Feature({"Android-TabSwitcher"}) @Feature({"Android-TabSwitcher"})
// clang-format off // clang-format off
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
@Features.DisableFeatures({ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID}) @Features.EnableFeatures({ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID})
public void testStartSurfaceLayoutDisabled() { @Features.DisableFeatures({ChromeFeatureList.TAB_GROUPS_ANDROID})
public void testStartSurfaceLayout_Disabled_LowEndPhone() throws Exception {
// clang-format on // clang-format on
CachedFeatureFlags.setForTesting(ChromeFeatureList.TAB_GRID_LAYOUT_ANDROID, false); CachedFeatureFlags.setForTesting(ChromeFeatureList.TAB_GRID_LAYOUT_ANDROID, true);
launchedChromeAndEnterTabSwitcher(); verifyOverviewListLayoutEnabled();
TestThreadUtils.runOnUiThreadBlocking(() -> { ApplicationTestUtils.finishActivity(mActivityTestRule.getActivity());
Layout activeLayout = getActiveLayout(); CachedFeatureFlags.setForTesting(ChromeFeatureList.TAB_GROUPS_ANDROID, false);
Assert.assertTrue(activeLayout instanceof OverviewListLayout); verifyOverviewListLayoutEnabled();
});
// Test accessibility
ApplicationTestUtils.finishActivity(mActivityTestRule.getActivity());
AccessibilityUtil.setAccessibilityEnabledForTesting(true);
verifyOverviewListLayoutEnabled();
} }
@Test @Test
@MediumTest @MediumTest
@Restriction({UiRestriction.RESTRICTION_TYPE_PHONE}) @Restriction({UiRestriction.RESTRICTION_TYPE_PHONE, RESTRICTION_TYPE_NON_LOW_END_DEVICE})
@Feature({"Android-TabSwitcher"}) @Feature({"Android-TabSwitcher"})
// clang-format off // clang-format off
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
@Features.DisableFeatures({ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID}) @Features.EnableFeatures({ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID})
public void testStartSurfaceLayoutDisabled_Accessibility() { @Features.DisableFeatures({ChromeFeatureList.TAB_GROUPS_ANDROID,
ChromeFeatureList.TAB_GRID_LAYOUT_ANDROID})
public void testStartSurfaceLayout_Disabled_HighEndPhone() throws Exception {
// clang-format on // clang-format on
CachedFeatureFlags.setForTesting(ChromeFeatureList.TAB_GRID_LAYOUT_ANDROID, true); CachedFeatureFlags.setForTesting(ChromeFeatureList.TAB_GRID_LAYOUT_ANDROID, false);
CachedFeatureFlags.setForTesting(ChromeFeatureList.TAB_GROUPS_ANDROID, true); CachedFeatureFlags.setForTesting(ChromeFeatureList.TAB_GROUPS_ANDROID, false);
AccessibilityUtil.setAccessibilityEnabledForTesting(true); verifyStackLayoutEnabled();
launchedChromeAndEnterTabSwitcher();
TestThreadUtils.runOnUiThreadBlocking(() -> { // Verify accessibility
Layout activeLayout = getActiveLayout(); ApplicationTestUtils.finishActivity(mActivityTestRule.getActivity());
Assert.assertTrue(activeLayout instanceof OverviewListLayout); AccessibilityUtil.setAccessibilityEnabledForTesting(true);
}); verifyOverviewListLayoutEnabled();
} }
@Test @Test
@MediumTest @MediumTest
@Restriction({UiRestriction.RESTRICTION_TYPE_PHONE, RESTRICTION_TYPE_NON_LOW_END_DEVICE}) @Restriction({UiRestriction.RESTRICTION_TYPE_PHONE})
@Feature({"Android-TabSwitcher"}) @Feature({"Android-TabSwitcher"})
// clang-format off // clang-format off
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
@Features.EnableFeatures({ChromeFeatureList.TAB_GRID_LAYOUT_ANDROID}) @Features.DisableFeatures({ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID})
public void testStartSurfaceLayoutEnabled_Grid() { public void testStartSurfaceLayout_Disabled_AllPhone_Accessibility_WithoutContinuationFlag() {
// clang-format on // clang-format on
CachedFeatureFlags.setForTesting(ChromeFeatureList.TAB_GRID_LAYOUT_ANDROID, true); CachedFeatureFlags.setForTesting(ChromeFeatureList.TAB_GRID_LAYOUT_ANDROID, true);
launchedChromeAndEnterTabSwitcher(); CachedFeatureFlags.setForTesting(ChromeFeatureList.TAB_GROUPS_ANDROID, true);
AccessibilityUtil.setAccessibilityEnabledForTesting(true);
TestThreadUtils.runOnUiThreadBlocking(() -> { verifyOverviewListLayoutEnabled();
Layout activeLayout = getActiveLayout();
Assert.assertTrue(activeLayout instanceof StartSurfaceLayout);
StartSurfaceLayout startSurfaceLayout = (StartSurfaceLayout) activeLayout;
Assert.assertEquals(TabListCoordinator.TabListMode.GRID,
startSurfaceLayout.getStartSurfaceForTesting()
.getTabListDelegate()
.getListModeForTesting());
});
} }
@Test @Test
...@@ -590,26 +587,21 @@ public class LayoutManagerTest implements MockTabModelDelegate { ...@@ -590,26 +587,21 @@ public class LayoutManagerTest implements MockTabModelDelegate {
@Feature({"Android-TabSwitcher"}) @Feature({"Android-TabSwitcher"})
// clang-format off // clang-format off
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
@Features.EnableFeatures({ChromeFeatureList.TAB_GRID_LAYOUT_ANDROID, @Features.EnableFeatures({ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID})
ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID}) public void testStartSurfaceLayout_Enabled_HighEndPhone() throws Exception {
public void testStartSurfaceLayoutEnabled_Grid_Accessibility() {
// clang-format on // clang-format on
CachedFeatureFlags.setForTesting(ChromeFeatureList.TAB_GRID_LAYOUT_ANDROID, true); CachedFeatureFlags.setForTesting(ChromeFeatureList.TAB_GRID_LAYOUT_ANDROID, true);
CachedFeatureFlags.setForTesting(ChromeFeatureList.TAB_GROUPS_ANDROID, true); verifyStartSurfaceLayoutEnable(TabListCoordinator.TabListMode.GRID);
AccessibilityUtil.setAccessibilityEnabledForTesting(true);
launchedChromeAndEnterTabSwitcher();
TestThreadUtils.runOnUiThreadBlocking(() -> {
Layout activeLayout = getActiveLayout();
Assert.assertTrue(activeLayout instanceof StartSurfaceLayout);
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, // Verify accessibility
startSurfaceLayout.getStartSurfaceForTesting() ApplicationTestUtils.finishActivity(mActivityTestRule.getActivity());
.getTabListDelegate() AccessibilityUtil.setAccessibilityEnabledForTesting(true);
.getListModeForTesting()); verifyStartSurfaceLayoutEnable(TabListCoordinator.TabListMode.GRID);
});
} }
@Test @Test
...@@ -619,24 +611,17 @@ public class LayoutManagerTest implements MockTabModelDelegate { ...@@ -619,24 +611,17 @@ public class LayoutManagerTest implements MockTabModelDelegate {
// clang-format off // clang-format off
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
@Features.EnableFeatures({ChromeFeatureList.TAB_GROUPS_ANDROID, @Features.EnableFeatures({ChromeFeatureList.TAB_GROUPS_ANDROID,
ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID}) ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID})
@Features.DisableFeatures(ChromeFeatureList.TAB_TO_GTS_ANIMATION) @Features.DisableFeatures(ChromeFeatureList.TAB_TO_GTS_ANIMATION)
public void testStartSurfaceLayoutEnabled_List() { public void testStartSurfaceLayout_Enabled_LowEndPhone() throws Exception {
// clang-format on // clang-format on
CachedFeatureFlags.setForTesting(ChromeFeatureList.TAB_GROUPS_ANDROID, true); CachedFeatureFlags.setForTesting(ChromeFeatureList.TAB_GROUPS_ANDROID, true);
launchedChromeAndEnterTabSwitcher(); verifyStartSurfaceLayoutEnable(TabListCoordinator.TabListMode.LIST);
TestThreadUtils.runOnUiThreadBlocking(() -> {
Layout activeLayout = getActiveLayout();
Assert.assertTrue(activeLayout instanceof StartSurfaceLayout);
StartSurfaceLayout startSurfaceLayout = (StartSurfaceLayout) activeLayout;
Assert.assertEquals(TabListCoordinator.TabListMode.LIST, // Test Accessibility
startSurfaceLayout.getStartSurfaceForTesting() ApplicationTestUtils.finishActivity(mActivityTestRule.getActivity());
.getTabListDelegate() AccessibilityUtil.setAccessibilityEnabledForTesting(true);
.getListModeForTesting()); verifyStartSurfaceLayoutEnable(TabListCoordinator.TabListMode.LIST);
});
} }
@Before @Before
...@@ -653,6 +638,49 @@ public class LayoutManagerTest implements MockTabModelDelegate { ...@@ -653,6 +638,49 @@ public class LayoutManagerTest implements MockTabModelDelegate {
AccessibilityUtil.setAccessibilityEnabledForTesting(null); 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() { private void launchedChromeAndEnterTabSwitcher() {
mActivityTestRule.startMainActivityOnBlankPage(); mActivityTestRule.startMainActivityOnBlankPage();
CriteriaHelper.pollUiThread(Criteria.equals(true, 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