17
17
18
18
package org .openqa .selenium .testing .drivers ;
19
19
20
+ import static org .junit .Assert .fail ;
20
21
import static org .openqa .selenium .testing .DevMode .isInDevMode ;
21
22
23
+ import com .google .common .base .Throwables ;
22
24
import com .google .common .collect .ImmutableMap ;
23
25
24
26
import org .openqa .selenium .BuckBuild ;
25
27
import org .openqa .selenium .Capabilities ;
28
+ import org .openqa .selenium .WebDriverException ;
26
29
import org .openqa .selenium .firefox .FirefoxDriver ;
27
30
import org .openqa .selenium .firefox .FirefoxProfile ;
28
31
import org .openqa .selenium .remote .DesiredCapabilities ;
31
34
import java .io .File ;
32
35
import java .io .IOException ;
33
36
import java .io .InputStream ;
37
+ import java .io .Reader ;
34
38
import java .net .URL ;
35
39
import java .nio .file .Files ;
36
40
import java .nio .file .Path ;
@@ -89,7 +93,7 @@ private static Capabilities tweakCapabilities(Capabilities desiredCaps) {
89
93
90
94
private static FirefoxProfile createTemporaryProfile () {
91
95
if (!isInDevMode ()) {
92
- FirefoxProfile profile = new FirefoxProfile ();
96
+ FirefoxProfile profile = new CustomProfile ();
93
97
94
98
if (Boolean .getBoolean ("webdriver.debug" )) {
95
99
try {
@@ -105,7 +109,7 @@ private static FirefoxProfile createTemporaryProfile() {
105
109
}
106
110
107
111
try {
108
- FirefoxProfile profile = new FirefoxProfile ();
112
+ FirefoxProfile profile = new CustomProfile ();
109
113
if (Boolean .getBoolean ("webdriver.debug" )) {
110
114
111
115
Firebug .addTo (profile );
@@ -148,5 +152,48 @@ private static FirefoxProfile copyExtensionTo(FirefoxProfile profile) throws IOE
148
152
profile .addExtension (ext );
149
153
return profile ;
150
154
}
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
+ }
151
198
}
152
199
0 commit comments