feat: add methods to allow customization of save dialog during will-download event (#15497)

* feat: add method to DownloadItem that allows customization of dialog options

* docs: add docs for get/setSaveDialogOptions

* add missing copy constructor for DialogSettings on mac and linux

* fix: don't filter dialog options for mas build, don't return properties

* test: add test for get/setSaveDialogOptions

* fix: remove openDevtools added for debugging

* test: fix failing test because of new event parameter

* docs: use SaveDialogOptions instead of Object
This commit is contained in:
Heilig Benedek 2018-11-08 15:51:06 +01:00 committed by John Kleinschmidt
parent 673004b878
commit ca2d74e118
13 changed files with 203 additions and 49 deletions

View file

@ -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 = {