spec: check if pdf has loaded
This commit is contained in:
parent
6e02d18a40
commit
80ce60f644
3 changed files with 19 additions and 6 deletions
|
@ -813,7 +813,10 @@ describe('chromium feature', function () {
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
w = new BrowserWindow({
|
w = new BrowserWindow({
|
||||||
show: false
|
show: false,
|
||||||
|
webPreferences: {
|
||||||
|
preload: path.join(fixtures, 'module', 'preload-inject-ipc.js')
|
||||||
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -822,15 +825,23 @@ describe('chromium feature', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('opens when loading a pdf resource as top level navigation', function (done) {
|
it('opens when loading a pdf resource as top level navigation', function (done) {
|
||||||
w.webContents.on('did-finish-load', function () {
|
ipcMain.once('pdf-loaded', function (event, success) {
|
||||||
|
if (success) done()
|
||||||
|
})
|
||||||
|
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)
|
const parsedURL = url.parse(w.webContents.getURL(), true)
|
||||||
assert.equal(parsedURL.protocol, 'chrome:')
|
assert.equal(parsedURL.protocol, 'chrome:')
|
||||||
assert.equal(parsedURL.hostname, 'pdf-viewer')
|
assert.equal(parsedURL.hostname, 'pdf-viewer')
|
||||||
assert.equal(parsedURL.query.src, pdfSource)
|
assert.equal(parsedURL.query.src, pdfSource)
|
||||||
})
|
|
||||||
w.webContents.on('page-title-updated', function () {
|
|
||||||
assert.equal(w.webContents.getTitle(), 'cat.pdf')
|
assert.equal(w.webContents.getTitle(), 'cat.pdf')
|
||||||
done()
|
w.webContents.executeJavaScript(source)
|
||||||
})
|
})
|
||||||
w.webContents.loadURL(pdfSource)
|
w.webContents.loadURL(pdfSource)
|
||||||
})
|
})
|
||||||
|
|
2
spec/fixtures/module/preload-inject-ipc.js
vendored
Normal file
2
spec/fixtures/module/preload-inject-ipc.js
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
const {ipcRenderer} = require('electron')
|
||||||
|
window.ipcRenderer = ipcRenderer
|
2
vendor/pdf_viewer
vendored
2
vendor/pdf_viewer
vendored
|
@ -1 +1 @@
|
||||||
Subproject commit 3bf66a67738aa338b0622f36caacbb23235e0844
|
Subproject commit a050a339cfeabcfb5f07c313161d2ee27b6c3a39
|
Loading…
Reference in a new issue