From: <rb...@us...> - 2018-03-30 08:55:19
|
Revision: 15215 http://sourceforge.net/p/htmlunit/code/15215 Author: rbri Date: 2018-03-30 08:55:15 +0000 (Fri, 30 Mar 2018) Log Message: ----------- GAE support is history Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/background/DefaultJavaScriptExecutor.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/background/JavaScriptExecutor.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/canvas/rendering/RenderingBackend.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/MatrixTransformer.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/UrlUtils.java Removed Paths: ------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnection.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/URLCreator.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnection2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnectionTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/gae/ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/background/JavaScriptJobManagerGaeMinimalTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/UrlCreatorTest.java trunk/htmlunit/src/test/resources/com/gargoylesoftware/htmlunit/gae/ Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2018-03-30 08:17:57 UTC (rev 15214) +++ trunk/htmlunit/src/changes/changes.xml 2018-03-30 08:55:15 UTC (rev 15215) @@ -7,6 +7,13 @@ </properties> <body> + <release version="2.31" date="xx, 2018" description="Bugfixes, special GAE handlings removed"> + <action type="update" dev="rbri"> + Special handling of the GAE environment is no longer required, the JDK8 at GAE has no longer + any restrictions. + </action> + </release> + <release version="2.30" date="March 25, 2018" description="Bugfixes, using or own CSSParser for improved performance, URLSearchParams implemented, start adding support of user defined iterators, CHROME 66"> <action type="fix" dev="rbri" issue="1959"> Improved clone implementation to take care of references. @@ -26,18 +33,18 @@ <action type="add" dev="rbri" issue="1954"> Use the correct content type when guessing from the '.js' file extension. </action> - <action type="change" dev="rbri"> + <action type="update" dev="rbri"> Major refactoring of the css handling (selector processing). Every style sheet now has a selector index to speed up style processing. </action> - <action type="change" dev="rbri"> + <action type="update" dev="rbri"> We have now our own cssparser (a cleaned up version of the cssparser we have used so far) to be able to change the model classes to better support our use cases. </action> - <action type="change" dev="rbri"> + <action type="update" dev="rbri"> getArttibute is optimized for speed in some special cases. </action> - <action type="change" dev="rbri"> + <action type="update" dev="rbri"> Local files are now cached using the same rules as server requests (cacheable if date-modified is more than ten minutes in the past) </action> @@ -74,7 +81,7 @@ <action type="add" dev="rbri"> JavaScript: Array.from() now supports user defined iterators also. </action> - <action type="change" dev="rbri"> + <action type="update" dev="rbri"> Samples on page Get Started updated. </action> <action type="fix" dev="rbri" issue="1946"> @@ -244,7 +251,7 @@ INCOMPATIBLE CHANGE: BrowserVersion is final now and all constructors are removed. The only way to create new customized Browser versions is by using the BrowserVersionBuilder. </action> - <action type="change" dev="rbri" issue="1890"> + <action type="update" dev="rbri" issue="1890"> BrowserVersion setter methods are fluent now. </action> <action type="fix" dev="asashour" issue="1905"> @@ -733,7 +740,7 @@ <action type="fix" dev="rbri" issue="1803" due-to="Carsten Steul"> IllegalStateException adding an option to a select. </action> - <action type="change" dev="rbri" issue="1620"> + <action type="update" dev="rbri" issue="1620"> New class DefaultJavaScriptErrorListener added. This listener will be always used of no specific listener is defined. The logging of js errors was moved to this class. If you like to have the logging and your own JavaScriptErrorListener than subclass or decorate this. Deleted: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnection.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnection.java 2018-03-30 08:17:57 UTC (rev 15214) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnection.java 2018-03-30 08:55:15 UTC (rev 15215) @@ -1,241 +0,0 @@ -/* - * Copyright (c) 2002-2018 Gargoyle Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.gargoylesoftware.htmlunit; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.HttpURLConnection; -import java.net.URL; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -import org.apache.commons.io.IOUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.http.client.utils.URLEncodedUtils; - -import com.gargoylesoftware.htmlunit.util.Cookie; -import com.gargoylesoftware.htmlunit.util.NameValuePair; - -/** - * An implementation of {@link WebConnection}, compatible with Google App Engine. - * <p> - * Note: this class is experimental and not mature like {@link HttpWebConnection}. - * It doesn't currently support multipart POST. - * </p> - * <p>This might not use all headers because the JDK ignores/censors some headers (at lease Origin). - * You can disable this censorship by setting 'sun.net.http.allowRestrictedHeaders' to true - * </p> - * - * @author Amit Manjhi - * @author Marc Guillemot - * @author Pieter Herroelen - * @author Ronald Brill - * - * @since HtmlUnit 2.8 - * @see "http://code.google.com/p/googleappengine/issues/detail?id=3379" - */ -public class UrlFetchWebConnection implements WebConnection { - - /** Logging support. */ - private static final Log LOG = LogFactory.getLog(UrlFetchWebConnection.class); - - private static final String[] GAE_URL_HACKS = {"http://gaeHack_javascript/", "http://gaeHack_data/", - "http://gaeHack_about/"}; - - private final WebClient webClient_; - - /** - * Creates a new web connection instance. - * @param webClient the WebClient that is using this connection - */ - public UrlFetchWebConnection(final WebClient webClient) { - webClient_ = webClient; - } - - /** - * {@inheritDoc} - */ - @Override - public WebResponse getResponse(final WebRequest webRequest) throws IOException { - final long startTime = System.currentTimeMillis(); - final URL url = webRequest.getUrl(); - if (LOG.isTraceEnabled()) { - LOG.trace("about to fetch URL " + url); - } - - // hack for JS, about, and data URLs. - final WebResponse response = produceWebResponseForGAEProcolHack(url); - if (response != null) { - return response; - } - - // this is a "normal" URL - try { - final HttpURLConnection connection = (HttpURLConnection) url.openConnection(); -// connection.setUseCaches(false); - connection.setConnectTimeout(webClient_.getOptions().getTimeout()); - - connection.addRequestProperty(HttpHeader.USER_AGENT, webClient_.getBrowserVersion().getUserAgent()); - connection.setInstanceFollowRedirects(false); - - // copy the headers from WebRequestSettings - // this might not copy all headers because the JDK ignores/censors some headers - // you can disable this by setting sun.net.http.allowRestrictedHeaders to true - // see UrlFetchWebConnectionTest for some links - for (final Entry<String, String> header : webRequest.getAdditionalHeaders().entrySet()) { - connection.addRequestProperty(header.getKey(), header.getValue()); - } - addCookies(connection); - - final HttpMethod httpMethod = webRequest.getHttpMethod(); - connection.setRequestMethod(httpMethod.name()); - if (HttpMethod.POST == httpMethod || HttpMethod.PUT == httpMethod || HttpMethod.PATCH == httpMethod) { - connection.setDoOutput(true); - final Charset charset = webRequest.getCharset(); - connection.addRequestProperty(HttpHeader.CONTENT_TYPE, FormEncodingType.URL_ENCODED.getName()); - - try (OutputStream outputStream = connection.getOutputStream()) { - final List<NameValuePair> pairs = webRequest.getRequestParameters(); - final org.apache.http.NameValuePair[] httpClientPairs = NameValuePair.toHttpClient(pairs); - final String query = URLEncodedUtils.format(Arrays.asList(httpClientPairs), charset); - outputStream.write(query.getBytes(charset)); - if (webRequest.getRequestBody() != null) { - IOUtils.write(webRequest.getRequestBody().getBytes(charset), outputStream); - } - } - } - - final int responseCode = connection.getResponseCode(); - if (LOG.isTraceEnabled()) { - LOG.trace("fetched URL " + url); - } - - final List<NameValuePair> headers = new ArrayList<>(); - for (final Map.Entry<String, List<String>> headerEntry : connection.getHeaderFields().entrySet()) { - final String headerKey = headerEntry.getKey(); - if (headerKey != null) { // map contains entry like (null: "HTTP/1.1 200 OK") - final StringBuilder sb = new StringBuilder(); - for (final String headerValue : headerEntry.getValue()) { - if (sb.length() != 0) { - sb.append(", "); - } - sb.append(headerValue); - } - headers.add(new NameValuePair(headerKey, sb.toString())); - } - } - - final byte[] byteArray; - try (InputStream is = responseCode < 400 - ? connection.getInputStream() : connection.getErrorStream()) { - byteArray = IOUtils.toByteArray(is); - } - - final long duration = System.currentTimeMillis() - startTime; - final WebResponseData responseData = new WebResponseData(byteArray, responseCode, - connection.getResponseMessage(), headers); - saveCookies(url.getHost(), headers); - return new WebResponse(responseData, webRequest, duration); - } - catch (final IOException e) { - LOG.error("Exception while tyring to fetch " + url, e); - throw new RuntimeException(e); - } - } - - private void addCookies(final HttpURLConnection connection) { - final StringBuilder cookieHeader = new StringBuilder(); - boolean isFirst = true; - for (Cookie cookie : webClient_.getCookies(connection.getURL())) { - if (isFirst) { - isFirst = false; - } - else { - cookieHeader.append("; "); - } - - cookieHeader.append(cookie.getName()).append('=').append(cookie.getValue()); - } - if (!isFirst) { - connection.setRequestProperty(HttpHeader.COOKIE, cookieHeader.toString()); - } - } - - private void saveCookies(final String domain, final List<NameValuePair> headers) { - for (final NameValuePair nvp : headers) { - if ("Set-Cookie".equalsIgnoreCase(nvp.getName())) { - final Set<Cookie> cookies = parseCookies(domain, nvp.getValue()); - for (Cookie cookie : cookies) { - webClient_.getCookieManager().addCookie(cookie); - } - } - } - } - - private static WebResponse produceWebResponseForGAEProcolHack(final URL url) { - final String externalForm = url.toExternalForm(); - for (String pattern : GAE_URL_HACKS) { - final int index = externalForm.indexOf(pattern); - if (index == 0) { - String contentString = externalForm.substring(pattern.length()); - if (contentString.startsWith("'") && contentString.endsWith("'")) { - contentString = contentString.substring(1, contentString.length() - 1); - } - if (LOG.isDebugEnabled()) { - LOG.debug("special handling of URL, returning (" + contentString + ") for URL " + url); - } - return new StringWebResponse(contentString, url); - } - } - return null; - } - - /** - * Parses the given string into cookies. - * Very limited implementation. - * All created cookies apply to all paths, never expire and are not secure. - * Will not work when there's a comma in the cookie value (because there's a bug in the Url Fetch Service) - * @see "http://code.google.com/p/googleappengine/issues/detail?id=3379" - * @param cookieHeaderString The cookie string to parse - * @param domain the domain of the current request - * @return The parsed cookies - */ - static Set<Cookie> parseCookies(final String domain, final String cookieHeaderString) { - final Set<Cookie> cookies = new HashSet<>(); - final String[] cookieStrings = cookieHeaderString.split(","); - for (int i = 0; i < cookieStrings.length; i++) { - final String[] nameAndValue = cookieStrings[i].split(";")[0].split("="); - if (nameAndValue.length > 1) { - cookies.add(new Cookie(domain, nameAndValue[0], nameAndValue[1])); - } - } - return cookies; - } - - /** - * {@inheritDoc} - */ - @Override - public void close() throws Exception { - } -} Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2018-03-30 08:17:57 UTC (rev 15214) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2018-03-30 08:55:15 UTC (rev 15215) @@ -70,7 +70,6 @@ import com.gargoylesoftware.htmlunit.activex.javascript.msxml.MSXMLActiveXObjectFactory; import com.gargoylesoftware.htmlunit.attachment.Attachment; import com.gargoylesoftware.htmlunit.attachment.AttachmentHandler; -import com.gargoylesoftware.htmlunit.gae.GAEUtils; import com.gargoylesoftware.htmlunit.html.BaseFrameElement; import com.gargoylesoftware.htmlunit.html.DomElement; import com.gargoylesoftware.htmlunit.html.DomNode; @@ -245,7 +244,7 @@ getOptions().setProxyConfig(new ProxyConfig(proxyHost, proxyPort)); } - webConnection_ = createWebConnection(); // this has to be done after the browser version was set + webConnection_ = new HttpWebConnection(this); // this has to be done after the browser version was set scriptEngine_ = new JavaScriptEngine(this); loadQueue_ = new ArrayList<>(); @@ -2050,7 +2049,7 @@ private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); - webConnection_ = createWebConnection(); + webConnection_ = new HttpWebConnection(this); scriptEngine_ = new JavaScriptEngine(this); jobManagers_ = Collections.synchronizedList(new ArrayList<WeakReference<JavaScriptJobManager>>()); loadQueue_ = new ArrayList<>(); @@ -2060,14 +2059,6 @@ } } - private WebConnection createWebConnection() { - if (GAEUtils.isGaeMode()) { - return new UrlFetchWebConnection(this); - } - - return new HttpWebConnection(this); - } - private static class LoadJob { private final WebWindow requestingWindow_; private final String target_; Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java 2018-03-30 08:17:57 UTC (rev 15214) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomElement.java 2018-03-30 08:55:15 UTC (rev 15215) @@ -860,7 +860,6 @@ * @return the page contained in the current window as returned by {@link WebClient#getCurrentWindow()} * @exception IOException if an IO error occurs */ - @SuppressWarnings("unchecked") public <P extends Page> P click() throws IOException { return click(false, false, false); } @@ -1102,7 +1101,6 @@ * @return the page that occupies this element's window after the element has been double-clicked * @exception IOException if an IO error occurs */ - @SuppressWarnings("unchecked") public <P extends Page> P dblClick() throws IOException { return dblClick(false, false, false); } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java 2018-03-30 08:17:57 UTC (rev 15214) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java 2018-03-30 08:55:15 UTC (rev 15215) @@ -671,19 +671,6 @@ } /** - * Executes the jobs in the eventLoop till timeoutMillis expires or the eventLoop becomes empty. - * No use in non-GAE mode (see {@link com.gargoylesoftware.htmlunit.gae.GAEUtils#isGaeMode}. - * @param timeoutMillis the timeout in milliseconds - * @return the number of jobs executed - */ - public int pumpEventLoop(final long timeoutMillis) { - if (javaScriptExecutor_ == null) { - return 0; - } - return javaScriptExecutor_.pumpEventLoop(timeoutMillis); - } - - /** * Shutdown the JavaScriptEngine. */ @Override Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/background/DefaultJavaScriptExecutor.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/background/DefaultJavaScriptExecutor.java 2018-03-30 08:17:57 UTC (rev 15214) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/background/DefaultJavaScriptExecutor.java 2018-03-30 08:55:15 UTC (rev 15215) @@ -120,17 +120,6 @@ return javaScriptJobManager; } - /** - * Executes the jobs in the eventLoop till timeoutMillis expires or the eventLoop becomes empty. - * No use in non-GAE mode. - * @param timeoutMillis the timeout in milliseconds - * @return the number of jobs executed - */ - @Override - public int pumpEventLoop(final long timeoutMillis) { - return 0; - } - /** Runs the eventLoop. */ @Override public void run() { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/background/JavaScriptExecutor.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/background/JavaScriptExecutor.java 2018-03-30 08:17:57 UTC (rev 15214) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/background/JavaScriptExecutor.java 2018-03-30 08:55:15 UTC (rev 15215) @@ -37,12 +37,4 @@ * Notes that this thread has been shutdown. */ void shutdown(); - - /** - * Executes the jobs in the eventLoop till timeoutMillis expires or the eventLoop becomes empty. - * No use in non-GAE mode. - * @param timeoutMillis the timeout in milliseconds - * @return the number of jobs executed - */ - int pumpEventLoop(long timeoutMillis); } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/canvas/rendering/RenderingBackend.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/canvas/rendering/RenderingBackend.java 2018-03-30 08:17:57 UTC (rev 15214) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/canvas/rendering/RenderingBackend.java 2018-03-30 08:55:15 UTC (rev 15215) @@ -21,7 +21,6 @@ /** * Interface to the rendering context used by * {@link com.gargoylesoftware.htmlunit.javascript.host.canvas.CanvasRenderingContext2D}. - * We have this abstraction to support GAE also. * * @author Ronald Brill */ Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/MatrixTransformer.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/MatrixTransformer.java 2018-03-30 08:17:57 UTC (rev 15214) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/svg/MatrixTransformer.java 2018-03-30 08:55:15 UTC (rev 15215) @@ -19,7 +19,7 @@ import java.io.Serializable; /** - * Interface redirection to support GAE also. + * Helper to support various matrix transform operations. * * @author Ronald Brill */ Deleted: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/URLCreator.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/URLCreator.java 2018-03-30 08:17:57 UTC (rev 15214) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/URLCreator.java 2018-03-30 08:55:15 UTC (rev 15215) @@ -1,137 +0,0 @@ -/* - * Copyright (c) 2002-2018 Gargoyle Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.gargoylesoftware.htmlunit.util; - -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLStreamHandler; -import java.util.Locale; - -import org.apache.commons.lang3.StringUtils; - -import com.gargoylesoftware.htmlunit.WebClient; -import com.gargoylesoftware.htmlunit.gae.GAEUtils; -import com.gargoylesoftware.htmlunit.protocol.AnyHandler; -import com.gargoylesoftware.htmlunit.protocol.javascript.JavaScriptURLConnection; - -/** - * Responsible for URL creation. - * @author Marc Guillemot - */ -abstract class URLCreator { - abstract URL toUrlUnsafeClassic(String url) throws MalformedURLException; - abstract String getProtocol(URL url); - - protected URL toNormalUrl(final String url) throws MalformedURLException { - final URL response = new URL(url); - if (response.getProtocol().startsWith("http") && StringUtils.isEmpty(response.getHost())) { - throw new MalformedURLException("Missing host name in url: " + url); - } - return response; - } - - /** - * Gets the instance responsible for URL creating, detecting if we are running on GoogleAppEngine - * where custom URLStreamHandler is prohibited. - */ - static URLCreator getCreator() { - if (!GAEUtils.isGaeMode()) { - return new URLCreatorStandard(); - } - return new URLCreatorGAE(); - } - - /** - * For the normal case. - */ - static class URLCreatorStandard extends URLCreator { - private static final URLStreamHandler JS_HANDLER - = new com.gargoylesoftware.htmlunit.protocol.javascript.Handler(); - private static final URLStreamHandler ABOUT_HANDLER - = new com.gargoylesoftware.htmlunit.protocol.about.Handler(); - private static final URLStreamHandler DATA_HANDLER = new com.gargoylesoftware.htmlunit.protocol.data.Handler(); - - @Override - URL toUrlUnsafeClassic(final String url) throws MalformedURLException { - final String protocol = StringUtils.substringBefore(url, ":") - .toLowerCase(Locale.ROOT); - - if (protocol.isEmpty() || UrlUtils.isNormalUrlProtocol(protocol)) { - return toNormalUrl(url); - } - else if (JavaScriptURLConnection.JAVASCRIPT_PREFIX.equals(protocol + ":")) { - return new URL(null, url, JS_HANDLER); - } - else if ("about".equals(protocol)) { - if (WebClient.URL_ABOUT_BLANK != null - && StringUtils.equalsIgnoreCase(WebClient.URL_ABOUT_BLANK.toExternalForm(), url)) { - return WebClient.URL_ABOUT_BLANK; - } - return new URL(null, url, ABOUT_HANDLER); - } - else if ("data".equals(protocol)) { - return new URL(null, url, DATA_HANDLER); - } - else { - return new URL(null, url, AnyHandler.INSTANCE); - } - } - - @Override - String getProtocol(final URL url) { - return url.getProtocol(); - } - } - - /** - * For working on GoogleAppEngine. The URL hack will require special handling from a dedicated WebConnection. - */ - static class URLCreatorGAE extends URLCreator { - private static final String PREFIX = "http://gaeHack_"; - - @Override - URL toUrlUnsafeClassic(final String url) throws MalformedURLException { - if (WebClient.URL_ABOUT_BLANK != null - && StringUtils.equalsIgnoreCase(WebClient.URL_ABOUT_BLANK.toExternalForm(), url)) { - return WebClient.URL_ABOUT_BLANK; - } - else if (StringUtils.startsWithIgnoreCase(url, JavaScriptURLConnection.JAVASCRIPT_PREFIX)) { - return new URL(PREFIX + url.replaceFirst(":", "/")); - } - else if (StringUtils.startsWithIgnoreCase(url, WebClient.ABOUT_SCHEME)) { - return new URL(PREFIX + url.replaceFirst(":", "/")); - } - else if (StringUtils.startsWithIgnoreCase(url, "data:")) { - return new URL(PREFIX + url.replaceFirst(":", "/")); - } - else { - return toNormalUrl(url); - } - } - - @Override - String getProtocol(final URL url) { - final String stringUrl = url.toString(); - if (stringUrl.startsWith(PREFIX)) { - final int begin = PREFIX.length(); - final int end = stringUrl.indexOf('/', begin); - return stringUrl.substring(begin, end); - } - - return url.getProtocol(); - } - } -} - Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/UrlUtils.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/UrlUtils.java 2018-03-30 08:17:57 UTC (rev 15214) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/UrlUtils.java 2018-03-30 08:55:15 UTC (rev 15215) @@ -21,13 +21,18 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URL; +import java.net.URLStreamHandler; import java.nio.charset.Charset; import java.util.BitSet; +import java.util.Locale; import org.apache.commons.codec.DecoderException; import org.apache.commons.codec.net.URLCodec; import com.gargoylesoftware.htmlunit.WebAssert; +import com.gargoylesoftware.htmlunit.WebClient; +import com.gargoylesoftware.htmlunit.protocol.AnyHandler; +import com.gargoylesoftware.htmlunit.protocol.javascript.JavaScriptURLConnection; /** * URL utilities class that makes it easy to create new URLs based off of old URLs @@ -43,11 +48,14 @@ * @author Hartmut Arlt */ public final class UrlUtils { + private static final URLStreamHandler JS_HANDLER = new com.gargoylesoftware.htmlunit.protocol.javascript.Handler(); + private static final URLStreamHandler ABOUT_HANDLER = new com.gargoylesoftware.htmlunit.protocol.about.Handler(); + private static final URLStreamHandler DATA_HANDLER = new com.gargoylesoftware.htmlunit.protocol.data.Handler(); + private static final BitSet PATH_ALLOWED_CHARS = new BitSet(256); private static final BitSet QUERY_ALLOWED_CHARS = new BitSet(256); private static final BitSet ANCHOR_ALLOWED_CHARS = new BitSet(256); private static final BitSet HASH_ALLOWED_CHARS = new BitSet(256); - private static final URLCreator URL_CREATOR = URLCreator.getCreator(); /** * URI allowed char initialization; based on HttpClient 3.1's URI bit sets. @@ -203,7 +211,36 @@ */ public static URL toUrlUnsafe(final String url) throws MalformedURLException { WebAssert.notNull("url", url); - return URL_CREATOR.toUrlUnsafeClassic(url); + + final String protocol = org.apache.commons.lang3.StringUtils.substringBefore(url, ":").toLowerCase(Locale.ROOT); + + if (protocol.isEmpty() || UrlUtils.isNormalUrlProtocol(protocol)) { + final URL response = new URL(url); + if (response.getProtocol().startsWith("http") + && org.apache.commons.lang3.StringUtils.isEmpty(response.getHost())) { + throw new MalformedURLException("Missing host name in url: " + url); + } + return response; + } + + if (JavaScriptURLConnection.JAVASCRIPT_PREFIX.equals(protocol + ":")) { + return new URL(null, url, JS_HANDLER); + } + + if ("about".equals(protocol)) { + if (WebClient.URL_ABOUT_BLANK != null + && org.apache.commons.lang3.StringUtils. + equalsIgnoreCase(WebClient.URL_ABOUT_BLANK.toExternalForm(), url)) { + return WebClient.URL_ABOUT_BLANK; + } + return new URL(null, url, ABOUT_HANDLER); + } + + if ("data".equals(protocol)) { + return new URL(null, url, DATA_HANDLER); + } + + return new URL(null, url, AnyHandler.INSTANCE); } /** @@ -218,7 +255,7 @@ * @return the encoded URL */ public static URL encodeUrl(final URL url, final boolean minimalQueryEncoding, final Charset charset) { - if (!isNormalUrlProtocol(URL_CREATOR.getProtocol(url))) { + if (!isNormalUrlProtocol(url.getProtocol())) { return url; // javascript:, about:, data: and anything not supported like foo: } Deleted: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnection2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnection2Test.java 2018-03-30 08:17:57 UTC (rev 15214) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnection2Test.java 2018-03-30 08:55:15 UTC (rev 15215) @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2002-2018 Gargoyle Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.gargoylesoftware.htmlunit; - -import org.junit.Test; -import org.junit.runner.RunWith; - -/** - * Unit tests for {@link UrlFetchWebConnection}. - * - * @author Marc Guillemot - * @author Pieter Herroelen - */ -@RunWith(BrowserRunner.class) -public class UrlFetchWebConnection2Test extends SimpleWebTestCase { - - /** - * Test a HEAD request with additional headers. - * @throws Exception if the test fails - */ - @Test - public void head() throws Exception { - final WebRequest referenceRequest = getHeadRequest(); - - getWebClient().setWebConnection(new UrlFetchWebConnection(getWebClient())); - final WebRequest newRequest = getHeadRequest(); - - // compare the two requests - UrlFetchWebConnectionTest.compareRequests(referenceRequest, newRequest); - } - - private WebRequest getHeadRequest() throws Exception { - final String html = "<html><head><script>\n" - + " function test() {\n" - + " var request = new XMLHttpRequest();\n" - + " request.open('HEAD', 'second.html', false);\n" - + " request.setRequestHeader('X-Foo', '123456');\n" - + " request.send('');\n" - + " }\n" - + "</script></head><body onload='test()'></body></html>"; - - getMockWebConnection().setDefaultResponse(""); - loadPage(html); - - return getMockWebConnection().getLastWebRequest(); - } - -} Deleted: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnectionTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnectionTest.java 2018-03-30 08:17:57 UTC (rev 15214) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/UrlFetchWebConnectionTest.java 2018-03-30 08:55:15 UTC (rev 15215) @@ -1,272 +0,0 @@ -/* - * Copyright (c) 2002-2018 Gargoyle Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.gargoylesoftware.htmlunit; - -import java.io.IOException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.TreeMap; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; - -import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; -import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; -import com.gargoylesoftware.htmlunit.html.HtmlPage; -import com.gargoylesoftware.htmlunit.util.Cookie; -import com.gargoylesoftware.htmlunit.util.NameValuePair; - -/** - * Unit tests for {@link UrlFetchWebConnection}. - * - * @author Marc Guillemot - * @author Pieter Herroelen - * @author Ronald Brill - */ -@RunWith(BrowserRunner.class) -public class UrlFetchWebConnectionTest extends WebServerTestCase { - - private static final String allowRestrictedHeaders = System.getProperty("sun.net.http.allowRestrictedHeaders"); - - /** - * Setup jdk / HttpURLConnection - * to support all headers (Origin in this case). - * - * see https://stackoverflow.com/questions/8335501/does-httpurlconnection-censor-some-headers-notably-origin - * see https://stackoverflow.com/questions/13255051/ - * setting-origin-and-access-control-request-method-headers-with-jersey-client - */ - @BeforeClass - public static void beforeClass() { - System.setProperty("sun.net.http.allowRestrictedHeaders", "true"); - } - - /** - * Saves HTML and PNG files. - * - * @throws IOException if an error occurs - */ - @AfterClass - public static void saveAll() throws IOException { - if (allowRestrictedHeaders == null) { - System.setProperty("sun.net.http.allowRestrictedHeaders", "false"); - } - else { - System.setProperty("sun.net.http.allowRestrictedHeaders", allowRestrictedHeaders); - } - } - - /** - * Tests a simple GET. - * @throws Exception if the test fails - */ - @Test - public void get() throws Exception { - doGetTest(URL_FIRST); - } - - /** - * GET with query parameters. - * @throws Exception if the test fails - */ - @Test - public void get_withQueryParameters() throws Exception { - final URL url = new URL(URL_FIRST, "?a=b&c=d&e=f"); - doGetTest(url); - } - - private void doGetTest(final URL url) throws Exception { - // get with default WebConnection - getMockWebConnection().setDefaultResponse(""); - loadPage("", url); - final WebRequest referenceRequest = getMockWebConnection().getLastWebRequest(); - - // get with UrlFetchWebConnection - final WebClient wc = getWebClient(); - wc.setWebConnection(new UrlFetchWebConnection(wc)); - wc.getPage(url); - final WebRequest newRequest = getMockWebConnection().getLastWebRequest(); - - // compare the two requests - compareRequests(referenceRequest, newRequest); - } - - /** - * Simple POST url-encoded. - * @throws Exception if the test fails - */ - @Test - public void post() throws Exception { - final WebRequest referenceRequest = getPostRequest(FormEncodingType.URL_ENCODED); - - getWebClient().setWebConnection(new UrlFetchWebConnection(getWebClient())); - final WebRequest newRequest = getPostRequest(FormEncodingType.URL_ENCODED); - - // compare the two requests - compareRequests(referenceRequest, newRequest); - } - - private WebRequest getPostRequest(final FormEncodingType encoding) throws Exception { - final String html = "<html><body><form action='foo' method='post' enctype='" + encoding.getName() + "'>\n" - + "<input name='text1' value='me &amp; you'>\n" - + "<textarea name='text2'>Hello\nworld!</textarea>\n" - + "<input type='submit' id='submit'>\n" - + "</form></body></html>"; - - getMockWebConnection().setDefaultResponse(""); - final HtmlPage page = loadPage(html, URL_FIRST); - page.getHtmlElementById("submit").click(); - return getMockWebConnection().getLastWebRequest(); - } - - /** - * Simple POST multipart. - * This doesn't work currently and the test should be reworked as the boundary for the body varies. - * @throws Exception if the test fails - */ - @NotYetImplemented - @Test - public void post_multipart() throws Exception { - final WebRequest referenceRequest = getPostRequest(FormEncodingType.MULTIPART); - - getWebClient().setWebConnection(new UrlFetchWebConnection(getWebClient())); - final WebRequest newRequest = getPostRequest(FormEncodingType.MULTIPART); - - // compare the two requests - compareRequests(referenceRequest, newRequest); - } - - /** - * @throws Exception if the test fails - */ - @Test - @Alerts("my_key=Hello") - public void cookie() throws Exception { - final List<NameValuePair> responseHeader = new ArrayList<>(); - responseHeader.add(new NameValuePair("Set-Cookie", "my_key=Hello")); - getMockWebConnection().setDefaultResponse(CookieManagerTest.HTML_ALERT_COOKIE, - 200, "OK", "text/html", responseHeader); - - // verify expectations with "normal" HTMLUnit - loadPageWithAlerts(URL_FIRST); - - getWebClient().getCookieManager().clearCookies(); - getWebClient().setWebConnection(new UrlFetchWebConnection(getWebClient())); - loadPageWithAlerts(URL_FIRST); - } - - static void compareRequests(final WebRequest referenceRequest, final WebRequest newRequest) { - assertEquals(referenceRequest.getRequestBody(), newRequest.getRequestBody()); - assertEquals(referenceRequest.getCharset(), newRequest.getCharset()); - assertEquals(referenceRequest.getProxyHost(), newRequest.getProxyHost()); - assertEquals(referenceRequest.getUrl(), newRequest.getUrl()); - assertEquals(referenceRequest.getEncodingType(), newRequest.getEncodingType()); - assertEquals(referenceRequest.getHttpMethod(), newRequest.getHttpMethod()); - assertEquals(referenceRequest.getProxyPort(), newRequest.getProxyPort()); - assertEquals(referenceRequest.getRequestParameters().toString(), newRequest.getRequestParameters().toString()); - - // java U - // https://stackoverflow.com/questions/8335501/does-httpurlconnection-censor-some-headers-notably-origin - assertEquals(headersToString(referenceRequest), headersToString(newRequest)); - } - - private static String headersToString(final WebRequest request) { - final Set<String> caseInsensitiveHeaders = new HashSet<>(Arrays.asList(HttpHeader.CONNECTION)); - - final StringBuilder sb = new StringBuilder(); - // ensure ordering for comparison - final Map<String, String> headers = new TreeMap<>(request.getAdditionalHeaders()); - for (final Entry<String, String> headerEntry : headers.entrySet()) { - sb.append(headerEntry.getKey()); - sb.append(": "); - if (caseInsensitiveHeaders.contains(headerEntry.getKey())) { - sb.append(headerEntry.getValue().toLowerCase(Locale.ROOT)); - } - else { - sb.append(headerEntry.getValue()); - } - sb.append("\n"); - } - return sb.toString(); - } - - /** - * Tests that an empty string is parsed into zero cookies. - */ - @Test - public void emptyStringHasNoCookies() { - assertTrue(UrlFetchWebConnection.parseCookies("www.foo.com", "").isEmpty()); - } - - /** - * Tests that a string with one cookie is parsed into one cookie with the right name and value. - */ - @Test - public void oneCookieStringHasOneCookie() { - final String cookieHeader = "Name=Value; expires=Fri, 18-Nov-2011 21:13:50 GMT"; - final Set<Cookie> cookies = UrlFetchWebConnection.parseCookies("www.foo.com", cookieHeader); - final Cookie cookie = cookies.iterator().next(); - assertEquals(1, cookies.size()); - assertEquals("Name", cookie.getName()); - assertEquals("Value", cookie.getValue()); - } - - /** - * Tests that a string with three cookies is parsed into three cookies. - */ - @Test - public void threeCookiesStringHasThreeCookies() { - final String cookieHeader = ".ASPXANONYMOUS=sl7T9zamzAEkAAAAY2RmY2U1MWEtMzllYy00MDk1LThmNDMtM2U0MzBiMmEyMTFi0;" - + " expires=Fri, 18-Nov-2011 21:13:50 GMT; path=/; HttpOnly, ASP.NET_SessionId=dqsvrc45gpj51f45n0c1q4qa;" - + " path=/; HttpOnly, language=en-US; path=/; HttpOnly"; - assertEquals(3, UrlFetchWebConnection.parseCookies("www.foo.com", cookieHeader).size()); - } - - /** - * Test that redirects are handled by the WebClient and not by the UrlFetchWebConnection (issue #3557486). - * @throws Exception if the test fails. - */ - @Test - public void redirect() throws Exception { - final String html = "<html></html>"; - - // get with default WebConnection - final List<NameValuePair> headers = Collections.singletonList( - new NameValuePair("Location", URL_SECOND.toString())); - final MockWebConnection conn = getMockWebConnection(); - conn.setResponse(URL_FIRST, "", 302, "Some error", "text/html", headers); - conn.setResponse(URL_SECOND, html); - - Page page = loadPageWithAlerts(URL_FIRST); - assertEquals(URL_SECOND, page.getUrl()); - - // get with UrlFetchWebConnection - final WebClient wc = getWebClient(); - wc.setWebConnection(new UrlFetchWebConnection(wc)); - - page = loadPageWithAlerts(URL_FIRST); - assertEquals(URL_SECOND, page.getUrl()); - } -} Deleted: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/background/JavaScriptJobManagerGaeMinimalTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/background/JavaScriptJobManagerGaeMinimalTest.java 2018-03-30 08:17:57 UTC (rev 15214) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/background/JavaScriptJobManagerGaeMinimalTest.java 2018-03-30 08:55:15 UTC (rev 15215) @@ -1,242 +0,0 @@ -/* - * Copyright (c) 2002-2018 Gargoyle Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.gargoylesoftware.htmlunit.javascript.background; - -import static org.junit.Assert.assertEquals; - -import org.apache.commons.lang3.mutable.MutableInt; -import org.easymock.EasyMock; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; - -import com.gargoylesoftware.htmlunit.Page; -import com.gargoylesoftware.htmlunit.WebClient; -import com.gargoylesoftware.htmlunit.WebWindow; -import com.gargoylesoftware.htmlunit.gae.GAETestRunner; - -/** - * Minimal tests for {@link JavaScriptJobManagerImpl} on GoogleAppEngine. - * - * @author Amit Manjhi - */ -@Ignore -@RunWith(GAETestRunner.class) -public class JavaScriptJobManagerGaeMinimalTest { - - private WebClient client_; - private WebWindow window_; - private Page page_; - private JavaScriptJobManagerImpl manager_; - private DefaultJavaScriptExecutor eventLoop_; - enum WaitingMode { - WAIT_STARTING_BEFORE, WAIT_TIMELIMIT, - } - - /** - * Initializes variables required by the unit tests. - */ - @Before - public void before() { - // set the GAE mode - client_ = new WebClient(); - window_ = EasyMock.createNiceMock(WebWindow.class); - page_ = EasyMock.createNiceMock(Page.class); - manager_ = new JavaScriptJobManagerImpl(window_); - EasyMock.expect(window_.getEnclosedPage()).andReturn(page_).anyTimes(); - EasyMock.expect(window_.getJobManager()).andReturn(manager_).anyTimes(); - EasyMock.replay(window_, page_); - eventLoop_ = new GAEJavaScriptExecutor(client_); - eventLoop_.addWindow(window_); - } - - /** - * Shuts down the event loop. - */ - @After - public void after() { - if (eventLoop_ != null) { - eventLoop_.shutdown(); - } - if (client_ != null) { - client_.close(); - } - } - - /** - * @throws Exception if an error occurs - */ - @Test - public void addJob_singleExecution() throws Exception { - final MutableInt count = new MutableInt(0); - final JavaScriptJob job = new BasicJavaScriptJob(5, null) { - @Override - public void run() { - count.increment(); - } - }; - manager_.addJob(job, page_); - assertEquals(1, manager_.getJobCount()); - final int executedJobs = eventLoop_.pumpEventLoop(10_000); - assertEquals(1, executedJobs); - assertEquals(1, count.intValue()); - assertEquals(0, manager_.getJobCount()); - } - - /** - * @throws Exception if an error occurs - */ - @Test - public void addJob_multipleExecution_removeJob() throws Exception { - final MutableInt id = new MutableInt(); - final MutableInt count = new MutableInt(0); - final JavaScriptJob job = new BasicJavaScriptJob(50, Integer.valueOf(50)) { - @Override - public void run() { - count.increment(); - if (count.intValue() >= 5) { - manager_.removeJob(id.intValue()); - } - } - }; - id.setValue(manager_.addJob(job, page_)); - final int executedJobs = eventLoop_.pumpEventLoop(1000); - assertEquals(5, executedJobs); - assertEquals(5, count.intValue()); - } - - /** - * @throws Exception if an error occurs - */ - @Test - public void addJob_multipleExecution_removeAllJobs() throws Exception { - final MutableInt count = new MutableInt(0); - final JavaScriptJob job = new BasicJavaScriptJob(50, Integer.valueOf(50)) { - @Override - public void run() { - count.increment(); - if (count.intValue() >= 5) { - manager_.removeAllJobs(); - } - } - }; - manager_.addJob(job, page_); - final int executedJobs = eventLoop_.pumpEventLoop(1000); - assertEquals(5, executedJobs); - assertEquals(5, count.intValue()); - } - - /** - * @throws Exception if an error occurs - */ - @Test - public void getJobCount() throws Exception { - final MutableInt count = new MutableInt(); - final JavaScriptJob job = new BasicJavaScriptJob(50, null) { - @Override - public void run() { - count.setValue(manager_.getJobCount()); - } - }; - assertEquals(0, manager_.getJobCount()); - manager_.addJob(job, page_); - final int executedJobs = eventLoop_.pumpEventLoop(1000); - assertEquals(1, executedJobs); - assertEquals(1, count.intValue()); - assertEquals(0, manager_.getJobCount()); - } - - /** - * Tests waiting for the current job. - */ - @Test - public void waitForCurrentLongJob() { - final JavaScriptJob job = new BasicJavaScriptJob(50, null) { - // Long job - @Override - public void run() { - try { - Thread.sleep(500); - } - catch (final InterruptedException e) { - // ignore - } - } - }; - assertEquals(0, manager_.getJobCount()); - manager_.addJob(job, page_); - final int executedJobs = eventLoop_.pumpEventLoop(1000); - assertEquals(1, executedJobs); - assertEquals(0, manager_.getJobCount()); - } - - /** - * Tests if waiting for simple jobs works. - */ - @Test - public void waitForSimpleJobs() { - final JavaScriptJob job1 = new BasicJavaScriptJob(50, null) { - @Override - public void run() { - // Empty. - } - }; - final JavaScriptJob job2 = new BasicJavaScriptJob(1000, null) { - @Override - public void run() { - // Empty. - } - }; - assertEquals(0, manager_.getJobCount()); - manager_.addJob(job1, page_); - manager_.addJob(job2, page_); - final int executedJobs = eventLoop_.pumpEventLoop(200); - assertEquals(1, executedJobs); - assertEquals(1, manager_.getJobCount()); - } - - /** - * Tests if waiting for complex jobs work. - */ - @Test - public void waitForComplexJobs() { - final JavaScriptJob job1 = new BasicJavaScriptJob(50, null) { - // This job takes 30ms to complete. - @Override - public void run() { - try { - Thread.sleep(30); - } - catch (final InterruptedException e) { - // ignore - } - } - }; - final JavaScriptJob job2 = new BasicJavaScriptJob(60, null) { - @Override - public void run() { - // Empty. - } - }; - assertEquals(0, manager_.getJobCount()); - manager_.addJob(job1, page_); - manager_.addJob(job2, page_); - final int executedJobs = eventLoop_.pumpEventLoop(70); - assertEquals(1, executedJobs); - assertEquals(1, manager_.getJobCount()); - } -} Deleted: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/UrlCreatorTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/UrlCreatorTest.java 2018-03-30 08:17:57 UTC (rev 15214) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/UrlCreatorTest.java 2018-03-30 08:55:15 UTC (rev 15215) @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2002-2018 Gargoyle Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.gargoylesoftware.htmlunit.util; - -import static org.junit.Assert.assertEquals; - -import java.net.URL; - -import org.junit.Test; - -import com.gargoylesoftware.htmlunit.util.URLCreator.URLCreatorGAE; - -/** - * Tests for {@link URLCreator}. - * - * @author Marc Guillemot - */ -public class UrlCreatorTest { - - /** - * @throws Exception if the test fails - */ - @Test - public void gaeGetProtocol() throws Exception { - final URLCreatorGAE creator = new URLCreator.URLCreatorGAE(); - - final URL url = creator.toUrlUnsafeClassic("data:text/javascript,d1%20%3D%20'one'%3B"); - assertEquals("http://gaeHack_data/text/javascript,d1%20%3D%20'one'%3B", url.toString()); - assertEquals("data", creator.getProtocol(url)); - } -} |