feat: add process.takeHeapSnapshot() / webContents.takeHeapSnapshot() (#14456)

This commit is contained in:
Milan Burda 2018-09-18 20:00:31 +02:00 committed by Shelley Vohr
parent 1855144d26
commit e22142ef9c
17 changed files with 262 additions and 5 deletions

View file

@ -1,6 +1,7 @@
'use strict'
const assert = require('assert')
const fs = require('fs')
const http = require('http')
const path = require('path')
const { closeWindow } = require('./window-helpers')
@ -799,4 +800,53 @@ describe('webContents module', () => {
w.loadURL('about:blank')
})
})
describe('takeHeapSnapshot()', () => {
it('works with sandboxed renderers', async () => {
w.destroy()
w = new BrowserWindow({
show: false,
webPreferences: {
sandbox: true
}
})
w.loadURL('about:blank')
await emittedOnce(w.webContents, 'did-finish-load')
const filePath = path.join(remote.app.getPath('temp'), 'test.heapsnapshot')
const cleanup = () => {
try {
fs.unlinkSync(filePath)
} catch (e) {
// ignore error
}
}
try {
await w.webContents.takeHeapSnapshot(filePath)
const stats = fs.statSync(filePath)
expect(stats.size).not.to.be.equal(0)
} finally {
cleanup()
}
})
it('fails with invalid file path', async () => {
w.destroy()
w = new BrowserWindow({
show: false,
webPreferences: {
sandbox: true
}
})
w.loadURL('about:blank')
await emittedOnce(w.webContents, 'did-finish-load')
const promise = w.webContents.takeHeapSnapshot('')
return expect(promise).to.be.eventually.rejectedWith(Error, 'takeHeapSnapshot failed')
})
})
})