fix: prevent print crash on bad deviceName (#21946)

* fix: prevent print crash on bad deviceName

* address review feedback
This commit is contained in:
Shelley Vohr 2020-01-31 02:49:13 +00:00 committed by GitHub
parent 662b94f46e
commit 2955c67c4e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 3 deletions

View file

@ -100,22 +100,35 @@ describe('webContents module', () => {
})
ifdescribe(features.isPrintingEnabled())('webContents.print()', () => {
let w: BrowserWindow
beforeEach(() => {
w = new BrowserWindow({ show: false })
})
afterEach(closeAllWindows)
it('throws when invalid settings are passed', () => {
const w = new BrowserWindow({ show: false })
expect(() => {
// @ts-ignore this line is intentionally incorrect
w.webContents.print(true)
}).to.throw('webContents.print(): Invalid print settings specified.')
})
it('throws when an invalid callback is passed', () => {
expect(() => {
// @ts-ignore this line is intentionally incorrect
w.webContents.print({}, true)
}).to.throw('webContents.print(): Invalid optional callback provided.')
})
ifit(process.platform !== 'linux')('throws when an invalid deviceName is passed', () => {
expect(() => {
w.webContents.print({ deviceName: 'i-am-a-nonexistent-printer' }, () => {})
}).to.throw('webContents.print(): Invalid deviceName provided.')
})
it('does not crash', () => {
const w = new BrowserWindow({ show: false })
expect(() => {
w.webContents.print({ silent: true })
}).to.not.throw()