2019-05-20 17:04:18 +00:00
|
|
|
const chai = require('chai')
|
|
|
|
const dirtyChai = require('dirty-chai')
|
2017-01-24 21:49:45 +00:00
|
|
|
const childProcess = require('child_process')
|
2017-03-30 14:11:49 +00:00
|
|
|
const fs = require('fs')
|
2016-03-25 20:03:49 +00:00
|
|
|
const http = require('http')
|
|
|
|
const multiparty = require('multiparty')
|
|
|
|
const path = require('path')
|
2016-10-05 20:53:13 +00:00
|
|
|
const temp = require('temp').track()
|
2016-03-25 20:03:49 +00:00
|
|
|
const url = require('url')
|
2018-09-13 16:10:51 +00:00
|
|
|
const { closeWindow } = require('./window-helpers')
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2018-09-13 16:10:51 +00:00
|
|
|
const { remote } = require('electron')
|
2019-01-07 19:19:27 +00:00
|
|
|
const { app, BrowserWindow, crashReporter } = remote
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2019-05-20 17:04:18 +00:00
|
|
|
const { expect } = chai
|
|
|
|
chai.use(dirtyChai)
|
|
|
|
|
2017-11-02 02:23:33 +00:00
|
|
|
describe('crashReporter module', () => {
|
2017-10-27 00:21:36 +00:00
|
|
|
if (process.mas || process.env.DISABLE_CRASH_REPORTER_TESTS) return
|
2017-04-05 20:42:24 +00:00
|
|
|
|
2018-06-12 16:40:15 +00:00
|
|
|
// TODO(alexeykuzmin): [Ch66] Fails. Fix it and enable back.
|
|
|
|
if (process.platform === 'linux') return
|
|
|
|
|
2017-10-27 00:21:36 +00:00
|
|
|
let originalTempDirectory = null
|
|
|
|
let tempDirectory = null
|
2017-04-05 20:42:24 +00:00
|
|
|
|
2017-10-27 00:21:36 +00:00
|
|
|
before(() => {
|
2017-04-05 20:42:24 +00:00
|
|
|
tempDirectory = temp.mkdirSync('electronCrashReporterSpec-')
|
|
|
|
originalTempDirectory = app.getPath('temp')
|
|
|
|
app.setPath('temp', tempDirectory)
|
|
|
|
})
|
|
|
|
|
2017-10-27 00:21:36 +00:00
|
|
|
after(() => {
|
2017-04-05 20:42:24 +00:00
|
|
|
app.setPath('temp', originalTempDirectory)
|
|
|
|
})
|
|
|
|
|
2017-10-27 00:21:36 +00:00
|
|
|
const fixtures = path.resolve(__dirname, 'fixtures')
|
2017-03-21 13:48:36 +00:00
|
|
|
const generateSpecs = (description, browserWindowOpts) => {
|
2017-10-27 00:21:36 +00:00
|
|
|
describe(description, () => {
|
|
|
|
let w = null
|
|
|
|
let stopServer = null
|
2017-03-21 13:53:17 +00:00
|
|
|
|
2017-10-27 00:21:36 +00:00
|
|
|
beforeEach(() => {
|
2017-04-19 16:48:32 +00:00
|
|
|
stopServer = null
|
2017-10-31 02:51:22 +00:00
|
|
|
w = new BrowserWindow(Object.assign({ show: false }, browserWindowOpts))
|
2017-03-21 13:53:17 +00:00
|
|
|
})
|
|
|
|
|
2017-10-27 00:21:36 +00:00
|
|
|
afterEach(() => closeWindow(w).then(() => { w = null }))
|
2017-03-21 13:53:17 +00:00
|
|
|
|
2017-10-27 00:21:36 +00:00
|
|
|
afterEach((done) => {
|
2017-04-19 16:48:32 +00:00
|
|
|
if (stopServer != null) {
|
|
|
|
stopServer(done)
|
2017-04-19 16:52:28 +00:00
|
|
|
} else {
|
|
|
|
done()
|
2017-04-19 16:48:32 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2017-11-25 11:55:35 +00:00
|
|
|
it('should send minidump when renderer crashes', function (done) {
|
|
|
|
this.timeout(180000)
|
2017-03-21 13:53:17 +00:00
|
|
|
|
2017-04-19 16:48:32 +00:00
|
|
|
stopServer = startServer({
|
2017-03-21 13:53:17 +00:00
|
|
|
callback (port) {
|
2018-09-13 16:10:51 +00:00
|
|
|
w.loadFile(path.join(fixtures, 'api', 'crash.html'), { query: { port } })
|
2017-03-21 13:53:17 +00:00
|
|
|
},
|
|
|
|
processType: 'renderer',
|
|
|
|
done: done
|
2016-08-09 22:41:46 +00:00
|
|
|
})
|
2017-03-21 13:53:17 +00:00
|
|
|
})
|
2017-11-10 08:39:16 +00:00
|
|
|
|
2018-06-18 09:00:59 +00:00
|
|
|
it('should send minidump when node processes crash', function (done) {
|
2017-11-25 11:55:35 +00:00
|
|
|
this.timeout(180000)
|
2017-03-21 13:53:17 +00:00
|
|
|
|
2017-04-19 16:48:32 +00:00
|
|
|
stopServer = startServer({
|
2017-03-21 13:53:17 +00:00
|
|
|
callback (port) {
|
2019-06-13 06:42:21 +00:00
|
|
|
const crashesDir = path.join(app.getPath('temp'), `${app.name} Crashes`)
|
2017-03-21 13:53:17 +00:00
|
|
|
const version = app.getVersion()
|
|
|
|
const crashPath = path.join(fixtures, 'module', 'crash.js')
|
2017-04-19 23:32:43 +00:00
|
|
|
|
2018-09-13 16:10:51 +00:00
|
|
|
childProcess.fork(crashPath, [port, version, crashesDir], { silent: true })
|
2017-03-21 13:53:17 +00:00
|
|
|
},
|
2019-06-13 06:42:21 +00:00
|
|
|
processType: 'node',
|
2017-03-21 13:53:17 +00:00
|
|
|
done: done
|
|
|
|
})
|
|
|
|
})
|
2017-11-10 08:39:16 +00:00
|
|
|
|
2017-11-25 11:55:35 +00:00
|
|
|
it('should not send minidump if uploadToServer is false', function (done) {
|
|
|
|
this.timeout(180000)
|
2017-03-30 14:11:49 +00:00
|
|
|
|
2017-04-05 20:42:24 +00:00
|
|
|
let dumpFile
|
|
|
|
let crashesDir = crashReporter.getCrashesDirectory()
|
|
|
|
const existingDumpFiles = new Set()
|
2019-06-13 06:42:21 +00:00
|
|
|
if (process.platform !== 'linux') {
|
2017-04-05 20:42:24 +00:00
|
|
|
// crashpad puts the dump files in the "completed" subdirectory
|
2019-06-13 06:42:21 +00:00
|
|
|
if (process.platform === 'darwin') {
|
|
|
|
crashesDir = path.join(crashesDir, 'completed')
|
|
|
|
} else {
|
|
|
|
crashesDir = path.join(crashesDir, 'reports')
|
|
|
|
}
|
2017-03-30 14:11:49 +00:00
|
|
|
crashReporter.setUploadToServer(false)
|
|
|
|
}
|
|
|
|
const testDone = (uploaded) => {
|
2017-10-27 00:21:36 +00:00
|
|
|
if (uploaded) return done(new Error('Uploaded crash report'))
|
2019-06-13 06:42:21 +00:00
|
|
|
if (process.platform !== 'linux') crashReporter.setUploadToServer(true)
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(fs.existsSync(dumpFile)).to.be.true()
|
2017-03-30 14:11:49 +00:00
|
|
|
done()
|
|
|
|
}
|
|
|
|
|
|
|
|
let pollInterval
|
|
|
|
const pollDumpFile = () => {
|
|
|
|
fs.readdir(crashesDir, (err, files) => {
|
2017-10-27 00:21:36 +00:00
|
|
|
if (err) return
|
2017-04-05 20:42:24 +00:00
|
|
|
const dumps = files.filter((file) => /\.dmp$/.test(file) && !existingDumpFiles.has(file))
|
2017-10-27 00:21:36 +00:00
|
|
|
if (!dumps.length) return
|
|
|
|
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(dumps).to.have.lengthOf(1)
|
2017-03-30 14:11:49 +00:00
|
|
|
dumpFile = path.join(crashesDir, dumps[0])
|
|
|
|
clearInterval(pollInterval)
|
|
|
|
// dump file should not be deleted when not uploading, so we wait
|
2017-04-05 20:42:24 +00:00
|
|
|
// 1s and assert it still exists in `testDone`
|
|
|
|
setTimeout(testDone, 1000)
|
2017-03-30 14:11:49 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-04-05 20:42:24 +00:00
|
|
|
remote.ipcMain.once('list-existing-dumps', (event) => {
|
2017-03-30 14:11:49 +00:00
|
|
|
fs.readdir(crashesDir, (err, files) => {
|
|
|
|
if (!err) {
|
2017-03-31 17:42:43 +00:00
|
|
|
for (const file of files) {
|
2017-03-30 14:11:49 +00:00
|
|
|
if (/\.dmp$/.test(file)) {
|
2017-04-05 20:42:24 +00:00
|
|
|
existingDumpFiles.add(file)
|
2017-03-30 14:11:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-13 16:10:51 +00:00
|
|
|
event.returnValue = null // allow the renderer to crash
|
2017-03-30 14:11:49 +00:00
|
|
|
pollInterval = setInterval(pollDumpFile, 100)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-04-19 16:48:32 +00:00
|
|
|
stopServer = startServer({
|
2017-03-30 14:11:49 +00:00
|
|
|
callback (port) {
|
|
|
|
const crashUrl = url.format({
|
|
|
|
protocol: 'file',
|
|
|
|
pathname: path.join(fixtures, 'api', 'crash.html'),
|
|
|
|
search: `?port=${port}&skipUpload=1`
|
|
|
|
})
|
|
|
|
w.loadURL(crashUrl)
|
|
|
|
},
|
|
|
|
processType: 'renderer',
|
|
|
|
done: testDone.bind(null, true)
|
|
|
|
})
|
|
|
|
})
|
2017-11-10 08:39:16 +00:00
|
|
|
|
2017-11-25 11:55:35 +00:00
|
|
|
it('should send minidump with updated extra parameters', function (done) {
|
|
|
|
this.timeout(180000)
|
2017-03-21 13:53:17 +00:00
|
|
|
|
2017-04-19 16:48:32 +00:00
|
|
|
stopServer = startServer({
|
2017-03-21 13:53:17 +00:00
|
|
|
callback (port) {
|
|
|
|
const crashUrl = url.format({
|
|
|
|
protocol: 'file',
|
|
|
|
pathname: path.join(fixtures, 'api', 'crash-restart.html'),
|
2017-10-31 22:19:04 +00:00
|
|
|
search: `?port=${port}`
|
2017-03-21 13:53:17 +00:00
|
|
|
})
|
|
|
|
w.loadURL(crashUrl)
|
|
|
|
},
|
|
|
|
processType: 'renderer',
|
2017-11-02 11:07:19 +00:00
|
|
|
done: done
|
2017-02-13 18:46:19 +00:00
|
|
|
})
|
2017-03-21 13:53:17 +00:00
|
|
|
})
|
2017-02-13 18:46:19 +00:00
|
|
|
})
|
2017-03-21 13:48:36 +00:00
|
|
|
}
|
|
|
|
|
2019-01-07 19:19:27 +00:00
|
|
|
generateSpecs('without sandbox', {
|
|
|
|
webPreferences: {
|
|
|
|
nodeIntegration: true
|
|
|
|
}
|
|
|
|
})
|
2017-04-19 16:28:52 +00:00
|
|
|
generateSpecs('with sandbox', {
|
2017-03-21 13:48:36 +00:00
|
|
|
webPreferences: {
|
|
|
|
sandbox: true,
|
|
|
|
preload: path.join(fixtures, 'module', 'preload-sandbox.js')
|
|
|
|
}
|
|
|
|
})
|
2018-10-13 17:50:07 +00:00
|
|
|
generateSpecs('with remote module disabled', {
|
|
|
|
webPreferences: {
|
2019-01-07 19:19:27 +00:00
|
|
|
nodeIntegration: true,
|
2018-10-13 17:50:07 +00:00
|
|
|
enableRemoteModule: false
|
|
|
|
}
|
|
|
|
})
|
2017-02-13 18:46:19 +00:00
|
|
|
|
2017-10-31 02:51:22 +00:00
|
|
|
describe('getProductName', () => {
|
|
|
|
it('returns the product name if one is specified', () => {
|
|
|
|
const name = crashReporter.getProductName()
|
2019-06-13 06:42:21 +00:00
|
|
|
const expectedName = 'Electron Test'
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(name).to.equal(expectedName)
|
2017-10-31 02:51:22 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('start(options)', () => {
|
2017-10-27 00:21:36 +00:00
|
|
|
it('requires that the companyName and submitURL options be specified', () => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(() => {
|
2018-09-13 16:10:51 +00:00
|
|
|
crashReporter.start({ companyName: 'Missing submitURL' })
|
2019-05-20 17:04:18 +00:00
|
|
|
}).to.throw('submitURL is a required option to crashReporter.start')
|
|
|
|
expect(() => {
|
2018-09-13 16:10:51 +00:00
|
|
|
crashReporter.start({ submitURL: 'Missing companyName' })
|
2019-05-20 17:04:18 +00:00
|
|
|
}).to.throw('companyName is a required option to crashReporter.start')
|
2016-03-25 20:03:49 +00:00
|
|
|
})
|
2017-10-27 00:21:36 +00:00
|
|
|
it('can be called multiple times', () => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(() => {
|
2016-07-26 17:43:57 +00:00
|
|
|
crashReporter.start({
|
|
|
|
companyName: 'Umbrella Corporation',
|
|
|
|
submitURL: 'http://127.0.0.1/crashes'
|
|
|
|
})
|
|
|
|
|
|
|
|
crashReporter.start({
|
|
|
|
companyName: 'Umbrella Corporation 2',
|
|
|
|
submitURL: 'http://127.0.0.1/more-crashes'
|
|
|
|
})
|
2019-05-20 17:04:18 +00:00
|
|
|
}).to.not.throw()
|
2016-07-26 17:43:57 +00:00
|
|
|
})
|
2016-03-25 20:03:49 +00:00
|
|
|
})
|
2017-10-31 03:15:57 +00:00
|
|
|
|
2017-10-31 02:51:22 +00:00
|
|
|
describe('getCrashesDirectory', () => {
|
|
|
|
it('correctly returns the directory', () => {
|
|
|
|
const crashesDir = crashReporter.getCrashesDirectory()
|
2019-06-13 06:42:21 +00:00
|
|
|
const dir = path.join(app.getPath('temp'), 'Electron Test Crashes')
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(crashesDir).to.equal(dir)
|
2017-10-31 02:51:22 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('getUploadedReports', () => {
|
|
|
|
it('returns an array of reports', () => {
|
|
|
|
const reports = crashReporter.getUploadedReports()
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(reports).to.be.an('array')
|
2017-10-31 02:51:22 +00:00
|
|
|
})
|
|
|
|
})
|
2016-11-28 23:01:38 +00:00
|
|
|
|
2018-06-14 09:24:28 +00:00
|
|
|
// TODO(alexeykuzmin): This suite should explicitly
|
|
|
|
// generate several crash reports instead of hoping
|
|
|
|
// that there will be enough of them already.
|
2017-10-31 02:51:22 +00:00
|
|
|
describe('getLastCrashReport', () => {
|
|
|
|
it('correctly returns the most recent report', () => {
|
2017-11-30 20:39:32 +00:00
|
|
|
const reports = crashReporter.getUploadedReports()
|
2018-06-14 09:24:28 +00:00
|
|
|
expect(reports).to.be.an('array')
|
|
|
|
expect(reports).to.have.lengthOf.at.least(2,
|
2018-09-13 16:10:51 +00:00
|
|
|
'There are not enough reports for this test')
|
2018-06-14 09:24:28 +00:00
|
|
|
|
2018-03-13 23:51:20 +00:00
|
|
|
const lastReport = crashReporter.getLastCrashReport()
|
2018-06-14 09:24:28 +00:00
|
|
|
expect(lastReport).to.be.an('object').that.includes.a.key('date')
|
2018-03-13 23:51:20 +00:00
|
|
|
|
2018-06-14 09:24:28 +00:00
|
|
|
// Let's find the newest report.
|
2018-09-13 16:10:51 +00:00
|
|
|
const { report: newestReport } = reports.reduce((acc, cur) => {
|
2018-03-14 00:40:41 +00:00
|
|
|
const timestamp = new Date(cur.date).getTime()
|
2018-03-14 00:28:15 +00:00
|
|
|
return (timestamp > acc.timestamp)
|
|
|
|
? { report: cur, timestamp: timestamp }
|
|
|
|
: acc
|
2018-06-14 09:24:28 +00:00
|
|
|
}, { timestamp: -Infinity })
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(newestReport).to.be.an('object')
|
2018-03-14 00:28:15 +00:00
|
|
|
|
2018-06-14 09:24:28 +00:00
|
|
|
expect(lastReport.date.getTime()).to.be.equal(
|
2018-09-13 16:10:51 +00:00
|
|
|
newestReport.date.getTime(),
|
|
|
|
'Last report is not the newest.')
|
2017-10-31 02:51:22 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('getUploadToServer()', () => {
|
2017-10-27 00:21:36 +00:00
|
|
|
it('throws an error when called from the renderer process', () => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(() => require('electron').crashReporter.getUploadToServer()).to.throw()
|
2016-11-28 23:01:38 +00:00
|
|
|
})
|
2017-11-15 21:05:46 +00:00
|
|
|
it('returns true when uploadToServer is set to true', function () {
|
2019-06-13 06:42:21 +00:00
|
|
|
if (process.platform === 'linux') {
|
2017-11-15 21:05:46 +00:00
|
|
|
// FIXME(alexeykuzmin): Skip the test.
|
|
|
|
// this.skip()
|
|
|
|
return
|
2017-10-31 02:51:22 +00:00
|
|
|
}
|
2017-11-15 21:05:46 +00:00
|
|
|
|
|
|
|
crashReporter.start({
|
|
|
|
companyName: 'Umbrella Corporation',
|
|
|
|
submitURL: 'http://127.0.0.1/crashes',
|
|
|
|
uploadToServer: true
|
|
|
|
})
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(crashReporter.getUploadToServer()).to.be.true()
|
2017-10-31 02:51:22 +00:00
|
|
|
})
|
2017-11-15 21:05:46 +00:00
|
|
|
it('returns false when uploadToServer is set to false', function () {
|
2019-06-13 06:42:21 +00:00
|
|
|
if (process.platform === 'linux') {
|
2017-11-15 21:05:46 +00:00
|
|
|
// FIXME(alexeykuzmin): Skip the test.
|
|
|
|
// this.skip()
|
|
|
|
return
|
2017-10-31 02:51:22 +00:00
|
|
|
}
|
2017-11-15 21:05:46 +00:00
|
|
|
|
|
|
|
crashReporter.start({
|
|
|
|
companyName: 'Umbrella Corporation',
|
|
|
|
submitURL: 'http://127.0.0.1/crashes',
|
|
|
|
uploadToServer: true
|
|
|
|
})
|
|
|
|
crashReporter.setUploadToServer(false)
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(crashReporter.getUploadToServer()).to.be.false()
|
2017-10-31 02:51:22 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('setUploadToServer(uploadToServer)', () => {
|
|
|
|
it('throws an error when called from the renderer process', () => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(() => require('electron').crashReporter.setUploadToServer('arg')).to.throw()
|
2017-10-31 02:51:22 +00:00
|
|
|
})
|
2017-11-15 21:05:46 +00:00
|
|
|
it('sets uploadToServer false when called with false', function () {
|
2019-06-13 06:42:21 +00:00
|
|
|
if (process.platform === 'linux') {
|
2017-11-15 21:05:46 +00:00
|
|
|
// FIXME(alexeykuzmin): Skip the test.
|
|
|
|
// this.skip()
|
|
|
|
return
|
2017-10-31 02:51:22 +00:00
|
|
|
}
|
2017-11-15 21:05:46 +00:00
|
|
|
|
|
|
|
crashReporter.start({
|
|
|
|
companyName: 'Umbrella Corporation',
|
|
|
|
submitURL: 'http://127.0.0.1/crashes',
|
|
|
|
uploadToServer: true
|
|
|
|
})
|
|
|
|
crashReporter.setUploadToServer(false)
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(crashReporter.getUploadToServer()).to.be.false()
|
2017-10-31 02:51:22 +00:00
|
|
|
})
|
2017-11-15 21:05:46 +00:00
|
|
|
it('sets uploadToServer true when called with true', function () {
|
2019-06-13 06:42:21 +00:00
|
|
|
if (process.platform === 'linux') {
|
2017-11-15 21:05:46 +00:00
|
|
|
// FIXME(alexeykuzmin): Skip the test.
|
|
|
|
// this.skip()
|
|
|
|
return
|
2016-11-28 23:01:38 +00:00
|
|
|
}
|
2017-11-15 21:05:46 +00:00
|
|
|
|
|
|
|
crashReporter.start({
|
|
|
|
companyName: 'Umbrella Corporation',
|
|
|
|
submitURL: 'http://127.0.0.1/crashes',
|
|
|
|
uploadToServer: false
|
|
|
|
})
|
|
|
|
crashReporter.setUploadToServer(true)
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(crashReporter.getUploadToServer()).to.be.true()
|
2016-11-28 23:01:38 +00:00
|
|
|
})
|
|
|
|
})
|
2017-10-31 02:51:22 +00:00
|
|
|
|
2017-10-31 22:19:04 +00:00
|
|
|
describe('Parameters', () => {
|
2017-10-31 14:38:48 +00:00
|
|
|
it('returns all of the current parameters', () => {
|
2017-10-31 17:51:44 +00:00
|
|
|
crashReporter.start({
|
|
|
|
companyName: 'Umbrella Corporation',
|
|
|
|
submitURL: 'http://127.0.0.1/crashes'
|
|
|
|
})
|
|
|
|
|
2017-10-31 14:38:48 +00:00
|
|
|
const parameters = crashReporter.getParameters()
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(parameters).to.be.an('object')
|
2017-10-31 14:38:48 +00:00
|
|
|
})
|
2017-11-15 21:05:46 +00:00
|
|
|
it('adds a parameter to current parameters', function () {
|
2019-06-13 06:42:21 +00:00
|
|
|
if (process.platform === 'linux') {
|
2017-11-15 21:05:46 +00:00
|
|
|
// FIXME(alexeykuzmin): Skip the test.
|
|
|
|
// this.skip()
|
|
|
|
return
|
|
|
|
}
|
2017-11-02 01:57:43 +00:00
|
|
|
|
|
|
|
crashReporter.start({
|
|
|
|
companyName: 'Umbrella Corporation',
|
|
|
|
submitURL: 'http://127.0.0.1/crashes'
|
|
|
|
})
|
|
|
|
|
|
|
|
crashReporter.addExtraParameter('hello', 'world')
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(crashReporter.getParameters()).to.have.a.property('hello')
|
2017-11-02 01:57:43 +00:00
|
|
|
})
|
2017-11-15 21:05:46 +00:00
|
|
|
it('removes a parameter from current parameters', function () {
|
2019-06-13 06:42:21 +00:00
|
|
|
if (process.platform === 'linux') {
|
2017-11-15 21:05:46 +00:00
|
|
|
// FIXME(alexeykuzmin): Skip the test.
|
|
|
|
// this.skip()
|
|
|
|
return
|
|
|
|
}
|
2017-10-31 14:38:48 +00:00
|
|
|
|
2017-10-31 17:51:44 +00:00
|
|
|
crashReporter.start({
|
|
|
|
companyName: 'Umbrella Corporation',
|
|
|
|
submitURL: 'http://127.0.0.1/crashes'
|
|
|
|
})
|
|
|
|
|
2017-11-02 05:02:16 +00:00
|
|
|
crashReporter.addExtraParameter('hello', 'world')
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(crashReporter.getParameters()).to.have.a.property('hello')
|
2017-10-31 14:38:48 +00:00
|
|
|
|
|
|
|
crashReporter.removeExtraParameter('hello')
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(crashReporter.getParameters()).to.not.have.a.property('hello')
|
2017-10-31 14:38:48 +00:00
|
|
|
})
|
2017-10-31 02:51:22 +00:00
|
|
|
})
|
2016-03-25 20:03:49 +00:00
|
|
|
})
|
2016-10-06 16:45:58 +00:00
|
|
|
|
|
|
|
const waitForCrashReport = () => {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
let times = 0
|
|
|
|
const checkForReport = () => {
|
|
|
|
if (crashReporter.getLastCrashReport() != null) {
|
|
|
|
resolve()
|
|
|
|
} else if (times >= 10) {
|
|
|
|
reject(new Error('No crash report available'))
|
|
|
|
} else {
|
|
|
|
times++
|
|
|
|
setTimeout(checkForReport, 100)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
checkForReport()
|
|
|
|
})
|
|
|
|
}
|
2017-01-24 21:49:45 +00:00
|
|
|
|
2018-09-13 16:10:51 +00:00
|
|
|
const startServer = ({ callback, processType, done }) => {
|
2017-10-27 00:21:36 +00:00
|
|
|
let called = false
|
2018-10-02 01:56:31 +00:00
|
|
|
const server = http.createServer((req, res) => {
|
2017-10-27 00:21:36 +00:00
|
|
|
const form = new multiparty.Form()
|
2017-01-24 21:49:45 +00:00
|
|
|
form.parse(req, (error, fields) => {
|
|
|
|
if (error) throw error
|
|
|
|
if (called) return
|
|
|
|
called = true
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(String(fields.prod)).to.equal('Electron')
|
|
|
|
expect(String(fields.ver)).to.equal(process.versions.electron)
|
|
|
|
expect(String(fields.process_type)).to.equal(processType)
|
|
|
|
expect(String(fields.platform)).to.equal(process.platform)
|
|
|
|
expect(String(fields.extra1)).to.equal('extra1')
|
|
|
|
expect(String(fields.extra2)).to.equal('extra2')
|
|
|
|
expect(fields.extra3).to.be.undefined()
|
|
|
|
expect(String(fields._productName)).to.equal('Zombies')
|
|
|
|
expect(String(fields._companyName)).to.equal('Umbrella Corporation')
|
|
|
|
expect(String(fields._version)).to.equal(app.getVersion())
|
2017-01-24 21:49:45 +00:00
|
|
|
|
|
|
|
const reportId = 'abc-123-def-456-abc-789-abc-123-abcd'
|
|
|
|
res.end(reportId, () => {
|
|
|
|
waitForCrashReport().then(() => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(crashReporter.getLastCrashReport().id).to.equal(reportId)
|
|
|
|
expect(crashReporter.getUploadedReports()).to.be.an('array').that.is.not.empty()
|
|
|
|
expect(crashReporter.getUploadedReports()[0].id).to.equal(reportId)
|
2017-02-13 18:46:19 +00:00
|
|
|
req.socket.destroy()
|
2017-01-24 21:49:45 +00:00
|
|
|
done()
|
|
|
|
}, done)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2017-04-19 16:48:32 +00:00
|
|
|
|
|
|
|
const activeConnections = new Set()
|
|
|
|
server.on('connection', (connection) => {
|
|
|
|
activeConnections.add(connection)
|
|
|
|
connection.once('close', () => {
|
|
|
|
activeConnections.delete(connection)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-09-13 16:10:51 +00:00
|
|
|
let { port } = remote.process
|
2017-01-24 21:49:45 +00:00
|
|
|
server.listen(port, '127.0.0.1', () => {
|
|
|
|
port = server.address().port
|
|
|
|
remote.process.port = port
|
2019-06-13 06:42:21 +00:00
|
|
|
if (process.platform !== 'linux') {
|
2017-01-24 21:49:45 +00:00
|
|
|
crashReporter.start({
|
|
|
|
companyName: 'Umbrella Corporation',
|
|
|
|
submitURL: 'http://127.0.0.1:' + port
|
|
|
|
})
|
|
|
|
}
|
|
|
|
callback(port)
|
|
|
|
})
|
2017-04-19 16:48:32 +00:00
|
|
|
|
|
|
|
return function stopServer (done) {
|
|
|
|
for (const connection of activeConnections) {
|
|
|
|
connection.destroy()
|
|
|
|
}
|
2017-10-27 00:21:36 +00:00
|
|
|
server.close(() => {
|
2017-04-19 16:48:32 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
}
|
2017-01-24 21:49:45 +00:00
|
|
|
}
|