From: <rb...@us...> - 2013-04-24 18:27:48
|
Revision: 8241 http://sourceforge.net/p/htmlunit/code/8241 Author: rbri Date: 2013-04-24 18:27:44 +0000 (Wed, 24 Apr 2013) Log Message: ----------- more tests and fixes Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput2Test.java 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-24 18:18:29 UTC (rev 8240) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java 2013-04-24 18:27:44 UTC (rev 8241) @@ -260,6 +260,18 @@ * {@inheritDoc} */ @Override + public DomNode cloneNode(final boolean deep) { + final HtmlRadioButtonInput clone = (HtmlRadioButtonInput) super.cloneNode(deep); + if (hasFeature(HTMLINPUT_SET_CHECKED_TO_FALSE_WHEN_ADDED)) { + clone.removeAttribute("checked"); + } + return clone; + } + + /** + * {@inheritDoc} + */ + @Override public void focus() { super.focus(); valueAtFocus_ = isChecked(); 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-24 18:18:29 UTC (rev 8240) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput2Test.java 2013-04-24 18:27:44 UTC (rev 8241) @@ -24,6 +24,8 @@ import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.BrowserRunner.Browser; +import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.WebDriverTestCase; /** @@ -334,6 +336,314 @@ } /** + * Verifies the behavior of 'checked' property on being attached to a page. + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "true", "true", "true", "true", "true", "true" }, + IE = { "false", "false", "false", "false", "false", "false" }, + IE6 = { "true", "false", "false", "false", "true", "true" }) + public void checked_cloneNode_appendChild() 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" + + " input = input.cloneNode(false);\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></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_cloneNode_appendChild() 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 = input.cloneNode(false);\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_cloneNode_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 = input.cloneNode(false);\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 = { "false", "false", "false", "false", "false", "false" }, + IE6 = { "false", "false", "false", "false", "true", "true" }) + public void checked_cloneNode_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" + + " input = input.cloneNode(false);\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); + } + + /** + * Verifies the behavior of 'checked' property on being attached to a page. + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "true", "true", "true", "true", "true", "true" }, + IE = { "false", "true", "true", "true", "true", "true" }) + @NotYetImplemented(Browser.IE) + public void checked_cloneNode_appendChild_fromHtml() throws Exception { + final String html = "<html>\n" + + "<head>\n" + + " <script>\n" + + " function test() {\n" + + " var builder = document.createElement('div');\n" + + " builder.innerHTML = '<input type=\"radio\" checked>';\n" + + " var input = builder.firstChild;\n" + + " input = input.cloneNode(false);\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></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_cloneNode_appendChild_fromHtml() throws Exception { + final String html = "<html>\n" + + "<head>\n" + + " <script>\n" + + " function test() {\n" + + " var builder = document.createElement('div');\n" + + " builder.innerHTML = '<input type=\"radio\">';\n" + + " var input = builder.firstChild;\n" + + " input = input.cloneNode(false);\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_cloneNode_insertBefore_fromHtml() throws Exception { + final String html = "<html>\n" + + "<head>\n" + + " <script>\n" + + " function test() {\n" + + " var builder = document.createElement('div');\n" + + " builder.innerHTML = '<input type=\"radio\">';\n" + + " var input = builder.firstChild;\n" + + " input = input.cloneNode(false);\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 = { "false", "true", "true", "true", "true", "true" }) + @NotYetImplemented(Browser.IE) + public void checked_cloneNode_insertBefore_fromHtml() throws Exception { + final String html = "<html>\n" + + "<head>\n" + + " <script>\n" + + " function test() {\n" + + " var builder = document.createElement('div');\n" + + " builder.innerHTML = '<input type=\"radio\" checked>';\n" + + " var input = builder.firstChild;\n" + + " input = input.cloneNode(false);\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); + } + + /** * Regression test for bug 2956588. * As of HttmlUnit-2.8-SNAPSHOT on 26.02.10, reading responseXML with xhtml namespace * was causing ClassCastException for IE simulation when it contained a checked radio button. @@ -503,7 +813,7 @@ } /** - * Verifies that a HtmlCheckBox is unchecked by default. + * Verifies that a HtmlRadioButton is unchecked by default. * The onClick tests make this assumption. * @throws Exception if the test fails */ |