From: <rb...@us...> - 2013-03-23 08:15:35
|
Revision: 8191 http://sourceforge.net/p/htmlunit/code/8191 Author: rbri Date: 2013-03-23 08:15:31 +0000 (Sat, 23 Mar 2013) Log Message: ----------- css selector fix for IE Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-03-22 19:36:33 UTC (rev 8190) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-03-23 08:15:31 UTC (rev 8191) @@ -1139,6 +1139,10 @@ @BrowserFeature(@WebBrowser(value = IE, minVersion = 8)) QUERYSELECTORALL_NOT_IN_QUIRKS, + /** Indicates that escaping in attrubute selectors is supported. */ + @BrowserFeature({ @WebBrowser(FF), @WebBrowser(CHROME) }) + SELECTOR_ATTRIBUTE_ESCAPING, + /** * Indicates that all options of a select are deselected, * if the select state is changed for an unknown option. Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2013-03-22 19:36:33 UTC (rev 8190) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2013-03-23 08:15:31 UTC (rev 8191) @@ -16,6 +16,7 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.CSS_SELECTOR_LANG; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.QUERYSELECTORALL_NOT_IN_QUIRKS; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.SELECTOR_ATTRIBUTE_ESCAPING; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.STYLESHEET_HREF_EXPANDURL; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.STYLESHEET_HREF_STYLE_EMPTY; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.STYLESHEET_HREF_STYLE_NULL; @@ -465,7 +466,10 @@ return ac4.getValue().equals(element.getId()); case Condition.SAC_CLASS_CONDITION: final AttributeCondition ac3 = (AttributeCondition) condition; - final String v3 = unescape(ac3.getValue()); + String v3 = ac3.getValue(); + if (v3.indexOf('\\') > -1) { + v3 = UNESCAPE_SELECTOR.matcher(v3).replaceAll("$1"); + } final String a3 = element.getAttribute("class"); return selects(v3, a3, ' '); case Condition.SAC_AND_CONDITION: @@ -475,7 +479,13 @@ case Condition.SAC_ATTRIBUTE_CONDITION: final AttributeCondition ac1 = (AttributeCondition) condition; if (ac1.getSpecified()) { - final String value = unescape(ac1.getValue()); + String value = ac1.getValue(); + if (value.indexOf('\\') > -1) { + if (!browserVersion.hasFeature(SELECTOR_ATTRIBUTE_ESCAPING)) { + throw new CSSException("Invalid selectors: '" + value + "'"); + } + value = UNESCAPE_SELECTOR.matcher(value).replaceAll("$1"); + } return element.getAttribute(ac1.getLocalName()).equals(value); } return element.hasAttribute(ac1.getLocalName()); @@ -528,13 +538,6 @@ } } - private static String unescape(final String value) { - if (value.indexOf('\\') == -1) { - return value; - } - return UNESCAPE_SELECTOR.matcher(value).replaceAll("$1"); - } - private static boolean selects(final String condition, final String attribute, final char separator) { // attribute.equals(condition) // || attribute.startsWith(condition + " ") || attriubte.endsWith(" " + condition) Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java 2013-03-22 19:36:33 UTC (rev 8190) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java 2013-03-23 08:15:31 UTC (rev 8191) @@ -1091,7 +1091,7 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = { "first", "second" }, IE8 = "exception") + @Alerts(DEFAULT = { "first", "second" }, IE8 = { "exception", "exception" }) public void escapedAttributeValue() throws Exception { final String html = "<html><head>\n" + "<meta http-equiv='X-UA-Compatible' content='IE=9'>\n" @@ -1101,6 +1101,8 @@ + "<script>\n" + "try {\n" + " alert(document.querySelectorAll('input[name=foo\\\\[bar\\\\]]')[0].id);\n" + + "} catch(e) {alert('exception')}\n" + + "try {\n" + " alert(document.querySelectorAll('input[name=foo\\\\.bar]')[0].id);\n" + "} catch(e) {alert('exception')}\n" + "</script></body></html>"; |
From: <rb...@us...> - 2013-03-23 10:12:14
|
Revision: 8192 http://sourceforge.net/p/htmlunit/code/8192 Author: rbri Date: 2013-03-23 10:12:11 +0000 (Sat, 23 Mar 2013) Log Message: ----------- Removing frame tag removes the associated FrameWindow also (2nd attempt) Issue 1497 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebWindowImpl.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/BaseFrameElement.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/FrameWindow.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLIFrameElementTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-03-23 08:15:31 UTC (rev 8191) +++ trunk/htmlunit/src/changes/changes.xml 2013-03-23 10:12:11 UTC (rev 8192) @@ -8,6 +8,9 @@ <body> <release version="2.13" date="???" description="Bugfixes"> + <action type="fix" dev="rbri" issue="1497"> + JavaScript: Removing frame tag removes the associated FrameWindow also. + </action> <action type="fix" dev="mguillem"> HtmlPage.getElementById: always return the first element in document order (and not the first parsed one). </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebWindowImpl.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebWindowImpl.java 2013-03-23 08:15:31 UTC (rev 8191) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebWindowImpl.java 2013-03-23 10:12:11 UTC (rev 8192) @@ -165,7 +165,10 @@ childWindows_.add(child); } - void destroyChildren() { + /** + * Destroy our childs. + */ + protected void destroyChildren() { if (LOG.isDebugEnabled()) { LOG.debug("destroyChildren"); } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/BaseFrameElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/BaseFrameElement.java 2013-03-23 08:15:31 UTC (rev 8191) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/BaseFrameElement.java 2013-03-23 10:12:11 UTC (rev 8192) @@ -408,4 +408,14 @@ ((BaseFrameElement) node).init(); return node; } + + /** + * Remove our window also. + * {@inheritDoc} + */ + @Override + public void remove() { + super.remove(); + ((FrameWindow) getEnclosedWindow()).close(); + } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java 2013-03-23 08:15:31 UTC (rev 8191) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java 2013-03-23 10:12:11 UTC (rev 8192) @@ -899,7 +899,7 @@ else { // clean up the new node, in case it is being moved if (domNode != this && domNode.getParentNode() != null) { - domNode.remove(); + domNode.detach(); } // move the node basicAppend(domNode); @@ -1098,9 +1098,12 @@ } /** - * Removes this node from all relationships with other nodes. + * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br/> + * + * Detach this node from all relationships with other nodes. + * This is the first step of an move. */ - public void remove() { + protected void detach() { final DomNode exParent = parent_; basicRemove(); @@ -1116,6 +1119,14 @@ } /** + * Removes this node from all relationships with other nodes. + */ + public void remove() { + // same as detach for the moment + detach(); + } + + /** * Cuts off all relationships this node has with siblings and parents. */ private void basicRemove() { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/FrameWindow.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/FrameWindow.java 2013-03-23 08:15:31 UTC (rev 8191) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/FrameWindow.java 2013-03-23 10:12:11 UTC (rev 8192) @@ -131,4 +131,18 @@ public String toString() { return "FrameWindow[name=\"" + getName() + "\"]"; } + + /** + * Closes this frame window. + */ + public void close() { + setClosed(); + final Page page = getEnclosedPage(); + if (page != null) { + page.cleanUp(); + } + getJobManager().shutdown(); + destroyChildren(); + getWebClient().deregisterWebWindow(this); + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLIFrameElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLIFrameElementTest.java 2013-03-23 08:15:31 UTC (rev 8191) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLIFrameElementTest.java 2013-03-23 10:12:11 UTC (rev 8192) @@ -600,7 +600,6 @@ * @throws Exception if the test fails */ @Test - @NotYetImplemented public void testRemoveFrameWindow() throws Exception { final String index = "<html><head></head><body>" + "<div id='content'>" @@ -633,7 +632,7 @@ assertEquals("new content", page.getElementById("content").asText()); - // frame is still there + // frame has to be gone frames = page.getFrames(); assertEquals(0, frames.size()); } |
From: <rb...@us...> - 2013-03-24 15:07:13
|
Revision: 8196 http://sourceforge.net/p/htmlunit/code/8196 Author: rbri Date: 2013-03-24 15:07:09 +0000 (Sun, 24 Mar 2013) Log Message: ----------- first step fixing DOMTokenList Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMTokenList.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMTokenListTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMTokenList.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMTokenList.java 2013-03-23 17:45:02 UTC (rev 8195) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMTokenList.java 2013-03-24 15:07:09 UTC (rev 8196) @@ -14,11 +14,15 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.dom; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import net.sourceforge.htmlunit.corejs.javascript.Context; + +import org.apache.commons.lang3.StringUtils; + import com.gargoylesoftware.htmlunit.html.DomAttr; +import com.gargoylesoftware.htmlunit.html.HtmlElement; import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction; @@ -30,10 +34,12 @@ * * @version $Revision$ * @author Ahmed Ashour + * @author Ronald Brill */ @JsxClass public final class DOMTokenList extends SimpleScriptable { + private static final String WHITESPACE_CHARS = " \t\r\n\u000C"; private String attributeName_; /** @@ -61,7 +67,7 @@ @JsxGetter public int getLength() { final String value = getDefaultValue(null); - return value.split(" ").length; + return StringUtils.split(value, WHITESPACE_CHARS).length; } /** @@ -84,8 +90,12 @@ @JsxFunction public void add(final String token) { if (!contains(token)) { - final DomAttr attr = (DomAttr) getDomNodeOrDie().getAttributes().getNamedItem(attributeName_); - attr.setValue(attr.getValue() + ' ' + token); + String value = getDefaultValue(null); + if (value.length() != 0 && !isWhitespache(value.charAt(value.length() - 1))) { + value = value + " "; + } + value = value + token; + updateAttribute(value); } } @@ -95,20 +105,36 @@ */ @JsxFunction public void remove(final String token) { - if (contains(token)) { - final DomAttr attr = (DomAttr) getDomNodeOrDie().getAttributes().getNamedItem(attributeName_); - if (attr != null) { - final List<String> values = new ArrayList<String>(Arrays.asList(attr.getValue().split(" "))); - values.remove(token); - final StringBuilder builder = new StringBuilder(); - for (int i = 0; i < values.size(); i++) { - builder.append(values.get(i)); - if (i < values.size() - 1) { - builder.append(' '); - } - } - attr.setValue(builder.toString()); + if (StringUtils.isEmpty(token)) { + throw Context.reportRuntimeError("Empty imput not allowed"); + } + if (StringUtils.containsAny(token, WHITESPACE_CHARS)) { + throw Context.reportRuntimeError("Empty imput not allowed"); + } + String value = getDefaultValue(null); + int pos = position(value, token); + while (pos != -1) { + int from = pos; + int to = pos + token.length(); + + while (from > 0 && isWhitespache(value.charAt(from - 1))) { + from = from - 1; } + while (to < value.length() - 1 && isWhitespache(value.charAt(to))) { + to = to + 1; + } + + final StringBuilder result = new StringBuilder(); + if (from > 0) { + result.append(value.substring(0, from)); + result.append(" "); + } + result.append(value.substring(to)); + + value = result.toString(); + updateAttribute(value); + + pos = position(value, token); } } @@ -134,12 +160,13 @@ */ @JsxFunction public boolean contains(final String token) { - final DomAttr attr = (DomAttr) getDomNodeOrDie().getAttributes().getNamedItem(attributeName_); - if (attr != null) { - final List<String> values = Arrays.asList(attr.getValue().split(" ")); - return values.contains(token); + if (StringUtils.isEmpty(token)) { + throw Context.reportRuntimeError("Empty imput not allowed"); } - return false; + if (StringUtils.containsAny(token, WHITESPACE_CHARS)) { + throw Context.reportRuntimeError("Empty imput not allowed"); + } + return position(getDefaultValue(null), token) > -1; } /** @@ -149,13 +176,47 @@ */ @JsxFunction public Object item(final int index) { - final DomAttr attr = (DomAttr) getDomNodeOrDie().getAttributes().getNamedItem(attributeName_); - if (attr != null) { - final List<String> values = Arrays.asList(attr.getValue().split(" ")); - if (index < values.size()) { - return values.get(index); - } + if (index < 0) { + return null; } + final String value = getDefaultValue(null); + final List<String> values = Arrays.asList(StringUtils.split(value, WHITESPACE_CHARS)); + if (index < values.size()) { + return values.get(index); + } return null; } + + private void updateAttribute(final String value) { + final HtmlElement domNode = (HtmlElement) getDomNodeOrDie(); + DomAttr attr = (DomAttr) domNode.getAttributes().getNamedItem(attributeName_); + if (null == attr) { + attr = domNode.getPage().createAttribute(attributeName_); + domNode.setAttributeNode(attr); + } + attr.setValue(value); + } + + private int position(final String value, final String token) { + final int pos = value.indexOf(token); + if (pos < 0) { + return -1; + } + + // whitespace before + if (pos != 0 && !isWhitespache(value.charAt(pos - 1))) { + return -1; + } + + // whitespace after + final int end = pos + token.length(); + if (end != value.length() && !isWhitespache(value.charAt(end))) { + return -1; + } + return pos; + } + + private boolean isWhitespache(final int ch) { + return WHITESPACE_CHARS.indexOf(ch) > -1; + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMTokenListTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMTokenListTest.java 2013-03-23 17:45:02 UTC (rev 8195) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMTokenListTest.java 2013-03-24 15:07:09 UTC (rev 8196) @@ -19,8 +19,6 @@ 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; /** @@ -64,7 +62,6 @@ */ @Test @Alerts(FF = { "0", "null", "false", "# removed", "" }) - @NotYetImplemented(Browser.FF) public void noAttribute() throws Exception { final String html = "<html><head><title>First</title><script>\n" @@ -89,7 +86,6 @@ */ @Test @Alerts(FF = { "0", "undefined", "1", "#" }) - @NotYetImplemented(Browser.FF) public void noAttributeAdd() throws Exception { final String html = "<html><head><title>First</title><script>\n" @@ -113,7 +109,6 @@ */ @Test @Alerts(FF = { "0", "true", "1", "#" }) - @NotYetImplemented(Browser.FF) public void noAttributeToggle() throws Exception { final String html = "<html><head><title>First</title><script>\n" @@ -137,7 +132,6 @@ */ @Test @Alerts(FF = { "3", "0", "3", "8" }) - @NotYetImplemented(Browser.FF) public void length() throws Exception { final String html = "<html><head><title>First</title><script>\n" @@ -168,7 +162,6 @@ */ @Test @Alerts(FF = { "a", "b", "c", "d", "\u000B", "e", "f", "g", "null", "null", "null" }) - @NotYetImplemented(Browser.FF) public void item() throws Exception { final String html = "<html><head><title>First</title><script>\n" @@ -194,8 +187,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(FF = { "exception", "true", "false" }) - @NotYetImplemented(Browser.FF) + @Alerts(FF = { "exception", "exception", "true", "false" }) public void contains() throws Exception { final String html = "<html><head><title>First</title><script>\n" @@ -205,6 +197,9 @@ + " try {\n" + " list.contains('ab\te');\n" + " } catch(e) { alert('exception');}\n" + + " try {\n" + + " list.contains('');\n" + + " } catch(e) { alert('exception');}\n" + " alert(list.contains('c'));\n" + " alert(list.contains('xyz'));\n" + " }\n" @@ -220,8 +215,34 @@ * @throws Exception if the test fails */ @Test + @Alerts(FF = { "true", "true", "true", "true" }) + public void containsBorderCheck() throws Exception { + final String html + = "<html><head><title>First</title><script>\n" + + "function test() {\n" + + " var list = document.getElementById('d1').classList;\n" + + " if (list) {\n" + + " alert(list.contains('a'));\n" + + " alert(list.contains('d'));\n" + + + " list = document.getElementById('d2').classList;\n" + + " alert(list.contains('a'));\n" + + " alert(list.contains('d'));\n" + + " }\n" + + "}\n" + + "</script></head><body onload='test()'>\n" + + " <div id='d1' class='a \t c \n d'></div>\n" + + " <div id='d2' class=' a \t c \n d\r'></div>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test @Alerts(FF = { "exception", "exception", "3", "4", "true" }) - @NotYetImplemented(Browser.FF) public void add() throws Exception { final String html = "<html><head><title>First</title><script>\n" @@ -252,7 +273,6 @@ */ @Test @Alerts(FF = { "1", "2", "a \t #" }) - @NotYetImplemented(Browser.FF) public void addWhitespaceAtEnd() throws Exception { final String html = "<html><head><title>First</title><script>\n" @@ -301,7 +321,6 @@ */ @Test @Alerts(FF = { "exception", "exception", "3", "3", "2", "false" }) - @NotYetImplemented(Browser.FF) public void remove() throws Exception { final String html = "<html><head><title>First</title><script>\n" @@ -334,7 +353,6 @@ */ @Test @Alerts(FF = { "3", "1", "false" }) - @NotYetImplemented(Browser.FF) public void removeDuplicated() throws Exception { final String html = "<html><head><title>First</title><script>\n" @@ -359,7 +377,6 @@ */ @Test @Alerts(FF = { "a \t c \n d e", "4", "3", "a d e" }) - @NotYetImplemented(Browser.FF) public void removeWhitespace() throws Exception { final String html = "<html><head><title>First</title><script>\n" @@ -386,7 +403,6 @@ */ @Test @Alerts(FF = { "exception", "exception", "2", "true", "false", "1", "false", "true", "2", "true" }) - @NotYetImplemented(Browser.FF) public void toggle() throws Exception { final String html = "<html><head><title>First</title><script>\n" |
From: <rb...@us...> - 2013-03-24 16:41:11
|
Revision: 8197 http://sourceforge.net/p/htmlunit/code/8197 Author: rbri Date: 2013-03-24 16:41:07 +0000 (Sun, 24 Mar 2013) Log Message: ----------- DOMTokenList implementation fixed and enhanced Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMTokenListTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-03-24 15:07:09 UTC (rev 8196) +++ trunk/htmlunit/src/changes/changes.xml 2013-03-24 16:41:07 UTC (rev 8197) @@ -8,6 +8,10 @@ <body> <release version="2.13" date="???" description="Bugfixes"> + <action type="fix" dev="rbri"> + JavaScript: DOMTokenList now works like in FF (different from spec). Some NPE exceptions + are fixed, separator chars are fixed, and we are able to create an attribute if needed. + </action> <action type="fix" dev="rbri" issue="1497"> JavaScript: Removing frame tag removes the associated FrameWindow also. </action> Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMTokenListTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMTokenListTest.java 2013-03-24 15:07:09 UTC (rev 8196) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMTokenListTest.java 2013-03-24 16:41:07 UTC (rev 8197) @@ -215,6 +215,29 @@ * @throws Exception if the test fails */ @Test + @Alerts(FF = { "false", "false", "false" }) + public void containsSubstring() throws Exception { + final String html + = "<html><head><title>First</title><script>\n" + + "function test() {\n" + + " var list = document.getElementById('d1').classList;\n" + + " if (list) {\n" + + " alert(list.contains('a'));\n" + + " alert(list.contains('d'));\n" + + " alert(list.contains('f'));\n" + + " }\n" + + "}\n" + + "</script></head><body onload='test()'>\n" + + " <div id='d1' class='ab cde ef'></div>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test @Alerts(FF = { "true", "true", "true", "true" }) public void containsBorderCheck() throws Exception { final String html |
From: <rb...@us...> - 2013-04-06 16:11:25
|
Revision: 8207 http://sourceforge.net/p/htmlunit/code/8207 Author: rbri Date: 2013-04-06 16:11:20 +0000 (Sat, 06 Apr 2013) Log Message: ----------- image.width() and image.height() are returning now the correct image size. Issue 1476 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/HTMLImageElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLImageElementTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-04-06 13:37:58 UTC (rev 8206) +++ trunk/htmlunit/src/changes/changes.xml 2013-04-06 16:11:20 UTC (rev 8207) @@ -8,6 +8,9 @@ <body> <release version="2.13" date="???" description="Bugfixes"> + <action type="fix" dev="rbri" issue="1476"> + JavaScript: image.width() and image.height() are returning now the correct image size. + </action> <action type="fix" dev="rbri"> JavaScript: DOMTokenList now works like in FF (different from spec). Some NPE exceptions are fixed, separator chars are fixed, and we are able to create an attribute if needed. Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-04-06 13:37:58 UTC (rev 8206) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-04-06 16:11:20 UTC (rev 8207) @@ -912,6 +912,18 @@ @BrowserFeature(@WebBrowser(IE)) JS_IGNORES_LAST_LINE_CONTAINING_UNCOMMENTED, + /** Getting the width and height of an image tag without a source returns 28x30; + * for invalid values returns 1 (IE). + */ + @BrowserFeature(@WebBrowser(CHROME)) + JS_IMAGE_WIDTH_HEIGHT_RETURNS_18x20x0, + + /** Getting the width and height of an image tag without a source returns 28x30; + * for invalid values returns 1 (IE). + */ + @BrowserFeature(@WebBrowser(IE)) + JS_IMAGE_WIDTH_HEIGHT_RETURNS_28x30x1, + /** Indicates if multiple spaces are replaced by a single one when accessing innerHTML. */ @BrowserFeature(@WebBrowser(IE)) JS_INNER_HTML_REDUCE_WHITESPACES, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLImageElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLImageElement.java 2013-04-06 13:37:58 UTC (rev 8206) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLImageElement.java 2013-04-06 16:11:20 UTC (rev 8207) @@ -15,7 +15,10 @@ package com.gargoylesoftware.htmlunit.javascript.host.html; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ALIGN_ACCEPTS_ARBITRARY_VALUES; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_IMAGE_WIDTH_HEIGHT_RETURNS_18x20x0; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_IMAGE_WIDTH_HEIGHT_RETURNS_28x30x1; +import java.io.IOException; import java.net.MalformedURLException; import java.util.HashMap; import java.util.Map; @@ -24,6 +27,7 @@ import org.apache.xalan.xsltc.runtime.AttributeList; +import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.SgmlPage; import com.gargoylesoftware.htmlunit.html.DomElement; import com.gargoylesoftware.htmlunit.html.HTMLParser; @@ -217,13 +221,43 @@ @JsxGetter public int getWidth() { final HtmlImage img = (HtmlImage) getDomNodeOrDie(); - final String width = img.getWidthAttribute(); - try { - return Integer.parseInt(width); + final String widthAttrib = img.getWidthAttribute(); + + if (DomElement.ATTRIBUTE_NOT_DEFINED != widthAttrib) { + try { + return Integer.parseInt(widthAttrib); + } + catch (final NumberFormatException e) { + if (getBrowserVersion().hasFeature(JS_IMAGE_WIDTH_HEIGHT_RETURNS_28x30x1)) { + return 1; + } + } } - catch (final NumberFormatException e) { - return 24; // anything else + + if (DomElement.ATTRIBUTE_NOT_DEFINED != img.getSrcAttribute()) { + try { + return img.getWidth(); + } + catch (final IOException e) { + final BrowserVersion browserVersion = getBrowserVersion(); + if (browserVersion.hasFeature(JS_IMAGE_WIDTH_HEIGHT_RETURNS_28x30x1)) { + return 1; + } + if (browserVersion.hasFeature(JS_IMAGE_WIDTH_HEIGHT_RETURNS_18x20x0)) { + return 18; + } + return 24; + } } + + final BrowserVersion browserVersion = getBrowserVersion(); + if (browserVersion.hasFeature(JS_IMAGE_WIDTH_HEIGHT_RETURNS_28x30x1)) { + return 28; + } + if (browserVersion.hasFeature(JS_IMAGE_WIDTH_HEIGHT_RETURNS_18x20x0)) { + return 0; + } + return 24; } /** @@ -244,12 +278,42 @@ public int getHeight() { final HtmlImage img = (HtmlImage) getDomNodeOrDie(); final String height = img.getHeightAttribute(); - try { - return Integer.parseInt(height); + + if (DomElement.ATTRIBUTE_NOT_DEFINED != height) { + try { + return Integer.parseInt(height); + } + catch (final NumberFormatException e) { + if (getBrowserVersion().hasFeature(JS_IMAGE_WIDTH_HEIGHT_RETURNS_28x30x1)) { + return 1; + } + } } - catch (final NumberFormatException e) { - return 24; // anything else + + if (DomElement.ATTRIBUTE_NOT_DEFINED != img.getSrcAttribute()) { + try { + return img.getHeight(); + } + catch (final IOException e) { + final BrowserVersion browserVersion = getBrowserVersion(); + if (browserVersion.hasFeature(JS_IMAGE_WIDTH_HEIGHT_RETURNS_28x30x1)) { + return 1; + } + if (browserVersion.hasFeature(JS_IMAGE_WIDTH_HEIGHT_RETURNS_18x20x0)) { + return 20; + } + return 24; + } } + + final BrowserVersion browserVersion = getBrowserVersion(); + if (browserVersion.hasFeature(JS_IMAGE_WIDTH_HEIGHT_RETURNS_28x30x1)) { + return 30; + } + if (browserVersion.hasFeature(JS_IMAGE_WIDTH_HEIGHT_RETURNS_18x20x0)) { + return 0; + } + return 24; } /** Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLImageElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLImageElementTest.java 2013-04-06 13:37:58 UTC (rev 8206) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLImageElementTest.java 2013-04-06 16:11:20 UTC (rev 8207) @@ -14,17 +14,27 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.html; +import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.FF17; + +import java.io.File; +import java.io.FileInputStream; +import java.net.URL; +import java.util.Collections; +import java.util.List; + +import org.apache.commons.io.IOUtils; import org.junit.Test; import org.junit.runner.RunWith; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; -import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.FF17; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; +import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.WebDriverTestCase; +import com.gargoylesoftware.htmlunit.util.NameValuePair; /** * Tests for {@link HTMLImageElement}. @@ -283,25 +293,25 @@ } /** - * Test that image's width and height are numbers. + * Test image's width and height. * Regression test for bug * http://sourceforge.net/tracker/?func=detail&atid=448266&aid=2861064&group_id=47038 * @throws Exception if the test fails */ @Test - @Alerts({ "number: 300", "number: 200", "number", "number", "number", "number" }) - public void testWidthHeight() throws Exception { + @Alerts(DEFAULT = { "number: 300", "number: 200", "number: 24", "number: 24", "number: 24", "number: 24" }, + IE = { "number: 300", "number: 200", "number: 28", "number: 30", "number: 1", "number: 1" }, + CHROME = { "number: 300", "number: 200", "number: 0", "number: 0", "number: 0", "number: 0" }) + public void testWidthHeightWithoutSource() throws Exception { final String html = "<html><head>\n" + "<script>\n" + " function showInfos(imageId) {\n" + " var img = document.getElementById(imageId);\n" - + " alert(typeof(img.width));\n" - + " alert(typeof(img.height));\n" + + " alert(typeof(img.width) + ': ' + img.width);\n" + + " alert(typeof(img.height) + ': ' + img.height);\n" + " }\n" + " function test() {\n" - + " var img1 = document.getElementById('myImage1');\n" - + " alert(typeof(img1.width) + ': ' + img1.width);\n" - + " alert(typeof(img1.height) + ': ' + img1.height);\n" + + " showInfos('myImage1');\n" + " showInfos('myImage2');\n" + " showInfos('myImage3');\n" + " }\n" @@ -314,4 +324,77 @@ loadPageWithAlerts2(html); } + + /** + * Test that image's width and height are numbers. + * @throws Exception if the test fails + */ + @Test + @Alerts({ "number: 300", "number: 200", "number: 1", "number: 1", "number: 1", "number: 1" }) + public void testWidthHeightWithSource() throws Exception { + getMockWebConnection().setDefaultResponse(""); + + final String html = "<html><head>\n" + + "<script>\n" + + " function showInfos(imageId) {\n" + + " var img = document.getElementById(imageId);\n" + + " alert(typeof(img.width) + ': ' + img.width);\n" + + " alert(typeof(img.height) + ': ' + img.height);\n" + + " }\n" + + " function test() {\n" + + " showInfos('myImage1');\n" + + " showInfos('myImage2');\n" + + " showInfos('myImage3');\n" + + " }\n" + + "</script>\n" + + "</head><body onload='test()'>\n" + + " <img id='myImage1' src='" + URL_SECOND + "' width='300' height='200'>\n" + + " <img id='myImage2' src='" + URL_SECOND + "' >\n" + + " <img id='myImage3' src='" + URL_SECOND + "' width='hello' height='hello'>\n" + + "</body></html>"; + + final URL url = getClass().getClassLoader().getResource("testfiles/tiny-jpg.img"); + final FileInputStream fis = new FileInputStream(new File(url.toURI())); + final byte[] directBytes = IOUtils.toByteArray(fis); + fis.close(); + + final MockWebConnection webConnection = getMockWebConnection(); + final List<NameValuePair> emptyList = Collections.emptyList(); + webConnection.setResponse(URL_SECOND, directBytes, 200, "ok", "image/jpg", emptyList); + + loadPageWithAlerts2(html); + } + + /** + * Test that image's width and height are numbers. + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "number: 300", "number: 200", "number: 24", "number: 24", "number: 24", "number: 24" }, + IE = { "number: 300", "number: 200", "number: 1", "number: 1", "number: 1", "number: 1" }, + CHROME = { "number: 300", "number: 200", "number: 18", "number: 20", "number: 18", "number: 20" }) + public void testWidthHeightInvalidSource() throws Exception { + getMockWebConnection().setDefaultResponse(""); + + final String html = "<html><head>\n" + + "<script>\n" + + " function showInfos(imageId) {\n" + + " var img = document.getElementById(imageId);\n" + + " alert(typeof(img.width) + ': ' + img.width);\n" + + " alert(typeof(img.height) + ': ' + img.height);\n" + + " }\n" + + " function test() {\n" + + " showInfos('myImage1');\n" + + " showInfos('myImage2');\n" + + " showInfos('myImage3');\n" + + " }\n" + + "</script>\n" + + "</head><body onload='test()'>\n" + + " <img id='myImage1' src='" + URL_SECOND + "' width='300' height='200'>\n" + + " <img id='myImage2' src='" + URL_SECOND + "' >\n" + + " <img id='myImage3' src='" + URL_SECOND + "' width='hello' height='hello'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } } |
From: <mgu...@us...> - 2013-04-08 10:33:41
|
Revision: 8212 http://sourceforge.net/p/htmlunit/code/8212 Author: mguillem Date: 2013-04-08 10:33:38 +0000 (Mon, 08 Apr 2013) Log Message: ----------- onsubmit and onchange are defined on HTMLElement (!) for FF and Chrome (can someone verify with IE?) Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/FormField.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDivElementTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/FormField.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/FormField.java 2013-04-07 12:34:07 UTC (rev 8211) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/FormField.java 2013-04-08 10:33:38 UTC (rev 8212) @@ -14,8 +14,6 @@ */ package com.gargoylesoftware.htmlunit.javascript.host; -import net.sourceforge.htmlunit.corejs.javascript.Function; - import com.gargoylesoftware.htmlunit.html.DomNode; import com.gargoylesoftware.htmlunit.html.HtmlElement; import com.gargoylesoftware.htmlunit.html.HtmlForm; @@ -102,24 +100,6 @@ } /** - * Sets the <tt>onchange</tt> event handler for this element. - * @param onchange the <tt>onchange</tt> event handler for this element - */ - @JsxSetter - public void setOnchange(final Object onchange) { - setEventHandlerProp("onchange", onchange); - } - - /** - * Returns the <tt>onchange</tt> event handler for this element. - * @return the <tt>onchange</tt> event handler for this element - */ - @JsxGetter - public Function getOnchange() { - return getEventHandler("onchange"); - } - - /** * {@inheritDoc} Overridden to modify browser configurations. */ @Override Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java 2013-04-07 12:34:07 UTC (rev 8211) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java 2013-04-08 10:33:38 UTC (rev 8212) @@ -2839,4 +2839,40 @@ protected boolean isLowerCaseInOuterHtml() { return false; } + + /** + * Sets the <tt>onchange</tt> event handler for this element. + * @param onchange the <tt>onchange</tt> event handler for this element + */ + @JsxSetter + public void setOnchange(final Object onchange) { + setEventHandlerProp("onchange", onchange); + } + + /** + * Returns the <tt>onchange</tt> event handler for this element. + * @return the <tt>onchange</tt> event handler for this element + */ + @JsxGetter + public Function getOnchange() { + return getEventHandler("onchange"); + } + + /** + * Returns the <tt>onsubmit</tt> event handler for this element. + * @return the <tt>onsubmit</tt> event handler for this element + */ + @JsxGetter + public Object getOnsubmit() { + return getEventHandlerProp("onsubmit"); + } + + /** + * Sets the <tt>onsubmit</tt> event handler for this element. + * @param onsubmit the <tt>onsubmit</tt> event handler for this element + */ + @JsxSetter + public void setOnsubmit(final Object onsubmit) { + setEventHandlerProp("onsubmit", onsubmit); + } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElement.java 2013-04-07 12:34:07 UTC (rev 8211) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElement.java 2013-04-08 10:33:38 UTC (rev 8212) @@ -233,24 +233,6 @@ } /** - * Returns the <tt>onsubmit</tt> event handler for this element. - * @return the <tt>onsubmit</tt> event handler for this element - */ - @JsxGetter - public Object getOnsubmit() { - return getEventHandlerProp("onsubmit"); - } - - /** - * Sets the <tt>onsubmit</tt> event handler for this element. - * @param onsubmit the <tt>onsubmit</tt> event handler for this element - */ - @JsxSetter - public void setOnsubmit(final Object onsubmit) { - setEventHandlerProp("onsubmit", onsubmit); - } - - /** * Sets the value of the JavaScript attribute "target". * @param target the new value */ Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDivElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDivElementTest.java 2013-04-07 12:34:07 UTC (rev 8211) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDivElementTest.java 2013-04-08 10:33:38 UTC (rev 8212) @@ -126,4 +126,25 @@ + "</body></html>"; loadPageWithAlerts2(html); } + + /** + * A similar test is used by jQuery-1.4.1 to detect browser capacities. + * @throws Exception if an error occurs + */ + @Test + @Alerts({ "null", "true", "null", "true" }) + public void handlers() throws Exception { + final String html + = "<html><body>\n" + + "<div id='d1'></div>\n" + + "<script>\n" + + "var d = document.getElementById('d1');\n" + + "alert(d.onchange);\n" + + "alert('onchange' in d);\n" + + "alert(d.onsubmit);\n" + + "alert('onsubmit' in d);\n" + + "</script>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } } |
From: <mgu...@us...> - 2013-04-08 12:51:35
|
Revision: 8213 http://sourceforge.net/p/htmlunit/code/8213 Author: mguillem Date: 2013-04-08 12:51:32 +0000 (Mon, 08 Apr 2013) Log Message: ----------- in fact onchange and onsubmit have to be defined as previously for IE Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/FormField.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDivElementTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElementTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/FormField.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/FormField.java 2013-04-08 10:33:38 UTC (rev 8212) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/FormField.java 2013-04-08 12:51:32 UTC (rev 8213) @@ -14,12 +14,16 @@ */ package com.gargoylesoftware.htmlunit.javascript.host; +import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.IE; +import net.sourceforge.htmlunit.corejs.javascript.Function; + import com.gargoylesoftware.htmlunit.html.DomNode; import com.gargoylesoftware.htmlunit.html.HtmlElement; import com.gargoylesoftware.htmlunit.html.HtmlForm; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter; +import com.gargoylesoftware.htmlunit.javascript.configuration.WebBrowser; /** * Base class for all JavaScript object corresponding to form fields. @@ -100,6 +104,24 @@ } /** + * Sets the <tt>onchange</tt> event handler for this element. + * @param onchange the <tt>onchange</tt> event handler for this element + */ + @JsxSetter(@WebBrowser(value = IE)) + public void setOnchange(final Object onchange) { + setEventHandlerProp("onchange", onchange); + } + + /** + * Returns the <tt>onchange</tt> event handler for this element. + * @return the <tt>onchange</tt> event handler for this element + */ + @JsxGetter(@WebBrowser(value = IE)) + public Function getOnchange() { + return getEventHandler("onchange"); + } + + /** * {@inheritDoc} Overridden to modify browser configurations. */ @Override Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java 2013-04-08 10:33:38 UTC (rev 8212) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java 2013-04-08 12:51:32 UTC (rev 8213) @@ -2844,7 +2844,7 @@ * Sets the <tt>onchange</tt> event handler for this element. * @param onchange the <tt>onchange</tt> event handler for this element */ - @JsxSetter + @JsxSetter({ @WebBrowser(value = FF), @WebBrowser(CHROME) }) public void setOnchange(final Object onchange) { setEventHandlerProp("onchange", onchange); } @@ -2853,7 +2853,7 @@ * Returns the <tt>onchange</tt> event handler for this element. * @return the <tt>onchange</tt> event handler for this element */ - @JsxGetter + @JsxGetter({ @WebBrowser(value = FF), @WebBrowser(CHROME) }) public Function getOnchange() { return getEventHandler("onchange"); } @@ -2862,7 +2862,7 @@ * Returns the <tt>onsubmit</tt> event handler for this element. * @return the <tt>onsubmit</tt> event handler for this element */ - @JsxGetter + @JsxGetter({ @WebBrowser(value = FF), @WebBrowser(CHROME) }) public Object getOnsubmit() { return getEventHandlerProp("onsubmit"); } @@ -2871,7 +2871,7 @@ * Sets the <tt>onsubmit</tt> event handler for this element. * @param onsubmit the <tt>onsubmit</tt> event handler for this element */ - @JsxSetter + @JsxSetter({ @WebBrowser(value = FF), @WebBrowser(CHROME) }) public void setOnsubmit(final Object onsubmit) { setEventHandlerProp("onsubmit", onsubmit); } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElement.java 2013-04-08 10:33:38 UTC (rev 8212) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElement.java 2013-04-08 12:51:32 UTC (rev 8213) @@ -15,10 +15,10 @@ package com.gargoylesoftware.htmlunit.javascript.host.html; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.FORMFIELD_REACHABLE_BY_NEW_NAMES; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_FORM_ENCODING_NORMALIZED; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_169; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_80; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_81; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_FORM_ENCODING_NORMALIZED; import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.IE; import java.net.MalformedURLException; @@ -233,6 +233,24 @@ } /** + * Returns the <tt>onsubmit</tt> event handler for this element. + * @return the <tt>onsubmit</tt> event handler for this element + */ + @JsxGetter(@WebBrowser(value = IE)) + public Object getOnsubmit() { + return getEventHandlerProp("onsubmit"); + } + + /** + * Sets the <tt>onsubmit</tt> event handler for this element. + * @param onsubmit the <tt>onsubmit</tt> event handler for this element + */ + @JsxSetter(@WebBrowser(value = IE)) + public void setOnsubmit(final Object onsubmit) { + setEventHandlerProp("onsubmit", onsubmit); + } + + /** * Sets the value of the JavaScript attribute "target". * @param target the new value */ Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDivElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDivElementTest.java 2013-04-08 10:33:38 UTC (rev 8212) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDivElementTest.java 2013-04-08 12:51:32 UTC (rev 8213) @@ -132,7 +132,8 @@ * @throws Exception if an error occurs */ @Test - @Alerts({ "null", "true", "null", "true" }) + @Alerts(DEFAULT = { "null", "true", "null", "true" }, + IE = { "undefined", "false", "undefined", "false" }) public void handlers() throws Exception { final String html = "<html><body>\n" Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElementTest.java 2013-04-08 10:33:38 UTC (rev 8212) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLFormElementTest.java 2013-04-08 12:51:32 UTC (rev 8213) @@ -14,7 +14,6 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.html; -import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.FF; import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.FF17; import java.net.URL; @@ -1275,7 +1274,6 @@ */ @Test @Alerts(FF = "function", IE = "string") - @NotYetImplemented(FF) public void onchangeHandler() throws Exception { final String html = "<html><head><title>foo</title><script>\n" |
From: <rb...@us...> - 2013-04-09 16:05:06
|
Revision: 8215 http://sourceforge.net/p/htmlunit/code/8215 Author: rbri Date: 2013-04-09 16:05:03 +0000 (Tue, 09 Apr 2013) Log Message: ----------- IE 9 supports String.trim(). Issue 1501 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/JavaScriptEngine.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeStringTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-04-08 19:11:50 UTC (rev 8214) +++ trunk/htmlunit/src/changes/changes.xml 2013-04-09 16:05:03 UTC (rev 8215) @@ -8,6 +8,9 @@ <body> <release version="2.13" date="???" description="Bugfixes"> + <action type="fix" dev="rbri" issue="1501"> + JavaScript: IE 9 supports String.trim(). + </action> <action type="update" dev="rbri"> Upgrade commons-logging to 1.1.2. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-04-08 19:11:50 UTC (rev 8214) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-04-09 16:05:03 UTC (rev 8215) @@ -1180,10 +1180,14 @@ @BrowserFeature({ @WebBrowser(value = FF, maxVersion = 10), @WebBrowser(CHROME) }) STORAGE_OBSOLETE, - /** Indicates that string.trim(), .trimLeft() and .trimRight() are supported. */ + /** Indicates that string.trim() is supported. */ @BrowserFeature({ @WebBrowser(FF), @WebBrowser(CHROME) }) STRING_TRIM, + /** Indicates that string.trimLeft() and .trimRight() are supported. */ + @BrowserFeature({ @WebBrowser(FF), @WebBrowser(value = IE, minVersion = 9), @WebBrowser(CHROME) }) + STRING_TRIM_LEFT_RIGHT, + /** * Indicates that the href property for a <link rel="stylesheet" type="text/css" href="..." /> * is the fully qualified URL. Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java 2013-04-08 19:11:50 UTC (rev 8214) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java 2013-04-09 16:05:03 UTC (rev 8215) @@ -25,6 +25,7 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_HAS_OBJECT_WITH_PROTOTYPE_PROPERTY_IN_WINDOW_SCOPE; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_XML; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.STRING_TRIM; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.STRING_TRIM_LEFT_RIGHT; import java.io.IOException; import java.io.ObjectInputStream; @@ -284,15 +285,16 @@ // Rhino defines too much methods for us, particularly since implementation of ECMAScript5 removePrototypeProperties(window, "String", "equals", "equalsIgnoreCase"); - if (browserVersion.hasFeature(STRING_TRIM)) { + if (!browserVersion.hasFeature(STRING_TRIM)) { + removePrototypeProperties(window, "String", "trim"); + } + if (browserVersion.hasFeature(STRING_TRIM_LEFT_RIGHT)) { final ScriptableObject stringPrototype = (ScriptableObject) ScriptableObject.getClassPrototype(window, "String"); stringPrototype.defineFunctionProperties(new String[] {"trimLeft", "trimRight"}, StringCustom.class, ScriptableObject.EMPTY); } - else { - removePrototypeProperties(window, "String", "trim"); - } + if (!browserVersion.hasFeature(JS_FUNCTION_BIND)) { removePrototypeProperties(window, "Function", "bind"); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeStringTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeStringTest.java 2013-04-08 19:11:50 UTC (rev 8214) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeStringTest.java 2013-04-09 16:05:03 UTC (rev 8215) @@ -92,15 +92,56 @@ * @throws Exception if the test fails */ @Test - @Alerts(IE = "", DEFAULT = { "2", "3", "4" }) + @Alerts(IE8 = "", DEFAULT = "2") public void trim() throws Exception { final String html - = "<html><head><title>foo</title><script>\n" + = "<!DOCTYPE html>\n" + + "<html><head><title>foo</title><script>\n" + "function doTest() {\n" + " var string = ' hi ';\n" + " if (''.trim) {\n" + " alert(string.trim().length);\n" + + " }\n" + + "}\n" + + "</script></head><body onload='doTest()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(IE = "", DEFAULT = "3") + public void trimRight() throws Exception { + final String html + = "<!DOCTYPE html>\n" + + "<html><head><title>foo</title><script>\n" + + "function doTest() {\n" + + " var string = ' hi ';\n" + + " if (''.trimRight) {\n" + " alert(string.trimRight().length);\n" + + " }\n" + + "}\n" + + "</script></head><body onload='doTest()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(IE = "", DEFAULT = "4") + public void trimLeft() throws Exception { + final String html + = "<!DOCTYPE html>\n" + + "<html><head><title>foo</title><script>\n" + + "function doTest() {\n" + + " var string = ' hi ';\n" + + " if (''.trimLeft) {\n" + " alert(string.trimLeft().length);\n" + " }\n" + "}\n" @@ -109,5 +150,4 @@ loadPageWithAlerts2(html); } - } |
From: <mgu...@us...> - 2013-04-11 14:29:06
|
Revision: 8218 http://sourceforge.net/p/htmlunit/code/8218 Author: mguillem Date: 2013-04-11 14:29:01 +0000 (Thu, 11 Apr 2013) Log Message: ----------- JavaScript: load the source of a dynamically created HTML(I)FrameElement first when it is added to the DOM. Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/BaseFrameElement.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlElement.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLIFrameElement2Test.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-04-10 16:07:28 UTC (rev 8217) +++ trunk/htmlunit/src/changes/changes.xml 2013-04-11 14:29:01 UTC (rev 8218) @@ -8,6 +8,9 @@ <body> <release version="2.13" date="???" description="Bugfixes"> + <action type="fix" dev="mguillem"> + JavaScript: load the source of a dynamically created HTML(I)FrameElement first when it is added to the DOM. + </action> <action type="fix" dev="rbri" issue="1501"> JavaScript: IE 9 supports String.trim(). </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/BaseFrameElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/BaseFrameElement.java 2013-04-10 16:07:28 UTC (rev 8217) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/BaseFrameElement.java 2013-04-11 14:29:01 UTC (rev 8218) @@ -50,9 +50,10 @@ public abstract class BaseFrameElement extends HtmlElement { private static final Log LOG = LogFactory.getLog(BaseFrameElement.class); - private WebWindow enclosedWindow_; + private FrameWindow enclosedWindow_; private boolean contentLoaded_ = false; private boolean createdByJavascript_ = false; + private boolean loadSrcWhenAddedToPage_ = false; /** * Creates an instance of BaseFrame. @@ -70,7 +71,7 @@ } private void init() { - WebWindow enclosedWindow = null; + FrameWindow enclosedWindow = null; try { if (getPage() instanceof HtmlPage) { // if loaded as part of XHR.responseXML, don't load content enclosedWindow = new FrameWindow(this); @@ -321,7 +322,7 @@ * Gets the window enclosed in this frame. * @return the window enclosed in this frame */ - public WebWindow getEnclosedWindow() { + public FrameWindow getEnclosedWindow() { return enclosedWindow_; } @@ -345,28 +346,46 @@ super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); if ("src".equals(qualifiedName) && !WebClient.ABOUT_BLANK.equals(attributeValue)) { - final JavaScriptEngine jsEngine = getPage().getWebClient().getJavaScriptEngine(); - // When src is set from a script, loading is postponed until script finishes - // in fact this implementation is probably wrong: JavaScript URL should be - // first evaluated and only loading, when any, should be postponed. - if (!jsEngine.isScriptRunning() || attributeValue.startsWith(JavaScriptURLConnection.JAVASCRIPT_PREFIX)) { - loadInnerPageIfPossible(attributeValue); + if (isDirectlyAttachedToPage()) { + loadSrc(); } else { - final String src = attributeValue; - final PostponedAction action = new PostponedAction(getPage()) { - @Override - public void execute() throws Exception { - if (getSrcAttribute().equals(src)) { - loadInnerPage(); - } - } - }; - jsEngine.addPostponedAction(action); + loadSrcWhenAddedToPage_ = true; } } } + private void loadSrc() { + loadSrcWhenAddedToPage_ = false; + final String src = getSrcAttribute(); + + final JavaScriptEngine jsEngine = getPage().getWebClient().getJavaScriptEngine(); + // When src is set from a script, loading is postponed until script finishes + // in fact this implementation is probably wrong: JavaScript URL should be + // first evaluated and only loading, when any, should be postponed. + if (!jsEngine.isScriptRunning() || src.startsWith(JavaScriptURLConnection.JAVASCRIPT_PREFIX)) { + loadInnerPageIfPossible(src); + } + else { + final PostponedAction action = new PostponedAction(getPage()) { + @Override + public void execute() throws Exception { + if (getSrcAttribute().equals(src)) { + loadInnerPage(); + } + } + }; + jsEngine.addPostponedAction(action); + } + } + + @Override + protected void onAddedToPage() { + if (loadSrcWhenAddedToPage_) { + loadSrc(); + } + } + /** * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br/> * Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java 2013-04-10 16:07:28 UTC (rev 8217) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java 2013-04-11 14:29:01 UTC (rev 8218) @@ -830,6 +830,7 @@ newnode.previousSibling_ = null; newnode.firstChild_ = null; newnode.scriptObject_ = null; + newnode.directlyAttachedToPage_ = false; // if deep, clone the kids too. if (deep) { @@ -914,19 +915,20 @@ final boolean wasAlreadyAttached = domNode.isDirectlyAttachedToPage(); domNode.directlyAttachedToPage_ = isDirectlyAttachedToPage(); - // trigger events - if (!(this instanceof DomDocumentFragment) && (getPage() instanceof HtmlPage)) { - ((HtmlPage) getPage()).notifyNodeAdded(domNode); - } + if (isDirectlyAttachedToPage()) { + // trigger events + if (!(this instanceof DomDocumentFragment) && (getPage() instanceof HtmlPage)) { + ((HtmlPage) getPage()).notifyNodeAdded(domNode); + } - // a node that is already "complete" (ie not being parsed) and not yet attached - if (!domNode.isBodyParsed() && isDirectlyAttachedToPage() && !wasAlreadyAttached) { - domNode.onAddedToPage(); - for (final DomNode child : domNode.getDescendants()) { - child.directlyAttachedToPage_ = true; - child.onAllChildrenAddedToPage(true); + // a node that is already "complete" (ie not being parsed) and not yet attached + if (!domNode.isBodyParsed() && !wasAlreadyAttached) { + for (final DomNode child : domNode.getDescendants()) { + child.directlyAttachedToPage_ = true; + child.onAllChildrenAddedToPage(true); + } + domNode.onAllChildrenAddedToPage(true); } - domNode.onAllChildrenAddedToPage(true); } fireNodeAdded(this, domNode); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlElement.java 2013-04-10 16:07:28 UTC (rev 8217) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlElement.java 2013-04-11 14:29:01 UTC (rev 8218) @@ -133,7 +133,8 @@ final String oldAttributeValue = getAttribute(qualifiedName); - final boolean mappedElement = HtmlPage.isMappedElement(getOwnerDocument(), qualifiedName); + final boolean mappedElement = isDirectlyAttachedToPage() + && HtmlPage.isMappedElement(getOwnerDocument(), qualifiedName); if (mappedElement) { ((HtmlPage) getPage()).removeMappedElement(this); } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2013-04-10 16:07:28 UTC (rev 8217) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2013-04-11 14:29:01 UTC (rev 8218) @@ -141,6 +141,7 @@ private String originalCharset_; private Map<String, SortedSet<DomElement>> idMap_ = new HashMap<String, SortedSet<DomElement>>(); private Map<String, SortedSet<DomElement>> nameMap_ = new HashMap<String, SortedSet<DomElement>>(); + private SortedSet<BaseFrameElement> frameElements_ = new TreeSet<BaseFrameElement>(documentPositionComparator); private HtmlElement elementWithFocus_; private int parserCount_; private int snippetParserCount_; @@ -1451,13 +1452,8 @@ */ public List<FrameWindow> getFrames() { final List<FrameWindow> list = new ArrayList<FrameWindow>(); - final WebWindow enclosingWindow = getEnclosingWindow(); - for (final WebWindow window : getWebClient().getWebWindows()) { - // quite strange but for a TopLevelWindow parent == self - if (enclosingWindow == window.getParentWindow() - && enclosingWindow != window) { - list.add((FrameWindow) window); - } + for (final BaseFrameElement frameElement : frameElements_) { + list.add(frameElement.getEnclosedWindow()); } return list; } @@ -1740,10 +1736,8 @@ * @param recurse indicates if children must be added too */ void addMappedElement(final DomElement element, final boolean recurse) { - if (isDescendant(element)) { - addElement(idMap_, element, "id", recurse); - addElement(nameMap_, element, "name", recurse); - } + addElement(idMap_, element, "id", recurse); + addElement(nameMap_, element, "name", recurse); } private void addElement(final Map<String, SortedSet<DomElement>> map, final DomElement element, @@ -1814,6 +1808,10 @@ if (node instanceof DomElement) { addMappedElement((DomElement) node, true); + if (node instanceof BaseFrameElement) { + frameElements_.add((BaseFrameElement) node); + } + if ("base".equals(node.getNodeName())) { calculateBase(); } @@ -1846,6 +1844,11 @@ void notifyNodeRemoved(final DomNode node) { if (node instanceof HtmlElement) { removeMappedElement((HtmlElement) node, true, true); + + if (node instanceof BaseFrameElement) { + frameElements_.remove(node); + } + if ("base".equals(node.getNodeName())) { calculateBase(); } @@ -2056,13 +2059,6 @@ final HtmlPage result = (HtmlPage) super.cloneNode(deep); final SimpleScriptable jsObjClone = ((SimpleScriptable) getScriptObject()).clone(); jsObjClone.setDomNode(result); - if (deep) { - // fix up idMap_ and result's idMap_s - for (final HtmlElement child : result.getHtmlElementDescendants()) { - removeMappedElement(child); - result.addMappedElement(child); - } - } return result; } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLIFrameElement2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLIFrameElement2Test.java 2013-04-10 16:07:28 UTC (rev 8217) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLIFrameElement2Test.java 2013-04-11 14:29:01 UTC (rev 8218) @@ -238,9 +238,26 @@ } /** + * A frame element that is not appended to the document should not be loaded. * @throws Exception if an error occurs */ @Test + @Alerts("created") + public void documentCreateElement_noAppendNoLoad() throws Exception { + final String html = "<html><body><script>\n" + + "var myFrame = document.createElement('iframe');\n" + + "myFrame.src = 'notExisting.html';\n" + + "alert('created');\n" + + "</script></body></html>"; + + loadPageWithAlerts2(html); + assertEquals(1, getMockWebConnection().getRequestCount()); + } + + /** + * @throws Exception if an error occurs + */ + @Test @Alerts(DEFAULT = { "createIFrame", "loaded", "foo" }, IE = { "createIFrame" }) public void documentCreateElement_onLoad3() throws Exception { final String html = |
From: <rb...@us...> - 2013-04-13 10:14:05
|
Revision: 8221 http://sourceforge.net/p/htmlunit/code/8221 Author: rbri Date: 2013-04-13 10:14:00 +0000 (Sat, 13 Apr 2013) Log Message: ----------- Starting with IE8 the radio button checked state is reseted to false when adding to page 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/html/HtmlRadioButtonInput.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput2Test.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-04-12 19:07:54 UTC (rev 8220) +++ trunk/htmlunit/src/changes/changes.xml 2013-04-13 10:14:00 UTC (rev 8221) @@ -8,6 +8,10 @@ <body> <release version="2.13" date="???" description="Bugfixes"> + <action type="fix" dev="rbri"> + JavaScript: Starting with IE8 the radio button checked state is reseted to false + when adding to page. + </action> <action type="update" dev="rbri"> Upgrade Apache HttpClient to 4.2.4. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-04-12 19:07:54 UTC (rev 8220) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-04-13 10:14:00 UTC (rev 8221) @@ -605,10 +605,14 @@ @BrowserFeature(@WebBrowser(IE)) HTMLPARSER_REMOVE_EMPTY_CONTENT, - /** Set this checked state back to default when added to page (IE). */ - @BrowserFeature(@WebBrowser(IE)) + /** 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/HtmlRadioButtonInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java 2013-04-12 19:07:54 UTC (rev 8220) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java 2013-04-13 10:14:00 UTC (rev 8221) @@ -17,6 +17,7 @@ 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 java.io.IOException; import java.util.Map; @@ -208,6 +209,9 @@ if (hasFeature(HTMLRADIOINPUT_SET_CHECKED_TO_DEFAULT_WHEN_ADDED)) { setChecked(isDefaultChecked()); } + if (hasFeature(HTMLRADIOINPUT_SET_CHECKED_TO_FALSE_WHEN_ADDED)) { + setChecked(false); + } } /** 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-12 19:07:54 UTC (rev 8220) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput2Test.java 2013-04-13 10:14:00 UTC (rev 8221) @@ -42,7 +42,8 @@ */ @Test @Alerts(DEFAULT = { "true", "true", "true", "true", "true", "true" }, - IE = { "true", "false", "false", "false", "true", "true" }) + IE = { "true", "false", "false", "false", "false", "false" }, + IE6 = { "true", "false", "false", "false", "true", "true" }) public void checked_on_attachment() throws Exception { final String html = "<html>\n" + "<head>\n" |
From: <rb...@us...> - 2013-04-15 17:10:40
|
Revision: 8224 http://sourceforge.net/p/htmlunit/code/8224 Author: rbri Date: 2013-04-15 17:10:36 +0000 (Mon, 15 Apr 2013) Log Message: ----------- Starting with IE8 the radio button checked state is reseted to false when adding to page but only when added from Javascript Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java 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/html/HtmlRadioButtonInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java 2013-04-13 15:14:35 UTC (rev 8223) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java 2013-04-15 17:10:36 UTC (rev 8224) @@ -17,7 +17,6 @@ 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 java.io.IOException; import java.util.Map; @@ -209,9 +208,6 @@ if (hasFeature(HTMLRADIOINPUT_SET_CHECKED_TO_DEFAULT_WHEN_ADDED)) { setChecked(isDefaultChecked()); } - if (hasFeature(HTMLRADIOINPUT_SET_CHECKED_TO_FALSE_WHEN_ADDED)) { - setChecked(false); - } } /** 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-13 15:14:35 UTC (rev 8223) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Node.java 2013-04-15 17:10:36 UTC (rev 8224) @@ -18,6 +18,7 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_124; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_125; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_45; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLRADIOINPUT_SET_CHECKED_TO_FALSE_WHEN_ADDED; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_APPEND_CHILD_CREATE_DOCUMENT_FRAGMENT_PARENT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_APPEND_CHILD_THROWS_NO_EXCEPTION_FOR_WRONG_NOTE; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_CLONE_NODE_COPIES_EVENT_LISTENERS; @@ -49,6 +50,7 @@ import com.gargoylesoftware.htmlunit.html.DomText; import com.gargoylesoftware.htmlunit.html.HtmlInlineFrame; import com.gargoylesoftware.htmlunit.html.HtmlPage; +import com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput; import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstant; @@ -233,6 +235,15 @@ parentNode.appendChild(childDomNode); appendedChild = childObject; + // special hack for IE and radio buttons + // this can't be done in onAddedToPage() because + // it only happens when appendChild() is called. + if (childDomNode instanceof HtmlRadioButtonInput) { + HtmlRadioButtonInput radio = (HtmlRadioButtonInput) childDomNode; + if (getBrowserVersion().hasFeature(HTMLRADIOINPUT_SET_CHECKED_TO_FALSE_WHEN_ADDED)) { + radio.setChecked(false); + } + } // if the parentNode has null parentNode in IE, // create a DocumentFragment to be the parentNode's parentNode. if (!(parentNode instanceof SgmlPage) 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-13 15:14:35 UTC (rev 8223) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput2Test.java 2013-04-15 17:10:36 UTC (rev 8224) @@ -73,6 +73,40 @@ } /** + * @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" + + " <script>\n" + + " function test() {\n" + + " var input = document.createElement('input');\n" + + " input.type = 'radio';\n" + + " alert(input.checked);\n" + + " document.body.appendChild(input);\n" + + " alert(input.checked);\n" + + " document.body.removeChild(input);\n" + + " alert(input.checked);\n" + + "\n" + + " input.defaultChecked = true;\n" + + " alert(input.checked);\n" + + " document.body.appendChild(input);\n" + + " alert(input.checked);\n" + + " document.body.removeChild(input);\n" + + " alert(input.checked);\n" + + " }\n" + + " </script>\n" + + "</head><body onload='test()'>\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. |
From: <rb...@us...> - 2013-04-18 18:03:44
|
Revision: 8228 http://sourceforge.net/p/htmlunit/code/8228 Author: rbri Date: 2013-04-18 18:03:39 +0000 (Thu, 18 Apr 2013) Log Message: ----------- Fix the mousedown/mouseup events triggered when clicking on an option. 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/html/HtmlOption.java Added Paths: ----------- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlOption2Test.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-04-17 17:38:32 UTC (rev 8227) +++ trunk/htmlunit/src/changes/changes.xml 2013-04-18 18:03:39 UTC (rev 8228) @@ -9,6 +9,9 @@ <body> <release version="2.13" date="???" description="Bugfixes"> <action type="fix" dev="rbri"> + JavaScript: Fix the mousedown/mouseup events triggered when clicking on an option. + </action> + <action type="fix" dev="rbri"> JavaScript: Starting with IE8 the radio button checked state is reseted to false when adding to page. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-04-17 17:38:32 UTC (rev 8227) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-04-18 18:03:39 UTC (rev 8228) @@ -183,6 +183,26 @@ @BrowserFeature({ @WebBrowser(FF), @WebBrowser(CHROME) }) EVENT_ONLOAD_IFRAME_CREATED_BY_JAVASCRIPT, + /** Does not trigger "onmousedown" event handler for the select options. */ + @BrowserFeature({ @WebBrowser(value = FF, minVersion = 10), @WebBrowser(IE) }) + EVENT_ONMOUSEDOWN_FOR_SELECT_OPTION_TRIGGERS_ADDITIONAL_DOWN_FOR_SELECT, + + /** Does not trigger "onmousedown" event handler for the select options. */ + @BrowserFeature({ @WebBrowser(value = FF, minVersion = 10) }) + EVENT_ONMOUSEDOWN_FOR_SELECT_OPTION_TRIGGERS_ADDITIONAL_UP_FOR_SELECT, + + /** Does not trigger "onmousedown" event handler for the select options. */ + @BrowserFeature({ @WebBrowser(IE), @WebBrowser(CHROME), @WebBrowser(value = FF, maxVersion = 3.6f) }) + EVENT_ONMOUSEDOWN_NOT_FOR_SELECT_OPTION, + + /** Does not trigger "onmousedown" event handler for the select options. */ + @BrowserFeature({ @WebBrowser(value = FF, maxVersion = 3.6f), @WebBrowser(IE), @WebBrowser(CHROME) }) + EVENT_ONMOUSEUP_FOR_SELECT_OPTION_TRIGGERS_ADDITIONAL_UP_FOR_SELECT, + + /** Does not trigger "onmouseup" event handler for the select options. */ + @BrowserFeature({ @WebBrowser(IE), @WebBrowser(CHROME) }) + EVENT_ONMOUSEUP_NOT_FOR_SELECT_OPTION, + /** Triggers "onreadystatechange" event. */ @BrowserFeature(@WebBrowser(IE)) EVENT_ONREADY_STATE_CHANGE, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlOption.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlOption.java 2013-04-17 17:38:32 UTC (rev 8227) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlOption.java 2013-04-18 18:03:39 UTC (rev 8228) @@ -16,6 +16,14 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.CONTROL_UPDATE_DONE_BEFORE_CLICK_EVENT_FIRED; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_ONCLICK_FOR_SELECT_OPTION_ALSO; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_ONMOUSEDOWN_NOT_FOR_SELECT_OPTION; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures. + EVENT_ONMOUSEDOWN_FOR_SELECT_OPTION_TRIGGERS_ADDITIONAL_DOWN_FOR_SELECT; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures. + EVENT_ONMOUSEDOWN_FOR_SELECT_OPTION_TRIGGERS_ADDITIONAL_UP_FOR_SELECT; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_ONMOUSEUP_NOT_FOR_SELECT_OPTION; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures. + EVENT_ONMOUSEUP_FOR_SELECT_OPTION_TRIGGERS_ADDITIONAL_UP_FOR_SELECT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLOPTION_EMPTY_TEXT_IS_NO_CHILDREN; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLOPTION_PREVENT_DISABLED; @@ -239,6 +247,42 @@ * {@inheritDoc} */ @Override + public Page mouseDown(final boolean shiftKey, final boolean ctrlKey, final boolean altKey, final int button) { + Page page = null; + if (hasFeature(EVENT_ONMOUSEDOWN_FOR_SELECT_OPTION_TRIGGERS_ADDITIONAL_DOWN_FOR_SELECT)) { + page = getEnclosingSelect().mouseDown(shiftKey, ctrlKey, altKey, button); + } + if (hasFeature(EVENT_ONMOUSEDOWN_FOR_SELECT_OPTION_TRIGGERS_ADDITIONAL_UP_FOR_SELECT)) { + page = getEnclosingSelect().mouseUp(shiftKey, ctrlKey, altKey, button); + } + + if (hasFeature(EVENT_ONMOUSEDOWN_NOT_FOR_SELECT_OPTION)) { + return page; + } + return super.mouseDown(shiftKey, ctrlKey, altKey, button); + } + + /** + * Selects the option if it's not already selected. + * {@inheritDoc} + */ + @Override + public Page mouseUp(final boolean shiftKey, final boolean ctrlKey, final boolean altKey, final int button) { + Page page = null; + if (hasFeature(EVENT_ONMOUSEUP_FOR_SELECT_OPTION_TRIGGERS_ADDITIONAL_UP_FOR_SELECT)) { + page = getEnclosingSelect().mouseUp(shiftKey, ctrlKey, altKey, button); + } + if (hasFeature(EVENT_ONMOUSEUP_NOT_FOR_SELECT_OPTION)) { + return page; + } + return super.mouseUp(shiftKey, ctrlKey, altKey, button); + } + + /** + * Selects the option if it's not already selected. + * {@inheritDoc} + */ + @Override protected boolean doClickStateUpdate() throws IOException { boolean changed = false; if (!isSelected()) { Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlOption2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlOption2Test.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlOption2Test.java 2013-04-18 18:03:39 UTC (rev 8228) @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2002-2013 Gargoyle Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gargoylesoftware.htmlunit.html; + +import java.util.Arrays; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; + +import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.WebDriverTestCase; + +/** + * Tests for {@link HtmlOption}. + * + * @version $Revision$ + * @author Ronald Brill + */ +@RunWith(BrowserRunner.class) +public class HtmlOption2Test extends WebDriverTestCase { + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "sDown,mousedown,sUp,mouseup,oDown,mousedown,sDown,mousedown,oUp,mouseup,sUp,mouseup,", + FF3_6 = "sUp,mouseup,oUp,mouseup,sUp,mouseup,", + IE = "sDown,mousedown,sUp,mouseup,", + CHROME = "sUp,mouseup,") + public void onMouse() throws Exception { + final String html = "<html><head><title>foo</title>\n" + + "<script>\n" + + " function debug(string) {\n" + + " document.getElementById('myTextarea').value += string + ',';\n" + + " }\n" + + "</script>\n" + + "</head><body>\n" + + " <form>\n" + + " <select name='select1' size='4'" + + " onMouseDown='debug(\"sDown\");debug(event.type);'" + + " onMouseUp='debug(\"sUp\");debug(event.type);'>\n" + + " <option id='opt1' value='option1'>Option1</option>\n" + + " <option id='opt2' value='option2' selected='selected'>Option2</option>\n" + + " <option id='opt3' value='option3'" + + " onMouseDown='debug(\"oDown\");debug(event.type);'" + + " onMouseUp='debug(\"oUp\");debug(event.type);'>Option3</option>\n" + + " </select>\n" + + " </form>\n" + + " <textarea id='myTextarea'></textarea>\n" + + "</body></html>"; + + final WebDriver driver = loadPage2(html); + driver.findElement(By.id("opt3")).click(); + + assertEquals(Arrays.asList(getExpectedAlerts()).toString(), + '[' + driver.findElement(By.id("myTextarea")).getAttribute("value") + ']'); + } +} Property changes on: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlOption2Test.java ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +Author Date Id Revision \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property |
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" |
From: <rb...@us...> - 2013-04-19 15:13:01
|
Revision: 8234 http://sourceforge.net/p/htmlunit/code/8234 Author: rbri Date: 2013-04-19 15:12:55 +0000 (Fri, 19 Apr 2013) Log Message: ----------- next try to behave like IE8 when working with radio buttons from JS Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Document.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Node.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLInputElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput2Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlInput.java 2013-04-19 12:31:58 UTC (rev 8233) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlInput.java 2013-04-19 15:12:55 UTC (rev 8234) @@ -52,6 +52,7 @@ private String defaultValue_; private String originalName_; private Collection<String> previousNames_ = Collections.emptySet(); + private boolean createdByJavascript_ = false; /** * Creates an instance. @@ -523,4 +524,35 @@ public Collection<String> getPreviousNames() { return previousNames_; } + + /** + * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br/> + * + * Marks this frame as created by javascript. This is needed to handle + * some special IE behavior. + */ + public void markAsCreatedByJavascript() { + createdByJavascript_ = true; + } + + /** + * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br/> + * + * Unmarks this frame as created by javascript. This is needed to handle + * some special IE behavior. + */ + public void unmarkAsCreatedByJavascript() { + createdByJavascript_ = false; + } + + /** + * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br/> + * + * Returns true if this frame was created by javascript. This is needed to handle + * some special IE behavior. + * @return true or false + */ + public boolean wasCreatedByJavascript() { + return createdByJavascript_; + } } 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-19 12:31:58 UTC (rev 8233) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java 2013-04-19 15:12:55 UTC (rev 8234) @@ -17,6 +17,7 @@ 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 java.io.IOException; import java.util.Map; @@ -208,6 +209,9 @@ if (hasFeature(HTMLRADIOINPUT_SET_CHECKED_TO_DEFAULT_WHEN_ADDED)) { setChecked(isDefaultChecked()); } + if (wasCreatedByJavascript() && hasFeature(HTMLRADIOINPUT_SET_CHECKED_TO_FALSE_WHEN_ADDED)) { + removeAttribute("checked"); + } } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Document.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Document.java 2013-04-19 12:31:58 UTC (rev 8233) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Document.java 2013-04-19 15:12:55 UTC (rev 8234) @@ -43,6 +43,7 @@ import com.gargoylesoftware.htmlunit.html.FrameWindow; import com.gargoylesoftware.htmlunit.html.HTMLParser; import com.gargoylesoftware.htmlunit.html.HtmlDivision; +import com.gargoylesoftware.htmlunit.html.HtmlInput; import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.html.impl.SimpleRange; import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; @@ -434,6 +435,9 @@ if (element instanceof BaseFrameElement) { ((BaseFrameElement) element).markAsCreatedByJavascript(); } + if (element instanceof HtmlInput) { + ((HtmlInput) element).markAsCreatedByJavascript(); + } final Object jsElement = getScriptableFor(element); if (jsElement == NOT_FOUND) { 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:31:58 UTC (rev 8233) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Node.java 2013-04-19 15:12:55 UTC (rev 8234) @@ -18,7 +18,6 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_124; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_125; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_45; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLRADIOINPUT_SET_CHECKED_TO_FALSE_WHEN_ADDED; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_APPEND_CHILD_CREATE_DOCUMENT_FRAGMENT_PARENT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_APPEND_CHILD_THROWS_NO_EXCEPTION_FOR_WRONG_NOTE; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_CLONE_NODE_COPIES_EVENT_LISTENERS; @@ -50,7 +49,6 @@ import com.gargoylesoftware.htmlunit.html.DomText; import com.gargoylesoftware.htmlunit.html.HtmlInlineFrame; import com.gargoylesoftware.htmlunit.html.HtmlPage; -import com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput; import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstant; @@ -235,15 +233,6 @@ parentNode.appendChild(childDomNode); appendedChild = childObject; - // special hack for IE and radio buttons - // this can't be done in onAddedToPage() because - // it only happens when appendChild() is called. - if (childDomNode instanceof HtmlRadioButtonInput) { - final HtmlRadioButtonInput radio = (HtmlRadioButtonInput) childDomNode; - if (getBrowserVersion().hasFeature(HTMLRADIOINPUT_SET_CHECKED_TO_FALSE_WHEN_ADDED)) { - radio.setChecked(false); - } - } // if the parentNode has null parentNode in IE, // create a DocumentFragment to be the parentNode's parentNode. if (!(parentNode instanceof SgmlPage) @@ -434,16 +423,6 @@ 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/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLInputElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLInputElement.java 2013-04-19 12:31:58 UTC (rev 8233) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLInputElement.java 2013-04-19 15:12:55 UTC (rev 8234) @@ -69,6 +69,10 @@ final HtmlInput newInput = (HtmlInput) InputElementFactory.instance .createElement(input.getPage(), "input", attributes); + if (input.wasCreatedByJavascript()) { + newInput.markAsCreatedByJavascript(); + } + if (input.getParentNode() != null) { input.getParentNode().replaceChild(newInput, input); } 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:31:58 UTC (rev 8233) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput2Test.java 2013-04-19 15:12:55 UTC (rev 8234) @@ -44,7 +44,7 @@ @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_attachment() throws Exception { + public void checked_appendChild() throws Exception { final String html = "<html>\n" + "<head>\n" + " <script>\n" @@ -53,20 +53,22 @@ + " input.type = 'radio';\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); @@ -79,7 +81,7 @@ @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_insertBefore() throws Exception { + public void notchecked_appendChild() throws Exception { final String html = "<html>\n" + "<head>\n" + " <script>\n" @@ -88,22 +90,21 @@ + " 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" + + " 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.insertBefore(input, after);\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" - + " <div id='myDiv'><div id='divAfter'></div></div>\n" + + " <form><div id='myDiv'></div></form>\n" + "</body></html>"; loadPageWithAlerts2(html); @@ -113,17 +114,16 @@ * @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 { + @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 = 'radio';\n" - + " input.checked = true;\n" + " alert(input.checked);\n" + " var parent=document.getElementById('myDiv');\n" + " var after=document.getElementById('divAfter');\n" @@ -141,7 +141,7 @@ + " }\n" + " </script>\n" + "</head><body onload='test()'>\n" - + " <div id='myDiv'><div id='divAfter'></div></div>\n" + + " <form><div id='myDiv'><div id='divAfter'></div></div></form>\n" + "</body></html>"; loadPageWithAlerts2(html); @@ -151,31 +151,35 @@ * @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 { + @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 = 'radio';\n" + + " input.checked = true;\n" + " alert(input.checked);\n" - + " document.body.appendChild(input);\n" + + " var parent=document.getElementById('myDiv');\n" + + " var after=document.getElementById('divAfter');\n" + + " parent.insertBefore(input, after);\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.insertBefore(input, after);\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 id='divAfter'></div></div></form>\n" + "</body></html>"; loadPageWithAlerts2(html); |
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" |
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 |
From: <rb...@us...> - 2013-04-24 18:18:32
|
Revision: 8240 http://sourceforge.net/p/htmlunit/code/8240 Author: rbri Date: 2013-04-24 18:18:29 +0000 (Wed, 24 Apr 2013) Log Message: ----------- more test, minor cleanup and preventDefault fix for radio buttons Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 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/HtmlPage.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2013-04-23 19:26:30 UTC (rev 8239) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2013-04-24 18:18:29 UTC (rev 8240) @@ -1999,43 +1999,6 @@ } /** - * Select the specified radio button in the page (outside any <form>). - * - * @param radioButtonInput the radio Button - */ - @SuppressWarnings("unchecked") - void setCheckedRadioButton(final HtmlRadioButtonInput radioButtonInput) { - // May be done in single XPath search? - final List<HtmlRadioButtonInput> pageInputs = - (List<HtmlRadioButtonInput>) getByXPath("//input[lower-case(@type)='radio' " - + "and @name='" + radioButtonInput.getNameAttribute() + "']"); - final List<HtmlRadioButtonInput> formInputs = - (List<HtmlRadioButtonInput>) getByXPath("//form//input[lower-case(@type)='radio' " - + "and @name='" + radioButtonInput.getNameAttribute() + "']"); - - pageInputs.removeAll(formInputs); - - boolean found = false; - for (final HtmlRadioButtonInput input : pageInputs) { - if (input == radioButtonInput) { - input.setAttribute("checked", "checked"); - found = true; - } - else { - input.removeAttribute("checked"); - } - } - for (final HtmlRadioButtonInput input : formInputs) { - if (input == radioButtonInput) { - found = true; - } - } - if (!found) { - radioButtonInput.setAttribute("checked", "checked"); - } - } - - /** * Creates a clone of this instance, and clears cached state * to be not shared with the original. * 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-23 19:26:30 UTC (rev 8239) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java 2013-04-24 18:18:29 UTC (rev 8240) @@ -20,6 +20,7 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLINPUT_SET_CHECKED_TO_FALSE_WHEN_ADDED; import java.io.IOException; +import java.util.List; import java.util.Map; import com.gargoylesoftware.htmlunit.Page; @@ -101,7 +102,7 @@ form.setCheckedRadioButton(this); } else if (page instanceof HtmlPage) { - ((HtmlPage) page).setCheckedRadioButton(this); + setCheckedForPage((HtmlPage) page); } } else { @@ -134,13 +135,46 @@ form.setCheckedRadioButton(this); } else if (page instanceof HtmlPage) { - ((HtmlPage) page).setCheckedRadioButton(this); + setCheckedForPage((HtmlPage) page); } super.doClickStateUpdate(); return changed; } /** + * Select the specified radio button in the page (outside any <form>). + * + * @param radioButtonInput the radio Button + */ + @SuppressWarnings("unchecked") + private void setCheckedForPage(final HtmlPage htmlPage) { + // May be done in single XPath search? + final List<HtmlRadioButtonInput> pageInputs = + (List<HtmlRadioButtonInput>) htmlPage.getByXPath("//input[lower-case(@type)='radio' " + + "and @name='" + getNameAttribute() + "']"); + final List<HtmlRadioButtonInput> formInputs = + (List<HtmlRadioButtonInput>) htmlPage.getByXPath("//form//input[lower-case(@type)='radio' " + + "and @name='" + getNameAttribute() + "']"); + + pageInputs.removeAll(formInputs); + + boolean foundInPage = false; + for (final HtmlRadioButtonInput input : pageInputs) { + if (input == this) { + input.setAttribute("checked", "checked"); + foundInPage = true; + } + else { + input.removeAttribute("checked"); + } + } + + if (!foundInPage && !formInputs.contains(this)) { + setAttribute("checked", "checked"); + } + } + + /** * {@inheritDoc} */ @Override @@ -163,6 +197,14 @@ /** * {@inheritDoc} + */ + @Override + protected void preventDefault() { + setChecked(!isChecked()); + } + + /** + * {@inheritDoc} * Also sets the value to the new default value. * @see SubmittableElement#setDefaultValue(String) */ 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-23 19:26:30 UTC (rev 8239) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput2Test.java 2013-04-24 18:18:29 UTC (rev 8240) @@ -20,6 +20,7 @@ import org.junit.runner.RunWith; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; @@ -473,4 +474,99 @@ assertEquals(getExpectedAlerts()[1], driver.getTitle()); } } + + /** + * @throws Exception if an error occurs + */ + @Test + public void preventDefault() throws Exception { + final String html = + "<html><head><script>\n" + + " function handler(e) {\n" + + " if (e)\n" + + " e.preventDefault();\n" + + " else\n" + + " return false;\n" + + " }\n" + + " function init() {\n" + + " document.getElementById('radio1').onclick = handler;\n" + + " }\n" + + "</script></head>\n" + + "<body onload='init()'>\n" + + " <input type='radio' id='radio1' name='radio1' />\n" + + "</body></html>"; + + final WebDriver driver = loadPage2(html); + final WebElement radio = driver.findElement(By.id("radio1")); + radio.click(); + assertFalse(radio.isSelected()); + } + + /** + * Verifies that a HtmlCheckBox is unchecked by default. + * The onClick tests make this assumption. + * @throws Exception if the test fails + */ + @Test + public void defaultState() throws Exception { + final String html + = "<html><head><title>foo</title></head><body>\n" + + "<form id='form1'>\n" + + " <input type='radio' name='radio' id='radio'>Check me</input>\n" + + "</form></body></html>"; + final WebDriver driver = loadPage2(html); + final WebElement radio = driver.findElement(By.id("radio")); + assertFalse(radio.isSelected()); + } + + /** + * @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('rdo').value);\n" + + + " var input = document.createElement('input');\n" + + " input.type = 'radio';\n" + + " alert(input.value);\n" + + + " var builder = document.createElement('div');\n" + + " builder.innerHTML = '<input type=\"radio\">';\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='radio' id='rdo'>\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 + */ + @Test + @Alerts("changed") + public void clickShouldTriggerOnchange() throws Exception { + final String html = "<html><body>\n" + + "<input type='radio' id='it' onchange='alert(\"changed\")'" + + "onmousedown='alert(\"down\")' onmouseup='alert(\"up\")' onfocus='alert(\"focused\")'>Check me\n" + + "<script>\n" + + "var elt = document.getElementById('it');\n" + + "elt.click();\n" + + "</script></body></html>"; + loadPageWithAlerts2(html); + } } |
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 */ |
From: <rb...@us...> - 2013-04-25 20:24:26
|
Revision: 8242 http://sourceforge.net/p/htmlunit/code/8242 Author: rbri Date: 2013-04-25 20:24:21 +0000 (Thu, 25 Apr 2013) Log Message: ----------- behave like IE8 when working with checkboxes/radio buttons from JS (next try to simulate the strange IE) Modified Paths: -------------- 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 trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput2Test.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-24 18:27:44 UTC (rev 8241) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput.java 2013-04-25 20:24:21 UTC (rev 8242) @@ -43,6 +43,7 @@ private boolean defaultCheckedState_; private boolean valueAtFocus_; + private boolean forceChecked_; /** * Creates an instance. @@ -188,10 +189,15 @@ @Override protected void onAddedToPage() { if (hasFeature(HTMLINPUT_SET_CHECKED_TO_DEFAULT_WHEN_ADDED)) { - setChecked(isDefaultChecked()); + reset(); } - if (wasCreatedByJavascript() && hasFeature(HTMLINPUT_SET_CHECKED_TO_FALSE_WHEN_ADDED)) { - removeAttribute("checked"); + if (hasFeature(HTMLINPUT_SET_CHECKED_TO_FALSE_WHEN_ADDED)) { + if (wasCreatedByJavascript()) { + removeAttribute("checked"); + } + else if (forceChecked_) { + setAttribute("checked", "checked"); + } } } @@ -203,7 +209,11 @@ final HtmlCheckBoxInput clone = (HtmlCheckBoxInput) super.cloneNode(deep); if (hasFeature(HTMLINPUT_SET_CHECKED_TO_FALSE_WHEN_ADDED)) { clone.removeAttribute("checked"); + clone.forceChecked_ = isDefaultChecked(); } + if (wasCreatedByJavascript()) { + clone.markAsCreatedByJavascript(); + } return clone; } 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:27:44 UTC (rev 8241) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java 2013-04-25 20:24:21 UTC (rev 8242) @@ -47,6 +47,7 @@ private boolean defaultCheckedState_; private boolean valueAtFocus_; + private boolean forceChecked_; /** * Creates an instance. @@ -249,10 +250,15 @@ @Override protected void onAddedToPage() { if (hasFeature(HTMLINPUT_SET_CHECKED_TO_DEFAULT_WHEN_ADDED)) { - setChecked(isDefaultChecked()); + reset(); } - if (wasCreatedByJavascript() && hasFeature(HTMLINPUT_SET_CHECKED_TO_FALSE_WHEN_ADDED)) { - removeAttribute("checked"); + if (hasFeature(HTMLINPUT_SET_CHECKED_TO_FALSE_WHEN_ADDED)) { + if (wasCreatedByJavascript()) { + removeAttribute("checked"); + } + else if (forceChecked_) { + setAttribute("checked", "checked"); + } } } @@ -264,7 +270,11 @@ final HtmlRadioButtonInput clone = (HtmlRadioButtonInput) super.cloneNode(deep); if (hasFeature(HTMLINPUT_SET_CHECKED_TO_FALSE_WHEN_ADDED)) { clone.removeAttribute("checked"); + clone.forceChecked_ = isDefaultChecked(); } + if (wasCreatedByJavascript()) { + clone.markAsCreatedByJavascript(); + } return clone; } 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-24 18:27:44 UTC (rev 8241) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput2Test.java 2013-04-25 20:24:21 UTC (rev 8242) @@ -26,7 +26,6 @@ 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; @@ -497,7 +496,6 @@ @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" @@ -612,7 +610,6 @@ @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" 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:27:44 UTC (rev 8241) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput2Test.java 2013-04-25 20:24:21 UTC (rev 8242) @@ -24,8 +24,6 @@ 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; /** @@ -495,7 +493,6 @@ @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" @@ -610,7 +607,6 @@ @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" |
From: <rb...@us...> - 2013-04-26 18:49:04
|
Revision: 8244 http://sourceforge.net/p/htmlunit/code/8244 Author: rbri Date: 2013-04-26 18:48:58 +0000 (Fri, 26 Apr 2013) Log Message: ----------- more generic test, more tests and again some fixes for IE8 Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java 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/DomNode.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java 2013-04-26 16:57:34 UTC (rev 8243) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java 2013-04-26 18:48:58 UTC (rev 8244) @@ -930,6 +930,9 @@ domNode.onAllChildrenAddedToPage(true); } } + if (this instanceof DomDocumentFragment) { + onAddedToDocumentFragment(); + } fireNodeAdded(this, domNode); } @@ -1202,6 +1205,20 @@ } /** + * Lifecycle method invoked whenever a node is added to a document fragment. Intended to + * be overridden by nodes which need to perform custom logic when they are + * added to a fragment. This method is recursive, so if you override it, please + * be sure to call <tt>super.onAddedToPage()</tt>. + */ + protected void onAddedToDocumentFragment() { + if (firstChild_ != null) { + for (final DomNode child : getChildren()) { + child.onAddedToDocumentFragment(); + } + } + } + + /** * @return an Iterable over the children of this node */ public final Iterable<DomNode> getChildren() { 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-26 16:57:34 UTC (rev 8243) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput.java 2013-04-26 18:48:58 UTC (rev 8244) @@ -188,6 +188,8 @@ */ @Override protected void onAddedToPage() { + super.onAddedToPage(); + if (hasFeature(HTMLINPUT_SET_CHECKED_TO_DEFAULT_WHEN_ADDED)) { reset(); } @@ -205,6 +207,26 @@ * {@inheritDoc} */ @Override + protected void onAddedToDocumentFragment() { + super.onAddedToDocumentFragment(); + + if (hasFeature(HTMLINPUT_SET_CHECKED_TO_DEFAULT_WHEN_ADDED)) { + reset(); + } + if (hasFeature(HTMLINPUT_SET_CHECKED_TO_FALSE_WHEN_ADDED)) { + if (wasCreatedByJavascript()) { + removeAttribute("checked"); + } + else if (forceChecked_) { + setAttribute("checked", "checked"); + } + } + } + + /** + * {@inheritDoc} + */ + @Override public DomNode cloneNode(final boolean deep) { final HtmlCheckBoxInput clone = (HtmlCheckBoxInput) super.cloneNode(deep); if (hasFeature(HTMLINPUT_SET_CHECKED_TO_FALSE_WHEN_ADDED)) { 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-26 16:57:34 UTC (rev 8243) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput2Test.java 2013-04-26 18:48:58 UTC (rev 8244) @@ -41,292 +41,233 @@ public class HtmlCheckBoxInput2Test extends WebDriverTestCase { /** - * 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 = { "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" - + " 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" - + " 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>"; + @Alerts(DEFAULT = { "true", "true", "true" }, + IE = { "true", "false", "false" }) + public void checked_appendChild_docFragment() throws Exception { + performTest(true, true, false, true, false); + } - loadPageWithAlerts2(html); + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "false", "false", "false" }) + public void notchecked_appendChild_docFragment() throws Exception { + performTest(false, true, false, true, false); } /** * @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>"; + @Alerts(DEFAULT = { "true", "true", "true" }, + IE = { "true", "false", "false" }) + public void checked_insertBefore_docFragment() throws Exception { + performTest(true, false, false, true, false); + } - loadPageWithAlerts2(html); + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "false", "false", "false" }) + public void notchecked_insertBefore_docFragment() throws Exception { + performTest(false, false, false, true, false); } /** * @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>"; + @Alerts(DEFAULT = { "true", "true", "true" }) + public void checked_appendChild_fromHtml_docFragment() throws Exception { + performTest(true, true, true, true, false); + } - loadPageWithAlerts2(html); + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "false", "false", "false" }) + public void notchecked_appendChild_fromHtml_docFragment() throws Exception { + performTest(false, true, true, true, false); } /** * @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>"; + @Alerts(DEFAULT = { "true", "true", "true" }) + public void checked_insertBefore_fromHtml_docFragment() throws Exception { + performTest(true, false, true, true, false); + } - loadPageWithAlerts2(html); + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "false", "false", "false" }) + public void notchecked_insertBefore_fromHtml_docFragment() throws Exception { + performTest(false, false, true, true, false); } /** - * 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" }) - public void checked_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" - + " 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>"; + @Alerts(DEFAULT = { "true", "true", "true" }, + IE = { "true", "false", "false" }) + public void checked_appendChild_docFragment_cloneNode() throws Exception { + performTest(true, true, false, true, true); + } - loadPageWithAlerts2(html); + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "false", "false", "false" }) + public void notchecked_appendChild_docFragment_cloneNode() throws Exception { + performTest(false, true, false, true, true); } /** * @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_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" - + " 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>"; + @Alerts(DEFAULT = { "true", "true", "true" }, + IE = { "true", "false", "false" }) + public void checked_insertBefore_docFragment_cloneNode() throws Exception { + performTest(true, false, false, true, true); + } - loadPageWithAlerts2(html); + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "false", "false", "false" }) + public void notchecked_insertBefore_docFragment_cloneNode() throws Exception { + performTest(false, false, false, true, true); } /** * @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_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" - + " 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>"; + @Alerts(DEFAULT = { "true", "true", "true" }) + public void checked_appendChild_fromHtml_docFragment_cloneNode() throws Exception { + performTest(true, true, true, true, true); + } - loadPageWithAlerts2(html); + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "false", "false", "false" }) + public void notchecked_appendChild_fromHtml_docFragment_cloneNode() throws Exception { + performTest(false, true, true, true, true); } /** * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = { "true", "true", "true", "true", "true", "true" }) - public void checked_insertBefore_fromHtml() throws Exception { - final String html = "<html>\n" + @Alerts(DEFAULT = { "true", "true", "true" }) + public void checked_insertBefore_fromHtml_docFragment_cloneNode() throws Exception { + performTest(true, false, true, true, true); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "false", "false", "false" }) + public void notchecked_insertBefore_fromHtml_docFragment_cloneNode() throws Exception { + performTest(false, false, true, true, true); + } + + private void performTest(final boolean checked, + final boolean appendChild, + final boolean fromHtml, + final boolean useFragment, + boolean cloneNode) throws Exception { + 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" + + " function test() {\n"; + if (fromHtml) { + html = html + + " var builder = document.createElement('div');\n" + + " builder.innerHTML = '<input type=\"checkbox\""; + if (checked) { + html = html + " checked"; + } + html = html + ">';\n" + + " var input = builder.firstChild;\n"; + } + else { + html = html + + " var input = document.createElement('input');\n" + + " input.type = 'checkbox';\n"; + if (checked) { + html = html + " input.checked = true;\n"; + } + } + + if (cloneNode && !useFragment) { + html = html + + " input=input.cloneNode(true);\n"; + cloneNode = false; + } + html = html + " 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" + + " var after=document.getElementById('divAfter');\n"; + if (useFragment) { + html = html + + " var appendix=document.createDocumentFragment();\n" + + " appendix.appendChild(input);\n" + + " alert(input.checked);\n"; + } + else { + html = html + + " var appendix=input\n"; + } + if (appendChild) { + if (cloneNode) { + html = html + " parent.appendChild(appendix.cloneNode(true));\n"; + } + else { + html = html + " parent.appendChild(appendix);\n"; + } + } + else { + if (cloneNode) { + html = html + " parent.insertBefore(appendix.cloneNode(true), after);\n"; + } + else { + html = html + " parent.insertBefore(appendix, after);\n"; + } + } + html = html + + " input = parent.getElementsByTagName('input')[0];\n" + + " alert(input.checked);\n"; + if (!useFragment) { + html = html + + " 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"; + } + html = html + " }\n" + " </script>\n" + "</head><body onload='test()'>\n" @@ -337,42 +278,14 @@ } /** - * 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" }, + IE = { "true", "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); + public void checked_appendChild() throws Exception { + performTest(true, true, false, false, false); } /** @@ -382,34 +295,19 @@ @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>"; + public void notchecked_appendChild() throws Exception { + performTest(false, true, false, false, false); + } - 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 { + performTest(true, false, false, false, false); } /** @@ -419,112 +317,59 @@ @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>"; + public void notchecked_insertBefore() throws Exception { + performTest(false, false, false, false, false); + } - loadPageWithAlerts2(html); + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "true", "true", "true", "true", "true", "true" }) + public void checked_appendChild_fromHtml() throws Exception { + performTest(true, true, true, false, false); } /** * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = { "true", "true", "true", "true", "true", "true" }, + @Alerts(DEFAULT = { "false", "false", "false", "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>"; + public void notchecked_appendChild_fromHtml() throws Exception { + performTest(false, true, true, false, false); + } - loadPageWithAlerts2(html); + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "true", "true", "true", "true", "true", "true" }) + public void checked_insertBefore_fromHtml() throws Exception { + performTest(true, false, true, false, false); } /** - * Verifies the behavior of 'checked' property on being attached to a page. * @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_fromHtml() throws Exception { + performTest(false, false, true, false, false); + } + + /** + * @throws Exception if the test fails + */ + @Test @Alerts(DEFAULT = { "true", "true", "true", "true", "true", "true" }, - IE = { "false", "true", "true", "true", "true", "true" }) - 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); + IE = { "false", "false", "false", "false", "false", "false" }, + IE6 = { "true", "false", "false", "false", "true", "true" }) + public void checked_appendChild_cloneNode() throws Exception { + performTest(true, true, false, false, true); } /** @@ -534,35 +379,19 @@ @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>"; + public void notchecked_appendChild_cloneNode() throws Exception { + performTest(false, true, false, false, true); + } - 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_insertBefore_cloneNode() throws Exception { + performTest(true, false, false, false, true); } /** @@ -572,74 +401,50 @@ @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>"; + public void notchecked_insertBefore_cloneNode() throws Exception { + performTest(false, false, false, false, true); + } - loadPageWithAlerts2(html); + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "true", "true", "true", "true", "true", "true" }, + IE = { "false", "true", "true", "true", "true", "true" }) + public void checked_appendChild_fromHtml_cloneNode() throws Exception { + performTest(true, true, true, false, true); } /** * @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_fromHtml_cloneNode() throws Exception { + performTest(false, true, true, false, true); + } + + /** + * @throws Exception if the test fails + */ + @Test @Alerts(DEFAULT = { "true", "true", "true", "true", "true", "true" }, IE = { "false", "true", "true", "true", "true", "true" }) 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>"; + performTest(true, false, true, false, true); + } - 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_fromHtml_cloneNode() throws Exception { + performTest(false, false, true, false, true); } /** |
From: <rb...@us...> - 2013-04-28 09:08:37
|
Revision: 8245 http://sourceforge.net/p/htmlunit/code/8245 Author: rbri Date: 2013-04-28 09:08:31 +0000 (Sun, 28 Apr 2013) Log Message: ----------- more generic test, more tests and again some fixes for IE8 Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput2Test.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-26 18:48:58 UTC (rev 8244) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java 2013-04-28 09:08:31 UTC (rev 8245) @@ -249,6 +249,8 @@ */ @Override protected void onAddedToPage() { + super.onAddedToPage(); + if (hasFeature(HTMLINPUT_SET_CHECKED_TO_DEFAULT_WHEN_ADDED)) { reset(); } @@ -256,16 +258,47 @@ if (wasCreatedByJavascript()) { removeAttribute("checked"); } - else if (forceChecked_) { - setAttribute("checked", "checked"); + else { + if (forceChecked_) { + setAttribute("checked", "checked"); + } + else { + return; + } } } + setChecked(isChecked()); } /** * {@inheritDoc} */ @Override + protected void onAddedToDocumentFragment() { + super.onAddedToPage(); + + if (hasFeature(HTMLINPUT_SET_CHECKED_TO_DEFAULT_WHEN_ADDED)) { + reset(); + } + if (hasFeature(HTMLINPUT_SET_CHECKED_TO_FALSE_WHEN_ADDED)) { + if (wasCreatedByJavascript()) { + removeAttribute("checked"); + } + else { + if (forceChecked_) { + setAttribute("checked", "checked"); + forceChecked_ = false; + } + return; + } + } + setChecked(isChecked()); + } + + /** + * {@inheritDoc} + */ + @Override public DomNode cloneNode(final boolean deep) { final HtmlRadioButtonInput clone = (HtmlRadioButtonInput) super.cloneNode(deep); if (hasFeature(HTMLINPUT_SET_CHECKED_TO_FALSE_WHEN_ADDED)) { 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-26 18:48:58 UTC (rev 8244) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput2Test.java 2013-04-28 09:08:31 UTC (rev 8245) @@ -188,95 +188,6 @@ performTest(false, false, true, true, true); } - private void performTest(final boolean checked, - final boolean appendChild, - final boolean fromHtml, - final boolean useFragment, - boolean cloneNode) throws Exception { - String html = "<html>\n" - + "<head>\n" - + " <script>\n" - + " function test() {\n"; - if (fromHtml) { - html = html - + " var builder = document.createElement('div');\n" - + " builder.innerHTML = '<input type=\"checkbox\""; - if (checked) { - html = html + " checked"; - } - html = html + ">';\n" - + " var input = builder.firstChild;\n"; - } - else { - html = html - + " var input = document.createElement('input');\n" - + " input.type = 'checkbox';\n"; - if (checked) { - html = html + " input.checked = true;\n"; - } - } - - if (cloneNode && !useFragment) { - html = html - + " input=input.cloneNode(true);\n"; - cloneNode = false; - } - html = html - + " alert(input.checked);\n" - - + " var parent=document.getElementById('myDiv');\n" - + " var after=document.getElementById('divAfter');\n"; - if (useFragment) { - html = html - + " var appendix=document.createDocumentFragment();\n" - + " appendix.appendChild(input);\n" - + " alert(input.checked);\n"; - } - else { - html = html - + " var appendix=input\n"; - } - if (appendChild) { - if (cloneNode) { - html = html + " parent.appendChild(appendix.cloneNode(true));\n"; - } - else { - html = html + " parent.appendChild(appendix);\n"; - } - } - else { - if (cloneNode) { - html = html + " parent.insertBefore(appendix.cloneNode(true), after);\n"; - } - else { - html = html + " parent.insertBefore(appendix, after);\n"; - } - } - html = html - + " input = parent.getElementsByTagName('input')[0];\n" - + " alert(input.checked);\n"; - if (!useFragment) { - html = html - + " 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"; - } - html = html - + " }\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 */ @@ -447,6 +358,95 @@ performTest(false, false, true, false, true); } + private void performTest(final boolean checked, + final boolean appendChild, + final boolean fromHtml, + final boolean useFragment, + boolean cloneNode) throws Exception { + String html = "<html>\n" + + "<head>\n" + + " <script>\n" + + " function test() {\n"; + if (fromHtml) { + html = html + + " var builder = document.createElement('div');\n" + + " builder.innerHTML = '<input type=\"checkbox\""; + if (checked) { + html = html + " checked"; + } + html = html + ">';\n" + + " var input = builder.firstChild;\n"; + } + else { + html = html + + " var input = document.createElement('input');\n" + + " input.type = 'checkbox';\n"; + if (checked) { + html = html + " input.checked = true;\n"; + } + } + + if (cloneNode && !useFragment) { + html = html + + " input=input.cloneNode(true);\n"; + cloneNode = false; + } + html = html + + " alert(input.checked);\n" + + + " var parent=document.getElementById('myDiv');\n" + + " var after=document.getElementById('divAfter');\n"; + if (useFragment) { + html = html + + " var appendix=document.createDocumentFragment();\n" + + " appendix.appendChild(input);\n" + + " alert(input.checked);\n"; + } + else { + html = html + + " var appendix=input;\n"; + } + if (appendChild) { + if (cloneNode) { + html = html + " parent.appendChild(appendix.cloneNode(true));\n"; + } + else { + html = html + " parent.appendChild(appendix);\n"; + } + } + else { + if (cloneNode) { + html = html + " parent.insertBefore(appendix.cloneNode(true), after);\n"; + } + else { + html = html + " parent.insertBefore(appendix, after);\n"; + } + } + html = html + + " input = parent.getElementsByTagName('input')[0];\n" + + " alert(input.checked);\n"; + if (!useFragment) { + html = html + + " 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"; + } + html = html + + " }\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 */ 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-26 18:48:58 UTC (rev 8244) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput2Test.java 2013-04-28 09:08:31 UTC (rev 8245) @@ -42,598 +42,437 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = { "true", "true", "true", "true", "true", "true" }, - IE = { "true", "false", "false", "false", "false", "false" }, + @Alerts(DEFAULT = { "true", "true-true", "true-false", "true-false", "true-false", "true-false", "true-false" }, + IE = { "true", "false-true", "false-true", "false-true", "false-true", "false-true", "false-true" }, IE6 = { "true", "false", "false", "false", "true", "true" }) - public void checked_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" - + " 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); + public void checked_appendChild_docFragment() throws Exception { + performTest(true, true, false, true, false); } /** * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = { "false", "false", "false", "true", "true", "true" }, - IE = { "false", "false", "false", "false", "false", "false" }, + @Alerts(DEFAULT = { "false", "false-true", "false-true", "false-true", "true-true", "true-false", "true-false" }, + IE = { "false", "false-true", "false-true", "false-true", "false-true", "false-true", "false-true" }, 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 = 'radio';\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>"; + public void notchecked_appendChild_docFragment() throws Exception { + performTest(false, true, false, true, false); + } - loadPageWithAlerts2(html); + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "true", "true-true", "true-false", "true-false", "true-false", "true-false", "true-false" }, + IE = { "true", "false-true", "false-true", "false-true", "false-true", "false-true", "false-true" }, + IE6 = { "true", "false", "false", "false", "true", "true" }) + public void checked_insertBefore_docFragment() throws Exception { + performTest(true, false, false, true, false); } /** * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = { "false", "false", "false", "true", "true", "true" }, - IE = { "false", "false", "false", "false", "false", "false" }, + @Alerts(DEFAULT = { "false", "false-true", "false-true", "false-true", "true-true", "true-false", "true-false" }, + IE = { "false", "false-true", "false-true", "false-true", "false-true", "false-true", "false-true" }, 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 = '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" - + " <form><div id='myDiv'><div id='divAfter'></div></div></form>\n" - + "</body></html>"; + public void notchecked_insertBefore_docFragment() throws Exception { + performTest(false, false, false, true, false); + } - 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-false", "true-false", "true-false", "true-false", "true-false" }, + IE = { "true", "true-true", "true-true", "true-true", "true-true", "true-true", "true-true" }) + public void checked_appendChild_fromHtml_docFragment() throws Exception { + performTest(true, true, true, true, false); } /** * @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 = '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" - + " <form><div id='myDiv'><div id='divAfter'></div></div></form>\n" - + "</body></html>"; + @Alerts(DEFAULT = { "false", "false-true", "false-true", "false-true", "true-true", "true-false", "true-false" }, + IE = { "false", "false-true", "false-true", "false-true", "false-true", "false-true", "false-true" }, + IE6 = { "false", "false", "false", "false", "true", "true" }) + public void notchecked_appendChild_fromHtml_docFragment() throws Exception { + performTest(false, true, true, true, false); + } - loadPageWithAlerts2(html); + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "true", "true-true", "true-false", "true-false", "true-false", "true-false", "true-false" }, + IE = { "true", "true-true", "true-true", "true-true", "true-true", "true-true", "true-true" }) + public void checked_insertBefore_fromHtml_docFragment() throws Exception { + performTest(true, false, true, true, false); } /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "false", "false-true", "false-true", "false-true", "true-true", "true-false", "true-false" }, + IE = { "false", "false-true", "false-true", "false-true", "false-true", "false-true", "false-true" }, + IE6 = { "false", "false", "false", "false", "true", "true" }) + public void notchecked_insertBefore_fromHtml_docFragment() throws Exception { + performTest(false, false, true, true, false); + } + + /** * 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" }) - public void checked_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" - + " 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>"; + @Alerts(DEFAULT = { "true", "true-true", "true-false", "true-false", "true-false", "true-false", "true-false" }, + IE = { "true", "false-true", "false-true", "false-true", "false-true", "false-true", "false-true" }, + IE6 = { "true", "false", "false", "false", "true", "true" }) + public void checked_appendChild_docFragment_cloneNode() throws Exception { + performTest(true, true, false, true, true); + } - loadPageWithAlerts2(html); + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "false", "false-true", "false-true", "false-true", "true-true", "true-false", "true-false" }, + IE = { "false", "false-true", "false-true", "false-true", "false-true", "false-true", "false-true" }, + IE6 = { "false", "false", "false", "false", "true", "true" }) + public void notchecked_appendChild_docFragment_cloneNode() throws Exception { + performTest(false, true, false, true, true); } /** * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = { "false", "false", "false", "true", "true", "true" }, - IE = { "false", "false", "false", "false", "false", "false" }, + @Alerts(DEFAULT = { "true", "true-true", "true-false", "true-false", "true-false", "true-false", "true-false" }, + IE = { "true", "false-true", "false-true", "false-true", "false-true", "false-true", "false-true" }, IE6 = { "false", "false", "false", "false", "true", "true" }) - public void notchecked_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" - + " 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); + public void checked_insertBefore_docFragment_cloneNode() throws Exception { + performTest(true, false, false, true, true); } /** * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = { "false", "false", "false", "true", "true", "true" }, - IE = { "false", "false", "false", "false", "false", "false" }, + @Alerts(DEFAULT = { "false", "false-true", "false-true", "false-true", "true-true", "true-false", "true-false" }, + IE = { "false", "false-true", "false-true", "false-true", "false-true", "false-true", "false-true" }, IE6 = { "false", "false", "false", "false", "true", "true" }) - public void notchecked_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" - + " 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>"; + public void notchecked_insertBefore_docFragment_cloneNode() throws Exception { + performTest(false, false, false, true, true); + } - 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-false", "true-false", "true-false", "true-false", "true-false" }, + IE = { "true", "true-true", "true-true", "true-true", "true-true", "true-true", "true-true" }) + public void checked_appendChild_fromHtml_docFragment_cloneNode() throws Exception { + performTest(true, true, true, true, true); } /** * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = { "true", "true", "true", "true", "true", "true" }) - public void checked_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" - + " 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>"; + @Alerts(DEFAULT = { "false", "false-true", "false-true", "false-true", "true-true", "true-false", "true-false" }, + IE = { "false", "false-true", "false-true", "false-true", "false-true", "false-true", "false-true" }, + IE6 = { "false", "false", "false", "false", "true", "true" }) + public void notchecked_appendChild_fromHtml_docFragment_cloneNode() throws Exception { + performTest(false, true, true, true, true); + } - loadPageWithAlerts2(html); + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "true", "true-true", "true-false", "true-false", "true-false", "true-false", "true-false" }, + IE = { "true", "true-true", "true-true", "true-true", "true-true", "true-true", "true-true" }) + public void checked_insertBefore_fromHtml_docFragment_cloneNode() throws Exception { + performTest(true, false, true, true, true); } /** - * 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" }, + @Alerts(DEFAULT = { "false", "false-true", "false-true", "false-true", "true-true", "true-false", "true-false" }, + IE = { "false", "false-true", "false-true", "false-true", "false-true", "false-true", "false-true" }, + IE6 = { "false", "false", "false", "false", "true", "true" }) + public void notchecked_insertBefore_fromHtml_docFragment_cloneNode() throws Exception { + performTest(false, false, true, true, true); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "true", "true-false", "true-false", "true-false", "true-false", "true-false" }, + IE = { "true", "false-true", "false-true", "false-true", "false-true", "false-true" }, 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); + public void checked_appendChild() throws Exception { + performTest(true, true, false, false, false); } /** * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = { "false", "false", "false", "true", "true", "true" }, - IE = { "false", "false", "false", "false", "false", "false" }, + @Alerts(DEFAULT = { "false", "false-true", "false-true", "true-true", "true-false", "true-false" }, + IE = { "false", "false-true", "false-true", "false-true", "false-true", "false-true" }, 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>"; + public void notchecked_appendChild() throws Exception { + performTest(false, true, false, false, false); + } - loadPageWithAlerts2(html); + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "true", "true-false", "true-false", "true-false", "true-false", "true-false" }, + IE = { "true", "false-true", "false-true", "false-true", "false-true", "false-true" }, + IE6 = { "true", "false", "false", "false", "true", "true" }) + public void checked_insertBefore() throws Exception { + performTest(true, false, false, false, false); } /** * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = { "false", "false", "false", "true", "true", "true" }, - IE = { "false", "false", "false", "false", "false", "false" }, + @Alerts(DEFAULT = { "false", "false-true", "false-true", "true-true", "true-false", "true-false" }, + IE = { "false", "false-true", "false-true", "false-true", "false-true", "false-true" }, 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>"; + public void notchecked_insertBefore() throws Exception { + performTest(false, false, false, false, false); + } - 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-false", "true-false", "true-false", "true-false", "true-false" }, + IE = { "true", "true-true", "true-true", "true-true", "true-true", "true-true" }) + public void checked_appendChild_fromHtml() throws Exception { + performTest(true, true, true, false, false); } /** * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = { "true", "true", "true", "true", "true", "true" }, - IE = { "false", "false", "false", "false", "false", "false" }, + @Alerts(DEFAULT = { "false", "false-true", "false-true", "true-true", "true-false", "true-false" }, + IE = { "false", "false-true", "false-true", "false-true", "false-true", "false-true" }, 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>"; + public void notchecked_appendChild_fromHtml() throws Exception { + performTest(false, true, true, false, false); + } - loadPageWithAlerts2(html); + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "true", "true-false", "true-false", "true-false", "true-false", "true-false" }, + IE = { "true", "true-true", "true-true", "true-true", "true-true", "true-true" }) + public void checked_insertBefore_fromHtml() throws Exception { + performTest(true, false, true, false, false); } /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "false", "false-true", "false-true", "true-true", "true-false", "true-false" }, + IE = { "false", "false-true", "false-true", "false-true", "false-true", "false-true" }, + IE6 = { "false", "false", "false", "false", "true", "true" }) + public void notchecked_insertBefore_fromHtml() throws Exception { + performTest(false, false, true, false, false); + } + + /** * 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" }) - 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>"; + @Alerts(DEFAULT = { "true", "true-false", "true-false", "true-false", "true-false", "true-false" }, + IE = { "false", "false-true", "false-true", "false-true", "false-true", "false-true" }, + IE6 = { "true", "false", "false", "false", "true", "true" }) + public void checked_appendChild_cloneNode() throws Exception { + performTest(true, true, false, false, true); + } - loadPageWithAlerts2(html); + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "false", "false-true", "false-true", "true-true", "true-false", "true-false" }, + IE = { "false", "false-true", "false-true", "false-true", "false-true", "false-true" }, + IE6 = { "false", "false", "false", "false", "true", "true" }) + public void notchecked_appendChild_cloneNode() throws Exception { + performTest(false, true, false, false, true); } /** * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = { "false", "false", "false", "true", "true", "true" }, - IE = { "false", "false", "false", "false", "false", "false" }, + @Alerts(DEFAULT = { "true", "true-false", "true-false", "true-false", "true-false", "true-false" }, + IE = { "false", "false-true", "false-true", "false-true", "false-true", "false-true" }, 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>"; + public void checked_insertBefore_cloneNode() throws Exception { + performTest(true, false, false, false, true); + } - loadPageWithAlerts2(html); + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "false", "false-true", "false-true", "true-true", "true-false", "true-false" }, + IE = { "false", "false-true", "false-true", "false-true", "false-true", "false-true" }, + IE6 = { "false", "false", "false", "false", "true", "true" }) + public void notchecked_insertBefore_cloneNode() throws Exception { + performTest(false, false, false, false, true); } /** + * Verifies the behavior of 'checked' property on being attached to a page. * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = { "false", "false", "false", "true", "true", "true" }, - IE = { "false", "false", "false", "false", "false", "false" }, + @Alerts(DEFAULT = { "true", "true-false", "true-false", "true-false", "true-false", "true-false" }, + IE = { "false", "true-false", "true-false", "true-false", "true-false", "true-false" }) + public void checked_appendChild_fromHtml_cloneNode() throws Exception { + performTest(true, true, true, false, true); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "false", "false-true", "false-true", "true-true", "true-false", "true-false" }, + IE = { "false", "false-true", "false-true", "false-true", "false-true", "false-true" }, 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>"; + public void notchecked_appendChild_fromHtml_cloneNode() throws Exception { + performTest(false, true, true, false, true); + } - loadPageWithAlerts2(html); + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "true", "true-false", "true-false", "true-false", "true-false", "true-false" }, + IE = { "false", "true-false", "true-false", "true-false", "true-false", "true-false" }) + public void checked_insertBefore_fromHtml_cloneNode() throws Exception { + performTest(true, false, true, false, true); } /** * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = { "true", "true", "true", "true", "true", "true" }, - IE = { "false", "true", "true", "true", "true", "true" }) - public void checked_cloneNode_insertBefore_fromHtml() throws Exception { - final String html = "<html>\n" + @Alerts(DEFAULT = { "false", "false-true", "false-true", "true-true", "true-false", "true-false" }, + IE = { "false", "false-true", "false-true", "false-true", "false-true", "false-true" }, + IE6 = { "false", "false", "false", "false", "true", "true" }) + public void notchecked_insertBefore_fromHtml_cloneNode() throws Exception { + performTest(false, false, true, false, true); + } + + private void performTest(final boolean checked, + final boolean appendChild, + final boolean fromHtml, + final boolean useFragment, + boolean cloneNode) throws Exception { + 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" + + " var existing = document.getElementById('rad1');\n"; + if (fromHtml) { + html = html + + " var builder = document.createElement('div');\n" + + " builder.innerHTML = '<input type=\"radio\" id=\"rad2\" name=\"radar\""; + if (checked) { + html = html + " checked"; + } + html = html + ">';\n" + + " var input = builder.firstChild;\n"; + } + else { + html = html + + " var input = document.createElement('input');\n" + + " input.type = 'radio';\n" + + " input.id = 'rad2';\n" + + " input.name = 'radar';\n"; + if (checked) { + html = html + " input.checked = true;\n"; + } + } + + if (cloneNode && !useFragment) { + html = html + + " input=input.cloneNode(true);\n"; + cloneNode = false; + } + html = html + " 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" + + " var after=document.getElementById('divAfter');\n"; + if (useFragment) { + html = html + + " var appendix=document.createDocumentFragment();\n" + + " appendix.appendChild(input);\n" + + " alert(input.checked + '-' + existing.checked);\n"; + } + else { + html = html + + " var appendix=input;\n"; + } + if (appendChild) { + if (cloneNode) { + html = html + " parent.appendChild(appendix.cloneNode(true));\n"; + } + else { + html = html + " parent.appendChild(appendix);\n"; + } + } + else { + if (cloneNode) { + html = html + " parent.insertBefore(appendix.cloneNode(true), after);\n"; + } + else { + html = html + " parent.insertBefore(appendix, after);\n"; + } + } + html = html + + " input = document.getElementById('rad2');\n" + + " alert(input.checked + '-' + existing.checked);\n" + " parent.removeChild(input);\n" - + " alert(input.checked);\n" + + " alert(input.checked + '-' + existing.checked);\n" + "\n" + " input.defaultChecked = true;\n" - + " alert(input.checked);\n" - + " parent.insertBefore(input, after);\n" - + " alert(input.checked);\n" + + " alert(input.checked + '-' + existing.checked);\n" + + " parent.appendChild(input);\n" + + " alert(input.checked + '-' + existing.checked);\n" + " parent.removeChild(input);\n" - + " alert(input.checked);\n" + + " alert(input.checked + '-' + existing.checked);\n" + " }\n" + " </script>\n" + "</head><body onload='test()'>\n" - + " <form><div id='myDiv'><div id='divAfter'></div></div></form>\n" + + " <form><div id='myDiv'>\n" + + " <input type='radio' id='rad1' name='radar' checked>\n" + + " <div id='divAfter'></div></div></form>\n" + "</body></html>"; loadPageWithAlerts2(html); |
From: <rb...@us...> - 2013-04-28 16:33:31
|
Revision: 8246 http://sourceforge.net/p/htmlunit/code/8246 Author: rbri Date: 2013-04-28 16:33:25 +0000 (Sun, 28 Apr 2013) Log Message: ----------- IE8 is different when doctype is defined 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 trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput2Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-04-28 09:08:31 UTC (rev 8245) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-04-28 16:33:25 UTC (rev 8246) @@ -607,8 +607,8 @@ 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, + @BrowserFeature(@WebBrowser(value = IE)) + HTMLINPUT_SET_CHECKED_TO_FALSE_WHEN_CLONE, /** * Set this property if the browser does NOT 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-28 09:08:31 UTC (rev 8245) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput.java 2013-04-28 16:33:25 UTC (rev 8246) @@ -16,8 +16,7 @@ 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 static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLINPUT_SET_CHECKED_TO_FALSE_WHEN_CLONE; import java.io.IOException; import java.util.Map; @@ -190,17 +189,10 @@ protected void onAddedToPage() { super.onAddedToPage(); - if (hasFeature(HTMLINPUT_SET_CHECKED_TO_DEFAULT_WHEN_ADDED)) { + if (forceChecked_) { reset(); + forceChecked_ = wasCreatedByJavascript(); } - if (hasFeature(HTMLINPUT_SET_CHECKED_TO_FALSE_WHEN_ADDED)) { - if (wasCreatedByJavascript()) { - removeAttribute("checked"); - } - else if (forceChecked_) { - setAttribute("checked", "checked"); - } - } } /** @@ -210,17 +202,10 @@ protected void onAddedToDocumentFragment() { super.onAddedToDocumentFragment(); - if (hasFeature(HTMLINPUT_SET_CHECKED_TO_DEFAULT_WHEN_ADDED)) { + if (forceChecked_) { reset(); + forceChecked_ = false; } - if (hasFeature(HTMLINPUT_SET_CHECKED_TO_FALSE_WHEN_ADDED)) { - if (wasCreatedByJavascript()) { - removeAttribute("checked"); - } - else if (forceChecked_) { - setAttribute("checked", "checked"); - } - } } /** @@ -229,13 +214,10 @@ @Override public DomNode cloneNode(final boolean deep) { final HtmlCheckBoxInput clone = (HtmlCheckBoxInput) super.cloneNode(deep); - if (hasFeature(HTMLINPUT_SET_CHECKED_TO_FALSE_WHEN_ADDED)) { + if (wasCreatedByJavascript() && hasFeature(HTMLINPUT_SET_CHECKED_TO_FALSE_WHEN_CLONE)) { clone.removeAttribute("checked"); clone.forceChecked_ = isDefaultChecked(); } - if (wasCreatedByJavascript()) { - clone.markAsCreatedByJavascript(); - } return clone; } 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-28 09:08:31 UTC (rev 8245) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java 2013-04-28 16:33:25 UTC (rev 8246) @@ -16,8 +16,7 @@ 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 static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLINPUT_SET_CHECKED_TO_FALSE_WHEN_CLONE; import java.io.IOException; import java.util.List; @@ -223,8 +222,12 @@ public void setDefaultChecked(final boolean defaultChecked) { defaultCheckedState_ = defaultChecked; if (hasFeature(HTMLINPUT_DEFAULT_IS_CHECKED)) { - setChecked(defaultChecked); + setChecked(isDefaultChecked()); } + if (hasFeature(HTMLINPUT_SET_CHECKED_TO_FALSE_WHEN_CLONE)) { + reset(); + forceChecked_ = true; + } } /** @@ -251,22 +254,9 @@ protected void onAddedToPage() { super.onAddedToPage(); - if (hasFeature(HTMLINPUT_SET_CHECKED_TO_DEFAULT_WHEN_ADDED)) { - reset(); + if (forceChecked_) { + return; } - if (hasFeature(HTMLINPUT_SET_CHECKED_TO_FALSE_WHEN_ADDED)) { - if (wasCreatedByJavascript()) { - removeAttribute("checked"); - } - else { - if (forceChecked_) { - setAttribute("checked", "checked"); - } - else { - return; - } - } - } setChecked(isChecked()); } @@ -276,23 +266,7 @@ @Override protected void onAddedToDocumentFragment() { super.onAddedToPage(); - - if (hasFeature(HTMLINPUT_SET_CHECKED_TO_DEFAULT_WHEN_ADDED)) { - reset(); - } - if (hasFeature(HTMLINPUT_SET_CHECKED_TO_FALSE_WHEN_ADDED)) { - if (wasCreatedByJavascript()) { - removeAttribute("checked"); - } - else { - if (forceChecked_) { - setAttribute("checked", "checked"); - forceChecked_ = false; - } - return; - } - } - setChecked(isChecked()); + forceChecked_ = true; } /** @@ -301,13 +275,11 @@ @Override public DomNode cloneNode(final boolean deep) { final HtmlRadioButtonInput clone = (HtmlRadioButtonInput) super.cloneNode(deep); - if (hasFeature(HTMLINPUT_SET_CHECKED_TO_FALSE_WHEN_ADDED)) { + clone.forceChecked_ = false; + if (wasCreatedByJavascript() && hasFeature(HTMLINPUT_SET_CHECKED_TO_FALSE_WHEN_CLONE)) { clone.removeAttribute("checked"); - clone.forceChecked_ = isDefaultChecked(); + clone.forceChecked_ = true; } - if (wasCreatedByJavascript()) { - clone.markAsCreatedByJavascript(); - } return clone; } 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-28 09:08:31 UTC (rev 8245) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput2Test.java 2013-04-28 16:33:25 UTC (rev 8246) @@ -18,6 +18,7 @@ import java.util.Arrays; +import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; import org.openqa.selenium.By; @@ -40,12 +41,21 @@ @RunWith(BrowserRunner.class) public class HtmlCheckBoxInput2Test extends WebDriverTestCase { + @After + public void after() { + try { + shutDownAll(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + /** * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = { "true", "true", "true" }, - IE = { "true", "false", "false" }) + @Alerts(DEFAULT = { "true", "true", "true" }) public void checked_appendChild_docFragment() throws Exception { performTest(true, true, false, true, false); } @@ -63,8 +73,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = { "true", "true", "true" }, - IE = { "true", "false", "false" }) + @Alerts(DEFAULT = { "true", "true", "true" }) public void checked_insertBefore_docFragment() throws Exception { performTest(true, false, false, true, false); } @@ -119,7 +128,7 @@ */ @Test @Alerts(DEFAULT = { "true", "true", "true" }, - IE = { "true", "false", "false" }) + IE = { "true", "true", "false" }) public void checked_appendChild_docFragment_cloneNode() throws Exception { performTest(true, true, false, true, true); } @@ -138,7 +147,7 @@ */ @Test @Alerts(DEFAULT = { "true", "true", "true" }, - IE = { "true", "false", "false" }) + IE = { "true", "true", "false" }) public void checked_insertBefore_docFragment_cloneNode() throws Exception { performTest(true, false, false, true, true); } @@ -192,9 +201,7 @@ * @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" }) + @Alerts(DEFAULT = { "true", "true", "true", "true", "true", "true" }) public void checked_appendChild() throws Exception { performTest(true, true, false, false, false); } @@ -203,9 +210,7 @@ * @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" }) + @Alerts(DEFAULT = { "false", "false", "false", "true", "true", "true" }) public void notchecked_appendChild() throws Exception { performTest(false, true, false, false, false); } @@ -214,9 +219,7 @@ * @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" }) + @Alerts(DEFAULT = { "true", "true", "true", "true", "true", "true" }) public void checked_insertBefore() throws Exception { performTest(true, false, false, false, false); } @@ -225,9 +228,7 @@ * @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" }) + @Alerts(DEFAULT = { "false", "false", "false", "true", "true", "true" }) public void notchecked_insertBefore() throws Exception { performTest(false, false, false, false, false); } @@ -245,9 +246,7 @@ * @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" }) + @Alerts(DEFAULT = { "false", "false", "false", "true", "true", "true" }) public void notchecked_appendChild_fromHtml() throws Exception { performTest(false, true, true, false, false); } @@ -265,9 +264,7 @@ * @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" }) + @Alerts(DEFAULT = { "false", "false", "false", "true", "true", "true" }) public void notchecked_insertBefore_fromHtml() throws Exception { performTest(false, false, true, false, false); } @@ -277,8 +274,7 @@ */ @Test @Alerts(DEFAULT = { "true", "true", "true", "true", "true", "true" }, - IE = { "false", "false", "false", "false", "false", "false" }, - IE6 = { "true", "false", "false", "false", "true", "true" }) + IE = { "false", "false", "false", "true", "true", "true" }) public void checked_appendChild_cloneNode() throws Exception { performTest(true, true, false, false, true); } @@ -287,9 +283,7 @@ * @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" }) + @Alerts(DEFAULT = { "false", "false", "false", "true", "true", "true" }) public void notchecked_appendChild_cloneNode() throws Exception { performTest(false, true, false, false, true); } @@ -299,8 +293,7 @@ */ @Test @Alerts(DEFAULT = { "true", "true", "true", "true", "true", "true" }, - IE = { "false", "false", "false", "false", "false", "false" }, - IE6 = { "false", "false", "false", "false", "true", "true" }) + IE = { "false", "false", "false", "true", "true", "true" }) public void checked_insertBefore_cloneNode() throws Exception { performTest(true, false, false, false, true); } @@ -309,9 +302,7 @@ * @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" }) + @Alerts(DEFAULT = { "false", "false", "false", "true", "true", "true" }) public void notchecked_insertBefore_cloneNode() throws Exception { performTest(false, false, false, false, true); } @@ -320,8 +311,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = { "true", "true", "true", "true", "true", "true" }, - IE = { "false", "true", "true", "true", "true", "true" }) + @Alerts(DEFAULT = { "true", "true", "true", "true", "true", "true" }) public void checked_appendChild_fromHtml_cloneNode() throws Exception { performTest(true, true, true, false, true); } @@ -330,9 +320,7 @@ * @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" }) + @Alerts(DEFAULT = { "false", "false", "false", "true", "true", "true" }) public void notchecked_appendChild_fromHtml_cloneNode() throws Exception { performTest(false, true, true, false, true); } @@ -341,9 +329,8 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = { "true", "true", "true", "true", "true", "true" }, - IE = { "false", "true", "true", "true", "true", "true" }) - public void checked_cloneNode_insertBefore_fromHtml() throws Exception { + @Alerts(DEFAULT = { "true", "true", "true", "true", "true", "true" }) + public void checked_insertBefore_fromHtml_cloneNode() throws Exception { performTest(true, false, true, false, true); } @@ -351,9 +338,7 @@ * @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" }) + @Alerts(DEFAULT = { "false", "false", "false", "true", "true", "true" }) public void notchecked_insertBefore_fromHtml_cloneNode() throws Exception { performTest(false, false, true, false, true); } @@ -363,7 +348,7 @@ final boolean fromHtml, final boolean useFragment, boolean cloneNode) throws Exception { - String html = "<html>\n" + String html = "<!DOCTYPE HTML>\n<html>\n" + "<head>\n" + " <script>\n" + " function test() {\n"; 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-28 09:08:31 UTC (rev 8245) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput2Test.java 2013-04-28 16:33:25 UTC (rev 8246) @@ -16,6 +16,7 @@ import java.util.Arrays; +import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; import org.openqa.selenium.By; @@ -38,13 +39,22 @@ @RunWith(BrowserRunner.class) public class HtmlRadioButtonInput2Test extends WebDriverTestCase { + @After + public void after() { + try { + shutDownAll(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + /** * @throws Exception if the test fails */ @Test @Alerts(DEFAULT = { "true", "true-true", "true-false", "true-false", "true-false", "true-false", "true-false" }, - IE = { "true", "false-true", "false-true", "false-true", "false-true", "false-true", "false-true" }, - IE6 = { "true", "false", "false", "false", "true", "true" }) + IE = { "true", "true-true", "true-true", "true-true", "true-true", "true-true", "true-true" }) public void checked_appendChild_docFragment() throws Exception { performTest(true, true, false, true, false); } @@ -54,8 +64,7 @@ */ @Test @Alerts(DEFAULT = { "false", "false-true", "false-true", "false-true", "true-true", "true-false", "true-false" }, - IE = { "false", "false-true", "false-true", "false-true", "false-true", "false-true", "false-true" }, - IE6 = { "false", "false", "false", "false", "true", "true" }) + IE = { "false", "false-true", "false-true", "false-true", "true-true", "true-true", "true-true" }) public void notchecked_appendChild_docFragment() throws Exception { performTest(false, true, false, true, false); } @@ -65,8 +74,7 @@ */ @Test @Alerts(DEFAULT = { "true", "true-true", "true-false", "true-false", "true-false", "true-false", "true-false" }, - IE = { "true", "false-true", "false-true", "false-true", "false-true", "false-true", "false-true" }, - IE6 = { "true", "false", "false", "false", "true", "true" }) + IE = { "true", "true-true", "true-true", "true-true", "true-true", "true-true", "true-true" }) public void checked_insertBefore_docFragment() throws Exception { performTest(true, false, false, true, false); } @@ -76,8 +84,7 @@ */ @Test @Alerts(DEFAULT = { "false", "false-true", "false-true", "false-true", "true-true", "true-false", "true-false" }, - IE = { "false", "false-true", "false-true", "false-true", "false-true", "false-true", "false-true" }, - IE6 = { "false", "false", "false", "false", "true", "true" }) + IE = { "false", "false-true", "false-true", "false-true", "true-true", "true-true", "true-true" }) public void notchecked_insertBefore_docFragment() throws Exception { performTest(false, false, false, true, false); } @@ -98,8 +105,7 @@ */ @Test @Alerts(DEFAULT = { "false", "false-true", "false-true", "false-true", "true-true", "true-false", "true-false" }, - IE = { "false", "false-true", "false-true", "false-true", "false-true", "false-true", "false-true" }, - IE6 = { "false", "false", "false", "false", "true", "true" }) + IE = { "false", "false-true", "false-true", "false-true", "true-true", "true-true", "true-true" }) public void notchecked_appendChild_fromHtml_docFragment() throws Exception { performTest(false, true, true, true, false); } @@ -119,8 +125,7 @@ */ @Test @Alerts(DEFAULT = { "false", "false-true", "false-true", "false-true", "true-true", "true-false", "true-false" }, - IE = { "false", "false-true", "false-true", "false-true", "false-true", "false-true", "false-true" }, - IE6 = { "false", "false", "false", "false", "true", "true" }) + IE = { "false", "false-true", "false-true", "false-true", "true-true", "true-true", "true-true" }) public void notchecked_insertBefore_fromHtml_docFragment() throws Exception { performTest(false, false, true, true, false); } @@ -131,8 +136,7 @@ */ @Test @Alerts(DEFAULT = { "true", "true-true", "true-false", "true-false", "true-false", "true-false", "true-false" }, - IE = { "true", "false-true", "false-true", "false-true", "false-true", "false-true", "false-true" }, - IE6 = { "true", "false", "false", "false", "true", "true" }) + IE = { "true", "true-true", "false-true", "false-true", "true-true", "true-true", "true-true" }) public void checked_appendChild_docFragment_cloneNode() throws Exception { performTest(true, true, false, true, true); } @@ -142,8 +146,7 @@ */ @Test @Alerts(DEFAULT = { "false", "false-true", "false-true", "false-true", "true-true", "true-false", "true-false" }, - IE = { "false", "false-true", "false-true", "false-true", "false-true", "false-true", "false-true" }, - IE6 = { "false", "false", "false", "false", "true", "true" }) + IE = { "false", "false-true", "false-true", "false-true", "true-true", "true-true", "true-true" }) public void notchecked_appendChild_docFragment_cloneNode() throws Exception { performTest(false, true, false, true, true); } @@ -153,8 +156,7 @@ */ @Test @Alerts(DEFAULT = { "true", "true-true", "true-false", "true-false", "true-false", "true-false", "true-false" }, - IE = { "true", "false-true", "false-true", "false-true", "false-true", "false-true", "false-true" }, - IE6 = { "false", "false", "false", "false", "true", "true" }) + IE = { "true", "true-true", "false-true", "false-true", "true-true", "true-true", "true-true" }) public void checked_insertBefore_docFragment_cloneNode() throws Exception { performTest(true, false, false, true, true); } @@ -164,8 +166,7 @@ */ @Test @Alerts(DEFAULT = { "false", "false-true", "false-true", "false-true", "true-true", "true-false", "true-false" }, - IE = { "false", "false-true", "false-true", "false-true", "false-true", "false-true", "false-true" }, - IE6 = { "false", "false", "false", "false", "true", "true" }) + IE = { "false", "false-true", "false-true", "false-true", "true-true", "true-true", "true-true" }) public void notchecked_insertBefore_docFragment_cloneNode() throws Exception { performTest(false, false, false, true, true); } @@ -186,8 +187,7 @@ */ @Test @Alerts(DEFAULT = { "false", "false-true", "false-true", "false-true", "true-true", "true-false", "true-false" }, - IE = { "false", "false-true", "false-true", "false-true", "false-true", "false-true", "false-true" }, - IE6 = { "false", "false", "false", "false", "true", "true" }) + IE = { "false", "false-true", "false-true", "false-true", "true-true", "true-true", "true-true" }) public void notchecked_appendChild_fromHtml_docFragment_cloneNode() throws Exception { performTest(false, true, true, true, true); } @@ -207,8 +207,7 @@ */ @Test @Alerts(DEFAULT = { "false", "false-true", "false-true", "false-true", "true-true", "true-false", "true-false" }, - IE = { "false", "false-true", "false-true", "false-true", "false-true", "false-true", "false-true" }, - IE6 = { "false", "false", "false", "false", "true", "true" }) + IE = { "false", "false-true", "false-true", "false-true", "true-true", "true-true", "true-true" }) public void notchecked_insertBefore_fromHtml_docFragment_cloneNode() throws Exception { performTest(false, false, true, true, true); } @@ -217,9 +216,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = { "true", "true-false", "true-false", "true-false", "true-false", "true-false" }, - IE = { "true", "false-true", "false-true", "false-true", "false-true", "false-true" }, - IE6 = { "true", "false", "false", "false", "true", "true" }) + @Alerts(DEFAULT = { "true", "true-false", "true-false", "true-false", "true-false", "true-false" }) public void checked_appendChild() throws Exception { performTest(true, true, false, false, false); } @@ -229,8 +226,7 @@ */ @Test @Alerts(DEFAULT = { "false", "false-true", "false-true", "true-true", "true-false", "true-false" }, - IE = { "false", "false-true", "false-true", "false-true", "false-true", "false-true" }, - IE6 = { "false", "false", "false", "false", "true", "true" }) + IE = { "false", "false-true", "false-true", "true-true", "true-true", "true-true" }) public void notchecked_appendChild() throws Exception { performTest(false, true, false, false, false); } @@ -239,9 +235,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = { "true", "true-false", "true-false", "true-false", "true-false", "true-false" }, - IE = { "true", "false-true", "false-true", "false-true", "false-true", "false-true" }, - IE6 = { "true", "false", "false", "false", "true", "true" }) + @Alerts(DEFAULT = { "true", "true-false", "true-false", "true-false", "true-false", "true-false" }) public void checked_insertBefore() throws Exception { performTest(true, false, false, false, false); } @@ -251,8 +245,7 @@ */ @Test @Alerts(DEFAULT = { "false", "false-true", "false-true", "true-true", "true-false", "true-false" }, - IE = { "false", "false-true", "false-true", "false-true", "false-true", "false-true" }, - IE6 = { "false", "false", "false", "false", "true", "true" }) + IE = { "false", "false-true", "false-true", "true-true", "true-true", "true-true" }) public void notchecked_insertBefore() throws Exception { performTest(false, false, false, false, false); } @@ -273,8 +266,7 @@ */ @Test @Alerts(DEFAULT = { "false", "false-true", "false-true", "true-true", "true-false", "true-false" }, - IE = { "false", "false-true", "false-true", "false-true", "false-true", "false-true" }, - IE6 = { "false", "false", "false", "false", "true", "true" }) + IE = { "false", "false-true", "false-true", "true-true", "true-true", "true-true" }) public void notchecked_appendChild_fromHtml() throws Exception { performTest(false, true, true, false, false); } @@ -294,8 +286,7 @@ */ @Test @Alerts(DEFAULT = { "false", "false-true", "false-true", "true-true", "true-false", "true-false" }, - IE = { "false", "false-true", "false-true", "false-true", "false-true", "false-true" }, - IE6 = { "false", "false", "false", "false", "true", "true" }) + IE = { "false", "false-true", "false-true", "true-true", "true-true", "true-true" }) public void notchecked_insertBefore_fromHtml() throws Exception { performTest(false, false, true, false, false); } @@ -306,8 +297,7 @@ */ @Test @Alerts(DEFAULT = { "true", "true-false", "true-false", "true-false", "true-false", "true-false" }, - IE = { "false", "false-true", "false-true", "false-true", "false-true", "false-true" }, - IE6 = { "true", "false", "false", "false", "true", "true" }) + IE = { "false", "false-true", "false-true", "true-true", "true-true", "true-true" }) public void checked_appendChild_cloneNode() throws Exception { performTest(true, true, false, false, true); } @@ -317,8 +307,7 @@ */ @Test @Alerts(DEFAULT = { "false", "false-true", "false-true", "true-true", "true-false", "true-false" }, - IE = { "false", "false-true", "false-true", "false-true", "false-true", "false-true" }, - IE6 = { "false", "false", "false", "false", "true", "true" }) + IE = { "false", "false-true", "false-true", "true-true", "true-true", "true-true" }) public void notchecked_appendChild_cloneNode() throws Exception { performTest(false, true, false, false, true); } @@ -328,8 +317,7 @@ */ @Test @Alerts(DEFAULT = { "true", "true-false", "true-false", "true-false", "true-false", "true-false" }, - IE = { "false", "false-true", "false-true", "false-true", "false-true", "false-true" }, - IE6 = { "false", "false", "false", "false", "true", "true" }) + IE = { "false", "false-true", "false-true", "true-true", "true-true", "true-true" }) public void checked_insertBefore_cloneNode() throws Exception { performTest(true, false, false, false, true); } @@ -339,8 +327,7 @@ */ @Test @Alerts(DEFAULT = { "false", "false-true", "false-true", "true-true", "true-false", "true-false" }, - IE = { "false", "false-true", "false-true", "false-true", "false-true", "false-true" }, - IE6 = { "false", "false", "false", "false", "true", "true" }) + IE = { "false", "false-true", "false-true", "true-true", "true-true", "true-true" }) public void notchecked_insertBefore_cloneNode() throws Exception { performTest(false, false, false, false, true); } @@ -350,8 +337,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = { "true", "true-false", "true-false", "true-false", "true-false", "true-false" }, - IE = { "false", "true-false", "true-false", "true-false", "true-false", "true-false" }) + @Alerts(DEFAULT = { "true", "true-false", "true-false", "true-false", "true-false", "true-false" }) public void checked_appendChild_fromHtml_cloneNode() throws Exception { performTest(true, true, true, false, true); } @@ -361,8 +347,7 @@ */ @Test @Alerts(DEFAULT = { "false", "false-true", "false-true", "true-true", "true-false", "true-false" }, - IE = { "false", "false-true", "false-true", "false-true", "false-true", "false-true" }, - IE6 = { "false", "false", "false", "false", "true", "true" }) + IE = { "false", "false-true", "false-true", "true-true", "true-true", "true-true" }) public void notchecked_appendChild_fromHtml_cloneNode() throws Exception { performTest(false, true, true, false, true); } @@ -372,7 +357,7 @@ */ @Test @Alerts(DEFAULT = { "true", "true-false", "true-false", "true-false", "true-false", "true-false" }, - IE = { "false", "true-false", "true-false", "true-false", "true-false", "true-false" }) + IE = { "true", "true-false", "true-false", "true-false", "true-false", "true-false" }) public void checked_insertBefore_fromHtml_cloneNode() throws Exception { performTest(true, false, true, false, true); } @@ -382,8 +367,7 @@ */ @Test @Alerts(DEFAULT = { "false", "false-true", "false-true", "true-true", "true-false", "true-false" }, - IE = { "false", "false-true", "false-true", "false-true", "false-true", "false-true" }, - IE6 = { "false", "false", "false", "false", "true", "true" }) + IE = { "false", "false-true", "false-true", "true-true", "true-true", "true-true" }) public void notchecked_insertBefore_fromHtml_cloneNode() throws Exception { performTest(false, false, true, false, true); } @@ -393,7 +377,7 @@ final boolean fromHtml, final boolean useFragment, boolean cloneNode) throws Exception { - String html = "<html>\n" + String html = "<!DOCTYPE HTML>\n<html>\n" + "<head>\n" + " <script>\n" + " function test() {\n" |
From: <rb...@us...> - 2013-04-28 17:55:46
|
Revision: 8247 http://sourceforge.net/p/htmlunit/code/8247 Author: rbri Date: 2013-04-28 17:55:44 +0000 (Sun, 28 Apr 2013) Log Message: ----------- more fixes Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput2Test.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-28 16:33:25 UTC (rev 8246) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java 2013-04-28 17:55:44 UTC (rev 8247) @@ -266,7 +266,9 @@ @Override protected void onAddedToDocumentFragment() { super.onAddedToPage(); - forceChecked_ = true; + if (hasFeature(HTMLINPUT_SET_CHECKED_TO_FALSE_WHEN_CLONE)) { + forceChecked_ = true; + } } /** 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-28 16:33:25 UTC (rev 8246) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput2Test.java 2013-04-28 17:55:44 UTC (rev 8247) @@ -18,7 +18,6 @@ import java.util.Arrays; -import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; import org.openqa.selenium.By; @@ -41,16 +40,6 @@ @RunWith(BrowserRunner.class) public class HtmlCheckBoxInput2Test extends WebDriverTestCase { - @After - public void after() { - try { - shutDownAll(); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - /** * @throws Exception if the test fails */ 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-28 16:33:25 UTC (rev 8246) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput2Test.java 2013-04-28 17:55:44 UTC (rev 8247) @@ -16,7 +16,6 @@ import java.util.Arrays; -import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; import org.openqa.selenium.By; @@ -39,16 +38,6 @@ @RunWith(BrowserRunner.class) public class HtmlRadioButtonInput2Test extends WebDriverTestCase { - @After - public void after() { - try { - shutDownAll(); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - /** * @throws Exception if the test fails */ |
From: <rb...@us...> - 2013-05-01 13:42:10
|
Revision: 8250 http://sourceforge.net/p/htmlunit/code/8250 Author: rbri Date: 2013-05-01 13:42:06 +0000 (Wed, 01 May 2013) Log Message: ----------- Checked state of radio buttons and checkboxes changes when setting defaultChecked in IE8ff. Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput2Test.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-05-01 13:18:24 UTC (rev 8249) +++ trunk/htmlunit/src/changes/changes.xml 2013-05-01 13:42:06 UTC (rev 8250) @@ -8,6 +8,9 @@ <body> <release version="2.13" date="???" description="Bugfixes"> + <action type="fix" dev="rbri"> + Checked state of radio buttons and checkboxes changes when setting defaultChecked in IE8ff. + </action> <action type="update" dev="rbri"> Upgrade commons-codec to 1.8 </action> Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput2Test.java 2013-05-01 13:18:24 UTC (rev 8249) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput2Test.java 2013-05-01 13:42:06 UTC (rev 8250) @@ -425,6 +425,42 @@ * @throws Exception if the test fails */ @Test + @Alerts(DEFAULT = { "true-true", "true-true", "false-false", "false-false", "true-true", "false-false" }) + public void defaultChecked() throws Exception { + final String html = + "<!DOCTYPE HTML>\n<html>\n" + + "<head>\n" + + " <script>\n" + + " function test() {\n" + + " chkbox = document.getElementById('chkboxChecked');\n" + + " alert(chkbox.checked + '-' + chkbox.defaultChecked);\n" + + " chkbox.defaultChecked = true;\n" + + " alert(chkbox.checked + '-' + chkbox.defaultChecked);\n" + + " chkbox.defaultChecked = false;\n" + + " alert(chkbox.checked + '-' + chkbox.defaultChecked);\n" + + + " chkbox = document.getElementById('chkboxNotChecked');\n" + + " alert(chkbox.checked + '-' + chkbox.defaultChecked);\n" + + " chkbox.defaultChecked = true;\n" + + " alert(chkbox.checked + '-' + chkbox.defaultChecked);\n" + + " chkbox.defaultChecked = false;\n" + + " alert(chkbox.checked + '-' + chkbox.defaultChecked);\n" + + " }\n" + + " </script>\n" + + "</head><body onload='test()'>\n" + + " <form>" + + " <input type='checkbox' id='chkboxChecked' checked>\n" + + " <input type='checkbox' id='chkboxNotChecked'>\n" + + " </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" Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput2Test.java 2013-05-01 13:18:24 UTC (rev 8249) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput2Test.java 2013-05-01 13:42:06 UTC (rev 8250) @@ -452,6 +452,76 @@ } /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "true-true", "false-false", "true-true", "false-false", "false-false", "false-false" }) + public void defaultChecked() throws Exception { + final String html = + "<!DOCTYPE HTML>\n<html>\n" + + "<head>\n" + + " <script>\n" + + " function test() {\n" + + " radio = document.getElementById('rad1');\n" + + " radio2 = document.getElementById('rad2');\n" + + " alert(radio.checked + '-' + radio.defaultChecked);\n" + + " alert(radio2.checked + '-' + radio2.defaultChecked);\n" + + + " radio.defaultChecked = true;\n" + + " alert(radio.checked + '-' + radio.defaultChecked);\n" + + " alert(radio2.checked + '-' + radio2.defaultChecked);\n" + + + " radio.defaultChecked = false;\n" + + " alert(radio.checked + '-' + radio.defaultChecked);\n" + + " alert(radio2.checked + '-' + radio2.defaultChecked);\n" + + " }\n" + + " </script>\n" + + "</head><body onload='test()'>\n" + + " <form>" + + " <input type='radio' id='rad1' name='radar' checked>\n" + + " <input type='radio' id='rad2' name='radar'>\n" + + " </form>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "false-false", "false-false", "true-true", "false-false", "false-false", "false-false" }) + public void defaultChecked_notchecked() throws Exception { + final String html = + "<!DOCTYPE HTML>\n<html>\n" + + "<head>\n" + + " <script>\n" + + " function test() {\n" + + " radio = document.getElementById('rad1');\n" + + " radio2 = document.getElementById('rad2');\n" + + " alert(radio.checked + '-' + radio.defaultChecked);\n" + + " alert(radio2.checked + '-' + radio2.defaultChecked);\n" + + + " radio.defaultChecked = true;\n" + + " alert(radio.checked + '-' + radio.defaultChecked);\n" + + " alert(radio2.checked + '-' + radio2.defaultChecked);\n" + + + " radio.defaultChecked = false;\n" + + " alert(radio.checked + '-' + radio.defaultChecked);\n" + + " alert(radio2.checked + '-' + radio2.defaultChecked);\n" + + " }\n" + + " </script>\n" + + "</head><body onload='test()'>\n" + + " <form>" + + " <input type='radio' id='rad1' name='radar'>\n" + + " <input type='radio' id='rad2' name='radar'>\n" + + " </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. |
From: <rb...@us...> - 2013-05-01 14:03:15
|
Revision: 8251 http://sourceforge.net/p/htmlunit/code/8251 Author: rbri Date: 2013-05-01 14:03:08 +0000 (Wed, 01 May 2013) Log Message: ----------- The default value of input-file is no longer empty in IE8ff. Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFileInput2Test.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-05-01 13:42:06 UTC (rev 8250) +++ trunk/htmlunit/src/changes/changes.xml 2013-05-01 14:03:08 UTC (rev 8251) @@ -9,6 +9,9 @@ <body> <release version="2.13" date="???" description="Bugfixes"> <action type="fix" dev="rbri"> + The default value of input-file is no longer empty in IE8ff. + </action> + <action type="fix" dev="rbri"> Checked state of radio buttons and checkboxes changes when setting defaultChecked in IE8ff. </action> <action type="update" dev="rbri"> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-05-01 13:42:06 UTC (rev 8250) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-05-01 14:03:08 UTC (rev 8251) @@ -216,7 +216,7 @@ EXECCOMMAND_THROWS_ON_WRONG_COMMAND, /** */ - @BrowserFeature(@WebBrowser(IE)) + @BrowserFeature(@WebBrowser(value = IE, maxVersion = 7)) FILEINPUT_EMPTY_DEFAULT_VALUE, /** For new pages the focus points to the html root node. */ Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFileInput2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFileInput2Test.java 2013-05-01 13:42:06 UTC (rev 8250) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFileInput2Test.java 2013-05-01 14:03:08 UTC (rev 8251) @@ -41,6 +41,7 @@ import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.WebDriverTestCase; +import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; /** * Tests for {@link HtmlFileInput}. @@ -300,4 +301,28 @@ writer.close(); } } + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({ "-initial", "-default" }) + public void defaultValue() throws Exception { + final String html = "<!DOCTYPE HTML>\n<html><head><title>foo</title>\n" + + "<script>\n" + + " function test() {\n" + + " var file = document.getElementById('testId');\n" + + " alert(file.value + '-' + file.defaultValue);\n" + + + " file.defaultValue = 'default';\n" + + " alert(file.value + '-' + file.defaultValue);\n" + + " }\n" + + "</script>\n" + + "</head><body onload='test()'>\n" + + "<form>\n" + + " <input type='file' id='testId' value='initial'>\n" + + "</form>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } } |