Skip to content

Commit

Permalink
code style
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Jun 21, 2024
1 parent dcf30b5 commit 8e41d03
Show file tree
Hide file tree
Showing 11 changed files with 310 additions and 167 deletions.
26 changes: 14 additions & 12 deletions src/main/java/org/openqa/selenium/htmlunit/HtmlUnitDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
* @author Rob Winch
* @author Andrei Solntsev
* @author Martin Bartoš
* @author Scott Babcock
*/
public class HtmlUnitDriver implements WebDriver, JavascriptExecutor, HasCapabilities, Interactive {

Expand Down Expand Up @@ -206,7 +207,7 @@ public HtmlUnitDriver(final boolean enableJavascript) {
public HtmlUnitDriver(final BrowserVersion version, final boolean enableJavascript) {
this(new HtmlUnitDriverOptions(version, enableJavascript));
}

public HtmlUnitDriver(final Capabilities desiredCapabilities, final Capabilities requiredCapabilities) {
this(new DesiredCapabilities(desiredCapabilities, requiredCapabilities));
}
Expand All @@ -220,22 +221,23 @@ public HtmlUnitDriver(final Capabilities desiredCapabilities, final Capabilities
* session
*/
public HtmlUnitDriver(final Capabilities capabilities) {
HtmlUnitDriverOptions driverOptions = new HtmlUnitDriverOptions(capabilities);
final HtmlUnitDriverOptions driverOptions = new HtmlUnitDriverOptions(capabilities);
webClient_ = newWebClient(driverOptions.getWebClientVersion());

setAcceptInsecureCerts(Boolean.FALSE != driverOptions.getCapability(ACCEPT_INSECURE_CERTS));

final String pageLoadStrategyString = (String) driverOptions.getCapability(PAGE_LOAD_STRATEGY);
if ("none".equals(pageLoadStrategyString)) {
pageLoadStrategy_ = PageLoadStrategy.NONE;
} else if ("eager".equals(pageLoadStrategyString)) {
}
else if ("eager".equals(pageLoadStrategyString)) {
pageLoadStrategy_ = PageLoadStrategy.EAGER;
}

final WebClientOptions clientOptions = webClient_.getOptions();
driverOptions.applyOptions(clientOptions);
setProxySettings(Proxy.extractFrom(driverOptions));

setProxySettings(Proxy.extractFrom(driverOptions));

webClient_.setRefreshHandler(new WaitingRefreshHandler());
webClient_.setClipboardHandler(new AwtClipboardHandler());
Expand Down Expand Up @@ -1115,7 +1117,7 @@ public Navigation navigate() {
protected HtmlUnitWebElement toWebElement(final DomElement element) {
return getElementsMap().addIfAbsent(this, element);
}

public HtmlUnitWebElement toWebElement(final String elementId) {
return getElementsMap().getWebElement(elementId);
}
Expand Down Expand Up @@ -1307,14 +1309,14 @@ public HtmlUnitWebElement addIfAbsent(final HtmlUnitDriver driver, final DomElem
}

public void remove(final Page page) {
Map<DomElement, HtmlUnitWebElement> pageMap = elementsMapByPage_.remove(page);
final Map<DomElement, HtmlUnitWebElement> pageMap = elementsMapByPage_.remove(page);
if (pageMap != null) {
pageMap.values().forEach(element -> elementsMapById_.remove(Integer.toString(element.getId())));
}
}

public HtmlUnitWebElement getWebElement(final String elementId) {
HtmlUnitWebElement webElement = elementsMapById_.get(elementId);
final HtmlUnitWebElement webElement = elementsMapById_.get(elementId);
if (webElement == null) {
throw new StaleElementReferenceException(
"Failed finding web element associated with identifier: " + elementId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

/**
* @author Scott Babcock
* @author Ronald Brill
*/
public enum BrowserVersionTrait implements BrowserVersionTraitNames, OptionEnum {
/**
Expand Down Expand Up @@ -425,36 +426,36 @@ public Object obtain(final BrowserVersion version) {
}
};

public final String key;
public final String name;
public final Class<?> type;
public final Object initial;
private final String capabilityKey_;
private final String propertyName_;
private final Class<?> optionType_;
private final Object defaultValue_;

BrowserVersionTrait(final String key, final Class<?> type, final Object initial) {
this.key = key;
this.name = "webdriver.htmlunit.browserVersionTrait." + key;
this.type = type;
this.initial = initial;
capabilityKey_ = key;
propertyName_ = "webdriver.htmlunit.browserVersionTrait." + key;
optionType_ = type;
defaultValue_ = initial;
}

@Override
public String getCapabilityKey() {
return key;
return capabilityKey_;
}

@Override
public String getPropertyName() {
return name;
return propertyName_;
}

@Override
public Class<?> getOptionType() {
return type;
return optionType_;
}

@Override
public Object getDefaultValue() {
return initial;
return defaultValue_;
}

/**
Expand All @@ -465,13 +466,13 @@ public Object getDefaultValue() {
*/
@Override
public boolean isDefaultValue(final Object value) {
if (initial == null) {
if (defaultValue_ == null) {
return value == null;
}
if (value == null) {
return false;
}
return value.equals(initial);
return value.equals(defaultValue_);
}

/**
Expand All @@ -481,10 +482,10 @@ public boolean isDefaultValue(final Object value) {
*/
@Override
public void applyPropertyTo(final Map<String, Object> optionsMap) {
final String value = System.getProperty(name);
final String value = System.getProperty(propertyName_);
if (value != null) {
optionsMap.put(key, decode(value));
System.clearProperty(key);
optionsMap.put(capabilityKey_, decode(value));
System.clearProperty(capabilityKey_);
}
}

Expand All @@ -496,17 +497,18 @@ public void applyPropertyTo(final Map<String, Object> optionsMap) {
*/
@Override
public Object encode(final Object value) {
switch (type.getName()) {
switch (optionType_.getName()) {
case "boolean":
case "int":
case "java.lang.String":
return value;
case "java.util.TimeZone":
return TypeCodec.encodeTimeZone(value);
default:
throw new IllegalStateException(
String.format("Unsupported type '%s' specified for option [%s]; value is of type: %s",
optionType_.getName(), toString(), TypeCodec.getClassName(value)));
}
throw new IllegalStateException(
String.format("Unsupported type '%s' specified for option [%s]; value is of type: %s",
this.type.getName(), this.toString(), TypeCodec.getClassName(value)));
}

/**
Expand All @@ -517,7 +519,7 @@ public Object encode(final Object value) {
*/
@Override
public Object decode(final Object value) {
switch (this.type.getName()) {
switch (optionType_.getName()) {
case "boolean":
return TypeCodec.decodeBoolean(value);
case "int":
Expand All @@ -526,10 +528,11 @@ public Object decode(final Object value) {
return TypeCodec.decodeString(value);
case "java.util.TimeZone":
return TypeCodec.decodeTimeZone(value);
default:
throw new IllegalStateException(
String.format("Unsupported type '%s' specified for option [%s]; value is of type: %s",
optionType_.getName(), toString(), TypeCodec.getClassName(value)));
}
throw new IllegalStateException(
String.format("Unsupported type '%s' specified for option [%s]; value is of type: %s",
this.type.getName(), this.toString(), TypeCodec.getClassName(value)));
}

/**
Expand All @@ -540,7 +543,7 @@ public Object decode(final Object value) {
*/
public void apply(final Object value, final BrowserVersionBuilder builder) {
throw new UnsupportedOperationException(
String.format("Trait '%s' does not support value insertion", this.toString()));
String.format("Trait '%s' does not support value insertion", toString()));
}

/**
Expand All @@ -555,7 +558,7 @@ public Object obtain(final BrowserVersion version) {

public static BrowserVersionTrait fromCapabilityKey(final String key) {
for (final BrowserVersionTrait trait : BrowserVersionTrait.values()) {
if (trait.key.equals(key)) {
if (trait.capabilityKey_.equals(key)) {
return trait;
}
}
Expand All @@ -564,7 +567,7 @@ public static BrowserVersionTrait fromCapabilityKey(final String key) {

public static BrowserVersionTrait fromPropertyName(final String name) {
for (final BrowserVersionTrait trait : BrowserVersionTrait.values()) {
if (trait.name.equals(name)) {
if (trait.propertyName_.equals(name)) {
return trait;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,72 @@

/**
* @author Scott Babcock
* @author Ronald Brill
*/
public interface BrowserVersionTraitNames {
/** "browser-version-trait". */
String SECTION = "browser-version-trait";

/** "numericCode". */
String optNumericCode = "numericCode";

/** "nickname". */
String optNickname = "nickname";

/** "applicationVersion". */
String optApplicationVersion = "applicationVersion";

/** "userAgent". */
String optUserAgent = "userAgent";

/** "applicationName". */
String optApplicationName = "applicationName";

/** "applicationCodeName". */
String optApplicationCodeName = "applicationCodeName";

/** "applicationMinorVersion". */
String optApplicationMinorVersion = "applicationMinorVersion";

/** "vendor". */
String optVendor = "vendor";

/** "browserLanguage". */
String optBrowserLanguage = "browserLanguage";

/** "isOnline". */
String optIsOnline = "isOnline";

/** "platform". */
String optPlatform = "platform";

/** "systemTimezone". */
String optSystemTimezone = "systemTimezone";

/** "acceptEncodingHeader". */
String optAcceptEncodingHeader = "acceptEncodingHeader";

/** "acceptLanguageHeader". */
String optAcceptLanguageHeader = "acceptLanguageHeader";

/** "htmlAcceptHeader". */
String optHtmlAcceptHeader = "htmlAcceptHeader";

/** "imgAcceptHeader". */
String optImgAcceptHeader = "imgAcceptHeader";

/** "cssAcceptHeader". */
String optCssAcceptHeader = "cssAcceptHeader";

/** "scriptAcceptHeader". */
String optScriptAcceptHeader = "scriptAcceptHeader";

/** "xmlHttpRequestAcceptHeader". */
String optXmlHttpRequestAcceptHeader = "xmlHttpRequestAcceptHeader";

/** "secClientHintUserAgentHeader". */
String optSecClientHintUserAgentHeader = "secClientHintUserAgentHeader";

/** "secClientHintUserAgentPlatformHeader". */
String optSecClientHintUserAgentPlatformHeader = "secClientHintUserAgentPlatformHeader";
}
Loading

0 comments on commit 8e41d03

Please sign in to comment.