@@ -47,19 +47,26 @@ const NO_FOCUS_LIB_AMD64 = isDevMode ?
47
47
48
48
const X_IGNORE_NO_FOCUS_LIB = 'x_ignore_nofocus.so' ;
49
49
50
- var foundBinary = null ;
50
+
51
+ let foundBinary = null ;
52
+ let foundDevBinary = null ;
51
53
52
54
53
55
/**
54
56
* Checks the default Windows Firefox locations in Program Files.
57
+ *
58
+ * @param {boolean= } opt_dev Whether to find the Developer Edition.
55
59
* @return {!Promise<?string> } A promise for the located executable.
56
60
* The promise will resolve to {@code null} if Firefox was not found.
57
61
*/
58
- function defaultWindowsLocation ( ) {
62
+ function defaultWindowsLocation ( opt_dev ) {
59
63
var files = [
60
64
process . env [ 'PROGRAMFILES' ] || 'C:\\Program Files' ,
61
65
process . env [ 'PROGRAMFILES(X86)' ] || 'C:\\Program Files (x86)'
62
66
] . map ( function ( prefix ) {
67
+ if ( opt_dev ) {
68
+ return path . join ( prefix , 'Firefox Developer Edition\\firefox.exe' ) ;
69
+ }
63
70
return path . join ( prefix , 'Mozilla Firefox\\firefox.exe' ) ;
64
71
} ) ;
65
72
return io . exists ( files [ 0 ] ) . then ( function ( exists ) {
@@ -72,31 +79,47 @@ function defaultWindowsLocation() {
72
79
73
80
/**
74
81
* Locates the Firefox binary for the current system.
75
- * @return {!promise.Promise.<string> } A promise for the located binary. The
76
- * promise will be rejected if Firefox cannot be located.
82
+ *
83
+ * @param {boolean= } opt_dev Whether to find the Developer Edition. This only
84
+ * used on Windows and OSX.
85
+ * @return {!Promise<string> } A promise for the located binary. The promise will
86
+ * be rejected if Firefox cannot be located.
77
87
*/
78
- function findFirefox ( ) {
79
- if ( foundBinary ) {
88
+ function findFirefox ( opt_dev ) {
89
+ if ( opt_dev && foundDevBinary ) {
90
+ return foundDevBinary ;
91
+ }
92
+
93
+ if ( ! opt_dev && foundBinary ) {
80
94
return foundBinary ;
81
95
}
82
96
97
+ let found ;
83
98
if ( process . platform === 'darwin' ) {
84
- var osxExe = '/Applications/Firefox.app/Contents/MacOS/firefox-bin' ;
85
- foundBinary = io . exists ( osxExe ) . then ( function ( exists ) {
86
- return exists ? osxExe : null ;
87
- } ) ;
99
+ let exe = opt_dev
100
+ ? '/Applications/FirefoxDeveloperEdition.app/Contents/MacOS/firefox-bin'
101
+ : '/Applications/Firefox.app/Contents/MacOS/firefox-bin' ;
102
+ found = io . exists ( exe ) . then ( exists => exists ? exe : null ) ;
103
+
88
104
} else if ( process . platform === 'win32' ) {
89
- foundBinary = defaultWindowsLocation ( ) ;
105
+ found = defaultWindowsLocation ( opt_dev ) ;
106
+
90
107
} else {
91
- foundBinary = promise . fulfilled ( io . findInPath ( 'firefox' ) ) ;
108
+ found = Promise . resolve ( io . findInPath ( 'firefox' ) ) ;
92
109
}
93
110
94
- return foundBinary = foundBinary . then ( function ( found ) {
111
+ found = found . then ( found => {
95
112
if ( found ) {
96
113
return found ;
97
114
}
98
115
throw Error ( 'Could not locate Firefox on the current system' ) ;
99
116
} ) ;
117
+
118
+ if ( opt_dev ) {
119
+ return foundDevBinary = found ;
120
+ } else {
121
+ return foundBinary = found ;
122
+ }
100
123
}
101
124
102
125
@@ -136,12 +159,17 @@ function installNoFocusLibs(profileDir) {
136
159
* Provides a mechanism to configure and launch Firefox in a subprocess for
137
160
* use with WebDriver.
138
161
*
162
+ * If created _without_ a path for the Firefox binary to use, this class will
163
+ * attempt to find Firefox when {@link #launch()} is called. For OSX and
164
+ * Windows, this class will look for Firefox in the current platform's default
165
+ * installation location (e.g. /Applications/Firefox.app on OSX). For all other
166
+ * platforms, the Firefox executable must be available on your system `PATH`.
167
+ *
139
168
* @final
140
169
*/
141
170
class Binary {
142
171
/**
143
- * @param {string= } opt_exe Path to the Firefox binary to use. If not
144
- * specified, will attempt to locate Firefox on the current system.
172
+ * @param {string= } opt_exe Path to the Firefox binary to use.
145
173
*/
146
174
constructor ( opt_exe ) {
147
175
/** @private {(string|undefined)} */
@@ -157,6 +185,9 @@ class Binary {
157
185
MOZ_NO_REMOTE : '1' ,
158
186
NO_EM_RESTART : '1'
159
187
} ) ;
188
+
189
+ /** @private {boolean} */
190
+ this . devEdition_ = false ;
160
191
}
161
192
162
193
/**
@@ -174,6 +205,34 @@ class Binary {
174
205
}
175
206
}
176
207
208
+ /**
209
+ * Specifies whether to use Firefox Developer Edition instead of the normal
210
+ * stable channel. Setting this option has no effect if this instance was
211
+ * created with a path to a specific Firefox binary.
212
+ *
213
+ * This method has no effect on Unix systems where the Firefox application
214
+ * has the same (default) name regardless of version.
215
+ *
216
+ * @param {boolean= } opt_use Whether to use the developer edition. Defaults to
217
+ * true.
218
+ */
219
+ useDevEdition ( opt_use ) {
220
+ this . devEdition_ = opt_use === undefined || ! ! opt_use ;
221
+ }
222
+
223
+ /**
224
+ * Returns a promise for the Firefox executable used by this instance. The
225
+ * returned promise will be immediately resolved if the user supplied an
226
+ * executable path when this instance was created. Otherwise, an attempt will
227
+ * be made to find Firefox on the current system.
228
+ *
229
+ * @return {!promise.Promise<string> } a promise for the path to the Firefox
230
+ * executable used by this instance.
231
+ */
232
+ locate ( ) {
233
+ return promise . fulfilled ( this . exe_ || findFirefox ( this . devEdition_ ) ) ;
234
+ }
235
+
177
236
/**
178
237
* Launches Firefox and returns a promise that will be fulfilled when the
179
238
* process terminates.
@@ -187,7 +246,7 @@ class Binary {
187
246
188
247
let args = [ '-foreground' ] . concat ( this . args_ ) ;
189
248
190
- return promise . when ( this . exe_ || findFirefox ( ) , function ( firefox ) {
249
+ return this . locate ( ) . then ( function ( firefox ) {
191
250
if ( process . platform === 'win32' || process . platform === 'darwin' ) {
192
251
return exec ( firefox , { args : args , env : env } ) ;
193
252
}
@@ -209,7 +268,7 @@ class Binary {
209
268
* representation.
210
269
*/
211
270
[ Symbols . serialize ] ( ) {
212
- return promise . fulfilled ( this . exe_ || findFirefox ( ) ) ;
271
+ return this . locate ( ) ;
213
272
}
214
273
}
215
274
0 commit comments