Skip to content

Commit

Permalink
Upgrade to 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
timja committed May 25, 2023
1 parent d69d1ec commit c943a26
Show file tree
Hide file tree
Showing 14 changed files with 126 additions and 199 deletions.
15 changes: 2 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ THE SOFTWARE.
<licenses>
<license>
<name>MIT</name>
<url>http://opensource.org/licenses/MIT</url>
<url>https://opensource.org/licenses/MIT</url>
</license>
</licenses>

Expand Down Expand Up @@ -121,7 +121,7 @@ THE SOFTWARE.
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jenkins-test-harness-htmlunit</artifactId>
<version>141.v740721146265</version>
<version>142.ve874f871a_6e3</version>
<exclusions>
<exclusion>
<groupId>commons-io</groupId>
Expand Down Expand Up @@ -201,17 +201,6 @@ THE SOFTWARE.
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jvnet.hudson</groupId>
<artifactId>embedded-rhino-debugger</artifactId>
<version>1.2</version>
<exclusions>
<exclusion>
<groupId>org.jvnet.hudson</groupId>
<artifactId>htmlunit-core-js</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.netbeans.modules</groupId>
<artifactId>org-netbeans-insane</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.gargoylesoftware.htmlunit;
package org.htmlunit;

import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.javascript.JavaScriptErrorListener;
import org.htmlunit.html.HtmlPage;
import org.htmlunit.javascript.JavaScriptErrorListener;
import org.junit.Assert;

import java.net.MalformedURLException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.gargoylesoftware.htmlunit;
package org.htmlunit;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.empty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.gargoylesoftware.htmlunit.html;
package org.htmlunit.html;

import com.gargoylesoftware.htmlunit.WebClientUtil;
import com.gargoylesoftware.htmlunit.html.xpath.XPathHelper;
import org.htmlunit.WebClientUtil;
import org.htmlunit.html.xpath.XPathHelper;

import java.util.List;

