Skip to content

Commit

Permalink
Fix some issues in Firefox (closes DevExpress#2035, closes DevExpress…
Browse files Browse the repository at this point in the history
…#2180)

Avoid password saving bubble in Firefox
Fix concurrently mode for Firefox on macOS
  • Loading branch information
AndreyBelym committed Mar 16, 2018
1 parent e7dee93 commit eec4474
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 20 deletions.
20 changes: 5 additions & 15 deletions src/browser/provider/built-in/chrome/local-chrome.js
Original file line number Diff line number Diff line change
@@ -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 []
Expand All @@ -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));
browserStarter.startBrowser(chromeOpenParameters, pageUrl);
}

export async function stop ({ browserId }) {
Expand Down
11 changes: 7 additions & 4 deletions src/browser/provider/built-in/firefox/local-firefox.js
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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 }) {
Expand Down
3 changes: 2 additions & 1 deletion src/browser/provider/built-in/firefox/runtime-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
38 changes: 38 additions & 0 deletions src/browser/provider/utils/browser-starter.js
Original file line number Diff line number Diff line change
@@ -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) {
var 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();
}
}

0 comments on commit eec4474

Please sign in to comment.