Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1606)

Unified Diff: android_webview/javatests/src/org/chromium/android_webview/test/AndroidScrollIntegrationTest.java

Issue 256303006: Make LayerScrollOffsetDelegate updates consistent. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: less jni Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..e4dbda6eecf159bb4183a0163224ef72628d4537 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;
+ float mContentHeightCssFromScrollRange;
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 float getContentHeightCssFromScrollRange() {
+ assert getCallCount() > 0;
+ return mContentHeightCssFromScrollRange;
+ }
+
+ public void notifyCalled(int deltaX, int deltaY, float contentHeightCssFromScrollRange) {
mDeltaX = deltaX;
mDeltaY = deltaY;
+ mContentHeightCssFromScrollRange = contentHeightCssFromScrollRange;
notifyCalled();
}
}
@@ -80,7 +87,9 @@ 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);
+ float scale = getAwContents().getScale();
+ float contentHeightCss = (scrollRangeY + getHeight()) / scale;
+ mOverScrollByCallbackHelper.notifyCalled(deltaX, deltaY, contentHeightCss);
return super.overScrollBy(deltaX, deltaY, scrollX, scrollY,
scrollRangeX, scrollRangeY, maxOverScrollX, maxOverScrollY, isTouchEvent);
}
@@ -122,6 +131,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 +334,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 +799,41 @@ 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, "");
+
+ final int contentHeightCss = runTestOnUiThreadAndGetResult(new Callable<Integer>() {
+ @Override
+ public Integer call() {
+ return awContents.getContentHeightCss();
+ }
+ });
+
+ final int callCount = overScrollByCallbackHelper.getCallCount();
+ // This assumes pinch-zooming will also cause a scroll to re-focus the contents.
+ getInstrumentation().runOnMainSync(new Runnable() {
+ @Override
+ public void run() {
+ awContents.zoomIn();
+ }
+ });
+ overScrollByCallbackHelper.waitForCallback(callCount);
boliu 2014/04/30 05:48:42 If this is synchronous, should we check this is ca
mkosiba (inactive) 2014/05/01 11:13:25 Done.
+
+ // If the scale change did not propagate at the same time as the scroll offset change the
+ // contents height calculated from the scroll range and scale will not match the actual
+ // contents height.
+ assertEquals(contentHeightCss,
+ (int) overScrollByCallbackHelper.getContentHeightCssFromScrollRange());
+ }
}

Powered by Google App Engine
This is Rietveld 408576698