Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Sep 22, 2024
1 parent 08bfc11 commit 9983b16
Showing 1 changed file with 10 additions and 26 deletions.
36 changes: 10 additions & 26 deletions src/test/java/org/htmlunit/WebDriverTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -592,14 +592,13 @@ private FirefoxDriver createFirefoxDriver(final String geckodriverBinary, final
final FirefoxOptions options = new FirefoxOptions();
options.setBinary(binary);

final String tz = getBrowserVersion().getSystemTimezone().getID();

String locale = getBrowserVersion().getBrowserLocale().toLanguageTag();
locale = locale + "," + getBrowserVersion().getBrowserLocale().getLanguage();

final FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("intl.accept_languages", locale);
// no idea so far how to set this
// final String tz = getBrowserVersion().getSystemTimezone().getID();
// profile.setPreference("intl.tz", tz);
options.setProfile(profile);

Expand Down Expand Up @@ -630,7 +629,7 @@ protected void startWebServer(final MockWebConnection mockConnection, final Char

LAST_TEST_UsesMockWebConnection_ = Boolean.TRUE;
if (STATIC_SERVER_ == null) {
final Server server = buildServer(PORT);
final Server server = new Server(PORT);

final WebAppContext context = new WebAppContext();
context.setContextPath("/");
Expand Down Expand Up @@ -666,7 +665,7 @@ protected void startWebServer(final MockWebConnection mockConnection, final Char
MockWebConnectionServlet.MockConnection_ = mockConnection;

if (STATIC_SERVER2_ == null && needThreeConnections()) {
final Server server2 = buildServer(PORT2);
final Server server2 = new Server(PORT2);
final WebAppContext context2 = new WebAppContext();
context2.setContextPath("/");
context2.setResourceBase("./");
Expand All @@ -677,7 +676,7 @@ protected void startWebServer(final MockWebConnection mockConnection, final Char
STATIC_SERVER2_STARTER_ = ExceptionUtils.getStackTrace(new Throwable("StaticServer2Starter"));
STATIC_SERVER2_ = server2;

final Server server3 = buildServer(PORT3);
final Server server3 = new Server(PORT3);
final WebAppContext context3 = new WebAppContext();
context3.setContextPath("/");
context3.setResourceBase("./");
Expand Down Expand Up @@ -958,7 +957,6 @@ protected final WebDriver loadPage2(String html, final URL url,
return loadPage2(url, serverCharset);
}


/**
* Load the page from the url.
* @param url the url to use to load the page
Expand Down Expand Up @@ -1570,26 +1568,6 @@ protected void assertTitle(final WebDriver webdriver, final String expected) thr
}
}

// limit resource usage
private static Server buildServer(final int port) {
return new Server(port);

// https://github.com/HtmlUnit/htmlunit/issues/462
// https://github.com/eclipse/jetty.project/issues/2503
// the value for the QueuedThreadPool are validated,
// let's make another try with the defaults
//
// final QueuedThreadPool threadPool = new QueuedThreadPool(5, 2);
//
// final Server server = new Server(threadPool);
//
// final ServerConnector connector = new ServerConnector(server);
// connector.setPort(port);
// server.setConnectors(new Connector[] {connector});
//
// return server;
}

/**
* Release resources but DON'T close the browser if we are running with a real browser.
* Note that HtmlUnitDriver is not cached by default, but that can be configured by {@link #isWebClientCached()}.
Expand Down Expand Up @@ -1673,6 +1651,12 @@ public void releaseResources() {
// in the remaining window, load a blank page
driver.get("about:blank");
}
catch (final NoSuchSessionException e) {
LOG.error("Error browser session no longer available.", e);
WEB_DRIVERS_REAL_BROWSERS.remove(getBrowserVersion());
WEB_DRIVERS_REAL_BROWSERS_USAGE_COUNT.remove(getBrowserVersion());
return;
}
catch (final WebDriverException e) {
shutDownRealBrowsers();
}
Expand Down

0 comments on commit 9983b16

Please sign in to comment.