From 7ee3c44365df645e49ef739590b2571c74c6d184 Mon Sep 17 00:00:00 2001 From: Jesse Zhou Date: Tue, 10 Dec 2019 05:42:48 -0800 Subject: [PATCH] fix: Removed default '--mute-audio' flag for chromium (#1775) * 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 --- src/extension-runners/chromium.js | 11 ++++++-- .../test-extension-runners/test.chromium.js | 28 +++++++++++++------ 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/extension-runners/chromium.js b/src/extension-runners/chromium.js index 862ba9c67e..ebebdbd6d1 100644 --- a/src/extension-runners/chromium.js +++ b/src/extension-runners/chromium.js @@ -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. */ @@ -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}`); diff --git a/tests/unit/test-extension-runners/test.chromium.js b/tests/unit/test-extension-runners/test.chromium.js index f7ba3cbf6e..041592b66c 100644 --- a/tests/unit/test-extension-runners/test.chromium.js +++ b/tests/unit/test-extension-runners/test.chromium.js @@ -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'; @@ -17,6 +16,7 @@ import { } from '../helpers'; import { ChromiumExtensionRunner, + DEFAULT_CHROME_FLAGS, } from '../../../src/extension-runners/chromium'; import type { ChromiumExtensionRunnerParams, @@ -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(), @@ -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); @@ -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, @@ -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, @@ -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', @@ -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', @@ -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', ],