aboutsummaryrefslogtreecommitdiff
path: root/node_modules/selenium-webdriver/firefox
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-04-20 03:09:25 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-04-24 16:14:29 +0200
commit82f2b76e25a4a67e01ec67e5ebe39d14ad771ea8 (patch)
tree965f6eb89b84d65a62b49008fd972c004832ccd1 /node_modules/selenium-webdriver/firefox
parente6e0cbc387c2a77b48e4065c229daa65bf1aa0fa (diff)
Reorganize module loading.
We now use webpack instead of SystemJS, effectively bundling modules into one file (plus commons chunks) for every entry point. This results in a much smaller extension size (almost half). Furthermore we use yarn/npm even for extension run-time dependencies. This relieves us from manually vendoring and building dependencies. It's also easier to understand for new developers familiar with node.
Diffstat (limited to 'node_modules/selenium-webdriver/firefox')
-rw-r--r--node_modules/selenium-webdriver/firefox/binary.js171
-rw-r--r--node_modules/selenium-webdriver/firefox/extension.js2
-rw-r--r--node_modules/selenium-webdriver/firefox/index.js88
3 files changed, 173 insertions, 88 deletions
diff --git a/node_modules/selenium-webdriver/firefox/binary.js b/node_modules/selenium-webdriver/firefox/binary.js
index b997b480d..a1360bab7 100644
--- a/node_modules/selenium-webdriver/firefox/binary.js
+++ b/node_modules/selenium-webdriver/firefox/binary.js
@@ -47,27 +47,17 @@ const NO_FOCUS_LIB_AMD64 = isDevMode ?
const X_IGNORE_NO_FOCUS_LIB = 'x_ignore_nofocus.so';
-let foundBinary = null;
-let foundDevBinary = null;
-
-
/**
- * Checks the default Windows Firefox locations in Program Files.
- *
- * @param {boolean=} opt_dev Whether to find the Developer Edition.
+ * @param {string} file Path to the file to find, relative to the program files
+ * root.
* @return {!Promise<?string>} A promise for the located executable.
* The promise will resolve to {@code null} if Firefox was not found.
*/
-function defaultWindowsLocation(opt_dev) {
- var files = [
+function findInProgramFiles(file) {
+ let files = [
process.env['PROGRAMFILES'] || 'C:\\Program Files',
process.env['PROGRAMFILES(X86)'] || 'C:\\Program Files (x86)'
- ].map(function(prefix) {
- if (opt_dev) {
- return path.join(prefix, 'Firefox Developer Edition\\firefox.exe');
- }
- return path.join(prefix, 'Mozilla Firefox\\firefox.exe');
- });
+ ].map(prefix => path.join(prefix, file));
return io.exists(files[0]).then(function(exists) {
return exists ? files[0] : io.exists(files[1]).then(function(exists) {
return exists ? files[1] : null;
@@ -77,49 +67,104 @@ function defaultWindowsLocation(opt_dev) {
/**
- * Locates the Firefox binary for the current system.
+ * Provides methods for locating the executable for a Firefox release channel
+ * on Windows and MacOS. For other systems (i.e. Linux), Firefox will always
+ * be located on the system PATH.
*
- * @param {boolean=} opt_dev Whether to find the Developer Edition. This only
- * used on Windows and OSX.
- * @return {!Promise<string>} A promise for the located binary. The promise will
- * be rejected if Firefox cannot be located.
+ * @final
*/
-function findFirefox(opt_dev) {
- if (opt_dev && foundDevBinary) {
- return foundDevBinary;
+class Channel {
+ /**
+ * @param {string} darwin The path to check when running on MacOS.
+ * @param {string} win32 The path to check when running on Windows.
+ */
+ constructor(darwin, win32) {
+ /** @private @const */ this.darwin_ = darwin;
+ /** @private @const */ this.win32_ = win32;
+ /** @private {Promise<string>} */
+ this.found_ = null;
}
- if (!opt_dev && foundBinary) {
- return foundBinary;
+ /**
+ * Attempts to locate the Firefox executable for this release channel. This
+ * will first check the default installation location for the channel before
+ * checking the user's PATH. The returned promise will be rejected if Firefox
+ * can not be found.
+ *
+ * @return {!Promise<string>} A promise for the location of the located
+ * Firefox executable.
+ */
+ locate() {
+ if (this.found_) {
+ return this.found_;
+ }
+
+ let found;
+ switch (process.platform) {
+ case 'darwin':
+ found = io.exists(this.darwin_)
+ .then(exists => exists ? this.darwin_ : io.findInPath('firefox'));
+ break;
+
+ case 'win32':
+ found = findInProgramFiles(this.win32_)
+ .then(found => found || io.findInPath('firefox.exe'));
+ break;
+
+ default:
+ found = Promise.resolve(io.findInPath('firefox'));
+ break;
+ }
+
+ this.found_ = found.then(found => {
+ if (found) {
+ // TODO: verify version info.
+ return found;
+ }
+ throw Error('Could not locate Firefox on the current system');
+ });
+ return this.found_;
}
+}
- let found;
- if (process.platform === 'darwin') {
- let exe = opt_dev
- ? '/Applications/FirefoxDeveloperEdition.app/Contents/MacOS/firefox-bin'
- : '/Applications/Firefox.app/Contents/MacOS/firefox-bin';
- found = io.exists(exe).then(exists => exists ? exe : null);
- } else if (process.platform === 'win32') {
- found = defaultWindowsLocation(opt_dev);
+/**
+ * Firefox's developer channel.
+ * @const
+ * @see <https://www.mozilla.org/en-US/firefox/channel/desktop/#aurora>
+ */
+Channel.AURORA = new Channel(
+ '/Applications/FirefoxDeveloperEdition.app/Contents/MacOS/firefox-bin',
+ 'Firefox Developer Edition\\firefox.exe');
- } else {
- found = Promise.resolve(io.findInPath('firefox'));
- }
+/**
+ * Firefox's beta channel. Note this is provided mainly for convenience as
+ * the beta channel has the same installation location as the main release
+ * channel.
+ * @const
+ * @see <https://www.mozilla.org/en-US/firefox/channel/desktop/#beta>
+ */
+Channel.BETA = new Channel(
+ '/Applications/Firefox.app/Contents/MacOS/firefox-bin',
+ 'Mozilla Firefox\\firefox.exe');
- found = found.then(found => {
- if (found) {
- return found;
- }
- throw Error('Could not locate Firefox on the current system');
- });
+/**
+ * Firefox's release channel.
+ * @const
+ * @see <https://www.mozilla.org/en-US/firefox/desktop/>
+ */
+Channel.RELEASE = new Channel(
+ '/Applications/Firefox.app/Contents/MacOS/firefox-bin',
+ 'Mozilla Firefox\\firefox.exe');
- if (opt_dev) {
- return foundDevBinary = found;
- } else {
- return foundBinary = found;
- }
-}
+/**
+ * Firefox's nightly release channel.
+ * @const
+ * @see <https://www.mozilla.org/en-US/firefox/channel/desktop/#nightly>
+ */
+Channel.NIGHTLY = new Channel(
+ '/Applications/FirefoxNightly.app/Contents/MacOS/firefox-bin',
+ 'Nightly\\firefox.exe');
/**
@@ -151,20 +196,23 @@ function installNoFocusLibs(profileDir) {
* use with WebDriver.
*
* If created _without_ a path for the Firefox binary to use, this class will
- * attempt to find Firefox when {@link #launch()} is called. For OSX and
+ * attempt to find Firefox when {@link #launch()} is called. For MacOS and
* Windows, this class will look for Firefox in the current platform's default
- * installation location (e.g. /Applications/Firefox.app on OSX). For all other
- * platforms, the Firefox executable must be available on your system `PATH`.
+ * installation location (e.g. /Applications/Firefox.app on MacOS). For all
+ * other platforms, the Firefox executable must be available on your system
+ * `PATH`.
*
* @final
*/
class Binary {
/**
- * @param {string=} opt_exe Path to the Firefox binary to use.
+ * @param {?(string|Channel)=} opt_exeOrChannel Either the path to a specific
+ * Firefox binary to use, or a {@link Channel} instance that describes
+ * how to locate the desired Firefox version.
*/
- constructor(opt_exe) {
- /** @private {(string|undefined)} */
- this.exe_ = opt_exe;
+ constructor(opt_exeOrChannel) {
+ /** @private {?(string|Channel)} */
+ this.exe_ = opt_exeOrChannel || null;
/** @private {!Array.<string>} */
this.args_ = [];
@@ -187,7 +235,7 @@ class Binary {
* on the current system.
*/
getExe() {
- return this.exe_;
+ return typeof this.exe_ === 'string' ? this.exe_ : undefined;
}
/**
@@ -223,6 +271,8 @@ class Binary {
*
* @param {boolean=} opt_use Whether to use the developer edition. Defaults to
* true.
+ * @deprecated Use the {@link Channel} class to indicate the desired Firefox
+ * version when creating a new binary: `new Binary(Channel.AURORA)`.
*/
useDevEdition(opt_use) {
this.devEdition_ = opt_use === undefined || !!opt_use;
@@ -238,7 +288,13 @@ class Binary {
* used by this instance.
*/
locate() {
- return Promise.resolve(this.exe_ || findFirefox(this.devEdition_));
+ if (typeof this.exe_ === 'string') {
+ return Promise.resolve(this.exe_);
+ } else if (this.exe_ instanceof Channel) {
+ return this.exe_.locate();
+ }
+ let channel = this.devEdition_ ? Channel.AURORA : Channel.RELEASE;
+ return channel.locate();
}
/**
@@ -284,4 +340,5 @@ class Binary {
exports.Binary = Binary;
+exports.Channel = Channel;
diff --git a/node_modules/selenium-webdriver/firefox/extension.js b/node_modules/selenium-webdriver/firefox/extension.js
index 60abb06b8..3bda759a7 100644
--- a/node_modules/selenium-webdriver/firefox/extension.js
+++ b/node_modules/selenium-webdriver/firefox/extension.js
@@ -161,7 +161,7 @@ function readManifest(addonPath) {
manifest = io.stat(addonPath).then(function(stats) {
if (!stats.isDirectory()) {
throw Error(
- 'Add-on path is niether a xpi nor a directory: ' + addonPath);
+ 'Add-on path is neither a xpi nor a directory: ' + addonPath);
}
return io.read(path.join(addonPath, 'install.rdf'));
});
diff --git a/node_modules/selenium-webdriver/firefox/index.js b/node_modules/selenium-webdriver/firefox/index.js
index 4ea1702a9..d5c88274a 100644
--- a/node_modules/selenium-webdriver/firefox/index.js
+++ b/node_modules/selenium-webdriver/firefox/index.js
@@ -26,28 +26,31 @@
*
* __Customizing the Firefox Profile__
*
- * The {@link Profile} class may be used to configure the browser profile used
- * with WebDriver, with functions to install additional
+ * The {@linkplain Profile} class may be used to configure the browser profile
+ * used with WebDriver, with functions to install additional
* {@linkplain Profile#addExtension extensions}, configure browser
* {@linkplain Profile#setPreference preferences}, and more. For example, you
* may wish to include Firebug:
*
- * var firefox = require('selenium-webdriver/firefox');
+ * const {Builder} = require('selenium-webdriver');
+ * const firefox = require('selenium-webdriver/firefox');
*
- * var profile = new firefox.Profile();
+ * let profile = new firefox.Profile();
* profile.addExtension('/path/to/firebug.xpi');
* profile.setPreference('extensions.firebug.showChromeErrors', true);
*
- * var options = new firefox.Options().setProfile(profile);
- * var driver = new firefox.Driver(options);
+ * let options = new firefox.Options().setProfile(profile);
+ * let driver = new Builder()
+ * .forBrowser('firefox')
+ * .setFirefoxOptions(options)
+ * .build();
*
- * The {@link Profile} class may also be used to configure WebDriver based on a
- * pre-existing browser profile:
+ * The {@linkplain Profile} class may also be used to configure WebDriver based
+ * on a pre-existing browser profile:
*
- * var profile = new firefox.Profile(
+ * let profile = new firefox.Profile(
* '/usr/local/home/bob/.mozilla/firefox/3fgog75h.testing');
- * var options = new firefox.Options().setProfile(profile);
- * var driver = new firefox.Driver(options);
+ * let options = new firefox.Options().setProfile(profile);
*
* The FirefoxDriver will _never_ modify a pre-existing profile; instead it will
* create a copy for it to modify. By extension, there are certain browser
@@ -56,21 +59,35 @@
*
* __Using a Custom Firefox Binary__
*
- * On Windows and OSX, the FirefoxDriver will search for Firefox in its
+ * On Windows and MacOS, the FirefoxDriver will search for Firefox in its
* default installation location:
*
- * * Windows: C:\Program Files and C:\Program Files (x86).
- * * Mac OS X: /Applications/Firefox.app
+ * - Windows: C:\Program Files and C:\Program Files (x86).
+ * - MacOS: /Applications/Firefox.app
+ *
+ * For Linux, Firefox will always be located on the PATH: `$(where firefox)`.
*
- * For Linux, Firefox will be located on the PATH: `$(where firefox)`.
+ * Several methods are provided for starting Firefox with a custom executable.
+ * First, on Windows and MacOS, you may configure WebDriver to check the default
+ * install location for a non-release channel. If the requested channel cannot
+ * be found in its default location, WebDriver will fallback to searching your
+ * PATH. _Note:_ on Linux, Firefox is _always_ located on your path, regardless
+ * of the requested channel.
+ *
+ * const {Builder} = require('selenium-webdriver');
+ * const firefox = require('selenium-webdriver/firefox');
+ *
+ * let options = new firefox.Options().setBinary(firefox.Channel.NIGHTLY);
+ * let driver = new Builder()
+ * .forBrowser('firefox')
+ * .setFirefoxOptions(options)
+ * .build();
*
- * You can configure WebDriver to start use a custom Firefox installation with
- * the {@link Binary} class:
+ * On all platforms, you may configrue WebDriver to use a Firefox specific
+ * executable:
*
- * var firefox = require('selenium-webdriver/firefox');
- * var binary = new firefox.Binary('/my/firefox/install/dir/firefox-bin');
- * var options = new firefox.Options().setBinary(binary);
- * var driver = new firefox.Driver(options);
+ * let options = new firefox.Options()
+ * .setBinary('/my/firefox/install/dir/firefox-bin');
*
* __Remote Testing__
*
@@ -84,11 +101,14 @@
* binaries are never copied to remote machines and must be referenced by
* installation path.
*
- * var options = new firefox.Options()
+ * const {Builder} = require('selenium-webdriver');
+ * const firefox = require('selenium-webdriver/firefox');
+ *
+ * let options = new firefox.Options()
* .setProfile('/profile/path/on/remote/host')
* .setBinary('/install/dir/on/remote/host/firefox-bin');
*
- * var driver = new (require('selenium-webdriver')).Builder()
+ * let driver = new Builder()
* .forBrowser('firefox')
* .usingServer('http://127.0.0.1:4444/wd/hub')
* .setFirefoxOptions(options)
@@ -99,8 +119,7 @@
* To test versions of Firefox prior to Firefox 47, you must disable the use of
* the geckodriver using the {@link Options} class.
*
- * var options = new firefox.Options().useGeckoDriver(false);
- * var driver = new firefox.Driver(options);
+ * let options = new firefox.Options().useGeckoDriver(false);
*
* Alternatively, you may disable the geckodriver at runtime by setting the
* environment variable `SELENIUM_MARIONETTE=false`.
@@ -113,7 +132,7 @@
const url = require('url');
-const Binary = require('./binary').Binary,
+const {Binary, Channel} = require('./binary'),
Profile = require('./profile').Profile,
decodeProfile = require('./profile').decode,
http = require('../http'),
@@ -196,16 +215,24 @@ class Options {
}
/**
- * Sets the binary to use. The binary may be specified as the path to a Firefox
- * executable, or as a {@link Binary} object.
+ * Sets the binary to use. The binary may be specified as the path to a
+ * Firefox executable, a specific {@link Channel}, or as a {@link Binary}
+ * object.
*
- * @param {(string|!Binary)} binary The binary to use.
+ * @param {(string|!Binary|!Channel)} binary The binary to use.
* @return {!Options} A self reference.
+ * @throws {TypeError} If `binary` is an invalid type.
*/
setBinary(binary) {
- if (typeof binary === 'string') {
+ if (typeof binary === 'string' || binary instanceof Channel) {
binary = new Binary(binary);
}
+
+ if (!(binary instanceof Binary)) {
+ throw TypeError(
+ 'binary must be a string path, Channel, or Binary object');
+ }
+
this.binary_ = binary;
return this;
}
@@ -687,6 +714,7 @@ class Driver extends webdriver.WebDriver {
exports.Binary = Binary;
+exports.Channel = Channel;
exports.Context = Context;
exports.Driver = Driver;
exports.Options = Options;