Exposing process.env status (#12166)

This commit is contained in:
Hari Juturu 2018-03-13 20:01:40 -07:00 committed by Samuel Attard
parent 134872e9c1
commit 704af29543
4 changed files with 24 additions and 0 deletions

View file

@ -44,6 +44,7 @@ preloadProcess.getSystemMemoryInfo = () => binding.getSystemMemoryInfo()
preloadProcess.argv = binding.getArgv()
process.platform = preloadProcess.platform = electron.remote.process.platform
process.execPath = preloadProcess.execPath = electron.remote.process.execPath
process.env = preloadProcess.env = electron.remote.process.env
process.on('exit', () => preloadProcess.emit('exit'))
// This is the `require` function that will be visible to the preload script

View file

@ -1539,6 +1539,23 @@ describe('BrowserWindow module', () => {
done()
})
})
it('validate process.env access in sandbox renderer', (done) => {
ipcMain.once('answer', function (event, test) {
assert.equal(test, 'foo')
done()
})
remote.process.env.sandboxmain = 'foo'
w.destroy()
w = new BrowserWindow({
show: false,
webPreferences: {
sandbox: true,
preload: preload
}
})
w.loadURL('file://' + path.join(fixtures, 'api', 'preload.html'))
})
})
describe('nativeWindowOpen option', () => {

View file

@ -7,6 +7,9 @@
if (location.protocol === 'file:') {
window.test = 'preload'
window.process = process
if (process.env.sandboxmain) {
window.test = process.env.sandboxmain
}
} else if (location.href !== 'about:blank') {
addEventListener('DOMContentLoaded', () => {
ipcRenderer.send('child-loaded', window.opener == null, document.body.innerHTML)

View file

@ -38,6 +38,9 @@ process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = true
// eslint-disable-next-line
process.stdout
// Adding a variable for sandbox process.env test validation
process.env.sandboxmain = ''
// Access console to reproduce #3482.
// eslint-disable-next-line
console