Add initial isolated world spec
This commit is contained in:
parent
5da4f032c3
commit
2928fe5c43
3 changed files with 67 additions and 0 deletions
|
@ -1835,6 +1835,39 @@ describe('BrowserWindow module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('isolated option', () => {
|
||||||
|
it('separates the page context from the Electron/preload context', (done) => {
|
||||||
|
if (w != null) w.destroy()
|
||||||
|
|
||||||
|
ipcMain.once('isolated-world', (event, data) => {
|
||||||
|
assert.deepEqual(data, {
|
||||||
|
preloadContext: {
|
||||||
|
preloadProperty: 'number',
|
||||||
|
pageProperty: 'undefined',
|
||||||
|
typeofRequire: 'function',
|
||||||
|
typeofProcess: 'object'
|
||||||
|
},
|
||||||
|
pageContext: {
|
||||||
|
preloadProperty: 'undefined',
|
||||||
|
pageProperty: 'string',
|
||||||
|
typeofRequire: 'undefined',
|
||||||
|
typeofProcess: 'undefined'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
|
||||||
|
w = new BrowserWindow({
|
||||||
|
show: false,
|
||||||
|
webPreferences: {
|
||||||
|
isolated: true,
|
||||||
|
preload: path.join(fixtures, 'api', 'isolated-preload.js')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
w.loadURL('file://' + fixtures + '/api/isolated.html')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('offscreen rendering', function () {
|
describe('offscreen rendering', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
if (w != null) w.destroy()
|
if (w != null) w.destroy()
|
||||||
|
|
15
spec/fixtures/api/isolated-preload.js
vendored
Normal file
15
spec/fixtures/api/isolated-preload.js
vendored
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
const {ipcRenderer} = require('electron')
|
||||||
|
|
||||||
|
window.foo = 3
|
||||||
|
|
||||||
|
window.addEventListener('message', (event) => {
|
||||||
|
ipcRenderer.send('isolated-world', {
|
||||||
|
preloadContext: {
|
||||||
|
preloadProperty: typeof window.foo,
|
||||||
|
pageProperty: typeof window.hello,
|
||||||
|
typeofRequire: typeof require,
|
||||||
|
typeofProcess: typeof process
|
||||||
|
},
|
||||||
|
pageContext: event.data
|
||||||
|
})
|
||||||
|
})
|
19
spec/fixtures/api/isolated.html
vendored
Normal file
19
spec/fixtures/api/isolated.html
vendored
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Isolated World</title>
|
||||||
|
<script>
|
||||||
|
window.hello = 'world'
|
||||||
|
window.postMessage({
|
||||||
|
preloadProperty: typeof window.foo,
|
||||||
|
pageProperty: typeof window.hello,
|
||||||
|
typeofRequire: typeof require,
|
||||||
|
typeofProcess: typeof process
|
||||||
|
}, '*')
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Add table
Add a link
Reference in a new issue