| Index: android_webview/javatests/src/org/chromium/android_webview/test/AndroidScrollIntegrationTest.java
|
| diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AndroidScrollIntegrationTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AndroidScrollIntegrationTest.java
|
| index a2220236b9de4a80b29055f860cc63eef1383b20..9c522a5280978c9dfb1b0a402d858432419c8be3 100644
|
| --- a/android_webview/javatests/src/org/chromium/android_webview/test/AndroidScrollIntegrationTest.java
|
| +++ b/android_webview/javatests/src/org/chromium/android_webview/test/AndroidScrollIntegrationTest.java
|
| @@ -30,6 +30,7 @@ public class AndroidScrollIntegrationTest extends AwTestBase {
|
| private static class OverScrollByCallbackHelper extends CallbackHelper {
|
| int mDeltaX;
|
| int mDeltaY;
|
| + int mScrollRangeY;
|
|
|
| public int getDeltaX() {
|
| assert getCallCount() > 0;
|
| @@ -41,9 +42,15 @@ public class AndroidScrollIntegrationTest extends AwTestBase {
|
| return mDeltaY;
|
| }
|
|
|
| - public void notifyCalled(int deltaX, int deltaY) {
|
| + public int getScrollRangeY() {
|
| + assert getCallCount() > 0;
|
| + return mScrollRangeY;
|
| + }
|
| +
|
| + public void notifyCalled(int deltaX, int deltaY, int scrollRangeY) {
|
| mDeltaX = deltaX;
|
| mDeltaY = deltaY;
|
| + mScrollRangeY = scrollRangeY;
|
| notifyCalled();
|
| }
|
| }
|
| @@ -80,7 +87,7 @@ public class AndroidScrollIntegrationTest extends AwTestBase {
|
| protected boolean overScrollBy(int deltaX, int deltaY, int scrollX, int scrollY,
|
| int scrollRangeX, int scrollRangeY, int maxOverScrollX, int maxOverScrollY,
|
| boolean isTouchEvent) {
|
| - mOverScrollByCallbackHelper.notifyCalled(deltaX, deltaY);
|
| + mOverScrollByCallbackHelper.notifyCalled(deltaX, deltaY, scrollRangeY);
|
| return super.overScrollBy(deltaX, deltaY, scrollX, scrollY,
|
| scrollRangeX, scrollRangeY, maxOverScrollX, maxOverScrollY, isTouchEvent);
|
| }
|
| @@ -122,6 +129,9 @@ public class AndroidScrollIntegrationTest extends AwTestBase {
|
| private static final String TEST_PAGE_COMMON_HEADERS =
|
| "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"> " +
|
| "<style type=\"text/css\"> " +
|
| + " body { " +
|
| + " margin: 0px; " +
|
| + " } " +
|
| " div { " +
|
| " width:1000px; " +
|
| " height:10000px; " +
|
| @@ -322,6 +332,36 @@ public class AndroidScrollIntegrationTest extends AwTestBase {
|
|
|
| @SmallTest
|
| @Feature({"AndroidWebView"})
|
| + public void testJsScrollFromBody() throws Throwable {
|
| + final TestAwContentsClient contentsClient = new TestAwContentsClient();
|
| + final ScrollTestContainerView testContainerView =
|
| + (ScrollTestContainerView) createAwTestContainerViewOnMainSync(contentsClient);
|
| + enableJavaScriptOnUiThread(testContainerView.getAwContents());
|
| +
|
| + final double deviceDIPScale =
|
| + DeviceDisplayInfo.create(testContainerView.getContext()).getDIPScale();
|
| + final int targetScrollXCss = 132;
|
| + final int targetScrollYCss = 243;
|
| + final int targetScrollXPix = (int) Math.floor(targetScrollXCss * deviceDIPScale);
|
| + final int targetScrollYPix = (int) Math.floor(targetScrollYCss * deviceDIPScale);
|
| +
|
| + final String scrollFromBodyScript =
|
| + "<script> " +
|
| + " window.scrollTo(" + targetScrollXCss + ", " + targetScrollYCss + "); " +
|
| + "</script> ";
|
| +
|
| + final CallbackHelper onScrollToCallbackHelper =
|
| + testContainerView.getOnScrollToCallbackHelper();
|
| + final int scrollToCallCount = onScrollToCallbackHelper.getCallCount();
|
| + loadDataAsync(testContainerView.getAwContents(),
|
| + makeTestPage(null, null, scrollFromBodyScript), "text/html", false);
|
| + onScrollToCallbackHelper.waitForCallback(scrollToCallCount);
|
| +
|
| + assertScrollOnMainSync(testContainerView, targetScrollXPix, targetScrollYPix);
|
| + }
|
| +
|
| + @SmallTest
|
| + @Feature({"AndroidWebView"})
|
| public void testJsScrollCanBeAlteredByUi() throws Throwable {
|
| final TestAwContentsClient contentsClient = new TestAwContentsClient();
|
| final ScrollTestContainerView testContainerView =
|
| @@ -757,4 +797,47 @@ public class AndroidScrollIntegrationTest extends AwTestBase {
|
| null /* completionLatch */);
|
| onScrollUpdateGestureConsumedHelper.waitForCallback(callCount);
|
| }
|
| +
|
| + @SmallTest
|
| + @Feature({"AndroidWebView"})
|
| + public void testPinchZoomUpdatesScrollRangeSynchronously() throws Throwable {
|
| + final TestAwContentsClient contentsClient = new TestAwContentsClient();
|
| + final ScrollTestContainerView testContainerView =
|
| + (ScrollTestContainerView) createAwTestContainerViewOnMainSync(contentsClient);
|
| + final OverScrollByCallbackHelper overScrollByCallbackHelper =
|
| + testContainerView.getOverScrollByCallbackHelper();
|
| + final AwContents awContents = testContainerView.getAwContents();
|
| + enableJavaScriptOnUiThread(awContents);
|
| +
|
| + loadTestPageAndWaitForFirstFrame(testContainerView, contentsClient, null, "");
|
| +
|
| + getInstrumentation().runOnMainSync(new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + assertTrue(awContents.canZoomIn());
|
| +
|
| + int oldScrollRange =
|
| + awContents.computeVerticalScrollRange() - testContainerView.getHeight();
|
| + float oldScale = awContents.getScale();
|
| + int oldContentHeightApproximation =
|
| + (int) Math.ceil(awContents.computeVerticalScrollRange() / oldScale);
|
| +
|
| + awContents.zoomIn();
|
| +
|
| + int newScrollRange =
|
| + awContents.computeVerticalScrollRange() - testContainerView.getHeight();
|
| + float newScale = awContents.getScale();
|
| + int newContentHeightApproximation =
|
| + (int) Math.ceil(awContents.computeVerticalScrollRange() / newScale);
|
| +
|
| + assertTrue(String.format("Scale range should increase after zoom (%f) > (%f)",
|
| + newScale, oldScale), newScale > oldScale);
|
| + assertTrue(String.format("Scroll range should increase after zoom (%d) > (%d)",
|
| + newScrollRange, oldScrollRange), newScrollRange > oldScrollRange);
|
| + assertEquals(awContents.getContentHeightCss(), oldContentHeightApproximation);
|
| + assertEquals(awContents.getContentHeightCss(), newContentHeightApproximation);
|
| + }
|
| + });
|
| +
|
| + }
|
| }
|
|
|