From: <asa...@us...> - 2017-07-20 10:07:15
|
Revision: 14677 http://sourceforge.net/p/htmlunit/code/14677 Author: asashour Date: 2017-07-20 10:07:12 +0000 (Thu, 20 Jul 2017) Log Message: ----------- Trying... Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2017-07-20 09:47:37 UTC (rev 14676) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2017-07-20 10:07:12 UTC (rev 14677) @@ -1336,8 +1336,7 @@ WebAssert.notNull("method", method); WebAssert.notNull("parameters", parameters); - url = UrlUtils.encodeUrl(url, getBrowserVersion().hasFeature(URL_MINIMAL_QUERY_ENCODING), - webRequest.getCharset()); + url = UrlUtils.encodeUrl(url, getBrowserVersion().hasFeature(URL_MINIMAL_QUERY_ENCODING), UTF_8); webRequest.setUrl(url); if (LOG.isDebugEnabled()) { Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java 2017-07-20 09:47:37 UTC (rev 14676) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java 2017-07-20 10:07:12 UTC (rev 14677) @@ -193,7 +193,6 @@ */ @Test @Alerts("§§URL§§test?%D8%A3%D9%87%D9%84%D8%A7%D9%8B") - @NotYetImplemented // seems to work only when running alone public void locationQueryUTF() throws Exception { final String response = "HTTP/1.1 302 Found\r\n" |
From: <asa...@us...> - 2017-07-20 10:22:29
|
Revision: 14678 http://sourceforge.net/p/htmlunit/code/14678 Author: asashour Date: 2017-07-20 10:22:26 +0000 (Thu, 20 Jul 2017) Log Message: ----------- Remove deprecated HtmlFileInput.setValueAttribute(String[]), HtmlInput.click(int,int), SgmlPage.getPageEncoding(), WebRequest.setCharset(String) and WebResponse.getContentAsString(String). Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/SgmlPage.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/StringWebResponse.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebRequest.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebResponse.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlFileInput.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/util/WebResponseWrapper.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CacheTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2017-07-20 10:07:12 UTC (rev 14677) +++ trunk/htmlunit/src/changes/changes.xml 2017-07-20 10:22:26 UTC (rev 14678) @@ -8,6 +8,10 @@ <body> <release version="2.28" date="???" description="Bugfixes"> + <action type="remove" dev="asashour"> + Remove deprecated HtmlFileInput.setValueAttribute(String[]), HtmlInput.click(int,int), + SgmlPage.getPageEncoding(), WebRequest.setCharset(String) and WebResponse.getContentAsString(String). + </action> <action type="fix" dev="asashour" issue="1898"> Fix Location header if it has non-ASCII characters. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/SgmlPage.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/SgmlPage.java 2017-07-20 10:07:12 UTC (rev 14677) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/SgmlPage.java 2017-07-20 10:22:26 UTC (rev 14678) @@ -194,17 +194,6 @@ public abstract Element createElementNS(String namespaceURI, String qualifiedName); /** - * Returns the page encoding. - * @return the page encoding - * @deprecated as of 2.25, please use {@link #getCharset()} instead - */ - @Deprecated - public String getPageEncoding() { - final Charset charset = getCharset(); - return charset == null ? null : charset.name(); - } - - /** * Returns the encoding. * @return the encoding */ Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/StringWebResponse.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/StringWebResponse.java 2017-07-20 10:07:12 UTC (rev 14677) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/StringWebResponse.java 2017-07-20 10:22:26 UTC (rev 14678) @@ -54,19 +54,7 @@ * @param content the content to return * @param charset the charset used to convert the content * @param originatingURL the URL that this should be associated with - * @deprecated as of 2.25, please use {@link #StringWebResponse(String, Charset, URL)} */ - @Deprecated - public StringWebResponse(final String content, final String charset, final URL originatingURL) { - this(content, Charset.forName(charset), originatingURL); - } - - /** - * Creates an instance associated with the specified originating URL. - * @param content the content to return - * @param charset the charset used to convert the content - * @param originatingURL the URL that this should be associated with - */ public StringWebResponse(final String content, final Charset charset, final URL originatingURL) { super(getWebResponseData(content, charset), buildWebRequest(originatingURL, charset), 0); } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebRequest.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebRequest.java 2017-07-20 10:07:12 UTC (rev 14677) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebRequest.java 2017-07-20 10:22:26 UTC (rev 14678) @@ -423,17 +423,6 @@ /** * Sets the character set to use to perform the request. The default value * is {@link java.nio.charset.StandardCharsets#ISO_8859_1}. - * @param charsetName the character set to use to perform the request - * @deprecated as of 2.25, please use {@link #setCharset(Charset)} - */ - @Deprecated - public void setCharset(final String charsetName) { - charset_ = Charset.forName(charsetName); - } - - /** - * Sets the character set to use to perform the request. The default value - * is {@link java.nio.charset.StandardCharsets#ISO_8859_1}. * @param charset the character set to use to perform the request */ public void setCharset(final Charset charset) { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebResponse.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebResponse.java 2017-07-20 10:07:12 UTC (rev 14677) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebResponse.java 2017-07-20 10:22:26 UTC (rev 14678) @@ -201,48 +201,6 @@ } /** - * Returns the response content as a string, using the specified charset/encoding, - * rather than the charset/encoding specified in the server response. If the specified - * charset/encoding is not supported then the default system encoding is used. - * @param encoding the charset/encoding to use to convert the response content into a string - * @return the response content as a string or null if the content retrieval was failing - * @deprecated as of 2.25, please use {@link #getContentAsString(Charset)} instead - */ - @Deprecated - public String getContentAsString(final String encoding) { - return getContentAsString(encoding, null); - } - - /** - * Returns the response content as a string, using the specified charset/encoding, - * rather than the charset/encoding specified in the server response. If the specified - * charset/encoding is not supported then the provided default encoding is used. - * @param encoding the charset/encoding to use to convert the response content into a string - * @param defaultEncoding the default encoding to use if the specified {@code encode} is not supported - * @return the response content as a string or null if the content retrieval was failing - * @deprecated as of 2.25, please use {@link #getContentAsString(Charset)} instead - */ - @Deprecated - public String getContentAsString(final String encoding, final String defaultEncoding) { - Charset charset; - // first verify the charset because we can't read the - // input stream twice - try { - charset = Charset.forName(encoding); - } - catch (final Exception e) { - if (encoding.equals(defaultEncoding)) { - LOG.warn(e); - return ""; - } - charset = defaultEncoding != null ? Charset.forName(defaultEncoding) : getContentCharset(); - LOG.warn("Attempted to use unsupported encoding '" - + encoding + "'; using default content charset ('" + charset + "')."); - } - return getContentAsString(charset); - } - - /** * Returns the response content as a string, using the specified charset, * rather than the charset/encoding specified in the server response. * If there is a bom header the charset parameter will be overwritten by the bom. Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlFileInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlFileInput.java 2017-07-20 10:07:12 UTC (rev 14677) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlFileInput.java 2017-07-20 10:22:26 UTC (rev 14678) @@ -21,7 +21,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.stream.Stream; import org.apache.commons.lang3.StringUtils; @@ -149,21 +148,6 @@ } /** - * Used to specify <code>multiple</code> paths to upload. - * - * The current implementation splits the value based on '§'. - * We may follow WebDriver solution, once made, - * see https://code.google.com/p/selenium/issues/detail?id=2239 - * @param files the list of paths of the files to upload - * @deprecated as of 2.25, please use {@link #setFiles(File...)} instead - */ - @Deprecated - public void setValueAttribute(final String[] files) { - final File[] array = Stream.of(files).map(p -> new File(p)).toArray(File[]::new); - setFiles(array); - } - - /** * Used to specify {@code multiple} files to upload. * * We may follow WebDriver solution, once made, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImageInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImageInput.java 2017-07-20 10:07:12 UTC (rev 14677) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImageInput.java 2017-07-20 10:22:26 UTC (rev 14678) @@ -137,10 +137,7 @@ * @return the page that is loaded after the click has taken place * @exception IOException If an IO error occurs * @exception ElementNotFoundException If a particular XML element could not be found in the DOM model - * @deprecated as of 2.25, please use {@link #click()} */ - @Override - @Deprecated public <P extends Page> P click(final int x, final int y) throws IOException, ElementNotFoundException { wasPositionSpecified_ = true; xPosition_ = x; Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlInput.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlInput.java 2017-07-20 10:07:12 UTC (rev 14677) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlInput.java 2017-07-20 10:22:26 UTC (rev 14678) @@ -18,13 +18,11 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.EVENT_MOUSE_ON_DISABLED; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLINPUT_DOES_NOT_CLICK_SURROUNDING_ANCHOR; -import java.io.IOException; import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Map; -import com.gargoylesoftware.htmlunit.ElementNotFoundException; import com.gargoylesoftware.htmlunit.Page; import com.gargoylesoftware.htmlunit.ScriptResult; import com.gargoylesoftware.htmlunit.SgmlPage; @@ -486,26 +484,6 @@ } /** - * Simulate clicking this input with a pointing device. The x and y coordinates - * of the pointing device will be sent to the server. - * - * @param <P> the page type - * @param x the x coordinate of the pointing device at the time of clicking - * @param y the y coordinate of the pointing device at the time of clicking - * @return the page that is loaded after the click has taken place - * @exception IOException If an IO error occurs - * @exception ElementNotFoundException If a particular XML element could not be found in the DOM model - * @deprecated as of 2.25, please use {@link #click()} - */ - @SuppressWarnings("unchecked") - @Deprecated - public <P extends Page> P click(final int x, final int y) - throws IOException, ElementNotFoundException { - // By default this is no different than a click without coordinates. - return (P) click(); - } - - /** * {@inheritDoc} */ @Override Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/WebResponseWrapper.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/WebResponseWrapper.java 2017-07-20 10:07:12 UTC (rev 14677) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/WebResponseWrapper.java 2017-07-20 10:22:26 UTC (rev 14678) @@ -69,25 +69,6 @@ /** * {@inheritDoc} - * The default behavior of this method is to return getContentAsString(String) on the wrapped webResponse object. - */ - @Override - @Deprecated - public String getContentAsString(final String encoding) { - return wrappedWebResponse_.getContentAsString(encoding); - } - - /** - * {@inheritDoc} - */ - @Override - @Deprecated - public String getContentAsString(final String encoding, final String defaultEncoding) { - return wrappedWebResponse_.getContentAsString(encoding, defaultEncoding); - } - - /** - * {@inheritDoc} * The default behavior of this method is to return getContentAsString(Charset) on the wrapped webResponse object. */ @Override Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CacheTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CacheTest.java 2017-07-20 10:07:12 UTC (rev 14677) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CacheTest.java 2017-07-20 10:22:26 UTC (rev 14678) @@ -436,11 +436,6 @@ } @Override - public String getContentAsString(final String encoding) { - throw new RuntimeException("not implemented"); - } - - @Override public Charset getContentCharset() { throw new RuntimeException("not implemented"); } |
From: <rb...@us...> - 2017-07-21 10:01:16
|
Revision: 14682 http://sourceforge.net/p/htmlunit/code/14682 Author: rbri Date: 2017-07-21 10:01:12 +0000 (Fri, 21 Jul 2017) Log Message: ----------- ff52, chrome and flash update Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/NavigatorTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-07-21 09:31:25 UTC (rev 14681) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-07-21 10:01:12 UTC (rev 14682) @@ -153,9 +153,9 @@ /** Latest Chrome. */ public static final BrowserVersion CHROME = new BrowserVersion( NETSCAPE, "5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36" - + " (KHTML, like Gecko) Chrome/59.0.3071.109 Safari/537.36", + + " (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36" - + " (KHTML, like Gecko) Chrome/59.0.3071.109 Safari/537.36", + + " (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36", 59, "Chrome", null); /** Microsoft Edge. Work In Progress!!! */ @@ -191,7 +191,7 @@ // FF52 FIREFOX_52.initDefaultFeatures(); FIREFOX_52.setVendor(""); - FIREFOX_52.buildId_ = "20170607123825"; + FIREFOX_52.buildId_ = "20170627155318"; FIREFOX_52.setHeaderNamesOrdered(new String[] { "Host", "User-Agent", "Accept", "Accept-Language", "Accept-Encoding", "Referer", "Cookie", "Connection", "Upgrade-Insecure-Requests"}); FIREFOX_52.setHtmlAcceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); @@ -327,19 +327,19 @@ CHROME.getPlugins().add(flash); flash = new PluginConfiguration("Shockwave Flash", - "Shockwave Flash 26.0 r0", "26.0.0.131", "NPSWF32_26_0_0_131.dll"); + "Shockwave Flash 26.0 r0", "26.0.0.137", "NPSWF32_26_0_0_137.dll"); flash.getMimeTypes().add(new PluginConfiguration.MimeType("application/x-shockwave-flash", "Shockwave Flash", "swf")); FIREFOX_45.getPlugins().add(flash); flash = new PluginConfiguration("Shockwave Flash", - "Shockwave Flash 26.0 r0", "26.0.0.131", "NPSWF64_26_0_0_131.dll"); + "Shockwave Flash 26.0 r0", "26.0.0.137", "NPSWF64_26_0_0_137.dll"); flash.getMimeTypes().add(new PluginConfiguration.MimeType("application/x-shockwave-flash", "Shockwave Flash", "swf")); FIREFOX_52.getPlugins().add(flash); flash = new PluginConfiguration("Shockwave Flash", - "Shockwave Flash 26.0 r0", "26.0.0.131", "Flash32_26_0_0_131.ocx"); + "Shockwave Flash 26.0 r0", "26.0.0.137", "Flash32_26_0_0_137.ocx"); flash.getMimeTypes().add(new PluginConfiguration.MimeType("application/x-shockwave-flash", "Shockwave Flash", "swf")); INTERNET_EXPLORER.getPlugins().add(flash); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/NavigatorTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/NavigatorTest.java 2017-07-21 09:31:25 UTC (rev 14681) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/NavigatorTest.java 2017-07-21 10:01:12 UTC (rev 14682) @@ -18,6 +18,7 @@ import org.junit.Test; import org.junit.runner.RunWith; +import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import com.gargoylesoftware.htmlunit.BrowserRunner; @@ -179,27 +180,32 @@ + "<head>\n" + " <title>test</title>\n" + " <script>\n" - + " function doTest() {\n" + + " function log(text) {\n" + + " var textarea = document.getElementById('myTextarea');\n" + + " textarea.value += text + ',';\n" + + " }\n" - + " var names = [];" - + " for (var i = 0; i < window.navigator.plugins.length; i++) {\n" - + " names[i] = window.navigator.plugins[i].name;\n" - + " }\n" + + " function doTest() {\n" + + " var names = [];" + + " for (var i = 0; i < window.navigator.plugins.length; i++) {\n" + + " names[i] = window.navigator.plugins[i].name;\n" + + " }\n" // there is no fixed order, sort for stable testing + " name = names.sort().join('; ');\n" - + " alert(names);\n" + + " log(names);\n" + " }\n" + " </script>\n" + "</head>\n" + "<body onload='doTest()'>\n" + + " <textarea id='myTextarea' cols='80' rows='10'></textarea>\n" + "</body>\n" + "</html>"; - final WebDriver driver = loadPage2(html); - final List<String> alerts = getCollectedAlerts(driver, 1); + final WebDriver driver = loadPageWithAlerts2(html); + final String alerts = driver.findElement(By.id("myTextarea")).getAttribute("value"); for (PluginConfiguration plugin : getBrowserVersion().getPlugins()) { - assertTrue(plugin.getName() + " not found", alerts.get(0).contains(plugin.getName())); + assertTrue(plugin.getName() + " not found", alerts.contains(plugin.getName())); } } @@ -208,10 +214,10 @@ * @throws Exception on test failure */ @Test - @Alerts(FF45 = {"Shockwave Flash", "Shockwave Flash 26.0 r0", "26.0.0.131", "NPSWF32_26_0_0_131.dll"}, - FF52 = {"Shockwave Flash", "Shockwave Flash 26.0 r0", "26.0.0.131", "NPSWF64_26_0_0_131.dll"}, + @Alerts(FF45 = {"Shockwave Flash", "Shockwave Flash 26.0 r0", "26.0.0.137", "NPSWF32_26_0_0_137.dll"}, + FF52 = {"Shockwave Flash", "Shockwave Flash 26.0 r0", "26.0.0.137", "NPSWF64_26_0_0_137.dll"}, CHROME = {"Shockwave Flash", "Shockwave Flash 24.0 r0", "undefined", "internal-not-yet-present"}, - IE = {"Shockwave Flash", "Shockwave Flash 26.0 r0", "26.0.0.131", "Flash32_26_0_0_131.ocx"}, + IE = {"Shockwave Flash", "Shockwave Flash 26.0 r0", "26.0.0.137", "Flash32_26_0_0_137.ocx"}, EDGE = {"Shockwave Flash", "Shockwave Flash 18.0 r0", "18.0.0.232", "Flash.ocx"}) public void pluginsShockwaveFlash() throws Exception { final String html = "<html>\n" @@ -374,7 +380,7 @@ @Test @Alerts(DEFAULT = "undefined", FF45 = "20170411115307", - FF52 = "20170607123825") + FF52 = "20170627155318") public void buildID() throws Exception { final String html = "<html><head><title>First</title>\n" |
From: <asa...@us...> - 2017-07-21 10:56:54
|
Revision: 14683 http://sourceforge.net/p/htmlunit/code/14683 Author: asashour Date: 2017-07-21 10:56:46 +0000 (Fri, 21 Jul 2017) Log Message: ----------- Fix build Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2017-07-21 10:01:12 UTC (rev 14682) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2017-07-21 10:56:46 UTC (rev 14683) @@ -1421,7 +1421,9 @@ if (locationString == null) { return webResponse; } - locationString = new String(locationString.getBytes(ISO_8859_1), UTF_8); + if (!getBrowserVersion().hasFeature(URL_MINIMAL_QUERY_ENCODING)) { + locationString = new String(locationString.getBytes(ISO_8859_1), UTF_8); + } newUrl = expandUrl(url, locationString); } catch (final MalformedURLException e) { Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java 2017-07-21 10:01:12 UTC (rev 14682) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java 2017-07-21 10:56:46 UTC (rev 14683) @@ -192,7 +192,9 @@ * @throws Exception if an error occurs */ @Test - @Alerts("§§URL§§test?%D8%A3%D9%87%D9%84%D8%A7%D9%8B") + @Alerts(DEFAULT = "§§URL§§test?%D8%A3%D9%87%D9%84%D8%A7%D9%8B", + IE = "§§URL§§test?أهلاً") + @NotYetImplemented(IE) // seems to work only when running alone public void locationQueryUTF() throws Exception { final String response = "HTTP/1.1 302 Found\r\n" |
From: <asa...@us...> - 2017-07-21 13:02:27
|
Revision: 14684 http://sourceforge.net/p/htmlunit/code/14684 Author: asashour Date: 2017-07-21 13:02:24 +0000 (Fri, 21 Jul 2017) Log Message: ----------- Fix build Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2017-07-21 10:56:46 UTC (rev 14683) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2017-07-21 13:02:24 UTC (rev 14684) @@ -1315,7 +1315,7 @@ default: return loadWebResponseFromWebConnection(webRequest, ALLOWED_REDIRECTIONS_SAME_URL, - webRequest.getCharset()); + webRequest.getCharset()); } } @@ -1422,7 +1422,7 @@ return webResponse; } if (!getBrowserVersion().hasFeature(URL_MINIMAL_QUERY_ENCODING)) { - locationString = new String(locationString.getBytes(ISO_8859_1), UTF_8); + locationString = new String(locationString.getBytes(ISO_8859_1), UTF_8); } newUrl = expandUrl(url, locationString); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java 2017-07-21 10:56:46 UTC (rev 14683) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection3Test.java 2017-07-21 13:02:24 UTC (rev 14684) @@ -157,7 +157,9 @@ * @throws Exception if an error occurs */ @Test - @Alerts("§§URL§§%D8%A3%D9%87%D9%84%D8%A7%D9%8B") + @Alerts(DEFAULT = "§§URL§§%D8%A3%D9%87%D9%84%D8%A7%D9%8B", + IE = "§§URL§§أهلاً") + @NotYetImplemented(IE) // seems to work only when running alone public void locationUTF() throws Exception { final String response = "HTTP/1.1 302 Found\r\n" @@ -193,7 +195,7 @@ */ @Test @Alerts(DEFAULT = "§§URL§§test?%D8%A3%D9%87%D9%84%D8%A7%D9%8B", - IE = "§§URL§§test?أهلاً") + IE = "§§URL§§test?أهلاً") @NotYetImplemented(IE) // seems to work only when running alone public void locationQueryUTF() throws Exception { |
From: <asa...@us...> - 2017-07-21 21:26:08
|
Revision: 14685 http://sourceforge.net/p/htmlunit/code/14685 Author: asashour Date: 2017-07-21 21:26:05 +0000 (Fri, 21 Jul 2017) Log Message: ----------- DomElement: Fix .getChildElements() Issue 1905 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/DomElement2Test.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2017-07-21 13:02:24 UTC (rev 14684) +++ trunk/htmlunit/src/changes/changes.xml 2017-07-21 21:26:05 UTC (rev 14685) @@ -8,6 +8,9 @@ <body> <release version="2.28" date="???" description="Bugfixes"> + <action type="fix" dev="asashour" issue="1905"> + DomElement: Fix .getChildElements(). + </action> <action type="remove" dev="asashour"> Remove deprecated HtmlFileInput.setValueAttribute(String[]), HtmlInput.click(int,int), SgmlPage.getPageEncoding(), WebRequest.setCharset(String) and WebResponse.getContentAsString(String). Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java 2017-07-21 13:02:24 UTC (rev 14684) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java 2017-07-21 21:26:05 UTC (rev 14685) @@ -820,7 +820,7 @@ private void setNextElement(final DomNode node) { DomNode next = node.getNextSibling(); - while (next != null && !(next instanceof HtmlElement)) { + while (next != null && !(next instanceof DomElement)) { next = next.getNextSibling(); } nextElement_ = (DomElement) next; Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/DomElement2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/DomElement2Test.java 2017-07-21 13:02:24 UTC (rev 14684) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/DomElement2Test.java 2017-07-21 21:26:05 UTC (rev 14685) @@ -14,11 +14,14 @@ */ package com.gargoylesoftware.htmlunit.html; +import java.util.concurrent.atomic.AtomicInteger; + import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.SimpleWebTestCase; +import com.gargoylesoftware.htmlunit.xml.XmlPage; /** * Tests for {@link DomElement}. @@ -80,4 +83,27 @@ assertFalse(page.getElementById("d3").isMouseOver()); assertTrue(page.getElementById("d4").isMouseOver()); } + + /** + * Test case for Bug #1905. + * + * @throws Exception if the test fails + */ + @Test + public void getChildElements() throws Exception { + final String xml = "<events>\n" + + " <something/>\n" + + "</events>"; + getMockWebConnection().setDefaultResponse(xml, "text/xml"); + getWebClient().setWebConnection(getMockWebConnection()); + final XmlPage page = getWebClient().getPage(URL_FIRST); + final DomElement root = page.getDocumentElement(); + final AtomicInteger count = new AtomicInteger(0); + root.getChildElements().forEach(e -> count.incrementAndGet()); + assertEquals(1, count.get()); + + count.set(0); + root.getChildren().forEach(e -> count.incrementAndGet()); + assertEquals(3, count.get()); + } } |
From: <rb...@us...> - 2017-07-22 12:38:17
|
Revision: 14687 http://sourceforge.net/p/htmlunit/code/14687 Author: rbri Date: 2017-07-22 12:38:14 +0000 (Sat, 22 Jul 2017) Log Message: ----------- add some more try/catch blocks to ignore the problem in IE also, add test that shows the problem Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlInlineFrame2Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java 2017-07-22 07:53:10 UTC (rev 14686) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java 2017-07-22 12:38:14 UTC (rev 14687) @@ -415,7 +415,18 @@ final Method jsConstructor = ActiveXObject.class.getDeclaredMethod("jsConstructor", Context.class, Object[].class, Function.class, boolean.class); final FunctionObject functionObject = new HiddenFunctionObject("ActiveXObject", jsConstructor, window); - functionObject.addAsConstructor(window, prototype); + try { + functionObject.addAsConstructor(window, prototype); + } + catch (final Exception e) { + // TODO see issue #1897 + if (LOG.isWarnEnabled()) { + final String newline = System.lineSeparator(); + LOG.warn("Error during JavaScriptEngine.init(WebWindow, Context)" + newline + + e.getMessage() + newline + + "prototype: " + prototype.getClassName()); + } + } } } @@ -484,10 +495,34 @@ private static void defineConstructor(final Window window, final Scriptable prototype, final ScriptableObject constructor) { constructor.setParentScope(window); - ScriptableObject.defineProperty(prototype, "constructor", constructor, - ScriptableObject.DONTENUM | ScriptableObject.PERMANENT | ScriptableObject.READONLY); - ScriptableObject.defineProperty(constructor, "prototype", prototype, - ScriptableObject.DONTENUM | ScriptableObject.PERMANENT | ScriptableObject.READONLY); + try { + ScriptableObject.defineProperty(prototype, "constructor", constructor, + ScriptableObject.DONTENUM | ScriptableObject.PERMANENT | ScriptableObject.READONLY); + } + catch (final Exception e) { + // TODO see issue #1897 + if (LOG.isWarnEnabled()) { + final String newline = System.lineSeparator(); + LOG.warn("Error during JavaScriptEngine.init(WebWindow, Context)" + newline + + e.getMessage() + newline + + "prototype: " + prototype.getClassName()); + } + } + + try { + ScriptableObject.defineProperty(constructor, "prototype", prototype, + ScriptableObject.DONTENUM | ScriptableObject.PERMANENT | ScriptableObject.READONLY); + } + catch (final Exception e) { + // TODO see issue #1897 + if (LOG.isWarnEnabled()) { + final String newline = System.lineSeparator(); + LOG.warn("Error during JavaScriptEngine.init(WebWindow, Context)" + newline + + e.getMessage() + newline + + "prototype: " + prototype.getClassName()); + } + } + window.defineProperty(constructor.getClassName(), constructor, ScriptableObject.DONTENUM); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlInlineFrame2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlInlineFrame2Test.java 2017-07-22 07:53:10 UTC (rev 14686) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlInlineFrame2Test.java 2017-07-22 12:38:14 UTC (rev 14687) @@ -230,4 +230,29 @@ assertEquals(getExpectedAlerts(), getCollectedAlerts(driver)); } + + /** + * See issue #1897. + * In the end the strict mode should not be used for the setup of + * the new window. + * + * @throws Exception if the test fails + */ + @Test + @Alerts("IFRAME") + public void createIframeFromStrictFunction() throws Exception { + final String html = "<html><head>\n" + + "<script>\n" + + " function test() {\n" + + " 'use strict';\n" + + " var iFrame = document.createElement('iframe');\n" + + " alert(iFrame.tagName);\n" + + " }\n" + + "</script>\n" + + "</head>\n" + + "<body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } } |
From: <rb...@us...> - 2017-07-22 15:07:12
|
Revision: 14688 http://sourceforge.net/p/htmlunit/code/14688 Author: rbri Date: 2017-07-22 15:07:10 +0000 (Sat, 22 Jul 2017) Log Message: ----------- more detailed tests, add isFirefox52 to make updates more robust Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/AbstractJavaScriptConfiguration.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Document.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/intl/DateTimeFormat.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CodeStyleTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection2Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-07-22 12:38:14 UTC (rev 14687) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-07-22 15:07:10 UTC (rev 14688) @@ -535,6 +535,14 @@ } /** + * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br> + * @return whether or not this version version 52 of a Firefox browser + */ + public final boolean isFirefox52() { + return isFirefox() && getBrowserVersionNumeric() == 52; + } + + /** * Returns the application code name, for example "Mozilla". * Default value is "Mozilla" if not explicitly configured. * @return the application code name Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/AbstractJavaScriptConfiguration.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/AbstractJavaScriptConfiguration.java 2017-07-22 12:38:14 UTC (rev 14687) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/configuration/AbstractJavaScriptConfiguration.java 2017-07-22 15:07:10 UTC (rev 14688) @@ -105,13 +105,11 @@ else if (browser.isEdge()) { expectedBrowser = SupportedBrowser.EDGE; } + else if (browser.isFirefox52()) { + expectedBrowser = SupportedBrowser.FF52; + } else if (browser.isFirefox()) { - if (browser.getBrowserVersionNumeric() < 52) { - expectedBrowser = SupportedBrowser.FF45; - } - else { - expectedBrowser = SupportedBrowser.FF52; - } + expectedBrowser = SupportedBrowser.FF45; } else { expectedBrowser = SupportedBrowser.CHROME; // our current fallback Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Document.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Document.java 2017-07-22 12:38:14 UTC (rev 14687) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/Document.java 2017-07-22 15:07:10 UTC (rev 14688) @@ -941,12 +941,11 @@ compatMode_ = "CSS1Compat"; - final BrowserVersion browserVersion = getBrowserVersion(); if (isQuirksDocType()) { compatMode_ = "BackCompat"; } - final float version = browserVersion.getBrowserVersionNumeric(); + final float version = getBrowserVersion().getBrowserVersionNumeric(); documentMode_ = (int) Math.floor(version); return documentMode_; } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/intl/DateTimeFormat.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/intl/DateTimeFormat.java 2017-07-22 12:38:14 UTC (rev 14687) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/intl/DateTimeFormat.java 2017-07-22 15:07:10 UTC (rev 14688) @@ -242,8 +242,7 @@ else if (browserVersion.isIE()) { formats = IE_FORMATS_; } - else if (browserVersion.isFirefox() - && browserVersion.getBrowserVersionNumeric() < BrowserVersion.FIREFOX_52.getBrowserVersionNumeric()) { + else if (!browserVersion.isFirefox52()) { formats = FF_45_FORMATS_; } else { Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CodeStyleTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CodeStyleTest.java 2017-07-22 12:38:14 UTC (rev 14687) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CodeStyleTest.java 2017-07-22 15:07:10 UTC (rev 14688) @@ -639,22 +639,39 @@ */ private void browserVersion_isIE(final List<String> lines, final String relativePath) { if (relativePath.replace('\\', '/').contains("src/main/java") - && !relativePath.contains("JavaScriptConfiguration") - && !relativePath.contains("BrowserVersionFeatures") - && !relativePath.contains("Document") - && !relativePath.contains("HTMLParser") - && !relativePath.contains("DateTimeFormat") - && !relativePath.contains("NashornJavaScriptEngine")) { + && !relativePath.contains("JavaScriptConfiguration.java") + && !relativePath.contains("BrowserVersionFeatures.java") + && !relativePath.contains("DateTimeFormat.java") + && !relativePath.contains("Document.java") + && !relativePath.contains("HTMLDocument2.java") + && !relativePath.contains("NashornJavaScriptEngine.java")) { int index = 1; for (final String line : lines) { - if (line.contains(".isIE()") || line.contains(".isFirefox()")) { - addFailure(".isIE() and .isFirefox() should not be used, please use .hasFeature(): " + if (line.contains(".isIE()")) { + addFailure(".isIE() should not be used, please use .hasFeature(): " + relativePath + ", line: " + index); } - if (line.contains(".getBrowserVersionNumeric()") - && !relativePath.contains("BrowserConfiguration") - && !relativePath.contains("Window.java") - && !relativePath.contains("Window2.java")) { + if (line.contains(".isFirefox()")) { + addFailure(".isFirefox() should not be used, please use .hasFeature(): " + + relativePath + ", line: " + index); + } + if (line.contains(".isChrome()")) { + addFailure(".isChrome() should not be used, please use .hasFeature(): " + + relativePath + ", line: " + index); + } + index++; + } + } + if (relativePath.replace('\\', '/').contains("src/main/java") + && !relativePath.contains("BrowserConfiguration.java") + && !relativePath.contains("BrowserVersion.java") + && !relativePath.contains("Document.java") + && !relativePath.contains("HTMLParser.java") + && !relativePath.contains("Window.java") + && !relativePath.contains("Window2.java")) { + int index = 1; + for (final String line : lines) { + if (line.contains(".getBrowserVersionNumeric()")) { addFailure(".getBrowserVersionNumeric() should not be used, please use .hasFeature(): " + relativePath + ", line: " + index); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection2Test.java 2017-07-22 12:38:14 UTC (rev 14687) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/HttpWebConnection2Test.java 2017-07-22 15:07:10 UTC (rev 14688) @@ -79,17 +79,17 @@ + "User-Agent: " + getBrowserVersion().getUserAgent() + "\n"; } if (getBrowserVersion().isFirefox()) { - if (getBrowserVersion().getBrowserVersionNumeric() < 52) { + if (getBrowserVersion().isFirefox52()) { expectedHeaders = "Connection: keep-alive\n" - + "Host: localhost:" + PORT + "\n" - + "Referer: http://localhost:" + PORT + "/\n" - + "User-Agent: " + getBrowserVersion().getUserAgent() + "\n"; + + "Host: localhost:" + PORT + "\n" + + "Referer: http://localhost:" + PORT + "/\n" + + "Upgrade-Insecure-Requests: 1\n" + + "User-Agent: " + getBrowserVersion().getUserAgent() + "\n"; } else { expectedHeaders = "Connection: keep-alive\n" + "Host: localhost:" + PORT + "\n" + "Referer: http://localhost:" + PORT + "/\n" - + "Upgrade-Insecure-Requests: 1\n" + "User-Agent: " + getBrowserVersion().getUserAgent() + "\n"; } } |
From: <rb...@us...> - 2017-07-24 17:46:21
|
Revision: 14697 http://sourceforge.net/p/htmlunit/code/14697 Author: rbri Date: 2017-07-24 17:46:18 +0000 (Mon, 24 Jul 2017) Log Message: ----------- Support for BrowserVersionFeatures parameter of the BrowserVersion constructor has been removed. Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2017-07-24 06:39:20 UTC (rev 14696) +++ trunk/htmlunit/src/changes/changes.xml 2017-07-24 17:46:18 UTC (rev 14697) @@ -8,6 +8,10 @@ <body> <release version="2.28" date="???" description="Bugfixes"> + <action type="remove" dev="rbri"> + INCOMPATIBLE CHANGE: Support for BrowserVersionFeatures parameter of the BrowserVersion constructor + has been removed. + </action> <action type="fix" dev="asashour" issue="1905"> DomElement: Fix .getChildElements(). </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-07-24 06:39:20 UTC (rev 14696) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-07-24 17:46:18 UTC (rev 14697) @@ -17,7 +17,6 @@ import java.io.File; import java.io.Serializable; import java.lang.reflect.Field; -import java.util.Arrays; import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; @@ -134,7 +133,7 @@ public static final BrowserVersion FIREFOX_45 = new BrowserVersion( NETSCAPE, "5.0 (Windows)", "Mozilla/5.0 (Windows NT 6.1; rv:45.0) Gecko/20100101 Firefox/45.0", - 45, "FF45", null); + 45, "FF45"); /** * Firefox 52 ESR. @@ -143,12 +142,12 @@ public static final BrowserVersion FIREFOX_52 = new BrowserVersion( NETSCAPE, "5.0 (Windows)", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:52.0) Gecko/20100101 Firefox/52.0", - 52, "FF52", null); + 52, "FF52"); /** Internet Explorer 11. */ public static final BrowserVersion INTERNET_EXPLORER = new BrowserVersion( NETSCAPE, "5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko", - "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko", 11, "IE", null); + "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko", 11, "IE"); /** Latest Chrome. */ public static final BrowserVersion CHROME = new BrowserVersion( @@ -156,7 +155,7 @@ + " (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36" + " (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36", - 59, "Chrome", null); + 59, "Chrome"); /** Microsoft Edge. Work In Progress!!! */ public static final BrowserVersion EDGE = new BrowserVersion( @@ -164,7 +163,7 @@ + " (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393", "Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36" + " (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393", - 14, "Edge", null); + 14, "Edge"); /** * The best supported browser version at the moment. @@ -177,8 +176,6 @@ /** Register plugins for the browser versions. */ static { // FF45 - FIREFOX_45.initDefaultFeatures(); - FIREFOX_45.setVendor(""); FIREFOX_45.setPlatform(PLATFORM_WIN32); FIREFOX_45.buildId_ = "20170411115307"; FIREFOX_45.setHeaderNamesOrdered(new String[] { @@ -189,8 +186,6 @@ FIREFOX_45.setCssAcceptHeader("text/css,*/*;q=0.1"); // FF52 - FIREFOX_52.initDefaultFeatures(); - FIREFOX_52.setVendor(""); FIREFOX_52.buildId_ = "20170627155318"; FIREFOX_52.setHeaderNamesOrdered(new String[] { "Host", "User-Agent", "Accept", "Accept-Language", "Accept-Encoding", "Referer", "Cookie", "Connection", "Upgrade-Insecure-Requests"}); @@ -198,8 +193,6 @@ FIREFOX_52.setCssAcceptHeader("text/css,*/*;q=0.1"); // IE - INTERNET_EXPLORER.initDefaultFeatures(); - INTERNET_EXPLORER.setVendor(""); INTERNET_EXPLORER.setPlatform(PLATFORM_WIN32); INTERNET_EXPLORER.setHeaderNamesOrdered(new String[] { "Accept", "Referer", "Accept-Language", "User-Agent", "Accept-Encoding", "Host", "DNT", "Connection", @@ -210,11 +203,8 @@ INTERNET_EXPLORER.setScriptAcceptHeader("application/javascript, */*;q=0.8"); // EDGE - EDGE.initDefaultFeatures(); - EDGE.setVendor(""); // CHROME - CHROME.initDefaultFeatures(); CHROME.setApplicationCodeName("Mozilla"); CHROME.setVendor("Google Inc."); CHROME.setPlatform(PLATFORM_WIN32); @@ -356,7 +346,7 @@ private String applicationName_; private String applicationVersion_; private String buildId_; - private String vendor_; + private String vendor_ = ""; private String browserLanguage_ = LANGUAGE_ENGLISH_US; private String cpuClass_ = CPU_CLASS_X86; private boolean onLine_ = true; @@ -389,27 +379,10 @@ final String userAgent, final int browserVersionNumeric) { this(applicationName, applicationVersion, userAgent, - browserVersionNumeric, applicationName + browserVersionNumeric, null); + browserVersionNumeric, applicationName + browserVersionNumeric); } /** - * Instantiates one. - * - * @param applicationName the name of the application - * @param applicationVersion the version string of the application - * @param userAgent the user agent string that will be sent to the server - * @param browserVersionNumeric the number version of the browser - * @param features the browser features - */ - public BrowserVersion(final String applicationName, final String applicationVersion, - final String userAgent, final int browserVersionNumeric, - final BrowserVersionFeatures[] features) { - - this(applicationName, applicationVersion, userAgent, - browserVersionNumeric, applicationName + browserVersionNumeric, features); - } - - /** * Creates a new browser version instance. * * @param applicationName the name of the application @@ -418,11 +391,10 @@ * @param javaScriptVersion the version of JavaScript * @param browserVersionNumeric the floating number version of the browser * @param nickname the short name of the browser (like "FF52", "IE", ...) - * @param features the browser features */ private BrowserVersion(final String applicationName, final String applicationVersion, final String userAgent, final int browserVersionNumeric, - final String nickname, final BrowserVersionFeatures[] features) { + final String nickname) { applicationName_ = applicationName; setApplicationVersion(applicationVersion); @@ -435,9 +407,7 @@ scriptAcceptHeader_ = "*/*"; xmlHttpRequestAcceptHeader_ = "*/*"; - if (features != null) { - features_.addAll(Arrays.asList(features)); - } + initDefaultFeatures(); } private void initDefaultFeatures() { @@ -959,7 +929,7 @@ @Override public BrowserVersion clone() { final BrowserVersion clone = new BrowserVersion(getApplicationName(), getApplicationVersion(), - getUserAgent(), getBrowserVersionNumeric(), getNickname(), null); + getUserAgent(), getBrowserVersionNumeric(), getNickname()); clone.setApplicationCodeName(getApplicationCodeName()); clone.setApplicationMinorVersion(getApplicationMinorVersion()); |
From: <rb...@us...> - 2017-07-24 17:51:50
|
Revision: 14698 http://sourceforge.net/p/htmlunit/code/14698 Author: rbri Date: 2017-07-24 17:51:48 +0000 (Mon, 24 Jul 2017) Log Message: ----------- BrowserVersion.clone now copies the system-timezone attribute Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2017-07-24 17:46:18 UTC (rev 14697) +++ trunk/htmlunit/src/changes/changes.xml 2017-07-24 17:51:48 UTC (rev 14698) @@ -8,6 +8,9 @@ <body> <release version="2.28" date="???" description="Bugfixes"> + <action type="fix" dev="rbri"> + BrowserVersion.clone now copies the system-timezone attribute. + </action> <action type="remove" dev="rbri"> INCOMPATIBLE CHANGE: Support for BrowserVersionFeatures parameter of the BrowserVersion constructor has been removed. Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-07-24 17:46:18 UTC (rev 14697) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-07-24 17:51:48 UTC (rev 14698) @@ -939,6 +939,7 @@ clone.setOnLine(isOnLine()); clone.setPlatform(getPlatform()); clone.setSystemLanguage(getSystemLanguage()); + clone.setSystemTimezone(getSystemTimezone()); clone.setUserLanguage(getUserLanguage()); clone.buildId_ = getBuildId(); |
From: <rb...@us...> - 2017-07-25 08:34:48
|
Revision: 14701 http://sourceforge.net/p/htmlunit/code/14701 Author: rbri Date: 2017-07-25 08:34:45 +0000 (Tue, 25 Jul 2017) Log Message: ----------- more BrowserVersion cleanup Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2017-07-24 18:12:04 UTC (rev 14700) +++ trunk/htmlunit/src/changes/changes.xml 2017-07-25 08:34:45 UTC (rev 14701) @@ -11,7 +11,7 @@ <action type="fix" dev="rbri"> BrowserVersion.clone now copies the system-timezone attribute. </action> - <action type="remove" dev="rbri"> + <action type="remove" dev="rbri" issue="1890"> INCOMPATIBLE CHANGE: Support for BrowserVersionFeatures parameter of the BrowserVersion constructor has been removed. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-07-24 18:12:04 UTC (rev 14700) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-07-25 08:34:45 UTC (rev 14701) @@ -131,9 +131,10 @@ * @since 2.21 */ public static final BrowserVersion FIREFOX_45 = new BrowserVersion( - NETSCAPE, "5.0 (Windows)", + "5.0 (Windows)", "Mozilla/5.0 (Windows NT 6.1; rv:45.0) Gecko/20100101 Firefox/45.0", - 45, "FF45"); + 45, + "FF45"); /** * Firefox 52 ESR. @@ -140,30 +141,35 @@ * @since 2.26 */ public static final BrowserVersion FIREFOX_52 = new BrowserVersion( - NETSCAPE, "5.0 (Windows)", + "5.0 (Windows)", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:52.0) Gecko/20100101 Firefox/52.0", - 52, "FF52"); + 52, + "FF52"); /** Internet Explorer 11. */ public static final BrowserVersion INTERNET_EXPLORER = new BrowserVersion( - NETSCAPE, "5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko", - "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko", 11, "IE"); + "5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko", + "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko", + 11, + "IE"); /** Latest Chrome. */ public static final BrowserVersion CHROME = new BrowserVersion( - NETSCAPE, "5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36" - + " (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36", + "5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36" + + " (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36" - + " (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36", - 59, "Chrome"); + + " (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36", + 59, + "Chrome"); /** Microsoft Edge. Work In Progress!!! */ public static final BrowserVersion EDGE = new BrowserVersion( - NETSCAPE, "5.0 (Windows NT 10.0) AppleWebKit/537.36" - + " (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393", + "5.0 (Windows NT 10.0) AppleWebKit/537.36" + + " (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393", "Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36" - + " (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393", - 14, "Edge"); + + " (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393", + 14, + "Edge"); /** * The best supported browser version at the moment. @@ -378,25 +384,24 @@ public BrowserVersion(final String applicationName, final String applicationVersion, final String userAgent, final int browserVersionNumeric) { - this(applicationName, applicationVersion, userAgent, - browserVersionNumeric, applicationName + browserVersionNumeric); + this(applicationVersion, userAgent, browserVersionNumeric, applicationName + browserVersionNumeric); + setApplicationName(applicationName); } /** * Creates a new browser version instance. * - * @param applicationName the name of the application * @param applicationVersion the version string of the application * @param userAgent the user agent string that will be sent to the server * @param javaScriptVersion the version of JavaScript * @param browserVersionNumeric the floating number version of the browser - * @param nickname the short name of the browser (like "FF52", "IE", ...) + * @param nickname the short name of the browser (like "FF52", "IE", ...) - has to be unique */ - private BrowserVersion(final String applicationName, final String applicationVersion, + private BrowserVersion(final String applicationVersion, final String userAgent, final int browserVersionNumeric, final String nickname) { - applicationName_ = applicationName; + applicationName_ = NETSCAPE; setApplicationVersion(applicationVersion); userAgent_ = userAgent; browserVersionNumeric_ = browserVersionNumeric; @@ -926,9 +931,10 @@ */ @Override public BrowserVersion clone() { - final BrowserVersion clone = new BrowserVersion(getApplicationName(), getApplicationVersion(), + final BrowserVersion clone = new BrowserVersion(getApplicationVersion(), getUserAgent(), getBrowserVersionNumeric(), getNickname()); + clone.setApplicationName(getApplicationName()); clone.setApplicationCodeName(getApplicationCodeName()); clone.setApplicationMinorVersion(getApplicationMinorVersion()); clone.setVendor(getVendor()); |
From: <rb...@us...> - 2017-07-25 16:23:21
|
Revision: 14705 http://sourceforge.net/p/htmlunit/code/14705 Author: rbri Date: 2017-07-25 16:23:19 +0000 (Tue, 25 Jul 2017) Log Message: ----------- next step on our way to an immutable BrowserVersion Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/HtmlUnitContextFactoryTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngineTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfigurationTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2017-07-25 15:48:34 UTC (rev 14704) +++ trunk/htmlunit/src/changes/changes.xml 2017-07-25 16:23:19 UTC (rev 14705) @@ -12,9 +12,12 @@ BrowserVersion.clone now copies the system-timezone attribute. </action> <action type="remove" dev="rbri" issue="1890"> - INCOMPATIBLE CHANGE: Support for BrowserVersionFeatures parameter of the BrowserVersion constructor - has been removed. + INCOMPATIBLE CHANGE: BrowserVersion is final now and all constructors are removed. + The only way to create new customizes Browser versions is to clone one of the predefined. </action> + <action type="change" dev="rbri" issue="1890"> + BrowserVersion setter methods are fluent now. + </action> <action type="fix" dev="asashour" issue="1905"> DomElement: Fix .getChildElements(). </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-07-25 15:48:34 UTC (rev 14704) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-07-25 16:23:19 UTC (rev 14705) @@ -35,7 +35,7 @@ * Objects of this class represent one specific version of a given browser. Predefined * constants are provided for common browser versions. * - * <p>You can change the constants by something like: + * <p>You can create a different browser setup by simply clone from the predefined ones. * <pre id='htmlUnitCode'> * String applicationName = "APPNAME"; * String applicationVersion = "APPVERSION"; @@ -42,14 +42,14 @@ * String userAgent = "USERAGENT"; * int browserVersionNumeric = NUMERIC; * - * BrowserVersion browser = new BrowserVersion(applicationName, applicationVersion, userAgent, browserVersionNumeric) { - * public boolean hasFeature(BrowserVersionFeatures property) { - * - * // change features here - * return BrowserVersion.BROWSER.hasFeature(property); - * } - * }; + * BrowserVersion browser = BrowserVersion.FF52.clone() + * .setApplicationName(applicationName) + * .setApplicationVersion(applicationVersion) + * .setUserAgent(userAgent); * </pre> + * <p>But keep in mind that this still behaves like a FF52, only the stuff reported to the + * outside is changed. This is more or less the same you can do with real browsers installing + * plugins like UserAgentSwitcher. * <script> var pre = document.getElementById('htmlUnitCode'); pre.innerHTML = pre.innerHTML.replace('APPNAME', navigator.appName); @@ -92,7 +92,7 @@ * @author Frank Danek * @author Ronald Brill */ -public class BrowserVersion implements Serializable, Cloneable { +public final class BrowserVersion implements Serializable, Cloneable { /** * Application name the Netscape navigator series of browsers. @@ -340,7 +340,7 @@ EDGE.getPlugins().add(flash); } - private int browserVersionNumeric_; + private final int browserVersionNumeric_; private final String nickname_; private String applicationCodeName_ = "Mozilla"; @@ -368,24 +368,6 @@ private Map<String, String> uploadMimeTypes_ = new HashMap<>(); /** - * Instantiates one. - * - * @param applicationName the name of the application - * @param applicationVersion the version string of the application - * @param userAgent the user agent string that will be sent to the server - * @param browserVersionNumeric the number version of the browser - */ - public BrowserVersion(final String applicationName, final String applicationVersion, - final String userAgent, final int browserVersionNumeric) { - - this(browserVersionNumeric, applicationName + browserVersionNumeric); - - setApplicationName(applicationName) - .setApplicationVersion(applicationVersion) - .setUserAgent(userAgent); - } - - /** * Creates a new browser version instance. * * @param browserVersionNumeric the floating number version of the browser @@ -465,7 +447,7 @@ * version of Internet Explorer. * @return whether or not this version is a version of IE */ - public final boolean isIE() { + public boolean isIE() { return getNickname().startsWith("IE"); } @@ -475,7 +457,7 @@ * in the application name, we have to look in the nickname. * @return whether or not this version is a version of a Chrome browser */ - public final boolean isChrome() { + public boolean isChrome() { return getNickname().startsWith("Chrome"); } @@ -484,7 +466,7 @@ * version of Microsoft Edge. * @return whether or not this version is a version of an Edge browser */ - public final boolean isEdge() { + public boolean isEdge() { return getNickname().startsWith("Edge"); } @@ -493,7 +475,7 @@ * version of Firefox. * @return whether or not this version is a version of a Firefox browser */ - public final boolean isFirefox() { + public boolean isFirefox() { return getNickname().startsWith("FF"); } @@ -517,7 +499,7 @@ * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br> * @return whether or not this version version 52 of a Firefox browser */ - public final boolean isFirefox52() { + public boolean isFirefox52() { return isFirefox() && getBrowserVersionNumeric() == 52; } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/HtmlUnitContextFactoryTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/HtmlUnitContextFactoryTest.java 2017-07-25 15:48:34 UTC (rev 14704) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/HtmlUnitContextFactoryTest.java 2017-07-25 16:23:19 UTC (rev 14705) @@ -35,10 +35,13 @@ @Test public void customBrowserVersion() throws Exception { final String html = "<html></html>"; - final String userAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0"; - final BrowserVersion browserVersion = new BrowserVersion("Firefox", - "5.0 (Windows NT 10.0; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0", userAgent, 39); + final BrowserVersion browserVersion + = BrowserVersion.FIREFOX_52.clone() + .setApplicationName("Firefox") + .setApplicationVersion("5.0 (Windows NT 10.0; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0") + .setUserAgent("Mozilla/5.0 (Windows NT 10.0; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0"); + loadPage(browserVersion, html, null, URL_FIRST); } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngineTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngineTest.java 2017-07-25 15:48:34 UTC (rev 14704) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngineTest.java 2017-07-25 16:23:19 UTC (rev 14705) @@ -34,7 +34,6 @@ import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserVersion; -import com.gargoylesoftware.htmlunit.BrowserVersionFeatures; import com.gargoylesoftware.htmlunit.CollectingAlertHandler; import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; import com.gargoylesoftware.htmlunit.HttpMethod; @@ -1295,12 +1294,9 @@ */ @Test public void nonStandardBrowserVersion() throws Exception { - final BrowserVersion browser = new BrowserVersion("Mozilla", "5.0", "Mozilla/5.0", 11) { - @Override - public boolean hasFeature(final BrowserVersionFeatures feature) { - return BrowserVersion.INTERNET_EXPLORER.hasFeature(feature); - } - }; + final BrowserVersion browser = BrowserVersion.INTERNET_EXPLORER.clone() + .setApplicationName("Mozilla") + .setApplicationVersion("5.0"); try (WebClient client = new WebClient(browser)) { client.openWindow(WebClient.URL_ABOUT_BLANK, "TestWindow"); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfigurationTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfigurationTest.java 2017-07-25 15:48:34 UTC (rev 14704) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfigurationTest.java 2017-07-25 16:23:19 UTC (rev 14705) @@ -74,12 +74,21 @@ field.setAccessible(true); final Map<?, ?> leakyMap = (Map<?, ?>) field.get(null); - // maybe some BrowserVersions are already known + leakyMap.clear(); final int knownBrowsers = leakyMap.size(); - for (int i = 0; i < 3; i++) { - final BrowserVersion browserVersion = new BrowserVersion("App", "Version", "User agent", 1); - JavaScriptConfiguration.getInstance(browserVersion); - } + + BrowserVersion browserVersion = BrowserVersion.FIREFOX_52.clone() + .setApplicationVersion("App") + .setApplicationVersion("Version") + .setUserAgent("User agent"); + JavaScriptConfiguration.getInstance(browserVersion); + + browserVersion = BrowserVersion.FIREFOX_52.clone() + .setApplicationVersion("App2") + .setApplicationVersion("Version2") + .setUserAgent("User agent2"); + JavaScriptConfiguration.getInstance(browserVersion); + assertEquals(knownBrowsers + 1, leakyMap.size()); } @@ -94,11 +103,10 @@ long count = 0; while (count++ < 3000) { - final BrowserVersion browserVersion = new BrowserVersion( - "App" + generator.generate(20), - "Version" + generator.generate(20), - "User Agent" + generator.generate(20), - 1); + final BrowserVersion browserVersion = BrowserVersion.FIREFOX_52.clone() + .setApplicationVersion("App" + generator.generate(20)) + .setApplicationVersion("Version" + generator.generate(20)) + .setUserAgent("User Agent" + generator.generate(20)); JavaScriptConfiguration.getInstance(browserVersion); if (LOG.isInfoEnabled()) { LOG.info("count: " + count + "; memory stats: " + getMemoryStats()); |
From: <asa...@us...> - 2017-07-26 07:56:07
|
Revision: 14709 http://sourceforge.net/p/htmlunit/code/14709 Author: asashour Date: 2017-07-26 07:56:04 +0000 (Wed, 26 Jul 2017) Log Message: ----------- update test, latest chrome Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersionTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlInlineFrame2Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-07-25 18:31:08 UTC (rev 14708) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-07-26 07:56:04 UTC (rev 14709) @@ -66,7 +66,7 @@ numeric = 14; } else if (isChrome) { - numeric = 58; + numeric = 60; } pre.innerHTML = pre.innerHTML.replace('NUMERIC', numeric); var browser = "FIREFOX_52"; @@ -150,11 +150,11 @@ /** Latest Chrome. */ public static final BrowserVersion CHROME - = new BrowserVersion(59, "Chrome") + = new BrowserVersion(60, "Chrome") .setApplicationVersion("5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36" - + " (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36") + + " (KHTML, like Gecko) Chrome/60.0.3112.78 Safari/537.36") .setUserAgent("Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36" - + " (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36"); + + " (KHTML, like Gecko) Chrome/60.0.3112.78 Safari/537.36"); /** Microsoft Edge. Work In Progress!!! */ public static final BrowserVersion EDGE Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersionTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersionTest.java 2017-07-25 18:31:08 UTC (rev 14708) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersionTest.java 2017-07-26 07:56:04 UTC (rev 14709) @@ -34,7 +34,7 @@ assertEquals(45, BrowserVersion.FIREFOX_45.getBrowserVersionNumeric()); assertEquals(52, BrowserVersion.FIREFOX_52.getBrowserVersionNumeric()); assertEquals(11, BrowserVersion.INTERNET_EXPLORER.getBrowserVersionNumeric()); - assertEquals(59, BrowserVersion.CHROME.getBrowserVersionNumeric()); + assertEquals(60, BrowserVersion.CHROME.getBrowserVersionNumeric()); assertEquals(14, BrowserVersion.EDGE.getBrowserVersionNumeric()); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlInlineFrame2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlInlineFrame2Test.java 2017-07-25 18:31:08 UTC (rev 14708) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlInlineFrame2Test.java 2017-07-26 07:56:04 UTC (rev 14709) @@ -27,6 +27,7 @@ import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.BrowserRunner.BuggyWebDriver; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.MockWebConnection; import com.gargoylesoftware.htmlunit.WebDriverTestCase; @@ -239,18 +240,27 @@ * @throws Exception if the test fails */ @Test - @Alerts("IFRAME") + @Alerts(DEFAULT = {"false", "false", "true", "false"}, + IE = {"false", "false", "false", "false"}) + @BuggyWebDriver(CHROME) + @NotYetImplemented public void createIframeFromStrictFunction() throws Exception { final String html = "<html><head>\n" + "<script>\n" + " function test() {\n" + " 'use strict';\n" - + " var iFrame = document.createElement('iframe');\n" - + " alert(iFrame.tagName);\n" + + " var iframe = document.createElement('iframe');\n" + + " alert(!this);\n" + + " alert(!iframe);\n" + " }\n" + + " function test2() {\n" + + " var iframe = document.createElement('iframe');\n" + + " alert(!this);\n" + + " alert(!iframe);\n" + + " }\n" + "</script>\n" + "</head>\n" - + "<body onload='test()'>\n" + + "<body onload='test();test2()'>\n" + "</body></html>"; loadPageWithAlerts2(html); |
From: <rb...@us...> - 2017-07-26 13:02:54
|
Revision: 14711 http://sourceforge.net/p/htmlunit/code/14711 Author: rbri Date: 2017-07-26 13:02:50 +0000 (Wed, 26 Jul 2017) Log Message: ----------- next step on our way to an immutable BrowserVersion Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersionTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/HtmlUnitContextFactoryTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngineTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfigurationTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-07-26 13:01:33 UTC (rev 14710) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-07-26 13:02:50 UTC (rev 14711) @@ -35,7 +35,7 @@ * Objects of this class represent one specific version of a given browser. Predefined * constants are provided for common browser versions. * - * <p>You can create a different browser setup by simply clone from the predefined ones. + * <p>You can create a different browser setup by using the BrowserVersionFactory. * <pre id='htmlUnitCode'> * String applicationName = "APPNAME"; * String applicationVersion = "APPVERSION"; @@ -42,12 +42,13 @@ * String userAgent = "USERAGENT"; * int browserVersionNumeric = NUMERIC; * - * BrowserVersion browser = BrowserVersion.FF52.clone() + * BrowserVersion browser = new BrowserVersion.BrowserVersionFactory(FF52) * .setApplicationName(applicationName) * .setApplicationVersion(applicationVersion) - * .setUserAgent(userAgent); + * .setUserAgent(userAgent) + * .build(); * </pre> - * <p>But keep in mind that this still behaves like a FF52, only the stuff reported to the + * <p>But keep in mind this now one still behaves like a FF52, only the stuff reported to the * outside is changed. This is more or less the same you can do with real browsers installing * plugins like UserAgentSwitcher. * <script> @@ -92,7 +93,7 @@ * @author Frank Danek * @author Ronald Brill */ -public final class BrowserVersion implements Serializable, Cloneable { +public final class BrowserVersion implements Serializable { /** * Application name the Netscape navigator series of browsers. @@ -128,41 +129,22 @@ * Firefox 45 ESR. * @since 2.21 */ - public static final BrowserVersion FIREFOX_45 - = new BrowserVersion(45, "FF45") - .setApplicationVersion("5.0 (Windows)") - .setUserAgent("Mozilla/5.0 (Windows NT 6.1; rv:45.0) Gecko/20100101 Firefox/45.0"); + public static final BrowserVersion FIREFOX_45 = new BrowserVersion(45, "FF45"); /** * Firefox 52 ESR. * @since 2.26 */ - public static final BrowserVersion FIREFOX_52 - = new BrowserVersion(52, "FF52") - .setApplicationVersion("5.0 (Windows)") - .setUserAgent("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:52.0) Gecko/20100101 Firefox/52.0"); + public static final BrowserVersion FIREFOX_52 = new BrowserVersion(52, "FF52"); /** Internet Explorer 11. */ - public static final BrowserVersion INTERNET_EXPLORER - = new BrowserVersion(11, "IE") - .setApplicationVersion("5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko") - .setUserAgent("Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko"); + public static final BrowserVersion INTERNET_EXPLORER = new BrowserVersion(11, "IE"); /** Latest Chrome. */ - public static final BrowserVersion CHROME - = new BrowserVersion(60, "Chrome") - .setApplicationVersion("5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36" - + " (KHTML, like Gecko) Chrome/60.0.3112.78 Safari/537.36") - .setUserAgent("Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36" - + " (KHTML, like Gecko) Chrome/60.0.3112.78 Safari/537.36"); + public static final BrowserVersion CHROME = new BrowserVersion(60, "Chrome"); /** Microsoft Edge. Work In Progress!!! */ - public static final BrowserVersion EDGE - = new BrowserVersion(14, "Edge") - .setApplicationVersion("5.0 (Windows NT 10.0) AppleWebKit/537.36" - + " (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393") - .setUserAgent("Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36" - + " (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393"); + public static final BrowserVersion EDGE = new BrowserVersion(14, "Edge"); /** * The best supported browser version at the moment. @@ -175,45 +157,56 @@ /** Register plugins for the browser versions. */ static { // FF45 - FIREFOX_45.setPlatform(PLATFORM_WIN32); + FIREFOX_45.applicationVersion_ = "5.0 (Windows)"; + FIREFOX_45.userAgent_ = "Mozilla/5.0 (Windows NT 6.1; rv:45.0) Gecko/20100101 Firefox/45.0"; + FIREFOX_45.platform_ = PLATFORM_WIN32; FIREFOX_45.buildId_ = "20170411115307"; - FIREFOX_45.setHeaderNamesOrdered(new String[] { - "Host", "User-Agent", "Accept", "Accept-Language", "Accept-Encoding", "Referer", "Cookie", "Connection"}); - FIREFOX_45.setHtmlAcceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); - FIREFOX_45.setXmlHttpRequestAcceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); - FIREFOX_45.setImgAcceptHeader("image/png,image/*;q=0.8,*/*;q=0.5"); - FIREFOX_45.setCssAcceptHeader("text/css,*/*;q=0.1"); + FIREFOX_45.headerNamesOrdered_ = new String[] { + "Host", "User-Agent", "Accept", "Accept-Language", "Accept-Encoding", "Referer", "Cookie", "Connection"}; + FIREFOX_45.htmlAcceptHeader_ = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; + FIREFOX_45.xmlHttpRequestAcceptHeader_ = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; + FIREFOX_45.imgAcceptHeader_ = "image/png,image/*;q=0.8,*/*;q=0.5"; + FIREFOX_45.cssAcceptHeader_ = "text/css,*/*;q=0.1"; // FF52 + FIREFOX_52.applicationVersion_ = "5.0 (Windows)"; + FIREFOX_52.userAgent_ = "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:52.0) Gecko/20100101 Firefox/52.0"; FIREFOX_52.buildId_ = "20170627155318"; - FIREFOX_52.setHeaderNamesOrdered(new String[] { - "Host", "User-Agent", "Accept", "Accept-Language", "Accept-Encoding", "Referer", "Cookie", "Connection", "Upgrade-Insecure-Requests"}); - FIREFOX_52.setHtmlAcceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); - FIREFOX_52.setCssAcceptHeader("text/css,*/*;q=0.1"); + FIREFOX_52.headerNamesOrdered_ = new String[] { + "Host", "User-Agent", "Accept", "Accept-Language", "Accept-Encoding", "Referer", "Cookie", "Connection", "Upgrade-Insecure-Requests"}; + FIREFOX_52.htmlAcceptHeader_ = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; + FIREFOX_52.cssAcceptHeader_ = "text/css,*/*;q=0.1"; // IE - INTERNET_EXPLORER.setPlatform(PLATFORM_WIN32); - INTERNET_EXPLORER.setHeaderNamesOrdered(new String[] { + INTERNET_EXPLORER.applicationVersion_ = "5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"; + INTERNET_EXPLORER.userAgent_ = "Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko"; + INTERNET_EXPLORER.platform_ = PLATFORM_WIN32; + INTERNET_EXPLORER.headerNamesOrdered_ = new String[] { "Accept", "Referer", "Accept-Language", "User-Agent", "Accept-Encoding", "Host", "DNT", "Connection", - "Cookie"}); - INTERNET_EXPLORER.setHtmlAcceptHeader("text/html, application/xhtml+xml, */*"); - INTERNET_EXPLORER.setImgAcceptHeader("image/png, image/svg+xml, image/*;q=0.8, */*;q=0.5"); - INTERNET_EXPLORER.setCssAcceptHeader("text/css, */*"); - INTERNET_EXPLORER.setScriptAcceptHeader("application/javascript, */*;q=0.8"); + "Cookie"}; + INTERNET_EXPLORER.htmlAcceptHeader_ = "text/html, application/xhtml+xml, */*"; + INTERNET_EXPLORER.imgAcceptHeader_ = "image/png, image/svg+xml, image/*;q=0.8, */*;q=0.5"; + INTERNET_EXPLORER.cssAcceptHeader_ = "text/css, */*"; + INTERNET_EXPLORER.scriptAcceptHeader_ = "application/javascript, */*;q=0.8"; // EDGE + EDGE.applicationVersion_ = "5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393"; + EDGE.userAgent_ = "Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393"; // CHROME - CHROME.setApplicationCodeName("Mozilla"); - CHROME.setVendor("Google Inc."); - CHROME.setPlatform(PLATFORM_WIN32); - CHROME.setCpuClass(null); - CHROME.setHeaderNamesOrdered(new String[] { - "Host", "Connection", "Upgrade-Insecure-Requests", "User-Agent", "Accept", "Referer", "Accept-Encoding", "Accept-Language", "Cookie"}); - CHROME.setHtmlAcceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"); - CHROME.setImgAcceptHeader("image/webp,image/apng,image/*,*/*;q=0.8"); - CHROME.setCssAcceptHeader("text/css,*/*;q=0.1"); - CHROME.setScriptAcceptHeader("*/*"); + CHROME.applicationVersion_ = "5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.78 Safari/537.36"; + CHROME.userAgent_ = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.78 Safari/537.36"; + + CHROME.applicationCodeName_ = "Mozilla"; + CHROME.vendor_ = "Google Inc."; + CHROME.platform_ = PLATFORM_WIN32; + CHROME.cpuClass_ = null; + CHROME.headerNamesOrdered_ = new String[] { + "Host", "Connection", "Upgrade-Insecure-Requests", "User-Agent", "Accept", "Referer", "Accept-Encoding", "Accept-Language", "Cookie"}; + CHROME.htmlAcceptHeader_ = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"; + CHROME.imgAcceptHeader_ = "image/webp,image/apng,image/*,*/*;q=0.8"; + CHROME.cssAcceptHeader_ = "text/css,*/*;q=0.1"; + CHROME.scriptAcceptHeader_ = "*/*"; // there are other issues with Chrome; a different productSub, etc. // default file upload mime types @@ -670,169 +663,6 @@ } /** - * @param applicationCodeName the applicationCodeName to set - * @return this for fluent use - */ - public BrowserVersion setApplicationCodeName(final String applicationCodeName) { - applicationCodeName_ = applicationCodeName; - return this; - } - - /** - * @param applicationMinorVersion the applicationMinorVersion to set - * @return this for fluent use - */ - public BrowserVersion setApplicationMinorVersion(final String applicationMinorVersion) { - applicationMinorVersion_ = applicationMinorVersion; - return this; - } - - /** - * @param applicationName the applicationName to set - * @return this for fluent use - */ - public BrowserVersion setApplicationName(final String applicationName) { - applicationName_ = applicationName; - return this; - } - - /** - * @param applicationVersion the applicationVersion to set - * @return this for fluent use - */ - public BrowserVersion setApplicationVersion(final String applicationVersion) { - applicationVersion_ = applicationVersion; - return this; - } - - /** - * @param vendor the vendor to set - * @return this for fluent use - */ - public BrowserVersion setVendor(final String vendor) { - vendor_ = vendor; - return this; - } - - /** - * @param browserLanguage the browserLanguage to set - * @return this for fluent use - */ - public BrowserVersion setBrowserLanguage(final String browserLanguage) { - browserLanguage_ = browserLanguage; - return this; - } - - /** - * @param cpuClass the cpuClass to set - * @return this for fluent use - */ - public BrowserVersion setCpuClass(final String cpuClass) { - cpuClass_ = cpuClass; - return this; - } - - /** - * @param onLine the onLine to set - * @return this for fluent use - */ - public BrowserVersion setOnLine(final boolean onLine) { - onLine_ = onLine; - return this; - } - - /** - * @param platform the platform to set - * @return this for fluent use - */ - public BrowserVersion setPlatform(final String platform) { - platform_ = platform; - return this; - } - - /** - * @param systemLanguage the systemLanguage to set - * @return this for fluent use - */ - public BrowserVersion setSystemLanguage(final String systemLanguage) { - systemLanguage_ = systemLanguage; - return this; - } - - /** - * @param systemTimezone the systemTimezone to set - * @return this for fluent use - */ - public BrowserVersion setSystemTimezone(final TimeZone systemTimezone) { - systemTimezone_ = systemTimezone; - return this; - } - - /** - * @param userAgent the userAgent to set - * @return this for fluent use - */ - public BrowserVersion setUserAgent(final String userAgent) { - userAgent_ = userAgent; - return this; - } - - /** - * @param userLanguage the userLanguage to set - * @return this for fluent use - */ - public BrowserVersion setUserLanguage(final String userLanguage) { - userLanguage_ = userLanguage; - return this; - } - - /** - * @param htmlAcceptHeader the {@code Accept} header to be used when retrieving pages - * @return this for fluent use - */ - public BrowserVersion setHtmlAcceptHeader(final String htmlAcceptHeader) { - htmlAcceptHeader_ = htmlAcceptHeader; - return this; - } - - /** - * @param imgAcceptHeader the {@code Accept} header to be used when retrieving images - * @return this for fluent use - */ - public BrowserVersion setImgAcceptHeader(final String imgAcceptHeader) { - imgAcceptHeader_ = imgAcceptHeader; - return this; - } - - /** - * @param cssAcceptHeader the {@code Accept} header to be used when retrieving pages - * @return this for fluent use - */ - public BrowserVersion setCssAcceptHeader(final String cssAcceptHeader) { - cssAcceptHeader_ = cssAcceptHeader; - return this; - } - - /** - * @param scriptAcceptHeader the {@code Accept} header to be used when retrieving scripts - * @return this for fluent use - */ - public BrowserVersion setScriptAcceptHeader(final String scriptAcceptHeader) { - scriptAcceptHeader_ = scriptAcceptHeader; - return this; - } - - /** - * @param xmlHttpRequestAcceptHeader the {@code Accept} header to be used when - * performing XMLHttpRequests - * @return this for fluent use - */ - public BrowserVersion setXmlHttpRequestAcceptHeader(final String xmlHttpRequestAcceptHeader) { - xmlHttpRequestAcceptHeader_ = xmlHttpRequestAcceptHeader; - return this; - } - - /** * Returns the available plugins. This makes only sense for Firefox as only this * browser makes this kind of information available via JavaScript. * @return the available plugins @@ -867,14 +697,6 @@ } /** - * Sets the headers names, so they are sent in the given order (if included in the request). - * @param headerNames the header names in ordered manner - */ - public void setHeaderNamesOrdered(final String[] headerNames) { - headerNamesOrdered_ = headerNames; - } - - /** * Registers a new mime type for the provided file extension. * @param fileExtension the file extension used to determine the mime type * @param mimeType the mime type to be used when uploading files with this extension @@ -910,43 +732,218 @@ } /** - * Creates and return a copy of this object. Current instance and cloned - * object can be modified independently. - * @return a clone of this instance. + * Because BrowserVersion is immutable we need a builder + * for this complex object setup. */ - @Override - public BrowserVersion clone() { - final BrowserVersion clone = new BrowserVersion(getBrowserVersionNumeric(), getNickname()); + public static class BrowserVersionBuilder { + private final BrowserVersion workPiece_; - clone.setApplicationVersion(getApplicationVersion()) - .setUserAgent(getUserAgent()) - .setApplicationName(getApplicationName()) - .setApplicationCodeName(getApplicationCodeName()) - .setApplicationMinorVersion(getApplicationMinorVersion()) - .setVendor(getVendor()) - .setBrowserLanguage(getBrowserLanguage()) - .setCpuClass(getCpuClass()) - .setOnLine(isOnLine()) - .setPlatform(getPlatform()) - .setSystemLanguage(getSystemLanguage()) - .setSystemTimezone(getSystemTimezone()) - .setUserLanguage(getUserLanguage()); + /** + * Creates a new BrowserVersionBuilder using the given browser version + * as template for the browser to be constructed. + * @param version the blueprint + */ + public BrowserVersionBuilder(final BrowserVersion version) { + workPiece_ = new BrowserVersion(version.getBrowserVersionNumeric(), version.getNickname()); - clone.buildId_ = getBuildId(); - clone.htmlAcceptHeader_ = getHtmlAcceptHeader(); - clone.imgAcceptHeader_ = getImgAcceptHeader(); - clone.cssAcceptHeader_ = getCssAcceptHeader(); - clone.scriptAcceptHeader_ = getScriptAcceptHeader(); - clone.xmlHttpRequestAcceptHeader_ = getXmlHttpRequestAcceptHeader(); - clone.headerNamesOrdered_ = getHeaderNamesOrdered(); + setApplicationVersion(version.getApplicationVersion()) + .setUserAgent(version.getUserAgent()) + .setApplicationName(version.getApplicationName()) + .setApplicationCodeName(version.getApplicationCodeName()) + .setApplicationMinorVersion(version.getApplicationMinorVersion()) + .setVendor(version.getVendor()) + .setBrowserLanguage(version.getBrowserLanguage()) + .setCpuClass(version.getCpuClass()) + .setOnLine(version.isOnLine()) + .setPlatform(version.getPlatform()) + .setSystemLanguage(version.getSystemLanguage()) + .setSystemTimezone(version.getSystemTimezone()) + .setUserLanguage(version.getUserLanguage()); - for (final PluginConfiguration pluginConf : getPlugins()) { - clone.getPlugins().add(pluginConf.clone()); + workPiece_.buildId_ = version.getBuildId(); + workPiece_.htmlAcceptHeader_ = version.getHtmlAcceptHeader(); + workPiece_.imgAcceptHeader_ = version.getImgAcceptHeader(); + workPiece_.cssAcceptHeader_ = version.getCssAcceptHeader(); + workPiece_.scriptAcceptHeader_ = version.getScriptAcceptHeader(); + workPiece_.xmlHttpRequestAcceptHeader_ = version.getXmlHttpRequestAcceptHeader(); + workPiece_.headerNamesOrdered_ = version.getHeaderNamesOrdered(); + + for (final PluginConfiguration pluginConf : version.getPlugins()) { + workPiece_.getPlugins().add(pluginConf.clone()); + } + + workPiece_.features_.addAll(version.features_); + workPiece_.uploadMimeTypes_.putAll(version.uploadMimeTypes_); } - clone.features_.addAll(features_); - clone.uploadMimeTypes_.putAll(uploadMimeTypes_); + /** + * @return the new immutable browser version + */ + public BrowserVersion build() { + return workPiece_; + } - return clone; + /** + * @param applicationMinorVersion the applicationMinorVersion to set + * @return this for fluent use + */ + public BrowserVersionBuilder setApplicationMinorVersion(final String applicationMinorVersion) { + workPiece_.applicationMinorVersion_ = applicationMinorVersion; + return this; + } + + /** + * @param applicationName the applicationName to set + * @return this for fluent use + */ + public BrowserVersionBuilder setApplicationName(final String applicationName) { + workPiece_.applicationName_ = applicationName; + return this; + } + + /** + * @param applicationVersion the applicationVersion to set + * @return this for fluent use + */ + public BrowserVersionBuilder setApplicationVersion(final String applicationVersion) { + workPiece_.applicationVersion_ = applicationVersion; + return this; + } + + /** + * @param vendor the vendor to set + * @return this for fluent use + */ + public BrowserVersionBuilder setVendor(final String vendor) { + workPiece_.vendor_ = vendor; + return this; + } + + /** + * @param applicationCodeName the applicationCodeName to set + * @return this for fluent use + */ + public BrowserVersionBuilder setApplicationCodeName(final String applicationCodeName) { + workPiece_.applicationCodeName_ = applicationCodeName; + return this; + } + + /** + * @param browserLanguage the browserLanguage to set + * @return this for fluent use + */ + public BrowserVersionBuilder setBrowserLanguage(final String browserLanguage) { + workPiece_.browserLanguage_ = browserLanguage; + return this; + } + + /** + * @param cpuClass the cpuClass to set + * @return this for fluent use + */ + public BrowserVersionBuilder setCpuClass(final String cpuClass) { + workPiece_.cpuClass_ = cpuClass; + return this; + } + + /** + * @param onLine the onLine to set + * @return this for fluent use + */ + public BrowserVersionBuilder setOnLine(final boolean onLine) { + workPiece_.onLine_ = onLine; + return this; + } + + /** + * @param platform the platform to set + * @return this for fluent use + */ + public BrowserVersionBuilder setPlatform(final String platform) { + workPiece_.platform_ = platform; + return this; + } + + /** + * @param systemLanguage the systemLanguage to set + * @return this for fluent use + */ + public BrowserVersionBuilder setSystemLanguage(final String systemLanguage) { + workPiece_.systemLanguage_ = systemLanguage; + return this; + } + + /** + * @param systemTimezone the systemTimezone to set + * @return this for fluent use + */ + public BrowserVersionBuilder setSystemTimezone(final TimeZone systemTimezone) { + workPiece_.systemTimezone_ = systemTimezone; + return this; + } + + /** + * @param userAgent the userAgent to set + * @return this for fluent use + */ + public BrowserVersionBuilder setUserAgent(final String userAgent) { + workPiece_.userAgent_ = userAgent; + return this; + } + + /** + * @param userLanguage the userLanguage to set + * @return this for fluent use + */ + public BrowserVersionBuilder setUserLanguage(final String userLanguage) { + workPiece_.userLanguage_ = userLanguage; + return this; + } + + /** + * @param htmlAcceptHeader the {@code Accept} header to be used when retrieving pages + * @return this for fluent use + */ + public BrowserVersionBuilder setHtmlAcceptHeader(final String htmlAcceptHeader) { + workPiece_.htmlAcceptHeader_ = htmlAcceptHeader; + return this; + } + + /** + * @param imgAcceptHeader the {@code Accept} header to be used when retrieving images + * @return this for fluent use + */ + public BrowserVersionBuilder setImgAcceptHeader(final String imgAcceptHeader) { + workPiece_.imgAcceptHeader_ = imgAcceptHeader; + return this; + } + + /** + * @param cssAcceptHeader the {@code Accept} header to be used when retrieving pages + * @return this for fluent use + */ + public BrowserVersionBuilder setCssAcceptHeader(final String cssAcceptHeader) { + workPiece_.cssAcceptHeader_ = cssAcceptHeader; + return this; + } + + /** + * @param scriptAcceptHeader the {@code Accept} header to be used when retrieving scripts + * @return this for fluent use + */ + public BrowserVersionBuilder setScriptAcceptHeader(final String scriptAcceptHeader) { + workPiece_.scriptAcceptHeader_ = scriptAcceptHeader; + return this; + } + + /** + * @param xmlHttpRequestAcceptHeader the {@code Accept} header to be used when + * performing XMLHttpRequests + * @return this for fluent use + */ + public BrowserVersionBuilder setXmlHttpRequestAcceptHeader(final String xmlHttpRequestAcceptHeader) { + workPiece_.xmlHttpRequestAcceptHeader_ = xmlHttpRequestAcceptHeader; + return this; + } } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersionTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersionTest.java 2017-07-26 13:01:33 UTC (rev 14710) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersionTest.java 2017-07-26 13:02:50 UTC (rev 14711) @@ -44,7 +44,7 @@ @Test public void testClone() { final BrowserVersion ff = BrowserVersion.FIREFOX_52; - final BrowserVersion clone = ff.clone(); + final BrowserVersion clone = new BrowserVersion.BrowserVersionBuilder(ff).build(); // Nickname is used as key for dictionaries storing browser setups assertTrue(ff.getNickname().equals(clone.getNickname())); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/HtmlUnitContextFactoryTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/HtmlUnitContextFactoryTest.java 2017-07-26 13:01:33 UTC (rev 14710) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/HtmlUnitContextFactoryTest.java 2017-07-26 13:02:50 UTC (rev 14711) @@ -37,10 +37,11 @@ final String html = "<html></html>"; final BrowserVersion browserVersion - = BrowserVersion.FIREFOX_52.clone() + = new BrowserVersion.BrowserVersionBuilder(BrowserVersion.FIREFOX_52) .setApplicationName("Firefox") .setApplicationVersion("5.0 (Windows NT 10.0; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0") - .setUserAgent("Mozilla/5.0 (Windows NT 10.0; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0"); + .setUserAgent("Mozilla/5.0 (Windows NT 10.0; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0") + .build(); loadPage(browserVersion, html, null, URL_FIRST); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngineTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngineTest.java 2017-07-26 13:01:33 UTC (rev 14710) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngineTest.java 2017-07-26 13:02:50 UTC (rev 14711) @@ -1294,9 +1294,10 @@ */ @Test public void nonStandardBrowserVersion() throws Exception { - final BrowserVersion browser = BrowserVersion.INTERNET_EXPLORER.clone() + final BrowserVersion browser = new BrowserVersion.BrowserVersionBuilder(BrowserVersion.INTERNET_EXPLORER) .setApplicationName("Mozilla") - .setApplicationVersion("5.0"); + .setApplicationVersion("5.0") + .build(); try (WebClient client = new WebClient(browser)) { client.openWindow(WebClient.URL_ABOUT_BLANK, "TestWindow"); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfigurationTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfigurationTest.java 2017-07-26 13:01:33 UTC (rev 14710) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfigurationTest.java 2017-07-26 13:02:50 UTC (rev 14711) @@ -77,16 +77,18 @@ leakyMap.clear(); final int knownBrowsers = leakyMap.size(); - BrowserVersion browserVersion = BrowserVersion.FIREFOX_52.clone() + BrowserVersion browserVersion = new BrowserVersion.BrowserVersionBuilder(BrowserVersion.FIREFOX_52) .setApplicationVersion("App") .setApplicationVersion("Version") - .setUserAgent("User agent"); + .setUserAgent("User agent") + .build(); JavaScriptConfiguration.getInstance(browserVersion); - browserVersion = BrowserVersion.FIREFOX_52.clone() + browserVersion = new BrowserVersion.BrowserVersionBuilder(BrowserVersion.FIREFOX_52) .setApplicationVersion("App2") .setApplicationVersion("Version2") - .setUserAgent("User agent2"); + .setUserAgent("User agent2") + .build(); JavaScriptConfiguration.getInstance(browserVersion); assertEquals(knownBrowsers + 1, leakyMap.size()); @@ -103,10 +105,11 @@ long count = 0; while (count++ < 3000) { - final BrowserVersion browserVersion = BrowserVersion.FIREFOX_52.clone() + final BrowserVersion browserVersion = new BrowserVersion.BrowserVersionBuilder(BrowserVersion.FIREFOX_52) .setApplicationVersion("App" + generator.generate(20)) .setApplicationVersion("Version" + generator.generate(20)) - .setUserAgent("User Agent" + generator.generate(20)); + .setUserAgent("User Agent" + generator.generate(20)) + .build(); JavaScriptConfiguration.getInstance(browserVersion); if (LOG.isInfoEnabled()) { LOG.info("count: " + count + "; memory stats: " + getMemoryStats()); @@ -310,7 +313,8 @@ */ @Test public void cloned() throws Exception { - final BrowserVersion browserVersion = BrowserVersion.FIREFOX_45.clone(); + final BrowserVersion browserVersion = new BrowserVersion.BrowserVersionBuilder(BrowserVersion.FIREFOX_45) + .build(); test(browserVersion); } @@ -322,8 +326,9 @@ */ @Test public void clonedAndModified() throws Exception { - final BrowserVersion browserVersion = BrowserVersion.FIREFOX_45.clone(); - browserVersion.setUserAgent("foo"); + final BrowserVersion browserVersion = new BrowserVersion.BrowserVersionBuilder(BrowserVersion.FIREFOX_45) + .setUserAgent("foo") + .build(); test(browserVersion); } |
From: <rb...@us...> - 2017-07-26 13:09:50
|
Revision: 14714 http://sourceforge.net/p/htmlunit/code/14714 Author: rbri Date: 2017-07-26 13:09:47 +0000 (Wed, 26 Jul 2017) Log Message: ----------- latest Chrome (wip) Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLUnknownElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementOuterHtmlTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2017-07-26 13:06:43 UTC (rev 14713) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2017-07-26 13:09:47 UTC (rev 14714) @@ -456,10 +456,6 @@ @BrowserFeature(CHROME) HTMLLINK_CHECK_TYPE_FOR_STYLESHEET, - /** No end tag for menu item. */ - @BrowserFeature(CHROME) - HTMLMENUITEM_END_TAG_FORBIDDEN, - /** */ @BrowserFeature({FF, IE}) HTMLOPTION_EMPTY_TEXT_IS_NO_CHILDREN, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLUnknownElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLUnknownElement.java 2017-07-26 13:06:43 UTC (rev 14713) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLUnknownElement.java 2017-07-26 13:09:47 UTC (rev 14714) @@ -14,7 +14,6 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.html; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLMENUITEM_END_TAG_FORBIDDEN; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_HTML_HYPHEN_ELEMENT_CLASS_NAME; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_HTML_RUBY_ELEMENT_CLASS_NAME; import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.CHROME; @@ -101,9 +100,7 @@ */ @Override protected boolean isEndTagForbidden() { - if ("BGSOUND".equals(getNodeName()) - || (getBrowserVersion().hasFeature(HTMLMENUITEM_END_TAG_FORBIDDEN) - && "MENUITEM".equals(getNodeName()))) { + if ("BGSOUND".equals(getNodeName())) { return true; } return super.isEndTagForbidden(); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementOuterHtmlTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementOuterHtmlTest.java 2017-07-26 13:06:43 UTC (rev 14713) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/ElementOuterHtmlTest.java 2017-07-26 13:09:47 UTC (rev 14714) @@ -791,8 +791,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "<menuitem></menuitem>", - CHROME = "<menuitem>") + @Alerts("<menuitem></menuitem>") public void menuitem() throws Exception { loadPageWithAlerts2(test("menuitem")); } |
From: <rb...@us...> - 2017-07-26 13:21:51
|
Revision: 14715 http://sourceforge.net/p/htmlunit/code/14715 Author: rbri Date: 2017-07-26 13:21:48 +0000 (Wed, 26 Jul 2017) Log Message: ----------- latest Chrome (wip) Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/InputEvent.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/HostClassNameTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/InputEvent.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/InputEvent.java 2017-07-26 13:09:47 UTC (rev 14714) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/InputEvent.java 2017-07-26 13:21:48 UTC (rev 14715) @@ -14,6 +14,7 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.event; +import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.CHROME; import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.FF; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; @@ -24,7 +25,7 @@ * * @author Ahmed Ashour */ -@JsxClass(FF) +@JsxClass({FF, CHROME}) public class InputEvent extends UIEvent { /** Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/HostClassNameTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/HostClassNameTest.java 2017-07-26 13:09:47 UTC (rev 14714) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/general/HostClassNameTest.java 2017-07-26 13:21:48 UTC (rev 14715) @@ -6921,6 +6921,7 @@ */ @Test @Alerts(DEFAULT = "exception", + CHROME = "function InputEvent() { [native code] }", FF = "function InputEvent() {\n [native code]\n}") public void inputEvent() throws Exception { test("InputEvent"); @@ -10250,7 +10251,8 @@ * @throws Exception if the test fails */ @Test - @Alerts("exception") + @Alerts(DEFAULT = "exception", + CHROME = "function SharedArrayBuffer() { [native code] }") public void sharedArrayBuffer() throws Exception { test("SharedArrayBuffer"); } @@ -10278,7 +10280,8 @@ * @throws Exception if the test fails */ @Test - @Alerts("exception") + @Alerts(DEFAULT = "exception", + CHROME = "[object Atomics]") public void atomics() throws Exception { test("Atomics"); } @@ -10709,8 +10712,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "exception", - CHROME = "function SiteBoundCredential() { [native code] }") + @Alerts("exception") public void siteBoundCredential() throws Exception { test("SiteBoundCredential"); } @@ -10831,7 +10833,8 @@ * @throws Exception if the test fails */ @Test - @Alerts("exception") + @Alerts(DEFAULT = "exception", + CHROME = "function BudgetService() { [native code] }") public void budgetService() throws Exception { test("BudgetService"); } @@ -10840,7 +10843,8 @@ * @throws Exception if the test fails */ @Test - @Alerts("exception") + @Alerts(DEFAULT = "exception", + CHROME = "function PaymentResponse() { [native code] }") public void paymentResponse() throws Exception { test("PaymentResponse"); } @@ -11144,7 +11148,8 @@ * @throws Exception if the test fails */ @Test - @Alerts("exception") + @Alerts(DEFAULT = "exception", + CHROME = "function PaymentAddress() { [native code] }") public void paymentAddress() throws Exception { test("PaymentAddress"); } @@ -11171,7 +11176,8 @@ * @throws Exception if the test fails */ @Test - @Alerts("exception") + @Alerts(DEFAULT = "exception", + CHROME = "function PaymentRequest() { [native code] }") public void paymentRequest() throws Exception { test("PaymentRequest"); } |
From: <rb...@us...> - 2017-07-28 10:12:37
|
Revision: 14733 http://sourceforge.net/p/htmlunit/code/14733 Author: rbri Date: 2017-07-28 10:12:34 +0000 (Fri, 28 Jul 2017) Log Message: ----------- latest Chrome - bring our impl in sync (wip) Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMTokenList.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMTokenListTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMTokenList.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMTokenList.java 2017-07-28 08:31:46 UTC (rev 14732) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMTokenList.java 2017-07-28 10:12:34 UTC (rev 14733) @@ -136,6 +136,10 @@ value = value + token; updateAttribute(value); } + else if (getBrowserVersion().hasFeature(JS_DOMTOKENLIST_REMOVE_WHITESPACE_CHARS_ON_REMOVE)) { + value = String.join(" ", StringUtils.split(value, whitespaceChars())); + updateAttribute(value); + } } /** Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMTokenListTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMTokenListTest.java 2017-07-28 08:31:46 UTC (rev 14732) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMTokenListTest.java 2017-07-28 10:12:34 UTC (rev 14733) @@ -14,6 +14,7 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.dom; +import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.CHROME; import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.FF52; import org.junit.Test; @@ -693,7 +694,7 @@ @Alerts(DEFAULT = {" \t \n ", "0", "0", " \t \n "}, CHROME = {" \t \n ", "0", "0", ""}, FF52 = {" \t \n ", "0", "0", ""}) - @NotYetImplemented(FF52) + @NotYetImplemented({CHROME, FF52}) public void removeFromWhitespace() throws Exception { remove(" \t \r ", "a"); } |
From: <rb...@us...> - 2017-07-30 14:20:38
|
Revision: 14744 http://sourceforge.net/p/htmlunit/code/14744 Author: rbri Date: 2017-07-30 14:20:35 +0000 (Sun, 30 Jul 2017) Log Message: ----------- more fixes Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMTokenList.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMTokenListTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2017-07-30 13:24:03 UTC (rev 14743) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2017-07-30 14:20:35 UTC (rev 14744) @@ -852,8 +852,12 @@ @BrowserFeature({CHROME, IE}) JS_DOMTOKENLIST_REMOVE_WHITESPACE_CHARS_ON_EDIT, + /** DOMTokenList removed all whitespace chars during add. */ + @BrowserFeature(CHROME) + JS_DOMTOKENLIST_REMOVE_WHITESPACE_CHARS_ON_ADD, + /** DOMTokenList removed all whitespace chars during remove. */ - @BrowserFeature(CHROME) + @BrowserFeature({CHROME, FF52}) JS_DOMTOKENLIST_REMOVE_WHITESPACE_CHARS_ON_REMOVE, /** Javascript property function {@code delete} throws an exception if the given count is negative. */ Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMTokenList.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMTokenList.java 2017-07-30 13:24:03 UTC (rev 14743) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMTokenList.java 2017-07-30 14:20:35 UTC (rev 14744) @@ -18,6 +18,7 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_DOMTOKENLIST_ENHANCED_WHITESPACE_CHARS; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_DOMTOKENLIST_GET_NULL_IF_OUTSIDE; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_DOMTOKENLIST_LENGTH_IGNORES_DUPLICATES; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_DOMTOKENLIST_REMOVE_WHITESPACE_CHARS_ON_ADD; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_DOMTOKENLIST_REMOVE_WHITESPACE_CHARS_ON_EDIT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_DOMTOKENLIST_REMOVE_WHITESPACE_CHARS_ON_REMOVE; import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.CHROME; @@ -129,15 +130,20 @@ } String value = getDefaultValue(null); + boolean changed = false; if (position(value, token) < 0) { if (value.length() != 0 && !isWhitespache(value.charAt(value.length() - 1))) { value = value + " "; } value = value + token; - updateAttribute(value); + changed = true; } - else if (getBrowserVersion().hasFeature(JS_DOMTOKENLIST_REMOVE_WHITESPACE_CHARS_ON_REMOVE)) { + else if (getBrowserVersion().hasFeature(JS_DOMTOKENLIST_REMOVE_WHITESPACE_CHARS_ON_ADD)) { value = String.join(" ", StringUtils.split(value, whitespaceChars())); + changed = true; + } + + if (changed) { updateAttribute(value); } } @@ -156,6 +162,7 @@ } String value = getDefaultValue(null); + boolean changed = false; int pos = position(value, token); while (pos != -1) { int from = pos; @@ -176,16 +183,20 @@ } } result.append(value, to, value.length()); - value = result.toString(); + changed = true; - if (getBrowserVersion().hasFeature(JS_DOMTOKENLIST_REMOVE_WHITESPACE_CHARS_ON_REMOVE)) { - value = String.join(" ", StringUtils.split(value, whitespaceChars())); - } - updateAttribute(value); - pos = position(value, token); } + + if (getBrowserVersion().hasFeature(JS_DOMTOKENLIST_REMOVE_WHITESPACE_CHARS_ON_REMOVE)) { + value = String.join(" ", StringUtils.split(value, whitespaceChars())); + changed = true; + } + + if (changed) { + updateAttribute(value); + } } /** Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMTokenListTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMTokenListTest.java 2017-07-30 13:24:03 UTC (rev 14743) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/dom/DOMTokenListTest.java 2017-07-30 14:20:35 UTC (rev 14744) @@ -14,15 +14,11 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.dom; -import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.CHROME; -import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.FF52; - import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; -import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.WebDriverTestCase; /** @@ -694,7 +690,6 @@ @Alerts(DEFAULT = {" \t \n ", "0", "0", " \t \n "}, CHROME = {" \t \n ", "0", "0", ""}, FF52 = {" \t \n ", "0", "0", ""}) - @NotYetImplemented({CHROME, FF52}) public void removeFromWhitespace() throws Exception { remove(" \t \r ", "a"); } @@ -753,7 +748,6 @@ @Test @Alerts(DEFAULT = {"a \t c \n d e", "4", "3", "a d e"}, FF45 = {"a \t c \n d e", "4", "3", "a d e"}) - @NotYetImplemented(FF52) public void removeWhitespace() throws Exception { remove("a \t c \n d e", "c"); } |
From: <rb...@us...> - 2017-08-01 08:51:24
|
Revision: 14746 http://sourceforge.net/p/htmlunit/code/14746 Author: rbri Date: 2017-08-01 08:51:21 +0000 (Tue, 01 Aug 2017) Log Message: ----------- fix most IE cases regarding encoding of external js Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebResponse.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlScript3Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2017-07-31 15:53:36 UTC (rev 14745) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2017-08-01 08:51:21 UTC (rev 14746) @@ -848,14 +848,14 @@ @BrowserFeature(CHROME) JS_DOMTOKENLIST_LENGTH_IGNORES_DUPLICATES, + /** DOMTokenList removed all whitespace chars during add. */ + @BrowserFeature(CHROME) + JS_DOMTOKENLIST_REMOVE_WHITESPACE_CHARS_ON_ADD, + /** DOMTokenList removed all whitespace chars during edit. */ @BrowserFeature({CHROME, IE}) JS_DOMTOKENLIST_REMOVE_WHITESPACE_CHARS_ON_EDIT, - /** DOMTokenList removed all whitespace chars during add. */ - @BrowserFeature(CHROME) - JS_DOMTOKENLIST_REMOVE_WHITESPACE_CHARS_ON_ADD, - /** DOMTokenList removed all whitespace chars during remove. */ @BrowserFeature({CHROME, FF52}) JS_DOMTOKENLIST_REMOVE_WHITESPACE_CHARS_ON_REMOVE, @@ -945,6 +945,10 @@ @BrowserFeature(IE) JS_IGNORES_LAST_LINE_CONTAINING_UNCOMMENTED, + /** Ignore the UTF8 BOM header when loading external js in some situations. */ + @BrowserFeature(IE) + JS_IGNORES_UTF8_BOM_SOMETIMES, + /** * The complete property returns also true, if the image download was failing * or if there was no src at all. Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebResponse.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebResponse.java 2017-07-31 15:53:36 UTC (rev 14745) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebResponse.java 2017-08-01 08:51:21 UTC (rev 14746) @@ -208,6 +208,20 @@ * @return the response content as a string or null if the content retrieval was failing */ public String getContentAsString(final Charset encoding) { + return getContentAsString(encoding, false); + } + + /** + * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br> + * + * Returns the response content as a string, using the specified charset, + * rather than the charset/encoding specified in the server response. + * If there is a bom header the charset parameter will be overwritten by the bom. + * @param encoding the charset/encoding to use to convert the response content into a string + * @param ignoreUtf8Bom if true utf8 bom header will be ignored + * @return the response content as a string or null if the content retrieval was failing + */ + public String getContentAsString(final Charset encoding, final boolean ignoreUtf8Bom) { if (responseData_ != null) { try (InputStream in = responseData_.getInputStream()) { if (in != null) { @@ -215,7 +229,7 @@ // there seems to be a bug in BOMInputStream // we have to call this before hasBOM(ByteOrderMark) if (bomIn.hasBOM()) { - if (bomIn.hasBOM(ByteOrderMark.UTF_8)) { + if (!ignoreUtf8Bom && bomIn.hasBOM(ByteOrderMark.UTF_8)) { return IOUtils.toString(bomIn, StandardCharsets.UTF_8); } if (bomIn.hasBOM(ByteOrderMark.UTF_16BE)) { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2017-07-31 15:53:36 UTC (rev 14745) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java 2017-08-01 08:51:21 UTC (rev 14746) @@ -19,6 +19,7 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.FOCUS_BODY_ELEMENT_AT_START; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_CALL_RESULT_IS_LAST_RETURN_VALUE; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_DEFERRED; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_IGNORES_UTF8_BOM_SOMETIMES; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.PAGE_SELECTION_RANGE_FROM_SELECTABLE_TEXT_INPUT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.URL_MISSING_SLASHES; import static java.nio.charset.StandardCharsets.ISO_8859_1; @@ -1070,18 +1071,29 @@ } Charset scriptEncoding = Charset.forName("windows-1252"); + boolean ignoreBom = false; final Charset contentCharset = EncodingSniffer.sniffEncodingFromHttpHeaders(response.getResponseHeaders()); if (contentCharset == null) { // use info from script tag or fall back to utf-8 - if (scriptCharset != null && scriptCharset != ISO_8859_1) { + if (scriptCharset != null && ISO_8859_1 != scriptCharset) { + ignoreBom = true; scriptEncoding = scriptCharset; } + else { + ignoreBom = ISO_8859_1 != scriptCharset; + } } - else if (contentCharset != ISO_8859_1) { + else if (ISO_8859_1 != contentCharset) { + ignoreBom = true; scriptEncoding = contentCharset; } + else { + ignoreBom = true; + } - final String scriptCode = response.getContentAsString(scriptEncoding); + final String scriptCode = response.getContentAsString(scriptEncoding, + ignoreBom + && getWebClient().getBrowserVersion().hasFeature(JS_IGNORES_UTF8_BOM_SOMETIMES)); if (null != scriptCode) { final AbstractJavaScriptEngine<?> javaScriptEngine = client.getJavaScriptEngine(); final Object script = javaScriptEngine.compile(this, scriptCode, url.toExternalForm(), 1); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlScript3Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlScript3Test.java 2017-07-31 15:53:36 UTC (rev 14745) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlScript3Test.java 2017-08-01 08:51:21 UTC (rev 14746) @@ -287,7 +287,6 @@ @Test @Alerts(DEFAULT = {"a", "ä", "أهلاً", "мир", "房间"}, IE = {"a", "ä", "أهلاً", "мир", "房间"}) - @NotYetImplemented(IE) public void _ISO88591__ISO88591__BOMUTF8() throws Exception { charset(TestCharset.ISO88591, null, TestCharset.ISO88591, null, BOM_UTF_8); } @@ -307,7 +306,6 @@ @Test @Alerts(DEFAULT = {"a", "ä", "أهلاً", "мир", "房间"}, IE = {"a", "ä", "أهلاً", "мир", "房间"}) - @NotYetImplemented(IE) public void _ISO88591__ISO88591_UTF8_BOMUTF8() throws Exception { charset(TestCharset.ISO88591, null, TestCharset.ISO88591, TestCharset.UTF8, BOM_UTF_8); } @@ -390,7 +388,6 @@ @Test @Alerts(DEFAULT = {"a", "ä", "أهلاً", "мир", "房间"}, IE = {"a", "ä", "أهلاً", "мир", "房间"}) - @NotYetImplemented(IE) public void _ISO88591_UTF8_ISO88591__BOMUTF8() throws Exception { charset(TestCharset.ISO88591, TestCharset.UTF8, TestCharset.ISO88591, null, BOM_UTF_8); } @@ -410,7 +407,6 @@ @Test @Alerts(DEFAULT = {"a", "ä", "أهلاً", "мир", "房间"}, IE = {"a", "ä", "أهلاً", "мир", "房间"}) - @NotYetImplemented(IE) public void _ISO88591_UTF8_ISO88591_UTF8_BOMUTF8() throws Exception { charset(TestCharset.ISO88591, TestCharset.UTF8, TestCharset.ISO88591, TestCharset.UTF8, BOM_UTF_8); } @@ -520,7 +516,6 @@ @Test @Alerts(DEFAULT = {"a", "ä", "أهلاً", "мир", "房间"}, IE = {"a", "ä", "أهلاً", "мир", "房间"}) - @NotYetImplemented(IE) public void _ISO88591_ISO88591_ISO88591__BOMUTF8() throws Exception { charset(TestCharset.ISO88591, TestCharset.ISO88591, TestCharset.ISO88591, null, BOM_UTF_8); } @@ -540,7 +535,6 @@ @Test @Alerts(DEFAULT = {"a", "ä", "أهلاً", "мир", "房间"}, IE = {"a", "ä", "أهلاً", "мир", "房间"}) - @NotYetImplemented(IE) public void _ISO88591_ISO88591_ISO88591_UTF8_BOMUTF8() throws Exception { charset(TestCharset.ISO88591, TestCharset.ISO88591, TestCharset.ISO88591, TestCharset.UTF8, BOM_UTF_8); } @@ -740,7 +734,6 @@ @Test @Alerts(DEFAULT = {"a", "ä", "أهلاً", "мир", "房间"}, IE = {"a", "ä", "أهلاً", "мир", "房间"}) - @NotYetImplemented(IE) public void _UTF8_ISO88591_ISO88591_UTF8_BOMUTF8() throws Exception { charset(TestCharset.UTF8, TestCharset.ISO88591, TestCharset.ISO88591, TestCharset.UTF8, BOM_UTF_8); } @@ -751,7 +744,6 @@ @Test @Alerts(DEFAULT = {"a", "ä", "أهلاً", "мир", "房间"}, IE = {"a", "ä", "أهلاً", "мир", "房间"}) - @NotYetImplemented(IE) public void _UTF8_ISO88591_ISO88591__BOMUTF8() throws Exception { charset(TestCharset.UTF8, TestCharset.ISO88591, TestCharset.ISO88591, null, BOM_UTF_8); } @@ -762,7 +754,6 @@ @Test @Alerts(DEFAULT = {"a", "ä", "أهلاً", "мир", "房间"}, IE = {"a", "ä", "أهلاً", "мир", "房间"}) - @NotYetImplemented(IE) public void _UTF8_UTF8_ISO88591_UTF8_BOMUTF8() throws Exception { charset(TestCharset.UTF8, TestCharset.UTF8, TestCharset.ISO88591, TestCharset.UTF8, BOM_UTF_8); } @@ -773,7 +764,6 @@ @Test @Alerts(DEFAULT = {"a", "ä", "أهلاً", "мир", "房间"}, IE = {"a", "ä", "أهلاً", "мир", "房间"}) - @NotYetImplemented(IE) public void _UTF8_UTF8_ISO88591__BOMUTF8() throws Exception { charset(TestCharset.UTF8, TestCharset.UTF8, TestCharset.ISO88591, null, BOM_UTF_8); } @@ -784,7 +774,6 @@ @Test @Alerts(DEFAULT = {"a", "ä", "أهلاً", "мир", "房间"}, IE = {"a", "ä", "أهلاً", "мир", "房间"}) - @NotYetImplemented(IE) public void _UTF8__ISO88591_UTF8_BOMUTF8() throws Exception { charset(TestCharset.UTF8, null, TestCharset.ISO88591, TestCharset.UTF8, BOM_UTF_8); } @@ -795,7 +784,6 @@ @Test @Alerts(DEFAULT = {"a", "ä", "أهلاً", "мир", "房间"}, IE = {"a", "ä", "أهلاً", "мир", "房间"}) - @NotYetImplemented(IE) public void _UTF8__ISO88591__BOMUTF8() throws Exception { charset(TestCharset.UTF8, null, TestCharset.ISO88591, null, BOM_UTF_8); } @@ -977,7 +965,6 @@ @Test @Alerts(DEFAULT = {"a", "ä", "أهلاً", "мир", "房间"}, IE = {"a", "ä", "أهلاً", "мир", "房间"}) - @NotYetImplemented(IE) public void __ISO88591_ISO88591_UTF8_BOMUTF8() throws Exception { charset(null, TestCharset.ISO88591, TestCharset.ISO88591, TestCharset.UTF8, BOM_UTF_8); } @@ -988,7 +975,6 @@ @Test @Alerts(DEFAULT = {"a", "ä", "أهلاً", "мир", "房间"}, IE = {"a", "ä", "أهلاً", "мир", "房间"}) - @NotYetImplemented(IE) public void __ISO88591_ISO88591__BOMUTF8() throws Exception { charset(null, TestCharset.ISO88591, TestCharset.ISO88591, null, BOM_UTF_8); } @@ -999,7 +985,6 @@ @Test @Alerts(DEFAULT = {"a", "ä", "أهلاً", "мир", "房间"}, IE = {"a", "ä", "أهلاً", "мир", "房间"}) - @NotYetImplemented(IE) public void __UTF8_ISO88591_UTF8_BOMUTF8() throws Exception { charset(null, TestCharset.UTF8, TestCharset.ISO88591, TestCharset.UTF8, BOM_UTF_8); } @@ -1010,7 +995,6 @@ @Test @Alerts(DEFAULT = {"a", "ä", "أهلاً", "мир", "房间"}, IE = {"a", "ä", "أهلاً", "мир", "房间"}) - @NotYetImplemented(IE) public void __UTF8_ISO88591__BOMUTF8() throws Exception { charset(null, TestCharset.UTF8, TestCharset.ISO88591, null, BOM_UTF_8); } @@ -1021,7 +1005,6 @@ @Test @Alerts(DEFAULT = {"a", "ä", "أهلاً", "мир", "房间"}, IE = {"a", "ä", "أهلاً", "мир", "房间"}) - @NotYetImplemented(IE) public void ___ISO88591_UTF8_BOMUTF8() throws Exception { charset(null, null, TestCharset.ISO88591, TestCharset.UTF8, BOM_UTF_8); } @@ -1032,7 +1015,6 @@ @Test @Alerts(DEFAULT = {"a", "ä", "أهلاً", "мир", "房间"}, IE = {"a", "ä", "أهلاً", "мир", "房间"}) - @NotYetImplemented(IE) public void ___ISO88591__BOMUTF8() throws Exception { charset(null, null, TestCharset.ISO88591, null, BOM_UTF_8); } @@ -1216,7 +1198,6 @@ @Test @Alerts(DEFAULT = {"a", "ä", "أهلاً", "мир", "房间"}, IE = {"a", "ä", "أهلاً", "мир", "房间"}) - @NotYetImplemented(IE) public void _GB2312_ISO88591_ISO88591_UTF8_BOMUTF8() throws Exception { charset(TestCharset.GB2312, TestCharset.ISO88591, TestCharset.ISO88591, TestCharset.UTF8, BOM_UTF_8); } @@ -1227,7 +1208,6 @@ @Test @Alerts(DEFAULT = {"a", "ä", "أهلاً", "мир", "房间"}, IE = {"a", "ä", "أهلاً", "мир", "房间"}) - @NotYetImplemented(IE) public void _GB2312_ISO88591_ISO88591__BOMUTF8() throws Exception { charset(TestCharset.GB2312, TestCharset.ISO88591, TestCharset.ISO88591, null, BOM_UTF_8); } @@ -1238,7 +1218,6 @@ @Test @Alerts(DEFAULT = {"a", "ä", "أهلاً", "мир", "房间"}, IE = {"a", "ä", "أهلاً", "мир", "房间"}) - @NotYetImplemented(IE) public void _GB2312_UTF8_ISO88591_UTF8_BOMUTF8() throws Exception { charset(TestCharset.GB2312, TestCharset.UTF8, TestCharset.ISO88591, TestCharset.UTF8, BOM_UTF_8); } @@ -1249,7 +1228,6 @@ @Test @Alerts(DEFAULT = {"a", "ä", "أهلاً", "мир", "房间"}, IE = {"a", "ä", "أهلاً", "мир", "房间"}) - @NotYetImplemented(IE) public void _GB2312_UTF8_ISO88591__BOMUTF8() throws Exception { charset(TestCharset.GB2312, TestCharset.UTF8, TestCharset.ISO88591, null, BOM_UTF_8); } @@ -1260,7 +1238,6 @@ @Test @Alerts(DEFAULT = {"a", "ä", "أهلاً", "мир", "房间"}, IE = {"a", "ä", "أهلاً", "мир", "房间"}) - @NotYetImplemented(IE) public void _GB2312__ISO88591_UTF8_BOMUTF8() throws Exception { charset(TestCharset.GB2312, null, TestCharset.ISO88591, TestCharset.UTF8, BOM_UTF_8); } @@ -1271,7 +1248,6 @@ @Test @Alerts(DEFAULT = {"a", "ä", "أهلاً", "мир", "房间"}, IE = {"a", "ä", "أهلاً", "мир", "房间"}) - @NotYetImplemented(IE) public void _GB2312__ISO88591__BOMUTF8() throws Exception { charset(TestCharset.GB2312, null, TestCharset.ISO88591, null, BOM_UTF_8); } @@ -1282,7 +1258,6 @@ @Test @Alerts(DEFAULT = {"a", "ä", "أهلاً", "мир", "房间"}, IE = {"a", "ä", "أهلاً", "мир", "房间"}) - @NotYetImplemented(IE) public void _GB2312_ISO88591_ISO88591_ISO88591_BOMUTF8() throws Exception { charset(TestCharset.GB2312, TestCharset.ISO88591, TestCharset.ISO88591, TestCharset.ISO88591, BOM_UTF_8); } @@ -1293,7 +1268,6 @@ @Test @Alerts(DEFAULT = {"a", "ä", "أهلاً", "мир", "房间"}, IE = {"a", "ä", "أهلاً", "мир", "房间"}) - @NotYetImplemented(IE) public void _GB2312_UTF8_ISO88591_ISO88591_BOMUTF8() throws Exception { charset(TestCharset.GB2312, TestCharset.UTF8, TestCharset.ISO88591, TestCharset.ISO88591, BOM_UTF_8); } @@ -1304,7 +1278,6 @@ @Test @Alerts(DEFAULT = {"a", "ä", "أهلاً", "мир", "房间"}, IE = {"a", "ä", "أهلاً", "мир", "房间"}) - @NotYetImplemented(IE) public void _GB2312__ISO88591_ISO88591_BOMUTF8() throws Exception { charset(TestCharset.GB2312, null, TestCharset.ISO88591, TestCharset.ISO88591, BOM_UTF_8); } @@ -1315,7 +1288,6 @@ @Test @Alerts(DEFAULT = {"a", "ä", "أهلاً", "мир", "房间"}, IE = {"a", "ä", "أهلاً", "мир", "房间"}) - @NotYetImplemented(IE) public void _ISO88591_ISO88591_ISO88591_ISO88591_BOMUTF8() throws Exception { charset(TestCharset.ISO88591, TestCharset.ISO88591, TestCharset.ISO88591, TestCharset.ISO88591, BOM_UTF_8); } @@ -1326,7 +1298,6 @@ @Test @Alerts(DEFAULT = {"a", "ä", "أهلاً", "мир", "房间"}, IE = {"a", "ä", "أهلاً", "мир", "房间"}) - @NotYetImplemented(IE) public void _ISO88591_UTF8_ISO88591_ISO88591_BOMUTF8() throws Exception { charset(TestCharset.ISO88591, TestCharset.UTF8, TestCharset.ISO88591, TestCharset.ISO88591, BOM_UTF_8); } @@ -1337,7 +1308,6 @@ @Test @Alerts(DEFAULT = {"a", "ä", "أهلاً", "мир", "房间"}, IE = {"a", "ä", "أهلاً", "мир", "房间"}) - @NotYetImplemented(IE) public void _ISO88591__ISO88591_ISO88591_BOMUTF8() throws Exception { charset(TestCharset.ISO88591, null, TestCharset.ISO88591, TestCharset.ISO88591, BOM_UTF_8); } @@ -1348,7 +1318,6 @@ @Test @Alerts(DEFAULT = {"a", "ä", "أهلاً", "мир", "房间"}, IE = {"a", "ä", "أهلاً", "мир", "房间"}) - @NotYetImplemented(IE) public void _UTF8_ISO88591_ISO88591_ISO88591_BOMUTF8() throws Exception { charset(TestCharset.UTF8, TestCharset.ISO88591, TestCharset.ISO88591, TestCharset.ISO88591, BOM_UTF_8); } @@ -1359,7 +1328,6 @@ @Test @Alerts(DEFAULT = {"a", "ä", "أهلاً", "мир", "房间"}, IE = {"a", "ä", "أهلاً", "мир", "房间"}) - @NotYetImplemented(IE) public void _UTF8_UTF8_ISO88591_ISO88591_BOMUTF8() throws Exception { charset(TestCharset.UTF8, TestCharset.UTF8, TestCharset.ISO88591, TestCharset.ISO88591, BOM_UTF_8); } @@ -1370,7 +1338,6 @@ @Test @Alerts(DEFAULT = {"a", "ä", "أهلاً", "мир", "房间"}, IE = {"a", "ä", "أهلاً", "мир", "房间"}) - @NotYetImplemented(IE) public void _UTF8__ISO88591_ISO88591_BOMUTF8() throws Exception { charset(TestCharset.UTF8, null, TestCharset.ISO88591, TestCharset.ISO88591, BOM_UTF_8); } @@ -1381,7 +1348,6 @@ @Test @Alerts(DEFAULT = {"a", "ä", "أهلاً", "мир", "房间"}, IE = {"a", "ä", "أهلاً", "мир", "房间"}) - @NotYetImplemented(IE) public void __ISO88591_ISO88591_ISO88591_BOMUTF8() throws Exception { charset(null, TestCharset.ISO88591, TestCharset.ISO88591, TestCharset.ISO88591, BOM_UTF_8); } @@ -1392,7 +1358,6 @@ @Test @Alerts(DEFAULT = {"a", "ä", "أهلاً", "мир", "房间"}, IE = {"a", "ä", "أهلاً", "мир", "房间"}) - @NotYetImplemented(IE) public void __UTF8_ISO88591_ISO88591_BOMUTF8() throws Exception { charset(null, TestCharset.UTF8, TestCharset.ISO88591, TestCharset.ISO88591, BOM_UTF_8); } @@ -1403,8 +1368,37 @@ @Test @Alerts(DEFAULT = {"a", "ä", "أهلاً", "мир", "房间"}, IE = {"a", "ä", "أهلاً", "мир", "房间"}) - @NotYetImplemented(IE) public void ___ISO88591_ISO88591_BOMUTF8() throws Exception { charset(null, null, TestCharset.ISO88591, TestCharset.ISO88591, BOM_UTF_8); } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"a", "ä", "أهلاً", "мир", "房间"}) + @NotYetImplemented(IE) + public void _GB2312____BOMUTF8() throws Exception { + charset(TestCharset.GB2312, null, null, null, BOM_UTF_8); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"a", "ä", "أهلاً", "мир", "房间"}) + @NotYetImplemented(IE) + public void _GB2312___UTF8_BOMUTF8() throws Exception { + charset(TestCharset.GB2312, null, null, TestCharset.UTF8, BOM_UTF_8); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"a", "ä", "أهلاً", "мир", "房间"}) + @NotYetImplemented(IE) + public void _GB2312___ISO88591_BOMUTF8() throws Exception { + charset(TestCharset.GB2312, null, null, TestCharset.ISO88591, BOM_UTF_8); + } } |
From: <rb...@us...> - 2017-08-01 15:39:28
|
Revision: 14750 http://sourceforge.net/p/htmlunit/code/14750 Author: rbri Date: 2017-08-01 15:39:26 +0000 (Tue, 01 Aug 2017) Log Message: ----------- latest Chrome - bring our impl in sync (wip) Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImage.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlImage2Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2017-08-01 13:58:48 UTC (rev 14749) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2017-08-01 15:39:26 UTC (rev 14750) @@ -416,6 +416,10 @@ @BrowserFeature(CHROME) HTMLIMAGE_HTMLUNKNOWNELEMENT, + /** Mark the image as invisible if the download failes. */ + @BrowserFeature(CHROME) + HTMLIMAGE_INVISIBLE_NOT_AVAILABLE, + /** Mark the image as invisible if no src attribute defined. */ @BrowserFeature({CHROME, FF}) HTMLIMAGE_INVISIBLE_NO_SRC, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImage.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImage.java 2017-08-01 13:58:48 UTC (rev 14749) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlImage.java 2017-08-01 15:39:26 UTC (rev 14750) @@ -18,6 +18,7 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLIMAGE_EMPTY_SRC_DISPLAY_FALSE; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLIMAGE_HTMLELEMENT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLIMAGE_HTMLUNKNOWNELEMENT; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLIMAGE_INVISIBLE_NOT_AVAILABLE; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLIMAGE_INVISIBLE_NO_SRC; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_IMAGE_COMPLETE_RETURNS_TRUE_FOR_NO_REQUEST; @@ -78,6 +79,7 @@ private int width_ = -1; private int height_ = -1; private boolean downloaded_; + private boolean isComplete_; private boolean onloadInvoked_; private boolean createdByJavascript_; @@ -137,6 +139,7 @@ // onload handlers may need to be invoked again, and a new image may need to be downloaded onloadInvoked_ = false; downloaded_ = false; + isComplete_ = false; width_ = -1; height_ = -1; if (imageData_ != null) { @@ -467,7 +470,8 @@ imageData_.close(); imageData_ = null; } - downloaded_ = hasFeature(JS_IMAGE_COMPLETE_RETURNS_TRUE_FOR_NO_REQUEST) + downloaded_ = true; + isComplete_ = hasFeature(JS_IMAGE_COMPLETE_RETURNS_TRUE_FOR_NO_REQUEST) || (imageWebResponse_ != null && imageWebResponse_.getContentType().contains("image")); width_ = -1; @@ -639,10 +643,9 @@ * @return true if the image was successfully downloaded */ public boolean isComplete() { - return downloaded_ - || (hasFeature(JS_IMAGE_COMPLETE_RETURNS_TRUE_FOR_NO_REQUEST) - ? ATTRIBUTE_NOT_DEFINED == getSrcAttribute() - : imageData_ != null); + return isComplete_ || (hasFeature(JS_IMAGE_COMPLETE_RETURNS_TRUE_FOR_NO_REQUEST) + ? ATTRIBUTE_NOT_DEFINED == getSrcAttribute() + : imageData_ != null); } /** @@ -666,6 +669,18 @@ || (hasFeature(HTMLIMAGE_EMPTY_SRC_DISPLAY_FALSE) && StringUtils.isEmpty(src)))) { return false; } + + if (hasFeature(HTMLIMAGE_INVISIBLE_NOT_AVAILABLE)) { + try { + downloadImageIfNeeded(); + if (imageWebResponse_ == null || !imageWebResponse_.getContentType().contains("image")) { + return false; + } + } + catch (final IOException e) { + return false; + } + } return super.isDisplayed(); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlImage2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlImage2Test.java 2017-08-01 13:58:48 UTC (rev 14749) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlImage2Test.java 2017-08-01 15:39:26 UTC (rev 14750) @@ -14,6 +14,8 @@ */ package com.gargoylesoftware.htmlunit.html; +import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.IE; + import java.io.InputStream; import java.net.URL; import java.util.Collections; @@ -28,6 +30,7 @@ import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.WebDriverTestCase; import com.gargoylesoftware.htmlunit.util.NameValuePair; @@ -85,6 +88,17 @@ loadImage("src='unknown'"); } + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "2", + IE = "1") + @NotYetImplemented(IE) + public void loadImageWrongType() throws Exception { + loadImage("src='" + URL_FIRST + "'"); + } + private void loadImage(final String src) throws Exception { try (InputStream is = getClass().getClassLoader().getResourceAsStream("testfiles/tiny-jpg.img")) { final byte[] directBytes = IOUtils.toByteArray(is); @@ -97,6 +111,8 @@ + "<script>\n" + " function test() {\n" + " var img = document.getElementById('myImage');\n" + + " img.width + img.width;\n" + + " img.height + img.height;\n" + " }\n" + "</script>\n" + "</head><body onload='test()'>\n" @@ -161,6 +177,16 @@ isDisplayed("src='unknown.gif'"); } + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = "true", + CHROME = "false") + public void isDisplayedWrongType() throws Exception { + isDisplayed("src='" + URL_FIRST + "'"); + } + private void isDisplayed(final String src) throws Exception { try (InputStream is = getClass().getClassLoader().getResourceAsStream("testfiles/tiny-jpg.img")) { final byte[] directBytes = IOUtils.toByteArray(is); |
From: <rb...@us...> - 2017-08-07 18:17:48
|
Revision: 14772 http://sourceforge.net/p/htmlunit/code/14772 Author: rbri Date: 2017-08-07 18:17:45 +0000 (Mon, 07 Aug 2017) Log Message: ----------- no longer include the file path when uploading a file Issue 1908 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/HttpWebConnection.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLInputElement.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFileInput2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFileInputTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2017-08-07 07:34:47 UTC (rev 14771) +++ trunk/htmlunit/src/changes/changes.xml 2017-08-07 18:17:45 UTC (rev 14772) @@ -8,6 +8,12 @@ <body> <release version="2.28" date="???" description="Bugfixes, Chrome 60"> + <action type="fix" dev="rbri" issue="1908"> + There is an option for IE that enables/disables the sending of the + complete file path when uploading a file. Starting with this version + we simulate this in disabled state like the default setting for the + internet zone. + </action> <action type="fix" dev="rbri"> BrowserVersion.clone now copies the system-timezone attribute. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2017-08-07 07:34:47 UTC (rev 14771) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2017-08-07 18:17:45 UTC (rev 14772) @@ -291,10 +291,6 @@ /** */ @BrowserFeature(IE) - HEADER_CONTENT_DISPOSITION_ABSOLUTE_PATH, - - /** */ - @BrowserFeature(IE) HTMLABBREVIATED, /** HtmlAllCollection.item returns null instead of undefined if an element was not found. */ @@ -445,13 +441,9 @@ HTMLINPUT_FILE_SELECTION_START_END_NULL, /** HTMLInputElement: type {@code file} value to be {@code fakepath}. */ - @BrowserFeature(CHROME) + @BrowserFeature({CHROME, IE}) HTMLINPUT_FILE_VALUE_FAKEPATH, - /** HTMLInputElement: type {@code file} value to be only the file name. */ - @BrowserFeature(FF) - HTMLINPUT_FILE_VALUE_NO_PATH, - /** Should the HTMLElement of {@code keygen} have no end tag. */ @BrowserFeature(IE) HTMLKEYGEN_END_TAG_FORBIDDEN, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2017-08-07 07:34:47 UTC (rev 14771) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2017-08-07 18:17:45 UTC (rev 14772) @@ -14,7 +14,6 @@ */ package com.gargoylesoftware.htmlunit; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HEADER_CONTENT_DISPOSITION_ABSOLUTE_PATH; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.URL_AUTH_CREDENTIALS; import java.io.ByteArrayInputStream; @@ -428,9 +427,6 @@ else if (pairWithFile.getFileName() != null) { filename = pairWithFile.getFileName(); } - else if (webClient_.getBrowserVersion().hasFeature(HEADER_CONTENT_DISPOSITION_ABSOLUTE_PATH)) { - filename = file.getAbsolutePath(); - } else { filename = file.getName(); } @@ -459,9 +455,6 @@ else if (pairWithFile.getFileName() != null) { filename = pairWithFile.getFileName(); } - else if (webClient_.getBrowserVersion().hasFeature(HEADER_CONTENT_DISPOSITION_ABSOLUTE_PATH)) { - filename = pairWithFile.getFile().getAbsolutePath(); - } else { filename = pairWithFile.getFile().getName(); } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLInputElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLInputElement.java 2017-08-07 07:34:47 UTC (rev 14771) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLInputElement.java 2017-08-07 18:17:45 UTC (rev 14772) @@ -18,7 +18,6 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLINPUT_FILES_UNDEFINED; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLINPUT_FILE_SELECTION_START_END_NULL; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLINPUT_FILE_VALUE_FAKEPATH; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLINPUT_FILE_VALUE_NO_PATH; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ALIGN_FOR_INPUT_IGNORES_VALUES; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_INPUT_NUMBER_SELECTION_START_END_NULL; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_INPUT_SET_TYPE_LOWERCASE; @@ -591,10 +590,7 @@ if (getBrowserVersion().hasFeature(HTMLINPUT_FILE_VALUE_FAKEPATH)) { return "C:\\fakepath\\" + name; } - else if (getBrowserVersion().hasFeature(HTMLINPUT_FILE_VALUE_NO_PATH)) { - return name; - } - return first.getAbsolutePath(); + return name; } return super.getValue(); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFileInput2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFileInput2Test.java 2017-08-07 07:34:47 UTC (rev 14771) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFileInput2Test.java 2017-08-07 18:17:45 UTC (rev 14772) @@ -598,12 +598,10 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = {"C:\\fakepath\\pom.xml-Hello world-Hello world", - "<input type=\"file\" id=\"f\" value=\"Hello world\" multiple=\"\">"}, - FF = {"pom.xml-Hello world-Hello world", - "<input type=\"file\" id=\"f\" value=\"Hello world\" multiple=\"\">"}, - IE = {"§§PATH§§-Hello world-Hello world", - "<input type=\"file\" id=\"f\" value=\"Hello world\" multiple=\"\">"}) + @Alerts(DEFAULT = {"pom.xml-Hello world-Hello world", + "<input type=\"file\" id=\"f\" value=\"Hello world\" multiple=\"\">"}, + CHROME = {"C:\\fakepath\\pom.xml-Hello world-Hello world", + "<input type=\"file\" id=\"f\" value=\"Hello world\" multiple=\"\">"}) public void value() throws Exception { final String html = "<html>\n" Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFileInputTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFileInputTest.java 2017-08-07 07:34:47 UTC (rev 14771) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFileInputTest.java 2017-08-07 18:17:45 UTC (rev 14772) @@ -458,9 +458,11 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = "Content-Disposition: form-data; name=\"myInput\"; filename=\"realm.properties\"", - IE = "Content-Disposition: form-data; name=\"myInput\";" - + " filename=\".*test-classes[\\\\/]realm\\.properties\"") + @Alerts("Content-Disposition: form-data; name=\"myInput\"; filename=\"realm.properties\"") + // since 2.28 + // there is an option for IE, for local and trusted sites IE includes the file path + // because we do not support any IE specific setting we do not send the filename as + // done by the other browsers public void realFile() throws Exception { final String htmlContent = "<html>\n" @@ -1030,8 +1032,11 @@ */ @Test @Alerts(DEFAULT = "C:\\fakepath\\pom.xml--null", - FF = "pom.xml--null", - IE = "§§PATH§§--null") + FF = "pom.xml--null") + // since 2.28 + // there is an option for IE, for local and trusted sites IE includes the file path + // because we do not support any IE specific setting we do not send the filename as + // done by the other browsers public void value2() throws Exception { final String html = "<html>\n" @@ -1054,9 +1059,7 @@ driver.findElement(By.id("f")).sendKeys(absolutePath); driver.findElement(By.id("clickMe")).click(); - final String[] expectedAlerts = getExpectedAlerts(); - expectedAlerts[0] = expectedAlerts[0].replace("§§PATH§§", absolutePath); - assertEquals(expectedAlerts, getCollectedAlerts(driver)); + assertEquals(getExpectedAlerts(), getCollectedAlerts(driver)); } /** @@ -1111,8 +1114,11 @@ */ @Test @Alerts(DEFAULT = "C:\\fakepath\\pom.xml", - FF = "pom.xml", - IE = "§§PATH§§") + FF = "pom.xml") + // since 2.28 + // there is an option for IE, for local and trusted sites IE includes the file path + // because we do not support any IE specific setting we do not send the filename as + // done by the other browsers public void getAttribute() throws Exception { final String html = "<html><body>\n" @@ -1124,9 +1130,6 @@ final WebDriver driver = loadPage2(html); final WebElement e = driver.findElement(By.id("f")); e.sendKeys(absolutePath); - final String[] expectedAlerts = getExpectedAlerts(); - expectedAlerts[0] = expectedAlerts[0].replace("§§PATH§§", absolutePath); - assertEquals(expectedAlerts[0], e.getAttribute("value")); + assertEquals(getExpectedAlerts()[0], e.getAttribute("value")); } - } |
From: <asa...@us...> - 2017-08-08 10:29:57
|
Revision: 14775 http://sourceforge.net/p/htmlunit/code/14775 Author: asashour Date: 2017-08-08 10:29:55 +0000 (Tue, 08 Aug 2017) Log Message: ----------- Test cases pass, thanks to Ronald. Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/HtmlUnitContextFactory.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeArrayTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2017-08-08 07:15:58 UTC (rev 14774) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2017-08-08 10:29:55 UTC (rev 14775) @@ -599,6 +599,10 @@ @BrowserFeature({CHROME, FF}) JS_ARRAY_FROM, + /** Indicates that the {@code Array} supports construction properties. */ + @BrowserFeature(FF) + JS_ARRAY_CONSTRUCTION_PROPERTIES, + /** firstChild and lastChild returns null for Attr (like IE does). */ @BrowserFeature({CHROME, FF}) JS_ATTR_FIRST_LAST_CHILD_RETURNS_NULL, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/HtmlUnitContextFactory.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/HtmlUnitContextFactory.java 2017-08-08 07:15:58 UTC (rev 14774) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/HtmlUnitContextFactory.java 2017-08-08 10:29:55 UTC (rev 14775) @@ -15,6 +15,7 @@ package com.gargoylesoftware.htmlunit.javascript; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ARGUMENTS_READ_ONLY_ACCESSED_FROM_FUNCTION; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ARRAY_CONSTRUCTION_PROPERTIES; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ENUM_NUMBERS_FIRST; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ERROR_STACK; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_FUNCTION_DECLARED_FORWARD_IN_BLOCK; @@ -348,6 +349,8 @@ return browserVersion_.hasFeature(JS_PROPERTY_DESCRIPTOR_NAME); case Context.FEATURE_HTMLUNIT_MEMBERBOX_NEWLINE: return browserVersion_.hasFeature(JS_PROPERTY_DESCRIPTOR_NEW_LINE); + case Context.FEATURE_HTMLUNIT_ARRAY_PROPERTIES: + return browserVersion_.hasFeature(JS_ARRAY_CONSTRUCTION_PROPERTIES); default: return super.hasFeature(cx, featureIndex); } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java 2017-08-08 07:15:58 UTC (rev 14774) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java 2017-08-08 10:29:55 UTC (rev 14775) @@ -829,7 +829,7 @@ if (ScriptRuntime.hasTopCall(cx)) { return function.call(cx, scope, thisObject, args); } - return ScriptRuntime.doTopCall(function, cx, scope, thisObject, args); + return ScriptRuntime.doTopCall(function, cx, scope, thisObject, args, cx.isStrictMode()); } @Override protected String getSourceCode(final Context cx) { Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeArrayTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeArrayTest.java 2017-08-08 07:15:58 UTC (rev 14774) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeArrayTest.java 2017-08-08 10:29:55 UTC (rev 14775) @@ -14,7 +14,6 @@ */ package com.gargoylesoftware.htmlunit.javascript; -import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.CHROME; import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.FF45; import static com.gargoylesoftware.htmlunit.BrowserRunner.TestedBrowser.IE; @@ -444,7 +443,6 @@ */ @Test @Alerts({"undefined", "TypeError"}) - @NotYetImplemented public void findStatic() throws Exception { final String html = "<html>\n" @@ -517,7 +515,6 @@ */ @Test @Alerts({"undefined", "TypeError"}) - @NotYetImplemented public void findIndexStatic() throws Exception { final String html = "<html>\n" @@ -591,7 +588,6 @@ @Test @Alerts(DEFAULT = {"undefined", "TypeError"}, FF = {"function", "20,17"}) - @NotYetImplemented public void filterStatic() throws Exception { final String html = "<html>\n" @@ -661,7 +657,6 @@ @Test @Alerts(DEFAULT = {"undefined", "TypeError"}, FF = {"function", "1,2,3,4"}) - @NotYetImplemented public void mapStatic() throws Exception { final String html = "<html>\n" @@ -733,7 +728,6 @@ @Test @Alerts(DEFAULT = {"undefined", "TypeError"}, FF = {"function", "false"}) - @NotYetImplemented public void everyStatic() throws Exception { final String html = "<html>\n" @@ -807,7 +801,6 @@ @Test @Alerts(DEFAULT = {"undefined", "TypeError"}, FF = {"function", "true"}) - @NotYetImplemented public void someStatic() throws Exception { final String html = "<html>\n" @@ -877,7 +870,6 @@ @Test @Alerts(DEFAULT = {"undefined", "TypeError"}, FF = {"function", "4", "7"}) - @NotYetImplemented({CHROME, IE}) public void forEachStatic() throws Exception { final String html = "<html>\n" @@ -949,7 +941,6 @@ @Test @Alerts(DEFAULT = {"undefined", "TypeError"}, FF = {"function", "30"}) - @NotYetImplemented({CHROME, IE}) public void reduceStatic() throws Exception { final String html = "<html>\n" @@ -1023,7 +1014,6 @@ @Test @Alerts(DEFAULT = {"undefined", "TypeError"}, FF = {"function", "2"}) - @NotYetImplemented({CHROME, IE}) public void reduceRightStatic() throws Exception { final String html = "<html>\n" @@ -1093,7 +1083,6 @@ @Test @Alerts(DEFAULT = {"undefined", "TypeError"}, FF = {"function", "1,4,9,16"}) - @NotYetImplemented({CHROME, IE}) public void joinStatic() throws Exception { final String html = "<html>\n" @@ -1161,7 +1150,6 @@ @Test @Alerts(DEFAULT = {"undefined", "TypeError"}, FF = {"function", "16,9,4,1"}) - @NotYetImplemented({CHROME, IE}) public void reverseStatic() throws Exception { final String html = "<html>\n" @@ -1229,7 +1217,6 @@ @Test @Alerts(DEFAULT = {"undefined", "TypeError"}, FF = {"function", "1,16,4,9"}) - @NotYetImplemented({CHROME, IE}) public void sortStatic() throws Exception { final String html = "<html>\n" @@ -1299,7 +1286,6 @@ @Test @Alerts(DEFAULT = {"undefined", "TypeError"}, FF = {"function", "6", "1,4,9,16,3,7"}) - @NotYetImplemented({CHROME, IE}) public void pushStatic() throws Exception { final String html = "<html>\n" @@ -1370,7 +1356,6 @@ @Test @Alerts(DEFAULT = {"undefined", "TypeError"}, FF = {"function", "16", "1,4,9"}) - @NotYetImplemented({CHROME, IE}) public void popStatic() throws Exception { final String html = "<html>\n" @@ -1441,7 +1426,6 @@ @Test @Alerts(DEFAULT = {"undefined", "TypeError"}, FF = {"function", "1", "4,9,16"}) - @NotYetImplemented({CHROME, IE}) public void shiftStatic() throws Exception { final String html = "<html>\n" @@ -1512,7 +1496,6 @@ @Test @Alerts(DEFAULT = {"undefined", "TypeError"}, FF = {"function", "6", "3,7,1,4,9,16"}) - @NotYetImplemented({CHROME, IE}) public void unshiftStatic() throws Exception { final String html = "<html>\n" @@ -1583,7 +1566,6 @@ @Test @Alerts(DEFAULT = {"undefined", "TypeError"}, FF = {"function", "4,9", "1,16"}) - @NotYetImplemented({CHROME, IE}) public void spliceStatic() throws Exception { final String html = "<html>\n" @@ -1654,7 +1636,6 @@ @Test @Alerts(DEFAULT = {"undefined", "TypeError"}, FF = {"function", "1,4,9,16,1,2", "1,4,9,16"}) - @NotYetImplemented({CHROME, IE}) public void concatStatic() throws Exception { final String html = "<html>\n" @@ -1725,7 +1706,6 @@ @Test @Alerts(DEFAULT = {"undefined", "TypeError"}, FF = {"function", "4", "1,4,9,16"}) - @NotYetImplemented({CHROME, IE}) public void sliceStatic() throws Exception { final String html = "<html>\n" @@ -1796,7 +1776,6 @@ @Test @Alerts(DEFAULT = {"undefined", "TypeError"}, FF = {"function", "2", "1,4,9,16"}) - @NotYetImplemented({CHROME, IE}) public void indexOfStatic() throws Exception { final String html = "<html>\n" @@ -1867,7 +1846,6 @@ @Test @Alerts(DEFAULT = {"undefined", "TypeError"}, FF = {"function", "2", "1,4,9,16"}) - @NotYetImplemented({CHROME, IE}) public void lastIndexOfStatic() throws Exception { final String html = "<html>\n" |
From: <rb...@us...> - 2017-08-10 19:01:01
|
Revision: 14781 http://sourceforge.net/p/htmlunit/code/14781 Author: rbri Date: 2017-08-10 19:00:58 +0000 (Thu, 10 Aug 2017) Log Message: ----------- minor start of file reader impl Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileReader.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileReaderTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileReader.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileReader.java 2017-08-10 18:16:25 UTC (rev 14780) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileReader.java 2017-08-10 19:00:58 UTC (rev 14781) @@ -17,12 +17,18 @@ 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.JsxFunction; +import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter; +import com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter; import com.gargoylesoftware.htmlunit.javascript.host.event.EventTarget; +import net.sourceforge.htmlunit.corejs.javascript.Function; + /** * A JavaScript object for {@code FileReader}. * * @author Ahmed Ashour + * @author Ronald Brill */ @JsxClass public class FileReader extends EventTarget { @@ -39,11 +45,66 @@ @JsxConstant public static final short DONE = 2; + private int readyState_; + /** * Creates an instance. */ @JsxConstructor public FileReader() { + readyState_ = EMPTY; } + /** + * Returns the {@code onload} event handler for this element. + * @return the {@code onload} event handler for this element + */ + @JsxGetter + public int getReadyState() { + return readyState_; + } + + /** + * Returns the {@code onload} event handler for this element. + * @return the {@code onload} event handler for this element + */ + @JsxGetter + public Function getOnload() { + return getEventHandler("load"); + } + + /** + * Sets the {@code onload} event handler for this element. + * @param onload the {@code onload} event handler for this element + */ + @JsxSetter + public void setOnload(final Object onload) { + setEventHandler("load", onload); + } + + /** + * Returns the {@code onerror} event handler for this element. + * @return the {@code onerror} event handler for this element + */ + @JsxGetter + public Function getOnerror() { + return getEventHandler("error"); + } + + /** + * Sets the {@code onerror} event handler for this element. + * @param onerror the {@code onerror} event handler for this element + */ + @JsxSetter + public void setOnerror(final Object onerror) { + setEventHandler("error", onerror); + } + + /** + * Function readAsDataURL. + * @param file the file + */ + @JsxFunction + public void readAsDataURL(final File file) { + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileReaderTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileReaderTest.java 2017-08-10 18:16:25 UTC (rev 14780) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileReaderTest.java 2017-08-10 19:00:58 UTC (rev 14781) @@ -24,9 +24,9 @@ import org.openqa.selenium.WebDriver; import com.gargoylesoftware.htmlunit.BrowserRunner; -import com.gargoylesoftware.htmlunit.WebDriverTestCase; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; +import com.gargoylesoftware.htmlunit.WebDriverTestCase; import com.gargoylesoftware.htmlunit.html.HtmlPageTest; /** @@ -41,8 +41,34 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "data:;base64,SHRtbFVuaXQ=", - FF = "data:application/octet-stream;base64,SHRtbFVuaXQ=") + @Alerts("0") + public void ctorReadyState() throws Exception { + final String html + = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html>\n" + + "<head>\n" + + " <script>\n" + + " function test() {\n" + + " var reader = new FileReader();\n" + + " alert(reader.readyState);\n" + + " }\n" + + " </script>\n" + + "<head>\n" + + "<body>\n" + + " <button id='testBtn' onclick='test()'>Tester</button>\n" + + "</body>\n" + + "</html>"; + + final WebDriver driver = loadPage2(html); + driver.findElement(By.id("testBtn")).click(); + verifyAlerts(driver, getExpectedAlerts()); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("data:text/plain;base64,SHRtbFVuaXQ=") @NotYetImplemented public void readAsDataURL() throws Exception { final String html @@ -51,12 +77,12 @@ + "<head>\n" + " <script>\n" + " function test() {\n" + + " var files = document.testForm.fileupload.files;\n" + " var reader = new FileReader();\n" + " reader.onload = function() {\n" + " var dataURL = reader.result;\n" + " alert(dataURL);\n" + " };\n" - + " var files = document.testForm.fileupload.files;\n" + " reader.readAsDataURL(files[0]);\n" + " }\n" + " </script>\n" |
From: <asa...@us...> - 2017-08-11 07:02:42
|
Revision: 14782 http://sourceforge.net/p/htmlunit/code/14782 Author: asashour Date: 2017-08-11 07:02:39 +0000 (Fri, 11 Aug 2017) Log Message: ----------- Initial implementation of FileReader.readAsDataURL Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventListenersContainer.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileReader.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileReaderTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventListenersContainer.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventListenersContainer.java 2017-08-10 19:00:58 UTC (rev 14781) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/event/EventListenersContainer.java 2017-08-11 07:02:39 UTC (rev 14782) @@ -31,6 +31,7 @@ import com.gargoylesoftware.htmlunit.html.DomNode; import com.gargoylesoftware.htmlunit.html.HtmlBody; import com.gargoylesoftware.htmlunit.html.HtmlPage; +import com.gargoylesoftware.htmlunit.javascript.host.Window; import net.sourceforge.htmlunit.corejs.javascript.Function; import net.sourceforge.htmlunit.corejs.javascript.NativeObject; @@ -220,7 +221,7 @@ private ScriptResult executeEventListeners(final boolean useCapture, final Event event, final Object[] args) { final DomNode node = jsNode_.getDomNodeOrNull(); // some event don't apply on all kind of nodes, for instance "blur" - if (node == null || !node.handles(event)) { + if (node != null && !node.handles(event)) { return null; } @@ -228,7 +229,8 @@ final List<Scriptable> listeners = getListeners(event.getType(), useCapture); if (listeners != null && !listeners.isEmpty()) { event.setCurrentTarget(jsNode_); - final HtmlPage page = (HtmlPage) node.getPage(); + + final HtmlPage page = (HtmlPage) ((Window) jsNode_.getParentScope()).getDomNodeOrDie(); // no need for a copy, listeners are copy on write for (final Scriptable listener : listeners) { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileReader.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileReader.java 2017-08-10 19:00:58 UTC (rev 14781) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileReader.java 2017-08-11 07:02:39 UTC (rev 14782) @@ -14,6 +14,13 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.file; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.nio.file.Files; + +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.io.FileUtils; + import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstant; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; @@ -20,6 +27,7 @@ import com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxSetter; +import com.gargoylesoftware.htmlunit.javascript.host.event.Event; import com.gargoylesoftware.htmlunit.javascript.host.event.EventTarget; import net.sourceforge.htmlunit.corejs.javascript.Function; @@ -45,7 +53,8 @@ @JsxConstant public static final short DONE = 2; - private int readyState_; + private int readyState_ = EMPTY; + private Object result_; /** * Creates an instance. @@ -52,12 +61,12 @@ */ @JsxConstructor public FileReader() { - readyState_ = EMPTY; } /** - * Returns the {@code onload} event handler for this element. - * @return the {@code onload} event handler for this element + * Returns the current state of the reading operation. + * + * @return {@value #EMPTY}, {@value #LOADING}, or {@value #DONE} */ @JsxGetter public int getReadyState() { @@ -65,46 +74,71 @@ } /** - * Returns the {@code onload} event handler for this element. - * @return the {@code onload} event handler for this element + * Returns the file's contents. + * @return the file's contents */ @JsxGetter + public Object getResult() { + return result_; + } + + /** + * Reads the contents of the specified {@link Blob} or {@link File}. + * @param object the {@link Blob} or {@link File} from which to read + */ + @JsxFunction + public void readAsDataURL(final Object object) throws IOException { + setResult(object); + final Event event = new Event(this, Event.TYPE_LOAD); + fireEvent(event); + } + + private void setResult(final Object object) throws IOException { + readyState_ = LOADING; + final java.io.File file = ((File) object).getFile(); + final String contentType = Files.probeContentType(file.toPath()); + try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) { + FileUtils.copyFile(file, bos); + + final byte[] bytes = bos.toByteArray(); + result_ = "data:" + contentType + ";base64," + new String(new Base64().encode(bytes)); + } + readyState_ = DONE; + } + + /** + * Returns the {@code onload} event handler for this {@link FileReader}. + * @return the {@code onload} event handler for this {@link FileReader} + */ + @JsxGetter public Function getOnload() { - return getEventHandler("load"); + return getEventHandler(Event.TYPE_LOAD); } /** - * Sets the {@code onload} event handler for this element. - * @param onload the {@code onload} event handler for this element + * Sets the {@code onload} event handler for this {@link FileReader}. + * @param onload the {@code onload} event handler for this {@link FileReader} */ @JsxSetter public void setOnload(final Object onload) { - setEventHandler("load", onload); + setEventHandler(Event.TYPE_LOAD, onload); } /** - * Returns the {@code onerror} event handler for this element. - * @return the {@code onerror} event handler for this element + * Returns the {@code onerror} event handler for this {@link FileReader}. + * @return the {@code onerror} event handler for this {@link FileReader} */ @JsxGetter public Function getOnerror() { - return getEventHandler("error"); + return getEventHandler(Event.TYPE_ERROR); } /** - * Sets the {@code onerror} event handler for this element. - * @param onerror the {@code onerror} event handler for this element + * Sets the {@code onerror} event handler for this {@link FileReader}. + * @param onerror the {@code onerror} event handler for this {@link FileReader} */ @JsxSetter public void setOnerror(final Object onerror) { - setEventHandler("error", onerror); + setEventHandler(Event.TYPE_ERROR, onerror); } - - /** - * Function readAsDataURL. - * @param file the file - */ - @JsxFunction - public void readAsDataURL(final File file) { - } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileReaderTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileReaderTest.java 2017-08-10 19:00:58 UTC (rev 14781) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileReaderTest.java 2017-08-11 07:02:39 UTC (rev 14782) @@ -25,7 +25,6 @@ import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; -import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.WebDriverTestCase; import com.gargoylesoftware.htmlunit.html.HtmlPageTest; @@ -69,7 +68,6 @@ */ @Test @Alerts("data:text/plain;base64,SHRtbFVuaXQ=") - @NotYetImplemented public void readAsDataURL() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ |
From: <asa...@us...> - 2017-08-11 07:56:46
|
Revision: 14783 http://sourceforge.net/p/htmlunit/code/14783 Author: asashour Date: 2017-08-11 07:56:43 +0000 (Fri, 11 Aug 2017) Log Message: ----------- JavaScript: support FileReader.readAsDataURL() Issue 1912 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/file/FileReader.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/ErrorOutputChecker.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileReaderTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2017-08-11 07:02:39 UTC (rev 14782) +++ trunk/htmlunit/src/changes/changes.xml 2017-08-11 07:56:43 UTC (rev 14783) @@ -8,6 +8,9 @@ <body> <release version="2.28" date="???" description="Bugfixes, Chrome 60"> + <action type="add" dev="asashour" issue="1912"> + JavaScript: support FileReader.readAsDataURL(). + </action> <action type="fix" dev="asashour" issue="1911"> ProxyAutoConfig: fix isInNet(). </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2017-08-11 07:02:39 UTC (rev 14782) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2017-08-11 07:56:43 UTC (rev 14783) @@ -897,6 +897,14 @@ @BrowserFeature(FF) JS_FILE_SHORT_DATE_FORMAT, + /** Whether {@link FileReader} includes content type or not. */ + @BrowserFeature(FF) + JS_FILEREADER_CONTENT_TYPE, + + /** Whether {@link FileReader} includes {@code base64} for empty content or not. */ + @BrowserFeature(IE) + JS_FILEREADER_EMPTY_NULL, + /** Indicates that the action property will not be expanded if defined as empty string. */ @BrowserFeature(FF) JS_FORM_ACTION_EXPANDURL_IGNORE_EMPTY, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileReader.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileReader.java 2017-08-11 07:02:39 UTC (rev 14782) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileReader.java 2017-08-11 07:56:43 UTC (rev 14783) @@ -14,6 +14,9 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.file; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_FILEREADER_CONTENT_TYPE; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_FILEREADER_EMPTY_NULL; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.file.Files; @@ -21,6 +24,7 @@ import org.apache.commons.codec.binary.Base64; import org.apache.commons.io.FileUtils; +import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstant; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxConstructor; @@ -96,12 +100,30 @@ private void setResult(final Object object) throws IOException { readyState_ = LOADING; final java.io.File file = ((File) object).getFile(); - final String contentType = Files.probeContentType(file.toPath()); + String contentType = Files.probeContentType(file.toPath()); try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) { FileUtils.copyFile(file, bos); final byte[] bytes = bos.toByteArray(); - result_ = "data:" + contentType + ";base64," + new String(new Base64().encode(bytes)); + final String value = new String(new Base64().encode(bytes)); + final BrowserVersion browserVersion = getBrowserVersion(); + + result_ = "data:"; + final boolean includeConentType = browserVersion.hasFeature(JS_FILEREADER_CONTENT_TYPE); + if (!value.isEmpty() || includeConentType) { + if (contentType == null) { + if (includeConentType) { + contentType = "application/octet-stream"; + } + else { + contentType = ""; + } + } + result_ += contentType + ";base64," + value; + } + if (value.isEmpty() && getBrowserVersion().hasFeature(JS_FILEREADER_EMPTY_NULL)) { + result_ = "null"; + } } readyState_ = DONE; } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/ErrorOutputChecker.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/ErrorOutputChecker.java 2017-08-11 07:02:39 UTC (rev 14782) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/ErrorOutputChecker.java 2017-08-11 07:56:43 UTC (rev 14783) @@ -45,6 +45,9 @@ Pattern.compile(".*geckodriver.*\r?\n"), Pattern.compile(".*mozprofile.*\r?\n"), Pattern.compile(".*Marionette.*\r?\n"), + Pattern.compile(".*\tDEBUG\t.*\r?\n"), + Pattern.compile(".*\taddons\\..*\r?\n"), + Pattern.compile("\\*\\*\\* Blocklist::.*\r?\n"), Pattern.compile("Started InternetExplorerDriver server \\(\\d\\d\\-bit\\)\r?\n" + "3\\.4\\.0\\.0\r?\n" + "Listening on port \\d*\r?\n" Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileReaderTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileReaderTest.java 2017-08-11 07:02:39 UTC (rev 14782) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileReaderTest.java 2017-08-11 07:56:43 UTC (rev 14783) @@ -110,4 +110,82 @@ FileUtils.deleteQuietly(tstFile); } } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "data:;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAABlBMVEX+1K8AAADjghFsAAAAGXRFWHRTb2" + + "Z0d2FyZQBHcmFwaGljQ29udmVydGVyNV1I7gAAABBJREFUeJxiYAAAAAD//wMAAAIAAcx+i34AAAAASUVORK5CYII=", + FF = "data:application/octet-stream;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAABlBMVEX+1K8AAAD" + + "jghFsAAAAGXRFWHRTb2Z0d2FyZQBHcmFwaGljQ29udmVydGVyNV1I7gAAABBJREFUeJxiYAAAAAD//wMAAAIAAcx+i34AAAAASU" + + "VORK5CYII=") + public void readAsDataURLUnknown() throws Exception { + final String html + = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html>\n" + + "<head><title>foo</title>\n" + + "<script>\n" + + " function previewFile() {\n" + + " var file = document.querySelector('input[type=file]').files[0];\n" + + " var reader = new FileReader();\n" + + " reader.addEventListener('load', function () {\n" + + " alert(reader.result);\n" + + " }, false);\n" + + "\n" + + " if (file) {\n" + + " reader.readAsDataURL(file);\n" + + " }\n" + + " }\n" + + "</script>\n" + + "</head>\n" + + "<body>\n" + + " <input type='file' onchange='previewFile()'>\n" + + "</body>\n" + + "</html>"; + + final WebDriver driver = loadPage2(html); + + final String path = new File("src/test/resources/testfiles/tiny-png.img").getCanonicalPath(); + driver.findElement(By.tagName("input")).sendKeys(path); + verifyAlerts(driver, getExpectedAlerts()); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "data:", + FF = "data:image/png;base64,", + IE = "null") + public void readAsDataURLEmptyImage() throws Exception { + final String html + = HtmlPageTest.STANDARDS_MODE_PREFIX_ + + "<html>\n" + + "<head><title>foo</title>\n" + + "<script>\n" + + " function previewFile() {\n" + + " var file = document.querySelector('input[type=file]').files[0];\n" + + " var reader = new FileReader();\n" + + " reader.addEventListener('load', function () {\n" + + " alert(reader.result);\n" + + " }, false);\n" + + "\n" + + " if (file) {\n" + + " reader.readAsDataURL(file);\n" + + " }\n" + + " }\n" + + "</script>\n" + + "</head>\n" + + "<body>\n" + + " <input type='file' onchange='previewFile()'>\n" + + "</body>\n" + + "</html>"; + + final WebDriver driver = loadPage2(html); + + final String path = new File("src/test/resources/testfiles/empty.png").getCanonicalPath(); + driver.findElement(By.tagName("input")).sendKeys(path); + verifyAlerts(driver, getExpectedAlerts()); + } } |