test: add test for app.on('certificate-error') event (#21978)

This commit is contained in:
Jeremy Apthorp 2020-01-31 15:25:01 -08:00 committed by GitHub
parent 08b1f0e25d
commit 720cf6eb27
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View file

@ -5,7 +5,7 @@ import * as http from 'http'
import * as net from 'net'
import * as fs from 'fs'
import * as path from 'path'
import { app, BrowserWindow, Menu } from 'electron'
import { app, BrowserWindow, Menu, session } from 'electron'
import { emittedOnce } from './events-helpers'
import { closeWindow, closeAllWindows } from './window-helpers'
import { ifdescribe } from './spec-helpers'
@ -305,6 +305,15 @@ describe('app module', () => {
})
})
describe('certificate-error event', () => {
afterEach(closeAllWindows)
it('is emitted when visiting a server with a self-signed cert', async () => {
const w = new BrowserWindow({ show: false })
w.loadURL(secureUrl)
await emittedOnce(app, 'certificate-error')
})
})
// xdescribe('app.importCertificate', () => {
// let w = null
@ -708,6 +717,7 @@ describe('app module', () => {
if (process.platform === 'linux') {
this.skip()
}
session.fromPartition('empty-certificate').setCertificateVerifyProc((req, cb) => { cb(0) })
})
beforeEach(() => {
@ -722,6 +732,8 @@ describe('app module', () => {
afterEach(() => closeWindow(w).then(() => { w = null as any }))
after(() => session.fromPartition('empty-certificate').setCertificateVerifyProc(null))
it('can respond with empty certificate list', async () => {
app.once('select-client-certificate', function (event, webContents, url, list, callback) {
console.log('select-client-certificate emitted')

View file

@ -20,9 +20,6 @@ v8.setFlagsFromString('--expose_gc')
app.commandLine.appendSwitch('js-flags', '--expose_gc')
// Prevent the spec runner quiting when the first window closes
app.on('window-all-closed', () => null)
// TODO: This API should _probably_ only be enabled for the specific test that needs it
// not the entire test suite
app.commandLine.appendSwitch('ignore-certificate-errors')
// Use fake device for Media Stream to replace actual camera and microphone.
app.commandLine.appendSwitch('use-fake-device-for-media-stream')