From: <rb...@us...> - 2013-04-22 18:06:07
|
Revision: 8236 http://sourceforge.net/p/htmlunit/code/8236 Author: rbri Date: 2013-04-22 18:06:02 +0000 (Mon, 22 Apr 2013) Log Message: ----------- behave like IE8 when working with checkboxes from JS Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput2Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-04-20 07:46:29 UTC (rev 8235) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-04-22 18:06:02 UTC (rev 8236) @@ -602,6 +602,14 @@ @BrowserFeature({ @WebBrowser(FF), @WebBrowser(CHROME) }) HTMLINPUT_DEFAULT_IS_CHECKED, + /** Set this checked state back to default when added to page (IE6). */ + @BrowserFeature(@WebBrowser(value = IE, maxVersion = 7)) + HTMLINPUT_SET_CHECKED_TO_DEFAULT_WHEN_ADDED, + + /** Set this checked state to false when added to page (IE). */ + @BrowserFeature(@WebBrowser(value = IE, minVersion = 8)) + HTMLINPUT_SET_CHECKED_TO_FALSE_WHEN_ADDED, + /** * Set this property if the browser does NOT * support the disabling of an individual option group. @@ -625,14 +633,6 @@ @BrowserFeature(@WebBrowser(IE)) HTMLPARSER_REMOVE_EMPTY_CONTENT, - /** Set this checked state back to default when added to page (IE6). */ - @BrowserFeature(@WebBrowser(value = IE, maxVersion = 7)) - HTMLRADIOINPUT_SET_CHECKED_TO_DEFAULT_WHEN_ADDED, - - /** Set this checked state to false when added to page (IE). */ - @BrowserFeature(@WebBrowser(value = IE, minVersion = 8)) - HTMLRADIOINPUT_SET_CHECKED_TO_FALSE_WHEN_ADDED, - /** * Set this property if the script tag supports the * types 'application/javascript' and 'application/x-javascript'. Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput.java 2013-04-20 07:46:29 UTC (rev 8235) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput.java 2013-04-22 18:06:02 UTC (rev 8236) @@ -16,6 +16,8 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_ONCHANGE_LOSING_FOCUS; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLINPUT_DEFAULT_IS_CHECKED; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLINPUT_SET_CHECKED_TO_DEFAULT_WHEN_ADDED; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLINPUT_SET_CHECKED_TO_FALSE_WHEN_ADDED; import java.io.IOException; import java.util.Map; @@ -184,6 +186,19 @@ * {@inheritDoc} */ @Override + protected void onAddedToPage() { + if (hasFeature(HTMLINPUT_SET_CHECKED_TO_DEFAULT_WHEN_ADDED)) { + setChecked(isDefaultChecked()); + } + if (wasCreatedByJavascript() && hasFeature(HTMLINPUT_SET_CHECKED_TO_FALSE_WHEN_ADDED)) { + removeAttribute("checked"); + } + } + + /** + * {@inheritDoc} + */ + @Override public void focus() { super.focus(); valueAtFocus_ = isChecked(); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java 2013-04-20 07:46:29 UTC (rev 8235) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java 2013-04-22 18:06:02 UTC (rev 8236) @@ -16,8 +16,8 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_ONCHANGE_LOSING_FOCUS; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLINPUT_DEFAULT_IS_CHECKED; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLRADIOINPUT_SET_CHECKED_TO_DEFAULT_WHEN_ADDED; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLRADIOINPUT_SET_CHECKED_TO_FALSE_WHEN_ADDED; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLINPUT_SET_CHECKED_TO_DEFAULT_WHEN_ADDED; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLINPUT_SET_CHECKED_TO_FALSE_WHEN_ADDED; import java.io.IOException; import java.util.Map; @@ -206,10 +206,10 @@ */ @Override protected void onAddedToPage() { - if (hasFeature(HTMLRADIOINPUT_SET_CHECKED_TO_DEFAULT_WHEN_ADDED)) { + if (hasFeature(HTMLINPUT_SET_CHECKED_TO_DEFAULT_WHEN_ADDED)) { setChecked(isDefaultChecked()); } - if (wasCreatedByJavascript() && hasFeature(HTMLRADIOINPUT_SET_CHECKED_TO_FALSE_WHEN_ADDED)) { + if (wasCreatedByJavascript() && hasFeature(HTMLINPUT_SET_CHECKED_TO_FALSE_WHEN_ADDED)) { removeAttribute("checked"); } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput2Test.java 2013-04-20 07:46:29 UTC (rev 8235) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput2Test.java 2013-04-22 18:06:02 UTC (rev 8236) @@ -46,10 +46,10 @@ * @throws Exception if the test fails */ @Test - @NotYetImplemented(IE) - @Alerts(IE = { "true", "false", "false", "false", "false", "false" }, - DEFAULT = { "true", "true", "true", "true", "true", "true" }) - public void checked_on_attachment() throws Exception { + @Alerts(DEFAULT = { "true", "true", "true", "true", "true", "true" }, + IE = { "true", "false", "false", "false", "false", "false" }, + IE6 = { "true", "false", "false", "false", "true", "true" }) + public void checked_appendChild() throws Exception { final String html = "<html>\n" + "<head>\n" + " <script>\n" @@ -58,20 +58,22 @@ + " input.type = 'checkbox';\n" + " input.checked = true;\n" + " alert(input.checked);\n" - + " document.body.appendChild(input);\n" + + " var parent=document.getElementById('myDiv');\n" + + " parent.appendChild(input);\n" + " alert(input.checked);\n" - + " document.body.removeChild(input);\n" + + " parent.removeChild(input);\n" + " alert(input.checked);\n" + "\n" + " input.defaultChecked = true;\n" + " alert(input.checked);\n" - + " document.body.appendChild(input);\n" + + " parent.appendChild(input);\n" + " alert(input.checked);\n" - + " document.body.removeChild(input);\n" + + " parent.removeChild(input);\n" + " alert(input.checked);\n" + " }\n" + " </script>\n" + "</head><body onload='test()'>\n" + + " <form><div id='myDiv'></div></div></form>\n" + "</body></html>"; loadPageWithAlerts2(html); @@ -81,6 +83,117 @@ * @throws Exception if the test fails */ @Test + @Alerts(DEFAULT = { "false", "false", "false", "true", "true", "true" }, + IE = { "false", "false", "false", "false", "false", "false" }, + IE6 = { "false", "false", "false", "false", "true", "true" }) + public void notchecked_appendChild() throws Exception { + final String html = "<html>\n" + + "<head>\n" + + " <script>\n" + + " function test() {\n" + + " var input = document.createElement('input');\n" + + " input.type = 'checkbox';\n" + + " alert(input.checked);\n" + + " var parent=document.getElementById('myDiv');\n" + + " parent.appendChild(input);\n" + + " alert(input.checked);\n" + + " parent.removeChild(input);\n" + + " alert(input.checked);\n" + + "\n" + + " input.defaultChecked = true;\n" + + " alert(input.checked);\n" + + " parent.appendChild(input);\n" + + " alert(input.checked);\n" + + " parent.removeChild(input);\n" + + " alert(input.checked);\n" + + " }\n" + + " </script>\n" + + "</head><body onload='test()'>\n" + + " <form><div id='myDiv'></div></form>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "false", "false", "false", "true", "true", "true" }, + IE = { "false", "false", "false", "false", "false", "false" }, + IE6 = { "false", "false", "false", "false", "true", "true" }) + public void notchecked_insertBefore() throws Exception { + final String html = "<html>\n" + + "<head>\n" + + " <script>\n" + + " function test() {\n" + + " var input = document.createElement('input');\n" + + " input.type = 'checkbox';\n" + + " alert(input.checked);\n" + + " var parent=document.getElementById('myDiv');\n" + + " var after=document.getElementById('divAfter');\n" + + " parent.insertBefore(input, after);\n" + + " alert(input.checked);\n" + + " parent.removeChild(input);\n" + + " alert(input.checked);\n" + + "\n" + + " input.defaultChecked = true;\n" + + " alert(input.checked);\n" + + " parent.insertBefore(input, after);\n" + + " alert(input.checked);\n" + + " parent.removeChild(input);\n" + + " alert(input.checked);\n" + + " }\n" + + " </script>\n" + + "</head><body onload='test()'>\n" + + " <form><div id='myDiv'><div id='divAfter'></div></div></form>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "true", "true", "true", "true", "true", "true" }, + IE = { "true", "false", "false", "false", "false", "false" }, + IE6 = { "true", "false", "false", "false", "true", "true" }) + public void checked_insertBefore() throws Exception { + final String html = "<html>\n" + + "<head>\n" + + " <script>\n" + + " function test() {\n" + + " var input = document.createElement('input');\n" + + " input.type = 'checkbox';\n" + + " input.checked = true;\n" + + " alert(input.checked);\n" + + " var parent=document.getElementById('myDiv');\n" + + " var after=document.getElementById('divAfter');\n" + + " parent.insertBefore(input, after);\n" + + " alert(input.checked);\n" + + " parent.removeChild(input);\n" + + " alert(input.checked);\n" + + "\n" + + " input.defaultChecked = true;\n" + + " alert(input.checked);\n" + + " parent.insertBefore(input, after);\n" + + " alert(input.checked);\n" + + " parent.removeChild(input);\n" + + " alert(input.checked);\n" + + " }\n" + + " </script>\n" + + "</head><body onload='test()'>\n" + + " <form><div id='myDiv'><div id='divAfter'></div></div></form>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test @Alerts(DEFAULT = "foo,change,", IE = { }) public void onchangeFires() throws Exception { final String html = "<html><head><title>foo</title>\n" |