From: <rb...@us...> - 2013-03-08 20:43:40
|
Revision: 8150 http://sourceforge.net/p/htmlunit/code/8150 Author: rbri Date: 2013-03-08 20:43:37 +0000 (Fri, 08 Mar 2013) Log Message: ----------- attribute.expando now returns the correct value instead of the so far hard coded true (IE only) Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Attr.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/AttrTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-03-08 03:01:20 UTC (rev 8149) +++ trunk/htmlunit/src/changes/changes.xml 2013-03-08 20:43:37 UTC (rev 8150) @@ -8,6 +8,9 @@ <body> <release version="2.13" date="???" description="Bugfixes"> + <action type="fix" dev="rbri" issue="1493" due-to="Barry Pitman"> + JavaScript: Attribute.expando now returns the correct value instead of the so far hard coded true (IE only). + </action> <action type="remove" dev="asashour"> WebClient: remove deprecated setPrintContentOnFailingStatusCode(), getPrintContentOnFailingStatusCode(), setThrowExceptionOnFailingStatusCode(), isThrowExceptionOnFailingStatusCode(), setJavaScriptEnabled(), Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Attr.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Attr.java 2013-03-08 03:01:20 UTC (rev 8149) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Attr.java 2013-03-08 20:43:37 UTC (rev 8150) @@ -17,6 +17,8 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ATTR_FIRST_LAST_CHILD_RETURNS_NULL; import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.FF; import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.IE; +import net.sourceforge.htmlunit.corejs.javascript.Scriptable; +import net.sourceforge.htmlunit.corejs.javascript.ScriptableObject; import com.gargoylesoftware.htmlunit.html.DomAttr; import com.gargoylesoftware.htmlunit.html.DomElement; @@ -36,6 +38,7 @@ * @author Chris Erskine * @author Ahmed Ashour * @author Sudhan Moghe + * @author Ronald Brill */ @JsxClass(domClasses = DomAttr.class) public class Attr extends Node { @@ -67,12 +70,16 @@ } /** - * Returns <tt>true</tt> if arbitrary properties can be added to this attribute. - * @return <tt>true</tt> if arbitrary properties can be added to this attribute + * Returns <tt>true</tt> if the attribute is an custom property. + * @return <tt>true</tt> if the attribute is an custom property */ @JsxGetter(@WebBrowser(IE)) public boolean getExpando() { - return true; + final Object owner = getOwnerElement(); + if (null == owner) { + return false; + } + return !ScriptableObject.hasProperty((Scriptable) owner, getName()); } /** Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/AttrTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/AttrTest.java 2013-03-08 03:01:20 UTC (rev 8149) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/AttrTest.java 2013-03-08 20:43:37 UTC (rev 8150) @@ -132,8 +132,9 @@ + " alert(d.getAttributeNode('name').isId);\n" + " alert(d.getAttributeNode('width').isId);\n" + "}\n" - + "</script></head><body onload='test()'>\n" - + "<div iD='d' name='d' width='40'>\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + "<div iD='d' name='d' width='40'></div>\n" + "</body></html>"; loadPageWithAlerts2(html); @@ -143,6 +144,53 @@ * @throws Exception if the test fails */ @Test + @Alerts(IE = { "false", "true", "false", "true", "true" }, + DEFAULT = { "undefined", "undefined", "undefined", "undefined", "undefined" }) + public void expando() throws Exception { + final String html + = "<html><head><script>\n" + + "function test() {\n" + + " var d = document.getElementById('d');\n" + + " alert(d.attributes['id'].expando);\n" + + " alert(d.attributes['name'].expando);\n" + + " alert(d.attributes['style'].expando);\n" + + " alert(d.attributes['custom'].expando);\n" + + " alert(d.attributes['other'].expando);\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + " <div id='d' name='d' style='display: block' custom='value' other></div>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * Testcase for issue http://sourceforge.net/p/htmlunit/bugs/1493/. + * @throws Exception if the test fails + */ + @Test + @Alerts(IE = "false", DEFAULT = "undefined") + public void expandoEvent() throws Exception { + final String html + = "<html><head><script>\n" + + "function test() {\n" + + " var d = document.getElementById('d');\n" + + " d.setAttribute('onfocusin', 't');\n" + + " alert(d.attributes['onfocusin'].expando);\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + " <div id='d'></div>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test @Alerts(FF = "test()", IE = "undefined") public void textContent() throws Exception { final String html |