From fd73279d169a28875028673ce3f07fb3454807a9 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 12 Jul 2016 22:38:50 +0900 Subject: [PATCH] spec: Test lifetime of sessions returned by session.fromPartition --- spec/api-session-spec.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/spec/api-session-spec.js b/spec/api-session-spec.js index 4f43ef04d30b..95436c73b885 100644 --- a/spec/api-session-spec.js +++ b/spec/api-session-spec.js @@ -3,12 +3,8 @@ const http = require('http') const path = require('path') const fs = require('fs') -const ipcRenderer = require('electron').ipcRenderer -const remote = require('electron').remote - -const ipcMain = remote.ipcMain -const session = remote.session -const BrowserWindow = remote.BrowserWindow +const {ipcRenderer, remote} = require('electron') +const {ipcMain, session, webContents, BrowserWindow} = remote describe('session module', function () { this.timeout(10000) @@ -41,6 +37,23 @@ describe('session module', function () { }) }) + describe('session.fromPartition(partition, options)', function () { + it('returns existing session with same partition', function () { + assert.equal(session.fromPartition('test'), session.fromPartition('test')) + }) + + it('created session is ref-counted', function () { + const partition = 'test2' + const userAgent = 'test-agent' + const ses1 = session.fromPartition(partition) + ses1.setUserAgent(userAgent) + assert.equal(ses1.getUserAgent(), userAgent) + ses1.destroy() + const ses2 = session.fromPartition(partition) + assert.notEqual(ses2.getUserAgent(), userAgent) + }) + }) + describe('ses.cookies', function () { it('should get cookies', function (done) { var server = http.createServer(function (req, res) {