From: <mgu...@us...> - 2014-03-21 15:44:56
|
Revision: 9197 http://sourceforge.net/p/htmlunit/code/9197 Author: mguillem Date: 2014-03-21 15:44:52 +0000 (Fri, 21 Mar 2014) Log Message: ----------- JavaScript: allow use of "in" operator with indexes for StaticNodeList and Attr. This makes Angular.js happy [#1559] Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/NamedNodeMap.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/StaticNodeList.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/NamedNodeMap2Test.java Added Paths: ----------- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/StaticNodeListTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2014-03-21 07:52:31 UTC (rev 9196) +++ trunk/htmlunit/src/changes/changes.xml 2014-03-21 15:44:52 UTC (rev 9197) @@ -8,6 +8,9 @@ <body> <release version="2.15" date="???" description="Bugfixes"> + <action type="fix" dev="mguillem" issue="1559"> + JavaScript: allow use of "in" operator with indexes for StaticNodeList and Attr. + </action> <action type="fix" dev="rbri" issue="1585" due-to="Jakub Kotasek"> File upload content type shouldn't contain charset. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/NamedNodeMap.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/NamedNodeMap.java 2014-03-21 07:52:31 UTC (rev 9196) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/NamedNodeMap.java 2014-03-21 15:44:52 UTC (rev 9197) @@ -252,4 +252,12 @@ } return null; } + + /** + * {@inheritDoc} + */ + @Override + public boolean has(final int index, final Scriptable start) { + return index >= 0 && index < getLength(); + } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/StaticNodeList.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/StaticNodeList.java 2014-03-21 07:52:31 UTC (rev 9196) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/StaticNodeList.java 2014-03-21 15:44:52 UTC (rev 9197) @@ -86,4 +86,11 @@ return elements_.size(); } + /** + * {@inheritDoc} + */ + @Override + public boolean has(final int index, final Scriptable start) { + return index >= 0 && index < getLength(); + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/NamedNodeMap2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/NamedNodeMap2Test.java 2014-03-21 07:52:31 UTC (rev 9196) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/NamedNodeMap2Test.java 2014-03-21 15:44:52 UTC (rev 9197) @@ -20,6 +20,7 @@ import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.WebDriverTestCase; +import com.gargoylesoftware.htmlunit.html.HtmlPageTest; import com.gargoylesoftware.htmlunit.javascript.host.xml.XMLDocumentTest; /** @@ -28,6 +29,7 @@ * @version $Revision$ * @author Ahmed Ashour * @author Frank Danek + * @author Marc Guillemot */ @RunWith(BrowserRunner.class) public class NamedNodeMap2Test extends WebDriverTestCase { @@ -58,4 +60,23 @@ getMockWebConnection().setResponse(URL_SECOND, xml, "text/xml"); loadPageWithAlerts2(html); } + + /** + * @throws Exception on test failure + */ + @Test + @Alerts({ "true", "[object Attr]", "true", "[object Attr]" }) + public void has() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html ng-app><body>\n" + + "<script>\n" + + "var attributes = document.documentElement.attributes;\n" + + "alert(0 in attributes);\n" + + "alert(attributes[0]);\n" + + "alert('0' in attributes);\n" + + "alert(attributes['0']);\n" + + "</script>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } } Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/StaticNodeListTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/StaticNodeListTest.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/StaticNodeListTest.java 2014-03-21 15:44:52 UTC (rev 9197) @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2002-2014 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.javascript.host; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.WebDriverTestCase; +import com.gargoylesoftware.htmlunit.html.HtmlPageTest; + +/** + * Tests for {@link StaticNodeList}. + * + * @version $Revision: 8931 $ + * @author Marc Guillemot + */ +@RunWith(BrowserRunner.class) +public class StaticNodeListTest extends WebDriverTestCase { + + /** + * @throws Exception on test failure + */ + @Test + @Alerts({ "true", "[object HTMLHtmlElement]", "true", "[object HTMLHtmlElement]" }) + public void has() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><body>\n" + + "<script>\n" + + "var list = document.querySelectorAll('html');\n" + + "alert(0 in list);\n" + + "alert(list[0]);\n" + + "alert('0' in list);\n" + + "alert(list['0']);\n" + + "</script>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } +} |