Index: chrome/android/javatests/src/org/chromium/chrome/browser/compositor/overlays/strip/TabStripTest.java |
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/compositor/overlays/strip/TabStripTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/compositor/overlays/strip/TabStripTest.java |
index 3d060ec9ed3758f5c5f5e927c8153151314dbfa2..b1916e9f78b3dd4c9bdbe3a5a3569c6bccf4ddb4 100644 |
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/compositor/overlays/strip/TabStripTest.java |
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/compositor/overlays/strip/TabStripTest.java |
@@ -22,6 +22,7 @@ import org.chromium.chrome.test.util.ChromeRestriction; |
import org.chromium.chrome.test.util.ChromeTabUtils; |
import org.chromium.chrome.test.util.TabStripUtils; |
import org.chromium.content.browser.test.util.CallbackHelper; |
+import org.chromium.ui.base.LocalizationUtils; |
import java.util.concurrent.TimeoutException; |
@@ -465,6 +466,108 @@ public class TabStripTest extends ChromeTabbedActivityTestBase { |
getActivity().getTabModelSelector().isIncognitoSelected()); |
} |
+ @LargeTest |
+ @Restriction(ChromeRestriction.RESTRICTION_TYPE_TABLET) |
+ @Feature({"TabStrip"}) |
+ public void testSwitchStripStackersWithIncognitoTabSelected() throws InterruptedException { |
+ // Open an incognito tab. |
+ newIncognitoTabFromMenu(); |
+ getInstrumentation().waitForIdleSync(); |
+ |
+ // Switch to the ScrollingStripStacker. |
+ setShouldCascadeTabs(false); |
+ |
+ // Switch to the CascadingStripStacker. |
+ setShouldCascadeTabs(true); |
+ } |
+ |
+ @LargeTest |
+ @Restriction(ChromeRestriction.RESTRICTION_TYPE_TABLET) |
+ @Feature({"TabStrip"}) |
+ public void testSwitchStripStackersWithLastTabSelected() throws InterruptedException { |
+ // Open enough regular tabs to cause the tabs to cascade or the strip to scroll depending |
+ // on which stacker is being used. |
+ ChromeTabUtils.newTabsFromMenu(getInstrumentation(), getActivity(), 10); |
+ getInstrumentation().waitForIdleSync(); |
+ |
+ // Switch to the ScrollingStripStacker. |
+ setShouldCascadeTabs(false); |
+ |
+ // Switch to the CascadingStripStacker. |
+ setShouldCascadeTabs(true); |
+ } |
+ |
+ @LargeTest |
+ @Restriction(ChromeRestriction.RESTRICTION_TYPE_TABLET) |
+ @Feature({"TabStrip"}) |
+ public void testSwitchStripStackersWithFirstTabSelected() throws InterruptedException { |
+ // Open enough regular tabs to cause the tabs to cascade or the strip to scroll depending |
+ // on which stacker is being used. |
+ ChromeTabUtils.newTabsFromMenu(getInstrumentation(), getActivity(), 10); |
+ getInstrumentation().waitForIdleSync(); |
+ |
+ // Select the first tab by setting the index directly. It may not be visible, so don't |
+ // try to tap on it. |
+ ChromeTabUtils.switchTabInCurrentTabModel(getActivity(), 0); |
+ |
+ // Switch to the ScrollingStripStacker. |
+ setShouldCascadeTabs(false); |
+ |
+ // Scroll so the first tab is off screen to verify that switching to the |
+ // CascadingStripStacker makes it visible again. The selected tab should always be visible |
+ // when using the CascadingStripStacker but may not be visible when using the |
+ // ScrollingStripStacker. |
+ scrollTabStrip((int) TabStripUtils.getActiveStripLayoutHelper( |
+ getActivity()).getMinimumScrollOffset()); |
+ StripLayoutTab selectedLayoutTab = TabStripUtils.findStripLayoutTab( |
+ getActivity(), false, getActivity().getCurrentTabModel().getTabAt(0).getId()); |
+ assertTabVisibility(false, selectedLayoutTab); |
+ |
+ // Switch to the CascadingStripStacker. |
+ setShouldCascadeTabs(true); |
+ } |
+ |
+ @LargeTest |
+ @Restriction(ChromeRestriction.RESTRICTION_TYPE_TABLET) |
+ @Feature({"TabStrip"}) |
+ public void testSwitchStripStackersWithMiddleTabSelected() throws InterruptedException { |
+ // Open enough regular tabs to cause the tabs to cascade or the strip to scroll depending |
+ // on which stacker is being used. |
+ ChromeTabUtils.newTabsFromMenu(getInstrumentation(), getActivity(), 10); |
+ getInstrumentation().waitForIdleSync(); |
+ |
+ // Select the fifth tab by setting the index directly. It may not be visible, so don't |
Theresa
2016/04/05 21:11:10
nit: s/fifth/sixth
Theresa
2016/04/06 06:49:51
Done.
|
+ // try to tap on it. |
+ ChromeTabUtils.switchTabInCurrentTabModel(getActivity(), 5); |
+ |
+ // Switch to the ScrollingStripStacker. |
+ setShouldCascadeTabs(false); |
+ |
+ // Switch to the CascadingStripStacker. |
+ setShouldCascadeTabs(true); |
+ } |
+ |
+ @LargeTest |
+ @Restriction(ChromeRestriction.RESTRICTION_TYPE_TABLET) |
+ @Feature({"TabStrip"}) |
+ public void testScrollingStripStackerPartialFadeOpacity() throws InterruptedException { |
+ // Switch to the ScrollingStripStacker. |
+ setShouldCascadeTabs(false); |
+ |
+ // Open enough regular tabs to cause the strip to scroll. |
+ ChromeTabUtils.newTabsFromMenu(getInstrumentation(), getActivity(), 10); |
+ getInstrumentation().waitForIdleSync(); |
+ |
+ // Scroll a little below the minimum scroll offset to cause the right fade (in LTR) to be |
+ // at partial opacity. |
+ scrollTabStrip((int) (TabStripUtils.getActiveStripLayoutHelper( |
+ getActivity()).getMinimumScrollOffset() |
+ + StripLayoutHelper.FADE_FULL_OPACITY_THRESHOLD_DP / 2)); |
+ |
+ // Scroll a little above 0 to cause the left fade (in LTR) to be at partial opacity. |
+ scrollTabStrip((int) (0 - StripLayoutHelper.FADE_FULL_OPACITY_THRESHOLD_DP / 2)); |
+ } |
+ |
/** |
* Take a model index and figure out which index it will be in the TabStrip's view hierarchy. |
* @param tabCount The number of tabs. |
@@ -584,15 +687,22 @@ public class TabStripTest extends ChromeTabbedActivityTestBase { |
&& getActivity().getTabModelSelector().isIncognitoSelected() == incognito) { |
assertTrue("ChromeTab is not in the proper selection state", |
tabStrip.isForegroundTab(tabView)); |
- assertEquals("ChromeTab is not completely visible, but is selected", |
- tabView.getVisiblePercentage(), 1.0f); |
+ if (tabStrip.shouldCascadeTabs()) { |
+ assertEquals("ChromeTab is not completely visible, but is selected. The selected " |
+ + "tab should be visible when the CascadingStripStacker is in use.", |
+ tabView.getVisiblePercentage(), 1.0f); |
+ } |
+ } |
+ |
+ if (!tabStrip.shouldCascadeTabs()) { |
+ checkTabVisibilityForScrollingStripStacker(tabStrip, tabView); |
} |
// TODO(dtrainor): Compare favicon bitmaps? Only compare a few pixels. |
} |
/** |
- * Compares an entire TabStrip with the corresponding TabModel. This tries to compare |
+ * Compares an entire TabStrip with the corresponding TabModel. This tries to compare |
* as many features as possible, including checking all of the tabs through |
* compareTabViewWithModel. It also checks that the incognito indicator is visible if the |
* incognito tab is showing. |
@@ -626,6 +736,8 @@ public class TabStripTest extends ChromeTabbedActivityTestBase { |
for (int i = 0; i < model.getCount(); ++i) { |
compareTabViewWithModel(incognito, model.getTabAt(i).getId()); |
} |
+ |
+ checkTabStripFadeOpacity(strip); |
} |
/** |
@@ -636,4 +748,142 @@ public class TabStripTest extends ChromeTabbedActivityTestBase { |
compareTabStripWithModel(true); |
compareTabStripWithModel(false); |
} |
+ |
+ /** |
+ * Sets whether the strip should cascade tabs and checks for validity. |
+ * |
+ * @param shouldCascadeTabs Whether the {@link CascadingStripStacker} should be used. If false, |
+ * the {@link ScrollingStripStacker} will be used instead. |
+ */ |
+ private void setShouldCascadeTabs(final boolean shouldCascadeTabs) { |
+ TabModel model = getActivity().getCurrentTabModel(); |
+ int selectedTabIndex = model.index(); |
+ |
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
+ @Override |
+ public void run() { |
+ TabStripUtils.getStripLayoutHelper(getActivity(), true).setShouldCascadeTabs( |
+ shouldCascadeTabs); |
+ TabStripUtils.getStripLayoutHelper(getActivity(), false).setShouldCascadeTabs( |
+ shouldCascadeTabs); |
+ } |
+ }); |
+ |
+ // Assert that the correct StripStacker is being used. |
+ assertEquals(shouldCascadeTabs |
+ ? "Expected CascadingStripStacker but was ScrollingStripStacker." |
+ : "Expected ScrollingStripStacker but was CascadingStripStacker.", |
+ shouldCascadeTabs, |
+ TabStripUtils.getActiveStripLayoutHelper(getActivity()).shouldCascadeTabs()); |
+ |
+ // Assert that the same tab is still selected. |
+ assertEquals("The correct tab is not selected.", selectedTabIndex, model.index()); |
+ |
+ // Compare all TabStrips with corresponding TabModels. |
+ compareAllTabStripsWithModel(); |
+ |
+ // The selected tab should always be visible in the CascadingStripStacker and switching to |
+ // the ScrollingStripStacker should auto-scroll to make the selected tab visible. |
+ StripLayoutTab selectedLayoutTab = TabStripUtils.findStripLayoutTab( |
+ getActivity(), model.isIncognito(), model.getTabAt(selectedTabIndex).getId()); |
+ assertTabVisibility(true, selectedLayoutTab); |
+ } |
+ |
+ /** |
+ * Scrolls the tab strip to the desired position and checks for validity. |
+ * |
+ * @param scrollOffset The end scroll position for the tab strip. |
+ */ |
+ private void scrollTabStrip(final int scrollOffset) { |
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
+ @Override |
+ public void run() { |
+ TabStripUtils.getActiveStripLayoutHelper( |
+ getActivity()).setScrollOffsetForTesting(scrollOffset); |
+ } |
+ }); |
+ |
+ compareAllTabStripsWithModel(); |
+ } |
+ |
+ /** |
+ * Checks that the left and right fade opacities are as expected based on the tab's current |
Theresa
2016/04/05 21:11:10
s/tab's/strip's
Theresa
2016/04/06 06:49:51
Done.
|
+ * scroll position and width. |
+ * |
+ * @param strip The active StripLayoutHelper. |
+ */ |
+ private void checkTabStripFadeOpacity(StripLayoutHelper strip) { |
+ if (!strip.shouldCascadeTabs()) { |
+ boolean isRtl = LocalizationUtils.isLayoutRtl(); |
+ |
+ // In LTR, scroll position 0 is on the left side of the screen. As you scroll right, |
+ // the scroll offset decreases. |
+ float leftOffset = -(!isRtl ? strip.getScrollOffset() |
+ : (strip.getMinimumScrollOffset() - strip.getScrollOffset())); |
+ if (leftOffset >= StripLayoutHelper.FADE_FULL_OPACITY_THRESHOLD_DP) { |
+ assertEquals("Expected left fade to be at full opacity.", 1.f, |
+ strip.getLeftFadeOpacity()); |
+ } else if (leftOffset == 0.f) { |
+ assertEquals("Expected left fade to be hidden.", 0.f, |
+ strip.getLeftFadeOpacity()); |
+ } else { |
+ boolean isPartialOpacity = strip.getLeftFadeOpacity() > 0.f |
+ && strip.getLeftFadeOpacity() < 1.f; |
+ assertTrue("Expected left fade to be at partial opacity but was " |
+ + strip.getLeftFadeOpacity() + " instead.", isPartialOpacity); |
+ } |
+ |
+ // In RTL, scroll position 0 is on the right side of the screen. As you scroll left, |
+ // the scroll offset decreases. |
+ float rightOffset = -(isRtl ? strip.getScrollOffset() |
+ : (strip.getMinimumScrollOffset() - strip.getScrollOffset())); |
+ if (rightOffset >= StripLayoutHelper.FADE_FULL_OPACITY_THRESHOLD_DP) { |
+ assertEquals("Expected right fade to be at full opacity.", 1.f, |
+ strip.getRightFadeOpacity()); |
+ } else if (rightOffset == 0.f) { |
+ assertEquals("Expected right fade to be hidden.", 0.f, |
+ strip.getRightFadeOpacity()); |
+ } else { |
+ boolean isPartialOpacity = strip.getRightFadeOpacity() > 0.f |
+ && strip.getRightFadeOpacity() < 1.f; |
+ assertTrue("Expected right fade to be at partial opacity but was " |
+ + strip.getRightFadeOpacity() + " instead.", isPartialOpacity); |
+ } |
+ } else { |
+ assertEquals("CascadingStripStacker should not have a left fade.", 0.f, |
+ strip.getLeftFadeOpacity()); |
+ assertEquals("CascadingStripStacker should not have a right fade.", 0.f, |
+ strip.getRightFadeOpacity()); |
+ } |
+ } |
+ |
+ /** |
+ * Checks visible percentage and visibility for the given tab. Should only be called when the |
+ * ScrollingStripStacker is in use. |
+ * |
+ * @param tabStrip The StripLayoutHelper that owns the tab. |
+ * @param tabView The StripLayoutTab associated with the tab to check. |
+ */ |
+ private void checkTabVisibilityForScrollingStripStacker(StripLayoutHelper tabStrip, |
+ StripLayoutTab tabView) { |
+ // The visible percent for all tabs is 1.0 in the ScrollingStripStacker. |
+ assertEquals("ChromeTab is not completely visible. All tabs should be visible when " |
+ + "the ScrollingStripStacker is in use.", |
+ tabView.getVisiblePercentage(), 1.0f); |
+ |
+ // Only tabs that can currently be seen on the screen should be visible. |
+ boolean shouldBeVisible = (tabView.getDrawX() + tabView.getWidth()) >= 0 |
+ && tabView.getDrawX() <= tabStrip.getWidth(); |
+ assertTabVisibility(shouldBeVisible, tabView); |
+ } |
+ |
+ /** |
+ * Asserts whether a tab should be visible. |
+ * @param shouldBeVisible Whether the tab should be visible. |
+ * @param tabView The StripLayoutTab associated with the tab to check. |
+ */ |
+ private void assertTabVisibility(boolean shouldBeVisible, StripLayoutTab tabView) { |
+ assertEquals("ChromeTab " + (shouldBeVisible ? "should" : "should not") + " be visible.", |
+ shouldBeVisible, tabView.isVisible()); |
+ } |
} |