|
@@ -1,4 +1,5 @@
|
|
|
const assert = require('assert')
|
|
|
+const chai = require('chai')
|
|
|
const http = require('http')
|
|
|
const https = require('https')
|
|
|
const path = require('path')
|
|
@@ -9,6 +10,7 @@ const { closeWindow } = require('./window-helpers')
|
|
|
|
|
|
const { ipcRenderer, remote } = require('electron')
|
|
|
const { ipcMain, session, BrowserWindow, net } = remote
|
|
|
+const { expect } = chai
|
|
|
|
|
|
/* The whole session API doesn't use standard callbacks */
|
|
|
/* eslint-disable standard/no-callback-literal */
|
|
@@ -421,6 +423,38 @@ describe('session module', () => {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
+ it('can set options for the save dialog', (done) => {
|
|
|
+ downloadServer.listen(0, '127.0.0.1', () => {
|
|
|
+ const filePath = path.join(__dirname, 'fixtures', 'mock.pdf')
|
|
|
+ const port = downloadServer.address().port
|
|
|
+ const options = {
|
|
|
+ window: null,
|
|
|
+ title: 'title',
|
|
|
+ message: 'message',
|
|
|
+ buttonLabel: 'buttonLabel',
|
|
|
+ nameFieldLabel: 'nameFieldLabel',
|
|
|
+ defaultPath: '/',
|
|
|
+ filters: [{
|
|
|
+ name: '1', extensions: ['.1', '.2']
|
|
|
+ }, {
|
|
|
+ name: '2', extensions: ['.3', '.4', '.5']
|
|
|
+ }],
|
|
|
+ showsTagField: true,
|
|
|
+ securityScopedBookmarks: true
|
|
|
+ }
|
|
|
+
|
|
|
+ ipcRenderer.sendSync('set-download-option', true, false, filePath, options)
|
|
|
+ w.webContents.downloadURL(`${url}:${port}`)
|
|
|
+ ipcRenderer.once('download-done', (event, state, url,
|
|
|
+ mimeType, receivedBytes,
|
|
|
+ totalBytes, disposition,
|
|
|
+ filename, savePath, dialogOptions) => {
|
|
|
+ expect(dialogOptions).to.deep.equal(options)
|
|
|
+ done()
|
|
|
+ })
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
describe('when a save path is specified and the URL is unavailable', () => {
|
|
|
it('does not display a save dialog and reports the done state as interrupted', (done) => {
|
|
|
ipcRenderer.sendSync('set-download-option', false, false)
|
|
@@ -697,7 +731,7 @@ describe('session module', () => {
|
|
|
const downloadUrl = `http://127.0.0.1:${port}/assets/logo.png`
|
|
|
const callback = (event, state, url, mimeType,
|
|
|
receivedBytes, totalBytes, disposition,
|
|
|
- filename, savePath, urlChain,
|
|
|
+ filename, savePath, dialogOptions, urlChain,
|
|
|
lastModifiedTime, eTag) => {
|
|
|
if (state === 'cancelled') {
|
|
|
const options = {
|