Index: android_webview/javatests/src/org/chromium/android_webview/test/AndroidViewIntegrationTest.java |
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AndroidViewIntegrationTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AndroidViewIntegrationTest.java |
index f4ba4d4e549923194a46785b198eb82c581aa384..49276649089d5289dc022a8ca100eda5fa5265a7 100644 |
--- a/android_webview/javatests/src/org/chromium/android_webview/test/AndroidViewIntegrationTest.java |
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/AndroidViewIntegrationTest.java |
@@ -204,16 +204,23 @@ public class AndroidViewIntegrationTest extends AwTestBase { |
assertTrue(mOnContentSizeChangedHelper.getHeight() > 0); |
} |
- private String makeHtmlPageOfSize(int widthCss, int heightCss) { |
+ private String makeHtmlPageOfSize(int widthCss, int heightCss, boolean heightPercent) { |
+ String content = "<div class=\"normal\">a</div>"; |
+ if (heightPercent) |
+ content += "<div class=\"heightPercent\">b</div>"; |
return CommonResources.makeHtmlPageFrom( |
"<style type=\"text/css\">" + |
"body { margin:0px; padding:0px; } " + |
- "div { " + |
+ ".normal { " + |
"width:" + widthCss + "px; " + |
"height:" + heightCss + "px; " + |
"background-color: red; " + |
"} " + |
- "</style>", "<div/>"); |
+ ".heightPercent { " + |
+ "height: 150%; " + |
+ "background-color: blue; " + |
+ "} " + |
+ "</style>", content); |
} |
private void waitForContentSizeToChangeTo(OnContentSizeChangedHelper helper, int callCount, |
@@ -232,9 +239,10 @@ public class AndroidViewIntegrationTest extends AwTestBase { |
} |
private void loadPageOfSizeAndWaitForSizeChange(AwContents awContents, |
- OnContentSizeChangedHelper helper, int widthCss, int heightCss) throws Exception { |
+ OnContentSizeChangedHelper helper, int widthCss, int heightCss, |
+ boolean heightPercent) throws Exception { |
- final String htmlData = makeHtmlPageOfSize(widthCss, heightCss); |
+ final String htmlData = makeHtmlPageOfSize(widthCss, heightCss, heightPercent); |
final int contentSizeChangeCallCount = helper.getCallCount(); |
loadDataAsync(awContents, htmlData, "text/html", false); |
@@ -253,7 +261,7 @@ public class AndroidViewIntegrationTest extends AwTestBase { |
final int contentHeightCss = 180; |
loadPageOfSizeAndWaitForSizeChange(testContainerView.getAwContents(), |
- mOnContentSizeChangedHelper, contentWidthCss, contentHeightCss); |
+ mOnContentSizeChangedHelper, contentWidthCss, contentHeightCss, false); |
} |
@SmallTest |
@@ -276,7 +284,7 @@ public class AndroidViewIntegrationTest extends AwTestBase { |
final int expectedHeightCss = contentHeightCss; |
loadPageOfSizeAndWaitForSizeChange(testContainerView.getAwContents(), |
- mOnContentSizeChangedHelper, expectedWidthCss, expectedHeightCss); |
+ mOnContentSizeChangedHelper, expectedWidthCss, expectedHeightCss, false); |
// This is to make sure that there are no more pending size change notifications. Ideally |
// we'd assert that the renderer is idle (has no pending layout passes) but that would |
@@ -286,4 +294,35 @@ public class AndroidViewIntegrationTest extends AwTestBase { |
assertEquals(expectedWidthCss, mOnContentSizeChangedHelper.getWidth()); |
assertEquals(expectedHeightCss, mOnContentSizeChangedHelper.getHeight()); |
} |
+ |
+ @SmallTest |
+ @Feature({"AndroidWebView"}) |
+ public void testViewSizedCorrectlyInWrapContentMode2() throws Throwable { |
+ final TestAwContentsClient contentsClient = new TestAwContentsClient(); |
+ final AwTestContainerView testContainerView = createCustomTestContainerViewOnMainSync( |
+ contentsClient, View.VISIBLE); |
+ assertZeroHeight(testContainerView); |
+ |
+ final double deviceDIPScale = |
+ DeviceDisplayInfo.create(testContainerView.getContext()).getDIPScale(); |
+ |
+ final int contentWidthCss = 142; |
+ final int contentHeightCss = 180; |
+ |
+ // In wrap-content mode the AwLayoutSizer will size the view to be as wide as the parent |
+ // view. |
+ final int expectedWidthCss = (int) (getRootLayoutWidthOnMainThread() / deviceDIPScale); |
+ final int expectedHeightCss = contentHeightCss; |
+ |
+ loadPageOfSizeAndWaitForSizeChange(testContainerView.getAwContents(), |
+ mOnContentSizeChangedHelper, expectedWidthCss, expectedHeightCss, true); |
+ |
+ // This is to make sure that there are no more pending size change notifications. Ideally |
+ // we'd assert that the renderer is idle (has no pending layout passes) but that would |
+ // require quite a bit of plumbing, so we just wait a bit and make sure the size hadn't |
+ // changed. |
+ Thread.sleep(CONTENT_SIZE_CHANGE_STABILITY_TIMEOUT_MS); |
+ assertEquals(expectedWidthCss, mOnContentSizeChangedHelper.getWidth()); |
+ assertEquals((int)(expectedHeightCss * 1.5), mOnContentSizeChangedHelper.getHeight()); |
+ } |
} |