Fix sandboxed crashReporter for windows.
- Use `path` module from browser process in sandboxed renderer. This is required because the return value of `path.join` is platform-specific, and this is an assumtion of crash-reporter.js which is shared between sandboxed and non-sandboxed renderers. - Set `process.platform` and `process.execPath` in sandboxed renderer environment. This is required to spawn the windows crash service from sandboxed renderer. - Use a single temporary directory for all crashReporter tests. This is required to make tests more deterministic across platforms(since mac's crashpad doesn't support changing the crash dump directory). Also make a few improvements/fixes to the `uploadToServer` test.
This commit is contained in:
parent
7574c33ef1
commit
ce1a5e3c9c
5 changed files with 33 additions and 36 deletions
|
@ -447,6 +447,8 @@
|
||||||
'-r',
|
'-r',
|
||||||
'./lib/sandboxed_renderer/api/exports/os.js:os',
|
'./lib/sandboxed_renderer/api/exports/os.js:os',
|
||||||
'-r',
|
'-r',
|
||||||
|
'./lib/sandboxed_renderer/api/exports/path.js:path',
|
||||||
|
'-r',
|
||||||
'./lib/sandboxed_renderer/api/exports/child_process.js:child_process'
|
'./lib/sandboxed_renderer/api/exports/child_process.js:child_process'
|
||||||
],
|
],
|
||||||
'isolated_args': [
|
'isolated_args': [
|
||||||
|
|
1
lib/sandboxed_renderer/api/exports/path.js
Normal file
1
lib/sandboxed_renderer/api/exports/path.js
Normal file
|
@ -0,0 +1 @@
|
||||||
|
module.exports = require('electron').remote.require('path')
|
|
@ -27,6 +27,7 @@ const preloadModules = new Map([
|
||||||
['electron', electron],
|
['electron', electron],
|
||||||
['fs', fs],
|
['fs', fs],
|
||||||
['os', require('os')],
|
['os', require('os')],
|
||||||
|
['path', require('path')],
|
||||||
['url', require('url')],
|
['url', require('url')],
|
||||||
['timers', require('timers')]
|
['timers', require('timers')]
|
||||||
])
|
])
|
||||||
|
@ -36,8 +37,9 @@ const preloadSrc = fs.readFileSync(preloadPath).toString()
|
||||||
// Pass different process object to the preload script(which should not have
|
// Pass different process object to the preload script(which should not have
|
||||||
// access to things like `process.atomBinding`).
|
// access to things like `process.atomBinding`).
|
||||||
const preloadProcess = new events.EventEmitter()
|
const preloadProcess = new events.EventEmitter()
|
||||||
preloadProcess.platform = electron.remote.process.platform
|
|
||||||
preloadProcess.crash = () => binding.crash()
|
preloadProcess.crash = () => binding.crash()
|
||||||
|
process.platform = preloadProcess.platform = electron.remote.process.platform
|
||||||
|
process.execPath = preloadProcess.execPath = electron.remote.process.execPath
|
||||||
process.on('exit', () => preloadProcess.emit('exit'))
|
process.on('exit', () => preloadProcess.emit('exit'))
|
||||||
|
|
||||||
// This is the `require` function that will be visible to the preload script
|
// This is the `require` function that will be visible to the preload script
|
||||||
|
|
|
@ -15,24 +15,32 @@ describe('crashReporter module', function () {
|
||||||
if (process.mas) {
|
if (process.mas) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var originalTempDirectory = null
|
||||||
|
var tempDirectory = null
|
||||||
|
|
||||||
|
before(function () {
|
||||||
|
tempDirectory = temp.mkdirSync('electronCrashReporterSpec-')
|
||||||
|
originalTempDirectory = app.getPath('temp')
|
||||||
|
app.setPath('temp', tempDirectory)
|
||||||
|
})
|
||||||
|
|
||||||
|
after(function () {
|
||||||
|
app.setPath('temp', originalTempDirectory)
|
||||||
|
})
|
||||||
|
|
||||||
var fixtures = path.resolve(__dirname, 'fixtures')
|
var fixtures = path.resolve(__dirname, 'fixtures')
|
||||||
const generateSpecs = (description, browserWindowOpts) => {
|
const generateSpecs = (description, browserWindowOpts) => {
|
||||||
describe(description, function () {
|
describe(description, function () {
|
||||||
var w = null
|
var w = null
|
||||||
var originalTempDirectory = null
|
|
||||||
var tempDirectory = null
|
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
w = new BrowserWindow(Object.assign({
|
w = new BrowserWindow(Object.assign({
|
||||||
show: false
|
show: false
|
||||||
}, browserWindowOpts))
|
}, browserWindowOpts))
|
||||||
tempDirectory = temp.mkdirSync('electronCrashReporterSpec-')
|
|
||||||
originalTempDirectory = app.getPath('temp')
|
|
||||||
app.setPath('temp', tempDirectory)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
app.setPath('temp', originalTempDirectory)
|
|
||||||
return closeWindow(w).then(function () { w = null })
|
return closeWindow(w).then(function () { w = null })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -77,13 +85,15 @@ describe('crashReporter module', function () {
|
||||||
it('should not send minidump if uploadToServer is false', function (done) {
|
it('should not send minidump if uploadToServer is false', function (done) {
|
||||||
this.timeout(120000)
|
this.timeout(120000)
|
||||||
|
|
||||||
if (process.platform === 'darwin') {
|
|
||||||
crashReporter.setUploadToServer(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
let server
|
let server
|
||||||
let dumpFile
|
let dumpFile
|
||||||
let crashesDir
|
let crashesDir = crashReporter.getCrashesDirectory()
|
||||||
|
const existingDumpFiles = new Set()
|
||||||
|
if (process.platform === 'darwin') {
|
||||||
|
// crashpad puts the dump files in the "completed" subdirectory
|
||||||
|
crashesDir = path.join(crashesDir, 'completed')
|
||||||
|
crashReporter.setUploadToServer(false)
|
||||||
|
}
|
||||||
const testDone = (uploaded) => {
|
const testDone = (uploaded) => {
|
||||||
if (uploaded) {
|
if (uploaded) {
|
||||||
return done(new Error('fail'))
|
return done(new Error('fail'))
|
||||||
|
@ -93,7 +103,6 @@ describe('crashReporter module', function () {
|
||||||
crashReporter.setUploadToServer(true)
|
crashReporter.setUploadToServer(true)
|
||||||
}
|
}
|
||||||
assert(fs.existsSync(dumpFile))
|
assert(fs.existsSync(dumpFile))
|
||||||
fs.unlinkSync(dumpFile)
|
|
||||||
done()
|
done()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,7 +112,7 @@ describe('crashReporter module', function () {
|
||||||
if (err) {
|
if (err) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const dumps = files.filter((file) => /\.dmp$/.test(file))
|
const dumps = files.filter((file) => /\.dmp$/.test(file) && !existingDumpFiles.has(file))
|
||||||
if (!dumps.length) {
|
if (!dumps.length) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -111,34 +120,17 @@ describe('crashReporter module', function () {
|
||||||
dumpFile = path.join(crashesDir, dumps[0])
|
dumpFile = path.join(crashesDir, dumps[0])
|
||||||
clearInterval(pollInterval)
|
clearInterval(pollInterval)
|
||||||
// dump file should not be deleted when not uploading, so we wait
|
// dump file should not be deleted when not uploading, so we wait
|
||||||
// 500 ms and assert it still exists in `testDone`
|
// 1s and assert it still exists in `testDone`
|
||||||
setTimeout(testDone, 500)
|
setTimeout(testDone, 1000)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
remote.ipcMain.once('set-crash-directory', (event, dir) => {
|
remote.ipcMain.once('list-existing-dumps', (event) => {
|
||||||
if (process.platform === 'linux') {
|
|
||||||
crashesDir = dir
|
|
||||||
} else {
|
|
||||||
crashesDir = crashReporter.getCrashesDirectory()
|
|
||||||
if (process.platform === 'darwin') {
|
|
||||||
// crashpad uses an extra subdirectory
|
|
||||||
crashesDir = path.join(crashesDir, 'completed')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Before starting, remove all dump files in the crash directory.
|
|
||||||
// This is required because:
|
|
||||||
// - mac crashpad not seem to allow changing the crash directory after
|
|
||||||
// the first "start" call.
|
|
||||||
// - Other tests in this suite may leave dumps there.
|
|
||||||
// - We want to verify in `testDone` that a dump file is created and
|
|
||||||
// not deleted.
|
|
||||||
fs.readdir(crashesDir, (err, files) => {
|
fs.readdir(crashesDir, (err, files) => {
|
||||||
if (!err) {
|
if (!err) {
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
if (/\.dmp$/.test(file)) {
|
if (/\.dmp$/.test(file)) {
|
||||||
fs.unlinkSync(path.join(crashesDir, file))
|
existingDumpFiles.add(file)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
2
spec/fixtures/api/crash.html
vendored
2
spec/fixtures/api/crash.html
vendored
|
@ -17,7 +17,7 @@ crashReporter.start({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!uploadToServer) {
|
if (!uploadToServer) {
|
||||||
ipcRenderer.sendSync('set-crash-directory', crashReporter.getCrashesDirectory())
|
ipcRenderer.sendSync('list-existing-dumps')
|
||||||
}
|
}
|
||||||
setImmediate(function() { process.crash(); });
|
setImmediate(function() { process.crash(); });
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in a new issue