Skip to content

Commit bce545c

Browse files
committed
fix number format exception
1 parent 4984c70 commit bce545c

File tree

4 files changed

+253
-3
lines changed

4 files changed

+253
-3
lines changed

src/main/java/org/htmlunit/platform/font/AwtFontUtil.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.text.AttributedString;
2121

2222
import org.apache.commons.lang3.StringUtils;
23+
import org.htmlunit.css.CssPixelValueConverter;
2324

2425
/**
2526
* <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br>
@@ -32,7 +33,7 @@ public class AwtFontUtil implements FontUtil {
3233
public int countLines(final String content, final int pixelWidth, final String fontSize) {
3334
final String[] lines = StringUtils.split(content, '\n');
3435
int lineCount = 0;
35-
final int fontSizeInt = Integer.parseInt(fontSize.substring(0, fontSize.length() - 2));
36+
final int fontSizeInt = CssPixelValueConverter.pixelValue(fontSize);
3637
final FontRenderContext fontRenderCtx = new FontRenderContext(null, false, true);
3738
for (final String line : lines) {
3839
if (StringUtils.isBlank(line)) {

src/test/java/org/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,7 @@ public void backgroundColor() throws Exception {
11191119
*/
11201120
@Test
11211121
@Alerts("10px")
1122-
public void fontSize() throws Exception {
1122+
public void fontSizePX() throws Exception {
11231123
final String html = DOCTYPE_HTML
11241124
+ "<html><body>\n"
11251125
+ "<div id='d0' style='font-size: 10px;'>\n"
@@ -1148,7 +1148,7 @@ public void fontSize() throws Exception {
11481148
EDGE = "10px",
11491149
FF = "10px",
11501150
FF_ESR = "10px")
1151-
public void fontSize2() throws Exception {
1151+
public void fontSizeEM() throws Exception {
11521152
final String html = DOCTYPE_HTML
11531153
+ "<html><body>\n"
11541154
+ "<div id='d0' style='font-size: 0.6em;'>\n"

src/test/java/org/htmlunit/javascript/host/css/property/ElementClientHeightTest.java

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import org.htmlunit.junit.annotation.HtmlUnitNYI;
2121
import org.junit.Test;
2222
import org.junit.runner.RunWith;
23+
import org.openqa.selenium.By;
24+
import org.openqa.selenium.WebDriver;
2325

2426
/**
2527
* Unit tests for {@code clientHeight} of an element.
@@ -2030,4 +2032,171 @@ public void slot() throws Exception {
20302032
loadPageVerifyTitle2(test("slot"));
20312033
}
20322034

2035+
/**
2036+
* Tests the relation between {@code fontSize} and {@code clientHeight}.
2037+
*
2038+
* @throws Exception if the test fails
2039+
*/
2040+
@Test
2041+
@Alerts(DEFAULT = "10, 11, 16, 18, 21, 27, 37, 55",
2042+
FF = "11, 12, 16, 18, 21, 28, 38, 56",
2043+
FF_ESR = "11, 12, 16, 18, 21, 28, 38, 56")
2044+
@HtmlUnitNYI(CHROME = "11, 11, 15, 18, 21, 28, 37, 55",
2045+
EDGE = "11, 11, 15, 18, 21, 28, 37, 55",
2046+
FF = "12, 12, 15, 18, 21, 29, 38, 56",
2047+
FF_ESR = "12, 12, 15, 18, 21, 29, 38, 56")
2048+
public void clientHeightSmallLarge() throws Exception {
2049+
final String html = DOCTYPE_HTML
2050+
+ "<html><head><body>\n"
2051+
+ " <div id='myDiv'>a</div>\n"
2052+
+ " <textarea id='myTextarea' cols='120' rows='20'></textarea>\n"
2053+
+ "<script>\n"
2054+
+ "var e = document.getElementById('myDiv');\n"
2055+
+ "var array = [];\n"
2056+
2057+
+ "e.style.fontSize = 'xx-small';\n"
2058+
+ "array.push(e.clientHeight);\n"
2059+
2060+
+ "e.style.fontSize = 'x-small';\n"
2061+
+ "array.push(e.clientHeight);\n"
2062+
2063+
+ "e.style.fontSize = 'small';\n"
2064+
+ "array.push(e.clientHeight);\n"
2065+
2066+
+ "e.style.fontSize = 'medium';\n"
2067+
+ "array.push(e.clientHeight);\n"
2068+
2069+
+ "e.style.fontSize = 'large';\n"
2070+
+ "array.push(e.clientHeight);\n"
2071+
2072+
+ "e.style.fontSize = 'x-large';\n"
2073+
+ "array.push(e.clientHeight);\n"
2074+
2075+
+ "e.style.fontSize = 'xx-large';\n"
2076+
+ "array.push(e.clientHeight);\n"
2077+
2078+
+ "e.style.fontSize = 'xxx-large';\n"
2079+
+ "array.push(e.clientHeight);\n"
2080+
2081+
+ "document.getElementById('myTextarea').value = array.join(', ');\n"
2082+
+ "</script></body></html>";
2083+
2084+
final WebDriver driver = loadPage2(html);
2085+
final String actual = driver.findElement(By.id("myTextarea")).getDomProperty("value");
2086+
assertEquals(getExpectedAlerts()[0], actual);
2087+
}
2088+
2089+
/**
2090+
* Tests the relation between {@code fontSize} and {@code clientHeight}.
2091+
*
2092+
* @throws Exception if the test fails
2093+
*/
2094+
@Test
2095+
@Alerts("16, 22")
2096+
@HtmlUnitNYI(CHROME = "15, 22",
2097+
EDGE = "15, 22",
2098+
FF = "15, 22",
2099+
FF_ESR = "15, 22")
2100+
public void clientHeightSmallerLarger() throws Exception {
2101+
final String html = DOCTYPE_HTML
2102+
+ "<html><head><body>\n"
2103+
+ " <div id='myDiv'>a</div>\n"
2104+
+ " <textarea id='myTextarea' cols='120' rows='20'></textarea>\n"
2105+
+ "<script>\n"
2106+
+ "var e = document.getElementById('myDiv');\n"
2107+
+ "var array = [];\n"
2108+
2109+
+ "e.style.fontSize = 'smaller';\n"
2110+
+ "array.push(e.clientHeight);\n"
2111+
2112+
+ "e.style.fontSize = 'larger';\n"
2113+
+ "array.push(e.clientHeight);\n"
2114+
2115+
+ "document.getElementById('myTextarea').value = array.join(', ');\n"
2116+
+ "</script></body></html>";
2117+
2118+
final WebDriver driver = loadPage2(html);
2119+
final String actual = driver.findElement(By.id("myTextarea")).getDomProperty("value");
2120+
assertEquals(getExpectedAlerts()[0], actual);
2121+
}
2122+
2123+
/**
2124+
* Tests the relation between {@code fontSize} and {@code clientHeight}.
2125+
*
2126+
* @throws Exception if the test fails
2127+
*/
2128+
@Test
2129+
@Alerts(DEFAULT = "11, 49, 6",
2130+
FF = "12, 49, 3",
2131+
FF_ESR = "12, 49, 3")
2132+
@HtmlUnitNYI(CHROME = "11, 49, 2",
2133+
EDGE = "11, 49, 2",
2134+
FF = "12, 49, 3",
2135+
FF_ESR = "12, 49, 3")
2136+
public void clientHeightUnits() throws Exception {
2137+
final String html = DOCTYPE_HTML
2138+
+ "<html><head><body>\n"
2139+
+ " <div id='myDivPX' style='font-size: 10px;'>a</div>\n"
2140+
+ " <div id='myDivEM' style='font-size: 2.7em;'>a</div>\n"
2141+
+ " <div id='myDivP' style='font-size: 10%;'>a</div>\n"
2142+
+ " <textarea id='myTextarea' cols='120' rows='20'></textarea>\n"
2143+
+ "<script>\n"
2144+
+ "var array = [];\n"
2145+
2146+
+ "var e = document.getElementById('myDivPX');\n"
2147+
+ "array.push(e.clientHeight);\n"
2148+
2149+
+ "e = document.getElementById('myDivEM');\n"
2150+
+ "array.push(e.clientHeight);\n"
2151+
2152+
+ "e = document.getElementById('myDivP');\n"
2153+
+ "array.push(e.clientHeight);\n"
2154+
2155+
+ "document.getElementById('myTextarea').value = array.join(', ');\n"
2156+
+ "</script></body></html>";
2157+
2158+
final WebDriver driver = loadPage2(html);
2159+
final String actual = driver.findElement(By.id("myTextarea")).getDomProperty("value");
2160+
assertEquals(getExpectedAlerts()[0], actual);
2161+
}
2162+
2163+
/**
2164+
* Tests the relation between {@code fontSize} and {@code clientHeight}.
2165+
*
2166+
* @throws Exception if the test fails
2167+
*/
2168+
@Test
2169+
@Alerts(DEFAULT = "12, 49, 6",
2170+
FF = "13, 49, 4",
2171+
FF_ESR = "13, 49, 4")
2172+
@HtmlUnitNYI(CHROME = "12, 49, 4",
2173+
EDGE = "12, 49, 4",
2174+
FF = "13, 49, 5",
2175+
FF_ESR = "13, 49, 5")
2176+
public void clientHeightUnitsWidth() throws Exception {
2177+
final String html = DOCTYPE_HTML
2178+
+ "<html><head><body>\n"
2179+
+ " <div id='myDivPX' style='font-size: 11.4px; width: 40px;'>a</div>\n"
2180+
+ " <div id='myDivEM' style='font-size: 2.7em; width: 40px;'>a</div>\n"
2181+
+ " <div id='myDivP' style='font-size: 17%; width: 40px;'>a</div>\n"
2182+
+ " <textarea id='myTextarea' cols='120' rows='20'></textarea>\n"
2183+
+ "<script>\n"
2184+
+ "var array = [];\n"
2185+
2186+
+ "var e = document.getElementById('myDivPX');\n"
2187+
+ "array.push(e.clientHeight);\n"
2188+
2189+
+ "e = document.getElementById('myDivEM');\n"
2190+
+ "array.push(e.clientHeight);\n"
2191+
2192+
+ "e = document.getElementById('myDivP');\n"
2193+
+ "array.push(e.clientHeight);\n"
2194+
2195+
+ "document.getElementById('myTextarea').value = array.join(', ');\n"
2196+
+ "</script></body></html>";
2197+
2198+
final WebDriver driver = loadPage2(html);
2199+
final String actual = driver.findElement(By.id("myTextarea")).getDomProperty("value");
2200+
assertEquals(getExpectedAlerts()[0], actual);
2201+
}
20332202
}

src/test/java/org/htmlunit/javascript/host/css/property/ElementOffsetHeightTest.java

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,86 @@ public void offsetHeightSmallerLarger() throws Exception {
255255
assertEquals(getExpectedAlerts()[0], actual);
256256
}
257257

258+
/**
259+
* Tests the relation between {@code fontSize} and {@code offsetHeight}.
260+
*
261+
* @throws Exception if the test fails
262+
*/
263+
@Test
264+
@Alerts(DEFAULT = "11, 49, 6",
265+
FF = "12, 49, 3",
266+
FF_ESR = "12, 49, 3")
267+
@HtmlUnitNYI(CHROME = "11, 49, 2",
268+
EDGE = "11, 49, 2",
269+
FF = "12, 49, 3",
270+
FF_ESR = "12, 49, 3")
271+
public void offsetHeightUnits() throws Exception {
272+
final String html = DOCTYPE_HTML
273+
+ "<html><head><body>\n"
274+
+ " <div id='myDivPX' style='font-size: 10px;'>a</div>\n"
275+
+ " <div id='myDivEM' style='font-size: 2.7em;'>a</div>\n"
276+
+ " <div id='myDivP' style='font-size: 10%;'>a</div>\n"
277+
+ " <textarea id='myTextarea' cols='120' rows='20'></textarea>\n"
278+
+ "<script>\n"
279+
+ "var array = [];\n"
280+
281+
+ "var e = document.getElementById('myDivPX');\n"
282+
+ "array.push(e.offsetHeight);\n"
283+
284+
+ "e = document.getElementById('myDivEM');\n"
285+
+ "array.push(e.offsetHeight);\n"
286+
287+
+ "e = document.getElementById('myDivP');\n"
288+
+ "array.push(e.offsetHeight);\n"
289+
290+
+ "document.getElementById('myTextarea').value = array.join(', ');\n"
291+
+ "</script></body></html>";
292+
293+
final WebDriver driver = loadPage2(html);
294+
final String actual = driver.findElement(By.id("myTextarea")).getDomProperty("value");
295+
assertEquals(getExpectedAlerts()[0], actual);
296+
}
297+
298+
/**
299+
* Tests the relation between {@code fontSize} and {@code offsetHeight}.
300+
*
301+
* @throws Exception if the test fails
302+
*/
303+
@Test
304+
@Alerts(DEFAULT = "12, 49, 6",
305+
FF = "13, 49, 4",
306+
FF_ESR = "13, 49, 4")
307+
@HtmlUnitNYI(CHROME = "12, 49, 4",
308+
EDGE = "12, 49, 4",
309+
FF = "13, 49, 5",
310+
FF_ESR = "13, 49, 5")
311+
public void offsetHeightUnitsWidth() throws Exception {
312+
final String html = DOCTYPE_HTML
313+
+ "<html><head><body>\n"
314+
+ " <div id='myDivPX' style='font-size: 11.4px; width: 40px;'>a</div>\n"
315+
+ " <div id='myDivEM' style='font-size: 2.7em; width: 40px;'>a</div>\n"
316+
+ " <div id='myDivP' style='font-size: 17%; width: 40px;'>a</div>\n"
317+
+ " <textarea id='myTextarea' cols='120' rows='20'></textarea>\n"
318+
+ "<script>\n"
319+
+ "var array = [];\n"
320+
321+
+ "var e = document.getElementById('myDivPX');\n"
322+
+ "array.push(e.offsetHeight);\n"
323+
324+
+ "e = document.getElementById('myDivEM');\n"
325+
+ "array.push(e.offsetHeight);\n"
326+
327+
+ "e = document.getElementById('myDivP');\n"
328+
+ "array.push(e.offsetHeight);\n"
329+
330+
+ "document.getElementById('myTextarea').value = array.join(', ');\n"
331+
+ "</script></body></html>";
332+
333+
final WebDriver driver = loadPage2(html);
334+
final String actual = driver.findElement(By.id("myTextarea")).getDomProperty("value");
335+
assertEquals(getExpectedAlerts()[0], actual);
336+
}
337+
258338
/**
259339
* Test case for #124.
260340
*

0 commit comments

Comments
 (0)