Commit 26eade91 authored by Ioana Pandele's avatar Ioana Pandele Committed by Commit Bot

Revert "Add test coverage for GestureListenerManager crash/reload case"

This reverts commit 9a10a6f1.

Reason for revert: org.chromium.content.browser.GestureListenerManagerTest#testOnScrollEventsAfterCrashAndReload is very flaky

Bug: 1150208

Original change's description:
> Add test coverage for GestureListenerManager crash/reload case
>
> Bug: 1144109
> Change-Id: Iba055d3a9876b80f0da828409e2f21b1c5940a85
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2521156
> Commit-Queue: Evan Stade <estade@chromium.org>
> Reviewed-by: Scott Violet <sky@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#825525}

TBR=sky@chromium.org,estade@chromium.org

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: 1144109
Change-Id: I46f9b3b990b578474258260715715103bfd851da
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2546543Reviewed-by: default avatarIoana Pandele <ioanap@chromium.org>
Commit-Queue: Ioana Pandele <ioanap@chromium.org>
Cr-Commit-Position: refs/heads/master@{#828731}
parent 46fc0b6a
...@@ -10,7 +10,6 @@ import androidx.test.filters.LargeTest; ...@@ -10,7 +10,6 @@ import androidx.test.filters.LargeTest;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -29,11 +28,8 @@ import org.chromium.content_public.browser.test.RenderFrameHostTestExt; ...@@ -29,11 +28,8 @@ import org.chromium.content_public.browser.test.RenderFrameHostTestExt;
import org.chromium.content_public.browser.test.util.TestCallbackHelperContainer; import org.chromium.content_public.browser.test.util.TestCallbackHelperContainer;
import org.chromium.content_public.browser.test.util.TestThreadUtils; import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.content_public.browser.test.util.TouchCommon; import org.chromium.content_public.browser.test.util.TouchCommon;
import org.chromium.content_public.browser.test.util.WebContentsUtils;
import org.chromium.content_shell_apk.ContentShellActivityTestRule; import org.chromium.content_shell_apk.ContentShellActivityTestRule;
import java.util.concurrent.TimeoutException;
/** /**
* Assertions for GestureListenerManager. * Assertions for GestureListenerManager.
*/ */
...@@ -49,18 +45,16 @@ public class GestureListenerManagerTest { ...@@ -49,18 +45,16 @@ public class GestureListenerManagerTest {
private static final class GestureStateListenerImpl implements GestureStateListenerWithScroll { private static final class GestureStateListenerImpl implements GestureStateListenerWithScroll {
private int mNumOnScrollOffsetOrExtentChangedCalls; private int mNumOnScrollOffsetOrExtentChangedCalls;
public CallbackHelper mScrollEndCallbackHelper = new CallbackHelper(); public CallbackHelper mCallbackHelper = new CallbackHelper();
private boolean mGotStarted; private boolean mGotStarted;
private boolean mDidScrollOffsetChangeWhileScrolling; private boolean mDidScrollOffsetChangeWhileScrolling;
private Integer mLastScrollOffsetY; private Integer mLastScrollOffsetY;
int mScrollOffsetCallCount;
@Override @Override
public void onScrollStarted(int scrollOffsetY, int scrollExtentY) { public void onScrollStarted(int scrollOffsetY, int scrollExtentY) {
org.chromium.base.Log.e("chrome", "!!!onScrollStarted " + scrollOffsetY); org.chromium.base.Log.e("chrome", "!!!onScrollStarted " + scrollOffsetY);
mGotStarted = true; mGotStarted = true;
mLastScrollOffsetY = null; mLastScrollOffsetY = null;
mScrollOffsetCallCount = 0;
} }
@Override @Override
public void onScrollOffsetOrExtentChanged(int scrollOffsetY, int scrollExtentY) { public void onScrollOffsetOrExtentChanged(int scrollOffsetY, int scrollExtentY) {
...@@ -71,7 +65,6 @@ public class GestureListenerManagerTest { ...@@ -71,7 +65,6 @@ public class GestureListenerManagerTest {
&& (mLastScrollOffsetY == null || !mLastScrollOffsetY.equals(scrollOffsetY))) { && (mLastScrollOffsetY == null || !mLastScrollOffsetY.equals(scrollOffsetY))) {
if (mLastScrollOffsetY != null) mDidScrollOffsetChangeWhileScrolling = true; if (mLastScrollOffsetY != null) mDidScrollOffsetChangeWhileScrolling = true;
mLastScrollOffsetY = scrollOffsetY; mLastScrollOffsetY = scrollOffsetY;
++mScrollOffsetCallCount;
} }
} }
@Override @Override
...@@ -82,131 +75,76 @@ public class GestureListenerManagerTest { ...@@ -82,131 +75,76 @@ public class GestureListenerManagerTest {
// onScrollOffsetOrExtentChanged() should be called at least twice. Once with an initial // onScrollOffsetOrExtentChanged() should be called at least twice. Once with an initial
// value, and then with a different value. // value, and then with a different value.
Assert.assertTrue(mDidScrollOffsetChangeWhileScrolling); Assert.assertTrue(mDidScrollOffsetChangeWhileScrolling);
mScrollEndCallbackHelper.notifyCalled(); mCallbackHelper.notifyCalled();
mGotStarted = false; mGotStarted = false;
} }
} }
private TestCallbackHelperContainer mCallbackHelperContainer;
private GestureStateListenerImpl mListener;
private WebContents mWebContents;
private float mCurrentX; private float mCurrentX;
private float mCurrentY; private float mCurrentY;
@Before /**
public void setUp() throws Throwable { * Assertions for GestureStateListener.onScrollOffsetOrExtentChanged.
*/
@Test
@LargeTest
@Feature({"Browser"})
public void testOnScrollOffsetOrExtentChanged() throws Throwable {
mActivityTestRule.launchContentShellWithUrl("about:blank"); mActivityTestRule.launchContentShellWithUrl("about:blank");
mWebContents = mActivityTestRule.getWebContents(); WebContents webContents = mActivityTestRule.getWebContents();
// This needs to wait for first-paint, otherwise scrolling doesn't happen. // This needs to wait for first-paint, otherwise scrolling doesn't happen.
mCallbackHelperContainer = new TestCallbackHelperContainer(mWebContents); TestCallbackHelperContainer callbackHelperContainer =
mActivityTestRule.loadUrl(mWebContents.getNavigationController(), mCallbackHelperContainer, new TestCallbackHelperContainer(webContents);
mActivityTestRule.loadUrl(webContents.getNavigationController(), callbackHelperContainer,
new LoadUrlParams(TEST_URL)); new LoadUrlParams(TEST_URL));
// Wait for the first non-empty visual paint and the title to change. The title changes when // Wait for the first non-empty visual paint and the title to change. The title changes when
// the doc has finished loading, which is a good signal events can be processed. // the doc has finished loading, which is a good signal events can be processed.
mCallbackHelperContainer.getOnFirstVisuallyNonEmptyPaintHelper().waitForCallback(0); callbackHelperContainer.getOnFirstVisuallyNonEmptyPaintHelper().waitForCallback(0);
CriteriaHelper.pollUiThread( CriteriaHelper.pollUiThread(
() -> Criteria.checkThat(mWebContents.getTitle(), Matchers.is("loaded"))); () -> Criteria.checkThat(webContents.getTitle(), Matchers.is("loaded")));
waitForReadinessToHandleEvents();
}
private void waitForReadinessToHandleEvents() throws TimeoutException {
// At this point the page has finished loading and a non-empty paint occurred. This does not // At this point the page has finished loading and a non-empty paint occurred. This does not
// mean the renderer is fully ready to process events (processing events requires layers, // mean the renderer is fully ready to process events (processing events requires layers,
// which may not have been created yet). Wait for a visual update, which should ensure the // which may not have been created yet). Wait for a visual update, which should ensure the
// renderer is ready. // renderer is ready.
CallbackHelper callbackHelper = new CallbackHelper(); CallbackHelper callbackHelper = new CallbackHelper();
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
new RenderFrameHostTestExt(mWebContents.getMainFrame()) new RenderFrameHostTestExt(webContents.getMainFrame())
.updateVisualState((Boolean result) -> { .updateVisualState((Boolean result) -> {
Assert.assertTrue(result); Assert.assertTrue(result);
callbackHelper.notifyCalled(); callbackHelper.notifyCalled();
}); });
}); });
callbackHelper.waitForFirst(); callbackHelper.waitForFirst();
}
private void startListening() {
mListener = new GestureStateListenerImpl();
final GestureStateListenerImpl listener = new GestureStateListenerImpl();
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
GestureListenerManagerImpl manager = GestureListenerManagerImpl manager =
(GestureListenerManagerImpl) GestureListenerManager.fromWebContents( (GestureListenerManagerImpl) GestureListenerManager.fromWebContents(
mWebContents); webContents);
// shouldReportAllRootScrolls() should initially be false (as there are no listeners). // shouldReportAllRootScrolls() should initially be false (as there are no listeners).
Assert.assertFalse(manager.shouldReportAllRootScrolls()); Assert.assertFalse(manager.shouldReportAllRootScrolls());
manager.addListener(mListener); manager.addListener(listener);
// Adding a listener enables root-scrolls. // Adding a listener enables root-scrolls.
Assert.assertTrue(manager.shouldReportAllRootScrolls()); Assert.assertTrue(manager.shouldReportAllRootScrolls());
View mWebContentsView = mWebContents.getViewAndroidDelegate().getContainerView(); View webContentsView = webContents.getViewAndroidDelegate().getContainerView();
mCurrentX = mWebContentsView.getWidth() / 2; mCurrentX = webContentsView.getWidth() / 2;
mCurrentY = mWebContentsView.getHeight() / 2; mCurrentY = webContentsView.getHeight() / 2;
Assert.assertTrue(mCurrentY > 0); Assert.assertTrue(mCurrentY > 0);
}); });
}
private void performAndVerifyScroll() throws TimeoutException { // Perform a scroll.
int scrollEndCallCount = mListener.mScrollEndCallbackHelper.getCallCount();
TouchCommon.performDrag(mActivityTestRule.getActivity(), mCurrentX, mCurrentX, mCurrentY, TouchCommon.performDrag(mActivityTestRule.getActivity(), mCurrentX, mCurrentX, mCurrentY,
mCurrentY - 50, /* stepCount*/ 3, /* duration in ms */ 250); mCurrentY - 50, /* stepCount*/ 3, /* duration in ms */ 250);
mListener.mScrollEndCallbackHelper.waitForCallback(scrollEndCallCount); listener.mCallbackHelper.waitForCallback(0);
}
/**
* Assertions for GestureStateListener.onScrollOffsetOrExtentChanged.
*/
@Test
@LargeTest
@Feature({"Browser"})
public void testOnScrollOffsetOrExtentChanged() throws Throwable {
startListening();
performAndVerifyScroll();
// Verify removing the only listener disables root-scrolls.
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
GestureListenerManagerImpl manager = GestureListenerManagerImpl manager =
(GestureListenerManagerImpl) GestureListenerManager.fromWebContents( (GestureListenerManagerImpl) GestureListenerManager.fromWebContents(
mWebContents); webContents);
manager.removeListener(mListener); manager.removeListener(listener);
// Removing the only listener disbles root-scrolls.
Assert.assertFalse(manager.shouldReportAllRootScrolls()); Assert.assertFalse(manager.shouldReportAllRootScrolls());
}); });
} }
/**
* In https://crbug.com/1144109, the report-all-root-scrolls bit was not propagated to a
* crashed and reloaded renderer, resulting in many fewer (but not 0) scroll callbacks. Test
* for this by verifying there's a similar number of scroll callbacks before and after the
* crash/reload.
*/
@Test
@LargeTest
@Feature({"Browser"})
public void testOnScrollEventsAfterCrashAndReload() throws Throwable {
startListening();
performAndVerifyScroll();
int scrollOffsetCallCount = mListener.mScrollOffsetCallCount;
// Crash and reload the tab.
WebContentsUtils.crashTabAndWait(mWebContents);
int paintCount =
mCallbackHelperContainer.getOnFirstVisuallyNonEmptyPaintHelper().getCallCount();
TestThreadUtils.runOnUiThreadBlocking(
() -> mWebContents.getNavigationController().reload(true));
mCallbackHelperContainer.getOnFirstVisuallyNonEmptyPaintHelper().waitForCallback(
paintCount);
waitForReadinessToHandleEvents();
// Verify the manager is still reporting all root scrolls.
TestThreadUtils.runOnUiThreadBlocking(() -> {
GestureListenerManagerImpl manager =
(GestureListenerManagerImpl) GestureListenerManager.fromWebContents(
mWebContents);
Assert.assertTrue(manager.shouldReportAllRootScrolls());
});
// Verify a *similar* number of scroll callbacks still come through.
performAndVerifyScroll();
int scrollOffsetCallCountAfterCrash = mListener.mScrollOffsetCallCount;
Assert.assertThat(
scrollOffsetCallCountAfterCrash, Matchers.greaterThan(scrollOffsetCallCount / 2));
}
} }
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