From: <rb...@us...> - 2013-04-19 12:27:22
|
Revision: 8232 http://sourceforge.net/p/htmlunit/code/8232 Author: rbri Date: 2013-04-19 12:27:17 +0000 (Fri, 19 Apr 2013) Log Message: ----------- fix insertAfter for radioButtons (IE8) Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Node.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput2Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Node.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Node.java 2013-04-19 12:26:22 UTC (rev 8231) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Node.java 2013-04-19 12:27:17 UTC (rev 8232) @@ -434,6 +434,16 @@ appendedChild = newChildObject; } + // special hack for IE and radio buttons + // this can't be done in onAddedToPage() because + // it only happens when appendChild() is called. + if (newChildNode instanceof HtmlRadioButtonInput) { + final HtmlRadioButtonInput radio = (HtmlRadioButtonInput) newChildNode; + if (getBrowserVersion().hasFeature(HTMLRADIOINPUT_SET_CHECKED_TO_FALSE_WHEN_ADDED)) { + radio.setChecked(false); + } + } + // if parentNode is null in IE, create a DocumentFragment to be the parentNode if (domNode.getParentNode() == null && getBrowserVersion() .hasFeature(JS_APPEND_CHILD_CREATE_DOCUMENT_FRAGMENT_PARENT)) { Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput2Test.java 2013-04-19 12:26:22 UTC (rev 8231) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput2Test.java 2013-04-19 12:27:17 UTC (rev 8232) @@ -79,6 +79,81 @@ @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_on_attachment1() throws Exception { + final String html = "<html>\n" + + "<head>\n" + + " <script>\n" + + " function test() {\n" + + " var input = document.createElement('input');\n" + + " input.type = 'radio';\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" + + " <div id='myDiv'><div id='divAfter'></div></div>\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_on_insertBefore() throws Exception { + final String html = "<html>\n" + + "<head>\n" + + " <script>\n" + + " function test() {\n" + + " var input = document.createElement('input');\n" + + " input.type = 'radio';\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" + + " <div id='myDiv'><div id='divAfter'></div></div>\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_on_attachment() throws Exception { final String html = "<html>\n" + "<head>\n" |