Skip to content

Commit

Permalink
Merge branch 'master' into update-deps
Browse files Browse the repository at this point in the history
  • Loading branch information
Mitchell Hentges committed Feb 26, 2016
2 parents f82598f + c14e680 commit 654d7fb
Show file tree
Hide file tree
Showing 11 changed files with 156 additions and 110 deletions.
6 changes: 6 additions & 0 deletions lib/darwin/canary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var util = require( './util' ),
CHROME_CANARY_ID = 'com.google.Chrome.canary',
CHROME_CANARY_VERSION = 'KSVersion';

exports.path = util.find.bind(null, CHROME_CANARY_ID);
exports.version = util.getInfoKey.bind(null, CHROME_CANARY_ID, CHROME_CANARY_VERSION);
38 changes: 4 additions & 34 deletions lib/darwin/chrome.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,6 @@
var util = require( './util' ),
currentPath;
CHROME_ID = 'com.google.Chrome',
CHROME_VERSION = 'KSVersion';

function getPath( callback ) {
if ( currentPath ) {
return callback( null, currentPath );
}

util.find( 'com.google.Chrome', function( err, path ) {
currentPath = path;
callback( err, currentPath );
} );
}

function getVersion( callback ) {
getPath( function( err, path ) {
if ( err ) {
return callback( err, null );
}

var pl = util.getInfoPath( path );

util.exists( pl, function( exists ) {
if ( exists ) {
util.parse( pl, function( err, data ) {
callback( err, data.KSVersion );
} );
} else {
callback( 'not installed', null );
}
} );
} );
}

exports.path = getPath;
exports.version = getVersion;
exports.path = util.find.bind(null, CHROME_ID);
exports.version = util.getInfoKey.bind(null, CHROME_ID, CHROME_VERSION);
36 changes: 36 additions & 0 deletions lib/darwin/chromium.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
var util = require( './util' ),
currentPath;

function getPath( callback ) {
if ( currentPath ) {
return callback( null, currentPath );
}

util.find( 'org.chromium.Chromium', function( err, path ) {
currentPath = path;
callback( err, currentPath );
} );
}

function getVersion( callback ) {
getPath( function( err, path ) {
if ( err ) {
return callback( err, null );
}

var pl = util.getInfoPath( path );

util.exists( pl, function( exists ) {
if ( exists ) {
util.parse( pl, function( err, data ) {
callback( err, data.CFBundleShortVersionString );
} );
} else {
callback( 'not installed', null );
}
} );
} );
}

exports.path = getPath;
exports.version = getVersion;
3 changes: 3 additions & 0 deletions lib/darwin/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
exports.safari = require( './safari' );
exports.firefox = require( './firefox' );
exports.chrome = exports[ 'google-chrome' ] = require( './chrome' );
exports.chromium = require( './chromium' );
exports.canary = exports[ 'chrome-canary' ] = exports[ 'google-chrome-canary' ] = require( './canary' );
exports.opera = require( './opera' );
exports.phantomjs = require( './phantomjs' );
38 changes: 4 additions & 34 deletions lib/darwin/opera.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,6 @@
var util = require( './util' ),
currentPath;
OPERA_ID = 'com.operasoftware.Opera',
OPERA_VERSION = 'CFBundleVersion';

function getPath( callback ) {
if ( currentPath ) {
return callback( null, currentPath );
}

util.find( 'com.operasoftware.Opera', function( err, path ) {
currentPath = path;
callback( err, currentPath );
} );
}

function getVersion( callback ) {
getPath( function( err, path ) {
if ( err ) {
return callback( err, null );
}

var pl = util.getInfoPath( path );

util.exists( pl, function( exists ) {
if ( exists ) {
util.parse( pl, function( err, data ) {
callback( err, data.CFBundleVersion );
} );
} else {
callback( 'not installed', null );
}
} );
} );
}

exports.path = getPath;
exports.version = getVersion;
exports.path = util.find.bind(null, OPERA_ID);
exports.version = util.getInfoKey.bind(null, OPERA_ID, OPERA_VERSION);
29 changes: 29 additions & 0 deletions lib/darwin/phantomjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
var util = require( './util' );

exports.path = getPath = function( callback ) {
util.findBin( 'phantomjs', function ( err, path ) {
if ( err ) {
callback( err, null );
} else if ( path ) {
callback( null, path );
} else {
callback( 'not installed' );
}
});
};

exports.version = getVersion = function ( callback ) {
getPath( function( err, path ) {
if ( err || !path ) {
callback( err, null );
return;
}
util.getBinVersion( 'phantomjs', function( err, version ) {
if ( err || !version ) {
callback( err, null );
} else {
callback( null, version );
}
});
});
};
38 changes: 4 additions & 34 deletions lib/darwin/safari.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,6 @@
var util = require( './util' ),
currentPath;
SAFARI_ID = 'com.apple.Safari',
SAFARI_VERSION_ID = 'CFBundleShortVersionString';

