Skip to content

Commit

Permalink
Chromium support for Darwin and Windows
Browse files Browse the repository at this point in the history
Add support for Chromium for Darwin and Windows platforms
Remove linux chromium binary lookup in Google Chrome
Closes karma-runner#45
  • Loading branch information
gmoz22 committed May 5, 2015
1 parent 7f32b59 commit 8b952f2
Showing 1 changed file with 62 additions and 4 deletions.
66 changes: 62 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,50 @@ function getChromeExe(chromeDirName) {
return windowsChromeDirectory;
}

var ChromiumBrowser = function(baseBrowserDecorator, args) {
baseBrowserDecorator(this);

var flags = args.flags || [];

this._getOptions = function(url) {
// Chromium CLI options
// http://peter.sh/experiments/chromium-command-line-switches/
flags.forEach(function(flag, i) {
if(isJSFlags(flag)) flags[i] = sanitizeJSFlags(flag);
});

return [
'--user-data-dir=' + this._tempDir,
'--no-default-browser-check',
'--no-first-run',
'--disable-default-apps',
'--disable-popup-blocking',
'--disable-translate'
].concat(flags, [url]);
};
};

// Return location of Chromium's chrome.exe file.
function getChromiumExe(chromeDirName) {
// Only run these checks on win32
if (process.platform !== 'win32') {
return null;
}
var windowsChromiumDirectory, i, prefix;
var suffix = '\\Chromium\\Application\\chrome.exe';
var prefixes = [process.env.LOCALAPPDATA, process.env.PROGRAMFILES, process.env['PROGRAMFILES(X86)']];

for (i = 0; i < prefixes.length; i++) {
prefix = prefixes[i];
if (fs.existsSync(prefix + suffix)) {
windowsChromiumDirectory = prefix + suffix;
break;
}
}

return windowsChromiumDirectory;
}

function getBin(commands) {
// Don't run these checks on win32
if (process.platform !== 'linux') {
Expand All @@ -79,9 +123,7 @@ ChromeBrowser.prototype = {
name: 'Chrome',

DEFAULT_CMD: {
// Try chromium-browser before chromium to avoid conflict with the legacy
// chromium-bsu package previously known as 'chromium' in Debian and Ubuntu.
linux: getBin(['chromium-browser', 'chromium', 'google-chrome', 'google-chrome-stable']),
linux: getBin(['google-chrome', 'google-chrome-stable']),
darwin: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
win32: getChromeExe('Chrome')
},
Expand Down Expand Up @@ -128,6 +170,21 @@ ChromeCanaryBrowser.prototype = {

ChromeCanaryBrowser.$inject = ['baseBrowserDecorator', 'args'];

ChromiumBrowser.prototype = {
name: 'Chromium',

DEFAULT_CMD: {
// Try chromium-browser before chromium to avoid conflict with the legacy
// chromium-bsu package previously known as 'chromium' in Debian and Ubuntu.
linux: getBin(['chromium-browser', 'chromium']),
darwin: '/Applications/Chromium.app/Contents/MacOS/Chromium',
win32: getChromiumExe()
},
ENV_CMD: 'CHROMIUM_BIN'
};

ChromiumBrowser.$inject = ['baseBrowserDecorator', 'args'];

var DartiumBrowser = function(baseBrowserDecorator, args) {
ChromeBrowser.call(this, baseBrowserDecorator, args);

Expand All @@ -153,11 +210,12 @@ DartiumBrowser.$inject = ['baseBrowserDecorator', 'args'];
module.exports = {
'launcher:Chrome': ['type', ChromeBrowser],
'launcher:ChromeCanary': ['type', ChromeCanaryBrowser],
'launcher:Chromium': ['type', ChromiumBrowser],
'launcher:Dartium': ['type', DartiumBrowser]
};

module.exports.test = {
isJSFlags: isJSFlags,
sanitizeJSFlags: sanitizeJSFlags,
canaryGetOptions: canaryGetOptions
}
}

0 comments on commit 8b952f2

Please sign in to comment.