Skip to content

Commit

Permalink
AlexeiBarantsev: Updating HtmlUnit to 2.11
Browse files Browse the repository at this point in the history
r18284
  • Loading branch information
barancev committed Dec 9, 2012
1 parent 9cc2f55 commit d426628
Show file tree
Hide file tree
Showing 18 changed files with 381 additions and 362 deletions.
93 changes: 46 additions & 47 deletions java/client/.classpath
Original file line number Diff line number Diff line change
@@ -1,47 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
<classpathentry kind="lib" path="/third-party/java/junit/junit-dep-4.11.jar" sourcepath="/third-party/java/junit/junit-dep-4.11-src.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="/third-party/java/hamcrest/hamcrest-core-1.3.jar"/>
<classpathentry kind="lib" path="/third-party/java/hamcrest/hamcrest-library-1.3.jar"/>
<classpathentry kind="lib" path="/third-party/java/testng/testng-6.8.jar" sourcepath="/third-party/java/testng/testng-6.8-sources.jar"/>
<classpathentry kind="lib" path="/third-party/java/guava-libraries/guava-13.0.1.jar" sourcepath="/third-party/java/guava-libraries/guava-13.0.1-sources.jar"/>
<classpathentry kind="lib" path="/third-party/java/htmlunit/htmlunit-2.10.jar" sourcepath="/third-party/java/htmlunit/htmlunit-2.10-sources.jar"/>
<classpathentry kind="lib" path="/third-party/java/htmlunit/htmlunit-core-js-2.10.jar"/>
<classpathentry kind="lib" path="/third-party/java/jna/jna-3.4.0.jar" sourcepath="/third-party/java/jna/jna-3.4.0-src.jar"/>
<classpathentry kind="lib" path="/third-party/java/jna/jna-platform-3.4.0.jar" sourcepath="/third-party/java/jna/jna-platform-3.4.0-src.jar"/>
<classpathentry kind="lib" path="/third-party/java/commons-exec/commons-exec-1.1.jar" sourcepath="/third-party/java/commons-exec/commons-exec-1.1-sources.jar"/>
<classpathentry kind="lib" path="/third-party/java/jetty/jetty-repacked-7.6.1.jar" sourcepath="/third-party/java/jetty/jetty-repacked-7.6.1-sources.jar"/>
<classpathentry kind="lib" path="/third-party/java/cglib/cglib-nodep-2.1_3.jar"/>
<classpathentry kind="lib" path="/third-party/java/json/json-20080701.jar"/>
<classpathentry kind="lib" path="/third-party/java/servlet-api/servlet-api-2.5-6.1.9.jar" sourcepath="/third-party/java/servlet-api/servlet-api-2.5-6.1.9-sources.jar"/>
<classpathentry kind="lib" path="/third-party/java/easymock/easymock-2.4.jar"/>
<classpathentry kind="lib" path="/third-party/java/easymock/easymockclassextension-2.4.jar"/>
<classpathentry kind="lib" path="/third-party/java/jmock/jmock-2.5.1.jar"/>
<classpathentry kind="lib" path="/third-party/java/jmock/jmock-junit4-2.5.1.jar"/>
<classpathentry kind="lib" path="/third-party/java/opera-driver/operadriver-1.1.jar" sourcepath="/third-party/java/opera-driver/operadriver-1.1-source.jar"/>
<classpathentry kind="lib" path="/third-party/java/apache-httpclient/httpclient-4.2.1.jar" sourcepath="/third-party/java/apache-httpclient/httpclient-4.2.1-sources.jar"/>
<classpathentry kind="lib" path="/third-party/java/apache-httpclient/httpcore-4.2.1.jar" sourcepath="/third-party/java/apache-httpclient/httpcore-4.2.1-sources.jar"/>
<classpathentry kind="lib" path="/third-party/java/android/android-14.jar"/>
<classpathentry kind="lib" path="/third-party/java/commons-logging/commons-logging-1.1.1.jar"/>
<classpathentry kind="lib" path="/third-party/java/commons-io/commons-io-2.2.jar" sourcepath="/third-party/java/commons-io/commons-io-2.2-src.zip"/>
<classpathentry kind="lib" path="/third-party/java/commons-codec/commons-codec-1.6.jar" sourcepath="/third-party/java/commons-codec/commons-codec-1.6-sources.jar"/>
<classpathentry kind="lib" path="/third-party/java/sac/sac-1.3.jar"/>
<classpathentry kind="lib" path="/third-party/java/commons-lang/commons-lang3-3.1.jar" sourcepath="/third-party/java/commons-lang/commons-lang3-3.1-sources.jar"/>
<classpathentry kind="lib" path="/third-party/java/apache-httpclient/httpmime-4.2.1.jar" sourcepath="/third-party/java/apache-httpclient/httpmime-4.2.1-sources.jar"/>
<classpathentry kind="lib" path="/third-party/java/commons-collections/commons-collections-3.2.1.jar" sourcepath="/third-party/java/commons-collections/commons-collections-3.2.1-sources.jar"/>
<classpathentry kind="lib" path="/third-party/java/cssparser/cssparser-0.9.7.jar"/>
<classpathentry kind="lib" path="/third-party/java/xml/xercesImpl-2.9.1.jar"/>
<classpathentry kind="lib" path="/third-party/java/xml/xalan-2.7.1.jar"/>
<classpathentry kind="lib" path="/third-party/java/commons-fileupload/commons-fileupload-1.2.2.jar" sourcepath="/third-party/java/commons-fileupload/commons-fileupload-1.2.2-src.jar"/>
<classpathentry kind="lib" path="/third-party/java/webbit/webbit-0.4.14.jar" sourcepath="/third-party/java/webbit/webbit-0.4.14-src.jar"/>
<classpathentry kind="lib" path="/third-party/java/little_proxy/littleproxy-0.5-SNAPSHOT.jar" sourcepath="/third-party/java/little_proxy/littleproxy-0.5-SNAPSHOT-sources.jar"/>
<classpathentry kind="lib" path="/third-party/java/nekohtml/nekohtml-1.9.16.jar"/>
<classpathentry kind="lib" path="/third-party/java/netty/netty-3.5.7.Final.jar"/>
<!-- Don't remove these! They are used by OperaDriver. -->
<classpathentry kind="lib" path="/third-party/java/google-protobuffers/protobuf-java-2.4.1.jar"/>
<classpathentry kind="lib" path="/third-party/java/commons-jxpath/commons-jxpath-1.3.jar"/>
<classpathentry kind="output" path="build/production"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
<classpathentry kind="lib" path="/third-party/java/junit/junit-dep-4.11.jar" sourcepath="/third-party/java/junit/junit-dep-4.11-src.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="/third-party/java/hamcrest/hamcrest-core-1.3.jar"/>
<classpathentry kind="lib" path="/third-party/java/hamcrest/hamcrest-library-1.3.jar"/>
<classpathentry kind="lib" path="/third-party/java/testng/testng-6.8.jar" sourcepath="/third-party/java/testng/testng-6.8-sources.jar"/>
<classpathentry kind="lib" path="/third-party/java/guava-libraries/guava-13.0.1.jar" sourcepath="/third-party/java/guava-libraries/guava-13.0.1-sources.jar"/>
<classpathentry kind="lib" path="/third-party/java/htmlunit/htmlunit-2.11.jar" sourcepath="/third-party/java/htmlunit/htmlunit-2.11-sources.jar"/>
<classpathentry kind="lib" path="/third-party/java/htmlunit/htmlunit-core-js-2.11.jar"/>
<classpathentry kind="lib" path="/third-party/java/jna/jna-3.4.0.jar" sourcepath="/third-party/java/jna/jna-3.4.0-src.jar"/>
<classpathentry kind="lib" path="/third-party/java/jna/jna-platform-3.4.0.jar" sourcepath="/third-party/java/jna/jna-platform-3.4.0-src.jar"/>
<classpathentry kind="lib" path="/third-party/java/commons-exec/commons-exec-1.1.jar" sourcepath="/third-party/java/commons-exec/commons-exec-1.1-sources.jar"/>
<classpathentry kind="lib" path="/third-party/java/jetty/jetty-repacked-7.6.1.jar" sourcepath="/third-party/java/jetty/jetty-repacked-7.6.1-sources.jar"/>
<classpathentry kind="lib" path="/third-party/java/cglib/cglib-nodep-2.1_3.jar"/>
<classpathentry kind="lib" path="/third-party/java/json/json-20080701.jar"/>
<classpathentry kind="lib" path="/third-party/java/servlet-api/servlet-api-2.5-6.1.9.jar" sourcepath="/third-party/java/servlet-api/servlet-api-2.5-6.1.9-sources.jar"/>
<classpathentry kind="lib" path="/third-party/java/easymock/easymock-2.4.jar"/>
<classpathentry kind="lib" path="/third-party/java/easymock/easymockclassextension-2.4.jar"/>
<classpathentry kind="lib" path="/third-party/java/jmock/jmock-2.5.1.jar"/>
<classpathentry kind="lib" path="/third-party/java/jmock/jmock-junit4-2.5.1.jar"/>
<classpathentry kind="lib" path="/third-party/java/opera-driver/operadriver-1.1.jar" sourcepath="/third-party/java/opera-driver/operadriver-1.1-source.jar"/>
<classpathentry kind="lib" path="/third-party/java/apache-httpclient/httpclient-4.2.1.jar" sourcepath="/third-party/java/apache-httpclient/httpclient-4.2.1-sources.jar"/>
<classpathentry kind="lib" path="/third-party/java/apache-httpclient/httpcore-4.2.1.jar" sourcepath="/third-party/java/apache-httpclient/httpcore-4.2.1-sources.jar"/>
<classpathentry kind="lib" path="/third-party/java/android/android-14.jar"/>
<classpathentry kind="lib" path="/third-party/java/commons-logging/commons-logging-1.1.1.jar"/>
<classpathentry kind="lib" path="/third-party/java/commons-io/commons-io-2.2.jar" sourcepath="/third-party/java/commons-io/commons-io-2.2-src.zip"/>
<classpathentry kind="lib" path="/third-party/java/commons-codec/commons-codec-1.6.jar" sourcepath="/third-party/java/commons-codec/commons-codec-1.6-sources.jar"/>
<classpathentry kind="lib" path="/third-party/java/sac/sac-1.3.jar"/>
<classpathentry kind="lib" path="/third-party/java/commons-lang/commons-lang3-3.1.jar" sourcepath="/third-party/java/commons-lang/commons-lang3-3.1-sources.jar"/>
<classpathentry kind="lib" path="/third-party/java/apache-httpclient/httpmime-4.2.1.jar" sourcepath="/third-party/java/apache-httpclient/httpmime-4.2.1-sources.jar"/>
<classpathentry kind="lib" path="/third-party/java/commons-collections/commons-collections-3.2.1.jar" sourcepath="/third-party/java/commons-collections/commons-collections-3.2.1-sources.jar"/>
<classpathentry kind="lib" path="/third-party/java/cssparser/cssparser-0.9.7.jar"/>
<classpathentry kind="lib" path="/third-party/java/xml/xercesImpl-2.9.1.jar"/>
<classpathentry kind="lib" path="/third-party/java/xml/xalan-2.7.1.jar"/>
<classpathentry kind="lib" path="/third-party/java/commons-fileupload/commons-fileupload-1.2.2.jar" sourcepath="/third-party/java/commons-fileupload/commons-fileupload-1.2.2-src.jar"/>
<classpathentry kind="lib" path="/third-party/java/webbit/webbit-0.4.14.jar" sourcepath="/third-party/java/webbit/webbit-0.4.14-src.jar"/>
<classpathentry kind="lib" path="/third-party/java/little_proxy/littleproxy-0.5-SNAPSHOT.jar" sourcepath="/third-party/java/little_proxy/littleproxy-0.5-SNAPSHOT-sources.jar"/>
<classpathentry kind="lib" path="/third-party/java/nekohtml/nekohtml-1.9.16.jar"/>
<classpathentry kind="lib" path="/third-party/java/netty/netty-3.5.7.Final.jar"/>
<classpathentry kind="lib" path="/third-party/java/google-protobuffers/protobuf-java-2.4.1.jar"/>
<classpathentry kind="lib" path="/third-party/java/commons-jxpath/commons-jxpath-1.3.jar"/>
<classpathentry kind="output" path="build/production"/>
</classpath>
4 changes: 2 additions & 2 deletions java/client/client.eml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<lib name="guava-11.0.1.jar" scope="COMPILE">
<srcroot url="file:///third-party/java/guava-libraries/guava-11.0.1-src.jar"/>
</lib>
<lib name="htmlunit-2.9.jar" scope="COMPILE">
<srcroot url="file:///third-party/java/htmlunit/htmlunit-2.9-sources.jar"/>
<lib name="htmlunit-2.11.jar" scope="COMPILE">
<srcroot url="file:///third-party/java/htmlunit/htmlunit-2.11-sources.jar"/>
</lib>
<lib name="jna-3.4.0.jar" scope="COMPILE">
<srcroot url="file:///third-party/java/jna/jna-3.4.0-src.jar"/>
Expand Down
52 changes: 25 additions & 27 deletions java/client/src/org/openqa/selenium/htmlunit/HtmlUnitDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@
import com.gargoylesoftware.htmlunit.TopLevelWindow;
import com.gargoylesoftware.htmlunit.WaitingRefreshHandler;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebClientOptions;
import com.gargoylesoftware.htmlunit.WebResponse;
import com.gargoylesoftware.htmlunit.WebWindow;
import com.gargoylesoftware.htmlunit.WebWindowEvent;
import com.gargoylesoftware.htmlunit.WebWindowListener;
import com.gargoylesoftware.htmlunit.WebWindowNotFoundException;
import com.gargoylesoftware.htmlunit.html.BaseFrame;
import com.gargoylesoftware.htmlunit.html.BaseFrameElement;
import com.gargoylesoftware.htmlunit.html.DomElement;
import com.gargoylesoftware.htmlunit.html.DomNode;
import com.gargoylesoftware.htmlunit.html.DomNodeList;
import com.gargoylesoftware.htmlunit.html.FrameWindow;
Expand All @@ -94,7 +96,6 @@
import java.net.ConnectException;
import java.net.URL;
import java.net.UnknownHostException;
import java.security.GeneralSecurityException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand Down Expand Up @@ -159,7 +160,7 @@ public void webWindowClosed(WebWindowEvent event) {
});

