Skip to content

Commit 7759ff4

Browse files
committed
Allow tests using the SynthesizedFirefoxDriver to work from an IDE.
We do this by creating a custom firefox profile.
1 parent 612e2b0 commit 7759ff4

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

java/client/test/org/openqa/selenium/testing/drivers/SynthesizedFirefoxDriver.java

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@
1717

1818
package org.openqa.selenium.testing.drivers;
1919

20+
import static org.junit.Assert.fail;
2021
import static org.openqa.selenium.testing.DevMode.isInDevMode;
2122

23+
import com.google.common.base.Throwables;
2224
import com.google.common.collect.ImmutableMap;
2325

2426
import org.openqa.selenium.BuckBuild;
2527
import org.openqa.selenium.Capabilities;
28+
import org.openqa.selenium.WebDriverException;
2629
import org.openqa.selenium.firefox.FirefoxDriver;
2730
import org.openqa.selenium.firefox.FirefoxProfile;
2831
import org.openqa.selenium.remote.DesiredCapabilities;
@@ -31,6 +34,7 @@
3134
import java.io.File;
3235
import java.io.IOException;
3336
import java.io.InputStream;
37+
import java.io.Reader;
3438
import java.net.URL;
3539
import java.nio.file.Files;
3640
import java.nio.file.Path;
@@ -89,7 +93,7 @@ private static Capabilities tweakCapabilities(Capabilities desiredCaps) {
8993

9094
private static FirefoxProfile createTemporaryProfile() {
9195
if (!isInDevMode()) {
92-
FirefoxProfile profile = new FirefoxProfile();
96+
FirefoxProfile profile = new CustomProfile();
9397

9498
if (Boolean.getBoolean("webdriver.debug")) {
9599
try {
@@ -105,7 +109,7 @@ private static FirefoxProfile createTemporaryProfile() {
105109
}
106110

107111
try {
108-
FirefoxProfile profile = new FirefoxProfile();
112+
FirefoxProfile profile = new CustomProfile();
109113
if (Boolean.getBoolean("webdriver.debug")) {
110114

111115
Firebug.addTo(profile);
@@ -148,5 +152,48 @@ private static FirefoxProfile copyExtensionTo(FirefoxProfile profile) throws IOE
148152
profile.addExtension(ext);
149153
return profile;
150154
}
155+
156+
private static class CustomProfile extends FirefoxProfile {
157+
158+
private static Path prefs;
159+
160+
@Override
161+
protected Reader onlyOverrideThisIfYouKnowWhatYouAreDoing() {
162+
try {
163+
return super.onlyOverrideThisIfYouKnowWhatYouAreDoing();
164+
} catch (RuntimeException e) {
165+
if (!DevMode.isInDevMode()) {
166+
throw e;
167+
}
168+
}
169+
170+
prefs = actuallyGetPrefsPath();
171+
172+
try {
173+
return Files.newBufferedReader(prefs);
174+
} catch (IOException e) {
175+
fail(Throwables.getStackTraceAsString(e));
176+
throw new RuntimeException(e);
177+
}
178+
}
179+
180+
private Path actuallyGetPrefsPath() {
181+
if (prefs != null) {
182+
return prefs;
183+
}
184+
185+
synchronized (CustomProfile.class) {
186+
if (prefs == null) {
187+
try {
188+
prefs = new BuckBuild().of("//javascript/firefox-driver:webdriver_prefs").go();
189+
} catch (IOException ioe) {
190+
throw new WebDriverException(ioe);
191+
}
192+
}
193+
}
194+
195+
return prefs;
196+
}
197+
}
151198
}
152199

0 commit comments

Comments
 (0)