2014-03-25 05:52:11 +09:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Mozilla Foundation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2018-02-11 01:06:03 +09:00
|
|
|
/* eslint-disable object-shorthand, mozilla/use-includes-instead-of-indexOf */
|
2014-03-25 05:52:11 +09:00
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var os = require('os');
|
|
|
|
var fs = require('fs');
|
|
|
|
var path = require('path');
|
|
|
|
var spawn = require('child_process').spawn;
|
|
|
|
var testUtils = require('./testutils.js');
|
2015-07-17 04:40:57 +09:00
|
|
|
var crypto = require('crypto');
|
2014-03-25 05:52:11 +09:00
|
|
|
|
|
|
|
var tempDirPrefix = 'pdfjs_';
|
|
|
|
|
2018-04-13 07:15:25 +09:00
|
|
|
function WebBrowser(name, path, headless) {
|
2014-03-25 05:52:11 +09:00
|
|
|
this.name = name;
|
|
|
|
this.path = path;
|
2018-04-13 07:15:25 +09:00
|
|
|
this.headless = headless;
|
2014-03-25 05:52:11 +09:00
|
|
|
this.tmpDir = null;
|
|
|
|
this.profileDir = null;
|
|
|
|
this.process = null;
|
2015-07-17 04:40:57 +09:00
|
|
|
this.requestedExit = false;
|
2014-03-25 05:52:11 +09:00
|
|
|
this.finished = false;
|
|
|
|
this.callback = null;
|
2015-07-17 04:40:57 +09:00
|
|
|
// Used to identify processes whose pid is lost. This string is directly used
|
|
|
|
// as a command-line argument, so it only consists of letters.
|
|
|
|
this.uniqStringId = 'webbrowser' + crypto.randomBytes(32).toString('hex');
|
2014-03-25 05:52:11 +09:00
|
|
|
}
|
|
|
|
WebBrowser.prototype = {
|
|
|
|
start: function (url) {
|
|
|
|
this.tmpDir = path.join(os.tmpdir(), tempDirPrefix + this.name);
|
|
|
|
if (!fs.existsSync(this.tmpDir)) {
|
|
|
|
fs.mkdirSync(this.tmpDir);
|
|
|
|
}
|
2015-07-17 04:40:57 +09:00
|
|
|
this.startProcess(url);
|
2014-03-25 05:52:11 +09:00
|
|
|
},
|
|
|
|
getProfileDir: function () {
|
|
|
|
if (!this.profileDir) {
|
|
|
|
var profileDir = path.join(this.tmpDir, 'profile');
|
|
|
|
if (fs.existsSync(profileDir)) {
|
|
|
|
testUtils.removeDirSync(profileDir);
|
|
|
|
}
|
|
|
|
fs.mkdirSync(profileDir);
|
|
|
|
this.profileDir = profileDir;
|
|
|
|
this.setupProfileDir(profileDir);
|
|
|
|
}
|
|
|
|
return this.profileDir;
|
|
|
|
},
|
|
|
|
buildArguments: function (url) {
|
|
|
|
return [url];
|
|
|
|
},
|
|
|
|
setupProfileDir: function (dir) {
|
|
|
|
},
|
|
|
|
startProcess: function (url) {
|
2015-07-17 04:40:57 +09:00
|
|
|
console.assert(!this.process, 'startProcess may be called only once');
|
|
|
|
|
2014-03-25 05:52:11 +09:00
|
|
|
var args = this.buildArguments(url);
|
2015-07-17 04:40:57 +09:00
|
|
|
args = args.concat('--' + this.uniqStringId);
|
2018-04-13 07:15:25 +09:00
|
|
|
|
|
|
|
this.process = spawn(this.path, args, { stdio: [process.stdin,
|
|
|
|
process.stdout,
|
|
|
|
process.stderr], });
|
|
|
|
|
2015-07-17 04:40:57 +09:00
|
|
|
this.process.on('exit', function (code, signal) {
|
|
|
|
this.process = null;
|
|
|
|
var exitInfo = code !== null ? ' with status ' + code :
|
|
|
|
' in response to signal ' + signal;
|
|
|
|
if (this.requestedExit) {
|
|
|
|
this.log('Browser process exited' + exitInfo);
|
|
|
|
} else {
|
|
|
|
// This was observed on Windows bots with Firefox. Apparently the
|
|
|
|
// Firefox Maintenance Service restarts Firefox shortly after starting
|
|
|
|
// up. When this happens, we no longer know the pid of the process.
|
|
|
|
this.log('Browser process unexpectedly exited' + exitInfo);
|
|
|
|
}
|
2014-03-25 05:52:11 +09:00
|
|
|
}.bind(this));
|
|
|
|
},
|
2015-07-17 04:40:57 +09:00
|
|
|
cleanup: function () {
|
|
|
|
console.assert(this.requestedExit,
|
|
|
|
'cleanup should only be called after an explicit stop() request');
|
|
|
|
|
2014-04-02 22:02:40 +09:00
|
|
|
try {
|
|
|
|
testUtils.removeDirSync(this.tmpDir);
|
|
|
|
} catch (e) {
|
2015-07-17 04:40:57 +09:00
|
|
|
if (e.code !== 'ENOENT') {
|
|
|
|
this.log('Failed to remove profile directory: ' + e);
|
|
|
|
if (!this.cleanupFailStart) {
|
|
|
|
this.cleanupFailStart = Date.now();
|
|
|
|
} else if (Date.now() - this.cleanupFailStart > 10000) {
|
|
|
|
throw new Error('Failed to remove profile dir within 10 seconds');
|
2014-04-02 22:02:40 +09:00
|
|
|
}
|
2015-07-17 04:40:57 +09:00
|
|
|
this.log('Retrying in a second...');
|
|
|
|
setTimeout(this.cleanup.bind(this), 1000);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// This should not happen, but we just warn instead of failing loudly
|
|
|
|
// because the post-condition of cleanup is that the profile directory is
|
|
|
|
// gone. If the directory does not exists, then this post-condition is
|
|
|
|
// satisfied.
|
|
|
|
this.log('Cannot remove non-existent directory: ' + e);
|
2014-04-02 22:02:40 +09:00
|
|
|
}
|
2015-07-17 04:40:57 +09:00
|
|
|
this.finished = true;
|
|
|
|
this.log('Clean-up finished. Going to call callback...');
|
|
|
|
this.callback();
|
2014-03-25 05:52:11 +09:00
|
|
|
},
|
|
|
|
stop: function (callback) {
|
2015-07-17 04:40:57 +09:00
|
|
|
console.assert(this.tmpDir, '.start() must be called before stop()');
|
|
|
|
// Require the callback to ensure that callers do not make any assumptions
|
|
|
|
// on the state of this browser instance until the callback is called.
|
|
|
|
console.assert(typeof callback === 'function', 'callback is required');
|
|
|
|
console.assert(!this.requestedExit, '.stop() may be called only once');
|
|
|
|
|
|
|
|
this.requestedExit = true;
|
2014-03-25 05:52:11 +09:00
|
|
|
if (this.finished) {
|
2015-07-17 04:40:57 +09:00
|
|
|
this.log('Browser already stopped, invoking callback...');
|
|
|
|
callback();
|
|
|
|
} else if (this.process) {
|
|
|
|
this.log('Going to wait until the browser process has exited.');
|
|
|
|
this.callback = callback;
|
|
|
|
this.process.once('exit', this.cleanup.bind(this));
|
|
|
|
this.process.kill('SIGTERM');
|
2014-03-25 05:52:11 +09:00
|
|
|
} else {
|
2015-07-17 04:40:57 +09:00
|
|
|
this.log('Process already exited, checking if the process restarted...');
|
2014-03-25 05:52:11 +09:00
|
|
|
this.callback = callback;
|
2015-07-17 04:40:57 +09:00
|
|
|
this.killProcessUnknownPid(this.cleanup.bind(this));
|
2014-03-25 05:52:11 +09:00
|
|
|
}
|
2015-07-17 04:40:57 +09:00
|
|
|
},
|
|
|
|
killProcessUnknownPid: function(callback) {
|
|
|
|
this.log('pid unknown, killing processes matching ' + this.uniqStringId);
|
2014-03-25 05:52:11 +09:00
|
|
|
|
2015-07-17 04:40:57 +09:00
|
|
|
var cmdKillAll, cmdCheckAllKilled, isAllKilled;
|
|
|
|
|
|
|
|
if (process.platform === 'win32') {
|
2017-05-02 09:03:13 +09:00
|
|
|
var wmicPrefix = ['process', 'where', '"not Name = \'cmd.exe\' ' +
|
2015-07-17 04:40:57 +09:00
|
|
|
'and not Name like \'%wmic%\' ' +
|
2017-05-02 09:03:13 +09:00
|
|
|
'and CommandLine like \'%' + this.uniqStringId + '%\'"'];
|
|
|
|
cmdKillAll = {
|
|
|
|
file: 'wmic',
|
Fix inconsistent spacing and trailing commas in objects in `test/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/test/chromium/test-telemetry.js b/test/chromium/test-telemetry.js
index cc412a31..2e5bdfa1 100755
--- a/test/chromium/test-telemetry.js
+++ b/test/chromium/test-telemetry.js
@@ -324,7 +324,7 @@ var tests = [
var window = createExtensionGlobal();
telemetryScript.runInNewContext(window);
window.chrome.runtime.getManifest = function() {
- return { version: '1.0.1', };
+ return { version: '1.0.1', };
};
window.Date.test_now_value += 12 * 36E5;
telemetryScript.runInNewContext(window);
diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js
index 1f00747a..f22988e7 100644
--- a/test/unit/api_spec.js
+++ b/test/unit/api_spec.js
@@ -503,8 +503,9 @@ describe('api', function() {
it('gets destinations, from /Dests dictionary', function(done) {
var promise = doc.getDestinations();
promise.then(function(data) {
- expect(data).toEqual({ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', },
- 0, 841.89, null], });
+ expect(data).toEqual({
+ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', }, 0, 841.89, null],
+ });
done();
}).catch(function (reason) {
done.fail(reason);
diff --git a/test/unit/function_spec.js b/test/unit/function_spec.js
index 66441212..62127eb9 100644
--- a/test/unit/function_spec.js
+++ b/test/unit/function_spec.js
@@ -492,9 +492,11 @@ describe('function', function() {
it('check compiled mul', function() {
check([0.25, 0.5, 'mul'], [], [0, 1], [{ input: [], output: [0.125], }]);
check([0, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
- check([0.5, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.125], }]);
+ check([0.5, 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0.125], }]);
check([1, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.25], }]);
- check([0, 'exch', 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
+ check([0, 'exch', 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0], }]);
check([0.5, 'exch', 'mul'], [0, 1], [0, 1],
[{ input: [0.25], output: [0.125], }]);
check([1, 'exch', 'mul'], [0, 1], [0, 1],
```
2017-06-02 19:55:01 +09:00
|
|
|
args: wmicPrefix.concat(['call', 'terminate']),
|
2017-05-02 09:03:13 +09:00
|
|
|
};
|
|
|
|
cmdCheckAllKilled = {
|
|
|
|
file: 'wmic',
|
Fix inconsistent spacing and trailing commas in objects in `test/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/test/chromium/test-telemetry.js b/test/chromium/test-telemetry.js
index cc412a31..2e5bdfa1 100755
--- a/test/chromium/test-telemetry.js
+++ b/test/chromium/test-telemetry.js
@@ -324,7 +324,7 @@ var tests = [
var window = createExtensionGlobal();
telemetryScript.runInNewContext(window);
window.chrome.runtime.getManifest = function() {
- return { version: '1.0.1', };
+ return { version: '1.0.1', };
};
window.Date.test_now_value += 12 * 36E5;
telemetryScript.runInNewContext(window);
diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js
index 1f00747a..f22988e7 100644
--- a/test/unit/api_spec.js
+++ b/test/unit/api_spec.js
@@ -503,8 +503,9 @@ describe('api', function() {
it('gets destinations, from /Dests dictionary', function(done) {
var promise = doc.getDestinations();
promise.then(function(data) {
- expect(data).toEqual({ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', },
- 0, 841.89, null], });
+ expect(data).toEqual({
+ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', }, 0, 841.89, null],
+ });
done();
}).catch(function (reason) {
done.fail(reason);
diff --git a/test/unit/function_spec.js b/test/unit/function_spec.js
index 66441212..62127eb9 100644
--- a/test/unit/function_spec.js
+++ b/test/unit/function_spec.js
@@ -492,9 +492,11 @@ describe('function', function() {
it('check compiled mul', function() {
check([0.25, 0.5, 'mul'], [], [0, 1], [{ input: [], output: [0.125], }]);
check([0, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
- check([0.5, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.125], }]);
+ check([0.5, 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0.125], }]);
check([1, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.25], }]);
- check([0, 'exch', 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
+ check([0, 'exch', 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0], }]);
check([0.5, 'exch', 'mul'], [0, 1], [0, 1],
[{ input: [0.25], output: [0.125], }]);
check([1, 'exch', 'mul'], [0, 1], [0, 1],
```
2017-06-02 19:55:01 +09:00
|
|
|
args: wmicPrefix.concat(['get', 'CommandLine']),
|
2017-05-02 09:03:13 +09:00
|
|
|
};
|
2015-07-17 04:40:57 +09:00
|
|
|
isAllKilled = function(exitCode, stdout) {
|
|
|
|
return stdout.indexOf(this.uniqStringId) === -1;
|
|
|
|
}.bind(this);
|
|
|
|
} else {
|
Fix inconsistent spacing and trailing commas in objects in `test/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/test/chromium/test-telemetry.js b/test/chromium/test-telemetry.js
index cc412a31..2e5bdfa1 100755
--- a/test/chromium/test-telemetry.js
+++ b/test/chromium/test-telemetry.js
@@ -324,7 +324,7 @@ var tests = [
var window = createExtensionGlobal();
telemetryScript.runInNewContext(window);
window.chrome.runtime.getManifest = function() {
- return { version: '1.0.1', };
+ return { version: '1.0.1', };
};
window.Date.test_now_value += 12 * 36E5;
telemetryScript.runInNewContext(window);
diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js
index 1f00747a..f22988e7 100644
--- a/test/unit/api_spec.js
+++ b/test/unit/api_spec.js
@@ -503,8 +503,9 @@ describe('api', function() {
it('gets destinations, from /Dests dictionary', function(done) {
var promise = doc.getDestinations();
promise.then(function(data) {
- expect(data).toEqual({ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', },
- 0, 841.89, null], });
+ expect(data).toEqual({
+ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', }, 0, 841.89, null],
+ });
done();
}).catch(function (reason) {
done.fail(reason);
diff --git a/test/unit/function_spec.js b/test/unit/function_spec.js
index 66441212..62127eb9 100644
--- a/test/unit/function_spec.js
+++ b/test/unit/function_spec.js
@@ -492,9 +492,11 @@ describe('function', function() {
it('check compiled mul', function() {
check([0.25, 0.5, 'mul'], [], [0, 1], [{ input: [], output: [0.125], }]);
check([0, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
- check([0.5, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.125], }]);
+ check([0.5, 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0.125], }]);
check([1, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.25], }]);
- check([0, 'exch', 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
+ check([0, 'exch', 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0], }]);
check([0.5, 'exch', 'mul'], [0, 1], [0, 1],
[{ input: [0.25], output: [0.125], }]);
check([1, 'exch', 'mul'], [0, 1], [0, 1],
```
2017-06-02 19:55:01 +09:00
|
|
|
cmdKillAll = { file: 'pkill', args: ['-f', this.uniqStringId], };
|
|
|
|
cmdCheckAllKilled = { file: 'pgrep', args: ['-f', this.uniqStringId], };
|
2015-07-17 04:40:57 +09:00
|
|
|
isAllKilled = function(pgrepStatus) {
|
|
|
|
return pgrepStatus === 1; // "No process matched.", per man pgrep.
|
|
|
|
};
|
2014-04-07 23:31:04 +09:00
|
|
|
}
|
2015-07-18 06:21:35 +09:00
|
|
|
function execAsyncNoStdin(cmd, onExit) {
|
2017-05-02 09:03:13 +09:00
|
|
|
var proc = spawn(cmd.file, cmd.args, {
|
|
|
|
shell: true,
|
|
|
|
stdio: 'pipe',
|
|
|
|
});
|
2015-07-17 04:40:57 +09:00
|
|
|
// Close stdin, otherwise wmic won't run.
|
|
|
|
proc.stdin.end();
|
2017-05-02 09:03:13 +09:00
|
|
|
var stdout = '';
|
|
|
|
proc.stdout.on('data', (data) => {
|
|
|
|
stdout += data;
|
|
|
|
});
|
|
|
|
proc.on('close', (code) => {
|
|
|
|
onExit(code, stdout);
|
|
|
|
});
|
2015-07-17 04:40:57 +09:00
|
|
|
}
|
|
|
|
var killDateStart = Date.now();
|
|
|
|
// Note: First process' output it shown, the later outputs are suppressed.
|
2015-07-18 06:21:35 +09:00
|
|
|
execAsyncNoStdin(cmdKillAll, function checkAlive(exitCode, firstStdout) {
|
|
|
|
execAsyncNoStdin(cmdCheckAllKilled, function(exitCode, stdout) {
|
2015-07-17 04:40:57 +09:00
|
|
|
if (isAllKilled(exitCode, stdout)) {
|
|
|
|
callback();
|
|
|
|
} else if (Date.now() - killDateStart > 10000) {
|
|
|
|
// Should finish termination within 10 (generous) seconds.
|
2015-07-18 06:21:35 +09:00
|
|
|
if (firstStdout) {
|
|
|
|
this.log('Output of first command:\n' + firstStdout);
|
|
|
|
}
|
2015-07-17 04:40:57 +09:00
|
|
|
if (stdout) {
|
|
|
|
this.log('Output of last command:\n' + stdout);
|
|
|
|
}
|
|
|
|
throw new Error('Failed to kill process of ' + this.name);
|
|
|
|
} else {
|
|
|
|
setTimeout(checkAlive.bind(this), 500);
|
|
|
|
}
|
|
|
|
}.bind(this));
|
|
|
|
}.bind(this));
|
|
|
|
},
|
|
|
|
log: function(msg) {
|
|
|
|
console.log('[' + this.name + '] ' + msg);
|
|
|
|
},
|
2014-03-25 05:52:11 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
var firefoxResourceDir = path.join(__dirname, 'resources', 'firefox');
|
|
|
|
|
2018-04-13 07:15:25 +09:00
|
|
|
function FirefoxBrowser(name, path, headless) {
|
2014-03-25 05:52:11 +09:00
|
|
|
if (os.platform() === 'darwin') {
|
|
|
|
var m = /([^.\/]+)\.app(\/?)$/.exec(path);
|
|
|
|
if (m) {
|
|
|
|
path += (m[2] ? '' : '/') + 'Contents/MacOS/firefox';
|
|
|
|
}
|
|
|
|
}
|
2018-04-13 07:15:25 +09:00
|
|
|
WebBrowser.call(this, name, path, headless);
|
2014-03-25 05:52:11 +09:00
|
|
|
}
|
|
|
|
FirefoxBrowser.prototype = Object.create(WebBrowser.prototype);
|
|
|
|
FirefoxBrowser.prototype.buildArguments = function (url) {
|
|
|
|
var profileDir = this.getProfileDir();
|
|
|
|
var args = [];
|
|
|
|
if (os.platform() === 'darwin') {
|
|
|
|
args.push('-foreground');
|
|
|
|
}
|
2018-04-13 07:15:25 +09:00
|
|
|
if (this.headless) {
|
|
|
|
args.push('--headless');
|
|
|
|
}
|
2014-03-25 05:52:11 +09:00
|
|
|
args.push('-no-remote', '-profile', profileDir, url);
|
|
|
|
return args;
|
|
|
|
};
|
|
|
|
FirefoxBrowser.prototype.setupProfileDir = function (dir) {
|
|
|
|
testUtils.copySubtreeSync(firefoxResourceDir, dir);
|
|
|
|
};
|
|
|
|
|
2018-04-13 07:15:25 +09:00
|
|
|
function ChromiumBrowser(name, path, headless) {
|
2014-03-25 05:52:11 +09:00
|
|
|
if (os.platform() === 'darwin') {
|
|
|
|
var m = /([^.\/]+)\.app(\/?)$/.exec(path);
|
|
|
|
if (m) {
|
|
|
|
path += (m[2] ? '' : '/') + 'Contents/MacOS/' + m[1];
|
|
|
|
console.log(path);
|
|
|
|
}
|
|
|
|
}
|
2018-04-13 07:15:25 +09:00
|
|
|
WebBrowser.call(this, name, path, headless);
|
2014-03-25 05:52:11 +09:00
|
|
|
}
|
|
|
|
ChromiumBrowser.prototype = Object.create(WebBrowser.prototype);
|
|
|
|
ChromiumBrowser.prototype.buildArguments = function (url) {
|
|
|
|
var profileDir = this.getProfileDir();
|
2018-04-13 07:15:25 +09:00
|
|
|
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;
|
2014-03-25 05:52:11 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
WebBrowser.create = function (desc) {
|
|
|
|
var name = desc.name;
|
2017-05-02 09:03:13 +09:00
|
|
|
var path = fs.realpathSync(desc.path);
|
2015-07-11 18:24:50 +09:00
|
|
|
if (!path) {
|
|
|
|
throw new Error('Browser executable not found: ' + desc.path);
|
|
|
|
}
|
2015-04-17 23:12:13 +09:00
|
|
|
|
2014-03-25 05:52:11 +09:00
|
|
|
if (/firefox/i.test(name)) {
|
2018-04-13 07:15:25 +09:00
|
|
|
return new FirefoxBrowser(name, path, desc.headless);
|
2014-03-25 05:52:11 +09:00
|
|
|
}
|
2014-04-04 21:48:23 +09:00
|
|
|
if (/(chrome|chromium|opera)/i.test(name)) {
|
2018-04-13 07:15:25 +09:00
|
|
|
return new ChromiumBrowser(name, path, desc.headless);
|
2014-03-25 05:52:11 +09:00
|
|
|
}
|
2018-04-13 07:15:25 +09:00
|
|
|
return new WebBrowser(name, path, desc.headless);
|
2014-03-25 05:52:11 +09:00
|
|
|
};
|
|
|
|
|
2015-07-12 03:08:00 +09:00
|
|
|
exports.WebBrowser = WebBrowser;
|