// Now put us on the home page, like a real browser
get(webClient.getHomePage());
get(webClient.getOptions().getHomePage());
gotPage = false;
resetKeyboardAndMouseState();
}
Expand Down Expand Up @@ -252,24 +253,21 @@ static BrowserVersion determineBrowserVersion(Capabilities capabilities) {

private WebClient createWebClient(BrowserVersion version) {
WebClient client = newWebClient(version);
client.setHomePage(WebClient.URL_ABOUT_BLANK.toString());
client.setThrowExceptionOnFailingStatusCode(false);
client.setPrintContentOnFailingStatusCode(false);
client.setJavaScriptEnabled(enableJavascript);
client.setRedirectEnabled(true);
client.setRefreshHandler(new WaitingRefreshHandler());

try {
client.setUseInsecureSSL(true);
} catch (GeneralSecurityException e) {
throw new WebDriverException(e);
}
WebClientOptions options = client.getOptions();
options.setHomePage(WebClient.URL_ABOUT_BLANK.toString());
options.setThrowExceptionOnFailingStatusCode(false);
options.setPrintContentOnFailingStatusCode(false);
options.setJavaScriptEnabled(enableJavascript);
options.setRedirectEnabled(true);
options.setUseInsecureSSL(true);

// Ensure that we've set the proxy if necessary
if (proxyConfig != null) {
client.setProxyConfig(proxyConfig);
options.setProxyConfig(proxyConfig);
}

client.setRefreshHandler(new WaitingRefreshHandler());

return modifyWebClient(client);
}

Expand Down Expand Up @@ -297,13 +295,13 @@ protected WebClient modifyWebClient(WebClient client) {

public void setProxy(String host, int port) {
proxyConfig = new ProxyConfig(host, port);
webClient.setProxyConfig(proxyConfig);
webClient.getOptions().setProxyConfig(proxyConfig);
}

public void setAutoProxy(String autoProxyUrl) {
proxyConfig = new ProxyConfig();
proxyConfig.setProxyAutoConfigUrl(autoProxyUrl);
webClient.setProxyConfig(proxyConfig);
webClient.getOptions().setProxyConfig(proxyConfig);
}

public Capabilities getCapabilities() {
Expand Down Expand Up @@ -743,9 +741,9 @@ public WebElement findElementByName(String name) {
throw new IllegalStateException("Unable to locate element by name for " + lastPage());
}

List<HtmlElement> allElements = ((HtmlPage) lastPage()).getElementsByName(name);
List<DomElement> allElements = ((HtmlPage) lastPage()).getElementsByName(name);
if (!allElements.isEmpty()) {
return newHtmlUnitWebElement(allElements.get(0));
return newHtmlUnitWebElement((HtmlElement) allElements.get(0));
}

throw new NoSuchElementException("Unable to locate element with name: " + name);
Expand All @@ -756,7 +754,7 @@ public List<WebElement> findElementsByName(String using) {
return new ArrayList<WebElement>();
}

List<HtmlElement> allElements = ((HtmlPage) lastPage()).getElementsByName(using);
List<DomElement> allElements = ((HtmlPage) lastPage()).getElementsByName(using);
return convertRawHtmlElementsToWebElements(allElements);
}

Expand Down Expand Up @@ -861,12 +859,12 @@ private List<WebElement> convertRawHtmlElementsToWebElements(List<?> nodes) {
}

public boolean isJavascriptEnabled() {
return webClient.isJavaScriptEnabled();
return webClient.getOptions().isJavaScriptEnabled();
}

public void setJavascriptEnabled(boolean enableJavascript) {
this.enableJavascript = enableJavascript;
webClient.setJavaScriptEnabled(enableJavascript);
webClient.getOptions().setJavaScriptEnabled(enableJavascript);
}

private class HtmlUnitTargetLocator implements TargetLocator {
Expand Down Expand Up @@ -900,8 +898,8 @@ public WebDriver frame(final String nameOrId) {
HtmlUnitWebElement element =
(HtmlUnitWebElement) HtmlUnitDriver.this.findElementById(nameOrId);
HtmlElement domElement = element.getElement();
if (domElement instanceof BaseFrame) {
currentWindow = ((BaseFrame) domElement).getEnclosedWindow();
if (domElement instanceof BaseFrameElement) {
currentWindow = ((BaseFrameElement) domElement).getEnclosedWindow();
return HtmlUnitDriver.this;
}
} catch (NoSuchElementException ignored) {
Expand All @@ -919,11 +917,11 @@ public WebDriver frame(WebElement frameElement) {
webElement.assertElementNotStale();

HtmlElement domElement = webElement.getElement();
if (!(domElement instanceof BaseFrame)) {
if (!(domElement instanceof BaseFrameElement)) {
throw new NoSuchFrameException(webElement.getTagName() + " is not a frame element.");
}

currentWindow = ((BaseFrame) domElement).getEnclosedWindow();
currentWindow = ((BaseFrameElement) domElement).getEnclosedWindow();
return HtmlUnitDriver.this;
}

Expand Down
Loading

0 comments on commit d426628

Please sign in to comment.