Skip to content

Commit

Permalink
[js] The firefox module will no longer apply the preferences required…
Browse files Browse the repository at this point in the history
… by the

legacy FirefoxDriver. These preferences were only required when using the legacy
driver, support for which was dropped in v3.5.0.
  • Loading branch information
jleyba committed Oct 6, 2017
1 parent d4bad7c commit 4d2b5e6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 50 deletions.
1 change: 0 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,6 @@ namespace :node do
" --output=build/javascript/node/selenium-webdriver" <<
" --resource=LICENSE:/LICENSE" <<
" --resource=NOTICE:/NOTICE" <<
" --resource=javascript/firefox-driver/webdriver.json:firefox/webdriver.json" <<
" --resource=common/src/web/:test/data/" <<
" --exclude_resource=common/src/web/Bin" <<
" --exclude_resource=.gitignore" <<
Expand Down
6 changes: 6 additions & 0 deletions javascript/node/selenium-webdriver/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## v.next

### Bug Fixes

* The firefox module will no longer apply the preferences required by the legacy
FirefoxDriver. These preferences were only required when using the legacy
driver, support for which was dropped in v3.5.0.

### API Changes

* Removed `selenium-webdriver/firefox.Options#useGeckoDriver()`
Expand Down
41 changes: 7 additions & 34 deletions javascript/node/selenium-webdriver/firefox/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,6 @@ const isDevMode = require('../lib/devmode'),
extension = require('./extension');


/** @const */
const WEBDRIVER_PREFERENCES_PATH = isDevMode
? path.join(__dirname, '../../../firefox-driver/webdriver.json')
: path.join(__dirname, '../lib/firefox/webdriver.json');

/** @type {Object} */
var defaultPreferences = null;

/**
* Synchronously loads the default preferences used for the FirefoxDriver.
* @return {!Object} The default preferences JSON object.
*/
function getDefaultPreferences() {
if (!defaultPreferences) {
var contents = /** @type {string} */(
fs.readFileSync(WEBDRIVER_PREFERENCES_PATH, 'utf8'));
defaultPreferences = /** @type {!Object} */(JSON.parse(contents));
}
return defaultPreferences;
}


/**
* Parses a user.js file in a Firefox profile directory.
* @param {string} f Path to the file to parse.
Expand Down Expand Up @@ -96,9 +74,13 @@ function writeUserPrefs(prefs, dir) {
var userPrefs = path.join(dir, 'user.js');
return loadUserPrefs(userPrefs).then(function(overrides) {
Object.assign(prefs, overrides);
Object.assign(prefs, getDefaultPreferences()['frozen']);

var contents = Object.keys(prefs).map(function(key) {
let keys = Object.keys(prefs);
if (!keys.length) {
return dir;
}

let contents = Object.keys(prefs).map(function(key) {
return 'user_pref(' + JSON.stringify(key) + ', ' +
JSON.stringify(prefs[key]) + ');';
}).join('\n');
Expand Down Expand Up @@ -206,12 +188,6 @@ class Profile {
* @throws {Error} If attempting to set a frozen preference.
*/
setPreference(key, value) {
var frozen = getDefaultPreferences()['frozen'];
if (frozen.hasOwnProperty(key) && frozen[key] !== value) {
throw Error('You may not set ' + key + '=' + JSON.stringify(value)
+ '; value is frozen for proper WebDriver functionality ('
+ key + '=' + JSON.stringify(frozen[key]) + ')');
}
this.preferences_[key] = value;
}

Expand Down Expand Up @@ -328,10 +304,7 @@ class Profile {
}

// Freeze preferences for async operations.
var prefs = {};
Object.assign(prefs, getDefaultPreferences()['mutable']);
Object.assign(prefs, getDefaultPreferences()['frozen']);
Object.assign(prefs, this.preferences_);
let prefs = Object.assign({}, this.preferences_);

// Freeze extensions for async operations.
var extensions = this.extensions_.concat();
Expand Down
32 changes: 17 additions & 15 deletions javascript/node/selenium-webdriver/test/firefox/firefox_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ test.suite(function(env) {
}
});

/**
* @param {...string} extensions the extensions to install.
* @return {!firefox.Profile} a new profile.
*/
function profileWithExtensions(...extensions) {
let profile = new firefox.Profile();
profile.setPreference('xpinstall.signatures.required', false);
extensions.forEach(ext => profile.addExtension(ext));
return profile;
}

/**
* Runs a test that requires Firefox Developer Edition. The test will be
* skipped if dev cannot be found on the current system.
Expand Down Expand Up @@ -99,9 +110,7 @@ test.suite(function(env) {
});

test.it('can start Firefox with a jetpack extension', function() {
let profile = new firefox.Profile();
profile.addExtension(JETPACK_EXTENSION);

let profile = profileWithExtensions(JETPACK_EXTENSION);
let options = new firefox.Options().setProfile(profile);

return runWithFirefoxDev(options, function*() {
Expand All @@ -115,9 +124,7 @@ test.suite(function(env) {
});

test.it('can start Firefox with a normal extension', function() {
let profile = new firefox.Profile();
profile.addExtension(NORMAL_EXTENSION);

let profile = profileWithExtensions(NORMAL_EXTENSION);
let options = new firefox.Options().setProfile(profile);

return runWithFirefoxDev(options, function*() {
Expand All @@ -131,9 +138,7 @@ test.suite(function(env) {
});

test.it('can start Firefox with a webextension extension', function() {
let profile = new firefox.Profile();
profile.addExtension(WEBEXTENSION_EXTENSION);

let profile = profileWithExtensions(WEBEXTENSION_EXTENSION);
let options = new firefox.Options().setProfile(profile);

return runWithFirefoxDev(options, function*() {
Expand All @@ -147,10 +152,8 @@ test.suite(function(env) {
});

test.it('can start Firefox with multiple extensions', function() {
let profile = new firefox.Profile();
profile.addExtension(JETPACK_EXTENSION);
profile.addExtension(NORMAL_EXTENSION);

let profile =
profileWithExtensions(JETPACK_EXTENSION, NORMAL_EXTENSION);
let options = new firefox.Options().setProfile(profile);

return runWithFirefoxDev(options, function*() {
Expand All @@ -171,8 +174,7 @@ test.suite(function(env) {
test.it('can be used alongside preset capabilities', function*() {
let binary = yield firefox.Channel.AURORA.locate();

let profile = new firefox.Profile();
profile.addExtension(JETPACK_EXTENSION);
let profile = profileWithExtensions(JETPACK_EXTENSION);
profile.setPreference('general.useragent.override', 'foo;bar');

driver = yield env.builder()
Expand Down

0 comments on commit 4d2b5e6

Please sign in to comment.