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

Support running the tests headlessly. #9660

Merged
merged 1 commit into from
Jun 9, 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
4 changes: 3 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ function examineRefImages() {
startServer();
var startUrl = 'http://' + server.host + ':' + server.port +
'/test/resources/reftest-analyzer.html#web=/test/eq.log';
var browser = WebBrowser.create(sessions[0].config);
var config = Object.assign({}, sessions[0].config);
config['headless'] = false;
var browser = WebBrowser.create(config);
browser.start(startUrl);
}

Expand Down
46 changes: 34 additions & 12 deletions test/webbrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ var crypto = require('crypto');

var tempDirPrefix = 'pdfjs_';

function WebBrowser(name, path) {
function WebBrowser(name, path, headless) {
this.name = name;
this.path = path;
this.headless = headless;
this.tmpDir = null;
this.profileDir = null;
this.process = null;
Expand Down Expand Up @@ -69,7 +70,11 @@ WebBrowser.prototype = {

var args = this.buildArguments(url);
args = args.concat('--' + this.uniqStringId);
this.process = spawn(this.path, args);

this.process = spawn(this.path, args, { stdio: [process.stdin,
process.stdout,
process.stderr], });

this.process.on('exit', function (code, signal) {
this.process = null;
var exitInfo = code !== null ? ' with status ' + code :
Expand Down Expand Up @@ -204,14 +209,14 @@ WebBrowser.prototype = {

var firefoxResourceDir = path.join(__dirname, 'resources', 'firefox');

function FirefoxBrowser(name, path) {
function FirefoxBrowser(name, path, headless) {
if (os.platform() === 'darwin') {
var m = /([^.\/]+)\.app(\/?)$/.exec(path);
if (m) {
path += (m[2] ? '' : '/') + 'Contents/MacOS/firefox';
}
}
WebBrowser.call(this, name, path);
WebBrowser.call(this, name, path, headless);
}
FirefoxBrowser.prototype = Object.create(WebBrowser.prototype);
FirefoxBrowser.prototype.buildArguments = function (url) {
Expand All @@ -220,29 +225,46 @@ FirefoxBrowser.prototype.buildArguments = function (url) {
if (os.platform() === 'darwin') {
args.push('-foreground');
}
if (this.headless) {
args.push('--headless');
}
args.push('-no-remote', '-profile', profileDir, url);
return args;
};
FirefoxBrowser.prototype.setupProfileDir = function (dir) {
testUtils.copySubtreeSync(firefoxResourceDir, dir);
};

function ChromiumBrowser(name, path) {
function ChromiumBrowser(name, path, headless) {
if (os.platform() === 'darwin') {
var m = /([^.\/]+)\.app(\/?)$/.exec(path);
if (m) {
path += (m[2] ? '' : '/') + 'Contents/MacOS/' + m[1];
console.log(path);
}
}
WebBrowser.call(this, name, path);
WebBrowser.call(this, name, path, headless);
}
ChromiumBrowser.prototype = Object.create(WebBrowser.prototype);
ChromiumBrowser.prototype.buildArguments = function (url) {
var profileDir = this.getProfileDir();
return ['--user-data-dir=' + profileDir,
'--no-first-run', '--disable-sync',
'--no-default-browser-check', url];
var crashDumpsDir = path.join(this.tmpDir, 'crash_dumps');
var args = ['--user-data-dir=' + profileDir,
'--no-first-run',
'--disable-sync',
'--no-default-browser-check',
'--disable-device-discovery-notifications',
'--disable-translate',
'--disable-background-timer-throttling',
'--disable-renderer-backgrounding'];
if (this.headless) {
args.push('--headless',
'--crash-dumps-dir=' + crashDumpsDir,
'--disable-gpu',
'--remote-debugging-port=9222');
}
args.push(url);
return args;
};

WebBrowser.create = function (desc) {
Expand All @@ -253,12 +275,12 @@ WebBrowser.create = function (desc) {
}

if (/firefox/i.test(name)) {
return new FirefoxBrowser(name, path);
return new FirefoxBrowser(name, path, desc.headless);
}
if (/(chrome|chromium|opera)/i.test(name)) {
return new ChromiumBrowser(name, path);
return new ChromiumBrowser(name, path, desc.headless);
}
return new WebBrowser(name, path);
return new WebBrowser(name, path, desc.headless);
};

exports.WebBrowser = WebBrowser;