The test code:
@Test
public void testMain() throws Exception
{
List<String> alerts = new ArrayList<>();
WebClient wc=new WebClient();
wc.setAlertHandler(new CollectingAlertHandler(alerts));
wc.getPage(getClass().getResource("element_size.html"));
System.out.println(alerts.toString());
}
The element_size.html page:
<html>
<head>
<title>size test</title>
</head>
<body>
<div id="div1">
<iframe height="360" src="http://www.bing.com" frameborder="0" width="410"></iframe>
</div>
<script language="JavaScript">
alert(div1.offsetHeight);
</script>
</body>
</html>
In real browser, the alert result is 360. In htmlunit, the result is 0.
If I comment out the code below in ComputedCSSStyleDeclaration.getCalculatedHeight(), the alert result is 154. Though it's still not the same as the browser, but it's much better.
private int getCalculatedHeight() {
if (height_ != null) {
return height_.intValue();
}
int height = getEmptyHeight();
// if (height == 0) {
// height_ = Integer.valueOf(0);
// return 0;
// }
if (super.getHeight().isEmpty()) {
I also noticed the logic in getCalculatedWidth() is different:
private int getCalculatedWidth() {
if (width_ != null) {
return width_.intValue();
}
final Element element = getElement();
final DomNode node = element.getDomNodeOrDie();
if (!node.mayBeDisplayed()) {
width_ = Integer.valueOf(0);
return 0;
}
Sorry, but this is not that simple.... will try to fix this if there is time