From d3df916033c603e0429645002f48bbb9b4a59df2 Mon Sep 17 00:00:00 2001 From: Ronald Brill Date: Fri, 12 Jan 2024 15:01:56 +0100 Subject: [PATCH] Htmx 1.9.19 --- .../HtmxOneNineTenScriptPreprozessor.java | 67 +++++++++++++++++++ .../java/org/htmlunit/libraries/HtmxTest.java | 7 +- .../htmlunit/libraries/HtmxTest1x9x10.java | 59 ++++++++++++++++ 3 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 src/main/java/org/htmlunit/javascript/preprocessor/HtmxOneNineTenScriptPreprozessor.java create mode 100644 src/test/java/org/htmlunit/libraries/HtmxTest1x9x10.java diff --git a/src/main/java/org/htmlunit/javascript/preprocessor/HtmxOneNineTenScriptPreprozessor.java b/src/main/java/org/htmlunit/javascript/preprocessor/HtmxOneNineTenScriptPreprozessor.java new file mode 100644 index 00000000000..745d7502ade --- /dev/null +++ b/src/main/java/org/htmlunit/javascript/preprocessor/HtmxOneNineTenScriptPreprozessor.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2002-2024 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.preprocessor; + +import org.apache.commons.lang3.StringUtils; +import org.htmlunit.ScriptPreProcessor; +import org.htmlunit.html.HtmlElement; +import org.htmlunit.html.HtmlPage; + +/** + * Preprozessor to fix one default parameter method. + * + * @author Ronald Brill + */ +public class HtmxOneNineTenScriptPreprozessor implements ScriptPreProcessor { + + private final ScriptPreProcessor nextScriptPreProcessor_; + + public HtmxOneNineTenScriptPreprozessor() { + nextScriptPreProcessor_ = null; + } + + public HtmxOneNineTenScriptPreprozessor(final ScriptPreProcessor nextScriptPreProcessor) { + nextScriptPreProcessor_ = nextScriptPreProcessor; + } + + @Override + public String preProcess(final HtmlPage htmlPage, final String sourceCode, final String sourceName, + final int lineNumber, final HtmlElement htmlElement) { + + String patchedSourceCode = sourceCode; + + if (sourceName.contains("/htmx.js")) { + patchedSourceCode = StringUtils.replace( + sourceCode, + "function makeTagRegEx(tag, global = false) {", + "function makeTagRegEx(tag) {\n" + + " " + + "var global = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;\n"); + } + else if (sourceName.contains("/htmx.min.js")) { + patchedSourceCode = StringUtils.replace( + sourceCode, + "function e(e,t=false){", + "function e(e){" + + "var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; "); + } + + if (nextScriptPreProcessor_ != null) { + return nextScriptPreProcessor_.preProcess(htmlPage, patchedSourceCode, sourceName, lineNumber, htmlElement); + } + + return patchedSourceCode; + } +} diff --git a/src/test/java/org/htmlunit/libraries/HtmxTest.java b/src/test/java/org/htmlunit/libraries/HtmxTest.java index 0281da3c3ac..33f0d40d0dc 100644 --- a/src/test/java/org/htmlunit/libraries/HtmxTest.java +++ b/src/test/java/org/htmlunit/libraries/HtmxTest.java @@ -49,8 +49,8 @@ protected void htmx(final String subDir) throws Exception { final String url = URL_FIRST + "test/index.html"; final WebDriver webDriver = getWebDriver(); - if (getWebDriver() instanceof HtmlUnitDriver) { - getWebClient().getOptions().setThrowExceptionOnScriptError(false); + if (webDriver instanceof HtmlUnitDriver) { + setupWebClient(((HtmlUnitDriver) webDriver).getWebClient()); } int tries = 0; @@ -102,6 +102,9 @@ protected void htmx(final String subDir) throws Exception { } } + protected void setupWebClient(final WebClient webClient) { + } + private static String getResultElementText(final WebDriver webdriver) { // if the elem is not available or stale we return an empty string // this will force a second try diff --git a/src/test/java/org/htmlunit/libraries/HtmxTest1x9x10.java b/src/test/java/org/htmlunit/libraries/HtmxTest1x9x10.java new file mode 100644 index 00000000000..f4c8fe57bb7 --- /dev/null +++ b/src/test/java/org/htmlunit/libraries/HtmxTest1x9x10.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2002-2024 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.libraries; + +import org.htmlunit.WebClient; +import org.htmlunit.javascript.preprocessor.HtmxOneNineTenScriptPreprozessor; +import org.htmlunit.junit.BrowserRunner; +import org.htmlunit.junit.BrowserRunner.Alerts; +import org.htmlunit.junit.BrowserRunner.HtmlUnitNYI; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * Tests for htmx. + * + * @author Ronald Brill + */ +@RunWith(BrowserRunner.class) +public class HtmxTest1x9x10 extends HtmxTest { + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = "passes:679failures:1", + FF = "passes:679failures:0", + FF_ESR = "passes:679failures:0", + IE = "not testable") + @HtmlUnitNYI( + CHROME = "passes:679failures:0", + EDGE = "passes:679failures:0") + public void htmx() throws Exception { + // the test page runs in an endless loop in ie + if (getBrowserVersion().isIE()) { + return; + } + htmx("htmx-1.9.10"); + } + + @Override + protected void setupWebClient(final WebClient webClient) { + super.setupWebClient(webClient); + + webClient.setScriptPreProcessor(new HtmxOneNineTenScriptPreprozessor()); + webClient.getOptions().setThrowExceptionOnScriptError(false); + } +}