Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some issues in Firefox (closes #2035, closes #2180) #2224

Merged
merged 2 commits into from
Mar 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
await 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) {
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();
}
}