Skip to content

Commit eb827eb

Browse files
committed
update spec
1 parent dead1ae commit eb827eb

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

spec/api-browser-window-spec.js

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -230,21 +230,8 @@ describe('BrowserWindow module', function () {
230230
})
231231

232232
it('should not crash when there is a pending navigation entry', function (done) {
233-
const source = `
234-
<script>
235-
setInterval(function () {
236-
window.location = 'http://host'
237-
}, 1000)
238-
</script>
239-
`
240-
w.webContents.on('did-fail-load', function (event, code, desc, url, isMainFrame) {
241-
assert.equal(url, 'http://host/')
242-
w.webContents.loadURL('about:blank')
243-
})
244-
w.webContents.on('did-navigate', function (event, url) {
245-
if (url === 'about:blank') done()
246-
})
247-
w.loadURL(`data:text/html,${source}`)
233+
ipcRenderer.once('navigated-with-pending-entry', () => done())
234+
ipcRenderer.send('navigate-with-pending-entry', w.id)
248235
})
249236

250237
describe('POST navigations', function () {

spec/static/main.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,35 @@ ipcMain.on('handle-unhandled-rejection', (event, message) => {
304304
})
305305
})
306306

307+
ipcMain.on('navigate-with-pending-entry', (event, id) => {
308+
const w = BrowserWindow.fromId(id)
309+
310+
const source = `
311+
<body>
312+
<a href='http://host'>Link</a>
313+
</body>
314+
<script>
315+
setInterval(function () {
316+
document.getElementsByTagName('a')[0].click();
317+
}, 100)
318+
</script>
319+
`
320+
321+
w.webContents.on('did-fail-load', () => {
322+
w.loadURL('about:blank')
323+
})
324+
325+
w.webContents.on('did-navigate', (e, url) => {
326+
if (url === 'about:blank') {
327+
event.sender.send('navigated-with-pending-entry')
328+
}
329+
})
330+
331+
w.webContents.session.clearHostResolverCache(() => {
332+
w.loadURL(`data:text/html,${source}`)
333+
})
334+
})
335+
307336
// Suspend listeners until the next event and then restore them
308337
const suspendListeners = (emitter, eventName, callback) => {
309338
const listeners = emitter.listeners(eventName)

0 commit comments

Comments
 (0)