Skip to content

Commit

Permalink
fix: Removed default '--mute-audio' flag for chromium (#1775)
Browse files Browse the repository at this point in the history
* fix: Removed default '--mute-audio' flag for chromium
* refactor: Combined 'defaultChromeFlags' into renamed exported const
* test: Asserted that only expected chrome flags are used
* refactor: Moved excluded flags into a const for easy future additions
  • Loading branch information
Jesse Zhou authored and rpl committed Dec 10, 2019
1 parent 7394344 commit 7ee3c44
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
11 changes: 9 additions & 2 deletions src/extension-runners/chromium.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ const log = createLogger(__filename);

const asyncMkdirp = promisify(mkdirp);

const EXCLUDED_CHROME_FLAGS = [
'--disable-extensions',
'--mute-audio',
];

export const DEFAULT_CHROME_FLAGS = ChromeLauncher.defaultFlags()
.filter((flag) => !EXCLUDED_CHROME_FLAGS.includes(flag));

/**
* Implements an IExtensionRunner which manages a Chromium instance.
*/
Expand Down Expand Up @@ -111,8 +119,7 @@ export class ChromiumExtensionRunner {
log.debug(`(chromiumBinary: ${chromiumBinary})`);
}

const chromeFlags = ChromeLauncher.defaultFlags()
.filter((flag) => flag !== '--disable-extensions');
const chromeFlags = [...DEFAULT_CHROME_FLAGS];

chromeFlags.push(`--load-extension=${extensions}`);

Expand Down
28 changes: 19 additions & 9 deletions tests/unit/test-extension-runners/test.chromium.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {describe, it} from 'mocha';
import deepcopy from 'deepcopy';
import fs from 'mz/fs';
import sinon from 'sinon';
import ChromeLauncher from 'chrome-launcher';
import WebSocket from 'ws';

import getValidatedManifest from '../../../src/util/manifest';
Expand All @@ -17,6 +16,7 @@ import {
} from '../helpers';
import {
ChromiumExtensionRunner,
DEFAULT_CHROME_FLAGS,
} from '../../../src/extension-runners/chromium';
import type {
ChromiumExtensionRunnerParams,
Expand All @@ -25,9 +25,6 @@ import {
consoleStream, // instance is imported to inspect logged messages
} from '../../../src/util/logger';

const defaultChromeFlags = ChromeLauncher.defaultFlags()
.filter((flag) => flag !== '--disable-extensions');

function prepareExtensionRunnerParams({params} = {}) {
const fakeChromeInstance = {
process: new StubChildProcess(),
Expand All @@ -52,6 +49,19 @@ function prepareExtensionRunnerParams({params} = {}) {

describe('util/extension-runners/chromium', async () => {

it('uses the expected chrome flags', () => {
const expectedFlags = [ // Flags from 11.2
'--disable-translate',
'--disable-background-networking',
'--disable-sync',
'--metrics-recording-only',
'--disable-default-apps',
'--no-first-run',
];

assert.deepEqual(DEFAULT_CHROME_FLAGS, expectedFlags);
});

it('installs and runs the extension', async () => {
const {params, fakeChromeInstance} = prepareExtensionRunnerParams();
const runnerInstance = new ChromiumExtensionRunner(params);
Expand All @@ -67,7 +77,7 @@ describe('util/extension-runners/chromium', async () => {
enableExtensions: true,
chromePath: undefined,
chromeFlags: [
...defaultChromeFlags,
...DEFAULT_CHROME_FLAGS,
`--load-extension=${reloadManagerExtension},/fake/sourceDir`,
],
startingUrl: undefined,
Expand Down Expand Up @@ -260,7 +270,7 @@ describe('util/extension-runners/chromium', async () => {
enableExtensions: true,
chromePath: '/my/custom/chrome-bin',
chromeFlags: [
...defaultChromeFlags,
...DEFAULT_CHROME_FLAGS,
`--load-extension=${reloadManagerExtension},/fake/sourceDir`,
],
startingUrl: undefined,
Expand All @@ -285,7 +295,7 @@ describe('util/extension-runners/chromium', async () => {
enableExtensions: true,
chromePath: undefined,
chromeFlags: [
...defaultChromeFlags,
...DEFAULT_CHROME_FLAGS,
`--load-extension=${reloadManagerExtension},/fake/sourceDir`,
'url2',
'url3',
Expand Down Expand Up @@ -315,7 +325,7 @@ describe('util/extension-runners/chromium', async () => {
enableExtensions: true,
chromePath: undefined,
chromeFlags: [
...defaultChromeFlags,
...DEFAULT_CHROME_FLAGS,
`--load-extension=${reloadManagerExtension},/fake/sourceDir`,
'--arg1',
'arg2',
Expand Down Expand Up @@ -347,7 +357,7 @@ describe('util/extension-runners/chromium', async () => {
enableExtensions: true,
chromePath: undefined,
chromeFlags: [
...defaultChromeFlags,
...DEFAULT_CHROME_FLAGS,
`--load-extension=${reloadManagerExtension},/fake/sourceDir`,
'--user-data-dir=/fake/chrome/profile',
],
Expand Down

0 comments on commit 7ee3c44

Please sign in to comment.