Expand All @@ -38,7 +38,7 @@ public class DomNodeUtil {
/**
* Evaluates an XPath expression from the specified node, returning the resultant nodes.
* <p>
* Calls {@link WebClientUtil#waitForJSExec(com.gargoylesoftware.htmlunit.WebClient)} before
* Calls {@link WebClientUtil#waitForJSExec(org.htmlunit.WebClient)} before
* executing the query.
*
* @param domNode the node to start searching from
Expand All @@ -54,7 +54,7 @@ public static <E> List<E> selectNodes(final DomNode domNode, final String xpathE
* Evaluates the specified XPath expression from this node, returning the first matching element,
* or {@code null} if no node matches the specified XPath expression.
* <p>
* Calls {@link WebClientUtil#waitForJSExec(com.gargoylesoftware.htmlunit.WebClient)} before
* Calls {@link WebClientUtil#waitForJSExec(org.htmlunit.WebClient)} before
* executing the query.
*
* @param domNode the node to start searching from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.gargoylesoftware.htmlunit.html;
package org.htmlunit.html;

import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebClientUtil;
import org.htmlunit.Page;
import org.htmlunit.WebClient;
import org.htmlunit.WebClientUtil;

import java.io.IOException;
import java.util.Set;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.gargoylesoftware.htmlunit.html;
package org.htmlunit.html;

import com.gargoylesoftware.htmlunit.ElementNotFoundException;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebClientUtil;
import org.htmlunit.ElementNotFoundException;
import org.htmlunit.Page;
import org.htmlunit.WebClient;
import org.htmlunit.WebClientUtil;

import java.io.IOException;
import java.util.List;
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/hudson/security/pages/SignupPage.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package hudson.security.pages;

import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import org.htmlunit.html.HtmlForm;
import org.htmlunit.html.HtmlPage;
import org.jvnet.hudson.test.JenkinsRule;

import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertNotNull;
import static org.hamcrest.MatcherAssert.assertThat;

/**
* The the signup page for {@link hudson.security.HudsonPrivateSecurityRealm}
* The signup page for {@link hudson.security.HudsonPrivateSecurityRealm}
*/
public class SignupPage {

Expand All @@ -31,28 +31,28 @@ public SignupPage(HtmlPage signupPage) {


public void enterUsername(String username) {
signupForm.getInputByName("username").setValueAttribute(username);
signupForm.getInputByName("username").setValue(username);
}

/**
* Enters the password in password1 and password2.
* You can then call {@link #enterPassword2(String)} if you want them to be different.
*/
public void enterPassword(String password) {
signupForm.getInputByName("password1").setValueAttribute(password);
signupForm.getInputByName("password2").setValueAttribute(password);
signupForm.getInputByName("password1").setValue(password);
signupForm.getInputByName("password2").setValue(password);
}

public void enterPassword2(String password2) {
signupForm.getInputByName("password2").setValueAttribute(password2);
signupForm.getInputByName("password2").setValue(password2);
}

public void enterFullName(String fullName) {
signupForm.getInputByName("fullname").setValueAttribute(fullName);
signupForm.getInputByName("fullname").setValue(fullName);
}

public void enterEmail(String email) {
signupForm.getInputByName("email").setValueAttribute(email);
signupForm.getInputByName("email").setValue(email);
}

public HtmlPage submit(JenkinsRule rule) throws Exception {
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/jvnet/hudson/test/HudsonPageCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
*/
package org.jvnet.hudson.test;

import com.gargoylesoftware.htmlunit.DefaultPageCreator;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebResponse;
import com.gargoylesoftware.htmlunit.WebWindow;
import com.gargoylesoftware.htmlunit.PageCreator;
import org.htmlunit.DefaultPageCreator;
import org.htmlunit.Page;
import org.htmlunit.WebResponse;
import org.htmlunit.WebWindow;
import org.htmlunit.PageCreator;

import java.io.IOException;
import java.util.Locale;
Expand Down
98 changes: 34 additions & 64 deletions src/main/java/org/jvnet/hudson/test/HudsonTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,31 @@
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;

import com.gargoylesoftware.css.parser.CSSErrorHandler;
import com.gargoylesoftware.css.parser.CSSException;
import com.gargoylesoftware.css.parser.CSSParseException;
import com.gargoylesoftware.htmlunit.AjaxController;
import com.gargoylesoftware.htmlunit.AlertHandler;
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.DefaultCssErrorHandler;
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebClientUtil;
import com.gargoylesoftware.htmlunit.WebRequest;
import com.gargoylesoftware.htmlunit.html.DomNode;
import com.gargoylesoftware.htmlunit.html.DomNodeUtil;
import com.gargoylesoftware.htmlunit.html.HtmlButton;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlFormUtil;
import com.gargoylesoftware.htmlunit.html.HtmlImage;
import com.gargoylesoftware.htmlunit.html.HtmlInput;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.javascript.AbstractJavaScriptEngine;
import com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory;
import com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine;
import com.gargoylesoftware.htmlunit.javascript.host.xml.XMLHttpRequest;
import com.gargoylesoftware.htmlunit.xml.XmlPage;
import org.htmlunit.AjaxController;
import org.htmlunit.AlertHandler;
import org.htmlunit.BrowserVersion;
import org.htmlunit.DefaultCssErrorHandler;
import org.htmlunit.FailingHttpStatusCodeException;
import org.htmlunit.Page;
import org.htmlunit.WebClientUtil;
import org.htmlunit.WebRequest;
import org.htmlunit.cssparser.parser.CSSErrorHandler;
import org.htmlunit.cssparser.parser.CSSException;
import org.htmlunit.cssparser.parser.CSSParseException;
import org.htmlunit.html.DomNode;
import org.htmlunit.html.DomNodeUtil;
import org.htmlunit.html.HtmlButton;
import org.htmlunit.html.HtmlElement;
import org.htmlunit.html.HtmlForm;
import org.htmlunit.html.HtmlFormUtil;
import org.htmlunit.html.HtmlImage;
import org.htmlunit.html.HtmlInput;
import org.htmlunit.html.HtmlPage;
import org.htmlunit.javascript.AbstractJavaScriptEngine;
import org.htmlunit.javascript.HtmlUnitContextFactory;
import org.htmlunit.javascript.JavaScriptEngine;
import org.htmlunit.javascript.host.xml.XMLHttpRequest;
import org.htmlunit.xml.XmlPage;
import com.google.inject.Injector;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.CloseProofOutputStream;
Expand Down Expand Up @@ -156,8 +156,8 @@
import jenkins.model.JenkinsLocationConfiguration;
import junit.framework.TestCase;
import net.sf.json.JSONObject;
import net.sourceforge.htmlunit.corejs.javascript.Context;
import net.sourceforge.htmlunit.corejs.javascript.ContextFactory;
import org.htmlunit.corejs.javascript.Context;
import org.htmlunit.corejs.javascript.ContextFactory;
import org.acegisecurity.AuthenticationException;
import org.acegisecurity.BadCredentialsException;
import org.acegisecurity.GrantedAuthority;
Expand Down Expand Up @@ -193,8 +193,6 @@
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.mozilla.javascript.tools.debugger.Dim;
import org.mozilla.javascript.tools.shell.Global;
import org.springframework.dao.DataAccessException;
import org.xml.sax.SAXException;

Expand Down Expand Up @@ -1043,7 +1041,7 @@ private List<String> listProperties(String properties) {
/**
* Submits the form.
*
* Plain {@link HtmlForm#submit(com.gargoylesoftware.htmlunit.html.SubmittableElement)} doesn't work correctly due to the use of YUI in Hudson.
* Plain {@link HtmlForm#submit(org.htmlunit.html.SubmittableElement)} doesn't work correctly due to the use of YUI in Hudson.
*/
public HtmlPage submit(HtmlForm form) throws Exception {
return (HtmlPage) HtmlFormUtil.submit(form, last(form.getElementsByTagName("button")));
Expand Down Expand Up @@ -1402,10 +1400,10 @@ public WebClient createWebClient() {
}

/**
* Extends {@link com.gargoylesoftware.htmlunit.WebClient} and provide convenience methods
* Extends {@link org.htmlunit.WebClient} and provide convenience methods
* for accessing Hudson.
*/
public class WebClient extends com.gargoylesoftware.htmlunit.WebClient {
public class WebClient extends org.htmlunit.WebClient {
private static final long serialVersionUID = 8720028298174337333L;

public WebClient() {
Expand Down Expand Up @@ -1488,8 +1486,8 @@ public WebClient login(String username, String password) throws Exception {
HtmlPage page = goTo("/login");

HtmlForm form = page.getFormByName("login");
form.getInputByName("j_username").setValueAttribute(username);
form.getInputByName("j_password").setValueAttribute(password);
form.getInputByName("j_username").setValue(username);
form.getInputByName("j_password").setValue(password);
HtmlFormUtil.submit(form, null);
return this;
}
Expand Down Expand Up @@ -1556,7 +1554,7 @@ public void run() {
public HtmlPage search(String q) throws IOException, SAXException {
HtmlPage top = goTo("");
HtmlForm search = top.getFormByName("search");
search.getInputByName("q").setValueAttribute(q);
search.getInputByName("q").setValue(q);
return (HtmlPage)HtmlFormUtil.submit(search, null);
}

Expand Down Expand Up @@ -1689,7 +1687,7 @@ public String getContextPath() throws IOException {
* Adds a security crumb to the quest
*/
public WebRequest addCrumb(WebRequest req) {
com.gargoylesoftware.htmlunit.util.NameValuePair crumb = new com.gargoylesoftware.htmlunit.util.NameValuePair(
org.htmlunit.util.NameValuePair crumb = new org.htmlunit.util.NameValuePair(
jenkins.getCrumbIssuer().getDescriptor().getCrumbRequestField(),
jenkins.getCrumbIssuer().getCrumb( null ));
req.setRequestParameters(List.of(crumb));
Expand Down Expand Up @@ -1717,34 +1715,6 @@ public HtmlPage eval(final Runnable requestHandler) throws IOException, SAXExcep
return goTo("closures/?uuid="+id);
}

/**
* Starts an interactive JavaScript debugger, and break at the next JavaScript execution.
*
* <p>
* This is useful during debugging a test so that you can step execute and inspect state of JavaScript.
* This will launch a Swing GUI, and the method returns immediately.
*
* <p>
* Note that installing a debugger appears to make an execution of JavaScript substantially slower.
*
* <p>
* TODO: because each script block evaluation in HtmlUnit is done in a separate Rhino context,
* if you step over from one script block, the debugger fails to kick in on the beginning of the next script block.
* This makes it difficult to set a break point on arbitrary script block in the HTML page. We need to fix this
* by tweaking {@link Dim.StackFrame#onLineChange(Context, int)}.
*/
public Dim interactiveJavaScriptDebugger() {
Global global = new Global();
HtmlUnitContextFactory cf = ((JavaScriptEngine)getJavaScriptEngine()).getContextFactory();
global.init(cf);

Dim dim = org.mozilla.javascript.tools.debugger.Main.mainEmbedded(cf, global, "Rhino debugger: " + getName());

// break on exceptions. this catch most of the errors
dim.setBreakOnExceptions(true);

return dim;
}
}

// needs to keep reference, or it gets GC-ed.
Expand Down
Loading

0 comments on commit c943a26

Please sign in to comment.