| Index: android_webview/javatests/src/org/chromium/android_webview/test/AwLayoutSizerTest.java
|
| diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwLayoutSizerTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwLayoutSizerTest.java
|
| index 4ef786bfbb93e227de15ea778446edf9b9623cf6..18e06ebb9116efd5bf3810e65345dcb29b0ae4cf 100644
|
| --- a/android_webview/javatests/src/org/chromium/android_webview/test/AwLayoutSizerTest.java
|
| +++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwLayoutSizerTest.java
|
| @@ -12,14 +12,16 @@ import android.view.View.MeasureSpec;
|
| import org.chromium.android_webview.AwLayoutSizer;
|
| import org.chromium.base.test.util.Feature;
|
|
|
| +/**
|
| + * Unittests for the AwLayoutSizer class.
|
| + */
|
| public class AwLayoutSizerTest extends InstrumentationTestCase {
|
| static class LayoutSizerDelegate implements AwLayoutSizer.Delegate {
|
| public int requestLayoutCallCount;
|
| public boolean setMeasuredDimensionCalled;
|
| public int measuredWidth;
|
| public int measuredHeight;
|
| - public int fixedLayoutWidth;
|
| - public int fixedLayoutHeight;
|
| + public boolean forceZeroHeight;
|
| public boolean heightWrapContent;
|
|
|
| @Override
|
| @@ -35,9 +37,8 @@ public class AwLayoutSizerTest extends InstrumentationTestCase {
|
| }
|
|
|
| @Override
|
| - public void setFixedLayoutSize(int widthDip, int heightDip) {
|
| - fixedLayoutWidth = widthDip;
|
| - fixedLayoutHeight = heightDip;
|
| + public void setForceZeroLayoutHeight(boolean forceZeroHeight) {
|
| + this.forceZeroHeight = forceZeroHeight;
|
| }
|
|
|
| @Override
|
| @@ -347,16 +348,6 @@ public class AwLayoutSizerTest extends InstrumentationTestCase {
|
| MeasureSpec.makeMeasureSpec(measuredHeight, MeasureSpec.EXACTLY));
|
| assertEquals(measuredWidth, delegate.measuredWidth & View.MEASURED_SIZE_MASK);
|
| assertEquals(measuredHeight, delegate.measuredHeight & View.MEASURED_SIZE_MASK);
|
| -
|
| - layoutSizer.onSizeChanged(measuredWidth, measuredHeight, 0, 0);
|
| -
|
| - assertEquals(0, delegate.fixedLayoutWidth);
|
| - assertEquals(0, delegate.fixedLayoutHeight);
|
| -
|
| - layoutSizer.onPageScaleChanged(2.0f);
|
| -
|
| - assertEquals(0, delegate.fixedLayoutWidth);
|
| - assertEquals(0, delegate.fixedLayoutHeight);
|
| }
|
|
|
| @SmallTest
|
| @@ -388,54 +379,6 @@ public class AwLayoutSizerTest extends InstrumentationTestCase {
|
|
|
| @SmallTest
|
| @Feature({"AndroidWebView"})
|
| - public void testViewportWithUnspecifiedMeasureSpec() {
|
| - AwLayoutSizer layoutSizer = new AwLayoutSizer();
|
| - LayoutSizerDelegate delegate = new LayoutSizerDelegate();
|
| - layoutSizer.setDelegate(delegate);
|
| -
|
| - final float dipScale = 1.5f;
|
| - final int pageScale = 2;
|
| - final int dipAndPageScale = (int) (dipScale * pageScale);
|
| -
|
| - int contentWidth = 800;
|
| - int contentHeight = 400;
|
| - int atMostWidth = contentWidth * dipAndPageScale;
|
| - int atMostHeight = contentHeight * dipAndPageScale;
|
| -
|
| - layoutSizer.setDIPScale(dipScale);
|
| - layoutSizer.onContentSizeChanged(contentWidth, contentHeight);
|
| - layoutSizer.onPageScaleChanged(pageScale);
|
| - layoutSizer.onMeasure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
|
| - MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
|
| -
|
| - assertTrue(delegate.setMeasuredDimensionCalled);
|
| - int measuredWidth = delegate.measuredWidth & View.MEASURED_SIZE_MASK;
|
| - int measuredHeight = delegate.measuredHeight & View.MEASURED_SIZE_MASK;
|
| -
|
| - int sizeWidth = measuredWidth;
|
| - int sizeHeight = measuredHeight;
|
| - layoutSizer.onSizeChanged(sizeWidth, sizeHeight, 0, 0);
|
| -
|
| - assertEquals(contentWidth, delegate.fixedLayoutWidth);
|
| - assertEquals(AwLayoutSizer.FIXED_LAYOUT_HEIGHT, delegate.fixedLayoutHeight);
|
| -
|
| - sizeWidth = measuredWidth * 2;
|
| - sizeHeight = measuredHeight * 2;
|
| - layoutSizer.onSizeChanged(sizeWidth, sizeHeight, 0, 0);
|
| -
|
| - assertEquals(sizeWidth / dipAndPageScale, delegate.fixedLayoutWidth);
|
| - assertEquals(AwLayoutSizer.FIXED_LAYOUT_HEIGHT, delegate.fixedLayoutHeight);
|
| -
|
| - sizeWidth = measuredWidth / 2;
|
| - sizeHeight = measuredHeight / 2;
|
| - layoutSizer.onSizeChanged(sizeWidth, sizeHeight, 0, 0);
|
| -
|
| - assertEquals(sizeWidth / dipAndPageScale, delegate.fixedLayoutWidth);
|
| - assertEquals(AwLayoutSizer.FIXED_LAYOUT_HEIGHT, delegate.fixedLayoutHeight);
|
| - }
|
| -
|
| - @SmallTest
|
| - @Feature({"AndroidWebView"})
|
| public void testViewportWithAtMostMeasureSpec() {
|
| AwLayoutSizer layoutSizer = new AwLayoutSizer();
|
| LayoutSizerDelegate delegate = new LayoutSizerDelegate();
|
| @@ -451,6 +394,8 @@ public class AwLayoutSizerTest extends InstrumentationTestCase {
|
| int contentWidthPix = contentWidth * dipAndPageScale;
|
| int contentHeightPix = contentHeight * dipAndPageScale;
|
|
|
| + assertFalse(delegate.forceZeroHeight);
|
| +
|
| layoutSizer.setDIPScale(dipScale);
|
| layoutSizer.onContentSizeChanged(contentWidth, contentHeight);
|
| layoutSizer.onPageScaleChanged(pageScale);
|
| @@ -458,54 +403,21 @@ public class AwLayoutSizerTest extends InstrumentationTestCase {
|
| MeasureSpec.makeMeasureSpec(contentHeightPix * 2, MeasureSpec.AT_MOST));
|
|
|
| assertTrue(delegate.setMeasuredDimensionCalled);
|
| + assertFalse(delegate.forceZeroHeight);
|
| +
|
| int measuredWidth = delegate.measuredWidth & View.MEASURED_SIZE_MASK;
|
| int measuredHeight = delegate.measuredHeight & View.MEASURED_SIZE_MASK;
|
| + layoutSizer.onSizeChanged(measuredWidth, measuredHeight, 0, 0);
|
|
|
| - int sizeWidth = measuredWidth;
|
| - int sizeHeight = measuredHeight;
|
| - layoutSizer.onSizeChanged(sizeWidth, sizeHeight, 0, 0);
|
| -
|
| - assertEquals(contentWidth, delegate.fixedLayoutWidth);
|
| - assertEquals(AwLayoutSizer.FIXED_LAYOUT_HEIGHT, delegate.fixedLayoutHeight);
|
| - }
|
| -
|
| - @SmallTest
|
| - @Feature({"AndroidWebView"})
|
| - public void testFixedLayoutViewportGoesBackToZeroWithWrapContentMeasureSpec() {
|
| - AwLayoutSizer layoutSizer = new AwLayoutSizer();
|
| - LayoutSizerDelegate delegate = new LayoutSizerDelegate();
|
| - layoutSizer.setDelegate(delegate);
|
| - layoutSizer.setDIPScale(DIP_SCALE);
|
| -
|
| - layoutSizer.onContentSizeChanged(FIRST_CONTENT_WIDTH, FIRST_CONTENT_HEIGHT);
|
| - layoutSizer.onPageScaleChanged(INITIAL_PAGE_SCALE);
|
| - layoutSizer.onMeasure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
|
| - MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
|
| - layoutSizer.onSizeChanged((int) (FIRST_CONTENT_WIDTH * DIP_SCALE),
|
| - (int) (FIRST_CONTENT_HEIGHT * DIP_SCALE), 0, 0);
|
| -
|
| - assertTrue(delegate.fixedLayoutWidth != 0);
|
| - assertEquals(AwLayoutSizer.FIXED_LAYOUT_HEIGHT, delegate.fixedLayoutHeight);
|
| -
|
| - layoutSizer.onContentSizeChanged(FIRST_CONTENT_WIDTH, AwLayoutSizer.FIXED_LAYOUT_HEIGHT);
|
| - layoutSizer.onSizeChanged((int) (FIRST_CONTENT_WIDTH * DIP_SCALE),
|
| - (int) (FIRST_CONTENT_HEIGHT * DIP_SCALE), 0, 0);
|
| - assertTrue(delegate.fixedLayoutWidth != 0);
|
| - assertEquals(0, delegate.fixedLayoutHeight);
|
| -
|
| - layoutSizer.onContentSizeChanged(FIRST_CONTENT_WIDTH, 0);
|
| - layoutSizer.onSizeChanged((int) (FIRST_CONTENT_WIDTH * DIP_SCALE),
|
| - (int) (FIRST_CONTENT_HEIGHT * DIP_SCALE), 0, 0);
|
| - assertTrue(delegate.fixedLayoutWidth != 0);
|
| - assertEquals(0, delegate.fixedLayoutHeight);
|
| + assertTrue(delegate.forceZeroHeight);
|
| }
|
|
|
| @SmallTest
|
| @Feature({"AndroidWebView"})
|
| - public void testFixedLayoutSizeUpdatedOnPageScaleChangeItNoLayoutRequest() {
|
| + public void testFixedLayoutSizeDependsOnHeightWrapContent() {
|
| AwLayoutSizer layoutSizer = new AwLayoutSizer();
|
| LayoutSizerDelegate delegate = new LayoutSizerDelegate();
|
| - delegate.heightWrapContent = true;
|
| + delegate.heightWrapContent = false;
|
| layoutSizer.setDelegate(delegate);
|
| layoutSizer.setDIPScale(DIP_SCALE);
|
|
|
| @@ -516,44 +428,12 @@ public class AwLayoutSizerTest extends InstrumentationTestCase {
|
| MeasureSpec.makeMeasureSpec(AT_MOST_MEASURE_SIZE, MeasureSpec.AT_MOST));
|
| layoutSizer.onSizeChanged(AT_MOST_MEASURE_SIZE, AT_MOST_MEASURE_SIZE, 0, 0);
|
|
|
| - assertTrue(delegate.fixedLayoutWidth != 0);
|
| - final int fixedLayoutWidth = delegate.fixedLayoutWidth;
|
| - final int requestLayoutCallCount = delegate.requestLayoutCallCount;
|
| - layoutSizer.onPageScaleChanged(INITIAL_PAGE_SCALE * 2f);
|
| - assertEquals(requestLayoutCallCount, delegate.requestLayoutCallCount);
|
| - assertEquals(fixedLayoutWidth / 2, delegate.fixedLayoutWidth);
|
| - }
|
| -
|
| - @SmallTest
|
| - @Feature({"AndroidWebView"})
|
| - public void testFixedLayoutSizeUpdatedIfNoSizeChangeAfterLayoutRequested() {
|
| - AwLayoutSizer layoutSizer = new AwLayoutSizer();
|
| - LayoutSizerDelegate delegate = new LayoutSizerDelegate();
|
| - layoutSizer.setDelegate(delegate);
|
| - layoutSizer.setDIPScale(DIP_SCALE);
|
| -
|
| - layoutSizer.onContentSizeChanged(FIRST_CONTENT_WIDTH, FIRST_CONTENT_HEIGHT);
|
| - layoutSizer.onPageScaleChanged(INITIAL_PAGE_SCALE);
|
| - layoutSizer.onMeasure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
|
| - MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
|
| -
|
| - layoutSizer.onSizeChanged((int) (FIRST_CONTENT_WIDTH * DIP_SCALE),
|
| - (int) (FIRST_CONTENT_HEIGHT * DIP_SCALE), 0, 0);
|
| -
|
| - assertTrue(delegate.fixedLayoutWidth != 0);
|
| - final int fixedLayoutWidth = delegate.fixedLayoutWidth;
|
| - final int requestLayoutCallCount = delegate.requestLayoutCallCount;
|
| - layoutSizer.onPageScaleChanged(INITIAL_PAGE_SCALE * 0.5f);
|
| - assertEquals(requestLayoutCallCount + 1, delegate.requestLayoutCallCount);
|
| - assertEquals(fixedLayoutWidth, delegate.fixedLayoutWidth);
|
| + assertFalse(delegate.forceZeroHeight);
|
|
|
| - // onMeasure and onLayoutChange should always be called as a result of the AwLayoutSizer
|
| - // calling Delegate.requestLayout.
|
| - layoutSizer.onMeasure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
|
| - MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
|
| - layoutSizer.onLayoutChange();
|
| + delegate.heightWrapContent = true;
|
| + layoutSizer.onSizeChanged(AT_MOST_MEASURE_SIZE, AT_MOST_MEASURE_SIZE, 0, 0);
|
|
|
| - assertEquals(fixedLayoutWidth * 2, delegate.fixedLayoutWidth);
|
| + assertTrue(delegate.forceZeroHeight);
|
| }
|
|
|
| @SmallTest
|
| @@ -572,7 +452,12 @@ public class AwLayoutSizerTest extends InstrumentationTestCase {
|
| MeasureSpec.makeMeasureSpec(AT_MOST_MEASURE_SIZE, MeasureSpec.AT_MOST));
|
| layoutSizer.onSizeChanged(AT_MOST_MEASURE_SIZE, AT_MOST_MEASURE_SIZE, 0, 0);
|
|
|
| - assertEquals(0, delegate.fixedLayoutWidth);
|
| - assertEquals(0, delegate.fixedLayoutHeight);
|
| + assertFalse(delegate.forceZeroHeight);
|
| +
|
| + layoutSizer.onMeasure(
|
| + MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
|
| + MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
|
| + layoutSizer.onSizeChanged(AT_MOST_MEASURE_SIZE, AT_MOST_MEASURE_SIZE, 0, 0);
|
| + assertFalse(delegate.forceZeroHeight);
|
| }
|
| }
|
|
|