From c89482f566bd2f806b448950c92bd4647c914079 Mon Sep 17 00:00:00 2001 From: Andrey Belym Date: Sat, 17 Mar 2018 00:12:13 +0300 Subject: [PATCH] Fix some issues in Firefox (closes #2035, closes #2180) (#2224) * Fix some issues in Firefox (closes #2035, closes #2180) Avoid password saving bubble in Firefox Fix concurrently mode for Firefox on macOS * Fix missing await --- .../provider/built-in/chrome/local-chrome.js | 20 +++------- .../built-in/firefox/local-firefox.js | 11 ++++-- .../provider/built-in/firefox/runtime-info.js | 3 +- src/browser/provider/utils/browser-starter.js | 38 +++++++++++++++++++ 4 files changed, 52 insertions(+), 20 deletions(-) create mode 100644 src/browser/provider/utils/browser-starter.js diff --git a/src/browser/provider/built-in/chrome/local-chrome.js b/src/browser/provider/built-in/chrome/local-chrome.js index 08caf94d623..4cd5289428c 100644 --- a/src/browser/provider/built-in/chrome/local-chrome.js +++ b/src/browser/provider/built-in/chrome/local-chrome.js @@ -1,13 +1,9 @@ -import OS from 'os-family'; -import Promise from 'pinkie'; import browserTools from 'testcafe-browser-tools'; import killBrowserProcess from '../../utils/kill-browser-process'; -import delay from '../../../../utils/delay'; +import BrowserStarter from '../../utils/browser-starter'; -const MACOS_PROCESS_THROTTLING = 500; - -var throttlingPromise = Promise.resolve(); +const browserStarter = new BrowserStarter(); function buildChromeArgs (config, cdpPort, platformArgs, profileDir) { return [] @@ -22,18 +18,12 @@ function buildChromeArgs (config, cdpPort, platformArgs, profileDir) { } export async function start (pageUrl, { browserName, config, cdpPort, tempProfileDir }) { - var chromeInfo = await browserTools.getBrowserInfo(config.path || browserName); - var chromeOpenParameters = Object.assign({}, chromeInfo); + const chromeInfo = await browserTools.getBrowserInfo(config.path || browserName); + const chromeOpenParameters = Object.assign({}, chromeInfo); chromeOpenParameters.cmd = buildChromeArgs(config, cdpPort, chromeOpenParameters.cmd, tempProfileDir); - var currentThrottlingPromise = throttlingPromise; - - if (OS.mac) - throttlingPromise = throttlingPromise.then(() => delay(MACOS_PROCESS_THROTTLING)); - - await currentThrottlingPromise - .then(() => browserTools.open(chromeOpenParameters, pageUrl)); + await browserStarter.startBrowser(chromeOpenParameters, pageUrl); } export async function stop ({ browserId }) { diff --git a/src/browser/provider/built-in/firefox/local-firefox.js b/src/browser/provider/built-in/firefox/local-firefox.js index 1fdc0b2f22e..0801d0335a8 100644 --- a/src/browser/provider/built-in/firefox/local-firefox.js +++ b/src/browser/provider/built-in/firefox/local-firefox.js @@ -1,8 +1,11 @@ import OS from 'os-family'; import browserTools from 'testcafe-browser-tools'; import killBrowserProcess from '../../utils/kill-browser-process'; +import BrowserStarter from '../../utils/browser-starter'; +const browserStarter = new BrowserStarter(); + function correctOpenParametersForMac (parameters) { parameters.macOpenCmdTemplate = parameters.macOpenCmdTemplate .replace('open', 'open -n') @@ -23,16 +26,16 @@ function buildFirefoxArgs (config, platformArgs, profileDir) { } export async function start (pageUrl, runtimeInfo) { - var { browserName, config, tempProfileDir } = runtimeInfo; - var firefoxInfo = await browserTools.getBrowserInfo(config.path || browserName); - var firefoxOpenParameters = Object.assign({}, firefoxInfo); + const { browserName, config, tempProfileDir } = runtimeInfo; + const firefoxInfo = await browserTools.getBrowserInfo(config.path || browserName); + const firefoxOpenParameters = Object.assign({}, firefoxInfo); if (OS.mac && !config.userProfile) correctOpenParametersForMac(firefoxOpenParameters); firefoxOpenParameters.cmd = buildFirefoxArgs(config, firefoxOpenParameters.cmd, tempProfileDir, runtimeInfo.newInstance); - await browserTools.open(firefoxOpenParameters, pageUrl); + await browserStarter.startBrowser(firefoxOpenParameters, pageUrl); } export async function stop ({ browserId }) { diff --git a/src/browser/provider/built-in/firefox/runtime-info.js b/src/browser/provider/built-in/firefox/runtime-info.js index 16552065479..9384ea68c82 100644 --- a/src/browser/provider/built-in/firefox/runtime-info.js +++ b/src/browser/provider/built-in/firefox/runtime-info.js @@ -38,7 +38,8 @@ async function generatePrefs (profileDir, port) { 'user_pref("extensions.shield-recipe-client.first_run", false);', 'user_pref("extensions.shield-recipe-client.startupExperimentPrefs.browser.newtabpage.activity-stream.enabled", false);', 'user_pref("devtools.toolbox.host", "window");', - 'user_pref("devtools.toolbox.previousHost", "bottom");' + 'user_pref("devtools.toolbox.previousHost", "bottom");', + 'user_pref("signon.rememberSignons", false);' ]; if (port) { diff --git a/src/browser/provider/utils/browser-starter.js b/src/browser/provider/utils/browser-starter.js new file mode 100644 index 00000000000..64198f447bf --- /dev/null +++ b/src/browser/provider/utils/browser-starter.js @@ -0,0 +1,38 @@ +import Promise from 'pinkie'; +import OS from 'os-family'; +import browserTools from 'testcafe-browser-tools'; +import delay from '../../../utils/delay'; + + +const POST_OPERATION_DELAY = 500; + +class OperationsQueue { + constructor () { + this.chainPromise = Promise.resolve(); + } + + executeOperation (operation) { + const operationPromise = this.chainPromise.then(operation); + + this.chainPromise = operationPromise.then(() => delay(POST_OPERATION_DELAY)); + + return operationPromise; + } +} + +export default class BrowserStarter { + constructor () { + // NOTE: You can't start multiple instances of the same app at the same time on macOS. + // That's why a queue of opening requests is needed. + this.macOSBrowserOpeningQueue = new OperationsQueue(); + } + + async startBrowser (...openArgs) { + const openBrowserOperation = () => browserTools.open(...openArgs); + + if (OS.mac) + await this.macOSBrowserOpeningQueue.executeOperation(openBrowserOperation); + else + await openBrowserOperation(); + } +}