|
@@ -10,13 +10,13 @@ const {closeWindow} = require('./window-helpers')
|
|
|
const {ipcRenderer, remote} = require('electron')
|
|
|
const {ipcMain, session, BrowserWindow, net} = remote
|
|
|
|
|
|
-describe('session module', function () {
|
|
|
- var fixtures = path.resolve(__dirname, 'fixtures')
|
|
|
- var w = null
|
|
|
- var webview = null
|
|
|
- var url = 'http://127.0.0.1'
|
|
|
+describe('session module', () => {
|
|
|
+ let fixtures = path.resolve(__dirname, 'fixtures')
|
|
|
+ let w = null
|
|
|
+ let webview = null
|
|
|
+ const url = 'http://127.0.0.1'
|
|
|
|
|
|
- beforeEach(function () {
|
|
|
+ beforeEach(() => {
|
|
|
w = new BrowserWindow({
|
|
|
show: false,
|
|
|
width: 400,
|
|
@@ -24,7 +24,7 @@ describe('session module', function () {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- afterEach(function () {
|
|
|
+ afterEach(() => {
|
|
|
if (webview != null) {
|
|
|
if (!document.body.contains(webview)) {
|
|
|
document.body.appendChild(webview)
|
|
@@ -32,21 +32,21 @@ describe('session module', function () {
|
|
|
webview.remove()
|
|
|
}
|
|
|
|
|
|
- return closeWindow(w).then(function () { w = null })
|
|
|
+ return closeWindow(w).then(() => { w = null })
|
|
|
})
|
|
|
|
|
|
- describe('session.defaultSession', function () {
|
|
|
- it('returns the default session', function () {
|
|
|
+ describe('session.defaultSession', () => {
|
|
|
+ it('returns the default session', () => {
|
|
|
assert.equal(session.defaultSession, session.fromPartition(''))
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- describe('session.fromPartition(partition, options)', function () {
|
|
|
- it('returns existing session with same partition', function () {
|
|
|
+ describe('session.fromPartition(partition, options)', () => {
|
|
|
+ it('returns existing session with same partition', () => {
|
|
|
assert.equal(session.fromPartition('test'), session.fromPartition('test'))
|
|
|
})
|
|
|
|
|
|
- it('created session is ref-counted', function () {
|
|
|
+ it('created session is ref-counted', () => {
|
|
|
const partition = 'test2'
|
|
|
const userAgent = 'test-agent'
|
|
|
const ses1 = session.fromPartition(partition)
|
|
@@ -58,104 +58,83 @@ describe('session module', function () {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- describe('ses.cookies', function () {
|
|
|
- it('should get cookies', function (done) {
|
|
|
- var server = http.createServer(function (req, res) {
|
|
|
+ describe('ses.cookies', () => {
|
|
|
+ it('should get cookies', (done) => {
|
|
|
+ const server = http.createServer((req, res) => {
|
|
|
res.setHeader('Set-Cookie', ['0=0'])
|
|
|
res.end('finished')
|
|
|
server.close()
|
|
|
})
|
|
|
- server.listen(0, '127.0.0.1', function () {
|
|
|
- var port = server.address().port
|
|
|
- w.loadURL(url + ':' + port)
|
|
|
- w.webContents.on('did-finish-load', function () {
|
|
|
- w.webContents.session.cookies.get({
|
|
|
- url: url
|
|
|
- }, function (error, list) {
|
|
|
- var cookie, i, len
|
|
|
- if (error) {
|
|
|
- return done(error)
|
|
|
- }
|
|
|
- for (i = 0, len = list.length; i < len; i++) {
|
|
|
- cookie = list[i]
|
|
|
+ server.listen(0, '127.0.0.1', () => {
|
|
|
+ const port = server.address().port
|
|
|
+ w.loadURL(`${url}:${port}`)
|
|
|
+ w.webContents.on('did-finish-load', () => {
|
|
|
+ w.webContents.session.cookies.get({url}, (error, list) => {
|
|
|
+ if (error) return done(error)
|
|
|
+ for (let i = 0; i < list.length; i++) {
|
|
|
+ const cookie = list[i]
|
|
|
if (cookie.name === '0') {
|
|
|
if (cookie.value === '0') {
|
|
|
return done()
|
|
|
} else {
|
|
|
- return done('cookie value is ' + cookie.value + ' while expecting 0')
|
|
|
+ return done(`cookie value is ${cookie.value} while expecting 0`)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- done('Can not find cookie')
|
|
|
+ done('Can\'t find cookie')
|
|
|
})
|
|
|
})
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- it('calls back with an error when setting a cookie with missing required fields', function (done) {
|
|
|
+ it('calls back with an error when setting a cookie with missing required fields', (done) => {
|
|
|
session.defaultSession.cookies.set({
|
|
|
url: '',
|
|
|
name: '1',
|
|
|
value: '1'
|
|
|
- }, function (error) {
|
|
|
+ }, (error) => {
|
|
|
assert.equal(error.message, 'Setting cookie failed')
|
|
|
done()
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- it('should over-write the existent cookie', function (done) {
|
|
|
+ it('should over-write the existent cookie', (done) => {
|
|
|
session.defaultSession.cookies.set({
|
|
|
- url: url,
|
|
|
+ url,
|
|
|
name: '1',
|
|
|
value: '1'
|
|
|
- }, function (error) {
|
|
|
- if (error) {
|
|
|
- return done(error)
|
|
|
- }
|
|
|
- session.defaultSession.cookies.get({
|
|
|
- url: url
|
|
|
- }, function (error, list) {
|
|
|
- var cookie, i, len
|
|
|
- if (error) {
|
|
|
- return done(error)
|
|
|
- }
|
|
|
- for (i = 0, len = list.length; i < len; i++) {
|
|
|
- cookie = list[i]
|
|
|
+ }, (error) => {
|
|
|
+ if (error) return done(error)
|
|
|
+ session.defaultSession.cookies.get({url}, (error, list) => {
|
|
|
+ if (error) return done(error)
|
|
|
+ for (let i = 0; i < list.length; i++) {
|
|
|
+ const cookie = list[i]
|
|
|
if (cookie.name === '1') {
|
|
|
if (cookie.value === '1') {
|
|
|
return done()
|
|
|
} else {
|
|
|
- return done('cookie value is ' + cookie.value + ' while expecting 1')
|
|
|
+ return done(`cookie value is ${cookie.value} while expecting 1`)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- done('Can not find cookie')
|
|
|
+ done('Can\'t find cookie')
|
|
|
})
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- it('should remove cookies', function (done) {
|
|
|
+ it('should remove cookies', (done) => {
|
|
|
session.defaultSession.cookies.set({
|
|
|
url: url,
|
|
|
name: '2',
|
|
|
value: '2'
|
|
|
- }, function (error) {
|
|
|
- if (error) {
|
|
|
- return done(error)
|
|
|
- }
|
|
|
- session.defaultSession.cookies.remove(url, '2', function () {
|
|
|
- session.defaultSession.cookies.get({
|
|
|
- url: url
|
|
|
- }, function (error, list) {
|
|
|
- var cookie, i, len
|
|
|
- if (error) {
|
|
|
- return done(error)
|
|
|
- }
|
|
|
- for (i = 0, len = list.length; i < len; i++) {
|
|
|
- cookie = list[i]
|
|
|
- if (cookie.name === '2') {
|
|
|
- return done('Cookie not deleted')
|
|
|
- }
|
|
|
+ }, (error) => {
|
|
|
+ if (error) return done(error)
|
|
|
+ session.defaultSession.cookies.remove(url, '2', () => {
|
|
|
+ session.defaultSession.cookies.get({url}, (error, list) => {
|
|
|
+ if (error) return done(error)
|
|
|
+ for (let i = 0; i < list.length; i++) {
|
|
|
+ const cookie = list[i]
|
|
|
+ if (cookie.name === '2') return done('Cookie not deleted')
|
|
|
}
|
|
|
done()
|
|
|
})
|
|
@@ -163,23 +142,17 @@ describe('session module', function () {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- it('should set cookie for standard scheme', function (done) {
|
|
|
+ it('should set cookie for standard scheme', (done) => {
|
|
|
const standardScheme = remote.getGlobal('standardScheme')
|
|
|
const origin = standardScheme + '://fake-host'
|
|
|
session.defaultSession.cookies.set({
|
|
|
url: origin,
|
|
|
name: 'custom',
|
|
|
value: '1'
|
|
|
- }, function (error) {
|
|
|
- if (error) {
|
|
|
- return done(error)
|
|
|
- }
|
|
|
- session.defaultSession.cookies.get({
|
|
|
- url: origin
|
|
|
- }, function (error, list) {
|
|
|
- if (error) {
|
|
|
- return done(error)
|
|
|
- }
|
|
|
+ }, (error) => {
|
|
|
+ if (error) return done(error)
|
|
|
+ session.defaultSession.cookies.get({url: origin}, (error, list) => {
|
|
|
+ if (error) return done(error)
|
|
|
assert.equal(list.length, 1)
|
|
|
assert.equal(list[0].name, 'custom')
|
|
|
assert.equal(list[0].value, '1')
|
|
@@ -189,16 +162,16 @@ describe('session module', function () {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- it('emits a changed event when a cookie is added or removed', function (done) {
|
|
|
+ it('emits a changed event when a cookie is added or removed', (done) => {
|
|
|
const {cookies} = session.fromPartition('cookies-changed')
|
|
|
|
|
|
- cookies.once('changed', function (event, cookie, cause, removed) {
|
|
|
+ cookies.once('changed', (event, cookie, cause, removed) => {
|
|
|
assert.equal(cookie.name, 'foo')
|
|
|
assert.equal(cookie.value, 'bar')
|
|
|
assert.equal(cause, 'explicit')
|
|
|
assert.equal(removed, false)
|
|
|
|
|
|
- cookies.once('changed', function (event, cookie, cause, removed) {
|
|
|
+ cookies.once('changed', (event, cookie, cause, removed) => {
|
|
|
assert.equal(cookie.name, 'foo')
|
|
|
assert.equal(cookie.value, 'bar')
|
|
|
assert.equal(cause, 'explicit')
|
|
@@ -206,7 +179,7 @@ describe('session module', function () {
|
|
|
done()
|
|
|
})
|
|
|
|
|
|
- cookies.remove(url, 'foo', function (error) {
|
|
|
+ cookies.remove(url, 'foo', (error) => {
|
|
|
if (error) return done(error)
|
|
|
})
|
|
|
})
|
|
@@ -215,13 +188,13 @@ describe('session module', function () {
|
|
|
url: url,
|
|
|
name: 'foo',
|
|
|
value: 'bar'
|
|
|
- }, function (error) {
|
|
|
+ }, (error) => {
|
|
|
if (error) return done(error)
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- describe('ses.cookies.flushStore(callback)', function () {
|
|
|
- it('flushes the cookies to disk and invokes the callback when done', function (done) {
|
|
|
+ describe('ses.cookies.flushStore(callback)', () => {
|
|
|
+ it('flushes the cookies to disk and invokes the callback when done', (done) => {
|
|
|
session.defaultSession.cookies.set({
|
|
|
url: url,
|
|
|
name: 'foo',
|
|
@@ -236,30 +209,30 @@ describe('session module', function () {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- describe('ses.clearStorageData(options)', function () {
|
|
|
+ describe('ses.clearStorageData(options)', () => {
|
|
|
fixtures = path.resolve(__dirname, 'fixtures')
|
|
|
- it('clears localstorage data', function (done) {
|
|
|
- ipcMain.on('count', function (event, count) {
|
|
|
+ it('clears localstorage data', (done) => {
|
|
|
+ ipcMain.on('count', (event, count) => {
|
|
|
ipcMain.removeAllListeners('count')
|
|
|
assert.equal(count, 0)
|
|
|
done()
|
|
|
})
|
|
|
w.loadURL('file://' + path.join(fixtures, 'api', 'localstorage.html'))
|
|
|
- w.webContents.on('did-finish-load', function () {
|
|
|
- var options = {
|
|
|
+ w.webContents.on('did-finish-load', () => {
|
|
|
+ const options = {
|
|
|
origin: 'file://',
|
|
|
storages: ['localstorage'],
|
|
|
quotas: ['persistent']
|
|
|
}
|
|
|
- w.webContents.session.clearStorageData(options, function () {
|
|
|
+ w.webContents.session.clearStorageData(options, () => {
|
|
|
w.webContents.send('getcount')
|
|
|
})
|
|
|
})
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- describe('will-download event', function () {
|
|
|
- beforeEach(function () {
|
|
|
+ describe('will-download event', () => {
|
|
|
+ beforeEach(() => {
|
|
|
if (w != null) w.destroy()
|
|
|
w = new BrowserWindow({
|
|
|
show: false,
|
|
@@ -268,10 +241,10 @@ describe('session module', function () {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- it('can cancel default download behavior', function (done) {
|
|
|
+ it('can cancel default download behavior', (done) => {
|
|
|
const mockFile = new Buffer(1024)
|
|
|
const contentDisposition = 'inline; filename="mockFile.txt"'
|
|
|
- const downloadServer = http.createServer(function (req, res) {
|
|
|
+ const downloadServer = http.createServer((req, res) => {
|
|
|
res.writeHead(200, {
|
|
|
'Content-Length': mockFile.length,
|
|
|
'Content-Type': 'application/plain',
|
|
@@ -281,13 +254,13 @@ describe('session module', function () {
|
|
|
downloadServer.close()
|
|
|
})
|
|
|
|
|
|
- downloadServer.listen(0, '127.0.0.1', function () {
|
|
|
+ downloadServer.listen(0, '127.0.0.1', () => {
|
|
|
const port = downloadServer.address().port
|
|
|
- const url = 'http://127.0.0.1:' + port + '/'
|
|
|
+ const url = `http://127.0.0.1:${port}/`
|
|
|
|
|
|
ipcRenderer.sendSync('set-download-option', false, true)
|
|
|
w.loadURL(url)
|
|
|
- ipcRenderer.once('download-error', function (event, downloadUrl, filename, error) {
|
|
|
+ ipcRenderer.once('download-error', (event, downloadUrl, filename, error) => {
|
|
|
assert.equal(downloadUrl, url)
|
|
|
assert.equal(filename, 'mockFile.txt')
|
|
|
assert.equal(error, 'Object has been destroyed')
|
|
@@ -297,14 +270,12 @@ describe('session module', function () {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- describe('DownloadItem', function () {
|
|
|
- var mockPDF = new Buffer(1024 * 1024 * 5)
|
|
|
- var contentDisposition = 'inline; filename="mock.pdf"'
|
|
|
- var downloadFilePath = path.join(fixtures, 'mock.pdf')
|
|
|
- var downloadServer = http.createServer(function (req, res) {
|
|
|
- if (req.url === '/?testFilename') {
|
|
|
- contentDisposition = 'inline'
|
|
|
- }
|
|
|
+ describe('DownloadItem', () => {
|
|
|
+ const mockPDF = new Buffer(1024 * 1024 * 5)
|
|
|
+ let contentDisposition = 'inline; filename="mock.pdf"'
|
|
|
+ const downloadFilePath = path.join(fixtures, 'mock.pdf')
|
|
|
+ const downloadServer = http.createServer((req, res) => {
|
|
|
+ if (req.url === '/?testFilename') contentDisposition = 'inline'
|
|
|
res.writeHead(200, {
|
|
|
'Content-Length': mockPDF.length,
|
|
|
'Content-Type': 'application/pdf',
|
|
@@ -313,13 +284,13 @@ describe('session module', function () {
|
|
|
res.end(mockPDF)
|
|
|
downloadServer.close()
|
|
|
})
|
|
|
- var assertDownload = function (event, state, url, mimeType,
|
|
|
+ const assertDownload = (event, state, url, mimeType,
|
|
|
receivedBytes, totalBytes, disposition,
|
|
|
- filename, port, savePath) {
|
|
|
+ filename, port, savePath) => {
|
|
|
assert.equal(state, 'completed')
|
|
|
assert.equal(filename, 'mock.pdf')
|
|
|
assert.equal(savePath, path.join(__dirname, 'fixtures', 'mock.pdf'))
|
|
|
- assert.equal(url, 'http://127.0.0.1:' + port + '/')
|
|
|
+ assert.equal(url, `http://127.0.0.1:${port}/`)
|
|
|
assert.equal(mimeType, 'application/pdf')
|
|
|
assert.equal(receivedBytes, mockPDF.length)
|
|
|
assert.equal(totalBytes, mockPDF.length)
|
|
@@ -328,15 +299,15 @@ describe('session module', function () {
|
|
|
fs.unlinkSync(downloadFilePath)
|
|
|
}
|
|
|
|
|
|
- it('can download using WebContents.downloadURL', function (done) {
|
|
|
- downloadServer.listen(0, '127.0.0.1', function () {
|
|
|
- var port = downloadServer.address().port
|
|
|
+ it('can download using WebContents.downloadURL', (done) => {
|
|
|
+ downloadServer.listen(0, '127.0.0.1', () => {
|
|
|
+ const port = downloadServer.address().port
|
|
|
ipcRenderer.sendSync('set-download-option', false, false)
|
|
|
- w.webContents.downloadURL(url + ':' + port)
|
|
|
- ipcRenderer.once('download-done', function (event, state, url,
|
|
|
+ w.webContents.downloadURL(`${url}:${port}`)
|
|
|
+ ipcRenderer.once('download-done', (event, state, url,
|
|
|
mimeType, receivedBytes,
|
|
|
totalBytes, disposition,
|
|
|
- filename, savePath) {
|
|
|
+ filename, savePath) => {
|
|
|
assertDownload(event, state, url, mimeType, receivedBytes,
|
|
|
totalBytes, disposition, filename, port, savePath)
|
|
|
done()
|
|
@@ -344,19 +315,19 @@ describe('session module', function () {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- it('can download using WebView.downloadURL', function (done) {
|
|
|
- downloadServer.listen(0, '127.0.0.1', function () {
|
|
|
- var port = downloadServer.address().port
|
|
|
+ it('can download using WebView.downloadURL', (done) => {
|
|
|
+ downloadServer.listen(0, '127.0.0.1', () => {
|
|
|
+ const port = downloadServer.address().port
|
|
|
ipcRenderer.sendSync('set-download-option', false, false)
|
|
|
webview = new WebView()
|
|
|
- webview.src = 'file://' + fixtures + '/api/blank.html'
|
|
|
- webview.addEventListener('did-finish-load', function () {
|
|
|
- webview.downloadURL(url + ':' + port + '/')
|
|
|
+ webview.src = `file://${fixtures}/api/blank.html`
|
|
|
+ webview.addEventListener('did-finish-load', () => {
|
|
|
+ webview.downloadURL(`${url}:${port}/`)
|
|
|
})
|
|
|
- ipcRenderer.once('download-done', function (event, state, url,
|
|
|
+ ipcRenderer.once('download-done', (event, state, url,
|
|
|
mimeType, receivedBytes,
|
|
|
totalBytes, disposition,
|
|
|
- filename, savePath) {
|
|
|
+ filename, savePath) => {
|
|
|
assertDownload(event, state, url, mimeType, receivedBytes,
|
|
|
totalBytes, disposition, filename, port, savePath)
|
|
|
document.body.removeChild(webview)
|
|
@@ -366,15 +337,15 @@ describe('session module', function () {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- it('can cancel download', function (done) {
|
|
|
- downloadServer.listen(0, '127.0.0.1', function () {
|
|
|
- var port = downloadServer.address().port
|
|
|
+ it('can cancel download', (done) => {
|
|
|
+ downloadServer.listen(0, '127.0.0.1', () => {
|
|
|
+ const port = downloadServer.address().port
|
|
|
ipcRenderer.sendSync('set-download-option', true, false)
|
|
|
- w.webContents.downloadURL(url + ':' + port + '/')
|
|
|
- ipcRenderer.once('download-done', function (event, state, url,
|
|
|
+ w.webContents.downloadURL(`${url}:${port}/`)
|
|
|
+ ipcRenderer.once('download-done', (event, state, url,
|
|
|
mimeType, receivedBytes,
|
|
|
totalBytes, disposition,
|
|
|
- filename) {
|
|
|
+ filename) => {
|
|
|
assert.equal(state, 'cancelled')
|
|
|
assert.equal(filename, 'mock.pdf')
|
|
|
assert.equal(mimeType, 'application/pdf')
|
|
@@ -386,18 +357,17 @@ describe('session module', function () {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- it('can generate a default filename', function (done) {
|
|
|
- // Somehow this test always fail on appveyor.
|
|
|
+ it('can generate a default filename', (done) => {
|
|
|
if (process.env.APPVEYOR === 'True') return done()
|
|
|
|
|
|
- downloadServer.listen(0, '127.0.0.1', function () {
|
|
|
- var port = downloadServer.address().port
|
|
|
+ downloadServer.listen(0, '127.0.0.1', () => {
|
|
|
+ const port = downloadServer.address().port
|
|
|
ipcRenderer.sendSync('set-download-option', true, false)
|
|
|
- w.webContents.downloadURL(url + ':' + port + '/?testFilename')
|
|
|
- ipcRenderer.once('download-done', function (event, state, url,
|
|
|
+ w.webContents.downloadURL(`${url}:${port}/?testFilename`)
|
|
|
+ ipcRenderer.once('download-done', (event, state, url,
|
|
|
mimeType, receivedBytes,
|
|
|
totalBytes, disposition,
|
|
|
- filename) {
|
|
|
+ filename) => {
|
|
|
assert.equal(state, 'cancelled')
|
|
|
assert.equal(filename, 'download.pdf')
|
|
|
assert.equal(mimeType, 'application/pdf')
|
|
@@ -409,28 +379,28 @@ describe('session module', function () {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- describe('when a save path is specified and the URL is unavailable', function () {
|
|
|
- it('does not display a save dialog and reports the done state as interrupted', function (done) {
|
|
|
+ describe('when a save path is specified and the URL is unavailable', () => {
|
|
|
+ it('does not display a save dialog and reports the done state as interrupted', (done) => {
|
|
|
ipcRenderer.sendSync('set-download-option', false, false)
|
|
|
ipcRenderer.once('download-done', (event, state) => {
|
|
|
assert.equal(state, 'interrupted')
|
|
|
done()
|
|
|
})
|
|
|
- w.webContents.downloadURL('file://' + path.join(__dirname, 'does-not-exist.txt'))
|
|
|
+ w.webContents.downloadURL(`file://${path.join(__dirname, 'does-not-exist.txt')}`)
|
|
|
})
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- describe('ses.protocol', function () {
|
|
|
+ describe('ses.protocol', () => {
|
|
|
const partitionName = 'temp'
|
|
|
const protocolName = 'sp'
|
|
|
const partitionProtocol = session.fromPartition(partitionName).protocol
|
|
|
const protocol = session.defaultSession.protocol
|
|
|
- const handler = function (ignoredError, callback) {
|
|
|
+ const handler = (ignoredError, callback) => {
|
|
|
callback({data: 'test', mimeType: 'text/html'})
|
|
|
}
|
|
|
|
|
|
- beforeEach(function (done) {
|
|
|
+ beforeEach((done) => {
|
|
|
if (w != null) w.destroy()
|
|
|
w = new BrowserWindow({
|
|
|
show: false,
|
|
@@ -438,53 +408,49 @@ describe('session module', function () {
|
|
|
partition: partitionName
|
|
|
}
|
|
|
})
|
|
|
- partitionProtocol.registerStringProtocol(protocolName, handler, function (error) {
|
|
|
+ partitionProtocol.registerStringProtocol(protocolName, handler, (error) => {
|
|
|
done(error != null ? error : undefined)
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- afterEach(function (done) {
|
|
|
+ afterEach((done) => {
|
|
|
partitionProtocol.unregisterProtocol(protocolName, () => done())
|
|
|
})
|
|
|
|
|
|
- it('does not affect defaultSession', function (done) {
|
|
|
- protocol.isProtocolHandled(protocolName, function (result) {
|
|
|
+ it('does not affect defaultSession', (done) => {
|
|
|
+ protocol.isProtocolHandled(protocolName, (result) => {
|
|
|
assert.equal(result, false)
|
|
|
- partitionProtocol.isProtocolHandled(protocolName, function (result) {
|
|
|
+ partitionProtocol.isProtocolHandled(protocolName, (result) => {
|
|
|
assert.equal(result, true)
|
|
|
done()
|
|
|
})
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- xit('handles requests from partition', function (done) {
|
|
|
- w.webContents.on('did-finish-load', function () {
|
|
|
- done()
|
|
|
- })
|
|
|
+ xit('handles requests from partition', (done) => {
|
|
|
+ w.webContents.on('did-finish-load', () => done())
|
|
|
w.loadURL(`${protocolName}://fake-host`)
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- describe('ses.setProxy(options, callback)', function () {
|
|
|
- it('allows configuring proxy settings', function (done) {
|
|
|
- const config = {
|
|
|
- proxyRules: 'http=myproxy:80'
|
|
|
- }
|
|
|
- session.defaultSession.setProxy(config, function () {
|
|
|
- session.defaultSession.resolveProxy('http://localhost', function (proxy) {
|
|
|
+ describe('ses.setProxy(options, callback)', () => {
|
|
|
+ it('allows configuring proxy settings', (done) => {
|
|
|
+ const config = {proxyRules: 'http=myproxy:80'}
|
|
|
+ session.defaultSession.setProxy(config, () => {
|
|
|
+ session.defaultSession.resolveProxy('http://localhost', (proxy) => {
|
|
|
assert.equal(proxy, 'PROXY myproxy:80')
|
|
|
done()
|
|
|
})
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- it('allows bypassing proxy settings', function (done) {
|
|
|
+ it('allows bypassing proxy settings', (done) => {
|
|
|
const config = {
|
|
|
proxyRules: 'http=myproxy:80',
|
|
|
proxyBypassRules: '<local>'
|
|
|
}
|
|
|
- session.defaultSession.setProxy(config, function () {
|
|
|
- session.defaultSession.resolveProxy('http://localhost', function (proxy) {
|
|
|
+ session.defaultSession.setProxy(config, () => {
|
|
|
+ session.defaultSession.resolveProxy('http://localhost', (proxy) => {
|
|
|
assert.equal(proxy, 'DIRECT')
|
|
|
done()
|
|
|
})
|
|
@@ -492,17 +458,17 @@ describe('session module', function () {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- describe('ses.getBlobData(identifier, callback)', function () {
|
|
|
- it('returns blob data for uuid', function (done) {
|
|
|
+ describe('ses.getBlobData(identifier, callback)', () => {
|
|
|
+ it('returns blob data for uuid', (done) => {
|
|
|
const scheme = 'temp'
|
|
|
const protocol = session.defaultSession.protocol
|
|
|
- const url = scheme + '://host'
|
|
|
- before(function () {
|
|
|
+ const url = `${scheme}://host`
|
|
|
+ before(() => {
|
|
|
if (w != null) w.destroy()
|
|
|
w = new BrowserWindow({show: false})
|
|
|
})
|
|
|
|
|
|
- after(function (done) {
|
|
|
+ after((done) => {
|
|
|
protocol.unregisterProtocol(scheme, () => {
|
|
|
closeWindow(w).then(() => {
|
|
|
w = null
|
|
@@ -525,30 +491,30 @@ describe('session module', function () {
|
|
|
</script>
|
|
|
</html>`
|
|
|
|
|
|
- protocol.registerStringProtocol(scheme, function (request, callback) {
|
|
|
+ protocol.registerStringProtocol(scheme, (request, callback) => {
|
|
|
if (request.method === 'GET') {
|
|
|
callback({data: content, mimeType: 'text/html'})
|
|
|
} else if (request.method === 'POST') {
|
|
|
let uuid = request.uploadData[1].blobUUID
|
|
|
assert(uuid)
|
|
|
- session.defaultSession.getBlobData(uuid, function (result) {
|
|
|
+ session.defaultSession.getBlobData(uuid, (result) => {
|
|
|
assert.equal(result.toString(), postData)
|
|
|
done()
|
|
|
})
|
|
|
}
|
|
|
- }, function (error) {
|
|
|
+ }, (error) => {
|
|
|
if (error) return done(error)
|
|
|
w.loadURL(url)
|
|
|
})
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- describe('ses.setCertificateVerifyProc(callback)', function () {
|
|
|
- var server = null
|
|
|
+ describe('ses.setCertificateVerifyProc(callback)', () => {
|
|
|
+ let server = null
|
|
|
|
|
|
- beforeEach(function (done) {
|
|
|
- var certPath = path.join(__dirname, 'fixtures', 'certificates')
|
|
|
- var options = {
|
|
|
+ beforeEach((done) => {
|
|
|
+ const certPath = path.join(__dirname, 'fixtures', 'certificates')
|
|
|
+ const options = {
|
|
|
key: fs.readFileSync(path.join(certPath, 'server.key')),
|
|
|
cert: fs.readFileSync(path.join(certPath, 'server.pem')),
|
|
|
ca: [
|
|
@@ -559,54 +525,54 @@ describe('session module', function () {
|
|
|
rejectUnauthorized: false
|
|
|
}
|
|
|
|
|
|
- server = https.createServer(options, function (req, res) {
|
|
|
+ server = https.createServer(options, (req, res) => {
|
|
|
res.writeHead(200)
|
|
|
res.end('<title>hello</title>')
|
|
|
})
|
|
|
server.listen(0, '127.0.0.1', done)
|
|
|
})
|
|
|
|
|
|
- afterEach(function () {
|
|
|
+ afterEach(() => {
|
|
|
session.defaultSession.setCertificateVerifyProc(null)
|
|
|
server.close()
|
|
|
})
|
|
|
|
|
|
- it('accepts the request when the callback is called with 0', function (done) {
|
|
|
- session.defaultSession.setCertificateVerifyProc(function ({hostname, certificate, verificationResult, errorCode}, callback) {
|
|
|
+ it('accepts the request when the callback is called with 0', (done) => {
|
|
|
+ session.defaultSession.setCertificateVerifyProc(({hostname, certificate, verificationResult, errorCode}, callback) => {
|
|
|
assert(['net::ERR_CERT_AUTHORITY_INVALID', 'net::ERR_CERT_COMMON_NAME_INVALID'].includes(verificationResult), verificationResult)
|
|
|
assert([-202, -200].includes(errorCode), errorCode)
|
|
|
callback(0)
|
|
|
})
|
|
|
|
|
|
- w.webContents.once('did-finish-load', function () {
|
|
|
+ w.webContents.once('did-finish-load', () => {
|
|
|
assert.equal(w.webContents.getTitle(), 'hello')
|
|
|
done()
|
|
|
})
|
|
|
w.loadURL(`https://127.0.0.1:${server.address().port}`)
|
|
|
})
|
|
|
|
|
|
- describe('deprecated function signature', function () {
|
|
|
- it('supports accepting the request', function (done) {
|
|
|
- session.defaultSession.setCertificateVerifyProc(function (hostname, certificate, callback) {
|
|
|
+ describe('deprecated function signature', () => {
|
|
|
+ it('supports accepting the request', (done) => {
|
|
|
+ session.defaultSession.setCertificateVerifyProc((hostname, certificate, callback) => {
|
|
|
assert.equal(hostname, '127.0.0.1')
|
|
|
callback(true)
|
|
|
})
|
|
|
|
|
|
- w.webContents.once('did-finish-load', function () {
|
|
|
+ w.webContents.once('did-finish-load', () => {
|
|
|
assert.equal(w.webContents.getTitle(), 'hello')
|
|
|
done()
|
|
|
})
|
|
|
w.loadURL(`https://127.0.0.1:${server.address().port}`)
|
|
|
})
|
|
|
|
|
|
- it('supports rejecting the request', function (done) {
|
|
|
- session.defaultSession.setCertificateVerifyProc(function (hostname, certificate, callback) {
|
|
|
+ it('supports rejecting the request', (done) => {
|
|
|
+ session.defaultSession.setCertificateVerifyProc((hostname, certificate, callback) => {
|
|
|
assert.equal(hostname, '127.0.0.1')
|
|
|
callback(false)
|
|
|
})
|
|
|
|
|
|
- var url = `https://127.0.0.1:${server.address().port}`
|
|
|
- w.webContents.once('did-finish-load', function () {
|
|
|
+ const url = `https://127.0.0.1:${server.address().port}`
|
|
|
+ w.webContents.once('did-finish-load', () => {
|
|
|
assert.equal(w.webContents.getTitle(), url)
|
|
|
done()
|
|
|
})
|
|
@@ -614,8 +580,8 @@ describe('session module', function () {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- it('rejects the request when the callback is called with -2', function (done) {
|
|
|
- session.defaultSession.setCertificateVerifyProc(function ({hostname, certificate, verificationResult}, callback) {
|
|
|
+ it('rejects the request when the callback is called with -2', (done) => {
|
|
|
+ session.defaultSession.setCertificateVerifyProc(({hostname, certificate, verificationResult}, callback) => {
|
|
|
assert.equal(hostname, '127.0.0.1')
|
|
|
assert.equal(certificate.issuerName, 'Intermediate CA')
|
|
|
assert.equal(certificate.subjectName, 'localhost')
|
|
@@ -630,8 +596,8 @@ describe('session module', function () {
|
|
|
callback(-2)
|
|
|
})
|
|
|
|
|
|
- var url = `https://127.0.0.1:${server.address().port}`
|
|
|
- w.webContents.once('did-finish-load', function () {
|
|
|
+ const url = `https://127.0.0.1:${server.address().port}`
|
|
|
+ w.webContents.once('did-finish-load', () => {
|
|
|
assert.equal(w.webContents.getTitle(), url)
|
|
|
done()
|
|
|
})
|
|
@@ -639,8 +605,8 @@ describe('session module', function () {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- describe('ses.createInterruptedDownload(options)', function () {
|
|
|
- it('can create an interrupted download item', function (done) {
|
|
|
+ describe('ses.createInterruptedDownload(options)', () => {
|
|
|
+ it('can create an interrupted download item', (done) => {
|
|
|
ipcRenderer.sendSync('set-download-option', true, false)
|
|
|
const filePath = path.join(__dirname, 'fixtures', 'mock.pdf')
|
|
|
const options = {
|
|
@@ -651,10 +617,10 @@ describe('session module', function () {
|
|
|
length: 5242880
|
|
|
}
|
|
|
w.webContents.session.createInterruptedDownload(options)
|
|
|
- ipcRenderer.once('download-created', function (event, state, urlChain,
|
|
|
+ ipcRenderer.once('download-created', (event, state, urlChain,
|
|
|
mimeType, receivedBytes,
|
|
|
totalBytes, filename,
|
|
|
- savePath) {
|
|
|
+ savePath) => {
|
|
|
assert.equal(state, 'interrupted')
|
|
|
assert.deepEqual(urlChain, ['http://127.0.0.1/'])
|
|
|
assert.equal(mimeType, 'application/pdf')
|
|
@@ -665,26 +631,22 @@ describe('session module', function () {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- it('can be resumed', function (done) {
|
|
|
+ it('can be resumed', (done) => {
|
|
|
const fixtures = path.join(__dirname, 'fixtures')
|
|
|
const downloadFilePath = path.join(fixtures, 'logo.png')
|
|
|
- const rangeServer = http.createServer(function (req, res) {
|
|
|
- let options = {
|
|
|
- root: fixtures
|
|
|
- }
|
|
|
+ const rangeServer = http.createServer((req, res) => {
|
|
|
+ let options = { root: fixtures }
|
|
|
send(req, req.url, options)
|
|
|
- .on('error', function (error) {
|
|
|
- done(error)
|
|
|
- }).pipe(res)
|
|
|
+ .on('error', (error) => { done(error) }).pipe(res)
|
|
|
})
|
|
|
ipcRenderer.sendSync('set-download-option', true, false, downloadFilePath)
|
|
|
- rangeServer.listen(0, '127.0.0.1', function () {
|
|
|
+ rangeServer.listen(0, '127.0.0.1', () => {
|
|
|
const port = rangeServer.address().port
|
|
|
const downloadUrl = `http://127.0.0.1:${port}/assets/logo.png`
|
|
|
- const callback = function (event, state, url, mimeType,
|
|
|
+ const callback = (event, state, url, mimeType,
|
|
|
receivedBytes, totalBytes, disposition,
|
|
|
filename, savePath, urlChain,
|
|
|
- lastModifiedTime, eTag) {
|
|
|
+ lastModifiedTime, eTag) => {
|
|
|
if (state === 'cancelled') {
|
|
|
const options = {
|
|
|
path: savePath,
|
|
@@ -718,11 +680,11 @@ describe('session module', function () {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- describe('ses.clearAuthCache(options[, callback])', function () {
|
|
|
- it('can clear http auth info from cache', function (done) {
|
|
|
+ describe('ses.clearAuthCache(options[, callback])', () => {
|
|
|
+ it('can clear http auth info from cache', (done) => {
|
|
|
const ses = session.fromPartition('auth-cache')
|
|
|
- const server = http.createServer(function (req, res) {
|
|
|
- var credentials = auth(req)
|
|
|
+ const server = http.createServer((req, res) => {
|
|
|
+ const credentials = auth(req)
|
|
|
if (!credentials || credentials.name !== 'test' || credentials.pass !== 'test') {
|
|
|
res.statusCode = 401
|
|
|
res.setHeader('WWW-Authenticate', 'Basic realm="Restricted"')
|
|
@@ -731,7 +693,7 @@ describe('session module', function () {
|
|
|
res.end('authenticated')
|
|
|
}
|
|
|
})
|
|
|
- server.listen(0, '127.0.0.1', function () {
|
|
|
+ server.listen(0, '127.0.0.1', () => {
|
|
|
const port = server.address().port
|
|
|
function issueLoginRequest (attempt = 1) {
|
|
|
if (attempt > 2) {
|
|
@@ -742,27 +704,25 @@ describe('session module', function () {
|
|
|
url: `http://127.0.0.1:${port}`,
|
|
|
session: ses
|
|
|
})
|
|
|
- request.on('login', function (info, callback) {
|
|
|
- attempt++
|
|
|
+ request.on('login', (info, callback) => {
|
|
|
+ attempt += 1
|
|
|
assert.equal(info.scheme, 'basic')
|
|
|
assert.equal(info.realm, 'Restricted')
|
|
|
callback('test', 'test')
|
|
|
})
|
|
|
- request.on('response', function (response) {
|
|
|
+ request.on('response', (response) => {
|
|
|
let data = ''
|
|
|
response.pause()
|
|
|
- response.on('data', function (chunk) {
|
|
|
+ response.on('data', (chunk) => {
|
|
|
data += chunk
|
|
|
})
|
|
|
- response.on('end', function () {
|
|
|
+ response.on('end', () => {
|
|
|
assert.equal(data, 'authenticated')
|
|
|
- ses.clearAuthCache({type: 'password'}, function () {
|
|
|
+ ses.clearAuthCache({type: 'password'}, () => {
|
|
|
issueLoginRequest(attempt)
|
|
|
})
|
|
|
})
|
|
|
- response.on('error', function (error) {
|
|
|
- done(error)
|
|
|
- })
|
|
|
+ response.on('error', (error) => { done(error) })
|
|
|
response.resume()
|
|
|
})
|
|
|
// Internal api to bypass cache for testing.
|
|
@@ -782,12 +742,12 @@ describe('session module', function () {
|
|
|
})
|
|
|
|
|
|
webview = new WebView()
|
|
|
- webview.addEventListener('ipc-message', function (e) {
|
|
|
+ webview.addEventListener('ipc-message', (e) => {
|
|
|
assert.equal(e.channel, 'message')
|
|
|
assert.deepEqual(e.args, ['SecurityError'])
|
|
|
done()
|
|
|
})
|
|
|
- webview.src = 'file://' + fixtures + '/pages/permissions/midi-sysex.html'
|
|
|
+ webview.src = `file://${fixtures}/pages/permissions/midi-sysex.html`
|
|
|
webview.partition = 'permissionTest'
|
|
|
webview.setAttribute('nodeintegration', 'on')
|
|
|
document.body.appendChild(webview)
|