|
@@ -3,7 +3,7 @@ const http = require('http')
|
|
|
const path = require('path')
|
|
|
const ws = require('ws')
|
|
|
const url = require('url')
|
|
|
-const {ipcRenderer, remote} = require('electron')
|
|
|
+const {ipcRenderer, remote, webFrame} = require('electron')
|
|
|
const {closeWindow} = require('./window-helpers')
|
|
|
|
|
|
const {app, BrowserWindow, ipcMain, protocol, session, webContents} = remote
|
|
@@ -802,4 +802,50 @@ describe('chromium feature', function () {
|
|
|
})
|
|
|
})
|
|
|
})
|
|
|
+
|
|
|
+ describe('PDF Viewer', function () {
|
|
|
+ let w = null
|
|
|
+ const pdfSource = `file://${fixtures}/assets/pdf.pdf`
|
|
|
+
|
|
|
+ beforeEach(function () {
|
|
|
+ w = new BrowserWindow({
|
|
|
+ show: false
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ afterEach(function () {
|
|
|
+ return closeWindow(w).then(function () { w = null })
|
|
|
+ })
|
|
|
+
|
|
|
+ it('opens when loading a pdf resource as top level navigation', function (done) {
|
|
|
+ w.webContents.on('did-finish-load', function () {
|
|
|
+ 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(!!parsedURL.query.streamId.length)
|
|
|
+ })
|
|
|
+ w.webContents.on('page-title-updated', function () {
|
|
|
+ assert.equal(w.webContents.getTitle(), 'PDF')
|
|
|
+ done()
|
|
|
+ })
|
|
|
+ w.webContents.loadURL(pdfSource)
|
|
|
+ })
|
|
|
+
|
|
|
+ it('should not open when pdf is requested as sub resource', function (done) {
|
|
|
+ webFrame.registerURLSchemeAsPrivileged('file', {
|
|
|
+ secure: false,
|
|
|
+ bypassCSP: false,
|
|
|
+ allowServiceWorkers: false,
|
|
|
+ corsEnabled: false
|
|
|
+ })
|
|
|
+ fetch(pdfSource).then(function (res) {
|
|
|
+ assert.equal(res.status, 200)
|
|
|
+ assert.notEqual(document.title, 'PDF')
|
|
|
+ done()
|
|
|
+ }).catch(function (e) {
|
|
|
+ done(e)
|
|
|
+ })
|
|
|
+ })
|
|
|
+ })
|
|
|
})
|