Commit 4c8de284 authored by Wei-Yin Chen (陳威尹)'s avatar Wei-Yin Chen (陳威尹) Committed by Commit Bot

Add RenderTests in StartSurfaceLayoutTest

Add some basic render tests in StartSurfaceLayoutTest, including a
test for INITIAL_SCROLL_INDEX_OFFSET.

Bug: 983170
Change-Id: Ie06cd2f3620a980b3c095eb0619704a7c714fd68
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1903402
Commit-Queue: Wei-Yin Chen (陳威尹) <wychen@chromium.org>
Reviewed-by: default avatarYue Zhang <yuezhanggg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713543}
parent d7237703
......@@ -43,6 +43,7 @@ import org.chromium.base.GarbageCollectionTestUtils;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.MinAndroidSdkLevel;
import org.chromium.base.test.util.Restriction;
import org.chromium.chrome.browser.ChromeFeatureList;
......@@ -55,12 +56,14 @@ import org.chromium.chrome.browser.tab.TabFeatureUtilities;
import org.chromium.chrome.browser.tabmodel.TabModel;
import org.chromium.chrome.browser.tabmodel.TabSelectionType;
import org.chromium.chrome.browser.tasks.tab_management.TabSwitcher;
import org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper;
import org.chromium.chrome.tab_ui.R;
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.ChromeTabUtils;
import org.chromium.chrome.test.util.MenuUtils;
import org.chromium.chrome.test.util.RenderTestRule;
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.CriteriaHelper;
......@@ -70,6 +73,7 @@ import org.chromium.net.test.EmbeddedTestServer;
import org.chromium.ui.test.util.UiRestriction;
import java.io.File;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.LinkedList;
import java.util.List;
......@@ -92,6 +96,9 @@ public class StartSurfaceLayoutTest {
@Rule
public TestRule mProcessor = new Features.InstrumentationProcessor();
@Rule
public RenderTestRule mRenderTestRule = new RenderTestRule();
private StartSurfaceLayout mStartSurfaceLayout;
private String mUrl;
private int mRepeat;
......@@ -130,7 +137,9 @@ public class StartSurfaceLayoutTest {
.getCurrentTabModelFilter()::isTabModelRestored));
assertEquals(0, mTabListDelegate.getBitmapFetchCountForTesting());
// Only skip thumbnail releasing assertion when "warm" (large soft-cleanup-delay).
// Only skip thumbnail releasing assertion when "warm" (large soft-cleanup-delay) or in
// RenderTest.
// TODO(wychen): figure out why thumbnails are not released in RenderTest.
mSkipAssertThumbnailsAreReleased = false;
}
......@@ -139,6 +148,79 @@ public class StartSurfaceLayoutTest {
if (!mSkipAssertThumbnailsAreReleased) assertThumbnailsAreReleased();
}
@Test
@MediumTest
@Feature({"RenderTest"})
@CommandLineFlags.Add({BASE_PARAMS})
public void testRenderGrid_3WebTabs() throws InterruptedException, IOException {
mSkipAssertThumbnailsAreReleased = true;
prepareTabs(3, 0, mUrl);
TabUiTestHelper.enterTabSwitcher(mActivityTestRule.getActivity());
TabUiTestHelper.clickFirstCardFromTabSwitcher(mActivityTestRule.getActivity());
enterGTS();
mRenderTestRule.render(mActivityTestRule.getActivity().findViewById(
org.chromium.chrome.tab_ui.R.id.tab_list_view),
"3_web_tabs");
}
@Test
@MediumTest
@Feature({"RenderTest"})
@CommandLineFlags.Add({BASE_PARAMS})
public void testRenderGrid_10WebTabs() throws InterruptedException, IOException {
mSkipAssertThumbnailsAreReleased = true;
prepareTabs(10, 0, mUrl);
TabUiTestHelper.enterTabSwitcher(mActivityTestRule.getActivity());
TabUiTestHelper.clickFirstCardFromTabSwitcher(mActivityTestRule.getActivity());
enterGTS();
mRenderTestRule.render(mActivityTestRule.getActivity().findViewById(
org.chromium.chrome.tab_ui.R.id.tab_list_view),
"10_web_tabs");
}
@Test
@MediumTest
@Feature({"RenderTest"})
@CommandLineFlags.Add({BASE_PARAMS})
public void testRenderGrid_10WebTabs_InitialScroll() throws InterruptedException, IOException {
mSkipAssertThumbnailsAreReleased = true;
prepareTabs(10, 0, mUrl);
TabUiTestHelper.enterTabSwitcher(mActivityTestRule.getActivity());
TabUiTestHelper.clickNthCardFromTabSwitcher(mActivityTestRule.getActivity(),
mActivityTestRule.getActivity().getTabModelSelector().getCurrentModel().getCount()
- 1);
enterGTS();
// Make sure the grid tab switcher is scrolled down to show the selected tab.
mRenderTestRule.render(mActivityTestRule.getActivity().findViewById(
org.chromium.chrome.tab_ui.R.id.tab_list_view),
"10_web_tabs-select_last");
}
@Test
@MediumTest
@Feature({"RenderTest"})
@CommandLineFlags.Add({BASE_PARAMS})
public void testRenderGrid_Incognito() throws InterruptedException, IOException {
mSkipAssertThumbnailsAreReleased = true;
// Prepare some incognito tabs and enter tab switcher.
prepareTabs(1, 3, mUrl);
assertTrue(mActivityTestRule.getActivity().getCurrentTabModel().isIncognito());
TabUiTestHelper.enterTabSwitcher(mActivityTestRule.getActivity());
TabUiTestHelper.clickFirstCardFromTabSwitcher(mActivityTestRule.getActivity());
enterGTS();
mRenderTestRule.render(mActivityTestRule.getActivity().findViewById(
org.chromium.chrome.tab_ui.R.id.tab_list_view),
"3_incognito_web_tabs");
}
@Test
@MediumTest
// clang-format off
......@@ -730,7 +812,6 @@ public class StartSurfaceLayoutTest {
} else {
// The final capture at StartSurfaceLayout#finishedShowing time.
delta = 1;
// TODO(wychen): refactor areAnimatorsEnabled() to a util class.
if (ChromeFeatureList.isEnabled(ChromeFeatureList.TAB_TO_GTS_ANIMATION)
&& areAnimatorsEnabled()) {
// The faster capturing without writing back to cache.
......
......@@ -20,7 +20,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.CardCountAssertion;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.clickFirstTabFromTabSwitcher;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.clickFirstCardFromTabSwitcher;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.createOverviewHideWatcher;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.createTabGroup;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.createTabs;
......@@ -111,7 +111,7 @@ public class TabGridDialogTest {
// Enter first tab page.
assertTrue(cta.getLayoutManager().overviewVisible());
clickFirstTabFromTabSwitcher(cta);
clickFirstCardFromTabSwitcher(cta);
clickFirstTabFromDialog(cta);
// Open dialog from tab strip and verify dialog is showing correct content.
openDialogFromStripAndVerify(cta, 2);
......@@ -176,7 +176,7 @@ public class TabGridDialogTest {
}
private void openDialogFromTabSwitcherAndVerify(ChromeTabbedActivity cta, int tabCount) {
clickFirstTabFromTabSwitcher(cta);
clickFirstCardFromTabSwitcher(cta);
CriteriaHelper.pollInstrumentationThread(() -> isDialogShowing(cta));
verifyShowingDialog(cta, tabCount);
}
......
......@@ -61,7 +61,7 @@ public class TabUiTestHelper {
* Enter tab switcher from a tab page.
* @param cta The current running activity.
*/
static void enterTabSwitcher(ChromeTabbedActivity cta) {
public static void enterTabSwitcher(ChromeTabbedActivity cta) {
OverviewModeBehaviorWatcher showWatcher = createOverviewShowWatcher(cta);
assertFalse(cta.getLayoutManager().overviewVisible());
// TODO(crbug.com/1019727) Figure out a better way to wait until isCompletelyDisplayed() is
......@@ -76,11 +76,21 @@ public class TabUiTestHelper {
* group, this will open up the dialog; otherwise this will open up the tab page.
* @param cta The current running activity.
*/
static void clickFirstTabFromTabSwitcher(ChromeTabbedActivity cta) {
public static void clickFirstCardFromTabSwitcher(ChromeTabbedActivity cta) {
clickNthCardFromTabSwitcher(cta, 0);
}
/**
* Click the Nth card in grid tab switcher. When group is enabled and the Nth card is a
* group, this will open up the dialog; otherwise this will open up the tab page.
* @param cta The current running activity.
* @param index The index of the target card.
*/
public static void clickNthCardFromTabSwitcher(ChromeTabbedActivity cta, int index) {
assertTrue(cta.getLayoutManager().overviewVisible());
onView(allOf(withParent(withId(org.chromium.chrome.R.id.compositor_view_holder)),
withId(R.id.tab_list_view)))
.perform(RecyclerViewActions.actionOnItemAtPosition(0, click()));
.perform(RecyclerViewActions.actionOnItemAtPosition(index, click()));
}
/**
......
43c97d59e40785dc7ea53e9982dcee293dbfd360
\ No newline at end of file
bafdd41367d78118cc377f20099a554268572f69
\ No newline at end of file
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