update spec

This commit is contained in:
deepak1556 2017-03-01 00:21:37 +05:30
parent dead1ae1ba
commit eb827eb020
2 changed files with 31 additions and 15 deletions

View file

@ -230,21 +230,8 @@ describe('BrowserWindow module', function () {
})
it('should not crash when there is a pending navigation entry', function (done) {
const source = `
<script>
setInterval(function () {
window.location = 'http://host'
}, 1000)
</script>
`
w.webContents.on('did-fail-load', function (event, code, desc, url, isMainFrame) {
assert.equal(url, 'http://host/')
w.webContents.loadURL('about:blank')
})
w.webContents.on('did-navigate', function (event, url) {
if (url === 'about:blank') done()
})
w.loadURL(`data:text/html,${source}`)
ipcRenderer.once('navigated-with-pending-entry', () => done())
ipcRenderer.send('navigate-with-pending-entry', w.id)
})
describe('POST navigations', function () {

View file

@ -304,6 +304,35 @@ ipcMain.on('handle-unhandled-rejection', (event, message) => {
})
})
ipcMain.on('navigate-with-pending-entry', (event, id) => {
const w = BrowserWindow.fromId(id)
const source = `
<body>
<a href='http://host'>Link</a>
</body>
<script>
setInterval(function () {
document.getElementsByTagName('a')[0].click();
}, 100)
</script>
`
w.webContents.on('did-fail-load', () => {
w.loadURL('about:blank')
})
w.webContents.on('did-navigate', (e, url) => {
if (url === 'about:blank') {
event.sender.send('navigated-with-pending-entry')
}
})
w.webContents.session.clearHostResolverCache(() => {
w.loadURL(`data:text/html,${source}`)
})
})
// Suspend listeners until the next event and then restore them
const suspendListeners = (emitter, eventName, callback) => {
const listeners = emitter.listeners(eventName)