[android_webview] Fix layout in AT_MOST mode.

This is a cherry-pick of http://crrev.com/24163004

> Due to a bug the AwLayoutSizer was ignoring all transitions
> to a content size greater than the AT_MOST height limit even
> if the previous height was less than the AT_MOST limit.
>
> BUG=internal b/10819823

BUG: 10819823
Change-Id: Ifab400b9e10c94a56b8e8eacf98cc55c2b9301a2
diff --git a/android_webview/java/src/org/chromium/android_webview/AwLayoutSizer.java b/android_webview/java/src/org/chromium/android_webview/AwLayoutSizer.java
index 20ac8b5..97efee1 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwLayoutSizer.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwLayoutSizer.java
@@ -38,7 +38,7 @@
 
     private double mDIPScale;
 
-    // Was our heightSpec is AT_MOST the last time onMeasure was called?
+    // Was our height larger than the AT_MOST constraint the last time onMeasure was called?
     private boolean mHeightMeasurementLimited;
     // If mHeightMeasurementLimited is true then this contains the height limit.
     private int mHeightMeasurementLimit;
@@ -152,12 +152,11 @@
         // Always use the given size unless unspecified. This matches WebViewClassic behavior.
         mWidthMeasurementIsFixed = (widthMode != MeasureSpec.UNSPECIFIED);
         mHeightMeasurementIsFixed = (heightMode == MeasureSpec.EXACTLY);
-        mHeightMeasurementLimited = (heightMode == MeasureSpec.AT_MOST);
+        mHeightMeasurementLimited =
+            (heightMode == MeasureSpec.AT_MOST) && (contentHeightPix > heightSize);
         mHeightMeasurementLimit = heightSize;
 
-        final boolean measuredHeightClipped =
-            mHeightMeasurementLimited && (contentHeightPix > heightSize);
-        if (mHeightMeasurementIsFixed || measuredHeightClipped) {
+        if (mHeightMeasurementIsFixed || mHeightMeasurementLimited) {
             measuredHeight = heightSize;
         }
 
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 1d75dd8..327fcff 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
@@ -151,6 +151,32 @@
 
     @SmallTest
     @Feature({"AndroidWebView"})
+    public void testContentHeightGrowthRequestsLayoutInAtMostSizeMode() {
+        AwLayoutSizer layoutSizer = new AwLayoutSizer();
+        LayoutSizerDelegate delegate = new LayoutSizerDelegate();
+        layoutSizer.setDelegate(delegate);
+        layoutSizer.setDIPScale(DIP_SCALE);
+
+        layoutSizer.onPageScaleChanged(INITIAL_PAGE_SCALE);
+        layoutSizer.onContentSizeChanged(SMALLER_CONTENT_SIZE, SMALLER_CONTENT_SIZE);
+        layoutSizer.onMeasure(
+                MeasureSpec.makeMeasureSpec(AT_MOST_MEASURE_SIZE, MeasureSpec.AT_MOST),
+                MeasureSpec.makeMeasureSpec(AT_MOST_MEASURE_SIZE, MeasureSpec.AT_MOST));
+        assertEquals(AT_MOST_MEASURE_SIZE, delegate.measuredWidth);
+        assertEquals(SMALLER_CONTENT_SIZE, delegate.measuredHeight);
+
+        int requestLayoutCallCount = delegate.requestLayoutCallCount;
+        layoutSizer.onContentSizeChanged(SMALLER_CONTENT_SIZE, AT_MOST_MEASURE_SIZE - 1);
+        assertEquals(requestLayoutCallCount + 1, delegate.requestLayoutCallCount);
+
+        // Test that crossing the AT_MOST_MEASURE_SIZE threshold results in a requestLayout.
+        requestLayoutCallCount = delegate.requestLayoutCallCount;
+        layoutSizer.onContentSizeChanged(SMALLER_CONTENT_SIZE, AT_MOST_MEASURE_SIZE + 1);
+        assertEquals(requestLayoutCallCount + 1, delegate.requestLayoutCallCount);
+    }
+
+    @SmallTest
+    @Feature({"AndroidWebView"})
     public void testContentHeightShrinksAfterAtMostSize() {
         AwLayoutSizer layoutSizer = new AwLayoutSizer();
         LayoutSizerDelegate delegate = new LayoutSizerDelegate();