2016-03-25 20:03:49 +00:00
|
|
|
'use strict'
|
2016-01-23 11:35:30 +00:00
|
|
|
|
2018-07-24 10:32:23 +00:00
|
|
|
const chai = require('chai')
|
|
|
|
const dirtyChai = require('dirty-chai')
|
2016-03-25 20:03:49 +00:00
|
|
|
const fs = require('fs')
|
|
|
|
const path = require('path')
|
|
|
|
const os = require('os')
|
2016-10-12 17:26:53 +00:00
|
|
|
const qs = require('querystring')
|
2016-04-18 17:33:56 +00:00
|
|
|
const http = require('http')
|
2018-09-13 16:10:51 +00:00
|
|
|
const { closeWindow } = require('./window-helpers')
|
|
|
|
const { emittedOnce } = require('./events-helpers')
|
2018-12-05 09:34:09 +00:00
|
|
|
const { ipcRenderer, remote } = require('electron')
|
|
|
|
const { app, ipcMain, BrowserWindow, BrowserView, protocol, session, screen, webContents } = remote
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2019-03-18 19:37:06 +00:00
|
|
|
const features = process.electronBinding('features')
|
2018-09-13 16:10:51 +00:00
|
|
|
const { expect } = chai
|
2016-03-25 20:03:49 +00:00
|
|
|
const isCI = remote.getGlobal('isCi')
|
2017-05-25 23:40:15 +00:00
|
|
|
const nativeModulesEnabled = remote.getGlobal('nativeModulesEnabled')
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2018-07-24 10:32:23 +00:00
|
|
|
chai.use(dirtyChai)
|
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
describe('BrowserWindow module', () => {
|
|
|
|
const fixtures = path.resolve(__dirname, 'fixtures')
|
|
|
|
let w = null
|
2018-08-31 20:51:29 +00:00
|
|
|
let iw = null
|
2017-11-01 14:48:09 +00:00
|
|
|
let ws = null
|
|
|
|
let server
|
|
|
|
let postData
|
|
|
|
|
2018-07-24 10:32:23 +00:00
|
|
|
const defaultOptions = {
|
|
|
|
show: false,
|
|
|
|
width: 400,
|
|
|
|
height: 400,
|
|
|
|
webPreferences: {
|
2019-01-07 19:19:27 +00:00
|
|
|
backgroundThrottling: false,
|
|
|
|
nodeIntegration: true
|
2018-07-24 10:32:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const openTheWindow = async (options = defaultOptions) => {
|
|
|
|
// The `afterEach` hook isn't called if a test fails,
|
|
|
|
// we should make sure that the window is closed ourselves.
|
|
|
|
await closeTheWindow()
|
|
|
|
|
|
|
|
w = new BrowserWindow(options)
|
|
|
|
return w
|
|
|
|
}
|
|
|
|
|
2018-05-03 16:10:25 +00:00
|
|
|
const closeTheWindow = function () {
|
|
|
|
return closeWindow(w).then(() => { w = null })
|
|
|
|
}
|
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
before((done) => {
|
2016-10-12 17:26:53 +00:00
|
|
|
const filePath = path.join(fixtures, 'pages', 'a.html')
|
|
|
|
const fileStats = fs.statSync(filePath)
|
|
|
|
postData = [
|
|
|
|
{
|
2016-11-11 17:22:45 +00:00
|
|
|
type: 'rawData',
|
2017-11-23 22:22:31 +00:00
|
|
|
bytes: Buffer.from('username=test&file=')
|
2016-10-12 17:26:53 +00:00
|
|
|
},
|
|
|
|
{
|
2016-11-11 17:22:45 +00:00
|
|
|
type: 'file',
|
|
|
|
filePath: filePath,
|
|
|
|
offset: 0,
|
|
|
|
length: fileStats.size,
|
|
|
|
modificationTime: fileStats.mtime.getTime() / 1000
|
2016-10-12 17:26:53 +00:00
|
|
|
}
|
|
|
|
]
|
2017-11-01 14:48:09 +00:00
|
|
|
server = http.createServer((req, res) => {
|
2016-10-12 17:26:53 +00:00
|
|
|
function respond () {
|
|
|
|
if (req.method === 'POST') {
|
|
|
|
let body = ''
|
|
|
|
req.on('data', (data) => {
|
2017-11-01 14:48:09 +00:00
|
|
|
if (data) body += data
|
2016-10-12 17:26:53 +00:00
|
|
|
})
|
|
|
|
req.on('end', () => {
|
2018-10-02 01:56:31 +00:00
|
|
|
const parsedData = qs.parse(body)
|
2016-10-12 17:26:53 +00:00
|
|
|
fs.readFile(filePath, (err, data) => {
|
|
|
|
if (err) return
|
|
|
|
if (parsedData.username === 'test' &&
|
|
|
|
parsedData.file === data.toString()) {
|
|
|
|
res.end()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
2018-09-15 15:42:43 +00:00
|
|
|
} else if (req.url === '/302') {
|
|
|
|
res.setHeader('Location', '/200')
|
|
|
|
res.statusCode = 302
|
|
|
|
res.end()
|
|
|
|
} else if (req.url === '/navigate-302') {
|
|
|
|
res.end(`<html><body><script>window.location='${server.url}/302'</script></body></html>`)
|
2018-12-05 08:03:39 +00:00
|
|
|
} else if (req.url === '/cross-site') {
|
|
|
|
res.end(`<html><body><h1>${req.url}</h1></body></html>`)
|
2016-10-12 17:26:53 +00:00
|
|
|
} else {
|
|
|
|
res.end()
|
|
|
|
}
|
|
|
|
}
|
2016-04-20 05:05:09 +00:00
|
|
|
setTimeout(respond, req.url.includes('slow') ? 200 : 0)
|
2016-06-29 16:37:10 +00:00
|
|
|
})
|
2017-11-01 14:48:09 +00:00
|
|
|
server.listen(0, '127.0.0.1', () => {
|
|
|
|
server.url = `http://127.0.0.1:${server.address().port}`
|
2016-04-20 05:05:09 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
after(() => {
|
2016-04-20 05:05:09 +00:00
|
|
|
server.close()
|
|
|
|
server = null
|
|
|
|
})
|
2016-02-09 18:12:45 +00:00
|
|
|
|
2018-07-24 10:32:23 +00:00
|
|
|
beforeEach(openTheWindow)
|
2016-02-09 18:12:45 +00:00
|
|
|
|
2018-05-03 16:10:25 +00:00
|
|
|
afterEach(closeTheWindow)
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
describe('window states', () => {
|
|
|
|
it('does not resize frameless windows when states change', () => {
|
2016-08-15 19:30:26 +00:00
|
|
|
w.destroy()
|
|
|
|
w = new BrowserWindow({
|
|
|
|
frame: false,
|
|
|
|
width: 300,
|
|
|
|
height: 200,
|
|
|
|
show: false
|
|
|
|
})
|
|
|
|
|
2019-06-05 05:44:16 +00:00
|
|
|
w.minimizable = false
|
|
|
|
w.minimizable = true
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.getSize()).to.deep.equal([300, 200])
|
2016-08-15 19:30:26 +00:00
|
|
|
|
2019-06-05 05:44:16 +00:00
|
|
|
w.resizable = false
|
|
|
|
w.resizable = true
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.getSize()).to.deep.equal([300, 200])
|
2016-08-15 19:30:26 +00:00
|
|
|
|
2019-06-05 05:44:16 +00:00
|
|
|
w.maximizable = false
|
|
|
|
w.maximizable = true
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.getSize()).to.deep.equal([300, 200])
|
2016-08-15 19:30:26 +00:00
|
|
|
|
2019-06-05 05:44:16 +00:00
|
|
|
w.fullScreenable = false
|
|
|
|
w.fullScreenable = true
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.getSize()).to.deep.equal([300, 200])
|
2016-08-15 19:30:26 +00:00
|
|
|
|
2019-06-05 05:44:16 +00:00
|
|
|
w.closable = false
|
|
|
|
w.closable = true
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.getSize()).to.deep.equal([300, 200])
|
2016-08-15 19:30:26 +00:00
|
|
|
})
|
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
describe('resizable state', () => {
|
|
|
|
it('can be changed with resizable option', () => {
|
2016-03-25 20:03:49 +00:00
|
|
|
w.destroy()
|
2018-09-13 16:10:51 +00:00
|
|
|
w = new BrowserWindow({ show: false, resizable: false })
|
2019-06-05 05:44:16 +00:00
|
|
|
expect(w.resizable).to.be.false()
|
2016-08-05 00:10:34 +00:00
|
|
|
|
|
|
|
if (process.platform === 'darwin') {
|
2019-06-05 05:44:16 +00:00
|
|
|
expect(w.maximizable).to.to.true()
|
2016-08-05 00:10:34 +00:00
|
|
|
}
|
2016-03-25 20:03:49 +00:00
|
|
|
})
|
|
|
|
|
2019-06-05 05:44:16 +00:00
|
|
|
// TODO(codebytere): remove when propertyification is complete
|
2017-11-01 14:48:09 +00:00
|
|
|
it('can be changed with setResizable method', () => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isResizable()).to.be.true()
|
2016-03-25 20:03:49 +00:00
|
|
|
w.setResizable(false)
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isResizable()).to.be.false()
|
2016-03-25 20:03:49 +00:00
|
|
|
w.setResizable(true)
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isResizable()).to.be.true()
|
2016-03-25 20:03:49 +00:00
|
|
|
})
|
2017-01-09 18:00:52 +00:00
|
|
|
|
2019-06-05 05:44:16 +00:00
|
|
|
it('can be changed with resizable property', () => {
|
|
|
|
expect(w.resizable).to.be.true()
|
|
|
|
w.resizable = false
|
|
|
|
expect(w.resizable).to.be.false()
|
|
|
|
w.resizable = true
|
|
|
|
expect(w.resizable).to.be.true()
|
|
|
|
})
|
|
|
|
|
2017-08-16 14:18:50 +00:00
|
|
|
it('works for a frameless window', () => {
|
2017-01-09 18:00:52 +00:00
|
|
|
w.destroy()
|
2018-09-13 16:10:51 +00:00
|
|
|
w = new BrowserWindow({ show: false, frame: false })
|
2019-06-05 05:44:16 +00:00
|
|
|
expect(w.resizable).to.be.true()
|
2017-01-09 18:00:52 +00:00
|
|
|
|
|
|
|
if (process.platform === 'win32') {
|
|
|
|
w.destroy()
|
2018-09-13 16:10:51 +00:00
|
|
|
w = new BrowserWindow({ show: false, thickFrame: false })
|
2019-06-05 05:44:16 +00:00
|
|
|
expect(w.resizable).to.be.false()
|
2017-01-09 18:00:52 +00:00
|
|
|
}
|
|
|
|
})
|
2018-05-12 15:37:31 +00:00
|
|
|
|
|
|
|
if (process.platform === 'win32') {
|
|
|
|
it('works for a window smaller than 64x64', () => {
|
|
|
|
w.destroy()
|
|
|
|
w = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
frame: false,
|
|
|
|
resizable: false,
|
|
|
|
transparent: true
|
|
|
|
})
|
|
|
|
w.setContentSize(60, 60)
|
2019-05-20 17:04:18 +00:00
|
|
|
expectBoundsEqual(w.getContentSize(), [60, 60])
|
2018-05-12 15:37:31 +00:00
|
|
|
w.setContentSize(30, 30)
|
2019-05-20 17:04:18 +00:00
|
|
|
expectBoundsEqual(w.getContentSize(), [30, 30])
|
2018-05-12 15:37:31 +00:00
|
|
|
w.setContentSize(10, 10)
|
2019-05-20 17:04:18 +00:00
|
|
|
expectBoundsEqual(w.getContentSize(), [10, 10])
|
2018-05-12 15:37:31 +00:00
|
|
|
})
|
|
|
|
}
|
2016-03-25 20:03:49 +00:00
|
|
|
})
|
2016-04-20 05:05:09 +00:00
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
describe('loading main frame state', () => {
|
|
|
|
it('is true when the main frame is loading', (done) => {
|
|
|
|
w.webContents.on('did-start-loading', () => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.webContents.isLoadingMainFrame()).to.be.true()
|
2016-04-20 05:05:09 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
w.webContents.loadURL(server.url)
|
|
|
|
})
|
2017-11-01 14:48:09 +00:00
|
|
|
it('is false when only a subframe is loading', (done) => {
|
|
|
|
w.webContents.once('did-finish-load', () => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.webContents.isLoadingMainFrame()).to.be.false()
|
2017-11-01 14:48:09 +00:00
|
|
|
w.webContents.on('did-start-loading', () => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.webContents.isLoadingMainFrame()).to.be.false()
|
2016-04-20 05:05:09 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
w.webContents.executeJavaScript(`
|
|
|
|
var iframe = document.createElement('iframe')
|
|
|
|
iframe.src = '${server.url}/page2'
|
|
|
|
document.body.appendChild(iframe)
|
|
|
|
`)
|
|
|
|
})
|
|
|
|
w.webContents.loadURL(server.url)
|
|
|
|
})
|
2017-11-01 14:48:09 +00:00
|
|
|
it('is true when navigating to pages from the same origin', (done) => {
|
|
|
|
w.webContents.once('did-finish-load', () => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.webContents.isLoadingMainFrame()).to.be.false()
|
2017-11-01 14:48:09 +00:00
|
|
|
w.webContents.on('did-start-loading', () => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.webContents.isLoadingMainFrame()).to.be.true()
|
2016-04-20 05:05:09 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
w.webContents.loadURL(`${server.url}/page2`)
|
|
|
|
})
|
|
|
|
w.webContents.loadURL(server.url)
|
|
|
|
})
|
|
|
|
})
|
2016-03-25 20:03:49 +00:00
|
|
|
})
|
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
describe('window states (excluding Linux)', () => {
|
2017-11-15 21:05:46 +00:00
|
|
|
// FIXME(alexeykuzmin): Skip the tests instead of using the `return` here.
|
|
|
|
// Why it cannot be done now:
|
|
|
|
// - `.skip()` called in the 'before' hook doesn't affect
|
|
|
|
// nested `describe`s.
|
|
|
|
// - `.skip()` called in the 'beforeEach' hook prevents 'afterEach'
|
|
|
|
// hook from being called.
|
2016-01-23 11:35:30 +00:00
|
|
|
// Not implemented on Linux.
|
2017-11-15 21:05:46 +00:00
|
|
|
if (process.platform === 'linux') {
|
|
|
|
return
|
|
|
|
}
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2019-06-05 05:44:16 +00:00
|
|
|
describe('movable state (property)', () => {
|
|
|
|
it('can be changed with movable option', () => {
|
|
|
|
w.destroy()
|
|
|
|
w = new BrowserWindow({ show: false, movable: false })
|
|
|
|
expect(w.movable).to.be.false()
|
|
|
|
})
|
|
|
|
it('can be changed with movable property', () => {
|
|
|
|
expect(w.movable).to.be.true()
|
|
|
|
w.movable = false
|
|
|
|
expect(w.movable).to.be.false()
|
|
|
|
w.movable = true
|
|
|
|
expect(w.movable).to.be.true()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
// TODO(codebytere): remove when propertyification is complete
|
|
|
|
describe('movable state (methods)', () => {
|
2017-11-01 14:48:09 +00:00
|
|
|
it('can be changed with movable option', () => {
|
2016-03-25 20:03:49 +00:00
|
|
|
w.destroy()
|
2018-09-13 16:10:51 +00:00
|
|
|
w = new BrowserWindow({ show: false, movable: false })
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isMovable()).to.be.false()
|
2016-03-25 20:03:49 +00:00
|
|
|
})
|
2017-11-01 14:48:09 +00:00
|
|
|
it('can be changed with setMovable method', () => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isMovable()).to.be.true()
|
2016-03-25 20:03:49 +00:00
|
|
|
w.setMovable(false)
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isMovable()).to.be.false()
|
2016-03-25 20:03:49 +00:00
|
|
|
w.setMovable(true)
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isMovable()).to.be.true()
|
2016-03-25 20:03:49 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-05 05:44:16 +00:00
|
|
|
describe('minimizable state (property)', () => {
|
|
|
|
it('can be changed with minimizable option', () => {
|
|
|
|
w.destroy()
|
|
|
|
w = new BrowserWindow({ show: false, minimizable: false })
|
|
|
|
expect(w.minimizable).to.be.false()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('can be changed with minimizable property', () => {
|
|
|
|
expect(w.minimizable).to.be.true()
|
|
|
|
w.minimizable = false
|
|
|
|
expect(w.minimizable).to.be.false()
|
|
|
|
w.minimizable = true
|
|
|
|
expect(w.minimizable).to.be.true()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
// TODO(codebytere): remove when propertyification is complete
|
|
|
|
describe('minimizable state (methods)', () => {
|
2017-11-01 14:48:09 +00:00
|
|
|
it('can be changed with minimizable option', () => {
|
2016-03-25 20:03:49 +00:00
|
|
|
w.destroy()
|
2018-09-13 16:10:51 +00:00
|
|
|
w = new BrowserWindow({ show: false, minimizable: false })
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isMinimizable()).to.be.false()
|
2016-03-25 20:03:49 +00:00
|
|
|
})
|
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
it('can be changed with setMinimizable method', () => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isMinimizable()).to.be.true()
|
2016-03-25 20:03:49 +00:00
|
|
|
w.setMinimizable(false)
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isMinimizable()).to.be.false()
|
2016-03-25 20:03:49 +00:00
|
|
|
w.setMinimizable(true)
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isMinimizable()).to.be.true()
|
2016-03-25 20:03:49 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-05 05:44:16 +00:00
|
|
|
describe('maximizable state (property)', () => {
|
|
|
|
it('can be changed with maximizable option', () => {
|
|
|
|
w.destroy()
|
|
|
|
w = new BrowserWindow({ show: false, maximizable: false })
|
|
|
|
expect(w.maximizable).to.be.false()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('can be changed with maximizable property', () => {
|
|
|
|
expect(w.maximizable).to.be.true()
|
|
|
|
w.maximizable = false
|
|
|
|
expect(w.maximizable).to.be.false()
|
|
|
|
w.maximizable = true
|
|
|
|
expect(w.maximizable).to.be.true()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('is not affected when changing other states', () => {
|
|
|
|
w.maximizable = false
|
|
|
|
expect(w.maximizable).to.be.false()
|
|
|
|
w.minimizable = false
|
|
|
|
expect(w.maximizable).to.be.false()
|
|
|
|
w.closable = false
|
|
|
|
expect(w.maximizable).to.be.false()
|
|
|
|
|
|
|
|
w.maximizable = true
|
|
|
|
expect(w.maximizable).to.be.true()
|
|
|
|
w.closable = true
|
|
|
|
expect(w.maximizable).to.be.true()
|
|
|
|
w.fullScreenable = false
|
|
|
|
expect(w.maximizable).to.be.true()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
// TODO(codebytere): remove when propertyification is complete
|
|
|
|
describe('maximizable state (methods)', () => {
|
2017-11-01 14:48:09 +00:00
|
|
|
it('can be changed with maximizable option', () => {
|
2016-03-25 20:03:49 +00:00
|
|
|
w.destroy()
|
2018-09-13 16:10:51 +00:00
|
|
|
w = new BrowserWindow({ show: false, maximizable: false })
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isMaximizable()).to.be.false()
|
2016-03-25 20:03:49 +00:00
|
|
|
})
|
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
it('can be changed with setMaximizable method', () => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isMaximizable()).to.be.true()
|
2016-03-25 20:03:49 +00:00
|
|
|
w.setMaximizable(false)
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isMaximizable()).to.be.false()
|
2016-03-25 20:03:49 +00:00
|
|
|
w.setMaximizable(true)
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isMaximizable()).to.be.true()
|
2016-03-25 20:03:49 +00:00
|
|
|
})
|
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
it('is not affected when changing other states', () => {
|
2016-03-25 20:03:49 +00:00
|
|
|
w.setMaximizable(false)
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isMaximizable()).to.be.false()
|
2016-03-25 20:03:49 +00:00
|
|
|
w.setMinimizable(false)
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isMaximizable()).to.be.false()
|
2016-03-25 20:03:49 +00:00
|
|
|
w.setClosable(false)
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isMaximizable()).to.be.false()
|
2016-08-04 22:06:49 +00:00
|
|
|
|
|
|
|
w.setMaximizable(true)
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isMaximizable()).to.be.true()
|
2016-08-04 22:06:49 +00:00
|
|
|
w.setClosable(true)
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isMaximizable()).to.be.true()
|
2016-08-04 22:06:49 +00:00
|
|
|
w.setFullScreenable(false)
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isMaximizable()).to.be.true()
|
2017-11-23 19:58:37 +00:00
|
|
|
})
|
2017-11-23 20:24:50 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('maximizable state (Windows only)', () => {
|
|
|
|
// Only implemented on windows.
|
|
|
|
if (process.platform !== 'win32') return
|
2017-11-23 19:58:37 +00:00
|
|
|
|
2019-06-05 05:44:16 +00:00
|
|
|
it('is reset to its former state', () => {
|
|
|
|
w.maximizable = false
|
|
|
|
w.resizable = false
|
|
|
|
w.resizable = true
|
|
|
|
expect(w.maximizable).to.be.false()
|
|
|
|
w.maximizable = true
|
|
|
|
w.resizable = false
|
|
|
|
w.resizable = true
|
|
|
|
expect(w.maximizable).to.be.true()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
// TODO(codebytere): remove when propertyification is complete
|
|
|
|
describe('maximizable state (Windows only) (methods)', () => {
|
|
|
|
// Only implemented on windows.
|
|
|
|
if (process.platform !== 'win32') return
|
|
|
|
|
2018-09-26 01:41:40 +00:00
|
|
|
it('is reset to its former state', () => {
|
|
|
|
w.setMaximizable(false)
|
2016-08-04 22:06:49 +00:00
|
|
|
w.setResizable(false)
|
2018-09-26 01:41:40 +00:00
|
|
|
w.setResizable(true)
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isMaximizable()).to.be.false()
|
2018-09-26 01:41:40 +00:00
|
|
|
w.setMaximizable(true)
|
|
|
|
w.setResizable(false)
|
|
|
|
w.setResizable(true)
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isMaximizable()).to.be.true()
|
2016-03-25 20:03:49 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-05 05:44:16 +00:00
|
|
|
describe('fullscreenable state (property)', () => {
|
2017-11-15 21:05:46 +00:00
|
|
|
before(function () {
|
2019-06-05 05:44:16 +00:00
|
|
|
if (process.platform !== 'darwin') this.skip()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('can be changed with fullscreenable option', () => {
|
|
|
|
w.destroy()
|
|
|
|
w = new BrowserWindow({ show: false, fullscreenable: false })
|
|
|
|
expect(w.fullScreenable).to.be.false()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('can be changed with fullScreenable property', () => {
|
|
|
|
expect(w.fullScreenable).to.be.true()
|
|
|
|
w.fullScreenable = false
|
|
|
|
expect(w.fullScreenable).to.be.false()
|
|
|
|
w.fullScreenable = true
|
|
|
|
expect(w.fullScreenable).to.be.true()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
// TODO(codebytere): remove when propertyification is complete
|
|
|
|
describe('fullscreenable state (methods)', () => {
|
|
|
|
before(function () {
|
|
|
|
if (process.platform !== 'darwin') this.skip()
|
2017-11-15 21:05:46 +00:00
|
|
|
})
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
it('can be changed with fullscreenable option', () => {
|
2016-03-25 20:03:49 +00:00
|
|
|
w.destroy()
|
2018-09-13 16:10:51 +00:00
|
|
|
w = new BrowserWindow({ show: false, fullscreenable: false })
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isFullScreenable()).to.be.false()
|
2016-03-25 20:03:49 +00:00
|
|
|
})
|
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
it('can be changed with setFullScreenable method', () => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isFullScreenable()).to.be.true()
|
2016-03-25 20:03:49 +00:00
|
|
|
w.setFullScreenable(false)
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isFullScreenable()).to.be.false()
|
2016-03-25 20:03:49 +00:00
|
|
|
w.setFullScreenable(true)
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isFullScreenable()).to.be.true()
|
2016-03-25 20:03:49 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
describe('kiosk state', () => {
|
2017-11-15 21:05:46 +00:00
|
|
|
before(function () {
|
|
|
|
// Only implemented on macOS.
|
|
|
|
if (process.platform !== 'darwin') {
|
|
|
|
this.skip()
|
|
|
|
}
|
|
|
|
})
|
2017-01-13 23:05:04 +00:00
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
it('can be changed with setKiosk method', (done) => {
|
2017-01-13 23:05:04 +00:00
|
|
|
w.destroy()
|
|
|
|
w = new BrowserWindow()
|
|
|
|
w.setKiosk(true)
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isKiosk()).to.be.true()
|
2017-04-18 23:42:01 +00:00
|
|
|
|
|
|
|
w.once('enter-full-screen', () => {
|
|
|
|
w.setKiosk(false)
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isKiosk()).to.be.false()
|
2017-04-18 23:42:01 +00:00
|
|
|
})
|
|
|
|
w.once('leave-full-screen', () => {
|
|
|
|
done()
|
|
|
|
})
|
2017-01-13 23:05:04 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
describe('fullscreen state with resizable set', () => {
|
2017-11-15 21:05:46 +00:00
|
|
|
before(function () {
|
2019-06-05 05:44:16 +00:00
|
|
|
if (process.platform !== 'darwin') this.skip()
|
2017-11-15 21:05:46 +00:00
|
|
|
})
|
2017-06-20 20:11:28 +00:00
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
it('resizable flag should be set to true and restored', (done) => {
|
2017-06-20 20:11:28 +00:00
|
|
|
w.destroy()
|
|
|
|
w = new BrowserWindow({ resizable: false })
|
|
|
|
w.once('enter-full-screen', () => {
|
2019-06-05 05:44:16 +00:00
|
|
|
expect(w.resizable).to.be.true()
|
2017-06-20 20:11:28 +00:00
|
|
|
w.setFullScreen(false)
|
|
|
|
})
|
|
|
|
w.once('leave-full-screen', () => {
|
2019-06-05 05:44:16 +00:00
|
|
|
expect(w.resizable).to.be.false()
|
2017-06-20 20:11:28 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
w.setFullScreen(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-09-07 18:21:58 +00:00
|
|
|
describe('fullscreen state', () => {
|
2017-11-15 21:05:46 +00:00
|
|
|
before(function () {
|
|
|
|
// Only implemented on macOS.
|
|
|
|
if (process.platform !== 'darwin') {
|
|
|
|
this.skip()
|
|
|
|
}
|
|
|
|
})
|
2017-01-13 23:05:04 +00:00
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
it('can be changed with setFullScreen method', (done) => {
|
2017-01-13 23:05:04 +00:00
|
|
|
w.destroy()
|
|
|
|
w = new BrowserWindow()
|
2017-01-24 16:29:50 +00:00
|
|
|
w.once('enter-full-screen', () => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isFullScreen()).to.be.true()
|
2017-01-24 16:29:50 +00:00
|
|
|
w.setFullScreen(false)
|
2017-01-24 19:22:25 +00:00
|
|
|
})
|
|
|
|
w.once('leave-full-screen', () => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isFullScreen()).to.be.false()
|
2017-01-24 16:29:50 +00:00
|
|
|
done()
|
|
|
|
})
|
2017-01-13 23:05:04 +00:00
|
|
|
w.setFullScreen(true)
|
|
|
|
})
|
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
it('should not be changed by setKiosk method', (done) => {
|
2017-01-24 19:22:25 +00:00
|
|
|
w.destroy()
|
|
|
|
w = new BrowserWindow()
|
|
|
|
w.once('enter-full-screen', () => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isFullScreen()).to.be.true()
|
2017-01-24 19:22:25 +00:00
|
|
|
w.setKiosk(true)
|
|
|
|
w.setKiosk(false)
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isFullScreen()).to.be.true()
|
2017-01-24 19:22:25 +00:00
|
|
|
w.setFullScreen(false)
|
|
|
|
})
|
|
|
|
w.once('leave-full-screen', () => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isFullScreen()).to.be.false()
|
2017-01-24 19:22:25 +00:00
|
|
|
done()
|
|
|
|
})
|
2017-01-13 23:05:04 +00:00
|
|
|
w.setFullScreen(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-05 05:44:16 +00:00
|
|
|
describe('closable state (property)', () => {
|
|
|
|
it('can be changed with closable option', () => {
|
|
|
|
w.destroy()
|
|
|
|
w = new BrowserWindow({ show: false, closable: false })
|
|
|
|
expect(w.closable).to.be.false()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('can be changed with setClosable method', () => {
|
|
|
|
expect(w.closable).to.be.true()
|
|
|
|
w.closable = false
|
|
|
|
expect(w.closable).to.be.false()
|
|
|
|
w.closable = true
|
|
|
|
expect(w.closable).to.be.true()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
// TODO(codebytere): remove when propertyification is complete
|
|
|
|
describe('closable state (methods)', () => {
|
2017-11-01 14:48:09 +00:00
|
|
|
it('can be changed with closable option', () => {
|
2016-03-25 20:03:49 +00:00
|
|
|
w.destroy()
|
2018-09-13 16:10:51 +00:00
|
|
|
w = new BrowserWindow({ show: false, closable: false })
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isClosable()).to.be.false()
|
2016-03-25 20:03:49 +00:00
|
|
|
})
|
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
it('can be changed with setClosable method', () => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isClosable()).to.be.true()
|
2016-03-25 20:03:49 +00:00
|
|
|
w.setClosable(false)
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isClosable()).to.be.false()
|
2016-03-25 20:03:49 +00:00
|
|
|
w.setClosable(true)
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.isClosable()).to.be.true()
|
2016-03-25 20:03:49 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
describe('hasShadow state', () => {
|
2016-01-23 12:03:56 +00:00
|
|
|
// On Window there is no shadow by default and it can not be changed
|
|
|
|
// dynamically.
|
2017-11-01 14:48:09 +00:00
|
|
|
it('can be changed with hasShadow option', () => {
|
2016-03-25 20:03:49 +00:00
|
|
|
w.destroy()
|
2018-10-02 01:56:31 +00:00
|
|
|
const hasShadow = process.platform !== 'darwin'
|
2018-09-13 16:10:51 +00:00
|
|
|
w = new BrowserWindow({ show: false, hasShadow: hasShadow })
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.hasShadow()).to.equal(hasShadow)
|
2016-03-25 20:03:49 +00:00
|
|
|
})
|
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
it('can be changed with setHasShadow method', () => {
|
2016-03-29 00:16:08 +00:00
|
|
|
if (process.platform !== 'darwin') return
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.hasShadow()).to.be.true()
|
2016-03-25 20:03:49 +00:00
|
|
|
w.setHasShadow(false)
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.hasShadow()).to.be.false()
|
2016-03-25 20:03:49 +00:00
|
|
|
w.setHasShadow(true)
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.hasShadow()).to.be.true()
|
2016-03-25 20:03:49 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
describe('window.webContents.send(channel, args...)', () => {
|
|
|
|
it('throws an error when the channel is missing', () => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(() => {
|
2016-03-25 20:03:49 +00:00
|
|
|
w.webContents.send()
|
2019-05-20 17:04:18 +00:00
|
|
|
}).to.throw('Missing required channel argument')
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(() => {
|
2016-03-25 20:03:49 +00:00
|
|
|
w.webContents.send(null)
|
2019-05-20 17:04:18 +00:00
|
|
|
}).to.throw('Missing required channel argument')
|
2016-03-25 20:03:49 +00:00
|
|
|
})
|
|
|
|
})
|
2016-02-16 04:30:42 +00:00
|
|
|
|
2018-12-11 17:45:55 +00:00
|
|
|
describe('window.getNativeWindowHandle()', () => {
|
2019-03-08 00:03:10 +00:00
|
|
|
before(function () {
|
|
|
|
if (!nativeModulesEnabled) {
|
|
|
|
this.skip()
|
|
|
|
}
|
|
|
|
})
|
2018-12-11 17:45:55 +00:00
|
|
|
|
|
|
|
it('returns valid handle', () => {
|
|
|
|
// The module's source code is hosted at
|
|
|
|
// https://github.com/electron/node-is-valid-window
|
|
|
|
const isValidWindow = remote.require('is-valid-window')
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(isValidWindow(w.getNativeWindowHandle())).to.be.true()
|
2018-12-11 17:45:55 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
describe('extensions and dev tools extensions', () => {
|
2017-01-27 00:15:10 +00:00
|
|
|
let showPanelTimeoutId
|
2017-01-26 17:42:45 +00:00
|
|
|
|
|
|
|
const showLastDevToolsPanel = () => {
|
2017-11-01 14:48:09 +00:00
|
|
|
w.webContents.once('devtools-opened', () => {
|
|
|
|
const show = () => {
|
|
|
|
if (w == null || w.isDestroyed()) return
|
2018-09-13 16:10:51 +00:00
|
|
|
const { devToolsWebContents } = w
|
2017-01-26 17:56:40 +00:00
|
|
|
if (devToolsWebContents == null || devToolsWebContents.isDestroyed()) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
const showLastPanel = () => {
|
2017-01-24 23:44:01 +00:00
|
|
|
const lastPanelId = UI.inspectorView._tabbedPane._tabs.peekLast().id
|
|
|
|
UI.inspectorView.showPanel(lastPanelId)
|
2017-01-26 17:42:45 +00:00
|
|
|
}
|
2019-04-30 14:08:33 +00:00
|
|
|
devToolsWebContents.executeJavaScript(`(${showLastPanel})()`, false).then(() => {
|
2017-01-27 00:15:10 +00:00
|
|
|
showPanelTimeoutId = setTimeout(show, 100)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
showPanelTimeoutId = setTimeout(show, 100)
|
2017-01-26 17:42:45 +00:00
|
|
|
})
|
|
|
|
}
|
2016-05-17 21:59:33 +00:00
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
afterEach(() => {
|
2017-01-27 00:15:10 +00:00
|
|
|
clearTimeout(showPanelTimeoutId)
|
2017-01-26 17:42:45 +00:00
|
|
|
})
|
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
describe('BrowserWindow.addDevToolsExtension', () => {
|
2018-05-14 18:17:31 +00:00
|
|
|
describe('for invalid extensions', () => {
|
|
|
|
it('throws errors for missing manifest.json files', () => {
|
|
|
|
const nonexistentExtensionPath = path.join(__dirname, 'does-not-exist')
|
|
|
|
expect(() => {
|
|
|
|
BrowserWindow.addDevToolsExtension(nonexistentExtensionPath)
|
|
|
|
}).to.throw(/ENOENT: no such file or directory/)
|
|
|
|
})
|
2016-05-17 21:59:33 +00:00
|
|
|
|
2018-05-14 18:17:31 +00:00
|
|
|
it('throws errors for invalid manifest.json files', () => {
|
|
|
|
const badManifestExtensionPath = path.join(__dirname, 'fixtures', 'devtools-extensions', 'bad-manifest')
|
|
|
|
expect(() => {
|
|
|
|
BrowserWindow.addDevToolsExtension(badManifestExtensionPath)
|
|
|
|
}).to.throw(/Unexpected token }/)
|
|
|
|
})
|
|
|
|
})
|
2016-05-17 21:59:33 +00:00
|
|
|
|
2018-07-05 01:33:45 +00:00
|
|
|
describe('for a valid extension', () => {
|
2018-05-14 18:17:31 +00:00
|
|
|
const extensionName = 'foo'
|
2016-05-17 21:59:33 +00:00
|
|
|
|
2018-05-14 18:17:31 +00:00
|
|
|
const removeExtension = () => {
|
|
|
|
BrowserWindow.removeDevToolsExtension('foo')
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(BrowserWindow.getDevToolsExtensions()).to.not.have.a.property(extensionName)
|
2018-05-14 18:17:31 +00:00
|
|
|
}
|
2016-05-17 21:56:00 +00:00
|
|
|
|
2018-05-14 18:17:31 +00:00
|
|
|
const addExtension = () => {
|
|
|
|
const extensionPath = path.join(__dirname, 'fixtures', 'devtools-extensions', 'foo')
|
|
|
|
BrowserWindow.addDevToolsExtension(extensionPath)
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(BrowserWindow.getDevToolsExtensions()).to.have.a.property(extensionName)
|
2018-05-14 18:17:31 +00:00
|
|
|
|
|
|
|
showLastDevToolsPanel()
|
|
|
|
|
|
|
|
w.loadURL('about:blank')
|
|
|
|
}
|
|
|
|
|
|
|
|
// After* hooks won't be called if a test fail.
|
|
|
|
// So let's make a clean-up in the before hook.
|
|
|
|
beforeEach(removeExtension)
|
|
|
|
|
|
|
|
describe('when the devtools is docked', () => {
|
|
|
|
beforeEach(function (done) {
|
|
|
|
addExtension()
|
2018-09-13 16:10:51 +00:00
|
|
|
w.webContents.openDevTools({ mode: 'bottom' })
|
2018-05-14 18:17:31 +00:00
|
|
|
ipcMain.once('answer', (event, message) => {
|
|
|
|
this.message = message
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('created extension info', function () {
|
|
|
|
it('has proper "runtimeId"', function () {
|
|
|
|
expect(this.message).to.have.own.property('runtimeId')
|
|
|
|
expect(this.message.runtimeId).to.equal(extensionName)
|
|
|
|
})
|
|
|
|
it('has "tabId" matching webContents id', function () {
|
|
|
|
expect(this.message).to.have.own.property('tabId')
|
|
|
|
expect(this.message.tabId).to.equal(w.webContents.id)
|
|
|
|
})
|
2018-07-09 14:38:48 +00:00
|
|
|
it('has "i18nString" with proper contents', function () {
|
2018-05-14 18:17:31 +00:00
|
|
|
expect(this.message).to.have.own.property('i18nString')
|
|
|
|
expect(this.message.i18nString).to.equal('foo - bar (baz)')
|
|
|
|
})
|
|
|
|
it('has "storageItems" with proper contents', function () {
|
|
|
|
expect(this.message).to.have.own.property('storageItems')
|
|
|
|
expect(this.message.storageItems).to.deep.equal({
|
|
|
|
local: {
|
2018-09-13 16:10:51 +00:00
|
|
|
set: { hello: 'world', world: 'hello' },
|
|
|
|
remove: { world: 'hello' },
|
2018-05-14 18:17:31 +00:00
|
|
|
clear: {}
|
|
|
|
},
|
|
|
|
sync: {
|
2018-09-13 16:10:51 +00:00
|
|
|
set: { foo: 'bar', bar: 'foo' },
|
|
|
|
remove: { foo: 'bar' },
|
2018-05-14 18:17:31 +00:00
|
|
|
clear: {}
|
|
|
|
}
|
|
|
|
})
|
2016-06-28 20:01:51 +00:00
|
|
|
})
|
2016-05-17 21:56:00 +00:00
|
|
|
})
|
2016-05-17 21:52:45 +00:00
|
|
|
})
|
|
|
|
|
2018-05-14 18:17:31 +00:00
|
|
|
describe('when the devtools is undocked', () => {
|
|
|
|
beforeEach(function (done) {
|
|
|
|
addExtension()
|
2018-09-13 16:10:51 +00:00
|
|
|
w.webContents.openDevTools({ mode: 'undocked' })
|
2018-05-14 18:17:31 +00:00
|
|
|
ipcMain.once('answer', (event, message, extensionId) => {
|
|
|
|
this.message = message
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
2016-05-17 21:56:00 +00:00
|
|
|
|
2018-05-14 18:17:31 +00:00
|
|
|
describe('created extension info', function () {
|
|
|
|
it('has proper "runtimeId"', function () {
|
|
|
|
expect(this.message).to.have.own.property('runtimeId')
|
|
|
|
expect(this.message.runtimeId).to.equal(extensionName)
|
|
|
|
})
|
|
|
|
it('has "tabId" matching webContents id', function () {
|
|
|
|
expect(this.message).to.have.own.property('tabId')
|
|
|
|
expect(this.message.tabId).to.equal(w.webContents.id)
|
|
|
|
})
|
2016-05-17 21:56:00 +00:00
|
|
|
})
|
2016-05-17 21:52:45 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-07-05 01:33:45 +00:00
|
|
|
it('works when used with partitions', (done) => {
|
2016-06-08 16:34:41 +00:00
|
|
|
if (w != null) {
|
|
|
|
w.destroy()
|
|
|
|
}
|
|
|
|
w = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
webPreferences: {
|
2019-01-07 19:19:27 +00:00
|
|
|
nodeIntegration: true,
|
2016-06-08 16:34:41 +00:00
|
|
|
partition: 'temp'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-09-28 23:17:00 +00:00
|
|
|
const extensionPath = path.join(__dirname, 'fixtures', 'devtools-extensions', 'foo')
|
2016-06-08 16:34:41 +00:00
|
|
|
BrowserWindow.removeDevToolsExtension('foo')
|
|
|
|
BrowserWindow.addDevToolsExtension(extensionPath)
|
|
|
|
|
2017-01-26 17:42:45 +00:00
|
|
|
showLastDevToolsPanel()
|
2016-06-08 16:34:41 +00:00
|
|
|
|
|
|
|
ipcMain.once('answer', function (event, message) {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(message.runtimeId).to.equal('foo')
|
2016-06-08 16:34:41 +00:00
|
|
|
done()
|
|
|
|
})
|
2018-11-29 01:52:19 +00:00
|
|
|
|
|
|
|
w.loadURL('about:blank')
|
|
|
|
w.webContents.openDevTools({ mode: 'bottom' })
|
2016-06-08 16:34:41 +00:00
|
|
|
})
|
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
it('serializes the registered extensions on quit', () => {
|
2018-09-28 23:17:00 +00:00
|
|
|
const extensionName = 'foo'
|
|
|
|
const extensionPath = path.join(__dirname, 'fixtures', 'devtools-extensions', extensionName)
|
|
|
|
const serializedPath = path.join(app.getPath('userData'), 'DevTools Extensions')
|
2016-03-25 20:03:49 +00:00
|
|
|
|
|
|
|
BrowserWindow.addDevToolsExtension(extensionPath)
|
|
|
|
app.emit('will-quit')
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(JSON.parse(fs.readFileSync(serializedPath))).to.deep.equal([extensionPath])
|
2016-03-25 20:03:49 +00:00
|
|
|
|
|
|
|
BrowserWindow.removeDevToolsExtension(extensionName)
|
|
|
|
app.emit('will-quit')
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(fs.existsSync(serializedPath)).to.be.false()
|
2016-03-25 20:03:49 +00:00
|
|
|
})
|
2017-07-05 15:21:06 +00:00
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
describe('BrowserWindow.addExtension', () => {
|
|
|
|
beforeEach(() => {
|
2017-07-05 15:21:06 +00:00
|
|
|
BrowserWindow.removeExtension('foo')
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(BrowserWindow.getExtensions()).to.not.have.property('foo')
|
2017-07-05 15:21:06 +00:00
|
|
|
|
2018-09-28 23:17:00 +00:00
|
|
|
const extensionPath = path.join(__dirname, 'fixtures', 'devtools-extensions', 'foo')
|
2017-07-05 15:21:06 +00:00
|
|
|
BrowserWindow.addExtension(extensionPath)
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(BrowserWindow.getExtensions()).to.have.property('foo')
|
2017-07-05 15:21:06 +00:00
|
|
|
|
|
|
|
showLastDevToolsPanel()
|
|
|
|
|
|
|
|
w.loadURL('about:blank')
|
|
|
|
})
|
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
it('throws errors for missing manifest.json files', () => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(() => {
|
2017-07-05 15:21:06 +00:00
|
|
|
BrowserWindow.addExtension(path.join(__dirname, 'does-not-exist'))
|
2019-05-20 17:04:18 +00:00
|
|
|
}).to.throw('ENOENT: no such file or directory')
|
2017-07-05 15:21:06 +00:00
|
|
|
})
|
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
it('throws errors for invalid manifest.json files', () => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(() => {
|
2017-07-05 15:21:06 +00:00
|
|
|
BrowserWindow.addExtension(path.join(__dirname, 'fixtures', 'devtools-extensions', 'bad-manifest'))
|
2019-05-20 17:04:18 +00:00
|
|
|
}).to.throw('Unexpected token }')
|
2017-07-05 15:21:06 +00:00
|
|
|
})
|
|
|
|
})
|
2016-03-25 20:03:49 +00:00
|
|
|
})
|
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
describe('window.webContents.executeJavaScript', () => {
|
|
|
|
const expected = 'hello, world!'
|
|
|
|
const expectedErrorMsg = 'woops!'
|
|
|
|
const code = `(() => "${expected}")()`
|
|
|
|
const asyncCode = `(() => new Promise(r => setTimeout(() => r("${expected}"), 500)))()`
|
|
|
|
const badAsyncCode = `(() => new Promise((r, e) => setTimeout(() => e("${expectedErrorMsg}"), 500)))()`
|
2017-11-18 18:59:09 +00:00
|
|
|
const errorTypes = new Set([
|
|
|
|
Error,
|
|
|
|
ReferenceError,
|
|
|
|
EvalError,
|
|
|
|
RangeError,
|
|
|
|
SyntaxError,
|
|
|
|
TypeError,
|
|
|
|
URIError
|
|
|
|
])
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2019-04-30 14:08:33 +00:00
|
|
|
it('resolves the returned promise with the result', (done) => {
|
|
|
|
ipcRenderer.send('executeJavaScript', code)
|
2017-11-01 14:48:09 +00:00
|
|
|
ipcRenderer.once('executeJavaScript-promise-response', (event, result) => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(result).to.equal(expected)
|
2017-03-06 18:49:23 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
2017-11-01 14:48:09 +00:00
|
|
|
it('resolves the returned promise with the result if the code returns an asyncronous promise', (done) => {
|
2019-04-30 14:08:33 +00:00
|
|
|
ipcRenderer.send('executeJavaScript', asyncCode)
|
2017-11-01 14:48:09 +00:00
|
|
|
ipcRenderer.once('executeJavaScript-promise-response', (event, result) => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(result).to.equal(expected)
|
2016-10-11 05:47:09 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
2017-11-01 14:48:09 +00:00
|
|
|
it('rejects the returned promise if an async error is thrown', (done) => {
|
2019-04-30 14:08:33 +00:00
|
|
|
ipcRenderer.send('executeJavaScript', badAsyncCode)
|
2017-11-01 14:48:09 +00:00
|
|
|
ipcRenderer.once('executeJavaScript-promise-error', (event, error) => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(error).to.equal(expectedErrorMsg)
|
2016-10-11 05:47:09 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
2017-11-18 08:51:27 +00:00
|
|
|
it('rejects the returned promise with an error if an Error.prototype is thrown', async () => {
|
2017-11-18 18:59:09 +00:00
|
|
|
for (const error in errorTypes) {
|
2017-11-18 08:51:27 +00:00
|
|
|
await new Promise((resolve) => {
|
2019-04-30 14:08:33 +00:00
|
|
|
ipcRenderer.send('executeJavaScript', `Promise.reject(new ${error.name}("Wamp-wamp")`)
|
2017-11-18 08:51:27 +00:00
|
|
|
ipcRenderer.once('executeJavaScript-promise-error-name', (event, name) => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(name).to.equal(error.name)
|
2017-11-18 08:51:27 +00:00
|
|
|
resolve()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2019-04-30 14:08:33 +00:00
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
it('works after page load and during subframe load', (done) => {
|
|
|
|
w.webContents.once('did-finish-load', () => {
|
2016-04-18 17:33:56 +00:00
|
|
|
// initiate a sub-frame load, then try and execute script during it
|
|
|
|
w.webContents.executeJavaScript(`
|
|
|
|
var iframe = document.createElement('iframe')
|
2016-04-20 05:05:09 +00:00
|
|
|
iframe.src = '${server.url}/slow'
|
2016-04-18 17:33:56 +00:00
|
|
|
document.body.appendChild(iframe)
|
2019-04-30 14:08:33 +00:00
|
|
|
`).then(() => {
|
|
|
|
w.webContents.executeJavaScript('console.log(\'hello\')').then(() => {
|
2016-04-18 17:33:56 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2016-04-20 05:05:09 +00:00
|
|
|
w.loadURL(server.url)
|
2016-04-18 17:33:56 +00:00
|
|
|
})
|
2019-04-30 14:08:33 +00:00
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
it('executes after page load', (done) => {
|
2019-04-30 14:08:33 +00:00
|
|
|
w.webContents.executeJavaScript(code).then(result => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(result).to.equal(expected)
|
2016-04-27 20:24:08 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
w.loadURL(server.url)
|
|
|
|
})
|
2019-04-30 14:08:33 +00:00
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
it('works with result objects that have DOM class prototypes', (done) => {
|
2019-04-30 14:08:33 +00:00
|
|
|
w.webContents.executeJavaScript('document.location').then(result => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(result.origin).to.equal(server.url)
|
|
|
|
expect(result.protocol).to.equal('http:')
|
2016-08-08 16:42:43 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
w.loadURL(server.url)
|
|
|
|
})
|
2016-03-25 20:03:49 +00:00
|
|
|
})
|
2016-07-31 15:10:53 +00:00
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
describe('previewFile', () => {
|
2017-11-15 21:05:46 +00:00
|
|
|
before(function () {
|
|
|
|
if (process.platform !== 'darwin') {
|
|
|
|
this.skip()
|
|
|
|
}
|
|
|
|
})
|
2016-11-28 21:03:33 +00:00
|
|
|
|
2017-11-15 21:05:46 +00:00
|
|
|
it('opens the path in Quick Look on macOS', () => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(() => {
|
2016-11-28 21:03:33 +00:00
|
|
|
w.previewFile(__filename)
|
|
|
|
w.closeFilePreview()
|
2019-05-20 17:04:18 +00:00
|
|
|
}).to.not.throw()
|
2016-11-28 21:03:33 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-07-28 00:08:24 +00:00
|
|
|
describe('contextIsolation option with and without sandbox option', () => {
|
2017-01-12 00:36:59 +00:00
|
|
|
const expectedContextData = {
|
|
|
|
preloadContext: {
|
|
|
|
preloadProperty: 'number',
|
|
|
|
pageProperty: 'undefined',
|
|
|
|
typeofRequire: 'function',
|
|
|
|
typeofProcess: 'object',
|
|
|
|
typeofArrayPush: 'function',
|
2018-08-31 20:51:29 +00:00
|
|
|
typeofFunctionApply: 'function',
|
|
|
|
typeofPreloadExecuteJavaScriptProperty: 'undefined'
|
2017-01-12 00:36:59 +00:00
|
|
|
},
|
|
|
|
pageContext: {
|
|
|
|
preloadProperty: 'undefined',
|
|
|
|
pageProperty: 'string',
|
|
|
|
typeofRequire: 'undefined',
|
|
|
|
typeofProcess: 'undefined',
|
|
|
|
typeofArrayPush: 'number',
|
|
|
|
typeofFunctionApply: 'boolean',
|
|
|
|
typeofPreloadExecuteJavaScriptProperty: 'number',
|
2017-05-22 18:10:10 +00:00
|
|
|
typeofOpenedWindow: 'object'
|
2017-01-12 00:36:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-09 23:18:47 +00:00
|
|
|
beforeEach(() => {
|
2018-08-31 20:51:29 +00:00
|
|
|
if (iw != null) iw.destroy()
|
|
|
|
iw = new BrowserWindow({
|
2017-01-09 23:18:47 +00:00
|
|
|
show: false,
|
|
|
|
webPreferences: {
|
|
|
|
contextIsolation: true,
|
|
|
|
preload: path.join(fixtures, 'api', 'isolated-preload.js')
|
|
|
|
}
|
|
|
|
})
|
2017-07-28 00:08:24 +00:00
|
|
|
if (ws != null) ws.destroy()
|
|
|
|
ws = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
webPreferences: {
|
|
|
|
sandbox: true,
|
|
|
|
contextIsolation: true,
|
|
|
|
preload: path.join(fixtures, 'api', 'isolated-preload.js')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(() => {
|
2018-08-31 20:51:29 +00:00
|
|
|
if (iw != null) iw.destroy()
|
2017-07-28 00:08:24 +00:00
|
|
|
if (ws != null) ws.destroy()
|
2017-01-09 23:18:47 +00:00
|
|
|
})
|
2016-12-13 19:47:54 +00:00
|
|
|
|
2018-08-31 20:51:29 +00:00
|
|
|
it('separates the page context from the Electron/preload context', async () => {
|
2018-11-29 01:52:19 +00:00
|
|
|
const p = emittedOnce(ipcMain, 'isolated-world')
|
2018-09-04 14:50:53 +00:00
|
|
|
iw.loadFile(path.join(fixtures, 'api', 'isolated.html'))
|
2018-11-29 01:52:19 +00:00
|
|
|
const [, data] = await p
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(data).to.deep.equal(expectedContextData)
|
2018-08-31 20:51:29 +00:00
|
|
|
})
|
|
|
|
it('recreates the contexts on reload', async () => {
|
2018-12-19 06:44:03 +00:00
|
|
|
await iw.loadFile(path.join(fixtures, 'api', 'isolated.html'))
|
2018-11-29 01:52:19 +00:00
|
|
|
const isolatedWorld = emittedOnce(ipcMain, 'isolated-world')
|
2018-08-31 20:51:29 +00:00
|
|
|
iw.webContents.reload()
|
2018-11-29 01:52:19 +00:00
|
|
|
const [, data] = await isolatedWorld
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(data).to.deep.equal(expectedContextData)
|
2018-08-31 20:51:29 +00:00
|
|
|
})
|
|
|
|
it('enables context isolation on child windows', async () => {
|
2018-11-29 01:52:19 +00:00
|
|
|
const browserWindowCreated = emittedOnce(app, 'browser-window-created')
|
2018-09-04 14:50:53 +00:00
|
|
|
iw.loadFile(path.join(fixtures, 'pages', 'window-open.html'))
|
2018-11-29 01:52:19 +00:00
|
|
|
const [, window] = await browserWindowCreated
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(window.webContents.getLastWebPreferences().contextIsolation).to.be.true()
|
2018-08-31 20:51:29 +00:00
|
|
|
})
|
|
|
|
it('separates the page context from the Electron/preload context with sandbox on', async () => {
|
2018-11-29 01:52:19 +00:00
|
|
|
const p = emittedOnce(ipcMain, 'isolated-world')
|
2018-09-04 14:50:53 +00:00
|
|
|
ws.loadFile(path.join(fixtures, 'api', 'isolated.html'))
|
2018-11-29 01:52:19 +00:00
|
|
|
const [, data] = await p
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(data).to.deep.equal(expectedContextData)
|
2018-08-31 20:51:29 +00:00
|
|
|
})
|
|
|
|
it('recreates the contexts on reload with sandbox on', async () => {
|
2018-12-19 06:44:03 +00:00
|
|
|
await ws.loadFile(path.join(fixtures, 'api', 'isolated.html'))
|
2018-11-29 01:52:19 +00:00
|
|
|
const isolatedWorld = emittedOnce(ipcMain, 'isolated-world')
|
2018-08-31 20:51:29 +00:00
|
|
|
ws.webContents.reload()
|
2018-11-29 01:52:19 +00:00
|
|
|
const [, data] = await isolatedWorld
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(data).to.deep.equal(expectedContextData)
|
2018-08-31 20:51:29 +00:00
|
|
|
})
|
|
|
|
it('supports fetch api', async () => {
|
|
|
|
const fetchWindow = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
webPreferences: {
|
|
|
|
contextIsolation: true,
|
|
|
|
preload: path.join(fixtures, 'api', 'isolated-fetch-preload.js')
|
|
|
|
}
|
2017-07-28 00:08:24 +00:00
|
|
|
})
|
2018-11-29 01:52:19 +00:00
|
|
|
const p = emittedOnce(ipcMain, 'isolated-fetch-error')
|
2018-08-31 20:51:29 +00:00
|
|
|
fetchWindow.loadURL('about:blank')
|
2018-11-29 01:52:19 +00:00
|
|
|
const [, error] = await p
|
2018-08-31 20:51:29 +00:00
|
|
|
fetchWindow.destroy()
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(error).to.equal('Failed to fetch')
|
2018-08-31 20:51:29 +00:00
|
|
|
})
|
|
|
|
it('doesn\'t break ipc serialization', async () => {
|
2018-11-29 01:52:19 +00:00
|
|
|
const p = emittedOnce(ipcMain, 'isolated-world')
|
2018-08-31 20:51:29 +00:00
|
|
|
iw.loadURL('about:blank')
|
|
|
|
iw.webContents.executeJavaScript(`
|
|
|
|
const opened = window.open()
|
2018-12-04 08:00:13 +00:00
|
|
|
openedLocation = opened.location.href
|
2018-08-31 20:51:29 +00:00
|
|
|
opened.close()
|
|
|
|
window.postMessage({openedLocation}, '*')
|
|
|
|
`)
|
2018-11-29 01:52:19 +00:00
|
|
|
const [, data] = await p
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(data.pageContext.openedLocation).to.equal('')
|
2017-07-28 00:08:24 +00:00
|
|
|
})
|
2016-12-13 19:47:54 +00:00
|
|
|
})
|
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
describe('offscreen rendering', () => {
|
2018-05-03 16:10:25 +00:00
|
|
|
beforeEach(function () {
|
|
|
|
if (!features.isOffscreenRenderingEnabled()) {
|
|
|
|
// XXX(alexeykuzmin): "afterEach" hook is not called
|
|
|
|
// for skipped tests, we have to close the window manually.
|
|
|
|
return closeTheWindow().then(() => { this.skip() })
|
|
|
|
}
|
2017-06-29 19:26:45 +00:00
|
|
|
|
|
|
|
if (w != null) w.destroy()
|
|
|
|
w = new BrowserWindow({
|
2017-05-13 00:14:30 +00:00
|
|
|
width: 100,
|
|
|
|
height: 100,
|
2016-07-31 15:10:53 +00:00
|
|
|
show: false,
|
|
|
|
webPreferences: {
|
|
|
|
backgroundThrottling: false,
|
|
|
|
offscreen: true
|
|
|
|
}
|
|
|
|
})
|
2016-08-03 01:27:55 +00:00
|
|
|
})
|
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
it('creates offscreen window with correct size', (done) => {
|
2017-05-13 00:14:30 +00:00
|
|
|
w.webContents.once('paint', function (event, rect, data) {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(data.constructor.name).to.equal('NativeImage')
|
|
|
|
expect(data.isEmpty()).to.be.false()
|
2018-10-02 01:56:31 +00:00
|
|
|
const size = data.getSize()
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(size.width).to.be.closeTo(100 * devicePixelRatio, 2)
|
|
|
|
expect(size.height).to.be.closeTo(100 * devicePixelRatio, 2)
|
2016-07-31 15:10:53 +00:00
|
|
|
done()
|
|
|
|
})
|
2018-09-04 14:50:53 +00:00
|
|
|
w.loadFile(path.join(fixtures, 'api', 'offscreen-rendering.html'))
|
2016-07-31 15:10:53 +00:00
|
|
|
})
|
|
|
|
|
2019-04-17 21:10:04 +00:00
|
|
|
it('does not crash after navigation', () => {
|
|
|
|
w.webContents.loadURL('about:blank')
|
|
|
|
w.loadFile(path.join(fixtures, 'api', 'offscreen-rendering.html'))
|
|
|
|
})
|
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
describe('window.webContents.isOffscreen()', () => {
|
|
|
|
it('is true for offscreen type', () => {
|
2018-09-04 14:50:53 +00:00
|
|
|
w.loadFile(path.join(fixtures, 'api', 'offscreen-rendering.html'))
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.webContents.isOffscreen()).to.be.true()
|
2016-07-31 15:10:53 +00:00
|
|
|
})
|
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
it('is false for regular window', () => {
|
2018-10-02 01:56:31 +00:00
|
|
|
const c = new BrowserWindow({ show: false })
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(c.webContents.isOffscreen()).to.be.false()
|
2016-08-03 01:27:55 +00:00
|
|
|
c.destroy()
|
2016-07-31 15:10:53 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
describe('window.webContents.isPainting()', () => {
|
|
|
|
it('returns whether is currently painting', (done) => {
|
2017-05-13 00:14:30 +00:00
|
|
|
w.webContents.once('paint', function (event, rect, data) {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.webContents.isPainting()).to.be.true()
|
2016-07-31 15:10:53 +00:00
|
|
|
done()
|
|
|
|
})
|
2018-09-04 14:50:53 +00:00
|
|
|
w.loadFile(path.join(fixtures, 'api', 'offscreen-rendering.html'))
|
2016-07-31 15:10:53 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
describe('window.webContents.stopPainting()', () => {
|
|
|
|
it('stops painting', (done) => {
|
|
|
|
w.webContents.on('dom-ready', () => {
|
2016-08-03 01:27:55 +00:00
|
|
|
w.webContents.stopPainting()
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.webContents.isPainting()).to.be.false()
|
2016-07-31 15:10:53 +00:00
|
|
|
done()
|
|
|
|
})
|
2018-09-04 14:50:53 +00:00
|
|
|
w.loadFile(path.join(fixtures, 'api', 'offscreen-rendering.html'))
|
2016-07-31 15:10:53 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-11-01 14:48:09 +00:00
|
|
|
describe('window.webContents.startPainting()', () => {
|
|
|
|
it('starts painting', (done) => {
|
|
|
|
w.webContents.on('dom-ready', () => {
|
2016-08-03 01:27:55 +00:00
|
|
|
w.webContents.stopPainting()
|
|
|
|
w.webContents.startPainting()
|
2017-05-13 00:14:30 +00:00
|
|
|
w.webContents.once('paint', function (event, rect, data) {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.webContents.isPainting()).to.be.true()
|
2016-07-31 15:10:53 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
2018-09-04 14:50:53 +00:00
|
|
|
w.loadFile(path.join(fixtures, 'api', 'offscreen-rendering.html'))
|
2016-07-31 15:10:53 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-07-03 15:57:10 +00:00
|
|
|
// TODO(codebytere): remove in Electron v8.0.0
|
2017-11-01 14:48:09 +00:00
|
|
|
describe('window.webContents.getFrameRate()', () => {
|
|
|
|
it('has default frame rate', (done) => {
|
2017-05-13 00:14:30 +00:00
|
|
|
w.webContents.once('paint', function (event, rect, data) {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.webContents.getFrameRate()).to.equal(60)
|
2016-07-31 15:10:53 +00:00
|
|
|
done()
|
|
|
|
})
|
2018-09-04 14:50:53 +00:00
|
|
|
w.loadFile(path.join(fixtures, 'api', 'offscreen-rendering.html'))
|
2016-07-31 15:10:53 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-07-03 15:57:10 +00:00
|
|
|
// TODO(codebytere): remove in Electron v8.0.0
|
2017-11-01 14:48:09 +00:00
|
|
|
describe('window.webContents.setFrameRate(frameRate)', () => {
|
|
|
|
it('sets custom frame rate', (done) => {
|
|
|
|
w.webContents.on('dom-ready', () => {
|
2016-08-03 01:27:55 +00:00
|
|
|
w.webContents.setFrameRate(30)
|
2017-05-13 00:14:30 +00:00
|
|
|
w.webContents.once('paint', function (event, rect, data) {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.webContents.getFrameRate()).to.equal(30)
|
2016-07-31 15:10:53 +00:00
|
|
|
done()
|
|
|
|
})
|
2019-07-03 15:57:10 +00:00
|
|
|
})
|
|
|
|
w.loadFile(path.join(fixtures, 'api', 'offscreen-rendering.html'))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('window.webContents.FrameRate', () => {
|
|
|
|
it('has default frame rate', (done) => {
|
|
|
|
w.webContents.once('paint', function (event, rect, data) {
|
|
|
|
expect(w.webContents.frameRate).to.equal(60)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
w.loadFile(path.join(fixtures, 'api', 'offscreen-rendering.html'))
|
|
|
|
})
|
|
|
|
|
|
|
|
it('sets custom frame rate', (done) => {
|
|
|
|
w.webContents.on('dom-ready', () => {
|
|
|
|
w.webContents.frameRate = 30
|
|
|
|
w.webContents.once('paint', function (event, rect, data) {
|
|
|
|
expect(w.webContents.frameRate).to.equal(30)
|
|
|
|
done()
|
|
|
|
})
|
2016-07-31 15:10:53 +00:00
|
|
|
})
|
2018-09-04 14:50:53 +00:00
|
|
|
w.loadFile(path.join(fixtures, 'api', 'offscreen-rendering.html'))
|
2016-07-31 15:10:53 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2016-03-25 20:03:49 +00:00
|
|
|
})
|
2016-09-08 20:31:01 +00:00
|
|
|
|
2019-05-20 17:04:18 +00:00
|
|
|
const expectBoundsEqual = (actual, expected) => {
|
2016-09-08 23:24:11 +00:00
|
|
|
if (!isScaleFactorRounding()) {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(expected).to.deep.equal(actual)
|
2016-09-08 20:33:43 +00:00
|
|
|
} else if (Array.isArray(actual)) {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(actual[0]).to.be.closeTo(expected[0], 1)
|
|
|
|
expect(actual[1]).to.be.closeTo(expected[1], 1)
|
2016-09-08 20:31:01 +00:00
|
|
|
} else {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(actual.x).to.be.closeTo(expected.x, 1)
|
|
|
|
expect(actual.y).to.be.closeTo(expected.y, 1)
|
|
|
|
expect(actual.width).to.be.closeTo(expected.width, 1)
|
|
|
|
expect(actual.height).to.be.closeTo(expected.height, 1)
|
2016-09-08 20:31:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-08 23:24:11 +00:00
|
|
|
// Is the display's scale factor possibly causing rounding of pixel coordinate
|
|
|
|
// values?
|
|
|
|
const isScaleFactorRounding = () => {
|
2018-09-13 16:10:51 +00:00
|
|
|
const { scaleFactor } = screen.getPrimaryDisplay()
|
2016-09-08 23:24:11 +00:00
|
|
|
// Return true if scale factor is non-integer value
|
2016-09-09 00:12:53 +00:00
|
|
|
if (Math.round(scaleFactor) !== scaleFactor) return true
|
2016-09-08 23:24:11 +00:00
|
|
|
// Return true if scale factor is odd number above 2
|
|
|
|
return scaleFactor > 2 && scaleFactor % 2 === 1
|
2016-09-08 20:31:01 +00:00
|
|
|
}
|