Skip to content

Commit

Permalink
Avoid adding webdriver extension to the profile if we use marionette,…
Browse files Browse the repository at this point in the history
… and

use a random port
  • Loading branch information
barancev committed Sep 10, 2013
1 parent fe02f78 commit ef4e042
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ public Timeouts setScriptTimeout(long time, TimeUnit unit) {
protected void startClient() {
LazyCommandExecutor exe = (LazyCommandExecutor) getCommandExecutor();
FirefoxProfile profileToUse = getProfile(exe.profile);
profileToUse.addWebDriverExtensionIfNeeded();

// TODO(simon): Make this not sinfully ugly
ExtensionConnection connection = connectTo(exe.binary, profileToUse, "localhost");
Expand Down
12 changes: 3 additions & 9 deletions java/client/src/org/openqa/selenium/firefox/FirefoxProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,8 @@ private void verifyModel(File model) {
}
}

protected void addWebDriverExtensionIfNeeded() {
if (extensions.containsKey("webdriver")) {
return;
}

ClasspathExtension extension = new ClasspathExtension(FirefoxProfile.class,
"/" + FirefoxProfile.class.getPackage().getName().replace(".", "/") + "/webdriver.xpi");
addExtension("webdriver", extension);
public boolean containsWebDriverExtension() {
return extensions.containsKey("webdriver");
}

public void addExtension(Class<?> loadResourcesUsing, String loadFrom) throws IOException {
Expand All @@ -192,7 +186,7 @@ public void addExtension(File extensionToInstall) throws IOException {
addExtension(extensionToInstall.getName(), new FileExtension(extensionToInstall));
}

protected void addExtension(String key, Extension extension) {
public void addExtension(String key, Extension extension) {
String name = deriveExtensionName(key);
extensions.put(name, extension);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.openqa.selenium.internal.Lock;
import org.openqa.selenium.logging.LocalLogs;
import org.openqa.selenium.logging.NeedsLocalLogs;
import org.openqa.selenium.net.PortProber;
import org.openqa.selenium.remote.BeanToJsonConverter;
import org.openqa.selenium.remote.Command;
import org.openqa.selenium.remote.DriverCommand;
Expand Down Expand Up @@ -93,10 +94,10 @@ public MarionetteConnection(Lock lock, FirefoxBinary binary, FirefoxProfile prof
}

public void start() throws IOException {
int port = 2828;
int port = PortProber.findFreePort();

profile.setPreference("marionette.defaultPrefs.enabled", true);
profile.setPreference("marionette.defaultPrefs.port", 2828);
profile.setPreference("marionette.defaultPrefs.port", port);
profile.setPreference("browser.warnOnQuit", false);

lock.lock(connectTimeout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public NewProfileExtensionConnection(Lock lock, FirefoxBinary binary, FirefoxPro
}

public void start() throws IOException {
addWebDriverExtensionIfNeeded();

int port = 0;

lock.lock(connectTimeout);
Expand Down Expand Up @@ -129,6 +131,16 @@ public void start() throws IOException {
}
}

protected void addWebDriverExtensionIfNeeded() {
if (profile.containsWebDriverExtension()) {
return;
}

ClasspathExtension extension = new ClasspathExtension(FirefoxProfile.class,
"/" + FirefoxProfile.class.getPackage().getName().replace(".", "/") + "/webdriver.xpi");
profile.addExtension("webdriver", extension);
}

public Response execute(Command command) throws IOException {
return delegate.execute(command);
}
Expand Down

0 comments on commit ef4e042

Please sign in to comment.