Use pdf-loaded event in specs

This commit is contained in:
Kevin Sawicki 2017-06-28 12:57:05 -07:00
parent 1aa3217899
commit 9f0d2cd39d
2 changed files with 7 additions and 10 deletions

View file

@ -987,7 +987,7 @@ describe('chromium feature', function () {
w = new BrowserWindow({
show: false,
webPreferences: {
preload: path.join(fixtures, 'module', 'preload-inject-ipc.js'),
preload: path.join(fixtures, 'module', 'preload-pdf-loaded.js'),
plugins: plugins
}
})
@ -996,22 +996,14 @@ describe('chromium feature', function () {
it('opens when loading a pdf resource as top level navigation', function (done) {
createBrowserWindow({plugins: true})
ipcMain.once('pdf-loaded', function (event, success) {
if (success) done()
success ? done() : done(new Error(`Unexpected loading state: ${success}`))
})
w.webContents.on('page-title-updated', function () {
const source = `
if (window.viewer) {
window.viewer.setLoadCallback(function(success) {
window.ipcRenderer.send('pdf-loaded', success);
});
}
`
const parsedURL = url.parse(w.webContents.getURL(), true)
assert.equal(parsedURL.protocol, 'chrome:')
assert.equal(parsedURL.hostname, 'pdf-viewer')
assert.equal(parsedURL.query.src, pdfSource)
assert.equal(w.webContents.getTitle(), 'cat.pdf')
w.webContents.executeJavaScript(source)
})
w.webContents.loadURL(pdfSource)
})

View file

@ -0,0 +1,5 @@
const {ipcRenderer} = require('electron')
window.addEventListener('pdf-loaded', function (event) {
ipcRenderer.send('pdf-loaded', event.detail);
})