Commit f8c5dd0d authored by Justin DeWitt's avatar Justin DeWitt Committed by Commit Bot

[Explore Sites] Fix render tests for other builders.

Some tablets failed because scrolling to a position did not guarantee
that position would be the first visible, since the catalog is not
big enough on a tablet.

Also switches scrollToPosition -> scrollToPositionWithOffset to match
behavior of moving a tile to the top.

Bug: 953254
Change-Id: Id7671a73e4ce16cc834ac66daa25369205ed4eee
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1570189Reviewed-by: default avatarCathy Li <chili@chromium.org>
Commit-Queue: Justin DeWitt <dewittj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#652173}
parent b469be44
...@@ -5,19 +5,25 @@ ...@@ -5,19 +5,25 @@
package org.chromium.chrome.browser.explore_sites; package org.chromium.chrome.browser.explore_sites;
import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.instanceOf;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.os.Build; import android.os.Build;
import android.os.SystemClock; import android.os.SystemClock;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.UiController;
import android.support.test.espresso.ViewAction;
import android.support.test.espresso.contrib.RecyclerViewActions; import android.support.test.espresso.contrib.RecyclerViewActions;
import android.support.test.filters.SmallTest; import android.support.test.filters.SmallTest;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.View; import android.view.View;
import org.hamcrest.Matcher;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Assume; import org.junit.Assume;
...@@ -27,7 +33,6 @@ import org.junit.Test; ...@@ -27,7 +33,6 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.chromium.base.test.util.CommandLineFlags; 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.Feature;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeActivity; import org.chromium.chrome.browser.ChromeActivity;
...@@ -57,6 +62,34 @@ import java.util.ArrayList; ...@@ -57,6 +62,34 @@ import java.util.ArrayList;
public class ExploreSitesPageTest { public class ExploreSitesPageTest {
// clang-format on // clang-format on
private static final class ScrollToPositionWithOffsetViewAction implements ViewAction {
private final int mPosition;
private final int mOffset;
private ScrollToPositionWithOffsetViewAction(int position, int offset) {
this.mPosition = position;
mOffset = offset;
}
@SuppressWarnings("unchecked")
@Override
public Matcher<View> getConstraints() {
return allOf(isAssignableFrom(RecyclerView.class), isDisplayed());
}
@Override
public String getDescription() {
return "scroll RecyclerView to mPosition: " + mPosition;
}
@Override
public void perform(UiController uiController, View view) {
RecyclerView recyclerView = (RecyclerView) view;
((LinearLayoutManager) recyclerView.getLayoutManager())
.scrollToPositionWithOffset(mPosition, mOffset);
}
}
ArrayList<ExploreSitesCategory> getTestingCatalog() { ArrayList<ExploreSitesCategory> getTestingCatalog() {
final ArrayList<ExploreSitesCategory> categoryList = new ArrayList<>(); final ArrayList<ExploreSitesCategory> categoryList = new ArrayList<>();
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
...@@ -112,16 +145,19 @@ public class ExploreSitesPageTest { ...@@ -112,16 +145,19 @@ public class ExploreSitesPageTest {
.findFirstCompletelyVisibleItemPosition(); .findFirstCompletelyVisibleItemPosition();
} }
private void scrollToPosition(int scrollPosition) {
onView(instanceOf(RecyclerView.class))
.perform(new ScrollToPositionWithOffsetViewAction(scrollPosition, 0));
}
@Test @Test
@SmallTest @SmallTest
@DisabledTest
@Feature({"ExploreSites", "RenderTest"}) @Feature({"ExploreSites", "RenderTest"})
public void testScrolledLayout_withBack() throws Exception { public void testScrolledLayout_withBack() throws Exception {
final int scrollPosition = 2; scrollToPosition(2);
onView(instanceOf(RecyclerView.class))
.perform(RecyclerViewActions.scrollToPosition(scrollPosition));
mRenderTestRule.render(mRecyclerView, "recycler_layout"); mRenderTestRule.render(mRecyclerView, "recycler_layout");
Assert.assertEquals(scrollPosition, getFirstVisiblePosition()); final int scrollPosition = getFirstVisiblePosition();
// TODO(https://crbug.com/938519): Remove this sleep in favor of actually waiting for the // TODO(https://crbug.com/938519): Remove this sleep in favor of actually waiting for the
// scroll bar to disappear. // scroll bar to disappear.
SystemClock.sleep(3000); SystemClock.sleep(3000);
......
d60de483ccbe01a433798e31df3f9f08dc387480 8d1722f71ac07ab22c7c126b00e18deff42827f1
\ No newline at end of file \ No newline at end of file
33ecdb2b25aac53cc826f38e281a11cf6eefdb8e 56c1615c2cae305efe6fdc0d73d660608d5470f5
\ No newline at end of file \ 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