| Index: chrome/android/junit/src/org/chromium/chrome/browser/compositor/overlays/strip/StripLayoutHelperTest.java
|
| diff --git a/chrome/android/junit/src/org/chromium/chrome/browser/compositor/overlays/strip/StripLayoutHelperTest.java b/chrome/android/junit/src/org/chromium/chrome/browser/compositor/overlays/strip/StripLayoutHelperTest.java
|
| index a1da830394c47bfa44758fd6e334f17051d7101d..e4d5d5624766ede7afc1235ba96b9dc6b8648aa8 100644
|
| --- a/chrome/android/junit/src/org/chromium/chrome/browser/compositor/overlays/strip/StripLayoutHelperTest.java
|
| +++ b/chrome/android/junit/src/org/chromium/chrome/browser/compositor/overlays/strip/StripLayoutHelperTest.java
|
| @@ -49,9 +49,15 @@ public class StripLayoutHelperTest {
|
| @Mock private LayoutRenderHost mRenderHost;
|
| private TestTabModel mModel = new TestTabModel();
|
| private StripLayoutHelper mStripLayoutHelper;
|
| + private boolean mIncognito;
|
| private static final String[] TEST_TAB_TITLES = {"Tab 1", "Tab 2", "Tab 3"};
|
| private static final String CLOSE_TAB = "Close tab test string";
|
| private static final String NEW_TAB = "New tab test string";
|
| + private static final String NEW_INCOGNITO_TAB = "New incognito tab test string";
|
| + private static final String IDENTIFIER = "Tab";
|
| + private static final String IDENTIFIER_SELECTED = "Selected Tab";
|
| + private static final String INCOGNITO_IDENTIFIER = "Incognito Tab";
|
| + private static final String INCOGNITO_IDENTIFIER_SELECTED = "Selected Incognito Tab";
|
|
|
| /** Reset the environment before each test. */
|
| @Before
|
| @@ -61,6 +67,16 @@ public class StripLayoutHelperTest {
|
| when(mResources.getString(R.string.accessibility_tabstrip_btn_close_tab)).thenReturn(
|
| CLOSE_TAB);
|
| when(mResources.getString(R.string.accessibility_toolbar_btn_new_tab)).thenReturn(NEW_TAB);
|
| + when(mResources.getString(R.string.accessibility_toolbar_btn_new_incognito_tab))
|
| + .thenReturn(NEW_INCOGNITO_TAB);
|
| + when(mResources.getString(R.string.accessibility_tabstrip_identifier))
|
| + .thenReturn(IDENTIFIER);
|
| + when(mResources.getString(R.string.accessibility_tabstrip_identifier_selected))
|
| + .thenReturn(IDENTIFIER_SELECTED);
|
| + when(mResources.getString(R.string.accessibility_tabstrip_incognito_identifier))
|
| + .thenReturn(INCOGNITO_IDENTIFIER);
|
| + when(mResources.getString(R.string.accessibility_tabstrip_incognito_identifier_selected))
|
| + .thenReturn(INCOGNITO_IDENTIFIER_SELECTED);
|
|
|
| // CompositorButton
|
| when(mResources.getDisplayMetrics()).thenReturn(new DisplayMetrics());
|
| @@ -84,9 +100,9 @@ public class StripLayoutHelperTest {
|
| @Test
|
| @Feature({"Accessibility"})
|
| public void testSimpleTabOrder() {
|
| - initializeTest(false, 0);
|
| + initializeTest(false, false, 0);
|
|
|
| - assertTabStripAndOrder(TEST_TAB_TITLES);
|
| + assertTabStripAndOrder(getExpectedAccessibilityDescriptions(0));
|
| }
|
|
|
| /**
|
| @@ -98,10 +114,10 @@ public class StripLayoutHelperTest {
|
| @Test
|
| @Feature({"Accessibility"})
|
| public void testTabOrderWithIndex() {
|
| - initializeTest(false, 1);
|
| + initializeTest(false, false, 1);
|
|
|
| // Tabs should be in left to right order regardless of index
|
| - assertTabStripAndOrder(TEST_TAB_TITLES);
|
| + assertTabStripAndOrder(getExpectedAccessibilityDescriptions(1));
|
| }
|
|
|
| /**
|
| @@ -112,17 +128,32 @@ public class StripLayoutHelperTest {
|
| @Test
|
| @Feature({"Accessibility"})
|
| public void testTabOrderRtl() {
|
| - initializeTest(true, 0);
|
| + initializeTest(true, false, 0);
|
|
|
| // Tabs should be in linear order even in RTL.
|
| // Android will take care of reversing it.
|
| - assertTabStripAndOrder(TEST_TAB_TITLES);
|
| + assertTabStripAndOrder(getExpectedAccessibilityDescriptions(0));
|
| }
|
|
|
| - private void initializeTest(boolean rtl, int tabIndex) {
|
| - mStripLayoutHelper = createStripLayoutHelper(rtl);
|
| + /**
|
| + * Test method for {@link stripLayoutHelper#getVirtualViews(List<VirtualView>)}.
|
| + *
|
| + * Checks that it returns the correct order of tabs, even in incognito mode.
|
| + */
|
| + @Test
|
| + @Feature({"Accessibility"})
|
| + public void testIncognitoAccessibilityDescriptions() {
|
| + initializeTest(false, true, 0);
|
| +
|
| + assertTabStripAndOrder(getExpectedAccessibilityDescriptions(0));
|
| + }
|
| +
|
| + private void initializeTest(boolean rtl, boolean incognito, int tabIndex) {
|
| + mStripLayoutHelper = createStripLayoutHelper(rtl, incognito);
|
| + mIncognito = incognito;
|
| for (int i = 0; i < TEST_TAB_TITLES.length; i++) {
|
| mModel.addTab(TEST_TAB_TITLES[i]);
|
| + when(mModel.getTabAt(i).isHidden()).thenReturn(tabIndex != i);
|
| }
|
| mModel.setIndex(tabIndex);
|
| mStripLayoutHelper.setTabModel(mModel, null);
|
| @@ -130,33 +161,51 @@ public class StripLayoutHelperTest {
|
| // Flush UI updated
|
| }
|
|
|
| - private void assertTabStripAndOrder(String[] expectedTabTitles) {
|
| + private void assertTabStripAndOrder(String[] expectedAccessibilityDescriptions) {
|
| // Each tab has a "close button", and there is one additional "new tab" button
|
| - final int expectedNumberOfViews = 2 * expectedTabTitles.length + 1;
|
| + final int expectedNumberOfViews = 2 * expectedAccessibilityDescriptions.length + 1;
|
|
|
| final List<VirtualView> views = new ArrayList<VirtualView>();
|
| mStripLayoutHelper.getVirtualViews(views);
|
| assertEquals(expectedNumberOfViews, views.size());
|
|
|
| // Tab titles
|
| - for (int i = 0; i < expectedTabTitles.length - 1; i++) {
|
| - final String expectedTitle = i % 2 == 0
|
| - ? expectedTabTitles[i / 2] : CLOSE_TAB;
|
| - assertEquals(expectedTitle, views.get(i).getAccessibilityDescription());
|
| + for (int i = 0; i < expectedNumberOfViews - 1; i++) {
|
| + final String expectedDescription = i % 2 == 0
|
| + ? expectedAccessibilityDescriptions[i / 2] : CLOSE_TAB;
|
| + assertEquals(expectedDescription, views.get(i).getAccessibilityDescription());
|
| }
|
|
|
| - assertEquals(NEW_TAB, views.get(views.size() - 1).getAccessibilityDescription());
|
| + assertEquals(mIncognito ? NEW_INCOGNITO_TAB : NEW_TAB,
|
| + views.get(views.size() - 1).getAccessibilityDescription());
|
| }
|
|
|
| - private StripLayoutHelper createStripLayoutHelper(boolean rtl) {
|
| + private StripLayoutHelper createStripLayoutHelper(boolean rtl, boolean incognito) {
|
| LocalizationUtils.setRtlForTesting(rtl);
|
| final StripLayoutHelper stripLayoutHelper =
|
| - new StripLayoutHelper(mContext, mUpdateHost, mRenderHost, false);
|
| + new StripLayoutHelper(mContext, mUpdateHost, mRenderHost, incognito);
|
| // Initialize StackScroller
|
| stripLayoutHelper.onContextChanged(mContext);
|
| return stripLayoutHelper;
|
| }
|
|
|
| + private String[] getExpectedAccessibilityDescriptions(int tabIndex) {
|
| + String[] expectedAccessibilityDescriptions = new String[TEST_TAB_TITLES.length];
|
| + for (int i = 0; i < TEST_TAB_TITLES.length; i++) {
|
| + boolean isHidden = (i != tabIndex);
|
| + String suffix = IDENTIFIER;
|
| + if (!isHidden && !mIncognito) {
|
| + suffix = IDENTIFIER_SELECTED;
|
| + } else if (!isHidden && mIncognito) {
|
| + suffix = INCOGNITO_IDENTIFIER_SELECTED;
|
| + } else if (isHidden && mIncognito) {
|
| + suffix = INCOGNITO_IDENTIFIER;
|
| + }
|
| + expectedAccessibilityDescriptions[i] = TEST_TAB_TITLES[i] + ", " + suffix;
|
| + }
|
| + return expectedAccessibilityDescriptions;
|
| + }
|
| +
|
| private class TestTabModel extends EmptyTabModel {
|
| private List<Tab> mMockTabs = new ArrayList<Tab>();
|
| private int mMaxId = -1;
|
| @@ -190,4 +239,4 @@ public class StripLayoutHelperTest {
|
| mIndex = index;
|
| }
|
| }
|
| -}
|
| +}
|
|
|