Skip to content
Permalink
Browse files

test: add ut for webContents' render-view-deleted emission

  • Loading branch information...
ppontes committed Nov 30, 2018
1 parent 5626466 commit e7ba3702cfa3ba6d30e590fb6cf3bd2c772bb560
Showing with 256 additions and 193 deletions.
  1. +63 −0 spec/api-web-contents-spec.js
  2. +193 −193 spec/package-lock.json
@@ -712,6 +712,69 @@ describe('webContents module', () => {
})
})

describe('render-view-deleted', () => {
let server = null

before((done) => {
server = http.createServer((req, res) => {
const respond = () => {
if (req.url === '/redirect-cross-site') {
res.setHeader('Location', `${server.cross_site_url}/redirected`)
res.statusCode = 302
res.end()
} else if (req.url === '/redirected') {
res.end('<html><script>window.localStorage</script></html>')
} else {
res.end()
}
}
setTimeout(respond, 0)
})
server.listen(0, '127.0.0.1', () => {
server.url = `http://127.0.0.1:${server.address().port}`
server.cross_site_url = `http://localhost:${server.address().port}`
done()
})
})

after(() => {
server.close()
server = null
})

it('does not emit when speculative RVHs are deleted', (done) => {
let renderViewDeletedEmitted = false
w.webContents.once('destroyed', () => {
assert.strictEqual(renderViewDeletedEmitted, false, 'render-view-deleted was emitted')
done()
})
const renderViewDeletedHandler = () => {
renderViewDeletedEmitted = true
}
w.webContents.on('render-view-deleted', renderViewDeletedHandler)
w.webContents.on('did-finish-load', (e) => {
w.webContents.removeListener('render-view-deleted', renderViewDeletedHandler)
w.close()
})
w.loadURL(`${server.url}/redirect-cross-site`)
})

it('emits if the current RVHs are deleted', (done) => {
let renderViewDeletedEmitted = false
w.webContents.once('destroyed', () => {
assert.strictEqual(renderViewDeletedEmitted, true, 'render-view-deleted wasn\'t emitted')
done()
})
w.webContents.on('render-view-deleted', () => {
renderViewDeletedEmitted = true
})
w.webContents.on('did-finish-load', (e) => {
w.close()
})
w.loadURL(`${server.url}/redirect-cross-site`)
})
})

describe('setIgnoreMenuShortcuts(ignore)', () => {
it('does not throw', () => {
assert.strictEqual(w.webContents.setIgnoreMenuShortcuts(true), undefined)

0 comments on commit e7ba370

Please sign in to comment.
You can’t perform that action at this time.