From 80ce60f644df20e24ebc3f0dc4e6a02fb81fb904 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Sun, 12 Mar 2017 03:06:08 +0530 Subject: [PATCH] spec: check if pdf has loaded --- spec/chromium-spec.js | 21 ++++++++++++++++----- spec/fixtures/module/preload-inject-ipc.js | 2 ++ vendor/pdf_viewer | 2 +- 3 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 spec/fixtures/module/preload-inject-ipc.js diff --git a/spec/chromium-spec.js b/spec/chromium-spec.js index a0e31ac13a..d6dfe18509 100644 --- a/spec/chromium-spec.js +++ b/spec/chromium-spec.js @@ -813,7 +813,10 @@ describe('chromium feature', function () { beforeEach(function () { 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) { - 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) assert.equal(parsedURL.protocol, 'chrome:') assert.equal(parsedURL.hostname, 'pdf-viewer') assert.equal(parsedURL.query.src, pdfSource) - }) - w.webContents.on('page-title-updated', function () { assert.equal(w.webContents.getTitle(), 'cat.pdf') - done() + w.webContents.executeJavaScript(source) }) w.webContents.loadURL(pdfSource) }) diff --git a/spec/fixtures/module/preload-inject-ipc.js b/spec/fixtures/module/preload-inject-ipc.js new file mode 100644 index 0000000000..3475cd69a6 --- /dev/null +++ b/spec/fixtures/module/preload-inject-ipc.js @@ -0,0 +1,2 @@ +const {ipcRenderer} = require('electron') +window.ipcRenderer = ipcRenderer diff --git a/vendor/pdf_viewer b/vendor/pdf_viewer index 3bf66a6773..a050a339cf 160000 --- a/vendor/pdf_viewer +++ b/vendor/pdf_viewer @@ -1 +1 @@ -Subproject commit 3bf66a67738aa338b0622f36caacbb23235e0844 +Subproject commit a050a339cfeabcfb5f07c313161d2ee27b6c3a39