spec: check if pdf has loaded
authordeepak1556 <hop2deep@gmail.com>
Sat, 11 Mar 2017 21:36:08 +0000 (03:06 +0530)
committerdeepak1556 <hop2deep@gmail.com>
Mon, 13 Mar 2017 18:56:27 +0000 (00:26 +0530)
spec/chromium-spec.js
spec/fixtures/module/preload-inject-ipc.js [new file with mode: 0644]
vendor/pdf_viewer

index a0e31ac..d6dfe18 100644 (file)
@@ -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 (file)
index 0000000..3475cd6
--- /dev/null
@@ -0,0 +1,2 @@
+const {ipcRenderer} = require('electron')
+window.ipcRenderer = ipcRenderer
index 3bf66a6..a050a33 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 3bf66a67738aa338b0622f36caacbb23235e0844
+Subproject commit a050a339cfeabcfb5f07c313161d2ee27b6c3a39