firefox-profile
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -1,3 +0,2 @@ | ||
/ | ||
'use strict'; | ||
Constructor | ||
@@ -9,3 +8,6 @@ _Source: [lib/firefox_profile.js](../lib/firefox_profile.js)_ | ||
- <a name="toc_firefoxprofileprofiledirectory"></a>[FirefoxProfile](#firefoxprofileprofiledirectory) | ||
- <a name="toc_firefoxprofileprototypesetpreferencekey-value"></a><a name="toc_firefoxprofileprototype"></a>[FirefoxProfile.prototype.setPreference](#firefoxprofileprototypesetpreferencekey-value) | ||
- <a name="toc_firefoxprofileprototypedeletedir"></a><a name="toc_firefoxprofileprototype"></a>[FirefoxProfile.prototype.deleteDir](#firefoxprofileprototypedeletedir) | ||
- <a name="toc_firefoxprofileprototypeshoulddeleteonexittrue"></a>[FirefoxProfile.prototype.shouldDeleteOnExit](#firefoxprofileprototypeshoulddeleteonexittrue) | ||
- <a name="toc_firefoxprofileprototypewilldeleteonexit"></a>[FirefoxProfile.prototype.willDeleteOnExit](#firefoxprofileprototypewilldeleteonexit) | ||
- <a name="toc_firefoxprofileprototypesetpreferencekey-value"></a>[FirefoxProfile.prototype.setPreference](#firefoxprofileprototypesetpreferencekey-value) | ||
- <a name="toc_firefoxprofileprototypeaddextensionpath-callback"></a>[FirefoxProfile.prototype.addExtension](#firefoxprofileprototypeaddextensionpath-callback) | ||
@@ -36,2 +38,35 @@ - <a name="toc_firefoxprofileprototypeaddextensionspath-callback"></a>[FirefoxProfile.prototype.addExtensions](#firefoxprofileprototypeaddextensionspath-callback) | ||
# FirefoxProfile.prototype.deleteDir() | ||
> Deletes the profile directory. | ||
Call it only if you do not need the profile. Otherwise use at your own risk. | ||
this function is automatically called by default (= if willDeleteOnExit() returns true) | ||
<sub>Go: [TOC](#tableofcontents) | [FirefoxProfile.prototype](#toc_firefoxprofileprototype)</sub> | ||
# FirefoxProfile.prototype.shouldDeleteOnExit(true) | ||
> Specify if the profile Directory should be deleted on process.exit() | ||
Note: by default: | ||
* if the constructor is called without param: the new profile directory is deleted | ||
* if the constructor is called with param (path to profile dir): the dir is copied at init and the copy is deleted on exit | ||
**Parameters:** | ||
- `{boolean} true` | ||
<sub>Go: [TOC](#tableofcontents) | [FirefoxProfile.prototype](#toc_firefoxprofileprototype)</sub> | ||
# FirefoxProfile.prototype.willDeleteOnExit() | ||
> returns true if the profile directory will be deleted on process.exit() | ||
**Return:** | ||
`{boolean}` true if (default) | ||
<sub>Go: [TOC](#tableofcontents) | [FirefoxProfile.prototype](#toc_firefoxprofileprototype)</sub> | ||
# FirefoxProfile.prototype.setPreference(key, value) | ||
@@ -38,0 +73,0 @@ |
@@ -1,6 +0,5 @@ | ||
/**/ | ||
'use strict'; | ||
var os = require('os'), | ||
crypto = require('crypto'), | ||
path = require('path'), | ||
@@ -82,6 +81,5 @@ fs = require('fs'), | ||
/** | ||
* Initialize a new instance of a Firefox Profile | ||
* | ||
* @param {String} profileDirectory | ||
* Constructor | ||
*/ | ||
@@ -97,2 +95,4 @@ /** | ||
this.profileDir = profileDirectory; | ||
// if true, the profile folder is deleted after | ||
this._deleteOnExit = true; | ||
if (!this.profileDir) { | ||
@@ -108,9 +108,57 @@ this.profileDir = this._createTempFolder(); | ||
this.profileDir = tmpDir; | ||
//throw 'not implemented yet!'; | ||
} | ||
this.extensionsDir = path.join(this.profileDir, 'extensions'); | ||
this.userPrefs = path.join(this.profileDir, 'user.js'); | ||
// delete on process.exit()... | ||
var self = this; | ||
this.onExit = function() { | ||
// console.log('on exit:: ', self.path()); | ||
if (self._deleteOnExit) { | ||
self.deleteDir(); | ||
} | ||
}; | ||
['exit', 'SIGINT'].forEach(function(event) { | ||
process.addListener(event, self.onExit); | ||
}); | ||
} | ||
/** | ||
* Deletes the profile directory. | ||
* | ||
* Call it only if you do not need the profile. Otherwise use at your own risk. | ||
* this function is automatically called by default (= if willDeleteOnExit() returns true) | ||
*/ | ||
FirefoxProfile.prototype.deleteDir = function() { | ||
var self = this; | ||
['exit', 'SIGINT'].forEach(function(event) { | ||
process.removeListener(event, self.onExit); | ||
}); | ||
this.shouldDeleteOnExit(false); | ||
fs.existsSync(this.profileDir) && wrench.rmdirSyncRecursive(this.profileDir); | ||
}; | ||
/** | ||
* Specify if the profile Directory should be deleted on process.exit() | ||
* | ||
* Note: by default: | ||
* * if the constructor is called without param: the new profile directory is deleted | ||
* * if the constructor is called with param (path to profile dir): the dir is copied at init and the copy is deleted on exit | ||
* | ||
* @param {boolean} true | ||
*/ | ||
FirefoxProfile.prototype.shouldDeleteOnExit = function(bool) { | ||
this._deleteOnExit = bool; | ||
}; | ||
/** | ||
* returns true if the profile directory will be deleted on process.exit() | ||
* | ||
* @return {boolean} true if (default) | ||
*/ | ||
FirefoxProfile.prototype.willDeleteOnExit = function() { | ||
return this._deleteOnExit; | ||
}; | ||
/** | ||
* Set a user preference. | ||
@@ -117,0 +165,0 @@ * |
{ | ||
"name": "firefox-profile", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "firefox profile for selenium WebDriverJs, admc/wd or any other node selenium driver that supports capabilities", | ||
@@ -34,3 +34,3 @@ "main": "lib/firefox_profile", | ||
"devDependencies": { | ||
"mocha": "~1.13.0", | ||
"mocha": "~1.14.0", | ||
"chai": "~1.8.0", | ||
@@ -37,0 +37,0 @@ "sinon": "~1.7.3", |
@@ -143,3 +143,3 @@ # firefox-profile-js | ||
* fix more bugs | ||
* clean tmp directory on process 'exit' and 'SIGINT' | ||
* ~~clean tmp directory on process 'exit' and 'SIGINT'~~ | ||
@@ -146,0 +146,0 @@ ## Disclaimer |
/*jshint camelcase:false*/ | ||
/*global describe:false, it:false, beforeEach:false, xit:false*/ | ||
/*global describe:false, it:false, beforeEach:false, afterEach:false*/ | ||
@@ -22,5 +22,17 @@ 'use strict'; | ||
describe('firefox_profile', function() { | ||
var fp; | ||
beforeEach(function() { | ||
fp = new FirefoxProfile(); | ||
}); | ||
afterEach(function() { | ||
// will remove the onexit() call (that deletes the dir folder) | ||
// prevents warning: | ||
// possible EventEmitter memory leak detected. | ||
// X listeners added. Use emitter.setMaxListeners() to increase limit. | ||
fp.deleteDir(); | ||
}); | ||
describe('#constructor', function() { | ||
it('without parameter, a temp folder will be created', function() { | ||
var fp = new FirefoxProfile(); | ||
expect(fs.statSync(fp.profileDir).isDirectory()).to.be.true; | ||
@@ -43,3 +55,2 @@ }); | ||
it('without newline characters', function () { | ||
var fp = new FirefoxProfile(); | ||
fp.setPreference('test.string.value', 'test string value'); | ||
@@ -50,3 +61,2 @@ expect(fp.defaultPreferences).to.have.property('test.string.value', '"test string value"'); | ||
it('with newline characters', function () { | ||
var fp = new FirefoxProfile(); | ||
fp.setPreference('test.string.value', 'test string\n value'); | ||
@@ -59,3 +69,2 @@ expect(fp.defaultPreferences).to.have.property('test.string.value', '"test string\\n value"'); | ||
it('should correctly store boolean values', function () { | ||
var fp = new FirefoxProfile(); | ||
fp.setPreference('test.true.boolean', true); | ||
@@ -70,4 +79,2 @@ fp.setPreference('test.false.boolean', false); | ||
it('should throw an expection if no proxyType is specified', function() { | ||
var fp = new FirefoxProfile(); | ||
expect(function() { | ||
@@ -78,3 +85,2 @@ fp.setProxy({httpProxy: 'http-proxy-server:8080'}); | ||
it('should allow to set manual proxy', function() { | ||
var fp = new FirefoxProfile(); | ||
fp.setProxy({ | ||
@@ -97,8 +103,6 @@ proxyType : 'manual', | ||
expect(fp.defaultPreferences).to.have.property('network.proxy.socks', '"socks-proxy-server"'); | ||
expect(fp.defaultPreferences).to.have.property('network.proxy.socks_port', '"9999"'); | ||
expect(fp.defaultPreferences).to.have.property('network.proxy.socks_port', '"9999"'); | ||
}); | ||
it('should allow to set auto-config proxy', function() { | ||
var fp = new FirefoxProfile(); | ||
fp.setProxy({ | ||
@@ -121,3 +125,2 @@ proxyType : 'pac', | ||
it('without new line characters', function() { | ||
var fp = new FirefoxProfile(); | ||
fp.setPreference('test.string.value', 'test string value'); | ||
@@ -128,4 +131,4 @@ fp.updatePreferences(); | ||
}); | ||
it('with new line characters', function() { | ||
var fp = new FirefoxProfile(); | ||
fp.setPreference('test.string.value', 'test string\nvalue'); | ||
@@ -138,3 +141,2 @@ fp.updatePreferences(); | ||
it('should correctly output a boolean value in user.js', function() { | ||
var fp = new FirefoxProfile(); | ||
fp.setPreference('test.true.boolean', true); | ||
@@ -150,3 +152,2 @@ fp.setPreference('test.false.boolean', false); | ||
it('should work with a brand new profile', function(done) { | ||
var fp = new FirefoxProfile(); | ||
fp.encoded(function(zippedProfile) { | ||
@@ -161,10 +162,6 @@ expect(zippedProfile).to.be.equal(testProfiles.brandNewProfile.expectedZip); | ||
}); | ||
// 'id': null, | ||
// 'name': null, | ||
// 'unpack': true, | ||
// 'version': null | ||
describe('#__addonDetails', function() { | ||
it('should correctly retrieve addon details from rdf that does not use namespace', function(done) { | ||
var fp = new FirefoxProfile(); | ||
fp._addonDetails(path.join(__dirname, 'extensions/test.no-namespace-template.xpi'), function(extDetails) { | ||
@@ -182,3 +179,2 @@ expect(extDetails).to.be.eql({ | ||
it('should correctly retrieve addon details from rdf that uses namespace', function(done) { | ||
var fp = new FirefoxProfile(); | ||
fp._addonDetails(path.join(__dirname, 'extensions/test.template.xpi'), function(extDetails) { | ||
@@ -198,3 +194,2 @@ expect(extDetails).to.be.eql({ | ||
it('you correctly deal you boolean values', function() { | ||
var fp = new FirefoxProfile(); | ||
expect(fp._sanitizePref('true')).to.be.true; | ||
@@ -207,3 +202,2 @@ expect(fp._sanitizePref('false')).to.be.false; | ||
it('should unzip extensions in profile folder' , function(done) { | ||
var fp = new FirefoxProfile(); | ||
fp.addExtension(path.join(__dirname, 'extensions/png-extension.xpi'), function() { | ||
@@ -222,3 +216,2 @@ var exensionDir = path.join(fp.profileDir, 'extensions', 'id@test.test'); | ||
it('should return the profile directory', function() { | ||
var fp = new FirefoxProfile(); | ||
expect(fp.path()).to.be.equal(fp.profileDir); | ||
@@ -229,3 +222,2 @@ }); | ||
it('should return default value if not set', function() { | ||
var fp = new FirefoxProfile(); | ||
expect(fp.canAcceptUntrustedCerts()).to.be.true; | ||
@@ -237,3 +229,2 @@ }); | ||
it('should properly set value', function() { | ||
var fp = new FirefoxProfile(); | ||
fp.setAcceptUntrustedCerts(false); | ||
@@ -247,3 +238,2 @@ expect(fp.canAcceptUntrustedCerts()).to.be.false; | ||
it('should return default value if not set', function() { | ||
var fp = new FirefoxProfile(); | ||
expect(fp.canAssumeUntrustedCertIssuer()).to.be.true; | ||
@@ -255,4 +245,3 @@ }); | ||
it('should properly set value', function() { | ||
var fp = new FirefoxProfile(); | ||
fp.setAssumeUntrustedCertIssuer(0); // faulty | ||
fp.setAssumeUntrustedCertIssuer(0); // falsy | ||
expect(fp.canAssumeUntrustedCertIssuer()).to.be.false; | ||
@@ -264,3 +253,2 @@ | ||
it('should return default value if not set', function() { | ||
var fp = new FirefoxProfile(); | ||
expect(fp.nativeEventsEnabled()).to.be.true; | ||
@@ -272,4 +260,3 @@ }); | ||
it('should properly set value', function() { | ||
var fp = new FirefoxProfile(); | ||
fp.setNativeEventsEnabled(false); // faulty | ||
fp.setNativeEventsEnabled(false); | ||
expect(fp.nativeEventsEnabled()).to.be.false; | ||
@@ -279,5 +266,19 @@ | ||
}); | ||
describe('#path', function() { | ||
describe('#shouldDeleteOnExit', function() { | ||
it('should properly set internal property', function() { | ||
expect(fp.willDeleteOnExit()).to.be.true; | ||
fp.shouldDeleteOnExit(false); | ||
expect(fp.willDeleteOnExit()).to.be.false; | ||
}); | ||
}); | ||
describe('#deleteDir', function() { | ||
it('should delete profile dir', function() { | ||
expect(fs.existsSync(fp.path())).to.be.true; | ||
expect(fs.statSync(fp.path()).isDirectory()).to.be.true; | ||
fp.deleteDir(); | ||
expect(fs.existsSync(fp.path())).to.be.false; | ||
}); | ||
}); | ||
}); |
@@ -30,4 +30,2 @@ /*jshint camelcase:false*/ | ||
// also the browser quits when running locally, not in saucelabs | ||
// so adding this... didn't help... | ||
after(function(done) { | ||
@@ -34,0 +32,0 @@ this.timeout(0); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2278869
836
6
27