refactor: ginify Session (#23569)

This commit is contained in:
Jeremy Apthorp 2020-05-19 10:18:12 -07:00 committed by GitHub
parent 3f3a760a01
commit de44d28c8e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 135 additions and 111 deletions

View file

@ -4,7 +4,7 @@ import * as https from 'https';
import * as path from 'path';
import * as fs from 'fs';
import * as ChildProcess from 'child_process';
import { session, BrowserWindow, net, ipcMain, Session } from 'electron/main';
import { app, session, BrowserWindow, net, ipcMain, Session } from 'electron/main';
import * as send from 'send';
import * as auth from 'basic-auth';
import { closeAllWindows } from './window-helpers';
@ -28,29 +28,6 @@ describe('session module', () => {
it('returns existing session with same partition', () => {
expect(session.fromPartition('test')).to.equal(session.fromPartition('test'));
});
// TODO(codebytere): remove in Electron v8.0.0
it.skip('created session is ref-counted (functions)', () => {
const partition = 'test2';
const userAgent = 'test-agent';
const ses1 = session.fromPartition(partition);
ses1.setUserAgent(userAgent);
expect(ses1.getUserAgent()).to.equal(userAgent);
ses1.destroy();
const ses2 = session.fromPartition(partition);
expect(ses2.getUserAgent()).to.not.equal(userAgent);
});
it.skip('created session is ref-counted', () => {
const partition = 'test2';
const userAgent = 'test-agent';
const ses1 = session.fromPartition(partition);
ses1.setUserAgent(userAgent);
expect(ses1.getUserAgent()).to.equal(userAgent);
ses1.destroy();
const ses2 = session.fromPartition(partition);
expect(ses2.getUserAgent()).to.not.equal(userAgent);
});
});
describe('ses.cookies', () => {
@ -370,9 +347,7 @@ describe('session module', () => {
if (server) {
server.close();
}
if (customSession) {
customSession.destroy();
}
customSession = null as any;
});
it('allows configuring proxy settings', async () => {
@ -966,4 +941,13 @@ describe('session module', () => {
expect(headers!['user-agent']).to.equal(userAgent);
});
});
describe('session-created event', () => {
it('is emitted when a session is created', async () => {
const eventEmitted = new Promise<Session>(resolve => app.once('session-created', resolve));
session.fromPartition('' + Math.random());
const s = await eventEmitted;
expect(s.constructor.name).to.equal('Session');
});
});
});