Skip to content

Commit

Permalink
Removing use of WindowsProxyManager from InternetExplorerDriver, prox…
Browse files Browse the repository at this point in the history
…y management is implemented in IEDriverServer now
  • Loading branch information
barancev committed Oct 22, 2013
1 parent 2c476c1 commit e92c363
Showing 1 changed file with 6 additions and 82 deletions.
88 changes: 6 additions & 82 deletions java/client/src/org/openqa/selenium/ie/InternetExplorerDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@

package org.openqa.selenium.ie;

import com.google.common.base.Predicate;
import com.google.common.base.Throwables;
import com.google.common.collect.Maps;

import org.openqa.selenium.Capabilities;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.Platform;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.browserlaunchers.WindowsProxyManager;
Expand All @@ -36,8 +33,6 @@
import org.openqa.selenium.remote.service.DriverCommandExecutor;

import java.io.File;
import java.util.HashSet;
import java.util.Set;

import static org.openqa.selenium.remote.CapabilityType.PROXY;

Expand Down Expand Up @@ -146,31 +141,11 @@ public class InternetExplorerDriver extends RemoteWebDriver implements TakesScre
*/
public final static String IE_SWITCHES = "ie.browserCommandLineSwitches";

/**
* @deprecated please set this option as True and allow IEDriverServer sets up proxy.
* In next releases it will be set to True by default.
*
* Capability that defines used proxy setter. Currently it's False by default.
*
* False means WindowsProxyManager will be used for setting proxy settings.
* True means IEDriverServer will be used for setting proxy settings.
*
* Be note that using both variants in concurrent drivers at the same node
* may lead to undefined behaviour.
*/
@Deprecated
public final static String IE_SET_PROXY_BY_SERVER = "ie.setProxyByServer";

/**
* Port which is used by default.
*/
private final static int DEFAULT_PORT = 0;

/**
* To set proxy by server or not.
*/
private final boolean setProxyByServer;

/**
* Proxy manager.
*/
Expand Down Expand Up @@ -201,27 +176,22 @@ public InternetExplorerDriver(WindowsProxyManager proxy, InternetExplorerDriverS
capabilities = DesiredCapabilities.internetExplorer();
}

setProxyByServer = useServerForProxy(capabilities);
proxyManager = proxy;

if (proxy == null) {
proxyManager = setupProxy(capabilities);
} else {
proxyManager = proxy;
}
if (service == null) {
service = setupService(capabilities, port);
}
run(service, capabilities, port);
run(service, capabilities);
}

private void run(InternetExplorerDriverService service, Capabilities capabilities, int port) {
private void run(InternetExplorerDriverService service, Capabilities capabilities) {
assertOnWindows();

prepareProxy(capabilities);

setCommandExecutor(new DriverCommandExecutor(service));

startSession(updateCapabilities(capabilities));
startSession(capabilities);
}

@Override
Expand Down Expand Up @@ -290,32 +260,16 @@ private InternetExplorerDriverService setupService(Capabilities caps, int port)
}
}

InternetExplorerDriverService service = builder.build();

return service;
return builder.build();

} catch (IllegalStateException ex) {
throw Throwables.propagate(ex);
}
}

private WindowsProxyManager setupProxy(Capabilities caps) {
// do not create proxy manager if it's not requested. see issue 4135
// also do not create proxy manager if it will be managed by server.
if (caps == null || caps.getCapability(PROXY) == null || setProxyByServer) {
return null;
}

return new WindowsProxyManager(
/* boolean customPACappropriate */ true,
/* String sessionId */ "webdriver-ie",
/* int port */ 0,
/* int portDriversShouldContact */ 0);
}

private void prepareProxy(Capabilities caps) {
// do not prepare proxy manager if it will be managed by server.
if (caps == null || caps.getCapability(PROXY) == null || setProxyByServer) {
if (caps == null || caps.getCapability(PROXY) == null || proxyManager == null) {
return;
}

Expand All @@ -333,34 +287,4 @@ public void run() {
Runtime.getRuntime().addShutdownHook(cleanupThread);
}

/**
* Determine to use server for setting proxy or not.
*
* @param caps capabilties
* @return to use or not
*/
private boolean useServerForProxy(Capabilities caps) {
if (caps == null || caps.getCapability(IE_SET_PROXY_BY_SERVER) == null) {
return false;
}

return (Boolean) caps.getCapability(IE_SET_PROXY_BY_SERVER);
}

/**
* if proxy will be not managed by server overwrite proxy capability so
* server will do nothing.
*/
private Capabilities updateCapabilities(Capabilities capabilities) {
if (capabilities == null || capabilities.getCapability(PROXY) == null || setProxyByServer) {
return capabilities;
}

Proxy proxy = new Proxy();
proxy.setProxyType(Proxy.ProxyType.SYSTEM);
((DesiredCapabilities) capabilities).setCapability(PROXY, proxy);

return capabilities;
}

}

0 comments on commit e92c363

Please sign in to comment.