Add spec for denying perm requests when handler is cleared

This commit is contained in:
Kevin Sawicki 2016-12-19 15:25:56 -08:00 committed by Birunthan Mohanathas
parent 18675cc6c1
commit 2f5acfedcd

View file

@ -13,6 +13,7 @@ const {ipcMain, session, BrowserWindow, net} = remote
describe('session module', function () {
var fixtures = path.resolve(__dirname, 'fixtures')
var w = null
var webview = null
var url = 'http://127.0.0.1'
beforeEach(function () {
@ -24,6 +25,11 @@ describe('session module', function () {
})
afterEach(function () {
if (!document.body.contains(webview)) {
document.body.appendChild(webview)
}
webview.remove()
return closeWindow(w).then(function () { w = null })
})
@ -325,7 +331,7 @@ describe('session module', function () {
downloadServer.listen(0, '127.0.0.1', function () {
var port = downloadServer.address().port
ipcRenderer.sendSync('set-download-option', false, false)
var webview = new WebView()
webview = new WebView()
webview.src = 'file://' + fixtures + '/api/blank.html'
webview.addEventListener('did-finish-load', function () {
webview.downloadURL(url + ':' + port + '/')
@ -718,4 +724,24 @@ describe('session module', function () {
})
})
})
describe('ses.setPermissionRequestHandler(handler)', () => {
it('cancels any pending requests when cleared', (done) => {
const ses = session.fromPartition('permissionTest')
ses.setPermissionRequestHandler(() => {
ses.setPermissionRequestHandler(null)
})
webview = new WebView()
webview.addEventListener('ipc-message', function (e) {
assert.equal(e.channel, 'message')
assert.deepEqual(e.args, ['SecurityError'])
done()
})
webview.src = 'file://' + fixtures + '/pages/permissions/midi-sysex.html'
webview.partition = 'permissionTest'
webview.setAttribute('nodeintegration', 'on')
document.body.appendChild(webview)
})
})
})