function getPath( callback ) {
if ( currentPath ) {
return callback( null, currentPath );
}

util.find( 'com.apple.Safari', function( err, path ) {
currentPath = path;
callback( err, currentPath );
} );
}

function getVersion( callback ) {
getPath( function( err, path ) {
if ( err ) {
return callback( err, null );
}

var pl = util.getInfoPath( path );

util.exists( pl, function( exists ) {
if ( exists ) {
util.parse( pl, function( err, data ) {
callback( err, data.CFBundleShortVersionString );
} );
} else {
callback( 'not installed', null );
}
} );
} );
}

exports.path = getPath;
exports.version = getVersion;
exports.path = util.find.bind(null, SAFARI_ID);
exports.version = util.getInfoKey.bind(null, SAFARI_ID, SAFARI_VERSION_ID);
66 changes: 58 additions & 8 deletions lib/darwin/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,37 @@ var exec = require( 'child_process' ).exec,
path = require( 'path' ),
plist = require( 'plist' );

exports.exists = require( 'fs' ).exists;
exports.exists = fs.exists;
exports.parse = parse;
exports.find = find;
exports.getInfoPath = getInfoPath;
exports.getInfoKey = getInfoKey;
exports.findBin = findBin;
exports.getBinVersion = getBinVersion;

exports.parse = function( file, callback ) {
var infoCache = Object.create(null);

function parse( file, callback ) {
if (infoCache[file] !== void 0) {
return callback(null, infoCache[file]);
}
fs.readFile( file, {
encoding: 'utf8'
}, function( err, data ) {
if ( !err ) {
data = plist.parse( data );
infoCache[ file ] = data = plist.parse( data );
}

callback( err, data );
} );
};
}

var bundleCache = Object.create(null);

exports.find = function( id, callback ) {
function find( id, callback ) {
if (bundleCache[id] !== void 0) {
return callback(null, bundleCache[id]);
}
var pathQuery = 'mdfind "kMDItemCFBundleIdentifier=="' + id + '"" | head -1';

exec( pathQuery, function( err, stdout ) {
Expand All @@ -26,12 +42,46 @@ exports.find = function( id, callback ) {
if ( loc === '' ) {
loc = null;
err = 'not installed';
} else {
bundleCache[id] = loc;
}

callback( err, loc );
} );
};
}

function findBin(id, callback) {
exec("which " + id, function( err, path ) {
callback( err, path ? path.trim() : path );
});
}

exports.getInfoPath = function( p ) {
function getBinVersion(id, callback) {
exec(id + " --version", function( err, version ) {
callback( err, version ? version.trim() : version );
});
}

function getInfoPath( p ) {
return path.join( p, 'Contents', 'Info.plist' );
};
}

function getInfoKey( bundleId, key, callback ) {
find( bundleId, function( err, path ) {
if ( err ) {
return callback( err, null );
}

var pl = getInfoPath( path );

fs.exists( pl, function( exists ) {
if ( exists ) {
parse( pl, function( err, data ) {
callback( err, data[key] );
} );
} else {
callback( 'not installed', null );
}
} );
} );
}
6 changes: 6 additions & 0 deletions lib/detect.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ var spawn = require( 'child_process' ).spawn,
type: 'chrome',
profile: true
},
'google-chrome-canary': {
name: 'canary',
re: /Google Chrome (\S+)/,
type: 'canary',
profile: true,
},
'chromium': {
name: 'chromium',
re: /Chromium (\S+)/,
Expand Down
5 changes: 5 additions & 0 deletions lib/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function Instance( options ) {
this.image = options.image;
this.processName = options.processName;
this.tempDir = options.tempDir;
this.browserType = options.type; //saving the type of browser instance for issue# 49

this.process = child.spawn( this.command, this.args, {
detached: options.detached,
Expand Down Expand Up @@ -66,6 +67,10 @@ Instance.prototype.stop = function( callback ) {
if ( process.platform === 'win32' && this.image ) {
child.exec( 'taskkill /F /IM ' + this.image )
.on( 'exit', this.emit.bind( this, 'stop' ) );
// ie case on windows machine
} else if ( process.platform === 'win32' && this.browserType === 'ie' ) {
child.exec( 'taskkill /F /IM iexplore.exe')
.on( 'exit', this.emit.bind( this, 'stop' ) );
// OSX case with "open" command
} else if ( this.command === 'open' ) {
child.exec( 'osascript -e \'tell application "' + this.processName + '" to quit\'' );
Expand Down
1 change: 1 addition & 0 deletions lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ setups.chrome = function( browser, uri, options, callback ) {
uri
] ).filter( Boolean ) );
};
setups.canary = setups.chrome;

/**
* Setup procedure for PhantomJS:
Expand Down

0 comments on commit 654d7fb

Please sign in to comment.