From: <rb...@us...> - 2013-04-23 19:26:36
|
Revision: 8239 http://sourceforge.net/p/htmlunit/code/8239 Author: rbri Date: 2013-04-23 19:26:30 +0000 (Tue, 23 Apr 2013) Log Message: ----------- more tests and more fixes, but still not done Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput2Test.java 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-22 18:45:34 UTC (rev 8238) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput.java 2013-04-23 19:26:30 UTC (rev 8239) @@ -199,6 +199,18 @@ * {@inheritDoc} */ @Override + public DomNode cloneNode(final boolean deep) { + final HtmlCheckBoxInput clone = (HtmlCheckBoxInput) 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/HtmlCheckBoxInput2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput2Test.java 2013-04-22 18:45:34 UTC (rev 8238) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput2Test.java 2013-04-23 19:26:30 UTC (rev 8239) @@ -26,6 +26,7 @@ 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; @@ -337,9 +338,317 @@ } /** + * 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 = 'checkbox';\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 = 'checkbox';\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 = 'checkbox';\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 = 'checkbox';\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=\"checkbox\" 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=\"checkbox\">';\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=\"checkbox\">';\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=\"checkbox\" 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); + } + + /** + * @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" @@ -489,6 +798,39 @@ } /** + * @throws Exception if the test fails + */ + @Test + @Alerts({ "on", "on", "on", "on" }) + public void defaultValue() throws Exception { + final String html = "<html><head><title>foo</title>\n" + + "<script>\n" + + " function test() {\n" + + " alert(document.getElementById('chkbox').value);\n" + + + " var input = document.createElement('input');\n" + + " input.type = 'checkbox';\n" + + " alert(input.value);\n" + + + " var builder = document.createElement('div');\n" + + " builder.innerHTML = '<input type=\"checkbox\">';\n" + + " var input = builder.firstChild;\n" + + " alert(input.value);\n" + + + " input = input.cloneNode(false);\n" + + " alert(input.value);\n" + + " }\n" + + "</script>\n" + + "</head><body onload='test()'>\n" + + "<form>\n" + + " <input type='checkbox' id='chkbox'>\n" + + "</form>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** * Call to JS function click() should trigger the onchange handler but neither the onfocus handler * nor the mousedown/up handlers. * @throws Exception if the test fails |