From: <rb...@us...> - 2013-07-21 09:11:07
|
Revision: 8412 http://sourceforge.net/p/htmlunit/code/8412 Author: rbri Date: 2013-07-21 09:11:04 +0000 (Sun, 21 Jul 2013) Log Message: ----------- StyleSheetListTest migrated to webdriver; fix: Using a wrong index when addressing an StyleSheetList always throws an Exception in IE. 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/css/StyleSheetList.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleSheetListTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-07-20 16:46:32 UTC (rev 8411) +++ trunk/htmlunit/src/changes/changes.xml 2013-07-21 09:11:04 UTC (rev 8412) @@ -8,6 +8,10 @@ <body> <release version="2.13" date="???" description="Bugfixes"> + <action type="fix" dev="rbri"> + Using a wrong index when addressing an StyleSheetList always throws an Exception + in IE. + </action> <action type="fix" dev="rbri" issue="1521"> Fix the way we search for some java methods when creating a XML document from ActiveXObject. This should work with all JavaVMs now. Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-07-20 16:46:32 UTC (rev 8411) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-07-21 09:11:04 UTC (rev 8412) @@ -1093,6 +1093,9 @@ @BrowserFeature({ @WebBrowser(FF), @WebBrowser(CHROME) }) JS_SET_ATTRIBUTE_SUPPORTS_EVENT_HANDLERS, + @BrowserFeature(@WebBrowser(IE)) + JS_STYLESHEET_LIST_EXEPTION_FOR_ALL_INVALID_INDEXES, + /** IE supports accessing unsupported style elements via getter * like val = elem.style.htmlunit;. */ Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleSheetList.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleSheetList.java 2013-07-20 16:46:32 UTC (rev 8411) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleSheetList.java 2013-07-21 09:11:04 UTC (rev 8412) @@ -17,6 +17,7 @@ import net.sourceforge.htmlunit.corejs.javascript.Context; import net.sourceforge.htmlunit.corejs.javascript.Scriptable; +import com.gargoylesoftware.htmlunit.BrowserVersionFeatures; import com.gargoylesoftware.htmlunit.html.DomNode; import com.gargoylesoftware.htmlunit.html.HtmlAttributeChangeEvent; import com.gargoylesoftware.htmlunit.html.HtmlElement; @@ -119,6 +120,10 @@ throw Context.reportRuntimeError("Invalid negative index: " + index); } else if (index >= nodes_.getLength()) { + if (getWindow().getWebWindow().getWebClient().getBrowserVersion().hasFeature( + BrowserVersionFeatures.JS_STYLESHEET_LIST_EXEPTION_FOR_ALL_INVALID_INDEXES)) { + throw Context.reportRuntimeError("Invalid index: " + index); + } return Context.getUndefinedValue(); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleSheetListTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleSheetListTest.java 2013-07-20 16:46:32 UTC (rev 8411) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleSheetListTest.java 2013-07-21 09:11:04 UTC (rev 8412) @@ -22,7 +22,7 @@ import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; -import com.gargoylesoftware.htmlunit.SimpleWebTestCase; +import com.gargoylesoftware.htmlunit.WebDriverTestCase; import com.gargoylesoftware.htmlunit.util.NameValuePair; /** @@ -32,9 +32,10 @@ * @author Daniel Gredler * @author Ahmed Ashour * @author Marc Guillemot + * @author Ronald Brill */ @RunWith(BrowserRunner.class) -public class StyleSheetListTest extends SimpleWebTestCase { +public class StyleSheetListTest extends WebDriverTestCase { /** * @throws Exception if an error occurs @@ -56,7 +57,7 @@ + " </body>\n" + "</html>"; - loadPageWithAlerts(html); + loadPageWithAlerts2(html); } /** @@ -89,14 +90,15 @@ final String css = "div {color:red}"; getMockWebConnection().setDefaultResponse(css, "text/css"); - loadPageWithAlerts(html); + loadPageWithAlerts2(html); } /** * @throws Exception if an error occurs */ @Test - @Alerts({ "0", "undefined", "undefined", "exception for -2" }) + @Alerts(DEFAULT = { "0", "undefined", "undefined", "exception for -2" }, + IE = { "0", "exception for 0", "exception for 46", "exception for -2" }) public void arrayIndexOutOfBoundAccess() throws Exception { final String html = "<html>\n" @@ -104,9 +106,23 @@ + " <script>\n" + " function test() {\n" + " alert(document.styleSheets.length);\n" - + " alert(document.styleSheets[0]);\n" - + " alert(document.styleSheets[46]);\n" + + " try {\n" + + " alert(document.styleSheets[0]);\n" + + " }\n" + + " catch (e) {\n" + + " alert('exception for 0');\n" + + " }\n" + + + + " try {\n" + + " alert(document.styleSheets[46]);\n" + + " }\n" + + " catch (e) {\n" + + " alert('exception for 46');\n" + + " }\n" + + + " try {\n" + " alert(document.styleSheets[-2]);\n" + " }\n" + " catch (e) {\n" @@ -119,7 +135,7 @@ + " </body>\n" + "</html>"; - loadPageWithAlerts(html); + loadPageWithAlerts2(html); } /** @@ -145,7 +161,7 @@ + "</html>"; getMockWebConnection().setDefaultResponse("Not Found", 404, "Not Found", "text/html"); - loadPageWithAlerts(html); + loadPageWithAlerts2(html); } /** @@ -178,7 +194,7 @@ headers.add(new NameValuePair("Content-Encoding", "gzip")); getMockWebConnection().setDefaultResponse(css, 200, "OK", "text/css", headers); - loadPageWithAlerts(html); + loadPageWithAlerts2(html); } /** @@ -210,6 +226,6 @@ headers.add(new NameValuePair("Content-Encoding", "gzip")); getMockWebConnection().setDefaultResponse(css, 200, "OK", "text/css", headers); - loadPageWithAlerts(html); + loadPageWithAlerts2(html); } } |