From: <rb...@us...> - 2013-06-01 18:45:00
|
Revision: 8317 http://sourceforge.net/p/htmlunit/code/8317 Author: rbri Date: 2013-06-01 18:44:57 +0000 (Sat, 01 Jun 2013) Log Message: ----------- Textarea cols() and rows() property processing fixed. Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTextAreaElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTextAreaElementTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-06-01 14:28:20 UTC (rev 8316) +++ trunk/htmlunit/src/changes/changes.xml 2013-06-01 18:44:57 UTC (rev 8317) @@ -9,6 +9,9 @@ <body> <release version="2.13" date="???" description="Bugfixes"> <action type="fix" dev="rbri"> + Textarea cols() and rows() property processing fixed. + </action> + <action type="fix" dev="rbri"> Basefont support removed from Firefox after 3.6. </action> <action type="fix" dev="rbri"> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-06-01 14:28:20 UTC (rev 8316) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-06-01 18:44:57 UTC (rev 8317) @@ -1105,27 +1105,41 @@ /** Getting the property cols returns 20, if the defined value is not convertible into an integer (IE). * FF returns -1 in this case. */ - @BrowserFeature(@WebBrowser(IE)) - JS_TEXT_AREA_COLS_RETURNS_20, + @BrowserFeature(@WebBrowser(value = FF, maxVersion = 3.6f)) + JS_TEXT_AREA_COLS_RETURNS_MINUS1, /** Getting the property rows returns 2, if the defined value is not convertible into an integer (IE). * FF returns -1 in this case. */ + @BrowserFeature(@WebBrowser(value = FF, maxVersion = 3.6f)) + JS_TEXT_AREA_ROWS_RETURNS_MINUS1, + + /** Setting the property cols throws an exception, if the provided value is less + * than 0 (IE). + * FF ignores the provided value in this case. + */ @BrowserFeature(@WebBrowser(IE)) - JS_TEXT_AREA_ROWS_RETURNS_2, + JS_TEXT_AREA_SET_COLS_NEGATIVE_THROWS_EXCEPTION, /** Setting the property cols throws an exception, if the provided value is not * convertible into an integer (IE). * FF ignores the provided value in this case and sets cols to 0. */ - @BrowserFeature(@WebBrowser(IE)) + @BrowserFeature({ @WebBrowser(IE), @WebBrowser(value = FF, minVersion = 10) }) JS_TEXT_AREA_SET_COLS_THROWS_EXCEPTION, + /** Setting the property rows throws an exception, if the provided value is less + * than 0 (IE). + * FF ignores the provided value in this case. + */ + @BrowserFeature(@WebBrowser(IE)) + JS_TEXT_AREA_SET_ROWS_NEGATIVE_THROWS_EXCEPTION, + /** Setting the property rows throws an exception, if the provided value is not * convertible into an integer (IE). * FF ignores the provided value in this case and sets rows to 0. */ - @BrowserFeature(@WebBrowser(IE)) + @BrowserFeature({ @WebBrowser(IE), @WebBrowser(value = FF, minVersion = 10) }) JS_TEXT_AREA_SET_ROWS_THROWS_EXCEPTION, /** It looks likes TreeWalker.expandEntityReferences is always <code>false</code> for FF17. Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTextAreaElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTextAreaElement.java 2013-06-01 14:28:20 UTC (rev 8316) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTextAreaElement.java 2013-06-01 18:44:57 UTC (rev 8317) @@ -14,9 +14,11 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.html; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_TEXT_AREA_COLS_RETURNS_20; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_TEXT_AREA_ROWS_RETURNS_2; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_TEXT_AREA_COLS_RETURNS_MINUS1; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_TEXT_AREA_ROWS_RETURNS_MINUS1; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_TEXT_AREA_SET_COLS_NEGATIVE_THROWS_EXCEPTION; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_TEXT_AREA_SET_COLS_THROWS_EXCEPTION; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_TEXT_AREA_SET_ROWS_NEGATIVE_THROWS_EXCEPTION; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_TEXT_AREA_SET_ROWS_THROWS_EXCEPTION; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.TEXTAREA_CRNL; import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.FF; @@ -91,10 +93,10 @@ return Integer.parseInt(s); } catch (final NumberFormatException e) { - if (getBrowserVersion().hasFeature(JS_TEXT_AREA_COLS_RETURNS_20)) { - return 20; + if (getBrowserVersion().hasFeature(JS_TEXT_AREA_COLS_RETURNS_MINUS1)) { + return -1; } - return -1; + return 20; } } @@ -108,13 +110,21 @@ try { i = Float.valueOf(cols).intValue(); if (i < 0) { - throw new NumberFormatException("New value for cols '" + cols + "' is smaller than zero."); + if (getBrowserVersion().hasFeature(JS_TEXT_AREA_SET_COLS_NEGATIVE_THROWS_EXCEPTION) + || getBrowserVersion().hasFeature(JS_TEXT_AREA_COLS_RETURNS_MINUS1)) { + throw new NumberFormatException("New value for cols '" + cols + "' is smaller than zero."); + } + getDomNodeOrDie().setAttribute("cols", null); + return; } } catch (final NumberFormatException e) { if (getBrowserVersion().hasFeature(JS_TEXT_AREA_SET_COLS_THROWS_EXCEPTION)) { throw Context.throwAsScriptRuntimeEx(e); } + if (!getBrowserVersion().hasFeature(JS_TEXT_AREA_COLS_RETURNS_MINUS1)) { + return; + } i = 0; } getDomNodeOrDie().setAttribute("cols", Integer.toString(i)); @@ -131,10 +141,10 @@ return Integer.parseInt(s); } catch (final NumberFormatException e) { - if (getBrowserVersion().hasFeature(JS_TEXT_AREA_ROWS_RETURNS_2)) { - return 2; + if (getBrowserVersion().hasFeature(JS_TEXT_AREA_ROWS_RETURNS_MINUS1)) { + return -1; } - return -1; + return 2; } } @@ -148,13 +158,21 @@ try { i = new Float(rows).intValue(); if (i < 0) { - throw new NumberFormatException("New value for rows '" + rows + "' is smaller than zero."); + if (getBrowserVersion().hasFeature(JS_TEXT_AREA_SET_ROWS_NEGATIVE_THROWS_EXCEPTION) + || getBrowserVersion().hasFeature(JS_TEXT_AREA_COLS_RETURNS_MINUS1)) { + throw new NumberFormatException("New value for rows '" + rows + "' is smaller than zero."); + } + getDomNodeOrDie().setAttribute("rows", null); + return; } } catch (final NumberFormatException e) { if (getBrowserVersion().hasFeature(JS_TEXT_AREA_SET_ROWS_THROWS_EXCEPTION)) { throw Context.throwAsScriptRuntimeEx(e); } + if (!getBrowserVersion().hasFeature(JS_TEXT_AREA_COLS_RETURNS_MINUS1)) { + return; + } i = 0; } getDomNodeOrDie().setAttribute("rows", Integer.toString(i)); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTextAreaElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTextAreaElementTest.java 2013-06-01 14:28:20 UTC (rev 8316) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTextAreaElementTest.java 2013-06-01 18:44:57 UTC (rev 8317) @@ -37,6 +37,7 @@ * @author Marc Guillemot * @author Ahmed Ashour * @author Daniel Gredler + * @author Ronald Brill */ @RunWith(BrowserRunner.class) public class HTMLTextAreaElementTest extends WebDriverTestCase { @@ -48,17 +49,22 @@ @Alerts({ "1234", "PoohBear" }) public void getValue() throws Exception { final String html - = "<html><head><title>foo</title><script>\n" - + "function doTest(){\n" - + "alert(document.form1.textarea1.value)\n" - + "document.form1.textarea1.value='PoohBear';\n" - + "alert(document.form1.textarea1.value )\n" - + "}\n" - + "</script></head><body onload='doTest()'>\n" - + "<p>hello world</p>\n" - + "<form name='form1' method='post' >\n" - + "<textarea name='textarea1' cols='45' rows='4'>1234</textarea>\n" - + "</form></body></html>"; + = "<html>\n" + + "<head><title>foo</title>\n" + + " <script>\n" + + " function doTest(){\n" + + " alert(document.form1.textarea1.value)\n" + + " document.form1.textarea1.value='PoohBear';\n" + + " alert(document.form1.textarea1.value )\n" + + " }\n" + + " </script>\n" + + "</head>\n" + + "<body onload='doTest()'>\n" + + " <p>hello world</p>\n" + + " <form name='form1' method='post' >\n" + + " <textarea name='textarea1' cols='45' rows='4'>1234</textarea>\n" + + " </form>\n" + + "</body></html>"; loadPageWithAlerts2(html); } @@ -69,13 +75,15 @@ @Test @Alerts("foo") public void onChange() throws Exception { - final String html = "<html><head><title>foo</title>\n" - + "</head><body>\n" - + "<p>hello world</p>\n" - + "<form name='form1'>\n" - + " <textarea name='textarea1' onchange='alert(this.value)'></textarea>\n" - + "<input name='myButton' type='button' onclick='document.form1.textarea1.value=\"from button\"'>\n" - + "</form>\n" + final String html + = "<html>\n" + + "<head><title>foo</title></head>\n" + + "<body>\n" + + " <p>hello world</p>\n" + + " <form name='form1'>\n" + + " <textarea name='textarea1' onchange='alert(this.value)'></textarea>\n" + + " <input name='myButton' type='button' onclick='document.form1.textarea1.value=\"from button\"'>\n" + + " </form>\n" + "</body></html>"; final WebDriver driver = loadPage2(html); @@ -94,21 +102,23 @@ @Test @Alerts({ "TEXTAREA", "INPUT" }) public void setValue() throws Exception { - final String content = "<html><head></head>\n" + final String html + = "<html>\n" + + "<head><title>foo</title></head>\n" + "<body>\n" - + "<form name='form1'>\n" - + "<textarea name='question'></textarea>\n" - + "<input type='button' name='btn_submit' value='Next'>\n" - + "</form>\n" - + "<script>\n" - + "document.form1.question.value = 'some text';\n" - + "alert(document.form1.elements[0].tagName);\n" - + "alert(document.form1.elements[1].tagName);\n" - + "</script>\n" + + " <form name='form1'>\n" + + " <textarea name='question'></textarea>\n" + + " <input type='button' name='btn_submit' value='Next'>\n" + + " </form>\n" + + " <script>\n" + + " document.form1.question.value = 'some text';\n" + + " alert(document.form1.elements[0].tagName);\n" + + " alert(document.form1.elements[1].tagName);\n" + + " </script>\n" + "</body>\n" + "</html>"; - loadPageWithAlerts2(content); + loadPageWithAlerts2(html); } /** @@ -118,20 +128,22 @@ @Alerts(IE = {"undefined", "undefined" }, FF = {"11", "0" }) public void textLength() throws Exception { - final String content = "<html>\n" + final String html + = "<html>\n" + + "<head><title>foo</title></head>\n" + "<body>\n" - + "<textarea id='myTextArea'></textarea>\n" - + "<script>\n" + + " <textarea id='myTextArea'></textarea>\n" + + " <script>\n" + " var textarea = document.getElementById('myTextArea');\n" + " textarea.value = 'hello there';\n" + " alert(textarea.textLength);\n" + " textarea.value = '';\n" + " alert(textarea.textLength);\n" - + "</script>\n" + + " </script>\n" + "</body>\n" + "</html>"; - loadPageWithAlerts2(content); + loadPageWithAlerts2(html); } /** @@ -172,10 +184,12 @@ } private void selection(final int selectionStart, final int selectionEnd) throws Exception { - final String html = "<html>\n" + final String html + = "<html>\n" + + "<head><title>foo</title></head>\n" + "<body>\n" - + "<textarea id='myTextArea'></textarea>\n" - + "<script>\n" + + " <textarea id='myTextArea'></textarea>\n" + + " <script>\n" + " var textarea = document.getElementById('myTextArea');\n" + " textarea.value = 'Hello there';\n" + " alert(textarea.selectionStart + ',' + textarea.selectionEnd);\n" @@ -183,7 +197,7 @@ + " alert(textarea.selectionStart + ',' + textarea.selectionEnd);\n" + " textarea.selectionEnd = " + selectionEnd + ";\n" + " alert(textarea.selectionStart + ',' + textarea.selectionEnd);\n" - + "</script>\n" + + " </script>\n" + "</body>\n" + "</html>"; @@ -239,15 +253,20 @@ private void value(final String textAreaBody) throws Exception { final String html - = "<html><head><title>foo</title><script>\n" - + "function doTest(){\n" - + " alert(document.form1.textarea1.value)\n" - + "}\n" - + "</script></head><body onload='doTest()'>\n" - + "<form name='form1' method='post' >\n" - + "<textarea name='textarea1'>" + textAreaBody + "</textarea>\n" - + "</textarea>\n" - + "</form></body></html>"; + = "<html>\n" + + "<head><title>foo</title>\n" + + " <script>\n" + + " function doTest(){\n" + + " alert(document.form1.textarea1.value);\n" + + " }\n" + + " </script>\n" + + "</head>\n" + + "<body onload='doTest()'>\n" + + " <form name='form1' method='post' >\n" + + " <textarea name='textarea1'>" + textAreaBody + "</textarea>\n" + + " </textarea>\n" + + " </form>\n" + + "</body></html>"; loadPageWithAlerts2(html); } @@ -282,7 +301,8 @@ @Test @Alerts({ "true", "false" }) public void readOnly() throws Exception { - final String html = "<html><head>\n" + final String html + = "<html><head>\n" + "<script>\n" + " function test() {\n" + " var t = document.getElementById('textArea');\n" @@ -331,35 +351,49 @@ * @throws Exception if an error occurs */ @Test - @Alerts(FF3_6 = { "-1", "5", "8", "2", "0", "0", "0", "3" }, - FF = { "20", "5", "8", "2", "error", "error", "8", "2", "20", "3" }, - IE = { "20", "5", "8", "2", "error", "error", "8", "2", "error", "8", "3" }) - @NotYetImplemented(Browser.FF17) + @Alerts(FF3_6 = { "-1", "5", "8", "4", "0", "0", "0", "3" }, + FF = { "20", "5", "8", "4", "error", "4", "error", "4", "20", "3" }, + IE = { "20", "5", "8", "4", "error", "4", "error", "4", "error", "4", "3" }) public void cols() throws Exception { final String html - = "<html><body><textarea id='a1'>a1</textarea><textarea id='a2' cols='5'>a2</textarea><script>\n" - + " function set(e, value) {\n" + = "<html><head>\n" + + "<script>\n" + + " function setCols(e, value) {\n" + " try {\n" + " e.cols = value;\n" + " } catch (e) {\n" + " alert('error');\n" + " }\n" + " }\n" - + " var a1 = document.getElementById('a1'), a2 = document.getElementById('a2');\n" - + " alert(a1.cols);\n" - + " alert(a2.cols);\n" - + " set(a1, '8');\n" - + " set(a2, 2);\n" - + " alert(a1.cols);\n" - + " alert(a2.cols);\n" - + " set(a1, 'a');\n" - + " set(a2, '');\n" - + " alert(a1.cols);\n" - + " alert(a2.cols);\n" - + " set(a1, -1);\n" - + " set(a2, 3.4);\n" - + " alert(a1.cols);\n" - + " alert(a2.cols);\n" + + "</script>\n" + + "</head>\n" + + + "<body>\n" + + " <textarea id='a1'>a1</textarea>\n" + + " <textarea id='a2' cols='5'>a2</textarea>\n" + + + " <script>\n" + + " var a1 = document.getElementById('a1'), a2 = document.getElementById('a2');\n" + + " alert(a1.cols);\n" + + " alert(a2.cols);\n" + + + " setCols(a1, '8');\n" + + " alert(a1.cols);\n" + + + " setCols(a1, 4);\n" + + " alert(a1.cols);\n" + + + " setCols(a1, 'a');\n" + + " alert(a1.cols);\n" + + + " setCols(a1, '');\n" + + " alert(a1.cols);\n" + + + " setCols(a1, -1);\n" + + " alert(a1.cols);\n" + + + " setCols(a1, 3.4);\n" + + " alert(a1.cols);\n" + "</script></body></html>"; loadPageWithAlerts2(html); } @@ -368,36 +402,51 @@ * @throws Exception if an error occurs */ @Test - @Alerts(FF3_6 = { "-1", "5", "8", "2", "0", "0", "0", "3" }, - FF = { "2", "5", "8", "2", "error", "error", "8", "2", "2", "3" }, - IE = { "2", "5", "8", "2", "error", "error", "8", "2", "error", "8", "3" }) - @NotYetImplemented(Browser.FF17) + @Alerts(FF3_6 = { "-1", "5", "8", "4", "0", "0", "0", "3" }, + FF = { "2", "5", "8", "4", "error", "4", "error", "4", "2", "3" }, + IE = { "2", "5", "8", "4", "error", "4", "error", "4", "error", "4", "3" }) public void rows() throws Exception { final String html - = "<html><body><textarea id='a1'>a1</textarea><textarea id='a2' rows='5'>a2</textarea><script>\n" - + " function set(e, value) {\n" + = "<html><head>\n" + + "<script>\n" + + " function setRows(e, value) {\n" + " try {\n" + " e.rows = value;\n" + " } catch (e) {\n" + " alert('error');\n" + " }\n" + " }\n" - + " var a1 = document.getElementById('a1'), a2 = document.getElementById('a2');\n" - + " alert(a1.rows);\n" - + " alert(a2.rows);\n" - + " set(a1, '8');\n" - + " set(a2, 2);\n" - + " alert(a1.rows);\n" - + " alert(a2.rows);\n" - + " set(a1, 'a');\n" - + " set(a2, '');\n" - + " alert(a1.rows);\n" - + " alert(a2.rows);\n" - + " set(a1, -1);\n" - + " set(a2, 3.4);\n" - + " alert(a1.rows);\n" - + " alert(a2.rows);\n" - + "</script></body></html>"; + + "</script>\n" + + "</head>\n" + + + "<body>\n" + + " <textarea id='a1'>a1</textarea>\n" + + " <textarea id='a2' rows='5'>a2</textarea>\n" + + + " <script>\n" + + " var a1 = document.getElementById('a1'), a2 = document.getElementById('a2');\n" + + " alert(a1.rows);\n" + + " alert(a2.rows);\n" + + + " setRows(a1, '8');\n" + + " alert(a1.rows);\n" + + + " setRows(a1, 4);\n" + + " alert(a1.rows);\n" + + + " setRows(a1, 'a');\n" + + " alert(a1.rows);\n" + + + " setRows(a1, '');\n" + + " alert(a1.rows);\n" + + + " setRows(a1, -1);\n" + + " alert(a1.rows);\n" + + + " setRows(a1, 3.4);\n" + + " alert(a1.rows);\n" + + " </script>\n" + + "</body></html>"; loadPageWithAlerts2(html); } @@ -409,18 +458,22 @@ @Alerts({ "9", "9", "2", "7" }) public void selectionRange() throws Exception { final String html - = "<html><head><title>foo</title><script>\n" - + "function test() {\n" - + " var ta = document.getElementById('myInput');\n" - + " ta.setSelectionRange(15, 15);\n" - + " alert(ta.selectionStart);" - + " alert(ta.selectionEnd);" - + " ta.setSelectionRange(2, 7);\n" - + " alert(ta.selectionStart);" - + " alert(ta.selectionEnd);" - + "}\n" - + "</script></head><body onload='test()'>\n" - + "<textarea id='myInput'>some test</textarea>\n" + = "<html>\n" + + "<head><title>foo</title>\n" + + " <script>\n" + + " function test() {\n" + + " var ta = document.getElementById('myInput');\n" + + " ta.setSelectionRange(15, 15);\n" + + " alert(ta.selectionStart);" + + " alert(ta.selectionEnd);" + + " ta.setSelectionRange(2, 7);\n" + + " alert(ta.selectionStart);" + + " alert(ta.selectionEnd);" + + " }\n" + + " </script>\n" + + "</head>\n" + + "<body onload='test()'>\n" + + " <textarea id='myInput'>some test</textarea>\n" + "</body></html>"; loadPageWithAlerts2(html); @@ -435,7 +488,7 @@ public void getAttributeAndSetValue() throws Exception { final String html = "<html>\n" - + " <head>\n" + + " <head><title>foo</title>\n" + " <script>\n" + " function test() {\n" + " var t = document.getElementById('t');\n" |