diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml index 205db2f9460..61afd4de5a2 100644 --- a/.github/workflows/checkstyle.yml +++ b/.github/workflows/checkstyle.yml @@ -22,12 +22,12 @@ jobs: steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Set up JDK - uses: actions/setup-java@7a6d8a8234af8eb26422e24e3006232cccaa061b # v4.6.0 + uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 # v4.7.0 with: java-version: 21 distribution: 'temurin' cache: maven - - uses: reviewdog/action-setup@3f401fe1d58fe77e10d665ab713057375e39b887 # v0.20.1 + - uses: reviewdog/action-setup@e04ffabe3898a0af8d0fb1af00c188831c4b5893 # v0.20.1 name: Set up reviewdog with: reviewdog_version: latest diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index c557dc66663..50c0767f714 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -24,12 +24,12 @@ jobs: steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Set up JDK ${{ matrix.Java }} - uses: actions/setup-java@7a6d8a8234af8eb26422e24e3006232cccaa061b # v4.6.0 + uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 # v4.7.0 with: java-version: ${{ matrix.Java }} distribution: 'temurin' cache: maven - - uses: reviewdog/action-setup@3f401fe1d58fe77e10d665ab713057375e39b887 # v0.20.1 + - uses: reviewdog/action-setup@e04ffabe3898a0af8d0fb1af00c188831c4b5893 # v0.20.1 name: Set up reviewdog with: reviewdog_version: latest diff --git a/.github/workflows/pmd.yml b/.github/workflows/pmd.yml index 9aaf21e9ff6..8e2105e7af5 100644 --- a/.github/workflows/pmd.yml +++ b/.github/workflows/pmd.yml @@ -20,12 +20,12 @@ jobs: steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Set up JDK - uses: actions/setup-java@7a6d8a8234af8eb26422e24e3006232cccaa061b # v4.6.0 + uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 # v4.7.0 with: java-version: 21 distribution: 'temurin' cache: maven - - uses: reviewdog/action-setup@3f401fe1d58fe77e10d665ab713057375e39b887 # v0.20.1 + - uses: reviewdog/action-setup@e04ffabe3898a0af8d0fb1af00c188831c4b5893 # v0.20.1 name: Set up reviewdog with: reviewdog_version: latest diff --git a/.github/workflows/scorecard.yml b/.github/workflows/scorecard.yml index 16327d49eb5..71154a0b1f3 100644 --- a/.github/workflows/scorecard.yml +++ b/.github/workflows/scorecard.yml @@ -37,7 +37,7 @@ jobs: persist-credentials: false - name: "Run analysis" - uses: ossf/scorecard-action@62b2cac7ed8198b15735ed49ab1e5cf35480ba46 # v2.4.0 + uses: ossf/scorecard-action@f49aabe0b5af0936a0987cfb85d86b75731b0186 # v2.4.1 with: results_file: results.sarif results_format: sarif diff --git a/README.md b/README.md index ae6660d8b40..6b62d79ccd8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # ![HtmlUnit Logo](https://github.com/HtmlUnit/htmlunit/blob/master/src/site/resources/images/htmlunit.png) -Version 4.10.0 / February 22, 2025 +Version 4.11.0 / March 25, 2025 :heart: [Sponsor](https://github.com/sponsors/rbri) @@ -51,7 +51,7 @@ Add to your `pom.xml`: org.htmlunit htmlunit - 4.10.0 + 4.11.0 ``` @@ -60,7 +60,7 @@ Add to your `pom.xml`: Add to your `build.gradle`: ```groovy -implementation group: 'org.htmlunit', name: 'htmlunit', version: '4.10.0' +implementation group: 'org.htmlunit', name: 'htmlunit', version: '4.11.0' ``` ## Vulnerabilities @@ -95,6 +95,7 @@ HtmlUnit is used as the underlying "browser" by different Open Source tools like * [WebDriver](https://github.com/SeleniumHQ/selenium) * [Arquillian Drone](https://arquillian.org/arquillian-extension-drone) * [Serenity BDD](https://serenity-bdd.info) + * [XLT](https://www.xceptance.com/en/products/xlt/) * [FluentLenium](https://github.com/FluentLenium/FluentLenium) * [WETATOR](https://www.wetator.org/) * [Selenium Foundation](https://github.com/sbabcoc/Selenium-Foundation) @@ -116,7 +117,9 @@ HtmlUnit is used by many projects for automated web testing * [Apache Maven Surefire](https://maven.apache.org/surefire/) * [JSCover](http://tntim96.github.io/JSCover/) * [Apache Jackrabbit](https://jackrabbit.apache.org/jcr/index.html) + * [Apache MyFaces](https://myfaces.apache.org/) * [JakartaEE TCK](https://github.com/jakartaee/platform-tck) + * [Jakarta Security](https://github.com/jakartaee/security) * [OpenXava](https://github.com/openxava/openxava) * [Cargo](https://github.com/codehaus-cargo/cargo) * [piranha cloud](https://github.com/piranhacloud/piranha) @@ -125,6 +128,7 @@ HtmlUnit is used by many projects for automated web testing ## Getting Started You can start here: * [Getting Started][7] +* [Introduction to HtmlUnit - Baeldung](https://www.baeldung.com/htmlunit) * [The Java Web Scraping Handbook][8] A nice tutorial about webscraping with a lot of background information and details about HtmlUnit. * [Web Scraping][9] Examples how to implement web scraping using HtmlUnit, Selenium or jaunt and compares them. * [The Complete Guide to Web Scraping with Java][10] A small straightforward guide to web scraping with Java. @@ -168,7 +172,7 @@ Add the snapshot repository and dependency to your `pom.xml`: org.htmlunit htmlunit - 4.11.0-SNAPSHOT + 4.12.0-SNAPSHOT @@ -187,7 +191,7 @@ repositories { } // ... dependencies { - implementation group: 'org.htmlunit', name: 'htmlunit', version: '4.11.0-SNAPSHOT' + implementation group: 'org.htmlunit', name: 'htmlunit', version: '4.12.0-SNAPSHOT' // ... } ``` diff --git a/checkstyle.xml b/checkstyle.xml index 46466aa5cdb..4440727915b 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -122,6 +122,10 @@ + + + + @@ -138,6 +142,16 @@ + + + + + + + + + + diff --git a/checkstyle_suppressions.xml b/checkstyle_suppressions.xml index c095435aad1..d5a3ce0ce1b 100644 --- a/checkstyle_suppressions.xml +++ b/checkstyle_suppressions.xml @@ -39,7 +39,7 @@ - + diff --git a/pom.xml b/pom.xml index fbb70c8294d..cd502d1f6e0 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.htmlunit htmlunit - 4.10.0 + 4.11.0 HtmlUnit Gargoyle Software Inc. @@ -25,36 +25,35 @@ 8 8 - 4.10.0 - 4.10.0 - 4.10.0 - 4.10.0 - 4.10.0 - 4.10.0 + 4.11.0 + 4.11.0 + 4.11.0 + 4.11.0 + 4.11.0 + 4.11.0 4.5.14 3.17.0 2.18.0 1.3.5 - 1.18.0 0.1.2 - 4.29.0 - 4.29.0 - selenium-devtools-v133 + 4.30.0 + 4.30.0 + selenium-devtools-v134 9.4.57.v20241219 4.0.66 2.24.3 - 2.0.16 + 2.0.17 1.5 4.4.0 1.5.5 - 10.21.2 - 4.9.1 - 7.10.0 + 10.21.4 + 4.9.3 + 7.11.0 4.13.2 1.4.0 10.0.4 @@ -87,7 +86,7 @@ com.github.spotbugs spotbugs-maven-plugin - 4.9.1.0 + 4.9.3.0 com.github.spotbugs @@ -208,7 +207,7 @@ true protected - html,missing,reference,syntax + html,reference,syntax true true org.htmlunit.platform.util @@ -289,11 +288,10 @@ - @@ -691,7 +688,7 @@ true protected - html,missing,reference,syntax + html,reference,syntax true true org.htmlunit.platform.util @@ -707,7 +704,7 @@ org.apache.maven.plugins maven-project-info-reports-plugin - 3.8.0 + 3.9.0 org.apache.maven.plugins @@ -1205,6 +1202,9 @@ Markus Winter + + Christoph Burgmer + @@ -1213,10 +1213,6 @@ httpmime ${httpcomponents.version} - - commons-codec - commons-codec - commons-logging commons-logging @@ -1276,11 +1272,6 @@ commons-logging ${commons-logging.version} - - commons-codec - commons-codec - ${commons-codec.version} - org.brotli dec diff --git a/src/changes/changes.xml b/src/changes/changes.xml index cc2736a1feb..2983f71f35c 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -7,9 +7,97 @@ + + + Event 'onload' is trigger by FF ESR also if the frame content was not shown because of csp. + + + Initial support for font sizes 'xx-small', 'x-small', 'small', 'medium', 'large', + 'x-large', 'xx-large', 'xxx-large'., 'smaller', and 'larger'. + + + core-js: Refactor NativeString based on lambdas and stop using IdScriptableObject. + + + The style cache has to handle all parents of added or deleted nodes. + + + Class HiddenFunctionObject removed, this was a leftover from the IE age. + + + core-js: Arguments.callee is always the same function in strict mode. + + + core-js: Arguments.caller is not available in real browsers. + + + core-js: An issue where capture groups in quantified expressions (min = 2) were not cleared between iterations fixed. + For example, in /(?:(\2)(\d)){2}/, during the second iteration, \2 incorrectly retained the first iteration's value instead of being reset. + + + Switched back from our RegExp translation into java regular expressions to use the core Rhino stuff. Rhino mades significant + progress in this arae. This simplifies out impl and supports more features in the future. + + + core-js: RegExp lookbehind implemented. + + + core-js: NativeObject converted from IdScriptableObject to lambda constructor + + + core-js: problem with 'super' and nested lambdas + + + core-js: RegExp.prototype[Symbol.match] and String.prototype.match. + + + core-js: Implement Symbol.match. + + + core-js: String.prototype.match. As per the spec, it is simply supposed to invoke the Symbol.match of the regexp. + + + core-js: Fix the behaviour of Regexp sticky flag. + + + Deprecated methods removed from EncodingSniffer, HttpClientConverter, WebResponse, and WebResponseWrapper. + + + cssparser: improved support for var initial values. + + + Apache commons-codec is no longer a runtime dependency. + + + atob() has to remove all whitespace from the provided string. + + + atob() must always fail on invalid input. + + + The script async attribute is ignored if the src attribute is absent. + + + Many more checkstyle jdoc rules enabled and all violations fixed. + + + HtmlImage onerror event is triggerd for 204 responses. + + + Some minor code improvements found by spotbugs. + + + Some more event initialization fixes. + + + Fix various event initialization when working with WebSocket's. + + + + - NativeGlobal now based on lambda functions. + core-js: NativeGlobal now based on lambda functions. Avoid using XPath for implementing form submit on enter key pressed. diff --git a/src/jenkins/huge-tests-m-o b/src/jenkins/huge-tests-m-o index cdd22ad9987..4b04403eeb3 100644 --- a/src/jenkins/huge-tests-m-o +++ b/src/jenkins/huge-tests-m-o @@ -4,7 +4,7 @@ pipeline { lock resource: 'htmlunit-test-ports' disableConcurrentBuilds() timestamps() - timeout(time: 15, unit: 'MINUTES') + timeout(time: 35, unit: 'MINUTES') } tools { jdk 'openjdk-11+28' diff --git a/src/main/java/org/htmlunit/BrowserVersion.java b/src/main/java/org/htmlunit/BrowserVersion.java index b74883169b0..21f04601d44 100644 --- a/src/main/java/org/htmlunit/BrowserVersion.java +++ b/src/main/java/org/htmlunit/BrowserVersion.java @@ -26,6 +26,7 @@ import java.util.TimeZone; import org.apache.commons.io.FilenameUtils; +import org.htmlunit.css.CssPixelValueConverter; import org.htmlunit.javascript.configuration.BrowserFeature; import org.htmlunit.javascript.configuration.SupportedBrowser; import org.htmlunit.util.MimeType; @@ -64,7 +65,7 @@ public final class BrowserVersion implements Serializable { /** Latest Firefox. */ - public static final BrowserVersion FIREFOX = new BrowserVersion(135, "FF"); + public static final BrowserVersion FIREFOX = new BrowserVersion(136, "FF"); private static final int FIREFOX_ESR_NUMERIC = 128; @@ -72,10 +73,10 @@ public final class BrowserVersion implements Serializable { public static final BrowserVersion FIREFOX_ESR = new BrowserVersion(FIREFOX_ESR_NUMERIC, "FF-ESR"); /** Latest Edge. */ - public static final BrowserVersion EDGE = new BrowserVersion(133, "Edge"); + public static final BrowserVersion EDGE = new BrowserVersion(134, "Edge"); /** Latest Chrome. */ - public static final BrowserVersion CHROME = new BrowserVersion(133, "Chrome"); + public static final BrowserVersion CHROME = new BrowserVersion(134, "Chrome"); /** * Array with all supported browsers. @@ -197,8 +198,8 @@ public final class BrowserVersion implements Serializable { CHROME.scriptAcceptHeader_ = "*/*"; if (CHROME.getBrowserVersionNumeric() % 2 == 0) { - CHROME.secClientHintUserAgentHeader_ = "\"Not A(Brand\";v=\"8\", \"Chromium\";v=\"" - + CHROME.getBrowserVersionNumeric() + "\", \"Google Chrome\";v=\"" + CHROME.secClientHintUserAgentHeader_ = "\"Chromium\";v=\"" + + CHROME.getBrowserVersionNumeric() + "\", \"Not:A-Brand\";v=\"24\", \"Google Chrome\";v=\"" + CHROME.getBrowserVersionNumeric() + "\""; } else { @@ -250,9 +251,9 @@ public final class BrowserVersion implements Serializable { EDGE.cssAcceptHeader_ = "text/css,*/*;q=0.1"; EDGE.scriptAcceptHeader_ = "*/*"; if (CHROME.getBrowserVersionNumeric() % 2 == 0) { - EDGE.secClientHintUserAgentHeader_ = "\"Microsoft Edge\";v=\"" - + EDGE.getBrowserVersionNumeric() + "\", \"Chromium\";v=\"" - + EDGE.getBrowserVersionNumeric() + "\", \"Not_A Brand\";v=\"24\""; + EDGE.secClientHintUserAgentHeader_ = "\"Chromium\";v=\"" + + EDGE.getBrowserVersionNumeric() + "\", \"Not:A-Brand\";v=\"24\", \"Microsoft Edge\";v=\"" + + EDGE.getBrowserVersionNumeric() + "\""; } else { EDGE.secClientHintUserAgentHeader_ = "\"Not(A:Brand\";v=\"99\", \"Microsoft Edge\";v=\"" @@ -366,7 +367,7 @@ public final class BrowserVersion implements Serializable { FIREFOX.registerUploadMimeType("mp3", "audio/mpeg"); FIREFOX.registerUploadMimeType("ogv", "video/ogg"); FIREFOX.registerUploadMimeType("ogm", "video/ogg"); - FIREFOX.registerUploadMimeType("ogg", "video/ogg"); + FIREFOX.registerUploadMimeType("ogg", "application/ogg"); FIREFOX.registerUploadMimeType("oga", "audio/ogg"); FIREFOX.registerUploadMimeType("opus", "audio/ogg"); FIREFOX.registerUploadMimeType("webm", "video/webm"); @@ -800,13 +801,46 @@ public String getUploadMimeType(final File file) { * @return the corresponding height */ public int getFontHeight(final String fontSize) { - if (fontHeights_ == null) { + if (fontHeights_ == null || fontSize.isEmpty()) { return 18; } - final int fontSizeInt = Integer.parseInt(fontSize.substring(0, fontSize.length() - 2)); + + if ("xx-small".equalsIgnoreCase(fontSize)) { + return fontHeights_[10]; + } + if ("x-small".equalsIgnoreCase(fontSize)) { + return fontHeights_[10]; + } + if ("small".equalsIgnoreCase(fontSize)) { + return fontHeights_[12]; + } + if ("medium".equalsIgnoreCase(fontSize)) { + return fontHeights_[16]; + } + if ("large".equalsIgnoreCase(fontSize)) { + return fontHeights_[18]; + } + if ("x-large".equalsIgnoreCase(fontSize)) { + return fontHeights_[25]; + } + if ("xx-large".equalsIgnoreCase(fontSize)) { + return fontHeights_[32]; + } + if ("xxx-large".equalsIgnoreCase(fontSize)) { + return fontHeights_[48]; + } + if ("smaller".equalsIgnoreCase(fontSize)) { + return fontHeights_[12]; + } + if ("larger".equalsIgnoreCase(fontSize)) { + return fontHeights_[19]; + } + + final int fontSizeInt = CssPixelValueConverter.pixelValue(fontSize); if (fontSizeInt < fontHeights_.length) { return fontHeights_[fontSizeInt]; } + return (int) (fontSizeInt * 1.2); } @@ -1023,7 +1057,7 @@ public BrowserVersionBuilder setScriptAcceptHeader(final String scriptAcceptHead /** * @param xmlHttpRequestAcceptHeader the {@code Accept} header to be used when - * performing XMLHttpRequests + * performing XMLHttpRequests * @return this for fluent use */ public BrowserVersionBuilder setXmlHttpRequestAcceptHeader(final String xmlHttpRequestAcceptHeader) { diff --git a/src/main/java/org/htmlunit/BrowserVersionFeatures.java b/src/main/java/org/htmlunit/BrowserVersionFeatures.java index 25827c41448..e3133d721c7 100644 --- a/src/main/java/org/htmlunit/BrowserVersionFeatures.java +++ b/src/main/java/org/htmlunit/BrowserVersionFeatures.java @@ -220,7 +220,8 @@ public enum BrowserVersionFeatures { @BrowserFeature(FF_ESR) JS_ANCHOR_PATHNAME_DETECT_WIN_DRIVES_URL, - /** The anchor pathname detects url's starting with one letter as file url's + /** + * The anchor pathname detects url's starting with one letter as file url's * and replaces them with the file protocol. */ @BrowserFeature({CHROME, EDGE}) JS_ANCHOR_PATHNAME_DETECT_WIN_DRIVES_URL_REPLACE, @@ -309,11 +310,6 @@ public enum BrowserVersionFeatures { @BrowserFeature({FF, FF_ESR}) JS_EVENT_KEYBOARD_CTOR_WHICH, - /** do not trigger the onload event if the frame content - * was not shown because of the csp. */ - @BrowserFeature(FF_ESR) - JS_EVENT_LOAD_SUPPRESSED_BY_CONTENT_SECURIRY_POLICY, - /** form.dispatchEvent(e) submits the form if the event is of type 'submit'. */ @BrowserFeature({FF, FF_ESR}) JS_FORM_DISPATCHEVENT_SUBMITS, diff --git a/src/main/java/org/htmlunit/Cache.java b/src/main/java/org/htmlunit/Cache.java index 8607c12782b..3b9e14523d0 100644 --- a/src/main/java/org/htmlunit/Cache.java +++ b/src/main/java/org/htmlunit/Cache.java @@ -169,7 +169,7 @@ else if (response.getResponseHeaderValue(HttpHeader.LAST_MODIFIED) != null) { * @param request the request corresponding to the specified compiled script * @param response the response corresponding to the specified compiled script * @param toCache the object that is to be cached, if possible (may be for instance a compiled script or - * simply a WebResponse) + * simply a WebResponse) * @return whether the response was cached or not */ public boolean cacheIfPossible(final WebRequest request, final WebResponse response, final Object toCache) { diff --git a/src/main/java/org/htmlunit/DefaultCredentialsProvider.java b/src/main/java/org/htmlunit/DefaultCredentialsProvider.java index 798e6238e31..b9c3478866e 100644 --- a/src/main/java/org/htmlunit/DefaultCredentialsProvider.java +++ b/src/main/java/org/htmlunit/DefaultCredentialsProvider.java @@ -47,7 +47,7 @@ public class DefaultCredentialsProvider implements CredentialsProvider, Serializ /** The {@code null} value represents any host. */ public static final String ANY_HOST = null; - /**The {@code -1} value represents any port. */ + /** The {@code -1} value represents any port. */ public static final int ANY_PORT = -1; /** The {@code null} value represents any realm. */ diff --git a/src/main/java/org/htmlunit/MockWebConnection.java b/src/main/java/org/htmlunit/MockWebConnection.java index 3bd3126737a..4e28befb684 100644 --- a/src/main/java/org/htmlunit/MockWebConnection.java +++ b/src/main/java/org/htmlunit/MockWebConnection.java @@ -386,7 +386,7 @@ public void setResponse(final URL url, final String content, final String conten * @param title the title of the page */ public void setResponseAsGenericHtml(final URL url, final String title) { - final String content = "" + title + ""; + final String content = "" + title + ""; setResponse(url, content); } diff --git a/src/main/java/org/htmlunit/ProxyConfig.java b/src/main/java/org/htmlunit/ProxyConfig.java index d25dfe5b406..5b3aca2dbf9 100644 --- a/src/main/java/org/htmlunit/ProxyConfig.java +++ b/src/main/java/org/htmlunit/ProxyConfig.java @@ -156,7 +156,7 @@ public void removeHostsFromProxyBypass(final String pattern) { * configured proxy. * @param hostname the name of the host to check * @return {@code true} if the host with the specified hostname should be accessed bypassing the - * configured proxy, {@code false} otherwise. + * configured proxy, {@code false} otherwise. */ protected boolean shouldBypassProxy(final String hostname) { boolean bypass = false; diff --git a/src/main/java/org/htmlunit/ScriptException.java b/src/main/java/org/htmlunit/ScriptException.java index 0f5b9f3bdfb..275b3248f57 100644 --- a/src/main/java/org/htmlunit/ScriptException.java +++ b/src/main/java/org/htmlunit/ScriptException.java @@ -52,8 +52,8 @@ public class ScriptException extends RuntimeException { * @param page the page in which the script causing this exception was executed * @param throwable the exception that was thrown from the script engine * @param scriptSourceCode the code that was being executed when this exception - * was thrown. This may be null if the exception was not caused by execution - * of JavaScript. + * was thrown. This may be null if the exception was not caused by execution + * of JavaScript. */ public ScriptException(final HtmlPage page, final Throwable throwable, final String scriptSourceCode) { @@ -192,7 +192,7 @@ public String getScriptSourceCode() { * thrown. * * @return the line of source or an empty string if the exception was not thrown - * due to the execution of a script. + * due to the execution of a script. */ public String getFailingLine() { final int lineNumber = getFailingLineNumber(); @@ -218,7 +218,7 @@ public String getFailingLine() { * Returns the line number of the source that was executing at the time of the exception. * * @return the line number or -1 if the exception was not thrown due to the - * execution of a script. + * execution of a script. */ public int getFailingLineNumber() { if (getCause() instanceof RhinoException) { @@ -233,7 +233,7 @@ public int getFailingLineNumber() { * Returns the column number of the source that was executing at the time of the exception. * * @return the column number or -1 if the exception was not thrown due to the - * execution of a script. + * execution of a script. */ public int getFailingColumnNumber() { if (getCause() instanceof RhinoException) { diff --git a/src/main/java/org/htmlunit/SgmlPage.java b/src/main/java/org/htmlunit/SgmlPage.java index 80253083678..33250378c75 100644 --- a/src/main/java/org/htmlunit/SgmlPage.java +++ b/src/main/java/org/htmlunit/SgmlPage.java @@ -347,24 +347,23 @@ public Comment createComment(final String data) { * Create a new NodeIterator over the subtree rooted at the * specified node. * @param root The node which will be iterated together with its - * children. The NodeIterator is initially positioned - * just before this node. The whatToShow flags and the - * filter, if any, are not considered when setting this position. The - * root must not be null. + * children. The NodeIterator is initially positioned + * just before this node. The whatToShow flags and the + * filter, if any, are not considered when setting this position. The + * root must not be null. * @param whatToShow This flag specifies which node types may appear in - * the logical view of the tree presented by the - * NodeIterator. See the description of - * NodeFilter for the set of possible SHOW_ - * values.These flags can be combined using OR. + * the logical view of the tree presented by the + * NodeIterator. See the description of + * NodeFilter for the set of possible SHOW_ + * values.These flags can be combined using OR. * @param filter The NodeFilter to be used with this - * NodeIterator, or null to indicate no - * filter. + * NodeIterator, or null to indicate no + * filter. * @param entityReferenceExpansion The value of this flag determines - * whether entity reference nodes are expanded. + * whether entity reference nodes are expanded. * @return The newly created NodeIterator. * @exception DOMException - * NOT_SUPPORTED_ERR: Raised if the specified root is - * null. + * NOT_SUPPORTED_ERR: Raised if the specified root is null. */ public DomNodeIterator createNodeIterator(final Node root, final int whatToShow, final NodeFilter filter, final boolean entityReferenceExpansion) throws DOMException { diff --git a/src/main/java/org/htmlunit/TopLevelWindow.java b/src/main/java/org/htmlunit/TopLevelWindow.java index 5baeb31fc91..178006f2c30 100644 --- a/src/main/java/org/htmlunit/TopLevelWindow.java +++ b/src/main/java/org/htmlunit/TopLevelWindow.java @@ -115,7 +115,7 @@ public void close() { * * Closes this window. * @param ignoreOnbeforeunloadAccepted if true the result of triggering the OnbeforeunloadAccepted event - * will be ignored + * will be ignored */ public void close(final boolean ignoreOnbeforeunloadAccepted) { final Page page = getEnclosedPage(); diff --git a/src/main/java/org/htmlunit/WebClient.java b/src/main/java/org/htmlunit/WebClient.java index 1eeed75862b..15972c06e64 100644 --- a/src/main/java/org/htmlunit/WebClient.java +++ b/src/main/java/org/htmlunit/WebClient.java @@ -589,7 +589,7 @@ public Page loadWebResponseInto(final WebResponse webResponse, final WebWindow w * @param webResponse the response that will be used to create the new page * @param webWindow the window that the new page will be placed within * @param forceAttachmentWithFilename if not {@code null}, handle this as an attachment with the specified name - * or if an empty string ("") use the filename provided in the response + * or if an empty string ("") use the filename provided in the response * @throws IOException if an IO error occurs * @throws FailingHttpStatusCodeException if the server returns a failing status code AND the property * {@link WebClientOptions#setThrowExceptionOnFailingStatusCode(boolean)} is set to true @@ -2080,7 +2080,7 @@ public void setClipboardHandler(final ClipboardHandler handler) { /** * Returns the current {@link PrintHandler}. * @return the current {@link PrintHandler} or null if print - * requests are ignored + * requests are ignored */ public PrintHandler getPrintHandler() { return printHandler_; @@ -2091,7 +2091,7 @@ public PrintHandler getPrintHandler() { * (Printing Spec). * * @param handler the new {@link PrintHandler} or null if you like to - * ignore print requests (default is null) + * ignore print requests (default is null) */ public void setPrintHandler(final PrintHandler handler) { printHandler_ = handler; @@ -2591,7 +2591,7 @@ public boolean isOutdated() { * @param checkHash if true check for hashChenage * @param forceLoad if true always load the request even if there is already the same in the queue * @param forceAttachmentWithFilename if not {@code null} the AttachmentHandler isAttachment() method is not called, - * the response has to be handled as attachment in any case + * the response has to be handled as attachment in any case * @param description information about the origin of the request. Useful for debugging. */ public void download(final WebWindow requestingWindow, final String target, @@ -2892,7 +2892,7 @@ public XHtmlPage loadXHtmlCodeIntoCurrentWindow(final String xhtmlCode) throws I * INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
* * @return a CSS3Parser that will return to an internal pool for reuse if closed using the - * try-with-resource concept + * try-with-resource concept */ public PooledCSS3Parser getCSS3Parser() { return this.css3ParserPool_.get(); diff --git a/src/main/java/org/htmlunit/WebClientOptions.java b/src/main/java/org/htmlunit/WebClientOptions.java index 88a5a02cf9a..a1a1237243d 100644 --- a/src/main/java/org/htmlunit/WebClientOptions.java +++ b/src/main/java/org/htmlunit/WebClientOptions.java @@ -640,8 +640,8 @@ public int getHistoryPageCacheLimit() { * entries in the history. For older entries only the url is saved; the page * will be (re)retrieved on demand. * @param historyPageCacheLimit maximum number of pages to cache in history - * default is Integer.MAX_VALUE; negative values are having the same effect - * as setting this to zero. + * default is Integer.MAX_VALUE; negative values are having the same effect + * as setting this to zero. */ public void setHistoryPageCacheLimit(final int historyPageCacheLimit) { historyPageCacheLimit_ = historyPageCacheLimit; @@ -853,6 +853,9 @@ public void setGeolocation(final Geolocation geolocation) { geolocation_ = geolocation; } + /** + * Support class for Geolocation. + */ public static class Geolocation implements Serializable { private final double accuracy_; private final double latitude_; diff --git a/src/main/java/org/htmlunit/WebRequest.java b/src/main/java/org/htmlunit/WebRequest.java index 22777886591..e07f4fd775b 100644 --- a/src/main/java/org/htmlunit/WebRequest.java +++ b/src/main/java/org/htmlunit/WebRequest.java @@ -56,6 +56,9 @@ */ public class WebRequest implements Serializable { + /** + * Enum to configure request creation. + */ public enum HttpHint { /** Force to include the charset. */ IncludeCharsetInContentTypeHeader, @@ -456,7 +459,7 @@ public String getRequestBody() { * Other request types result in {@link RuntimeException}. * Should not be used in combination with {@link #setRequestParameters(List) request parameters}. * @param requestBody the body content to be submitted if this is a {@code POST}, {@code PUT} - * or {@code PATCH} request + * or {@code PATCH} request * @throws RuntimeException if the request parameters have already been set * or this is not a {@code POST}, {@code PUT} or {@code PATCH} request. */ @@ -655,6 +658,10 @@ public void setDefaultResponseContentCharset(final Charset defaultResponseConten this.defaultResponseContentCharset_ = Objects.requireNonNull(defaultResponseContentCharset); } + /** + * @param hint the hint to check for + * @return true if the hint is enabled + */ public boolean hasHint(final HttpHint hint) { if (httpHints_ == null) { return false; @@ -662,6 +669,10 @@ public boolean hasHint(final HttpHint hint) { return httpHints_.contains(hint); } + /** + * Enables the hint. + * @param hint the hint to add + */ public void addHint(final HttpHint hint) { if (httpHints_ == null) { httpHints_ = EnumSet.noneOf(HttpHint.class); diff --git a/src/main/java/org/htmlunit/WebResponse.java b/src/main/java/org/htmlunit/WebResponse.java index 9224b2efe3e..80ce54b66d5 100644 --- a/src/main/java/org/htmlunit/WebResponse.java +++ b/src/main/java/org/htmlunit/WebResponse.java @@ -174,25 +174,6 @@ public Charset getHeaderContentCharset() { return EncodingSniffer.extractEncodingFromContentType(contentType); } - /** - * Returns the content charset specified explicitly in the header or in the content, - * or {@code null} if none was specified. - * @return the content charset specified explicitly in the header or in the content, - * or {@code null} if none was specified - * - * @deprecated as of version 4.0.0; use {@link #getContentCharset()} instead - */ - @Deprecated - public Charset getContentCharsetOrNull() { - try (InputStream is = getContentAsStream()) { - return EncodingSniffer.sniffEncoding(getResponseHeaders(), is); - } - catch (final IOException e) { - LOG.warn("Error trying to sniff encoding.", e); - return null; - } - } - /** * Returns the content charset for this response, even if no charset was specified explicitly. *

@@ -257,7 +238,7 @@ public Charset getContentCharset() { * For example, HTML meta-tag sniffing can be fooled by text that looks-like-a-meta-tag inside * JavaScript code (false positive) or if the meta-tag is after the first 1024 bytes (false negative). * @return {@code true} if the charset of the previous call to {@link #getContentCharset()} was - * "tentative". + * "tentative". * @see * https://html.spec.whatwg.org/multipage/parsing.html#concept-encoding-confidence */ @@ -268,7 +249,7 @@ public boolean wasContentCharsetTentative() { /** * Returns the response content as a string, using the charset/encoding specified in the server response. * @return the response content as a string, using the charset/encoding specified in the server response - * or null if the content retrieval was failing + * or null if the content retrieval was failing */ public String getContentAsString() { return getContentAsString(getContentCharset()); @@ -362,15 +343,6 @@ public void cleanUp() { } } - /** - * Mark this response for using UTF-8 as default charset. - * @deprecated as of version 4.0.0; use {@link WebRequest#setDefaultResponseContentCharset(Charset)} instead - */ - @Deprecated - public void defaultCharsetUtf8() { - getWebRequest().setDefaultResponseContentCharset(UTF_8); - } - /** * @return true if the 2xx */ diff --git a/src/main/java/org/htmlunit/WebResponseData.java b/src/main/java/org/htmlunit/WebResponseData.java index 6dab15f7ff7..6f55e37a4ab 100644 --- a/src/main/java/org/htmlunit/WebResponseData.java +++ b/src/main/java/org/htmlunit/WebResponseData.java @@ -113,7 +113,7 @@ private InputStream getStream(final ByteOrderMark... bomHeaders) throws IOExcept LOG.error("Reading gzip encodec content failed.", e); stream.close(); stream = IOUtils.toInputStream( - "\n" + "\n" + "Problem loading page\n" + "\n" + "

Content Encoding Error

\n" @@ -136,7 +136,7 @@ private InputStream getStream(final ByteOrderMark... bomHeaders) throws IOExcept LOG.error("Reading Brotli encodec content failed.", e); stream.close(); stream = IOUtils.toInputStream( - "\n" + "\n" + "Problem loading page\n" + "\n" + "

Content Encoding Error

\n" diff --git a/src/main/java/org/htmlunit/WebWindow.java b/src/main/java/org/htmlunit/WebWindow.java index b1660b2ff5d..09612fd7ce4 100644 --- a/src/main/java/org/htmlunit/WebWindow.java +++ b/src/main/java/org/htmlunit/WebWindow.java @@ -71,7 +71,7 @@ public interface WebWindow extends Serializable { * is a top level window, then return this window. * * @return the top level window that contains this window or this - * window if there is no parent. + * window if there is no parent. */ WebWindow getTopWindow(); @@ -187,15 +187,15 @@ public interface WebWindow extends Serializable { Screen getScreen(); /** - * INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
- * + * INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
+ * * Returns computed style of the element. Computed style represents the final computed values * of all CSS properties for the element. This method's return value is of the same type as * that of element.style, but the value returned by this method is read-only. * * @param element the element * @param pseudoElement a string specifying the pseudo-element to match (may be {@code null}); - * e.g. ':before' + * e.g. ':before' * @return the computed style */ ComputedCssStyleDeclaration getComputedStyle(DomElement element, String pseudoElement); diff --git a/src/main/java/org/htmlunit/WebWindowEvent.java b/src/main/java/org/htmlunit/WebWindowEvent.java index 4af175d9b3e..bbe17d7b1dc 100644 --- a/src/main/java/org/htmlunit/WebWindowEvent.java +++ b/src/main/java/org/htmlunit/WebWindowEvent.java @@ -169,7 +169,9 @@ public String toString() { return builder.toString(); } - /** @return the event type */ + /** + * @return the event type + */ public int getEventType() { return type_; } diff --git a/src/main/java/org/htmlunit/WebWindowListener.java b/src/main/java/org/htmlunit/WebWindowListener.java index 07fa3d376c7..0cb8868d4f1 100644 --- a/src/main/java/org/htmlunit/WebWindowListener.java +++ b/src/main/java/org/htmlunit/WebWindowListener.java @@ -37,7 +37,7 @@ public interface WebWindowListener { * This usually takes place AFTER the event was processed

* * @param event the event (the oldPage and newPage properties will be {@code null} - * because the event is generated after the window is opened but before the content is loaded) + * because the event is generated after the window is opened but before the content is loaded) */ void webWindowOpened(WebWindowEvent event); diff --git a/src/main/java/org/htmlunit/css/ComputedCssStyleDeclaration.java b/src/main/java/org/htmlunit/css/ComputedCssStyleDeclaration.java index 391f1c880b9..ae132d1273c 100644 --- a/src/main/java/org/htmlunit/css/ComputedCssStyleDeclaration.java +++ b/src/main/java/org/htmlunit/css/ComputedCssStyleDeclaration.java @@ -44,6 +44,7 @@ import org.htmlunit.BrowserVersion; import org.htmlunit.BrowserVersionFeatures; import org.htmlunit.Page; +import org.htmlunit.SgmlPage; import org.htmlunit.WebWindow; import org.htmlunit.css.CssPixelValueConverter.CssValue; import org.htmlunit.css.StyleAttributes.Definition; @@ -87,6 +88,12 @@ import org.htmlunit.html.HtmlFileInput; import org.htmlunit.html.HtmlFooter; import org.htmlunit.html.HtmlHeader; +import org.htmlunit.html.HtmlHeading1; +import org.htmlunit.html.HtmlHeading2; +import org.htmlunit.html.HtmlHeading3; +import org.htmlunit.html.HtmlHeading4; +import org.htmlunit.html.HtmlHeading5; +import org.htmlunit.html.HtmlHeading6; import org.htmlunit.html.HtmlHiddenInput; import org.htmlunit.html.HtmlImage; import org.htmlunit.html.HtmlInlineFrame; @@ -104,6 +111,7 @@ import org.htmlunit.html.HtmlNoLayer; import org.htmlunit.html.HtmlNoScript; import org.htmlunit.html.HtmlOutput; +import org.htmlunit.html.HtmlPage; import org.htmlunit.html.HtmlPasswordInput; import org.htmlunit.html.HtmlPlainText; import org.htmlunit.html.HtmlRadioButtonInput; @@ -136,7 +144,6 @@ import org.htmlunit.html.HtmlUnknownElement; import org.htmlunit.html.HtmlVariable; import org.htmlunit.html.HtmlWordBreak; -import org.htmlunit.javascript.host.html.HTMLElement; import org.htmlunit.platform.Platform; /** @@ -202,7 +209,7 @@ public class ComputedCssStyleDeclaration extends AbstractCssStyleDeclaration { * The computed, cached height of the element to which this computed style belongs (no padding, borders, etc.), * not taking child elements into account. */ - private Integer height2_; + private Integer emptyHeight_; /** The computed, cached horizontal padding (left + right) of the element to which this computed style belongs. */ private Integer paddingHorizontal_; @@ -235,7 +242,7 @@ public class ComputedCssStyleDeclaration extends AbstractCssStyleDeclaration { public ComputedCssStyleDeclaration(final ElementCssStyleDeclaration styleDeclaration) { super(); elementStyleDeclaration_ = styleDeclaration; - getDomElement().setDefaults(this); + elementStyleDeclaration_.getDomElement().setDefaults(this); } /** @@ -500,7 +507,7 @@ public Map getStyleMap() { /** * @return the {@link DomElement} the backing {@link ElementCssStyleDeclaration} - * is associated with + * is associated with */ public DomElement getDomElement() { return elementStyleDeclaration_.getDomElement(); @@ -725,11 +732,7 @@ public String getFontFamily() { */ @Override public String getFontSize() { - String value = getStyleAttribute(Definition.FONT_SIZE, true); - if (!value.isEmpty()) { - value = CssPixelValueConverter.pixelValue(value) + "px"; - } - return value; + return getStyleAttribute(Definition.FONT_SIZE, true); } /** @@ -753,16 +756,20 @@ public String getHeight() { if (!elem.isAttachedToPage()) { return ""; } - final int windowHeight = elem.getPage().getEnclosingWindow().getInnerHeight(); - return CssPixelValueConverter - .pixelString(elem, new CssPixelValueConverter.CssValue(0, windowHeight) { - @Override - public String get(final ComputedCssStyleDeclaration style) { - // TODO don't reach out to the js peer - final String offsetHeight = ((HTMLElement) elem.getScriptableObject()).getOffsetHeight() + "px"; - return defaultIfEmpty(style.getStyleAttribute(Definition.HEIGHT, true), offsetHeight, AUTO); - } - }); + + final ComputedCssStyleDeclaration style = elem.getPage().getEnclosingWindow().getComputedStyle(elem, null); + final String styleValue = style.getStyleAttribute(Definition.HEIGHT, true); + + if (styleValue == null || styleValue.isEmpty() || AUTO.equals(styleValue) || styleValue.endsWith("%")) { + final String calculatedHeight = style.getCalculatedHeight(false, false) + "px"; + return calculatedHeight; + } + + if (styleValue.endsWith("px")) { + return styleValue; + } + + return CssPixelValueConverter.pixelValue(styleValue) + "px"; } /** @@ -770,16 +777,24 @@ public String get(final ComputedCssStyleDeclaration style) { */ @Override public String getLeft() { + if (NONE.equals(getDisplay())) { + return AUTO; + } + + final DomElement elem = getDomElement(); + if (!elem.isAttachedToPage()) { + return ""; + } + final String superLeft = super.getLeft(); if (!superLeft.endsWith("%")) { return defaultIfEmpty(superLeft, AUTO, null); } - final DomElement element = getDomElement(); - return CssPixelValueConverter.pixelString(element, new CssPixelValueConverter.CssValue(0, 0) { + return CssPixelValueConverter.pixelString(elem, new CssPixelValueConverter.CssValue(0, 0) { @Override public String get(final ComputedCssStyleDeclaration style) { - if (style.getDomElement() == element) { + if (style.getDomElement() == elem) { return style.getStyleAttribute(Definition.LEFT, true); } return style.getStyleAttribute(Definition.WIDTH, true); @@ -974,19 +989,24 @@ public String getTextIndent() { */ @Override public String getTop() { - final DomElement element = getDomElement(); - if (!element.isAttachedToPage()) { + if (NONE.equals(getDisplay())) { + return AUTO; + } + + final DomElement elem = getDomElement(); + if (!elem.isAttachedToPage()) { return ""; } + final String superTop = super.getTop(); if (!superTop.endsWith("%")) { return defaultIfEmpty(superTop, Definition.TOP); } - return CssPixelValueConverter.pixelString(element, new CssPixelValueConverter.CssValue(0, 0) { + return CssPixelValueConverter.pixelString(elem, new CssPixelValueConverter.CssValue(0, 0) { @Override public String get(final ComputedCssStyleDeclaration style) { - if (style.getDomElement() == element) { + if (style.getDomElement() == elem) { return style.getStyleAttribute(Definition.TOP, true); } return style.getStyleAttribute(Definition.HEIGHT, true); @@ -1416,12 +1436,12 @@ public int getCalculatedHeight(final boolean includeBorder, final boolean includ if (!element.isAttachedToPage()) { return 0; } - int height = getCalculatedHeight(); + int height = getCalculatedHeight(element); if (!"border-box".equals(getStyleAttribute(Definition.BOX_SIZING, true))) { if (includeBorder) { height += getBorderVertical(); } - else if (isScrollable(true, true) && !(element instanceof HtmlBody)) { + else if (isScrollable(element, true, true) && !(element instanceof HtmlBody)) { height -= 17; } @@ -1436,14 +1456,12 @@ else if (isScrollable(true, true) && !(element instanceof HtmlBody)) { * Returns the element's calculated height, taking both relevant CSS and the element's children into account. * @return the element's calculated height, taking both relevant CSS and the element's children into account */ - private int getCalculatedHeight() { + private int getCalculatedHeight(final DomElement element) { final Integer cachedHeight = getCachedHeight(); if (cachedHeight != null) { return cachedHeight.intValue(); } - final DomElement element = getDomElement(); - if (element instanceof HtmlImage) { return updateCachedHeight(((HtmlImage) element).getHeightOrDefault()); } @@ -1457,7 +1475,7 @@ private int getCalculatedHeight() { } } - return updateCachedHeight(getEmptyHeight()); + return updateCachedHeight(getEmptyHeight(element)); } /** @@ -1477,7 +1495,7 @@ public int getCalculatedWidth(final boolean includeBorder, final boolean include if (includeBorder) { width += getBorderHorizontal(); } - else if (isScrollable(false, true) && !(element instanceof HtmlBody)) { + else if (isScrollable(element, false, true) && !(element instanceof HtmlBody)) { width -= 17; } @@ -1628,7 +1646,8 @@ else if (child instanceof DomText) { final DomNode parent = child.getParentNode(); if (parent instanceof HtmlElement) { final ComputedCssStyleDeclaration style = webWindow.getComputedStyle((DomElement) parent, null); - final int height = browserVersion.getFontHeight(style.getFontSize()); + final int height = browserVersion.getFontHeight( + style.getStyleAttribute(Definition.FONT_SIZE, true)); width += child.getVisibleText().length() * (int) (height / 1.8f); } else { @@ -1640,33 +1659,34 @@ else if (child instanceof DomText) { } /** - * Returns the element's calculated height taking relevant CSS into account, but not the element's child - * elements. - * * @return the element's calculated height taking relevant CSS into account, but not the element's child * elements */ - private int getEmptyHeight() { - final Integer cachedHeight2 = getCachedHeight2(); + private int getEmptyHeight(final DomElement element) { + final Integer cachedHeight2 = getCachedEmptyHeight(); if (cachedHeight2 != null) { return cachedHeight2.intValue(); } - final DomElement element = getDomElement(); if (!element.mayBeDisplayed()) { - return updateCachedHeight2(0); + return updateCachedEmptyHeight(0); } final String display = getDisplay(); if (NONE.equals(display)) { - return updateCachedHeight2(0); + return updateCachedEmptyHeight(0); } - final WebWindow webWindow = element.getPage().getEnclosingWindow(); + final SgmlPage page = element.getPage(); + final WebWindow webWindow = page.getEnclosingWindow(); final int windowHeight = webWindow.getInnerHeight(); if (element instanceof HtmlBody) { - return updateCachedHeight2(windowHeight); + if (page instanceof HtmlPage && ((HtmlPage) page).isQuirksMode()) { + return updateCachedEmptyHeight(windowHeight); + } + + return updateCachedEmptyHeight(0); } final boolean isInline = INLINE.equals(display) && !(element instanceof HtmlInlineFrame); @@ -1778,10 +1798,77 @@ else if (element instanceof HtmlInlineFrame) { } } else { - final String fontSize = getFontSize(); + final String fontSize; + + boolean isHeading = false; + if (element instanceof HtmlHeading1) { + isHeading = true; + final String value = getStyleAttribute(Definition.FONT_SIZE, false); + if (value.isEmpty()) { + fontSize = "32px"; + } + else { + fontSize = getStyleAttribute(Definition.FONT_SIZE, true); + } + } + else if (element instanceof HtmlHeading2) { + isHeading = true; + final String value = getStyleAttribute(Definition.FONT_SIZE, false); + if (value.isEmpty()) { + fontSize = "24px"; + } + else { + fontSize = getStyleAttribute(Definition.FONT_SIZE, true); + } + } + else if (element instanceof HtmlHeading3) { + isHeading = true; + final String value = getStyleAttribute(Definition.FONT_SIZE, false); + if (value.isEmpty()) { + fontSize = "19px"; + } + else { + fontSize = getStyleAttribute(Definition.FONT_SIZE, true); + } + } + else if (element instanceof HtmlHeading4) { + isHeading = true; + final String value = getStyleAttribute(Definition.FONT_SIZE, false); + if (value.isEmpty()) { + fontSize = "16px"; + } + else { + fontSize = getStyleAttribute(Definition.FONT_SIZE, true); + } + } + else if (element instanceof HtmlHeading5) { + isHeading = true; + final String value = getStyleAttribute(Definition.FONT_SIZE, false); + if (value.isEmpty()) { + fontSize = "13px"; + } + else { + fontSize = getStyleAttribute(Definition.FONT_SIZE, true); + } + } + else if (element instanceof HtmlHeading6) { + isHeading = true; + final String value = getStyleAttribute(Definition.FONT_SIZE, false); + if (value.isEmpty()) { + fontSize = "11px"; + } + else { + fontSize = getStyleAttribute(Definition.FONT_SIZE, true); + } + } + else { + fontSize = getStyleAttribute(Definition.FONT_SIZE, true); + } + defaultHeight = webWindow.getWebClient().getBrowserVersion().getFontHeight(fontSize); - if (element instanceof HtmlDivision + if (isHeading + || element instanceof HtmlDivision || element instanceof HtmlSpan) { String width = getStyleAttribute(Definition.WIDTH, false); @@ -1839,7 +1926,7 @@ else if (element instanceof HtmlInlineFrame) { height = defaultHeight; } - return updateCachedHeight2(height); + return updateCachedEmptyHeight(height); } /** @@ -1909,15 +1996,14 @@ else if (ABSOLUTE.equals(position) || FIXED.equals(position)) { * @return {@code true} if the element is scrollable along the specified axis */ public boolean isScrollable(final boolean horizontal) { - return isScrollable(horizontal, false); + return isScrollable(getDomElement(), horizontal, false); } /** * @param ignoreSize whether to consider the content/calculated width/height */ - private boolean isScrollable(final boolean horizontal, final boolean ignoreSize) { + private boolean isScrollable(final DomElement element, final boolean horizontal, final boolean ignoreSize) { final boolean scrollable; - final DomElement element = getDomElement(); String overflow; if (horizontal) { @@ -1943,7 +2029,7 @@ private boolean isScrollable(final boolean horizontal, final boolean ignoreSize) } scrollable = (element instanceof HtmlBody || SCROLL.equals(overflow) || AUTO.equals(overflow)) - && (ignoreSize || getContentHeight() > getEmptyHeight()); + && (ignoreSize || getContentHeight() > getEmptyHeight(element)); } return scrollable; } @@ -2090,20 +2176,20 @@ public int updateCachedHeight(final int height) { /** * INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK. - * @return the cached height2 + * @return the cached emptyHeight */ - public Integer getCachedHeight2() { - return height2_; + public Integer getCachedEmptyHeight() { + return emptyHeight_; } /** * INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK. - * @param height the new value - * @return the param height2 + * @param emptyHeight the new value + * @return the param emptyHeight */ - public int updateCachedHeight2(final int height) { - height2_ = Integer.valueOf(height); - return height; + public int updateCachedEmptyHeight(final int emptyHeight) { + emptyHeight_ = Integer.valueOf(emptyHeight); + return emptyHeight; } /** diff --git a/src/main/java/org/htmlunit/css/CssColors.java b/src/main/java/org/htmlunit/css/CssColors.java index 57d809b7ef7..85c0a8aa086 100644 --- a/src/main/java/org/htmlunit/css/CssColors.java +++ b/src/main/java/org/htmlunit/css/CssColors.java @@ -63,7 +63,7 @@ public static boolean isColorKeyword(final String token) { * Gets the RGB equivalent of a CSS color if the provided color is recognized. * @param color the color * @return the provided color if this is not a recognized color keyword, the RGB value - * in the form "rgb(x, y, z)" otherwise + * in the form "rgb(x, y, z)" otherwise */ public static String toRGBColor(final String color) { final String rgbValue = CSS_COLORS.get(color.toLowerCase(Locale.ROOT)); diff --git a/src/main/java/org/htmlunit/css/ElementCssStyleDeclaration.java b/src/main/java/org/htmlunit/css/ElementCssStyleDeclaration.java index 1f11ae5d973..f98bab0d4b1 100644 --- a/src/main/java/org/htmlunit/css/ElementCssStyleDeclaration.java +++ b/src/main/java/org/htmlunit/css/ElementCssStyleDeclaration.java @@ -188,6 +188,9 @@ public Map getStyleMap() { return domElement_.getStyleMap(); } + /** + * @return the {@link DomElement} associated with this + */ public DomElement getDomElement() { return domElement_; } diff --git a/src/main/java/org/htmlunit/html/DomCharacterData.java b/src/main/java/org/htmlunit/html/DomCharacterData.java index 78f098bde90..79e316a31fd 100644 --- a/src/main/java/org/htmlunit/html/DomCharacterData.java +++ b/src/main/java/org/htmlunit/html/DomCharacterData.java @@ -105,9 +105,9 @@ public void appendData(final String newData) { /** * Deletes characters from character data. * @param offset the position of the first character to be deleted (can't be - * less than zero) + * less than zero) * @param count the number of characters to be deleted, if less than zero - * leaves the first offset chars + * leaves the first offset chars */ @Override public void deleteData(final int offset, final int count) { diff --git a/src/main/java/org/htmlunit/html/DomElement.java b/src/main/java/org/htmlunit/html/DomElement.java index ef5776e3f1c..1081a5c767f 100644 --- a/src/main/java/org/htmlunit/html/DomElement.java +++ b/src/main/java/org/htmlunit/html/DomElement.java @@ -130,7 +130,7 @@ public int compare(final StyleElement first, final StyleElement second) { * @param qualifiedName the qualified name of the element type to instantiate * @param page the page that contains this element * @param attributes a map ready initialized with the attributes for this element, or - * {@code null}. The map will be stored as is, not copied. + * {@code null}. The map will be stored as is, not copied. */ public DomElement(final String namespaceURI, final String qualifiedName, final SgmlPage page, final Map attributes) { @@ -195,7 +195,7 @@ public final boolean hasAttributes() { * * @param attributeName the name of the attribute * @return true if an attribute with the given name is specified on this element or has a - * default value, false otherwise. + * default value, false otherwise. */ @Override public boolean hasAttribute(final String attributeName) { @@ -477,7 +477,7 @@ public final Attr removeAttributeNode(final Attr attribute) { * @param namespaceURI the URI that identifies an XML namespace * @param localName the name within the namespace * @return true if an attribute with the given name is specified on this element or has a - * default value, false otherwise. + * default value, false otherwise. */ @Override public final boolean hasAttributeNS(final String namespaceURI, final String localName) { @@ -822,7 +822,8 @@ public final Iterable getChildElements() { private static class ChildElementsIterable implements Iterable { private final Iterator iterator_; - /** Constructor. + /** + * Constructor. * @param domNode the parent */ protected ChildElementsIterable(final DomNode domNode) { @@ -842,7 +843,8 @@ protected static class ChildElementsIterator implements Iterator { private DomElement nextElement_; - /** Constructor. + /** + * Constructor. * @param domNode the parent */ protected ChildElementsIterator(final DomNode domNode) { @@ -857,13 +859,17 @@ protected ChildElementsIterator(final DomNode domNode) { } } - /** @return is there a next one ? */ + /** + * @return is there a next one ? + */ @Override public boolean hasNext() { return nextElement_ != null; } - /** @return the next one */ + /** + * @return the next one + */ @Override public DomElement next() { if (nextElement_ != null) { @@ -1179,7 +1185,7 @@ public

P click(final Event event, * @param ctrlKey {@code true} if CTRL is pressed * * @return true if doClickFireEvent method has to be called later on (to signal, - * that the value was changed) + * that the value was changed) * @throws IOException if an IO error occurs */ protected boolean doClickStateUpdate(final boolean shiftKey, final boolean ctrlKey) throws IOException { @@ -1197,11 +1203,9 @@ protected boolean doClickStateUpdate(final boolean shiftKey, final boolean ctrlK } /** - * @see #doClickStateUpdate(boolean, boolean) - * Usually the click is propagated to the parent. Overwrite if you - * like to disable this. - * + * Usually the click is propagated to the parent. Overwrite if you like to disable this. * @return true or false + * @see #doClickStateUpdate(boolean, boolean) */ protected boolean propagateClickStateUpdateToParent() { return true; diff --git a/src/main/java/org/htmlunit/html/DomNode.java b/src/main/java/org/htmlunit/html/DomNode.java index 0ddd78fbd78..019fee9bbbb 100644 --- a/src/main/java/org/htmlunit/html/DomNode.java +++ b/src/main/java/org/htmlunit/html/DomNode.java @@ -207,7 +207,7 @@ public int getStartColumnNumber() { /** * Returns the line number in the source page where the DOM node ends. * @return 0 if no information on the line number is available (for instance for nodes dynamically added), - * -1 if the end tag has not yet been parsed (during page loading) + * -1 if the end tag has not yet been parsed (during page loading) */ public int getEndLineNumber() { return endLineNumber_; @@ -216,7 +216,7 @@ public int getEndLineNumber() { /** * Returns the column number in the source page where the DOM node ends. * @return 0 if no information on the line number is available (for instance for nodes dynamically added), - * -1 if the end tag has not yet been parsed (during page loading) + * -1 if the end tag has not yet been parsed (during page loading) */ public int getEndColumnNumber() { return endColumnNumber_; @@ -1244,11 +1244,11 @@ public void quietlyRemoveAndMoveChildrenTo(final DomNode destination) { * * @param newChild the new child node that is being inserted below this node * @throws DOMException HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does - * not allow children of the type of the newChild node, or if the node to insert is one of - * this node's ancestors or this node itself, or if this node is of type Document and the - * DOM application attempts to insert a second DocumentType or Element node. - * WRONG_DOCUMENT_ERR: Raised if newChild was created from a different document than the - * one that created this node. + * not allow children of the type of the newChild node, or if the node to insert is one of + * this node's ancestors or this node itself, or if this node is of type Document and the + * DOM application attempts to insert a second DocumentType or Element node. + * WRONG_DOCUMENT_ERR: Raised if newChild was created from a different document than the + * one that created this node. */ protected void checkChildHierarchy(final Node newChild) throws DOMException { Node parentNode = this; @@ -1391,7 +1391,7 @@ public final Iterable getDomElementDescendants() { * @param the type of nodes over which to iterate * * @deprecated as of version 4.7.0; use {@link DescendantDomNodesIterator}, - * {@link DescendantDomElementsIterator}, or {@link DescendantHtmlElementsIterator} instead. + * {@link DescendantDomElementsIterator}, or {@link DescendantHtmlElementsIterator} instead. */ @Deprecated protected class DescendantElementsIterator implements Iterator { @@ -1434,7 +1434,9 @@ public void remove() { current.remove(); } - /** @return the next node, if there is one */ + /** + * @return the next node, if there is one + */ @SuppressWarnings("unchecked") public T nextNode() { currentNode_ = nextNode_; @@ -1537,7 +1539,9 @@ public void remove() { current.remove(); } - /** @return the next node, if there is one */ + /** + * @return the next node, if there is one + */ @SuppressWarnings("unchecked") public DomNode nextNode() { currentNode_ = nextNode_; @@ -1638,7 +1642,9 @@ public void remove() { current.remove(); } - /** @return the next node, if there is one */ + /** + * @return the next node, if there is one + */ @SuppressWarnings("unchecked") public DomElement nextNode() { currentNode_ = nextNode_; @@ -1739,7 +1745,9 @@ public void remove() { current.remove(); } - /** @return the next node, if there is one */ + /** + * @return the next node, if there is one + */ @SuppressWarnings("unchecked") public HtmlElement nextNode() { currentNode_ = nextNode_; @@ -2227,7 +2235,7 @@ public boolean handles(final Event event) { * Returns the previous sibling element node of this element. * null if this element has no element sibling nodes that come before this one in the document tree. * @return the previous sibling element node of this element. - * null if this element has no element sibling nodes that come before this one in the document tree + * null if this element has no element sibling nodes that come before this one in the document tree */ public DomElement getPreviousElementSibling() { DomNode node = getPreviousSibling(); @@ -2241,7 +2249,7 @@ public DomElement getPreviousElementSibling() { * Returns the next sibling element node of this element. * null if this element has no element sibling nodes that come after this one in the document tree. * @return the next sibling element node of this element. - * null if this element has no element sibling nodes that come after this one in the document tree + * null if this element has no element sibling nodes that come after this one in the document tree */ public DomElement getNextElementSibling() { DomNode node = getNextSibling(); diff --git a/src/main/java/org/htmlunit/html/DomNodeIterator.java b/src/main/java/org/htmlunit/html/DomNodeIterator.java index d487fe6f2b0..9424ff28139 100644 --- a/src/main/java/org/htmlunit/html/DomNodeIterator.java +++ b/src/main/java/org/htmlunit/html/DomNodeIterator.java @@ -38,7 +38,7 @@ public class DomNodeIterator implements NodeIterator { * * @param root The root node at which to begin the {@link NodeIterator}'s traversal * @param whatToShow an optional int representing a bitmask created by combining - * the constant properties of {@link NodeFilter} + * the constant properties of {@link NodeFilter} * @param expandEntityReferences If false, the contents of * EntityReference nodes are not present in the logical view. * @param filter an object implementing the {@link NodeFilter} interface diff --git a/src/main/java/org/htmlunit/html/HtmlElement.java b/src/main/java/org/htmlunit/html/HtmlElement.java index e79552093ad..d028fc6fa93 100644 --- a/src/main/java/org/htmlunit/html/HtmlElement.java +++ b/src/main/java/org/htmlunit/html/HtmlElement.java @@ -162,7 +162,7 @@ public String value() { * @param qualifiedName the qualified name of the element type to instantiate * @param page the page that contains this element * @param attributes a map ready initialized with the attributes for this element, or - * {@code null}. The map will be stored as is, not copied. + * {@code null}. The map will be stored as is, not copied. */ protected HtmlElement(final String qualifiedName, final SgmlPage page, final Map attributes) { @@ -176,7 +176,7 @@ protected HtmlElement(final String qualifiedName, final SgmlPage page, * @param qualifiedName the qualified name of the element type to instantiate * @param page the page that contains this element * @param attributes a map ready initialized with the attributes for this element, or - * {@code null}. The map will be stored as is, not copied. + * {@code null}. The map will be stored as is, not copied. */ protected HtmlElement(final String namespaceURI, final String qualifiedName, final SgmlPage page, final Map attributes) { @@ -1277,7 +1277,7 @@ public DisplayStyle getDefaultStyleDisplay() { * Helper for src retrieval and normalization. * * @return the value of the attribute {@code src} with all line breaks removed - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ protected final String getSrcAttributeNormalized() { // at the moment StringUtils.replaceChars returns the org string diff --git a/src/main/java/org/htmlunit/html/HtmlFileInput.java b/src/main/java/org/htmlunit/html/HtmlFileInput.java index ccd737981ae..5f95299fd61 100644 --- a/src/main/java/org/htmlunit/html/HtmlFileInput.java +++ b/src/main/java/org/htmlunit/html/HtmlFileInput.java @@ -137,7 +137,7 @@ public void setContentType(final String contentType) { /** * Gets the content type that should be sent together with the uploaded file. * @return the content type, or {@code null} if this has not been explicitly set - * and should be guessed from file content + * and should be guessed from file content */ public String getContentType() { return contentType_; diff --git a/src/main/java/org/htmlunit/html/HtmlForm.java b/src/main/java/org/htmlunit/html/HtmlForm.java index b1aa8eb653f..fdb07d5c743 100644 --- a/src/main/java/org/htmlunit/html/HtmlForm.java +++ b/src/main/java/org/htmlunit/html/HtmlForm.java @@ -567,10 +567,11 @@ public List getElements() { /** * @return A List containing all form controls in the form. - * The form controls in the returned collection are in the same order - * in which they appear in the form by following a preorder, - * depth-first traversal of the tree. This is called tree order. Only the following elements are returned: - * button, fieldset, input, object, output, select, textarea. + * The form controls in the returned collection are in the same order + * in which they appear in the form by following a preorder, + * depth-first traversal of the tree. This is called tree order. + * Only the following elements are returned: + * button, fieldset, input, object, output, select, textarea. */ public List getFormElements() { return getElements(htmlElement -> { @@ -590,12 +591,13 @@ public List getFormElements() { * see https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/elements * * @return A List containing all non-image controls in the form. - * The form controls in the returned collection are in the same order - * in which they appear in the form by following a preorder, - * depth-first traversal of the tree. This is called tree order. Only the following elements are returned: - * button, fieldset, - * input (with the exception that any whose type is "image" are omitted for historical reasons), - * object, output, select, textarea. + * The form controls in the returned collection are in the same order + * in which they appear in the form by following a preorder, + * depth-first traversal of the tree. This is called tree order. + * Only the following elements are returned: + * button, fieldset, + * input (with the exception that any whose type is "image" are omitted for historical reasons), + * object, output, select, textarea. */ public List getElementsJS() { return getElements(htmlElement -> { diff --git a/src/main/java/org/htmlunit/html/HtmlImage.java b/src/main/java/org/htmlunit/html/HtmlImage.java index c0c7a223347..0695114fa4b 100644 --- a/src/main/java/org/htmlunit/html/HtmlImage.java +++ b/src/main/java/org/htmlunit/html/HtmlImage.java @@ -41,6 +41,7 @@ import org.htmlunit.WebClient; import org.htmlunit.WebRequest; import org.htmlunit.WebResponse; +import org.htmlunit.http.HttpStatus; import org.htmlunit.javascript.AbstractJavaScriptEngine; import org.htmlunit.javascript.PostponedAction; import org.htmlunit.javascript.host.dom.Document; @@ -278,7 +279,9 @@ public void doOnLoad() { downloadImageIfNeeded(); // if the download was a success if (imageWebResponse_.isSuccess()) { - loadSuccessful = true; // Trigger the onload handler + if (imageWebResponse_.getStatusCode() != HttpStatus.NO_CONTENT_204) { + loadSuccessful = true; // Trigger the onload handler + } } } catch (final IOException e) { diff --git a/src/main/java/org/htmlunit/html/HtmlInlineQuotation.java b/src/main/java/org/htmlunit/html/HtmlInlineQuotation.java index 1f528886577..3197d7a7df9 100644 --- a/src/main/java/org/htmlunit/html/HtmlInlineQuotation.java +++ b/src/main/java/org/htmlunit/html/HtmlInlineQuotation.java @@ -51,7 +51,7 @@ public class HtmlInlineQuotation extends HtmlElement { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code cite} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getCiteAttribute() { return getAttributeDirect("cite"); diff --git a/src/main/java/org/htmlunit/html/HtmlInput.java b/src/main/java/org/htmlunit/html/HtmlInput.java index 527d033d5d9..5cabcfdb7fc 100644 --- a/src/main/java/org/htmlunit/html/HtmlInput.java +++ b/src/main/java/org/htmlunit/html/HtmlInput.java @@ -25,7 +25,6 @@ import java.util.HashSet; import java.util.Locale; import java.util.Map; -import java.util.regex.Pattern; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; @@ -36,11 +35,13 @@ import org.htmlunit.ScriptResult; import org.htmlunit.SgmlPage; import org.htmlunit.WebClient; +import org.htmlunit.corejs.javascript.Context; +import org.htmlunit.corejs.javascript.regexp.RegExpEngineAccess; import org.htmlunit.javascript.AbstractJavaScriptEngine; +import org.htmlunit.javascript.HtmlUnitContextFactory; import org.htmlunit.javascript.host.event.Event; import org.htmlunit.javascript.host.event.MouseEvent; import org.htmlunit.javascript.host.html.HTMLInputElement; -import org.htmlunit.javascript.regexp.RegExpJsToJavaConverter; import org.htmlunit.util.NameValuePair; import org.xml.sax.helpers.AttributesImpl; @@ -222,7 +223,7 @@ public final boolean isDisabled() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code readonly} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getReadOnlyAttribute() { return getAttributeDirect("readonly"); @@ -234,7 +235,7 @@ public final String getReadOnlyAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code size} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getSizeAttribute() { return getAttributeDirect("size"); @@ -246,7 +247,7 @@ public final String getSizeAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code maxlength} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getMaxLengthAttribute() { return getAttribute("maxLength"); @@ -276,7 +277,7 @@ protected int getMaxLength() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code minlength} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getMinLengthAttribute() { return getAttribute("minLength"); @@ -306,7 +307,7 @@ protected int getMinLength() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code src} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public String getSrcAttribute() { return getSrcAttributeNormalized(); @@ -352,7 +353,7 @@ public void setSrcAttribute(final String src) { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code alt} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getAltAttribute() { return getAttributeDirect("alt"); @@ -364,7 +365,7 @@ public final String getAltAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code usemap} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getUseMapAttribute() { return getAttributeDirect("usemap"); @@ -376,7 +377,7 @@ public final String getUseMapAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code tabindex} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getTabIndexAttribute() { return getAttributeDirect("tabindex"); @@ -388,7 +389,7 @@ public final String getTabIndexAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code accesskey} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getAccessKeyAttribute() { return getAttributeDirect("accesskey"); @@ -400,7 +401,7 @@ public final String getAccessKeyAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code onfocus} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getOnFocusAttribute() { return getAttributeDirect("onfocus"); @@ -412,7 +413,7 @@ public final String getOnFocusAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code onblur} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getOnBlurAttribute() { return getAttributeDirect("onblur"); @@ -424,7 +425,7 @@ public final String getOnBlurAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code onselect} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getOnSelectAttribute() { return getAttributeDirect("onselect"); @@ -436,7 +437,7 @@ public final String getOnSelectAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code onchange} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getOnChangeAttribute() { return getAttributeDirect("onchange"); @@ -448,7 +449,7 @@ public final String getOnChangeAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code accept} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getAcceptAttribute() { return getAttribute(HttpHeader.ACCEPT_LC); @@ -460,7 +461,7 @@ public final String getAcceptAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code align} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getAlignAttribute() { return getAttributeDirect("align"); @@ -1011,10 +1012,12 @@ private boolean isPatternValid() { return true; } - final RegExpJsToJavaConverter converter = new RegExpJsToJavaConverter(); - final String javaPattern = converter.convert(pattern); - try { - return Pattern.matches(javaPattern, value); + try (Context cx = HtmlUnitContextFactory.getGlobal().enterContext()) { + RegExpEngineAccess.compile(cx, pattern, ""); + final RegExpEngineAccess.CompiledRegExp compiled + = RegExpEngineAccess.compile(cx, "^(?:" + pattern + ")$", ""); + + return RegExpEngineAccess.matches(cx, value, compiled); } catch (final Exception ignored) { // ignore if regex invalid diff --git a/src/main/java/org/htmlunit/html/HtmlInsertedText.java b/src/main/java/org/htmlunit/html/HtmlInsertedText.java index a3d66ae1faa..3f65a4d2e3e 100644 --- a/src/main/java/org/htmlunit/html/HtmlInsertedText.java +++ b/src/main/java/org/htmlunit/html/HtmlInsertedText.java @@ -51,7 +51,7 @@ public class HtmlInsertedText extends HtmlElement { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code cite} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getCiteAttribute() { return getAttributeDirect("cite"); @@ -63,7 +63,7 @@ public final String getCiteAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code datetime} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getDateTimeAttribute() { return getAttributeDirect("datetime"); diff --git a/src/main/java/org/htmlunit/html/HtmlLabel.java b/src/main/java/org/htmlunit/html/HtmlLabel.java index fbad667da7c..7ab63990ef7 100644 --- a/src/main/java/org/htmlunit/html/HtmlLabel.java +++ b/src/main/java/org/htmlunit/html/HtmlLabel.java @@ -56,7 +56,7 @@ public class HtmlLabel extends HtmlElement { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code for} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getForAttribute() { return getAttributeDirect("for"); @@ -68,7 +68,7 @@ public final String getForAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code accesskey} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getAccessKeyAttribute() { return getAttributeDirect("accesskey"); @@ -80,7 +80,7 @@ public final String getAccessKeyAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code onfocus} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getOnFocusAttribute() { return getAttributeDirect("onfocus"); @@ -92,7 +92,7 @@ public final String getOnFocusAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code onblur} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getOnBlurAttribute() { return getAttributeDirect("onblur"); diff --git a/src/main/java/org/htmlunit/html/HtmlLegend.java b/src/main/java/org/htmlunit/html/HtmlLegend.java index 1efcb47e383..4eaa2c826ff 100644 --- a/src/main/java/org/htmlunit/html/HtmlLegend.java +++ b/src/main/java/org/htmlunit/html/HtmlLegend.java @@ -51,7 +51,7 @@ public class HtmlLegend extends HtmlElement { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code accesskey} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getAccessKeyAttribute() { return getAttributeDirect("accesskey"); @@ -63,7 +63,7 @@ public final String getAccessKeyAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code align} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getAlignAttribute() { return getAttributeDirect("align"); diff --git a/src/main/java/org/htmlunit/html/HtmlLink.java b/src/main/java/org/htmlunit/html/HtmlLink.java index aea7061577a..0011d0671c4 100644 --- a/src/main/java/org/htmlunit/html/HtmlLink.java +++ b/src/main/java/org/htmlunit/html/HtmlLink.java @@ -78,7 +78,7 @@ public class HtmlLink extends HtmlElement { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code charset} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getCharsetAttribute() { return getAttributeDirect("charset"); @@ -90,7 +90,7 @@ public final String getCharsetAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code href} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getHrefAttribute() { return getAttributeDirect("href"); @@ -102,7 +102,7 @@ public final String getHrefAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code hreflang} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getHrefLangAttribute() { return getAttributeDirect("hreflang"); @@ -114,7 +114,7 @@ public final String getHrefLangAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code type} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getTypeAttribute() { return getAttributeDirect(TYPE_ATTRIBUTE); @@ -126,7 +126,7 @@ public final String getTypeAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code rel} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getRelAttribute() { return getAttributeDirect("rel"); @@ -138,7 +138,7 @@ public final String getRelAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code rev} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getRevAttribute() { return getAttributeDirect("rev"); @@ -150,7 +150,7 @@ public final String getRevAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code media} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getMediaAttribute() { return getAttributeDirect("media"); @@ -162,7 +162,7 @@ public final String getMediaAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code target} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getTargetAttribute() { return getAttributeDirect("target"); @@ -175,7 +175,7 @@ public final String getTargetAttribute() { * * @param downloadIfNeeded indicates if a request should be performed this hasn't been done previously * @return {@code null} if no download should be performed and when this wasn't already done; the response - * received when performing a request for the content referenced by this tag otherwise + * received when performing a request for the content referenced by this tag otherwise * @throws IOException if an error occurs while downloading the content */ public WebResponse getWebResponse(final boolean downloadIfNeeded) throws IOException { @@ -191,7 +191,7 @@ public WebResponse getWebResponse(final boolean downloadIfNeeded) throws IOExcep * @param downloadIfNeeded indicates if a request should be performed this hasn't been done previously * @param request the request; if null getWebRequest() is called to create one * @return {@code null} if no download should be performed and when this wasn't already done; the response - * received when performing a request for the content referenced by this tag otherwise + * received when performing a request for the content referenced by this tag otherwise * @throws IOException if an error occurs while downloading the content */ public WebResponse getWebResponse(final boolean downloadIfNeeded, WebRequest request) throws IOException { diff --git a/src/main/java/org/htmlunit/html/HtmlListItem.java b/src/main/java/org/htmlunit/html/HtmlListItem.java index e81804083e4..05ce4b5f967 100644 --- a/src/main/java/org/htmlunit/html/HtmlListItem.java +++ b/src/main/java/org/htmlunit/html/HtmlListItem.java @@ -50,7 +50,7 @@ public class HtmlListItem extends HtmlElement { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code type} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getTypeAttribute() { return getAttributeDirect(TYPE_ATTRIBUTE); @@ -62,7 +62,7 @@ public final String getTypeAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code value} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getValueAttribute() { return getAttributeDirect(VALUE_ATTRIBUTE); diff --git a/src/main/java/org/htmlunit/html/HtmlMap.java b/src/main/java/org/htmlunit/html/HtmlMap.java index 7ac59c853fa..bb248b3b4ef 100644 --- a/src/main/java/org/htmlunit/html/HtmlMap.java +++ b/src/main/java/org/htmlunit/html/HtmlMap.java @@ -52,7 +52,7 @@ public class HtmlMap extends HtmlElement { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code name} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getNameAttribute() { return getAttributeDirect(NAME_ATTRIBUTE); diff --git a/src/main/java/org/htmlunit/html/HtmlMenu.java b/src/main/java/org/htmlunit/html/HtmlMenu.java index e582f81a4c0..4a920511bb6 100644 --- a/src/main/java/org/htmlunit/html/HtmlMenu.java +++ b/src/main/java/org/htmlunit/html/HtmlMenu.java @@ -50,7 +50,7 @@ public class HtmlMenu extends HtmlElement { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code compact} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getCompactAttribute() { return getAttributeDirect("compact"); diff --git a/src/main/java/org/htmlunit/html/HtmlMeta.java b/src/main/java/org/htmlunit/html/HtmlMeta.java index 72e7fdae9f7..cb73a6ce15b 100644 --- a/src/main/java/org/htmlunit/html/HtmlMeta.java +++ b/src/main/java/org/htmlunit/html/HtmlMeta.java @@ -68,7 +68,7 @@ public boolean mayBeDisplayed() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code http-equiv} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getHttpEquivAttribute() { return getAttribute("http-equiv"); @@ -80,7 +80,7 @@ public final String getHttpEquivAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code name} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getNameAttribute() { return getAttributeDirect(NAME_ATTRIBUTE); @@ -92,7 +92,7 @@ public final String getNameAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code content} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getContentAttribute() { return getAttributeDirect("content"); @@ -104,7 +104,7 @@ public final String getContentAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code scheme} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getSchemeAttribute() { return getAttributeDirect("scheme"); diff --git a/src/main/java/org/htmlunit/html/HtmlObject.java b/src/main/java/org/htmlunit/html/HtmlObject.java index 7c0650b6bb6..e1464ff9003 100644 --- a/src/main/java/org/htmlunit/html/HtmlObject.java +++ b/src/main/java/org/htmlunit/html/HtmlObject.java @@ -60,7 +60,7 @@ public class HtmlObject extends HtmlElement implements ValidatableElement { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code declare} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getDeclareAttribute() { return getAttributeDirect("declare"); @@ -72,7 +72,7 @@ public final String getDeclareAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code classid} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getClassIdAttribute() { return getAttributeDirect("classid"); @@ -84,7 +84,7 @@ public final String getClassIdAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute "codebase" - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getCodebaseAttribute() { return getAttributeDirect("codebase"); @@ -96,7 +96,7 @@ public final String getCodebaseAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code data} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getDataAttribute() { return getAttributeDirect("data"); @@ -108,7 +108,7 @@ public final String getDataAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code type} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getTypeAttribute() { return getAttributeDirect(TYPE_ATTRIBUTE); @@ -120,7 +120,7 @@ public final String getTypeAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute "codetype" - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getCodeTypeAttribute() { return getAttributeDirect("codetype"); @@ -132,7 +132,7 @@ public final String getCodeTypeAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code archive} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getArchiveAttribute() { return getAttributeDirect("archive"); @@ -144,7 +144,7 @@ public final String getArchiveAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code standby} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getStandbyAttribute() { return getAttributeDirect("standby"); @@ -156,7 +156,7 @@ public final String getStandbyAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code height} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getHeightAttribute() { return getAttributeDirect("height"); @@ -168,7 +168,7 @@ public final String getHeightAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code width} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getWidthAttribute() { return getAttributeDirect("width"); @@ -180,7 +180,7 @@ public final String getWidthAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code usemap} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getUseMapAttribute() { return getAttributeDirect("usemap"); @@ -192,7 +192,7 @@ public final String getUseMapAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code name} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getNameAttribute() { return getAttributeDirect(NAME_ATTRIBUTE); @@ -204,7 +204,7 @@ public final String getNameAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code tabindex} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getTabIndexAttribute() { return getAttributeDirect("tabindex"); @@ -216,7 +216,7 @@ public final String getTabIndexAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code align} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getAlignAttribute() { return getAttributeDirect("align"); @@ -228,7 +228,7 @@ public final String getAlignAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code border} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getBorderAttribute() { return getAttributeDirect("border"); @@ -240,7 +240,7 @@ public final String getBorderAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code hspace} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getHspaceAttribute() { return getAttributeDirect("hspace"); @@ -252,7 +252,7 @@ public final String getHspaceAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code vspace} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getVspaceAttribute() { return getAttributeDirect("vspace"); diff --git a/src/main/java/org/htmlunit/html/HtmlOption.java b/src/main/java/org/htmlunit/html/HtmlOption.java index 3e8d0167e57..12438877c9e 100644 --- a/src/main/java/org/htmlunit/html/HtmlOption.java +++ b/src/main/java/org/htmlunit/html/HtmlOption.java @@ -151,7 +151,7 @@ public void reset() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code selected} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getSelectedAttribute() { return getAttributeDirect("selected"); diff --git a/src/main/java/org/htmlunit/html/HtmlOrderedList.java b/src/main/java/org/htmlunit/html/HtmlOrderedList.java index f535b6f46a5..25e20d1c087 100644 --- a/src/main/java/org/htmlunit/html/HtmlOrderedList.java +++ b/src/main/java/org/htmlunit/html/HtmlOrderedList.java @@ -50,7 +50,7 @@ public class HtmlOrderedList extends HtmlElement { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code type} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getTypeAttribute() { return getAttributeDirect(TYPE_ATTRIBUTE); @@ -62,7 +62,7 @@ public final String getTypeAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code compact} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getCompactAttribute() { return getAttributeDirect("compact"); @@ -74,7 +74,7 @@ public final String getCompactAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code start} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getStartAttribute() { return getAttributeDirect("start"); diff --git a/src/main/java/org/htmlunit/html/HtmlPage.java b/src/main/java/org/htmlunit/html/HtmlPage.java index 7c91c2fb014..a52a241cb47 100644 --- a/src/main/java/org/htmlunit/html/HtmlPage.java +++ b/src/main/java/org/htmlunit/html/HtmlPage.java @@ -15,7 +15,6 @@ package org.htmlunit.html; import static org.htmlunit.BrowserVersionFeatures.EVENT_FOCUS_ON_LOAD; -import static org.htmlunit.BrowserVersionFeatures.JS_EVENT_LOAD_SUPPRESSED_BY_CONTENT_SECURIRY_POLICY; import static org.htmlunit.html.DomElement.ATTRIBUTE_NOT_DEFINED; import java.io.File; @@ -67,7 +66,6 @@ import org.htmlunit.corejs.javascript.Scriptable; import org.htmlunit.css.ComputedCssStyleDeclaration; import org.htmlunit.css.CssStyleSheet; -import org.htmlunit.html.FrameWindow.PageDenied; import org.htmlunit.html.impl.SimpleRange; import org.htmlunit.html.parser.HTMLParserDOMBuilder; import org.htmlunit.http.HttpStatus; @@ -232,8 +230,8 @@ public boolean hasCaseSensitiveTagNames() { * Initialize this page. * @throws IOException if an IO problem occurs * @throws FailingHttpStatusCodeException if the server returns a failing status code AND the property - * {@link org.htmlunit.WebClientOptions#setThrowExceptionOnFailingStatusCode(boolean)} is set - * to true. + * {@link org.htmlunit.WebClientOptions#setThrowExceptionOnFailingStatusCode(boolean)} is set + * to true. */ @Override public void initialize() throws IOException, FailingHttpStatusCodeException { @@ -785,8 +783,8 @@ public List getTabbableElementIds() { * Additionally, the value of tabindex must be within 0 and 32767. Any * values outside this range will be ignored.

* - * The following elements support the tabindex attribute: A, AREA, BUTTON, - * INPUT, OBJECT, SELECT, and TEXTAREA.

+ * The following elements support the tabindex attribute: + * A, AREA, BUTTON, INPUT, OBJECT, SELECT, and TEXTAREA. * * @return all the tabbable elements in proper tab order */ @@ -908,7 +906,7 @@ public List getHtmlElementsByAccessKey(final char accessKey) { * (see {@link org.htmlunit.WebClient#isJavaScriptEnabled()}.

* @param sourceCode the JavaScript code to execute * @return a ScriptResult which will contain both the current page (which may be different than - * the previous page) and a JavaScript result object + * the previous page) and a JavaScript result object */ public ScriptResult executeJavaScript(final String sourceCode) { return executeJavaScript(sourceCode, "injected script", 1); @@ -932,7 +930,7 @@ public ScriptResult executeJavaScript(final String sourceCode) { * @param sourceName the name for this chunk of code (will be displayed in error messages) * @param startLine the line at which the script source starts * @return a ScriptResult which will contain both the current page (which may be different than - * the previous page and a JavaScript result object. + * the previous page and a JavaScript result object. */ public ScriptResult executeJavaScript(String sourceCode, final String sourceName, final int startLine) { if (!getWebClient().isJavaScriptEnabled()) { @@ -1288,12 +1286,6 @@ else if (Event.TYPE_READY_STATE_CHANGE.equals(eventType)) { event = new BeforeUnloadEvent(frame, eventType); } else { - // ff does not trigger the onload event in this case - if (PageDenied.BY_CONTENT_SECURIRY_POLICY == fw.getPageDenied() - && hasFeature(JS_EVENT_LOAD_SUPPRESSED_BY_CONTENT_SECURIRY_POLICY)) { - return true; - } - event = new Event(frame, eventType); } // This fires the "load" event for the element which, like all non-window @@ -1531,7 +1523,7 @@ public FrameWindow getFrameByName(final String name) throws ElementNotFoundExcep * * @param accessKey the key that will be pressed * @return the element that has the focus after pressing this access key or null if no element - * has the focus. + * has the focus. * @throws IOException if an IO error occurs during the processing of this access key (this * would only happen if the access key triggered a button which in turn caused a page load) */ @@ -2649,7 +2641,7 @@ public void putStyleIntoCache(final DomElement element, final String normalizedP * INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
* * @return a list of all styles from this page (<style> and <link rel=stylesheet>). - * This returns an empty list if css support is disabled in the web client options. + * This returns an empty list if css support is disabled in the web client options. */ public List getStyleSheets() { final List styles = new ArrayList<>(); @@ -2783,7 +2775,8 @@ private void nodeChanged(final DomNode changedNode, final String attribName) { } // Apparently it wasn't a stylesheet that changed; be semi-smart about what we evict and when. - final boolean clearParents = ATTRIBUTES_AFFECTING_PARENT.contains(attribName); + // null means that a node was added/removed; we always have to take care of this for the parents + final boolean clearParents = attribName == null || ATTRIBUTES_AFFECTING_PARENT.contains(attribName); if (computedStylesCache_ != null) { computedStylesCache_.nodeChanged(changedNode, clearParents); } diff --git a/src/main/java/org/htmlunit/html/HtmlParagraph.java b/src/main/java/org/htmlunit/html/HtmlParagraph.java index fcb292f0472..c8e4cd21f4b 100644 --- a/src/main/java/org/htmlunit/html/HtmlParagraph.java +++ b/src/main/java/org/htmlunit/html/HtmlParagraph.java @@ -51,7 +51,7 @@ public class HtmlParagraph extends HtmlElement { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code align} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getAlignAttribute() { return getAttributeDirect("align"); diff --git a/src/main/java/org/htmlunit/html/HtmlParameter.java b/src/main/java/org/htmlunit/html/HtmlParameter.java index 033d60879b4..c44aedaa1c3 100644 --- a/src/main/java/org/htmlunit/html/HtmlParameter.java +++ b/src/main/java/org/htmlunit/html/HtmlParameter.java @@ -50,7 +50,7 @@ public class HtmlParameter extends HtmlElement { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code id} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getIdAttribute() { return getAttributeDirect(ID_ATTRIBUTE); @@ -62,7 +62,7 @@ public final String getIdAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code name} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getNameAttribute() { return getAttributeDirect(NAME_ATTRIBUTE); @@ -74,7 +74,7 @@ public final String getNameAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code value} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getValueAttribute() { return getAttributeDirect(VALUE_ATTRIBUTE); @@ -86,7 +86,7 @@ public final String getValueAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code valuetype} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getValueTypeAttribute() { return getAttributeDirect("valuetype"); @@ -98,7 +98,7 @@ public final String getValueTypeAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code type} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getTypeAttribute() { return getAttributeDirect(TYPE_ATTRIBUTE); diff --git a/src/main/java/org/htmlunit/html/HtmlPreformattedText.java b/src/main/java/org/htmlunit/html/HtmlPreformattedText.java index 3e1a63c67f5..265711cdbc2 100644 --- a/src/main/java/org/htmlunit/html/HtmlPreformattedText.java +++ b/src/main/java/org/htmlunit/html/HtmlPreformattedText.java @@ -50,7 +50,7 @@ public class HtmlPreformattedText extends HtmlElement { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code width} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getWidthAttribute() { return getAttributeDirect("width"); diff --git a/src/main/java/org/htmlunit/html/HtmlRadioButtonInput.java b/src/main/java/org/htmlunit/html/HtmlRadioButtonInput.java index 8471105f8cb..d0eeb72b17d 100644 --- a/src/main/java/org/htmlunit/html/HtmlRadioButtonInput.java +++ b/src/main/java/org/htmlunit/html/HtmlRadioButtonInput.java @@ -96,7 +96,7 @@ void setCheckedInternal(final boolean isChecked) { * * @param isChecked true if this element is to be selected * @return the page that occupies this window after setting checked status - * It may be the same window or it may be a freshly loaded one. + * It may be the same window or it may be a freshly loaded one. */ @Override public Page setChecked(final boolean isChecked) { diff --git a/src/main/java/org/htmlunit/html/HtmlScript.java b/src/main/java/org/htmlunit/html/HtmlScript.java index 7eb093bb317..4a5fdc5c32d 100644 --- a/src/main/java/org/htmlunit/html/HtmlScript.java +++ b/src/main/java/org/htmlunit/html/HtmlScript.java @@ -72,7 +72,7 @@ public class HtmlScript extends HtmlElement implements ScriptElement { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code charset} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getCharsetAttribute() { return getAttributeDirect("charset"); @@ -92,7 +92,7 @@ public final String getScriptCharset() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code type} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getTypeAttribute() { return getAttributeDirect(TYPE_ATTRIBUTE); @@ -104,7 +104,7 @@ public final String getTypeAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code language} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getLanguageAttribute() { return getAttributeDirect("language"); @@ -116,7 +116,7 @@ public final String getLanguageAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code src} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getSrcAttribute() { return getSrcAttributeNormalized(); @@ -152,7 +152,7 @@ public final String getHtmlForAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code defer} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getDeferAttribute() { return getAttributeDirect("defer"); diff --git a/src/main/java/org/htmlunit/html/HtmlSelect.java b/src/main/java/org/htmlunit/html/HtmlSelect.java index 10ad2b0fb4d..5c3b99a774c 100644 --- a/src/main/java/org/htmlunit/html/HtmlSelect.java +++ b/src/main/java/org/htmlunit/html/HtmlSelect.java @@ -275,7 +275,7 @@ public DomNode appendChild(final Node node) { * @param optionValue the value of the option that is to change * @param

the page type * @return the page contained in the current window as returned - * by {@link org.htmlunit.WebClient#getCurrentWindow()} + * by {@link org.htmlunit.WebClient#getCurrentWindow()} */ public

P setSelectedAttribute(final String optionValue, final boolean isSelected) { return setSelectedAttribute(optionValue, isSelected, true); @@ -294,7 +294,7 @@ public

P setSelectedAttribute(final String optionValue, final b * @param invokeOnFocus whether to set focus or not. * @param

the page type * @return the page contained in the current window as returned - * by {@link org.htmlunit.WebClient#getCurrentWindow()} + * by {@link org.htmlunit.WebClient#getCurrentWindow()} */ @SuppressWarnings("unchecked") public

P setSelectedAttribute(final String optionValue, @@ -321,7 +321,7 @@ public

P setSelectedAttribute(final String optionValue, * @param selectedOption the value of the option that is to change * @param

the page type * @return the page contained in the current window as returned - * by {@link org.htmlunit.WebClient#getCurrentWindow()} + * by {@link org.htmlunit.WebClient#getCurrentWindow()} */ public

P setSelectedAttribute(final HtmlOption selectedOption, final boolean isSelected) { return setSelectedAttribute(selectedOption, isSelected, true, true, false, true); @@ -343,7 +343,7 @@ public

P setSelectedAttribute(final HtmlOption selectedOption, * @param isClick is mouse clicked * @param

the page type * @return the page contained in the current window as returned - * by {@link org.htmlunit.WebClient#getCurrentWindow()} + * by {@link org.htmlunit.WebClient#getCurrentWindow()} */ @SuppressWarnings("unchecked") public

P setSelectedAttribute(final HtmlOption selectedOption, final boolean isSelected, diff --git a/src/main/java/org/htmlunit/html/HtmlTable.java b/src/main/java/org/htmlunit/html/HtmlTable.java index 71731bd5601..a656ed38ebb 100644 --- a/src/main/java/org/htmlunit/html/HtmlTable.java +++ b/src/main/java/org/htmlunit/html/HtmlTable.java @@ -235,7 +235,7 @@ public List getBodies() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code summary} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getSummaryAttribute() { return getAttributeDirect("summary"); @@ -247,7 +247,7 @@ public final String getSummaryAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code width} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getWidthAttribute() { return getAttributeDirect("width"); @@ -259,7 +259,7 @@ public final String getWidthAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code border} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getBorderAttribute() { return getAttributeDirect("border"); @@ -271,7 +271,7 @@ public final String getBorderAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code frame} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getFrameAttribute() { return getAttributeDirect("frame"); @@ -283,7 +283,7 @@ public final String getFrameAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code rules} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getRulesAttribute() { return getAttributeDirect("rules"); @@ -295,7 +295,7 @@ public final String getRulesAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code cellspacing} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getCellSpacingAttribute() { return getAttributeDirect("cellspacing"); @@ -307,7 +307,7 @@ public final String getCellSpacingAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code cellpadding} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getCellPaddingAttribute() { return getAttributeDirect("cellpadding"); @@ -319,7 +319,7 @@ public final String getCellPaddingAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code align} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getAlignAttribute() { return getAttributeDirect("align"); @@ -331,7 +331,7 @@ public final String getAlignAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code bgcolor} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getBgcolorAttribute() { return getAttributeDirect("bgcolor"); diff --git a/src/main/java/org/htmlunit/html/HtmlTableColumn.java b/src/main/java/org/htmlunit/html/HtmlTableColumn.java index abc8e1bdbd1..41b63761952 100644 --- a/src/main/java/org/htmlunit/html/HtmlTableColumn.java +++ b/src/main/java/org/htmlunit/html/HtmlTableColumn.java @@ -51,7 +51,7 @@ public class HtmlTableColumn extends HtmlElement { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code span} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getSpanAttribute() { return getAttributeDirect("span"); @@ -63,7 +63,7 @@ public final String getSpanAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code width} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getWidthAttribute() { return getAttributeDirect("width"); @@ -75,7 +75,7 @@ public final String getWidthAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code align} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getAlignAttribute() { return getAttributeDirect("align"); @@ -87,7 +87,7 @@ public final String getAlignAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code char} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getCharAttribute() { return getAttributeDirect("char"); @@ -99,7 +99,7 @@ public final String getCharAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code charoff} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getCharoffAttribute() { return getAttributeDirect("charoff"); @@ -111,7 +111,7 @@ public final String getCharoffAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code valign} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getValignAttribute() { return getAttributeDirect("valign"); diff --git a/src/main/java/org/htmlunit/html/HtmlTableColumnGroup.java b/src/main/java/org/htmlunit/html/HtmlTableColumnGroup.java index 9ba63d40c1d..ac92ea5e2f6 100644 --- a/src/main/java/org/htmlunit/html/HtmlTableColumnGroup.java +++ b/src/main/java/org/htmlunit/html/HtmlTableColumnGroup.java @@ -51,7 +51,7 @@ public class HtmlTableColumnGroup extends HtmlElement { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code span} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getSpanAttribute() { return getAttributeDirect("span"); @@ -63,7 +63,7 @@ public final String getSpanAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code width} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getWidthAttribute() { return getAttributeDirect("width"); @@ -75,7 +75,7 @@ public final String getWidthAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code align} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getAlignAttribute() { return getAttributeDirect("align"); @@ -87,7 +87,7 @@ public final String getAlignAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code char} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getCharAttribute() { return getAttributeDirect("char"); @@ -99,7 +99,7 @@ public final String getCharAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code charoff} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getCharoffAttribute() { return getAttributeDirect("charoff"); @@ -111,7 +111,7 @@ public final String getCharoffAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code valign} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getValignAttribute() { return getAttributeDirect("valign"); diff --git a/src/main/java/org/htmlunit/html/HtmlTableDataCell.java b/src/main/java/org/htmlunit/html/HtmlTableDataCell.java index dd77fd2889b..65693e08c7f 100644 --- a/src/main/java/org/htmlunit/html/HtmlTableDataCell.java +++ b/src/main/java/org/htmlunit/html/HtmlTableDataCell.java @@ -50,7 +50,7 @@ public class HtmlTableDataCell extends HtmlTableCell { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code abbr} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getAbbrAttribute() { return getAttributeDirect("abbr"); @@ -62,7 +62,7 @@ public final String getAbbrAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code axis} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getAxisAttribute() { return getAttributeDirect("axis"); @@ -74,7 +74,7 @@ public final String getAxisAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code headers} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getHeadersAttribute() { return getAttributeDirect("headers"); @@ -86,7 +86,7 @@ public final String getHeadersAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code scope} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getScopeAttribute() { return getAttributeDirect("scope"); @@ -98,7 +98,7 @@ public final String getScopeAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code rowspan} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getRowSpanAttribute() { return getAttributeDirect("rowspan"); @@ -110,7 +110,7 @@ public final String getRowSpanAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code colspan} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getColumnSpanAttribute() { return getAttributeDirect("colspan"); @@ -122,7 +122,7 @@ public final String getColumnSpanAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code align} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getAlignAttribute() { return getAttributeDirect("align"); @@ -134,7 +134,7 @@ public final String getAlignAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code char} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getCharAttribute() { return getAttributeDirect("char"); @@ -146,7 +146,7 @@ public final String getCharAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code charoff} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getCharoffAttribute() { return getAttributeDirect("charoff"); @@ -158,7 +158,7 @@ public final String getCharoffAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code valign} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getValignAttribute() { return getAttributeDirect("valign"); @@ -170,7 +170,7 @@ public final String getValignAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code nowrap} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getNoWrapAttribute() { return getAttributeDirect("nowrap"); @@ -182,7 +182,7 @@ public final String getNoWrapAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code bgcolor} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getBgcolorAttribute() { return getAttributeDirect("bgcolor"); @@ -194,7 +194,7 @@ public final String getBgcolorAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code width} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getWidthAttribute() { return getAttributeDirect("width"); @@ -206,7 +206,7 @@ public final String getWidthAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code height} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getHeightAttribute() { return getAttributeDirect("height"); diff --git a/src/main/java/org/htmlunit/html/HtmlTableHeaderCell.java b/src/main/java/org/htmlunit/html/HtmlTableHeaderCell.java index 7885fc90b04..40514eb6bc4 100644 --- a/src/main/java/org/htmlunit/html/HtmlTableHeaderCell.java +++ b/src/main/java/org/htmlunit/html/HtmlTableHeaderCell.java @@ -50,7 +50,7 @@ public class HtmlTableHeaderCell extends HtmlTableCell { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code abbr} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getAbbrAttribute() { return getAttributeDirect("abbr"); @@ -62,7 +62,7 @@ public final String getAbbrAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code axis} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getAxisAttribute() { return getAttributeDirect("axis"); @@ -74,7 +74,7 @@ public final String getAxisAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code headers} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getHeadersAttribute() { return getAttributeDirect("headers"); @@ -86,7 +86,7 @@ public final String getHeadersAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code scope} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getScopeAttribute() { return getAttributeDirect("scope"); @@ -98,7 +98,7 @@ public final String getScopeAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code rowspan} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getRowSpanAttribute() { return getAttributeDirect("rowspan"); @@ -110,7 +110,7 @@ public final String getRowSpanAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code colspan} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getColumnSpanAttribute() { return getAttributeDirect("colspan"); @@ -122,7 +122,7 @@ public final String getColumnSpanAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code align} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getAlignAttribute() { return getAttributeDirect("align"); @@ -134,7 +134,7 @@ public final String getAlignAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code char} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getCharAttribute() { return getAttributeDirect("char"); @@ -146,7 +146,7 @@ public final String getCharAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code charoff} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getCharoffAttribute() { return getAttributeDirect("charoff"); @@ -158,7 +158,7 @@ public final String getCharoffAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code valign} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getValignAttribute() { return getAttributeDirect("valign"); @@ -170,7 +170,7 @@ public final String getValignAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code nowrap} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getNoWrapAttribute() { return getAttributeDirect("nowrap"); @@ -182,7 +182,7 @@ public final String getNoWrapAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code bgcolor} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getBgcolorAttribute() { return getAttributeDirect("bgcolor"); @@ -194,7 +194,7 @@ public final String getBgcolorAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code width} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getWidthAttribute() { return getAttributeDirect("width"); @@ -206,7 +206,7 @@ public final String getWidthAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code height} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getHeightAttribute() { return getAttributeDirect("height"); diff --git a/src/main/java/org/htmlunit/html/HtmlTableRow.java b/src/main/java/org/htmlunit/html/HtmlTableRow.java index 7d0eba3849e..0afdd5f95a9 100644 --- a/src/main/java/org/htmlunit/html/HtmlTableRow.java +++ b/src/main/java/org/htmlunit/html/HtmlTableRow.java @@ -91,7 +91,7 @@ public HtmlTableCell getCell(final int index) throws IndexOutOfBoundsException { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code align} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getAlignAttribute() { return getAttributeDirect("align"); @@ -103,7 +103,7 @@ public final String getAlignAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code char} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getCharAttribute() { return getAttributeDirect("char"); @@ -115,7 +115,7 @@ public final String getCharAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code charoff} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getCharoffAttribute() { return getAttributeDirect("charoff"); @@ -127,7 +127,7 @@ public final String getCharoffAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code valign} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getValignAttribute() { return getAttributeDirect("valign"); @@ -147,7 +147,7 @@ public HtmlTable getEnclosingTable() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code bgcolor} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getBgcolorAttribute() { return getAttributeDirect("bgcolor"); @@ -166,7 +166,9 @@ public CellIterator() { setNextCell(getFirstChild()); } - /** @return whether there is another cell available */ + /** + * @return whether there is another cell available + */ @Override public boolean hasNext() { return nextCell_ != null; diff --git a/src/main/java/org/htmlunit/html/HtmlUnorderedList.java b/src/main/java/org/htmlunit/html/HtmlUnorderedList.java index a9b6b5ddb07..e12a0904b37 100644 --- a/src/main/java/org/htmlunit/html/HtmlUnorderedList.java +++ b/src/main/java/org/htmlunit/html/HtmlUnorderedList.java @@ -50,7 +50,7 @@ public class HtmlUnorderedList extends HtmlElement { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code type} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getTypeAttribute() { return getAttributeDirect(TYPE_ATTRIBUTE); @@ -62,7 +62,7 @@ public final String getTypeAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code compact} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getCompactAttribute() { return getAttributeDirect("compact"); diff --git a/src/main/java/org/htmlunit/html/ScriptElementSupport.java b/src/main/java/org/htmlunit/html/ScriptElementSupport.java index 871f01ba8f6..796c53d1a94 100644 --- a/src/main/java/org/htmlunit/html/ScriptElementSupport.java +++ b/src/main/java/org/htmlunit/html/ScriptElementSupport.java @@ -74,7 +74,8 @@ public static void onAllChildrenAddedToPage(final ScriptElement script, final bo LOG.debug("Script node added: " + element.asXml()); } - final WebClient webClient = element.getPage().getWebClient(); + final SgmlPage page = element.getPage(); + final WebClient webClient = page.getWebClient(); if (!webClient.isJavaScriptEngineEnabled()) { LOG.debug("Script found but not executed because javascript engine is disabled"); return; @@ -86,7 +87,7 @@ public static void onAllChildrenAddedToPage(final ScriptElement script, final bo return; } - final WebWindow webWindow = element.getPage().getEnclosingWindow(); + final WebWindow webWindow = page.getEnclosingWindow(); if (webWindow != null) { final StringBuilder description = new StringBuilder() .append("Execution of ") @@ -96,7 +97,7 @@ public static void onAllChildrenAddedToPage(final ScriptElement script, final bo description.append(" (").append(srcAttrib).append(')'); } - final PostponedAction action = new PostponedAction(element.getPage(), description.toString()) { + final PostponedAction action = new PostponedAction(page, description.toString()) { @Override public void execute() { // see HTMLDocument.setExecutingDynamicExternalPosponed(boolean) @@ -105,7 +106,7 @@ public void execute() { if (window != null) { jsDoc = (HTMLDocument) window.getDocument(); jsDoc.setExecutingDynamicExternalPosponed(element.getStartLineNumber() == -1 - && ATTRIBUTE_NOT_DEFINED != srcAttrib); + && !hasNoSrcAttrib); } try { executeScriptIfNeeded(script, false, false); @@ -119,12 +120,10 @@ public void execute() { }; final AbstractJavaScriptEngine engine = webClient.getJavaScriptEngine(); - if (element.hasAttribute("async") && !engine.isScriptRunning()) { - final HtmlPage owningPage = element.getHtmlPageOrNull(); - owningPage.addAfterLoadAction(action); + if (element.hasAttribute("async") && !hasNoSrcAttrib) { + engine.addPostponedAction(action); } - else if (element.hasAttribute("async") - || postponed && StringUtils.isBlank(element.getTextContent())) { + else if (postponed && !hasNoSrcAttrib) { engine.addPostponedAction(action); } else { @@ -306,6 +305,10 @@ public static boolean isJavaScript(String typeAttribute, final String languageAt private static void executeEvent(final DomElement element, final String type) { final EventTarget eventTarget = element.getScriptableObject(); final Event event = new Event(element, type); + + event.setParentScope(eventTarget); + event.setPrototype(eventTarget.getPrototype(event.getClass())); + eventTarget.executeEventLocally(event); } diff --git a/src/main/java/org/htmlunit/html/TableRowGroup.java b/src/main/java/org/htmlunit/html/TableRowGroup.java index 4c3655a8d13..c1befc12605 100644 --- a/src/main/java/org/htmlunit/html/TableRowGroup.java +++ b/src/main/java/org/htmlunit/html/TableRowGroup.java @@ -68,7 +68,7 @@ public final List getRows() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code align} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getAlignAttribute() { return getAttributeDirect("align"); @@ -80,7 +80,7 @@ public final String getAlignAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code char} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getCharAttribute() { return getAttributeDirect("char"); @@ -92,7 +92,7 @@ public final String getCharAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code charoff} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getCharoffAttribute() { return getAttributeDirect("charoff"); @@ -104,7 +104,7 @@ public final String getCharoffAttribute() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code valign} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getValignAttribute() { return getAttributeDirect("valign"); diff --git a/src/main/java/org/htmlunit/html/ValidatableElement.java b/src/main/java/org/htmlunit/html/ValidatableElement.java index 844b3f7cb09..0b441b20e32 100644 --- a/src/main/java/org/htmlunit/html/ValidatableElement.java +++ b/src/main/java/org/htmlunit/html/ValidatableElement.java @@ -37,7 +37,7 @@ public interface ValidatableElement { /** * @return a boolean value boolean value that is true if the user - * has provided input that the browser is unable to convert. + * has provided input that the browser is unable to convert. */ default boolean hasBadInputValidityState() { return false; @@ -45,14 +45,14 @@ default boolean hasBadInputValidityState() { /** * @return a boolean value indicating whether the element's custom validity message - * has been set to a non-empty string by calling the element's setCustomValidity() method. + * has been set to a non-empty string by calling the element's setCustomValidity() method. */ boolean isCustomErrorValidityState(); /** * @return true if the value does not match the specified pattern, - * and false if it does match. - * If true, the element matches the :invalid CSS pseudo-class + * and false if it does match. + * If true, the element matches the :invalid CSS pseudo-class */ default boolean hasPatternMismatchValidityState() { return false; @@ -60,9 +60,9 @@ default boolean hasPatternMismatchValidityState() { /** * @return true if the value does not fit the rules determined by the step attribute - * (that is, it's not evenly divisible by the step value), - * or false if it does fit the step rule. - * If true, the element matches the :invalid and :out-of-range CSS pseudo-classes. + * (that is, it's not evenly divisible by the step value), + * or false if it does fit the step rule. + * If true, the element matches the :invalid and :out-of-range CSS pseudo-classes. */ default boolean isStepMismatchValidityState() { return false; @@ -70,8 +70,8 @@ default boolean isStepMismatchValidityState() { /** * @return true if the value is longer than the maximum length specified - * by the maxlength attribute, or false if it is shorter than or equal to the maximum. - * If true, the element matches the :invalid CSS pseudo-class + * by the maxlength attribute, or false if it is shorter than or equal to the maximum. + * If true, the element matches the :invalid CSS pseudo-class */ default boolean isTooLongValidityState() { return false; @@ -79,8 +79,8 @@ default boolean isTooLongValidityState() { /** * @return true if the value is shorter than the minimum length specified - * by the minlength attribute, or false if it is greater than or equal to the minimum. - * If true, the element matches the :invalid CSS pseudo-class + * by the minlength attribute, or false if it is greater than or equal to the minimum. + * If true, the element matches the :invalid CSS pseudo-class */ default boolean isTooShortValidityState() { return false; @@ -88,8 +88,8 @@ default boolean isTooShortValidityState() { /** * @return true if the value is not in the required syntax (when type is email or url), - * or false if the syntax is correct. - * If true, the element matches the :invalid CSS pseudo-class. + * or false if the syntax is correct. + * If true, the element matches the :invalid CSS pseudo-class. */ default boolean hasTypeMismatchValidityState() { return false; @@ -97,8 +97,8 @@ default boolean hasTypeMismatchValidityState() { /** * @return true if the value is greater than the maximum specified by the max attribute, - * or false if it is less than or equal to the maximum. - * If true, the element matches the :invalid and :out-of-range CSS pseudo-classes. + * or false if it is less than or equal to the maximum. + * If true, the element matches the :invalid and :out-of-range CSS pseudo-classes. */ default boolean hasRangeOverflowValidityState() { return false; @@ -106,8 +106,8 @@ default boolean hasRangeOverflowValidityState() { /** * @return true if the value is less than the minimum specified by the min attribute, - * or false if it is greater than or equal to the minimum. - * If true, the element matches the :invalid and :out-of-range CSS pseudo-classes. + * or false if it is greater than or equal to the minimum. + * If true, the element matches the :invalid and :out-of-range CSS pseudo-classes. */ default boolean hasRangeUnderflowValidityState() { return false; @@ -115,14 +115,14 @@ default boolean hasRangeUnderflowValidityState() { /** * @return true if the element meets all its validation constraints, and is therefore - * considered to be valid, or false if it fails any constraint. - * If true, the element matches the :valid CSS pseudo-class; the :invalid CSS pseudo-class otherwise. + * considered to be valid, or false if it fails any constraint. + * If true, the element matches the :valid CSS pseudo-class; the :invalid CSS pseudo-class otherwise. */ boolean isValidValidityState(); /** * @return true if the element has a required attribute, but no value, or false otherwise. - * If true, the element matches the :invalid CSS pseudo-class. + * If true, the element matches the :invalid CSS pseudo-class. */ default boolean isValueMissingValidityState() { return false; diff --git a/src/main/java/org/htmlunit/html/XmlSerializer.java b/src/main/java/org/htmlunit/html/XmlSerializer.java index a462cf6b7f7..79e7c20789d 100644 --- a/src/main/java/org/htmlunit/html/XmlSerializer.java +++ b/src/main/java/org/htmlunit/html/XmlSerializer.java @@ -54,6 +54,12 @@ public class XmlSerializer { private final StringBuilder indent_ = new StringBuilder(); private File outputDir_; + /** + * Saves the given {@link SgmlPage} to the file. + * @param page the page to save + * @param file the destination + * @throws IOException in case of error + */ public void save(final SgmlPage page, final File file) throws IOException { save(page, file, false); } diff --git a/src/main/java/org/htmlunit/html/impl/SimpleRange.java b/src/main/java/org/htmlunit/html/impl/SimpleRange.java index 2705f7877df..a9fa08f70a3 100644 --- a/src/main/java/org/htmlunit/html/impl/SimpleRange.java +++ b/src/main/java/org/htmlunit/html/impl/SimpleRange.java @@ -291,7 +291,7 @@ public DomDocumentFragment extractContents() throws DOMException { /** * @return true if startContainer equals endContainer and - * startOffset equals endOffset + * startOffset equals endOffset * @throws DOMException in case of error */ public boolean isCollapsed() throws DOMException { @@ -300,7 +300,7 @@ public boolean isCollapsed() throws DOMException { /** * @return the deepest common ancestor container of this range's two - * boundary-points. + * boundary-points. * @throws DOMException in case of error */ public DomNode getCommonAncestorContainer() throws DOMException { diff --git a/src/main/java/org/htmlunit/html/parser/neko/HtmlUnitNekoHtmlParser.java b/src/main/java/org/htmlunit/html/parser/neko/HtmlUnitNekoHtmlParser.java index 1a0b8d7c79a..6c40cb36074 100644 --- a/src/main/java/org/htmlunit/html/parser/neko/HtmlUnitNekoHtmlParser.java +++ b/src/main/java/org/htmlunit/html/parser/neko/HtmlUnitNekoHtmlParser.java @@ -315,7 +315,9 @@ class HtmlUnitNekoHTMLErrorHandler implements XMLErrorHandler { html_ = htmlContent; } - /** @see DefaultErrorHandler#error(String,String,XMLParseException) */ + /** + * @see DefaultErrorHandler#error(String,String,XMLParseException) + */ @Override public void error(final String domain, final String key, final XMLParseException exception) throws XNIException { @@ -327,7 +329,9 @@ public void error(final String domain, final String key, key); } - /** @see DefaultErrorHandler#warning(String,String,XMLParseException) */ + /** + * @see DefaultErrorHandler#warning(String,String,XMLParseException) + */ @Override public void warning(final String domain, final String key, final XMLParseException exception) throws XNIException { diff --git a/src/main/java/org/htmlunit/html/xpath/XPathHelper.java b/src/main/java/org/htmlunit/html/xpath/XPathHelper.java index c2236fa1950..e7e675ff736 100644 --- a/src/main/java/org/htmlunit/html/xpath/XPathHelper.java +++ b/src/main/java/org/htmlunit/html/xpath/XPathHelper.java @@ -92,6 +92,14 @@ public static List getByXPath(final DomNode contextNode, final String xpa } } + /** + * @param the type of nodes expected + * @param node the start node + * @param xpath the {@link XPathAdapter} to search for + * @param prefixResolver the {@link PrefixResolver} to be used + * @return a list of nodes matching the given xpath + * @throws TransformerException in case of error + */ public static List getByXPath(final Node node, final XPathAdapter xpath, final PrefixResolver prefixResolver) throws TransformerException { final List list = new ArrayList<>(); diff --git a/src/main/java/org/htmlunit/http/HttpUtils.java b/src/main/java/org/htmlunit/http/HttpUtils.java index 352821b7936..34d357f9c2b 100644 --- a/src/main/java/org/htmlunit/http/HttpUtils.java +++ b/src/main/java/org/htmlunit/http/HttpUtils.java @@ -293,7 +293,7 @@ private HttpUtils() { * @param buf buffer with the sequence of chars to be parsed * @param range defines the bounds and current position of the buffer * @param delimiters set of delimiting characters. Can be {@code null} if the token - * is not delimited by any character. + * is not delimited by any character. */ private static String parseToken(final String buf, final ParseRange range, final BitSet delimiters) { final StringBuilder dst = new StringBuilder(); @@ -345,7 +345,7 @@ private static void skipWhiteSpace(final String buf, final ParseRange range) { * @param buf buffer with the sequence of chars to be parsed * @param range defines the bounds and current position of the buffer * @param delimiters set of delimiting characters. Can be {@code null} if the value - * is delimited by a whitespace only. + * is delimited by a whitespace only. * @param dst destination buffer */ private static void copyContent(final String buf, final ParseRange range, diff --git a/src/main/java/org/htmlunit/httpclient/HttpClientConverter.java b/src/main/java/org/htmlunit/httpclient/HttpClientConverter.java index 455633bfadf..9a7a9562f26 100644 --- a/src/main/java/org/htmlunit/httpclient/HttpClientConverter.java +++ b/src/main/java/org/htmlunit/httpclient/HttpClientConverter.java @@ -16,16 +16,12 @@ import java.net.MalformedURLException; import java.net.URL; -import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Collection; -import java.util.Date; import java.util.List; import java.util.Set; import org.apache.http.NoHttpResponseException; -import org.apache.http.client.utils.DateUtils; -import org.apache.http.client.utils.URLEncodedUtils; import org.apache.http.cookie.ClientCookie; import org.apache.http.cookie.Cookie; import org.apache.http.cookie.CookieOrigin; @@ -35,8 +31,6 @@ import org.apache.http.message.BufferedHeader; import org.apache.http.util.CharArrayBuffer; import org.htmlunit.BrowserVersion; -import org.htmlunit.http.HttpStatus; -import org.htmlunit.http.HttpUtils; import org.htmlunit.util.NameValuePair; import org.htmlunit.util.UrlUtils; @@ -47,84 +41,6 @@ */ public final class HttpClientConverter { - /** Forwarder to HttpStatus.SC_OK. - * @deprecated as of version 4.1.0; use {@link HttpStatus#OK_200} instead - */ - @Deprecated - public static final int OK = org.apache.http.HttpStatus.SC_OK; - - /** Forwarder to HttpStatus.SC_NO_CONTENT. - * @deprecated as of version 4.1.0; use {@link HttpStatus#NO_CONTENT_204} instead - */ - @Deprecated - public static final int NO_CONTENT = org.apache.http.HttpStatus.SC_NO_CONTENT; - - /** Forwarder to HttpStatus.MULTIPLE_CHOICES. - * @deprecated as of version 4.1.0; use {@link HttpStatus#MULTIPLE_CHOICES_300} instead - */ - @Deprecated - public static final int MULTIPLE_CHOICES = org.apache.http.HttpStatus.SC_MULTIPLE_CHOICES; - - /** Forwarder to HttpStatus.MOVED_PERMANENTLY. - * @deprecated as of version 4.1.0; use {@link HttpStatus#MOVED_PERMANENTLY_301} instead - */ - @Deprecated - public static final int MOVED_PERMANENTLY = org.apache.http.HttpStatus.SC_MOVED_PERMANENTLY; - - /** Forwarder to HttpStatus.MOVED_TEMPORARILY. - * @deprecated as of version 4.1.0; use {@link HttpStatus#FOUND_302} instead - */ - @Deprecated - public static final int MOVED_TEMPORARILY = org.apache.http.HttpStatus.SC_MOVED_TEMPORARILY; - - /** Forwarder to HttpStatus.SEE_OTHER. - * @deprecated as of version 4.1.0; use {@link HttpStatus#SEE_OTHER_303} instead - */ - @Deprecated - public static final int SEE_OTHER = org.apache.http.HttpStatus.SC_SEE_OTHER; - - /** Forwarder to HttpStatus.TEMPORARY_REDIRECT. - * @deprecated as of version 4.1.0; use {@link HttpStatus#TEMPORARY_REDIRECT_307} instead - */ - @Deprecated - public static final int TEMPORARY_REDIRECT = org.apache.http.HttpStatus.SC_TEMPORARY_REDIRECT; - - /** 308. - * @deprecated as of version 4.1.0; use {@link HttpStatus#PERMANENT_REDIRECT_308} instead - */ - @Deprecated - public static final int PERMANENT_REDIRECT = 308; - - /** Forwarder to HttpStatus.NOT_MODIFIED. - * @deprecated as of version 4.1.0; use {@link HttpStatus#NOT_MODIFIED_304} instead - */ - @Deprecated - public static final int NOT_MODIFIED = org.apache.http.HttpStatus.SC_NOT_MODIFIED; - - /** Forwarder to HttpStatus.SC_USE_PROXY. - * @deprecated as of version 4.1.0; use {@link HttpStatus#USE_PROXY_305} instead - */ - @Deprecated - public static final int USE_PROXY = org.apache.http.HttpStatus.SC_USE_PROXY; - - /** Forwarder to HttpStatus.SC_FORBIDDEN. - * @deprecated as of version 4.1.0; use {@link HttpStatus#FORBIDDEN_403} instead - */ - @Deprecated - public static final int FORBIDDEN = org.apache.http.HttpStatus.SC_FORBIDDEN; - - /** Forwarder to HttpStatus.SC_NOT_FOUND. - * @deprecated as of version 4.1.0; use {@link HttpStatus#NOT_FOUND_404} instead - */ - @Deprecated - public static final int NOT_FOUND = org.apache.http.HttpStatus.SC_NOT_FOUND; - - /** Forwarder to HttpStatus.SC_INTERNAL_SERVER_ERROR. - * @deprecated as of version 4.1.0; use {@link HttpStatus#INTERNAL_SERVER_ERROR_500} instead - */ - @Deprecated - public static final int INTERNAL_SERVER_ERROR = org.apache.http.HttpStatus.SC_INTERNAL_SERVER_ERROR; - private HttpClientConverter() { // util class } @@ -142,67 +58,6 @@ public static List nameValuePairsToHttpClient(fin return resultingPairs; } - /** - * Parses url query into name/value pairs using methods from HttpClient. - * @param query the urlencoded query - * @param charset the charset or null (defaulting to utf-8) - * @return the name/value pairs - * - * @deprecated as of version 4.1.0; use {@link HttpUtils#parseUrlQuery(String, Charset)} instead - */ - @Deprecated - public static List parseUrlQuery(final String query, final Charset charset) { - final List pairs = URLEncodedUtils.parse(query, charset); - - final List resultingPairs = new ArrayList<>(); - for (final org.apache.http.NameValuePair pair : pairs) { - resultingPairs.add(new NameValuePair(pair.getName(), pair.getValue())); - } - return resultingPairs; - } - - /** - * @param parameters the paramters - * @param enc the charset - * @return the query string from the given parameters - * - * @deprecated as of version 4.1.0; use {@link HttpUtils#toQueryFormFields(Iterable, Charset)} instead - */ - @Deprecated - public static String toQueryFormFields(final List parameters, final Charset enc) { - return URLEncodedUtils.format(nameValuePairsToHttpClient(parameters), enc); - } - - /** - * Parses the specified date string, assuming that it is formatted according to RFC 1123, RFC 1036 or as an ANSI - * C HTTP date header. This method returns {@code null} if the specified string is {@code null} or unparseable. - * - * @param s the string to parse as a date - * @return the date version of the specified string, or {@code null} - * - * @deprecated as of version 4.1.0; use {@link HttpUtils#parseDate(String)} instead - */ - @Deprecated - public static Date parseHttpDate(final String s) { - if (s == null) { - return null; - } - return DateUtils.parseDate(s); - } - - /** - * Formats the given date according to the RFC 1123 pattern. - * - * @param date The date to format. - * @return An RFC 1123 formatted date string. - * - * @deprecated as of version 4.1.0; use {@link HttpUtils#parseDate(String)} instead - */ - @Deprecated - public static String formatDate(final Date date) { - return DateUtils.formatDate(date); - } - /** * @param e the exception to check * @return true if the provided Exception is na {@link NoHttpResponseException} @@ -254,6 +109,13 @@ public static URL replaceForCookieIfNecessary(URL url) { return url; } + /** + * @param cookieString the string to parse + * @param pageUrl the page url as root + * @param browserVersion the {@link BrowserVersion} + * @return a list of {@link org.htmlunit.util.Cookie}'s + * @throws MalformedCookieException in case the cookie does not conform to the spec + */ public static List parseCookie(final String cookieString, final URL pageUrl, final BrowserVersion browserVersion) throws MalformedCookieException { @@ -298,6 +160,13 @@ public static List fromHttpClient(final List c return list; } + /** + * Adds all matching cookies to the provided set. + * @param cookies the cookies to select from + * @param normalizedUrl the url to match against + * @param browserVersion the {@link BrowserVersion} + * @param matches the set to add + */ public static void addMatching(final Set cookies, final URL normalizedUrl, final BrowserVersion browserVersion, final Set matches) { diff --git a/src/main/java/org/htmlunit/httpclient/HttpDelete.java b/src/main/java/org/htmlunit/httpclient/HttpDelete.java index 9697896df26..3f9d2a671d5 100644 --- a/src/main/java/org/htmlunit/httpclient/HttpDelete.java +++ b/src/main/java/org/htmlunit/httpclient/HttpDelete.java @@ -25,10 +25,17 @@ */ public class HttpDelete extends HttpEntityEnclosingRequestBase { + /** + * Ctor. + */ public HttpDelete() { super(); } + /** + * Ctor. + * @param uri the uri + */ public HttpDelete(final URI uri) { super(); setURI(uri); diff --git a/src/main/java/org/htmlunit/httpclient/HttpOptions.java b/src/main/java/org/htmlunit/httpclient/HttpOptions.java index 92a9a329d19..0b643b8ac96 100644 --- a/src/main/java/org/htmlunit/httpclient/HttpOptions.java +++ b/src/main/java/org/htmlunit/httpclient/HttpOptions.java @@ -25,10 +25,17 @@ */ public class HttpOptions extends HttpEntityEnclosingRequestBase { + /** + * Ctor. + */ public HttpOptions() { super(); } + /** + * Ctor. + * @param uri the uri + */ public HttpOptions(final URI uri) { super(); setURI(uri); diff --git a/src/main/java/org/htmlunit/javascript/HiddenFunctionObject.java b/src/main/java/org/htmlunit/javascript/HiddenFunctionObject.java deleted file mode 100644 index a26539221c7..00000000000 --- a/src/main/java/org/htmlunit/javascript/HiddenFunctionObject.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2002-2025 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 - * https://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 org.htmlunit.javascript; - -import java.lang.reflect.Member; - -import org.htmlunit.corejs.javascript.FunctionObject; -import org.htmlunit.corejs.javascript.Scriptable; - -/** - * Extended FunctionObject that overrides avoidObjectDetection(). - * - * @author Ronald Brill - */ -class HiddenFunctionObject extends FunctionObject { - - /** - * Constructor. - */ - HiddenFunctionObject(final String name, final Member methodOrConstructor, final Scriptable scope) { - super(name, methodOrConstructor, scope); - } - - @Override - public boolean avoidObjectDetection() { - return true; - } -} diff --git a/src/main/java/org/htmlunit/javascript/HtmlUnitContextFactory.java b/src/main/java/org/htmlunit/javascript/HtmlUnitContextFactory.java index f2aea14b5ec..1926f59b5e2 100644 --- a/src/main/java/org/htmlunit/javascript/HtmlUnitContextFactory.java +++ b/src/main/java/org/htmlunit/javascript/HtmlUnitContextFactory.java @@ -34,12 +34,10 @@ import org.htmlunit.corejs.javascript.EvaluatorException; import org.htmlunit.corejs.javascript.Function; import org.htmlunit.corejs.javascript.Script; -import org.htmlunit.corejs.javascript.ScriptRuntime; import org.htmlunit.corejs.javascript.Scriptable; import org.htmlunit.corejs.javascript.debug.Debugger; import org.htmlunit.html.HtmlElement; import org.htmlunit.html.HtmlPage; -import org.htmlunit.javascript.regexp.HtmlUnitRegExpProxy; /** * ContextFactory that supports termination of scripts if they exceed a timeout. Based on example from @@ -268,9 +266,6 @@ protected Context makeContext() { cx.setDebugger(debugger_, null); } - // register custom RegExp processing - ScriptRuntime.setRegExpProxy(cx, new HtmlUnitRegExpProxy(ScriptRuntime.getRegExpProxy(cx))); - cx.setMaximumInterpreterStackDepth(5_000); return cx; diff --git a/src/main/java/org/htmlunit/javascript/JavaScriptEngine.java b/src/main/java/org/htmlunit/javascript/JavaScriptEngine.java index 97466abf29b..9b93756300f 100644 --- a/src/main/java/org/htmlunit/javascript/JavaScriptEngine.java +++ b/src/main/java/org/htmlunit/javascript/JavaScriptEngine.java @@ -194,7 +194,7 @@ public void initialize(final WebWindow webWindow, final Page page) { /** * Returns the JavaScriptExecutor. * @return the JavaScriptExecutor or null if javascript is disabled - * or no executor was required so far. + * or no executor was required so far. */ public JavaScriptExecutor getJavaScriptExecutor() { return javaScriptExecutor_; @@ -718,18 +718,7 @@ public Script compile(final HtmlPage owningPage, final Scriptable scope, final S LOG.trace("Javascript compile " + sourceName + newline + sourceCode + newline); } - final HtmlUnitContextAction action = new HtmlUnitContextAction(owningPage) { - @Override - public Object doRun(final Context cx) { - return cx.compileString(sourceCode, sourceName, startLine, null); - } - - @Override - protected String getSourceCode(final Context cx) { - return sourceCode; - } - }; - + final HtmlUnitCompileContextAction action = new HtmlUnitCompileContextAction(owningPage, sourceCode, sourceName, startLine); return (Script) getContextFactory().callSecured(action, owningPage); } @@ -862,6 +851,49 @@ public boolean isScriptRunning() { return Boolean.TRUE.equals(javaScriptRunning_.get()); } + /** + * Special ContextAction only for compiling. This reduces some code and avoid + * some calls. + */ + private final class HtmlUnitCompileContextAction implements ContextAction { + private final HtmlPage page_; + private final String sourceCode_; + private final String sourceName_; + private final int startLine_; + + HtmlUnitCompileContextAction(final HtmlPage page, final String sourceCode, final String sourceName, final int startLine) { + page_ = page; + sourceCode_ = sourceCode; + sourceName_ = sourceName; + startLine_ = startLine; + } + + @Override + public Object run(final Context cx) { + try { + final Object response; + cx.putThreadLocal(KEY_STARTING_PAGE, page_); + synchronized (page_) { // 2 scripts can't be executed in parallel for one page + if (page_ != page_.getEnclosingWindow().getEnclosedPage()) { + return null; // page has been unloaded + } + response = cx.compileString(sourceCode_, sourceName_, startLine_, null); + + } + + return response; + } + catch (final Exception e) { + handleJavaScriptException(new ScriptException(page_, e, sourceCode_), true); + return null; + } + catch (final TimeoutError e) { + handleJavaScriptTimeoutError(page_, e); + return null; + } + } + } + /** * Facility for ContextAction usage. * ContextAction should be preferred because according to Rhino doc it @@ -881,7 +913,6 @@ public final Object run(final Context cx) { try { final Object response; - cx.putThreadLocal(KEY_STARTING_PAGE, page_); synchronized (page_) { // 2 scripts can't be executed in parallel for one page if (page_ != page_.getEnclosingWindow().getEnclosedPage()) { return null; // page has been unloaded @@ -896,6 +927,7 @@ public final Object run(final Context cx) { if (!holdPostponedActions_) { doProcessPostponedActions(); } + return response; } catch (final Exception e) { @@ -937,8 +969,8 @@ private void doProcessPostponedActions() { } final List actions = postponedActions_.get(); - if (actions != null) { - postponedActions_.set(null); + if (actions != null && actions.size() > 0) { + postponedActions_.set(new ArrayList<>()); try { for (final PostponedAction action : actions) { if (LOG.isDebugEnabled()) { @@ -951,6 +983,9 @@ private void doProcessPostponedActions() { } } } + catch (final RuntimeException e) { + throw e; + } catch (final Exception e) { throw JavaScriptEngine.throwAsScriptRuntimeEx(e); } diff --git a/src/main/java/org/htmlunit/javascript/PostponedAction.java b/src/main/java/org/htmlunit/javascript/PostponedAction.java index f2c94e67fe0..6937c7c534c 100644 --- a/src/main/java/org/htmlunit/javascript/PostponedAction.java +++ b/src/main/java/org/htmlunit/javascript/PostponedAction.java @@ -61,7 +61,9 @@ protected Page getOwningPage() { */ public boolean isStillAlive() { final Page owningPage = getOwningPage(); - return owningPage != null && owningPage == owningPage.getEnclosingWindow().getEnclosedPage(); + return owningPage != null + && owningPage.getEnclosingWindow() != null + && owningPage == owningPage.getEnclosingWindow().getEnclosedPage(); } @Override diff --git a/src/main/java/org/htmlunit/javascript/background/BasicJavaScriptJob.java b/src/main/java/org/htmlunit/javascript/background/BasicJavaScriptJob.java index 50282b8d855..0bf6b997125 100644 --- a/src/main/java/org/htmlunit/javascript/background/BasicJavaScriptJob.java +++ b/src/main/java/org/htmlunit/javascript/background/BasicJavaScriptJob.java @@ -55,7 +55,7 @@ public BasicJavaScriptJob() { BasicJavaScriptJob(final int initialDelay, final Integer period) { initialDelay_ = initialDelay; period_ = period; - setTargetExecutionTime(initialDelay + System.currentTimeMillis()); + targetExecutionTime_ = initialDelay + System.currentTimeMillis(); executeAsap_ = initialDelay == 0; // XHR are currently run as jobs and should have priority } diff --git a/src/main/java/org/htmlunit/javascript/background/DefaultJavaScriptExecutor.java b/src/main/java/org/htmlunit/javascript/background/DefaultJavaScriptExecutor.java index aeb731f6779..ce096f28b3c 100644 --- a/src/main/java/org/htmlunit/javascript/background/DefaultJavaScriptExecutor.java +++ b/src/main/java/org/htmlunit/javascript/background/DefaultJavaScriptExecutor.java @@ -43,7 +43,8 @@ public class DefaultJavaScriptExecutor implements JavaScriptExecutor { /** Logging support. */ private static final Log LOG = LogFactory.getLog(DefaultJavaScriptExecutor.class); - /** Creates an EventLoop for the webClient. + /** + * Creates an EventLoop for the webClient. * * @param webClient the provided webClient */ diff --git a/src/main/java/org/htmlunit/javascript/configuration/ClassConfiguration.java b/src/main/java/org/htmlunit/javascript/configuration/ClassConfiguration.java index 408daa66fdd..e768a133b20 100644 --- a/src/main/java/org/htmlunit/javascript/configuration/ClassConfiguration.java +++ b/src/main/java/org/htmlunit/javascript/configuration/ClassConfiguration.java @@ -278,7 +278,7 @@ public Map.Entry getJsConstructor() { /** * @return the JavaScript constructor method alias - * or null if there is nothing. + * or null if there is nothing. */ public String getJsConstructorAlias() { return jsConstructorAlias_; diff --git a/src/main/java/org/htmlunit/javascript/host/Element.java b/src/main/java/org/htmlunit/javascript/host/Element.java index 89d33858320..9eaff5df7dc 100644 --- a/src/main/java/org/htmlunit/javascript/host/Element.java +++ b/src/main/java/org/htmlunit/javascript/host/Element.java @@ -36,6 +36,7 @@ import org.htmlunit.corejs.javascript.Function; import org.htmlunit.corejs.javascript.NativeObject; import org.htmlunit.corejs.javascript.Scriptable; +import org.htmlunit.corejs.javascript.ScriptableObject; import org.htmlunit.css.ComputedCssStyleDeclaration; import org.htmlunit.css.ElementCssStyleDeclaration; import org.htmlunit.cssparser.parser.CSSException; @@ -139,8 +140,11 @@ public void setDomNode(final DomNode domNode) { */ protected void createEventHandler(final String eventName, final String attrValue) { final DomElement htmlElt = getDomNodeOrDie(); + // TODO: check that it is an "allowed" event for the browser, and take care to the case final BaseFunction eventHandler = new EventHandler(htmlElt, eventName, attrValue); + eventHandler.setPrototype(ScriptableObject.getClassPrototype(htmlElt.getScriptableObject(), "Function")); + setEventHandler(eventName, eventHandler); } @@ -1451,7 +1455,7 @@ public void remove() { /** * Mock for the moment. * @param retargetToElement if true, all events are targeted directly to this element; - * if false, events can also fire at descendants of this element + * if false, events can also fire at descendants of this element */ @JsxFunction({FF, FF_ESR}) public void setCapture(final boolean retargetToElement) { @@ -1570,6 +1574,16 @@ public static boolean webkitMatchesSelector(final Context context, final Scripta return matches(context, scope, thisObj, args, function); } + /** + * Traverses the element and its parents (heading toward the document root) until it finds a node + * that matches the specified CSS selector. + * @param context the context + * @param scope the scope + * @param thisObj this object + * @param args the arguments + * @param function the function + * @return the found element or null + */ @JsxFunction public static Element closest(final Context context, final Scriptable scope, final Scriptable thisObj, final Object[] args, final Function function) { @@ -1604,8 +1618,8 @@ public static Element closest(final Context context, final Scriptable scope, * removes attribute with name. * * @param name the name of the attribute to be toggled. - * The attribute name is automatically converted to all lower-case when toggleAttribute() - * is called on an HTML element in an HTML document. + * The attribute name is automatically converted to all lower-case when toggleAttribute() + * is called on an HTML element in an HTML document. * @param force if true, the toggleAttribute method adds an attribute named name * @return true if attribute name is eventually present, and false otherwise * @see = 0 && index < getLength(); } + /** + * @return the Iterator symbol + */ @JsxSymbol public Scriptable iterator() { return JavaScriptEngine.newArrayIteratorTypeValues(getParentScope(), this); diff --git a/src/main/java/org/htmlunit/javascript/host/Navigator.java b/src/main/java/org/htmlunit/javascript/host/Navigator.java index 826dab6fdea..214a1ba26f4 100644 --- a/src/main/java/org/htmlunit/javascript/host/Navigator.java +++ b/src/main/java/org/htmlunit/javascript/host/Navigator.java @@ -299,7 +299,7 @@ public Geolocation getGeolocation() { /** * @return true whether the browser supports inline display - * of PDF files when navigating to them + * of PDF files when navigating to them */ @JsxGetter public boolean getPdfViewerEnabled() { diff --git a/src/main/java/org/htmlunit/javascript/host/Plugin.java b/src/main/java/org/htmlunit/javascript/host/Plugin.java index 63f35f364ba..762d77348e2 100644 --- a/src/main/java/org/htmlunit/javascript/host/Plugin.java +++ b/src/main/java/org/htmlunit/javascript/host/Plugin.java @@ -170,6 +170,9 @@ public String getName() { return name_; } + /** + * @return the Iterator symbol + */ @JsxSymbol public Scriptable iterator() { return JavaScriptEngine.newArrayIteratorTypeValues(getParentScope(), this); diff --git a/src/main/java/org/htmlunit/javascript/host/PluginArray.java b/src/main/java/org/htmlunit/javascript/host/PluginArray.java index 95546cabac6..2218be89dab 100644 --- a/src/main/java/org/htmlunit/javascript/host/PluginArray.java +++ b/src/main/java/org/htmlunit/javascript/host/PluginArray.java @@ -151,6 +151,9 @@ void add(final Plugin element) { elements_.add(element); } + /** + * @return the Iterator symbol + */ @JsxSymbol public Scriptable iterator() { return JavaScriptEngine.newArrayIteratorTypeValues(getParentScope(), this); diff --git a/src/main/java/org/htmlunit/javascript/host/URL.java b/src/main/java/org/htmlunit/javascript/host/URL.java index d07929d8616..0de3ba46250 100644 --- a/src/main/java/org/htmlunit/javascript/host/URL.java +++ b/src/main/java/org/htmlunit/javascript/host/URL.java @@ -52,10 +52,10 @@ public class URL extends HtmlUnitScriptable { /** * Creates an instance. * @param url a string representing an absolute or relative URL. - * If url is a relative URL, base is required, and will be used - * as the base URL. If url is an absolute URL, a given base will be ignored. + * If url is a relative URL, base is required, and will be used + * as the base URL. If url is an absolute URL, a given base will be ignored. * @param base a string representing the base URL to use in case url - * is a relative URL. If not specified, it defaults to ''. + * is a relative URL. If not specified, it defaults to ''. */ @JsxConstructor @JsxConstructorAlias(alias = "webkitURL") @@ -125,6 +125,10 @@ public String getHash() { return ref == null ? "" : "#" + ref; } + /** + * Sets the {@code hash} property. + * @param fragment the {@code hash} property + */ @JsxSetter public void setHash(final String fragment) throws MalformedURLException { if (url_ == null) { @@ -135,7 +139,7 @@ public void setHash(final String fragment) throws MalformedURLException { /** * @return the host, that is the hostname, and then, if the port of the URL is nonempty, - * a ':', followed by the port of the URL. + * a ':', followed by the port of the URL. */ @JsxGetter public String getHost() { @@ -146,6 +150,10 @@ public String getHost() { return url_.getHost() + (port > 0 ? ":" + port : ""); } + /** + * Sets the {@code host} property. + * @param host the {@code host} property + */ @JsxSetter public void setHost(final String host) throws MalformedURLException { if (url_ == null) { @@ -199,7 +207,7 @@ public void setHost(final String host) throws MalformedURLException { /** * @return the host, that is the hostname, and then, if the port of the URL is nonempty, - * a ':', followed by the port of the URL. + * a ':', followed by the port of the URL. */ @JsxGetter public String getHostname() { @@ -210,6 +218,10 @@ public String getHostname() { return UrlUtils.encodeAnchor(url_.getHost()); } + /** + * Sets the {@code hostname} property. + * @param hostname the {@code hostname} property + */ @JsxSetter public void setHostname(final String hostname) throws MalformedURLException { if (getBrowserVersion().hasFeature(JS_ANCHOR_HOSTNAME_IGNORE_BLANK)) { @@ -234,6 +246,10 @@ public String getHref() { return jsToString(); } + /** + * Sets the {@code href} property. + * @param href the {@code href} property + */ @JsxSetter public void setHref(final String href) throws MalformedURLException { if (url_ == null) { @@ -289,6 +305,10 @@ public String getPassword() { return idx == -1 ? "" : userInfo.substring(idx + 1); } + /** + * Sets the {@code password} property. + * @param password the {@code password} property + */ @JsxSetter public void setPassword(final String password) throws MalformedURLException { if (url_ == null) { @@ -311,6 +331,10 @@ public String getPathname() { return path.isEmpty() ? "/" : path; } + /** + * Sets the {@code path} property. + * @param path the {@code path} property + */ @JsxSetter public void setPathname(final String path) throws MalformedURLException { if (url_ == null) { @@ -322,7 +346,7 @@ public void setPathname(final String path) throws MalformedURLException { /** * @return the port number of the URL. If the URL does not contain an explicit port number, - * it will be set to '' + * it will be set to '' */ @JsxGetter public String getPort() { @@ -334,6 +358,10 @@ public String getPort() { return port == -1 ? "" : Integer.toString(port); } + /** + * Sets the {@code port} property. + * @param port the {@code port} property + */ @JsxSetter public void setPort(final String port) throws MalformedURLException { if (url_ == null) { @@ -356,6 +384,10 @@ public String getProtocol() { return protocol.isEmpty() ? "" : (protocol + ":"); } + /** + * Sets the {@code protocol} property. + * @param protocol the {@code protocol} property + */ @JsxSetter public void setProtocol(final String protocol) throws MalformedURLException { if (url_ == null || protocol.isEmpty()) { @@ -391,6 +423,10 @@ public String getSearch() { return search == null ? "" : "?" + search; } + /** + * Sets the {@code search} property. + * @param search the {@code search} property + */ @JsxSetter public void setSearch(final String search) throws MalformedURLException { if (url_ == null) { @@ -416,6 +452,11 @@ public void setSearch(final String search) throws MalformedURLException { url_ = UrlUtils.getUrlWithNewQuery(url_, query); } + /** + * Sets the {@code search} property based on {@link NameValuePair}'s. + * @param nameValuePairs the pairs + * @throws MalformedURLException in case of error + */ public void setSearch(final List nameValuePairs) throws MalformedURLException { final StringBuilder newSearch = new StringBuilder(); for (final NameValuePair nameValuePair : nameValuePairs) { @@ -448,6 +489,10 @@ public String getUsername() { return StringUtils.substringBefore(userInfo, ':'); } + /** + * Sets the {@code username} property. + * @param username the {@code username} property + */ @JsxSetter public void setUsername(final String username) throws MalformedURLException { if (url_ == null) { @@ -476,7 +521,7 @@ public Object getDefaultValue(final Class hint) { /** * @return a serialized version of the URL, - * although in practice it seems to have the same effect as URL.toString(). + * although in practice it seems to have the same effect as URL.toString(). */ @JsxFunction public String toJSON() { diff --git a/src/main/java/org/htmlunit/javascript/host/URLSearchParams.java b/src/main/java/org/htmlunit/javascript/host/URLSearchParams.java index dd5efacd697..7e8f851c54d 100644 --- a/src/main/java/org/htmlunit/javascript/host/URLSearchParams.java +++ b/src/main/java/org/htmlunit/javascript/host/URLSearchParams.java @@ -66,6 +66,9 @@ public class URLSearchParams extends HtmlUnitScriptable { private URL url_; + /** + * {@link ES6Iterator} implementation for js support. + */ public static final class NativeParamsIterator extends ES6Iterator { enum Type { KEYS, VALUES, BOTH } @@ -73,10 +76,19 @@ enum Type { KEYS, VALUES, BOTH } private final String className_; private final transient Iterator iterator_; + /** + * Init. + * @param scope the scope + * @param className the class name + */ public static void init(final ScriptableObject scope, final String className) { ES6Iterator.init(scope, false, new NativeParamsIterator(className), URL_SEARCH_PARMS_TAG); } + /** + * Ctor. + * @param className the class name + */ public NativeParamsIterator(final String className) { super(); iterator_ = Collections.emptyIterator(); @@ -84,6 +96,13 @@ public NativeParamsIterator(final String className) { className_ = className; } + /** + * Ctor. + * @param scope the scope + * @param className the class name + * @param type the type + * @param iterator the backing iterator + */ public NativeParamsIterator(final Scriptable scope, final String className, final Type type, final Iterator iterator) { super(scope, URL_SEARCH_PARMS_TAG); diff --git a/src/main/java/org/htmlunit/javascript/host/WebSocket.java b/src/main/java/org/htmlunit/javascript/host/WebSocket.java index 3d3847fd89c..0dd6c67ac52 100644 --- a/src/main/java/org/htmlunit/javascript/host/WebSocket.java +++ b/src/main/java/org/htmlunit/javascript/host/WebSocket.java @@ -123,8 +123,9 @@ public void onWebSocketConnecting() { public void onWebSocketConnect() { setReadyState(OPEN); - final Event openEvent = new Event(); - openEvent.setType(Event.TYPE_OPEN); + final Event openEvent = new Event(Event.TYPE_OPEN); + openEvent.setParentScope(window); + openEvent.setPrototype(getPrototype(openEvent.getClass())); openEvent.setSrcElement(WebSocket.this); fire(openEvent); callFunction(openHandler_, new Object[] {openEvent}); @@ -135,6 +136,8 @@ public void onWebSocketClose(final int statusCode, final String reason) { setReadyState(CLOSED); final CloseEvent closeEvent = new CloseEvent(); + closeEvent.setParentScope(window); + closeEvent.setPrototype(getPrototype(closeEvent.getClass())); closeEvent.setCode(statusCode); closeEvent.setReason(reason); closeEvent.setWasClean(true); @@ -145,6 +148,8 @@ public void onWebSocketClose(final int statusCode, final String reason) { @Override public void onWebSocketText(final String message) { final MessageEvent msgEvent = new MessageEvent(message); + msgEvent.setParentScope(window); + msgEvent.setPrototype(getPrototype(msgEvent.getClass())); if (originSet_) { msgEvent.setOrigin(getUrl()); } @@ -161,6 +166,8 @@ public void onWebSocketBinary(final byte[] data, final int offset, final int len buffer.setPrototype(ScriptableObject.getClassPrototype(getWindow(), buffer.getClassName())); final MessageEvent msgEvent = new MessageEvent(buffer); + msgEvent.setParentScope(window); + msgEvent.setPrototype(getPrototype(msgEvent.getClass())); if (originSet_) { msgEvent.setOrigin(getUrl()); } @@ -180,13 +187,16 @@ public void onWebSocketConnectError(final Throwable cause) { public void onWebSocketError(final Throwable cause) { setReadyState(CLOSED); - final Event errorEvent = new Event(); - errorEvent.setType(Event.TYPE_ERROR); + final Event errorEvent = new Event(Event.TYPE_ERROR); + errorEvent.setParentScope(window); + errorEvent.setPrototype(getPrototype(errorEvent.getClass())); errorEvent.setSrcElement(WebSocket.this); fire(errorEvent); callFunction(errorHandler_, new Object[] {errorEvent}); final CloseEvent closeEvent = new CloseEvent(); + closeEvent.setParentScope(window); + closeEvent.setPrototype(getPrototype(closeEvent.getClass())); closeEvent.setCode(1006); closeEvent.setReason(cause.getMessage()); closeEvent.setWasClean(false); diff --git a/src/main/java/org/htmlunit/javascript/host/Window.java b/src/main/java/org/htmlunit/javascript/host/Window.java index 7c8b94e886c..6d1470b012b 100644 --- a/src/main/java/org/htmlunit/javascript/host/Window.java +++ b/src/main/java/org/htmlunit/javascript/host/Window.java @@ -1329,9 +1329,9 @@ public String getName() { } /** - * Sets the value of the window's {@code name} property. - * @param name the value of the window's {@code name} property - */ + * Sets the value of the window's {@code name} property. + * @param name the value of the window's {@code name} property + */ @JsxSetter public void setName(final String name) { getWebWindow().setName(name); @@ -1716,7 +1716,7 @@ public void releaseEvents(final String type) { * * @param element the element * @param pseudoElement a string specifying the pseudo-element to match (may be {@code null}); - * e.g. ':before' + * e.g. ':before' * @return the computed style */ @JsxFunction diff --git a/src/main/java/org/htmlunit/javascript/host/WindowOrWorkerGlobalScopeMixin.java b/src/main/java/org/htmlunit/javascript/host/WindowOrWorkerGlobalScopeMixin.java index bb5054327ac..b9722a1c092 100644 --- a/src/main/java/org/htmlunit/javascript/host/WindowOrWorkerGlobalScopeMixin.java +++ b/src/main/java/org/htmlunit/javascript/host/WindowOrWorkerGlobalScopeMixin.java @@ -18,6 +18,7 @@ import java.util.Arrays; import java.util.Base64; +import org.apache.commons.lang3.StringUtils; import org.htmlunit.Page; import org.htmlunit.WebWindow; import org.htmlunit.corejs.javascript.Context; @@ -57,17 +58,17 @@ private WindowOrWorkerGlobalScopeMixin() { * @return the decoded value */ public static String atob(final String encodedData, final HtmlUnitScriptable scriptable) { - final int l = encodedData.length(); - for (int i = 0; i < l; i++) { - if (encodedData.charAt(i) > 255) { - throw JavaScriptEngine.asJavaScriptException( - scriptable, - "Function atob supports only latin1 characters", - org.htmlunit.javascript.host.dom.DOMException.INVALID_CHARACTER_ERR); - } + final String withoutWhitespace = StringUtils.replaceChars(encodedData, " \t\r\n\u000c", ""); + final byte[] bytes = withoutWhitespace.getBytes(StandardCharsets.ISO_8859_1); + try { + return new String(Base64.getDecoder().decode(bytes), StandardCharsets.ISO_8859_1); + } + catch (final IllegalArgumentException e) { + throw JavaScriptEngine.asJavaScriptException( + scriptable, + "Failed to execute atob(): " + e.getMessage(), + org.htmlunit.javascript.host.dom.DOMException.INVALID_CHARACTER_ERR); } - final byte[] bytes = encodedData.getBytes(StandardCharsets.ISO_8859_1); - return new String(Base64.getDecoder().decode(bytes), StandardCharsets.ISO_8859_1); } /** @@ -86,8 +87,17 @@ public static String btoa(final String stringToEncode, final HtmlUnitScriptable org.htmlunit.javascript.host.dom.DOMException.INVALID_CHARACTER_ERR); } } + final byte[] bytes = stringToEncode.getBytes(StandardCharsets.ISO_8859_1); - return new String(Base64.getEncoder().encode(bytes), StandardCharsets.UTF_8); + try { + return new String(Base64.getEncoder().encode(bytes), StandardCharsets.UTF_8); + } + catch (final IllegalArgumentException e) { + throw JavaScriptEngine.asJavaScriptException( + scriptable, + "Failed to execute btoa(): " + e.getMessage(), + org.htmlunit.javascript.host.dom.DOMException.INVALID_CHARACTER_ERR); + } } /** diff --git a/src/main/java/org/htmlunit/javascript/host/canvas/CanvasGradient.java b/src/main/java/org/htmlunit/javascript/host/canvas/CanvasGradient.java index e674972f62f..418a51d16a9 100644 --- a/src/main/java/org/htmlunit/javascript/host/canvas/CanvasGradient.java +++ b/src/main/java/org/htmlunit/javascript/host/canvas/CanvasGradient.java @@ -39,9 +39,9 @@ public void jsConstructor() { /** * Adds a new stop, defined by an offset and a color, to the gradient. * @param offset A number between 0 and 1. An INDEX_SIZE_ERR is raised, - * if the number is not in that range. + * if the number is not in that range. * @param color A CSS color. A SYNTAX_ERR is raised, if the value - * can not be parsed as a CSS color value. + * can not be parsed as a CSS color value. */ @JsxFunction public void addColorStop(final double offset, final String color) { diff --git a/src/main/java/org/htmlunit/javascript/host/canvas/CanvasRenderingContext2D.java b/src/main/java/org/htmlunit/javascript/host/canvas/CanvasRenderingContext2D.java index d6b0b05d009..f8a0f9d8e02 100644 --- a/src/main/java/org/htmlunit/javascript/host/canvas/CanvasRenderingContext2D.java +++ b/src/main/java/org/htmlunit/javascript/host/canvas/CanvasRenderingContext2D.java @@ -593,13 +593,13 @@ public void moveTo(final double x, final double y) { * @param dx horizontal position (x coordinate) at which to place the image data in the destination canvas * @param dy vertical position (y coordinate) at which to place the image data in the destination canvas * @param dirtyX horizontal position (x coordinate) of the top-left corner - * from which the image data will be extracted. Defaults to 0. + * from which the image data will be extracted. Defaults to 0. * @param dirtyY vertical position (y coordinate) of the top-left corner - * from which the image data will be extracted. Defaults to 0. + * from which the image data will be extracted. Defaults to 0. * @param dirtyWidth width of the rectangle to be painted. - * Defaults to the width of the image data. + * Defaults to the width of the image data. * @param dirtyHeight height of the rectangle to be painted. - * Defaults to the height of the image data. + * Defaults to the height of the image data. */ @JsxFunction public void putImageData(final ImageData imageData, diff --git a/src/main/java/org/htmlunit/javascript/host/crypto/Crypto.java b/src/main/java/org/htmlunit/javascript/host/crypto/Crypto.java index 05d8e2209ee..9db8732c22c 100644 --- a/src/main/java/org/htmlunit/javascript/host/crypto/Crypto.java +++ b/src/main/java/org/htmlunit/javascript/host/crypto/Crypto.java @@ -104,6 +104,9 @@ public SubtleCrypto getSubtle() { return stuble; } + /** + * @return a v4 UUID generated using a cryptographically secure random number generator + */ @JsxFunction public String randomUUID() { // Let bytes be a byte sequence of length 16. diff --git a/src/main/java/org/htmlunit/javascript/host/css/CSSStyleDeclaration.java b/src/main/java/org/htmlunit/javascript/host/css/CSSStyleDeclaration.java index 29fe9977205..7ec85aa4df0 100644 --- a/src/main/java/org/htmlunit/javascript/host/css/CSSStyleDeclaration.java +++ b/src/main/java/org/htmlunit/javascript/host/css/CSSStyleDeclaration.java @@ -112,6 +112,9 @@ public class CSSStyleDeclaration extends HtmlUnitScriptable { private static final String[] ALIGN_KEYWORDS = {"baseline", "sub", "super", "text-top", "text-bottom", "middle", "top", "bottom", "inherit", "initial", "revert", "unset"}; + private static final String[] FONT_SIZES = + {"xx-small", "x-small", "small", "medium", "large", "x-large", "xx-large", "xxx-large", + "smaller", "larger"}; // private static final Log LOG = LogFactory.getLog(CSSStyleDeclaration.class); @@ -741,7 +744,7 @@ public String getFontSize() { */ @JsxSetter public void setFontSize(final Object fontSize) { - setStyleLengthAttribute(Definition.FONT_SIZE.getAttributeName(), fontSize, "", false, true, false, null); + setStyleLengthAttribute(Definition.FONT_SIZE.getAttributeName(), fontSize, "", false, true, false, FONT_SIZES); updateFont(getFont(), false); } diff --git a/src/main/java/org/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java b/src/main/java/org/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java index fc0c4f0c42e..480b718cb60 100644 --- a/src/main/java/org/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java +++ b/src/main/java/org/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java @@ -19,6 +19,8 @@ import org.htmlunit.corejs.javascript.Scriptable; import org.htmlunit.css.ComputedCssStyleDeclaration; +import org.htmlunit.css.CssPixelValueConverter; +import org.htmlunit.css.StyleAttributes.Definition; import org.htmlunit.javascript.JavaScriptEngine; import org.htmlunit.javascript.configuration.JsxClass; import org.htmlunit.javascript.configuration.JsxConstructor; @@ -285,7 +287,11 @@ public String getFontFamily() { */ @Override public String getFontSize() { - return getCssStyleDeclaration().getFontSize(); + String value = getStyleAttribute(Definition.FONT_SIZE, true); + if (!value.isEmpty()) { + value = CssPixelValueConverter.pixelValue(value) + "px"; + } + return value; } /** diff --git a/src/main/java/org/htmlunit/javascript/host/css/StyleSheet.java b/src/main/java/org/htmlunit/javascript/host/css/StyleSheet.java index 2103916bdc5..ac57a5af644 100644 --- a/src/main/java/org/htmlunit/javascript/host/css/StyleSheet.java +++ b/src/main/java/org/htmlunit/javascript/host/css/StyleSheet.java @@ -59,6 +59,10 @@ public void jsConstructor() { // nothing to do } + /** + * Ctor. + * @param ownerNode the owner node + */ public StyleSheet(final HTMLElement ownerNode) { super(); ownerNode_ = ownerNode; diff --git a/src/main/java/org/htmlunit/javascript/host/dom/AbstractList.java b/src/main/java/org/htmlunit/javascript/host/dom/AbstractList.java index 70cc5f17eb2..b365b9d412b 100644 --- a/src/main/java/org/htmlunit/javascript/host/dom/AbstractList.java +++ b/src/main/java/org/htmlunit/javascript/host/dom/AbstractList.java @@ -103,7 +103,7 @@ public AbstractList() { * * @param domNode the {@link DomNode} * @param attributeChangeSensitive indicates if the content of the collection may change when an attribute - * of a descendant node of parentScope changes (attribute added, modified or removed) + * of a descendant node of parentScope changes (attribute added, modified or removed) * @param initialElements the initial content for the cache */ protected AbstractList(final DomNode domNode, final boolean attributeChangeSensitive, @@ -114,8 +114,8 @@ protected AbstractList(final DomNode domNode, final boolean attributeChangeSensi final HtmlUnitScriptable parentScope = domNode.getScriptableObject(); if (parentScope != null) { setParentScope(parentScope); - setPrototype(getPrototype(getClass())); } + setPrototype(getPrototype(getClass())); } attributeChangeSensitive_ = attributeChangeSensitive; cachedElements_ = initialElements; diff --git a/src/main/java/org/htmlunit/javascript/host/dom/CharacterData.java b/src/main/java/org/htmlunit/javascript/host/dom/CharacterData.java index 1ed1fe96026..7409f487f40 100644 --- a/src/main/java/org/htmlunit/javascript/host/dom/CharacterData.java +++ b/src/main/java/org/htmlunit/javascript/host/dom/CharacterData.java @@ -111,7 +111,7 @@ public void deleteData(final int offset, final int count) { /** * Insert a string into character data. * @param offset the position within the first character at which - * the string is to be inserted. + * the string is to be inserted. * @param arg the string to insert */ @JsxFunction @@ -122,10 +122,10 @@ public void insertData(final int offset, final String arg) { /** * Replace characters of character data with a string. * @param offset the position within the first character at which - * the string is to be replaced. + * the string is to be replaced. * @param count the number of characters to be replaced * @param arg the string that replaces the count characters beginning at - * the character at offset. + * the character at offset. */ @JsxFunction public void replaceData(final int offset, final int count, final String arg) { diff --git a/src/main/java/org/htmlunit/javascript/host/dom/DOMException.java b/src/main/java/org/htmlunit/javascript/host/dom/DOMException.java index e52829d1c8c..0ac07a95ee7 100644 --- a/src/main/java/org/htmlunit/javascript/host/dom/DOMException.java +++ b/src/main/java/org/htmlunit/javascript/host/dom/DOMException.java @@ -183,9 +183,9 @@ public DOMException() { * JavaScript constructor. * @param message a description of the exception. If not present, the empty string '' is used * @param error If the specified name is a standard error name, - * then getting the code property of the DOMException object will return the - * code number corresponding to the specified name. - * If not present, the string 'Error' is used. + * then getting the code property of the DOMException object will return the + * code number corresponding to the specified name. + * If not present, the string 'Error' is used. */ @JsxConstructor public void jsConstructor(final String message, final Object error) { diff --git a/src/main/java/org/htmlunit/javascript/host/dom/DOMImplementation.java b/src/main/java/org/htmlunit/javascript/host/dom/DOMImplementation.java index 272fd701703..9f9ca2b6f3d 100644 --- a/src/main/java/org/htmlunit/javascript/host/dom/DOMImplementation.java +++ b/src/main/java/org/htmlunit/javascript/host/dom/DOMImplementation.java @@ -241,10 +241,10 @@ public HTMLDocument createHTMLDocument(final Object titleObj) { final WebWindow webWindow = getWindow().getWebWindow(); final String html; if (JavaScriptEngine.isUndefined(titleObj)) { - html = ""; + html = ""; } else { - html = "" + html = "<!DOCTYPE html><html><head><title>" + JavaScriptEngine.toString(titleObj) + ""; } diff --git a/src/main/java/org/htmlunit/javascript/host/dom/Document.java b/src/main/java/org/htmlunit/javascript/host/dom/Document.java index c3eb6ece4c0..8177db60351 100644 --- a/src/main/java/org/htmlunit/javascript/host/dom/Document.java +++ b/src/main/java/org/htmlunit/javascript/host/dom/Document.java @@ -1202,7 +1202,7 @@ && getBrowserVersion().hasFeature(EVENT_ONANIMATION_DOCUMENT_CREATE_NOT_SUPPORTE * * @param root The root node at which to begin the NodeIterator's traversal. * @param whatToShow an optional long representing a bitmask created by combining - * the constant properties of {@link NodeFilter} + * the constant properties of {@link NodeFilter} * @param filter an object implementing the {@link NodeFilter} interface * @return a new NodeIterator object */ @@ -3571,8 +3571,7 @@ public boolean contains(final Object element) { /** * Generate and return the URL for the given blob. * @param blob the Blob containing the data - * @return the URL - * {@link org.htmlunit.javascript.host.URL#createObjectURL(Object)} + * @return the URL {@link org.htmlunit.javascript.host.URL#createObjectURL(Object)} */ public String generateBlobUrl(final Blob blob) { final URL url = getPage().getUrl(); @@ -3597,8 +3596,7 @@ public Blob resolveBlobUrl(final String url) { /** * Revokes the URL for the given blob. - * @param url the url to revoke - * {@link org.htmlunit.javascript.host.URL#revokeObjectURL(Scriptable)} + * @param url the url to revoke {@link org.htmlunit.javascript.host.URL#revokeObjectURL(Scriptable)} */ public void revokeBlobUrl(final String url) { blobUrl2Blobs_.remove(url); diff --git a/src/main/java/org/htmlunit/javascript/host/dom/Node.java b/src/main/java/org/htmlunit/javascript/host/dom/Node.java index db0167594b9..175f7119e03 100644 --- a/src/main/java/org/htmlunit/javascript/host/dom/Node.java +++ b/src/main/java/org/htmlunit/javascript/host/dom/Node.java @@ -64,75 +64,111 @@ @JsxClass public class Node extends EventTarget { - /** @see org.w3c.dom.Node#ELEMENT_NODE */ + /** + * @see org.w3c.dom.Node#ELEMENT_NODE + */ @JsxConstant public static final int ELEMENT_NODE = org.w3c.dom.Node.ELEMENT_NODE; - /** @see org.w3c.dom.Node#ATTRIBUTE_NODE */ + /** + * @see org.w3c.dom.Node#ATTRIBUTE_NODE + */ @JsxConstant public static final int ATTRIBUTE_NODE = org.w3c.dom.Node.ATTRIBUTE_NODE; - /** @see org.w3c.dom.Node#TEXT_NODE */ + /** + * @see org.w3c.dom.Node#TEXT_NODE + */ @JsxConstant public static final int TEXT_NODE = org.w3c.dom.Node.TEXT_NODE; - /** @see org.w3c.dom.Node#CDATA_SECTION_NODE */ + /** + * @see org.w3c.dom.Node#CDATA_SECTION_NODE + */ @JsxConstant public static final int CDATA_SECTION_NODE = org.w3c.dom.Node.CDATA_SECTION_NODE; - /** @see org.w3c.dom.Node#ENTITY_REFERENCE_NODE */ + /** + * @see org.w3c.dom.Node#ENTITY_REFERENCE_NODE + */ @JsxConstant public static final int ENTITY_REFERENCE_NODE = org.w3c.dom.Node.ENTITY_REFERENCE_NODE; - /** @see org.w3c.dom.Node#ENTITY_NODE */ + /** + * @see org.w3c.dom.Node#ENTITY_NODE + */ @JsxConstant public static final int ENTITY_NODE = org.w3c.dom.Node.ENTITY_NODE; - /** @see org.w3c.dom.Node#PROCESSING_INSTRUCTION_NODE */ + /** + * @see org.w3c.dom.Node#PROCESSING_INSTRUCTION_NODE + */ @JsxConstant public static final int PROCESSING_INSTRUCTION_NODE = org.w3c.dom.Node.PROCESSING_INSTRUCTION_NODE; - /** @see org.w3c.dom.Node#COMMENT_NODE */ + /** + * @see org.w3c.dom.Node#COMMENT_NODE + */ @JsxConstant public static final int COMMENT_NODE = org.w3c.dom.Node.COMMENT_NODE; - /** @see org.w3c.dom.Node#DOCUMENT_NODE */ + /** + * @see org.w3c.dom.Node#DOCUMENT_NODE + */ @JsxConstant public static final int DOCUMENT_NODE = org.w3c.dom.Node.DOCUMENT_NODE; - /** @see org.w3c.dom.Node#DOCUMENT_TYPE_NODE */ + /** + * @see org.w3c.dom.Node#DOCUMENT_TYPE_NODE + */ @JsxConstant public static final int DOCUMENT_TYPE_NODE = org.w3c.dom.Node.DOCUMENT_TYPE_NODE; - /** @see org.w3c.dom.Node#DOCUMENT_FRAGMENT_NODE */ + /** + * @see org.w3c.dom.Node#DOCUMENT_FRAGMENT_NODE + */ @JsxConstant public static final int DOCUMENT_FRAGMENT_NODE = org.w3c.dom.Node.DOCUMENT_FRAGMENT_NODE; - /** @see org.w3c.dom.Node#NOTATION_NODE */ + /** + * @see org.w3c.dom.Node#NOTATION_NODE + */ @JsxConstant public static final int NOTATION_NODE = org.w3c.dom.Node.NOTATION_NODE; - /** @see org.w3c.dom.Node#DOCUMENT_POSITION_DISCONNECTED */ + /** + * @see org.w3c.dom.Node#DOCUMENT_POSITION_DISCONNECTED + */ @JsxConstant public static final int DOCUMENT_POSITION_DISCONNECTED = org.w3c.dom.Node.DOCUMENT_POSITION_DISCONNECTED; - /** @see org.w3c.dom.Node#DOCUMENT_POSITION_PRECEDING */ + /** + * @see org.w3c.dom.Node#DOCUMENT_POSITION_PRECEDING + */ @JsxConstant public static final int DOCUMENT_POSITION_PRECEDING = org.w3c.dom.Node.DOCUMENT_POSITION_PRECEDING; - /** @see org.w3c.dom.Node#DOCUMENT_POSITION_FOLLOWING */ + /** + * @see org.w3c.dom.Node#DOCUMENT_POSITION_FOLLOWING + */ @JsxConstant public static final int DOCUMENT_POSITION_FOLLOWING = org.w3c.dom.Node.DOCUMENT_POSITION_FOLLOWING; - /** @see org.w3c.dom.Node#DOCUMENT_POSITION_CONTAINS */ + /** + * @see org.w3c.dom.Node#DOCUMENT_POSITION_CONTAINS + */ @JsxConstant public static final int DOCUMENT_POSITION_CONTAINS = org.w3c.dom.Node.DOCUMENT_POSITION_CONTAINS; - /** @see org.w3c.dom.Node#DOCUMENT_POSITION_CONTAINED_BY */ + /** + * @see org.w3c.dom.Node#DOCUMENT_POSITION_CONTAINED_BY + */ @JsxConstant public static final int DOCUMENT_POSITION_CONTAINED_BY = org.w3c.dom.Node.DOCUMENT_POSITION_CONTAINED_BY; - /** @see org.w3c.dom.Node#DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC */ + /** + * @see org.w3c.dom.Node#DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC + */ @JsxConstant public static final int DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = org.w3c.dom.Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC; @@ -595,8 +631,8 @@ public boolean hasChildNodes() { /** * @param namespace string containing the namespace to look the prefix up * @return a string containing the prefix for a given namespace URI, - * if present, and null if not. When multiple prefixes are possible, - * the first prefix is returned. + * if present, and null if not. When multiple prefixes are possible, + * the first prefix is returned. */ @JsxFunction public String lookupPrefix(final String namespace) { @@ -648,7 +684,7 @@ public Object getParentNode() { * Gets the JavaScript property {@code nextSibling} for the node that * contains the current node. * @return the next sibling node or null if the current node has - * no next sibling. + * no next sibling. */ @JsxGetter public Node getNextSibling() { @@ -659,7 +695,7 @@ public Node getNextSibling() { * Gets the JavaScript property {@code previousSibling} for the node that * contains the current node. * @return the previous sibling node or null if the current node has - * no previous sibling. + * no previous sibling. */ @JsxGetter public Node getPreviousSibling() { @@ -670,7 +706,7 @@ public Node getPreviousSibling() { * Gets the JavaScript property {@code firstChild} for the node that * contains the current node. * @return the first child node or null if the current node has - * no children. + * no children. */ @JsxGetter public Node getFirstChild() { @@ -681,7 +717,7 @@ public Node getFirstChild() { * Gets the JavaScript property {@code lastChild} for the node that * contains the current node. * @return the last child node or null if the current node has - * no children. + * no children. */ @JsxGetter public Node getLastChild() { diff --git a/src/main/java/org/htmlunit/javascript/host/dom/NodeFilter.java b/src/main/java/org/htmlunit/javascript/host/dom/NodeFilter.java index 9babfdfc0b9..ebb70f9fbcd 100644 --- a/src/main/java/org/htmlunit/javascript/host/dom/NodeFilter.java +++ b/src/main/java/org/htmlunit/javascript/host/dom/NodeFilter.java @@ -58,7 +58,8 @@ public class NodeFilter extends HtmlUnitScriptable { @JsxConstant public static final int SHOW_ELEMENT = org.w3c.dom.traversal.NodeFilter.SHOW_ELEMENT; - /** Show Attr nodes. Only useful when creating a TreeWalker with an + /** + * Show Attr nodes. Only useful when creating a TreeWalker with an * attribute node as its root. */ @JsxConstant public static final int SHOW_ATTRIBUTE = org.w3c.dom.traversal.NodeFilter.SHOW_ATTRIBUTE; diff --git a/src/main/java/org/htmlunit/javascript/host/dom/NodeIterator.java b/src/main/java/org/htmlunit/javascript/host/dom/NodeIterator.java index 2503defd01b..777cf90e24f 100644 --- a/src/main/java/org/htmlunit/javascript/host/dom/NodeIterator.java +++ b/src/main/java/org/htmlunit/javascript/host/dom/NodeIterator.java @@ -53,7 +53,7 @@ public void jsConstructor() { * * @param root The root node at which to begin the {@link NodeIterator}'s traversal * @param whatToShow an optional long representing a bitmask created by combining - * the constant properties of {@link NodeFilter} + * the constant properties of {@link NodeFilter} * @param filter an object implementing the {@link NodeFilter} interface */ public NodeIterator(final Node root, final int whatToShow, diff --git a/src/main/java/org/htmlunit/javascript/host/dom/NodeList.java b/src/main/java/org/htmlunit/javascript/host/dom/NodeList.java index 9c0f9b5464b..ec43c0586f6 100644 --- a/src/main/java/org/htmlunit/javascript/host/dom/NodeList.java +++ b/src/main/java/org/htmlunit/javascript/host/dom/NodeList.java @@ -71,7 +71,7 @@ public void jsConstructor() { * * @param domNode the {@link DomNode} * @param attributeChangeSensitive indicates if the content of the collection may change when an attribute - * of a descendant node of parentScope changes (attribute added, modified or removed) + * of a descendant node of parentScope changes (attribute added, modified or removed) */ public NodeList(final DomNode domNode, final boolean attributeChangeSensitive) { super(domNode, attributeChangeSensitive, null); diff --git a/src/main/java/org/htmlunit/javascript/host/dom/RadioNodeList.java b/src/main/java/org/htmlunit/javascript/host/dom/RadioNodeList.java index 9ca03d07df6..ec61c8a1e77 100644 --- a/src/main/java/org/htmlunit/javascript/host/dom/RadioNodeList.java +++ b/src/main/java/org/htmlunit/javascript/host/dom/RadioNodeList.java @@ -59,7 +59,7 @@ public RadioNodeList(final DomNode domNode) { * * @param domNode the {@link DomNode} * @param attributeChangeSensitive indicates if the content of the collection may change when an attribute - * of a descendant node of parentScope changes (attribute added, modified or removed) + * of a descendant node of parentScope changes (attribute added, modified or removed) */ public RadioNodeList(final DomNode domNode, final boolean attributeChangeSensitive) { super(domNode, attributeChangeSensitive); @@ -86,7 +86,7 @@ public void jsConstructor() { /** * Returns the value of the first checked radio button represented by radioNodeList. * @return the value of the first checked radio button represented by radioNodeList ("on" if value attribute - * is not defined) or an empty string if no radio button is checked. + * is not defined) or an empty string if no radio button is checked. * @see HTML Standard */ @JsxGetter @@ -122,6 +122,9 @@ public void setValue(final String newValue) { } } + /** + * @return the Iterator symbol + */ @JsxSymbol public Scriptable iterator() { return JavaScriptEngine.newArrayIteratorTypeValues(getParentScope(), this); diff --git a/src/main/java/org/htmlunit/javascript/host/dom/Range.java b/src/main/java/org/htmlunit/javascript/host/dom/Range.java index 2848901659c..95b39143c64 100644 --- a/src/main/java/org/htmlunit/javascript/host/dom/Range.java +++ b/src/main/java/org/htmlunit/javascript/host/dom/Range.java @@ -289,7 +289,7 @@ public HtmlUnitScriptable extractContents() { * @param how a constant describing the comparison method * @param sourceRange the Range to compare boundary points with this range * @return -1, 0, or 1, indicating whether the corresponding boundary-point of range is respectively before, - * equal to, or after the corresponding boundary-point of sourceRange. + * equal to, or after the corresponding boundary-point of sourceRange. */ @JsxFunction public int compareBoundaryPoints(final int how, final Range sourceRange) { diff --git a/src/main/java/org/htmlunit/javascript/host/dom/Selection.java b/src/main/java/org/htmlunit/javascript/host/dom/Selection.java index 0999f3eac5a..7d4d387b7fd 100644 --- a/src/main/java/org/htmlunit/javascript/host/dom/Selection.java +++ b/src/main/java/org/htmlunit/javascript/host/dom/Selection.java @@ -54,7 +54,7 @@ public void jsConstructor() { /** * @return a string currently being represented by the selection object, - * i.e. the currently selected text. + * i.e. the currently selected text. */ @JsxFunction(functionName = "toString") public String jsToString() { diff --git a/src/main/java/org/htmlunit/javascript/host/dom/TreeWalker.java b/src/main/java/org/htmlunit/javascript/host/dom/TreeWalker.java index 6f893b80a9c..e0506e09315 100644 --- a/src/main/java/org/htmlunit/javascript/host/dom/TreeWalker.java +++ b/src/main/java/org/htmlunit/javascript/host/dom/TreeWalker.java @@ -228,13 +228,13 @@ public Node lastChild() { } /** - * Moves the TreeWalker to the previous sibling of the current node, and - * returns the new node. If the current node has no visible previous - * sibling, returns {@code null}, and retains the current node. - * - * @return The new node, or {@code null} if the current node has no - * previous sibling in the TreeWalker's logical view. - */ + * Moves the TreeWalker to the previous sibling of the current node, and + * returns the new node. If the current node has no visible previous + * sibling, returns {@code null}, and retains the current node. + * + * @return The new node, or {@code null} if the current node has no + * previous sibling in the TreeWalker's logical view. + */ @JsxFunction public Node previousSibling() { return getNodeOrNull(walker_.previousSibling()); diff --git a/src/main/java/org/htmlunit/javascript/host/dom/XPathNSResolver.java b/src/main/java/org/htmlunit/javascript/host/dom/XPathNSResolver.java index 3b0423bba27..6453157d349 100644 --- a/src/main/java/org/htmlunit/javascript/host/dom/XPathNSResolver.java +++ b/src/main/java/org/htmlunit/javascript/host/dom/XPathNSResolver.java @@ -36,7 +36,7 @@ public class XPathNSResolver extends HtmlUnitScriptable implements PrefixResolve /** * Sets the element to start lookup from. * @param element {@link org.htmlunit.javascript.host.html.HTMLElement} - * or {@link org.htmlunit.javascript.host.Element} to start lookup from + * or {@link org.htmlunit.javascript.host.Element} to start lookup from */ public void setElement(final Node element) { element_ = element; diff --git a/src/main/java/org/htmlunit/javascript/host/dom/XPathResult.java b/src/main/java/org/htmlunit/javascript/host/dom/XPathResult.java index 5997f2b91ec..47f75f37f3b 100644 --- a/src/main/java/org/htmlunit/javascript/host/dom/XPathResult.java +++ b/src/main/java/org/htmlunit/javascript/host/dom/XPathResult.java @@ -187,8 +187,8 @@ public Node getSingleNodeValue() { /** * @return signifies that the iterator has become invalid. - * It is true if XPathResult.resultType is UNORDERED_NODE_ITERATOR_TYPE or - * ORDERED_NODE_ITERATOR_TYPE and the document has been modified since this result was returned. + * It is true if XPathResult.resultType is UNORDERED_NODE_ITERATOR_TYPE or + * ORDERED_NODE_ITERATOR_TYPE and the document has been modified since this result was returned. */ @JsxGetter public boolean getInvalidIteratorState() { diff --git a/src/main/java/org/htmlunit/javascript/host/draganddrop/DataTransferItem.java b/src/main/java/org/htmlunit/javascript/host/draganddrop/DataTransferItem.java index 10433dc8e57..f9c5eb3af40 100644 --- a/src/main/java/org/htmlunit/javascript/host/draganddrop/DataTransferItem.java +++ b/src/main/java/org/htmlunit/javascript/host/draganddrop/DataTransferItem.java @@ -61,10 +61,19 @@ private DataTransferItem(final String kind, final String type, final Object data data_ = data; } + /** + * @param data the data + * @param type the type + * @return a new {@link DataTransferItem} + */ public static DataTransferItem buildStringItem(final CharSequence data, final String type) { return new DataTransferItem(KIND_STRING, type, data); } + /** + * @param file the file + * @return a new {@link DataTransferItem} + */ public static DataTransferItem buildFileItem(final File file) { return new DataTransferItem(KIND_FILE, file.getType(), file); } diff --git a/src/main/java/org/htmlunit/javascript/host/draganddrop/DataTransferItemList.java b/src/main/java/org/htmlunit/javascript/host/draganddrop/DataTransferItemList.java index 739e606e8bf..f99b37759a9 100644 --- a/src/main/java/org/htmlunit/javascript/host/draganddrop/DataTransferItemList.java +++ b/src/main/java/org/htmlunit/javascript/host/draganddrop/DataTransferItemList.java @@ -138,7 +138,7 @@ public void clear() { * Removes the DataTransferItem at the specified index from the list. If the index is less * than zero or greater than one less than the length of the list, the list will not be changed. * @param index the zero-based index number of the item in the drag data list to remove. - * If the index doesn't correspond to an existing item in the list, the list is left unchanged. + * If the index doesn't correspond to an existing item in the list, the list is left unchanged. */ @JsxFunction public void remove(final int index) { diff --git a/src/main/java/org/htmlunit/javascript/host/event/BeforeUnloadEvent.java b/src/main/java/org/htmlunit/javascript/host/event/BeforeUnloadEvent.java index c8945c58948..c36f07545bb 100644 --- a/src/main/java/org/htmlunit/javascript/host/event/BeforeUnloadEvent.java +++ b/src/main/java/org/htmlunit/javascript/host/event/BeforeUnloadEvent.java @@ -40,8 +40,7 @@ public class BeforeUnloadEvent extends Event { * Creates a new event instance. */ public BeforeUnloadEvent() { - super(); - setType(""); + super(""); returnValue_ = ""; } diff --git a/src/main/java/org/htmlunit/javascript/host/event/Event.java b/src/main/java/org/htmlunit/javascript/host/event/Event.java index c3e436d457b..e343cf9236f 100644 --- a/src/main/java/org/htmlunit/javascript/host/event/Event.java +++ b/src/main/java/org/htmlunit/javascript/host/event/Event.java @@ -538,11 +538,11 @@ public Event(final DomNode domNode, final String type) { * @param type the event type */ public Event(final EventTarget target, final String type) { - super(); + this(type); + srcElement_ = target; target_ = target; currentTarget_ = target; - type_ = type; setParentScope(target); setPrototype(getPrototype(getClass())); @@ -569,6 +569,15 @@ else if ( } } + /** + * Creates a new event instance. + * @param type the event type + */ + public Event(final String type) { + super(); + type_ = type; + } + /** * Creates a new Event with {@link #TYPE_PROPERTY_CHANGE} type. * @param domNode the DOM node that triggered the event diff --git a/src/main/java/org/htmlunit/javascript/host/event/EventHandler.java b/src/main/java/org/htmlunit/javascript/host/event/EventHandler.java index 537d2829c16..eaaf2fe70f7 100644 --- a/src/main/java/org/htmlunit/javascript/host/event/EventHandler.java +++ b/src/main/java/org/htmlunit/javascript/host/event/EventHandler.java @@ -19,7 +19,6 @@ import org.htmlunit.corejs.javascript.Function; import org.htmlunit.corejs.javascript.JavaScriptException; import org.htmlunit.corejs.javascript.Scriptable; -import org.htmlunit.corejs.javascript.ScriptableObject; import org.htmlunit.html.DomNode; /** @@ -45,8 +44,6 @@ public EventHandler(final DomNode node, final String eventName, final String jsS node_ = node; eventName_ = eventName; jsSnippet_ = jsSnippet; - - setPrototype(ScriptableObject.getClassPrototype(node.getScriptableObject(), "Function")); } /** diff --git a/src/main/java/org/htmlunit/javascript/host/event/HashChangeEvent.java b/src/main/java/org/htmlunit/javascript/host/event/HashChangeEvent.java index 970edf87c73..91d663c83c2 100644 --- a/src/main/java/org/htmlunit/javascript/host/event/HashChangeEvent.java +++ b/src/main/java/org/htmlunit/javascript/host/event/HashChangeEvent.java @@ -39,8 +39,7 @@ public class HashChangeEvent extends Event { * Creates a new event instance. */ public HashChangeEvent() { - super(); - setEventType(""); + super(""); } /** diff --git a/src/main/java/org/htmlunit/javascript/host/event/PopStateEvent.java b/src/main/java/org/htmlunit/javascript/host/event/PopStateEvent.java index 4129f3a191b..b788c2a7daf 100644 --- a/src/main/java/org/htmlunit/javascript/host/event/PopStateEvent.java +++ b/src/main/java/org/htmlunit/javascript/host/event/PopStateEvent.java @@ -37,8 +37,7 @@ public class PopStateEvent extends Event { * Default constructor. */ public PopStateEvent() { - super(); - setEventType(""); + super(""); } /** diff --git a/src/main/java/org/htmlunit/javascript/host/event/UIEvent.java b/src/main/java/org/htmlunit/javascript/host/event/UIEvent.java index 5d190c7b4ad..2213b613dc0 100644 --- a/src/main/java/org/htmlunit/javascript/host/event/UIEvent.java +++ b/src/main/java/org/htmlunit/javascript/host/event/UIEvent.java @@ -164,7 +164,7 @@ public void initUIEvent( /** * @return a number that indicates which button was pressed on the mouse, - * or the numeric keyCode or the character code (charCode) of the key pressed on the keyboard + * or the numeric keyCode or the character code (charCode) of the key pressed on the keyboard */ @JsxGetter public int getWhich() { diff --git a/src/main/java/org/htmlunit/javascript/host/file/Blob.java b/src/main/java/org/htmlunit/javascript/host/file/Blob.java index 349f03ec7e1..96a45e24d2e 100644 --- a/src/main/java/org/htmlunit/javascript/host/file/Blob.java +++ b/src/main/java/org/htmlunit/javascript/host/file/Blob.java @@ -104,7 +104,7 @@ protected abstract static class Backend implements Serializable { } /** - * Returns the KeyDataPare for this Blob/File. + * Returns the KeyDataPair for this Blob/File. * * @param name the name * @param fileName the file name @@ -299,9 +299,9 @@ public void jsConstructor(final NativeArray fileBits, final ScriptableObject pro nativeBits = null; } - setBackend(InMemoryBackend.create(nativeBits, null, + backend_ = InMemoryBackend.create(nativeBits, null, extractFileTypeOrDefault(properties), - extractLastModifiedOrDefault(properties))); + extractLastModifiedOrDefault(properties)); } /** @@ -335,7 +335,7 @@ public String getType() { /** * @return a Promise that resolves with an ArrayBuffer containing the - * data in binary form. + * data in binary form. */ @JsxFunction public NativePromise arrayBuffer() { @@ -349,6 +349,19 @@ public NativePromise arrayBuffer() { }); } + /** + * @param start An index into the Blob indicating the first byte to include in the new Blob. If you specify + * a negative value, it's treated as an offset from the end of the Blob toward the beginning. + * For example, -10 would be the 10th from last byte in the Blob. The default value is 0. + * If you specify a value for start that is larger than the size of the source Blob, + * the returned Blob has size 0 and contains no data. + * @param end An index into the Blob indicating the first byte that will not be included in the + * new Blob (i.e. the byte exactly at this index is not included). If you specify a negative value, + * it's treated as an offset from the end of the Blob toward the beginning. + * For example, -10 would be the 10th from last byte in the Blob. The default value is size. + * @param contentType The content type to assign to the new Blob; this will be the value of its type property. The default value is an empty string. + * @return a new Blob object which contains data from a subset of the blob on which it's called. + */ @JsxFunction public Blob slice(final Object start, final Object end, final Object contentType) { final Blob blob = new Blob(); @@ -388,6 +401,9 @@ public Blob slice(final Object start, final Object end, final Object contentType return blob; } + /** + * @return a ReadableStream which, upon reading, returns the contents of the Blob. + */ @JsxFunction public ReadableStream stream() { throw new UnsupportedOperationException("Blob.stream() is not yet implemented."); @@ -395,13 +411,16 @@ public ReadableStream stream() { /** * @return a Promise that resolves with a string containing the - * contents of the blob, interpreted as UTF-8. + * contents of the blob, interpreted as UTF-8. */ @JsxFunction public NativePromise text() { return setupPromise(() -> getBackend().getText()); } + /** + * @return the bytes of this blob + */ public byte[] getBytes() { return getBackend().getBytes(0, (int) getBackend().getSize()); } @@ -423,6 +442,12 @@ public void fillRequest(final WebRequest webRequest) { } } + /** + * Delegates the KeyDataPair construction to the backend. + * @param name the name + * @param fileName the filename + * @return the constructed {@link KeyDataPair} + */ public KeyDataPair getKeyDataPair(final String name, final String fileName) { String contentType = getType(); if (StringUtils.isEmpty(contentType)) { diff --git a/src/main/java/org/htmlunit/javascript/host/html/HTMLCanvasElement.java b/src/main/java/org/htmlunit/javascript/host/html/HTMLCanvasElement.java index aa7c96d53e2..8a6cdab39ec 100644 --- a/src/main/java/org/htmlunit/javascript/host/html/HTMLCanvasElement.java +++ b/src/main/java/org/htmlunit/javascript/host/html/HTMLCanvasElement.java @@ -108,7 +108,7 @@ public void setHeight(final int height) { * Gets the context. * @param contextId the context id * @return Returns an object that exposes an API for drawing on the canvas, - * or null if the given context ID is not supported + * or null if the given context ID is not supported */ @JsxFunction public HtmlUnitScriptable getContext(final String contextId) { diff --git a/src/main/java/org/htmlunit/javascript/host/html/HTMLCollection.java b/src/main/java/org/htmlunit/javascript/host/html/HTMLCollection.java index 782b950e045..56a446aafe9 100644 --- a/src/main/java/org/htmlunit/javascript/host/html/HTMLCollection.java +++ b/src/main/java/org/htmlunit/javascript/host/html/HTMLCollection.java @@ -74,7 +74,7 @@ public void jsConstructor() { * Creates an instance. * @param domNode parent scope * @param attributeChangeSensitive indicates if the content of the collection may change when an attribute - * of a descendant node of parentScope changes (attribute added, modified or removed) + * of a descendant node of parentScope changes (attribute added, modified or removed) */ public HTMLCollection(final DomNode domNode, final boolean attributeChangeSensitive) { super(domNode, attributeChangeSensitive, null); @@ -111,6 +111,9 @@ protected HTMLCollection create(final DomNode parentScope, final List i return new HTMLCollection(parentScope, initialElements); } + /** + * @return the Iterator symbol + */ @JsxSymbol public Scriptable iterator() { return JavaScriptEngine.newArrayIteratorTypeValues(getParentScope(), this); diff --git a/src/main/java/org/htmlunit/javascript/host/html/HTMLElement.java b/src/main/java/org/htmlunit/javascript/host/html/HTMLElement.java index 4c4b4afb265..3fbe110f1e6 100644 --- a/src/main/java/org/htmlunit/javascript/host/html/HTMLElement.java +++ b/src/main/java/org/htmlunit/javascript/host/html/HTMLElement.java @@ -37,6 +37,7 @@ import org.htmlunit.SgmlPage; import org.htmlunit.WebWindow; import org.htmlunit.corejs.javascript.Function; +import org.htmlunit.corejs.javascript.ScriptableObject; import org.htmlunit.css.ComputedCssStyleDeclaration; import org.htmlunit.css.StyleAttributes; import org.htmlunit.html.DomElement; @@ -359,7 +360,9 @@ public void setAttribute(String name, final String value) { try { name = Character.toUpperCase(name.charAt(0)) + name.substring(1); final Method method = getClass().getMethod("set" + name, METHOD_PARAMS_OBJECT); - method.invoke(this, new EventHandler(getDomNodeOrDie(), name.substring(2), value)); + final EventHandler eventHandler = new EventHandler(getDomNodeOrDie(), name.substring(2), value); + eventHandler.setPrototype(ScriptableObject.getClassPrototype(this, "Function")); + method.invoke(this, eventHandler); } catch (final NoSuchMethodException | IllegalAccessException ignored) { // silently ignore @@ -1067,7 +1070,7 @@ public int getOffsetTop() { * offsetTop attributes are relative to the offsetParent. * * @return this element's offsetParent. This may be undefined when this node is - * not attached or {@code null} for body. + * not attached or {@code null} for body. * @see MSDN Documentation * @see Gecko DOM Reference * @see Element Dimensions diff --git a/src/main/java/org/htmlunit/javascript/host/html/HTMLFormControlsCollection.java b/src/main/java/org/htmlunit/javascript/host/html/HTMLFormControlsCollection.java index 872025ba148..fa592334e18 100644 --- a/src/main/java/org/htmlunit/javascript/host/html/HTMLFormControlsCollection.java +++ b/src/main/java/org/htmlunit/javascript/host/html/HTMLFormControlsCollection.java @@ -48,7 +48,7 @@ public HTMLFormControlsCollection() { * Creates an instance. * @param domNode parent scope * @param attributeChangeSensitive indicates if the content of the collection may change when an attribute - * of a descendant node of parentScope changes (attribute added, modified or removed) + * of a descendant node of parentScope changes (attribute added, modified or removed) */ public HTMLFormControlsCollection(final DomNode domNode, final boolean attributeChangeSensitive) { super(domNode, attributeChangeSensitive); diff --git a/src/main/java/org/htmlunit/javascript/host/html/HTMLFormElement.java b/src/main/java/org/htmlunit/javascript/host/html/HTMLFormElement.java index 95601c7ce9d..a598717e56a 100644 --- a/src/main/java/org/htmlunit/javascript/host/html/HTMLFormElement.java +++ b/src/main/java/org/htmlunit/javascript/host/html/HTMLFormElement.java @@ -131,6 +131,9 @@ protected Object getWithPreemption(final String name) { return elements; } + /** + * @return the Iterator symbol + */ @JsxSymbol public Scriptable iterator() { return getElements().iterator(); @@ -313,9 +316,9 @@ public void submit() { /** * Submits the form by submitted using a specific submit button. * @param submitter The submit button whose attributes describe the method - * by which the form is to be submitted. This may be either - * an <input> or <button> element whose type attribute is submit. - * If you omit the submitter parameter, the form element itself is used as the submitter. + * by which the form is to be submitted. This may be either + * an <input> or <button> element whose type attribute is submit. + * If you omit the submitter parameter, the form element itself is used as the submitter. */ @JsxFunction public void requestSubmit(final Object submitter) { diff --git a/src/main/java/org/htmlunit/javascript/host/html/HTMLInputElement.java b/src/main/java/org/htmlunit/javascript/host/html/HTMLInputElement.java index 6ba144291b9..cbd71ad4dc3 100644 --- a/src/main/java/org/htmlunit/javascript/host/html/HTMLInputElement.java +++ b/src/main/java/org/htmlunit/javascript/host/html/HTMLInputElement.java @@ -145,7 +145,7 @@ public HtmlInput getDomNodeOrDie() { * checkbox and radio. This implementation does nothing. The * implementations in Checkbox and Radio actually do the work. * - *@return the checked property + * @return the checked property */ @JsxGetter public boolean isChecked() { diff --git a/src/main/java/org/htmlunit/javascript/host/html/HTMLOptionsCollection.java b/src/main/java/org/htmlunit/javascript/host/html/HTMLOptionsCollection.java index 80ce6feba9b..d01c0489e19 100644 --- a/src/main/java/org/htmlunit/javascript/host/html/HTMLOptionsCollection.java +++ b/src/main/java/org/htmlunit/javascript/host/html/HTMLOptionsCollection.java @@ -233,8 +233,8 @@ public void setLength(final int newLength) { * * @param newOptionObject the DomNode to insert in the collection * @param beforeOptionObject An optional parameter which specifies the index position in the - * collection where the element is placed. If no value is given, the method places - * the element at the end of the collection. + * collection where the element is placed. If no value is given, the method places + * the element at the end of the collection. * * @see #put(int, Scriptable, Object) */ @@ -310,6 +310,9 @@ public void setSelectedIndex(final int index) { htmlSelect_.setSelectedIndex(index); } + /** + * @return the Iterator symbol + */ @JsxSymbol public Scriptable iterator() { return JavaScriptEngine.newArrayIteratorTypeValues(getParentScope(), this); diff --git a/src/main/java/org/htmlunit/javascript/host/html/HTMLSelectElement.java b/src/main/java/org/htmlunit/javascript/host/html/HTMLSelectElement.java index ed71efd5e35..52e0e1a7702 100644 --- a/src/main/java/org/htmlunit/javascript/host/html/HTMLSelectElement.java +++ b/src/main/java/org/htmlunit/javascript/host/html/HTMLSelectElement.java @@ -409,6 +409,9 @@ public void setCustomValidity(final String message) { getDomNodeOrDie().setCustomValidity(message); } + /** + * @return the Iterator symbol + */ @JsxSymbol public Scriptable iterator() { return getOptions().iterator(); diff --git a/src/main/java/org/htmlunit/javascript/host/html/ValidityState.java b/src/main/java/org/htmlunit/javascript/host/html/ValidityState.java index 93a46a73ed2..a16131761e0 100644 --- a/src/main/java/org/htmlunit/javascript/host/html/ValidityState.java +++ b/src/main/java/org/htmlunit/javascript/host/html/ValidityState.java @@ -52,7 +52,7 @@ public void setDomNode(final DomNode domNode) { /** * @return a boolean value that is true if the user has provided - * input that the browser is unable to convert. + * input that the browser is unable to convert. */ @JsxGetter public boolean isBadInput() { diff --git a/src/main/java/org/htmlunit/javascript/host/intl/DateTimeFormat.java b/src/main/java/org/htmlunit/javascript/host/intl/DateTimeFormat.java index 1644b6ead1a..243735e13ed 100644 --- a/src/main/java/org/htmlunit/javascript/host/intl/DateTimeFormat.java +++ b/src/main/java/org/htmlunit/javascript/host/intl/DateTimeFormat.java @@ -259,7 +259,7 @@ public String format(final Object object) { /** * @return A new object with properties reflecting the locale and date and time formatting options - * computed during the initialization of the given {@code DateTimeFormat} object. + * computed during the initialization of the given {@code DateTimeFormat} object. */ @JsxFunction public Scriptable resolvedOptions() { diff --git a/src/main/java/org/htmlunit/javascript/host/intl/NumberFormat.java b/src/main/java/org/htmlunit/javascript/host/intl/NumberFormat.java index 7a01e2ef84b..7052282805b 100644 --- a/src/main/java/org/htmlunit/javascript/host/intl/NumberFormat.java +++ b/src/main/java/org/htmlunit/javascript/host/intl/NumberFormat.java @@ -206,7 +206,7 @@ public String format(final Object object) { /** * @return A new object with properties reflecting the locale and date and time formatting options - * computed during the initialization of the given {@code DateTimeFormat} object. + * computed during the initialization of the given {@code DateTimeFormat} object. */ @JsxFunction public Scriptable resolvedOptions() { diff --git a/src/main/java/org/htmlunit/javascript/host/media/BaseAudioContext.java b/src/main/java/org/htmlunit/javascript/host/media/BaseAudioContext.java index 5005f749193..824d7dcea46 100644 --- a/src/main/java/org/htmlunit/javascript/host/media/BaseAudioContext.java +++ b/src/main/java/org/htmlunit/javascript/host/media/BaseAudioContext.java @@ -47,7 +47,7 @@ public void jsConstructor() { /** * @return a new AudioBufferSourceNode, which can be used to - * play audio data contained within an AudioBuffer object. + * play audio data contained within an AudioBuffer object. */ @JsxFunction public AudioBufferSourceNode createBufferSource() { @@ -59,7 +59,7 @@ public AudioBufferSourceNode createBufferSource() { /** * @return new, empty AudioBuffer object, which can then be - * populated by data, and played via an AudioBufferSourceNode. + * populated by data, and played via an AudioBufferSourceNode. */ @JsxFunction public AudioBuffer createBuffer() { @@ -88,13 +88,13 @@ public GainNode createGain() { * The decoded AudioBuffer is resampled to the AudioContext's sampling rate, * then passed to a callback or promise. * @param buffer An ArrayBuffer containing the audio data to be decoded, usually grabbed - * from XMLHttpRequest, WindowOrWorkerGlobalScope.fetch() or FileReader + * from XMLHttpRequest, WindowOrWorkerGlobalScope.fetch() or FileReader * @param success A callback function to be invoked when the decoding successfully finishes. - * The single argument to this callback is an AudioBuffer representing the decodedData - * (the decoded PCM audio data). Usually you'll want to put the decoded data into - * an AudioBufferSourceNode, from which it can be played and manipulated how you want. + * The single argument to this callback is an AudioBuffer representing the decodedData + * (the decoded PCM audio data). Usually you'll want to put the decoded data into + * an AudioBufferSourceNode, from which it can be played and manipulated how you want. * @param error An optional error callback, to be invoked if an error occurs - * when the audio data is being decoded. + * when the audio data is being decoded. * @return the promise or null */ @JsxFunction diff --git a/src/main/java/org/htmlunit/javascript/host/media/MediaDevices.java b/src/main/java/org/htmlunit/javascript/host/media/MediaDevices.java index 801a5feaaea..453e74791c8 100644 --- a/src/main/java/org/htmlunit/javascript/host/media/MediaDevices.java +++ b/src/main/java/org/htmlunit/javascript/host/media/MediaDevices.java @@ -39,6 +39,10 @@ public void jsConstructor() { super.jsConstructor(); } + /** + * @return a {@link NativePromise} that resolves to a {@link DOMException} because HtmlUnit + * does not support media streaming + */ @JsxFunction public NativePromise getUserMedia() { return setupRejectedPromise(() -> diff --git a/src/main/java/org/htmlunit/javascript/host/media/MediaSource.java b/src/main/java/org/htmlunit/javascript/host/media/MediaSource.java index e3577c82f54..9d88134ad1f 100644 --- a/src/main/java/org/htmlunit/javascript/host/media/MediaSource.java +++ b/src/main/java/org/htmlunit/javascript/host/media/MediaSource.java @@ -43,7 +43,7 @@ public void jsConstructor() { * * @param mimeType the mimeType to check * @return indicating if the given MIME type is supported by the - * current user agent — this is, if it can successfully create SourceBuffer objects for that MIME type + * current user agent — this is, if it can successfully create SourceBuffer objects for that MIME type */ @JsxStaticFunction public static boolean isTypeSupported(final String mimeType) { diff --git a/src/main/java/org/htmlunit/javascript/host/performance/Performance.java b/src/main/java/org/htmlunit/javascript/host/performance/Performance.java index 5c4bacbe42e..e0cc357a109 100644 --- a/src/main/java/org/htmlunit/javascript/host/performance/Performance.java +++ b/src/main/java/org/htmlunit/javascript/host/performance/Performance.java @@ -79,10 +79,10 @@ public double now() { /** * @return a list of all PerformanceEntry objects for the page. - * The list's members (entries) can be created by making performance marks - * or measures (for example by calling the mark() method) at explicit points in time. - * If you are only interested in performance entries of certain types or that have - * certain names, see getEntriesByType() and getEntriesByName(). + * The list's members (entries) can be created by making performance marks + * or measures (for example by calling the mark() method) at explicit points in time. + * If you are only interested in performance entries of certain types or that have + * certain names, see getEntriesByType() and getEntriesByName(). */ @JsxFunction public Scriptable getEntries() { @@ -91,10 +91,10 @@ public Scriptable getEntries() { /** * @return a list of all PerformanceEntry objects for the page. - * The list's members (entries) can be created by making performance marks - * or measures (for example by calling the mark() method) at explicit points in time. - * If you are only interested in performance entries of certain types or that have - * certain names, see getEntriesByType() and getEntriesByName(). + * The list's members (entries) can be created by making performance marks + * or measures (for example by calling the mark() method) at explicit points in time. + * If you are only interested in performance entries of certain types or that have + * certain names, see getEntriesByType() and getEntriesByName(). */ @JsxFunction public Scriptable getEntriesByName() { @@ -103,8 +103,8 @@ public Scriptable getEntriesByName() { /** * @return a list of PerformanceEntry objects for a given type. The list's - * members (entries) can be created by making performance marks or measures - * (for example by calling the mark() method) at explicit points in time. + * members (entries) can be created by making performance marks or measures + * (for example by calling the mark() method) at explicit points in time. */ @JsxFunction public Scriptable getEntriesByType() { diff --git a/src/main/java/org/htmlunit/javascript/host/xml/XMLHttpRequest.java b/src/main/java/org/htmlunit/javascript/host/xml/XMLHttpRequest.java index 364142d1ac8..b3bf073223e 100644 --- a/src/main/java/org/htmlunit/javascript/host/xml/XMLHttpRequest.java +++ b/src/main/java/org/htmlunit/javascript/host/xml/XMLHttpRequest.java @@ -291,7 +291,7 @@ public void setResponseType(final String responseType) { /** * @return returns the response's body content as an ArrayBuffer, Blob, Document, JavaScript Object, - * or DOMString, depending on the value of the request's responseType property. + * or DOMString, depending on the value of the request's responseType property. */ @JsxGetter public Object getResponse() { @@ -1272,11 +1272,19 @@ public void setOnreadystatechange(final Function readyStateChangeHandler) { super.setOnreadystatechange(readyStateChangeHandler); } + /** + * @return the number of milliseconds a request can take before automatically being terminated. + * The default value is 0, which means there is no timeout. + */ @JsxGetter public int getTimeout() { return timeout_; } + /** + * Sets the number of milliseconds a request can take before automatically being terminated. + * @param timeout the timeout in milliseconds + */ @JsxSetter public void setTimeout(final int timeout) { timeout_ = timeout; @@ -1337,11 +1345,6 @@ public Charset getContentCharset() { return null; } - @Override - public Charset getContentCharsetOrNull() { - return null; - } - @Override public WebRequest getWebRequest() { return request_; diff --git a/src/main/java/org/htmlunit/javascript/polyfill/Polyfill.java b/src/main/java/org/htmlunit/javascript/polyfill/Polyfill.java index afd5132a4c2..893f690e71d 100644 --- a/src/main/java/org/htmlunit/javascript/polyfill/Polyfill.java +++ b/src/main/java/org/htmlunit/javascript/polyfill/Polyfill.java @@ -38,6 +38,10 @@ public class Polyfill { private String source_; private Script script_; + /** + * @return the build in fetch polyfill + * @throws IOException in case of error + */ public static Polyfill getFetchPolyfill() throws IOException { return getPolyfill("fetch/fetch.umd.js"); } diff --git a/src/main/java/org/htmlunit/javascript/proxyautoconfig/ProxyAutoConfig.java b/src/main/java/org/htmlunit/javascript/proxyautoconfig/ProxyAutoConfig.java index 96eb64829cd..732f278519e 100644 --- a/src/main/java/org/htmlunit/javascript/proxyautoconfig/ProxyAutoConfig.java +++ b/src/main/java/org/htmlunit/javascript/proxyautoconfig/ProxyAutoConfig.java @@ -73,7 +73,7 @@ public static boolean dnsDomainIs(final String host, final String domain) { * @param host the hostname from the URL * @param hostdom fully qualified hostname to match against * @return true if the hostname matches exactly the specified hostname, - * or if there is no domain name part in the hostname, but the unqualified hostname matches. + * or if there is no domain name part in the hostname, but the unqualified hostname matches. */ @JsxFunction public static boolean localHostOrDomainIs(final String host, final String hostdom) { @@ -93,10 +93,10 @@ public static boolean isResolvable(final String host) { /** * Returns true if the IP address of the host matches the specified IP address pattern. * @param host a DNS hostname, or IP address. - * If a hostname is passed, it will be resolved into an IP address by this function. + * If a hostname is passed, it will be resolved into an IP address by this function. * @param pattern an IP address pattern in the dot-separated format * @param mask mask for the IP address pattern informing which parts of the IP address should be matched against. - * 0 means ignore, 255 means match + * 0 means ignore, 255 means match * @return true if the IP address of the host matches the specified IP address pattern. */ @JsxFunction diff --git a/src/main/java/org/htmlunit/javascript/regexp/HtmlUnitRegExpProxy.java b/src/main/java/org/htmlunit/javascript/regexp/HtmlUnitRegExpProxy.java deleted file mode 100644 index 384d9f18be6..00000000000 --- a/src/main/java/org/htmlunit/javascript/regexp/HtmlUnitRegExpProxy.java +++ /dev/null @@ -1,575 +0,0 @@ -/* - * Copyright (c) 2002-2025 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 - * https://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 org.htmlunit.javascript.regexp; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.regex.MatchResult; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.regex.PatternSyntaxException; - -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.htmlunit.NotYetImplementedException; -import org.htmlunit.corejs.javascript.Context; -import org.htmlunit.corejs.javascript.RegExpProxy; -import org.htmlunit.corejs.javascript.ScriptRuntime; -import org.htmlunit.corejs.javascript.Scriptable; -import org.htmlunit.corejs.javascript.regexp.NativeRegExp; -import org.htmlunit.corejs.javascript.regexp.RegExpImpl; -import org.htmlunit.corejs.javascript.regexp.SubString; -import org.htmlunit.javascript.JavaScriptEngine; - -/** - * Begins customization of JavaScript RegExp base on JDK regular expression support. - * - * @author Marc Guillemot - * @author Ahmed Ashour - * @author Ronald Brill - * @author Carsten Steul - */ -public class HtmlUnitRegExpProxy extends RegExpImpl { - - private static final Log LOG = LogFactory.getLog(HtmlUnitRegExpProxy.class); - /** Pattern cache */ - private static final Map PATTENS = new HashMap<>(); - - private final RegExpProxy wrapped_; - - /** - * Wraps a proxy to enhance it. - * @param wrapped the original proxy - */ - public HtmlUnitRegExpProxy(final RegExpProxy wrapped) { - super(); - wrapped_ = wrapped; - } - - /** - * Use the wrapped proxy except for replacement with string arg where it uses Java regular expression. - * {@inheritDoc} - */ - @Override - public Object action(final Context cx, final Scriptable scope, final Scriptable thisObj, - final Object[] args, final int actionType) { - try { - return doAction(cx, scope, thisObj, args, actionType); - } - catch (final RegExStickyNotSupportedException e) { - if (LOG.isWarnEnabled()) { - LOG.warn(e.getMessage(), e); - } - return wrapped_.action(cx, scope, thisObj, args, actionType); - } - catch (final StackOverflowError e) { - // TODO: We shouldn't have to catch this exception and fall back to Rhino's regex support! - // See HtmlUnitRegExpProxyTest.stackOverflow() - if (LOG.isWarnEnabled()) { - LOG.warn(e.getMessage(), e); - } - return wrapped_.action(cx, scope, thisObj, args, actionType); - } - } - - private Object doAction(final Context cx, final Scriptable scope, final Scriptable thisObj, - final Object[] args, final int actionType) { - // in a first time just improve replacement with a String (not a function) - if ((RA_REPLACE == actionType || RA_REPLACE_ALL == actionType) - && args.length == 2 && args[1] instanceof String) { - final String thisString = JavaScriptEngine.toString(thisObj); - final String replacement = (String) args[1]; - final Object arg0 = args[0]; - if (arg0 instanceof String) { - // arg0 should *not* be interpreted as a RegExp - return doStringReplacement(thisString, (String) arg0, replacement, RA_REPLACE_ALL == actionType); - } - - if (arg0 instanceof NativeRegExp) { - try { - final NativeRegExp regexp = (NativeRegExp) arg0; - - if (RA_REPLACE_ALL == actionType - && (regexp.getFlags() & NativeRegExp.JSREG_GLOB) == 0) { - throw ScriptRuntime.typeError( - "replaceAll must be called with a global RegExp"); - } - - final RegExpData reData = new RegExpData(regexp); - final Matcher matcher = reData.getPattern().matcher(thisString); - return doReplacement(thisString, replacement, matcher, - reData.isGlobal() || RA_REPLACE_ALL == actionType); - } - catch (final PatternSyntaxException e) { - if (LOG.isWarnEnabled()) { - LOG.warn(e.getMessage(), e); - } - } - } - } - else if (RA_MATCH == actionType || RA_SEARCH == actionType) { - if (args.length == 0) { - return null; - } - final Object arg0 = args[0]; - final String thisString = JavaScriptEngine.toString(thisObj); - final RegExpData reData; - if (arg0 instanceof NativeRegExp) { - reData = new RegExpData((NativeRegExp) arg0); - } - else { - reData = new RegExpData(JavaScriptEngine.toString(arg0)); - } - - final Matcher matcher = reData.getPattern().matcher(thisString); - - final boolean found = matcher.find(); - if (RA_SEARCH == actionType) { - if (found) { - setProperties(matcher, thisString, matcher.start(), matcher.end()); - return matcher.start(); - } - return -1; - } - - if (!found) { - return null; - } - final int index = matcher.start(0); - final List groups = new ArrayList<>(); - if (reData.isGlobal()) { // has flag g - groups.add(matcher.group(0)); - setProperties(matcher, thisString, matcher.start(0), matcher.end(0)); - - while (matcher.find()) { - groups.add(matcher.group(0)); - setProperties(matcher, thisString, matcher.start(0), matcher.end(0)); - } - } - else { - for (int i = 0; i <= matcher.groupCount(); i++) { - Object group = matcher.group(i); - if (group == null) { - group = JavaScriptEngine.UNDEFINED; - } - groups.add(group); - } - - setProperties(matcher, thisString, matcher.start(), matcher.end()); - } - final Scriptable response = cx.newArray(scope, groups.toArray()); - // the additional properties (cf ECMA script reference 15.10.6.2 13) - response.put("index", response, Integer.valueOf(index)); - response.put("input", response, thisString); - return response; - } - - return wrappedAction(cx, scope, thisObj, args, actionType); - } - - private String doStringReplacement(final String originalString, - final String searchString, final String replacement, - final boolean replaceAll) { - if (originalString == null) { - return ""; - } - - final StaticStringMatcher matcher = new StaticStringMatcher(originalString, searchString); - - final StringBuilder sb = new StringBuilder(); - int previousIndex = 0; - - while (matcher.find()) { - sb.append(originalString, previousIndex, matcher.start()); - - String localReplacement = replacement; - if (replacement.contains("$")) { - localReplacement = computeReplacementValue(localReplacement, originalString, matcher, false); - } - sb.append(localReplacement); - previousIndex = matcher.end(); - - if (!replaceAll) { - break; - } - } - sb.append(originalString, previousIndex, originalString.length()); - return sb.toString(); - } - - private String doReplacement(final String originalString, final String replacement, final Matcher matcher, - final boolean replaceAll) { - - final StringBuilder sb = new StringBuilder(); - int previousIndex = 0; - while (matcher.find()) { - sb.append(originalString, previousIndex, matcher.start()); - String localReplacement = replacement; - if (replacement.contains("$")) { - localReplacement = computeReplacementValue(replacement, originalString, matcher, false); - } - sb.append(localReplacement); - previousIndex = matcher.end(); - - setProperties(matcher, originalString, matcher.start(), previousIndex); - if (!replaceAll) { - break; - } - } - sb.append(originalString, previousIndex, originalString.length()); - return sb.toString(); - } - - String computeReplacementValue(final String replacement, final String originalString, - final MatchResult matcher, final boolean group0ReturnsWholeMatch) { - - int lastIndex = 0; - final StringBuilder result = new StringBuilder(); - int i; - while ((i = replacement.indexOf('$', lastIndex)) > -1) { - if (i > 0) { - result.append(replacement, lastIndex, i); - } - String ss = null; - if (i < replacement.length() - 1 && (i == lastIndex || replacement.charAt(i - 1) != '$')) { - final char next = replacement.charAt(i + 1); - // only valid back reference are "evaluated" - if (next >= '1' && next <= '9') { - final int num1digit = next - '0'; - final char next2 = i + 2 < replacement.length() ? replacement.charAt(i + 2) : 'x'; - final int num2digits; - // if there are 2 digits, the second one is considered as part of the group number - // only if there is such a group - if (next2 >= '1' && next2 <= '9') { - num2digits = num1digit * 10 + (next2 - '0'); - } - else { - num2digits = Integer.MAX_VALUE; - } - if (num2digits <= matcher.groupCount()) { - ss = matcher.group(num2digits); - i++; - } - else if (num1digit <= matcher.groupCount()) { - ss = StringUtils.defaultString(matcher.group(num1digit)); - } - } - else { - switch (next) { - case '&': - ss = matcher.group(); - break; - case '0': - if (group0ReturnsWholeMatch) { - ss = matcher.group(); - } - break; - case '`': - ss = originalString.substring(0, matcher.start()); - break; - case '\'': - ss = originalString.substring(matcher.end()); - break; - case '$': - ss = "$"; - break; - default: - } - } - } - if (ss == null) { - result.append('$'); - lastIndex = i + 1; - } - else { - result.append(ss); - lastIndex = i + 2; - } - } - - result.append(replacement, lastIndex, replacement.length()); - - return result.toString(); - } - - /** - * Calls action on the wrapped RegExp proxy. - */ - private Object wrappedAction(final Context cx, final Scriptable scope, final Scriptable thisObj, - final Object[] args, final int actionType) { - - // take care to set the context's RegExp proxy to the original one as this is checked - // (cf org.htmlunit.corejs.javascript.regexp.RegExpImp:334) - try { - ScriptRuntime.setRegExpProxy(cx, wrapped_); - return wrapped_.action(cx, scope, thisObj, args, actionType); - } - finally { - ScriptRuntime.setRegExpProxy(cx, this); - } - } - - private void setProperties(final Matcher matcher, final String thisString, final int startPos, final int endPos) { - // lastMatch - final String match = matcher.group(); - if (match == null) { - lastMatch = new SubString(); - } - else { - lastMatch = new SubString(match, 0, match.length()); - } - - // parens - final int groupCount = matcher.groupCount(); - if (groupCount == 0) { - parens = null; - } - else { - final int count = Math.min(9, groupCount); - parens = new SubString[count]; - for (int i = 0; i < count; i++) { - final String group = matcher.group(i + 1); - if (group == null) { - parens[i] = new SubString(); - } - else { - parens[i] = new SubString(group, 0, group.length()); - } - } - } - - // lastParen - if (groupCount > 0) { - final String last = matcher.group(groupCount); - if (last == null) { - lastParen = new SubString(); - } - else { - lastParen = new SubString(last, 0, last.length()); - } - } - - // leftContext - if (startPos > 0) { - leftContext = new SubString(thisString, 0, startPos); - } - else { - leftContext = new SubString(); - } - - // rightContext - final int length = thisString.length(); - if (endPos < length) { - rightContext = new SubString(thisString, endPos, length - endPos); - } - else { - rightContext = new SubString(); - } - } - - /** - * {@inheritDoc} - */ - @Override - public Object compileRegExp(final Context cx, final String source, final String flags) { - try { - return wrapped_.compileRegExp(cx, source, flags); - } - catch (final Exception e) { - if (LOG.isWarnEnabled()) { - LOG.warn("compileRegExp() threw for >" + source + "<, flags: >" + flags + "<. " - + "Replacing with a '####shouldNotFindAnything###'"); - } - return wrapped_.compileRegExp(cx, "####shouldNotFindAnything###", ""); - } - } - - /** - * {@inheritDoc} - */ - @Override - public int find_split(final Context cx, final Scriptable scope, final String target, - final String separator, final Scriptable re, final int[] ip, final int[] matchlen, - final boolean[] matched, final String[][] parensp) { - return wrapped_.find_split(cx, scope, target, separator, re, ip, matchlen, matched, parensp); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isRegExp(final Scriptable obj) { - return wrapped_.isRegExp(obj); - } - - /** - * {@inheritDoc} - */ - @Override - public Scriptable wrapRegExp(final Context cx, final Scriptable scope, final Object compiled) { - return wrapped_.wrapRegExp(cx, scope, compiled); - } - - private static class RegExpData { - private final boolean global_; - private Pattern pattern_; - - RegExpData(final NativeRegExp re) { - final String str = re.toString(); // the form is /regex/flags - final String jsFlags = StringUtils.substringAfterLast(str, "/"); - - if (jsFlags.indexOf('y') != -1) { - throw new RegExStickyNotSupportedException(str); - } - - global_ = jsFlags.indexOf('g') != -1; - - pattern_ = PATTENS.get(str); - if (pattern_ == null) { - final String jsSource = StringUtils.substringBeforeLast(str.substring(1), "/"); - pattern_ = Pattern.compile(jsRegExpToJavaRegExp(jsSource), getJavaFlags(jsFlags)); - PATTENS.put(str, pattern_); - } - } - - RegExpData(final String string) { - global_ = false; - - pattern_ = PATTENS.get(string); - if (pattern_ == null) { - pattern_ = Pattern.compile(jsRegExpToJavaRegExp(string), 0); - PATTENS.put(string, pattern_); - } - } - - /** - * Converts the current JavaScript RegExp flags to Java Pattern flags. - * @return the Java Pattern flags - */ - private static int getJavaFlags(final String jsFlags) { - int flags = 0; - if (jsFlags.contains("i")) { - flags |= Pattern.CASE_INSENSITIVE; - } - if (jsFlags.contains("m")) { - flags |= Pattern.MULTILINE; - } - if (jsFlags.contains("s")) { - flags |= Pattern.DOTALL; - } - return flags; - } - - boolean isGlobal() { - return global_; - } - - Pattern getPattern() { - return pattern_; - } - } - - /** - * Transform a JavaScript regular expression to a Java regular expression - * @param re the JavaScript regular expression to transform - * @return the transformed expression - */ - static String jsRegExpToJavaRegExp(final String re) { - final RegExpJsToJavaConverter regExpJsToJavaFSM = new RegExpJsToJavaConverter(); - return regExpJsToJavaFSM.convert(re); - } - - /** - * Simple helper. - */ - private static final class StaticStringMatcher implements MatchResult { - private final String original_; - private final String search_; - - private int start_; - private int end_; - - StaticStringMatcher(final String originalString, final String searchString) { - original_ = originalString; - search_ = searchString; - - start_ = -1; - end_ = 0; - } - - public boolean find() { - if (start_ == end_) { - end_++; - } - if (end_ > original_.length()) { - return false; - } - - final int pos = original_.indexOf(search_, end_); - if (pos != -1) { - start_ = pos; - end_ = pos + search_.length(); - return true; - } - return false; - } - - @Override - public String group() { - return search_; - } - - @Override - public int start() { - return start_; - } - - @Override - public int end() { - return end_; - } - - @Override - public int start(final int group) { - throw new NotYetImplementedException("StaticStringMatcher.start(int)"); - } - - @Override - public int end(final int group) { - throw new NotYetImplementedException("StaticStringMatcher.end(int)"); - } - - @Override - public String group(final int group) { - throw new NotYetImplementedException("StaticStringMatcher.group(int)"); - } - - @Override - public int groupCount() { - return 0; - } - } - - // a bit of a hack but sufficent for the moment - private static class RegExStickyNotSupportedException extends IllegalArgumentException { - RegExStickyNotSupportedException(final String regex) { - super("RegEx sticky flag is not supported (" + regex + ") by HtmlUnitRegExProxy"); - } - } - -} diff --git a/src/main/java/org/htmlunit/javascript/regexp/RegExpJsToJavaConverter.java b/src/main/java/org/htmlunit/javascript/regexp/RegExpJsToJavaConverter.java deleted file mode 100644 index f99763f02c6..00000000000 --- a/src/main/java/org/htmlunit/javascript/regexp/RegExpJsToJavaConverter.java +++ /dev/null @@ -1,513 +0,0 @@ -/* - * Copyright (c) 2002-2025 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 - * https://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 org.htmlunit.javascript.regexp; - -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.Deque; -import java.util.HashMap; -import java.util.List; - -/** - * Translates JavaScript RegExp to Java RegExp.
- * // [...\b...] to [...\cH...] - * // [...[...] to [...\[...] - * // [^\\1] to . - * // back reference in character classes are simply ignored by browsers [...ab\5cd...] to [...abcd...] - * // characters escaped without need should be "un-escaped" - * Escape curly braces that are not used in an expression - * like "{n}", "{n,}" or "{n,m}" (where n and m are positive integers). - * - * @author Ronald Brill - * @author Leszek Hoppe - * @author Atsushi Nakagawa - * @author Lai Quang Duong - */ -public class RegExpJsToJavaConverter { - - private static final String DIGITS = "0123456789"; - private static final HashMap UNICODE_ESCAPES; - - private Tape tape_; - private boolean insideCharClass_; - private boolean insideRepetition_; - private Deque parsingSubexpressions_; - private List subexpressions_; - - static { - UNICODE_ESCAPES = new HashMap<>(); - UNICODE_ESCAPES.put("L", "L"); - UNICODE_ESCAPES.put("LETTER", "L"); - UNICODE_ESCAPES.put("LU", "Lu"); - UNICODE_ESCAPES.put("UPPERCASELETTER", "Lu"); - UNICODE_ESCAPES.put("LL", "Ll"); - UNICODE_ESCAPES.put("LOWERCASELETTER", "Ll"); - } - - /** - * Helper to encapsulate the transformations. - */ - private static class Tape { - private final StringBuilder tape_; - private int currentPos_; - - /** - * Wraps a JavaScript RegExp to access it char by char like a tape. - * - * @param input the Javascript RegExp - */ - Tape(final String input) { - currentPos_ = 0; - tape_ = new StringBuilder(input); - } - - /** - * Moves the current read position by offset. - * @param offset the move position offset - */ - public void move(final int offset) { - currentPos_ += offset; - } - - /** - * Reads the character at the current position and - * moves the read position by 1. - * - * @return the character at current position - */ - public int read() { - if (currentPos_ < 0) { - return -1; - } - if (currentPos_ >= tape_.length()) { - return -1; - } - - return tape_.charAt(currentPos_++); - } - - /** - * Inserts a string at the current position + offset. - * @param token the string to insert - * @param offset the move position offset - */ - public void insert(final String token, final int offset) { - tape_.insert(currentPos_ + offset, token); - currentPos_ += token.length(); - } - - /** - * Inserts a string at the given pos. - * @param token the string to insert - * @param pos the move position offset - */ - public void insertAt(final String token, final int pos) { - tape_.insert(pos, token); - currentPos_ += token.length(); - } - - /** - * Replaces the current char with the given string. - * @param token the string to insert - */ - public void replace(final int count, final String token) { - tape_.replace(currentPos_, currentPos_ + count, token); - currentPos_ += token.length(); - } - - /** - * Removes number of chars from the given string. - * @param count the number of chars to remove - */ - public void remove(final int count) { - tape_.delete(currentPos_, currentPos_ + count); - } - - /** - * Read the whole tape content. - * - * @return tape content - */ - @Override - public String toString() { - return tape_.toString(); - } - } - - private static final class Subexpresion { - private boolean closed_; - private boolean optional_; - private final boolean enhanced_; - private int start_; - private int end_; - - Subexpresion() { - closed_ = false; - optional_ = false; - enhanced_ = false; - start_ = -1; - end_ = -1; - } - } - - /** - * Run the state machine on a given input string. - * - * @param input - * the js regexp to process - * @return a valid java regex pattern - */ - public String convert(final String input) { - tape_ = new Tape(input); - insideCharClass_ = false; - insideRepetition_ = false; - - parsingSubexpressions_ = new ArrayDeque<>(); - subexpressions_ = new ArrayList<>(); - - int current = tape_.read(); - while (current > -1) { - if ('\\' == current) { - processEscapeSequence(); - } - else if ('[' == current) { - processCharClassStart(); - } - else if (']' == current) { - processCharClassEnd(); - } - else if ('{' == current) { - processRepetitionStart(); - } - else if ('}' == current) { - processRepetitionEnd(); - } - else if ('(' == current) { - processSubExpressionStart(); - } - else if (')' == current) { - processSubExpressionEnd(); - } - - // process next - current = tape_.read(); - } - - return tape_.toString(); - } - - private void processCharClassStart() { - if (insideCharClass_) { - tape_.insert("\\", -1); - } - else { - insideCharClass_ = true; - - int next = tape_.read(); - if (next < 0) { - tape_.insert("\\", -1); - return; - } - if ('^' == next) { - // [^\2] - next = tape_.read(); - if (next < 0) { - tape_.insert("\\", -2); - return; - } - if ('\\' == next) { - next = tape_.read(); - if (DIGITS.indexOf(next) < 0) { - tape_.move(-2); - return; - } - // if it was a back reference then we have to check more - if (handleBackReferenceOrOctal(next)) { - next = tape_.read(); - if (']' == next) { - tape_.move(-3); - tape_.replace(3, "."); - insideCharClass_ = false; - } - } - } - else if (']' == next) { - // [^] - tape_.move(-3); - tape_.replace(3, "(?s:.)"); - insideCharClass_ = false; - } - else { - tape_.move(-1); - } - } - else if (']' == next) { - // [] - tape_.move(-2); - tape_.replace(2, "(?!)"); - insideCharClass_ = false; - } - else { - tape_.move(-1); - } - } - } - - private void processCharClassEnd() { - insideCharClass_ = false; - } - - private void processRepetitionStart() { - final int next = tape_.read(); - if (next < 0) { - tape_.insert("\\", -1); - return; - } - - if (DIGITS.indexOf(next) > -1) { - insideRepetition_ = true; - } - else { - tape_.insert("\\", -2); - tape_.move(-1); - } - } - - private void processRepetitionEnd() { - if (insideRepetition_) { - insideRepetition_ = false; - return; - } - - tape_.insert("\\", -1); - } - - private void processSubExpressionStart() { - int next = tape_.read(); - if (next < 0) { - return; - } - - if ('?' != next) { - final Subexpresion sub = new Subexpresion(); - sub.start_ = tape_.currentPos_; - parsingSubexpressions_.push(sub); - subexpressions_.add(sub); - - tape_.move(-1); - return; - } - - next = tape_.read(); - if (next < 0) { - return; - } - if (':' != next) { - final Subexpresion sub = new Subexpresion(); - sub.start_ = tape_.currentPos_; - parsingSubexpressions_.push(sub); - subexpressions_.add(sub); - - tape_.move(-1); - return; - } - - final Subexpresion sub = new Subexpresion(); - sub.start_ = tape_.currentPos_; - parsingSubexpressions_.push(sub); - } - - private void processSubExpressionEnd() { - if (parsingSubexpressions_.isEmpty()) { - return; - } - final Subexpresion sub = parsingSubexpressions_.pop(); - sub.closed_ = true; - sub.end_ = tape_.currentPos_; - - final int next = tape_.read(); - sub.optional_ = '?' == next; - tape_.move(-1); - } - - private void processEscapeSequence() { - final int escapeSequence = tape_.read(); - if (escapeSequence < 0) { - return; - } - - if ('x' == escapeSequence) { - // Hex code (e.g. \x00) - // Read the two char hex code - tape_.move(2); - return; - } - - if ('u' == escapeSequence) { - int next = tape_.read(); - if (next > -1) { - if (next == '{') { - final int uPos = tape_.currentPos_ - 2; - // Unicode point escapes - do { - next = tape_.read(); - } - while (next > -1 && next != '}'); - if (next == '}') { - tape_.tape_.replace(uPos, uPos + 1, "x"); - } - return; - } - - // Unicode (e.g. \u0009) - // we have nothing to convert here - } - - return; - } - - // Unicode property escape - if ('p' == escapeSequence) { - int next = tape_.read(); - if (next > -1) { - if (next == '{') { - final int uPos = tape_.currentPos_; - do { - next = tape_.read(); - } - while (next > -1 && next != '}'); - if (next == '}') { - return; - } - - // back to the old behavior - tape_.move(uPos - tape_.currentPos_ - 3); - tape_.remove(1); - } - } - - return; - } - - if ("ACEFGHIJKLMNOPQRTUVXYZaeghijklmpqyz".indexOf(escapeSequence) > -1) { - // no need to escape this chars - tape_.move(-2); - tape_.remove(1); - tape_.move(1); - return; - } - - if (insideCharClass_ && 'b' == escapeSequence) { - // [...\b...] -> [...\cH...] - tape_.move(-1); - tape_.replace(1, "cH"); - return; - } - - if (DIGITS.indexOf(escapeSequence) > -1) { - handleBackReferenceOrOctal(escapeSequence); - } - } - - private boolean handleBackReferenceOrOctal(final int aFirstChar) { - // first try to figure out what the number is - final StringBuilder tmpNo = new StringBuilder(Character.toString((char) aFirstChar)); - int tmpInsertPos = -1; - int next = tape_.read(); - if (next > -1) { - if (DIGITS.indexOf(next) > -1) { - tmpNo.append(next); - tmpInsertPos--; - next = tape_.read(); - if (next > -1) { - if (DIGITS.indexOf(next) > -1) { - tmpNo.append(next); - tmpInsertPos--; - } - else { - tape_.move(-1); - } - } - } - else { - tape_.move(-1); - if ('0' == aFirstChar) { - // \0 has to be replaced by \x00 - tape_.insert("x0", -1); - return false; - } - } - } - else { - // if \0 is last character of pattern - if ('0' == aFirstChar) { - // \0 has to be replaced by \x00 - tape_.insert("x0", -1); - return false; - } - } - - if (tmpNo.charAt(0) == '0') { - // we have a octal here - return false; - } - - final int value = Integer.parseInt(tmpNo.toString()); - if (value > subexpressions_.size()) { - // we have a octal here - tape_.insert("0", tmpInsertPos); - return false; - } - - // ignore invalid back references (inside char classes - // of if the referenced group is not (yet) available - if (insideCharClass_ - || (0 < value && !subexpressions_.get(value - 1).closed_)) { - // drop back reference - for (int i = tmpInsertPos; i <= 0; i++) { - tape_.move(-1); - tape_.remove(1); - } - } - - // ok it is a backreference - final Subexpresion back = subexpressions_.get(value - 1); - if (back.optional_ && !back.enhanced_) { - // change subexpression to make it java compatible - int insertPos = back.start_ - 1; - tape_.insertAt("(?:", insertPos); - for (final Subexpresion subexp : subexpressions_) { - if (subexp.start_ > insertPos) { - subexp.start_ = subexp.start_ + 3; - } - if (subexp.end_ > insertPos) { - subexp.end_ = subexp.end_ + 3; - } - } - - insertPos = back.end_ + 1; - tape_.insertAt(")", insertPos); - for (final Subexpresion subexp : subexpressions_) { - if (subexp.start_ > insertPos) { - subexp.start_ = subexp.start_ + 1; - } - if (subexp.end_ > insertPos) { - subexp.end_ = subexp.end_ + 1; - } - } - } - return true; - } -} diff --git a/src/main/java/org/htmlunit/platform/Platform.java b/src/main/java/org/htmlunit/platform/Platform.java index d3bb85a4298..7bd6b9e808b 100644 --- a/src/main/java/org/htmlunit/platform/Platform.java +++ b/src/main/java/org/htmlunit/platform/Platform.java @@ -123,7 +123,7 @@ public static Map> getAttributesOrderMap(final Document do * @param imageWidth the width of the image this backend is for * @param imageHeight the height of the image this backend is for * @return a new {@link RenderingBackend}. If the {@link AwtRenderingBackend} can't be used a - * {@link NoOpRenderingBackend} is used instead. + * {@link NoOpRenderingBackend} is used instead. */ public static RenderingBackend getRenderingBackend(final int imageWidth, final int imageHeight) { // for Android @@ -139,7 +139,7 @@ public static RenderingBackend getRenderingBackend(final int imageWidth, final i /** * @return a new {@link FontUtil}. If the {@link AwtFontUtil} can't be used a - * {@link NoOpFontUtil} is used instead. + * {@link NoOpFontUtil} is used instead. */ public static FontUtil getFontUtil() { // for Android @@ -158,6 +158,11 @@ public static FontUtil getFontUtil() { } } + /** + * @param inputStream the {@link InputStream} to read from + * @return a new {@link ImageData} object constructed from the given inputStream + * @throws IOException in case of error + */ public static ImageData buildImageData(final InputStream inputStream) throws IOException { try { final Class backendClass = Class.forName( diff --git a/src/main/java/org/htmlunit/platform/XmlUtilsHelperAPI.java b/src/main/java/org/htmlunit/platform/XmlUtilsHelperAPI.java index 9b7b87b2602..27aa017887f 100644 --- a/src/main/java/org/htmlunit/platform/XmlUtilsHelperAPI.java +++ b/src/main/java/org/htmlunit/platform/XmlUtilsHelperAPI.java @@ -37,7 +37,7 @@ public interface XmlUtilsHelperAPI { * is the array of ordered attributes names. * @param document the document * @return the map of an element index with its ordered attribute names or null if the - * provided document is not supported + * provided document is not supported */ Map> getAttributesOrderMap(Document document); diff --git a/src/main/java/org/htmlunit/platform/canvas/rendering/AwtRenderingBackend.java b/src/main/java/org/htmlunit/platform/canvas/rendering/AwtRenderingBackend.java index c2c93436740..66ec7ccb790 100644 --- a/src/main/java/org/htmlunit/platform/canvas/rendering/AwtRenderingBackend.java +++ b/src/main/java/org/htmlunit/platform/canvas/rendering/AwtRenderingBackend.java @@ -260,7 +260,7 @@ public AwtRenderingBackend(final int imageWidth, final int imageHeight) { strokeColor_ = Color.black; lineWidth_ = 1; transformation_ = new AffineTransform(); - setGlobalAlpha(1.0); + updateGlobalAlpha(1f); graphics2D_.setClip(null); final Font font = new Font("SansSerif", Font.PLAIN, 10); @@ -292,12 +292,16 @@ public void setGlobalAlpha(final double globalAlpha) { } if (globalAlpha >= 0 && globalAlpha <= 1) { - globalAlpha_ = (float) globalAlpha; - final AlphaComposite composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, globalAlpha_); - graphics2D_.setComposite(composite); + updateGlobalAlpha((float) globalAlpha); } } + private void updateGlobalAlpha(final float globalAlpha) { + globalAlpha_ = globalAlpha; + final AlphaComposite composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, globalAlpha_); + graphics2D_.setComposite(composite); + } + /** * {@inheritDoc} */ diff --git a/src/main/java/org/htmlunit/platform/canvas/rendering/RenderingBackend.java b/src/main/java/org/htmlunit/platform/canvas/rendering/RenderingBackend.java index eb120f76e47..613c6c04f72 100644 --- a/src/main/java/org/htmlunit/platform/canvas/rendering/RenderingBackend.java +++ b/src/main/java/org/htmlunit/platform/canvas/rendering/RenderingBackend.java @@ -26,6 +26,9 @@ */ public interface RenderingBackend { + /** + * WindingRule to be used while rendering. + */ enum WindingRule { /** WindingRule.NON_ZERO. */ NON_ZERO, @@ -179,13 +182,13 @@ void ellipse(double x, double y, * @param dx horizontal position (x coordinate) at which to place the image data in the destination canvas * @param dy vertical position (y coordinate) at which to place the image data in the destination canvas * @param dirtyX horizontal position (x coordinate) of the top-left corner - * from which the image data will be extracted. Defaults to 0. + * from which the image data will be extracted. Defaults to 0. * @param dirtyY vertical position (y coordinate) of the top-left corner - * from which the image data will be extracted. Defaults to 0. + * from which the image data will be extracted. Defaults to 0. * @param dirtyWidth width of the rectangle to be painted. - * Defaults to the width of the image data. + * Defaults to the width of the image data. * @param dirtyHeight height of the rectangle to be painted. - * Defaults to the height of the image data. + * Defaults to the height of the image data. */ void putImageData(byte[] imageDataBytes, int imageDataHeight, int imageDataWidth, int dx, int dy, int dirtyX, int dirtyY, int dirtyWidth, int dirtyHeight); @@ -306,7 +309,7 @@ void putImageData(byte[] imageDataBytes, int imageDataHeight, int imageDataWidth * Turns the current or given path into the current clipping region. * It replaces any previous clipping region. * @param windingRule the RenderingBackend.WindingRule {@link WindingRule} - * to be used + * to be used * @param path the path or null if the current path should be used */ void clip(RenderingBackend.WindingRule windingRule, Path2D path); @@ -319,7 +322,7 @@ void putImageData(byte[] imageDataBytes, int imageDataHeight, int imageDataWidth /** * @return the alpha (transparency) value that is applied to shapes and images - * before they are drawn onto the canvas. + * before they are drawn onto the canvas. */ double getGlobalAlpha(); diff --git a/src/main/java/org/htmlunit/platform/image/ImageData.java b/src/main/java/org/htmlunit/platform/image/ImageData.java index c67d9a05bb4..7474d7dd99d 100644 --- a/src/main/java/org/htmlunit/platform/image/ImageData.java +++ b/src/main/java/org/htmlunit/platform/image/ImageData.java @@ -27,5 +27,10 @@ */ public interface ImageData extends AutoCloseable { + /** + * INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
+ * @return the {@link IntDimension2D} of this + * @throws IOException in case of error + */ IntDimension2D getWidthHeight() throws IOException; } diff --git a/src/main/java/org/htmlunit/platform/image/ImageIOImageData.java b/src/main/java/org/htmlunit/platform/image/ImageIOImageData.java index 44834d152e1..75b282c013f 100644 --- a/src/main/java/org/htmlunit/platform/image/ImageIOImageData.java +++ b/src/main/java/org/htmlunit/platform/image/ImageIOImageData.java @@ -49,6 +49,11 @@ public class ImageIOImageData implements ImageData { private final ImageReader imageReader_; + /** + * Ctor. + * @param inputStream the {@link InputStream} to read from + * @throws IOException in case of error + */ public ImageIOImageData(final InputStream inputStream) throws IOException { final ImageInputStream iis = ImageIO.createImageInputStream(inputStream); final Iterator iter = ImageIO.getImageReaders(iis); diff --git a/src/main/java/org/htmlunit/protocol/data/DataUrlDecoder.java b/src/main/java/org/htmlunit/protocol/data/DataUrlDecoder.java index 1c1018ec96f..1aef11f2d95 100644 --- a/src/main/java/org/htmlunit/protocol/data/DataUrlDecoder.java +++ b/src/main/java/org/htmlunit/protocol/data/DataUrlDecoder.java @@ -22,8 +22,8 @@ import java.nio.charset.Charset; import java.nio.charset.IllegalCharsetNameException; import java.nio.charset.UnsupportedCharsetException; +import java.util.Base64; -import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.StringUtils; import org.htmlunit.util.MimeType; import org.htmlunit.util.UrlUtils; @@ -69,7 +69,7 @@ public static DataUrlDecoder decode(final URL url) throws UnsupportedEncodingExc * @param url the string representation of the URL to decode * @return the {@link DataUrlDecoder} holding decoded information * @throws UnsupportedEncodingException if the encoding specified by the data URL is invalid or not - * available on the JVM + * available on the JVM */ public static DataUrlDecoder decodeDataURL(final String url) throws UnsupportedEncodingException { if (!url.startsWith(DATA_PREFIX)) { @@ -90,10 +90,9 @@ public static DataUrlDecoder decodeDataURL(final String url) throws UnsupportedE try { byte[] data = url.substring(comma + 1).getBytes(charset); - data = UrlUtils.decodeDataUrl(data); + data = UrlUtils.decodeDataUrl(data, base64); if (base64) { - // the commons codec decoder skip's invalid chars - data = Base64.decodeBase64(data); + data = Base64.getDecoder().decode(data); } return new DataUrlDecoder(data, mediaType, charset); } diff --git a/src/main/java/org/htmlunit/svg/SvgScript.java b/src/main/java/org/htmlunit/svg/SvgScript.java index 73a0b4a6fa0..7a295a055af 100644 --- a/src/main/java/org/htmlunit/svg/SvgScript.java +++ b/src/main/java/org/htmlunit/svg/SvgScript.java @@ -69,7 +69,7 @@ public void setExecuted(final boolean executed) { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code src} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getSrcAttribute() { return getSrcAttributeNormalized(); @@ -87,7 +87,7 @@ public final String getScriptSource() { * Helper for src retrieval and normalization. * * @return the value of the attribute {@code src} with all line breaks removed - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ protected final String getSrcAttributeNormalized() { // at the moment StringUtils.replaceChars returns the org string @@ -107,7 +107,7 @@ protected final String getSrcAttributeNormalized() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code charset} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getCharsetAttribute() { return getAttributeDirect("charset"); @@ -127,7 +127,7 @@ public final String getScriptCharset() { * documentation for details on the use of this attribute. * * @return the value of the attribute {@code defer} - * or an empty string if that attribute isn't defined. + * or an empty string if that attribute isn't defined. */ public final String getDeferAttribute() { return getAttributeDirect("defer"); diff --git a/src/main/java/org/htmlunit/util/DebuggingWebConnection.java b/src/main/java/org/htmlunit/util/DebuggingWebConnection.java index 81299ccc55f..c84c70a49d8 100644 --- a/src/main/java/org/htmlunit/util/DebuggingWebConnection.java +++ b/src/main/java/org/htmlunit/util/DebuggingWebConnection.java @@ -80,7 +80,7 @@ public class DebuggingWebConnection extends WebConnectionWrapper { * Wraps a web connection to have a report generated of the received responses. * @param webConnection the webConnection that do the real work * @param dirName the name of the directory to create in the tmp folder to save received responses. - * If this folder already exists, it will be deleted first. + * If this folder already exists, it will be deleted first. * @throws IOException in case of problems writing the files */ public DebuggingWebConnection(final WebConnection webConnection, diff --git a/src/main/java/org/htmlunit/util/EncodingSniffer.java b/src/main/java/org/htmlunit/util/EncodingSniffer.java index 5121d98160e..2b8bb9e5293 100644 --- a/src/main/java/org/htmlunit/util/EncodingSniffer.java +++ b/src/main/java/org/htmlunit/util/EncodingSniffer.java @@ -19,7 +19,6 @@ import static java.nio.charset.StandardCharsets.UTF_16LE; import static java.nio.charset.StandardCharsets.UTF_8; -import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; @@ -115,77 +114,6 @@ private EncodingSniffer() { // Empty. } - /** - *

If the specified content is HTML content, this method sniffs encoding settings - * from the specified HTML content and/or the corresponding HTTP headers based on the - * HTML5 - * encoding sniffing algorithm.

- * - *

If the specified content is XML content, this method sniffs encoding settings - * from the specified XML content and/or the corresponding HTTP headers using a custom algorithm.

- * - *

Otherwise, this method sniffs encoding settings from the specified content of unknown type by looking for - * Content-Type information in the HTTP headers and - * Byte Order Mark information in the content.

- * - *

Note that if an encoding is found but it is not supported on the current platform, this method returns - * {@code null}, as if no encoding had been found.

- * - * @param headers the HTTP response headers sent back with the content to be sniffed - * @param content the content to be sniffed - * @return the encoding sniffed from the specified content and/or the corresponding HTTP headers, - * or {@code null} if the encoding could not be determined - * @throws IOException if an IO error occurs - * - * @deprecated as of version 4.0.0; depending on the content use {@link #sniffEncodingFromMetaTag(InputStream)}, - * {@link #sniffEncodingFromXmlDeclaration(InputStream)}, or {@link #sniffEncodingFromCssDeclaration(InputStream) } - * instead - */ - @Deprecated - public static Charset sniffEncoding(final List headers, final InputStream content) - throws IOException { - final Charset charset; - if (isHtml(headers)) { - charset = sniffHtmlEncoding(headers, content); - } - else if (isXml(headers)) { - charset = sniffXmlEncoding(headers, content); - } - else if (contentTypeEndsWith(headers, MimeType.TEXT_CSS)) { - charset = sniffCssEncoding(headers, content); - } - else { - charset = sniffUnknownContentTypeEncoding(headers, content); - } - return charset; - } - - /** - * Returns {@code true} if the specified HTTP response headers indicate an HTML response. - * - * @param headers the HTTP response headers - * @return {@code true} if the specified HTTP response headers indicate an HTML response - * - * @deprecated as of version 4.0.0; method will be removed without replacement - */ - @Deprecated - static boolean isHtml(final List headers) { - return contentTypeEndsWith(headers, MimeType.TEXT_HTML); - } - - /** - * Returns {@code true} if the specified HTTP response headers indicate an XML response. - * - * @param headers the HTTP response headers - * @return {@code true} if the specified HTTP response headers indicate an XML response - * - * @deprecated as of version 4.0.0; method will be removed without replacement - */ - @Deprecated - static boolean isXml(final List headers) { - return contentTypeEndsWith(headers, MimeType.TEXT_XML, MimeType.APPLICATION_XML, "text/vnd.wap.wml", "+xml"); - } - /** * Returns {@code true} if the specified HTTP response headers contain a Content-Type that * ends with one of the specified strings. @@ -216,167 +144,6 @@ static boolean contentTypeEndsWith(final List headers, final Stri return false; } - /** - *

Sniffs encoding settings from the specified HTML content and/or the corresponding HTTP headers based on the - * HTML5 - * encoding sniffing algorithm.

- * - *

Note that if an encoding is found but it is not supported on the current platform, this method returns - * {@code null}, as if no encoding had been found.

- * - * @param headers the HTTP response headers sent back with the HTML content to be sniffed - * @param content the HTML content to be sniffed - * @return the encoding sniffed from the specified HTML content and/or the corresponding HTTP headers, - * or {@code null} if the encoding could not be determined - * @throws IOException if an IO error occurs - * - * @deprecated as of version 4.0.0; depending on the content use {@link #sniffEncodingFromMetaTag(InputStream)}, - * {@link #sniffEncodingFromXmlDeclaration(InputStream)}, or {@link #sniffEncodingFromCssDeclaration(InputStream) } - * instead - */ - @Deprecated - public static Charset sniffHtmlEncoding(final List headers, final InputStream content) - throws IOException { - - byte[] bytes = read(content, 3); - Charset encoding = sniffEncodingFromUnicodeBom(bytes); - if (encoding != null) { - return encoding; - } - - encoding = sniffEncodingFromHttpHeaders(headers); - if (encoding != null || content == null) { - return encoding; - } - - bytes = readAndPrepend(content, SIZE_OF_HTML_CONTENT_SNIFFED, bytes); - encoding = sniffEncodingFromMetaTag(bytes); - return encoding; - } - - /** - *

Sniffs encoding settings from the specified XML content and/or the corresponding HTTP headers using - * a custom algorithm.

- * - *

Note that if an encoding is found but it is not supported on the current platform, this method returns - * {@code null}, as if no encoding had been found.

- * - * @param headers the HTTP response headers sent back with the XML content to be sniffed - * @param content the XML content to be sniffed - * @return the encoding sniffed from the specified XML content and/or the corresponding HTTP headers, - * or {@code null} if the encoding could not be determined - * @throws IOException if an IO error occurs - * - * @deprecated as of version 4.0.0; depending on the content use {@link #sniffEncodingFromMetaTag(InputStream)}, - * {@link #sniffEncodingFromXmlDeclaration(InputStream)}, or {@link #sniffEncodingFromCssDeclaration(InputStream) } - * instead - */ - @Deprecated - public static Charset sniffXmlEncoding(final List headers, final InputStream content) - throws IOException { - - byte[] bytes = read(content, 3); - Charset encoding = sniffEncodingFromUnicodeBom(bytes); - if (encoding != null) { - return encoding; - } - - encoding = sniffEncodingFromHttpHeaders(headers); - if (encoding != null || content == null) { - return encoding; - } - - bytes = readAndPrepend(content, SIZE_OF_XML_CONTENT_SNIFFED, bytes); - encoding = sniffEncodingFromXmlDeclaration(bytes); - return encoding; - } - - /** - * @deprecated as of version 4.0.0; depending on the content use {@link #sniffEncodingFromMetaTag(InputStream)}, - * {@link #sniffEncodingFromXmlDeclaration(InputStream)}, or {@link #sniffEncodingFromCssDeclaration(InputStream) } - * instead - */ - @Deprecated - private static Charset sniffCssEncoding(final List headers, final InputStream content) - throws IOException { - - byte[] bytes = read(content, 3); - Charset encoding = sniffEncodingFromUnicodeBom(bytes); - if (encoding != null) { - return encoding; - } - - encoding = sniffEncodingFromHttpHeaders(headers); - if (encoding != null || content == null) { - return encoding; - } - - bytes = readAndPrepend(content, SIZE_OF_CSS_CONTENT_SNIFFED, bytes); - encoding = sniffEncodingFromCssDeclaration(bytes); - return encoding; - } - - /** - *

Sniffs encoding settings from the specified content of unknown type by looking for Content-Type - * information in the HTTP headers and Byte Order Mark - * information in the content.

- * - *

Note that if an encoding is found but it is not supported on the current platform, this method returns - * {@code null}, as if no encoding had been found.

- * - * @param headers the HTTP response headers sent back with the content to be sniffed - * @param content the content to be sniffed - * @return the encoding sniffed from the specified content and/or the corresponding HTTP headers, - * or {@code null} if the encoding could not be determined - * @throws IOException if an IO error occurs - * - * @deprecated as of version 4.0.0; depending on the content use {@link #sniffEncodingFromMetaTag(InputStream)}, - * {@link #sniffEncodingFromXmlDeclaration(InputStream)}, or {@link #sniffEncodingFromCssDeclaration(InputStream) } - * instead - */ - @Deprecated - public static Charset sniffUnknownContentTypeEncoding(final List headers, final InputStream content) - throws IOException { - - final byte[] bytes = read(content, 3); - Charset encoding = sniffEncodingFromUnicodeBom(bytes); - if (encoding != null) { - return encoding; - } - - encoding = sniffEncodingFromHttpHeaders(headers); - if (encoding != null || content == null) { - return encoding; - } - return encoding; - } - - /** - * Attempts to sniff an encoding from the specified HTTP headers. - * - * @param headers the HTTP headers to examine - * @return the encoding sniffed from the specified HTTP headers, or {@code null} if the encoding - * could not be determined - * - * @deprecated as of version 4.0.0; method will be removed without replacement - */ - @Deprecated - public static Charset sniffEncodingFromHttpHeaders(final List headers) { - for (final NameValuePair pair : headers) { - final String name = pair.getName(); - if (HttpHeader.CONTENT_TYPE_LC.equalsIgnoreCase(name)) { - final Charset encoding = extractEncodingFromContentType(pair.getValue()); - if (encoding != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("Encoding found in HTTP headers: '" + encoding + "'."); - } - return encoding; - } - } - } - return null; - } - /** * Attempts to sniff an encoding from a Byte Order Mark * in the specified byte array. @@ -419,20 +186,6 @@ private static boolean startsWith(final byte[] bytes, final ByteOrderMark bom) { return Arrays.equals(firstBytes, bomBytes); } - /** - * Attempts to sniff an encoding from an HTML meta tag in the specified byte array. - * - * @param bytes the bytes to check for an HTML meta tag - * @return the encoding sniffed from the specified bytes, or {@code null} if the encoding - * could not be determined - * - * @deprecated as of version 4.0.0; method will be removed without replacement - */ - @Deprecated - static Charset sniffEncodingFromMetaTag(final byte[] bytes)throws IOException { - return sniffEncodingFromMetaTag(new ByteArrayInputStream(bytes)); - } - /** * Attempts to sniff an encoding from an HTML meta tag in the specified byte array. * @@ -698,20 +451,6 @@ public static Charset extractEncodingFromContentType(final String s) { return toCharset(charsetName); } - /** - * Searches the specified XML content for an XML declaration and returns the encoding if found, - * otherwise returns {@code null}. - * - * @param bytes the XML content to sniff - * @return the encoding of the specified XML content, or {@code null} if it could not be determined - * - * @deprecated as of version 4.0.0; use {@link #sniffEncodingFromXmlDeclaration(InputStream)} instead - */ - @Deprecated - static Charset sniffEncodingFromXmlDeclaration(final byte[] bytes) throws IOException { - return sniffEncodingFromXmlDeclaration(new ByteArrayInputStream(bytes)); - } - /** * Searches the specified XML content for an XML declaration and returns the encoding if found, * otherwise returns {@code null}. @@ -761,22 +500,6 @@ public static Charset sniffEncodingFromXmlDeclaration(final InputStream is) thro return encoding; } - /** - * Parses and returns the charset declaration at the start of a css file if any, otherwise returns {@code null}. - * @param bytes the input bytes to sniff the encoding from - * @return the charset declaration at the start of a css file if any, otherwise returns {@code null}. - * - *

e.g.

@charset "UTF-8"
- * - * @deprecated as of version 4.0.0; depending on the content use {@link #sniffEncodingFromMetaTag(InputStream)}, - * {@link #sniffEncodingFromXmlDeclaration(InputStream)}, or {@link #sniffEncodingFromCssDeclaration(InputStream) } - * instead - */ - @Deprecated - static Charset sniffEncodingFromCssDeclaration(final byte[] bytes) throws IOException { - return sniffEncodingFromXmlDeclaration(new ByteArrayInputStream(bytes)); - } - /** * Parses and returns the charset declaration at the start of a css file if any, otherwise returns {@code null}. *

e.g.

@charset "UTF-8"
@@ -982,19 +705,6 @@ int getUpdatedIndex() { } } - /** - * Translates the given encoding label into a normalized form - * according to Reference. - * @param encodingLabel the label to translate - * @return the normalized encoding name or null if not found - * - * @deprecated as of version 4.0.0; method will be removed without replacement - */ - @Deprecated - public static String translateEncodingLabel(final Charset encodingLabel) { - return translateEncodingLabel(encodingLabel.name()); - } - /** * Translates the given encoding label into a normalized form * according to Reference. diff --git a/src/main/java/org/htmlunit/util/KeyDataPair.java b/src/main/java/org/htmlunit/util/KeyDataPair.java index 124ba2ad21d..88d7a2e6d68 100644 --- a/src/main/java/org/htmlunit/util/KeyDataPair.java +++ b/src/main/java/org/htmlunit/util/KeyDataPair.java @@ -80,9 +80,9 @@ public KeyDataPair(final String key, final File file, final String fileName, * @param name will passed as name to the super constructor * @param value will be passed as value to the super constructor * @param file the file, may be null - * @param fileName, the filename, may be null - * @param mimeType, the mimetype, may be null - * @param charset, the charset, may be null + * @param fileName the filename, may be null + * @param mimeType the mimetype, may be null + * @param charset the charset, may be null */ private KeyDataPair(final String name, final String value, final File file, final String fileName, final String mimeType, final Charset charset, diff --git a/src/main/java/org/htmlunit/util/OrderedFastHashMap.java b/src/main/java/org/htmlunit/util/OrderedFastHashMap.java index ba8c42d6805..18dfdc7f0a5 100644 --- a/src/main/java/org/htmlunit/util/OrderedFastHashMap.java +++ b/src/main/java/org/htmlunit/util/OrderedFastHashMap.java @@ -544,26 +544,54 @@ public V put(final K key, final V value) { return this.put(key, value, Position.LAST); } + /** + * Insert at the beginning. + * @param key the key + * @param value the value + * @return the inserted value + */ public V addFirst(final K key, final V value) { return this.put(key, value, Position.FIRST); } + /** + * Append at the end. + * @param key the key + * @param value the value + * @return the appended value + */ public V add(final K key, final V value) { return this.put(key, value, Position.LAST); } + /** + * Append at the end. + * @param key the key + * @param value the value + * @return the appended value + */ public V addLast(final K key, final V value) { return this.put(key, value, Position.LAST); } + /** + * @return the first value. + */ public V getFirst() { return getValue(0); } + /** + * @return the last value. + */ public V getLast() { return getValue(this.orderedListSize_ - 1); } + /** + * Removes the first entry. + * @return the removed value or null if the map was empty. + */ public V removeFirst() { if (this.orderedListSize_ > 0) { final int pos = this.orderedList_[0]; @@ -573,6 +601,10 @@ public V removeFirst() { return null; } + /** + * Removes the last entry. + * @return the removed value or null if the map was empty. + */ public V removeLast() { if (this.orderedListSize_ > 0) { final int pos = this.orderedList_[this.orderedListSize_ - 1]; diff --git a/src/main/java/org/htmlunit/util/UrlUtils.java b/src/main/java/org/htmlunit/util/UrlUtils.java index 226ec5c5faa..ae2b4f6ab15 100644 --- a/src/main/java/org/htmlunit/util/UrlUtils.java +++ b/src/main/java/org/htmlunit/util/UrlUtils.java @@ -374,7 +374,7 @@ private static String encode(final String unescaped, final BitSet allowed, final * string that is not followed by two hexadecimal characters. * @param input the input bytes * @return the given input string where every occurrence of % in - * invalid escape sequences has been replace by %25 + * invalid escape sequences has been replace by %25 */ private static String encodePercentSign(final byte[] input) { if (input == null) { @@ -952,9 +952,8 @@ public static boolean isValidScheme(final String scheme) { /** * Returns true if specified string is a special scheme. - *

- * https://url.spec.whatwg.org/#special-scheme - *

+ * see + * https://url.spec.whatwg.org/#special-scheme * * @param scheme the scheme string to check * @return true if special @@ -1379,32 +1378,66 @@ public static URL removeRedundantPort(final URL url) throws MalformedURLExceptio return url; } - // adapted from apache commons codec + /** + * Decodes an array of URL safe 7-bit characters into an array of original bytes. + * Escaped characters are converted back to their original representation. + * @param bytes array of URL safe characters + * @return array of original bytes + * @throws IllegalArgumentException in case of error + * + * @deprecated as of version 4.11.0; use {@link #decodeDataUrl(byte[], boolean)} instead + */ + @Deprecated public static byte[] decodeDataUrl(final byte[] bytes) throws IllegalArgumentException { + return decodeDataUrl(bytes, false); + } + + /** + * Decodes an array of URL safe 7-bit characters into an array of original bytes. + * Escaped characters are converted back to their original representation. + * @param bytes array of URL safe characters + * @param removeWhitespace if true don't add whitespace chars to the output + * @return array of original bytes + * @throws IllegalArgumentException in case of error + */ + public static byte[] decodeDataUrl(final byte[] bytes, final boolean removeWhitespace) + throws IllegalArgumentException { + // adapted from apache commons codec if (bytes == null) { return null; } final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); for (int i = 0; i < bytes.length; i++) { - final int b = bytes[i]; + int b = bytes[i]; if (b == '%') { try { final int u = digit16(bytes[++i]); final int l = digit16(bytes[++i]); - buffer.write((char) ((u << 4) + l)); + b = (u << 4) + l; } catch (final ArrayIndexOutOfBoundsException e) { throw new IllegalArgumentException("Invalid URL encoding: ", e); } } - else { - buffer.write(b); + if (removeWhitespace + && (b == 9 || b == 10 || b == 12 || b == 13 || b == 32)) { + continue; } + + buffer.write(b); } return buffer.toByteArray(); } + /** + * Decodes an array of URL safe 7-bit characters into an array of original bytes. + * Escaped characters are converted back to their original representation. + * @param bytes array of URL safe characters + * @return array of original bytes + * @throws IllegalArgumentException in case of error + */ public static byte[] decodeUrl(final byte[] bytes) throws IllegalArgumentException { + // adapted from apache commons codec if (bytes == null) { return null; } @@ -1439,8 +1472,14 @@ private static int digit16(final byte b) throws IllegalArgumentException { return i; } - // adapted from apache commons codec + /** + * Encodes an array of bytes into an array of URL safe 7-bit characters. Unsafe characters are escaped. + * @param urlsafe bitset of characters deemed URL safe + * @param bytes array of bytes to convert to URL safe characters + * @return array of bytes containing URL safe characters + */ public static byte[] encodeUrl(final BitSet urlsafe, final byte[] bytes) { + // adapted from apache commons codec if (bytes == null) { return null; } diff --git a/src/main/java/org/htmlunit/util/WebResponseWrapper.java b/src/main/java/org/htmlunit/util/WebResponseWrapper.java index 58ed2bdeb05..1bdad6f07b6 100644 --- a/src/main/java/org/htmlunit/util/WebResponseWrapper.java +++ b/src/main/java/org/htmlunit/util/WebResponseWrapper.java @@ -105,18 +105,6 @@ public Charset getHeaderContentCharset() { return wrappedWebResponse_.getHeaderContentCharset(); } - /** - * {@inheritDoc} - * The default behavior of this method is to return getContentCharsetOrNull() on the wrapped webResponse object. - * - * @deprecated as of version 4.0.0; use {@link #getContentCharset()} instead - */ - @Override - @Deprecated - public Charset getContentCharsetOrNull() { - return wrappedWebResponse_.getContentCharsetOrNull(); - } - /** * {@inheritDoc} * The default behavior of this method is to return getContentCharset() on the wrapped webResponse object. @@ -198,17 +186,6 @@ public void cleanUp() { wrappedWebResponse_.cleanUp(); } - /** - * {@inheritDoc} - * The default behavior of this method is to call defaultCharsetUtf8() on the wrapped webResponse object. - * @deprecated as of version 4.0.0; use {@link WebRequest#setDefaultResponseContentCharset(Charset)} instead - */ - @Deprecated - @Override - public void defaultCharsetUtf8() { - wrappedWebResponse_.defaultCharsetUtf8(); - } - @Override public InputStream getContentAsStreamWithBomIfApplicable() throws IOException { return wrappedWebResponse_.getContentAsStreamWithBomIfApplicable(); diff --git a/src/main/java/org/htmlunit/util/geometry/Point2D.java b/src/main/java/org/htmlunit/util/geometry/Point2D.java index e0f65728a9c..d6497d0febb 100644 --- a/src/main/java/org/htmlunit/util/geometry/Point2D.java +++ b/src/main/java/org/htmlunit/util/geometry/Point2D.java @@ -23,15 +23,26 @@ public class Point2D { private final double myX_; private final double myY_; + /** + * Ctor. + * @param x x value + * @param y y value + */ public Point2D(final double x, final double y) { myX_ = x; myY_ = y; } + /** + * @return the x value + */ public double getX() { return myX_; } + /** + * @return the y value + */ public double getY() { return myY_; } diff --git a/src/main/java/org/htmlunit/util/geometry/Rectangle2D.java b/src/main/java/org/htmlunit/util/geometry/Rectangle2D.java index ebb3e82211b..d88e4383b11 100644 --- a/src/main/java/org/htmlunit/util/geometry/Rectangle2D.java +++ b/src/main/java/org/htmlunit/util/geometry/Rectangle2D.java @@ -77,6 +77,13 @@ public boolean contains(final double x, final double y) { && y >= bottom_; } + /** + * Makes sure the provided point is part of the extended {@link Rectangle2D} by + * moving the right or left border to include y and moving the top or bottom border + * to include y. + * @param x the x position to include + * @param y the y position to include + */ public void extend(final double x, final double y) { if (x > right_) { right_ = x; diff --git a/src/main/java/org/htmlunit/websocket/JettyWebSocketAdapter.java b/src/main/java/org/htmlunit/websocket/JettyWebSocketAdapter.java index aededd40da1..36d2f90bec2 100644 --- a/src/main/java/org/htmlunit/websocket/JettyWebSocketAdapter.java +++ b/src/main/java/org/htmlunit/websocket/JettyWebSocketAdapter.java @@ -38,6 +38,10 @@ public abstract class JettyWebSocketAdapter implements WebSocketAdapter { private volatile Session incomingSession_; private Session outgoingSession_; + /** + * Ctor. + * @param webClient the {@link WebClient} + */ public JettyWebSocketAdapter(final WebClient webClient) { super(); final WebClientOptions options = webClient.getOptions(); diff --git a/src/site/resources/images/logos/bsky.png b/src/site/resources/images/logos/bsky.png new file mode 100644 index 00000000000..faf72f9e096 Binary files /dev/null and b/src/site/resources/images/logos/bsky.png differ diff --git a/src/site/resources/images/logos/mastodon.png b/src/site/resources/images/logos/mastodon.png index d2a59097650..a51c090aa27 100644 Binary files a/src/site/resources/images/logos/mastodon.png and b/src/site/resources/images/logos/mastodon.png differ diff --git a/src/site/resources/images/logos/twitter.png b/src/site/resources/images/logos/twitter.png index 87822dae99f..c29b02fd9b6 100644 Binary files a/src/site/resources/images/logos/twitter.png and b/src/site/resources/images/logos/twitter.png differ diff --git a/src/site/xdoc/index.xml b/src/site/xdoc/index.xml index 3076ff84fdf..0ff026ceb5a 100644 --- a/src/site/xdoc/index.xml +++ b/src/site/xdoc/index.xml @@ -26,12 +26,10 @@ HtmlUnit is a "GUI-Less browser for Java programs". It models HTML documents and provides an API that allows you to invoke pages, fill out forms, click links, etc... just like you do in your "normal" browser. -

-

+
It has fairly good JavaScript support (which is constantly improving) and is able to work even with quite complex AJAX libraries, simulating Chrome, Firefox or Edge depending on the configuration used. -

-

+
It is typically used for testing purposes or to retrieve information from websites.

@@ -43,31 +41,43 @@

HtmlUnit is used as the underlying "browser" by different Open Source tools like - WebDriver, - Arquillian Drone, - Serenity BDD, - FluentLenium, - WETATOR, - Selenium Foundation, - Spring Testing - JWebUnit, - JSFUnit, ... +

HtmlUnit is used by many projects for automated web testing - jenkins-test-harness, - Apache Shiro, - Apache Struts, - Quarkus, - Togglz, - Dataverse, - Janssen Project, - Apache TomEE, - Apache Maven Surefire, - JSCover, - Apache Jackrabbit, - OpenXava - Cargo, ... +

HtmlUnit was originally written by @@ -75,17 +85,16 @@ Gargoyle Software and is released under the Apache 2 license. Since then, it has received many contributions from - other developers, and would not be where it is today without their - assistance. + other developers, and would not be where it is today without their assistance.

-
Latest release February 22, 2025
+
Latest release March 25, 2025
-

version 4.10.0

+

version 4.11.0

Source code
@@ -96,8 +105,9 @@
News

- Twitter - Twitter + Mastodon + Bluesky + Twitter

@@ -210,10 +220,16 @@ org.htmlunit htmlunit - 4.10.0 + 4.11.0 ]]>

+

+ For gradle, you would add: + +

+

If you like to use the latest available snapshot build you have to add the sonatype snapshot repository to your pom repositories section; also (check diff --git a/src/test/java/org/htmlunit/BrowserVersion2Test.java b/src/test/java/org/htmlunit/BrowserVersion2Test.java index 605de1a522a..f391575f695 100644 --- a/src/test/java/org/htmlunit/BrowserVersion2Test.java +++ b/src/test/java/org/htmlunit/BrowserVersion2Test.java @@ -18,7 +18,6 @@ import java.util.Map; import java.util.Map.Entry; -import org.htmlunit.html.HtmlPageTest; import org.htmlunit.junit.BrowserRunner; import org.htmlunit.junit.annotation.Alerts; import org.htmlunit.util.MimeType; @@ -47,7 +46,7 @@ public class BrowserVersion2Test extends WebDriverTestCase { FF = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", FF_ESR = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") public void acceptHeaderGetUrl() throws Exception { - final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + final String html = DOCTYPE_HTML + "Response"; loadPage2(html); @@ -64,11 +63,11 @@ public void acceptHeaderGetUrl() throws Exception { FF = {"2", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"}, FF_ESR = {"2", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"}) public void acceptHeaderWindowOpen() throws Exception { - String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + String html = DOCTYPE_HTML + "Response"; getMockWebConnection().setDefaultResponse(html); - html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + html = DOCTYPE_HTML + "First\n" + "\n" + " Click me\n" @@ -76,7 +75,7 @@ public void acceptHeaderWindowOpen() throws Exception { final WebDriver driver = loadPage2(html); driver.findElement(By.id("clickme")).click(); // because real browsers are doing the open async, we have to be a bit patient - Thread.sleep(DEFAULT_WAIT_TIME); + Thread.sleep(DEFAULT_WAIT_TIME.toMillis()); assertEquals(getExpectedAlerts()[0], Integer.toString(getMockWebConnection().getRequestCount())); assertEquals(getExpectedAlerts()[1], acceptHeaderString()); @@ -92,11 +91,11 @@ public void acceptHeaderWindowOpen() throws Exception { FF = {"2", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"}, FF_ESR = {"2", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"}) public void acceptHeaderAnchorClick() throws Exception { - String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + String html = DOCTYPE_HTML + "Response"; getMockWebConnection().setDefaultResponse(html); - html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + html = DOCTYPE_HTML + "First\n" + "\n" + " Click me\n" @@ -118,11 +117,11 @@ public void acceptHeaderAnchorClick() throws Exception { FF = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", FF_ESR = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") public void acceptHeaderAnchorClickWithType() throws Exception { - String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + String html = DOCTYPE_HTML + "Response"; getMockWebConnection().setDefaultResponse(html); - html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + html = DOCTYPE_HTML + "First\n" + "\n" + " Click me\n" @@ -145,8 +144,7 @@ public void acceptHeaderAnchorClickWithType() throws Exception { FF = "Accept: image/avif,image/webp,image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5", FF_ESR = "Accept: image/avif,image/webp,image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5") public void acceptHeaderImage() throws Exception { - final String html - = HtmlPageTest.STANDARDS_MODE_PREFIX_ + final String html = DOCTYPE_HTML + "\n" + "\n" + "\n" @@ -216,8 +212,7 @@ public void acceptHeaderJavascript() throws Exception { @Test @Alerts("Accept: */*") public void acceptHeaderJavascriptWithoutType() throws Exception { - final String html - = HtmlPageTest.STANDARDS_MODE_PREFIX_ + final String html = DOCTYPE_HTML + "\n" + " \n" + "\n" @@ -236,8 +231,7 @@ public void acceptHeaderJavascriptWithoutType() throws Exception { @Test @Alerts("Accept: text/css,*/*;q=0.1") public void acceptHeaderCssWithoutType() throws Exception { - final String html - = HtmlPageTest.STANDARDS_MODE_PREFIX_ + final String html = DOCTYPE_HTML + "\n" + " \n" + "\n" + "\n" + "\n" + "to page 2\n" + ""; - final String content2 = "page 2\n" + final String content2 = DOCTYPE_HTML + + "page 2\n" + "\n" + "\n" + "to page 1\n" @@ -235,11 +264,12 @@ public void usage() throws Exception { } /** - *@throws Exception if the test fails + * @throws Exception if the test fails */ @Test public void jsUrlEncoded() throws Exception { - final String content = "\n" + final String content = DOCTYPE_HTML + + "\n" + "\n" + " page 1\n" + " \n" @@ -250,7 +280,8 @@ public void jsUrlEncoded() throws Exception { + "\n" + ""; - final String content2 = "\n" + final String content2 = DOCTYPE_HTML + + "\n" + "\n" + " page 2\n" + " \n" @@ -292,11 +323,12 @@ public void jsUrlEncoded() throws Exception { } /** - *@throws Exception if the test fails + * @throws Exception if the test fails */ @Test public void cssUrlEncoded() throws Exception { - final String content = "\n" + final String content = DOCTYPE_HTML + + "\n" + "\n" + " page 1\n" + " \n" @@ -315,7 +347,8 @@ public void cssUrlEncoded() throws Exception { + "\n" + ""; - final String content2 = "\n" + final String content2 = DOCTYPE_HTML + + "\n" + "\n" + " page 2\n" + " \n" @@ -362,11 +395,12 @@ public void cssUrlEncoded() throws Exception { } /** - *@throws Exception if the test fails + * @throws Exception if the test fails */ @Test public void maxSizeMaintained() throws Exception { - final String html = "page 1\n" + final String html = DOCTYPE_HTML + + "page 1\n" + "\n" + "\n" + ""; @@ -581,7 +587,8 @@ public void domainDuplicateLeadingDot() throws Exception { */ @Test public void domainDuplicateLeadingDotSend() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "next page\n" + ""; @@ -608,7 +615,8 @@ public void domainDuplicateLeadingDotSend() throws Exception { */ @Test public void domainDuplicateLeadingDotRedirect() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "next page\n" + ""; @@ -647,7 +655,8 @@ public void domain2() throws Exception { responseHeader1.add(new NameValuePair("Set-Cookie", "c4=4; Domain=" + DOMAIN + "; Path=/")); responseHeader1.add(new NameValuePair("Set-Cookie", "c5=5; Domain=.org; Path=/")); - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + "

Cookie Domain Test

\n" @@ -678,7 +687,8 @@ public void domain3() throws Exception { responseHeader1.add(new NameValuePair("Set-Cookie", "c4=4; Domain=" + DOMAIN + "; Path=/")); responseHeader1.add(new NameValuePair("Set-Cookie", "c5=5; Domain=.org; Path=/")); - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + "

Cookie Domain Test

\n" @@ -705,7 +715,8 @@ public void differentHostsSameDomain() throws Exception { final List responseHeader1 = new ArrayList<>(); responseHeader1.add(new NameValuePair("Set-Cookie", "cross-domain=1; Domain=." + DOMAIN + "; Path=/")); - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + "

Cookie Domain Test

\n" @@ -729,7 +740,8 @@ public void differentHostsSameDomain() throws Exception { @Test @Alerts("cross-domain=1") public void differentHostsSameDomainCookieFromJS() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + "\n" @@ -755,7 +767,8 @@ public void differentHostsSameDomainCookieFromJS() throws Exception { @Test @Alerts("cross-domain=1") public void differentHostsSameDomainCookieFromMeta() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + " \n" + "\n" @@ -947,7 +960,7 @@ public void sameSiteIncludeFromSameDomain() throws Exception { responseHeader.add(new NameValuePair("Set-Cookie", "c4=empty; SameSite=")); responseHeader.add(new NameValuePair("Set-Cookie", "c5=unknown; SameSite=unknown")); - final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + final String html = DOCTYPE_HTML + "\n" + " \n" + "\n" @@ -1002,7 +1015,7 @@ public void sameSiteIncludeFromSubDomain() throws Exception { responseHeader.add(new NameValuePair("Set-Cookie", "c4=empty; SameSite=")); responseHeader.add(new NameValuePair("Set-Cookie", "c5=unknown; SameSite=unknown")); - final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + final String html = DOCTYPE_HTML + "\n" + " \n" + "\n" @@ -1057,7 +1070,7 @@ public void sameSiteIFrameFromSameDomain() throws Exception { responseHeader.add(new NameValuePair("Set-Cookie", "c4=empty; SameSite=")); responseHeader.add(new NameValuePair("Set-Cookie", "c5=unknown; SameSite=unknown")); - final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + final String html = DOCTYPE_HTML + "\n" + "\n" + "\n" @@ -1112,7 +1125,7 @@ public void sameSiteIFrameFromSubDomain() throws Exception { responseHeader.add(new NameValuePair("Set-Cookie", "c4=empty; SameSite=")); responseHeader.add(new NameValuePair("Set-Cookie", "c5=unknown; SameSite=unknown")); - final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + final String html = DOCTYPE_HTML + "\n" + "\n" + "\n" @@ -1162,7 +1175,8 @@ public void issue270() throws Exception { final List responseHeader1 = new ArrayList<>(); responseHeader1.add(new NameValuePair("Set-Cookie", "first=1; path=/c")); - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" @@ -303,7 +302,7 @@ public void setCookieExpired() throws Exception { @Test @Alerts({"cookies: first=1", "cookies: "}) public void setCookieTimeout() throws Exception { - final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + final String html = DOCTYPE_HTML + "\n" + ""; + String html = DOCTYPE_HTML + + ""; html = "HTTP/1.1 200 OK\r\n" + "Content-Length: " + (html.length()) + "\r\n" + "Content-Type: text/html\r\n" @@ -1142,7 +1146,8 @@ public void locationSetHref() throws Exception { "Sec-Fetch-User: ?1", "Priority: u=0, i"}) public void locationSetSearch() throws Exception { - String html = ""; + String html = DOCTYPE_HTML + + ""; html = "HTTP/1.1 200 OK\r\n" + "Content-Length: " + (html.length()) + "\r\n" + "Content-Type: text/html\r\n" @@ -1293,7 +1298,8 @@ public void locationSetSearch() throws Exception { "Sec-Fetch-User: ?1", /* wrong */ "Priority: u=0, i"}) public void loadJavascript() throws Exception { - String html = " "; + String html = DOCTYPE_HTML + + " "; html = "HTTP/1.1 200 OK\r\n" + "Content-Length: " + (html.length()) + "\r\n" + "Content-Type: text/html\r\n" @@ -1448,7 +1454,8 @@ public void loadJavascript() throws Exception { // PrimitiveWebServer @NotYetImplemented(value = {}, os = OS.Linux) public void loadJavascriptCharset() throws Exception { - String html = "" + String html = DOCTYPE_HTML + + "" + "" + "" + ""; diff --git a/src/test/java/org/htmlunit/HttpWebConnectionTest.java b/src/test/java/org/htmlunit/HttpWebConnectionTest.java index 804d72e53b5..21aec5c549f 100644 --- a/src/test/java/org/htmlunit/HttpWebConnectionTest.java +++ b/src/test/java/org/htmlunit/HttpWebConnectionTest.java @@ -292,7 +292,8 @@ public void emptyPut() throws Exception { public static class EmptyPutServlet extends ServletContentWrapper { /** Constructor. */ public EmptyPutServlet() { - super("\n" + super(DOCTYPE_HTML + + "\n" + "\n" + " \n" + "\n" + "\n" diff --git a/src/test/java/org/htmlunit/MiniServer.java b/src/test/java/org/htmlunit/MiniServer.java index 6e22eaf30b7..5f6e25c1bd5 100644 --- a/src/test/java/org/htmlunit/MiniServer.java +++ b/src/test/java/org/htmlunit/MiniServer.java @@ -58,19 +58,35 @@ public class MiniServer extends Thread implements Closeable { private static final Set DROP_REQUESTS = new HashSet<>(); private static final Set DROP_GET_REQUESTS = new HashSet<>(); + /** + * Resets the drop and drop-get request counters. + */ public static void resetDropRequests() { DROP_REQUESTS.clear(); DROP_GET_REQUESTS.clear(); } + /** + * Add the given url to the list of drop requests. + * @param url to url to add + */ public static void configureDropRequest(final URL url) { DROP_REQUESTS.add(url); } + /** + * Add the given url to the list of drop-get requests. + * @param url to url to add + */ public static void configureDropGetRequest(final URL url) { DROP_GET_REQUESTS.add(url); } + /** + * Ctor. + * @param port the port to listen on + * @param mockWebConnection the {@link MockWebConnection} to get the responses from + */ public MiniServer(final int port, final MockWebConnection mockWebConnection) { port_ = port; mockWebConnection_ = mockWebConnection; @@ -211,6 +227,9 @@ else if ("POST".equalsIgnoreCase(methodText)) { } } + /** + * @return the last received request + */ public String getLastRequest() { return lastRequest_; } diff --git a/src/test/java/org/htmlunit/MockWebConnectionTest.java b/src/test/java/org/htmlunit/MockWebConnectionTest.java index d1a97b540ff..547420d8214 100644 --- a/src/test/java/org/htmlunit/MockWebConnectionTest.java +++ b/src/test/java/org/htmlunit/MockWebConnectionTest.java @@ -35,7 +35,8 @@ public class MockWebConnectionTest extends SimpleWebTestCase { */ @Test public void charset() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + " \n" + " Pound Test\n" diff --git a/src/test/java/org/htmlunit/NiceRefreshHandlerTest.java b/src/test/java/org/htmlunit/NiceRefreshHandlerTest.java index a4071e20725..eb7ac4b2afd 100644 --- a/src/test/java/org/htmlunit/NiceRefreshHandlerTest.java +++ b/src/test/java/org/htmlunit/NiceRefreshHandlerTest.java @@ -46,7 +46,8 @@ public void noRefreshForDelayLargerThanMax() throws Exception { } private void doTest(final int handlerMaxDelay, final URL expectedUrl) throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "Meta Redirect Page\n" + "\n" + "\n" diff --git a/src/test/java/org/htmlunit/NoHttpResponseTest.java b/src/test/java/org/htmlunit/NoHttpResponseTest.java index d20e6e1fc1a..febe69294b1 100644 --- a/src/test/java/org/htmlunit/NoHttpResponseTest.java +++ b/src/test/java/org/htmlunit/NoHttpResponseTest.java @@ -60,6 +60,11 @@ public class NoHttpResponseTest { @RunWith(BrowserRunner.class) public static class WithWebDriverTest extends WebDriverTestCase { + /** + * Resets the {@link MiniServer}. + * + * @throws Exception in case of error + */ @After public void after() throws Exception { MiniServer.resetDropRequests(); @@ -79,7 +84,8 @@ public void submit() throws Exception { mockWebConnection.setResponse(URL_FIRST, HTML); MiniServer.configureDropRequest(new URL(URL_FIRST, "page2?textfield=")); final URL urlRightSubmit = new URL(URL_FIRST, "page2?textfield=new+value"); - mockWebConnection.setResponse(urlRightSubmit, "right submit"); + mockWebConnection.setResponse(urlRightSubmit, + DOCTYPE_HTML + "right submit"); expandExpectedAlertsVariables(URL_FIRST); final WebDriver driver = getWebDriver(); @@ -89,6 +95,9 @@ public void submit() throws Exception { driver.get(URL_FIRST.toString()); driver.findElement(By.id("inputSubmit")).click(); + if (useRealBrowser()) { + Thread.sleep(400); + } assertEquals(getExpectedAlerts()[0], driver.getCurrentUrl()); } catch (final WebDriverException e) { @@ -106,7 +115,8 @@ public void callSubmitInButtonAndReturnTrue() throws Exception { mockWebConnection.setResponse(URL_FIRST, HTML); MiniServer.configureDropRequest(new URL(URL_FIRST, "page2?textfield=")); final URL urlRightSubmit = new URL(URL_FIRST, "page2?textfield=new+value"); - mockWebConnection.setResponse(urlRightSubmit, "right submit"); + mockWebConnection.setResponse(urlRightSubmit, + DOCTYPE_HTML + "right submit"); final WebDriver driver = getWebDriver(); @@ -126,6 +136,11 @@ public void callSubmitInButtonAndReturnTrue() throws Exception { @RunWith(BrowserRunner.class) public static class WithWebClientTest extends SimpleWebTestCase { + /** + * Resets the {@link MiniServer}. + * + * @throws Exception in case of error + */ @After public void after() throws Exception { MiniServer.resetDropRequests(); @@ -140,7 +155,8 @@ public void submit() throws Throwable { mockWebConnection.setResponse(URL_FIRST, HTML); MiniServer.configureDropRequest(new URL(URL_FIRST, "page2?textfield=")); final URL urlRightSubmit = new URL(URL_FIRST, "page2?textfield=new+value"); - mockWebConnection.setResponse(urlRightSubmit, "right submit"); + mockWebConnection.setResponse(urlRightSubmit, + DOCTYPE_HTML + "right submit"); expandExpectedAlertsVariables(URL_FIRST); @@ -162,7 +178,8 @@ public void callSubmitInButtonAndReturnTrue() throws Throwable { mockWebConnection.setResponse(URL_FIRST, HTML); MiniServer.configureDropRequest(new URL(URL_FIRST, "page2?textfield=")); final URL urlRightSubmit = new URL(URL_FIRST, "page2?textfield=new+value"); - mockWebConnection.setResponse(urlRightSubmit, "right submit"); + mockWebConnection.setResponse(urlRightSubmit, + DOCTYPE_HTML + "right submit"); try (MiniServer miniServer = new MiniServer(PORT, mockWebConnection)) { miniServer.start(); diff --git a/src/test/java/org/htmlunit/PageReloadTest.java b/src/test/java/org/htmlunit/PageReloadTest.java index 3246e5a2d78..1e7b5928cec 100644 --- a/src/test/java/org/htmlunit/PageReloadTest.java +++ b/src/test/java/org/htmlunit/PageReloadTest.java @@ -1682,6 +1682,9 @@ private void openUrlAndClickById( // click driver.findElement(By.id(id)).click(); + if (useRealBrowser()) { + Thread.sleep(400); + } assertEquals(counterChange, getMockWebConnection().getRequestCount() - 1); // check location visible to javascript diff --git a/src/test/java/org/htmlunit/ScriptExceptionTest.java b/src/test/java/org/htmlunit/ScriptExceptionTest.java index 53f7a83c806..540c93f0505 100644 --- a/src/test/java/org/htmlunit/ScriptExceptionTest.java +++ b/src/test/java/org/htmlunit/ScriptExceptionTest.java @@ -41,7 +41,7 @@ public final class ScriptExceptionTest extends SimpleWebTestCase { public void constructor() throws Exception { final String message = "bla bla"; final Throwable t = new RuntimeException(message); - final HtmlPage page = loadPage(""); + final HtmlPage page = loadPage(DOCTYPE_HTML + ""); final ScriptException exception = new ScriptException(page, t); assertEquals(t, exception.getCause()); @@ -54,7 +54,7 @@ public void constructor() throws Exception { */ @Test public void getPage() throws Exception { - final String html = ""; + final String html = DOCTYPE_HTML + ""; try { loadPage(html); } diff --git a/src/test/java/org/htmlunit/ScriptPreProcessorTest.java b/src/test/java/org/htmlunit/ScriptPreProcessorTest.java index ef892f8bac4..f34d3680754 100644 --- a/src/test/java/org/htmlunit/ScriptPreProcessorTest.java +++ b/src/test/java/org/htmlunit/ScriptPreProcessorTest.java @@ -54,8 +54,8 @@ public void scriptPreProcessor() throws IOException { final MockWebConnection webConnection = new MockWebConnection(); final String alertText = "content"; final String newAlertText = "newcontent"; - final String content - = "foo\n" + "

hello world

\n" @@ -118,7 +118,8 @@ public void handleAlert(final Page page, final String message) { public void scriptPreProcessor_UnimplementedJavascript() throws Exception { final WebClient client = getWebClient(); final MockWebConnection webConnection = new MockWebConnection(); - final String content = "foo\n" + final String content = DOCTYPE_HTML + + "foo\n" + "

hello world

\n" + "\n" + "\n" @@ -151,7 +152,8 @@ public String preProcess(final HtmlPage htmlPage, final String sourceCode, final */ @Test public void scriptPreProcessor_Eval() throws Exception { - final String html = ""; + final String html = DOCTYPE_HTML + + ""; final WebClient client = getWebClient(); final MockWebConnection conn = new MockWebConnection(); diff --git a/src/test/java/org/htmlunit/SgmlPage2Test.java b/src/test/java/org/htmlunit/SgmlPage2Test.java index 6611c52eaa8..f001c11f17d 100644 --- a/src/test/java/org/htmlunit/SgmlPage2Test.java +++ b/src/test/java/org/htmlunit/SgmlPage2Test.java @@ -36,7 +36,8 @@ public final class SgmlPage2Test extends WebDriverTestCase { @Test @Alerts({"2", "2"}) public void getElementsByTagName() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" @@ -50,8 +50,8 @@ public void localStorage() throws Exception { assertEquals(1, localStorage.size()); assertEquals("Tom", localStorage.get("myCat")); - html - = "\n" + html = DOCTYPE_HTML + + "\n" + "\n" @@ -73,8 +73,8 @@ public void populateLocalStorage() throws Exception { localStorage.put("myCat", "Tom"); - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" @@ -96,8 +96,8 @@ public void sessionStorage() throws Exception { webClient.getStorageHolder().getSessionStorage(webClient.getCurrentWindow()); assertEquals(0, sessionStorage.size()); - String html - = "\n" + String html = DOCTYPE_HTML + + "\n" + "\n" @@ -107,8 +107,8 @@ public void sessionStorage() throws Exception { assertEquals(1, sessionStorage.size()); assertEquals("Tom", sessionStorage.get("myCat")); - html - = "\n" + html = DOCTYPE_HTML + + "\n" + "\n" @@ -131,8 +131,8 @@ public void populateSessionStorage() throws Exception { sessionStorage.put("myCat", "Tom"); - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" diff --git a/src/test/java/org/htmlunit/StringWebResponseTest.java b/src/test/java/org/htmlunit/StringWebResponseTest.java index aa18ba7af65..a19a1cf3159 100644 --- a/src/test/java/org/htmlunit/StringWebResponseTest.java +++ b/src/test/java/org/htmlunit/StringWebResponseTest.java @@ -43,6 +43,9 @@ public void charset() { assertSame(UTF_8, webResponse.getContentCharset()); } + /** + * @throws Exception if the test fails + */ @Test public void charsetImplicit() { final StringWebResponse webResponse = new StringWebResponse("hello", URL_FIRST); @@ -54,7 +57,8 @@ public void charsetImplicit() { */ @Test public void charsetInContent() { - final String content = "\n" + final String content = DOCTYPE_HTML + + "\n" + "\n" + "\u010C\u00CDSLO"; final StringWebResponse webResponse = new StringWebResponse(content, UTF_8, URL_FIRST); @@ -63,9 +67,13 @@ public void charsetInContent() { assertEquals(content, webResponse.getContentAsString()); } + /** + * @throws Exception if the test fails + */ @Test public void charsetInContentImplicit() { - final String content = "\n" + final String content = DOCTYPE_HTML + + "\n" + "\n" + "\u010C\u00CDSLO"; final StringWebResponse webResponse = new StringWebResponse(content, URL_FIRST); @@ -75,11 +83,12 @@ public void charsetInContentImplicit() { } /** - * @throws IOException + * @throws IOException in case of error */ @Test public void inputStream() throws IOException { - final String content = "\n" + final String content = DOCTYPE_HTML + + "\n" + "\n" + "\u010C\u00CDSLO"; final StringWebResponse webResponse = new StringWebResponse(content, URL_FIRST); diff --git a/src/test/java/org/htmlunit/TopLevelWindowTest.java b/src/test/java/org/htmlunit/TopLevelWindowTest.java index 6cdbe6a52c2..49e837ab55b 100644 --- a/src/test/java/org/htmlunit/TopLevelWindowTest.java +++ b/src/test/java/org/htmlunit/TopLevelWindowTest.java @@ -191,7 +191,8 @@ public void webWindowClosed(final WebWindowEvent event) { window.setJobManager(mgr); final MockWebConnection conn = getMockWebConnection(); - conn.setDefaultResponse(""); + conn.setDefaultResponse(DOCTYPE_HTML + + ""); client.getPage(URL_FIRST); assertEquals(1, jobCount.intValue()); @@ -210,10 +211,13 @@ public void history() throws Exception { final History history = window.getHistory(); final MockWebConnection conn = getMockWebConnection(); - conn.setResponse(URL_FIRST, "foo\n" - + "bar"); - conn.setResponse(URL_SECOND, "foo"); - conn.setResponse(URL_THIRD, "foo"); + conn.setResponse(URL_FIRST, DOCTYPE_HTML + + "foo\n" + + "bar"); + conn.setResponse(URL_SECOND, DOCTYPE_HTML + + "foo"); + conn.setResponse(URL_THIRD, DOCTYPE_HTML + + "foo"); assertEquals(0, history.getLength()); assertEquals(-1, history.getIndex()); @@ -305,7 +309,7 @@ public void history() throws Exception { */ @Test public void onBeforeUnloadCalledOnClose() throws Exception { - final String html = "abc"; + final String html = DOCTYPE_HTML + "abc"; final List alerts = new ArrayList<>(); final HtmlPage page = loadPage(html, alerts); assertTrue(alerts.isEmpty()); @@ -323,7 +327,8 @@ public void onBeforeUnloadCalledOnClose() throws Exception { @Test @Alerts("closing") public void setTimeoutDuringOnUnload() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "to second"; - final String secondContent = ""; + final String secondContent = DOCTYPE_HTML + ""; final MockWebConnection webConnection = getMockWebConnection(); webConnection.setResponse(URL_SECOND, secondContent); @@ -185,7 +188,8 @@ public void clickReturnsWhenThePageHasBeenCompleteLoaded() throws Exception { @Test @Alerts({"open", "first", "second"}) public void windowOpenedByAnchorTargetIsAttachedToJavascriptEventLoop() throws Exception { - final String firstContent = "\n" + final String firstContent = DOCTYPE_HTML + + "\n" + "\n" + "\n" + ""; @@ -439,7 +458,8 @@ private void doTestDeflateCompression(final boolean gzipCompatibleCompression) t final MockWebConnection conn = getMockWebConnection(); conn.setResponse(URL_SECOND, content, 200, "OK", "text/javascript", headers); - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "Hello world\n" + "\n" + ""; @@ -558,8 +578,8 @@ public void encodingCharsetGBK() throws Exception { private void encodingCharset(final String title, final String metaCharset, final String responseCharset) throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "" + title + "\n" + "\n" @@ -589,8 +609,8 @@ private void encodingCharset(final String title, @Test @Alerts({"en-US", "en-US,en"}) public void language() throws Exception { - final String html - = "\n" @@ -247,7 +256,8 @@ public void script() throws Exception { */ @Test public void link() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + " foo\n" + " \n" @@ -271,7 +281,8 @@ public void link() throws Exception { */ @Test public void object() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + " foo\n" + "\n" @@ -295,7 +306,8 @@ public void object() throws Exception { */ @Test public void svgScript() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + " foo\n" + "\n" @@ -316,7 +328,8 @@ public void svgScript() throws Exception { */ @Test public void invalidElementEventWithNoJS() throws Exception { - final String html = "" + final String html = DOCTYPE_HTML + + "" + "" + " foo" + "" @@ -334,7 +347,8 @@ public void invalidElementEventWithNoJS() throws Exception { */ @Test public void checkingWithNoJS() throws Exception { - final String html = "" + final String html = DOCTYPE_HTML + + "" + "" + " foo" + "" @@ -362,7 +376,8 @@ public void checkingWithNoJS() throws Exception { */ @Test public void frameSetWithNoJS() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + " foo\n" + "\n" @@ -384,7 +399,8 @@ public void frameSetWithNoJS() throws Exception { */ @Test public void imageEventHandlersWithNoJs() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + " \n" @@ -402,7 +418,8 @@ public void imageEventHandlersWithNoJs() throws Exception { */ @Test public void clickWithNoJs() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + " \n" diff --git a/src/test/java/org/htmlunit/WebClient9Test.java b/src/test/java/org/htmlunit/WebClient9Test.java index bf58e14d809..b61568444a9 100644 --- a/src/test/java/org/htmlunit/WebClient9Test.java +++ b/src/test/java/org/htmlunit/WebClient9Test.java @@ -141,6 +141,9 @@ public void flow1_2() { } } + /** + * @throws Exception if the test fails + */ @Test public void multithreading() throws InterruptedException { final String css = "body { background-color: green; }"; diff --git a/src/test/java/org/htmlunit/WebClientTest.java b/src/test/java/org/htmlunit/WebClientTest.java index 233f1ac27d1..ffbbf22b524 100644 --- a/src/test/java/org/htmlunit/WebClientTest.java +++ b/src/test/java/org/htmlunit/WebClientTest.java @@ -45,7 +45,6 @@ import org.htmlunit.html.HtmlElement; import org.htmlunit.html.HtmlInlineFrame; import org.htmlunit.html.HtmlPage; -import org.htmlunit.html.HtmlPageTest; import org.htmlunit.html.parser.HTMLParser; import org.htmlunit.html.parser.neko.HtmlUnitNekoHtmlParser; import org.htmlunit.http.HttpStatus; @@ -87,7 +86,8 @@ public class WebClientTest extends SimpleWebTestCase { */ @Test public void credentialProvider_NoCredentials() throws Exception { - final String htmlContent = "foo\n" + final String htmlContent = DOCTYPE_HTML + + "foo\n" + "No access"; final WebClient client = getWebClient(); client.getOptions().setPrintContentOnFailingStatusCode(false); @@ -113,7 +113,8 @@ public void credentialProvider_NoCredentials() throws Exception { */ @Test public void htmlWindowEvents_changed() throws Exception { - final String htmlContent = "foo\n" + final String htmlContent = DOCTYPE_HTML + + "foo\n" + "link to foo2\n" + ""; final WebClient client = getWebClient(); @@ -164,12 +165,13 @@ public void webWindowClosed(final WebWindowEvent event) { */ @Test public void htmlWindowEvents_opened() throws Exception { - final String page1Content = "foo\n" + final String page1Content = DOCTYPE_HTML + + "foo\n" + "\n" + "\n" + "link to foo2\n" + ""; - final String page2Content = "foo"; + final String page2Content = DOCTYPE_HTML + "foo"; final WebClient client = getWebClient(); final List events = new LinkedList<>(); @@ -219,12 +221,13 @@ public void webWindowClosed(final WebWindowEvent event) { */ @Test public void htmlWindowEvents_closedFromFrame() throws Exception { - final String firstContent = "first\n" + final String firstContent = DOCTYPE_HTML + + "first\n" + "\n" + "link to foo2\n" + ""; - final String secondContent = "second"; - final String thirdContent = "third"; + final String secondContent = DOCTYPE_HTML + "second"; + final String thirdContent = DOCTYPE_HTML + "third"; final WebClient client = getWebClient(); final MockWebConnection webConnection = new MockWebConnection(); @@ -289,8 +292,8 @@ public void redirection301_MovedPermanently_GetMethod() throws Exception { * @throws Exception if the test fails */ private void doTestRedirectionSameUrlAfterPost(final int statusCode) throws Exception { - final String firstContent = "First"; - final String secondContent = "Second"; + final String firstContent = DOCTYPE_HTML + "First"; + final String secondContent = DOCTYPE_HTML + "Second"; final WebClient webClient = getWebClient(); @@ -436,7 +439,7 @@ public void redirection307_TemporaryRedirect_PostMethod() throws Exception { * @param statusCode the code to return from the initial request * @param initialRequestMethod the initial request * @param expectedRedirectedRequestMethod the submit method of the second (redirected) request - * If a redirect is not expected to happen then this must be null + * If a redirect is not expected to happen then this must be null * @param newLocation the Location set in the redirection header * @throws Exception if the test fails */ @@ -470,8 +473,8 @@ public void redirectionSameURL() throws Exception { } private HtmlPage getPageWithRedirectionsSameURL(final int nbRedirections) throws Exception { - final String firstContent = "First"; - final String secondContent = "Second"; + final String firstContent = DOCTYPE_HTML + "First"; + final String secondContent = DOCTYPE_HTML + "Second"; final WebClient webClient = getWebClient(); @@ -523,7 +526,7 @@ private void redirection_AdditionalHeadersMaintained(final int statusCode) throw final List headers = asList(new NameValuePair("Location", URL_SECOND.toString())); conn.setResponse(URL_FIRST, "", statusCode, "", MimeType.TEXT_HTML, headers); - conn.setResponse(URL_SECOND, "abc"); + conn.setResponse(URL_SECOND, DOCTYPE_HTML + "abc"); final WebRequest request = new WebRequest(URL_FIRST); request.setAdditionalHeader("foo", "bar"); @@ -539,7 +542,7 @@ private void redirection_AdditionalHeadersMaintained(final int statusCode) throw * @param statusCode the code to return from the initial request * @param initialRequestMethod the initial request * @param expectedRedirectedRequestMethod the submit method of the second (redirected) request - * If a redirect is not expected to happen then this must be null + * If a redirect is not expected to happen then this must be null * @param newLocation the Location set in the redirection header * @param useProxy indicates if the test should be performed with a proxy * @throws Exception if the test fails @@ -553,8 +556,8 @@ private void doTestRedirection( final boolean useProxy) throws Exception { - final String firstContent = "First"; - final String secondContent = "Second"; + final String firstContent = DOCTYPE_HTML + "First"; + final String secondContent = DOCTYPE_HTML + "Second"; final WebClient webClient; final String proxyHost; @@ -644,7 +647,8 @@ public void setPageCreator_null() { */ @Test public void setPageCreator() throws Exception { - final String page1Content = "foo\n" + final String page1Content = DOCTYPE_HTML + + "foo\n" + "\n" + "link to foo2\n" + ""; @@ -706,7 +710,8 @@ public HTMLParser getHtmlParser() { */ @Test public void loadPage_PostWithParameters() throws Exception { - final String htmlContent = "foo\n" + final String htmlContent = DOCTYPE_HTML + + "foo\n" + ""; final WebClient client = getWebClient(); @@ -727,7 +732,8 @@ public void loadPage_PostWithParameters() throws Exception { */ @Test public void loadPage_SlashesInQueryString() throws Exception { - final String htmlContent = "foo\n" + final String htmlContent = DOCTYPE_HTML + + "foo\n" + "to page 2\n" + ""; @@ -754,7 +760,7 @@ public void loadFilePage() throws Exception { // It could be useful to have existing files to test in a special location in filesystem. // It will be really needed when we have to test binary files using the file protocol. - final String htmlContent = "foo"; + final String htmlContent = DOCTYPE_HTML + "foo"; final File currentDirectory = new File((new File("")).getAbsolutePath()); final File tmpFile = File.createTempFile("test", ".html", currentDirectory); tmpFile.deleteOnExit(); @@ -873,10 +879,12 @@ public void loadFilePageXml() throws Exception { */ @Test public void redirectViaJavaScriptDuringInitialPageLoad() throws Exception { - final String firstContent = "First"; - final String secondContent = "Second"; + final String secondContent = DOCTYPE_HTML + + "Second"; final WebClient webClient = getWebClient(); @@ -900,7 +908,7 @@ public void redirectViaJavaScriptDuringInitialPageLoad() throws Exception { public void loadWebResponseInto() throws Exception { final WebClient webClient = getWebClient(); final WebResponse webResponse = new StringWebResponse( - "first", URL_FIRST); + DOCTYPE_HTML + "first", URL_FIRST); final Page page = webClient.loadWebResponseInto(webResponse, webClient.getCurrentWindow()); assertTrue(HtmlPage.class.isInstance(page)); @@ -917,7 +925,7 @@ public void loadWebResponseInto() throws Exception { */ @Test public void getPageFailingStatusCode() throws Exception { - final String firstContent = "Hello World"; + final String firstContent = DOCTYPE_HTML + "Hello World"; final WebClient webClient = getWebClient(); @@ -951,7 +959,7 @@ public void proxyConfig() throws Exception { defaultProxyHost, defaultProxyPort)) { // Configure the mock web connection. - final String html = "Hello World"; + final String html = DOCTYPE_HTML + "Hello World"; final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(URL_FIRST, html); webClient.setWebConnection(webConnection); @@ -1021,7 +1029,7 @@ public void proxyConfig() throws Exception { public void proxyConfigWithRedirect() throws Exception { final String defaultProxyHost = "defaultProxyHost"; final int defaultProxyPort = 777; - final String html = "Hello World"; + final String html = DOCTYPE_HTML + "Hello World"; try (WebClient webClient = new WebClient(getBrowserVersion(), defaultProxyHost, defaultProxyPort)) { webClient.getOptions().getProxyConfig().addHostsToProxyBypass("hostToByPass"); @@ -1030,7 +1038,8 @@ public void proxyConfigWithRedirect() throws Exception { final List headers = Collections.singletonList(new NameValuePair("Location", location2)); final MockWebConnection webConnection = new MockWebConnection(); webConnection.setResponse(URL_FIRST, html, 302, "Some error", MimeType.TEXT_HTML, headers); - webConnection.setResponse(new URL(location2), "2nd page"); + webConnection.setResponse(new URL(location2), + DOCTYPE_HTML + "2nd page"); webClient.setWebConnection(webConnection); final Page page2 = webClient.getPage(URL_FIRST); @@ -1060,7 +1069,8 @@ public void proxyConfigWithRedirect() throws Exception { public void proxyConfigForJS() throws Exception { final String defaultProxyHost = "defaultProxyHost"; final int defaultProxyPort = 777; - final String html = "Hello World\n" + final String html = DOCTYPE_HTML + + "Hello World\n" + "\n" + ""; try (WebClient webClient = new WebClient(getBrowserVersion(), defaultProxyHost, defaultProxyPort)) { @@ -1137,7 +1147,8 @@ public void refreshHandlerAccessors() { */ @Test public void badCharset() throws Exception { - final String page1Content = "foo\n" + final String page1Content = DOCTYPE_HTML + + "foo\n" + ""; final WebClient client = getWebClient(); @@ -1167,12 +1178,14 @@ public void expandUrlHandlesColonsInRelativeUrl() throws Exception { */ @Test public void reusingHtmlPageToSubmitFormMultipleTimes() throws Exception { - final String firstContent = "First\n" + final String firstContent = DOCTYPE_HTML + + "First\n" + "\n" + "
\n" + "\n" + "
"; - final String secondContent = "SecondSecond"; + final String secondContent = DOCTYPE_HTML + + "SecondSecond"; final WebClient webClient = getWebClient(); @@ -1195,11 +1208,13 @@ public void reusingHtmlPageToSubmitFormMultipleTimes() throws Exception { */ @Test public void openerInFrameset() throws Exception { - final String firstContent = "\n" + final String firstContent = DOCTYPE_HTML + + "\n" + "\n" + "\n" + ""; - final String secondContent = "to top"; + final String secondContent = DOCTYPE_HTML + + "to top"; final WebClient webClient = getWebClient(); @@ -1301,7 +1316,7 @@ private File getTestFile(final String fileName) throws Exception { */ @Test public void requestHeader() throws Exception { - final String content = ""; + final String content = DOCTYPE_HTML + ""; final WebClient client = getWebClient(); final MockWebConnection webConnection = new MockWebConnection(); @@ -1330,7 +1345,7 @@ public void requestHeaderOverwritesClient() throws Exception { final String fromRequest = "from request"; final String fromClient = "from client"; - final String content = ""; + final String content = DOCTYPE_HTML + ""; final WebClient client = getWebClient(); final MockWebConnection webConnection = new MockWebConnection(); @@ -1364,7 +1379,7 @@ public void requestHeaderOverwritesClient() throws Exception { public void clientHeaderOverwritesDefault() throws Exception { final String fromClient = "from client"; - final String content = ""; + final String content = DOCTYPE_HTML + ""; final WebClient client = getWebClient(); final MockWebConnection webConnection = new MockWebConnection(); @@ -1385,7 +1400,7 @@ public void clientHeaderOverwritesDefault() throws Exception { */ @Test public void requestHeaderDoNotOverwriteWebRequestAcceptHeader() throws Exception { - final String content = ""; + final String content = DOCTYPE_HTML + ""; final WebClient webClient = getWebClient(); final MockWebConnection webConnection = new MockWebConnection(); @@ -1419,7 +1434,7 @@ public void requestHeaderDoNotOverwriteWebRequestAcceptHeader() throws Exception */ @Test public void requestHeaderDoNotOverwriteWebRequestAcceptHeader2() throws Exception { - final String content = ""; + final String content = DOCTYPE_HTML + ""; final WebClient client = getWebClient(); final MockWebConnection webConnection = new MockWebConnection(); @@ -1457,7 +1472,8 @@ public void requestHeaderDoNotOverwriteWebRequestAcceptHeader2() throws Exceptio */ @Test public void contentTypeCaseInsensitive() throws Exception { - final String content = "\n" + final String content = DOCTYPE_HTML + + "\n" + "\n" + ""; final WebClient client = getWebClient(); @@ -1504,7 +1520,8 @@ public void loadFilePageWithExternalJS() throws Exception { FileUtils.writeStringToFile(tmpFileJS, "alert('foo')", encoding); // HTML file - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + ""; final File tmpFile = File.createTempFile("test", ".html", currentDirectory); @@ -1528,7 +1545,7 @@ public void loadFilePageWithExternalJS() throws Exception { */ @Test public void onBeforeUnloadCalledOnCorrectPage() throws Exception { - final String html = ""; + final String html = DOCTYPE_HTML + ""; final List alerts = new ArrayList<>(); loadPage(html, alerts); assertTrue(alerts.isEmpty()); @@ -1542,7 +1559,7 @@ public void onBeforeUnloadCalledOnCorrectPage() throws Exception { @Test public void urlEncoding() throws Exception { final URL url = new URL("http://host/x+y\u00E9/a\u00E9 b?c \u00E9 d"); - final HtmlPage page = loadPage(BrowserVersion.FIREFOX, "", new ArrayList<>(), url); + final HtmlPage page = loadPage(BrowserVersion.FIREFOX, DOCTYPE_HTML + "", new ArrayList<>(), url); final WebRequest wrs = page.getWebResponse().getWebRequest(); assertEquals("http://host/x+y%C3%A9/a%C3%A9%20b?c%20%C3%A9%20d", wrs.getUrl()); } @@ -1555,7 +1572,8 @@ public void urlEncoding() throws Exception { @Test public void urlEncoding2() throws Exception { final URL url = new URL("http://host/x+y\u00E9/a\u00E9 b?c \u00E9 d"); - final HtmlPage page = loadPage(BrowserVersion.BEST_SUPPORTED, "", new ArrayList<>(), url); + final HtmlPage page = loadPage(BrowserVersion.BEST_SUPPORTED, + DOCTYPE_HTML + "", new ArrayList<>(), url); final WebRequest wrs = page.getWebResponse().getWebRequest(); assertEquals("http://host/x+y%C3%A9/a%C3%A9%20b?c%20%C3%A9%20d", wrs.getUrl()); } @@ -1567,7 +1585,7 @@ public void urlEncoding2() throws Exception { @Test public void plusNotEncodedInUrl() throws Exception { final URL url = new URL("http://host/search/my+category/"); - final HtmlPage page = loadPage("", new ArrayList<>(), url); + final HtmlPage page = loadPage(DOCTYPE_HTML + "", new ArrayList<>(), url); final WebRequest wrs = page.getWebResponse().getWebRequest(); assertEquals("http://host/search/my+category/", wrs.getUrl()); } @@ -1581,8 +1599,8 @@ public void cssEnablementControlsCssLoading() throws Exception { final MockWebConnection conn = new MockWebConnection(); client.setWebConnection(conn); - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + " \n" + " \n" + " \n" @@ -1619,7 +1637,7 @@ public void cssEnablementControlsCssLoading() throws Exception { public void getPageDataProtocol() throws Exception { final WebClient webClient = getWebClient(); - final String html = "DataUrl Test"; + final String html = DOCTYPE_HTML + "DataUrl Test"; final Page page = webClient.getPage("data:text/html;charset=utf-8," + html); assertEquals("DataUrl Test", ((HtmlPage) page).asNormalizedText()); @@ -1632,7 +1650,8 @@ public void getPageDataProtocol() throws Exception { public void getPageJavascriptProtocol() throws Exception { final WebClient webClient = getWebClient(); final MockWebConnection webConnection = new MockWebConnection(); - webConnection.setDefaultResponse("Hello World"); + webConnection.setDefaultResponse(DOCTYPE_HTML + + "Hello World"); webClient.setWebConnection(webConnection); final List collectedAlerts = new ArrayList<>(); @@ -1686,7 +1705,7 @@ public void javaScriptTimeout() throws Exception { try { client.getOptions().setThrowExceptionOnScriptError(false); - final String content = ""; + final String content = DOCTYPE_HTML + ""; final MockWebConnection webConnection = new MockWebConnection(); webConnection.setDefaultResponse(content); client.setWebConnection(webConnection); @@ -1737,7 +1756,7 @@ public void openWindowWithNullUrl() throws Exception { public void basicWindowTracking() throws Exception { // Create mock web connection. final MockWebConnection conn = new MockWebConnection(); - conn.setDefaultResponse("First\n" + "
\n" + "\n" + "
"; conn.setResponse(URL_FIRST, html1); - final String html2 = "Second\n" + final String html2 = DOCTYPE_HTML + + "Second\n" + "\n" + ""; @@ -1853,13 +1876,15 @@ public void windowTracking_SpecialCase3() throws Exception { final List collectedAlerts = new ArrayList<>(); webClient.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); - final String html1 = "First\n" + final String html1 = DOCTYPE_HTML + + "First\n" + "\n" + "\n" + ""; conn.setResponse(URL_FIRST, html1); - final String html2 = "Second\n" + final String html2 = DOCTYPE_HTML + + "Second\n" + "\n" + "
\n" + "
\n" @@ -1874,7 +1899,8 @@ public void windowTracking_SpecialCase3() throws Exception { + ""; conn.setResponse(URL_SECOND, html2); - final String html3 = "Third\n" + final String html3 = DOCTYPE_HTML + + "Third\n" + "\n" + "\n" @@ -2052,12 +2081,13 @@ public void currentWindow() throws Exception { final WebClient client = getWebClient(); final MockWebConnection conn = new MockWebConnection(); - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + ""; conn.setResponse(URL_FIRST, html); final URL frameUrl = new URL(URL_FIRST, "frame.html"); - conn.setResponse(frameUrl, ""); - conn.setResponse(URL_SECOND, ""); + conn.setResponse(frameUrl, DOCTYPE_HTML + ""); + conn.setResponse(URL_SECOND, DOCTYPE_HTML + ""); client.setWebConnection(conn); client.getPage(URL_FIRST); @@ -2076,7 +2106,8 @@ public void currentWindow() throws Exception { */ @Test public void currentWindow2() throws Exception { - final String html = "\n" + ""; - final String html2 = "\n" @@ -2272,7 +2306,8 @@ public void close() throws Exception { */ @Test public void test() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + " \n" @@ -2376,7 +2411,8 @@ public void webSocketDisabled() throws Exception { */ @Test public void loadHtmlCodeIntoCurrentWindow() throws Exception { - final String htmlCode = "" + final String htmlCode = DOCTYPE_HTML + + "" + " " + " Title" + " " @@ -2416,11 +2452,13 @@ public void loadXHtmlCodeIntoCurrentWindow() throws Exception { */ @Test public void reset() throws Exception { - final String html = "testpage\n" + final String html = DOCTYPE_HTML + + "testpage\n" + "\n" + ""; - final String html2 = "testpage\n" + final String html2 = DOCTYPE_HTML + + "testpage\n" + "\n" + "\n" + ""; @@ -2481,8 +2519,7 @@ public void reset() throws Exception { */ @Test public void loginFlowClickSubmitRedirect() throws Exception { - final String startPage = - HtmlPageTest.STANDARDS_MODE_PREFIX_ + final String startPage = DOCTYPE_HTML + "Start page" + "
" + " " @@ -2492,8 +2529,7 @@ public void loginFlowClickSubmitRedirect() throws Exception { int reqCount = getMockWebConnection().getRequestCount(); - final String submitPage = - HtmlPageTest.STANDARDS_MODE_PREFIX_ + final String submitPage = DOCTYPE_HTML + "Submit page" + "" + "" @@ -2508,8 +2544,7 @@ public void loginFlowClickSubmitRedirect() throws Exception { final URL urlRedirectPage = new URL(URL_FIRST, "redirect.html"); getMockWebConnection().setResponse(urlRedirectPage, "", 302, "Found", null, headers); - final String landingPage = - HtmlPageTest.STANDARDS_MODE_PREFIX_ + final String landingPage = DOCTYPE_HTML + "Landing page" + ""; final URL urlLandingPage = new URL(URL_FIRST, "landing.html"); @@ -2543,7 +2578,8 @@ public void loginFlowClickSubmitRedirect() throws Exception { */ @Test public void getPageInSeparateThread() throws Exception { - final String html = "testpage\n" + final String html = DOCTYPE_HTML + + "testpage\n" + "\n" + ""; diff --git a/src/test/java/org/htmlunit/WebClientWaitForBackgroundJobsTest.java b/src/test/java/org/htmlunit/WebClientWaitForBackgroundJobsTest.java index fd876b0209b..5406e14d3e6 100644 --- a/src/test/java/org/htmlunit/WebClientWaitForBackgroundJobsTest.java +++ b/src/test/java/org/htmlunit/WebClientWaitForBackgroundJobsTest.java @@ -59,7 +59,8 @@ private void assertMaxTestRunTime(final long maxRunTimeMilliseconds) { */ @Test public void dontWaitWhenUnnecessary() throws Exception { - final String content = "\n" + final String content = DOCTYPE_HTML + + "\n" + "\n" + " test\n" + " \n" + ""; - final String page3 = ""; diff --git a/src/test/java/org/htmlunit/WebDriverTestCase.java b/src/test/java/org/htmlunit/WebDriverTestCase.java index 6b4e41afd99..e52a0616f62 100644 --- a/src/test/java/org/htmlunit/WebDriverTestCase.java +++ b/src/test/java/org/htmlunit/WebDriverTestCase.java @@ -16,7 +16,6 @@ import static java.nio.charset.StandardCharsets.ISO_8859_1; import static java.nio.charset.StandardCharsets.UTF_8; -import static org.junit.Assert.fail; import java.io.File; import java.io.FileInputStream; @@ -24,6 +23,7 @@ import java.net.URISyntaxException; import java.net.URL; import java.nio.charset.Charset; +import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -67,7 +67,6 @@ import org.eclipse.jetty.webapp.WebAppContext; import org.htmlunit.MockWebConnection.RawResponseData; import org.htmlunit.html.HtmlElement; -import org.htmlunit.html.HtmlPageTest; import org.htmlunit.javascript.JavaScriptEngine; import org.htmlunit.util.NameValuePair; import org.junit.After; @@ -90,7 +89,7 @@ import org.openqa.selenium.chrome.ChromeDriverService; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.devtools.DevTools; -import org.openqa.selenium.devtools.v133.emulation.Emulation; +import org.openqa.selenium.devtools.v134.emulation.Emulation; import org.openqa.selenium.edge.EdgeDriver; import org.openqa.selenium.edge.EdgeDriverService; import org.openqa.selenium.edge.EdgeOptions; @@ -192,7 +191,8 @@ public abstract class WebDriverTestCase extends WebTestCase { * Function used in many tests. */ public static final String LOG_WINDOW_NAME_FUNCTION = - " function log(msg) { window.top.name += msg + '\\u00a7'; }\n window.top.name = '';" + " function log(msg) { window.top.name += msg + '\\u00a7'; }\n" + + " window.top.name = '';" + LOG_EX_FUNCTION; /** @@ -267,7 +267,6 @@ public abstract class WebDriverTestCase extends WebTestCase { private static final Executor EXECUTOR_POOL = Executors.newFixedThreadPool(4); private boolean useRealBrowser_; - private Boolean useStandards_; /** * The HtmlUnitDriver. @@ -282,6 +281,9 @@ protected boolean needThreeConnections() { return false; } + /** + * @return the browser properties (and initializes them lazy) + */ public static Set getBrowsersProperties() { if (BROWSERS_PROPERTIES_ == null) { try { @@ -503,14 +505,6 @@ public void setUseRealBrowser(final boolean useRealBrowser) { useRealBrowser_ = useRealBrowser; } - /** - * Sets whether to use {@code Standards Mode} or not. - * @param useStandards whether to use {@code Standards Mode} or not - */ - public void setUseStandards(final boolean useStandards) { - useStandards_ = useStandards; - } - /** * Builds a new WebDriver instance. * @return the instance @@ -967,18 +961,9 @@ protected final WebDriver loadPage2(final String html, final URL url, * @return the web driver * @throws Exception if something goes wrong */ - protected final WebDriver loadPage2(String html, final URL url, + protected final WebDriver loadPage2(final String html, final URL url, final String contentType, final Charset charset, final Charset serverCharset) throws Exception { - if (useStandards_ != null) { - if (html.startsWith(HtmlPageTest.STANDARDS_MODE_PREFIX_)) { - fail("HTML must not be prefixed with Standards Mode."); - } - if (useStandards_) { - html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + html; - } - } getMockWebConnection().setResponse(url, html, contentType, charset); - return loadPage2(url, serverCharset); } @@ -1111,7 +1096,7 @@ protected final WebDriver loadPageVerifyTitle2(final String html, final String.. return verifyTitle2(driver, expectedAlerts); } - protected final WebDriver verifyTitle2(final long maxWaitTime, final WebDriver driver, + protected final WebDriver verifyTitle2(final Duration maxWaitTime, final WebDriver driver, final String... expectedAlerts) throws Exception { final StringBuilder expected = new StringBuilder(); @@ -1120,7 +1105,7 @@ protected final WebDriver verifyTitle2(final long maxWaitTime, final WebDriver d } final String expectedTitle = expected.toString(); - final long maxWait = System.currentTimeMillis() + maxWaitTime; + final long maxWait = System.currentTimeMillis() + maxWaitTime.toMillis(); while (System.currentTimeMillis() < maxWait) { try { @@ -1217,9 +1202,9 @@ protected final WebDriver verifyJsVariable(final WebDriver driver, final String return driver; } - protected final WebDriver verifyWindowName2(final long maxWaitTime, final WebDriver driver, + protected final WebDriver verifyWindowName2(final Duration maxWaitTime, final WebDriver driver, final String... expectedAlerts) throws Exception { - final long maxWait = System.currentTimeMillis() + maxWaitTime; + final long maxWait = System.currentTimeMillis() + maxWaitTime.toMillis(); while (System.currentTimeMillis() < maxWait) { try { @@ -1262,7 +1247,7 @@ protected final WebDriver verifySessionStorage2(final WebDriver driver, * @return the web driver * @throws Exception if something goes wrong */ - protected final WebDriver loadPageWithAlerts2(final String html, final long maxWaitTime) throws Exception { + protected final WebDriver loadPageWithAlerts2(final String html, final Duration maxWaitTime) throws Exception { return loadPageWithAlerts2(html, URL_FIRST, maxWaitTime); } @@ -1285,7 +1270,7 @@ protected final WebDriver loadPageWithAlerts2(final String html, final URL url) * @return the web driver * @throws Exception if something goes wrong */ - protected final WebDriver loadPageWithAlerts2(final String html, final URL url, final long maxWaitTime) + protected final WebDriver loadPageWithAlerts2(final String html, final URL url, final Duration maxWaitTime) throws Exception { final WebDriver driver = loadPage2(html, url); @@ -1311,7 +1296,7 @@ protected void verifyAlerts(final WebDriver driver, final String... expectedAler * @param expected the expected alerts * @throws Exception in case of failure */ - protected void verifyAlerts(final long maxWaitTime, final WebDriver driver, final String... expected) + protected void verifyAlerts(final Duration maxWaitTime, final WebDriver driver, final String... expected) throws Exception { final List actualAlerts = getCollectedAlerts(maxWaitTime, driver, expected.length); @@ -1359,7 +1344,7 @@ protected final WebDriver loadPageWithAlerts2(final String html, * @return the web driver * @throws Exception if something goes wrong */ - protected final WebDriver loadPageWithAlerts2(final String html, final URL url, final long maxWaitTime, + protected final WebDriver loadPageWithAlerts2(final String html, final URL url, final Duration maxWaitTime, final Map> servlets) throws Exception { expandExpectedAlertsVariables(URL_FIRST); @@ -1388,7 +1373,7 @@ protected final WebDriver loadPageWithAlerts2(final URL url) throws Exception { * @return the web driver * @throws Exception if something goes wrong */ - protected final WebDriver loadPageWithAlerts2(final URL url, final long maxWaitTime) throws Exception { + protected final WebDriver loadPageWithAlerts2(final URL url, final Duration maxWaitTime) throws Exception { startWebServer(getMockWebConnection(), null); final WebDriver driver = getWebDriver(); @@ -1430,11 +1415,11 @@ protected List getCollectedAlerts(final WebDriver driver, final int aler * @return the collected alerts * @throws Exception in case of problem */ - protected List getCollectedAlerts(final long maxWaitTime, final WebDriver driver, final int alertsLength) - throws Exception { + protected List getCollectedAlerts(final Duration maxWaitTime, + final WebDriver driver, final int alertsLength) throws Exception { final List collectedAlerts = new ArrayList<>(); - long maxWait = System.currentTimeMillis() + maxWaitTime; + long maxWait = System.currentTimeMillis() + maxWaitTime.toMillis(); while (collectedAlerts.size() < alertsLength && System.currentTimeMillis() < maxWait) { try { @@ -1584,7 +1569,7 @@ public void beforeTest() throws InterruptedException { * @throws Exception in case of failure */ protected void assertTitle(final WebDriver webdriver, final String expected) throws Exception { - final long maxWait = System.currentTimeMillis() + DEFAULT_WAIT_TIME; + final long maxWait = System.currentTimeMillis() + DEFAULT_WAIT_TIME.toMillis(); while (true) { final String title = webdriver.getTitle(); diff --git a/src/test/java/org/htmlunit/WebRequest2Test.java b/src/test/java/org/htmlunit/WebRequest2Test.java index 51e3056770b..e83cd11acea 100644 --- a/src/test/java/org/htmlunit/WebRequest2Test.java +++ b/src/test/java/org/htmlunit/WebRequest2Test.java @@ -186,6 +186,9 @@ public void getParametersFromQueryAndUrlEncodedBodyPost() throws Exception { assertEquals("d", parameters.get(1).getValue()); } + /** + * @throws Exception if the test fails + */ @Test public void getParametersFromQueryAndUrlEncodedBodyPostWhenEncodingTypeIsMultipart() throws Exception { final URL url = new URL(URL_FIRST, "?a=b"); @@ -206,6 +209,9 @@ public void getParametersFromQueryAndUrlEncodedBodyPostWhenEncodingTypeIsMultipa assertEquals("d", parameters.get(1).getValue()); } + /** + * @throws Exception if the test fails + */ @Test public void getParametersUrlEncodedPostNoBody() throws Exception { final URL url = new URL(URL_FIRST, "?a=b"); @@ -223,6 +229,9 @@ public void getParametersUrlEncodedPostNoBody() throws Exception { assertEquals("b", parameters.get(0).getValue()); } + /** + * @throws Exception if the test fails + */ @Test public void getParametersTextEncodedPostNoBody() throws Exception { final URL url = new URL(URL_FIRST, "?a=b"); @@ -240,6 +249,9 @@ public void getParametersTextEncodedPostNoBody() throws Exception { assertEquals("b", parameters.get(0).getValue()); } + /** + * @throws Exception if the test fails + */ @Test public void getParametersTextEncodedPostBody() throws Exception { final URL url = new URL(URL_FIRST, "?a=b"); diff --git a/src/test/java/org/htmlunit/WebResponse2Test.java b/src/test/java/org/htmlunit/WebResponse2Test.java index 94bc0867a60..ecc87406cef 100644 --- a/src/test/java/org/htmlunit/WebResponse2Test.java +++ b/src/test/java/org/htmlunit/WebResponse2Test.java @@ -42,13 +42,13 @@ public class WebResponse2Test extends SimpleWebTestCase { */ @Test public void charsetInMetaTag() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "foo\n" + ""; final HtmlPage page = loadPage(html); - assertSame(UTF_8, page.getWebResponse().getContentCharsetOrNull()); + assertSame(UTF_8, page.getWebResponse().getContentCharset()); assertEquals(html, page.getWebResponse().getContentAsString()); } diff --git a/src/test/java/org/htmlunit/WebResponseTest.java b/src/test/java/org/htmlunit/WebResponseTest.java index 6c600549495..c0db0a16024 100644 --- a/src/test/java/org/htmlunit/WebResponseTest.java +++ b/src/test/java/org/htmlunit/WebResponseTest.java @@ -59,8 +59,8 @@ public class WebResponseTest extends WebServerTestCase { @Test public void encodingCharsetUtf8() throws Exception { final String title = "\u6211\u662F\u6211\u7684FOCUS"; - final String content = - "\n" + final String content = DOCTYPE_HTML + + "\n" + "" + title + "\n" + "\n" + "\n" @@ -178,7 +178,8 @@ public void getContentAsStringIllegalCharset() throws Exception { * Servlet for {@link #binaryResponseHeaders()}. */ public static class BinaryResponseHeadersServlet extends HttpServlet { - private static final String RESPONSE = "FooThis is foo!"; + private static final String RESPONSE = DOCTYPE_HTML + + "FooThis is foo!"; /** * {@inheritDoc} @@ -218,7 +219,7 @@ public void binaryResponseHeaders() throws Exception { page.getWebResponse().getContentAsString(UTF_8)); assertEquals("gzip", page.getWebResponse().getResponseHeaderValue("Content-Encoding")); - assertEquals("73", page.getWebResponse().getResponseHeaderValue(HttpHeader.CONTENT_LENGTH)); + assertEquals("85", page.getWebResponse().getResponseHeaderValue(HttpHeader.CONTENT_LENGTH)); } /** diff --git a/src/test/java/org/htmlunit/WebServerTestCase.java b/src/test/java/org/htmlunit/WebServerTestCase.java index cf55669d921..70f36b0efda 100644 --- a/src/test/java/org/htmlunit/WebServerTestCase.java +++ b/src/test/java/org/htmlunit/WebServerTestCase.java @@ -20,6 +20,7 @@ import java.net.BindException; import java.net.URL; import java.nio.charset.Charset; +import java.time.Duration; import java.util.List; import java.util.Map; @@ -256,7 +257,7 @@ public void tearDown() throws Exception { */ protected final HtmlPage loadPageWithAlerts(final String html, final URL url) throws Exception { - return loadPageWithAlerts(html, url, 0); + return loadPageWithAlerts(html, url, Duration.ofSeconds(0)); } /** @@ -267,7 +268,7 @@ protected final HtmlPage loadPageWithAlerts(final String html, final URL url) * @return the page * @throws Exception if something goes wrong */ - protected final HtmlPage loadPageWithAlerts(final String html, final URL url, final long maxWaitTime) + protected final HtmlPage loadPageWithAlerts(final String html, final URL url, final Duration maxWaitTime) throws Exception { alertHandler_.clear(); expandExpectedAlertsVariables(URL_FIRST); @@ -276,7 +277,7 @@ protected final HtmlPage loadPageWithAlerts(final String html, final URL url, fi final HtmlPage page = loadPage(html, url); List actualAlerts = getCollectedAlerts(page); - final long maxWait = System.currentTimeMillis() + maxWaitTime; + final long maxWait = System.currentTimeMillis() + maxWaitTime.toMillis(); while (actualAlerts.size() < expectedAlerts.length && System.currentTimeMillis() < maxWait) { Thread.sleep(30); actualAlerts = getCollectedAlerts(page); diff --git a/src/test/java/org/htmlunit/WebTestCase.java b/src/test/java/org/htmlunit/WebTestCase.java index 38b613befd8..356a6606118 100644 --- a/src/test/java/org/htmlunit/WebTestCase.java +++ b/src/test/java/org/htmlunit/WebTestCase.java @@ -27,6 +27,7 @@ import java.net.URL; import java.nio.file.Files; import java.nio.file.Paths; +import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; import java.util.Base64; @@ -67,6 +68,9 @@ */ public abstract class WebTestCase { + /** The html5 doctype. */ + public static final String DOCTYPE_HTML = "\n"; + /** * Make the test method name available to the tests. */ @@ -79,9 +83,7 @@ public abstract class WebTestCase { @Rule public final RetryRule retryRule_ = new RetryRule(4); - - - /** Logging support. */ + // /** Logging support. */ // private static final Log LOG = LogFactory.getLog(WebTestCase.class); /** save the environment */ @@ -114,7 +116,7 @@ public abstract class WebTestCase { public static final String SOCKS_PROXY_HOST = System.getProperty("htmlunit.test.socksproxy.host", "localhost"); /** The default time used to wait for the expected alerts. */ - protected static final long DEFAULT_WAIT_TIME = 1000; + protected static final Duration DEFAULT_WAIT_TIME = Duration.ofSeconds(1); /** Constant for the URL which is used in the tests. */ public static final URL URL_FIRST; @@ -484,8 +486,8 @@ protected void verify(final Supplier func, final String expected) throws * @throws Exception in case of failure */ protected void verify(final Supplier func, final String expected, - final long maxWaitTime) throws Exception { - final long maxWait = System.currentTimeMillis() + maxWaitTime; + final Duration maxWaitTime) throws Exception { + final long maxWait = System.currentTimeMillis() + maxWaitTime.toMillis(); String actual = null; while (System.currentTimeMillis() < maxWait) { diff --git a/src/test/java/org/htmlunit/WebWindowListenerTest.java b/src/test/java/org/htmlunit/WebWindowListenerTest.java index 78a4f07d4c4..a1ea4228046 100644 --- a/src/test/java/org/htmlunit/WebWindowListenerTest.java +++ b/src/test/java/org/htmlunit/WebWindowListenerTest.java @@ -36,8 +36,8 @@ public class WebWindowListenerTest extends SimpleWebTestCase { @Test @NotYetImplemented public void eventOrder() throws Exception { - final String firstHtml - = "\n" + final String firstHtml = DOCTYPE_HTML + + "\n" + "Test 1\n" + "\n" + "\n" + " " + " \n" + "\n" @@ -1377,7 +1374,6 @@ public void cssStyleDeclaration() throws Exception { */ @Test @Alerts("function CSSStyleRule() { [native code] }") - @AlertsStandards("function CSSStyleRule() { [native code] }") public void cssStyleRule() throws Exception { test("CSSStyleRule"); } @@ -4567,7 +4563,6 @@ public void localMediaStream() throws Exception { */ @Test @Alerts("function Location() { [native code] }") - @AlertsStandards("function Location() { [native code] }") public void location() throws Exception { test("Location"); } diff --git a/src/test/java/org/htmlunit/general/HostConstantsTest.java b/src/test/java/org/htmlunit/general/HostConstantsTest.java index 5792e4569ad..9ccab39dcd2 100644 --- a/src/test/java/org/htmlunit/general/HostConstantsTest.java +++ b/src/test/java/org/htmlunit/general/HostConstantsTest.java @@ -76,7 +76,8 @@ public static Collection data() throws Exception { public void test() throws Exception { setExpectedAlerts(getExpectedString()); - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + ""; diff --git a/src/test/java/org/htmlunit/general/HostTypeOfTest.java b/src/test/java/org/htmlunit/general/HostTypeOfTest.java index 6a49ffb3f63..07932df2adb 100644 --- a/src/test/java/org/htmlunit/general/HostTypeOfTest.java +++ b/src/test/java/org/htmlunit/general/HostTypeOfTest.java @@ -35,13 +35,13 @@ public class HostTypeOfTest extends WebDriverTestCase { private void test(final String className) throws Exception { - final String html = - "\n" + ""; diff --git a/src/test/java/org/htmlunit/general/huge/ElementClosesElementTest.java b/src/test/java/org/htmlunit/general/huge/ElementClosesElementTest.java index ec55357d316..7a47665ea67 100644 --- a/src/test/java/org/htmlunit/general/huge/ElementClosesElementTest.java +++ b/src/test/java/org/htmlunit/general/huge/ElementClosesElementTest.java @@ -138,7 +138,8 @@ else if ("tr".equals(parent)) { html = "<" + parent + " id='outer'><" + child + ">\n"; } - String pageHtml = "\n" + String pageHtml = DOCTYPE_HTML + + "\n" + "-\n" + "\n" + bodyStart @@ -149,18 +150,21 @@ else if ("tr".equals(parent)) { if ("basefont".equals(parent) || "base".equals(parent) || "isindex".equals(parent)) { - pageHtml = "\n" + pageHtml = DOCTYPE_HTML + + "\n" + "<" + parent + " id='outer'><" + child + ">\n" + "\n" + ""; } else if ("head".equals(parent)) { - pageHtml = "<" + child + ">\n" + pageHtml = DOCTYPE_HTML + + "<" + child + ">\n" + "\n" + ""; } else if ("title".equals(parent)) { - pageHtml = "\n" + pageHtml = DOCTYPE_HTML + + "\n" + "<" + child + ">\n" + "</head><body>\n" + "</body></html>"; diff --git a/src/test/java/org/htmlunit/general/huge/HostParentOf.java b/src/test/java/org/htmlunit/general/huge/HostParentOf.java index b613c91a0da..feb1838a719 100644 --- a/src/test/java/org/htmlunit/general/huge/HostParentOf.java +++ b/src/test/java/org/htmlunit/general/huge/HostParentOf.java @@ -22,7 +22,6 @@ import org.htmlunit.TestCaseTest; import org.htmlunit.WebDriverTestCase; -import org.htmlunit.html.HtmlPageTest; import org.htmlunit.junit.BrowserParameterizedRunner.Default; import org.htmlunit.junit.annotation.Alerts; import org.junit.After; @@ -91,7 +90,7 @@ public void isParentOf() throws Exception { * @throws Exception if an error occurs */ protected void test(final String parent, final String child) throws Exception { - final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + final String html = DOCTYPE_HTML + "<html>\n" + "<head>\n" + "<title>-\n" diff --git a/src/test/java/org/htmlunit/general/huge/HostParentOfDTest.java b/src/test/java/org/htmlunit/general/huge/HostParentOfDTest.java index f708116b521..8c7367cc9b4 100644 --- a/src/test/java/org/htmlunit/general/huge/HostParentOfDTest.java +++ b/src/test/java/org/htmlunit/general/huge/HostParentOfDTest.java @@ -3996,11 +3996,7 @@ public void _EventTarget_StereoPannerNode() throws Exception { * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "false", - CHROME = "true", - EDGE = "true") - @HtmlUnitNYI(CHROME = "false", - EDGE = "false") + @Alerts("false") public void _EventTarget_StorageManager() throws Exception { test("EventTarget", "StorageManager"); } diff --git a/src/test/java/org/htmlunit/html/BaseFrameElement2Test.java b/src/test/java/org/htmlunit/html/BaseFrameElement2Test.java index f148ea22ea1..e408c086d31 100644 --- a/src/test/java/org/htmlunit/html/BaseFrameElement2Test.java +++ b/src/test/java/org/htmlunit/html/BaseFrameElement2Test.java @@ -36,8 +36,8 @@ public class BaseFrameElement2Test extends WebDriverTestCase { @Test @Alerts("posted called") public void windowEventListenersContainer() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + " \n" + "\n" @@ -60,7 +60,8 @@ public void clickOnFocus() throws Exception { @Test @Alerts({"click", "click", "dblclick"}) public void dblClick() throws Exception { - final String content = "\n" + final String content = DOCTYPE_HTML + + "\n" + "\n" + "\n" diff --git a/src/test/java/org/htmlunit/html/DomNodeListTest.java b/src/test/java/org/htmlunit/html/DomNodeListTest.java index 4cc71b42306..1ee0ca57401 100644 --- a/src/test/java/org/htmlunit/html/DomNodeListTest.java +++ b/src/test/java/org/htmlunit/html/DomNodeListTest.java @@ -36,8 +36,8 @@ public class DomNodeListTest extends SimpleWebTestCase { */ @Test public void getElementsByTagName() throws Exception { - final String firstContent - = "First\n" + final String firstContent = DOCTYPE_HTML + + "First\n" + "\n" + "
\n" + "
a
b
c
\n" @@ -61,8 +61,8 @@ public void getElementsByTagName() throws Exception { */ @Test public void getChildNodes() throws Exception { - final String firstContent - = "First\n" + final String firstContent = DOCTYPE_HTML + + "First\n" + "\n" + "
\n" + "
a
b
c
\n" diff --git a/src/test/java/org/htmlunit/html/DomNodeTest.java b/src/test/java/org/htmlunit/html/DomNodeTest.java index 3916fc8a99b..94b76231985 100644 --- a/src/test/java/org/htmlunit/html/DomNodeTest.java +++ b/src/test/java/org/htmlunit/html/DomNodeTest.java @@ -47,7 +47,7 @@ public class DomNodeTest extends SimpleWebTestCase { */ @Test public void elementHasAttributesWith() throws Exception { - final String content = "text"; + final String content = DOCTYPE_HTML + "text"; final HtmlPage page = loadPage(content); final DomNode node = page.getElementById("tag"); @@ -60,7 +60,7 @@ public void elementHasAttributesWith() throws Exception { */ @Test public void elementHasAttributesNone() throws Exception { - final String content = "text"; + final String content = DOCTYPE_HTML + "text"; final HtmlPage page = loadPage(content); final DomNode node = page.getElementById("tag"); @@ -74,7 +74,7 @@ public void elementHasAttributesNone() throws Exception { */ @Test public void nonElementHasAttributes() throws Exception { - final String content = "text"; + final String content = DOCTYPE_HTML + "text"; final HtmlPage page = loadPage(content); final DomNode node = page.getElementById("tag"); @@ -88,7 +88,7 @@ public void nonElementHasAttributes() throws Exception { */ @Test public void nonElementGetPrefix() throws Exception { - final String content = "text"; + final String content = DOCTYPE_HTML + "text"; final HtmlPage page = loadPage(content); final DomNode node = page.getElementById("tag"); @@ -102,7 +102,7 @@ public void nonElementGetPrefix() throws Exception { */ @Test public void nonElementGetNamespaceURI() throws Exception { - final String content = "text"; + final String content = DOCTYPE_HTML + "text"; final HtmlPage page = loadPage(content); final DomNode node = page.getElementById("tag"); @@ -116,7 +116,7 @@ public void nonElementGetNamespaceURI() throws Exception { */ @Test public void nonElementGetLocalName() throws Exception { - final String content = "text"; + final String content = DOCTYPE_HTML + "text"; final HtmlPage page = loadPage(content); final DomNode node = page.getElementById("tag"); @@ -130,7 +130,7 @@ public void nonElementGetLocalName() throws Exception { */ @Test public void nonElementSetPrefix() throws Exception { - final String content = "text"; + final String content = DOCTYPE_HTML + "text"; final HtmlPage page = loadPage(content); final DomNode node = page.getElementById("tag"); @@ -144,8 +144,8 @@ public void nonElementSetPrefix() throws Exception { */ @Test public void removeAllChildren() throws Exception { - final String content - = "\n" + final String content = DOCTYPE_HTML + + "\n" + "

\n" + "\n" + "\n" @@ -162,8 +162,8 @@ public void removeAllChildren() throws Exception { */ @Test public void replace() throws Exception { - final String content - = "\n" + final String content = DOCTYPE_HTML + + "\n" + "

"; final HtmlPage page = loadPage(content); @@ -202,8 +202,8 @@ public void replace() throws Exception { */ @Test public void getNewNodeById() throws Exception { - final String content - = "\n" + final String content = DOCTYPE_HTML + + "\n" + "
"; final HtmlPage page = loadPage(content); @@ -242,8 +242,8 @@ public void getNewNodeById() throws Exception { */ @Test public void appendChild() throws Exception { - final String content - = "\n" + final String content = DOCTYPE_HTML + + "\n" + "

"; final HtmlPage page = loadPage(content); @@ -272,8 +272,8 @@ public void appendChild() throws Exception { */ @Test public void insertBefore() throws Exception { - final String content - = "\n" + final String content = DOCTYPE_HTML + + "\n" + "

"; final HtmlPage page = loadPage(content); @@ -320,8 +320,8 @@ private static int readPositionAmongParentChildren(final DomNode node) { */ @Test public void getByXPath() throws Exception { - final String htmlContent - = "\n" + final String htmlContent = DOCTYPE_HTML + + "\n" + " \n" + " my title\n" + " " @@ -362,8 +362,8 @@ public void getByXPath() throws Exception { */ @Test public void getByXPathSelectedNode() throws Exception { - final String htmlContent - = "\n" + final String htmlContent = DOCTYPE_HTML + + "\n" + " \n" + " my title\n" + " " @@ -388,7 +388,8 @@ public void getByXPathSelectedNode() throws Exception { */ @Test public void getByXPath_trim_namespace() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "
bla
\n" + ""; @@ -404,8 +405,8 @@ public void getByXPath_trim_namespace() throws Exception { */ @Test public void getFirstByXPathDisplayNone() throws Exception { - final String htmlContent - = "\n" + final String htmlContent = DOCTYPE_HTML + + "\n" + " \n" + " my title\n" + " " @@ -429,8 +430,8 @@ public void getFirstByXPathDisplayNone() throws Exception { */ @Test public void getFirstByXPath() throws Exception { - final String htmlContent - = "my title\n" + final String htmlContent = DOCTYPE_HTML + + "my title\n" + "
  • foo 1
  • foo 2
\n" + "
bla
\n" + ""; @@ -459,7 +460,8 @@ public void getFirstByXPath() throws Exception { */ @Test public void getHtmlElementDescendantsOrder() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + "\n" @@ -489,8 +491,8 @@ public void getHtmlElementDescendantsOrder() throws Exception { */ @Test public void getDescendants_remove() throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + "
a
b
a
c
a
d
\n" + ""; final HtmlPage page = loadPage(html); @@ -528,8 +530,8 @@ List getCollectedValues() { */ @Test public void domChangeListenerTestImpl_insertBefore() throws Exception { - final String htmlContent - = "foo\n" + final String htmlContent = DOCTYPE_HTML + + "foo\n" + "\n" + final String htmlContent = DOCTYPE_HTML + + "\n" + "a1\n" + "a2\n" + "a3\n" @@ -349,7 +349,8 @@ public void click_javascriptUrl_encoded() throws Exception { */ @Test public void openLinkInNewWindow() throws Exception { - final String htmlContent = "foo\n" + final String htmlContent = DOCTYPE_HTML + + "foo\n" + "link to foo1\n" + ""; @@ -378,11 +379,12 @@ public void openLinkInNewWindow() throws Exception { */ @Test public void correctLinkTargetWhenOnclickOpensWindow() throws Exception { - final String firstContent = "First\n" + final String firstContent = DOCTYPE_HTML + + "First\n" + "X\n" + ""; - final String html2 = "Second"; - final String htmlPopup = "Popup"; + final String html2 = DOCTYPE_HTML + "Second"; + final String htmlPopup = DOCTYPE_HTML + "Popup"; final WebClient client = getWebClient(); final List collectedAlerts = new ArrayList<>(); @@ -410,8 +412,8 @@ public void correctLinkTargetWhenOnclickOpensWindow() throws Exception { */ @Test public void preventDefault1() throws Exception { - final String html = - "\n" @@ -465,16 +466,16 @@ public void innerHtmlHrefQuotedEvenInIE() throws Exception { */ @Test public void click() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + "foo\n" + "\n" + "link to foo1\n" + "link to foo2\n" + ""; - final String secondContent - = "Second"; + final String secondContent = DOCTYPE_HTML + + "Second"; final MockWebConnection webConnection = getMockWebConnection(); webConnection.setDefaultResponse(secondContent); @@ -497,8 +498,8 @@ public void click() throws Exception { */ @Test public void clickAnchorName() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + "foo\n" + "\n" + " link to foo1\n" @@ -519,8 +520,8 @@ public void clickAnchorName() throws Exception { @Test @Alerts({"", "#anchor", "#!bang"}) public void dontReloadHashBang() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + " link1\n" @@ -560,8 +561,8 @@ public void dontReloadHashBang() throws Exception { @Test @Alerts({"#!board/WebDev", "#!article/WebDev/35", "#!article/WebDev/35"}) public void dontReloadHashBang2() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + " link1\n" @@ -606,8 +607,8 @@ public void dontReloadHashBang2() throws Exception { FF = {"click", "href", "click", "href", "doubleClick"}, FF_ESR = {"click", "href", "click", "href", "doubleClick"}) public void doubleClick() throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + " \n" @@ -415,8 +424,8 @@ public void click_javascriptUrlMixedCase() throws Exception { getMockWebConnection().setResponse(urlImage, directBytes, 200, "ok", "image/jpg", Collections.emptyList()); } - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + " \n" @@ -456,8 +465,8 @@ public void click_javascriptUrlLeadingWhitespace() throws Exception { getMockWebConnection().setResponse(urlImage, directBytes, 200, "ok", "image/jpg", Collections.emptyList()); } - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + " \n" @@ -497,8 +506,8 @@ public void thisInJavascriptHref() throws Exception { getMockWebConnection().setResponse(urlImage, directBytes, 200, "ok", "image/jpg", Collections.emptyList()); } - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + " \n" diff --git a/src/test/java/org/htmlunit/html/HtmlAttrTest.java b/src/test/java/org/htmlunit/html/HtmlAttrTest.java index a25e61dfb15..55020f7c18e 100644 --- a/src/test/java/org/htmlunit/html/HtmlAttrTest.java +++ b/src/test/java/org/htmlunit/html/HtmlAttrTest.java @@ -128,7 +128,8 @@ public void getParent() { */ @Test public void nodeType() throws Exception { - final String content = "foo\n" @@ -657,7 +666,8 @@ public void firingOnchange() throws Exception { @Test @Alerts({"true", "true"}) public void nonZeroWidthHeight() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "
\n" + "\n" + "Click me\n" + ""; - final String secondHtml = "Second"; + final String secondHtml = DOCTYPE_HTML + "Second"; final WebClient client = getWebClientWithMockWebConnection(); final List collectedAlerts = new ArrayList<>(); @@ -542,8 +542,8 @@ public void submit_AnchorCausesSubmit_onSubmitHandler_returnFalse() throws Excep */ @Test public void submit_CheckboxClicked() throws Exception { - final String html - = "foo\n" + final String html = DOCTYPE_HTML + + "foo\n" + "\n" + "\n" + ""; - final String secondHtml = "\n" + final String secondHtml = DOCTYPE_HTML + + "\n" + "\n" @@ -73,7 +75,8 @@ public void crossFrameJavascript() throws Exception { @HtmlUnitNYI(CHROME = "1", EDGE = "1") public void iframeOnloadCalledOnlyOnce() throws Exception { - final String firstHtml = "\n" + final String firstHtml = DOCTYPE_HTML + + "\n" + "\n" + ""; @@ -90,7 +93,8 @@ public void iframeOnloadCalledOnlyOnce() throws Exception { @Test @Alerts("1") public void iframeOnloadAboutBlank() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + ""; @@ -114,12 +118,14 @@ public void postponeLoading() throws Exception { + " \n" + ""; - final String secondHtml = "\n" + final String secondHtml = DOCTYPE_HTML + + "\n" + "\n" + "

second

\n" + ""; - final String thirdHtml = "\n" + final String thirdHtml = DOCTYPE_HTML + + "\n" + "\n" + "
\n" + " \n" @@ -145,12 +151,14 @@ public void frameOnload() throws Exception { + " \n" + ""; - final String secondHtml = "\n" + final String secondHtml = DOCTYPE_HTML + + "\n" + "\n" + "

second

\n" + ""; - final String thirdHtml = "\n" + final String thirdHtml = DOCTYPE_HTML + + "\n" + "\n" + "

third

\n" + ""; @@ -175,7 +183,8 @@ public void frameOnloadFrameInFrame() throws Exception { + " \n" + ""; - final String secondHtml = "\n" + final String secondHtml = DOCTYPE_HTML + + "\n" + "\n" + "

second

\n" + ""; @@ -184,7 +193,8 @@ public void frameOnloadFrameInFrame() throws Exception { + " \n" + ""; - final String fourthHtml = "\n" + final String fourthHtml = DOCTYPE_HTML + + "\n" + "\n" + "

fourth

\n" + ""; @@ -207,7 +217,8 @@ public void frameOnloadFrameInFrame() throws Exception { @Test @Alerts("myInputName") public void iframeContentNotLoaded() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "FooBar\n" + "\n" + "\n" @@ -248,16 +259,18 @@ public void iframeContentNotLoaded() throws Exception { @Test @Alerts("foo") public void onloadInNavigatedFrame() throws Exception { - final String html = "first\n" + final String html = DOCTYPE_HTML + + "first\n" + "\n" + " \n" + ""; - final String firstHtml = "\n" + final String firstHtml = DOCTYPE_HTML + + "\n" + "hello\n" + ""; - final String secondHtml = ""; + final String secondHtml = DOCTYPE_HTML + ""; final MockWebConnection webConnection = getMockWebConnection(); webConnection.setResponse(new URL(URL_FIRST, "frame1.html"), firstHtml); @@ -277,8 +290,8 @@ public void onloadInNavigatedFrame() throws Exception { @Test @Alerts("loaded") public void lineBreaksInUrl() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "Test\n" + ""; @@ -286,8 +299,8 @@ public void lineBreaksInUrl() throws Exception { getMockWebConnection().setResponse(new URL(URL_SECOND, "abcd"), html); expandExpectedAlertsVariables(URL_SECOND); - final String frame - = "\n" + final String frame = DOCTYPE_HTML + + "\n" + " \n" + " \n" + " "; @@ -302,8 +315,8 @@ public void lineBreaksInUrl() throws Exception { @Test @Alerts("loaded") public void lineBreaksInUrlIFrame() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "Test\n" + ""; @@ -311,8 +324,8 @@ public void lineBreaksInUrlIFrame() throws Exception { getMockWebConnection().setResponse(new URL(URL_SECOND, "abcd"), html); expandExpectedAlertsVariables(URL_SECOND); - final String frame - = "\n" + final String frame = DOCTYPE_HTML + + "\n" + " \n" + " \n" + " \n" diff --git a/src/test/java/org/htmlunit/html/HtmlFrameSetTest.java b/src/test/java/org/htmlunit/html/HtmlFrameSetTest.java index 6c144cffb4e..6f82c6316e5 100644 --- a/src/test/java/org/htmlunit/html/HtmlFrameSetTest.java +++ b/src/test/java/org/htmlunit/html/HtmlFrameSetTest.java @@ -46,8 +46,8 @@ public class HtmlFrameSetTest extends SimpleWebTestCase { */ @Test public void loadingFrameSet() throws Exception { - final String firstContent - = "First\n" + final String firstContent = DOCTYPE_HTML + + "First\n" + "\n" + " \n" + " \n" @@ -56,8 +56,8 @@ public void loadingFrameSet() throws Exception { + " \n" + "\n" + ""; - final String secondContent = "Second"; - final String thirdContent = "Third"; + final String secondContent = DOCTYPE_HTML + "Second"; + final String thirdContent = DOCTYPE_HTML + "Third"; final WebClient webClient = getWebClientWithMockWebConnection(); @@ -84,13 +84,13 @@ public void loadingFrameSet() throws Exception { */ @Test public void loadingIFrames() throws Exception { - final String firstContent - = "First\n" + final String firstContent = DOCTYPE_HTML + + "First\n" + "\n" + " \n" + " \n" + "\n" + ""; - final String rightFrame = "Right Frame\n" + final String rightFrame = DOCTYPE_HTML + + "Right Frame\n" + "
Body of right frame
\n" + ""; - final String leftFrame = "Left Frame\n" + final String leftFrame = DOCTYPE_HTML + + "Left Frame\n" + "\n" + "
Body of left frame
\n" + " Click link\n" @@ -122,11 +127,13 @@ public void targetResolution() throws Exception { + "\n" + ""; - final String innerFrame = "Inner Frame\n" + final String innerFrame = DOCTYPE_HTML + + "Inner Frame\n" + "
Body of inner frame
\n" + ""; - final String newInnerFrame = "New inner Frame\n" + final String newInnerFrame = DOCTYPE_HTML + + "New inner Frame\n" + "
Body of new inner frame
\n" + ""; @@ -184,15 +191,15 @@ public void targetResolution() throws Exception { @Test @Alerts("2") public void scriptUnderIFrame() throws Exception { - final String firstContent - = "\n" + final String firstContent = DOCTYPE_HTML + + "\n" + "\n" + ""; - final String secondContent - = ""; + final String secondContent = DOCTYPE_HTML + + ""; final String thirdContent = "alert('3');"; getMockWebConnection().setResponse(URL_SECOND, secondContent); @@ -213,8 +220,8 @@ public void scriptUnderIFrame() throws Exception { EDGE = "about://unsupported") @NotYetImplemented({CHROME, EDGE}) public void aboutSrc() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + ""; - final String secondContent = "Second"; - final String thirdContent = "Third"; + final String secondContent = DOCTYPE_HTML + "Second"; + final String thirdContent = DOCTYPE_HTML + "Third"; final WebClient client = getWebClientWithMockWebConnection(); final MockWebConnection webConnection = getMockWebConnection(); @@ -196,8 +197,8 @@ public void setSrcAttribute_ViaJavaScript() throws Exception { */ @Test public void frameCloneDoesNotReloadFrame() throws Exception { - final String html1 = ""; - final String html2 = "abc"; + final String html1 = DOCTYPE_HTML + ""; + final String html2 = DOCTYPE_HTML + "abc"; final WebClient client = getWebClientWithMockWebConnection(); @@ -218,11 +219,11 @@ public void frameCloneDoesNotReloadFrame() throws Exception { */ @Test public void frameWriteDoesNotReloadFrame() throws Exception { - final String html1 = - "\n" + final String html1 = DOCTYPE_HTML + + "\n" + "\n" + ""; - final String html2 = "iframe content"; + final String html2 = DOCTYPE_HTML + "iframe content"; final WebClient client = getWebClientWithMockWebConnection(); @@ -247,8 +248,8 @@ public void frameWriteDoesNotReloadFrame() throws Exception { */ @Test public void frameSetInnerHtmlDoesLoadFrame() throws Exception { - final String html1 = - "\n" + final String html1 = DOCTYPE_HTML + + "\n" + "';\n" + "\n" + "\n" + ""; - final String html2 = "iframe content"; - final String html3 = "Third content"; + final String html2 = DOCTYPE_HTML + "iframe content"; + final String html3 = DOCTYPE_HTML + "Third content"; final WebClient client = getWebClientWithMockWebConnection(); @@ -289,8 +290,8 @@ public void frameSetInnerHtmlDoesLoadFrame() throws Exception { */ @Test public void frameSetInnerHtmlDoesLoadFrameContentTimeout() throws Exception { - final String html1 = - "\n" + final String html1 = DOCTYPE_HTML + + "\n" + "';\n" + "\n" + "\n" + ""; - final String html2 = "iframe content"; - final String html3 = "Third content"; + final String html2 = DOCTYPE_HTML + "iframe content"; + final String html3 = DOCTYPE_HTML + "Third content"; final WebClient client = getWebClientWithMockWebConnection(); @@ -339,8 +340,8 @@ public void frameSetInnerHtmlDoesLoadFrameContentTimeout() throws Exception { */ @Test public void frameContentCreationViaJavascript() throws Exception { - final String html = - "frames\n" + final String html = DOCTYPE_HTML + + "frames\n" + "\n" + "\n" + "\n" @@ -82,8 +82,8 @@ public void onchangeDirectCall() throws Exception { @Test @Alerts({"function handler() {}", "null"}) public void onchangeNull() throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" @@ -133,8 +133,8 @@ public void testJavaScript() throws Exception { */ @Test public void formValues() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "
row 1
row 2
\n" + ""; @@ -467,7 +481,8 @@ private void testGetFullQualifiedUrl_WithBase(final String baseProtocol, final S throws Exception { final String baseUrl = baseProtocol + "://second" + basePortPart; - final String htmlContent = "foo\n" + final String htmlContent = DOCTYPE_HTML + + "foo\n" + "\n" + "\n" + "

\n" @@ -490,7 +505,7 @@ private void testGetFullQualifiedUrl_WithBase(final String baseProtocol, final S */ @Test(expected = MalformedURLException.class) public void getFullQualifiedUrl_invalid() throws Exception { - final String htmlContent = ""; + final String htmlContent = DOCTYPE_HTML + ""; final HtmlPage page = loadPage(htmlContent); page.getFullyQualifiedUrl("http://"); @@ -501,7 +516,8 @@ public void getFullQualifiedUrl_invalid() throws Exception { */ @Test public void testBase_Multiple() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + "\n" @@ -536,7 +552,8 @@ public void notify(final String message, final Object origin) { */ @Test public void testBase_InsideBody() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + " \n" + " link\n" + ""; @@ -558,7 +575,8 @@ public void testBase_InsideBody() throws Exception { */ @Test public void onLoadHandler_BodyStatement() throws Exception { - final String htmlContent = "foo\n" + final String htmlContent = DOCTYPE_HTML + + "foo\n" + "\n" + ""; final List collectedAlerts = new ArrayList<>(); @@ -575,7 +593,8 @@ public void onLoadHandler_BodyStatement() throws Exception { */ @Test public void onLoadHandler_TwoBodyStatements() throws Exception { - final String htmlContent = "foo\n" + final String htmlContent = DOCTYPE_HTML + + "foo\n" + "\n" + ""; final List collectedAlerts = new ArrayList<>(); @@ -592,7 +611,8 @@ public void onLoadHandler_TwoBodyStatements() throws Exception { */ @Test public void onLoadHandler_BodyName() throws Exception { - final String htmlContent = "foo\n" + final String htmlContent = DOCTYPE_HTML + + "foo\n" + "\n" + ""; @@ -610,7 +630,8 @@ public void onLoadHandler_BodyName() throws Exception { */ @Test public void onLoadHandler_BodyName_NotAFunction() throws Exception { - final String htmlContent = "foo\n" + final String htmlContent = DOCTYPE_HTML + + "foo\n" + "\n" + "\n" + ""; @@ -630,7 +651,8 @@ public void onLoadHandler_BodyName_NotAFunction() throws Exception { */ @Test public void onLoadHandler_ScriptName() throws Exception { - final String htmlContent = "foo\n" + final String htmlContent = DOCTYPE_HTML + + "foo\n" + "\n" + "\n" + "

helloworld &amp; helloall

\n" @@ -1092,7 +1132,8 @@ public void asXml2() throws Exception { @Test public void asXml_unicode() throws Exception { final String unicodeString = "\u064A\u0627 \u0644\u064A\u064A\u0644"; - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "" + unicodeString + ""; @@ -1113,7 +1154,8 @@ public void asXml_unicode() throws Exception { */ @Test public void asXml_noscript() throws Exception { - final String html = "" + final String html = DOCTYPE_HTML + + "" + "" + "" + ""; @@ -1137,7 +1179,8 @@ public void asXml_noscript() throws Exception { */ @Test public void getElementsById() throws Exception { - final String html = "" + final String html = DOCTYPE_HTML + + "" + "
foo
" + "
" + "
" @@ -1163,7 +1206,8 @@ public void getElementsById() throws Exception { */ @Test public void getElementsByName() throws Exception { - final String html = "
foo
"; + final String html = DOCTYPE_HTML + + "
foo
"; final HtmlPage page = loadPage(html); assertEquals(1, page.getElementsByName("a").size()); assertEquals(2, page.getElementsByName("b").size()); @@ -1183,7 +1227,8 @@ public void getElementsByName() throws Exception { */ @Test public void getElementByName() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "
foo
\n" + "
bar
\n" + "
baz
"; @@ -1200,7 +1245,8 @@ public void getElementByName() throws Exception { */ @Test(expected = ElementNotFoundException.class) public void getElementByNameNotfound() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "
foo
\n" + "
bar
\n" + "
baz
"; @@ -1213,8 +1259,9 @@ public void getElementByNameNotfound() throws Exception { */ @Test public void getHtmlElementsByIdAndOrName() throws Exception { - final String html = "
foo
bar
" - + "
bar
"; + final String html = DOCTYPE_HTML + + "
foo
bar
" + + "
bar
"; final HtmlPage page = loadPage(html); assertEquals(1, page.getElementsByIdAndOrName("a").size()); assertEquals(2, page.getElementsByIdAndOrName("b").size()); @@ -1236,8 +1283,8 @@ public void getHtmlElementsByIdAndOrName() throws Exception { */ @Test public void getHtmlElementByIdAfterRemove() throws Exception { - final String htmlContent - = "foo\n" + final String htmlContent = DOCTYPE_HTML + + "foo\n" + "\n" + "
\n" + "
\n" @@ -1274,8 +1321,8 @@ public void getHtmlElementByIdAfterRemove() throws Exception { */ @Test public void getHtmlElementById_idTwice() throws Exception { - final String htmlContent - = "foo\n" + final String htmlContent = DOCTYPE_HTML + + "foo\n" + "\n" + "
foo
\n" + "bla\n" @@ -1296,7 +1343,8 @@ public void getHtmlElementById_idTwice() throws Exception { @Test @Alerts("webm=none") public void setCookieMetaTag() throws Exception { - final String content = "\n" + final String content = DOCTYPE_HTML + + "\n" + "\n" + "\n" + "\n" @@ -1325,12 +1373,12 @@ public void noSlashURL() throws Exception { } private void testNoSlashURL(final String url) throws Exception { - final String firstContent - = "\n" + final String firstContent = DOCTYPE_HTML + + "\n" + "\n" + ""; - final String secondContent = ""; + final String secondContent = DOCTYPE_HTML + ""; final WebClient client = getWebClient(); final URL secondURL = new URL("http://second/"); @@ -1360,7 +1408,7 @@ public void metaTagWithEmptyURL() throws Exception { private int nbCalls_ = 0; @Override public WebResponse getResponse(final WebRequest request) throws IOException { - String content = "\n"; + String content = DOCTYPE_HTML + "\n"; if (nbCalls_ == 0) { content += "\n"; } @@ -1387,8 +1435,8 @@ public void serialization() throws Exception { // The document.all and form.elements calls are important because they trigger the creation // of HTMLCollections, which have caused serialization problems in the past (see bug #606). - final String content = - "\n" + final String content = DOCTYPE_HTML + + "\n" + "
Hello there!
\n" + "\n" @@ -1465,8 +1513,8 @@ public void serializationLambda() throws Exception { */ @Test public void serializationStaticDomNodeList() throws Exception { - final String content = - "\n" + final String content = DOCTYPE_HTML + + "\n" + "
Hello there!
\n" + "\n" + "\n" @@ -1495,7 +1543,8 @@ public void serializationStaticDomNodeList() throws Exception { */ @Test public void clonedPageHasOwnIdMap() throws Exception { - final String content = "foo" + final String content = DOCTYPE_HTML + + "foo" + "" + "
" + ""; @@ -1529,7 +1578,8 @@ public void clonedPageHasOwnIdMap() throws Exception { */ @Test public void clonedPageHasOwnDocumentElement() throws Exception { - final String content = "foo\n" + final String content = DOCTYPE_HTML + + "foo\n" + "\n" + "
\n" + ""; @@ -1547,8 +1597,8 @@ public void clonedPageHasOwnDocumentElement() throws Exception { */ @Test public void htmlAttributeChangeListener_AddAttribute() throws Exception { - final String htmlContent - = "foo\n" + final String htmlContent = DOCTYPE_HTML + + "foo\n" + "\n" + ""; @@ -1852,8 +1908,8 @@ public void srcJavaScript() throws Exception { */ @Test public void asNormalizedText() throws Exception { - final String htmlContent - = "test\n" + final String htmlContent = DOCTYPE_HTML + + "test\n" + "\n" + "\n" + "
a
"; @@ -1867,8 +1923,8 @@ public void asNormalizedText() throws Exception { */ @Test public void getElementsByTagName() throws Exception { - final String firstContent - = "First\n" + final String firstContent = DOCTYPE_HTML + + "First\n" + "\n" + "
\n" + "
a
b
c
\n" @@ -1907,8 +1963,8 @@ public void getElementsByTagName() throws Exception { */ @Test public void readyState() throws Exception { - final String htmlContent - = "test\n" + final String htmlContent = DOCTYPE_HTML + + "test\n" + "\n" + "\n" + "
a
"; @@ -1922,7 +1978,8 @@ public void readyState() throws Exception { */ @Test public void cloneNode() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "foo\n" + "\n" + "

hello world

\n" @@ -1938,16 +1995,16 @@ public void cloneNode() throws Exception { */ @Test public void cloneHtmlPageWithFrame() throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "
" + " " + "
" + ""; - final String frameContent = - "\n" + final String frameContent = DOCTYPE_HTML + + "\n" + "\n" + "" + "

frame1

" @@ -2024,8 +2081,8 @@ public void addAutoCloseableNull() throws Exception { */ @Test public void getBaseUrl() throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "body\n" + ""; diff --git a/src/test/java/org/htmlunit/html/HtmlPageTest5.java b/src/test/java/org/htmlunit/html/HtmlPageTest5.java index 8d44ea29644..fbd5182d306 100644 --- a/src/test/java/org/htmlunit/html/HtmlPageTest5.java +++ b/src/test/java/org/htmlunit/html/HtmlPageTest5.java @@ -37,7 +37,8 @@ public class HtmlPageTest5 extends SimpleWebTestCase { @Test @Alerts({"focus-0", "blur-0", "focus-1", "blur-1", "focus-2"}) public void tabNext() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "First\n" + "\n" + "\n" @@ -69,7 +70,8 @@ public void tabNext() throws Exception { @Test @Alerts({"focus-2", "blur-2", "focus-1", "blur-1", "focus-0"}) public void tabPrevious() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "First\n" + "\n" + "\n" @@ -100,7 +102,8 @@ public void tabPrevious() throws Exception { */ @Test public void keyboard_NoTabbableElements() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "First\n" + "\n" + "\n" @@ -138,7 +141,8 @@ public void keyboard_NoTabbableElements() throws Exception { @Test @Alerts({"focus-0", "blur-0", "focus-0"}) public void keyboard_OneTabbableElement() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "First\n" + "\n" + "\n" @@ -184,7 +188,8 @@ public void keyboard_OneTabbableElement() throws Exception { @Test @Alerts({"focus-0", "blur-0", "focus-2", "blur-2", "focus-1"}) public void accessKeys() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "First\n" + "\n" + "\n" @@ -216,7 +221,8 @@ public void accessKeys() throws Exception { @Test @Alerts("buttonPushed") public void pressAccessKey_Button() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "First\n" + "\n" + "\n" diff --git a/src/test/java/org/htmlunit/html/HtmlParagraphTest.java b/src/test/java/org/htmlunit/html/HtmlParagraphTest.java index 4452d79c384..c0ac0b3ff0c 100644 --- a/src/test/java/org/htmlunit/html/HtmlParagraphTest.java +++ b/src/test/java/org/htmlunit/html/HtmlParagraphTest.java @@ -32,7 +32,8 @@ public class HtmlParagraphTest extends SimpleWebTestCase { */ @Test public void asXml_emptyTag() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "

\n" + ""; @@ -46,7 +47,8 @@ public void asXml_emptyTag() throws Exception { */ @Test public void asNormalizedText_getTextContent() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "

\n" + "

abc

\n" + "

$24.43

\n" diff --git a/src/test/java/org/htmlunit/html/HtmlParameterTest.java b/src/test/java/org/htmlunit/html/HtmlParameterTest.java index 1131c4bd555..20b18bed1eb 100644 --- a/src/test/java/org/htmlunit/html/HtmlParameterTest.java +++ b/src/test/java/org/htmlunit/html/HtmlParameterTest.java @@ -37,7 +37,8 @@ public class HtmlParameterTest extends WebDriverTestCase { @Test @Alerts("[object HTMLParamElement]") public void simpleScriptable() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" @@ -149,7 +152,8 @@ public void typeDoesNotChangeValueAttribute() throws Exception { @Test @Alerts({"HtmlUnit", "HtmlUnit"}) public void typeDoesNotChangeValueAttributeWithInitialValue() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + "\n" @@ -176,8 +180,8 @@ public void typeDoesNotChangeValueAttributeWithInitialValue() throws Exception { */ @Test public void preventDefault_OnKeyDown() throws Exception { - final String html = - "\n" + "\n" + "\n" @@ -271,8 +275,8 @@ public void typeOnChange() throws Exception { */ @Test public void setValueOnChange() throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + "\n" @@ -298,8 +302,8 @@ public void setValueOnChange() throws Exception { */ @Test public void setDefaultValueOnChange() throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + " \n" + "\n" @@ -570,7 +917,7 @@ public void addEventListener_NoContent() throws Exception { + ""; getMockWebConnection().setResponse(scriptUrl, (String) null, - HttpStatus.NO_CONTENT_204, HttpStatus.NO_CONTENT_204_MSG, MimeType.TEXT_JAVASCRIPT, null); + statusCode, "test", MimeType.TEXT_JAVASCRIPT, null); loadPageVerifyTitle2(html); } @@ -580,7 +927,8 @@ public void addEventListener_NoContent() throws Exception { */ @Test public void badSrcUrl() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + ""; @@ -594,7 +942,7 @@ public void badSrcUrl() throws Exception { */ @Test public void invalidJQuerySrcAttribute() throws Exception { - loadPage2(""); + loadPage2(DOCTYPE_HTML + ""); } /** @@ -603,8 +951,8 @@ public void invalidJQuerySrcAttribute() throws Exception { @Test @Alerts({"loaded", "§§URL§§abcd"}) public void lineBreaksInUrl() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + " \n" @@ -626,8 +974,8 @@ public void lineBreaksInUrl() throws Exception { @Alerts({"\u0623\u0647\u0644\u0627\u064b\u0623\u0647\u0644\u0627" + "\u064b\u0623\u0647\u0644\u0627\u064b\u0623\u0647\u0644\u0627\u064b", "§§URL§§"}) public void incorrectCharset() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + " \n" @@ -684,8 +1032,8 @@ public void onLoadOnErrorWithoutType() throws Exception { } private void onLoadOnError(final String attribs) throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + " " + "" + "abc"; @@ -878,7 +1227,8 @@ public void whitespaceInSrc() throws Exception { @Test @Alerts({"loaded", "§§URL§§"}) public void controlCharsInSrc() throws Exception { - final String html = "" + final String html = DOCTYPE_HTML + + "" + " " + "" + "abc"; @@ -900,7 +1250,8 @@ public void tabCharInSrc() throws Exception { String url = URL_SECOND.toExternalForm(); url = url.replace("http", "http\t"); - final String html = "" + final String html = DOCTYPE_HTML + + "" + " " + "" + "abc"; @@ -918,8 +1269,8 @@ public void tabCharInSrc() throws Exception { */ @Test public void emptySrc() throws Exception { - final String html1 = "abc"; - final String html2 = "abc"; + final String html1 = DOCTYPE_HTML + "abc"; + final String html2 = DOCTYPE_HTML + "abc"; loadPageWithAlerts2(html1); loadPageWithAlerts2(html2); @@ -932,7 +1283,7 @@ public void emptySrc() throws Exception { */ @Test public void noContent() throws Exception { - final String html = "\n"; @@ -965,7 +1317,8 @@ public void srcAndContent() throws Exception { */ @Test public void emptySrcAndContent() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + " \n" + " \n"; @@ -981,7 +1334,8 @@ public void emptySrcAndContent() throws Exception { */ @Test public void blankSrcAndContent() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + " \n" + " \n"; @@ -997,7 +1351,8 @@ public void blankSrcAndContent() throws Exception { */ @Test public void attribSrcAndContent() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + " \n" + " \n"; @@ -1015,7 +1370,8 @@ public void attribSrcAndContent() throws Exception { @Test @Alerts({"first script", "second script"}) public void content() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + " \n" + " \n" + " \n"; diff --git a/src/test/java/org/htmlunit/html/HtmlScriptTest.java b/src/test/java/org/htmlunit/html/HtmlScriptTest.java index c901b9f1ace..5e5f3fa758e 100644 --- a/src/test/java/org/htmlunit/html/HtmlScriptTest.java +++ b/src/test/java/org/htmlunit/html/HtmlScriptTest.java @@ -52,7 +52,8 @@ public class HtmlScriptTest extends SimpleWebTestCase { */ @Test public void badExternalScriptReference() throws Exception { - final String html = "foo\n" + final String html = DOCTYPE_HTML + + "foo\n" + "\n" + ""; @@ -89,7 +90,7 @@ public void badExternalScriptReference() throws Exception { */ @Test public void asNormalizedText() throws Exception { - final String html = ""; + final String html = DOCTYPE_HTML + ""; final HtmlPage page = loadPage(html); final HtmlScript script = page.getHtmlElementById("s"); assertEquals("", script.asNormalizedText()); @@ -101,8 +102,8 @@ public void asNormalizedText() throws Exception { @Test @Alerts("hello") public void asXml() throws Exception { - final String html - = "foo\n" + final String html = DOCTYPE_HTML + + "foo\n" + ""; @@ -122,7 +123,7 @@ public void asXml_scriptNestedInCData() throws Exception { final String script = "//"; - final String html = ""; + final String html = DOCTYPE_HTML + ""; final HtmlPage page = loadPage(html); final HtmlScript scriptElement = page.getHtmlElementById("s"); assertEquals("\r\n", @@ -136,7 +137,7 @@ public void asXml_scriptNestedInCData() throws Exception { @Test @Alerts("loaded") public void scriptCloneDoesNotReloadScript() throws Exception { - final String html = ""; + final String html = DOCTYPE_HTML + ""; final String js = "alert('loaded')"; final WebClient client = getWebClient(); @@ -178,8 +179,8 @@ public void addEventListener_error_clientDoesNotThrow() throws Exception { private void addEventListener_error(final boolean throwOnFailingStatusCode) throws Exception { final URL fourOhFour = new URL(URL_FIRST, "/404"); - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + ""; + final String html = DOCTYPE_HTML + + "Page A"; final HtmlPage page = loadPageWithAlerts(html); final HtmlScript script = page.getFirstByXPath("//script"); assertFalse(script.isDisplayed()); @@ -250,16 +253,16 @@ public void isDisplayed() throws Exception { @Test @Alerts({"First script executes", "Second page loading"}) public void changingLocationSkipsFurtherScriptsOnPage() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + "\n" + "\n" + ""; - final String secondPage - = "\n" + final String secondPage = DOCTYPE_HTML + + "\n" + "\n" + ""; diff --git a/src/test/java/org/htmlunit/html/HtmlSearchInput2Test.java b/src/test/java/org/htmlunit/html/HtmlSearchInput2Test.java index 7930ff80e24..3f8575f7175 100644 --- a/src/test/java/org/htmlunit/html/HtmlSearchInput2Test.java +++ b/src/test/java/org/htmlunit/html/HtmlSearchInput2Test.java @@ -34,8 +34,8 @@ public class HtmlSearchInput2Test extends SimpleWebTestCase { */ @Test public void patternValidation() throws Exception { - final String htmlContent - = "\n" + final String htmlContent = DOCTYPE_HTML + + "\n" + "\n" + "\n" + "
\n" @@ -64,7 +64,8 @@ public void patternValidation() throws Exception { @Test @Alerts({"true", "true", "true", "", "foo"}) public void maxLengthValidation() throws Exception { - final String htmlContent = "\n" + final String htmlContent = DOCTYPE_HTML + + "\n" + "\n" + "\n" + "\n" @@ -91,7 +92,8 @@ public void maxLengthValidation() throws Exception { @Test @Alerts({"true", "false", "true", "", "foobar"}) public void minLengthValidation() throws Exception { - final String htmlContent = "\n" + final String htmlContent = DOCTYPE_HTML + + "\n" + "\n" + "\n" + "\n" diff --git a/src/test/java/org/htmlunit/html/HtmlSearchInputTest.java b/src/test/java/org/htmlunit/html/HtmlSearchInputTest.java index 9a2f7fdc56a..57eac9e9a1c 100644 --- a/src/test/java/org/htmlunit/html/HtmlSearchInputTest.java +++ b/src/test/java/org/htmlunit/html/HtmlSearchInputTest.java @@ -31,7 +31,7 @@ * @author Marc Guillemot * @author Anton Demydenko * @author Ronald Brill -*/ + */ @RunWith(BrowserRunner.class) public class HtmlSearchInputTest extends WebDriverTestCase { @@ -40,7 +40,7 @@ public class HtmlSearchInputTest extends WebDriverTestCase { */ @Test public void type() throws Exception { - final String html = ""; + final String html = DOCTYPE_HTML + ""; final WebDriver webDriver = loadPage2(html); final WebElement input = webDriver.findElement(By.id("t")); @@ -66,10 +66,14 @@ public void type() throws Exception { assertEquals("", input.getDomProperty("value")); } + /** + * @throws Exception if an error occurs + */ @Test @Alerts({"--null", "--null", "--null"}) public void defaultValuesAfterClone() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "" @@ -292,8 +296,8 @@ public void typeOnChange() throws Exception { */ @Test public void setValueOnChange() throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + " \n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + " \n" + "\n" + "\n" @@ -71,7 +72,8 @@ public void xPathNull() throws Exception { @Test @Alerts({"4", "null"}) public void xPathUndefined() throws Exception { - final String content = "\n" + final String content = DOCTYPE_HTML + + "\n" + "\n" + "\n" @@ -98,7 +100,8 @@ public void xPathUndefined() throws Exception { @Test @Alerts({"102", "111", "111", "160", "97", "110", "100", "160", "102", "111", "111"}) public void optionText() throws Exception { - final String content = "\n" + final String content = DOCTYPE_HTML + + "\n" + "\n" + "\n" @@ -125,7 +128,8 @@ public void optionText() throws Exception { @Test @Alerts("[object HTMLParagraphElement][object HTMLDivElement]") public void pipe() throws Exception { - final String content = "\n" + final String content = DOCTYPE_HTML + + "\n" + "\n" + "\n" + "\n" @@ -155,7 +159,8 @@ public void pipe() throws Exception { @Test @Alerts("a") public void math() throws Exception { - final String content = "\n" + final String content = DOCTYPE_HTML + + "\n" + "\n" + "\n" + "\n" @@ -379,7 +384,9 @@ public void substringWithNegativeLength() throws Exception { compareStringValue("substring(\"HtmlUnit\", 2, -1)"); } - /** @throws Exception in case of problems */ + /** + * @throws Exception in case of problems + */ @Test @Alerts("''") public void substringNegativeStartWithLength() throws Exception { @@ -450,7 +457,8 @@ public void endsWithNotSupported() throws Exception { } private void compare(final String xpath) throws Exception { - final String content = "\n" + final String content = DOCTYPE_HTML + + "\n" + "\n" + "\n" + "\n" @@ -477,7 +485,8 @@ private void compare(final String xpath) throws Exception { } private void compareStringValue(final String xpath) throws Exception { - final String content = "\n" + final String content = DOCTYPE_HTML + + "\n" + "\n" + "\n" + "\n" @@ -501,7 +510,8 @@ private void compareStringValue(final String xpath) throws Exception { } private void compareBooleanValue(final String xpath) throws Exception { - final String content = "\n" + final String content = DOCTYPE_HTML + + "\n" + "\n" + "\n" + "\n" @@ -525,7 +535,8 @@ private void compareBooleanValue(final String xpath) throws Exception { } private void compareError(final String xpath) throws Exception { - final String content = "\n" + final String content = DOCTYPE_HTML + + "\n" + "\n" + "\n" + "\n" @@ -549,7 +560,8 @@ private void compareError(final String xpath) throws Exception { @Test @Alerts("mySpan") public void minimalParameters() throws Exception { - final String content = "\n" + final String content = DOCTYPE_HTML + + "\n" + "\n" + "\n" + "\n" @@ -578,7 +590,8 @@ public void minimalParameters() throws Exception { @Test @Alerts("mySpan") public void undefinedResult() throws Exception { - final String content = "\n" + final String content = DOCTYPE_HTML + + "\n" + "\n" + "\n" + "\n" @@ -608,7 +621,8 @@ public void undefinedResult() throws Exception { @Test @Alerts("TypeError") public void stringResult() throws Exception { - final String content = "\n" + final String content = DOCTYPE_HTML + + "\n" + "\n" + "\n" + "\n" @@ -638,7 +652,8 @@ public void stringResult() throws Exception { @Test @Alerts("mySpan") public void objectResult() throws Exception { - final String content = "\n" + final String content = DOCTYPE_HTML + + "\n" + "\n" + "\n" + "\n" @@ -670,7 +685,8 @@ public void objectResult() throws Exception { FF = "mySpan - myDiv - ", FF_ESR = "mySpan - myDiv - ") public void reuseResult() throws Exception { - final String content = "\n" + final String content = DOCTYPE_HTML + + "\n" + "\n" + "\n" + "\n" @@ -713,7 +729,8 @@ public void reuseResult() throws Exception { @Test @Alerts("myDiv1") public void documentEvaluateFirst() throws Exception { - final String content = "\n" + final String content = DOCTYPE_HTML + + "\n" + "\n" + "\n" + "\n" diff --git a/src/test/java/org/htmlunit/html/xpath/HtmlUnitXPathTest.java b/src/test/java/org/htmlunit/html/xpath/HtmlUnitXPathTest.java index 2cc526cd0c3..a0e1cdb81ec 100644 --- a/src/test/java/org/htmlunit/html/xpath/HtmlUnitXPathTest.java +++ b/src/test/java/org/htmlunit/html/xpath/HtmlUnitXPathTest.java @@ -49,7 +49,8 @@ public class HtmlUnitXPathTest extends SimpleWebTestCase { */ @Test public void simplePath() throws Exception { - final String content = "Test page\n" + final String content = DOCTYPE_HTML + + "Test page\n" + "foo\n" + ""; @@ -66,7 +67,8 @@ public void simplePath() throws Exception { */ @Test public void xpathFromElement() throws Exception { - final String content = "Test page\n" + final String content = DOCTYPE_HTML + + "Test page\n" + "foo\n" + ""; @@ -83,8 +85,8 @@ public void xpathFromElement() throws Exception { @Test @SuppressWarnings("unchecked") public void elementOrder() throws Exception { - final String content - = "First\n" + ""; @@ -105,8 +107,8 @@ public void elementOrder() throws Exception { */ @Test public void whenJSChangesPage() throws Exception { - final String content - = "foo"; + + loadPageVerifyTitle2(html); + } + + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("callee,length") + public void argumentsPropertyNamesStrict() throws Exception { + final String html = DOCTYPE_HTML + + "" + + ""; + + loadPageVerifyTitle2(html); + } + /** * @throws Exception if the test fails */ @Test @Alerts("2") public void passedCountDifferentFromDeclared() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + ""; + + loadPageVerifyTitle2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"true", "true"}) + public void argumentsCalleeDifferentFunctions() throws Exception { + final String html = DOCTYPE_HTML + + "" + + ""; + + loadPageVerifyTitle2(html); + } } diff --git a/src/test/java/org/htmlunit/javascript/AttributeCaseTest.java b/src/test/java/org/htmlunit/javascript/AttributeCaseTest.java index d74339b3cfd..215d0e14b9f 100644 --- a/src/test/java/org/htmlunit/javascript/AttributeCaseTest.java +++ b/src/test/java/org/htmlunit/javascript/AttributeCaseTest.java @@ -174,7 +174,8 @@ private void setupAttributeTest(final String content, final String elementId) th private void setupGetAttributeTest(final String attributeName, final String attributeValue) throws Exception { final String elementId = "p-id"; - final String content = "AttributeCaseTest\n" + final String content = DOCTYPE_HTML + + "AttributeCaseTest\n" + "

\n" + ""; @@ -187,8 +188,8 @@ private void setupSetAttributeTest( throws Exception { final String elementId = "p-id"; - final String content - = "AttributeCaseTest\n" + final String content = DOCTYPE_HTML + + "AttributeCaseTest\n" + "

\n" + "\n" + "\n" + "\n" @@ -276,8 +277,8 @@ public void externalScriptWithApostrophesInComment() throws Exception { @Test public void scriptErrorContainsPageUrl() throws Exception { // embedded script - final String content1 - = "\n" + final String content1 = DOCTYPE_HTML + + "\n" + "\n" + ""; @@ -292,8 +293,8 @@ public void scriptErrorContainsPageUrl() throws Exception { final WebClient client = getWebClient(); final MockWebConnection webConnection = new MockWebConnection(); - final String content2 - = "foo\n" + "\n" @@ -360,8 +361,8 @@ public void externalScriptEmptyGZipEncoded() throws Exception { bytes.toByteArray(), 200, "OK", "text/javascript", headers); } - final String htmlContent - = "\n" + final String htmlContent = DOCTYPE_HTML + + "\n" + "foo\n" + "\n" + "\n" @@ -388,8 +389,8 @@ public void externalScriptBrokenGZipEncoded() throws Exception { bytes.toByteArray(), 200, "OK", "text/javascript", headers); } - final String htmlContent - = "\n" + final String htmlContent = DOCTYPE_HTML + + "\n" + "foo\n" + "\n" + "\n" @@ -412,8 +413,8 @@ public void referencingVariablesFromOneScriptToAnother_Regression() throws Excep final WebClient client = getWebClient(); final MockWebConnection webConnection = new MockWebConnection(); - final String htmlContent - = "foo\n" + final String htmlContent = DOCTYPE_HTML + + "foo\n" + "\n" + "\n" + "\n" @@ -439,8 +440,8 @@ public void referencingVariablesFromOneScriptToAnother_Regression() throws Excep */ @Test public void javaScriptUrl() throws Exception { - final String htmlContent - = "\n" @@ -468,8 +469,8 @@ public void javaScriptUrl() throws Exception { */ @Test public void thisDotInOnClick() throws Exception { - final String htmlContent - = "First\n" + final String htmlContent = DOCTYPE_HTML + + "First\n" + "

\n" + ""; @@ -491,8 +492,8 @@ public void functionDefinedInExternalFile_CalledFromInlineScript() throws Except final WebClient client = getWebClient(); final MockWebConnection webConnection = new MockWebConnection(); - final String htmlContent - = "foo\n" + final String htmlContent = DOCTYPE_HTML + + "foo\n" + "\n" + " \n" + ""; @@ -529,8 +530,8 @@ public void externalScriptWithNewLineBeforeClosingScriptTag() throws Exception { final WebClient client = getWebClient(); final MockWebConnection webConnection = new MockWebConnection(); - final String htmlContent - = "foo\n" + final String htmlContent = DOCTYPE_HTML + + "foo\n" + "\n" + "\n" // \n between opening and closing tag is important + ""; @@ -558,8 +559,8 @@ public void externalScriptWithNewLineBeforeClosingScriptTag() throws Exception { */ @Test public void functionDefinedInSameFile() throws Exception { - final String htmlContent - = "First\n" + "

hello world

\n" @@ -700,8 +702,8 @@ private static String getJavaScriptContent(final String javascript) { */ @Test public void scriptErrorIsolated() throws Exception { - final String content - = "\n" + final String content = DOCTYPE_HTML + + "\n" + "\n" + "\n" + "\n" @@ -756,15 +758,15 @@ public void prototypeScope() throws Exception { } private void prototypeScope(final String name, final String value) throws Exception { - final String content1 - = "\n" + final String content1 = DOCTYPE_HTML + + "\n" + "\n" + ""; - final String content2 - = "\n" + final String content2 = DOCTYPE_HTML + + "\n" + ""; + final String content = DOCTYPE_HTML + ""; final MockWebConnection webConnection = new MockWebConnection(); webConnection.setDefaultResponse(content); client.setWebConnection(webConnection); @@ -883,22 +885,30 @@ public Object callFunction( return super.callFunction(page, javaScriptFunction, thisObject, args, htmlElementScope); } - /** @return the number of times that this engine has called functions */ + /** + * @return the number of times that this engine has called functions + */ public int getCallCount() { return scriptCallCount_; } - /** @return the number of times that this engine has executed code */ + /** + * @return the number of times that this engine has executed code + */ public int getExecutionCount() { return scriptExecutionCount_; } - /** @return the number of times that this engine has compiled code */ + /** + * @return the number of times that this engine has compiled code + */ public int getCompileCount() { return scriptCompileCount_; } - /** @return the number of times that this engine has executed a compiled script */ + /** + * @return the number of times that this engine has executed a compiled script + */ public int getExecuteScriptCount() { return scriptExecuteScriptCount_; } @@ -910,8 +920,8 @@ public int getExecuteScriptCount() { @Test @Alerts({"", "ex thrown"}) public void commentNoDoubleSlash() throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" @@ -927,7 +937,7 @@ public void commentNoDoubleSlash() throws Exception { } catch (final ScriptException e) { exceptionThrown = "ex thrown"; - assertEquals(4, e.getFailingLineNumber()); + assertEquals(5, e.getFailingLineNumber()); } assertEquals(expectedExThrown, exceptionThrown); @@ -939,14 +949,14 @@ public void commentNoDoubleSlash() throws Exception { */ @Test public void compiledScriptCached() throws Exception { - final String content1 - = "foo\n" + final String content1 = DOCTYPE_HTML + + "foo\n" + "\n" + "\n" + "to page 2\n" + ""; - final String content2 - = "page 2\n" + final String content2 = DOCTYPE_HTML + + "page 2\n" + "\n" + "\n" + ""; @@ -988,8 +998,8 @@ public void compiledScriptCached() throws Exception { */ @Test public void scriptTags_AllLocalContent() throws Exception { - final String content - = "\n" + final String content = DOCTYPE_HTML + + "\n" + "foo\n" + "\n" // no language specified - assume JavaScript + "\n" @@ -1076,7 +1086,8 @@ protected void handleJavaScriptException(final ScriptException scriptException, }; webClient.setJavaScriptEngine(myEngine); - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "Test page<\n" + "\n" @@ -1169,7 +1181,8 @@ private static ThreadLocal> getPostponedActions(final Abst @Retry @Alerts("starting") public void shutdownShouldKill() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "Test page\n" + ""; + final String html = DOCTYPE_HTML + ""; getMockWebConnection().setDefaultResponse(html); webClient.getPage(URL_FIRST); assertEquals("org.htmlunit.corejs.javascript.EvaluatorException: " - + "Unexpected end of file (script in " + URL_FIRST + " from (1, 21) to (1, 37)#1)\n", + + "Unexpected end of file (script in " + URL_FIRST + " from (2, 21) to (2, 37)#2)\n", scriptExceptions.toString()); } } diff --git a/src/test/java/org/htmlunit/javascript/JavascriptErrorListenerTest.java b/src/test/java/org/htmlunit/javascript/JavascriptErrorListenerTest.java index 1e27cb09188..ed7d5438300 100644 --- a/src/test/java/org/htmlunit/javascript/JavascriptErrorListenerTest.java +++ b/src/test/java/org/htmlunit/javascript/JavascriptErrorListenerTest.java @@ -52,11 +52,12 @@ public void nullJavaScriptErrorListener() throws Exception { webClient.getOptions().setThrowExceptionOnScriptError(false); webClient.setJavaScriptErrorListener(null); final MockWebConnection webConnection = new MockWebConnection(); - final String errorContent = "ERROR 500"; + final String errorContent = DOCTYPE_HTML + "ERROR 500"; webConnection.setResponse(URL_SECOND, errorContent, 500, "BOOM", MimeType.TEXT_HTML, Collections.emptyList()); // test script exception - String content = "Throw JavaScript Error\n" + String content = DOCTYPE_HTML + + "Throw JavaScript Error\n" + "\n" + ""; webConnection.setResponse(URL_FIRST, content); @@ -64,7 +65,8 @@ public void nullJavaScriptErrorListener() throws Exception { webClient.getPage(URL_FIRST); // test load script error - content = "Throw JavaScript Error\n" + content = DOCTYPE_HTML + + "Throw JavaScript Error\n" + "\n" + ""; webConnection.setResponse(URL_FIRST, content); @@ -77,7 +79,8 @@ public void nullJavaScriptErrorListener() throws Exception { } // test malformed script url error - content = "Throw JavaScript Error\n" + content = DOCTYPE_HTML + + "Throw JavaScript Error\n" + "\n" + ""; webConnection.setResponse(URL_FIRST, content); @@ -86,7 +89,8 @@ public void nullJavaScriptErrorListener() throws Exception { // test timeout error webClient.setJavaScriptTimeout(100); - content = "Throw JavaScript Timeout Error\n" + content = DOCTYPE_HTML + + "Throw JavaScript Timeout Error\n" + "\n" + ""; webConnection.setResponse(URL_FIRST, content); @@ -105,7 +109,8 @@ public void listenForScriptException() throws Exception { webClient.setJavaScriptErrorListener(javaScriptErrorListener); // test script exception - final String html = "Throw JavaScript Error" + final String html = DOCTYPE_HTML + + "Throw JavaScript Error" + "" + ""; loadPage(html); @@ -113,7 +118,7 @@ public void listenForScriptException() throws Exception { assertEquals("", javaScriptErrorListener.getWarnings()); assertEquals("org.htmlunit.ScriptException: " + "ReferenceError: \"unknown\" is not defined. " - + "(script in http://localhost:" + PORT + "/ from (1, 58) to (1, 81)#1)", + + "(script in http://localhost:" + PORT + "/ from (2, 58) to (2, 81)#2)", javaScriptErrorListener.getScriptExceptions()); assertEquals("", javaScriptErrorListener.getLoadScriptErrors()); assertEquals("", javaScriptErrorListener.getMalformedScriptURLErrors()); @@ -133,7 +138,8 @@ public void listenForLoadScriptError() throws Exception { getMockWebConnection().setDefaultResponse("", 500, "Server Error", MimeType.TEXT_HTML); - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + ""; @@ -165,7 +171,8 @@ public void listenForMalformedScriptUrl() throws Exception { final CollectingJavaScriptErrorListener javaScriptErrorListener = new CollectingJavaScriptErrorListener(); webClient.setJavaScriptErrorListener(javaScriptErrorListener); - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "Throw JavaScript Error\n" + "\n" + "\n" @@ -195,7 +202,8 @@ public void listenForTimeoutError() throws Exception { webClient.setJavaScriptErrorListener(javaScriptErrorListener); webClient.setJavaScriptTimeout(100); - final String html = "Throw JavaScript Timeout Error\n" + final String html = DOCTYPE_HTML + + "Throw JavaScript Timeout Error\n" + "\n" + ""; diff --git a/src/test/java/org/htmlunit/javascript/NativeArrayTest.java b/src/test/java/org/htmlunit/javascript/NativeArrayTest.java index f534f4f78fc..45f54bf43cb 100644 --- a/src/test/java/org/htmlunit/javascript/NativeArrayTest.java +++ b/src/test/java/org/htmlunit/javascript/NativeArrayTest.java @@ -44,8 +44,8 @@ public class NativeArrayTest extends WebDriverTestCase { @HtmlUnitNYI(FF = {"5<>1", "2<>5", "2<>5", "2<>1", "1<>2", "1<>1", "9<>2", "9<>5"}, FF_ESR = {"5<>1", "2<>5", "2<>5", "2<>1", "1<>2", "1<>1", "9<>2", "9<>5"}) public void sortSteps() throws Exception { - final String html - = "\n" @@ -273,8 +274,8 @@ public void constructorToString() throws Exception { @Test @Alerts({"mandarin", "", "mandarin"}) public void shiftOneElement() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" @@ -152,6 +206,9 @@ private void ctorDateTimeString(final String js) throws Exception { loadPageVerifyTitle2(html); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("2021-12-18T22:23:00.000Z") @BuggyWebDriver(FF = "2021-12-18T21:23:00.000Z", @@ -160,6 +217,9 @@ public void ctorDateTimeGMT() throws Exception { ctorDateTime("GMT"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("2021-12-18T22:23:00.000Z") @BuggyWebDriver(FF = "2021-12-18T21:23:00.000Z", @@ -168,6 +228,9 @@ public void ctorDateTimeUTC() throws Exception { ctorDateTime("UTC"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("2021-12-19T03:23:00.000Z") @BuggyWebDriver(FF = "2021-12-18T21:23:00.000Z", @@ -176,12 +239,18 @@ public void ctorDateTimeEST() throws Exception { ctorDateTime("EST"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("2021-12-18T21:23:00.000Z") public void ctorDateTimeBerlin() throws Exception { ctorDateTime("Europe/Berlin"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("2021-12-18T13:23:00.000Z") @BuggyWebDriver(FF = "2021-12-18T21:23:00.000Z", @@ -190,6 +259,9 @@ public void ctorDateTimeTokyo() throws Exception { ctorDateTime("Asia/Tokyo"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("2021-12-18T13:23:00.000Z") @BuggyWebDriver(FF = "2021-12-18T21:23:00.000Z", @@ -198,6 +270,9 @@ public void ctorDateTimeJST() throws Exception { ctorDateTime("JST"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("2021-12-19T03:23:00.000Z") @BuggyWebDriver(FF = "2021-12-18T21:23:00.000Z", @@ -207,8 +282,8 @@ public void ctorDateTimeNewYork() throws Exception { } private void ctorDateTime(final String tz) throws Exception { - final String html - = "\n" @@ -228,42 +303,63 @@ private void ctorDateTime(final String tz) throws Exception { } } + /** + * @throws Exception if the test fails + */ @Test @Alerts("2021-12-18T00:00:00.000Z") public void ctorDateGMT() throws Exception { ctorDate("GMT"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("2021-12-18T00:00:00.000Z") public void ctorDateUTC() throws Exception { ctorDate("UTC"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("2021-12-18T00:00:00.000Z") public void ctorDateEST() throws Exception { ctorDate("EST"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("2021-12-18T00:00:00.000Z") public void ctorDateBerlin() throws Exception { ctorDate("Europe/Berlin"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("2021-12-18T00:00:00.000Z") public void ctorDateNewYork() throws Exception { ctorDate("America/New_York"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("2021-12-18T00:00:00.000Z") public void ctorDateTokyo() throws Exception { ctorDate("Asia/Tokyo"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("2021-12-18T00:00:00.000Z") public void ctorDateJST() throws Exception { @@ -271,8 +367,8 @@ public void ctorDateJST() throws Exception { } private void ctorDate(final String tz) throws Exception { - final String html - = "\n" @@ -292,11 +388,14 @@ private void ctorDate(final String tz) throws Exception { } } + /** + * @throws Exception if the test fails + */ @Test @Alerts("2000-02-28T23:59:59.000Z") public void ctorInt() throws Exception { - final String html - = "\n" @@ -305,11 +404,14 @@ public void ctorInt() throws Exception { loadPageVerifyTitle2(html); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("2035-11-30T01:46:40.000Z") public void ctorDouble() throws Exception { - final String html - = "\n" @@ -318,6 +420,9 @@ public void ctorDouble() throws Exception { loadPageVerifyTitle2(html); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("12/18/2021, 10:23:00 PM") @HtmlUnitNYI(CHROME = "12/18/21, 10:23 PM", @@ -328,6 +433,9 @@ public void toLocaleEnUs() throws Exception { toLocale("new Date('2021-12-18T22:23').toLocaleString('en-US')"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("12/18/2021") @HtmlUnitNYI(CHROME = "12/18/21", @@ -338,6 +446,9 @@ public void toLocaleEnUsDate() throws Exception { toLocale("new Date('2021-12-18T22:23').toLocaleDateString('en-US')"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("10:23:00 PM") @HtmlUnitNYI(CHROME = "10:23 PM", @@ -348,6 +459,9 @@ public void toLocaleEnUsTime() throws Exception { toLocale("new Date('2021-12-18T22:23').toLocaleTimeString('en-US')"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("18.12.2021, 22:23:00") @HtmlUnitNYI(CHROME = "18.12.21, 22:23", @@ -358,6 +472,9 @@ public void toLocaleDeDe() throws Exception { toLocale("new Date('2021-12-18T22:23').toLocaleString('de-DE')"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("18.12.2021") @HtmlUnitNYI(CHROME = "18.12.21", @@ -368,6 +485,9 @@ public void toLocaleDeDeDate() throws Exception { toLocale("new Date('2021-12-18T22:23').toLocaleDateString('de-DE')"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("22:23:00") @HtmlUnitNYI(CHROME = "22:23", @@ -378,6 +498,9 @@ public void toLocaleDeDeTime() throws Exception { toLocale("new Date('2021-12-18T22:23').toLocaleTimeString('de-DE')"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("2021/12/18 22:23:00") @HtmlUnitNYI(CHROME = "2021/12/18 22:23", @@ -388,12 +511,18 @@ public void toLocaleJaJp() throws Exception { toLocale("new Date('2021-12-18T22:23').toLocaleString('ja-JP')"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("2021/12/18") public void toLocaleJaJpDate() throws Exception { toLocale("new Date('2021-12-18T22:23').toLocaleDateString('ja-JP')"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("22:23:00") @HtmlUnitNYI(CHROME = "22:23", @@ -404,6 +533,9 @@ public void toLocaleJaJpTime() throws Exception { toLocale("new Date('2021-12-18T22:23').toLocaleTimeString('ja-JP')"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("2021/12/18 22:23:00") @HtmlUnitNYI(CHROME = "2021/12/18 22:23", @@ -414,12 +546,18 @@ public void toLocaleArray() throws Exception { toLocale("new Date('2021-12-18T22:23').toLocaleString(['foo', 'ja-JP', 'en-US'])"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("2021/12/18") public void toLocaleArrayDate() throws Exception { toLocale("new Date('2021-12-18T22:23').toLocaleDateString(['foo', 'ja-JP', 'en-US'])"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("22:23:00") @HtmlUnitNYI(CHROME = "22:23", @@ -431,8 +569,8 @@ public void toLocaleArrayTime() throws Exception { } private void toLocale(final String js) throws Exception { - final String html - = "\n" @@ -452,36 +590,54 @@ private void toLocale(final String js) throws Exception { } } + /** + * @throws Exception if the test fails + */ @Test @Alerts("Sat Dec 18 2021") public void toDateStringGMT() throws Exception { toDateString("GMT"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("Sat Dec 18 2021") public void toDateStringUTC() throws Exception { toDateString("UTC"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("Sat Dec 18 2021") public void toDateStringEST() throws Exception { toDateString("EST"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("Sat Dec 18 2021") public void toDateStringBerlin() throws Exception { toDateString("Europe/Berlin"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("Sat Dec 18 2021") public void toDateStringNewYork() throws Exception { toDateString("America/New_York"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("Sun Dec 19 2021") @BuggyWebDriver(FF = "Sat Dec 18 2021", @@ -490,6 +646,9 @@ public void toDateStringTokyo() throws Exception { toDateString("Asia/Tokyo"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("Sun Dec 19 2021") @BuggyWebDriver(FF = "Sat Dec 18 2021", @@ -499,8 +658,8 @@ public void toDateStringJST() throws Exception { } private void toDateString(final String tz) throws Exception { - final String html - = "\n" @@ -520,6 +679,9 @@ private void toDateString(final String tz) throws Exception { } } + /** + * @throws Exception if the test fails + */ @Test @Alerts("22:23:00 GMT+0000 (Greenwich Mean Time)") @BuggyWebDriver(FF = "23:23:00 GMT+0100 (Central European Standard Time)", @@ -532,6 +694,9 @@ public void toTimeStringGMT() throws Exception { toTimeString("GMT"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("22:23:00 GMT+0000 (Coordinated Universal Time)") @BuggyWebDriver(FF = "23:23:00 GMT+0100 (Central European Standard Time)", @@ -544,6 +709,9 @@ public void toTimeStringUTC() throws Exception { toTimeString("UTC"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("17:23:00 GMT-0500 (Eastern Standard Time)") @BuggyWebDriver(FF = "23:23:00 GMT+0100 (Central European Standard Time)", @@ -556,6 +724,9 @@ public void toTimeStringEST() throws Exception { toTimeString("EST"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("23:23:00 GMT+0100 (Central European Standard Time)") @HtmlUnitNYI(CHROME = "23:23:00 GMT+0100 (CET)", @@ -566,6 +737,9 @@ public void toTimeStringBerlin() throws Exception { toTimeString("Europe/Berlin"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("17:23:00 GMT-0500 (Eastern Standard Time)") @BuggyWebDriver(FF = "23:23:00 GMT+0100 (Central European Standard Time)", @@ -578,6 +752,9 @@ public void toTimeStringNewYork() throws Exception { toTimeString("America/New_York"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("07:23:00 GMT+0900 (Japan Standard Time)") @BuggyWebDriver(FF = "23:23:00 GMT+0100 (Central European Standard Time)", @@ -590,6 +767,9 @@ public void toTimeStringTokyo() throws Exception { toTimeString("Asia/Tokyo"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("07:23:00 GMT+0900 (Japan Standard Time)") @BuggyWebDriver(FF = "23:23:00 GMT+0100 (Central European Standard Time)", @@ -603,8 +783,8 @@ public void toTimeStringJST() throws Exception { } private void toTimeString(final String tz) throws Exception { - final String html - = "\n" @@ -624,42 +804,63 @@ private void toTimeString(final String tz) throws Exception { } } + /** + * @throws Exception if the test fails + */ @Test @Alerts("Sat, 18 Dec 2021 22:23:00 GMT") public void toUTCStringGMT() throws Exception { toUTCString("GMT"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("Sat, 18 Dec 2021 22:23:00 GMT") public void toUTCStringUTC() throws Exception { toUTCString("UTC"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("Sat, 18 Dec 2021 22:23:00 GMT") public void toUTCStringEST() throws Exception { toUTCString("EST"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("Sat, 18 Dec 2021 22:23:00 GMT") public void toUTCStringBerlin() throws Exception { toUTCString("Europe/Berlin"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("Sat, 18 Dec 2021 22:23:00 GMT") public void toUTCStringNewYork() throws Exception { toUTCString("America/New_York"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("Sat, 18 Dec 2021 22:23:00 GMT") public void toUTCStringTokyo() throws Exception { toUTCString("Asia/Tokyo"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("Sat, 18 Dec 2021 22:23:00 GMT") public void toUTCStringJST() throws Exception { @@ -667,8 +868,8 @@ public void toUTCStringJST() throws Exception { } private void toUTCString(final String tz) throws Exception { - final String html - = "\n" @@ -688,6 +889,9 @@ private void toUTCString(final String tz) throws Exception { } } + /** + * @throws Exception if the test fails + */ @Test @Alerts("0") @BuggyWebDriver(FF = "-60", @@ -696,6 +900,9 @@ public void timezoneOffsetGMT() throws Exception { timezoneOffset("GMT"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("0") @BuggyWebDriver(FF = "-60", @@ -704,6 +911,9 @@ public void timezoneOffsetUTC() throws Exception { timezoneOffset("UTC"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("300") @BuggyWebDriver(FF = "-60", @@ -712,12 +922,18 @@ public void timezoneOffsetEST() throws Exception { timezoneOffset("EST"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("-60") public void timezoneOffsetBerlin() throws Exception { timezoneOffset("Europe/Berlin"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("300") @BuggyWebDriver(FF = "-60", @@ -726,6 +942,9 @@ public void timezoneOffsetNewYork() throws Exception { timezoneOffset("America/New_York"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("-540") @BuggyWebDriver(FF = "-60", @@ -734,6 +953,9 @@ public void timezoneOffsetTokyo() throws Exception { timezoneOffset("Asia/Tokyo"); } + /** + * @throws Exception if the test fails + */ @Test @Alerts("-540") @BuggyWebDriver(FF = "-60", @@ -743,8 +965,8 @@ public void timezoneOffsetJST() throws Exception { } private void timezoneOffset(final String tz) throws Exception { - final String html - = "\n" diff --git a/src/test/java/org/htmlunit/javascript/NativeDateTest.java b/src/test/java/org/htmlunit/javascript/NativeDateTest.java index 005e8dc2777..375ac3c171b 100644 --- a/src/test/java/org/htmlunit/javascript/NativeDateTest.java +++ b/src/test/java/org/htmlunit/javascript/NativeDateTest.java @@ -40,8 +40,8 @@ public class NativeDateTest extends WebDriverTestCase { @Test @Alerts({"-13", "84", "109"}) public void getYear() throws Exception { - final String html - = "\n" + ""; @@ -420,7 +429,8 @@ public void commaOperatorFunctionTry() throws Exception { @Test @Alerts("my y var") public void commaOperatorFunctionCall() throws Exception { - final String html = "\n" @@ -262,7 +263,8 @@ public void toStringRhinoBug538172() throws Exception { @Test @Alerts("12,345") public void toLocaleString() throws Exception { - final String html = "\n" @@ -276,7 +278,8 @@ public void toLocaleString() throws Exception { @Test @Alerts("12.345") public void toLocaleStringDe() throws Exception { - final String html = "\n" @@ -290,7 +293,8 @@ public void toLocaleStringDe() throws Exception { @Test @Alerts("12,345") public void toLocaleStringEnUS() throws Exception { - final String html = "\n" @@ -304,7 +308,8 @@ public void toLocaleStringEnUS() throws Exception { @Test @Alerts("12,345") public void toLocaleStringNoParam() throws Exception { - final String html = "\n" + "\n" @@ -254,14 +254,14 @@ public void getPrototypeOfString() throws Exception { @Test @Alerts("true") public void getPrototypeOfNumber() throws Exception { - final String html = "" + final String html = DOCTYPE_HTML + "\n" + "\n" + "\n" @@ -277,14 +277,14 @@ public void getPrototypeOfNumber() throws Exception { @Test @Alerts("true") public void getPrototypeOfBoolean() throws Exception { - final String html = "" + final String html = DOCTYPE_HTML + "\n" + "\n" + "\n" @@ -300,14 +300,14 @@ public void getPrototypeOfBoolean() throws Exception { @Test @Alerts("object") public void getTypeOfPrototypeOfNumber() throws Exception { - final String html = "" + final String html = DOCTYPE_HTML + "\n" + "\n" + "\n" @@ -323,7 +323,7 @@ public void getTypeOfPrototypeOfNumber() throws Exception { @Test @Alerts({"2", "true", "true"}) public void getOwnPropertySymbols() throws Exception { - final String html = "" + final String html = DOCTYPE_HTML + "\n" + "\n" + "\n" @@ -356,7 +356,7 @@ public void getOwnPropertySymbols() throws Exception { @Test @Alerts("TypeError") public void getOwnPropertySymbolsEmpty() throws Exception { - final String html = "" + final String html = DOCTYPE_HTML + "\n" + "\n" + "\n" @@ -383,7 +383,7 @@ public void getOwnPropertySymbolsEmpty() throws Exception { FF = {"[object HTMLInputElement]", "[object HTMLInputElement]", "[object Object]", "function"}, FF_ESR = {"[object HTMLInputElement]", "[object HTMLInputElement]", "[object Object]", "function"}) public void getOwnPropertyDescriptor() throws Exception { - final String html = "" + final String html = DOCTYPE_HTML + "\n" + "\n" + "\n" @@ -428,7 +428,8 @@ public void getOwnPropertyDescriptor() throws Exception { "x.get = function value() { [native code] }", "x.get.call = function call() { [native code] }"}) public void getOwnPropertyDescriptorGetCall() throws Exception { - final String html = "\n" + ""; - final String thirdContent = "Third"; + final String thirdContent = DOCTYPE_HTML + + "Third"; final MockWebConnection webConnection = getMockWebConnection(); webConnection.setResponse(URL_SECOND, secondContent); @@ -179,7 +184,8 @@ public void navigationStopThreadsInChildWindows() throws Exception { */ @Test public void interruptAllWithRecursiveSetTimeout() throws Exception { - final String content = "\n" + final String content = DOCTYPE_HTML + + "\n" + "\n" + " test\n" + " "); + conn.setResponse(URL_FIRST, + DOCTYPE_HTML + ""); client.setWebConnection(conn); client.getPage(URL_FIRST); diff --git a/src/test/java/org/htmlunit/javascript/configuration/JavaScriptConfigurationTest.java b/src/test/java/org/htmlunit/javascript/configuration/JavaScriptConfigurationTest.java index 7adcbb18f11..d0a1d3cf4da 100644 --- a/src/test/java/org/htmlunit/javascript/configuration/JavaScriptConfigurationTest.java +++ b/src/test/java/org/htmlunit/javascript/configuration/JavaScriptConfigurationTest.java @@ -317,7 +317,7 @@ public void clonedAndModified() throws Exception { private static void test(final BrowserVersion browserVersion) throws IOException { try (WebClient webClient = new WebClient(browserVersion)) { final MockWebConnection conn = new MockWebConnection(); - conn.setDefaultResponse(""); + conn.setDefaultResponse(DOCTYPE_HTML + ""); webClient.setWebConnection(conn); webClient.getPage("http://localhost/"); diff --git a/src/test/java/org/htmlunit/javascript/host/ActiveXObject2Test.java b/src/test/java/org/htmlunit/javascript/host/ActiveXObject2Test.java index 3a145d47829..dd0a5f600a1 100644 --- a/src/test/java/org/htmlunit/javascript/host/ActiveXObject2Test.java +++ b/src/test/java/org/htmlunit/javascript/host/ActiveXObject2Test.java @@ -37,7 +37,8 @@ public class ActiveXObject2Test extends WebDriverTestCase { @Test @Alerts({"undefined", "undefined", "NaN", "false", "No", "No", "No", "No"}) public void browserDetection() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + " \n" @@ -71,8 +71,8 @@ public void elementAttributes() throws Exception { @Test @Alerts("TypeError") public void positionAndSizeAttributes() throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + " \n" + " \n" + "
daniel
\n" @@ -85,7 +85,7 @@ public void positionAndSizeAttributes() throws Exception { + " log(box.x + '-' + box.y);\n" + " log(box.screenX + '-' + box.screenY);\n" + " log(box.width + '-' + box.height);\n" - + " } catch(e) {logEx(e)}\n" + + " } catch(e) { logEx(e) }\n" + " }\n" + " \n" + " \n" diff --git a/src/test/java/org/htmlunit/javascript/host/ClientRectListTest.java b/src/test/java/org/htmlunit/javascript/host/ClientRectListTest.java index 4eac0c40452..0eba744b518 100644 --- a/src/test/java/org/htmlunit/javascript/host/ClientRectListTest.java +++ b/src/test/java/org/htmlunit/javascript/host/ClientRectListTest.java @@ -34,8 +34,8 @@ public class ClientRectListTest extends WebDriverTestCase { @Test @Alerts({"[object DOMRectList]", "1", "[object DOMRect]", "[object DOMRect]"}) public void getClientRects() throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + ""; @@ -153,8 +153,8 @@ public void windowProperty() throws Exception { @Test @Alerts("success") public void fromWindow() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + ""; @@ -175,8 +175,8 @@ public void fromWindow() throws Exception { @Test @BuggyWebDriver public void simpleString() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + "\n" @@ -1200,7 +1221,7 @@ public void prototypConstructor() throws Exception { @Alerts({"function Element() { [native code] }", "[object Element]", "function Element() { [native code] }"}) public void prototypConstructorStandards() throws Exception { - final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + final String html = DOCTYPE_HTML + "\n" + ""; + final String html = DOCTYPE_HTML + + ""; loadPage2(html); } @@ -554,15 +567,16 @@ public void setHrefWithOnlyHash2() throws Exception { */ @Test public void replace() throws Exception { - final String html - = "First\n" + ""; - final String secondContent = "Second"; + final String secondContent = DOCTYPE_HTML + + "Second"; getMockWebConnection().setResponse(URL_SECOND, secondContent); final WebDriver driver = loadPage2(html); @@ -576,17 +590,19 @@ public void replace() throws Exception { */ @Test public void replaceLastInHistory() throws Exception { - final String startContent = "First Page"; + final String startContent = DOCTYPE_HTML + + "First Page"; - final String secondContent - = "Second Page\n" + ""; - final String thirdContent = "Third Page§"; + final String thirdContent = DOCTYPE_HTML + + "Third Page§"; getMockWebConnection().setResponse(URL_SECOND, secondContent); getMockWebConnection().setResponse(URL_THIRD, thirdContent); @@ -608,8 +624,8 @@ public void replaceLastInHistory() throws Exception { @Test @Alerts("on-load") public void replaceOnload() throws Exception { - final String html - = "First\n" + final String html = DOCTYPE_HTML + + "First\n" + "\n" + ""; - final String secondContent = "Second Page"; + final String secondContent = DOCTYPE_HTML + + "Second Page"; getMockWebConnection().setResponse(URL_SECOND, secondContent); @@ -658,15 +676,16 @@ public void replaceFirstInHistory() throws Exception { */ @Test public void assign() throws Exception { - final String firstContent - = "First\n" + ""; - final String secondContent = "Second"; + final String secondContent = DOCTYPE_HTML + + "Second"; getMockWebConnection().setResponse(URL_SECOND, secondContent); @@ -680,8 +699,8 @@ public void assign() throws Exception { @Test @Alerts("on-load") public void assignOnload() throws Exception { - final String firstContent - = "First\n" + ""; - final String secondContent = "Second"; + final String secondContent = DOCTYPE_HTML + + "Second"; getMockWebConnection().setResponse(URL_SECOND, secondContent); @@ -729,8 +750,8 @@ public void assingByEquals() throws Exception { @Test @Alerts("on-load") public void assingByEqualsOnload() throws Exception { - final String firstContent - = "First\n" @@ -775,8 +797,8 @@ public void changeLocationToNonHtml() throws Exception { @Test @Alerts("foo") public void jsLocation() throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + " "; + final String secondHtml = DOCTYPE_HTML + + ""; getMockWebConnection().setResponse(URL_SECOND, secondHtml); @@ -839,8 +863,8 @@ public void href_postponed() throws Exception { @Test @Alerts({"", "foo3.html", "foo2.html"}) public void onlick_set_location_WithHref() throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + " click me\n" + ""; @@ -861,8 +885,8 @@ public void onlick_set_location_WithHref() throws Exception { @Test @Alerts({"", "foo3.html"}) public void onlick_set_location_WithoutHref() throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + " click me\n" + ""; @@ -881,8 +905,8 @@ public void onlick_set_location_WithoutHref() throws Exception { @Test @Alerts({"supported", "onhashchange §§URL§§#1 §§URL§§"}) public void onHashChange() throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + ""; @@ -1132,8 +1167,8 @@ public void origin() throws Exception { @Test @Alerts("§§URL§§") public void documentOrigin() throws Exception { - final String html = - ""; @@ -1153,8 +1188,8 @@ public void documentOrigin() throws Exception { CHROME = "§§URL§§a.html?p1=sieben&p2", EDGE = "§§URL§§a.html?p1=sieben&p2") public void reloadGet() throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + " \n" + " \n" + " reload\n" @@ -1193,8 +1228,8 @@ public void reloadGet() throws Exception { FF = "null", FF_ESR = "null") public void reloadGetNoHash() throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + " \n" + " \n" + " \n" @@ -1231,8 +1266,8 @@ public void reloadGetNoHash() throws Exception { FF = "null", FF_ESR = "null") public void reloadGetHashDetails() throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + " \n" + " "; - final String html2 = "\n" + final String html2 = DOCTYPE_HTML + + "\n" + "

iFrame body

\n" + "\n" + "\n" @@ -341,8 +345,8 @@ public void language() throws Exception { @Test @Alerts("en-US,en") public void languages() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + " \n" @@ -359,8 +363,8 @@ public void languages() throws Exception { @Test @Alerts({"number", "number"}) public void mozilla() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + ""; - final String secondHtml - = "\n" + final String secondHtml = DOCTYPE_HTML + + "\n" + "\n" + "\n" @@ -211,8 +209,7 @@ public void defaultValue() throws Exception { @Test @Alerts({"function", "symbol", "symbol", "symbol"}) public void typeOf() throws Exception { - final String html = - HtmlPageTest.STANDARDS_MODE_PREFIX_ + final String html = DOCTYPE_HTML + "\n" + "\n" + "\n" + "\n" @@ -240,8 +237,7 @@ public void typeOf() throws Exception { @Test @Alerts({"false", "true", "Symbol(mario)"}) public void symbolFor() throws Exception { - final String html = - HtmlPageTest.STANDARDS_MODE_PREFIX_ + final String html = DOCTYPE_HTML + "\n" + "\n" + "\n" + "\n" @@ -270,8 +266,7 @@ public void symbolFor() throws Exception { @Test @Alerts({"true", "false"}) public void symbolForGlobal() throws Exception { - final String html = - HtmlPageTest.STANDARDS_MODE_PREFIX_ + final String html = DOCTYPE_HTML + "\n" + "\n" + "\n" + "\n" @@ -300,8 +295,7 @@ public void symbolForGlobal() throws Exception { @Test @Alerts({"TypeError", "TypeError"}) public void symbolNew() throws Exception { - final String html = - HtmlPageTest.STANDARDS_MODE_PREFIX_ + final String html = DOCTYPE_HTML + "\n" + "\n" + "\n" + "\n" @@ -329,8 +323,7 @@ public void symbolNew() throws Exception { @Test @Alerts({"TypeError", "TypeError"}) public void globalSymbolRegistry() throws Exception { - final String html = - HtmlPageTest.STANDARDS_MODE_PREFIX_ + final String html = DOCTYPE_HTML + "\n" + "\n" + "\n" + "\n" @@ -358,7 +351,8 @@ public void globalSymbolRegistry() throws Exception { @Test @Alerts("called") public void inFunction() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" diff --git a/src/test/java/org/htmlunit/javascript/host/WeakSetTest.java b/src/test/java/org/htmlunit/javascript/host/WeakSetTest.java index b90b9d83eef..d0f32b041a7 100644 --- a/src/test/java/org/htmlunit/javascript/host/WeakSetTest.java +++ b/src/test/java/org/htmlunit/javascript/host/WeakSetTest.java @@ -35,8 +35,8 @@ public class WeakSetTest extends WebDriverTestCase { @Test @Alerts("true") public void constructorArray() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + + ""; + loadPageVerifyTitle2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"SGVsbG8gV29ybGQh", "Hello World!"}) + public void atobTrailingWhitespace() throws Exception { + final String html = DOCTYPE_HTML + + "\n" + "\n" + + ""; + loadPageVerifyTitle2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"SGVsbG8gV29ybGQh", "Hello World!"}) + public void atobLeadingWhitespace() throws Exception { + final String html = DOCTYPE_HTML + + "\n" + + "\n" + + ""; + loadPageVerifyTitle2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"SGVsbG8gV29ybGQh", "Hello World!"}) + public void atobWhitespace() throws Exception { + final String html = DOCTYPE_HTML + + "\n" + + "\n" + + ""; + loadPageVerifyTitle2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"SGVsbG8gV29ybGQh", "InvalidCharacterError/DOMException", + "InvalidCharacterError/DOMException", "InvalidCharacterError/DOMException"}) + public void atobNbsp() throws Exception { + final String html = DOCTYPE_HTML + + "\n" + + "\n" + + ""; + loadPageVerifyTitle2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"SGVsbG8gV29ybGQh", "InvalidCharacterError/DOMException"}) + public void atobInvalid() throws Exception { + final String html = DOCTYPE_HTML + + "\n" + + "\n" + + ""; + loadPageVerifyTitle2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("InvalidCharacterError/DOMException") + public void atobMalformedInput() throws Exception { + final String html = DOCTYPE_HTML + + "\n" + + "\n" + + ""; + loadPageVerifyTitle2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts("InvalidCharacterError/DOMException") + public void atobEmptyInput() throws Exception { + final String html = DOCTYPE_HTML + + "\n" + + "\n" + ""; loadPageVerifyTitle2(html); @@ -187,16 +330,16 @@ public void atob() throws Exception { @Test @Alerts({"InvalidCharacterError/DOMException", "InvalidCharacterError/DOMException"}) public void atobUnicode() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + ""; loadPageVerifyTitle2(html); @@ -208,11 +351,11 @@ public void atobUnicode() throws Exception { @Test @Alerts({"M8OuwqY=", "3\u00C3\u00AE\u00C2\u00A6"}) public void atobUnicodeOutput() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + ""; @@ -228,11 +371,11 @@ public void atobUnicodeOutput() throws Exception { @Test @Alerts({"CSAe", "\t \u001e"}) public void atobControlChar() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + ""; @@ -248,13 +391,13 @@ public void atobControlChar() throws Exception { @Test @Alerts({"bnVsbA==", "null"}) public void atobNull() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + ""; loadPageVerifyTitle2(html); @@ -266,13 +409,13 @@ public void atobNull() throws Exception { @Test @Alerts({"dW5kZWZpbmVk", "undefined"}) public void atobUndefined() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + ""; loadPageVerifyTitle2(html); @@ -309,7 +452,8 @@ public void topLevelProperties() throws Exception { "NaN", "Infinity", "eval", "print", "parseInt", "parseFloat", "isNaN", "isFinite", "encodeURI", "encodeURIComponent", "decodeURI", "decodeURIComponent", "escape", "unescape"}; - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" @@ -646,7 +799,8 @@ public void open() throws Exception { + " window.open('" + URL_SECOND + "');\n" + "\n" + ""; - final String windowContent = "\n" + final String windowContent = DOCTYPE_HTML + + "\n" + "\n" + "\n" @@ -678,7 +833,8 @@ public void openWindowParams() throws Exception { + " window.open('" + URL_SECOND + "', 'New window', 'width=200,height=100');\n" + "\n" + ""; - final String windowContent = "\n" + final String windowContent = DOCTYPE_HTML + + "\n" + "\n" + "\n" + ""; - final String windowContent = "\n" + final String windowContent = DOCTYPE_HTML + + "\n" + "\n" + "\n" + + ""; + loadPageVerifyTitle2(html); + } + + /** + * Regression test for bug 2897473. + * @throws Exception if the test fails + */ + @Test + @Alerts(CHROME = {"true", "0", "147", "true", "true", "16"}, + EDGE = {"true", "0", "138", "true", "true", "24"}, + FF = {"true", "0", "93", "true", "true", "16"}, + FF_ESR = {"true", "0", "91", "true", "true", "12"}) + public void heightsAndWidthsQuirks() throws Exception { + final String html = + "\n" + + "\n" + + "\n" + + ""; + loadPageVerifyTitle2(html); + } + /** * Regression test for bug 2944261. * @throws Exception if the test fails @@ -901,12 +1130,15 @@ public void setOuterHeight() throws Exception { EDGE = {"630", "1248", "615", "1233"}, FF = {"675", "1256", "658", "1239"}, FF_ESR = {"677", "1260", "660", "1243"}) - @NotYetImplemented // TODO width and height calculation needs to be reworked in HtmlUnit // but as the calculation might be effected by e.g. current windows style it is not that simple - public void changeHeightsAndWidths() throws Exception { - final String html - = "\n" + @HtmlUnitNYI(CHROME = {"605", "1256", "705", "1256"}, + EDGE = {"605", "1256", "705", "1256"}, + FF = {"605", "1256", "705", "1256"}, + FF_ESR = {"605", "1256", "705", "1256"}) + public void changeHeightsAndWidthsQuirks() throws Exception { + final String html = + "\n" + ""; @@ -1089,8 +1321,8 @@ public void typeof() throws Exception { FF = {"12", "89"}, FF_ESR = {"10", "89"}) public void mozInnerScreen() throws Exception { - final String html - = "\n" + ""; @@ -1152,8 +1384,8 @@ public void eval() throws Exception { @Test @Alerts({"true", "I was here"}) public void firedEvent_equals_original_event() throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + ""; @@ -2150,8 +2394,8 @@ public void showModalDialog() throws Exception { @Test @Alerts("undefined") public void showModelessDialog() throws Exception { - final String html - = ""; @@ -2166,8 +2410,8 @@ public void showModelessDialog() throws Exception { @Test @Alerts("function") public void find() throws Exception { - final String html - = ""; @@ -2183,8 +2427,8 @@ public void find() throws Exception { @Test @Alerts("\"0.33\"") public void getComputedStylePseudo() throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + " \n" @@ -2273,8 +2518,8 @@ public void getComputedStyleElementDocument() throws Exception { @Test @Alerts({"1", "false", "true", "false", "false"}) public void in() throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" @@ -2319,7 +2565,8 @@ public void calledTwice() throws Exception { @Test @Alerts("TypeError") public void constructor() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" @@ -2366,7 +2614,8 @@ public void constructorError() throws Exception { @Test @Alerts({"false", "false", "test2 alert"}) public void objectCallOnFrameWindow() throws Exception { - final String firstContent = "\n" + final String firstContent = DOCTYPE_HTML + + "\n" + "\n" + "\n" @@ -2455,8 +2706,8 @@ public void xmlNotInWindow() throws Exception { @Test @Alerts({"[object Window]", "true", "true"}) public void globalThis() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + ""; @@ -2639,8 +2897,8 @@ public void isSecureContextLocalhost() throws Exception { @Test @Alerts("false") public void isSecureContextHttp() throws Exception { - final String html - = ""; @@ -2668,8 +2926,8 @@ public void isSecureContextHttpS() throws Exception { @Test @Alerts("true") public void isSecureContextFile() throws Exception { - final String html - = ""; @@ -2712,7 +2970,8 @@ public void isSecureContextAboutBlank() throws Exception { @Test @Alerts("inline") public void getComputedStyleShouldLoadOnlyStylesheets() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" @@ -2746,7 +3005,8 @@ public void getComputedStyleShouldLoadOnlyStylesheets() throws Exception { @Test @Alerts("length[GSCE]") public void lengthProperty() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + "\n" + + "\n" + + ""; + + loadPage2(content); + verifyTitle2(DEFAULT_WAIT_TIME, getWebDriver(), getExpectedAlerts()); + } +} diff --git a/src/test/java/org/htmlunit/javascript/host/Window3Test.java b/src/test/java/org/htmlunit/javascript/host/Window3Test.java index 31ec3d3d43a..274d52b1e2e 100644 --- a/src/test/java/org/htmlunit/javascript/host/Window3Test.java +++ b/src/test/java/org/htmlunit/javascript/host/Window3Test.java @@ -27,7 +27,6 @@ import org.apache.commons.lang3.StringUtils; import org.htmlunit.HttpHeader; import org.htmlunit.WebDriverTestCase; -import org.htmlunit.html.HtmlPageTest; import org.htmlunit.junit.BrowserRunner; import org.htmlunit.junit.annotation.Alerts; import org.htmlunit.junit.annotation.NotYetImplemented; @@ -62,7 +61,7 @@ public class Window3Test extends WebDriverTestCase { @Test @Alerts("about:blank") public void openWindow_emptyUrl() throws Exception { - final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + final String html = DOCTYPE_HTML + "\n" + "\n" + ""; - final String secondContent = HtmlPageTest.STANDARDS_MODE_PREFIX_ - + "Second\n" + + "\n" + + "\n" + "
\n" + ""; - final String thirdContent = HtmlPageTest.STANDARDS_MODE_PREFIX_ - + "Third\n" + final String firstContent = DOCTYPE_HTML + + "\n" + + "First\n" + + "\n" + + "\n" + + "\n" + ""; - final String secondContent = HtmlPageTest.STANDARDS_MODE_PREFIX_ - + "Second\n" + final String secondContent = DOCTYPE_HTML + + "\n" + + "Second\n" + + "\n" + + "\n" + + "\n" + + "\n" + ""; getMockWebConnection().setResponse(URL_SECOND, secondContent); - final String thirdContent = HtmlPageTest.STANDARDS_MODE_PREFIX_ - + "Third\n" + ""; getMockWebConnection().setResponse(urlThird, thirdContent); - final WebDriver driver = loadPageWithAlerts2(firstContent); + final WebDriver driver = loadPage2(firstContent); assertTitle(driver, "First"); + verifyWindowName2(driver, getExpectedAlerts()); } /** @@ -205,7 +223,7 @@ public void javascriptVariableFromNamedFrame() throws Exception { final URL urlThird = new URL(URL_FIRST, "third/"); final URL urlFourth = new URL(URL_FIRST, "fourth/"); - final String firstContent = HtmlPageTest.STANDARDS_MODE_PREFIX_ + final String firstContent = DOCTYPE_HTML + "first\n" + "\n" + " \n" @@ -215,30 +233,41 @@ public void javascriptVariableFromNamedFrame() throws Exception { + " \n" + ""; - final String secondContent = HtmlPageTest.STANDARDS_MODE_PREFIX_ - + "second

second

"; + final String secondContent = DOCTYPE_HTML + + "\n" + + "second\n" + + "\n" + + "\n" + + "

second

"; getMockWebConnection().setResponse(URL_SECOND, secondContent); - final String thirdContent = HtmlPageTest.STANDARDS_MODE_PREFIX_ - + "third

third

"; + final String thirdContent = DOCTYPE_HTML + + "\n" + + "third\n" + + "\n" + + "\n" + + "\n" + + "

third

"; getMockWebConnection().setResponse(urlThird, thirdContent); - final String fourthContent = HtmlPageTest.STANDARDS_MODE_PREFIX_ - + "fourth"; getMockWebConnection().setResponse(urlFourth, fourthContent); - final WebDriver driver = loadPageWithAlerts2(firstContent); + final WebDriver driver = loadPage2(firstContent); assertTitle(driver, "first"); + verifyWindowName2(driver, getExpectedAlerts()); } /** @@ -248,7 +277,7 @@ public void javascriptVariableFromNamedFrame() throws Exception { @Test @Alerts("true") public void javascriptVariableFromWindow_NotFound() throws Exception { - final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + final String html = DOCTYPE_HTML + "\n" + "\n" + ""; getMockWebConnection().setResponse(urlFourth, fourthContent); @@ -303,8 +336,9 @@ public void getFrameByName() throws Exception { } setExpectedAlerts(expectedAlerts); - final WebDriver driver = loadPageWithAlerts2(firstContent); + final WebDriver driver = loadPage2(firstContent); assertTitle(driver, "first"); + verifyWindowName2(driver, expectedAlerts); } /** @@ -314,7 +348,7 @@ public void getFrameByName() throws Exception { @Test @Alerts({"false", "false", "true"}) public void closed() throws Exception { - final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + final String html = DOCTYPE_HTML + "\n" + "\n" + ""; getMockWebConnection().setDefaultResponse(iframe); - loadPageWithAlerts2(html); + loadPage2(html); + verifyWindowName2(getWebDriver(), getExpectedAlerts()); } /** @@ -1285,7 +1321,7 @@ public void evalScopeOtherWindow() throws Exception { @Test @Alerts({"elementValue", "elementValue", "elementValue"}) public void evalScopeLocal() throws Exception { - final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + final String html = DOCTYPE_HTML + "
\n" + "\n" + ""; @@ -1411,8 +1448,7 @@ public void eval() throws Exception { final WebDriver driver = loadPage2(content); driver.findElement(By.id("myButton")).click(); - - verifyAlerts(driver, getExpectedAlerts()); + verifyTitle2(driver, getExpectedAlerts()); } /** @@ -1421,7 +1457,7 @@ public void eval() throws Exception { @Test @Alerts({"undefined", "undefined", "true"}) public void undefinedProperty() throws Exception { - final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + final String html = DOCTYPE_HTML + "\n" + "\n" + ""; - final String secondContent = "Second"; + final String secondContent = DOCTYPE_HTML + + "Second"; getMockWebConnection().setResponse(URL_SECOND, secondContent); @@ -1680,8 +1717,8 @@ public void navigate() throws Exception { @Test @Alerts("1") public void devicePixelRatio() throws Exception { - final String html - = "\n" + ""; @@ -1760,7 +1797,7 @@ public void getComputedStyle() throws Exception { "window at load 2 capture", "after"}) public void onload() throws Exception { - final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + final String html = DOCTYPE_HTML + "\n" + ""; final List collectedAlerts = Collections.synchronizedList(new ArrayList()); @@ -101,7 +101,8 @@ public void setTimeout() throws Exception { */ @Test public void setTimeoutByReference() throws Exception { - final String content = ""; @@ -118,8 +119,8 @@ public void setTimeoutByReference() throws Exception { */ @Test public void setAndClearInterval() throws Exception { - final String content - = "\n" + final String content = DOCTYPE_HTML + + "\n" + "\n" + ""; - final String secondContent = "Second"; + final String secondContent = DOCTYPE_HTML + + "Second"; final List collectedAlerts = Collections.synchronizedList(new ArrayList()); client_.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); @@ -224,8 +228,8 @@ public void setTimeoutStopped() throws Exception { */ @Test public void clearTimeout() throws Exception { - final String content = - "\n" + final String content = DOCTYPE_HTML + + "\n" + "\n" + " test\n" + " \n" + ""; - final String iframe = ""; @@ -87,8 +88,8 @@ public void postMessageFromIframe() throws Exception { expectedAlerts[4] += "http://localhost:" + PORT; setExpectedAlerts(expectedAlerts); - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + " \n" @@ -112,7 +113,8 @@ public void postMessageFromIframe() throws Exception { + "\n" + ""; - final String iframe = "

inside frame

"; + final String iframe = DOCTYPE_HTML + + "

inside frame

"; getMockWebConnection().setResponse(URL_SECOND, iframe); loadPageVerifyTitle2(html); @@ -124,8 +126,8 @@ public void postMessageFromIframe() throws Exception { @Test @Alerts("TypeError") public void postMessageMissingParameters() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + "\n" + ""; - final String iframe = "

inside frame

"; + final String iframe = DOCTYPE_HTML + + "

inside frame

"; getMockWebConnection().setResponse(URL_THIRD, iframe); loadPageVerifyTitle2(html); @@ -191,8 +194,8 @@ public void postMessageWithoutTargetOrigin() throws Exception { @Test @Alerts({"data: hello", "source: true false"}) public void postMessageFromClick() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + ""; @@ -332,8 +336,8 @@ public void postMessageSameOrigin_otherProtocol() throws Exception { } private void postMessage(final String url) throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + ""; @@ -355,8 +360,8 @@ private void postMessage(final String url) throws Exception { } private void postMessageSameOrigin(final String url) throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + ""; @@ -405,8 +411,8 @@ public void postMessageTargetOriginSubpath() throws Exception { } private void postMessageInvalidTargetOrigin(final String targetOrigin) throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + ""; @@ -448,11 +458,14 @@ public void postMessage_jsonPayload() throws Exception { loadPageVerifyTitle2(html); } + /** + * @throws Exception if an error occurs + */ @Test @Alerts("data: innerProperty") public void postMessage_jsonPayloadWithNestedObjects() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + ""; diff --git a/src/test/java/org/htmlunit/javascript/host/WindowTest.java b/src/test/java/org/htmlunit/javascript/host/WindowTest.java index e84211fbbfc..3600e22c190 100644 --- a/src/test/java/org/htmlunit/javascript/host/WindowTest.java +++ b/src/test/java/org/htmlunit/javascript/host/WindowTest.java @@ -83,15 +83,15 @@ public void openWindow() throws Exception { final List collectedAlerts = new ArrayList<>(); webClient.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); - final String firstContent - = "First\n" + final String firstContent = DOCTYPE_HTML + + "First\n" + "
\n" + " Click me\n" + "
\n" + ""; - final String secondContent - = "Second\n" + final String secondContent = DOCTYPE_HTML + + "Second\n" + "\n" + ""; @@ -153,14 +153,14 @@ public void openWindow_base() throws Exception { final List collectedAlerts = new ArrayList<>(); webClient.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); - final String firstContent - = "First\n" + final String firstContent = DOCTYPE_HTML + + "First\n" + "
\n" + " Click me\n" + "
\n" + ""; - final String secondContent - = "Second\n" + final String secondContent = DOCTYPE_HTML + + "Second\n" + "\n" + ""; @@ -199,18 +199,18 @@ public void openWindow_blank() throws Exception { final List collectedAlerts = new ArrayList<>(); webClient.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); - final String firstContent - = "First\n" + final String firstContent = DOCTYPE_HTML + + "First\n" + " \n" + ""; - final String secondContent - = "Second\n" + final String secondContent = DOCTYPE_HTML + + "Second\n" + " \n" + "Click me\n" + ""; - final String thirdContent - = "Third\n" + final String thirdContent = DOCTYPE_HTML + + "Third\n" + ""; webConnection.setResponse(URL_FIRST, firstContent); @@ -262,14 +262,15 @@ public void openWindow_self() throws Exception { final WebClient webClient = getWebClient(); final MockWebConnection webConnection = new MockWebConnection(); - final String firstContent - = "First\n" + final String firstContent = DOCTYPE_HTML + + "First\n" + "
\n" + " Click me\n" + "
\n" + ""; - final String secondContent = "Second"; + final String secondContent = DOCTYPE_HTML + + "Second"; webConnection.setResponse(URL_FIRST, firstContent); webConnection.setResponse(URL_SECOND, secondContent); @@ -320,20 +321,21 @@ public void openWindow_top() throws Exception { final WebClient webClient = getWebClient(); final MockWebConnection webConnection = new MockWebConnection(); - final String firstContent - = "First\n" + final String firstContent = DOCTYPE_HTML + + "First\n" + " \n" + ""; - final String secondContent - = "Second\n" + final String secondContent = DOCTYPE_HTML + + "Second\n" + " \n" + ""; - final String thirdContent - = "Third\n" - + " Click me\n" + ""; - final String fourthContent = "Fourth"; + final String fourthContent = DOCTYPE_HTML + + "Fourth"; webConnection.setResponse(URL_FIRST, firstContent); webConnection.setResponse(URL_SECOND, secondContent); @@ -387,20 +389,21 @@ public void openWindow_parent() throws Exception { final WebClient webClient = getWebClient(); final MockWebConnection webConnection = new MockWebConnection(); - final String firstContent - = "First\n" + final String firstContent = DOCTYPE_HTML + + "First\n" + " \n" + ""; - final String secondContent - = "Second\n" + final String secondContent = DOCTYPE_HTML + + "Second\n" + " \n" + ""; - final String thirdContent - = "Third\n" - + " Click me\n" + ""; - final String fourthContent = "Fourth"; + final String fourthContent = DOCTYPE_HTML + + "Fourth"; webConnection.setResponse(URL_FIRST, firstContent); webConnection.setResponse(URL_SECOND, secondContent); @@ -453,8 +456,8 @@ public void openWindow_parent() throws Exception { @Test @Alerts({"true", "true", "true"}) public void openWindow_existingWindow() throws Exception { - final String html - = "\n" + final String firstContent = DOCTYPE_HTML + + "First\n" + ""; final HtmlPage firstPage = loadPage(firstContent); @@ -523,16 +526,16 @@ public void alert_NoAlertHandler() throws Exception { */ @Test public void parentAndTop() throws Exception { - final String firstContent - = "First\n" + final String firstContent = DOCTYPE_HTML + + "First\n" + " \n" + ""; - final String secondContent - = "Second\n" + final String secondContent = DOCTYPE_HTML + + "Second\n" + " \n" + ""; - final String thirdContent - = "Third\n" + final String html = DOCTYPE_HTML + + "First\n" + ""; final List collectedAlerts = new ArrayList<>(); @@ -634,8 +637,8 @@ public void prompt() throws Exception { return "Flintstone"; }); - final String html - = "First\n" + final String html = DOCTYPE_HTML + + "First\n" + "\n" + ""; @@ -668,8 +671,8 @@ public void promptWithDefault() throws Exception { return defaultValue; }); - final String html - = "First\n" + final String html = DOCTYPE_HTML + + "First\n" + "\n" + ""; @@ -697,8 +700,8 @@ public void prompt_noPromptHandler() throws Exception { webClient.setAlertHandler(new CollectingAlertHandler(collectedAlerts)); - final String firstContent - = "First\n" + final String firstContent = DOCTYPE_HTML + + "First\n" + ""; webConnection.setResponse(URL_FIRST, firstContent); @@ -719,18 +722,18 @@ public void setOpenerLocationHrefRelative() throws Exception { final WebClient webClient = getWebClient(); final MockWebConnection webConnection = new MockWebConnection(); - final String aContent - = "A\n" + final String aContent = DOCTYPE_HTML + + "A\n" + "
\n" + "\n" + + "\n" + + "\n" + + "
\n" + + ""; + loadPageVerifyTitle2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts({"false", "true", "true", "true", "false"}) + public void widthAutoDiv() throws Exception { + final String html = DOCTYPE_HTML + + "\n" + + "\n" + + " \n" + "\n" + "\n" - + "
\n" + + "
\n" + ""; loadPageVerifyTitle2(html); } @@ -1614,9 +1701,13 @@ public void widthAuto() throws Exception { */ @Test @Alerts({"", "rgb(0, 0, 255)"}) - @NotYetImplemented + @HtmlUnitNYI(CHROME = {"red", "rgb(0, 0, 255)"}, + EDGE = {"red", "rgb(0, 0, 255)"}, + FF = {"red", "rgb(0, 0, 255)"}, + FF_ESR = {"red", "rgb(0, 0, 255)"}) public void getPropertyValue() throws Exception { - final String html = "\n" + + "\n" + + "\n" + + ""; + loadPageVerifyTitle2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"104", "104", "104", "104", "auto", "100px", "100px", + "3px", "block", "content-box", "0px", "0px"}) + public void measureAttached() throws Exception { + final String html = DOCTYPE_HTML + + "\n" + + "\n" + "\n" @@ -2457,7 +2616,8 @@ public void height() throws Exception { @Test @Alerts({"18", "18px", "36", "36px", "54", "54px"}) public void heightManyLines() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + "\n"; - getMockWebConnection().setDefaultResponse("\n" + getMockWebConnection().setDefaultResponse(DOCTYPE_HTML + + "\n" + "\n" @@ -1270,8 +1275,8 @@ public void removeTwoObject() throws Exception { } private void remove(final String in, final String toRemove) throws Exception { - String html - = "\n" + String html = DOCTYPE_HTML + + "\n" + "\n" diff --git a/src/test/java/org/htmlunit/javascript/host/dom/DocumentFragmentTest.java b/src/test/java/org/htmlunit/javascript/host/dom/DocumentFragmentTest.java index e62fca97dfd..13b94131c1c 100644 --- a/src/test/java/org/htmlunit/javascript/host/dom/DocumentFragmentTest.java +++ b/src/test/java/org/htmlunit/javascript/host/dom/DocumentFragmentTest.java @@ -41,7 +41,8 @@ public class DocumentFragmentTest extends WebDriverTestCase { FF = "[object CSS2Properties]", FF_ESR = "[object CSS2Properties]") public void getComputedStyleOnChild() throws Exception { - final String html = "\n" + "\n" @@ -65,8 +66,8 @@ public void getComputedStyleOnChild() throws Exception { */ @Test public void createElement() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + " \n" + " \n" @@ -1330,8 +1329,8 @@ public void getElementById_scriptSrc() throws Exception { @Test @Alerts("parentDiv") public void parentNode_Nested() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + ""; + final String html = DOCTYPE_HTML + + ""; final String script = "alert(document.getElementsByTagName('script').length);\n"; getMockWebConnection().setResponse(new URL(URL_FIRST, "script"), script, "text/javascript"); @@ -1815,7 +1817,8 @@ public void getElementsByTagName_LoadScript() throws Exception { @Test @Alerts({"2", "Three", "Four", "1", "Two", "0", "0"}) public void getElementsByTagNameXml() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + "\n" @@ -2106,7 +2109,8 @@ public void all_Caching() throws Exception { @Test @Alerts({"null", "null", "null"}) public void all_NotExisting() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" @@ -2171,7 +2176,8 @@ public void body_read() throws Exception { @Test @Alerts("FRAMESET") public void body_readFrameset() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + ""; @@ -2186,8 +2192,8 @@ public void body_readFrameset() throws Exception { @Test @Alerts({"0", "3", "3", "true", "firstImage"}) public void images() throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" @@ -2495,7 +2508,8 @@ public void precedence() throws Exception { @Test @Alerts({"true", "false"}) public void defaultViewAndParentWindow() throws Exception { - final String html = "\n" + + ""; + + loadPageVerifyTitle2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(CHROME = {"0", "0", "621", "1256"}, + EDGE = {"0", "0", "630", "1248"}, + FF = {"0", "0", "8", "1256"}, + FF_ESR = {"0", "0", "8", "1260"}) + @HtmlUnitNYI(CHROME = {"0", "0", "613", "1256"}, + EDGE = {"0", "0", "613", "1256"}, + FF = {"0", "0", "613", "1256"}, + FF_ESR = {"0", "0", "613", "1256"}) + public void documentElementBoundingClientRectQuirks() throws Exception { + final String html = + "" + + "\n" + + "\n" + + ""; + + loadPageVerifyTitle2(html); + } + + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(CHROME = {"0", "0", "8", "1256"}, + EDGE = {"0", "0", "8", "1248"}, + FF = {"0", "0", "8", "1256"}, + FF_ESR = {"0", "0", "8", "1260"}) + @HtmlUnitNYI(EDGE = {"0", "0", "8", "1256"}, + FF_ESR = {"0", "0", "8", "1256"}) + public void documentElementOffset() throws Exception { + final String html = DOCTYPE_HTML + + "" + + "\n" + + "\n" + + ""; + + loadPageVerifyTitle2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(CHROME = {"0", "0", "621", "1256"}, + EDGE = {"0", "0", "630", "1248"}, + FF = {"0", "0", "8", "1256"}, + FF_ESR = {"0", "0", "8", "1260"}) + @HtmlUnitNYI(CHROME = {"0", "0", "613", "1256"}, + EDGE = {"0", "0", "613", "1256"}, + FF = {"0", "0", "613", "1256"}, + FF_ESR = {"0", "0", "613", "1256"}) + public void documentElementOffsetQuirks() throws Exception { + final String html = + "" + + "\n" + + "\n" + + ""; + + loadPageVerifyTitle2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(CHROME = {"0", "0", "621", "1256"}, + EDGE = {"0", "0", "630", "1248"}, + FF = {"0", "0", "675", "1256"}, + FF_ESR = {"0", "0", "677", "1260"}) + @HtmlUnitNYI(CHROME = {"0", "0", "605", "1256"}, + EDGE = {"0", "0", "605", "1256"}, + FF = {"0", "0", "605", "1256"}, + FF_ESR = {"0", "0", "605", "1256"}) + public void documentElementClientWidthHeight() throws Exception { + final String html = DOCTYPE_HTML + + "" + + "\n" + + "\n" + + ""; + + loadPageVerifyTitle2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(CHROME = {"0", "0", "621", "1256"}, + EDGE = {"0", "0", "630", "1248"}, + FF = {"0", "0", "8", "1256"}, + FF_ESR = {"0", "0", "8", "1260"}) + @HtmlUnitNYI(CHROME = {"0", "0", "605", "1256"}, + EDGE = {"0", "0", "605", "1256"}, + FF = {"0", "0", "605", "1256"}, + FF_ESR = {"0", "0", "605", "1256"}) + public void documentElementClientWidthHeightQuirks() throws Exception { + final String html = + "" + + "\n" + + "\n" + + ""; + + loadPageVerifyTitle2(html); + } } diff --git a/src/test/java/org/htmlunit/javascript/host/dom/DocumentTypeTest.java b/src/test/java/org/htmlunit/javascript/host/dom/DocumentTypeTest.java index a58fe43058a..34e60781df4 100644 --- a/src/test/java/org/htmlunit/javascript/host/dom/DocumentTypeTest.java +++ b/src/test/java/org/htmlunit/javascript/host/dom/DocumentTypeTest.java @@ -15,7 +15,6 @@ package org.htmlunit.javascript.host.dom; import org.htmlunit.WebDriverTestCase; -import org.htmlunit.html.HtmlPageTest; import org.htmlunit.junit.BrowserRunner; import org.htmlunit.junit.annotation.Alerts; import org.htmlunit.util.MimeType; @@ -73,8 +72,8 @@ public void doctype() throws Exception { @Alerts({"[object DocumentType]", "greeting,10,null,undefined,undefined,undefined", "greeting,MyIdentifier,hello.dtd,undefined,undefined,undefined"}) public void doctype_xml() throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + " \n" + " \n" @@ -1591,8 +1620,8 @@ public void lookupPrefixXhtml() throws Exception { FF = {"null", "null", "null", "null", "null", "null", "null", "null", "null", "null"}, FF_ESR = {"null", "null", "null", "null", "null", "null", "null", "null", "null", "null"}) public void lookupPrefixXml() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + ""; loadPageVerifyTitle2(html); @@ -70,7 +72,8 @@ public void equality_getSelection() throws Exception { @Test @Alerts({"0", "0", "0", "cdefg"}) public void inputSelectionsAreIndependent() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + ""; @@ -225,8 +225,8 @@ public void initCustomEvent() throws Exception { @Test @Alerts({"true", "details", "I was here"}) public void dispatchEvent() throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" @@ -157,8 +160,8 @@ public void write2_html_endhtml_in_head() throws Exception { @Test @Alerts("true") public void writeScript() throws Exception { - final String html = - ""; @@ -172,7 +175,8 @@ public void writeScript() throws Exception { */ @Test public void writeUnicode() throws Exception { - final String html = "\n" + ""; @@ -414,7 +431,8 @@ public void write_loadScript() throws Exception { */ @Test public void write_fromScriptAddedWithAppendChild_inline() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "
\n" + " \n" @@ -502,8 +521,8 @@ public void write_Destination() throws Exception { @Test @Alerts({"null", "[object HTMLBodyElement]", "", "foo"}) public void write_BodyAttributesKept() throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + " \n" + " \n" + " \n" @@ -529,8 +548,8 @@ public void write_BodyAttributesKept() throws Exception { @Test @Alerts({"1", "2", "3"}) public void write_ScriptExecutionOrder() throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + " \n" + " test\n" + " \n" @@ -552,7 +571,8 @@ public void write_ScriptExecutionOrder() throws Exception { @Test @Alerts("outer") public void writeInManyTimes() throws Exception { - final String html = "foo\n" + "\n" @@ -722,7 +747,8 @@ public void write_script() throws Exception { final URL secondUrl = new URL(URL_FIRST, "second.html"); final URL scriptUrl = new URL(URL_FIRST, "script.js"); - final String mainHtml = "\n" + final String mainHtml = DOCTYPE_HTML + + "\n" + "Main\n" + "\n" + " \n" @@ -733,10 +759,10 @@ public void write_script() throws Exception { getMockWebConnection().setResponse(mainUrl, mainHtml); - final String firstHtml = "

First

"; + final String firstHtml = DOCTYPE_HTML + "

First

"; getMockWebConnection().setResponse(firstUrl, firstHtml); - final String secondHtml = "

Second

"; + final String secondHtml = DOCTYPE_HTML + "

Second

"; getMockWebConnection().setResponse(secondUrl, secondHtml); final String script = "document.getElementById('iframe').src = '" + secondUrl + "';\n"; @@ -758,7 +784,8 @@ public void write_script() throws Exception { @Test @Alerts({"A", "A"}) public void write_InDOM() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + " 3"; + final String html = DOCTYPE_HTML + + "13"; final WebDriver driver = loadPage2(html); assertEquals("123", driver.findElement(By.tagName("body")).getText()); @@ -870,7 +901,8 @@ public void open_IgnoredDuringParsing() throws Exception { */ @Test public void writeWithSpace() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + " \n" + "\n" + "\n" + ""; - final URL scriptUrl = new URL(URL_FIRST, "script.js"); + final URL scriptUrlA = new URL(URL_FIRST, "scriptA.js"); + final URL scriptUrlB = new URL(URL_FIRST, "scriptB.js"); + + getMockWebConnection().setDefaultResponse(html); + getMockWebConnection().setResponse(scriptUrlA, "log('A');\n", MimeType.TEXT_JAVASCRIPT); + getMockWebConnection().setResponse(scriptUrlB, "log('B');\n", MimeType.TEXT_JAVASCRIPT); + + loadPageVerifyTitle2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"0", "foo1", "1", "foo2", "2", "3", "4", "A", "foo3"}) + public void writeScriptPostponed() throws Exception { + final String html = DOCTYPE_HTML + + "\n" + + "\n" + + "\n" + + + "'\n" + + + "\n" + + + "\n" + + "\n" + + ""; + + final URL scriptUrlA = new URL(URL_FIRST, "scriptA.js"); + + getMockWebConnection().setDefaultResponse(html); + getMockWebConnection().setResponse(scriptUrlA, "log('A');\n", MimeType.TEXT_JAVASCRIPT); + + loadPageVerifyTitle2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts({"0", "A", "1", "foo2", "2", "3", "4", "B", "foo3"}) + public void writeScriptPostponedBeforeWrite() throws Exception { + final String html = DOCTYPE_HTML + + "\n" + + "\n" + + "\n" + + + "'\n" + + + "\n" + + + "\n" + + "\n" + + ""; + + final URL scriptUrlA = new URL(URL_FIRST, "scriptA.js"); + final URL scriptUrlB = new URL(URL_FIRST, "scriptB.js"); getMockWebConnection().setDefaultResponse(html); - getMockWebConnection().setResponse(scriptUrl, "log('foo');\n", MimeType.TEXT_JAVASCRIPT); + getMockWebConnection().setResponse(scriptUrlA, "log('A');\n", MimeType.TEXT_JAVASCRIPT); + getMockWebConnection().setResponse(scriptUrlB, "log('B');\n", MimeType.TEXT_JAVASCRIPT); loadPageVerifyTitle2(html); } @@ -915,7 +1038,8 @@ public void writeScriptInManyTimes() throws Exception { @Test @Alerts({"scr1", "scr2", "null", "null", "[object HTMLScriptElement]", "[object HTMLScriptElement]"}) public void writeAddNodesInCorrectPositions() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + "
\n" @@ -955,8 +1079,8 @@ public void writeAddNodesInCorrectPositions() throws Exception { */ @Test public void aboutURL() throws Exception { - final String html = - "\n" diff --git a/src/test/java/org/htmlunit/javascript/host/html/HTMLElement2Test.java b/src/test/java/org/htmlunit/javascript/host/html/HTMLElement2Test.java index 6e1676531d3..56575cea06a 100644 --- a/src/test/java/org/htmlunit/javascript/host/html/HTMLElement2Test.java +++ b/src/test/java/org/htmlunit/javascript/host/html/HTMLElement2Test.java @@ -18,7 +18,6 @@ import static org.htmlunit.junit.annotation.TestedBrowser.EDGE; import org.htmlunit.WebDriverTestCase; -import org.htmlunit.html.HtmlPageTest; import org.htmlunit.junit.BrowserRunner; import org.htmlunit.junit.annotation.Alerts; import org.htmlunit.junit.annotation.HtmlUnitNYI; @@ -47,7 +46,8 @@ public class HTMLElement2Test extends WebDriverTestCase { @Test @Alerts({"undefined", "undefined"}) public void scopeName() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "" + "" @@ -1057,7 +1072,8 @@ public void innerText_Head() throws Exception { @Test @Alerts({"something", "0"}) public void innerText_emptyString() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" @@ -257,7 +261,8 @@ public void attributesAccess() throws Exception { @Test @Alerts({"a", "b", "undefined", "foo"}) public void setAttribute() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + " \n" + " \n" + ""; - final String page2 = ""; + final String page2 = DOCTYPE_HTML + + ""; getMockWebConnection().setResponse(new URL(URL_FIRST, "page2"), page2); loadPageWithAlerts2(html); @@ -2841,7 +2906,8 @@ public void dispatchEvent_submitOnForm() throws Exception { */ @Test public void dispatchEvent_submitOnFormChild() throws Exception { - final String html = "page 1\n" + final String html = DOCTYPE_HTML + + "page 1\n" + "
\n" + "\n" @@ -3542,8 +3609,8 @@ private void mergeAttributesTest(final String params) throws Exception { @Test @Alerts("false") public void document() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "
\n" @@ -274,8 +274,8 @@ public void lostFunction() throws Exception { @Test @Alerts("hi!") public void assignedOnsubmit() throws Exception { - final String content - = "foo\n" + "\n" + "\n" @@ -698,8 +704,8 @@ public void findInputWithoutTypeDefined() throws Exception { @Test @Alerts("2") public void length() throws Exception { - final String html - = "\n" + "\n" @@ -958,8 +971,8 @@ public void getFormFromFormsById() throws Exception { @Test @Alerts("§§URL§§") public void action() throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + "\n" @@ -979,8 +992,8 @@ public void action() throws Exception { @Test @Alerts("§§URL§§") public void actionEmpty() throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + "\n" @@ -1000,8 +1013,8 @@ public void actionEmpty() throws Exception { @Test @Alerts("§§URL§§") public void actionBlank() throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + "\n" @@ -1021,8 +1034,8 @@ public void actionBlank() throws Exception { @Test @Alerts("text") public void getFieldNamedLikeForm() throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "\n" + "\n" @@ -1072,8 +1085,8 @@ public void fieldNamedSubmit() throws Exception { * @throws Exception if the test fails */ private void fieldNamedSubmit(final String htmlSnippet, final String expected) throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + ""; @@ -1716,7 +1751,8 @@ public void enctype_defaultValue() throws Exception { */ @Test public void submitMultipartTextFieldWithRightEncoding() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + " \n" + "
"; @@ -1740,7 +1776,8 @@ public void submitMultipartTextFieldWithRightEncoding() throws Exception { @Test @Alerts("application/x-www-form-urlencoded") public void submitUrlEncodedEmptyForm() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "
\n" + "
\n" @@ -1767,7 +1804,8 @@ public void submitUrlEncodedEmptyForm() throws Exception { @Test @Alerts({"application/x-www-form-urlencoded", "myField=abcDEF"}) public void submitUrlEncodedAsciiText() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "
\n" + " \n" @@ -1795,7 +1833,8 @@ public void submitUrlEncodedAsciiText() throws Exception { @Test @Alerts({"application/x-www-form-urlencoded", "my\tFie ld = a b\tc \t"}) public void submitUrlEncodedSpecialChars() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + " \n" + " \n" @@ -1823,7 +1862,8 @@ public void submitUrlEncodedSpecialChars() throws Exception { @Test @Alerts({"application/x-www-form-urlencoded", "myField=éèê\u00e4\u00f6\u00fc"}) public void submitUrlEncodedUnicode() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + " \n" + " \n" @@ -1851,7 +1891,8 @@ public void submitUrlEncodedUnicode() throws Exception { @Test @Alerts({"application/x-www-form-urlencoded", "myField=HtmlUnit \u043B\u0189"}) public void submitUrlEncodedUnicodeUTF8() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + " \n" + " \n" @@ -1879,7 +1920,8 @@ public void submitUrlEncodedUnicodeUTF8() throws Exception { @Test @Alerts({"application/x-www-form-urlencoded", "myField=HtmlUnit \u043B\u0189"}) public void submitUrlEncodedUnicodeUTF16() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + " \n" + " \n" @@ -1907,7 +1949,8 @@ public void submitUrlEncodedUnicodeUTF16() throws Exception { @Test @Alerts({"application/x-www-form-urlencoded", "myFile=htmlunit-test", ".txt"}) public void submitUrlEncodedFile() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + " \n" + " \n" @@ -1925,6 +1968,9 @@ public void submitUrlEncodedFile() throws Exception { final String path = tmpFile.getAbsolutePath(); driver.findElement(By.id("f")).sendKeys(path); driver.findElement(By.id("clickMe")).click(); + if (useRealBrowser()) { + Thread.sleep(400); + } } finally { assertTrue(tmpFile.delete()); @@ -1948,7 +1994,8 @@ public void submitUrlEncodedFile() throws Exception { @Test @Alerts("text/plain") public void submitPlainTextEmptyForm() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + " \n" + "
\n" @@ -1974,7 +2021,8 @@ public void submitPlainTextEmptyForm() throws Exception { @Test @Alerts({"text/plain", "myField=abcDEF\r\n"}) public void submitPlainTextAsciiText() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + "
\n" + " \n" @@ -2001,7 +2049,8 @@ public void submitPlainTextAsciiText() throws Exception { @Test @Alerts({"text/plain", "my\tField = abcDEF \t\r\n"}) public void submitPlainTextSpecialChars() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + " \n" + " \n" @@ -2028,7 +2077,8 @@ public void submitPlainTextSpecialChars() throws Exception { @Test @Alerts({"text/plain", "myField=éèê\u00e4\u00f6\u00fc\u00a9\r\n"}) public void submitPlainTextUnicode() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + " \n" + " \n" @@ -2055,7 +2105,8 @@ public void submitPlainTextUnicode() throws Exception { @Test @Alerts({"text/plain", "myField=éèê\u00e4\u00f6\u00fc\u00a9?\r\n"}) public void submitPlainTextISO_8859_1() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + " \n" + " \n" @@ -2084,7 +2135,8 @@ public void submitPlainTextISO_8859_1() throws Exception { @Test @Alerts({"text/plain", "myField=éèêäöü©?\r\n"}) public void submitPlainTextISO_8859_1_AcceptCharsetUtf8() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + " \n" + " \n" @@ -2112,7 +2164,8 @@ public void submitPlainTextISO_8859_1_AcceptCharsetUtf8() throws Exception { @Test @Alerts({"text/plain", "myField=HtmlUnit \u00D0\u00BB\u00C6\u0089\r\n"}) public void submitPlainTextUnicodeUTF8() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + " \n" + " \n" @@ -2140,7 +2193,8 @@ public void submitPlainTextUnicodeUTF8() throws Exception { @Test @Alerts({"text/plain", "myField=HtmlUnit \u00D0\u00BB\u00C6\u0089\r\n"}) public void submitPlainTextUnicodeUTF16() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + " \n" + " \n" @@ -2168,7 +2222,8 @@ public void submitPlainTextUnicodeUTF16() throws Exception { @Test @Alerts({"text/plain", "myField=HtmlUnit \u00D0\u00BB\u00C6\u0089\r\n"}) public void submitPlainTextUnicodeUTF16AcceptCharsetUtf8() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + " \n" + " \n" @@ -2196,7 +2251,8 @@ public void submitPlainTextUnicodeUTF16AcceptCharsetUtf8() throws Exception { @Test @Alerts({"text/plain", "myFile=htmlunit-test", ".txt\r\n"}) public void submitPlainTextFile() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + " \n" + " \n" @@ -2214,6 +2270,9 @@ public void submitPlainTextFile() throws Exception { final String path = tmpFile.getAbsolutePath(); driver.findElement(By.id("f")).sendKeys(path); driver.findElement(By.id("clickMe")).click(); + if (useRealBrowser()) { + Thread.sleep(400); + } } finally { assertTrue(tmpFile.delete()); @@ -2248,8 +2307,8 @@ public void submitToSameUrlFromLinkOnclick_get() throws Exception { } private void submitToSameUrlFromLinkOnclick(final String method) throws Exception { - final String html - = "foo\n" + final String html = DOCTYPE_HTML + + "foo\n" + "\n" + "\n" + "submit it\n" @@ -2258,6 +2317,9 @@ private void submitToSameUrlFromLinkOnclick(final String method) throws Exceptio final WebDriver driver = loadPage2(html); driver.findElement(By.id("clickMe")).click(); driver.findElement(By.id("clickMe")).click(); // a second time to be sure to have same resulting Url + if (useRealBrowser()) { + Thread.sleep(400); + } assertEquals(3, getMockWebConnection().getRequestCount()); } @@ -2269,7 +2331,8 @@ private void submitToSameUrlFromLinkOnclick(final String method) throws Exceptio @Alerts({"", "foo4?foo=", "script4.js"}) @NotYetImplemented public void submitTriggersRequestNotParsed() throws Exception { - final String html = "\n" + "\n" @@ -2388,8 +2452,8 @@ public void accessByNameAfterNameChangeFieldSet() throws Exception { } private void accessByNameAfterNameChange(final String htmlElement) throws Exception { - final String html - = ""; - final String page2 = ""; + final String page2 = DOCTYPE_HTML + + ""; getMockWebConnection().setResponse(new URL(URL_FIRST, "page1"), page1); getMockWebConnection().setResponse(new URL(URL_FIRST, "page2"), page2); @@ -2500,7 +2567,8 @@ public void dispatchEventSubmitTriggersHandlers() throws Exception { "srcElement null: false", "srcElement==form: true", "target null: false", "target==form: true"}) public void onSubmitEvent() throws Exception { - final String html = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" @@ -70,8 +70,7 @@ public void frameName() throws Exception { @Test @Alerts({"[object HTMLDocument]", "true"}) public void contentDocument() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + "\n" + "\n" + " "; + + final String defaultContent = DOCTYPE_HTML + + "\n" + + "\n" + + ""; getMockWebConnection().setDefaultResponse(defaultContent); final WebDriver driver = loadPage2(firstContent); expandExpectedAlertsVariables(URL_FIRST); - verifyAlerts(driver, getExpectedAlerts()); + verifyWindowName2(driver, getExpectedAlerts()); assertTitle(driver, "first"); } @@ -215,7 +222,8 @@ private void location(final String jsExpr) throws Exception { @Test @Alerts("2") public void writeFrameset() throws Exception { - final String content1 = "\n" + final String content1 = DOCTYPE_HTML + + "\n" + "\n" + ""; - final String content2 = ""; + final String content2 = DOCTYPE_HTML + ""; getMockWebConnection().setDefaultResponse(content2); @@ -237,8 +245,8 @@ public void writeFrameset() throws Exception { @Test @Alerts("DIV") public void frameLoadedAfterParent() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" @@ -246,8 +254,8 @@ public void frameLoadedAfterParent() throws Exception { + "\n" + "
test text
\n" + ""; - final String frameContent - = "\n" + final String frameContent = DOCTYPE_HTML + + "\n" + "\n" @@ -266,7 +274,8 @@ public void frameLoadedAfterParent() throws Exception { @Alerts({"about:blank", "oFrame.foo: undefined", "/frame1.html", "oFrame.foo: foo of frame 1", "/frame2.html", "oFrame.foo: foo of frame 2"}) public void changingFrameDocumentLocation() throws Exception { - final String firstHtml = "\n" + final String firstHtml = DOCTYPE_HTML + + "\n" + "\n" + "frame 1"; final String frame2Html = frame1Html.replaceAll("frame 1", "frame 2"); @@ -315,8 +325,8 @@ public void changingFrameDocumentLocation() throws Exception { @Test @Alerts("[object HTMLFrameElement]") public void frames_framesetOnLoad() throws Exception { - final String mainHtml = - "\n" + final String mainHtml = DOCTYPE_HTML + + "\n" + "" @@ -327,7 +337,8 @@ public void frames_framesetOnLoad() throws Exception { + "\n" + ""; - final String frame1 = "1\n" + final String frame1 = DOCTYPE_HTML + + "1\n" + "\n" + ""; @@ -342,8 +353,8 @@ public void frames_framesetOnLoad() throws Exception { @Test @Alerts("[object HTMLFrameElement]") public void frames_bodyOnLoad() throws Exception { - final String mainHtml = - "\n" + final String mainHtml = DOCTYPE_HTML + + "\n" + "\n" @@ -353,7 +364,8 @@ public void frames_bodyOnLoad() throws Exception { + "\n" + ""; - final String frame1 = "1\n" + final String frame1 = DOCTYPE_HTML + + "1\n" + "\n" + ""; @@ -368,8 +380,8 @@ public void frames_bodyOnLoad() throws Exception { @Test @Alerts("[object HTMLFrameElement]") public void parent_frames() throws Exception { - final String mainHtml = - "\n" + final String mainHtml = DOCTYPE_HTML + + "\n" + "\n" @@ -379,7 +391,8 @@ public void parent_frames() throws Exception { + "\n" + ""; - final String frame1 = "f1\n" + final String frame1 = DOCTYPE_HTML + + "f1\n" + "\n" + + "\n" + + "\n" + " \n" + "

onloadFrame

\n" + "

New content loaded...

\n" @@ -514,8 +542,7 @@ public void windowLocationReplaceOnload() throws Exception { assertEquals(getExpectedAlerts()[2], driver.findElement(By.tagName("body")).getText()); driver.findElement(By.name("onloadFrameAnchor")).click(); - verifyAlerts(driver, "Body alert."); - verifyAlerts(driver, "Onload alert."); + verifyWindowName2(driver, "Body alert.", "Onload alert."); driver.switchTo().defaultContent(); Thread.sleep(1000); @@ -537,7 +564,8 @@ public void windowLocationReplaceOnload() throws Exception { "header -> content -> frameSet -> onloadFrame", "onloadFrame\nNew content loaded..."}) public void windowLocationAssignOnload() throws Exception { - final String html = "OnloadTest\n" + final String html = DOCTYPE_HTML + + "OnloadTest\n" + "\n" + " \n" + " \n" + ""; - final String headerFrame = "headerFrame\n" + final String headerFrame = DOCTYPE_HTML + + "headerFrame\n" + "\n" + + "\n" + + "\n" + " \n" + "

onloadFrame

\n" + "

New content loaded...

\n" @@ -592,8 +628,8 @@ public void windowLocationAssignOnload() throws Exception { assertEquals(getExpectedAlerts()[2], driver.findElement(By.tagName("body")).getText()); driver.findElement(By.name("onloadFrameAnchor")).click(); - verifyAlerts(driver, "Body alert."); - verifyAlerts(driver, "Onload alert."); + verifyWindowName2(driver, "Body alert.", "Onload alert."); + driver.switchTo().defaultContent(); Thread.sleep(1000); @@ -615,7 +651,8 @@ public void windowLocationAssignOnload() throws Exception { "onloadFrame\nNew content loaded..."}) @NotYetImplemented public void windowLocationSetOnload() throws Exception { - final String html = "OnloadTest\n" + final String html = DOCTYPE_HTML + + "OnloadTest\n" + "\n" + " \n" + " \n" + ""; - final String headerFrame = "headerFrame\n" + final String headerFrame = DOCTYPE_HTML + + "headerFrame\n" + "\n" + + "\n" + + "\n" + + "

HtmlUnit

\n" + + "

HtmlUnit

\n" + + "

HtmlUnit

\n" + + "

HtmlUnit

\n" + + "
HtmlUnit
\n" + + "
HtmlUnit
\n" + + ""; + + loadPageVerifyTitle2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts({"0", "0", "0", "0", "0", "0"}) + public void clientHeightEmpty() throws Exception { + final String html = DOCTYPE_HTML + + "\n" + + "\n" + + " \n" + + "\n" + + "\n" + + "

\n" + + "

\n" + + "

\n" + + "

\n" + + "
\n" + + "
\n" + + ""; + + loadPageVerifyTitle2(html); + } } diff --git a/src/test/java/org/htmlunit/javascript/host/html/HTMLHtmlElementTest.java b/src/test/java/org/htmlunit/javascript/host/html/HTMLHtmlElementTest.java index dc2e26990fe..a86bf52fde8 100644 --- a/src/test/java/org/htmlunit/javascript/host/html/HTMLHtmlElementTest.java +++ b/src/test/java/org/htmlunit/javascript/host/html/HTMLHtmlElementTest.java @@ -44,7 +44,8 @@ public class HTMLHtmlElementTest extends WebDriverTestCase { @Test @Alerts("[object HTMLHtmlElement]") public void simpleScriptable() throws Exception { - final String html = "foo\n" + "\n" + ""; - final String html2 = "foo"; + final String html2 = DOCTYPE_HTML + "foo"; getMockWebConnection().setResponse(URL_SECOND, html2); loadPageVerifyTitle2(html); @@ -104,8 +104,8 @@ public void documentWrite_onLoad() throws Exception { @Test @Alerts("loaded") public void documentWrite_onLoad_noSrc() throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + " \n" + " \n" + " \n" + ""; - final String html2 = "foo"; + final String html2 = DOCTYPE_HTML + "foo"; getMockWebConnection().setResponse(URL_SECOND, html2); loadPageVerifyTitle2(html); @@ -157,8 +157,8 @@ public void documentCreateElement_onLoad() throws Exception { @Test @Alerts({"loaded", ""}) public void documentCreateElement_onLoad_noSrc() throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + ""; getMockWebConnection().setResponse(URL_SECOND, html2); @@ -311,8 +313,8 @@ public void documentCreateElement_iFrameInsideDiv() throws Exception { @Test @Alerts({"createIFrame", "loaded", "foo"}) public void documentCreateElement_onLoad3() throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + " \n" + ""; - final String html2 = "foo"; + final String html2 = DOCTYPE_HTML + "foo"; getMockWebConnection().setResponse(URL_SECOND, html2); loadPageVerifyTitle2(html); @@ -438,8 +440,8 @@ public void documentFragmentCreateElement_onLoad_noSrc() throws Exception { @Test @Alerts("createIFrame") public void documentFragmentCreateElement_onLoad2() throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + "\n" + " \n" + ""; - final String html2 = "foo"; + final String html2 = DOCTYPE_HTML + "foo"; getMockWebConnection().setResponse(URL_SECOND, html2); loadPageVerifyTitle2(html); @@ -641,8 +647,8 @@ public void documentDocumentFragmentCreateElement_onLoad() throws Exception { @Test @Alerts({"fragment append done", "loaded"}) public void documentDocumentFragmentCreateElement_onLoad_noSrc() throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + ""; + final String html2 = DOCTYPE_HTML + + "foo"; getMockWebConnection().setResponse(URL_SECOND, html2); final WebDriver driver = loadPage2(html); - Thread.sleep(DEFAULT_WAIT_TIME); + Thread.sleep(DEFAULT_WAIT_TIME.toMillis()); final int start = getMockWebConnection().getRequestCount(); driver.findElement(By.id("clickMe")).click(); - Thread.sleep(DEFAULT_WAIT_TIME); + Thread.sleep(DEFAULT_WAIT_TIME.toMillis()); assertEquals(1, getMockWebConnection().getRequestCount() - start); @@ -1103,8 +1110,8 @@ public void detachAppend() throws Exception { FF_ESR = {"iframe external script", "loaded", "null", "loaded", "[object Window]", "about:blank", "iframe external script", "loaded"}) public void detachAppendExternalScript() throws Exception { - final String html = - "\n" + final String html = DOCTYPE_HTML + + "\n" + ""; + final String html2 = DOCTYPE_HTML + + "foo"; getMockWebConnection().setResponse(URL_SECOND, html2); final String js = "parent.log('iframe external script');"; getMockWebConnection().setResponse(new URL(URL_SECOND, "ext.js"), js, MimeType.TEXT_JAVASCRIPT); final WebDriver driver = loadPage2(html); - Thread.sleep(DEFAULT_WAIT_TIME); + Thread.sleep(DEFAULT_WAIT_TIME.toMillis()); final int start = getMockWebConnection().getRequestCount(); driver.findElement(By.id("clickMe")).click(); - Thread.sleep(DEFAULT_WAIT_TIME); + Thread.sleep(DEFAULT_WAIT_TIME.toMillis()); assertEquals(2, getMockWebConnection().getRequestCount() - start); diff --git a/src/test/java/org/htmlunit/javascript/host/html/HTMLIFrameElement3Test.java b/src/test/java/org/htmlunit/javascript/host/html/HTMLIFrameElement3Test.java index a6fc9bd5c37..10fffbe7b77 100644 --- a/src/test/java/org/htmlunit/javascript/host/html/HTMLIFrameElement3Test.java +++ b/src/test/java/org/htmlunit/javascript/host/html/HTMLIFrameElement3Test.java @@ -24,7 +24,6 @@ import org.htmlunit.WebClient; import org.htmlunit.WebDriverTestCase; import org.htmlunit.html.HtmlPage; -import org.htmlunit.html.HtmlPageTest; import org.htmlunit.junit.BrowserRunner; import org.htmlunit.junit.annotation.Alerts; import org.htmlunit.junit.annotation.HtmlUnitNYI; @@ -61,8 +60,7 @@ protected boolean needThreeConnections() { @Test @Alerts("false") public void style() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + "\n" + "\n" + "\n" + ""; @@ -147,7 +144,8 @@ public void onLoadGetsIFrameElementByIdInParent() throws Exception { webConnection.setDefaultResponse(frameContent); - loadPageWithAlerts2(firstContent); + loadPage2(firstContent); + verifyWindowName2(getWebDriver(), getExpectedAlerts()); } /** @@ -156,8 +154,7 @@ public void onLoadGetsIFrameElementByIdInParent() throws Exception { @Test @Alerts({"[object HTMLDocument]", "true"}) public void contentDocument() throws Exception { - final String html - = HtmlPageTest.STANDARDS_MODE_PREFIX_ + final String html = DOCTYPE_HTML + "\n" + "\n" + " "; - final String frame2 = ""; + final String frame1 = DOCTYPE_HTML + + "\n" + + "\n" + + ""; + final String frame2 = DOCTYPE_HTML + + "\n" + + "\n" + + ""; final String[] alerts = getExpectedAlerts(); final MockWebConnection webConnection = getMockWebConnection(); @@ -263,10 +269,10 @@ public void iFrameReinitialized() throws Exception { webConnection.setResponse(new URL(URL_FIRST, "2.html"), frame2); final WebDriver driver = loadPage2(html); - verifyAlerts(driver, alerts[0]); + verifyWindowName2(driver, alerts[0]); driver.findElement(By.id("test")).click(); - verifyAlerts(driver, alerts[1]); + verifyWindowName2(driver, alerts[1]); assertEquals(3, getMockWebConnection().getRequestCount()); } @@ -277,8 +283,7 @@ public void iFrameReinitialized() throws Exception { @Test @Alerts("about:blank") public void setSrc_JavascriptUrl() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + "\n" + "\n" - + ""; + final String frame = DOCTYPE_HTML + + "\n" + + "\n" + + "\n" + + ""; final MockWebConnection webConnection = getMockWebConnection(); webConnection.setDefaultResponse(frame); - loadPageWithAlerts2(html); + loadPage2(html); + verifyWindowName2(getWebDriver(), getExpectedAlerts()); } /** @@ -457,8 +465,7 @@ public void body() throws Exception { @Test @Alerts("128px") public void width_px() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + "\n" + ""; - final String html2 = "foo"; + final String html2 = DOCTYPE_HTML + "foo"; final MockWebConnection conn = getMockWebConnection(); conn.setResponse(new URL(URL_FIRST, "frame.html"), html2); @@ -539,8 +544,7 @@ public void settingInnerHtmlTriggersFrameLoad() throws Exception { @Test @Alerts("something") public void window() throws Exception { - final String html - = "\n" + final String html = DOCTYPE_HTML + "First\n" + "\n" + "\n" + " \n" + + "onLoad='log(\"loaded\")' onError='log(\"error\")'>\n" + "