Skip to content

Commit

Permalink
feat: Chromium support for Linux, Darwin and Windows
Browse files Browse the repository at this point in the history
Add support for Chromium for Linux, Darwin and Windows platforms
Remove linux chromium binary lookup in Google Chrome

Closes #45

BREAKING: Chromium needs to be explicitly enabled now
  • Loading branch information
haifengkao authored and dignifiedquire committed Aug 18, 2016
1 parent 108cd87 commit 33e8d82
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[![Build Status](https://img.shields.io/travis/karma-runner/karma-chrome-launcher/master.svg?style=flat-square)](https://travis-ci.org/karma-runner/karma-chrome-launcher) [![Dependency Status](https://img.shields.io/david/karma-runner/karma-chrome-launcher.svg?style=flat-square)](https://david-dm.org/karma-runner/karma-chrome-launcher) [![devDependency Status](https://img.shields.io/david/dev/karma-runner/karma-chrome-launcher.svg?style=flat-square)](https://david-dm.org/karma-runner/karma-chrome-launcher#info=devDependencies)

> Launcher for Google Chrome and Google Chrome Canary.
> Launcher for Google Chrome, Google Chrome Canary and Google Chromium.

This comment has been minimized.

Copy link
@mgol

mgol Aug 22, 2016

Contributor

It's just Chromium, not Google Chromium.

## Installation

Expand All @@ -22,7 +22,7 @@ $ npm install karma-chrome-launcher --save-dev
// karma.conf.js
module.exports = function(config) {
config.set({
browsers: ['Chrome', 'Chrome_without_security'],
browsers: ['Chrome', 'Chrome_without_security'], // You may use 'ChromeCanary' or 'Chromium' as well

// you can define custom flags
customLaunchers: {
Expand Down
66 changes: 65 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,54 @@ 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',
'--disable-background-timer-throttling'
].concat(flags, [url])

This comment has been minimized.

Copy link
@mgol

mgol Aug 22, 2016

Contributor

Those flags (and maybe even more code from this cconstructor) should be extracted, currenlty there's a lot of repetition in this file.

This comment has been minimized.

Copy link
@dignifiedquire

dignifiedquire Aug 22, 2016

Member

agreed

}
}

// 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]
try {
windowsChromiumDirectory = path.join(prefix, suffix)
fsAccess.sync(windowsChromiumDirectory)
return windowsChromiumDirectory
} catch (e) {}
}

return windowsChromiumDirectory
}

function getBin (commands) {
// Don't run these checks on win32
if (process.platform !== 'linux') {
Expand Down Expand Up @@ -104,7 +152,7 @@ ChromeBrowser.prototype = {
DEFAULT_CMD: {
// Try chromium-browser before chromium to avoid conflict with the legacy

This comment has been minimized.

Copy link
@rkrisztian

rkrisztian Dec 7, 2016

This comment will then need some update, I suppose.

// 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: getChromeDarwin('/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'),
win32: getChromeExe('Chrome')
},
Expand Down Expand Up @@ -150,6 +198,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 () {
ChromeBrowser.apply(this, arguments)

Expand All @@ -174,6 +237,7 @@ DartiumBrowser.$inject = ['baseBrowserDecorator', 'args']
module.exports = {
'launcher:Chrome': ['type', ChromeBrowser],
'launcher:ChromeCanary': ['type', ChromeCanaryBrowser],
'launcher:Chromium': ['type', ChromiumBrowser],
'launcher:Dartium': ['type', DartiumBrowser]
}

Expand Down

0 comments on commit 33e8d82

Please sign in to comment.