Commit 6a906689 authored by Becky Zhou's avatar Becky Zhou Committed by Commit Bot

Fix ContextualSuggestionsTest#testPeekWithPageScrollPercentage on O

The maximum scroll offset varies among different screen height. It's
not very reliable to use the hard-coded html body height for testing.
This patch simulates scroll based on the maximum scroll offset from
the RenderCoordinates instead.

Bug: 871305
Change-Id: I983036b8d72d60c4077eea1cbc39b2177e6aebf4
Reviewed-on: https://chromium-review.googlesource.com/1164416
Commit-Queue: Becky Zhou <huayinz@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#581266}
parent 68dd310e
...@@ -79,6 +79,7 @@ import org.chromium.content.browser.test.util.TestWebContentsObserver; ...@@ -79,6 +79,7 @@ import org.chromium.content.browser.test.util.TestWebContentsObserver;
import org.chromium.content_public.browser.GestureListenerManager; import org.chromium.content_public.browser.GestureListenerManager;
import org.chromium.content_public.browser.GestureStateListener; import org.chromium.content_public.browser.GestureStateListener;
import org.chromium.content_public.browser.LoadUrlParams; import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.content_public.browser.RenderCoordinates;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
import org.chromium.net.test.EmbeddedTestServer; import org.chromium.net.test.EmbeddedTestServer;
import org.chromium.ui.test.util.UiRestriction; import org.chromium.ui.test.util.UiRestriction;
...@@ -629,6 +630,8 @@ public class ContextualSuggestionsTest { ...@@ -629,6 +630,8 @@ public class ContextualSuggestionsTest {
WebContents webContents = mActivityTestRule.getWebContents(); WebContents webContents = mActivityTestRule.getWebContents();
GestureListenerManager.fromWebContents(webContents).addListener(gestureStateListener); GestureListenerManager.fromWebContents(webContents).addListener(gestureStateListener);
View view = webContents.getViewAndroidDelegate().getContainerView(); View view = webContents.getViewAndroidDelegate().getContainerView();
int maxScrollOffset =
RenderCoordinates.fromWebContents(webContents).getMaxVerticalScrollPixInt();
// Verify that suggestions are not shown before scroll. // Verify that suggestions are not shown before scroll.
ThreadUtils.runOnUiThreadBlocking( ThreadUtils.runOnUiThreadBlocking(
...@@ -636,10 +639,10 @@ public class ContextualSuggestionsTest { ...@@ -636,10 +639,10 @@ public class ContextualSuggestionsTest {
assertEquals("Bottom sheet should be hidden before scroll.", BottomSheet.SheetState.HIDDEN, assertEquals("Bottom sheet should be hidden before scroll.", BottomSheet.SheetState.HIDDEN,
mBottomSheet.getSheetState()); mBottomSheet.getSheetState());
// Scroll the page to 30% and verify that the suggestions are not shown. The pixel to scroll // Scroll the page to 30% and verify that the suggestions are not shown.
// is hard coded (approximately) based on the html height of the TEST_PAGE.
int callCount = scrollChangedCallback.getCallCount(); int callCount = scrollChangedCallback.getCallCount();
ThreadUtils.runOnUiThreadBlocking(() -> view.scrollBy(0, 3000)); ThreadUtils.runOnUiThreadBlocking(
() -> view.scrollBy(0, Math.round(maxScrollOffset * 0.3f)));
scrollChangedCallback.waitForCallback(callCount); scrollChangedCallback.waitForCallback(callCount);
// Simulate call to show content without browser controls being hidden. // Simulate call to show content without browser controls being hidden.
...@@ -648,9 +651,10 @@ public class ContextualSuggestionsTest { ...@@ -648,9 +651,10 @@ public class ContextualSuggestionsTest {
assertEquals("Bottom sheet should be hidden on 30% scroll percentage.", assertEquals("Bottom sheet should be hidden on 30% scroll percentage.",
BottomSheet.SheetState.HIDDEN, mBottomSheet.getSheetState()); BottomSheet.SheetState.HIDDEN, mBottomSheet.getSheetState());
// Scroll the page to approximately 60% and verify that the suggestions are shown. // Scroll the page 20% more for a total of 50% and verify that the suggestions are shown.
callCount = scrollChangedCallback.getCallCount(); callCount = scrollChangedCallback.getCallCount();
ThreadUtils.runOnUiThreadBlocking(() -> view.scrollBy(0, 3000)); ThreadUtils.runOnUiThreadBlocking(
() -> view.scrollBy(0, Math.round(maxScrollOffset * 0.2f)));
scrollChangedCallback.waitForCallback(callCount); scrollChangedCallback.waitForCallback(callCount);
// Simulate call to show content without browser controls being hidden. // Simulate call to show content without browser controls being hidden.
......
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