From: <rb...@us...> - 2013-09-28 10:51:57
|
Revision: 8523 http://sourceforge.net/p/htmlunit/code/8523 Author: rbri Date: 2013-09-28 10:51:52 +0000 (Sat, 28 Sep 2013) Log Message: ----------- caching now works for encoded URLs also. Issue 1352 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/Cache.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.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/CacheTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-09-27 21:15:35 UTC (rev 8522) +++ trunk/htmlunit/src/changes/changes.xml 2013-09-28 10:51:52 UTC (rev 8523) @@ -8,6 +8,9 @@ <body> <release version="2.13" date="???" description="Bugfixes"> + <action type="fix" dev="rbri" issue="1352"> + Caching now works for encoded URLs also. + </action> <action type="update" dev="asashour"> Deprecate KeyDataPair. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/Cache.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/Cache.java 2013-09-27 21:15:35 UTC (rev 8522) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/Cache.java 2013-09-28 10:51:52 UTC (rev 8523) @@ -15,6 +15,7 @@ package com.gargoylesoftware.htmlunit; import java.io.Serializable; +import java.net.URL; import java.util.Collections; import java.util.Date; import java.util.HashMap; @@ -89,15 +90,14 @@ * Caches the specified object, if the corresponding request and response objects indicate * that it is cacheable. * - * @param request the request corresponding to the specified compiled script + * @param url the cache key * @param response the response corresponding to the specified compiled script * @param toCache the object that is to be cached, if possible (may be for instance a compiled script or * simply a WebResponse) */ - public void cacheIfPossible(final WebRequest request, final WebResponse response, final Object toCache) { - if (isCacheable(request, response)) { - final String url = response.getWebRequest().getUrl().toString(); - final Entry entry = new Entry(url, toCache); + public void cacheIfPossible(final URL url, final WebResponse response, final Object toCache) { + if (isCacheable(response)) { + final Entry entry = new Entry(url.toString(), toCache); entries_.put(entry.key_, entry); deleteOverflow(); } @@ -135,11 +135,10 @@ /** * Determines if the specified response can be cached. * - * @param request the performed request * @param response the received response * @return <code>true</code> if the response can be cached */ - protected boolean isCacheable(final WebRequest request, final WebResponse response) { + protected boolean isCacheable(final WebResponse response) { return HttpMethod.GET == response.getWebRequest().getHttpMethod() && !isDynamicContent(response); } @@ -205,14 +204,11 @@ * Returns the cached object corresponding to the specified request. If there is * no corresponding cached object, this method returns <tt>null</tt>. * - * @param request the request whose corresponding cached compiled script is sought + * @param url the cache key * @return the cached object corresponding to the specified request if any */ - public Object getCachedObject(final WebRequest request) { - if (HttpMethod.GET != request.getHttpMethod()) { - return null; - } - final Entry cachedEntry = entries_.get(request.getUrl().toString()); + public Object getCachedObject(final URL url) { + final Entry cachedEntry = entries_.get(url.toString()); if (cachedEntry == null) { return null; } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2013-09-27 21:15:35 UTC (rev 8522) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2013-09-28 10:51:52 UTC (rev 8523) @@ -1275,8 +1275,11 @@ addDefaultHeaders(webRequest); // Retrieve the response, either from the cache or from the server. - final Object fromCache = getCache().getCachedObject(webRequest); final WebResponse webResponse; + Object fromCache = null; + if (HttpMethod.GET == webRequest.getHttpMethod()) { + fromCache = getCache().getCachedObject(url); + } if (fromCache != null && fromCache instanceof WebResponse) { webResponse = new WebResponseFromCache((WebResponse) fromCache, webRequest); } @@ -1287,7 +1290,7 @@ catch (final NoHttpResponseException e) { return new WebResponse(responseDataNoHttpResponse_, webRequest, 0); } - getCache().cacheIfPossible(webRequest, webResponse, webResponse); + getCache().cacheIfPossible(url, webResponse, webResponse); } // Continue according to the HTTP status code. Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2013-09-27 21:15:35 UTC (rev 8522) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2013-09-28 10:51:52 UTC (rev 8523) @@ -1089,7 +1089,7 @@ request.setAdditionalHeaders(new HashMap<String, String>(referringRequest.getAdditionalHeaders())); request.setAdditionalHeader("Referer", referringRequest.getUrl().toString()); - final Object cachedScript = cache.getCachedObject(request); + final Object cachedScript = cache.getCachedObject(url); if (cachedScript instanceof Script) { return (Script) cachedScript; } @@ -1142,7 +1142,7 @@ final JavaScriptEngine javaScriptEngine = client.getJavaScriptEngine(); final Script script = javaScriptEngine.compile(this, scriptCode, url.toExternalForm(), 1); if (script != null) { - cache.cacheIfPossible(request, response, script); + cache.cacheIfPossible(url, response, script); } return script; 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-09-27 21:15:35 UTC (rev 8522) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2013-09-28 10:51:52 UTC (rev 8523) @@ -72,6 +72,7 @@ import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.Cache; import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; +import com.gargoylesoftware.htmlunit.HttpMethod; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebRequest; import com.gargoylesoftware.htmlunit.WebResponse; @@ -301,11 +302,14 @@ request.setAdditionalHeader("Referer", referer); } - uri = request.getUrl().toExternalForm(); + final URL reqUrl = request.getUrl(); + Object fromCache = null; final Cache cache = client.getCache(); - final Object fromCache = cache.getCachedObject(request); + if (HttpMethod.GET == request.getHttpMethod()) { + fromCache = cache.getCachedObject(reqUrl); + } if (fromCache != null && fromCache instanceof org.w3c.dom.css.CSSStyleSheet) { - sheet = new CSSStyleSheet(element, (org.w3c.dom.css.CSSStyleSheet) fromCache, uri); + sheet = new CSSStyleSheet(element, (org.w3c.dom.css.CSSStyleSheet) fromCache, reqUrl.toExternalForm()); } else { final WebResponse response = client.loadWebResponse(request); @@ -317,7 +321,7 @@ source.setByteStream(response.getContentAsStream()); source.setEncoding(response.getContentCharset()); sheet = new CSSStyleSheet(element, source, uri); - cache.cacheIfPossible(request, response, sheet.getWrappedSheet()); + cache.cacheIfPossible(reqUrl, response, sheet.getWrappedSheet()); } } catch (final FailingHttpStatusCodeException e) { Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CacheTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CacheTest.java 2013-09-27 21:15:35 UTC (rev 8522) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CacheTest.java 2013-09-28 10:51:52 UTC (rev 8523) @@ -138,6 +138,63 @@ *@throws Exception if the test fails */ @Test + public void usageUrlEncoded() throws Exception { + final String content = "<html>\n" + + "<head>\n" + + " <title>page 1</title>\n" + + " <script src='foo1.js'></script>\n" + + " <script src='foo2.js?foo[1]=bar/baz'></script>\n" + + "</head>\n" + + "<body>\n" + + " <a href='page2.html'>to page 2</a>\n" + + "</body>\n" + + "</html>"; + + final String content2 = "<html>\n2" + + "<head>\n" + + " <title>page 2</title>\n" + + " <script src='foo2.js?foo[1]=bar/baz'></script>\n" + + "</head>\n" + + "<body>\n" + + " <a href='page1.html'>to page 1</a>\n" + + "</body>\n" + + "</html>"; + + final String script1 = "alert('in foo1');"; + final String script2 = "alert('in foo2');"; + + final URL urlPage1 = new URL(URL_FIRST, "page1.html"); + getMockWebConnection().setResponse(urlPage1, content); + final URL urlPage2 = new URL(URL_FIRST, "page2.html"); + getMockWebConnection().setResponse(urlPage2, content2); + + final List<NameValuePair> headers = new ArrayList<NameValuePair>(); + headers.add(new NameValuePair("Last-Modified", "Sun, 15 Jul 2007 20:46:27 GMT")); + getMockWebConnection().setResponse(new URL(URL_FIRST, "foo1.js"), script1, + 200, "ok", JAVASCRIPT_MIME_TYPE, headers); + getMockWebConnection().setDefaultResponse(script2, 200, "ok", JAVASCRIPT_MIME_TYPE, headers); + + final WebClient webClient = getWebClientWithMockWebConnection(); + + final List<String> collectedAlerts = new ArrayList<String>(); + webClient.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); + + final HtmlPage page1 = webClient.getPage(urlPage1); + final String[] expectedAlerts = {"in foo1", "in foo2"}; + assertEquals(expectedAlerts, collectedAlerts); + + collectedAlerts.clear(); + page1.getAnchors().get(0).click(); + + assertEquals(new String[] {"in foo2"}, collectedAlerts); + assertEquals("no request for scripts should have been performed", + urlPage2, getMockWebConnection().getLastWebRequest().getUrl()); + } + + /** + *@throws Exception if the test fails + */ + @Test public void maxSizeMaintained() throws Exception { final String html = "<html><head><title>page 1</title>\n" + "<script src='foo1.js' type='text/javascript'/>\n" |
From: <rb...@us...> - 2013-09-28 12:19:17
|
Revision: 8524 http://sourceforge.net/p/htmlunit/code/8524 Author: rbri Date: 2013-09-28 12:19:14 +0000 (Sat, 28 Sep 2013) Log Message: ----------- Some debug log output added if HTMLDocument.canAlreadyBeParsed(String) returns false. Issue 1524 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-09-28 10:51:52 UTC (rev 8523) +++ trunk/htmlunit/src/changes/changes.xml 2013-09-28 12:19:14 UTC (rev 8524) @@ -8,6 +8,9 @@ <body> <release version="2.13" date="???" description="Bugfixes"> + <action type="fix" dev="rbri" issue="1524"> + Some debug log output added if HTMLDocument.canAlreadyBeParsed(String) returns false. + </action> <action type="fix" dev="rbri" issue="1352"> Caching now works for encoded URLs also. </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-09-28 10:51:52 UTC (rev 8523) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java 2013-09-28 12:19:14 UTC (rev 8524) @@ -741,6 +741,15 @@ index++; } if (scriptTagCount > 0 || tagState != PARSING_STATUS.OUTSIDE) { + if (LOG.isDebugEnabled()) { + final StringBuffer message = new StringBuffer(); + message.append("canAlreadyBeParsed() retruns false for content: '"); + message.append(StringUtils.abbreviateMiddle(content, ".", 100)); + message.append("' (scriptTagCount: " + scriptTagCount); + message.append(" tagState: " + tagState); + message.append(")"); + LOG.debug(message.toString()); + } return false; } |
From: <rb...@us...> - 2013-09-29 17:57:32
|
Revision: 8529 http://sourceforge.net/p/htmlunit/code/8529 Author: rbri Date: 2013-09-29 17:57:26 +0000 (Sun, 29 Sep 2013) Log Message: ----------- use the correct accept header (work in progress) Issue 1245 Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebRequest.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImage.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersion2Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2013-09-29 11:48:27 UTC (rev 8528) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2013-09-29 17:57:26 UTC (rev 8529) @@ -84,6 +84,9 @@ private final Set<PluginConfiguration> plugins_ = new HashSet<PluginConfiguration>(); private final Set<BrowserVersionFeatures> features_ = EnumSet.noneOf(BrowserVersionFeatures.class); private final String nickname_; + private String htmlAcceptHeader_; + private String imgAcceptHeader_; + private String cssAcceptHeader_; /** * Application name for the Internet Explorer series of browsers. @@ -201,6 +204,18 @@ FIREFOX_10.initDefaultFeatures(); FIREFOX_17.initDefaultFeatures(); + FIREFOX_3_6.setHtmlAcceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); + FIREFOX_3_6.setImgAcceptHeader("image/png,image/*;q=0.8,*/*;q=0.5"); + FIREFOX_3_6.setCssAcceptHeader("text/css,*/*;q=0.1"); + FIREFOX_10.setHtmlAcceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); + FIREFOX_10.setImgAcceptHeader("image/png,image/*;q=0.8,*/*;q=0.5"); + FIREFOX_10.setCssAcceptHeader("text/css,*/*;q=0.1"); + FIREFOX_17.setHtmlAcceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); + FIREFOX_17.setImgAcceptHeader("image/png,image/*;q=0.8,*/*;q=0.5"); + FIREFOX_17.setCssAcceptHeader("text/css,*/*;q=0.1"); + + INTERNET_EXPLORER_8.setHtmlAcceptHeader("image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, */*"); + final PluginConfiguration flash = new PluginConfiguration("Shockwave Flash", "Shockwave Flash 9.0 r31", "libflashplayer.so"); flash.getMimeTypes().add(new PluginConfiguration.MimeType("application/x-shockwave-flash", @@ -274,6 +289,10 @@ userAgent_ = userAgent; browserVersionNumeric_ = browserVersionNumeric; nickname_ = nickname; + htmlAcceptHeader_ = "*/*"; + imgAcceptHeader_ = "*/*"; + cssAcceptHeader_ = "*/*"; + if (features != null) { features_.addAll(Arrays.asList(features)); } @@ -465,6 +484,33 @@ } /** + * Returns the value used by the browser for the accept header + * if requesting a page. + * @return the accept header string + */ + public String getHtmlAcceptHeader() { + return htmlAcceptHeader_; + } + + /** + * Returns the value used by the browser for the accept header + * if requesting an image. + * @return the accept header string + */ + public String getImgAcceptHeader() { + return imgAcceptHeader_; + } + + /** + * Returns the value used by the browser for the accept header + * if requesting a css declaration. + * @return the accept header string + */ + public String getCssAcceptHeader() { + return cssAcceptHeader_; + } + + /** * @param applicationCodeName the applicationCodeName to set */ public void setApplicationCodeName(final String applicationCodeName) { @@ -549,6 +595,27 @@ } /** + * @param htmlAcceptHeader the accept header to be used when retrieving pages + */ + public void setHtmlAcceptHeader(final String htmlAcceptHeader) { + htmlAcceptHeader_ = htmlAcceptHeader; + } + + /** + * @param imgAcceptHeader the accept header to be used when retrieving images + */ + public void setImgAcceptHeader(final String imgAcceptHeader) { + imgAcceptHeader_ = imgAcceptHeader; + } + + /** + * @param cssAcceptHeader the accept header to be used when retrieving pages + */ + public void setCssAcceptHeader(final String cssAcceptHeader) { + cssAcceptHeader_ = cssAcceptHeader; + } + + /** * @return the browserVersionNumeric */ public float getBrowserVersionNumeric() { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2013-09-29 11:48:27 UTC (rev 8528) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2013-09-29 17:57:26 UTC (rev 8529) @@ -373,7 +373,8 @@ */ @SuppressWarnings("unchecked") public <P extends Page> P getPage(final URL url) throws IOException, FailingHttpStatusCodeException { - return (P) getPage(getCurrentWindow().getTopWindow(), new WebRequest(url)); + return (P) getPage(getCurrentWindow().getTopWindow(), + new WebRequest(url, getBrowserVersion().getHtmlAcceptHeader())); } /** @@ -781,7 +782,7 @@ final HtmlPage openerPage = (HtmlPage) opener.getEnclosedPage(); if (url != null) { try { - final WebRequest request = new WebRequest(url); + final WebRequest request = new WebRequest(url, getBrowserVersion().getHtmlAcceptHeader()); if (getBrowserVersion().hasFeature(DIALOGWINDOW_REFERER) && openerPage != null) { final String referer = openerPage.getUrl().toExternalForm(); @@ -910,7 +911,7 @@ fireWindowOpened(new WebWindowEvent(window, WebWindowEvent.OPEN, null, null)); final HtmlPage openerPage = (HtmlPage) opener.getEnclosedPage(); - final WebRequest request = new WebRequest(url); + final WebRequest request = new WebRequest(url, getBrowserVersion().getHtmlAcceptHeader()); if (getBrowserVersion().hasFeature(DIALOGWINDOW_REFERER) && openerPage != null) { final String referer = openerPage.getUrl().toExternalForm(); request.setAdditionalHeader("Referer", referer); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebRequest.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebRequest.java 2013-09-29 11:48:27 UTC (rev 8528) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebRequest.java 2013-09-29 17:57:26 UTC (rev 8529) @@ -66,14 +66,23 @@ /** * Instantiates a {@link WebRequest} for the specified URL. * @param url the target URL + * @param acceptHeader the accept header to use */ - public WebRequest(final URL url) { + public WebRequest(final URL url, final String acceptHeader) { setUrl(url); - setAdditionalHeader("Accept", "*/*"); + setAdditionalHeader("Accept", acceptHeader); setAdditionalHeader("Accept-Encoding", "gzip, deflate"); } /** + * Instantiates a {@link WebRequest} for the specified URL. + * @param url the target URL + */ + public WebRequest(final URL url) { + this(url, "*/*"); + } + + /** * Instantiates a {@link WebRequest} for the specified URL using the proxy configuration from the * specified original request. * @param originalRequest the original request Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImage.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImage.java 2013-09-29 11:48:27 UTC (rev 8528) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImage.java 2013-09-29 17:57:26 UTC (rev 8529) @@ -391,7 +391,8 @@ final WebClient webclient = page.getWebClient(); final URL url = page.getFullyQualifiedUrl(getSrcAttribute()); - final WebRequest request = new WebRequest(url); + final String accept = getPage().getWebClient().getBrowserVersion().getImgAcceptHeader(); + final WebRequest request = new WebRequest(url, accept); request.setAdditionalHeader("Referer", page.getUrl().toExternalForm()); imageWebResponse_ = webclient.loadWebResponse(request); imageReader_ = null; 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-09-29 11:48:27 UTC (rev 8528) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2013-09-29 17:57:26 UTC (rev 8529) @@ -290,14 +290,16 @@ try { // Retrieve the associated content and respect client settings regarding failing HTTP status codes. final WebRequest request; + final String accept = page.getWebClient().getBrowserVersion().getCssAcceptHeader(); final WebClient client = page.getWebClient(); if (link != null) { // Use link. request = link.getWebRequest(); + request.setAdditionalHeader("Accept", accept); } else { // Use href. - request = new WebRequest(new URL(url)); + request = new WebRequest(new URL(url), accept); final String referer = page.getUrl().toExternalForm(); request.setAdditionalHeader("Referer", referer); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersion2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersion2Test.java 2013-09-29 11:48:27 UTC (rev 8528) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersion2Test.java 2013-09-29 17:57:26 UTC (rev 8529) @@ -20,10 +20,10 @@ import org.junit.Test; import org.junit.runner.RunWith; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; -import com.gargoylesoftware.htmlunit.BrowserRunner.Browser; -import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; /** * Unit tests for {@link BrowserVersion}. @@ -42,7 +42,6 @@ @Test @Alerts(DEFAULT = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", IE = "Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, */*") - @NotYetImplemented public void acceptHeaderGetUrl() throws Exception { final String html = "<html><body>Response</body></html>"; loadPage2(html, getDefaultUrl()); @@ -54,10 +53,30 @@ * @throws Exception if an error occurs */ @Test + @Alerts(DEFAULT = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", + IE = "Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, */*") + public void acceptHeaderWindowOpen() throws Exception { + String html = "<html><body>Response</body></html>"; + getMockWebConnection().setDefaultResponse(html); + + html = "<html><head><title>First</title></head>\n" + + "<body>\n" + + " <a id='clickme' href='javascript: window.open(\"" + URL_SECOND + "\")'>Click me</a>\n" + + "</body></html>"; + final WebDriver driver = loadPage2(html, getDefaultUrl()); + driver.findElement(By.id("clickme")).click(); + + assertEquals(2, getMockWebConnection().getRequestCount()); + assertEquals(getExpectedAlerts()[0], acceptHeaderString()); + } + + /** + * @throws Exception if an error occurs + */ + @Test @Alerts(DEFAULT = "Accept: image/png,image/*;q=0.8,*/*;q=0.5", IE = "Accept: */*", CHROME = "Accept: image/webp,*/*;q=0.8") - @NotYetImplemented(Browser.FF) public void acceptHeaderImage() throws Exception { final String html = "<html><head>\n" @@ -82,7 +101,6 @@ @Test @Alerts(DEFAULT = "Accept: text/css,*/*;q=0.1", IE = "Accept: */*") - @NotYetImplemented(Browser.FF) public void acceptHeaderCss() throws Exception { final String html = "<html><head>\n" @@ -108,7 +126,6 @@ @Test @Alerts(DEFAULT = "Accept: text/css,*/*;q=0.1", IE = "Accept: */*") - @NotYetImplemented(Browser.FF) public void acceptHeaderCssWithoutType() throws Exception { final String html = "<html><head>\n" @@ -134,7 +151,6 @@ @Test @Alerts(DEFAULT = "Accept: text/css,*/*;q=0.1", IE = "Accept: */*") - @NotYetImplemented(Browser.FF) public void acceptHeaderCssDifferentType() throws Exception { final String html = "<html><head>\n" |
From: <rb...@us...> - 2013-09-30 17:47:46
|
Revision: 8530 http://sourceforge.net/p/htmlunit/code/8530 Author: rbri Date: 2013-09-30 17:47:42 +0000 (Mon, 30 Sep 2013) Log Message: ----------- add expectations for ie10 (frank danek) Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.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/BrowserVersionTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2013-09-29 17:57:26 UTC (rev 8529) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2013-09-30 17:47:42 UTC (rev 8530) @@ -66,6 +66,7 @@ * @author Marc Guillemot * @author Chris Erskine * @author Ahmed Ashour + * @author Frank Danek */ public class BrowserVersion implements Serializable, Cloneable { @@ -170,6 +171,11 @@ INTERNET_EXPLORER, "5.0 (compatible; MSIE 9.0; Windows NT 6.1)", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1)", 9, "IE9", null); + /** Internet Explorer 10. Work In Progress!!! */ + public static final BrowserVersion INTERNET_EXPLORER_10 = new BrowserVersion( + INTERNET_EXPLORER, "5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)", + "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)", 10, "IE10", null); + /** * Chrome 16. * @deprecated as of 2.12 @@ -199,6 +205,7 @@ INTERNET_EXPLORER_7.initDefaultFeatures(); INTERNET_EXPLORER_8.initDefaultFeatures(); INTERNET_EXPLORER_9.initDefaultFeatures(); + INTERNET_EXPLORER_10.initDefaultFeatures(); FIREFOX_3_6.initDefaultFeatures(); FIREFOX_10.initDefaultFeatures(); @@ -665,6 +672,11 @@ return nickname_; } + @Override + public String toString() { + return nickname_; + } + /** * Creates and return a copy of this object. Current instance and cloned * object can be modified independently. Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserRunner.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserRunner.java 2013-09-29 17:57:26 UTC (rev 8529) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserRunner.java 2013-09-30 17:47:42 UTC (rev 8530) @@ -45,7 +45,7 @@ * public class SomeTest extends WebTestCase { * * @Test - * @Browsers({Browser.FF17}) + * @Browsers({ Browser.FF17 }) * public void test() { * //your test case that succeeds with only Firefox 17 * } @@ -90,6 +90,9 @@ if (/*browsers.contains("hu") ||*/ browsers.contains("hu-ie9")) { runners_.add(new BrowserVersionClassRunner(klass, BrowserVersion.INTERNET_EXPLORER_9, false)); } + if (/*browsers.contains("hu") ||*/ browsers.contains("hu-ie10")) { + runners_.add(new BrowserVersionClassRunner(klass, BrowserVersion.INTERNET_EXPLORER_10, false)); + } if (/*browsers.contains("hu") || */browsers.contains("hu-chrome")) { runners_.add(new BrowserVersionClassRunner(klass, BrowserVersion.CHROME, false)); } @@ -116,6 +119,9 @@ if (browsers.contains("ie9")) { runners_.add(new BrowserVersionClassRunner(klass, BrowserVersion.INTERNET_EXPLORER_9, true)); } + if (browsers.contains("ie10")) { + runners_.add(new BrowserVersionClassRunner(klass, BrowserVersion.INTERNET_EXPLORER_10, true)); + } if (browsers.contains("chrome")) { runners_.add(new BrowserVersionClassRunner(klass, BrowserVersion.CHROME, true)); } @@ -186,6 +192,9 @@ /** Internet Explorer 9. */ IE9, + /** Internet Explorer 10. */ + IE10, + /** All versions of Firefox. */ FF, @@ -236,40 +245,43 @@ public static @interface Alerts { /** Alerts that is used for all browsers (if defined, the other values are ignored). */ - String[] value() default {EMPTY_DEFAULT }; + String[] value() default { EMPTY_DEFAULT }; /** Alerts for any Internet Explorer, it can be overridden by specific IE version. */ - String[] IE() default {EMPTY_DEFAULT }; + String[] IE() default { EMPTY_DEFAULT }; /** Alerts for Internet Explorer 6. If not defined, {@link #IE()} is used. */ - String[] IE6() default {EMPTY_DEFAULT }; + String[] IE6() default { EMPTY_DEFAULT }; /** Alerts for Internet Explorer 7. If not defined, {@link #IE()} is used. */ - String[] IE7() default {EMPTY_DEFAULT }; + String[] IE7() default { EMPTY_DEFAULT }; /** Alerts for Internet Explorer 8. If not defined, {@link #IE()} is used. */ - String[] IE8() default {EMPTY_DEFAULT }; + String[] IE8() default { EMPTY_DEFAULT }; /** Alerts for Internet Explorer 9. If not defined, {@link #IE()} is used. */ - String[] IE9() default {EMPTY_DEFAULT }; + String[] IE9() default { EMPTY_DEFAULT }; + /** Alerts for Internet Explorer 10. If not defined, {@link #IE()} is used. */ + String[] IE10() default { EMPTY_DEFAULT }; + /** Alerts for any Firefox, it can be overridden by specific FF version. */ - String[] FF() default {EMPTY_DEFAULT }; + String[] FF() default { EMPTY_DEFAULT }; /** Alerts for Firefox 3.6. If not defined, {@link #FF()} is used. */ - String[] FF3_6() default {EMPTY_DEFAULT }; + String[] FF3_6() default { EMPTY_DEFAULT }; /** Alerts for Firefox 10. If not defined, {@link #FF()} is used. */ - String[] FF10() default {EMPTY_DEFAULT }; + String[] FF10() default { EMPTY_DEFAULT }; /** Alerts for Firefox 17. If not defined, {@link #FF()} is used. */ - String[] FF17() default {EMPTY_DEFAULT }; + String[] FF17() default { EMPTY_DEFAULT }; /** Alerts for latest Chrome. */ - String[] CHROME() default{EMPTY_DEFAULT }; + String[] CHROME() default { EMPTY_DEFAULT }; /** The default alerts, if nothing more specific is defined. */ - String[] DEFAULT() default{EMPTY_DEFAULT }; + String[] DEFAULT() default { EMPTY_DEFAULT }; } /** @@ -291,7 +303,7 @@ } /** - * Indicates that the test runs manually in a real browser but not when using WebDriver to driver the browser. + * Indicates that the test runs manually in a real browser but not when using WebDriver to drive the browser. * @see Browser */ @Retention(RetentionPolicy.RUNTIME) Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersionClassRunner.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersionClassRunner.java 2013-09-29 17:57:26 UTC (rev 8529) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersionClassRunner.java 2013-09-30 17:47:42 UTC (rev 8530) @@ -82,6 +82,9 @@ else if (browserVersion_ == BrowserVersion.INTERNET_EXPLORER_9) { expectedAlerts = firstDefined(alerts.IE9(), alerts.IE(), alerts.DEFAULT()); } + else if (browserVersion_ == BrowserVersion.INTERNET_EXPLORER_10) { + expectedAlerts = firstDefined(alerts.IE10(), alerts.IE(), alerts.DEFAULT()); + } else if (browserVersion_ == BrowserVersion.FIREFOX_3_6) { expectedAlerts = firstDefined(alerts.FF3_6(), alerts.FF(), alerts.DEFAULT()); } @@ -256,6 +259,12 @@ } break; + case IE10: + if (browserVersion_ == BrowserVersion.INTERNET_EXPLORER_10) { + return true; + } + break; + case FF: if (browserVersion_.isFirefox()) { return true; Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersionTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersionTest.java 2013-09-29 17:57:26 UTC (rev 8529) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersionTest.java 2013-09-30 17:47:42 UTC (rev 8530) @@ -37,6 +37,7 @@ assertEquals(7.0f, BrowserVersion.INTERNET_EXPLORER_7.getBrowserVersionNumeric()); assertEquals(8.0f, BrowserVersion.INTERNET_EXPLORER_8.getBrowserVersionNumeric()); assertEquals(9.0f, BrowserVersion.INTERNET_EXPLORER_9.getBrowserVersionNumeric()); + assertEquals(10.0f, BrowserVersion.INTERNET_EXPLORER_10.getBrowserVersionNumeric()); assertEquals(16.0f, BrowserVersion.CHROME_16.getBrowserVersionNumeric()); assertEquals(29.0f, BrowserVersion.CHROME.getBrowserVersionNumeric()); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java 2013-09-29 17:57:26 UTC (rev 8529) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java 2013-09-30 17:47:42 UTC (rev 8530) @@ -109,6 +109,7 @@ private static String FF3_6_BIN_; private static String FF10_BIN_; private static String FF17_BIN_; + private static String IE_BIN_; private static String CHROME_BIN_; /** The driver cache. */ @@ -144,6 +145,7 @@ BROWSERS_PROPERTIES_ = Arrays.asList(properties.getProperty("browsers", "hu") .replaceAll(" ", "").toLowerCase().split(",")); + IE_BIN_ = properties.getProperty("ie.bin"); FF3_6_BIN_ = properties.getProperty("ff3.6.bin"); FF10_BIN_ = properties.getProperty("ff10.bin"); FF17_BIN_ = properties.getProperty("ff17.bin"); @@ -227,9 +229,10 @@ protected WebDriver buildWebDriver() throws IOException { if (useRealBrowser_) { if (getBrowserVersion().isIE()) { + System.setProperty("webdriver.ie.driver", IE_BIN_); return new InternetExplorerDriver(); } - if (BrowserVersion.CHROME.equals(getBrowserVersion())) { + if (BrowserVersion.CHROME == getBrowserVersion()) { if (CHROME_SERVICE_ == null) { CHROME_SERVICE_ = new ChromeDriverService.Builder() .usingDriverExecutable(new File(CHROME_BIN_)) @@ -244,13 +247,13 @@ } String ffBinary = null; - if (getBrowserVersion() == BrowserVersion.FIREFOX_3_6) { + if (BrowserVersion.FIREFOX_3_6 == getBrowserVersion()) { ffBinary = FF3_6_BIN_; } - else if (getBrowserVersion() == BrowserVersion.FIREFOX_10) { + else if (BrowserVersion.FIREFOX_10 == getBrowserVersion()) { ffBinary = FF10_BIN_; } - else if (getBrowserVersion() == BrowserVersion.FIREFOX_17) { + else if (BrowserVersion.FIREFOX_17 == getBrowserVersion()) { ffBinary = FF17_BIN_; } if (ffBinary != null) { |
From: <rb...@us...> - 2013-09-30 17:56:34
|
Revision: 8531 http://sourceforge.net/p/htmlunit/code/8531 Author: rbri Date: 2013-09-30 17:56:31 +0000 (Mon, 30 Sep 2013) Log Message: ----------- fix clone Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersionTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2013-09-30 17:47:42 UTC (rev 8530) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2013-09-30 17:56:31 UTC (rev 8531) @@ -696,6 +696,10 @@ clone.setSystemLanguage(getSystemLanguage()); clone.setUserLanguage(getUserLanguage()); + clone.htmlAcceptHeader_ = getHtmlAcceptHeader(); + clone.imgAcceptHeader_ = getImgAcceptHeader(); + clone.cssAcceptHeader_ = getCssAcceptHeader(); + for (final PluginConfiguration pluginConf : getPlugins()) { clone.getPlugins().add(pluginConf.clone()); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersionTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersionTest.java 2013-09-30 17:47:42 UTC (rev 8530) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersionTest.java 2013-09-30 17:56:31 UTC (rev 8531) @@ -47,7 +47,7 @@ */ @Test public void testClone() { - final BrowserVersion ff = BrowserVersion.FIREFOX_3_6; + final BrowserVersion ff = BrowserVersion.FIREFOX_17; final BrowserVersion clone = ff.clone(); assertFalse(ff == clone); |
From: <rb...@us...> - 2013-10-04 09:53:15
|
Revision: 8587 http://sourceforge.net/p/htmlunit/code/8587 Author: rbri Date: 2013-10-04 09:53:10 +0000 (Fri, 04 Oct 2013) Log Message: ----------- Date.toUTCString and Date.toGMTString now returns the correct format in IE mode. Date.toLocaleTimeString fixed in IE8 mode. Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/DateCustom.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeDateTest.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-10-03 08:49:18 UTC (rev 8586) +++ trunk/htmlunit/src/changes/changes.xml 2013-10-04 09:53:10 UTC (rev 8587) @@ -8,6 +8,12 @@ <body> <release version="2.13" date="???" description="Bugfixes"> + <action type="fix" dev="rbri"> + Date.toUTCString and Date.toGMTString now returns the correct format in IE mode. + </action> + <action type="fix" dev="rbri"> + Date.toLocaleTimeString fixed in IE8 mode. + </action> <action type="fix" dev="rbri" issue="1524"> Some debug log output added if HTMLDocument.canAlreadyBeParsed(String) returns false. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-10-03 08:49:18 UTC (rev 8586) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-10-04 09:53:10 UTC (rev 8587) @@ -769,9 +769,14 @@ JS_CONSTRUCTOR, /** Is Date.toLocaleTimeString() in 24-hour format. */ - @BrowserFeature({ @WebBrowser(CHROME), @WebBrowser(value = FF, minVersion = 17) }) + @BrowserFeature({ @WebBrowser(value = IE, minVersion = 8), @WebBrowser(value = FF, minVersion = 17), + @WebBrowser(CHROME) }) JS_DATE_LOCATE_TIME_24, + /** Is Date.toUTCString() and Date.toGMTString are returning UTC instead of GMT. */ + @BrowserFeature({ @WebBrowser(IE) }) + JS_DATE_USE_UTC, + /** */ @BrowserFeature(@WebBrowser(IE)) JS_DEFERRED, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java 2013-10-03 08:49:18 UTC (rev 8586) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java 2013-10-04 09:53:10 UTC (rev 8587) @@ -16,6 +16,7 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ALLOW_CONST_ASSIGNMENT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_CONSTRUCTOR; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_DATE_USE_UTC; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_DEFINE_GETTER; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_DONT_ENUM_FUNCTIONS; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ECMA5_FUNCTIONS; @@ -331,6 +332,12 @@ final ScriptableObject datePrototype = (ScriptableObject) ScriptableObject.getClassPrototype(window, "Date"); datePrototype.defineFunctionProperties(new String[] {"toLocaleDateString", "toLocaleTimeString"}, DateCustom.class, ScriptableObject.DONTENUM); + + if (browserVersion.hasFeature(JS_DATE_USE_UTC)) { + datePrototype.defineFunctionProperties(new String[] {"toUTCString"}, + DateCustom.class, ScriptableObject.DONTENUM); + } + window.setPrototypes(prototypes); window.initialize(webWindow); } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/DateCustom.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/DateCustom.java 2013-10-03 08:49:18 UTC (rev 8586) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/DateCustom.java 2013-10-04 09:53:10 UTC (rev 8587) @@ -21,11 +21,14 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; +import java.util.TimeZone; import net.sourceforge.htmlunit.corejs.javascript.Context; import net.sourceforge.htmlunit.corejs.javascript.Function; import net.sourceforge.htmlunit.corejs.javascript.Scriptable; +import org.apache.commons.lang3.time.DateFormatUtils; + import com.gargoylesoftware.htmlunit.BrowserVersion; /** @@ -33,9 +36,12 @@ * * @version $Revision$ * @author Ahmed Ashour + * @author Ronald Brill */ public final class DateCustom { + private static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone("UTC"); + private DateCustom() { } private static Field DATE_FIELD_; @@ -76,6 +82,20 @@ return format.format(new Date(getDateValue(thisObj))); } + /** + * Converts a date to a UTC string. Special version for IE + * @param context the JavaScript context + * @param thisObj the scriptable + * @param args the arguments passed into the method + * @param function the function + * @return converted string + */ + public static String toUTCString( + final Context context, final Scriptable thisObj, final Object[] args, final Function function) { + final Date date = new Date(getDateValue(thisObj)); + return DateFormatUtils.format(date, "EEE, d MMM yyyy HH:mm:ss z", UTC_TIME_ZONE, Locale.ENGLISH); + } + private static long getDateValue(final Scriptable thisObj) { try { if (DATE_FIELD_ == null) { Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeDateTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeDateTest.java 2013-10-03 08:49:18 UTC (rev 8586) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeDateTest.java 2013-10-04 09:53:10 UTC (rev 8587) @@ -155,6 +155,74 @@ * @throws Exception if the test fails */ @Test + @Alerts(DEFAULT = { "2005-12-03T07:14:15.000Z", "2005-07-12T11:04:15.000Z", + "2005-07-03T15:14:05.000Z" }, + IE6 = "", + IE8 = "") + public void toISOString() throws Exception { + final String html + = "<html><head><title>foo</title><script>\n" + + "function test() {\n" + + " if (new Date().toISOString) {\n" + + " alert(new Date(2005, 11, 3, 8, 14, 15).toISOString());\n" + + " alert(new Date(2005, 6, 12, 13, 4, 15).toISOString());\n" + + " alert(new Date(2005, 6, 3, 17, 14, 5).toISOString());\n" + + " }\n" + + "}\n" + + "</script></head><body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "Sat, 03 Dec 2005 07:14:15 GMT", "Tue, 12 Jul 2005 11:04:15 GMT", + "Sun, 03 Jul 2005 15:14:05 GMT" }, + IE = { "Sat, 3 Dec 2005 07:14:15 UTC", "Tue, 12 Jul 2005 11:04:15 UTC", + "Sun, 3 Jul 2005 15:14:05 UTC" }) + public void toUTCString() throws Exception { + final String html + = "<html><head><title>foo</title><script>\n" + + "function test() {\n" + + " alert(new Date(2005, 11, 3, 8, 14, 15).toUTCString());\n" + + " alert(new Date(2005, 6, 12, 13, 4, 15).toUTCString());\n" + + " alert(new Date(2005, 6, 3, 17, 14, 5).toUTCString());\n" + + "}\n" + + "</script></head><body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "Sat, 03 Dec 2005 07:14:15 GMT", "Tue, 12 Jul 2005 11:04:15 GMT", + "Sun, 03 Jul 2005 15:14:05 GMT" }, + IE = { "Sat, 3 Dec 2005 07:14:15 UTC", "Tue, 12 Jul 2005 11:04:15 UTC", + "Sun, 3 Jul 2005 15:14:05 UTC" }) + public void toGMTString() throws Exception { + final String html + = "<html><head><title>foo</title><script>\n" + + "function test() {\n" + + " alert(new Date(2005, 11, 3, 8, 14, 15).toGMTString());\n" + + " alert(new Date(2005, 6, 12, 13, 4, 15).toGMTString());\n" + + " alert(new Date(2005, 6, 3, 17, 14, 5).toGMTString());\n" + + "}\n" + + "</script></head><body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test public void enumerable() throws Exception { final String html = "<html><head><title>foo</title><script>\n" @@ -174,15 +242,20 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "12:00:00 AM", - CHROME = "00:00:00", - FF17 = "00:00:00", - IE10 = "00:00:00") + @Alerts(DEFAULT = { "00:00:00", "07:08:09" }, + FF3_6 = { "12:00:00 AM", "07:08:09 AM" }, + FF10 = { "12:00:00 AM", "07:08:09 AM" }, + IE6 = { "12:00:00 AM", "07:08:09 AM" }) public void toLocaleTimeString() throws Exception { final String html = "<html><head><title>foo</title><script>\n" + "function test() {\n" + " alert(new Date(2000, 0, 1).toLocaleTimeString());\n" + + " var date = new Date(2013, 0, 1);\n" + + " date.setHours(7);\n" + + " date.setMinutes(8);\n" + + " date.setSeconds(9);\n" + + " alert(date.toLocaleTimeString());\n" + "}\n" + "</script></head><body onload='test()'>\n" + "</body></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-10-03 08:49:18 UTC (rev 8586) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java 2013-10-04 09:53:10 UTC (rev 8587) @@ -597,7 +597,8 @@ * @throws Exception if the test fails */ @Test - @Alerts({ "string", "Fri, 16 Oct 2009 13:59:47 GMT" }) + @Alerts(DEFAULT = { "string", "Fri, 16 Oct 2009 13:59:47 GMT" }, + IE = { "string", "Fri, 16 Oct 2009 13:59:47 UTC" }) public void lastModified() throws Exception { final List<NameValuePair> responseHeaders = new ArrayList<NameValuePair>(); responseHeaders.add(new NameValuePair("Last-Modified", "Fri, 16 Oct 2009 13:59:47 GMT")); |
From: <rb...@us...> - 2013-10-04 14:59:05
|
Revision: 8589 http://sourceforge.net/p/htmlunit/code/8589 Author: rbri Date: 2013-10-04 14:59:02 +0000 (Fri, 04 Oct 2013) Log Message: ----------- add expectations for ie10 (frank danek) retest with IE8 and adapt some exptectations (frank danek) fix for document mode regarding the updated tests 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-10-04 14:57:55 UTC (rev 8588) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java 2013-10-04 14:59:02 UTC (rev 8589) @@ -833,7 +833,7 @@ final float version = browserVersion.getBrowserVersionNumeric(); if (version == 8) { - documentMode_ = 7; + documentMode_ = 8; return documentMode_; } documentMode_ = 9; 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-10-04 14:57:55 UTC (rev 8588) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java 2013-10-04 14:59:02 UTC (rev 8589) @@ -17,6 +17,9 @@ import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.FF; import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.FF3_6; import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.IE; +import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.IE10; +import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.IE6; +import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.IE8; import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.NONE; import static com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument.EMPTY_COOKIE_NAME; import static com.gargoylesoftware.htmlunit.util.StringUtils.parseHttpDate; @@ -55,6 +58,7 @@ * @author Ahmed Ashour * @author Marc Guillemot * @author Ronald Brill + * @author Frank Danek */ @RunWith(BrowserRunner.class) public class HTMLDocumentTest extends WebDriverTestCase { @@ -97,8 +101,9 @@ * @throws Exception if the test fails */ @Test - @Alerts(FF = { "function", "div1", "span2", "span3", "2", "1", "1", "0", "0", "0" }, - IE = { "undefined", "exception" }) + @Alerts(DEFAULT = { "function", "div1", "span2", "span3", "2", "1", "1", "0", "0", "0" }, + IE6 = { "undefined", "exception" }, + IE8 = { "undefined", "exception" }) public void getElementsByClassName() throws Exception { final String html = "<html><head><title>First</title><script>\n" @@ -143,7 +148,7 @@ */ @Test @Alerts("CSS1Compat") - public void compatMode_doctype_html() throws Exception { + public void compatMode_html() throws Exception { compatMode("<!DOCTYPE html>"); } @@ -152,7 +157,7 @@ */ @Test @Alerts("BackCompat") - public void compatMode_no_url() throws Exception { + public void compatMode_html_transitional_40_noUrl() throws Exception { compatMode("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">"); } @@ -160,27 +165,30 @@ * @throws Exception if the test fails */ @Test - @Alerts("CSS1Compat") - public void compatMode_strict() throws Exception { - compatMode("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">"); + @Alerts("BackCompat") + public void compatMode_html_transitional_noUrl() throws Exception { + compatMode("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"); } /** * @throws Exception if the test fails */ @Test - @Alerts("CSS1Compat") - public void compatMode_strict_40() throws Exception { - compatMode("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">"); + @Alerts(DEFAULT = "BackCompat", + IE6 = "CSS1Compat", + IE8 = "CSS1Compat") + public void compatMode_html_transitional_40() throws Exception { + compatMode("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" " + + "\"http://www.w3.org/TR/html4/loose.dtd\">"); } /** * @throws Exception if the test fails */ @Test - @Alerts(IE = "CSS1Compat", FF = "BackCompat") - public void compatMode_loose_40() throws Exception { - compatMode("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" " + @Alerts("CSS1Compat") + public void compatMode_html_transitional() throws Exception { + compatMode("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" " + "\"http://www.w3.org/TR/html4/loose.dtd\">"); } @@ -189,9 +197,8 @@ */ @Test @Alerts("CSS1Compat") - public void compatMode_loose() throws Exception { - compatMode("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" " - + "\"http://www.w3.org/TR/html4/loose.dtd\">"); + public void compatMode_html_strict_40() throws Exception { + compatMode("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">"); } /** @@ -199,7 +206,16 @@ */ @Test @Alerts("CSS1Compat") - public void compatMode_xhtml_traditional() throws Exception { + public void compatMode_html_strict() throws Exception { + compatMode("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("CSS1Compat") + public void compatMode_xhtml_transitional() throws Exception { compatMode("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" " + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"); } @@ -243,7 +259,8 @@ * @throws Exception if the test fails */ @Test - @Alerts(IE = "true", FF = "false") + @Alerts(DEFAULT = "false", + IE = "true") public void uniqueID() throws Exception { final String html = "<html>\n" + "<head>\n" @@ -265,7 +282,7 @@ * @throws Exception if the test fails */ @Test - @Browsers(FF) + @Browsers({ FF, IE10 }) @Alerts({ "[object HTMLDivElement]", "[object HTMLUnknownElement]", "[object Element]" }) public void createDocumentNS() throws Exception { final String html = "<html>\n" @@ -293,7 +310,9 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "[object SVGSVGElement]", IE = "exception") + @Alerts(DEFAULT = "[object SVGSVGElement]", + IE6 = "exception", + IE8 = "exception") public void createDocumentNS_svg() throws Exception { final String html = "<html><body>\n" + "<script>\n" @@ -310,7 +329,8 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "exception", FF3_6 = "Hello", FF = "exception") + @Alerts(DEFAULT = "exception", + FF3_6 = "Hello") public void createDocumentNS_xul() throws Exception { final String html = "<html><body>\n" + "<script>\n" @@ -334,7 +354,9 @@ * @throws Exception if the test fails */ @Test - @Alerts(FF = { "[object HTMLCollection]", "0" }, IE = { "[object]", "0" }) + @Alerts(DEFAULT = { "[object HTMLCollection]", "0" }, + IE6 = { "[object]", "0" }, + IE8 = { "[object]", "0" }) public void applets() throws Exception { final String html = "<html>\n" + "<head>\n" @@ -357,8 +379,9 @@ * @throws Exception if the test fails */ @Test - @Alerts(FF = { "imported: [object HTMLScriptElement]", "replaced" }, - IE = "exception") + @Alerts(DEFAULT = { "imported: [object HTMLScriptElement]", "replaced" }, + IE6 = "exception", + IE8 = "exception") public void importNode_script() throws Exception { final String html = "<html><head><title>foo</title><script>\n" + "function test() {\n" @@ -388,8 +411,9 @@ * @throws Exception if the test fails */ @Test - @Alerts(FF = { "imported: [object HTMLDivElement]", "replaced" }, - IE = "exception") + @Alerts(DEFAULT = { "imported: [object HTMLDivElement]", "replaced" }, + IE6 = "exception", + IE8 = "exception") public void importNode_scriptChild() throws Exception { final String html = "<html><head><title>foo</title><script>\n" + "function test() {\n" @@ -417,7 +441,7 @@ * @throws Exception if an error occurs */ @Test - @Browsers(FF) + @Browsers({ FF, IE10 }) @Alerts("clicked") public void dispatchEvent() throws Exception { final String html = @@ -442,8 +466,9 @@ * @throws Exception if an error occurs */ @Test - @Alerts(FF = { "undefined", "exception" }, - IE = { "[object]", "0", "1", "f", "f", "f", "f", "urn:f", "urn:f", "true" }) + @Alerts(DEFAULT = { "undefined", "exception" }, + IE6 = { "[object]", "0", "1", "f", "f", "f", "f", "urn:f", "urn:f", "true" }, + IE8 = { "[object]", "0", "1", "f", "f", "f", "f", "urn:f", "urn:f", "true" }) public void namespaces() throws Exception { final String html = "<body><script>\n" @@ -471,7 +496,9 @@ * @throws Exception if the test fails */ @Test - @Alerts(FF = "exception", IE = { "d", "1" }) + @Alerts(DEFAULT = "exception", + IE6 = { "d", "1" }, + IE8 = { "d", "1" }) public void documentMethodsWithoutDocument() throws Exception { final String html = "<div id='d' name='d'>d</div>\n" @@ -488,7 +515,9 @@ * @throws Exception if the test fails */ @Test - @Alerts(IE = "[object]", FF = "null") + @Alerts(DEFAULT = "null", + IE6 = "[object]", + IE8 = "[object]") public void getElementById_caseSensitivity() throws Exception { final String html = "<html>\n" + "<head>\n" @@ -512,10 +541,11 @@ * @throws Exception if an error occurs */ @Test - @Alerts(IE = {"#ffffff", "", "#0000aa", "#0000aa", "#000000", "#000000" }, + @Alerts(DEFAULT = {"", "", "#0000aa", "#0000aa", "x", "x" }, + FF3_6 = {"", "", "#0000aa", "#0000aa", "#000000", "#000000" }, + IE = {"#ffffff", "", "#0000aa", "#0000aa", "#000000", "#000000" }, // IE9 = {"#ffffff", "", "#0000aa", "#0000aa", "#000000", "#0" }, - FF3_6 = {"", "", "#0000aa", "#0000aa", "#000000", "#000000" }, - DEFAULT = {"", "", "#0000aa", "#0000aa", "x", "x" }) + IE10 = {"#ffffff", "", "#0000aa", "#0000aa", "#000000", "#0" }) public void bgColor() throws Exception { final String html = "<html>\n" @@ -543,8 +573,9 @@ * @throws Exception if an error occurs */ @Test - @Alerts(FF = { "[object HTMLCollection]", "4", "red" }, - IE = { "[object]", "4", "red" }) + @Alerts(DEFAULT = { "[object HTMLCollection]", "4", "red" }, + IE6 = { "[object]", "4", "red" }, + IE8 = { "[object]", "4", "red" }) public void identicalIDs() throws Exception { final String html = "<html>\n" @@ -678,21 +709,31 @@ /** * Warning: this test works fine in real FF8 when started manually but fails through WebDriver. + * Warning: opens a modal panel when run through IEDriver which needs to be closed MANUALLY. + * If not all following test will fail. * @throws Exception if an error occurs */ @Test @BuggyWebDriver // tested with FF8, FF17, FF18 - @Alerts(FF = { "1", "[object HTMLBodyElement]" }, CHROME = { "0", "exception" }, IE = "exception") + @Alerts(CHROME = { "0", "exception" }, + FF = { "1", "[object HTMLBodyElement]" }, + IE = "exception") + // TODO [IE10]MODALPANEL real IE10 opens a modal panel which webdriver cannot handle public void designMode_selectionRange_empty() throws Exception { designMode_selectionRange(""); } /** + * Warning: opens a modal panel when run through IEDriver which needs to be closed MANUALLY. + * If not all following test will fail. * @throws Exception if an error occurs */ @Test @BuggyWebDriver // tested with FF8, FF17, FF18 - @Alerts(FF = { "1", "[object Text]" }, CHROME = { "0", "exception" }, IE = "exception") + @Alerts(CHROME = { "0", "exception" }, + FF = { "1", "[object Text]" }, + IE = "exception") + // TODO [IE10]MODALPANEL real IE10 opens a modal panel which webdriver cannot handle public void designMode_selectionRange_text() throws Exception { designMode_selectionRange("hello"); } @@ -720,7 +761,9 @@ */ @Test @Alerts(FF = "not defined", - IE = { "true", "1", "about:blank", "about:blank" }) + IE = { "false", "1", "about:blank", "about:blank" }, + IE10 = { "true", "1" }) + @NotYetImplemented(IE) public void frames() throws Exception { final String html = "<html><head><script>\n" + "function test(){\n" @@ -747,7 +790,8 @@ */ @Test @Alerts(FF = { "undefined", "false" }, - IE = { "[object]", "true" }) + IE = { "[object]", "true" }, + IE10 = { "[object Window]", "true" }) public void frameAccessByName() throws Exception { final String html = "<html><head><script>\n" + "function test(){\n" @@ -765,7 +809,9 @@ * @throws Exception if the test fails */ @Test - @Alerts(FF = { "2", "2" }, IE = { "0", "0" }) + @Alerts(FF = { "2", "2" }, + IE = { "0", "0" }, + IE10 = { "2", "0" }) public void getElementsByName() throws Exception { final String html = "<html><head><title>Test</title><script>\n" @@ -848,9 +894,8 @@ * @throws Exception if the test fails */ @Test - @Alerts(FF3_6 = { "exception", "0 commands supported" }, - FF17 = { "32 commands supported", "not supported: foo, 123" }, - IE = { "32 commands supported", "not supported: foo, 123" }) + @Alerts(DEFAULT = { "32 commands supported", "not supported: foo, 123" }, + FF3_6 = { "exception", "0 commands supported" }) public void queryCommandSupported_common() throws Exception { final String[] commands = {"BackColor", "Bold", "Copy", "CreateLink", "Cut", "Delete", @@ -869,8 +914,8 @@ * @throws Exception if the test fails */ @Test - @Alerts(FF3_6 = { "exception", "0 commands supported" }, - DEFAULT = { "0 commands supported" }, + @Alerts(DEFAULT = { "0 commands supported" }, + FF3_6 = { "exception", "0 commands supported" }, IE = { "46 commands supported" }) public void queryCommandSupported_disctinct() throws Exception { final String[] commands = {"2D-Position", "AbsolutePosition", @@ -923,7 +968,8 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = { "3", "div1" }, IE8 = "undefined") + @Alerts(DEFAULT = { "3", "div1" }, + IE6 = "undefined") public void querySelectorAll() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>Test</title>\n" + "<style>\n" @@ -999,8 +1045,9 @@ * @throws Exception if the test fails */ @Test - @Alerts(FF = { "3", "div1" }, - IE = "undefined") + @Alerts(DEFAULT = { "3", "div1" }, + IE6 = "undefined", + IE8 = "undefined") public void querySelectorAll_quirks() throws Exception { final String html = "<html><head><title>Test</title>\n" + "<style>\n" @@ -1032,7 +1079,9 @@ * @throws Exception if the test fails */ @Test - @Alerts(FF = "3", IE = "undefined") + @Alerts(DEFAULT = "3", + IE6 = "undefined", + IE8 = "undefined") public void querySelectorAll_implicitAttribute() throws Exception { final String html = "<html><head><title>Test</title>\n" + "<script>\n" @@ -1064,7 +1113,8 @@ */ @Test @Alerts(DEFAULT = { "div1", "null" }, - IE6 = "undefined", IE7 = "undefined", IE8 = "undefined") + IE6 = "undefined", + IE7 = "undefined") public void querySelector() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>Test</title>\n" + "<style>\n" @@ -1095,7 +1145,9 @@ * @throws Exception if the test fails */ @Test - @Alerts(FF = { "1", "0" }, IE = { "0", "1" }) + @Alerts(DEFAULT = { "1", "0" }, + IE6 = { "0", "1" }, + IE8 = { "0", "1" }) public void getElementsByTagName2() throws Exception { final String html = "<html xmlns:ns1='http://example.com'>\n" + "<head>\n" @@ -1119,7 +1171,7 @@ */ @Test @Alerts({ "1", "0" }) - @NotYetImplemented(IE) + @NotYetImplemented({ IE6, IE8 }) public void getElementsByTagName3() throws Exception { final String html = "<html>\n" + "<head>\n" @@ -1159,6 +1211,7 @@ */ @Test @Alerts({ "true", "", "foo=bar", "foo=hello world" }) + // TODO [IE10]SINGLE-VS-BULK test runs when executed as single but breaks as bulk public void cookie_write_cookiesEnabled() throws Exception { loadPageWithAlerts2(getCookieWriteHtmlCode()); } @@ -1271,7 +1324,9 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "exception", IE = "INPUT") + @Alerts(DEFAULT = "exception", + IE6 = "INPUT", + IE8 = "INPUT") public void createElement_notOnlyTagName() throws Exception { final String html = "<html><body>\n" + "<script>\n" @@ -1291,7 +1346,8 @@ * @throws Exception if the test fails */ @Test - @Alerts("null") + @Alerts(DEFAULT = "null", + IE6 = "") public void getElementById_strict() throws Exception { getElementById_strict(true); } @@ -1300,7 +1356,9 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "null", IE = "") + @Alerts(DEFAULT = "null", + IE6 = "", + IE8 = "") public void getElementById_quirks() throws Exception { getElementById_strict(false); } @@ -1324,9 +1382,10 @@ * @throws Exception if the test fails */ @Test - @Alerts(FF = "[object HTMLHeadElement]", + @Alerts(DEFAULT = "[object HTMLHeadElement]", FF3_6 = "undefined", - IE = "undefined") + IE6 = "undefined", + IE8 = "undefined") public void head() throws Exception { final String html = "<html><body>\n" + "<script>\n" @@ -1340,10 +1399,11 @@ * @throws Exception if an error occurs */ @Test - @Alerts(IE = {"#0000ff", "", "#0000aa", "#0000aa", "#000000", "#000000" }, + @Alerts(FF = {"", "", "#0000aa", "#0000aa", "x", "x" }, + FF3_6 = {"", "", "#0000aa", "#0000aa", "#000000", "#000000" }, + IE = {"#0000ff", "", "#0000aa", "#0000aa", "#000000", "#000000" }, // IE9 = {"#0000ff", "", "#0000aa", "#0000aa", "#000000", "#0" }, - FF3_6 = {"", "", "#0000aa", "#0000aa", "#000000", "#000000" }, - FF = {"", "", "#0000aa", "#0000aa", "x", "x" }) + IE10 = {"#0000ff", "", "#0000aa", "#0000aa", "#000000", "#0" }) public void alinkColor() throws Exception { final String html = "<html>\n" @@ -1371,10 +1431,11 @@ * @throws Exception if an error occurs */ @Test - @Alerts(IE = {"#0000ff", "", "#0000aa", "#0000aa", "#000000", "#000000" }, + @Alerts(FF = {"", "", "#0000aa", "#0000aa", "x", "x" }, + FF3_6 = {"", "", "#0000aa", "#0000aa", "#000000", "#000000" }, + IE = {"#0000ff", "", "#0000aa", "#0000aa", "#000000", "#000000" }, // IE9 = {"#0000ff", "", "#0000aa", "#0000aa", "#000000", "#0" }, - FF3_6 = {"", "", "#0000aa", "#0000aa", "#000000", "#000000" }, - FF = {"", "", "#0000aa", "#0000aa", "x", "x" }) + IE10 = {"#0000ff", "", "#0000aa", "#0000aa", "#000000", "#0" }) public void linkColor() throws Exception { final String html = "<html>\n" @@ -1402,11 +1463,12 @@ * @throws Exception if an error occurs */ @Test - @Alerts(IE = {"#800080", "", "#0000aa", "#0000aa", "#000000", "#000000" }, + @Alerts(FF3_6 = {"", "", "#0000aa", "#0000aa", "#000000", "#000000" }, + FF10 = {"#800080", "", "#0000aa", "#0000aa", "x", "x" }, + FF17 = {"", "", "#0000aa", "#0000aa", "x", "x" }, + IE = {"#800080", "", "#0000aa", "#0000aa", "#000000", "#000000" }, // IE9 = {"#800080", "", "#0000aa", "#0000aa", "#000000", "#0" }, - FF3_6 = {"", "", "#0000aa", "#0000aa", "#000000", "#000000" }, - FF10 = {"#800080", "", "#0000aa", "#0000aa", "x", "x" }, - FF17 = {"", "", "#0000aa", "#0000aa", "x", "x" }) + IE10 = {"#800080", "", "#0000aa", "#0000aa", "#000000", "#0" }) public void vlinkColor() throws Exception { final String html = "<html>\n" @@ -1434,10 +1496,11 @@ * @throws Exception if an error occurs */ @Test - @Alerts(IE = {"#000000", "", "#0000aa", "#0000aa", "#000000", "#000000" }, + @Alerts(FF = {"", "", "#0000aa", "#0000aa", "x", "x" }, + FF3_6 = {"", "", "#0000aa", "#0000aa", "#000000", "#000000" }, + IE = {"#000000", "", "#0000aa", "#0000aa", "#000000", "#000000" }, // IE9 = {"#000000", "", "#0000aa", "#0000aa", "#000000", "#0" }, - FF3_6 = {"", "", "#0000aa", "#0000aa", "#000000", "#000000" }, - FF = {"", "", "#0000aa", "#0000aa", "x", "x" }) + IE10 = {"#000000", "", "#0000aa", "#0000aa", "#000000", "#0" }) public void fgColor() throws Exception { final String html = "<html>\n" @@ -1465,9 +1528,12 @@ * @throws Exception if an error occurs */ @Test - @Alerts(FF = { "", "true" }, FF3_6 = { "", "false" }, IE = { }) + @Alerts(DEFAULT = { "", "true" }, + FF3_6 = { "", "false" }, + IE6 = { }, + IE8 = { }) +// IE9 = {"", "true" } @NotYetImplemented(FF3_6) -// IE9 = {"", "true" } public void getSelection() throws Exception { final String html = "<html>\n" @@ -1490,8 +1556,9 @@ * @throws Exception if the test fails */ @Test - @Alerts(IE = { "true", "[object]", "true" }, - DEFAULT = { "true", "undefined", "false" }) + @Alerts(DEFAULT = { "true", "undefined", "false" }, + IE = { "true", "[object]", "true" }, + IE10 = { "true", "[object HTMLFormElement]", "true" }) public void document_xxx_formAccess() throws Exception { final String html = "<html>\n" + "<head>\n" @@ -1516,9 +1583,10 @@ * @throws Exception if the test fails */ @Test - @Alerts(IE = { "undefined", "undefined", "iso-8859-1", "windows-1252" }, + @Alerts(CHROME = { "ISO-8859-1", "ISO-8859-1", "ISO-8859-1", "ISO-8859-1" }, FF = { "ISO-8859-1", "ISO-8859-1", "undefined", "undefined" }, - CHROME = { "ISO-8859-1", "ISO-8859-1", "ISO-8859-1", "ISO-8859-1" }) + IE = { "undefined", "undefined", "iso-8859-1", "windows-1252" }, + IE10 = { "ISO-8859-1", "iso-8859-1", "iso-8859-1", "windows-1252" }) public void encoding() throws Exception { final String html = "<html>\n" + "<head>\n" @@ -1540,9 +1608,10 @@ * @throws Exception if the test fails */ @Test - @Alerts(IE = { "undefined", "undefined", "iso-8859-1", "windows-1252" }, + @Alerts(CHROME = { "ISO-8859-1", "ISO-8859-1", "ISO-8859-1", "ISO-8859-1" }, FF = { "ISO-8859-1", "ISO-8859-1", "undefined", "undefined" }, - CHROME = { "ISO-8859-1", "ISO-8859-1", "ISO-8859-1", "ISO-8859-1" }) + IE = { "undefined", "undefined", "iso-8859-1", "windows-1252" }, + IE10 = { "ISO-8859-1", "iso-8859-1", "iso-8859-1", "windows-1252" }) public void encoding2() throws Exception { final String html = "<html>\n" + "<head>\n" @@ -1565,9 +1634,10 @@ * @throws Exception if the test fails */ @Test - @Alerts(IE = { "undefined", "undefined", "iso-8859-1", "windows-1252" }, + @Alerts(CHROME = { "ISO-8859-1", "ISO-8859-1", "ISO-8859-1", "ISO-8859-1" }, FF = { "ISO-8859-1", "ISO-8859-1", "undefined", "undefined" }, - CHROME = { "ISO-8859-1", "ISO-8859-1", "ISO-8859-1", "ISO-8859-1" }) + IE = { "undefined", "undefined", "iso-8859-1", "windows-1252" }, + IE10 = { "ISO-8859-1", "iso-8859-1", "iso-8859-1", "windows-1252" }) public void encoding3() throws Exception { final String html = "<html>\n" + "<head>\n" @@ -1592,9 +1662,10 @@ * @throws Exception if the test fails */ @Test - @Alerts(IE = { "undefined", "undefined", "utf-8", "windows-1252" }, + @Alerts(CHROME = { "UTF-8", "UTF-8", "UTF-8", "ISO-8859-1" }, FF = { "UTF-8", "UTF-8", "undefined", "undefined" }, - CHROME = { "UTF-8", "UTF-8", "UTF-8", "ISO-8859-1" }) + IE = { "undefined", "undefined", "utf-8", "windows-1252" }, + IE10 = { "UTF-8", "utf-8", "utf-8", "windows-1252" }) public void encoding4() throws Exception { final String html = "<html>\n" + "<head>\n" @@ -1619,9 +1690,10 @@ * @throws Exception if the test fails */ @Test - @Alerts(IE = { "undefined", "undefined", "utf-8", "windows-1252" }, + @Alerts(CHROME = { "UTF-8", "UTF-8", "UTF-8", "ISO-8859-1" }, FF = { "UTF-8", "UTF-8", "undefined", "undefined" }, - CHROME = { "UTF-8", "UTF-8", "UTF-8", "ISO-8859-1" }) + IE = { "undefined", "undefined", "utf-8", "windows-1252" }, + IE10 = { "UTF-8", "utf-8", "utf-8", "windows-1252" }) public void encoding5() throws Exception { final String html = "<html>\n" + "<head>\n" @@ -1646,9 +1718,10 @@ * @throws Exception if the test fails */ @Test - @Alerts(IE = { "undefined", "undefined", "utf-8", "windows-1252" }, + @Alerts(CHROME = { "UTF-8", "UTF-8", "UTF-8", "ISO-8859-1" }, FF = { "UTF-8", "UTF-8", "undefined", "undefined" }, - CHROME = { "UTF-8", "UTF-8", "UTF-8", "ISO-8859-1" }) + IE = { "undefined", "undefined", "utf-8", "windows-1252" }, + IE10 = { "UTF-8", "utf-8", "utf-8", "windows-1252" }) public void encoding6() throws Exception { final String html = "<html>\n" + "<head>\n" @@ -1674,6 +1747,8 @@ * @throws Exception if the test fails */ @Test + @Alerts(DEFAULT = "?%C3%A8=%C3%A8", + IE = "?\u00E8=\u00E8") public void encoding7() throws Exception { final String html = "<html>\n" + "<head>\n" @@ -1686,149 +1761,159 @@ driver.findElement(By.id("myId")).click(); String actualQuery = driver.getCurrentUrl(); actualQuery = actualQuery.substring(actualQuery.indexOf('?')); - final String expectedQuery; - if (getBrowserVersion().isIE()) { - expectedQuery = "?\u00E8=\u00E8"; - } - else { - expectedQuery = "?%C3%A8=%C3%A8"; - } - assertTrue(actualQuery.endsWith(expectedQuery)); + assertTrue(actualQuery.endsWith(getExpectedAlerts()[0])); } /** * @throws Exception if the test fails */ @Test - @Alerts(IE = { "5", "BackCompat", "undefined", "undefined" }, - DEFAULT = { "undefined", "BackCompat", "function", "function" }) + @Alerts(DEFAULT = { "undefined", "BackCompat", "function", "function" }, + IE6 = { "undefined", "BackCompat", "undefined", "undefined" }, + IE8 = { "5", "BackCompat", "undefined", "undefined" }, + IE10 = { "10", "BackCompat", "function", "function" }) public void documentMode() throws Exception { - final String html = "<html>\n" - + "<head>\n" - + " <script>\n" - + " function test() {\n" - + " alert(document.documentMode);\n" - + " alert(document.compatMode);\n" - + " alert(typeof document.querySelectorAll);\n" - + " alert(typeof document.createElement('div').querySelector);\n" - + " }\n" - + " </script>\n" - + "</head><body onload='test()'>\n" - + "</body></html>"; - - loadPageWithAlerts2(html); + documentMode("", ""); } /** * @throws Exception if the test fails */ @Test - @Alerts(IE8 = { "7", "CSS1Compat", "undefined", "undefined" }, + @Alerts(DEFAULT = { "undefined", "CSS1Compat", "function", "function" }, + IE6 = { "undefined", "CSS1Compat", "undefined", "undefined" }, + IE8 = { "8", "CSS1Compat", "object", "object" }, IE9 = { "9", "CSS1Compat", "function", "function" }, - DEFAULT = { "undefined", "CSS1Compat", "function", "function" }) - public void documentMode_standards() throws Exception { - final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html>\n" - + "<head>\n" - + " <script>\n" - + " function test() {\n" - + " alert(document.documentMode);\n" - + " alert(document.compatMode);\n" - + " alert(typeof document.querySelectorAll);\n" - + " alert(typeof document.createElement('div').querySelector);\n" - + " }\n" - + " </script>\n" - + "</head><body onload='test()'>\n" - + "</body></html>"; + IE10 = { "10", "CSS1Compat", "function", "function" }) + @NotYetImplemented(IE8) + public void documentMode_doctypeStrict() throws Exception { + documentMode(HtmlPageTest.STANDARDS_MODE_PREFIX_, ""); + } - loadPageWithAlerts2(html); + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "undefined", "BackCompat", "function", "function" }, + IE6 = { "undefined", "CSS1Compat", "undefined", "undefined" }, + IE8 = { "8", "CSS1Compat", "object", "object" }, + IE9 = { "9", "BackCompat", "function", "function" }, + IE10 = { "10", "BackCompat", "function", "function" }) + @NotYetImplemented(IE8) + public void documentMode_doctypeTransitional() throws Exception { + documentMode("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"" + + " \"http://www.w3.org/TR/html4/loose.dtd\">\n", ""); } /** * @throws Exception if the test fails */ @Test - @Alerts(IE8 = { "8", "CSS1Compat", "false", "false" }, - IE9 = { "9", "CSS1Compat", "false", "false" }, - DEFAULT = { "undefined", "BackCompat", "false", "false" }) - public void documentMode_standards_8() throws Exception { - final String html = "<html>\n" - + "<head>\n" - + " <meta http-equiv='X-UA-Compatible' content='IE=8'>\n" - + " <script>\n" - + " function test() {\n" - + " alert(document.documentMode);\n" - + " alert(document.compatMode);\n" - + " alert(!document.querySelectorAll);\n" - + " alert(!document.createElement('div').querySelector);\n" - + " }\n" - + " </script>\n" - + "</head><body onload='test()'>\n" - + "</body></html>"; + @Alerts(DEFAULT = { "undefined", "CSS1Compat", "function", "function" }, + IE6 = { "undefined", "CSS1Compat", "undefined", "undefined" }, + IE8 = { "8", "CSS1Compat", "object", "object" }, + IE9 = { "9", "CSS1Compat", "function", "function" }, + IE10 = { "10", "CSS1Compat", "function", "function" }) + @NotYetImplemented(IE8) + public void documentMode_doctypeHTML5() throws Exception { + documentMode("<!DOCTYPE html>\n", ""); + } - loadPageWithAlerts2(html); + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "undefined", "BackCompat", "function", "function" }, + IE = { "5", "BackCompat", "undefined", "undefined" }, + IE6 = { "undefined", "BackCompat", "undefined", "undefined" }) + public void documentMode_metaIE5() throws Exception { + documentMode("", " <meta http-equiv='X-UA-Compatible' content='IE=5'>\n"); } /** * @throws Exception if the test fails */ @Test - @Alerts(IE8 = { "8", "CSS1Compat", "false", "false" }, - IE9 = { "9", "CSS1Compat", "false", "false" }, - DEFAULT = { "undefined", "CSS1Compat", "false", "false" }) - public void documentMode_standards_8_prefix() throws Exception { - final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html>\n" - + "<head>\n" - + " <meta http-equiv='X-UA-Compatible' content='IE=8'>\n" - + " <script>\n" - + " function test() {\n" - + " alert(document.documentMode);\n" - + " alert(document.compatMode);\n" - + " alert(!document.querySelectorAll);\n" - + " alert(!document.createElement('div').querySelector);\n" - + " }\n" - + " </script>\n" - + "</head><body onload='test()'>\n" - + "</body></html>"; + @Alerts(DEFAULT = { "undefined", "BackCompat", "function", "function" }, + IE = { "8", "CSS1Compat", "object", "object" }, + IE6 = { "undefined", "BackCompat", "undefined", "undefined" }) + @NotYetImplemented(IE8) + public void documentMode_metaIE8() throws Exception { + documentMode("", " <meta http-equiv='X-UA-Compatible' content='IE=8'>\n"); + } - loadPageWithAlerts2(html); + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "undefined", "CSS1Compat", "function", "function" }, + IE = { "8", "CSS1Compat", "object", "object" }, + IE6 = { "undefined", "CSS1Compat", "undefined", "undefined" }) + @NotYetImplemented(IE8) + public void documentMode_metaIE8_doctypeStrict() throws Exception { + documentMode(HtmlPageTest.STANDARDS_MODE_PREFIX_, " <meta http-equiv='X-UA-Compatible' content='IE=8'>\n"); } /** * @throws Exception if the test fails */ @Test - @Alerts(IE8 = { "8", "CSS1Compat", "false", "false" }, - IE9 = { "9", "CSS1Compat", "false", "false" }, - DEFAULT = { "undefined", "BackCompat", "false", "false" }) - public void documentMode_standards_9() throws Exception { - final String html = "<html>\n" - + "<head>\n" - + " <meta http-equiv='X-UA-Compatible' content='IE=9'>\n" - + " <script>\n" - + " function test() {\n" - + " alert(document.documentMode);\n" - + " alert(document.compatMode);\n" - + " alert(!document.querySelectorAll);\n" - + " alert(!document.createElement('div').querySelector);\n" - + " }\n" - + " </script>\n" - + "</head><body onload='test()'>\n" - + "</body></html>"; + @Alerts(DEFAULT = { "undefined", "BackCompat", "function", "function" }, + IE6 = { "undefined", "BackCompat", "undefined", "undefined" }, + IE8 = { "5", "BackCompat", "undefined", "undefined" }, + IE9 = { "9", "BackCompat", "function", "function" }, + IE10 = { "10", "BackCompat", "function", "function" }) + public void documentMode_metaEmulateIE8() throws Exception { + documentMode("", " <meta http-equiv='X-UA-Compatible' content='IE=Emulate8'>\n"); + } - loadPageWithAlerts2(html); + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "undefined", "CSS1Compat", "function", "function" }, + IE6 = { "undefined", "CSS1Compat", "undefined", "undefined" }, + IE8 = { "8", "CSS1Compat", "object", "object" }, + IE9 = { "9", "CSS1Compat", "function", "function" }, + IE10 = { "10", "CSS1Compat", "function", "function" }) + @NotYetImplemented(IE8) + public void documentMode_metaEmulateIE8_doctypeStrict() throws Exception { + documentMode(HtmlPageTest.STANDARDS_MODE_PREFIX_, + " <meta http-equiv='X-UA-Compatible' content='IE=Emulate8'>\n"); } /** * @throws Exception if the test fails */ @Test - @Alerts(IE8 = { "7", "CSS1Compat", "undefined", "undefined" }, + @Alerts(DEFAULT = { "undefined", "BackCompat", "function", "function" }, + IE = { "9", "CSS1Compat", "function", "function" }, + IE6 = { "undefined", "BackCompat", "undefined", "undefined" }, + IE8 = { "8", "CSS1Compat", "object", "object" }) + @NotYetImplemented(IE8) + public void documentMode_metaIE9() throws Exception { + documentMode("", " <meta http-equiv='X-UA-Compatible' content='IE=9'>\n"); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "undefined", "BackCompat", "function", "function" }, + IE6 = { "undefined", "BackCompat", "undefined", "undefined" }, + IE8 = { "8", "CSS1Compat", "object", "object" }, IE9 = { "9", "CSS1Compat", "function", "function" }, - DEFAULT = { "undefined", "CSS1Compat", "function", "function" }) - public void documentMode_html5() throws Exception { - final String html = "<!DOCTYPE html>\n" + IE10 = { "10", "CSS1Compat", "function", "function" }) + @NotYetImplemented(IE8) + public void documentMode_metaIEEdge() throws Exception { + documentMode("", " <meta http-equiv='X-UA-Compatible' content='IE=edge'>\n"); + } + + private void documentMode(final String doctype, final String meta) throws Exception { + final String html = doctype + "<html>\n" + "<head>\n" + + meta + " <script>\n" + " function test() {\n" + " alert(document.documentMode);\n" |
From: <rb...@us...> - 2013-10-04 18:33:23
|
Revision: 8590 http://sourceforge.net/p/htmlunit/code/8590 Author: rbri Date: 2013-10-04 18:33:20 +0000 (Fri, 04 Oct 2013) Log Message: ----------- use the correct accept header for javascript requests Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersion2Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2013-10-04 14:59:02 UTC (rev 8589) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2013-10-04 18:33:20 UTC (rev 8590) @@ -221,7 +221,7 @@ FIREFOX_17.setImgAcceptHeader("image/png,image/*;q=0.8,*/*;q=0.5"); FIREFOX_17.setCssAcceptHeader("text/css,*/*;q=0.1"); - INTERNET_EXPLORER_8.setHtmlAcceptHeader("image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, */*"); + INTERNET_EXPLORER_8.setHtmlAcceptHeader("image/gif, image/jpeg, image/pjpeg, image/pjpeg, */*"); final PluginConfiguration flash = new PluginConfiguration("Shockwave Flash", "Shockwave Flash 9.0 r31", "libflashplayer.so"); @@ -501,6 +501,15 @@ /** * Returns the value used by the browser for the accept header + * if requesting an script. + * @return the accept header string + */ + public String getScriptAcceptHeader() { + return "*/*"; + } + + /** + * Returns the value used by the browser for the accept header * if requesting an image. * @return the accept header string */ Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2013-10-04 14:59:02 UTC (rev 8589) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2013-10-04 18:33:20 UTC (rev 8590) @@ -1088,6 +1088,7 @@ final WebRequest request = new WebRequest(url); request.setAdditionalHeaders(new HashMap<String, String>(referringRequest.getAdditionalHeaders())); request.setAdditionalHeader("Referer", referringRequest.getUrl().toString()); + request.setAdditionalHeader("Accept", client.getBrowserVersion().getScriptAcceptHeader()); final Object cachedScript = cache.getCachedObject(url); if (cachedScript instanceof Script) { Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersion2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersion2Test.java 2013-10-04 14:59:02 UTC (rev 8589) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersion2Test.java 2013-10-04 18:33:20 UTC (rev 8590) @@ -41,7 +41,7 @@ */ @Test @Alerts(DEFAULT = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", - IE = "Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, */*", + IE = "Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, */*", IE10 = "Accept: text/html, application/xhtml+xml, */*") public void acceptHeaderGetUrl() throws Exception { final String html = "<html><body>Response</body></html>"; @@ -55,7 +55,7 @@ */ @Test @Alerts(DEFAULT = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", - IE = "Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, */*") + IE = "Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, */*") public void acceptHeaderWindowOpen() throws Exception { String html = "<html><body>Response</body></html>"; getMockWebConnection().setDefaultResponse(html); @@ -75,6 +75,48 @@ * @throws Exception if an error occurs */ @Test + @Alerts(DEFAULT = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", + IE = "Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, */*") + public void acceptHeaderAnchorClick() throws Exception { + String html = "<html><body>Response</body></html>"; + getMockWebConnection().setDefaultResponse(html); + + html = "<html><head><title>First</title></head>\n" + + "<body>\n" + + " <a id='clickme' href='test.html'>Click me</a>\n" + + "</body></html>"; + final WebDriver driver = loadPage2(html, getDefaultUrl()); + driver.findElement(By.id("clickme")).click(); + + assertEquals(2, getMockWebConnection().getRequestCount()); + assertEquals(getExpectedAlerts()[0], acceptHeaderString()); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", + IE = "Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, */*") + public void acceptHeaderAnchorClickWithType() throws Exception { + String html = "<html><body>Response</body></html>"; + getMockWebConnection().setDefaultResponse(html); + + html = "<html><head><title>First</title></head>\n" + + "<body>\n" + + " <a id='clickme' href='test.html' type='text/plain'>Click me</a>\n" + + "</body></html>"; + final WebDriver driver = loadPage2(html, getDefaultUrl()); + driver.findElement(By.id("clickme")).click(); + + assertEquals(2, getMockWebConnection().getRequestCount()); + assertEquals(getExpectedAlerts()[0], acceptHeaderString()); + } + + /** + * @throws Exception if an error occurs + */ + @Test @Alerts(DEFAULT = "Accept: image/png,image/*;q=0.8,*/*;q=0.5", CHROME = "Accept: image/webp,*/*;q=0.8", IE = "Accept: */*", @@ -127,6 +169,42 @@ * @throws Exception if an error occurs */ @Test + @Alerts(DEFAULT = "Accept: */*") + public void acceptHeaderJavascript() throws Exception { + final String html + = "<html><head>\n" + + " <script src='test.js' type='text/javascript'>\n" + + "</head>\n" + + "<body>\n" + + "</body></html>"; + loadPage2(html, getDefaultUrl()); + + assertEquals(2, getMockWebConnection().getRequestCount()); + assertEquals(getExpectedAlerts()[0], acceptHeaderString()); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = "Accept: */*") + public void acceptHeaderJavascriptWithoutType() throws Exception { + final String html + = "<html><head>\n" + + " <script src='test.js'>\n" + + "</head>\n" + + "<body>\n" + + "</body></html>"; + loadPage2(html, getDefaultUrl()); + + assertEquals(2, getMockWebConnection().getRequestCount()); + assertEquals(getExpectedAlerts()[0], acceptHeaderString()); + } + + /** + * @throws Exception if an error occurs + */ + @Test @Alerts(DEFAULT = "Accept: text/css,*/*;q=0.1", IE = "Accept: */*", IE10 = "Accept: text/css") |
From: <asa...@us...> - 2016-02-19 13:37:49
|
Revision: 11870 http://sourceforge.net/p/htmlunit/code/11870 Author: asashour Date: 2016-02-19 13:37:46 +0000 (Fri, 19 Feb 2016) Log Message: ----------- Constants Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ClientRectList.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Notification.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/HostTypeOfTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ClientRectList.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ClientRectList.java 2016-02-19 09:30:19 UTC (rev 11869) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/ClientRectList.java 2016-02-19 13:37:46 UTC (rev 11870) @@ -48,7 +48,7 @@ */ @JsxConstructor({ @WebBrowser(CHROME), @WebBrowser(value = FF, maxVersion = 24), @WebBrowser(EDGE) }) public ClientRectList() { - clientRects_ = new ArrayList<ClientRect>(); + clientRects_ = new ArrayList<>(); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Notification.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Notification.java 2016-02-19 09:30:19 UTC (rev 11869) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Notification.java 2016-02-19 13:37:46 UTC (rev 11870) @@ -19,6 +19,7 @@ import net.sourceforge.htmlunit.corejs.javascript.Scriptable; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; +import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstant; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxStaticFunction; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxStaticGetter; @@ -38,6 +39,12 @@ public class Notification extends EventTarget { /** + * The rule is a {@code CSSKeyframesRule}. + */ + @JsxConstant(@WebBrowser(CHROME)) + public static final short maxActions = 2; + + /** * JavaScript constructor. * @param title the title */ Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/HostTypeOfTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/HostTypeOfTest.java 2016-02-19 09:30:19 UTC (rev 11869) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/HostTypeOfTest.java 2016-02-19 13:37:46 UTC (rev 11870) @@ -3835,7 +3835,8 @@ */ @Test @Alerts(DEFAULT = "undefined", - IE = "object") + IE = "object", + CHROME = "function") public void cssNamespaceRule() throws Exception { test("CSSNamespaceRule"); } @@ -5792,7 +5793,8 @@ */ @Test @Alerts(DEFAULT = "undefined", - FF38 = "function") + FF38 = "function", + CHROME = "function") public void mediaDevices() throws Exception { test("MediaDevices"); } @@ -5925,8 +5927,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "undefined", - CHROME = "function") + @Alerts("undefined") public void mediaKeyError() throws Exception { test("MediaKeyError"); } @@ -5935,8 +5936,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "undefined", - CHROME = "function") + @Alerts("undefined") public void mediaKeyEvent() throws Exception { test("MediaKeyEvent"); } @@ -6026,7 +6026,6 @@ */ @Test @Alerts(DEFAULT = "undefined", - CHROME = "function", FF = "function", IE = "object") public void svgPathSeg() throws Exception { @@ -6038,7 +6037,6 @@ */ @Test @Alerts(DEFAULT = "undefined", - CHROME = "function", FF = "function", IE = "object") public void svgPathSegArcAbs() throws Exception { @@ -6050,7 +6048,6 @@ */ @Test @Alerts(DEFAULT = "undefined", - CHROME = "function", FF = "function", IE = "object") public void svgPathSegArcRel() throws Exception { @@ -6062,7 +6059,6 @@ */ @Test @Alerts(DEFAULT = "undefined", - CHROME = "function", FF = "function", IE = "object") public void svgPathSegClosePath() throws Exception { @@ -6074,7 +6070,6 @@ */ @Test @Alerts(DEFAULT = "undefined", - CHROME = "function", FF = "function", IE = "object") public void svgPathSegCurvetoCubicAbs() throws Exception { @@ -6086,7 +6081,6 @@ */ @Test @Alerts(DEFAULT = "undefined", - CHROME = "function", FF = "function", IE = "object") public void svgPathSegCurvetoCubicRel() throws Exception { @@ -6098,7 +6092,6 @@ */ @Test @Alerts(DEFAULT = "undefined", - CHROME = "function", FF = "function", IE = "object") public void svgPathSegCurvetoCubicSmoothAbs() throws Exception { @@ -6110,7 +6103,6 @@ */ @Test @Alerts(DEFAULT = "undefined", - CHROME = "function", FF = "function", IE = "object") public void svgPathSegCurvetoCubicSmoothRel() throws Exception { @@ -6122,7 +6114,6 @@ */ @Test @Alerts(DEFAULT = "undefined", - CHROME = "function", FF = "function", IE = "object") public void svgPathSegCurvetoQuadraticAbs() throws Exception { @@ -6134,7 +6125,6 @@ */ @Test @Alerts(DEFAULT = "undefined", - CHROME = "function", FF = "function", IE = "object") public void svgPathSegCurvetoQuadraticRel() throws Exception { @@ -6146,7 +6136,6 @@ */ @Test @Alerts(DEFAULT = "undefined", - CHROME = "function", FF = "function", IE = "object") public void svgPathSegCurvetoQuadraticSmoothAbs() throws Exception { @@ -6158,7 +6147,6 @@ */ @Test @Alerts(DEFAULT = "undefined", - CHROME = "function", FF = "function", IE = "object") public void svgPathSegCurvetoQuadraticSmoothRel() throws Exception { @@ -6170,7 +6158,6 @@ */ @Test @Alerts(DEFAULT = "undefined", - CHROME = "function", FF = "function", IE = "object") public void svgPathSegLinetoAbs() throws Exception { @@ -6182,7 +6169,6 @@ */ @Test @Alerts(DEFAULT = "undefined", - CHROME = "function", FF = "function", IE = "object") public void svgPathSegLinetoHorizontalAbs() throws Exception { @@ -6194,7 +6180,6 @@ */ @Test @Alerts(DEFAULT = "undefined", - CHROME = "function", FF = "function", IE = "object") public void svgPathSegLinetoHorizontalRel() throws Exception { @@ -6206,7 +6191,6 @@ */ @Test @Alerts(DEFAULT = "undefined", - CHROME = "function", FF = "function", IE = "object") public void svgPathSegLinetoRel() throws Exception { @@ -6218,7 +6202,6 @@ */ @Test @Alerts(DEFAULT = "undefined", - CHROME = "function", FF = "function", IE = "object") public void svgPathSegLinetoVerticalAbs() throws Exception { @@ -6230,7 +6213,6 @@ */ @Test @Alerts(DEFAULT = "undefined", - CHROME = "function", FF = "function", IE = "object") public void svgPathSegLinetoVerticalRel() throws Exception { @@ -6242,7 +6224,6 @@ */ @Test @Alerts(DEFAULT = "undefined", - CHROME = "function", FF = "function", IE = "object") public void svgPathSegList() throws Exception { @@ -6254,7 +6235,6 @@ */ @Test @Alerts(DEFAULT = "undefined", - CHROME = "function", FF = "function", IE = "object") public void svgPathSegMovetoAbs() throws Exception { @@ -6266,7 +6246,6 @@ */ @Test @Alerts(DEFAULT = "undefined", - CHROME = "function", FF = "function", IE = "object") public void svgPathSegMovetoRel() throws Exception { |
From: <rb...@us...> - 2016-03-04 09:36:56
|
Revision: 11999 http://sourceforge.net/p/htmlunit/code/11999 Author: rbri Date: 2016-03-04 09:36:53 +0000 (Fri, 04 Mar 2016) Log Message: ----------- adapt for latest chrome Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/RecursiveFunctionObject.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ElementTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLBodyElementTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2016-03-04 09:24:48 UTC (rev 11998) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2016-03-04 09:36:53 UTC (rev 11999) @@ -901,10 +901,6 @@ @BrowserFeature(@WebBrowser(FF)) JS_FUNCTION_TOSOURCE, - /** Indicates if the method 'toString' is enumerated. */ - @BrowserFeature(@WebBrowser(CHROME)) - JS_FUNCTION_TOSTRING_ENUMERATED, - /** HTMLElement instead of HTMLUnknownElement for elements with hyphen ('-'). */ @BrowserFeature({ @WebBrowser(FF), @WebBrowser(CHROME) }) JS_HTML_HYPHEN_ELEMENT_CLASS_NAME, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/RecursiveFunctionObject.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/RecursiveFunctionObject.java 2016-03-04 09:24:48 UTC (rev 11998) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/RecursiveFunctionObject.java 2016-03-04 09:36:53 UTC (rev 11999) @@ -14,7 +14,6 @@ */ package com.gargoylesoftware.htmlunit.javascript; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_FUNCTION_TOSTRING_ENUMERATED; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_IMAGE_HTML_IMAGE_ELEMENT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_INTL_V8_BREAK_ITERATOR; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_OPTION_HTML_OPTION_ELEMENT; @@ -62,9 +61,6 @@ if (super.has(name, start)) { return true; } - if ("toString".equals(name) && getBrowserVersion().hasFeature(JS_FUNCTION_TOSTRING_ENUMERATED)) { - return true; - } for (Class<?> c = getMethodOrConstructor().getDeclaringClass().getSuperclass(); c != null; c = c.getSuperclass()) { final Object scripatble = getParentScope().get(c.getSimpleName(), this); @@ -83,9 +79,6 @@ @Override public Object[] getIds() { final Set<Object> objects = new LinkedHashSet<>(); - if (getBrowserVersion().hasFeature(JS_FUNCTION_TOSTRING_ENUMERATED)) { - objects.add("toString"); - } for (final Object o : super.getIds()) { objects.add(o); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ElementTest.java 2016-03-04 09:24:48 UTC (rev 11998) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ElementTest.java 2016-03-04 09:36:53 UTC (rev 11999) @@ -672,21 +672,14 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = { "prototype found", "" }, - CHROME = { "prototype found", "toString, " + @Alerts(DEFAULT = { "prototype found", "" + "ELEMENT_NODE, ATTRIBUTE_NODE, TEXT_NODE, CDATA_SECTION_NODE, ENTITY_REFERENCE_NODE, " + "ENTITY_NODE, PROCESSING_INSTRUCTION_NODE, COMMENT_NODE, DOCUMENT_NODE, DOCUMENT_TYPE_NODE, " + "DOCUMENT_FRAGMENT_NODE, NOTATION_NODE, DOCUMENT_POSITION_DISCONNECTED, " + "DOCUMENT_POSITION_PRECEDING, " + "DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_CONTAINED_BY, " + "DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, " }, - FF = { "prototype found", "" - + "ELEMENT_NODE, ATTRIBUTE_NODE, TEXT_NODE, CDATA_SECTION_NODE, ENTITY_REFERENCE_NODE, " - + "ENTITY_NODE, PROCESSING_INSTRUCTION_NODE, COMMENT_NODE, DOCUMENT_NODE, DOCUMENT_TYPE_NODE, " - + "DOCUMENT_FRAGMENT_NODE, NOTATION_NODE, DOCUMENT_POSITION_DISCONNECTED, " - + "DOCUMENT_POSITION_PRECEDING, " - + "DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_CONTAINED_BY, " - + "DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, " }) + IE = { "prototype found", "" }) public void enumeratedProperties() throws Exception { final String html = "<html><head>\n" 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 2016-03-04 09:24:48 UTC (rev 11998) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/Window2Test.java 2016-03-04 09:36:53 UTC (rev 11999) @@ -1588,7 +1588,7 @@ @Test @Alerts(DEFAULT = { "[object Window]", "[object Window]", "" }, CHROME = { "[object Window]", "function Window() { [native code] }", - "toString, TEMPORARY, PERSISTENT, " }, + "TEMPORARY, PERSISTENT, " }, FF38 = { "[object Window]", "function Window() {\n [native code]\n}", "" }) public void enumeratedProperties() throws Exception { final String html Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLBodyElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLBodyElementTest.java 2016-03-04 09:24:48 UTC (rev 11998) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLBodyElementTest.java 2016-03-04 09:36:53 UTC (rev 11999) @@ -284,7 +284,7 @@ */ @Test @Alerts(DEFAULT = { "[object HTMLBodyElement]", "" }, - CHROME = { "function HTMLBodyElement() { [native code] }", "toString, " + CHROME = { "function HTMLBodyElement() { [native code] }", "" + "ELEMENT_NODE, ATTRIBUTE_NODE, TEXT_NODE, CDATA_SECTION_NODE, ENTITY_REFERENCE_NODE, " + "ENTITY_NODE, PROCESSING_INSTRUCTION_NODE, COMMENT_NODE, DOCUMENT_NODE, DOCUMENT_TYPE_NODE, " + "DOCUMENT_FRAGMENT_NODE, NOTATION_NODE, DOCUMENT_POSITION_DISCONNECTED, " |
From: <rb...@us...> - 2016-03-04 09:59:47
|
Revision: 12001 http://sourceforge.net/p/htmlunit/code/12001 Author: rbri Date: 2016-03-04 09:59:44 +0000 (Fri, 04 Mar 2016) Log Message: ----------- adapt for latest chrome Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionElement2Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2016-03-04 09:45:53 UTC (rev 12000) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2016-03-04 09:59:44 UTC (rev 12001) @@ -425,7 +425,7 @@ HTMLOPTION_PREVENT_DISABLED, /** Removing the selected attribute, de selects the option. */ - @BrowserFeature(@WebBrowser(FF)) + @BrowserFeature({ @WebBrowser(FF), @WebBrowser(CHROME) }) HTMLOPTION_REMOVE_SELECTED_ATTRIB_DESELECTS, /** Trims the value of the type attribute before to verify it. */ Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionElement2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionElement2Test.java 2016-03-04 09:45:53 UTC (rev 12000) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLOptionElement2Test.java 2016-03-04 09:59:44 UTC (rev 12001) @@ -1301,8 +1301,6 @@ @Test @Alerts(DEFAULT = { "false-null", "true-true", "false-null", "false-null", "true-true", "false-null" }, - CHROME = { "false-null", "true-true", "true-null", - "false-null", "true-true", "true-null" }, IE = { "false-null", "true-true", "true-", "false-null", "true-true", "false-null" }) @NotYetImplemented(IE) |
From: <rb...@us...> - 2016-05-12 17:55:43
|
Revision: 12597 http://sourceforge.net/p/htmlunit/code/12597 Author: rbri Date: 2016-05-12 17:55:41 +0000 (Thu, 12 May 2016) Log Message: ----------- latest Chrome Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/FormData.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/FormDataTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/FormData.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/FormData.java 2016-05-12 15:47:31 UTC (rev 12596) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/FormData.java 2016-05-12 17:55:41 UTC (rev 12597) @@ -14,6 +14,7 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.xml; +import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.CHROME; import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.FF; import java.util.ArrayList; @@ -92,7 +93,7 @@ * Removes the entry (if exists). * @param name the name of the field to remove */ - @JsxFunction(functionName = "delete", value = @WebBrowser(value = FF, minVersion = 45)) + @JsxFunction(functionName = "delete", value = {@WebBrowser(value = FF, minVersion = 45), @WebBrowser(CHROME)}) public void delete_js(final String name) { if (StringUtils.isEmpty(name)) { return; @@ -111,7 +112,7 @@ * @param name the name of the field to check * @return the first value found for the give name */ - @JsxFunction(@WebBrowser(value = FF, minVersion = 45)) + @JsxFunction({@WebBrowser(value = FF, minVersion = 45), @WebBrowser(CHROME)}) public String get(final String name) { if (StringUtils.isEmpty(name)) { return null; @@ -131,7 +132,7 @@ * @param name the name of the field to check * @return the first value found for the give name */ - @JsxFunction(@WebBrowser(value = FF, minVersion = 45)) + @JsxFunction({@WebBrowser(value = FF, minVersion = 45), @WebBrowser(CHROME)}) public Scriptable getAll(final String name) { if (StringUtils.isEmpty(name)) { return Context.getCurrentContext().newArray(this, 0); @@ -154,7 +155,7 @@ * @param name the name of the field to check * @return true if the name exists */ - @JsxFunction(@WebBrowser(value = FF, minVersion = 45)) + @JsxFunction({@WebBrowser(value = FF, minVersion = 45), @WebBrowser(CHROME)}) public boolean has(final String name) { if (StringUtils.isEmpty(name)) { return false; @@ -177,7 +178,7 @@ * @param value the field's value * @param filename the filename reported to the server (optional) */ - @JsxFunction(@WebBrowser(value = FF, minVersion = 45)) + @JsxFunction({@WebBrowser(value = FF, minVersion = 45), @WebBrowser(CHROME)}) public void set(final String name, final Object value, final Object filename) { if (StringUtils.isEmpty(name)) { return; Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/FormDataTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/FormDataTest.java 2016-05-12 15:47:31 UTC (rev 12596) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/xml/FormDataTest.java 2016-05-12 17:55:41 UTC (rev 12597) @@ -55,8 +55,9 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = {"function", "undefined", "undefined", "undefined", "undefined", "undefined"}, - FF45 = {"function", "function", "function", "function", "function", "function"}) + @Alerts(DEFAULT = {"function", "function", "function", "function", "function", "function"}, + FF38 = {"function", "undefined", "undefined", "undefined", "undefined", "undefined"}, + IE = {"function", "undefined", "undefined", "undefined", "undefined", "undefined"}) public void functions() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ @@ -397,8 +398,9 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = "no delete", - FF45 = {"myKey", "myKey1"}) + @Alerts(DEFAULT = {"myKey", "myKey1"}, + FF38 = "no delete", + IE = "no delete") public void delete() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ @@ -451,8 +453,9 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = "no get", - FF45 = {"myValue", "null", "null", "null", "null"}) + @Alerts(DEFAULT = {"myValue", "null", "null", "null", "null"}, + FF38 = "no get", + IE = "no get") public void get() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ @@ -494,8 +497,9 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = "no getAll", - FF45 = {"myValue,myValue2", "", "", "", ""}) + @Alerts(DEFAULT = {"myValue,myValue2", "", "", "", ""}, + FF38 = "no getAll", + IE = "no getAll") public void getAll() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ @@ -537,8 +541,9 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = "no has", - FF45 = {"true", "false", "false"}) + @Alerts(DEFAULT = {"true", "false", "false"}, + FF38 = "no has", + IE = "no has") public void has() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ |
From: <rb...@us...> - 2016-09-05 15:52:27
|
Revision: 12960 http://sourceforge.net/p/htmlunit/code/12960 Author: rbri Date: 2016-09-05 15:52:24 +0000 (Mon, 05 Sep 2016) Log Message: ----------- more NaN handling Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclarationTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration.java 2016-09-04 15:23:12 UTC (rev 12959) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration.java 2016-09-05 15:52:24 UTC (rev 12960) @@ -1865,11 +1865,11 @@ final String trimedOpacity = opacity.trim(); try { - final float value = Float.parseFloat(trimedOpacity); + final double value = Double.parseDouble(trimedOpacity); if (value % 1 == 0) { return Integer.toString((int) value); } - return Float.toString(value); + return Double.toString(value); } catch (final NumberFormatException e) { // ignore wrong value @@ -1882,19 +1882,37 @@ * @param opacity the new attribute */ @JsxSetter - public void setOpacity(final String opacity) { - if (opacity.isEmpty()) { - setStyleAttribute(OPACITY.getAttributeName(), opacity); + public void setOpacity(final Object opacity) { + if (ScriptRuntime.NaNobj == opacity) { + return; } - final String trimedOpacity = opacity.trim(); - try { - Float.parseFloat(trimedOpacity); - setStyleAttribute(OPACITY.getAttributeName(), trimedOpacity); + final double doubleValue; + if (opacity instanceof Number) { + doubleValue = ((Number) opacity).doubleValue(); } - catch (final NumberFormatException e) { - // ignore wrong value + else { + String valueString = Context.toString(opacity); + + if (valueString.isEmpty()) { + setStyleAttribute(OPACITY.getAttributeName(), valueString); + return; + } + + valueString = valueString.trim(); + try { + doubleValue = Double.parseDouble(valueString); + } + catch (final NumberFormatException e) { + // ignore wrong value + return; + } } + + if (Double.isNaN(doubleValue) || Double.isInfinite(doubleValue)) { + return; + } + setStyleAttribute(OPACITY.getAttributeName(), Double.toString(doubleValue)); } /** @@ -3008,7 +3026,7 @@ token = token.substring(0, token.length() - 2); } try { - Float.parseFloat(token); + Double.parseDouble(token); return true; } catch (final NumberFormatException e) { Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclarationTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclarationTest.java 2016-09-04 15:23:12 UTC (rev 12959) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclarationTest.java 2016-09-05 15:52:24 UTC (rev 12960) @@ -410,7 +410,7 @@ * @throws Exception if an error occurs */ @Test - @Alerts(" 0.5 0.4 0.33333 -3 3 8 7 7 7 7 ") + @Alerts(" 0.5 0.4 0.33333 -3 3 8 7 7 7 7 7 ") public void setOpacity() throws Exception { final String html = "<html><body>\n" + "<div id='d'>d</div>\n" @@ -432,6 +432,8 @@ + "s += d.style.opacity + ' ';\n" + "d.style.opacity = ' 7 ';\n" + "s += d.style.opacity + ' ';\n" + + "d.style.opacity = NaN;\n" + + "s += d.style.opacity + ' ';\n" + "d.style.opacity = '10px';\n" + "s += d.style.opacity + ' ';\n" + "d.style.opacity = 'foo';\n" |
From: <asa...@us...> - 2017-01-26 16:40:50
|
Revision: 13427 http://sourceforge.net/p/htmlunit/code/13427 Author: asashour Date: 2017-01-26 16:40:47 +0000 (Thu, 26 Jan 2017) Log Message: ----------- Notify AttributeChangeListeners only at the end of 'typing()'. Issue 1811 Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/BaseFrameElement.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DoTypeProcessor.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomText.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlButton.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlButtonInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlElement.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlEmailInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlHiddenInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImage.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImageInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlResetInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlScript.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlSelect.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlSubmitInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/MutationObserver.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CodeStyleTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/MutationObserverTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/BaseFrameElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/BaseFrameElement.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/BaseFrameElement.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -350,12 +350,13 @@ * {@inheritDoc} */ @Override - public void setAttributeNS(final String namespaceURI, final String qualifiedName, String attributeValue) { + public void setAttributeNS(final String namespaceURI, final String qualifiedName, String attributeValue, + final boolean notifyAttributeChangeListeners) { if (null != attributeValue && "src".equals(qualifiedName)) { attributeValue = attributeValue.trim(); } - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); if ("src".equals(qualifiedName) && WebClient.ABOUT_BLANK != attributeValue) { if (isAttachedToPage()) { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DoTypeProcessor.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DoTypeProcessor.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DoTypeProcessor.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -46,7 +46,7 @@ import com.gargoylesoftware.htmlunit.html.impl.SelectionDelegate; /** - * The process for {@link HtmlElement#doType(char, boolean)}. + * The process for {@link HtmlElement#doType(char, boolean, boolean)}. * * @author Marc Guillemot * @author Ronald Brill @@ -82,7 +82,7 @@ } void doType(final String currentValue, final SelectionDelegate selectionDelegate, - final char c, final HtmlElement element) { + final char c, final HtmlElement element, final boolean lastType) { int selectionStart = selectionDelegate.getSelectionStart(); int selectionEnd = selectionDelegate.getSelectionEnd(); @@ -124,7 +124,7 @@ } } - typeDone(newValue.toString()); + typeDone(newValue.toString(), lastType); selectionDelegate.setSelectionStart(selectionStart); selectionDelegate.setSelectionEnd(selectionEnd); @@ -170,12 +170,12 @@ clipboard.setContents(stringSelection, this); } - private void typeDone(final String newValue) { + private void typeDone(final String newValue, final boolean notifyAttributeChangeListeners) { if (domNode_ instanceof DomText) { ((DomText) domNode_).setData(newValue); } else { - ((HtmlElement) domNode_).typeDone(newValue); + ((HtmlElement) domNode_).typeDone(newValue, notifyAttributeChangeListeners); } } @@ -187,7 +187,7 @@ } void doType(final String currentValue, final SelectionDelegate selectionDelegate, - final int keyCode, final HtmlElement element) { + final int keyCode, final HtmlElement element, final boolean lastType) { final StringBuilder newValue = new StringBuilder(currentValue); int selectionStart = selectionDelegate.getSelectionStart(); @@ -195,7 +195,7 @@ final Character ch = SPECIAL_KEYS_MAP_.get(keyCode); if (ch != null) { - doType(currentValue, selectionDelegate, ch, element); + doType(currentValue, selectionDelegate, ch, element, lastType); return; } switch (keyCode) { @@ -263,7 +263,7 @@ selectionEnd = selectionStart; } - typeDone(newValue.toString()); + typeDone(newValue.toString(), lastType); selectionDelegate.setSelectionStart(selectionStart); selectionDelegate.setSelectionEnd(selectionEnd); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -463,7 +463,7 @@ */ @Override public void setAttribute(final String attributeName, final String attributeValue) { - setAttributeNS(null, attributeName, attributeValue); + setAttributeNS(null, attributeName, attributeValue, true); } /** @@ -474,8 +474,21 @@ * @param attributeValue the value of the attribute */ @Override - public void setAttributeNS(final String namespaceURI, final String qualifiedName, + public final void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { + setAttributeNS(namespaceURI, qualifiedName, attributeValue, true); + } + + /** + * Sets the value of the attribute specified by namespace and qualified name. + * + * @param namespaceURI the URI that identifies an XML namespace + * @param qualifiedName the qualified name (prefix:local) of the attribute + * @param attributeValue the value of the attribute + * @param notifyAttributeChangeListeners to notify the associated {@link HtmlAttributeChangeListener}s + */ + protected void setAttributeNS(final String namespaceURI, final String qualifiedName, + final String attributeValue, final boolean notifyAttributeChangeListeners) { final String value = attributeValue; final DomAttr newAttr = new DomAttr(getPage(), namespaceURI, qualifiedName, value, true); newAttr.setParentNode(this); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomText.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomText.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomText.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -169,13 +169,15 @@ * @param c the character you with to simulate typing * @param startAtEnd whether typing should start at the text end or not * @param htmlElement the element in which typing occurs + * @param lastType is this the last character to type */ - protected void doType(final char c, final boolean startAtEnd, final HtmlElement htmlElement) { + protected void doType(final char c, final boolean startAtEnd, final HtmlElement htmlElement, + final boolean lastType) { initDoTypeProcessor(); if (startAtEnd) { selectionDelegate_.setSelectionStart(getData().length()); } - doTypeProcessor_.doType(getData(), selectionDelegate_, c, htmlElement); + doTypeProcessor_.doType(getData(), selectionDelegate_, c, htmlElement, lastType); } /** @@ -184,13 +186,15 @@ * @param keyCode the key code wish to simulate typing * @param startAtEnd whether typing should start at the text end or not * @param htmlElement the element in which typing occurs + * @param lastType is this the last character to type */ - protected void doType(final int keyCode, final boolean startAtEnd, final HtmlElement htmlElement) { + protected void doType(final int keyCode, final boolean startAtEnd, final HtmlElement htmlElement, + final boolean lastType) { initDoTypeProcessor(); if (startAtEnd) { selectionDelegate_.setSelectionStart(getData().length()); } - doTypeProcessor_.doType(getData(), selectionDelegate_, keyCode, htmlElement); + doTypeProcessor_.doType(getData(), selectionDelegate_, keyCode, htmlElement, lastType); } private void initDoTypeProcessor() { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlButton.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlButton.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlButton.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -326,14 +326,15 @@ * {@inheritDoc} */ @Override - public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { + public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, + final boolean notifyAttributeChangeListeners) { if ("name".equals(qualifiedName)) { if (newNames_.isEmpty()) { newNames_ = new HashSet<>(); } newNames_.add(attributeValue); } - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlButtonInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlButtonInput.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlButtonInput.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -55,11 +55,12 @@ * {@inheritDoc} */ @Override - public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { + public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, + final boolean notifyAttributeChangeListeners) { if ("value".equals(qualifiedName)) { setDefaultValue(attributeValue, false); } - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -226,14 +226,15 @@ * {@inheritDoc} */ @Override - public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { + public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, + final boolean notifyAttributeChangeListeners) { if ("value".equals(qualifiedName)) { setDefaultValue(attributeValue, false); } if ("checked".equals(qualifiedName)) { checkedState_ = true; } - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlElement.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlElement.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -165,22 +165,15 @@ } /** - * Sets the value of the specified attribute. This method may be overridden by subclasses - * which are interested in specific attribute value changes, but such methods <b>must</b> - * invoke <tt>super.setAttributeValue()</tt>, and <b>should</b> consider the value of the - * <tt>cloning</tt> parameter when deciding whether or not to execute custom logic. - * - * @param namespaceURI the URI that identifies an XML namespace - * @param qualifiedName the qualified name of the attribute - * @param attributeValue the value of the attribute + * {@inheritDoc} */ @Override public void setAttributeNS(final String namespaceURI, final String qualifiedName, - final String attributeValue) { + final String attributeValue, final boolean notifyAttributeChangeListeners) { // TODO: Clean up; this is a hack for HtmlElement living within an XmlPage. if (null == getHtmlPageOrNull()) { - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); return; } @@ -200,10 +193,13 @@ else { event = new HtmlAttributeChangeEvent(this, qualifiedName, oldAttributeValue); } - notifyAttributeChangeListeners(event, this, oldAttributeValue); - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); + if (notifyAttributeChangeListeners) { + notifyAttributeChangeListeners(event, this, oldAttributeValue); + } + fireAttributeChangeImpl(event, htmlPage, mappedElement, qualifiedName, attributeValue, oldAttributeValue); } @@ -519,7 +515,7 @@ * @exception IOException if an IO error occurs */ public Page type(final char c) throws IOException { - return type(c, false); + return type(c, false, true); } /** @@ -530,10 +526,11 @@ * * @param c the character you wish to simulate typing * @param startAtEnd whether typing should start at the text end or not + * @param lastType is this the last character to type * @return the page contained in the current window as returned by {@link WebClient#getCurrentWindow()} * @exception IOException if an IO error occurs */ - private Page type(final char c, final boolean startAtEnd) + private Page type(final char c, final boolean startAtEnd, final boolean lastType) throws IOException { if (this instanceof DisabledElement && ((DisabledElement) this).isDisabled()) { return getPage(); @@ -571,7 +568,7 @@ if ((shiftDown == null || !shiftDown.isAborted(shiftDownResult)) && !keyPress.isAborted(keyPressResult)) { - doType(c, startAtEnd); + doType(c, startAtEnd, lastType); } } @@ -616,7 +613,7 @@ * @return the page that occupies this window after typing */ public Page type(final int keyCode) { - return type(keyCode, false, true, true, true); + return type(keyCode, false, true, true, true, true); } /** @@ -637,7 +634,7 @@ final Object[] entry = keys.get(i); final boolean startAtEnd = i == 0 && keyboard.isStartAtEnd(); if (entry.length == 1) { - type((char) entry[0], startAtEnd); + type((char) entry[0], startAtEnd, i == keys.size() - 1); } else { final int key = (int) entry[0]; @@ -670,10 +667,10 @@ default: } - page = type(key, startAtEnd, true, keyPress, keyUp); + page = type(key, startAtEnd, true, keyPress, keyUp, i == keys.size() - 1); } else { - page = type(key, startAtEnd, false, false, true); + page = type(key, startAtEnd, false, false, true, i == keys.size() - 1); } } } @@ -682,7 +679,8 @@ } private Page type(final int keyCode, final boolean startAtEnd, - final boolean fireKeyDown, final boolean fireKeyPress, final boolean fireKeyUp) { + final boolean fireKeyDown, final boolean fireKeyPress, final boolean fireKeyUp, + final boolean lastType) { if (this instanceof DisabledElement && ((DisabledElement) this).isDisabled()) { return getPage(); } @@ -720,7 +718,7 @@ if (keyDown != null && !keyDown.isAborted(keyDownResult) && (keyPress == null || !keyPress.isAborted(keyPressResult))) { - doType(keyCode, startAtEnd); + doType(keyCode, startAtEnd, lastType); } if (this instanceof HtmlTextInput @@ -756,15 +754,16 @@ * Performs the effective type action, called after the keyPress event and before the keyUp event. * @param c the character you with to simulate typing * @param startAtEnd whether typing should start at the text end or not + * @param lastType is this the last character to type */ - protected void doType(final char c, final boolean startAtEnd) { + protected void doType(final char c, final boolean startAtEnd, final boolean lastType) { final DomNode domNode = getDoTypeNode(); if (domNode instanceof DomText) { - ((DomText) domNode).doType(c, startAtEnd, this); + ((DomText) domNode).doType(c, startAtEnd, this, lastType); } else if (domNode instanceof HtmlElement) { try { - ((HtmlElement) domNode).type(c, startAtEnd); + ((HtmlElement) domNode).type(c, startAtEnd, lastType); } catch (final IOException e) { throw new RuntimeException(e); @@ -779,14 +778,15 @@ * * @param keyCode the key code wish to simulate typing * @param startAtEnd whether typing should start at the text end or not + * @param lastType is this the last to type */ - protected void doType(final int keyCode, final boolean startAtEnd) { + protected void doType(final int keyCode, final boolean startAtEnd, final boolean lastType) { final DomNode domNode = getDoTypeNode(); if (domNode instanceof DomText) { - ((DomText) domNode).doType(keyCode, startAtEnd, this); + ((DomText) domNode).doType(keyCode, startAtEnd, this, lastType); } else if (domNode instanceof HtmlElement) { - ((HtmlElement) domNode).type(keyCode, startAtEnd, true, true, true); + ((HtmlElement) domNode).type(keyCode, startAtEnd, true, true, true, lastType); } } @@ -822,8 +822,9 @@ /** * Called from {@link DoTypeProcessor}. * @param newValue the new value + * @param notifyAttributeChangeListeners to notify the associated {@link HtmlAttributeChangeListener}s */ - protected void typeDone(final String newValue) { + protected void typeDone(final String newValue, final boolean notifyAttributeChangeListeners) { // nothing } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlEmailInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlEmailInput.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlEmailInput.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -126,31 +126,31 @@ * {@inheritDoc} */ @Override - protected void doType(final char c, final boolean startAtEnd) { + protected void doType(final char c, final boolean startAtEnd, final boolean lastType) { if (startAtEnd) { selectionDelegate_.setSelectionStart(getValueAttribute().length()); } - doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, c, this); + doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, c, this, lastType); } /** * {@inheritDoc} */ @Override - protected void doType(final int keyCode, final boolean startAtEnd) { + protected void doType(final int keyCode, final boolean startAtEnd, final boolean lastType) { if (startAtEnd) { selectionDelegate_.setSelectionStart(getValueAttribute().length()); } - doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, keyCode, this); + doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, keyCode, this, lastType); } /** * {@inheritDoc} */ @Override - protected void typeDone(final String newValue) { + protected void typeDone(final String newValue, final boolean notifyAttributeChangeListeners) { if (newValue.length() <= getMaxLength()) { - setAttribute("value", newValue); + setAttributeNS(null, "value", newValue, notifyAttributeChangeListeners); } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlHiddenInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlHiddenInput.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlHiddenInput.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -48,11 +48,12 @@ * {@inheritDoc} */ @Override - public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { + public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, + final boolean notifyAttributeChangeListeners) { if ("value".equals(qualifiedName)) { setDefaultValue(attributeValue, false); } - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImage.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImage.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImage.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -111,13 +111,14 @@ * {@inheritDoc} */ @Override - public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String value) { + public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String value, + final boolean notifyAttributeChangeListeners) { final HtmlPage htmlPage = getHtmlPageOrNull(); if ("src".equals(qualifiedName) && value != ATTRIBUTE_NOT_DEFINED && htmlPage != null) { final String oldValue = getAttributeNS(namespaceURI, qualifiedName); if (!oldValue.equals(value)) { - super.setAttributeNS(namespaceURI, qualifiedName, value); + super.setAttributeNS(namespaceURI, qualifiedName, value, notifyAttributeChangeListeners); // onload handlers may need to be invoked again, and a new image may need to be downloaded onloadInvoked_ = false; @@ -139,7 +140,7 @@ } } - super.setAttributeNS(namespaceURI, qualifiedName, value); + super.setAttributeNS(namespaceURI, qualifiedName, value, notifyAttributeChangeListeners); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImageInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImageInput.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImageInput.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -166,11 +166,12 @@ * {@inheritDoc} */ @Override - public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { + public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, + final boolean notifyAttributeChangeListeners) { if ("value".equals(qualifiedName)) { setDefaultValue(attributeValue, false); } - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlInput.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlInput.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -403,7 +403,7 @@ else { event = new HtmlAttributeChangeEvent(this, "value", defaultValue_); } - notifyAttributeChangeListeners(event, this, defaultValue_); +// notifyAttributeChangeListeners(event, this, defaultValue_); defaultValue_ = defaultValue; } } @@ -559,14 +559,15 @@ * {@inheritDoc} */ @Override - public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { + public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, + final boolean notifyAttributeChangeListeners) { if ("name".equals(qualifiedName)) { if (newNames_.isEmpty()) { newNames_ = new HashSet<>(); } newNames_.add(attributeValue); } - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlNumberInput.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -50,31 +50,31 @@ * {@inheritDoc} */ @Override - protected void doType(final char c, final boolean startAtEnd) { + protected void doType(final char c, final boolean startAtEnd, final boolean lastType) { if (startAtEnd) { selectionDelegate_.setSelectionStart(getValueAttribute().length()); } - doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, c, this); + doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, c, this, lastType); } /** * {@inheritDoc} */ @Override - protected void doType(final int keyCode, final boolean startAtEnd) { + protected void doType(final int keyCode, final boolean startAtEnd, final boolean lastType) { if (startAtEnd) { selectionDelegate_.setSelectionStart(getValueAttribute().length()); } - doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, keyCode, this); + doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, keyCode, this, lastType); } /** * {@inheritDoc} */ @Override - protected void typeDone(final String newValue) { + protected void typeDone(final String newValue, final boolean notifyAttributeChangeListeners) { if (newValue.length() <= getMaxLength()) { - setAttribute("value", newValue); + setAttributeNS(null, "value", newValue, notifyAttributeChangeListeners); } } @@ -154,8 +154,9 @@ * {@inheritDoc} */ @Override - public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, + final boolean notifyAttributeChangeListeners) { + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); if ("value".equals(qualifiedName)) { final SgmlPage page = getPage(); if (page != null && page.isHtmlPage()) { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -127,31 +127,31 @@ * {@inheritDoc} */ @Override - protected void doType(final char c, final boolean startAtEnd) { + protected void doType(final char c, final boolean startAtEnd, final boolean lastType) { if (startAtEnd) { selectionDelegate_.setSelectionStart(getValueAttribute().length()); } - doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, c, this); + doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, c, this, lastType); } /** * {@inheritDoc} */ @Override - protected void doType(final int keyCode, final boolean startAtEnd) { + protected void doType(final int keyCode, final boolean startAtEnd, final boolean lastType) { if (startAtEnd) { selectionDelegate_.setSelectionStart(getValueAttribute().length()); } - doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, keyCode, this); + doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, keyCode, this, lastType); } /** * {@inheritDoc} */ @Override - protected void typeDone(final String newValue) { + protected void typeDone(final String newValue, final boolean notifyAttributeChangeListeners) { if (newValue.length() <= getMaxLength()) { - setAttribute("value", newValue); + setAttributeNS(null, "value", newValue, notifyAttributeChangeListeners); } } @@ -167,8 +167,9 @@ * {@inheritDoc} */ @Override - public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, + final boolean notifyAttributeChangeListeners) { + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); if ("value".equals(qualifiedName)) { final SgmlPage page = getPage(); if (page != null && page.isHtmlPage()) { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -307,14 +307,15 @@ * {@inheritDoc} */ @Override - public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { + public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, + final boolean notifyAttributeChangeListeners) { if ("value".equals(qualifiedName)) { setDefaultValue(attributeValue, false); } if ("checked".equals(qualifiedName)) { checkedState_ = true; } - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlResetInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlResetInput.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlResetInput.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -115,11 +115,12 @@ * {@inheritDoc} */ @Override - public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { + public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, + final boolean notifyAttributeChangeListeners) { if ("value".equals(qualifiedName)) { setDefaultValue(attributeValue, false); } - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlScript.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlScript.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlScript.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -180,15 +180,16 @@ * (behavior varies by browser version). {@inheritDoc} */ @Override - public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { + public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, + final boolean notifyAttributeChangeListeners) { // special additional processing for the 'src' if (namespaceURI != null || !"src".equals(qualifiedName)) { - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); return; } final String oldValue = getAttributeNS(namespaceURI, qualifiedName); - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); if (isAttachedToPage()) { // if FF, only execute if the "src" attribute Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlSelect.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlSelect.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlSelect.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -667,14 +667,15 @@ * {@inheritDoc} */ @Override - public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { + public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, + final boolean notifyAttributeChangeListeners) { if ("name".equals(qualifiedName)) { if (newNames_.isEmpty()) { newNames_ = new HashSet<>(); } newNames_.add(attributeValue); } - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlSubmitInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlSubmitInput.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlSubmitInput.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -152,11 +152,12 @@ * {@inheritDoc} */ @Override - public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { + public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, + final boolean notifyAttributeChangeListeners) { if ("value".equals(qualifiedName)) { setDefaultValue(attributeValue, false); } - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTelInput.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -111,31 +111,31 @@ * {@inheritDoc} */ @Override - protected void doType(final char c, final boolean startAtEnd) { + protected void doType(final char c, final boolean startAtEnd, final boolean lastType) { if (startAtEnd) { selectionDelegate_.setSelectionStart(getValueAttribute().length()); } - doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, c, this); + doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, c, this, lastType); } /** * {@inheritDoc} */ @Override - protected void doType(final int keyCode, final boolean startAtEnd) { + protected void doType(final int keyCode, final boolean startAtEnd, final boolean lastType) { if (startAtEnd) { selectionDelegate_.setSelectionStart(getValueAttribute().length()); } - doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, keyCode, this); + doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, keyCode, this, lastType); } /** * {@inheritDoc} */ @Override - protected void typeDone(final String newValue) { + protected void typeDone(final String newValue, final boolean notifyAttributeChangeListeners) { if (newValue.length() <= getMaxLength()) { - setAttribute("value", newValue); + setAttributeNS(null, "value", newValue, notifyAttributeChangeListeners); } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextArea.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -464,29 +464,29 @@ * {@inheritDoc} */ @Override - protected void doType(final char c, final boolean startAtEnd) { + protected void doType(final char c, final boolean startAtEnd, final boolean lastType) { if (startAtEnd) { selectionDelegate_.setSelectionStart(getText().length()); } - doTypeProcessor_.doType(getText(), selectionDelegate_, c, this); + doTypeProcessor_.doType(getText(), selectionDelegate_, c, this, lastType); } /** * {@inheritDoc} */ @Override - protected void doType(final int keyCode, final boolean startAtEnd) { + protected void doType(final int keyCode, final boolean startAtEnd, final boolean lastType) { if (startAtEnd) { selectionDelegate_.setSelectionStart(getText().length()); } - doTypeProcessor_.doType(getText(), selectionDelegate_, keyCode, this); + doTypeProcessor_.doType(getText(), selectionDelegate_, keyCode, this, lastType); } /** * {@inheritDoc} */ @Override - protected void typeDone(final String newValue) { + protected void typeDone(final String newValue, final boolean notifyAttributeChangeListeners) { setTextInternal(newValue); } @@ -553,14 +553,15 @@ * {@inheritDoc} */ @Override - public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { + public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, + final boolean notifyAttributeChangeListeners) { if ("name".equals(qualifiedName)) { if (newNames_.isEmpty()) { newNames_ = new HashSet<>(); } newNames_.add(attributeValue); } - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); } /** Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -56,31 +56,31 @@ * {@inheritDoc} */ @Override - protected void doType(final char c, final boolean startAtEnd) { + protected void doType(final char c, final boolean startAtEnd, final boolean lastType) { if (startAtEnd) { selectionDelegate_.setSelectionStart(getValueAttribute().length()); } - doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, c, this); + doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, c, this, lastType); } /** * {@inheritDoc} */ @Override - protected void doType(final int keyCode, final boolean startAtEnd) { + protected void doType(final int keyCode, final boolean startAtEnd, final boolean lastType) { if (startAtEnd) { selectionDelegate_.setSelectionStart(getValueAttribute().length()); } - doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, keyCode, this); + doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, keyCode, this, lastType); } /** * {@inheritDoc} */ @Override - protected void typeDone(final String newValue) { + protected void typeDone(final String newValue, final boolean notifyAttributeChangeListeners) { if (newValue.length() <= getMaxLength()) { - setAttribute("value", newValue); + setAttributeNS(null, "value", newValue, notifyAttributeChangeListeners); } } @@ -160,8 +160,9 @@ * {@inheritDoc} */ @Override - public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue) { - super.setAttributeNS(namespaceURI, qualifiedName, attributeValue); + public void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, + final boolean notifyAttributeChangeListeners) { + super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners); if ("value".equals(qualifiedName)) { final SgmlPage page = getPage(); if (page != null && page.isHtmlPage()) { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlUrlInput.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -126,31 +126,31 @@ * {@inheritDoc} */ @Override - protected void doType(final char c, final boolean startAtEnd) { + protected void doType(final char c, final boolean startAtEnd, final boolean lastType) { if (startAtEnd) { selectionDelegate_.setSelectionStart(getValueAttribute().length()); } - doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, c, this); + doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, c, this, lastType); } /** * {@inheritDoc} */ @Override - protected void doType(final int keyCode, final boolean startAtEnd) { + protected void doType(final int keyCode, final boolean startAtEnd, final boolean lastType) { if (startAtEnd) { selectionDelegate_.setSelectionStart(getValueAttribute().length()); } - doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, keyCode, this); + doTypeProcessor_.doType(getValueAttribute(), selectionDelegate_, keyCode, this, lastType); } /** * {@inheritDoc} */ @Override - protected void typeDone(final String newValue) { + protected void typeDone(final String newValue, final boolean notifyAttributeChangeListeners) { if (newValue.length() <= getMaxLength()) { - setAttribute("value", newValue); + setAttributeNS(null, "value", newValue, notifyAttributeChangeListeners); } } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/MutationObserver.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/MutationObserver.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/MutationObserver.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -103,6 +103,15 @@ } /** + * Empties the MutationObserver instance's record queue and returns what was in there. + * @return an Array of {@link MutationRecord}s + */ + @JsxFunction + public NativeArray takeRecords() { + return new NativeArray(0); + } + + /** * {@inheritDoc} */ @Override Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CodeStyleTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CodeStyleTest.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CodeStyleTest.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -901,7 +901,7 @@ || lineTrimmed.startsWith("if")) { final int difference = getInitialSpaces(next) - getInitialSpaces(line); if (difference > 2) { - addFailure("Too many spaces in " + relativePath + ", line: " + (i + 2)); + addFailure("Too many initial spaces in " + relativePath + ", line: " + (i + 2)); } else if (difference == 1) { addFailure("Add one more space in " + relativePath + ", line: " + (i + 2)); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/MutationObserverTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/MutationObserverTest.java 2017-01-26 12:04:47 UTC (rev 13426) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/MutationObserverTest.java 2017-01-26 16:40:47 UTC (rev 13427) @@ -195,14 +195,14 @@ */ @Test @Alerts("[object HTMLHeadingElement]-attributes") - public void test() throws Exception { + public void attributeValue2() throws Exception { final String html = "<html><head><script>\n" + " function makeRed() {\n" + " document.getElementById('headline').setAttribute('style', 'color: red');\n" + " }\n" + " function print(mutation) {\n" - + " alert(mutation.target + '-' + mutation.type);\n" + + " alert(mutation.target + '-' + mutation.type);\n" + " }\n" + " function test() {\n" @@ -227,7 +227,7 @@ + " <input id='id1' type='button' onclick='makeRed()' value='Make Red'>\n" + " </div>\n" + "</body></html>\n"; - WebDriver driver = loadPage2(html); + final WebDriver driver = loadPage2(html); driver.findElement(By.id("id1")).click(); verifyAlerts(driver, getExpectedAlerts()); |
From: <asa...@us...> - 2017-01-26 17:10:53
|
Revision: 13429 http://sourceforge.net/p/htmlunit/code/13429 Author: asashour Date: 2017-01-26 17:10:50 +0000 (Thu, 26 Jan 2017) Log Message: ----------- JavaScript: fix Symbol creation. Issue 1852 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Symbol.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/SymbolTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2017-01-26 16:56:30 UTC (rev 13428) +++ trunk/htmlunit/src/changes/changes.xml 2017-01-26 17:10:50 UTC (rev 13429) @@ -8,6 +8,9 @@ <body> <release version="2.25" date="???" description="Java 8, InteractivePage and SvgPage removed, Bugfixes"> + <action type="fix" dev="asashour" issue="1852"> + JavaScript: fix Symbol creation. + </action> <action type="fix" dev="asashour"> HtmlOption: clicking should unselect other options, even if the parent select is 'multiple'. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Symbol.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Symbol.java 2017-01-26 16:56:30 UTC (rev 13428) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Symbol.java 2017-01-26 17:10:50 UTC (rev 13429) @@ -94,7 +94,8 @@ Symbol symbol = map.get(name); if (symbol == null) { - symbol = new Symbol(name); + symbol = new Symbol(); + symbol.name_ = name; symbol.setParentScope(scope); symbol.setPrototype(scope.getPrototype(symbol.getClass())); map.put(name, symbol); @@ -221,7 +222,8 @@ if (symbol == null) { final SimpleScriptable parentScope = (SimpleScriptable) thisObj.getParentScope(); - symbol = new Symbol(key); + symbol = new Symbol(); + symbol.name_ = key; symbol.setParentScope(parentScope); symbol.setPrototype(parentScope.getPrototype(symbol.getClass())); thisObj.put(key, thisObj, symbol); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/SymbolTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/SymbolTest.java 2017-01-26 16:56:30 UTC (rev 13428) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/SymbolTest.java 2017-01-26 17:10:50 UTC (rev 13429) @@ -364,4 +364,25 @@ + "</body></html>"; loadPageWithAlerts2(html); } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = "called", + IE = {}) + public void inFunction() throws Exception { + final String html = "<html><head><script>\n" + + "function test() {\n" + + " if (window.Symbol) {\n" + + " [].forEach.call('_', function(e) {\n" + + " var x = Symbol.toPrimitive;\n" + + " alert('called');\n" + + " });\n" + + " }\n" + + "}\n" + + "</script></head><body onload='test()'>\n" + + "</body></html>\n"; + loadPageWithAlerts2(html); + } } |
From: <asa...@us...> - 2017-07-21 07:54:33
|
Revision: 14680 http://sourceforge.net/p/htmlunit/code/14680 Author: asashour Date: 2017-07-21 07:54:30 +0000 (Fri, 21 Jul 2017) Log Message: ----------- No need to use .toString(),.toExternalForm() in string concatenation. Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/httpclient/HtmlUnitBrowserCompatCookieSpec.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersionFeaturesTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient6Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClientTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlForm2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFormTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WindowTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/FalsifyingWebConnectionTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/httpclient/HtmlUnitBrowserCompatCookieSpec.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/httpclient/HtmlUnitBrowserCompatCookieSpec.java 2017-07-21 07:44:41 UTC (rev 14679) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/httpclient/HtmlUnitBrowserCompatCookieSpec.java 2017-07-21 07:54:30 UTC (rev 14680) @@ -137,7 +137,7 @@ final String headername = header.getName(); if (!headername.equalsIgnoreCase(SM.SET_COOKIE)) { - throw new MalformedCookieException("Unrecognized cookie header '" + header.toString() + "'"); + throw new MalformedCookieException("Unrecognized cookie header '" + header + "'"); } final HeaderElement[] helems = header.getElements(); boolean versioned = false; 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 2017-07-21 07:44:41 UTC (rev 14679) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/xml/XMLHttpRequest.java 2017-07-21 07:54:30 UTC (rev 14680) @@ -663,9 +663,7 @@ @Override public String toString() { - return "XMLHttpRequest " - + webRequest_.getHttpMethod().toString() - + " '" + webRequest_.getUrl().toExternalForm() + "'"; + return "XMLHttpRequest " + webRequest_.getHttpMethod() + " '" + webRequest_.getUrl() + "'"; } }; final JavaScriptJob job = BackgroundJavaScriptFactory.theFactory(). Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersionFeaturesTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersionFeaturesTest.java 2017-07-21 07:44:41 UTC (rev 14679) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersionFeaturesTest.java 2017-07-21 07:54:30 UTC (rev 14680) @@ -98,7 +98,7 @@ } } assertTrue("BrowserVersionFeatures.java: Annotation '" - + annotatedBrowser.toString() + "' of feature '" + + annotatedBrowser + "' of feature '" + feature.name() + "' in no longer in use.", inUse); } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java 2017-07-21 07:44:41 UTC (rev 14679) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java 2017-07-21 07:54:30 UTC (rev 14680) @@ -162,7 +162,7 @@ public void locationUTF() throws Exception { final String response = "HTTP/1.1 302 Found\r\n" + "Content-Length: 0\r\n" - + "Location: " + URL_FIRST.toExternalForm() + "أهلاً" + "\r\n" + + "Location: " + URL_FIRST + "أهلاً" + "\r\n" + "\r\n"; final String response2 = "HTTP/1.1 200 OK\r\n" @@ -197,7 +197,7 @@ public void locationQueryUTF() throws Exception { final String response = "HTTP/1.1 302 Found\r\n" + "Content-Length: 0\r\n" - + "Location: " + URL_FIRST.toExternalForm() + "test?أهلاً" + "\r\n" + + "Location: " + URL_FIRST + "test?أهلاً" + "\r\n" + "\r\n"; final String response2 = "HTTP/1.1 200 OK\r\n" Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient6Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient6Test.java 2017-07-21 07:44:41 UTC (rev 14679) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient6Test.java 2017-07-21 07:54:30 UTC (rev 14680) @@ -487,6 +487,6 @@ final WebDriver driver = loadPage2(html); driver.findElement(By.tagName("a")).click(); - assertEquals(url.toString() + "?param=http%3A//somwhere.org", driver.getCurrentUrl()); + assertEquals(url + "?param=http%3A//somwhere.org", driver.getCurrentUrl()); } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClientTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClientTest.java 2017-07-21 07:44:41 UTC (rev 14679) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClientTest.java 2017-07-21 07:54:30 UTC (rev 14680) @@ -2096,7 +2096,7 @@ final String html = "<html><body onload='document.getElementById(\"f\").src=\"frame.html\";'>\n" + "<iframe id='f'></iframe></body></html>"; conn.setResponse(URL_FIRST, html); - final URL frameUrl = new URL(URL_FIRST.toExternalForm() + "frame.html"); + final URL frameUrl = new URL(URL_FIRST, "frame.html"); conn.setResponse(frameUrl, "<html><body></body></html>"); conn.setResponse(URL_SECOND, "<html><body></body></html>"); client.setWebConnection(conn); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlForm2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlForm2Test.java 2017-07-21 07:44:41 UTC (rev 14679) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlForm2Test.java 2017-07-21 07:54:30 UTC (rev 14680) @@ -191,7 +191,7 @@ else { linkSuffix = "bug.html?k%F6nig"; } - assertEquals(URL_FIRST.toExternalForm() + linkSuffix, driver.getCurrentUrl()); + assertEquals(URL_FIRST + linkSuffix, driver.getCurrentUrl()); } /** Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFormTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFormTest.java 2017-07-21 07:44:41 UTC (rev 14679) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFormTest.java 2017-07-21 07:54:30 UTC (rev 14680) @@ -1026,7 +1026,7 @@ urlAfterSubmit("post", "foo?foo=12", "foo?foo=12"); urlAfterSubmit("post", "", ""); urlAfterSubmit("post", "?a=1&b=2", "?a=1&b=2"); - final URL url = new URL(URL_FIRST.toExternalForm() + "?a=1&b=2"); + final URL url = new URL(URL_FIRST + "?a=1&b=2"); urlAfterSubmit(url, "post", "", url.toExternalForm()); } 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 2017-07-21 07:44:41 UTC (rev 14679) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WindowTest.java 2017-07-21 07:54:30 UTC (rev 14680) @@ -1225,7 +1225,7 @@ final MockWebConnection conn = new MockWebConnection(); conn.setResponse(URL_FIRST, html1); - conn.setResponse(new URL(URL_FIRST.toExternalForm() + "myDialog.html"), html2); + conn.setResponse(new URL(URL_FIRST, "myDialog.html"), html2); client.setWebConnection(conn); final HtmlPage page = client.getPage(URL_FIRST); @@ -1284,7 +1284,7 @@ final MockWebConnection conn = new MockWebConnection(); conn.setResponse(URL_FIRST, html1); - conn.setResponse(new URL(URL_FIRST.toExternalForm() + "myDialog.html"), html2); + conn.setResponse(new URL(URL_FIRST, "myDialog.html"), html2); client.setWebConnection(conn); final HtmlPage page = getWebClient().getPage(URL_FIRST); @@ -1334,7 +1334,7 @@ final MockWebConnection conn = new MockWebConnection(); conn.setResponse(URL_FIRST, html1); - conn.setResponse(new URL(URL_FIRST.toExternalForm() + "myDialog.html"), html2); + conn.setResponse(new URL(URL_FIRST, "myDialog.html"), html2); client.setWebConnection(conn); final HtmlPage page = client.getPage(URL_FIRST); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/FalsifyingWebConnectionTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/FalsifyingWebConnectionTest.java 2017-07-21 07:44:41 UTC (rev 14679) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/FalsifyingWebConnectionTest.java 2017-07-21 07:54:30 UTC (rev 14680) @@ -57,7 +57,7 @@ final MockWebConnection mockConnection = new MockWebConnection(); mockConnection.setResponse(URL_FIRST, html); - mockConnection.setResponse(new URL(URL_FIRST.toExternalForm() + "myJs.js"), "alert('hello');"); + mockConnection.setResponse(new URL(URL_FIRST, "myJs.js"), "alert('hello');"); webClient.setWebConnection(mockConnection); final List<String> collectedAlerts = new ArrayList<>(); @@ -98,7 +98,7 @@ final MockWebConnection mockConnection = new MockWebConnection(); mockConnection.setResponse(URL_FIRST, html); - mockConnection.setResponse(new URL(URL_FIRST.toExternalForm() + "myJs.js"), "alert('hello');"); + mockConnection.setResponse(new URL(URL_FIRST, "myJs.js"), "alert('hello');"); webClient.setWebConnection(mockConnection); final List<String> collectedAlerts = new ArrayList<>(); |
From: <asa...@us...> - 2013-10-04 20:41:17
|
Revision: 8591 http://sourceforge.net/p/htmlunit/code/8591 Author: asashour Date: 2013-10-04 20:41:11 +0000 (Fri, 04 Oct 2013) Log Message: ----------- JavaScript: .innerHTML to correctly process nested SVG elements. Issue 1548 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.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-10-04 18:33:20 UTC (rev 8590) +++ trunk/htmlunit/src/changes/changes.xml 2013-10-04 20:41:11 UTC (rev 8591) @@ -8,6 +8,9 @@ <body> <release version="2.13" date="???" description="Bugfixes"> + <action type="fix" dev="asashour" issue="1548"> + JavaScript: .innerHTML to correctly process nested SVG elements. + </action> <action type="fix" dev="rbri"> Date.toUTCString and Date.toGMTString now returns the correct format in IE mode. </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-10-04 18:33:20 UTC (rev 8590) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java 2013-10-04 20:41:11 UTC (rev 8591) @@ -287,9 +287,8 @@ * {@inheritDoc} */ @Override - @SuppressWarnings("unchecked") - public DomNode getDomNodeOrNull() { - DomNode node = super.getDomNodeOrNull(); + public <N extends DomNode> N getDomNodeOrNull() { + N node = super.getDomNodeOrNull(); if (node == null) { node = getDomNodeOrNullFromRealDocument(); } @@ -306,8 +305,8 @@ * * @return the real document's DOM node, or <tt>null</tt> if we're not emulating IE */ - private DomNode getDomNodeOrNullFromRealDocument() { - DomNode node = null; + private <N extends DomNode> N getDomNodeOrNullFromRealDocument() { + N node = null; // don't use getBrowserVersion() here because this is called // from getBrowserVersion() and will endless loop final boolean ie = getWindow().getWebWindow().getWebClient().getBrowserVersion().hasFeature(GENERATED_51); 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-10-04 18:33:20 UTC (rev 8590) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java 2013-10-04 20:41:11 UTC (rev 8591) @@ -929,11 +929,12 @@ buffer.append(s); } else if (html) { - final HtmlElement element = (HtmlElement) node; - final HTMLElement scriptObject = (HTMLElement) node.getScriptObject(); + final DomElement element = (DomElement) node; + final Element scriptObject = (Element) node.getScriptObject(); final boolean isUpperCase = getBrowserVersion().hasFeature(HTMLELEMENT_OUTER_HTML_UPPER_CASE); String tag = element.getTagName(); - if (isUpperCase && !scriptObject.isLowerCaseInOuterHtml()) { + if (isUpperCase && scriptObject instanceof HTMLElement + && !((HTMLElement) scriptObject).isLowerCaseInOuterHtml()) { tag = tag.toUpperCase(Locale.ENGLISH); } buffer.append("<").append(tag); @@ -958,7 +959,7 @@ buffer.append(">"); // Add the children. printChildren(buffer, node, html); - if (!scriptObject.isEndTagForbidden()) { + if (!(scriptObject instanceof HTMLElement) || !((HTMLElement) scriptObject).isEndTagForbidden()) { buffer.append("</").append(tag).append(">"); } } 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-10-04 18:33:20 UTC (rev 8590) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java 2013-10-04 20:41:11 UTC (rev 8591) @@ -4652,4 +4652,32 @@ loadPageWithAlerts2(html); } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "<svg id=\"svgElem2\"></svg>", IE = "undefined") + public void innerHTML_svg() throws Exception { + final String html = "<html>\n" + + "<head>\n" + + " <script>\n" + + " function test() {\n" + + " var div = document.createElement('div');\n" + + " document.body.appendChild(div);\n" + + " if (document.createElementNS) {\n" + + " var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');\n" + + " svg.setAttribute('id', 'svgElem2');\n" + + " div.appendChild(svg);\n" + + " alert(div.innerHTML);\n" + + " } else {\n" + + " alert('undefined');\n" + + " }\n" + + " }\n" + + " </script>\n" + + "</head><body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } } |
From: <rb...@us...> - 2013-10-05 11:50:20
|
Revision: 8595 http://sourceforge.net/p/htmlunit/code/8595 Author: rbri Date: 2013-10-05 11:50:17 +0000 (Sat, 05 Oct 2013) Log Message: ----------- fix another selector issues, our selector validation was missing a check 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 trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/libraries/JQuery182Test.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-10-05 10:26:35 UTC (rev 8594) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2013-10-05 11:50:17 UTC (rev 8595) @@ -1124,6 +1124,12 @@ final SiblingSelector ss = (SiblingSelector) selector; return isValidSelector(ss.getSelector(), documentMode) && isValidSelector(ss.getSiblingSelector(), documentMode); + case Selector.SAC_ANY_NODE_SELECTOR: + if (selector instanceof SiblingSelector) { + final SiblingSelector sibling = (SiblingSelector) selector; + return isValidSelector(sibling.getSelector(), documentMode) + && isValidSelector(sibling.getSiblingSelector(), documentMode); + } default: LOG.warn("Unhandled CSS selector type '" + selector.getSelectorType() + "'. Accepting it silently."); return true; // at least in a first time to break less stuff 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-10-05 10:26:35 UTC (rev 8594) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java 2013-10-05 11:50:17 UTC (rev 8595) @@ -15,6 +15,7 @@ package com.gargoylesoftware.htmlunit.javascript.host.css; import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.FF3_6; +import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.IE; import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.IE6; import org.junit.Test; @@ -536,7 +537,7 @@ * @throws Exception if an error occurs */ @Test - @Alerts({ "1", "ul2" }) + @Alerts({ "2", "ul2", "ul3" }) public void generalAdjacentSelector() throws Exception { final String html = "<html><head><title>First</title>\n" + "<meta http-equiv='X-UA-Compatible' content='IE=edge'>\n" @@ -545,7 +546,9 @@ + " if (document.querySelectorAll) {\n" + " var list = document.querySelectorAll('div~ul');\n" + " alert(list.length);\n" - + " alert(list[0].id);\n" + + " for (var i = 0 ; i < list.length; i++) {\n" + + " alert(list[i].id);\n" + + " }\n" + " }\n" + "}\n" + "</script></head>\n" @@ -553,6 +556,7 @@ + " <div></div>\n" + " <p></p>\n" + " <ul id='ul2'></ul>\n" + + " <ul id='ul3'></ul>\n" + "</body></html>"; loadPageWithAlerts2(html); @@ -699,6 +703,37 @@ * @throws Exception if an error occurs */ @Test + @Alerts(DEFAULT = { }, + IE = { "li1" }) + @NotYetImplemented(IE) + public void pseudoAfter() throws Exception { + final String html + = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>Pseudo-After</title><script>\n" + + "function test() {\n" + + " if (document.querySelectorAll) {\n" + + " try {\n" + + " var list = document.querySelectorAll('#li1:after');\n" + + " for (var i = 0 ; i < list.length; i++) {\n" + + " alert(list[i].id);\n" + + " }\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" + + "</ul>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test @Alerts("li1") public void first_child() throws Exception { final String html = "<html><head><title>First</title>\n" @@ -1225,4 +1260,31 @@ loadPageWithAlerts2(html); } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts({ "exception" }) + public void invalidSelectors() throws Exception { + final String html + = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>Invalid Selectors</title><script>\n" + + "function test() {\n" + + " if (document.querySelectorAll) {\n" + + " try {\n" + + " var list = document.querySelectorAll('li:foo() ~ li');\n" + + " alert(list.length);\n" + + " } catch (e) {alert('exception')}\n" + + " }\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + "<ul id='ul'>\n" + + " <li id='li1'></li>\n" + + " <li id='li2'></li>\n" + + "</ul>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/libraries/JQuery182Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/libraries/JQuery182Test.java 2013-10-05 10:26:35 UTC (rev 8594) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/libraries/JQuery182Test.java 2013-10-05 11:50:17 UTC (rev 8595) @@ -6787,7 +6787,6 @@ */ @Test @Alerts("0, 42, 42") - @NotYetImplemented public void Sizzle__selector__child_and_adjacent() throws Exception { runTest("Sizzle: selector: child and adjacent"); } |
From: <asa...@us...> - 2013-10-06 13:19:57
|
Revision: 8603 http://sourceforge.net/p/htmlunit/code/8603 Author: asashour Date: 2013-10-06 13:19:54 +0000 (Sun, 06 Oct 2013) Log Message: ----------- JavaScript: add SVGSVGElement.createSVGRect(). Issue 1538 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGSVGElement.java Added Paths: ----------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGRect.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGSVGElementTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-10-06 12:21:52 UTC (rev 8602) +++ trunk/htmlunit/src/changes/changes.xml 2013-10-06 13:19:54 UTC (rev 8603) @@ -8,6 +8,9 @@ <body> <release version="2.13" date="???" description="Bugfixes"> + <action type="add" dev="asashour" issue="1538"> + JavaScript: add SVGSVGElement.createSVGRect(). + </action> <action type="fix" dev="asashour" issue="1548"> JavaScript: .innerHTML to correctly process nested SVG elements. </action> Added: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGRect.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGRect.java (rev 0) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGRect.java 2013-10-06 13:19:54 UTC (rev 8603) @@ -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.svg; + +import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; +import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; +import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter; +import com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter; + +/** + * A JavaScript object for SVGRect. + * + * @version $Revision$ + * @author Ahmed Ashour + */ +@JsxClass +public class SVGRect extends SimpleScriptable { + + private double xValue_; + private double yValue_; + private double width_; + private double height_; + + /** + * Gets x. + * @return x + */ + @JsxGetter + public double getX() { + return xValue_; + } + + /** + * Sets x. + * @param x the x + */ + @JsxSetter + public void setX(final double x) { + this.xValue_ = x; + } + + /** + * Gets y. + * @return y + */ + @JsxGetter + public double getY() { + return yValue_; + } + + /** + * Sets y. + * @param y the y + */ + @JsxSetter + public void setY(final double y) { + this.yValue_ = y; + } + + /** + * Gets width. + * @return width + */ + @JsxGetter + public double getWidth() { + return width_; + } + + /** + * Sets width. + * @param width the width + */ + @JsxSetter + public void setWidth(final double width) { + this.width_ = width; + } + + /** + * Gets height. + * @return height + */ + @JsxGetter + public double getHeight() { + return height_; + } + + /** + * Sets height. + * @param height the height + */ + @JsxSetter + public void setHeigth(final double height) { + this.height_ = height; + } + +} Property changes on: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGRect.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property 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/svg/SVGSVGElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGSVGElement.java 2013-10-06 12:21:52 UTC (rev 8602) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGSVGElement.java 2013-10-06 13:19:54 UTC (rev 8603) @@ -57,4 +57,16 @@ public SVGMatrix getScreenCTM() { return new SVGMatrix(getWindow()); } + + /** + * Creates a new {@link SVGRect}. + * @return the new rect + */ + @JsxFunction + public SVGRect createSVGRect() { + final SVGRect rect = new SVGRect(); + rect.setPrototype(getPrototype(rect.getClass())); + rect.setParentScope(getParentScope()); + return rect; + } } Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGSVGElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGSVGElementTest.java (rev 0) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGSVGElementTest.java 2013-10-06 13:19:54 UTC (rev 8603) @@ -0,0 +1,56 @@ +/* + * 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.svg; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.WebDriverTestCase; +import com.gargoylesoftware.htmlunit.html.HtmlPageTest; + +/** + * Tests for {@link SVGSVGElement}. + * + * @version $Revision$ + * @author Ahmed Ashour + */ +@RunWith(BrowserRunner.class) +public class SVGSVGElementTest extends WebDriverTestCase { + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "[object SVGRect]", IE = "undefined") + public void createSVGRect() throws Exception { + final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html><head>\n" + + "<script>\n" + + " function test() {\n" + + " if (document.createElementNS) {\n" + + " alert(document.createElementNS('http://www.w3.org/2000/svg', 'svg').createSVGRect());\n" + + " } else {\n" + + " alert('undefined');\n" + + " }\n" + + " }\n" + + "</script>\n" + + "</head><body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } +} Property changes on: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/svg/SVGSVGElementTest.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property 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: <asa...@us...> - 2013-10-07 17:14:17
|
Revision: 8608 http://sourceforge.net/p/htmlunit/code/8608 Author: asashour Date: 2013-10-07 17:14:14 +0000 (Mon, 07 Oct 2013) Log Message: ----------- IEConditionalCompilationScriptPreProcessor fix when evaluated to false. Issue 1502 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HTMLParser.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HTMLParser2Test.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-10-06 16:01:38 UTC (rev 8607) +++ trunk/htmlunit/src/changes/changes.xml 2013-10-07 17:14:14 UTC (rev 8608) @@ -8,6 +8,9 @@ <body> <release version="2.13" date="???" description="Bugfixes"> + <action type="fix" dev="asashour" issue="1502"> + IEConditionalCompilationScriptPreProcessor fix when evaluated to false. + </action> <action type="add" dev="asashour" issue="1538"> JavaScript: add SVGSVGElement.createSVGRect(). </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HTMLParser.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HTMLParser.java 2013-10-06 16:01:38 UTC (rev 8607) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HTMLParser.java 2013-10-07 17:14:14 UTC (rev 8608) @@ -962,13 +962,6 @@ protected void scanComment() throws IOException { final String s = nextContent(30); // [if ... if (s.startsWith("[if ") && s.contains("]>")) { - String commentTill = null; - if (s.contains("]><!-->")) { - commentTill = "<![endif]-->"; - } - else if (s.contains("]>-->")) { - commentTill = "<!--<![endif]-->"; - } final String condition = StringUtils.substringBefore(s.substring(4), "]>"); try { if (IEConditionalCommentExpressionEvaluator.evaluate(condition, browserVersion_)) { @@ -982,21 +975,14 @@ else if (s.contains("]>-->")) { skip("-->", false); } - return; } - if (commentTill != null) { - final XMLStringBuffer buffer = new XMLStringBuffer(); - int ch; - while ((ch = read()) != -1) { - buffer.append((char) ch); - if (buffer.toString().endsWith(commentTill)) { - final XMLStringBuffer trimmedBuffer - = new XMLStringBuffer(buffer.ch, 0, buffer.length - 3); - fDocumentHandler.comment(trimmedBuffer, locationAugs()); - return; - } + else { + final StringBuilder builder = new StringBuilder(); + while (!builder.toString().endsWith("-->")) { + builder.append((char) read()); } } + return; } catch (final Exception e) { // incorrect expression => handle it as plain text // TODO: report it! Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HTMLParser2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HTMLParser2Test.java 2013-10-06 16:01:38 UTC (rev 8607) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HTMLParser2Test.java 2013-10-07 17:14:14 UTC (rev 8608) @@ -1553,7 +1553,7 @@ @Alerts(DEFAULT = { "<!--[if gt IE 11]><br><![endif]-->", "<!--[if lt IE 11]><br><![endif]-->" }, IE6 = { "", "<BR>" }, IE8 = { "", "<BR>" }) - @NotYetImplemented({ IE6, IE8 }) + @NotYetImplemented(IE6) public void ieConditionalCommentsNotInDom() throws Exception { final String html = "<html><head>\n" + "<script>\n" |
From: <rb...@us...> - 2013-10-07 20:31:19
|
Revision: 8612 http://sourceforge.net/p/htmlunit/code/8612 Author: rbri Date: 2013-10-07 20:31:15 +0000 (Mon, 07 Oct 2013) Log Message: ----------- outerHTML don't check for correct tag closing in FF mode. Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/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-10-07 18:49:56 UTC (rev 8611) +++ trunk/htmlunit/src/changes/changes.xml 2013-10-07 20:31:15 UTC (rev 8612) @@ -8,6 +8,9 @@ <body> <release version="2.13" date="???" description="Bugfixes"> + <action type="fix" dev="rbri"> + JavaScript: .outerHTML don't check for correct tag closing in FF mode. + </action> <action type="fix" dev="asashour" issue="1502"> IEConditionalCompilationScriptPreProcessor fix when evaluated to false. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-10-07 18:49:56 UTC (rev 8611) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-10-07 20:31:15 UTC (rev 8612) @@ -1023,6 +1023,12 @@ @BrowserFeature(@WebBrowser(IE)) JS_OUTER_HTML_BODY_HEAD_READONLY, + /** element.outerHTML throws an exception, if the new tag will close + * the outer one when parsing the html source (IE). + */ + @BrowserFeature(@WebBrowser(IE)) + JS_OUTER_THROW_EXCEPTION_WHEN_CLOSES, + /** If <tt>true</tt>, then treat <tt>__parent__</tt> and <tt>__proto__</tt> as special properties. */ @BrowserFeature(@WebBrowser(IE)) JS_PARENT_PROTO_PROPERTIES, 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-10-07 18:49:56 UTC (rev 8611) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement.java 2013-10-07 20:31:15 UTC (rev 8612) @@ -35,6 +35,7 @@ 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_OUTER_HTML_BODY_HEAD_READONLY; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_OUTER_THROW_EXCEPTION_WHEN_CLOSES; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_PREFIX_RETURNS_EMPTY_WHEN_UNDEFINED; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_SET_ATTRIBUTE_CONSIDERS_ATTR_FOR_CLASS_AS_REAL; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_SET_ATTRIBUTE_SUPPORTS_EVENT_HANDLERS; @@ -1072,7 +1073,7 @@ final DomDocumentFragment fragment = (DomDocumentFragment) domNode.getPage().createDocumentFragment(); parseHtmlSnippet(fragment, false, value); DomNode child = fragment.getFirstChild(); - if (child instanceof DomElement) { + if (getBrowserVersion().hasFeature(JS_OUTER_THROW_EXCEPTION_WHEN_CLOSES) && child instanceof DomElement) { final String parentName = domNode.getParentNode().getNodeName().toUpperCase(Locale.ENGLISH); final short[] closes = HTMLElements.getElement(child.getNodeName()).closes; if (closes != null) { 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-10-07 18:49:56 UTC (rev 8611) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElementTest.java 2013-10-07 20:31:15 UTC (rev 8612) @@ -1228,7 +1228,6 @@ "New = <span id=\"innerNode\">Old outerHTML</span>" }, IE6 = { "Old = <SPAN id=innerNode>Old outerHTML</SPAN>", "exception" }, IE8 = { "Old = <SPAN id=innerNode>Old outerHTML</SPAN>", "exception" }) - @NotYetImplemented(FF17) public void setOuterHTMLAddBlockToParagraph() throws Exception { final String html = createPageForSetOuterHTML("p", "<div>test</div>"); loadPageWithAlerts2(html); @@ -1250,7 +1249,6 @@ "New = <span id=\"innerNode\">Old outerHTML</span>" }, IE6 = { "Old = <SPAN id=innerNode>Old outerHTML</SPAN>", "exception" }, IE8 = { "Old = <SPAN id=innerNode>Old outerHTML</SPAN>", "exception" }) - @NotYetImplemented(FF17) public void setOuterHTMLAddParagraphToParagraph() throws Exception { final String html = createPageForSetOuterHTML("p", "<p>test</p>"); loadPageWithAlerts2(html); @@ -1290,7 +1288,6 @@ "New = <span id=\"innerNode\">Old outerHTML</span>" }, IE6 = { "Old = <SPAN id=innerNode>Old outerHTML</SPAN>", "exception" }, IE8 = { "Old = <SPAN id=innerNode>Old outerHTML</SPAN>", "exception" }) - @NotYetImplemented(FF17) public void setOuterHTMLAddAnchorToAnchor() throws Exception { final String html = createPageForSetOuterHTML("a", "<a>test</a>"); loadPageWithAlerts2(html); |
From: <asa...@us...> - 2013-10-08 10:46:20
|
Revision: 8614 http://sourceforge.net/p/htmlunit/code/8614 Author: asashour Date: 2013-10-08 10:46:17 +0000 (Tue, 08 Oct 2013) Log Message: ----------- JavaScript: TextRange: add getBookmark() and moveToBookmark(). Issue 1499 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/TextRange.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/TextRangeTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-10-08 10:17:16 UTC (rev 8613) +++ trunk/htmlunit/src/changes/changes.xml 2013-10-08 10:46:17 UTC (rev 8614) @@ -8,6 +8,9 @@ <body> <release version="2.13" date="???" description="Bugfixes"> + <action type="add" dev="asashour" issue="1499"> + JavaScript: TextRange: add getBookmark() and moveToBookmark(). + </action> <action type="fix" dev="rbri"> JavaScript: .outerHTML don't check for correct tag closing in FF mode. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/TextRange.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/TextRange.java 2013-10-08 10:17:16 UTC (rev 8613) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/TextRange.java 2013-10-08 10:46:17 UTC (rev 8614) @@ -316,4 +316,26 @@ } return moveBy; } + + /** + * Retrieves a bookmark (opaque string) that can be used with {@link #moveToBookmark} + * to return to the same range. + * The current implementation return empty string + * @return the bookmark + */ + @JsxFunction + public String getBookmark() { + return ""; + } + + /** + * Moves to a bookmark. + * The current implementation does nothing + * @param bookmark the bookmark + */ + @JsxFunction + public boolean moveToBookmark(final String bookmark) { + return false; + } + } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/TextRangeTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/TextRangeTest.java 2013-10-08 10:17:16 UTC (rev 8613) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/TextRangeTest.java 2013-10-08 10:46:17 UTC (rev 8614) @@ -37,8 +37,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "exception", - IE = { "", "bla bla", "bla blabli bli" }) + @Alerts(DEFAULT = "exception", IE = { "", "bla bla", "bla blabli bli" }) public void text() throws Exception { final String html = "<html>\n" + "<head>\n" @@ -70,8 +69,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "exception", - IE = "BODY") + @Alerts(DEFAULT = "exception", IE = "BODY") public void parentElement() throws Exception { final String html = "<html>\n" + "<head>\n" @@ -95,8 +93,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "exception", - IE = { "hello", "" }) + @Alerts(DEFAULT = "exception", IE = { "hello", "" }) public void collapse() throws Exception { final String html = "<html>\n" + "<head>\n" @@ -128,8 +125,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "exception", - IE = "") + @Alerts(DEFAULT = "exception", IE = "") public void select() throws Exception { final String html = "<html>\n" + "<head>\n" @@ -155,8 +151,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "exception", - IE = { "hello", "hell", "ell" }) + @Alerts(DEFAULT = "exception", IE = { "hello", "hell", "ell" }) public void moveEnd() throws Exception { final String html = "<html>\n" + "<head>\n" @@ -189,8 +184,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "exception", - IE = { "hello", "hell", "ell", "1", "-1", "hello" }) + @Alerts(DEFAULT = "exception", IE = { "hello", "hell", "ell", "1", "-1", "hello" }) public void moveOutOfBounds_input() throws Exception { final String html = "<html>\n" + "<head>\n" @@ -226,8 +220,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "exception", - IE = { "true", "true", "false", "true" }) + @Alerts(DEFAULT = "exception", IE = { "true", "true", "false", "true" }) public void inRange() throws Exception { final String html = "<html>\n" + "<head>\n" @@ -260,8 +253,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "exception", - IE = "false") + @Alerts(DEFAULT = "exception", IE = "false") public void inRange2() throws Exception { final String html = "<html><body>" + "<form name='f'><input name='q' value=''></form>" @@ -330,8 +322,7 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = "exception", - IE = "BODY") + @Alerts(DEFAULT = "exception", IE = "BODY") public void createRangeParentElement() throws Exception { final String html = "<html><body>\n" @@ -350,8 +341,7 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = "exception", - IE = "") + @Alerts(DEFAULT = "exception", IE = "") public void createRangeHtmlText() throws Exception { final String html = "<html><body>\n" @@ -365,4 +355,23 @@ + "</body></html>"; loadPageWithAlerts2(html); } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = "exception", IE = "ok") + public void moveToBookmark() throws Exception { + final String html = + "<html><body>\n" + + "<script>\n" + + "try {\n" + + " var rng = document.body.createTextRange();\n" + + " rng.moveToBookmark(rng.getBookmark());\n" + + " alert('ok');\n" + + "} catch(e) { alert('exception'); }\n" + + "</script>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } } |
From: <mgu...@us...> - 2013-10-08 15:16:42
|
Revision: 8616 http://sourceforge.net/p/htmlunit/code/8616 Author: mguillem Date: 2013-10-08 15:16:37 +0000 (Tue, 08 Oct 2013) Log Message: ----------- Fixed wrong scripting scope assignment when handling attachments. Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/attachment/AttachmentTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-10-08 15:16:15 UTC (rev 8615) +++ trunk/htmlunit/src/changes/changes.xml 2013-10-08 15:16:37 UTC (rev 8616) @@ -8,6 +8,9 @@ <body> <release version="2.13" date="???" description="Bugfixes"> + <action type="fix" dev="mguillem"> + Fixed wrong scripting scope assignment when handling attachments. + </action> <action type="add" dev="asashour" issue="1499"> JavaScript: TextRange: add getBookmark() and moveToBookmark(). </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2013-10-08 15:16:15 UTC (rev 8615) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2013-10-08 15:16:37 UTC (rev 8616) @@ -796,11 +796,6 @@ } else { initializeEmptyWindow(window); - if (openerPage != null) { - final Window jsWindow = (Window) window.getScriptObject(); - jsWindow.setDomNode(openerPage); - jsWindow.getDocument().setDomNode(openerPage); - } } return window; } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/attachment/AttachmentTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/attachment/AttachmentTest.java 2013-10-08 15:16:15 UTC (rev 8615) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/attachment/AttachmentTest.java 2013-10-08 15:16:37 UTC (rev 8616) @@ -31,6 +31,7 @@ import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebResponse; import com.gargoylesoftware.htmlunit.html.HtmlAnchor; +import com.gargoylesoftware.htmlunit.html.HtmlElement; import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.util.NameValuePair; @@ -133,4 +134,37 @@ attachments.clear(); } + /** + * This was causing a ClassCastException in Location.setHref as of 2013-10-08 because the TextPage + * used for the attachment was wrongly associated to the HTMLDocument of the first page. + * @throws Exception if an error occurs + */ + @Test + public void jsChangeLocationAfterReceptionOfAttachment() throws Exception { + final String html = "<html><body>\n" + + "<form action='action'>\n" + + "<input type='submit' onclick='window.location=\"foo\"; return false'>\n" + + "</form>\n" + + "<a href='" + URL_SECOND + "'>download</a>\n" + + "</body></html>"; + + final WebClient client = getWebClient(); + final List<Attachment> attachments = new ArrayList<Attachment>(); + client.setAttachmentHandler(new CollectingAttachmentHandler(attachments)); + + final List<NameValuePair> headers = new ArrayList<NameValuePair>(); + headers.add(new NameValuePair("Content-Disposition", "attachment")); + + final MockWebConnection conn = getMockWebConnection(); + conn.setDefaultResponse(""); + conn.setResponse(URL_SECOND, "some text", 200, "OK", "text/plain", headers); + + final HtmlPage page = loadPage(html); + // download text attachment + page.getAnchors().get(0).click(); + assertEquals(1, attachments.size()); + + final HtmlElement htmlElement = (HtmlElement) page.getFirstByXPath("//input"); + htmlElement.click(); // exception was occurring here + } } |
From: <rb...@us...> - 2013-10-09 18:28:31
|
Revision: 8636 http://sourceforge.net/p/htmlunit/code/8636 Author: rbri Date: 2013-10-09 18:28:28 +0000 (Wed, 09 Oct 2013) Log Message: ----------- revert fix for 1352 because it breaks backward compatibility Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/Cache.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.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 Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-10-09 18:07:01 UTC (rev 8635) +++ trunk/htmlunit/src/changes/changes.xml 2013-10-09 18:28:28 UTC (rev 8636) @@ -41,9 +41,6 @@ <action type="fix" dev="rbri" issue="1524"> Some debug log output added if HTMLDocument.canAlreadyBeParsed(String) returns false. </action> - <action type="fix" dev="rbri" issue="1352"> - Caching now works for encoded URLs also. - </action> <action type="update" dev="asashour"> Deprecate KeyDataPair. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/Cache.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/Cache.java 2013-10-09 18:07:01 UTC (rev 8635) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/Cache.java 2013-10-09 18:28:28 UTC (rev 8636) @@ -15,7 +15,6 @@ package com.gargoylesoftware.htmlunit; import java.io.Serializable; -import java.net.URL; import java.util.Collections; import java.util.Date; import java.util.HashMap; @@ -34,7 +33,6 @@ * @version $Revision$ * @author Marc Guillemot * @author Daniel Gredler - * @author Ronald Brill */ public class Cache implements Serializable { @@ -95,25 +93,11 @@ * @param response the response corresponding to the specified compiled script * @param toCache the object that is to be cached, if possible (may be for instance a compiled script or * simply a WebResponse) - * @deprecated as of 2.13, please use {@link Cache#cacheIfPossible(URL, WebResponse, Object)} */ - @Deprecated public void cacheIfPossible(final WebRequest request, final WebResponse response, final Object toCache) { - cacheIfPossible(request.getUrl(), response, toCache); - } - - /** - * Caches the specified object, if the corresponding request and response objects indicate - * that it is cacheable. - * - * @param url the cache key - * @param response the response corresponding to the specified compiled script - * @param toCache the object that is to be cached, if possible (may be for instance a compiled script or - * simply a WebResponse) - */ - public void cacheIfPossible(final URL url, final WebResponse response, final Object toCache) { - if (isCacheable(response)) { - final Entry entry = new Entry(url.toString(), toCache); + if (isCacheable(request, response)) { + final String url = response.getWebRequest().getUrl().toString(); + final Entry entry = new Entry(url, toCache); entries_.put(entry.key_, entry); deleteOverflow(); } @@ -154,20 +138,8 @@ * @param request the performed request * @param response the received response * @return <code>true</code> if the response can be cached - * @deprecated as of 2.13, please use {@link Cache#isCacheable(WebResponse)} */ - @Deprecated protected boolean isCacheable(final WebRequest request, final WebResponse response) { - return isCacheable(response); - } - - /** - * Determines if the specified response can be cached. - * - * @param response the received response - * @return <code>true</code> if the response can be cached - */ - protected boolean isCacheable(final WebResponse response) { return HttpMethod.GET == response.getWebRequest().getHttpMethod() && !isDynamicContent(response); } @@ -235,22 +207,12 @@ * * @param request the request whose corresponding cached compiled script is sought * @return the cached object corresponding to the specified request if any - * @deprecated as of 2.13, please use {@link Cache#getCachedObject(URL)} */ - @Deprecated public Object getCachedObject(final WebRequest request) { - return getCachedObject(request.getUrl()); - } - - /** - * Returns the cached object corresponding to the specified request. If there is - * no corresponding cached object, this method returns <tt>null</tt>. - * - * @param url the cache key - * @return the cached object corresponding to the specified request if any - */ - public Object getCachedObject(final URL url) { - final Entry cachedEntry = entries_.get(url.toString()); + if (HttpMethod.GET != request.getHttpMethod()) { + return null; + } + final Entry cachedEntry = entries_.get(request.getUrl().toString()); if (cachedEntry == null) { return null; } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2013-10-09 18:07:01 UTC (rev 8635) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2013-10-09 18:28:28 UTC (rev 8636) @@ -1271,11 +1271,8 @@ addDefaultHeaders(webRequest); // Retrieve the response, either from the cache or from the server. + final Object fromCache = getCache().getCachedObject(webRequest); final WebResponse webResponse; - Object fromCache = null; - if (HttpMethod.GET == webRequest.getHttpMethod()) { - fromCache = getCache().getCachedObject(url); - } if (fromCache != null && fromCache instanceof WebResponse) { webResponse = new WebResponseFromCache((WebResponse) fromCache, webRequest); } @@ -1286,7 +1283,7 @@ catch (final NoHttpResponseException e) { return new WebResponse(responseDataNoHttpResponse_, webRequest, 0); } - getCache().cacheIfPossible(url, webResponse, webResponse); + getCache().cacheIfPossible(webRequest, webResponse, webResponse); } // Continue according to the HTTP status code. Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2013-10-09 18:07:01 UTC (rev 8635) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2013-10-09 18:28:28 UTC (rev 8636) @@ -1090,7 +1090,7 @@ request.setAdditionalHeader("Referer", referringRequest.getUrl().toString()); request.setAdditionalHeader("Accept", client.getBrowserVersion().getScriptAcceptHeader()); - final Object cachedScript = cache.getCachedObject(url); + final Object cachedScript = cache.getCachedObject(request); if (cachedScript instanceof Script) { return (Script) cachedScript; } @@ -1143,7 +1143,7 @@ final JavaScriptEngine javaScriptEngine = client.getJavaScriptEngine(); final Script script = javaScriptEngine.compile(this, scriptCode, url.toExternalForm(), 1); if (script != null) { - cache.cacheIfPossible(url, response, script); + cache.cacheIfPossible(request, response, script); } return script; 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-10-09 18:07:01 UTC (rev 8635) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2013-10-09 18:28:28 UTC (rev 8636) @@ -72,7 +72,6 @@ import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.Cache; import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; -import com.gargoylesoftware.htmlunit.HttpMethod; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebRequest; import com.gargoylesoftware.htmlunit.WebResponse; @@ -304,14 +303,11 @@ request.setAdditionalHeader("Referer", referer); } - final URL reqUrl = request.getUrl(); - Object fromCache = null; + uri = request.getUrl().toExternalForm(); final Cache cache = client.getCache(); - if (HttpMethod.GET == request.getHttpMethod()) { - fromCache = cache.getCachedObject(reqUrl); - } + final Object fromCache = cache.getCachedObject(request); if (fromCache != null && fromCache instanceof org.w3c.dom.css.CSSStyleSheet) { - sheet = new CSSStyleSheet(element, (org.w3c.dom.css.CSSStyleSheet) fromCache, reqUrl.toExternalForm()); + sheet = new CSSStyleSheet(element, (org.w3c.dom.css.CSSStyleSheet) fromCache, uri); } else { final WebResponse response = client.loadWebResponse(request); @@ -323,7 +319,7 @@ source.setByteStream(response.getContentAsStream()); source.setEncoding(response.getContentCharset()); sheet = new CSSStyleSheet(element, source, uri); - cache.cacheIfPossible(reqUrl, response, sheet.getWrappedSheet()); + cache.cacheIfPossible(request, response, sheet.getWrappedSheet()); } } catch (final FailingHttpStatusCodeException e) { |
From: <asa...@us...> - 2013-10-10 09:43:37
|
Revision: 8640 http://sourceforge.net/p/htmlunit/code/8640 Author: asashour Date: 2013-10-10 09:43:34 +0000 (Thu, 10 Oct 2013) Log Message: ----------- HtmlImage: close imageReader in finalize(). Issue 1541 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImage.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-10-10 06:58:51 UTC (rev 8639) +++ trunk/htmlunit/src/changes/changes.xml 2013-10-10 09:43:34 UTC (rev 8640) @@ -8,6 +8,9 @@ <body> <release version="2.13" date="???" description="Bugfixes"> + <action type="update" dev="asashour" issue="1541"> + HtmlImage: close imageReader in finalize(). + </action> <action type="update" dev="mguillem"> Upgrade NekoHtml to 1.9.19. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImage.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImage.java 2013-10-10 06:58:51 UTC (rev 8639) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImage.java 2013-10-10 09:43:34 UTC (rev 8640) @@ -489,4 +489,24 @@ final ImageReader reader = getImageReader(); ImageIO.write(reader.read(0), reader.getFormatName(), file); } + + /** + * {@inheritDoc} + */ + @Override + protected void finalize() { + if (imageReader_ != null) { + try { + final ImageInputStream stream = (ImageInputStream) imageReader_.getInput(); + if (stream != null) { + stream.close(); + } + imageReader_.setInput(null); + imageReader_.dispose(); + } + catch (final IOException e) { + LOG.error(e.getMessage() , e); + } + } + } } |