Delete mock.pdf after download completes

This commit is contained in:
Kevin Sawicki 2017-05-22 14:24:28 -07:00
parent 25015c4c63
commit 647e88da5a

View file

@ -1012,18 +1012,18 @@ describe('chromium feature', function () {
slashes: true slashes: true
}) })
function createBrowserWindow (isPluginsEnabled) { function createBrowserWindow ({plugins}) {
w = new BrowserWindow({ w = new BrowserWindow({
show: false, show: false,
webPreferences: { webPreferences: {
preload: path.join(fixtures, 'module', 'preload-inject-ipc.js'), preload: path.join(fixtures, 'module', 'preload-inject-ipc.js'),
plugins: isPluginsEnabled plugins: plugins
} }
}) })
} }
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) {
createBrowserWindow(true) createBrowserWindow({plugins: true})
ipcMain.once('pdf-loaded', function (event, success) { ipcMain.once('pdf-loaded', function (event, success) {
if (success) done() if (success) done()
}) })
@ -1046,19 +1046,20 @@ describe('chromium feature', function () {
}) })
it('should download a pdf when plugins are disabled', function (done) { it('should download a pdf when plugins are disabled', function (done) {
createBrowserWindow(false) createBrowserWindow({plugins: false})
ipcRenderer.sendSync('set-download-option', false, false) ipcRenderer.sendSync('set-download-option', false, false)
ipcRenderer.once('download-done', function (event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename) { ipcRenderer.once('download-done', function (event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename) {
assert.equal(state, 'completed') assert.equal(state, 'completed')
assert.equal(filename, 'cat.pdf') assert.equal(filename, 'cat.pdf')
assert.equal(mimeType, 'application/pdf') assert.equal(mimeType, 'application/pdf')
fs.unlinkSync(path.join(fixtures, 'mock.pdf'))
done() done()
}) })
w.webContents.loadURL(pdfSource) w.webContents.loadURL(pdfSource)
}) })
it('should not open when pdf is requested as sub resource', function (done) { it('should not open when pdf is requested as sub resource', function (done) {
createBrowserWindow(true) createBrowserWindow({plugins: true})
webFrame.registerURLSchemeAsPrivileged('file', { webFrame.registerURLSchemeAsPrivileged('file', {
secure: false, secure: false,
bypassCSP: false, bypassCSP: false,