Commit 7e095c83 authored by Yue Zhang's avatar Yue Zhang Committed by Commit Bot

Clean up TabSwitcherMultiWindowTest

* Instead of holding on to references of RecyclerViews to check tab
  switcher state within two Activities, use Espresso style checks.
  Benefits of doing so are: 1) Espresso style requires us to use
  moveActivityToFront() to bring current activity to the front, which
  makes tests more readable. 2) It aligns better with the approach that
  we are using across tab_ui.
* Use helper functions from TabUiTestHelper.

Bug: 1017141
Change-Id: I939fc48f258a0c0b8089fd91a1492f0479370cf6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2145076Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Commit-Queue: Yue Zhang <yuezhanggg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759136}
parent c9a92f74
...@@ -12,7 +12,6 @@ import static android.support.test.espresso.contrib.RecyclerViewActions.actionOn ...@@ -12,7 +12,6 @@ import static android.support.test.espresso.contrib.RecyclerViewActions.actionOn
import static android.support.test.espresso.matcher.ViewMatchers.Visibility.GONE; import static android.support.test.espresso.matcher.ViewMatchers.Visibility.GONE;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.isRoot; import static android.support.test.espresso.matcher.ViewMatchers.isRoot;
import static android.support.test.espresso.matcher.ViewMatchers.withContentDescription;
import static android.support.test.espresso.matcher.ViewMatchers.withEffectiveVisibility; import static android.support.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
import static android.support.test.espresso.matcher.ViewMatchers.withId; import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withParent; import static android.support.test.espresso.matcher.ViewMatchers.withParent;
...@@ -33,10 +32,10 @@ import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.c ...@@ -33,10 +32,10 @@ import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.c
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.enterTabSwitcher; import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.enterTabSwitcher;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.getSwipeToDismissAction; import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.getSwipeToDismissAction;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.rotateDeviceToOrientation; import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.rotateDeviceToOrientation;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.switchTabModel;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.verifyTabModelTabCount; import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.verifyTabModelTabCount;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.verifyTabSwitcherCardCount; import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.verifyTabSwitcherCardCount;
import static org.chromium.chrome.test.util.ViewUtils.waitForView; import static org.chromium.chrome.test.util.ViewUtils.waitForView;
import static org.chromium.chrome.test.util.browser.RecyclerViewTestUtils.waitForStableRecyclerView;
import static org.chromium.components.embedder_support.util.UrlConstants.NTP_URL; import static org.chromium.components.embedder_support.util.UrlConstants.NTP_URL;
import static org.chromium.content_public.browser.test.util.CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL; import static org.chromium.content_public.browser.test.util.CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL;
import static org.chromium.content_public.browser.test.util.CriteriaHelper.DEFAULT_POLLING_INTERVAL; import static org.chromium.content_public.browser.test.util.CriteriaHelper.DEFAULT_POLLING_INTERVAL;
...@@ -675,6 +674,7 @@ public class StartSurfaceLayoutTest { ...@@ -675,6 +674,7 @@ public class StartSurfaceLayoutTest {
message = "https://crbug.com/1023833") message = "https://crbug.com/1023833")
public void testIncognitoToggle_tabCount() throws InterruptedException { public void testIncognitoToggle_tabCount() throws InterruptedException {
mActivityTestRule.loadUrl(mUrl); mActivityTestRule.loadUrl(mUrl);
ChromeTabbedActivity cta = mActivityTestRule.getActivity();
// Prepare two incognito tabs and enter tab switcher. // Prepare two incognito tabs and enter tab switcher.
prepareTabs(1, 2, mUrl); prepareTabs(1, 2, mUrl);
...@@ -683,11 +683,11 @@ public class StartSurfaceLayoutTest { ...@@ -683,11 +683,11 @@ public class StartSurfaceLayoutTest {
.check(TabCountAssertion.havingTabCount(2)); .check(TabCountAssertion.havingTabCount(2));
for (int i = 0; i < mRepeat; i++) { for (int i = 0; i < mRepeat; i++) {
switchTabModel(false); switchTabModel(cta, false);
onView(withId(R.id.tab_list_view)) onView(withId(R.id.tab_list_view))
.check(TabCountAssertion.havingTabCount(1)); .check(TabCountAssertion.havingTabCount(1));
switchTabModel(true); switchTabModel(cta, true);
onView(withId(R.id.tab_list_view)) onView(withId(R.id.tab_list_view))
.check(TabCountAssertion.havingTabCount(2)); .check(TabCountAssertion.havingTabCount(2));
} }
...@@ -701,6 +701,7 @@ public class StartSurfaceLayoutTest { ...@@ -701,6 +701,7 @@ public class StartSurfaceLayoutTest {
message = "https://crbug.com/1023833") message = "https://crbug.com/1023833")
public void testIncognitoToggle_thumbnailFetchCount() throws InterruptedException { public void testIncognitoToggle_thumbnailFetchCount() throws InterruptedException {
mActivityTestRule.loadUrl(mUrl); mActivityTestRule.loadUrl(mUrl);
ChromeTabbedActivity cta = mActivityTestRule.getActivity();
int oldFetchCount = mTabListDelegate.getBitmapFetchCountForTesting(); int oldFetchCount = mTabListDelegate.getBitmapFetchCountForTesting();
// Prepare two incognito tabs and enter tab switcher. // Prepare two incognito tabs and enter tab switcher.
...@@ -715,7 +716,7 @@ public class StartSurfaceLayoutTest { ...@@ -715,7 +716,7 @@ public class StartSurfaceLayoutTest {
TabContentManager.ThumbnailFetchingResult.GOT_JPEG); TabContentManager.ThumbnailFetchingResult.GOT_JPEG);
for (int i = 0; i < mRepeat; i++) { for (int i = 0; i < mRepeat; i++) {
switchTabModel(false); switchTabModel(cta, false);
currentFetchCount = mTabListDelegate.getBitmapFetchCountForTesting(); currentFetchCount = mTabListDelegate.getBitmapFetchCountForTesting();
int currentHistogramRecord = RecordHistogram.getHistogramValueCountForTesting( int currentHistogramRecord = RecordHistogram.getHistogramValueCountForTesting(
TabContentManager.UMA_THUMBNAIL_FETCHING_RESULT, TabContentManager.UMA_THUMBNAIL_FETCHING_RESULT,
...@@ -725,7 +726,7 @@ public class StartSurfaceLayoutTest { ...@@ -725,7 +726,7 @@ public class StartSurfaceLayoutTest {
oldFetchCount = currentFetchCount; oldFetchCount = currentFetchCount;
oldHistogramRecord = currentHistogramRecord; oldHistogramRecord = currentHistogramRecord;
switchTabModel(true); switchTabModel(cta, true);
currentFetchCount = mTabListDelegate.getBitmapFetchCountForTesting(); currentFetchCount = mTabListDelegate.getBitmapFetchCountForTesting();
currentHistogramRecord = RecordHistogram.getHistogramValueCountForTesting( currentHistogramRecord = RecordHistogram.getHistogramValueCountForTesting(
TabContentManager.UMA_THUMBNAIL_FETCHING_RESULT, TabContentManager.UMA_THUMBNAIL_FETCHING_RESULT,
...@@ -767,11 +768,12 @@ public class StartSurfaceLayoutTest { ...@@ -767,11 +768,12 @@ public class StartSurfaceLayoutTest {
ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID}) ChromeFeatureList.TAB_GROUPS_CONTINUATION_ANDROID})
public void testUrlUpdatedNotCrashing_ForTabNotInCurrentModel() throws Exception { public void testUrlUpdatedNotCrashing_ForTabNotInCurrentModel() throws Exception {
// clang-format on // clang-format on
ChromeTabbedActivity cta = mActivityTestRule.getActivity();
prepareTabs(1, 1, null); prepareTabs(1, 1, null);
enterGTSWithThumbnailChecking(); enterGTSWithThumbnailChecking();
Tab tab = mActivityTestRule.getActivity().getTabModelSelector().getCurrentTab(); Tab tab = cta.getTabModelSelector().getCurrentTab();
switchTabModel(false); switchTabModel(cta, false);
mActivityTestRule.loadUrlInTab( mActivityTestRule.loadUrlInTab(
mUrl, PageTransition.TYPED | PageTransition.FROM_ADDRESS_BAR, tab); mUrl, PageTransition.TYPED | PageTransition.FROM_ADDRESS_BAR, tab);
...@@ -909,7 +911,7 @@ public class StartSurfaceLayoutTest { ...@@ -909,7 +911,7 @@ public class StartSurfaceLayoutTest {
verifyTabModelTabCount(cta, 3, 0); verifyTabModelTabCount(cta, 3, 0);
// New tab tile should be showing in incognito mode. // New tab tile should be showing in incognito mode.
switchTabModel(true); switchTabModel(cta, true);
onView(withId(R.id.tab_list_view)).check(TabCountAssertion.havingTabCount(1)); onView(withId(R.id.tab_list_view)).check(TabCountAssertion.havingTabCount(1));
onView(withId(R.id.new_tab_tile)).check(matches(isDisplayed())); onView(withId(R.id.new_tab_tile)).check(matches(isDisplayed()));
...@@ -923,13 +925,13 @@ public class StartSurfaceLayoutTest { ...@@ -923,13 +925,13 @@ public class StartSurfaceLayoutTest {
// Close all normal tabs and incognito tabs, the new tab tile should still show in both // Close all normal tabs and incognito tabs, the new tab tile should still show in both
// modes. // modes.
switchTabModel(false); switchTabModel(cta, false);
onView(withId(R.id.tab_list_view)).check(TabCountAssertion.havingTabCount(4)); onView(withId(R.id.tab_list_view)).check(TabCountAssertion.havingTabCount(4));
MenuUtils.invokeCustomMenuActionSync( MenuUtils.invokeCustomMenuActionSync(
InstrumentationRegistry.getInstrumentation(), cta, R.id.close_all_tabs_menu_id); InstrumentationRegistry.getInstrumentation(), cta, R.id.close_all_tabs_menu_id);
onView(withId(R.id.tab_list_view)).check(TabCountAssertion.havingTabCount(1)); onView(withId(R.id.tab_list_view)).check(TabCountAssertion.havingTabCount(1));
onView(withId(R.id.new_tab_tile)).check(matches(isDisplayed())); onView(withId(R.id.new_tab_tile)).check(matches(isDisplayed()));
switchTabModel(true); switchTabModel(cta, true);
onView(withId(R.id.tab_list_view)).check(TabCountAssertion.havingTabCount(1)); onView(withId(R.id.tab_list_view)).check(TabCountAssertion.havingTabCount(1));
onView(withId(R.id.new_tab_tile)).check(matches(isDisplayed())); onView(withId(R.id.new_tab_tile)).check(matches(isDisplayed()));
} }
...@@ -1014,7 +1016,7 @@ public class StartSurfaceLayoutTest { ...@@ -1014,7 +1016,7 @@ public class StartSurfaceLayoutTest {
onView(withId(R.id.new_tab_tile)).check(doesNotExist()); onView(withId(R.id.new_tab_tile)).check(doesNotExist());
verifyTabSwitcherCardCount(cta, 2); verifyTabSwitcherCardCount(cta, 2);
switchTabModel(true); switchTabModel(cta, true);
onView(withId(R.id.new_tab_tile)).check(doesNotExist()); onView(withId(R.id.new_tab_tile)).check(doesNotExist());
verifyTabSwitcherCardCount(cta, 0); verifyTabSwitcherCardCount(cta, 0);
} }
...@@ -1288,10 +1290,10 @@ public class StartSurfaceLayoutTest { ...@@ -1288,10 +1290,10 @@ public class StartSurfaceLayoutTest {
enterTabSwitcher(cta); enterTabSwitcher(cta);
checkNewTabVariationVisibility(false); checkNewTabVariationVisibility(false);
switchTabModel(false); switchTabModel(cta, false);
checkNewTabVariationVisibility(false); checkNewTabVariationVisibility(false);
switchTabModel(true); switchTabModel(cta, true);
checkNewTabVariationVisibility(false); checkNewTabVariationVisibility(false);
closeFirstTabInTabSwitcher(); closeFirstTabInTabSwitcher();
...@@ -1622,24 +1624,6 @@ public class StartSurfaceLayoutTest { ...@@ -1622,24 +1624,6 @@ public class StartSurfaceLayoutTest {
InstrumentationRegistry.getInstrumentation(), cta, R.id.menu_group_tabs); InstrumentationRegistry.getInstrumentation(), cta, R.id.menu_group_tabs);
} }
private void switchTabModel(boolean isIncognito) {
assertTrue(isIncognito !=
mActivityTestRule.getActivity().getTabModelSelector().isIncognitoSelected());
onView(withContentDescription(
isIncognito ? R.string.accessibility_tab_switcher_incognito_stack
: R.string.accessibility_tab_switcher_standard_stack)
).perform(click());
CriteriaHelper.pollUiThread(Criteria.equals(isIncognito,
() -> mActivityTestRule.getActivity().getTabModelSelector().isIncognitoSelected()));
// Wait for tab list recyclerView to finish animation after tab model switch.
RecyclerView recyclerView =
mActivityTestRule.getActivity().findViewById(R.id.tab_list_view);
waitForStableRecyclerView(recyclerView);
}
/** /**
* TODO(wychen): move some of the callers to {@link TabUiTestHelper#enterTabSwitcher}. * TODO(wychen): move some of the callers to {@link TabUiTestHelper#enterTabSwitcher}.
*/ */
......
...@@ -7,17 +7,19 @@ package org.chromium.chrome.browser.tasks.tab_management; ...@@ -7,17 +7,19 @@ package org.chromium.chrome.browser.tasks.tab_management;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.chromium.chrome.browser.multiwindow.MultiWindowTestHelper.moveActivityToFront;
import static org.chromium.chrome.browser.multiwindow.MultiWindowTestHelper.waitForSecondChromeTabbedActivity; import static org.chromium.chrome.browser.multiwindow.MultiWindowTestHelper.waitForSecondChromeTabbedActivity;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.clickFirstCardFromTabSwitcher; import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.clickFirstCardFromTabSwitcher;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.createTabs; import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.createTabs;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.enterTabSwitcher;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.switchTabModel;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.verifyTabModelTabCount;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.verifyTabSwitcherCardCount;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.os.Build; import android.os.Build;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
import android.support.test.filters.MediumTest; import android.support.test.filters.MediumTest;
import android.view.ViewGroup;
import androidx.recyclerview.widget.RecyclerView;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
...@@ -32,7 +34,6 @@ import org.chromium.chrome.browser.ChromeTabbedActivity; ...@@ -32,7 +34,6 @@ import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.compositor.layouts.Layout; import org.chromium.chrome.browser.compositor.layouts.Layout;
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;
import org.chromium.chrome.browser.toolbar.IncognitoToggleTabLayout;
import org.chromium.chrome.features.start_surface.StartSurfaceLayout; import org.chromium.chrome.features.start_surface.StartSurfaceLayout;
import org.chromium.chrome.tab_ui.R; import org.chromium.chrome.tab_ui.R;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
...@@ -41,14 +42,13 @@ import org.chromium.chrome.test.util.MenuUtils; ...@@ -41,14 +42,13 @@ import org.chromium.chrome.test.util.MenuUtils;
import org.chromium.chrome.test.util.browser.Features; import org.chromium.chrome.test.util.browser.Features;
import org.chromium.content_public.browser.test.util.Criteria; import org.chromium.content_public.browser.test.util.Criteria;
import org.chromium.content_public.browser.test.util.CriteriaHelper; import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.ui.test.util.UiRestriction; import org.chromium.ui.test.util.UiRestriction;
/** Tests for Multi-window related behavior in grid tab switcher. */ /** Tests for Multi-window related behavior in grid tab switcher. */
@RunWith(ChromeJUnit4ClassRunner.class) @RunWith(ChromeJUnit4ClassRunner.class)
// clang-format off // clang-format off
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
ChromeSwitches.DISABLE_TAB_MERGING_FOR_TESTING}) ChromeSwitches.DISABLE_TAB_MERGING_FOR_TESTING})
@Restriction(UiRestriction.RESTRICTION_TYPE_PHONE) @Restriction(UiRestriction.RESTRICTION_TYPE_PHONE)
@MinAndroidSdkLevel(Build.VERSION_CODES.N) @MinAndroidSdkLevel(Build.VERSION_CODES.N)
@Features.EnableFeatures({ChromeFeatureList.TAB_GRID_LAYOUT_ANDROID}) @Features.EnableFeatures({ChromeFeatureList.TAB_GRID_LAYOUT_ANDROID})
...@@ -87,48 +87,42 @@ public class TabSwitcherMultiWindowTest { ...@@ -87,48 +87,42 @@ public class TabSwitcherMultiWindowTest {
assertTrue(cta1.getTabModelSelector().getCurrentModel().isIncognito()); assertTrue(cta1.getTabModelSelector().getCurrentModel().isIncognito());
// Before move, there are 3 incognito tabs in cta1. // Before move, there are 3 incognito tabs in cta1.
RecyclerView recyclerView1 = cta1.findViewById(R.id.tab_list_view); verifyTabSwitcherCardCount(cta1, 3);
CriteriaHelper.pollUiThread(Criteria.equals(3, recyclerView1::getChildCount));
// Move 2 incognito tabs to cta2. // Move 2 incognito tabs to cta2.
clickFirstCardFromTabSwitcher(cta1); clickFirstCardFromTabSwitcher(cta1);
moveTabsToOtherWindow(cta1, 2); MenuUtils.invokeCustomMenuActionSync(InstrumentationRegistry.getInstrumentation(), cta1,
R.id.move_to_other_window_menu_id);
final ChromeTabbedActivity cta2 = waitForSecondChromeTabbedActivity();
moveActivityToFront(cta1);
moveTabsToOtherWindow(cta1, 1);
// After move, there are 1 incognito tab in cta1 and 2 incognito tabs in cta2. // After move, there are 1 incognito tab in cta1 and 2 incognito tabs in cta2.
final ChromeTabbedActivity cta2 = waitForSecondChromeTabbedActivity();
verifyTabModelTabCount(cta1, 4, 1);
verifyTabModelTabCount(cta2, 0, 2);
enterTabSwitcher(cta1); enterTabSwitcher(cta1);
CriteriaHelper.pollUiThread(Criteria.equals(1, recyclerView1::getChildCount)); verifyTabSwitcherCardCount(cta1, 1);
clickFirstCardFromTabSwitcher(cta1);
// Enter tab switcher in cta2. moveActivityToFront(cta2);
enterTabSwitcher(cta2); enterTabSwitcher(cta2);
verifyTabSwitcherCardCount(cta2, 2);
// There should be two incognito tabs in tab switcher in cta2. verifyTabModelTabCount(cta1, 4, 1);
RecyclerView recyclerView2 = cta2.findViewById(R.id.tab_list_view); verifyTabModelTabCount(cta2, 0, 2);
CriteriaHelper.pollUiThread(Criteria.equals(2, recyclerView2::getChildCount));
// Move 1 incognito tab back to cta1. // Move 1 incognito tab back to cta1.
clickFirstCardFromTabSwitcher(cta2); clickFirstCardFromTabSwitcher(cta2);
moveTabsToOtherWindow(cta2, 1); moveTabsToOtherWindow(cta2, 1);
// After move, there are 2 incognito tabs in cta1 and 1 incognito tab in cta2. // After move, there are 2 incognito tabs in cta1 and 1 incognito tab in cta2.
verifyTabModelTabCount(cta1, 4, 2);
verifyTabModelTabCount(cta2, 0, 1);
enterTabSwitcher(cta2); enterTabSwitcher(cta2);
CriteriaHelper.pollUiThread(Criteria.equals(1, recyclerView2::getChildCount)); verifyTabSwitcherCardCount(cta2, 1);
clickFirstCardFromTabSwitcher(cta2);
// Enter tab switcher in cta1. Verify there are two incognito tabs in tab switcher in cta1. moveActivityToFront(cta1);
enterTabSwitcher(cta1); enterTabSwitcher(cta1);
CriteriaHelper.pollUiThread(Criteria.equals(2, recyclerView1::getChildCount)); verifyTabSwitcherCardCount(cta1, 2);
verifyTabModelTabCount(cta1, 4, 2);
verifyTabModelTabCount(cta2, 0, 1);
// Switch to normal tab list in cta1. // Switch to normal tab list in cta1.
TestThreadUtils.runOnUiThreadBlocking(() -> { switchTabModel(cta1, false);
IncognitoToggleTabLayout toggleTabLayout =
cta1.findViewById(R.id.incognito_toggle_tabs);
ViewGroup toggleButtons = (ViewGroup) toggleTabLayout.getChildAt(0);
toggleButtons.getChildAt(0).performClick();
});
assertFalse(cta1.getTabModelSelector().getCurrentModel().isIncognito()); assertFalse(cta1.getTabModelSelector().getCurrentModel().isIncognito());
// Move 3 normal tabs to cta2. // Move 3 normal tabs to cta2.
...@@ -136,48 +130,35 @@ public class TabSwitcherMultiWindowTest { ...@@ -136,48 +130,35 @@ public class TabSwitcherMultiWindowTest {
moveTabsToOtherWindow(cta1, 3); moveTabsToOtherWindow(cta1, 3);
// After move, there are 1 normal tab in cta1 and 3 normal tabs in cta2. // After move, there are 1 normal tab in cta1 and 3 normal tabs in cta2.
verifyTabModelTabCount(cta1, 1, 2);
verifyTabModelTabCount(cta2, 3, 1);
enterTabSwitcher(cta1); enterTabSwitcher(cta1);
CriteriaHelper.pollUiThread(Criteria.equals(1, recyclerView1::getChildCount)); verifyTabSwitcherCardCount(cta1, 1);
clickFirstCardFromTabSwitcher(cta1);
// Enter tab switcher in cta2. moveActivityToFront(cta2);
enterTabSwitcher(cta2); enterTabSwitcher(cta2);
verifyTabSwitcherCardCount(cta2, 3);
// There should be 3 normal tabs in tab switcher in cta2. verifyTabModelTabCount(cta1, 1, 2);
CriteriaHelper.pollUiThread(Criteria.equals(3, recyclerView2::getChildCount)); verifyTabModelTabCount(cta2, 3, 1);
// Move 2 normal tabs back to cta1. // Move 2 normal tabs back to cta1.
clickFirstCardFromTabSwitcher(cta2); clickFirstCardFromTabSwitcher(cta2);
moveTabsToOtherWindow(cta2, 2); moveTabsToOtherWindow(cta2, 2);
// After move, there are 3 normal tabs in cta1 and 1 normal tab in cta2. // After move, there are 3 normal tabs in cta1 and 1 normal tab in cta2.
enterTabSwitcher(cta2);
verifyTabSwitcherCardCount(cta2, 1);
clickFirstCardFromTabSwitcher(cta2);
moveActivityToFront(cta1);
enterTabSwitcher(cta1);
verifyTabSwitcherCardCount(cta1, 3);
verifyTabModelTabCount(cta1, 3, 2); verifyTabModelTabCount(cta1, 3, 2);
verifyTabModelTabCount(cta2, 1, 1); verifyTabModelTabCount(cta2, 1, 1);
enterTabSwitcher(cta2);
CriteriaHelper.pollUiThread(Criteria.equals(1, recyclerView2::getChildCount));
} }
private void moveTabsToOtherWindow(ChromeTabbedActivity cta, int number) { private void moveTabsToOtherWindow(ChromeTabbedActivity cta, int number) {
for (int i = 0; i < number; i++) { for (int i = 0; i < number; i++) {
MenuUtils.invokeCustomMenuActionSync(InstrumentationRegistry.getInstrumentation(), cta, MenuUtils.invokeCustomMenuActionSync(InstrumentationRegistry.getInstrumentation(), cta,
org.chromium.chrome.R.id.move_to_other_window_menu_id); R.id.move_to_other_window_menu_id);
moveActivityToFront(cta);
} }
} }
private void enterTabSwitcher(ChromeTabbedActivity cta) {
assertFalse(cta.getLayoutManager().overviewVisible());
TestThreadUtils.runOnUiThreadBlocking(
() -> { cta.findViewById(R.id.tab_switcher_button).performClick(); });
CriteriaHelper.pollUiThread(
Criteria.equals(true, () -> cta.getLayoutManager().overviewVisible()));
}
private void verifyTabModelTabCount(
ChromeTabbedActivity cta, int normalTabs, int incognitoTabs) {
CriteriaHelper.pollUiThread(Criteria.equals(
normalTabs, () -> cta.getTabModelSelector().getModel(false).getCount()));
CriteriaHelper.pollUiThread(Criteria.equals(
incognitoTabs, () -> cta.getTabModelSelector().getModel(true).getCount()));
}
} }
...@@ -10,6 +10,7 @@ import static android.support.test.espresso.assertion.ViewAssertions.matches; ...@@ -10,6 +10,7 @@ import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.RootMatchers.withDecorView; import static android.support.test.espresso.matcher.RootMatchers.withDecorView;
import static android.support.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed; import static android.support.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withContentDescription;
import static android.support.test.espresso.matcher.ViewMatchers.withId; import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withParent; import static android.support.test.espresso.matcher.ViewMatchers.withParent;
...@@ -21,6 +22,7 @@ import static org.junit.Assert.assertFalse; ...@@ -21,6 +22,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.chromium.base.test.util.CallbackHelper.WAIT_TIMEOUT_SECONDS; import static org.chromium.base.test.util.CallbackHelper.WAIT_TIMEOUT_SECONDS;
import static org.chromium.chrome.test.util.browser.RecyclerViewTestUtils.waitForStableRecyclerView;
import static org.chromium.content_public.browser.test.util.CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL; import static org.chromium.content_public.browser.test.util.CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL;
import static org.chromium.content_public.browser.test.util.CriteriaHelper.DEFAULT_POLLING_INTERVAL; import static org.chromium.content_public.browser.test.util.CriteriaHelper.DEFAULT_POLLING_INTERVAL;
...@@ -588,6 +590,29 @@ public class TabUiTestHelper { ...@@ -588,6 +590,29 @@ public class TabUiTestHelper {
PseudoTab.clearForTesting(); PseudoTab.clearForTesting();
} }
/**
* Click on the incognito toggle within grid tab switcher top toolbar to switch between normal
* and incognito tab model.
* @param cta The current running activity.
* @param isIncognito indicates whether the incognito or normal tab model is selected after
* switch.
*/
public static void switchTabModel(ChromeTabbedActivity cta, boolean isIncognito) {
assertTrue(isIncognito != cta.getTabModelSelector().isIncognitoSelected());
assertTrue(cta.getOverviewModeBehavior().overviewVisible());
onView(withContentDescription(isIncognito
? R.string.accessibility_tab_switcher_incognito_stack
: R.string.accessibility_tab_switcher_standard_stack))
.perform(click());
CriteriaHelper.pollUiThread(Criteria.equals(
isIncognito, () -> cta.getTabModelSelector().isIncognitoSelected()));
// Wait for tab list recyclerView to finish animation after tab model switch.
RecyclerView recyclerView = cta.findViewById(R.id.tab_list_view);
waitForStableRecyclerView(recyclerView);
}
/** /**
* Implementation of {@link ViewAssertion} to verify the {@link RecyclerView} has correct number * Implementation of {@link ViewAssertion} to verify the {@link RecyclerView} has correct number
* of children. * of children.
......
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