Add explicit spec for removing preload from webview

This commit is contained in:
Kevin Sawicki 2017-05-17 13:47:00 -07:00
parent 9e88d337ec
commit fd782706b2
4 changed files with 28 additions and 0 deletions

View file

@ -0,0 +1 @@
window.foo = 'bar'

View file

@ -0,0 +1,7 @@
<html>
<body>
<script type="text/javascript" charset="utf-8">
console.log(typeof window.foo);
</script>
</body>
</html>

View file

@ -277,6 +277,14 @@ ipcMain.on('disable-node-on-next-will-attach-webview', (event, id) => {
})
})
ipcMain.on('disable-preload-on-next-will-attach-webview', (event, id) => {
event.sender.once('will-attach-webview', (event, webPreferences, params) => {
params.src = `file://${path.join(__dirname, '..', 'fixtures', 'pages', 'webview-stripped-preload.html')}`
delete webPreferences.preload
delete webPreferences.preloadURL
})
})
ipcMain.on('try-emit-web-contents-event', (event, id, eventName) => {
const consoleWarn = console.warn
let warningMessage = null

View file

@ -1140,6 +1140,18 @@ describe('<webview> tag', function () {
webview.src = 'file://' + fixtures + '/pages/c.html'
document.body.appendChild(webview)
})
it('supports removing the preload script', (done) => {
ipcRenderer.send('disable-preload-on-next-will-attach-webview')
webview.addEventListener('console-message', (event) => {
assert.equal(event.message, 'undefined')
done()
})
webview.setAttribute('nodeintegration', 'yes')
webview.setAttribute('preload', path.join(fixtures, 'module', 'preload-set-global.js'))
webview.src = 'file://' + fixtures + '/pages/a.html'
document.body.appendChild(webview)
})
})
it('loads devtools extensions registered on the parent window', function (done) {