From: <mgu...@us...> - 2013-01-24 08:06:58
|
Revision: 8031 http://sourceforge.net/p/htmlunit/code/8031 Author: mguillem Date: 2013-01-24 08:06:51 +0000 (Thu, 24 Jan 2013) Log Message: ----------- JavaScript: place document before window in scope chain for event handlers defined in HTML attributes. Fixed many incorrect unit tests that were calling document.open and not window.open as awaited. Issue 898 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlSubmitInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/EventHandler.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/EventListenersContainer.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlSelectTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/EventTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WindowTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLIFrameElement2Test.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-01-23 13:37:53 UTC (rev 8030) +++ trunk/htmlunit/src/changes/changes.xml 2013-01-24 08:06:51 UTC (rev 8031) @@ -8,6 +8,9 @@ <body> <release version="2.12" date="???" description="Bugfixes, CSS3 Selectors"> + <action type="fix" dev="mguillem" issue="898"> + JavaScript: place document before window in scope chain for event handlers defined in HTML attributes. + </action> <action type="add" dev="mguillem"> JavaScript: added basic support for SVGAngle and SVGMatrix. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlSubmitInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlSubmitInput.java 2013-01-23 13:37:53 UTC (rev 8030) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlSubmitInput.java 2013-01-24 08:06:51 UTC (rev 8031) @@ -20,6 +20,7 @@ import java.io.PrintWriter; import java.util.Map; +import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.SgmlPage; import com.gargoylesoftware.htmlunit.util.NameValuePair; import com.gargoylesoftware.htmlunit.util.StringUtils; @@ -53,11 +54,31 @@ */ HtmlSubmitInput(final String namespaceURI, final String qualifiedName, final SgmlPage page, final Map<String, DomAttr> attributes) { - super(namespaceURI, qualifiedName, page, attributes); - if (hasFeature(SUBMITINPUT_DEFAULT_VALUE_IF_VALUE_NOT_DEFINED) - && !hasAttribute("value")) { - setAttribute("value", DEFAULT_VALUE); + super(namespaceURI, qualifiedName, page, addValueIfNeeded(page, attributes)); + } + + /** + * Add missing attribute if needed by fixing attribute map rather to add it afterwards as this second option + * triggers the instantiation of the script object at a time where the DOM node has not yet been added to its + * parent. + */ + private static Map<String, DomAttr> addValueIfNeeded(final SgmlPage page, + final Map<String, DomAttr> attributes) { + + final BrowserVersion browserVersion = page.getWebClient().getBrowserVersion(); + if (browserVersion.hasFeature(SUBMITINPUT_DEFAULT_VALUE_IF_VALUE_NOT_DEFINED)) { + for (final String key : attributes.keySet()) { + if ("value".equalsIgnoreCase(key)) { + return attributes; // value attribute was specified + } + } + + // value attribute was not specified, add it + final DomAttr newAttr = new DomAttr(page, null, "value", DEFAULT_VALUE, true); + attributes.put("value", newAttr); } + + return attributes; } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/EventHandler.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/EventHandler.java 2013-01-23 13:37:53 UTC (rev 8030) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/EventHandler.java 2013-01-24 08:06:51 UTC (rev 8031) @@ -75,6 +75,7 @@ if (realFunction_ == null) { realFunction_ = cx.compileFunction(jsObj, jsSnippet_, eventName_ + " event for " + node_ + " in " + node_.getPage().getUrl(), 0, null); + realFunction_.setParentScope(jsObj); } final Object result = realFunction_.call(cx, scope, thisObj, args); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/EventListenersContainer.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/EventListenersContainer.java 2013-01-23 13:37:53 UTC (rev 8030) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/EventListenersContainer.java 2013-01-24 08:06:51 UTC (rev 8031) @@ -205,7 +205,8 @@ if (LOG.isDebugEnabled()) { LOG.debug("Executing " + event.getType() + " handler for " + node); } - return page.executeJavaScriptFunctionIfPossible(handler, jsNode_, propHandlerArgs, node); + return page.executeJavaScriptFunctionIfPossible(handler, jsNode_, + propHandlerArgs, page); } return null; } 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-01-23 13:37:53 UTC (rev 8030) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java 2013-01-24 08:06:51 UTC (rev 8031) @@ -386,6 +386,7 @@ @Override public void setDomNode(final DomNode domNode) { super.setDomNode(domNode); + setParentScope(getWindow().getDocument()); /** * Convert JavaScript snippets defined in the attribute map to executable event handlers. Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlSelectTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlSelectTest.java 2013-01-23 13:37:53 UTC (rev 8030) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlSelectTest.java 2013-01-24 08:06:51 UTC (rev 8031) @@ -627,7 +627,7 @@ final String htmlContent = "<html><head><title>foo</title></head><body>\n" + "<form id='form1'>\n" - + "<select name='select1' id='select1' onchange='open(\"about:blank\", \"_blank\")'>\n" + + "<select name='select1' id='select1' onchange='window.open(\"about:blank\", \"_blank\")'>\n" + " <option id='option1'>Option1</option>\n" + " <option id='option2' selected>Number Two</option>\n" + "</select>\n" Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/EventTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/EventTest.java 2013-01-23 13:37:53 UTC (rev 8030) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/EventTest.java 2013-01-24 08:06:51 UTC (rev 8031) @@ -22,6 +22,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.openqa.selenium.By; +import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; @@ -272,7 +273,7 @@ */ @Test @Alerts("frame1") - public void testEventScope() throws Exception { + public void thisInEventHandler() throws Exception { final String html = "<html><head></head>\n" + "<body>\n" @@ -534,12 +535,11 @@ /** * Regression test for bug - * <a href="http://sourceforge.net/tracker/?func=detail&aid=2851920&group_id=47038&atid=448266">2851920</a>. + * <a href="http://sourceforge.net/p/htmlunit/bugs/898/">898</a>. * Name resolution doesn't work the same in inline handlers than in "normal" JS code! * @throws Exception if the test fails */ @Test - @NotYetImplemented @Alerts(FF = { "form1 -> custom", "form2 -> [object HTMLFormElement]", "form1: [object HTMLFormElement]", "form2: [object HTMLFormElement]", "form1 -> custom", "form2 -> [object HTMLFormElement]" }, @@ -670,4 +670,122 @@ final String text = addedValue.trim().replaceAll("\r", ""); assertEquals(StringUtils.join(getExpectedAlerts(), "\n"), text); } + + /** + * Test that the parent scope of the event handler defined in HTML attributes is "document". + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "2from window", "1from document" }, + IE = { "1from document", "3from window" }) + public void eventHandlersParentScope() throws Exception { + final String html = "<html><body>\n" + + "<button name='button1' id='button1' onclick='alert(1 + foo)'>click me</button>\n" + + "<script>\n" + + " if (window.addEventListener) {\n" + + " window.addEventListener('click', function() { alert(2 + foo); }, true);\n" + + " }\n" + + " else if (window.attachEvent) {\n" + + " window.attachEvent('onclick', function() { alert(3 + foo); });\n" + + " }\n" + + "document.foo = 'from document';\n" + + "var foo = 'from window';\n" + + "</script>\n" + + "</body></html>"; + + final WebDriver driver = loadPage2(html); + driver.findElement(By.id("button1")).click(); + assertEquals(getExpectedAlerts(), getCollectedAlerts(driver)); + } + + /** + * Test that the parent scopes chain for an event handler. + * @throws Exception if the test fails + */ + @Test + @Alerts({ "from theField", "from theForm", "from document", "from window" }) + public void eventHandlersParentScopeChain_formFields() throws Exception { + eventHandlersParentScopeChain("<button", "</button>"); + eventHandlersParentScopeChain("<input type='text'", ""); + eventHandlersParentScopeChain("<input type='submit' value='xxx'", ""); + // case without value attribute was failing first with IE due to the way the value attribute was added + eventHandlersParentScopeChain("<input type='submit'", ""); + } + + /** + * Test that the parent scopes chain for an event handler. + * @throws Exception if the test fails + */ + @Test + @Alerts({ "from theField", "from document", "from document", "from window" }) + public void eventHandlersParentScopeChain_span() throws Exception { + eventHandlersParentScopeChain("<span", "</span>"); + } + + private void eventHandlersParentScopeChain(final String startTag, final String endTag) throws Exception { + final String html = "<html><body id='body'>\n" + + "<form id='theForm'>\n" + + "<div id='theDiv'>\n" + + startTag + " id='theField' onclick='alert(foo); return false;'>click me" + endTag + "\n" + + "</div>\n" + + "</form>\n" + + "<script>\n" + + "var foo = 'from window';\n" + + "document.foo = 'from document';\n" + + "document.body.foo = 'from body';\n" + + "document.getElementById('theForm').foo = 'from theForm';\n" + + "document.getElementById('theDiv').foo = 'from theDiv';\n" + + "document.getElementById('theField').foo = 'from theField';\n" + + "</script>\n" + + "</body></html>"; + + final WebDriver driver = loadPage2(html); + final WebElement field = driver.findElement(By.id("theField")); + field.click(); + + final JavascriptExecutor jsExecutor = (JavascriptExecutor) driver; + + // remove property on field + jsExecutor.executeScript("delete document.getElementById('theField').foo"); + field.click(); + + // remove property on form + jsExecutor.executeScript("delete document.getElementById('theForm').foo"); + field.click(); + + // remove property on document + jsExecutor.executeScript("delete document.foo"); + field.click(); + + assertEquals(getExpectedAlerts(), getCollectedAlerts(driver)); + } + + /** + * Test that the function open resolves to document.open within a handler defined by an attribute. + * This was wrong (even in unit tests) up to HtmlUnit-2.12. + * @throws Exception if the test fails + */ + @Test + @Alerts("from document") + public void eventHandlers_functionOpen() throws Exception { + final String html = "<html><body>\n" + + "<button id='button1' onclick='identify(open)'>click me</button>\n" + + "<script>\n" + + "function identify(fnOpen) {\n" + + " var origin = 'unknown';\n" + + " if (fnOpen === window.open) {\n" + + " origin = 'from window';\n" + + " }\n" + + " else if (fnOpen === document.open) {\n" + + " origin = 'from document';\n" + + " }\n" + + " alert(origin);\n" + + "}\n" + + "</script>\n" + + "</body></html>"; + + final WebDriver driver = loadPage2(html); + driver.findElement(By.id("button1")).click(); + assertEquals(getExpectedAlerts(), getCollectedAlerts(driver)); + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WindowTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WindowTest.java 2013-01-23 13:37:53 UTC (rev 8030) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WindowTest.java 2013-01-24 08:06:51 UTC (rev 8031) @@ -121,7 +121,7 @@ final String firstContent = "<html><head><title>First</title></head><body>\n" + "<form name='form1'>\n" - + " <a id='link' onClick='open(\"" + URL_SECOND + "\", \"MyNewWindow\").focus(); " + + " <a id='link' onClick='window.open(\"" + URL_SECOND + "\", \"MyNewWindow\").focus(); " + "return false;'>Click me</a>\n" + "</form>\n" + "</body></html>"; @@ -226,7 +226,7 @@ final String secondContent = "<html><head><title>Second</title></head><body>\n" + " <a id='link' " - + "onClick='open(\"" + URL_THIRD + "\", \"_blank\").focus(); '>\n" + + "onClick='window.open(\"" + URL_THIRD + "\", \"_blank\").focus(); '>\n" + "Click me</a>\n" + "</body></html>"; final String thirdContent @@ -285,7 +285,7 @@ final String firstContent = "<html><head><title>First</title></head><body>\n" + "<form name='form1'>\n" - + " <a id='link' onClick='open(\"" + URL_SECOND + "\", \"_self\"); " + + " <a id='link' onClick='window.open(\"" + URL_SECOND + "\", \"_self\"); " + "return false;'>Click me</a>\n" + "</form>\n" + "</body></html>"; @@ -336,7 +336,7 @@ + "</body></html>"; final String thirdContent = "<html><head><title>Third</title></head><body>\n" - + " <a id='link' onClick='open(\"http://fourth\", \"_top\"); " + + " <a id='link' onClick='window.open(\"http://fourth\", \"_top\"); " + "return false;'>Click me</a>\n" + "</body></html>"; final String fourthContent = "<html><head><title>Fourth</title></head><body></body></html>"; @@ -403,7 +403,7 @@ + "</body></html>"; final String thirdContent = "<html><head><title>Third</title></head><body>\n" - + " <a id='link' onClick='open(\"http://fourth\", \"_parent\"); " + + " <a id='link' onClick='window.open(\"http://fourth\", \"_parent\"); " + "return false;'>Click me</a>\n" + "</body></html>"; final String fourthContent = "<html><head><title>Fourth</title></head><body></body></html>"; @@ -1579,7 +1579,7 @@ final String firstContent = "<html><head><title>First</title></head><body>\n" + "<form name='form1'>\n" - + " <a id='link' onClick='open(\"" + URL_SECOND + "\", \"_blank\").focus(); return false;'" + + " <a id='link' onClick='window.open(\"" + URL_SECOND + "\", \"_blank\").focus(); return false;'" + "return false;'>Click me</a>\n" + "</form>\n" + "</body></html>"; @@ -1630,7 +1630,7 @@ final String firstContent = "<html><head><title>First</title></head><body>\n" + "<form name='form1'>\n" - + " <a id='link' onClick='open(\"" + URL_SECOND + "\", \"_blank\").focus(); return false;'" + + " <a id='link' onClick='window.open(\"" + URL_SECOND + "\", \"_blank\").focus(); return false;'" + "return false;'>Click me</a>\n" + "</form>\n" + "</body></html>"; @@ -1675,7 +1675,7 @@ final String firstContent = "<html><head><title>First</title></head><body>\n" + "<form name='form1'>\n" - + " <a id='link' onClick='open(\"" + URL_SECOND + "\", \"_blank\").focus(); return false;'" + + " <a id='link' onClick='window.open(\"" + URL_SECOND + "\", \"_blank\").focus(); return false;'" + "return false;'>Click me</a>\n" + "</form>\n" + "</body></html>"; @@ -1720,7 +1720,7 @@ final String firstContent = "<html><head><title>First</title></head><body>\n" + "<form name='form1'>\n" - + " <a id='link' onClick='open(\"" + URL_SECOND + "\", \"_blank\").focus(); return false;'" + + " <a id='link' onClick='window.open(\"" + URL_SECOND + "\", \"_blank\").focus(); return false;'" + "return false;'>Click me</a>\n" + "</form>\n" + "</body></html>"; @@ -1765,7 +1765,7 @@ final String firstContent = "<html><head><title>First</title></head><body>\n" + "<form name='form1'>\n" - + " <a id='link' onClick='open(\"" + URL_SECOND + "\", \"_blank\").focus(); return false;'" + + " <a id='link' onClick='window.open(\"" + URL_SECOND + "\", \"_blank\").focus(); return false;'" + "return false;'>Click me</a>\n" + "</form>\n" + "</body></html>"; 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-01-23 13:37:53 UTC (rev 8030) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLIFrameElement2Test.java 2013-01-24 08:06:51 UTC (rev 8031) @@ -14,11 +14,13 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.html; +import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.FF17; import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.IE; -import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.FF17; 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; @@ -745,4 +747,32 @@ + "</body></html>"; loadPageWithAlerts2(html); } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts({ "loaded", "loaded", "loaded" }) + public void onLoadCalledEachTimeFrameContentChanges() throws Exception { + final String html = + "<html>\n" + + " <body>\n" + + " <iframe id='testFrame' onload='alert(\"loaded\");'></iframe>\n" + + " <div id='d1' onclick='i.contentWindow.location.replace(\"blah.html\")'>1</div>\n" + + " <div id='d2' onclick='i.contentWindow.location.href=\"blah.html\"'>2</div>\n" + + " <script>var i = document.getElementById('testFrame')</script>\n" + + " </body>\n" + + "</html>"; + + final String frameHtml = "<html><body>foo</body></html>"; + + getMockWebConnection().setDefaultResponse(frameHtml); + + final WebDriver driver = loadPage2(html); + + driver.findElement(By.id("d1")).click(); + driver.findElement(By.id("d2")).click(); + + assertEquals(getExpectedAlerts(), getCollectedAlerts(driver)); + } } 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-01-23 13:37:53 UTC (rev 8030) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLIFrameElementTest.java 2013-01-24 08:06:51 UTC (rev 8031) @@ -135,41 +135,6 @@ } /** - * @throws Exception if an error occurs - */ - @Test - @Alerts({ "loaded", "loaded", "loaded" }) - public void onLoadCalledEachTimeFrameContentChanges() throws Exception { - final String html = - "<html>\n" - + " <body>\n" - + " <iframe id='i' onload='alert(\"loaded\");'></iframe>\n" - + " <div id='d1' onclick='i.contentWindow.location.replace(\"blah.html\")'>1</div>\n" - + " <div id='d2' onclick='i.contentWindow.location.href=\"blah.html\"'>2</div>\n" - + " <script>var i = document.getElementById(\"i\")</script>\n" - + " </body>\n" - + "</html>"; - - final String frameHtml = "<html><body>foo</body></html>"; - - final WebClient webClient = getWebClient(); - final MockWebConnection webConnection = new MockWebConnection(); - - webConnection.setDefaultResponse(frameHtml); - webConnection.setResponse(URL_FIRST, html); - webClient.setWebConnection(webConnection); - - final List<String> collectedAlerts = new ArrayList<String>(); - webClient.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); - - final HtmlPage page = webClient.getPage(URL_FIRST); - page.getHtmlElementById("d1").click(); - page.getHtmlElementById("d2").click(); - - assertEquals(getExpectedAlerts(), collectedAlerts); - } - - /** * @throws Exception if the test fails */ @Test |
From: <mgu...@us...> - 2013-01-24 09:49:21
|
Revision: 8032 http://sourceforge.net/p/htmlunit/code/8032 Author: mguillem Date: 2013-01-24 09:49:17 +0000 (Thu, 24 Jan 2013) Log Message: ----------- JavaScript: determine default path for cookies set with document.cookie from current URL. Issue 1458 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CookieManagerTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-01-24 08:06:51 UTC (rev 8031) +++ trunk/htmlunit/src/changes/changes.xml 2013-01-24 09:49:17 UTC (rev 8032) @@ -8,6 +8,9 @@ <body> <release version="2.12" date="???" description="Bugfixes, CSS3 Selectors"> + <action type="fix" dev="mguillem" issue="1458"> + JavaScript: determine default path for cookies set with document.cookie from current URL. + </action> <action type="fix" dev="mguillem" issue="898"> JavaScript: place document before window in scope chain for event handlers defined in HTML attributes. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java 2013-01-24 08:06:51 UTC (rev 8031) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java 2013-01-24 09:49:17 UTC (rev 8032) @@ -896,7 +896,7 @@ // Default attribute values (note: HttpClient doesn't like null paths). final Map<String, Object> atts = new HashMap<String, Object>(); atts.put("domain", currentURL.getHost()); - atts.put("path", ""); + atts.put("path", getDefaultCookiePath(currentURL)); // Custom attribute values. while (st.hasMoreTokens()) { @@ -924,6 +924,23 @@ } /** + * Same logic than in CookieSpecBase#getDefaultPath which is protected. + */ + private static String getDefaultCookiePath(final URL url) { + String path = url.getPath(); + final int lastSlashIndex = path.lastIndexOf('/'); + if (lastSlashIndex >= 0) { + if (lastSlashIndex == 0) { + path = "/"; + } + else { + path = path.substring(0, lastSlashIndex); + } + } + return path; + } + + /** * Returns the value of the "images" property. * @return the value of the "images" property */ Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CookieManagerTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CookieManagerTest.java 2013-01-24 08:06:51 UTC (rev 8031) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CookieManagerTest.java 2013-01-24 09:49:17 UTC (rev 8032) @@ -439,6 +439,7 @@ public void setCookieDifferentPath() throws Exception { final List<NameValuePair> responseHeader1 = new ArrayList<NameValuePair>(); responseHeader1.add(new NameValuePair("Set-Cookie", "first=1; path=/foo/blah")); + responseHeader1.add(new NameValuePair("Set-Cookie", "second=2; path=/other/path")); responseHeader1.add(new NameValuePair("Location", "/foo/blah")); getMockWebConnection().setDefaultResponse(HTML_ALERT_COOKIE); @@ -475,4 +476,49 @@ assertFalse(mgr.getCookie("second").isHttpOnly()); } } + + /** + * A cookie set with document.cookie without path applies only for the current path + * and overrides cookie previously set for this path. + * @throws Exception if the test fails + */ + @Test + @Alerts("first=new") + public void cookieSetFromJSWithoutPathUsesCurrentLocation() throws Exception { + final List<NameValuePair> responseHeader1 = new ArrayList<NameValuePair>(); + responseHeader1.add(new NameValuePair("Set-Cookie", "first=1")); + + final String html = "<head><body><script>\n" + + "document.cookie = 'first=new';\n" + + "location.replace('/a/b/-');\n" + + "</script></body></html>"; + + getMockWebConnection().setDefaultResponse(HTML_ALERT_COOKIE); + final URL firstUrl = new URL(getDefaultUrl(), "/a/b"); + getMockWebConnection().setResponse(firstUrl, html, 200, "Ok", "text/html", responseHeader1); + + loadPageWithAlerts2(firstUrl); + } + + /** + * A cookie set with document.cookie without path applies only for the current path. + * @throws Exception if the test fails + */ + @Test + @Alerts("first=1") + public void cookieSetFromJSWithoutPathUsesCurrentLocation2() throws Exception { + final List<NameValuePair> responseHeader1 = new ArrayList<NameValuePair>(); + responseHeader1.add(new NameValuePair("Set-Cookie", "first=1; path=/c")); + + final String html = "<head><body><script>\n" + + "document.cookie = 'first=new';\n" + + "location.replace('/c');\n" + + "</script></body></html>"; + + getMockWebConnection().setDefaultResponse(HTML_ALERT_COOKIE); + final URL firstUrl = new URL(getDefaultUrl(), "/a/b"); + getMockWebConnection().setResponse(firstUrl, html, 200, "Ok", "text/html", responseHeader1); + + loadPageWithAlerts2(firstUrl); + } } |
From: <mgu...@us...> - 2013-01-24 11:16:31
|
Revision: 8033 http://sourceforge.net/p/htmlunit/code/8033 Author: mguillem Date: 2013-01-24 11:16:28 +0000 (Thu, 24 Jan 2013) Log Message: ----------- JavaScript: fixed hanging problem (infinite loop) after Object function was called with a window as parameter. Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/WindowProxy.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window2Test.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-01-24 09:49:17 UTC (rev 8032) +++ trunk/htmlunit/src/changes/changes.xml 2013-01-24 11:16:28 UTC (rev 8033) @@ -8,6 +8,9 @@ <body> <release version="2.12" date="???" description="Bugfixes, CSS3 Selectors"> + <action type="fix" dev="mguillem"> + JavaScript: fixed hanging problem (infinite loop) after Object function was called with a window as parameter. + </action> <action type="fix" dev="mguillem" issue="1458"> JavaScript: determine default path for cookies set with document.cookie from current URL. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/WindowProxy.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/WindowProxy.java 2013-01-24 09:49:17 UTC (rev 8032) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/WindowProxy.java 2013-01-24 11:16:28 UTC (rev 8033) @@ -14,6 +14,8 @@ */ package com.gargoylesoftware.htmlunit.javascript.host; +import net.sourceforge.htmlunit.corejs.javascript.Scriptable; + import com.gargoylesoftware.htmlunit.WebWindow; import com.gargoylesoftware.htmlunit.javascript.SimpleScriptableProxy; @@ -43,4 +45,12 @@ return (Window) webWindow_.getScriptObject(); } + /** + * Does nothing. + * @param parent the new parent scope + */ + @Override + public void setParentScope(final Scriptable parent) { + // nothing as the window is the top level scope and its parent scope should stay null + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window2Test.java 2013-01-24 09:49:17 UTC (rev 8032) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window2Test.java 2013-01-24 11:16:28 UTC (rev 8033) @@ -1029,4 +1029,25 @@ loadPageWithAlerts2(html); } + + /** + * This was causing HtmlUnit to hang as of HtmlUnit-2.12 snapshot from 24.01.2013 and probably since a very long + * time. + * The reason was that "top" evaluate to WindowProxy and "Object(top)" was setting the top scope as parentScope + * of the WindowProxy which was setting it on the Window where it should always be null. + * @throws Exception if the test fails + */ + @Test + @Alerts("undefined") + public void hangingObjectCallOnWindowProxy() throws Exception { + final String html = "<html><body>\n" + + "<iframe id='it'></iframe>;\n" + + "<script>\n" + + " Object(top);\n" + + " alert(window.foo);\n" + + "</script>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } } |
From: <mgu...@us...> - 2013-01-28 09:06:36
|
Revision: 8041 http://sourceforge.net/p/htmlunit/code/8041 Author: mguillem Date: 2013-01-28 09:06:33 +0000 (Mon, 28 Jan 2013) Log Message: ----------- XHR.open allows empty URLs for FF17. Make XMLHttpRequest2Test working for FF17. Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest2Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-01-28 09:01:15 UTC (rev 8040) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-01-28 09:06:33 UTC (rev 8041) @@ -1255,6 +1255,10 @@ @BrowserFeature(@WebBrowser(FF)) XHR_ONREADYSTATECHANGE_WITH_EVENT_PARAM, + /** Indicates if an empty url is allowed as url param for the open method. */ + @BrowserFeature({ @WebBrowser(value = FF, minVersion = 10), @WebBrowser(CHROME) }) + XHR_OPEN_ALLOW_EMTPY_URL, + /** Indicates if a "Origin" header should be sent. */ @BrowserFeature({ @WebBrowser(FF), @WebBrowser(CHROME) }) XHR_ORIGIN_HEADER, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java 2013-01-28 09:01:15 UTC (rev 8040) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java 2013-01-28 09:06:33 UTC (rev 8041) @@ -22,6 +22,7 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.XHR_ONREADYSTATECANGE_SYNC_REQUESTS_COMPLETED; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.XHR_ONREADYSTATECANGE_SYNC_REQUESTS_NOT_TRIGGERED; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.XHR_ONREADYSTATECHANGE_WITH_EVENT_PARAM; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.XHR_OPEN_ALLOW_EMTPY_URL; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.XHR_ORIGIN_HEADER; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.XHR_TRIGGER_ONLOAD_ON_COMPLETED; import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.CHROME; @@ -441,7 +442,7 @@ @JsxFunction public void open(final String method, final Object urlParam, final boolean async, final Object user, final Object password) { - if (urlParam == null || "".equals(urlParam)) { + if ((urlParam == null || "".equals(urlParam)) && !getBrowserVersion().hasFeature(XHR_OPEN_ALLOW_EMTPY_URL)) { throw Context.reportRuntimeError("URL for XHR.open can't be empty!"); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest2Test.java 2013-01-28 09:01:15 UTC (rev 8040) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest2Test.java 2013-01-28 09:06:33 UTC (rev 8041) @@ -28,14 +28,12 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; -import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.WebDriverTestCase; import com.gargoylesoftware.htmlunit.WebRequest; import com.gargoylesoftware.htmlunit.util.NameValuePair; @@ -61,10 +59,13 @@ * Strangely, this test seem to fail even without the implementation of the "/setStateXX" handling * on the "server side". * Strange thing. + * + * Update 28.01.2013: + * no deadlock occur anymore (we use a single JS execution thread for a while). Activating the test as it may help. + * * @throws Exception if the test fails */ @Test - @NotYetImplemented public void deadlock() throws Exception { final String jsCallSynchXHR = "function callSynchXHR(url) {\n" + " var xhr = " + XHRInstantiation_ + ";\n" @@ -113,8 +114,7 @@ // just to avoid unused variable warning when the next line is commented getMockWebConnection().setResponse(getDefaultUrl(), html); - // loadPageWithAlerts2(html); - Assert.fail("didn't run the real test as it causes a deadlock"); + loadPage2(html); } /** @@ -179,9 +179,9 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = { "exception", "exception", "pass", "pass" }, - FF10 = { "pass", "pass", "pass", "pass" }, - CHROME = { "pass", "pass", "pass", "pass" }) + @Alerts(DEFAULT = { "pass", "pass", "pass", "pass" }, + FF3_6 = { "exception", "exception", "pass", "pass" }, + IE = { "exception", "exception", "pass", "pass" }) public void openThrowOnEmptyUrl() throws Exception { final String html = "<html><head>\n" + "<script>\n" @@ -200,7 +200,7 @@ loadPageWithAlerts2(html); final int expectedRequests; - if (getBrowserVersion().isChrome() || BrowserVersion.FIREFOX_10 == getBrowserVersion()) { + if ("pass".equals(getExpectedAlerts()[0])) { expectedRequests = 5; } else { @@ -477,7 +477,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(IE = { "1", "2", "3", "4" }, FF10 = "4", CHROME = "4") + @Alerts(DEFAULT = "4", IE = { "1", "2", "3", "4" }, FF3_6 = { }) public void testOnreadystatechange_sync() throws Exception { final String html = "<html>\n" @@ -516,7 +516,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(FF10 = "[object Event]#[object XMLHttpRequest]", IE = "no param") + @Alerts(FF3_6 = { }, FF = "[object Event]#[object XMLHttpRequest]", IE = "no param") public void testOnreadystatechangeSyncWithParam() throws Exception { final String html = "<html>\n" |
From: <mgu...@us...> - 2013-01-28 10:49:45
|
Revision: 8043 http://sourceforge.net/p/htmlunit/code/8043 Author: mguillem Date: 2013-01-28 10:49:41 +0000 (Mon, 28 Jan 2013) Log Message: ----------- - added @BuggyWebDriver to mark tests that are not running in real browser through WebDriver but are working fine when run manually - command "JustifyFull" is supported by FF17 - made HTMLDocumentTest working for FF17 Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Document.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserRunner.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersionClassRunner.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-01-28 09:11:32 UTC (rev 8042) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-01-28 10:49:41 UTC (rev 8043) @@ -312,10 +312,6 @@ /** Was originally .isFirefox(). */ @BrowserFeature({ @WebBrowser(FF), @WebBrowser(CHROME) }) - GENERATED_165, - - /** Was originally .isFirefox(). */ - @BrowserFeature({ @WebBrowser(FF), @WebBrowser(CHROME) }) GENERATED_167, /** Was originally .isFirefox(). */ @@ -971,6 +967,10 @@ @BrowserFeature(@WebBrowser(IE)) JS_PARENT_PROTO_PROPERTIES, + /** Indicates that document.queryCommandSupported(..) is only available in design mode. */ + @BrowserFeature(@WebBrowser(value = FF, maxVersion = 3.6f)) + JS_QUERYCOMMAND_SUPPORTED_ONLY_DESIGNMODE, + /** Javascript script.text(...) reexecutes the script (IE). */ @BrowserFeature(@WebBrowser(IE)) JS_SCRIPT_ALWAYS_REEXECUTE_ON_SET_TEXT, 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-01-28 09:11:32 UTC (rev 8042) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Document.java 2013-01-28 10:49:41 UTC (rev 8043) @@ -463,8 +463,10 @@ public Object createElementNS(final String namespaceURI, final String qualifiedName) { final org.w3c.dom.Element element; final BrowserVersion browserVersion = getBrowserVersion(); - if (browserVersion.hasFeature(XUL_SUPPORT) - && "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul".equals(namespaceURI)) { + if ("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul".equals(namespaceURI)) { + if (!browserVersion.hasFeature(XUL_SUPPORT)) { + throw Context.reportRuntimeError("XUL not available"); + } // simple hack, no need to implement the XUL objects (at least in a first time) element = new HtmlDivision(namespaceURI, qualifiedName, getPage(), null); } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java 2013-01-28 09:11:32 UTC (rev 8042) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java 2013-01-28 10:49:41 UTC (rev 8043) @@ -19,7 +19,6 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_160; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_161; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_164; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_165; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_51; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_53; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_55; @@ -27,7 +26,6 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_59; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_60; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_61; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_63; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLCOLLECTION_OBJECT_DETECTION; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLDOCUMENT_CHARSET_LOWERCASE; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLDOCUMENT_COLOR; @@ -39,6 +37,7 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_DOCUMENT_SETTING_DOMAIN_THROWS_FOR_ABOUT_BLANK; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_GET_ELEMENT_BY_ID_ALSO_BY_NAME_IN_QUICKS_MODE; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_GET_ELEMENT_BY_ID_CASE_SENSITIVE; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_QUERYCOMMAND_SUPPORTED_ONLY_DESIGNMODE; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_TREEWALKER_EXPAND_ENTITY_REFERENCES_FALSE; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.QUERYSELECTORALL_NOT_IN_QUIRKS; import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.CHROME; @@ -174,7 +173,7 @@ */ private static final Map<String, Class<? extends Event>> SUPPORTED_EVENT_TYPE_MAP; - private static final List<String> EXECUTE_CMDS_IE = Arrays.asList(new String[] { + private static final List<String> EXECUTE_CMDS_IE = Arrays.asList( "2D-Position", "AbsolutePosition", "BackColor", "BackgroundImageCache" /* Undocumented */, "BlockDirLTR", "BlockDirRTL", "Bold", "BrowseMode", "ClearAuthenticationCache", "Copy", "CreateBookmark", "CreateLink", "Cut", "Delete", "DirLTR", "DirRTL", @@ -191,18 +190,23 @@ "SizeToControl", "SizeToControlHeight", "SizeToControlWidth", "Stop", "StopImage", "StrikeThrough", "Subscript", "Superscript", "UnBookmark", "Underline", "Undo", "Unlink", "Unselect" - }); + ); /** https://developer.mozilla.org/en/Rich-Text_Editing_in_Mozilla#Executing_Commands */ - private static final List<String> EXECUTE_CMDS_FF = Arrays.asList(new String[] { + private static final List<String> EXECUTE_CMDS_FF = Arrays.asList( "backColor", "bold", "contentReadOnly", "copy", "createLink", "cut", "decreaseFontSize", "delete", "fontName", "fontSize", "foreColor", "formatBlock", "heading", "hiliteColor", "increaseFontSize", "indent", "insertHorizontalRule", "insertHTML", "insertImage", "insertOrderedList", "insertUnorderedList", "insertParagraph", "italic", "justifyCenter", "justifyLeft", "justifyRight", "outdent", "paste", "redo", "removeFormat", "selectAll", "strikeThrough", "subscript", "superscript", "underline", "undo", "unlink", "useCSS", "styleWithCSS" - }); + ); + private static final List<String> EXECUTE_CMDS_FF17 = new ArrayList<String>(EXECUTE_CMDS_FF) { { + add("JustifyFull"); + } + }; + /** * Static counter for {@link #uniqueID_}. */ @@ -1855,16 +1859,24 @@ */ @JsxFunction public boolean queryCommandSupported(final String cmd) { - final boolean ff = getBrowserVersion().hasFeature(GENERATED_165); - final String mode = getDesignMode(); - if (!ff) { + if (getBrowserVersion().hasFeature(JS_QUERYCOMMAND_SUPPORTED_ONLY_DESIGNMODE)) { + final String mode = getDesignMode(); + if (!"on".equals(mode)) { + final String msg = "queryCommandSupported() called while document.designMode='" + mode + "'."; + throw Context.reportRuntimeError(msg); + } + } + return hasCommand(cmd); + } + + private boolean hasCommand(final String cmd) { + if (getBrowserVersion().isIE()) { return containsCaseInsensitive(EXECUTE_CMDS_IE, cmd); } - if (!"on".equals(mode)) { - final String msg = "queryCommandSupported() called while document.designMode='" + mode + "'."; - throw Context.reportRuntimeError(msg); + else if ("FF3.6".equals(getBrowserVersion().getNickname())) { + return containsCaseInsensitive(EXECUTE_CMDS_FF, cmd); } - return containsCaseInsensitive(EXECUTE_CMDS_FF, cmd); + return containsCaseInsensitive(EXECUTE_CMDS_FF17, cmd); } /** @@ -1875,16 +1887,14 @@ */ @JsxFunction public boolean queryCommandEnabled(final String cmd) { - final boolean ff = getBrowserVersion().hasFeature(GENERATED_165); - final String mode = getDesignMode(); - if (!ff) { - return containsCaseInsensitive(EXECUTE_CMDS_IE, cmd); + if (getBrowserVersion().hasFeature(JS_QUERYCOMMAND_SUPPORTED_ONLY_DESIGNMODE)) { + final String mode = getDesignMode(); + if (!"on".equals(mode)) { + final String msg = "queryCommandEnabled() called while document.designMode='" + mode + "'."; + throw Context.reportRuntimeError(msg); + } } - if (!"on".equals(mode)) { - final String msg = "queryCommandEnabled() called while document.designMode='" + mode + "'."; - throw Context.reportRuntimeError(msg); - } - return containsCaseInsensitive(EXECUTE_CMDS_FF, cmd); + return hasCommand(cmd); } /** @@ -1897,12 +1907,8 @@ */ @JsxFunction public boolean execCommand(final String cmd, final boolean userInterface, final Object value) { - final BrowserVersion browser = getBrowserVersion(); - final boolean ie = browser.hasFeature(GENERATED_63); - if ((ie && !containsCaseInsensitive(EXECUTE_CMDS_IE, cmd)) - || (!ie && !containsCaseInsensitive(EXECUTE_CMDS_FF, cmd))) { - - if (browser.hasFeature(EXECCOMMAND_THROWS_ON_WRONG_COMMAND)) { + if (!hasCommand(cmd)) { + if (getBrowserVersion().hasFeature(EXECCOMMAND_THROWS_ON_WRONG_COMMAND)) { throw Context.reportRuntimeError("document.execCommand(): invalid command '" + cmd + "'"); } return false; Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserRunner.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserRunner.java 2013-01-28 09:11:32 UTC (rev 8042) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserRunner.java 2013-01-28 10:49:41 UTC (rev 8043) @@ -276,6 +276,15 @@ } /** + * Indicates that the test runs manually in a real browser but not when using WebDriver to driver the browser. + * @see Browser + */ + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.METHOD) + public static @interface BuggyWebDriver { + } + + /** * The number of tries that test will be executed. * The test will fail if and only if all trials failed. */ Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersionClassRunner.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersionClassRunner.java 2013-01-28 09:11:32 UTC (rev 8042) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersionClassRunner.java 2013-01-28 10:49:41 UTC (rev 8043) @@ -39,6 +39,7 @@ import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.Browser; import com.gargoylesoftware.htmlunit.BrowserRunner.Browsers; +import com.gargoylesoftware.htmlunit.BrowserRunner.BuggyWebDriver; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.BrowserRunner.Tries; @@ -164,6 +165,9 @@ else if (isExpectedToFail(method)) { prefix = "(failure expected) "; } + else if (realBrowser_ && isBuggyWebDriver(method)) { + prefix = "(buggy) "; + } String browserString = browserVersion_.getNickname(); if (realBrowser_) { @@ -320,7 +324,7 @@ final int tries; if (testCase instanceof WebDriverTestCase && realBrowser_) { - notYetImplemented = false; + notYetImplemented = isBuggyWebDriver(method); tries = 1; } else { @@ -375,6 +379,11 @@ return notYetImplementedBrowsers != null && isDefinedIn(notYetImplementedBrowsers.value()); } + private boolean isBuggyWebDriver(final FrameworkMethod method) { + final BuggyWebDriver buggyWebDriver = method.getAnnotation(BuggyWebDriver.class); + return buggyWebDriver != null; + } + private int getTries(final FrameworkMethod method) { final Tries tries = method.getAnnotation(Tries.class); return tries != null ? tries.value() : 1; Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java 2013-01-28 09:11:32 UTC (rev 8042) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java 2013-01-28 10:49:41 UTC (rev 8043) @@ -29,6 +29,7 @@ import java.util.Date; import java.util.List; +import org.apache.commons.lang3.StringUtils; import org.junit.Test; import org.junit.runner.RunWith; import org.openqa.selenium.By; @@ -38,6 +39,7 @@ import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.Browsers; +import com.gargoylesoftware.htmlunit.BrowserRunner.BuggyWebDriver; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.WebDriverTestCase; import com.gargoylesoftware.htmlunit.WebWindow; @@ -299,7 +301,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "exception", FF = "Hello", FF10 = "exception") + @Alerts(DEFAULT = "exception", FF3_6 = "Hello", FF = "exception") public void createDocumentNS_xul() throws Exception { final String html = "<html><body>\n" + "<script>\n" @@ -669,6 +671,7 @@ * @throws Exception if an error occurs */ @Test + @BuggyWebDriver // tested with FF8, FF17, FF18 @Alerts(FF = { "1", "[object HTMLBodyElement]" }, CHROME = { "0", "exception" }, IE = "exception") public void designMode_selectionRange_empty() throws Exception { designMode_selectionRange(""); @@ -678,6 +681,7 @@ * @throws Exception if an error occurs */ @Test + @BuggyWebDriver // tested with FF8, FF17, FF18 @Alerts(FF = { "1", "[object Text]" }, CHROME = { "0", "exception" }, IE = "exception") public void designMode_selectionRange_text() throws Exception { designMode_selectionRange("hello"); @@ -834,25 +838,56 @@ * @throws Exception if the test fails */ @Test - @Alerts(FF = { "exception", "0 commands supported" }, - IE = { "Not supported: foo", "Not supported: 123", "78 commands supported" }) - public void queryCommandSupported() throws Exception { + @Alerts(FF3_6 = { "exception", "0 commands supported" }, + FF17 = { "32 commands supported", "not supported: foo, 123" }, + IE = { "32 commands supported", "not supported: foo, 123" }) + public void queryCommandSupported_common() throws Exception { + final String[] commands = {"BackColor", "Bold", + "Copy", "CreateLink", "Cut", "Delete", + "FontName", "FontSize", "ForeColor", "FormatBlock", + "Indent", "InsertHorizontalRule", "InsertImage", "InsertOrderedList", + "InsertParagraph", "InsertUnorderedList", "Italic", + "JustifyCenter", "JustifyFull", "JustifyLeft", "JustifyRight", + "Outdent", "Paste", "Redo", "RemoveFormat", + "SelectAll", "StrikeThrough", "Subscript", "Superscript", + "Underline", "Undo", "Unlink", + "foo", "123" }; + queryCommandSupported(commands); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(FF3_6 = { "exception", "0 commands supported" }, + DEFAULT = { "0 commands supported" }, + IE = { "46 commands supported" }) + public void queryCommandSupported_disctinct() throws Exception { + final String[] commands = {"2D-Position", "AbsolutePosition", + "BlockDirLTR", "BlockDirRTL", "BrowseMode", + "ClearAuthenticationCache", "CreateBookmark", + "DirLTR", "DirRTL", "EditMode", + "InlineDirLTR", "InlineDirRTL", "InsertButton", "InsertFieldset", + "InsertIFrame", "InsertInputButton", "InsertInputCheckbox", "InsertInputFileUpload", + "InsertInputHidden", "InsertInputImage", "InsertInputPassword", "InsertInputRadio", + "InsertInputReset", "InsertInputSubmit", "InsertInputText", "InsertMarquee", + "InsertSelectDropdown", "InsertSelectListbox", "InsertTextArea", + "JustifyNone", + "LiveResize", "MultipleSelection", "Open", "OverWrite", + "PlayImage", "Print", "Refresh", "RemoveParaFormat", + "SaveAs", "SizeToControl", "SizeToControlHeight", "SizeToControlWidth", "Stop", "StopImage", + "UnBookmark", "Unselect"}; + + queryCommandSupported(commands); + } + + private void queryCommandSupported(final String... commands) throws Exception { + final String jsCommandArray = "['" + StringUtils.join(commands, "', '") + "']"; final String html = "<html><head><title>Test</title><script>\n" + "function doTest() {\n" - + " var cmds = ['2D-Position', 'AbsolutePosition', 'BackColor', 'BlockDirLTR', 'BlockDirRTL', 'Bold', " - + "'BrowseMode', 'ClearAuthenticationCache', 'Copy', 'CreateBookmark', 'CreateLink', 'Cut', 'Delete', " - + "'DirLTR', 'DirRTL', 'EditMode', 'FontName', 'FontSize', 'ForeColor', 'FormatBlock', 'Indent', " - + "'InlineDirLTR', 'InlineDirRTL', 'InsertButton', 'InsertFieldset', 'InsertHorizontalRule', " - + "'InsertIFrame', 'InsertImage', 'InsertInputButton', 'InsertInputCheckbox', 'InsertInputFileUpload', " - + "'InsertInputHidden', 'InsertInputImage', 'InsertInputPassword', 'InsertInputRadio', " - + "'InsertInputReset', 'InsertInputSubmit', 'InsertInputText', 'InsertMarquee', 'InsertOrderedList', " - + "'InsertParagraph', 'InsertSelectDropdown', 'InsertSelectListbox', 'InsertTextArea', " - + "'InsertUnorderedList', 'Italic', 'JustifyCenter', 'JustifyFull', 'JustifyLeft', 'JustifyNone', " - + "'JustifyRight', 'LiveResize', 'MultipleSelection', 'Open', 'Outdent', 'OverWrite', 'Paste', " - + "'PlayImage', 'Print', 'Redo', 'Refresh', 'RemoveFormat', 'RemoveParaFormat', 'SaveAs', 'SelectAll', " - + "'SizeToControl', 'SizeToControlHeight', 'SizeToControlWidth', 'Stop', 'StopImage', 'StrikeThrough', " - + "'Subscript', 'Superscript', 'UnBookmark', 'Underline', 'Undo', 'Unlink', 'Unselect', 'foo', 123];\n" + + " var cmds = " + jsCommandArray + ";\n" + " var nbSupported = 0;\n" + + " var cmdsNotSupported = [];\n" + " try {\n" + " for (var i=0; i<cmds.length; ++i) {\n" + " var cmd = cmds[i];" @@ -860,10 +895,12 @@ + " if (b)\n" + " nbSupported++;\n" + " else\n" - + " alert('Not supported: ' + cmd);\n" + + " cmdsNotSupported[cmdsNotSupported.length] = cmd;\n" + " }" + " } catch (e) { alert('exception'); }\n" + " alert(nbSupported + ' commands supported');\n" + + " if (nbSupported != 0 && cmdsNotSupported.length > 0)\n" + + " alert('not supported: ' + cmdsNotSupported.join(', '));\n" + "}\n" + "</script></head><body onload='doTest()'>\n" + "<div id='log'></div>\n" @@ -1358,7 +1395,8 @@ @Alerts(IE = {"#800080", "", "#0000aa", "#0000aa", "#000000", "#000000" }, // IE9 = {"#800080", "", "#0000aa", "#0000aa", "#000000", "#0" }, FF3_6 = {"", "", "#0000aa", "#0000aa", "#000000", "#000000" }, - FF = {"#800080", "", "#0000aa", "#0000aa", "x", "x" }) + FF10 = {"#800080", "", "#0000aa", "#0000aa", "x", "x" }, + FF17 = {"", "", "#0000aa", "#0000aa", "x", "x" }) public void vlinkColor() throws Exception { final String html = "<html>\n" |
From: <mgu...@us...> - 2013-01-28 13:55:08
|
Revision: 8048 http://sourceforge.net/p/htmlunit/code/8048 Author: mguillem Date: 2013-01-28 13:55:03 +0000 (Mon, 28 Jan 2013) Log Message: ----------- FF3.6+ - returns color as rgb - doesn't lower case align value Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlHeading2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleSheetListTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLAppletElementTest.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/HTMLHeadingElementTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLIFrameElement2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLInputElementTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTableCaptionElementTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTableColElementTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2013-01-28 12:27:20 UTC (rev 8047) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2013-01-28 13:55:03 UTC (rev 8048) @@ -504,7 +504,11 @@ */ @Override public String getColor() { - return defaultIfEmpty(super.getColor(), "rgb(0, 0, 0)"); + String value = defaultIfEmpty(super.getColor(), "rgb(0, 0, 0)"); + if (getBrowserVersion().hasFeature(JS_GET_BACKGROUND_COLOR_FOR_COMPUTED_STYLE_AS_RGB)) { + value = toRGBColor(value); + } + return value; } /** 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-01-28 12:27:20 UTC (rev 8047) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java 2013-01-28 13:55:03 UTC (rev 8048) @@ -2368,16 +2368,17 @@ * @param ignoreIfNoError if <tt>true</tt>, the invocation will be a no-op if it does not trigger an error * (i.e., it will not actually set the align attribute) */ - protected void setAlign(String align, final boolean ignoreIfNoError) { - align = align.toLowerCase(); + protected void setAlign(final String align, final boolean ignoreIfNoError) { + final String alignLC = align.toLowerCase(); final boolean acceptArbitraryValues = getBrowserVersion().hasFeature(JS_ALIGN_ACCEPTS_ARBITRARY_VALUES); if (acceptArbitraryValues - || "center".equals(align) - || "justify".equals(align) - || "left".equals(align) - || "right".equals(align)) { + || "center".equals(alignLC) + || "justify".equals(alignLC) + || "left".equals(alignLC) + || "right".equals(alignLC)) { if (!ignoreIfNoError) { - getDomNodeOrDie().setAttribute("align", align); + final String newValue = acceptArbitraryValues ? align : alignLC; + getDomNodeOrDie().setAttribute("align", newValue); } return; } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlHeading2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlHeading2Test.java 2013-01-28 12:27:20 UTC (rev 8047) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlHeading2Test.java 2013-01-28 13:55:03 UTC (rev 8048) @@ -22,8 +22,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; /** @@ -93,10 +91,7 @@ * @throws Exception if an error occurs */ @Test - @NotYetImplemented({ Browser.CHROME, Browser.FF17 }) - @Alerts(DEFAULT = { "center", "8", "foo" }, - CHROME = { "CenTer", "8", "foo" }, - FF17 = { "CenTer", "8", "foo" }, + @Alerts(DEFAULT = { "CenTer", "8", "foo" }, IE = { "center", "error", "center", "error", "center" }) public void setAlign() throws Exception { final String html Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window2Test.java 2013-01-28 12:27:20 UTC (rev 8047) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window2Test.java 2013-01-28 13:55:03 UTC (rev 8048) @@ -986,7 +986,7 @@ * @throws Exception if an error occurs */ @Test - @Alerts(FF = "red", IE = "exception") + @Alerts(FF = "rgb(255, 0, 0)", IE = "exception") public void getComputedStyle_WithComputedColor() throws Exception { final String html = "<html>\n" Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java 2013-01-28 12:27:20 UTC (rev 8047) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclarationTest.java 2013-01-28 13:55:03 UTC (rev 8048) @@ -481,8 +481,8 @@ * @throws Exception if the test fails */ @Test - @Alerts(FF3_6 = { "red", "blue" }, FF17 = { "", "rgb(0, 0, 255)" }, IE = "exception") - @NotYetImplemented(Browser.FF17) + @Alerts(DEFAULT = { "", "rgb(0, 0, 255)" }, IE = "exception") + @NotYetImplemented(Browser.FF) public void getPropertyValue() throws Exception { final String html = "<html><head><title>First</title><script>\n" + "function doTest() {\n" 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-01-28 12:27:20 UTC (rev 8047) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/StyleSheetListTest.java 2013-01-28 13:55:03 UTC (rev 8048) @@ -63,7 +63,7 @@ * @throws Exception if an error occurs */ @Test - @Alerts(FF = { "red", "red" }, IE = "exception") + @Alerts(FF = { "rgb(255, 0, 0)", "rgb(255, 0, 0)" }, IE = "exception") public void testGetComputedStyle_Link() throws Exception { final String html = "<html>\n" Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLAppletElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLAppletElementTest.java 2013-01-28 12:27:20 UTC (rev 8047) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLAppletElementTest.java 2013-01-28 13:55:03 UTC (rev 8048) @@ -63,7 +63,7 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = { "center", "8", "foo", "left", "right", "bottom", "middle", "top" }, + @Alerts(DEFAULT = { "CenTer", "8", "foo", "left", "right", "bottom", "middle", "top" }, IE = { "center", "error", "center", "error", "center", "left", "right", "bottom", "middle", "top" }) @NotYetImplemented(IE) public void setAlign() throws Exception { 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-01-28 12:27:20 UTC (rev 8047) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDivElementTest.java 2013-01-28 13:55:03 UTC (rev 8048) @@ -95,7 +95,7 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = { "center", "8", "foo", "left", "right", "justify", "center" }, + @Alerts(DEFAULT = { "CenTer", "8", "foo", "left", "right", "justify", "center" }, IE = { "center", "error", "center", "error", "center", "left", "right", "justify", "center" }) public void setAlign() throws Exception { final String html Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLHeadingElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLHeadingElementTest.java 2013-01-28 12:27:20 UTC (rev 8047) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLHeadingElementTest.java 2013-01-28 13:55:03 UTC (rev 8048) @@ -58,7 +58,7 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = { "center", "8", "foo", "left", "right", "center", "justify" }, + @Alerts(DEFAULT = { "CenTer", "8", "foo", "left", "right", "center", "justify" }, IE = { "center", "error", "center", "error", "center", "left", "right", "center", "justify" }) public void setAlign() throws Exception { final String html 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-01-28 12:27:20 UTC (rev 8047) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLIFrameElement2Test.java 2013-01-28 13:55:03 UTC (rev 8048) @@ -14,7 +14,6 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.html; -import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.FF17; import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.IE; import org.junit.Test; @@ -715,10 +714,9 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = { "center", "8", "foo", "left", "right", "bottom", "middle", "top" }, - FF17 = { "CenTer", "8", "foo", "left", "right", "bottom", "middle", "top" }, + @Alerts(DEFAULT = { "CenTer", "8", "foo", "left", "right", "bottom", "middle", "top" }, IE = { "center", "error", "center", "error", "center", "left", "right", "bottom", "middle", "top" }) - @NotYetImplemented({ FF17, IE }) + @NotYetImplemented(IE) public void setAlign() throws Exception { final String html = "<html><body>\n" Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLInputElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLInputElementTest.java 2013-01-28 12:27:20 UTC (rev 8047) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLInputElementTest.java 2013-01-28 13:55:03 UTC (rev 8048) @@ -14,6 +14,7 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.html; +import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.FF17; import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.IE; import org.junit.Test; @@ -293,19 +294,22 @@ * @throws Exception if the test fails */ @Test + @Alerts("true") public void thisDotFormInOnClick() throws Exception { final String html = "<html>\n" - + "<head><title>First</title></head>\n" + "<body>\n" + "<form name='form1'>\n" + "<input type='submit' id='clickMe' onClick=\"this.form.target='_blank'; return false;\">\n" + "</form>\n" + + "<script>\n" + + "alert(document.forms[0].target == '');\n" + + "</script>\n" + "</body></html>"; - final WebDriver driver = loadPage2(html); - assertEquals("First", driver.getTitle()); + final WebDriver driver = loadPageWithAlerts2(html); - assertEquals(null, driver.findElement(By.name("form1")).getAttribute("target")); + // HtmlUnitDriver is buggy, it returns null here +// assertEquals("", driver.findElement(By.name("form1")).getAttribute("target")); driver.findElement(By.id("clickMe")).click(); @@ -704,7 +708,10 @@ @Alerts(DEFAULT = {"text text", "password password", "hidden hidden", "checkbox checkbox", "radio radio", "file file", "checkbox checkbox" }, FF10 = {"text TeXt", "password PassWord", "hidden Hidden", + "checkbox CheckBox", "radio rAdiO", "file FILE", "checkbox CHECKBOX" }, + FF17 = {"text TeXt", "password PassWord", "hidden Hidden", "checkbox CheckBox", "radio rAdiO", "file FILE", "checkbox CHECKBOX" }) + @NotYetImplemented(FF17) public void typeCase() throws Exception { final String html = "<html><head><title>foo</title><script>\n" @@ -790,7 +797,7 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = { "center", "8", "foo", "left", "right", "bottom", "middle", "top" }, + @Alerts(DEFAULT = { "CenTer", "8", "foo", "left", "right", "bottom", "middle", "top" }, IE = { "center", "error", "center", "error", "center", "left", "right", "bottom", "middle", "top" }) @NotYetImplemented(IE) public void setAlign() throws Exception { Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTableCaptionElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTableCaptionElementTest.java 2013-01-28 12:27:20 UTC (rev 8047) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTableCaptionElementTest.java 2013-01-28 13:55:03 UTC (rev 8048) @@ -66,7 +66,7 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = { "center", "8", "foo", "left", "right", "bottom", "top" }, + @Alerts(DEFAULT = { "CenTer", "8", "foo", "left", "right", "bottom", "top" }, IE = { "center", "error", "center", "error", "center", "left", "right", "bottom", "top" }) @NotYetImplemented(IE) public void setAlign() throws Exception { Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTableColElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTableColElementTest.java 2013-01-28 12:27:20 UTC (rev 8047) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTableColElementTest.java 2013-01-28 13:55:03 UTC (rev 8048) @@ -14,6 +14,8 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.html; +import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.FF; +import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.FF17; import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.IE; import org.junit.Test; @@ -68,7 +70,7 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = { "center", "8", "foo", "left", "right", "justify", "char", "center" }, + @Alerts(DEFAULT = { "CenTer", "8", "foo", "left", "right", "justify", "char", "center" }, IE = { "center", "error", "center", "error", "center", "left", "right", "error", "right", "error", "right", "center" }) @NotYetImplemented(IE) @@ -223,9 +225,9 @@ * @throws Exception if an error occurs */ @Test - @Alerts(FF3_6 = { "top", "baseline", "3", "middle", "8", "bottom" }, - FF = { "top", "baseline", "3", "middle", "8", "BOTtom" }, + @Alerts(FF = { "top", "baseline", "3", "middle", "8", "BOTtom" }, IE = { "top", "baseline", "top", "error", "middle", "baseline", "bottom" }) + @NotYetImplemented(FF) public void vAlign() throws Exception { final String html = "<html><body><table>\n" @@ -270,6 +272,7 @@ @Alerts(FF3_6 = { "50", "75%", "foo", "0", "20", "", "80", "40", "abc", "0", "30%", "33" }, FF = { "50", "75%", "foo", "-7", "20.2", "", "80", "40", "abc", "-10", "30%", "33.3" }, IE = { "50", "75%", "", "", "20", "", "error", "error", "80", "40", "", "", "30%", "33" }) + @NotYetImplemented(FF17) public void width() throws Exception { final String html = "<html><body><table>\n" @@ -327,7 +330,8 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = "128", FF10 = "128px") + @Alerts(DEFAULT = "128", FF10 = "128px", FF17 = "128px") + @NotYetImplemented(FF17) public void width_px() throws Exception { final String html = "<html><head>" |
From: <mgu...@us...> - 2013-01-28 15:52:04
|
Revision: 8053 http://sourceforge.net/p/htmlunit/code/8053 Author: mguillem Date: 2013-01-28 15:52:02 +0000 (Mon, 28 Jan 2013) Log Message: ----------- FF doesn't normalize case of align, added expectations for FF17 Modified Paths: -------------- 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/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLImageElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLImageElement.java 2013-01-28 15:42:21 UTC (rev 8052) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLImageElement.java 2013-01-28 15:52:02 UTC (rev 8053) @@ -193,8 +193,7 @@ * @param align the value of the "align" property */ @JsxSetter - public void setAlign(String align) { - align = align.toLowerCase(); + public void setAlign(final String align) { final boolean acceptArbitraryValues = getBrowserVersion().hasFeature(JS_ALIGN_ACCEPTS_ARBITRARY_VALUES); if (acceptArbitraryValues) { getDomNodeOrDie().setAttribute("align", align); 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-01-28 15:42:21 UTC (rev 8052) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLImageElementTest.java 2013-01-28 15:52:02 UTC (rev 8053) @@ -20,8 +20,10 @@ 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.WebDriverTestCase; /** @@ -200,8 +202,11 @@ "top", "absbottom", "absmiddle", "baseline", "texttop", "wrong", "" }, FF10 = { "left", "right", "middle", "justify", "bottom", "middle", "top", "absbottom", "absmiddle", "bottom", "texttop", "wrong", "" }, + FF17 = { "left", "right", "middle", "justify", "bottom", "middle", + "top", "absbottom", "absmiddle", "bottom", "texttop", "wrong", "" }, IE = { "left", "right", "center", "", "bottom", "middle", "top", "absBottom", "absMiddle", "baseline", "textTop", "", "" }) + @NotYetImplemented(FF17) public void getAlign() throws Exception { final String html = "<html><body>\n" @@ -232,13 +237,16 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = { "center", "8", "foo", "left", "right", "center", "justify", + @Alerts(DEFAULT = { "CenTer", "8", "foo", "left", "right", "center", "justify", "bottom", "middle", "top", "absbottom", "absmiddle", "baseline", "texttop" }, FF10 = { "CenTer", "8", "foo", "left", "right", "middle", "justify", "bottom", "middle", "top", "absbottom", "absmiddle", "bottom", "texttop" }, + FF17 = { "CenTer", "8", "foo", "left", "right", "middle", "justify", + "bottom", "middle", "top", "absbottom", "absmiddle", "bottom", "texttop" }, IE = { "center", "error", "center", "error", "center", "left", "right", "center", "error", "center", "bottom", "middle", "top", "absBottom", "absMiddle", "baseline", "textTop" }) + @NotYetImplemented(FF17) public void setAlign() throws Exception { final String html = "<html><body>\n" |
From: <mgu...@us...> - 2013-01-29 08:17:29
|
Revision: 8059 http://sourceforge.net/p/htmlunit/code/8059 Author: mguillem Date: 2013-01-29 08:17:24 +0000 (Tue, 29 Jan 2013) Log Message: ----------- 1/1/2000 is a valid format for a cookie expiration date Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CookieManagerTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2013-01-29 08:16:42 UTC (rev 8058) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2013-01-29 08:17:24 UTC (rev 8059) @@ -772,6 +772,7 @@ "EEE dd MMM yyyy HH mm ss z ", "EEE dd MM yy HH mm ss z ", "EEE dd MM yyyy HH mm ss z ", + "d/M/yyyy", }; HtmlUnitBrowserCompatCookieSpec(final IncorrectnessListener incorrectnessListener) { Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CookieManagerTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CookieManagerTest.java 2013-01-29 08:16:42 UTC (rev 8058) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CookieManagerTest.java 2013-01-29 08:17:24 UTC (rev 8059) @@ -275,6 +275,7 @@ responseHeader1.add(new NameValuePair("Set-Cookie", "first=1;expires=Dec-1-94 16:00:00")); responseHeader1.add(new NameValuePair("Set-Cookie", "second=2;expires=Dec-1-1994 16:00:00")); responseHeader1.add(new NameValuePair("Set-Cookie", "third=3;expires=Dec-1-2094 16:00:00")); + responseHeader1.add(new NameValuePair("Set-Cookie", "fourth=4;expires=1/1/2000; path=/")); getMockWebConnection().setResponse(getDefaultUrl(), HTML_ALERT_COOKIE, 200, "OK", "text/html", responseHeader1); loadPageWithAlerts2(getDefaultUrl()); |
From: <mgu...@us...> - 2013-01-29 09:48:09
|
Revision: 8060 http://sourceforge.net/p/htmlunit/code/8060 Author: mguillem Date: 2013-01-29 09:48:03 +0000 (Tue, 29 Jan 2013) Log Message: ----------- compatMode is "CSS1Compat" for <!DOCTYPE html> Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java 2013-01-29 08:17:24 UTC (rev 8059) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java 2013-01-29 09:48:03 UTC (rev 8060) @@ -829,6 +829,9 @@ return false; } } + else if (docType.getPublicId() == null) { + return false; + } } return true; } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java 2013-01-29 08:17:24 UTC (rev 8059) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java 2013-01-29 09:48:03 UTC (rev 8060) @@ -142,6 +142,15 @@ * @throws Exception if the test fails */ @Test + @Alerts("CSS1Compat") + public void compatMode_doctype_html() throws Exception { + compatMode("<!DOCTYPE html>"); + } + + /** + * @throws Exception if the test fails + */ + @Test @Alerts("BackCompat") public void compatMode_no_url() throws Exception { compatMode("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">"); @@ -1815,7 +1824,6 @@ @Alerts(IE8 = { "7", "CSS1Compat", "undefined", "undefined" }, IE9 = { "9", "CSS1Compat", "function", "function" }, DEFAULT = { "undefined", "CSS1Compat", "function", "function" }) - @NotYetImplemented public void documentMode_html5() throws Exception { final String html = "<!DOCTYPE html>\n" + "<html>\n" |
From: <rb...@us...> - 2013-01-29 20:11:18
|
Revision: 8062 http://sourceforge.net/p/htmlunit/code/8062 Author: rbri Date: 2013-01-29 20:11:15 +0000 (Tue, 29 Jan 2013) Log Message: ----------- Support for CSS pseudo selector ':focus' added. When simulating IE, the initial focus for a page is on the html element. 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/HtmlPage.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClientTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlSelectTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-01-29 17:43:36 UTC (rev 8061) +++ trunk/htmlunit/src/changes/changes.xml 2013-01-29 20:11:15 UTC (rev 8062) @@ -8,6 +8,12 @@ <body> <release version="2.12" date="???" description="Bugfixes, CSS3 Selectors"> + <action type="fix" dev="rbri" issue="1478"> + Support for CSS pseudo selector ':focus' added. + </action> + <action type="fix" dev="rbri"> + When simulating IE, the initial focus for a page is on the html element. + </action> <action type="fix" dev="mguillem"> JavaScript: fixed hanging problem (infinite loop) after Object function was called with a window as parameter. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-01-29 17:43:36 UTC (rev 8061) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-01-29 20:11:15 UTC (rev 8062) @@ -199,6 +199,10 @@ @BrowserFeature(@WebBrowser(IE)) FILEINPUT_EMPTY_DEFAULT_VALUE, + /** For new pages the focus points to the html root node. */ + @BrowserFeature(@WebBrowser(IE)) + FOCUS_HTML_ELEMENT_AT_START, + /** Indicates if a form field is directly reachable by its new name once this has been changed. */ @BrowserFeature({ @WebBrowser(FF), @WebBrowser(CHROME) }) FORMFIELD_REACHABLE_BY_NEW_NAMES, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2013-01-29 17:43:36 UTC (rev 8061) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2013-01-29 20:11:15 UTC (rev 8062) @@ -18,6 +18,7 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_DOM_CONTENT_LOADED; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_ONLOAD_FRAMESET_FIRST; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_ONLOAD_IFRAME_CREATED_BY_JAVASCRIPT; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.FOCUS_HTML_ELEMENT_AT_START; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_DEFERRED; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_FRAME_RESOLVE_URL_WITH_PARENT_WINDOW; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.PAGE_SELECTION_RANGE_FROM_SELECTABLE_TEXT_INPUT; @@ -204,14 +205,19 @@ } } loadFrames(); + + final BrowserVersion browserVersion = getWebClient().getBrowserVersion(); + // don't set the ready state if we really load the blank page into the window // see Node.initInlineFrameIfNeeded() if (!isAboutBlank) { + if (browserVersion.hasFeature(FOCUS_HTML_ELEMENT_AT_START)) { + elementWithFocus_ = getDocumentElement(); + } setReadyState(READY_STATE_COMPLETE); getDocumentElement().setReadyState(READY_STATE_COMPLETE); } - final BrowserVersion browserVersion = getWebClient().getBrowserVersion(); if (browserVersion.hasFeature(EVENT_DOM_CONTENT_LOADED)) { executeEventHandlersIfNeeded(Event.TYPE_DOM_DOCUMENT_LOADED); } 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-01-29 17:43:36 UTC (rev 8061) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2013-01-29 20:11:15 UTC (rev 8062) @@ -70,6 +70,7 @@ import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.Cache; import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; +import com.gargoylesoftware.htmlunit.SgmlPage; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebRequest; import com.gargoylesoftware.htmlunit.WebResponse; @@ -560,6 +561,13 @@ else if ("disabled".equals(value)) { return (element instanceof DisabledElement && ((DisabledElement) element).isDisabled()); } + else if ("focus".equals(value)) { + final SgmlPage page = element.getPage(); + if (page instanceof HtmlPage) { + final HtmlElement focus = ((HtmlPage) page).getFocusedElement(); + return element == focus; + } + } else if ("checked".equals(value)) { return (element instanceof HtmlCheckBoxInput && ((HtmlCheckBoxInput) element).isChecked()) || (element instanceof HtmlRadioButtonInput && ((HtmlRadioButtonInput) element).isChecked()); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClientTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClientTest.java 2013-01-29 17:43:36 UTC (rev 8061) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClientTest.java 2013-01-29 20:11:15 UTC (rev 8062) @@ -925,11 +925,18 @@ final List<String> collectedAlerts = new ArrayList<String>(); webClient.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); - Assert.assertNull("original", page.getFocusedElement()); - Assert.assertNull("next", page.tabToNextElement()); - Assert.assertNull("previous", page.tabToPreviousElement()); - Assert.assertNull("accesskey", page.pressAccessKey('a')); + HtmlElement focus = page.getFocusedElement(); + Assert.assertTrue("original", (focus == null) || (focus == page.getDocumentElement())); + focus = page.tabToPreviousElement(); + Assert.assertTrue("next", (focus == null) || (focus == page.getDocumentElement())); + + focus = page.tabToNextElement(); + Assert.assertTrue("previous", (focus == null) || (focus == page.getDocumentElement())); + + focus = page.pressAccessKey('a'); + Assert.assertTrue("accesskey", (focus == null) || (focus == page.getDocumentElement())); + final List<?> expectedAlerts = Collections.EMPTY_LIST; assertEquals(expectedAlerts, collectedAlerts); } @@ -947,8 +954,10 @@ final HtmlPage page = getPageForKeyboardTest(webClient, new String[]{null}); final HtmlElement element = page.getHtmlElementById("submit0"); - Assert.assertNull("original", page.getFocusedElement()); - Assert.assertNull("accesskey", page.pressAccessKey('x')); + HtmlElement focus = page.getFocusedElement(); + Assert.assertTrue("original", (focus == null) || (focus == page.getDocumentElement())); + focus = page.pressAccessKey('x'); + Assert.assertTrue("accesskey", (focus == null) || (focus == page.getDocumentElement())); Assert.assertEquals("next", element, page.tabToNextElement()); Assert.assertEquals("nextAgain", element, page.tabToNextElement()); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlSelectTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlSelectTest.java 2013-01-29 17:43:36 UTC (rev 8061) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlSelectTest.java 2013-01-29 20:11:15 UTC (rev 8062) @@ -15,6 +15,7 @@ package com.gargoylesoftware.htmlunit.html; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import java.io.File; @@ -675,7 +676,7 @@ assertEquals(Collections.emptyList(), collectedAlerts); final HtmlSelect select = page.getHtmlElementById("select1"); - assertNull(page.getFocusedElement()); + assertNotSame(select, page.getFocusedElement()); select.getOption(0).setSelected(true); assertSame(select, page.getFocusedElement()); 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-01-29 17:43:36 UTC (rev 8061) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java 2013-01-29 20:11:15 UTC (rev 8062) @@ -588,4 +588,43 @@ loadPageWithAlerts2(html); } + /** + * + * @throws Exception if an error occurs + */ + @Test + @Alerts(FF = { "0", "undefined", "1", "[object HTMLInputElement]", "id2" }, + DEFAULT = { "1", "[object HTMLHtmlElement]", "1", "[object HTMLInputElement]", "id2" }) + public void focus() throws Exception { + final String html = "<html><head><title>First</title>\n" + + "<meta http-equiv='X-UA-Compatible' content='IE=9'>\n" + + "<script>\n" + + "function test() {\n" + + " if (document.querySelectorAll) {\n" + + " try {\n" + + " found = document.querySelectorAll(':focus');\n" + + " alert(found.length);\n" + + " alert(found[0]);\n" + + " } catch(e) {alert('exception')}\n" + + " }\n" + + "\n" + + " document.getElementById('id2').focus();\n" + + "\n" + + " if (document.querySelectorAll) {\n" + + " try {\n" + + " found = document.querySelectorAll(':focus');\n" + + " alert(found.length);\n" + + " alert(found[0]);\n" + + " alert(found[0].id);\n" + + " } catch(e) {alert('exception')}\n" + + " }\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + " <input id='id1'>\n" + + " <input id='id2'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } } |
From: <mgu...@us...> - 2013-01-30 08:47:42
|
Revision: 8064 http://sourceforge.net/p/htmlunit/code/8064 Author: mguillem Date: 2013-01-30 08:47:35 +0000 (Wed, 30 Jan 2013) Log Message: ----------- JavaScript: fixed exception occurring while testing window or document == "some string". Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/SimpleScriptableProxy.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-01-29 21:06:47 UTC (rev 8063) +++ trunk/htmlunit/src/changes/changes.xml 2013-01-30 08:47:35 UTC (rev 8064) @@ -8,6 +8,9 @@ <body> <release version="2.12" date="???" description="Bugfixes, CSS3 Selectors"> + <action type="fix" dev="mguillem" issue="1479"> + JavaScript: fixed exception occurring while testing window or document == "some string". + </action> <action type="fix" dev="rbri" issue="1478"> Support for CSS pseudo selector ':focus' added. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/SimpleScriptableProxy.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/SimpleScriptableProxy.java 2013-01-29 21:06:47 UTC (rev 8063) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/SimpleScriptableProxy.java 2013-01-30 08:47:35 UTC (rev 8064) @@ -123,4 +123,15 @@ getDelegee().put(name, start, value); } + /** + * Delegates call to delegee. + * @param hint the type hint + * @return the default value + * + * @see net.sourceforge.htmlunit.corejs.javascript.Scriptable#getDefaultValue + */ + @Override + public Object getDefaultValue(final Class<?> hint) { + return getDelegee().getDefaultValue(hint); + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window2Test.java 2013-01-29 21:06:47 UTC (rev 8063) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window2Test.java 2013-01-30 08:47:35 UTC (rev 8064) @@ -1050,4 +1050,21 @@ loadPageWithAlerts2(html); } + + /** + * Was producing "TypeError: Object's getDefaultValue() method returned an object" due to Delegator not delegating + * getDefaultValue(hint) to delegee when hint is null. + * @throws Exception if the test fails + */ + @Test + @Alerts("false") + public void equalsString() throws Exception { + final String html = "<html><body>\n" + + "<script>\n" + + " alert('foo' == window);\n" + + "</script>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java 2013-01-29 21:06:47 UTC (rev 8063) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java 2013-01-30 08:47:35 UTC (rev 8064) @@ -1841,4 +1841,21 @@ loadPageWithAlerts2(html); } + + /** + * Was producing "TypeError: Object's getDefaultValue() method returned an object" due to Delegator not delegating + * getDefaultValue(hint) to delegee when hint is null. + * @throws Exception if the test fails + */ + @Test + @Alerts("false") + public void equalsString() throws Exception { + final String html = "<html><body>\n" + + "<script>\n" + + " alert('foo' == document);\n" + + "</script>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } } |
From: <mgu...@us...> - 2013-01-31 14:44:32
|
Revision: 8068 http://sourceforge.net/p/htmlunit/code/8068 Author: mguillem Date: 2013-01-31 14:44:26 +0000 (Thu, 31 Jan 2013) Log Message: ----------- - Initial support for HtmlMeter (FF 17) - add getters for value and max for HTMLProgressElement Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DefaultElementFactory.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLProgressElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlProgressTest.java Added Paths: ----------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlMeter.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLMeterElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLMeterElementTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-01-30 19:13:19 UTC (rev 8067) +++ trunk/htmlunit/src/changes/changes.xml 2013-01-31 14:44:26 UTC (rev 8068) @@ -8,6 +8,9 @@ <body> <release version="2.12" date="???" description="Bugfixes, CSS3 Selectors"> + <action type="add" dev="mguillem"> + Initial support for HtmlMeter (FF 17). + </action> <action type="fix" dev="mguillem" issue="1479"> JavaScript: fixed exception occurring while testing window or document == "some string". </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DefaultElementFactory.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DefaultElementFactory.java 2013-01-30 19:13:19 UTC (rev 8067) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DefaultElementFactory.java 2013-01-31 14:44:26 UTC (rev 8068) @@ -72,7 +72,7 @@ HtmlItalic.TAG_NAME, HtmlKeyboard.TAG_NAME, HtmlLabel.TAG_NAME, HtmlLegend.TAG_NAME, HtmlListing.TAG_NAME, HtmlListItem.TAG_NAME, HtmlLink.TAG_NAME, HtmlMap.TAG_NAME, HtmlMarquee.TAG_NAME, - HtmlMenu.TAG_NAME, HtmlMeta.TAG_NAME, HtmlMultiColumn.TAG_NAME, + HtmlMenu.TAG_NAME, HtmlMeta.TAG_NAME, HtmlMeter.TAG_NAME, HtmlMultiColumn.TAG_NAME, HtmlNoBreak.TAG_NAME, HtmlNoEmbed.TAG_NAME, HtmlNoFrames.TAG_NAME, HtmlNoScript.TAG_NAME, HtmlObject.TAG_NAME, HtmlOrderedList.TAG_NAME, HtmlOptionGroup.TAG_NAME, HtmlOption.TAG_NAME, HtmlParagraph.TAG_NAME, @@ -352,6 +352,14 @@ else if (tagName.equals(HtmlMeta.TAG_NAME)) { element = new HtmlMeta(namespaceURI, qualifiedName, page, attributeMap); } + else if (tagName.equals(HtmlMeter.TAG_NAME)) { + if (page.getWebClient().getBrowserVersion().hasFeature(HTML5_TAGS)) { + element = new HtmlMeter(namespaceURI, qualifiedName, page, attributeMap); + } + else { + return UnknownElementFactory.instance.createElementNS(page, namespaceURI, qualifiedName, attributes); + } + } else if (tagName.equals(HtmlMultiColumn.TAG_NAME)) { element = new HtmlMultiColumn(namespaceURI, qualifiedName, page, attributeMap); } Added: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlMeter.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlMeter.java (rev 0) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlMeter.java 2013-01-31 14:44:26 UTC (rev 8068) @@ -0,0 +1,45 @@ +/* + * 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.Map; + +import com.gargoylesoftware.htmlunit.SgmlPage; + +/** + * HTML 5 "meter" element. + * + * @see <a href="https://developer.mozilla.org/en-US/docs/HTML/Element/meter">MDN documentation</a> + * @version $Revision$ + * @author Marc Guillemot + */ +public class HtmlMeter extends HtmlMedia { + + /** The HTML tag represented by this element. */ + public static final String TAG_NAME = "meter"; + + /** + * Creates an instance of HtmlMeter + * + * @param namespaceURI the URI that identifies an XML namespace + * @param qualifiedName the qualified name of the element type to instantiate + * @param page the HtmlPage that contains this element + * @param attributes the initial attributes + */ + HtmlMeter(final String namespaceURI, final String qualifiedName, final SgmlPage page, + final Map<String, DomAttr> attributes) { + super(namespaceURI, qualifiedName, page, attributes); + } +} Property changes on: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlMeter.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 Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.java 2013-01-30 19:13:19 UTC (rev 8067) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.java 2013-01-31 14:44:26 UTC (rev 8068) @@ -164,6 +164,7 @@ import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLMediaElement; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLMenuElement; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLMetaElement; +import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLMeterElement; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLOListElement; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLObjectElement; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLOptGroupElement; @@ -300,8 +301,8 @@ HTMLIFrameElement.class, HTMLImageElement.class, HTMLInputElement.class, HTMLInsElement.class, HTMLIsIndexElement.class, HTMLLIElement.class, HTMLLabelElement.class, HTMLLegendElement.class, HTMLLinkElement.class, HTMLListElement.class, HTMLMapElement.class, - HTMLMediaElement.class, HTMLMenuElement.class, - HTMLMetaElement.class, HTMLOListElement.class, HTMLObjectElement.class, HTMLOptGroupElement.class, + HTMLMediaElement.class, HTMLMenuElement.class, HTMLMetaElement.class, HTMLMeterElement.class, + HTMLOListElement.class, HTMLObjectElement.class, HTMLOptGroupElement.class, HTMLOptionElement.class, HTMLOptionsCollection.class, HTMLParagraphElement.class, HTMLParamElement.class, HTMLPreElement.class, HTMLProgressElement.class, HTMLQuoteElement.class, HTMLScriptElement.class, HTMLSelectElement.class, HTMLSourceElement.class, HTMLSpacerElement.class, HTMLSpanElement.class, Added: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLMeterElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLMeterElement.java (rev 0) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLMeterElement.java 2013-01-31 14:44:26 UTC (rev 8068) @@ -0,0 +1,108 @@ +/* + * 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.javascript.host.html; + +import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.CHROME; +import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.FF; + +import com.gargoylesoftware.htmlunit.html.HtmlMeter; +import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; +import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter; +import com.gargoylesoftware.htmlunit.javascript.configuration.WebBrowser; + +/** + * The JavaScript object "HTMLMeterElement". + * + * @version $Revision$ + * @author Marc Guillemot + */ +@JsxClass(domClasses = HtmlMeter.class, browsers = { @WebBrowser(value = FF, minVersion = 16), @WebBrowser(CHROME) }) +public class HTMLMeterElement extends HTMLElement { + + /** + * The getter for the "value" property. + * @return the value + */ + @JsxGetter + public double getValue() { + return getAttributeAsDouble("value", 0); + } + + /** + * The getter for the "min" property. + * @return the value + */ + @JsxGetter + public double getMin() { + return getAttributeAsDouble("min", 0); + } + + /** + * The getter for the "max" property. + * @return the value + */ + @JsxGetter + public double getMax() { + return getAttributeAsDouble("max", 1); + } + + /** + * The getter for the "low" property. + * @return the value + */ + @JsxGetter + public double getLow() { + final double val = getAttributeAsDouble("low", Double.MAX_VALUE); + if (val == Double.MAX_VALUE) { + return getMin(); + } + return val; + } + + /** + * The getter for the "high" property. + * @return the value + */ + @JsxGetter + public double getHigh() { + final double val = getAttributeAsDouble("high", Double.MIN_VALUE); + if (val == Double.MIN_VALUE) { + return getMax(); + } + return val; + } + + /** + * The getter for the "optimum" property. + * @return the value + */ + @JsxGetter + public double getOptimum() { + final double val = getAttributeAsDouble("optimum", Double.MAX_VALUE); + if (val == Double.MAX_VALUE) { + return getValue(); + } + return val; + } + + private double getAttributeAsDouble(final String attributeName, final double defaultValue) { + try { + return Double.parseDouble(getDomNodeOrDie().getAttribute(attributeName)); + } + catch (final NumberFormatException e) { + return defaultValue; + } + } +} Property changes on: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLMeterElement.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 Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLProgressElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLProgressElement.java 2013-01-30 19:13:19 UTC (rev 8067) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLProgressElement.java 2013-01-31 14:44:26 UTC (rev 8068) @@ -18,6 +18,7 @@ import com.gargoylesoftware.htmlunit.html.HtmlProgress; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; +import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter; import com.gargoylesoftware.htmlunit.javascript.configuration.WebBrowser; /** @@ -25,8 +26,35 @@ * * @version $Revision$ * @author Ahmed Ashour + * @author Marc Guillemot */ @JsxClass(domClasses = HtmlProgress.class, browsers = @WebBrowser(value = FF, minVersion = 10)) public class HTMLProgressElement extends HTMLElement { + /** + * The getter for the "value" property. + * @return the value + */ + @JsxGetter + public double getValue() { + return getAttributeAsDouble("value", 0); + } + + /** + * The getter for the "max" property. + * @return the value + */ + @JsxGetter + public double getMax() { + return getAttributeAsDouble("max", 1); + } + + private double getAttributeAsDouble(final String attributeName, final double defaultValue) { + try { + return Double.parseDouble(getDomNodeOrDie().getAttribute(attributeName)); + } + catch (final NumberFormatException e) { + return defaultValue; + } + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlProgressTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlProgressTest.java 2013-01-30 19:13:19 UTC (rev 8067) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlProgressTest.java 2013-01-31 14:44:26 UTC (rev 8068) @@ -60,4 +60,23 @@ } } } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = { "number70", "number100" }, + FF3_6 = { }, IE = { }) + public void properties() throws Exception { + final String html = "<html><body>\n" + + "<progress id='it' value='70' max='100'>70%</progress>\n" + + "<script>\n" + + "var elt = document.getElementById('it');\n" + + "if (window.HTMLProgressElement) {\n" + + " alert(typeof(elt.value) + elt.value);\n" + + " alert(typeof(elt.max) + elt.max);\n" + + "}\n" + + "</script></body></html>"; + loadPageWithAlerts2(html); + } } Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLMeterElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLMeterElementTest.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLMeterElementTest.java 2013-01-31 14:44:26 UTC (rev 8068) @@ -0,0 +1,71 @@ +/* + * 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.javascript.host.html; + +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; + +/** + * Tests for {@link HTMLMeterElement}. + * @version $Revision$ + * @author Marc Guillemot + */ +@RunWith(BrowserRunner.class) +public class HTMLMeterElementTest extends WebDriverTestCase { + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(IE = "[object]", + FF = "[object HTMLUnknownElement]", + FF17 = "[object HTMLMeterElement]") + public void tag() throws Exception { + final String html = "<html><body>\n" + + "<meter id='it' min='200' max='500' value='350'>\n" + + "<script>\n" + + "alert(document.getElementById('it'));\n" + + "</script></body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = { }, + FF17 = { "number200", "number500", + "number200", "number500", "number350", "number350" }) + public void properties() throws Exception { + final String html = "<html><body>\n" + + "<meter id='it' min='200' max='500' value='350'>\n" + + "<script>\n" + + "var elt = document.getElementById('it');\n" + + "if (window.HTMLMeterElement) {\n" + + " alert(typeof(elt.min) + elt.min);\n" + + " alert(typeof(elt.max) + elt.max);\n" + + " alert(typeof(elt.low) + elt.low);\n" + + " alert(typeof(elt.high) + elt.high);\n" + + " alert(typeof(elt.value) + elt.value);\n" + + " alert(typeof(elt.optimum) + elt.optimum);\n" + + "}\n" + + "</script></body></html>"; + loadPageWithAlerts2(html); + } +} Property changes on: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLMeterElementTest.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-01-31 18:32:14
|
Revision: 8069 http://sourceforge.net/p/htmlunit/code/8069 Author: rbri Date: 2013-01-31 18:32:08 +0000 (Thu, 31 Jan 2013) Log Message: ----------- css selector parser fixes Modified Paths: -------------- 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/javascript/host/css/CSSStyleSheet.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2013-01-31 14:44:26 UTC (rev 8068) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2013-01-31 18:32:08 UTC (rev 8069) @@ -43,6 +43,7 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.math.NumberUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.w3c.css.sac.AttributeCondition; @@ -724,22 +725,20 @@ // an+b final int nIndex = nth.indexOf('n'); - final int a; + int a = 0; if (nIndex != -1) { String value = nth.substring(0, nIndex).trim(); if (value.startsWith("+")) { value = value.substring(1); } - a = Integer.parseInt(value); + a = NumberUtils.toInt(value, 1); } - else { - a = 0; - } + String value = nth.substring(nIndex + 1).trim(); if (value.startsWith("+")) { value = value.substring(1); } - final int b = Integer.parseInt(value); + final int b = NumberUtils.toInt(value, 0); if (a == 0) { return index == b; } 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-01-31 14:44:26 UTC (rev 8068) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java 2013-01-31 18:32:08 UTC (rev 8069) @@ -41,7 +41,7 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = "li2", IE8 = "exception") + @Alerts(DEFAULT = { "li2", "li1", "li2", "li1", "li3", "li1" }, IE8 = "exception") public void nth_child() throws Exception { final String html = "<html><head><title>First</title>\n" + "<meta http-equiv='X-UA-Compatible' content='IE=9'>\n" @@ -50,6 +50,11 @@ + " if (document.querySelectorAll) {\n" + " try {\n" + " alert(document.querySelectorAll('li:nth-child(2)')[0].id);\n" + + " alert(document.querySelectorAll('li:nth-child(n)')[0].id);\n" + + " alert(document.querySelectorAll('li:nth-child(2n)')[0].id);\n" + + " alert(document.querySelectorAll('li:nth-child(2n+1)')[0].id);\n" + + " alert(document.querySelectorAll('li:nth-child(2n+1)')[1].id);\n" + + " alert(document.querySelectorAll('li:nth-child(2n-1)')[0].id);\n" + " } catch(e) {alert('exception')}\n" + " }\n" + "}\n" @@ -69,6 +74,38 @@ * @throws Exception if an error occurs */ @Test + @Alerts(DEFAULT = { "1", "li2", "2", "li1", "li3" }, IE8 = "exception") + public void nth_child_even_odd() throws Exception { + final String html = "<html><head><title>First</title>\n" + + "<meta http-equiv='X-UA-Compatible' content='IE=9'>\n" + + "<script>\n" + + "function test() {\n" + + " if (document.querySelectorAll) {\n" + + " try {\n" + + " alert(document.querySelectorAll('li:nth-child(even)').length);\n" + + " alert(document.querySelectorAll('li:nth-child(eVen)')[0].id);\n" + + " alert(document.querySelectorAll('li:nth-child(odd)').length);\n" + + " alert(document.querySelectorAll('li:nth-child(OdD)')[0].id);\n" + + " alert(document.querySelectorAll('li:nth-child(ODD)')[1].id);\n" + + " } catch(e) {alert('exception')}\n" + + " }\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + "<ul>\n" + + " <li id='li1'></li>\n" + + " <li id='li2'></li>\n" + + " <li id='li3'></li>\n" + + "</ul>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test @Alerts("exception") public void nth_child_no_argument() throws Exception { final String html |
From: <rb...@us...> - 2013-02-01 13:36:22
|
Revision: 8072 http://sourceforge.net/p/htmlunit/code/8072 Author: rbri Date: 2013-02-01 13:36:15 +0000 (Fri, 01 Feb 2013) Log Message: ----------- Method innerHTML does not encode entities for style tags. Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLStyleElementTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-02-01 07:35:03 UTC (rev 8071) +++ trunk/htmlunit/src/changes/changes.xml 2013-02-01 13:36:15 UTC (rev 8072) @@ -8,6 +8,9 @@ <body> <release version="2.12" date="???" description="Bugfixes, CSS3 Selectors"> + <action type="fix" dev="rbri"> + Method innerHTML does not encode entities for style tags. + </action> <action type="add" dev="mguillem"> Initial support for HtmlMeter (FF 17). </action> 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-02-01 07:35:03 UTC (rev 8071) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java 2013-02-01 13:36:15 UTC (rev 8072) @@ -851,8 +851,12 @@ @JsxGetter public String getInnerHTML() { final StringBuilder buf = new StringBuilder(); + + final String tagName = getTagName(); + boolean isPlain = "SCRIPT".equals(tagName) || "STYLE".equals(tagName); + // we can't rely on DomNode.asXml because it adds indentation and new lines - printChildren(buf, getDomNodeOrDie(), !"SCRIPT".equals(getTagName())); + printChildren(buf, getDomNodeOrDie(), !isPlain); return buf.toString(); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLStyleElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLStyleElementTest.java 2013-02-01 07:35:03 UTC (rev 8071) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLStyleElementTest.java 2013-02-01 13:36:15 UTC (rev 8072) @@ -26,6 +26,7 @@ * * @version $Revision$ * @author Marc Guillemot + * @author Ronald Brill */ @RunWith(BrowserRunner.class) public class HTMLStyleElementTest extends WebDriverTestCase { @@ -78,4 +79,33 @@ loadPageWithAlerts2(html); } -} + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({ ".a > .t { }", ".b > .t { }", ".c > .t { }" }) + public void innerHtml() throws Exception { + final String html + = "<html><head><title>foo</title>\n" + + + "<style id='style_none'>.a > .t { }</style>\n" + + "<style type='text/test' id='style_text'>.b > .t { }</style>\n" + + "<style type='text/html' id='style_html'>.c > .t { }</style>\n" + + + "<script>\n" + + "function doTest() {\n" + + " style = document.getElementById('style_none');\n" + + " alert(style.innerHTML);\n" + + " style = document.getElementById('style_text');\n" + + " alert(style.innerHTML);\n" + + " style = document.getElementById('style_html');\n" + + " alert(style.innerHTML);\n" + + "}\n" + + "</script>\n" + + "</head><body onload='doTest()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } +} \ No newline at end of file |
From: <mgu...@us...> - 2013-02-01 14:00:31
|
Revision: 8073 http://sourceforge.net/p/htmlunit/code/8073 Author: mguillem Date: 2013-02-01 14:00:27 +0000 (Fri, 01 Feb 2013) Log Message: ----------- JavaScript: move method contains to Node, throw runtime exception on invalid argument. Issue 1480 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Node.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-02-01 13:36:15 UTC (rev 8072) +++ trunk/htmlunit/src/changes/changes.xml 2013-02-01 14:00:27 UTC (rev 8073) @@ -8,6 +8,9 @@ <body> <release version="2.12" date="???" description="Bugfixes, CSS3 Selectors"> + <action type="fix" dev="mguillem" issue="1480"> + JavaScript: move method contains to Node, throw runtime exception on invalid argument. + </action> <action type="fix" dev="rbri"> Method innerHTML does not encode entities for style tags. </action> 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-02-01 13:36:15 UTC (rev 8072) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Node.java 2013-02-01 14:00:27 UTC (rev 8073) @@ -1023,4 +1023,21 @@ return null; } + /** + * Checks whether the given element is contained within this object. + * @param element element object that specifies the element to check + * @return true if the element is contained within this object + */ + @JsxFunction({ @WebBrowser(IE), @WebBrowser(value = FF, minVersion = 10), @WebBrowser(CHROME) }) + public boolean contains(final Object element) { + if (!(element instanceof Node)) { + throw Context.reportRuntimeError("Could not convert JavaScript argument arg 0"); + } + for (Node parent = (Node) element; parent != null; parent = parent.getParentElement()) { + if (this == parent) { + return true; + } + } + return false; + } } 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-02-01 13:36:15 UTC (rev 8072) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java 2013-02-01 14:00:27 UTC (rev 8073) @@ -853,7 +853,7 @@ final StringBuilder buf = new StringBuilder(); final String tagName = getTagName(); - boolean isPlain = "SCRIPT".equals(tagName) || "STYLE".equals(tagName); + final boolean isPlain = "SCRIPT".equals(tagName) || "STYLE".equals(tagName); // we can't rely on DomNode.asXml because it adds indentation and new lines printChildren(buf, getDomNodeOrDie(), !isPlain); @@ -1964,21 +1964,6 @@ } /** - * Checks whether the given element is contained within this object. - * @param element element object that specifies the element to check - * @return true if the element is contained within this object - */ - @JsxFunction({ @WebBrowser(IE), @WebBrowser(value = FF, minVersion = 10), @WebBrowser(CHROME) }) - public boolean contains(final HTMLElement element) { - for (HTMLElement parent = element; parent != null; parent = (HTMLElement) parent.getParentElement()) { - if (this == parent) { - return true; - } - } - return false; - } - - /** * Sets the focus to this element. */ @JsxFunction Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java 2013-02-01 13:36:15 UTC (rev 8072) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java 2013-02-01 14:00:27 UTC (rev 8073) @@ -2177,7 +2177,7 @@ */ @Test @Alerts(FF3_6 = "exception", - DEFAULT = { "true", "true", "true", "false", "false", "false", "false", "true" }) + DEFAULT = { "true", "true", "true", "false", "false", "false", "false", "true", "true", "false", "false" }) public void contains() throws Exception { final String html = "<html><head>\n" @@ -2186,6 +2186,7 @@ + "try {\n" + " var div1 = document.getElementById('div1');\n" + " var div2 = document.getElementById('div2');\n" + + " var text = div2.firstChild;\n" + " var div3 = document.getElementById('div3');\n" + " alert(div1.contains(div1));\n" + " alert(div1.contains(div2));\n" @@ -2195,11 +2196,14 @@ + " alert(div3.contains(div1));\n" + " alert(div4.contains(div1));\n" + " alert(div2.contains(div3));\n" + + " alert(div2.contains(text));\n" + + " alert(div3.contains(text));\n" + + " alert(text.contains(div3));\n" + "} catch(e) { alert('exception'); }\n" + "}\n" + "</script></head><body onload='test()'>\n" + "<div id='div1'>\n" - + " <div id='div2'>\n" + + " <div id='div2'>hello\n" + " <div id='div3'>\n" + " </div>\n" + " </div>\n" @@ -2215,6 +2219,21 @@ * @throws Exception if the test fails */ @Test + @Alerts("exception") + public void contains_invalid_argument() throws Exception { + final String html = "<html><body><script>\n" + + "try {\n" + + " alert(document.body.contains([]));\n" + + "} catch(e) { alert('exception'); }\n" + + "</script></body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test @Alerts(DEFAULT = "undefined", IE = "defined") public void filters() throws Exception { final String html |
From: <rb...@us...> - 2013-02-01 18:26:33
|
Revision: 8078 http://sourceforge.net/p/htmlunit/code/8078 Author: rbri Date: 2013-02-01 18:26:28 +0000 (Fri, 01 Feb 2013) Log Message: ----------- enabled selector was missing in the list of supported pseudo selectors Modified Paths: -------------- 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/javascript/host/css/CSSStyleSheet.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2013-02-01 17:38:11 UTC (rev 8077) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2013-02-01 18:26:28 UTC (rev 8078) @@ -142,7 +142,7 @@ "focus", "lang", "first-child"); private static final Collection<String> CSS3_PSEUDO_CLASSES = new ArrayList<String>(Arrays.asList( - "checked", "disabled", "indeterminated", "root", "target", "not()", + "checked", "disabled", "enabled", "indeterminated", "root", "target", "not()", "nth-child()", "nth-last-child()", "nth-of-type()", "nth-last-of-type()", "last-child", "first-of-type", "last-of-type", "only-child", "only-of-type", "empty")); 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-02-01 17:38:11 UTC (rev 8077) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java 2013-02-01 18:26:28 UTC (rev 8078) @@ -810,4 +810,79 @@ loadPageWithAlerts2(html); } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = { "1", "id1", "1", "id1" }) + public void enabled() throws Exception { + final String html = "<html><head><title>First</title>\n" + + "<meta http-equiv='X-UA-Compatible' content='IE=9'>\n" + + "<script>\n" + + "function test() {\n" + + " if (document.querySelectorAll) {\n" + + " try {\n" + + " found = document.querySelectorAll('input:enabled');\n" + + " alert(found.length);\n" + + " alert(found[0].id);\n" + + " } catch(e) {alert('exception')}\n" + + " }\n" + + "\n" + + " document.getElementById('id2').focus();\n" + + "\n" + + " if (document.querySelectorAll) {\n" + + " try {\n" + + " found = document.querySelectorAll('input:enabled');\n" + + " alert(found.length);\n" + + " alert(found[0].id);\n" + + " } catch(e) {alert('exception')}\n" + + " }\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + " <input id='id1' >\n" + + " <input id='id2' disabled='disabled'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = { "1", "id2", "1", "id2" }) + public void disabled() throws Exception { + final String html = "<html><head><title>First</title>\n" + + "<meta http-equiv='X-UA-Compatible' content='IE=9'>\n" + + "<script>\n" + + "function test() {\n" + + " if (document.querySelectorAll) {\n" + + " try {\n" + + " found = document.querySelectorAll('input:disabled');\n" + + " alert(found.length);\n" + + " alert(found[0].id);\n" + + " } catch(e) {alert('exception')}\n" + + " }\n" + + "\n" + + " document.getElementById('id2').focus();\n" + + "\n" + + " if (document.querySelectorAll) {\n" + + " try {\n" + + " found = document.querySelectorAll('input:disabled');\n" + + " alert(found.length);\n" + + " alert(found[0].id);\n" + + " } catch(e) {alert('exception')}\n" + + " }\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + " <input id='id1' >\n" + + " <input id='id2' disabled='disabled'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } } |
From: <rb...@us...> - 2013-02-01 19:13:09
|
Revision: 8081 http://sourceforge.net/p/htmlunit/code/8081 Author: rbri Date: 2013-02-01 19:13:04 +0000 (Fri, 01 Feb 2013) Log Message: ----------- add DocumentFragment.querySelectorAll()/DocumentFragment.querySelector(). Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/DocumentFragment.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/DocumentFragmentTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-02-01 18:57:06 UTC (rev 8080) +++ trunk/htmlunit/src/changes/changes.xml 2013-02-01 19:13:04 UTC (rev 8081) @@ -8,6 +8,9 @@ <body> <release version="2.12" date="???" description="Bugfixes, CSS3 Selectors"> + <action type="add" dev="rbri"> + JavaScript: add DocumentFragment.querySelectorAll()/DocumentFragment.querySelector(). + </action> <action type="fix" dev="mguillem" issue="1480"> JavaScript: move method contains to Node, throw runtime exception on invalid argument. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/DocumentFragment.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/DocumentFragment.java 2013-02-01 18:57:06 UTC (rev 8080) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/DocumentFragment.java 2013-02-01 19:13:04 UTC (rev 8081) @@ -14,9 +14,18 @@ */ package com.gargoylesoftware.htmlunit.javascript.host; +import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.FF; import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.IE; +import java.util.ArrayList; +import java.util.List; + +import net.sourceforge.htmlunit.corejs.javascript.Context; + +import org.w3c.css.sac.CSSException; + import com.gargoylesoftware.htmlunit.html.DomDocumentFragment; +import com.gargoylesoftware.htmlunit.html.DomNode; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction; import com.gargoylesoftware.htmlunit.javascript.configuration.WebBrowser; @@ -107,4 +116,47 @@ public Object createTextNode(final String newData) { return getDocument().createTextNode(newData); } + + /** + * Retrieves all element nodes from descendants of the starting element node that match any selector + * within the supplied selector strings. + * The NodeList object returned by the querySelectorAll() method must be static, not live. + * @param selectors the selectors + * @return the static node list + */ + @JsxFunction({ @WebBrowser(value = IE, minVersion = 8), @WebBrowser(FF) }) + public StaticNodeList querySelectorAll(final String selectors) { + try { + final List<Node> nodes = new ArrayList<Node>(); + for (final DomNode domNode : getDomNodeOrDie().querySelectorAll(selectors)) { + nodes.add((Node) domNode.getScriptObject()); + } + return new StaticNodeList(nodes, this); + } + catch (final CSSException e) { + throw Context.reportRuntimeError("An invalid or illegal selector was specified (selector: '" + + selectors + "' error: " + e.getMessage() + ")."); + } + } + + /** + * Returns the first element within the document that matches the specified group of selectors. + * @param selectors the selectors + * @return null if no matches are found; otherwise, it returns the first matching element + */ + @JsxFunction({ @WebBrowser(value = IE, minVersion = 8), @WebBrowser(FF) }) + public Node querySelector(final String selectors) { + try { + final DomNode node = getDomNodeOrDie().querySelector(selectors); + if (node != null) { + return (Node) node.getScriptObject(); + } + return null; + } + catch (final CSSException e) { + throw Context.reportRuntimeError("An invalid or illegal selector was specified (selector: '" + + selectors + "' error: " + e.getMessage() + ")."); + } + } + } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/DocumentFragmentTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/DocumentFragmentTest.java 2013-02-01 18:57:06 UTC (rev 8080) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/DocumentFragmentTest.java 2013-02-01 19:13:04 UTC (rev 8081) @@ -29,6 +29,7 @@ * @version $Revision$ * @author Marc Guillemot * @author Ahmed Ashour + * @author Ronald Brill */ @RunWith(BrowserRunner.class) public class DocumentFragmentTest extends WebDriverTestCase { @@ -89,4 +90,35 @@ loadPageWithAlerts2(html); } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = { "1", "DIV", "DIV" }) + public void querySelector() throws Exception { + final String html = "<html><head><title>First</title>\n" + + "<meta http-equiv='X-UA-Compatible' content='IE=9'>\n" + + "<script>\n" + + "function test() {\n" + + " var frag = document.createDocumentFragment();\n" + + " var d = document.createElement('div');\n" + + " frag.appendChild(d);\n" + + + " if (document.querySelectorAll) {\n" + + " try {\n" + + " alert(frag.querySelectorAll('div').length);\n" + + " alert(frag.querySelectorAll('div')[0].tagName);\n" + + " alert(frag.querySelector('div').tagName);\n" + + " } catch(e) {alert('exception')}\n" + + " }\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + "<div id='root'>\n" + + "</div>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } } |
From: <rb...@us...> - 2013-02-02 08:20:44
|
Revision: 8082 http://sourceforge.net/p/htmlunit/code/8082 Author: rbri Date: 2013-02-02 08:20:41 +0000 (Sat, 02 Feb 2013) Log Message: ----------- another nth selector fix Modified Paths: -------------- 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/javascript/host/css/CSSStyleSheet.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2013-02-01 19:13:04 UTC (rev 8081) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2013-02-02 08:20:41 UTC (rev 8082) @@ -728,10 +728,15 @@ int a = 0; if (nIndex != -1) { String value = nth.substring(0, nIndex).trim(); - if (value.startsWith("+")) { - value = value.substring(1); + if ("-".equals(value)) { + a = -1; } - a = NumberUtils.toInt(value, 1); + else { + if (value.startsWith("+")) { + value = value.substring(1); + } + a = NumberUtils.toInt(value, 1); + } } String value = nth.substring(nIndex + 1).trim(); @@ -740,9 +745,11 @@ } final int b = NumberUtils.toInt(value, 0); if (a == 0) { - return index == b; + return index == b && b > 0; } - return (index - b) % a == 0; + + final double n = (index - b) / (double)a; + return (n >= 0) && (n % 1 == 0); } /** 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-02-01 19:13:04 UTC (rev 8081) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java 2013-02-02 08:20:41 UTC (rev 8082) @@ -105,7 +105,7 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = { "li2", "li1", "li2", "li1", "li3", "li1" }, IE8 = "exception") + @Alerts(DEFAULT = { "li2", "li1", "li2", "li1", "li3", "li1", "2", "li1", "li2" }, IE8 = "exception") public void nth_child() throws Exception { final String html = "<html><head><title>First</title>\n" + "<meta http-equiv='X-UA-Compatible' content='IE=9'>\n" @@ -119,6 +119,10 @@ + " alert(document.querySelectorAll('li:nth-child(2n+1)')[0].id);\n" + " alert(document.querySelectorAll('li:nth-child(2n+1)')[1].id);\n" + " alert(document.querySelectorAll('li:nth-child(2n-1)')[0].id);\n" + + + " alert(document.querySelectorAll('li:nth-child(-n+2)').length);\n" + + " alert(document.querySelectorAll('li:nth-child(-n+2)')[0].id);\n" + + " alert(document.querySelectorAll('li:nth-child(-n+2)')[1].id);\n" + " } catch(e) {alert('exception')}\n" + " }\n" + "}\n" |
From: <rb...@us...> - 2013-02-02 09:49:13
|
Revision: 8083 http://sourceforge.net/p/htmlunit/code/8083 Author: rbri Date: 2013-02-02 09:49:10 +0000 (Sat, 02 Feb 2013) Log Message: ----------- fixes for handling of empty prefix/postfix/substring selector Modified Paths: -------------- 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/javascript/host/css/CSSStyleSheet.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2013-02-02 08:20:41 UTC (rev 8082) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2013-02-02 09:49:10 UTC (rev 8083) @@ -436,15 +436,18 @@ static boolean selects(final BrowserVersion browserVersion, final Condition condition, final DomElement element) { if (condition instanceof PrefixAttributeConditionImpl) { final AttributeCondition ac = (AttributeCondition) condition; - return element.getAttribute(ac.getLocalName()).startsWith(ac.getValue()); + final String value = ac.getValue(); + return !"".equals(value) && element.getAttribute(ac.getLocalName()).startsWith(value); } if (condition instanceof SuffixAttributeConditionImpl) { final AttributeCondition ac = (AttributeCondition) condition; - return element.getAttribute(ac.getLocalName()).endsWith(ac.getValue()); + final String value = ac.getValue(); + return !"".equals(value) && element.getAttribute(ac.getLocalName()).endsWith(value); } if (condition instanceof SubstringAttributeConditionImpl) { final AttributeCondition ac = (AttributeCondition) condition; - return element.getAttribute(ac.getLocalName()).contains(ac.getValue()); + final String value = ac.getValue(); + return !"".equals(value) && element.getAttribute(ac.getLocalName()).contains(value); } switch (condition.getConditionType()) { case Condition.SAC_ID_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-02-02 08:20:41 UTC (rev 8082) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java 2013-02-02 09:49:10 UTC (rev 8083) @@ -340,6 +340,32 @@ * @throws Exception if an error occurs */ @Test + @Alerts({ "0" }) + public void prefixAttributeEmpty() throws Exception { + final String html = "<html><head><title>First</title>\n" + + "<meta http-equiv='X-UA-Compatible' content='IE=8'>\n" + + "<script>\n" + + "function test() {\n" + + " if (document.querySelectorAll) {\n" + + " var list = document.querySelectorAll('[id^=\"\"]');\n" + + " alert(list.length);\n" + + " }\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + " <div></div>\n" + + " <ul id='something'></ul>\n" + + " <p></p>\n" + + " <ul id='thing1'></ul>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test @Alerts({ "1", "something" }) public void suffixAttribute() throws Exception { final String html = "<html><head><title>First</title>\n" @@ -367,6 +393,32 @@ * @throws Exception if an error occurs */ @Test + @Alerts({ "0" }) + public void suffixAttributeEmpty() throws Exception { + final String html = "<html><head><title>First</title>\n" + + "<meta http-equiv='X-UA-Compatible' content='IE=8'>\n" + + "<script>\n" + + "function test() {\n" + + " if (document.querySelectorAll) {\n" + + " var list = document.querySelectorAll('[id$=\"\"]');\n" + + " alert(list.length);\n" + + " }\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + " <div></div>\n" + + " <ul id='something'></ul>\n" + + " <p></p>\n" + + " <ul id='thing2'></ul>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test @Alerts({ "2", "something", "thing2" }) public void substringAttribute() throws Exception { final String html = "<html><head><title>First</title>\n" @@ -391,10 +443,36 @@ loadPageWithAlerts2(html); } + /** * @throws Exception if an error occurs */ @Test + @Alerts({ "0" }) + public void substringAttributeEmpty() throws Exception { + final String html = "<html><head><title>First</title>\n" + + "<meta http-equiv='X-UA-Compatible' content='IE=8'>\n" + + "<script>\n" + + "function test() {\n" + + " if (document.querySelectorAll) {\n" + + " var list = document.querySelectorAll('[id*=\"\"]');\n" + + " alert(list.length);\n" + + " }\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + " <div></div>\n" + + " <ul id='something'></ul>\n" + + " <p></p>\n" + + " <ul id='thing2'></ul>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + /** + * @throws Exception if an error occurs + */ + @Test @Alerts({ "1", "ul2" }) public void generalAdjacentSelector() throws Exception { final String html = "<html><head><title>First</title>\n" |
From: <rb...@us...> - 2013-02-02 17:14:16
|
Revision: 8084 http://sourceforge.net/p/htmlunit/code/8084 Author: rbri Date: 2013-02-02 17:14:13 +0000 (Sat, 02 Feb 2013) Log Message: ----------- fixes for handling of empty oneof selector Modified Paths: -------------- 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/javascript/host/css/CSSStyleSheet.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2013-02-02 09:49:10 UTC (rev 8083) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2013-02-02 17:14:13 UTC (rev 8084) @@ -522,8 +522,12 @@ // || attribute.startsWith(condition + " ") || attriubte.endsWith(" " + condition) // || attribute.contains(" " + condition + " "); + final int conditionLength = condition.length(); + if (conditionLength < 1) { + return false; + } + final int attribLength = attribute.length(); - final int conditionLength = condition.length(); if (attribLength < conditionLength) { return false; } 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-02-02 09:49:10 UTC (rev 8083) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java 2013-02-02 17:14:13 UTC (rev 8084) @@ -443,7 +443,6 @@ loadPageWithAlerts2(html); } - /** * @throws Exception if an error occurs */ @@ -469,10 +468,65 @@ loadPageWithAlerts2(html); } + /** * @throws Exception if an error occurs */ @Test + @Alerts({ "2", "id1", "id2" }) + public void oneOfAttribute() throws Exception { + final String html = "<html><head><title>First</title>\n" + + "<meta http-equiv='X-UA-Compatible' content='IE=8'>\n" + + "<script>\n" + + "function test() {\n" + + " if (document.querySelectorAll) {\n" + + " var list = document.querySelectorAll('[title~=\"w2\"]');\n" + + " alert(list.length);\n" + + " alert(list[0].id);\n" + + " alert(list[1].id);\n" + + " }\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + " <div></div>\n" + + " <ul id='id1' title='w1 w2 w3'></ul>\n" + + " <p id='id2' title='w2'></p>\n" + + " <ul id='id3' title='w1w2 w3'></ul>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts({ "0" }) + public void oneOfAttributeEmpty() throws Exception { + final String html = "<html><head><title>First</title>\n" + + "<meta http-equiv='X-UA-Compatible' content='IE=8'>\n" + + "<script>\n" + + "function test() {\n" + + " if (document.querySelectorAll) {\n" + + " var list = document.querySelectorAll('[title~=\"\"]');\n" + + " alert(list.length);\n" + + " }\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + " <div></div>\n" + + " <ul id='id1' title='w1 w2 w3'></ul>\n" + + " <p id='id2' title='w2'></p>\n" + + " <ul id='id3' title='w1w2 w3'></ul>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test @Alerts({ "1", "ul2" }) public void generalAdjacentSelector() throws Exception { final String html = "<html><head><title>First</title>\n" |
From: <rb...@us...> - 2013-02-02 18:06:58
|
Revision: 8085 http://sourceforge.net/p/htmlunit/code/8085 Author: rbri Date: 2013-02-02 18:06:54 +0000 (Sat, 02 Feb 2013) Log Message: ----------- Support for CSS pseudo selector ':target' added. Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml 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/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-02-02 17:14:13 UTC (rev 8084) +++ trunk/htmlunit/src/changes/changes.xml 2013-02-02 18:06:54 UTC (rev 8085) @@ -8,6 +8,9 @@ <body> <release version="2.12" date="???" description="Bugfixes, CSS3 Selectors"> + <action type="fix" dev="rbri"> + Support for CSS pseudo selector ':target' added. + </action> <action type="add" dev="rbri"> JavaScript: add DocumentFragment.querySelectorAll()/DocumentFragment.querySelector(). </action> 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-02-02 17:14:13 UTC (rev 8084) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2013-02-02 18:06:54 UTC (rev 8085) @@ -686,6 +686,10 @@ else if ("empty".equals(value)) { return element.getFirstChild() == null; } + else if ("target".equals(value)) { + final String ref = element.getPage().getUrl().getRef(); + return StringUtils.isNotBlank(ref) && ref.equals(element.getId()); + } else if (value.startsWith("not(")) { final String selectors = value.substring(value.indexOf('(') + 1, value.length() - 1); final AtomicBoolean errorOccured = new AtomicBoolean(false); 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-02-02 17:14:13 UTC (rev 8084) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java 2013-02-02 18:06:54 UTC (rev 8085) @@ -24,6 +24,7 @@ import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.WebDriverTestCase; import com.gargoylesoftware.htmlunit.html.HtmlPageTest; +import com.gargoylesoftware.htmlunit.util.UrlUtils; /** * Tests for CSS selectors. @@ -340,7 +341,7 @@ * @throws Exception if an error occurs */ @Test - @Alerts({ "0" }) + @Alerts("0") public void prefixAttributeEmpty() throws Exception { final String html = "<html><head><title>First</title>\n" + "<meta http-equiv='X-UA-Compatible' content='IE=8'>\n" @@ -393,7 +394,7 @@ * @throws Exception if an error occurs */ @Test - @Alerts({ "0" }) + @Alerts("0") public void suffixAttributeEmpty() throws Exception { final String html = "<html><head><title>First</title>\n" + "<meta http-equiv='X-UA-Compatible' content='IE=8'>\n" @@ -447,7 +448,7 @@ * @throws Exception if an error occurs */ @Test - @Alerts({ "0" }) + @Alerts("0") public void substringAttributeEmpty() throws Exception { final String html = "<html><head><title>First</title>\n" + "<meta http-equiv='X-UA-Compatible' content='IE=8'>\n" @@ -501,7 +502,7 @@ * @throws Exception if an error occurs */ @Test - @Alerts({ "0" }) + @Alerts("0") public void oneOfAttributeEmpty() throws Exception { final String html = "<html><head><title>First</title>\n" + "<meta http-equiv='X-UA-Compatible' content='IE=8'>\n" @@ -1000,4 +1001,86 @@ loadPageWithAlerts2(html); } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = { "1", "id2" }, IE = "exception") + public void target() throws Exception { + final String html = "<html><head><title>First</title>\n" + + "<meta http-equiv='X-UA-Compatible' content='IE=9'>\n" + + "<script>\n" + + "function test() {\n" + + " if (document.querySelectorAll) {\n" + + " try {\n" + + " found = document.querySelectorAll(':target');\n" + + " alert(found.length);\n" + + " alert(found[0].id);\n" + + " } catch(e) {alert('exception')}\n" + + " }\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + " <input id='id1' >\n" + + " <input id='id2'>\n" + + "</body></html>"; + + getMockWebConnection().setDefaultResponse(html); + loadPageWithAlerts2(UrlUtils.getUrlWithNewRef(URL_FIRST, "id2")); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = { "0" }, IE = "exception") + public void targetNoHash() throws Exception { + final String html = "<html><head><title>First</title>\n" + + "<meta http-equiv='X-UA-Compatible' content='IE=9'>\n" + + "<script>\n" + + "function test() {\n" + + " if (document.querySelectorAll) {\n" + + " try {\n" + + " found = document.querySelectorAll(':target');\n" + + " alert(found.length);\n" + + " } catch(e) {alert('exception')}\n" + + " }\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + " <input id='id1' >\n" + + " <input id='id2'>\n" + + "</body></html>"; + + getMockWebConnection().setDefaultResponse(html); + loadPageWithAlerts2(URL_FIRST); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = { "0" }, IE = "exception") + public void targetUnknown() throws Exception { + final String html = "<html><head><title>First</title>\n" + + "<meta http-equiv='X-UA-Compatible' content='IE=9'>\n" + + "<script>\n" + + "function test() {\n" + + " if (document.querySelectorAll) {\n" + + " try {\n" + + " found = document.querySelectorAll(':target');\n" + + " alert(found.length);\n" + + " } catch(e) {alert('exception')}\n" + + " }\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + " <input id='id1' >\n" + + " <input id='id2'>\n" + + "</body></html>"; + + getMockWebConnection().setDefaultResponse(html); + loadPageWithAlerts2(UrlUtils.getUrlWithNewRef(URL_FIRST, "id3")); + } } |
From: <rb...@us...> - 2013-02-02 19:22:21
|
Revision: 8086 http://sourceforge.net/p/htmlunit/code/8086 Author: rbri Date: 2013-02-02 19:22:17 +0000 (Sat, 02 Feb 2013) Log Message: ----------- tescase for script.innerHTML added (including a minor output fix for IE) Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLScriptElementTest.java 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-02-02 18:06:54 UTC (rev 8085) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java 2013-02-02 19:22:17 UTC (rev 8086) @@ -34,6 +34,7 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_CLIENT_LEFT_TOP_ZERO; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ELEMENT_EXTENT_WITHOUT_PADDING; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_INNER_HTML_REDUCE_WHITESPACES; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_NATIVE_FUNCTION_TOSTRING_NEW_LINE; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_OFFSET_PARENT_THROWS_NOT_ATTACHED; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_SET_ATTRIBUTE_CONSIDERS_ATTR_FOR_CLASS_AS_REAL; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.QUERYSELECTORALL_NOT_IN_QUIRKS; @@ -853,8 +854,13 @@ final StringBuilder buf = new StringBuilder(); final String tagName = getTagName(); - final boolean isPlain = "SCRIPT".equals(tagName) || "STYLE".equals(tagName); + boolean isPlain = "SCRIPT".equals(tagName); + if(isPlain && getBrowserVersion().hasFeature(JS_NATIVE_FUNCTION_TOSTRING_NEW_LINE)) { + buf.append("\r\n"); + } + isPlain = isPlain || "STYLE".equals(tagName); + // we can't rely on DomNode.asXml because it adds indentation and new lines printChildren(buf, getDomNodeOrDie(), !isPlain); return buf.toString(); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLScriptElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLScriptElementTest.java 2013-02-02 18:06:54 UTC (rev 8085) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLScriptElementTest.java 2013-02-02 19:22:17 UTC (rev 8086) @@ -35,6 +35,7 @@ * @author Ahmed Ashour * @author Marc Guillemot * @author Frank Danek + * @author Ronald Brill */ @RunWith(BrowserRunner.class) public class HTMLScriptElementTest extends WebDriverTestCase { @@ -868,4 +869,34 @@ assertEquals(getExpectedAlerts()[0], webDriver.findElement(By.id("myTextarea")).getAttribute("value")); } + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "function foo() { return a > b}", "function mce() { return a > b}" }, + IE = { "\r\nfunction foo() { return a > b}", "function mce() { return a > b}" }) + public void innerHtml() throws Exception { + final String html + = "<html><head><title>foo</title>\n" + + + "<script id='script1'>function foo() { return a > b}</script>\n" + + + "<script>\n" + + "function doTest() {\n" + + " script = document.getElementById('script1');\n" + + " alert(script.innerHTML);\n" + + + " script = document.getElementById('mce');\n" + + " alert(script.innerHTML);\n" + + + "}\n" + + "</script>\n" + + "</head><body onload='doTest()'>\n" + // this is done by TinyMce + + "<script>document.write('<mce:script id=\"mce\">function mce() { return a > b}</mce:script>');</script>\n" + + + "</body></html>"; + + loadPageWithAlerts2(html); + } } |
From: <rb...@us...> - 2013-02-03 15:09:20
|
Revision: 8089 http://sourceforge.net/p/htmlunit/code/8089 Author: rbri Date: 2013-02-03 15:09:16 +0000 (Sun, 03 Feb 2013) Log Message: ----------- checkstyle fixes Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLStyleElementTest.java 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-02-02 20:13:39 UTC (rev 8088) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2013-02-03 15:09:16 UTC (rev 8089) @@ -759,7 +759,7 @@ return index == b && b > 0; } - final double n = (index - b) / (double)a; + final double n = (index - b) / (double) a; return (n >= 0) && (n % 1 == 0); } 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-02-02 20:13:39 UTC (rev 8088) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java 2013-02-03 15:09:16 UTC (rev 8089) @@ -855,7 +855,7 @@ final String tagName = getTagName(); boolean isPlain = "SCRIPT".equals(tagName); - if(isPlain && getBrowserVersion().hasFeature(JS_NATIVE_FUNCTION_TOSTRING_NEW_LINE)) { + if (isPlain && getBrowserVersion().hasFeature(JS_NATIVE_FUNCTION_TOSTRING_NEW_LINE)) { buf.append("\r\n"); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLStyleElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLStyleElementTest.java 2013-02-02 20:13:39 UTC (rev 8088) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLStyleElementTest.java 2013-02-03 15:09:16 UTC (rev 8089) @@ -108,4 +108,4 @@ loadPageWithAlerts2(html); } -} \ No newline at end of file +} |
From: <mgu...@us...> - 2013-02-04 12:56:11
|
Revision: 8090 http://sourceforge.net/p/htmlunit/code/8090 Author: mguillem Date: 2013-02-04 12:56:08 +0000 (Mon, 04 Feb 2013) Log Message: ----------- - XHR error handler should be called, when CORS header is missing - avoid exception when reading responseXML from a XHR where the requested host does't exist Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestCORSTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java 2013-02-03 15:09:16 UTC (rev 8089) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java 2013-02-04 12:56:08 UTC (rev 8090) @@ -336,6 +336,9 @@ if (webResponse_ == null) { return null; // send() has not been called } + if (webResponse_ instanceof NetworkErrorWebResponse) { + return null; + } final String contentType = webResponse_.getContentType(); if (contentType.isEmpty() || contentType.contains("xml")) { try { @@ -667,8 +670,7 @@ if (LOG.isDebugEnabled()) { LOG.debug("No permitted \"Access-Control-Allow-Origin\" header for URL " + webRequest_.getUrl()); } - Context.throwAsScriptRuntimeEx( - new RuntimeException("No permitted \"Access-Control-Allow-Origin\" header.")); + throw new IOException("No permitted \"Access-Control-Allow-Origin\" header."); } } catch (final IOException e) { @@ -677,7 +679,12 @@ } webResponse_ = new NetworkErrorWebResponse(webRequest_); setState(STATE_COMPLETED, context); - processError(context); + if (async_) { + processError(context); + } + else { + Context.throwAsScriptRuntimeEx(e); + } } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestCORSTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestCORSTest.java 2013-02-03 15:09:16 UTC (rev 8089) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestCORSTest.java 2013-02-04 12:56:08 UTC (rev 8090) @@ -50,6 +50,29 @@ * @throws Exception if the test fails. */ @Test + @Alerts(DEFAULT = "error", IE = { }) + public void noCorsHeaderCallsErrorHandler() throws Exception { + final String html = "<html><head>\n" + + "<script>\n" + + "var xhr = " + XHRInstantiation_ + ";\n" + + "function test() {\n" + + " try {\n" + + " var url = '" + URL_THIRD + "';\n" + + " xhr.open('GET', url, true);\n" + + " xhr.onerror = function() { alert('error'); };\n" + + " xhr.send();\n" + + " } catch(e) { alert('exception'); }\n" + + "}\n" + + "</script>\n" + + "</head>\n" + + "<body onload='test()'></body></html>"; + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails. + */ + @Test @Alerts(IE = { "4", "200", "No Origin!" }, DEFAULT = { "4", "200", "§§URL§§" }) public void simple() throws Exception { SimpleServerServlet.ACCESS_CONTROL_ALLOW_ORIGIN_ = "*"; Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestTest.java 2013-02-03 15:09:16 UTC (rev 8089) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequestTest.java 2013-02-04 12:56:08 UTC (rev 8090) @@ -229,6 +229,34 @@ * @throws Exception if the test fails */ @Test + @Alerts("received: null") + public void responseXML_siteNotExisting() throws Exception { + final String html = "<html><head>\n" + + "<script>\n" + + "function test() {\n" + + " var request;\n" + + " if (window.XMLHttpRequest)\n" + + " request = new XMLHttpRequest();\n" + + " else if (window.ActiveXObject)\n" + + " request = new ActiveXObject('Microsoft.XMLHTTP');\n" + + "try {\n" + + " request.open('GET', 'http://this.doesnt.exist/foo.xml', false);\n" + + " request.send('');\n" + + "} catch(e) {\n" + + " alert('received: ' + request.responseXML);\n" + + "}\n" + + "}\n" + + "</script>\n" + + "</head>\n" + + "<body onload='test()'></body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test public void sendNull() throws Exception { final String html = "<html><head>\n" + "<script>\n" |
From: <mgu...@us...> - 2013-02-04 12:57:09
|
Revision: 8091 http://sourceforge.net/p/htmlunit/code/8091 Author: mguillem Date: 2013-02-04 12:57:07 +0000 (Mon, 04 Feb 2013) Log Message: ----------- compareDocumentPosition: throw runtime exception when argument's type is wrong Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Node.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/NodeTest.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-02-04 12:56:08 UTC (rev 8090) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Node.java 2013-02-04 12:57:07 UTC (rev 8091) @@ -946,8 +946,11 @@ * @see org.w3c.dom.Node#compareDocumentPosition(org.w3c.dom.Node) */ @JsxFunction(@WebBrowser(FF)) - public short compareDocumentPosition(final Node node) { - return getDomNodeOrDie().compareDocumentPosition(node.getDomNodeOrDie()); + public short compareDocumentPosition(final Object node) { + if (!(node instanceof Node)) { + throw Context.reportRuntimeError("Could not convert JavaScript argument arg 0"); + } + return getDomNodeOrDie().compareDocumentPosition(((Node) node).getDomNodeOrDie()); } /** Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/NodeTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/NodeTest.java 2013-02-04 12:56:08 UTC (rev 8090) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/NodeTest.java 2013-02-04 12:57:07 UTC (rev 8091) @@ -617,7 +617,7 @@ */ @Test @Browsers(FF) - @Alerts({ "0", "20", "20", "4", "10", "10", "2", "20" }) + @Alerts({ "0", "20", "20", "4", "10", "10", "2", "20", "exception" }) public void compareDocumentPosition() throws Exception { final String html = "<html><head>\n" @@ -634,6 +634,9 @@ + " alert(div3.compareDocumentPosition(div1));\n" + " alert(div4.compareDocumentPosition(div1));\n" + " alert(div2.compareDocumentPosition(div3));\n" + + " try {\n" + + " alert(div2.compareDocumentPosition({}));\n" + + " } catch(e) { alert('exception'); }\n" + "}\n" + "</script></head><body onload='test()'>\n" + "<div id='div1'>\n" |