fix: implement 'login' event for WebContents (#20954)

This commit is contained in:
Jeremy Apthorp 2019-11-11 09:47:01 -08:00 committed by GitHub
parent 049bd09150
commit 034f4d5734
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 239 additions and 247 deletions

View file

@ -1,12 +1,13 @@
import { expect } from 'chai'
import * as cp from 'child_process'
import * as https from 'https'
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 { emittedOnce } from './events-helpers'
import { closeWindow } from './window-helpers'
import { closeWindow, closeAllWindows } from './window-helpers'
import { ifdescribe } from './spec-helpers'
import split = require('split')
@ -1415,6 +1416,33 @@ describe('default behavior', () => {
expect(output[0]).to.equal(output[1])
})
})
describe('login event', () => {
afterEach(closeAllWindows)
let server: http.Server
let serverUrl: string
before((done) => {
server = http.createServer((request, response) => {
if (request.headers.authorization) {
return response.end('ok')
}
response
.writeHead(401, { 'WWW-Authenticate': 'Basic realm="Foo"' })
.end()
}).listen(0, '127.0.0.1', () => {
serverUrl = 'http://127.0.0.1:' + (server.address() as net.AddressInfo).port
done()
})
})
it('should emit a login event on app when a WebContents hits a 401', async () => {
const w = new BrowserWindow({ show: false })
w.loadURL(serverUrl)
const [, webContents] = await emittedOnce(app, 'login')
expect(webContents).to.equal(w.webContents)
})
})
})
async function runTestApp (name: string, ...args: any[]) {