2016-03-25 23:03:49 +03:00
|
|
|
'use strict'
|
2016-01-23 14:35:30 +03:00
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
const assert = require('assert')
|
|
|
|
const fs = require('fs')
|
|
|
|
const path = require('path')
|
|
|
|
const os = require('os')
|
2016-04-18 20:33:56 +03:00
|
|
|
const http = require('http')
|
2016-08-03 22:47:53 +03:00
|
|
|
const {closeWindow} = require('./window-helpers')
|
2016-01-12 05:40:23 +03:00
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
const remote = require('electron').remote
|
|
|
|
const screen = require('electron').screen
|
2016-01-12 05:40:23 +03:00
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
const app = remote.require('electron').app
|
|
|
|
const ipcMain = remote.require('electron').ipcMain
|
|
|
|
const ipcRenderer = require('electron').ipcRenderer
|
|
|
|
const BrowserWindow = remote.require('electron').BrowserWindow
|
2016-01-12 05:40:23 +03:00
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
const isCI = remote.getGlobal('isCi')
|
2016-01-12 05:40:23 +03:00
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
describe('browser-window module', function () {
|
|
|
|
var fixtures = path.resolve(__dirname, 'fixtures')
|
|
|
|
var w = null
|
2016-04-20 08:05:09 +03:00
|
|
|
var server
|
|
|
|
|
|
|
|
before(function (done) {
|
|
|
|
server = http.createServer(function (req, res) {
|
2016-06-29 19:37:10 +03:00
|
|
|
function respond () { res.end('') }
|
2016-04-20 08:05:09 +03:00
|
|
|
setTimeout(respond, req.url.includes('slow') ? 200 : 0)
|
2016-06-29 19:37:10 +03:00
|
|
|
})
|
2016-04-20 08:05:09 +03:00
|
|
|
server.listen(0, '127.0.0.1', function () {
|
|
|
|
server.url = 'http://127.0.0.1:' + server.address().port
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
server.close()
|
|
|
|
server = null
|
|
|
|
})
|
2016-02-09 21:12:45 +03:00
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
beforeEach(function () {
|
2016-02-09 21:12:45 +03:00
|
|
|
w = new BrowserWindow({
|
2016-01-12 05:40:23 +03:00
|
|
|
show: false,
|
|
|
|
width: 400,
|
2016-06-26 05:53:58 +03:00
|
|
|
height: 400,
|
|
|
|
webPreferences: {
|
|
|
|
backgroundThrottling: false
|
|
|
|
}
|
2016-03-25 23:03:49 +03:00
|
|
|
})
|
|
|
|
})
|
2016-02-09 21:12:45 +03:00
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
afterEach(function () {
|
2016-08-03 22:47:53 +03:00
|
|
|
return closeWindow(w).then(function () { w = null })
|
2016-03-25 23:03:49 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('BrowserWindow.close()', function () {
|
|
|
|
it('should emit unload handler', function (done) {
|
|
|
|
w.webContents.on('did-finish-load', function () {
|
|
|
|
w.close()
|
|
|
|
})
|
2016-08-03 23:10:26 +03:00
|
|
|
w.once('closed', function () {
|
2016-03-25 23:03:49 +03:00
|
|
|
var test = path.join(fixtures, 'api', 'unload')
|
|
|
|
var content = fs.readFileSync(test)
|
|
|
|
fs.unlinkSync(test)
|
|
|
|
assert.equal(String(content), 'unload')
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
w.loadURL('file://' + path.join(fixtures, 'api', 'unload.html'))
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should emit beforeunload handler', function (done) {
|
2016-08-03 23:10:26 +03:00
|
|
|
w.once('onbeforeunload', function () {
|
2016-03-25 23:03:49 +03:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
w.webContents.on('did-finish-load', function () {
|
|
|
|
w.close()
|
|
|
|
})
|
|
|
|
w.loadURL('file://' + path.join(fixtures, 'api', 'beforeunload-false.html'))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('window.close()', function () {
|
|
|
|
it('should emit unload handler', function (done) {
|
2016-08-03 23:10:26 +03:00
|
|
|
w.once('closed', function () {
|
2016-03-25 23:03:49 +03:00
|
|
|
var test = path.join(fixtures, 'api', 'close')
|
|
|
|
var content = fs.readFileSync(test)
|
|
|
|
fs.unlinkSync(test)
|
|
|
|
assert.equal(String(content), 'close')
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
w.loadURL('file://' + path.join(fixtures, 'api', 'close.html'))
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should emit beforeunload handler', function (done) {
|
2016-08-03 23:10:26 +03:00
|
|
|
w.once('onbeforeunload', function () {
|
2016-03-25 23:03:49 +03:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-false.html'))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('BrowserWindow.destroy()', function () {
|
|
|
|
it('prevents users to access methods of webContents', function () {
|
|
|
|
var webContents = w.webContents
|
|
|
|
w.destroy()
|
2016-03-29 03:16:08 +03:00
|
|
|
assert.throws(function () {
|
2016-03-25 23:03:49 +03:00
|
|
|
webContents.getId()
|
2016-03-29 03:16:08 +03:00
|
|
|
}, /Object has been destroyed/)
|
2016-03-25 23:03:49 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('BrowserWindow.loadURL(url)', function () {
|
|
|
|
it('should emit did-start-loading event', function (done) {
|
|
|
|
w.webContents.on('did-start-loading', function () {
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
w.loadURL('about:blank')
|
|
|
|
})
|
|
|
|
|
2016-04-08 21:19:36 +03:00
|
|
|
it('should emit did-get-response-details event', function (done) {
|
|
|
|
// expected {fileName: resourceType} pairs
|
|
|
|
var expectedResources = {
|
|
|
|
'did-get-response-details.html': 'mainFrame',
|
|
|
|
'logo.png': 'image'
|
|
|
|
}
|
2016-06-29 19:37:10 +03:00
|
|
|
var responses = 0
|
2016-04-08 21:19:36 +03:00
|
|
|
w.webContents.on('did-get-response-details', function (event, status, newUrl, oldUrl, responseCode, method, referrer, headers, resourceType) {
|
|
|
|
responses++
|
|
|
|
var fileName = newUrl.slice(newUrl.lastIndexOf('/') + 1)
|
|
|
|
var expectedType = expectedResources[fileName]
|
|
|
|
assert(!!expectedType, `Unexpected response details for ${newUrl}`)
|
|
|
|
assert(typeof status === 'boolean', 'status should be boolean')
|
|
|
|
assert.equal(responseCode, 200)
|
|
|
|
assert.equal(method, 'GET')
|
|
|
|
assert(typeof referrer === 'string', 'referrer should be string')
|
|
|
|
assert(!!headers, 'headers should be present')
|
|
|
|
assert(typeof headers === 'object', 'headers should be object')
|
|
|
|
assert.equal(resourceType, expectedType, 'Incorrect resourceType')
|
|
|
|
if (responses === Object.keys(expectedResources).length) {
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
w.loadURL('file://' + path.join(fixtures, 'pages', 'did-get-response-details.html'))
|
|
|
|
})
|
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
it('should emit did-fail-load event for files that do not exist', function (done) {
|
2016-04-05 05:24:58 +03:00
|
|
|
w.webContents.on('did-fail-load', function (event, code, desc, url, isMainFrame) {
|
2016-03-25 23:03:49 +03:00
|
|
|
assert.equal(code, -6)
|
2016-05-21 07:51:15 +03:00
|
|
|
assert.equal(desc, 'ERR_FILE_NOT_FOUND')
|
2016-04-05 05:24:58 +03:00
|
|
|
assert.equal(isMainFrame, true)
|
2016-03-25 23:03:49 +03:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
w.loadURL('file://a.txt')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should emit did-fail-load event for invalid URL', function (done) {
|
2016-04-05 05:24:58 +03:00
|
|
|
w.webContents.on('did-fail-load', function (event, code, desc, url, isMainFrame) {
|
2016-03-25 23:03:49 +03:00
|
|
|
assert.equal(desc, 'ERR_INVALID_URL')
|
|
|
|
assert.equal(code, -300)
|
2016-04-05 05:24:58 +03:00
|
|
|
assert.equal(isMainFrame, true)
|
2016-03-25 23:03:49 +03:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
w.loadURL('http://example:port')
|
|
|
|
})
|
2016-04-05 05:24:58 +03:00
|
|
|
|
|
|
|
it('should set `mainFrame = false` on did-fail-load events in iframes', function (done) {
|
|
|
|
w.webContents.on('did-fail-load', function (event, code, desc, url, isMainFrame) {
|
|
|
|
assert.equal(isMainFrame, false)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
w.loadURL('file://' + path.join(fixtures, 'api', 'did-fail-load-iframe.html'))
|
|
|
|
})
|
2016-04-13 13:39:11 +03:00
|
|
|
|
|
|
|
it('does not crash in did-fail-provisional-load handler', function (done) {
|
2016-04-30 12:21:18 +03:00
|
|
|
this.timeout(10000)
|
2016-04-13 13:39:11 +03:00
|
|
|
w.webContents.once('did-fail-provisional-load', function () {
|
2016-04-30 12:21:18 +03:00
|
|
|
w.loadURL('http://127.0.0.1:11111')
|
2016-04-13 13:39:11 +03:00
|
|
|
done()
|
|
|
|
})
|
2016-04-30 12:21:18 +03:00
|
|
|
w.loadURL('http://127.0.0.1:11111')
|
2016-04-13 13:39:11 +03:00
|
|
|
})
|
2016-03-25 23:03:49 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('BrowserWindow.show()', function () {
|
2016-03-08 22:11:17 +03:00
|
|
|
if (isCI) {
|
2016-03-25 23:03:49 +03:00
|
|
|
return
|
2016-03-08 22:11:17 +03:00
|
|
|
}
|
2016-02-09 21:12:45 +03:00
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
it('should focus on window', function () {
|
|
|
|
w.show()
|
|
|
|
assert(w.isFocused())
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should make the window visible', function () {
|
|
|
|
w.show()
|
|
|
|
assert(w.isVisible())
|
|
|
|
})
|
|
|
|
|
|
|
|
it('emits when window is shown', function (done) {
|
|
|
|
this.timeout(10000)
|
|
|
|
w.once('show', function () {
|
|
|
|
assert.equal(w.isVisible(), true)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
w.show()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('BrowserWindow.hide()', function () {
|
2016-03-08 22:11:17 +03:00
|
|
|
if (isCI) {
|
2016-03-25 23:03:49 +03:00
|
|
|
return
|
2016-03-08 22:11:17 +03:00
|
|
|
}
|
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
it('should defocus on window', function () {
|
|
|
|
w.hide()
|
|
|
|
assert(!w.isFocused())
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should make the window not visible', function () {
|
|
|
|
w.show()
|
|
|
|
w.hide()
|
|
|
|
assert(!w.isVisible())
|
|
|
|
})
|
|
|
|
|
|
|
|
it('emits when window is hidden', function (done) {
|
|
|
|
this.timeout(10000)
|
|
|
|
w.show()
|
|
|
|
w.once('hide', function () {
|
|
|
|
assert.equal(w.isVisible(), false)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
w.hide()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('BrowserWindow.showInactive()', function () {
|
|
|
|
it('should not focus on window', function () {
|
|
|
|
w.showInactive()
|
|
|
|
assert(!w.isFocused())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('BrowserWindow.focus()', function () {
|
|
|
|
it('does not make the window become visible', function () {
|
|
|
|
assert.equal(w.isVisible(), false)
|
|
|
|
w.focus()
|
|
|
|
assert.equal(w.isVisible(), false)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('BrowserWindow.blur()', function () {
|
|
|
|
it('removes focus from window', function () {
|
|
|
|
w.blur()
|
|
|
|
assert(!w.isFocused())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('BrowserWindow.capturePage(rect, callback)', function () {
|
|
|
|
it('calls the callback with a Buffer', function (done) {
|
2016-02-09 21:12:45 +03:00
|
|
|
w.capturePage({
|
2016-01-12 05:40:23 +03:00
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
width: 100,
|
|
|
|
height: 100
|
2016-03-25 23:03:49 +03:00
|
|
|
}, function (image) {
|
|
|
|
assert.equal(image.isEmpty(), true)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('BrowserWindow.setSize(width, height)', function () {
|
|
|
|
it('sets the window size', function (done) {
|
|
|
|
var size = [300, 400]
|
|
|
|
w.once('resize', function () {
|
|
|
|
var newSize = w.getSize()
|
|
|
|
assert.equal(newSize[0], size[0])
|
|
|
|
assert.equal(newSize[1], size[1])
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
w.setSize(size[0], size[1])
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2016-07-12 20:19:34 +03:00
|
|
|
describe('BrowserWindow.setMinimum/MaximumSize(width, height)', function () {
|
|
|
|
it('sets the maximum and minimum size of the window', function () {
|
|
|
|
assert.deepEqual(w.getMinimumSize(), [0, 0])
|
|
|
|
assert.deepEqual(w.getMaximumSize(), [0, 0])
|
|
|
|
|
|
|
|
w.setMinimumSize(100, 100)
|
|
|
|
assert.deepEqual(w.getMinimumSize(), [100, 100])
|
|
|
|
assert.deepEqual(w.getMaximumSize(), [0, 0])
|
|
|
|
|
|
|
|
w.setMaximumSize(900, 600)
|
|
|
|
assert.deepEqual(w.getMinimumSize(), [100, 100])
|
|
|
|
assert.deepEqual(w.getMaximumSize(), [900, 600])
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2016-05-29 15:47:42 +03:00
|
|
|
describe('BrowserWindow.setAspectRatio(ratio)', function () {
|
|
|
|
it('resets the behaviour when passing in 0', function (done) {
|
|
|
|
var size = [300, 400]
|
2016-06-29 19:37:10 +03:00
|
|
|
w.setAspectRatio(1 / 2)
|
2016-05-29 15:47:42 +03:00
|
|
|
w.setAspectRatio(0)
|
|
|
|
w.once('resize', function () {
|
|
|
|
var newSize = w.getSize()
|
|
|
|
assert.equal(newSize[0], size[0])
|
|
|
|
assert.equal(newSize[1], size[1])
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
w.setSize(size[0], size[1])
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
describe('BrowserWindow.setPosition(x, y)', function () {
|
|
|
|
it('sets the window position', function (done) {
|
|
|
|
var pos = [10, 10]
|
|
|
|
w.once('move', function () {
|
|
|
|
var newPos = w.getPosition()
|
|
|
|
assert.equal(newPos[0], pos[0])
|
|
|
|
assert.equal(newPos[1], pos[1])
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
w.setPosition(pos[0], pos[1])
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('BrowserWindow.setContentSize(width, height)', function () {
|
|
|
|
it('sets the content size', function () {
|
|
|
|
var size = [400, 400]
|
|
|
|
w.setContentSize(size[0], size[1])
|
|
|
|
var after = w.getContentSize()
|
|
|
|
assert.equal(after[0], size[0])
|
|
|
|
assert.equal(after[1], size[1])
|
|
|
|
})
|
|
|
|
|
2016-08-04 22:34:09 +03:00
|
|
|
it('works for a frameless window', function () {
|
2016-03-25 23:03:49 +03:00
|
|
|
w.destroy()
|
2016-01-12 05:40:23 +03:00
|
|
|
w = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
frame: false,
|
2016-08-04 22:54:45 +03:00
|
|
|
width: 400,
|
|
|
|
height: 400
|
2016-03-25 23:03:49 +03:00
|
|
|
})
|
|
|
|
var size = [400, 400]
|
|
|
|
w.setContentSize(size[0], size[1])
|
|
|
|
var after = w.getContentSize()
|
|
|
|
assert.equal(after[0], size[0])
|
|
|
|
assert.equal(after[1], size[1])
|
2016-08-04 22:34:09 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('BrowserWindow.setContentBounds(bounds)', function () {
|
2016-08-04 22:54:45 +03:00
|
|
|
it('sets the content size and position', function (done) {
|
2016-08-04 23:02:41 +03:00
|
|
|
var bounds = {x: 10, y: 10, width: 250, height: 250}
|
2016-08-04 22:54:45 +03:00
|
|
|
w.once('resize', function () {
|
|
|
|
assert.deepEqual(w.getContentBounds(), bounds)
|
|
|
|
done()
|
|
|
|
})
|
2016-08-04 22:34:09 +03:00
|
|
|
w.setContentBounds(bounds)
|
|
|
|
})
|
|
|
|
|
2016-08-04 22:54:45 +03:00
|
|
|
it('works for a frameless window', function (done) {
|
2016-08-04 22:34:09 +03:00
|
|
|
w.destroy()
|
|
|
|
w = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
frame: false,
|
|
|
|
width: 300,
|
|
|
|
height: 300
|
|
|
|
})
|
2016-08-04 23:02:41 +03:00
|
|
|
var bounds = {x: 10, y: 10, width: 250, height: 250}
|
2016-08-04 22:54:45 +03:00
|
|
|
w.once('resize', function () {
|
|
|
|
assert.deepEqual(w.getContentBounds(), bounds)
|
|
|
|
done()
|
|
|
|
})
|
2016-08-04 22:34:09 +03:00
|
|
|
w.setContentBounds(bounds)
|
2016-03-25 23:03:49 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2016-06-17 00:57:07 +03:00
|
|
|
describe('BrowserWindow.setProgressBar(progress)', function () {
|
|
|
|
it('sets the progress', function () {
|
|
|
|
assert.doesNotThrow(function () {
|
|
|
|
if (process.platform === 'darwin') {
|
|
|
|
app.dock.setIcon(path.join(fixtures, 'assets', 'logo.png'))
|
|
|
|
}
|
2016-06-29 19:37:10 +03:00
|
|
|
w.setProgressBar(0.5)
|
2016-06-17 01:01:37 +03:00
|
|
|
|
|
|
|
if (process.platform === 'darwin') {
|
|
|
|
app.dock.setIcon(null)
|
|
|
|
}
|
|
|
|
w.setProgressBar(-1)
|
2016-06-17 00:57:07 +03:00
|
|
|
})
|
|
|
|
})
|
2016-08-09 01:44:48 +03:00
|
|
|
|
|
|
|
it('sets the progress using "paused" mode', function () {
|
|
|
|
assert.doesNotThrow(function () {
|
|
|
|
w.setProgressBar(0.5, {mode: 'paused'})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('sets the progress using "error" mode', function () {
|
|
|
|
assert.doesNotThrow(function () {
|
|
|
|
w.setProgressBar(0.5, {mode: 'error'})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('sets the progress using "normal" mode', function () {
|
|
|
|
assert.doesNotThrow(function () {
|
|
|
|
w.setProgressBar(0.5, {mode: 'normal'})
|
|
|
|
})
|
|
|
|
})
|
2016-06-17 00:57:07 +03:00
|
|
|
})
|
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
describe('BrowserWindow.fromId(id)', function () {
|
|
|
|
it('returns the window with id', function () {
|
|
|
|
assert.equal(w.id, BrowserWindow.fromId(w.id).id)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('"useContentSize" option', function () {
|
|
|
|
it('make window created with content size when used', function () {
|
|
|
|
w.destroy()
|
2016-01-12 05:40:23 +03:00
|
|
|
w = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
width: 400,
|
|
|
|
height: 400,
|
|
|
|
useContentSize: true
|
2016-03-25 23:03:49 +03:00
|
|
|
})
|
|
|
|
var contentSize = w.getContentSize()
|
|
|
|
assert.equal(contentSize[0], 400)
|
|
|
|
assert.equal(contentSize[1], 400)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('make window created with window size when not used', function () {
|
|
|
|
var size = w.getSize()
|
|
|
|
assert.equal(size[0], 400)
|
|
|
|
assert.equal(size[1], 400)
|
|
|
|
})
|
|
|
|
|
2016-08-04 22:34:09 +03:00
|
|
|
it('works for a frameless window', function () {
|
2016-03-25 23:03:49 +03:00
|
|
|
w.destroy()
|
2016-01-12 05:40:23 +03:00
|
|
|
w = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
frame: false,
|
|
|
|
width: 400,
|
|
|
|
height: 400,
|
|
|
|
useContentSize: true
|
2016-03-25 23:03:49 +03:00
|
|
|
})
|
|
|
|
var contentSize = w.getContentSize()
|
|
|
|
assert.equal(contentSize[0], 400)
|
|
|
|
assert.equal(contentSize[1], 400)
|
|
|
|
var size = w.getSize()
|
|
|
|
assert.equal(size[0], 400)
|
|
|
|
assert.equal(size[1], 400)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('"title-bar-style" option', function () {
|
2016-01-12 05:40:23 +03:00
|
|
|
if (process.platform !== 'darwin') {
|
2016-03-25 23:03:49 +03:00
|
|
|
return
|
2016-01-12 05:40:23 +03:00
|
|
|
}
|
|
|
|
if (parseInt(os.release().split('.')[0]) < 14) {
|
2016-03-25 23:03:49 +03:00
|
|
|
return
|
2016-01-12 05:40:23 +03:00
|
|
|
}
|
2016-02-09 21:12:45 +03:00
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
it('creates browser window with hidden title bar', function () {
|
|
|
|
w.destroy()
|
2016-01-12 05:40:23 +03:00
|
|
|
w = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
width: 400,
|
|
|
|
height: 400,
|
|
|
|
titleBarStyle: 'hidden'
|
2016-03-25 23:03:49 +03:00
|
|
|
})
|
|
|
|
var contentSize = w.getContentSize()
|
|
|
|
assert.equal(contentSize[1], 400)
|
|
|
|
})
|
2016-02-09 21:12:45 +03:00
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
it('creates browser window with hidden inset title bar', function () {
|
|
|
|
w.destroy()
|
2016-01-12 05:40:23 +03:00
|
|
|
w = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
width: 400,
|
|
|
|
height: 400,
|
|
|
|
titleBarStyle: 'hidden-inset'
|
2016-03-25 23:03:49 +03:00
|
|
|
})
|
|
|
|
var contentSize = w.getContentSize()
|
|
|
|
assert.equal(contentSize[1], 400)
|
|
|
|
})
|
|
|
|
})
|
2016-02-09 21:12:45 +03:00
|
|
|
|
2016-06-29 19:37:10 +03:00
|
|
|
describe('enableLargerThanScreen" option', function () {
|
2016-01-12 05:40:23 +03:00
|
|
|
if (process.platform === 'linux') {
|
2016-03-25 23:03:49 +03:00
|
|
|
return
|
2016-01-12 05:40:23 +03:00
|
|
|
}
|
2016-02-09 21:12:45 +03:00
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
beforeEach(function () {
|
|
|
|
w.destroy()
|
2016-02-09 21:12:45 +03:00
|
|
|
w = new BrowserWindow({
|
2016-01-12 05:40:23 +03:00
|
|
|
show: true,
|
|
|
|
width: 400,
|
|
|
|
height: 400,
|
|
|
|
enableLargerThanScreen: true
|
2016-03-25 23:03:49 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('can move the window out of screen', function () {
|
|
|
|
w.setPosition(-10, -10)
|
|
|
|
var after = w.getPosition()
|
|
|
|
assert.equal(after[0], -10)
|
|
|
|
assert.equal(after[1], -10)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('can set the window larger than screen', function () {
|
|
|
|
var size = screen.getPrimaryDisplay().size
|
|
|
|
size.width += 100
|
|
|
|
size.height += 100
|
|
|
|
w.setSize(size.width, size.height)
|
|
|
|
var after = w.getSize()
|
|
|
|
assert.equal(after[0], size.width)
|
|
|
|
assert.equal(after[1], size.height)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('"web-preferences" option', function () {
|
|
|
|
afterEach(function () {
|
|
|
|
ipcMain.removeAllListeners('answer')
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('"preload" option', function () {
|
|
|
|
it('loads the script before other scripts in window', function (done) {
|
|
|
|
var preload = path.join(fixtures, 'module', 'set-global.js')
|
|
|
|
ipcMain.once('answer', function (event, test) {
|
|
|
|
assert.equal(test, 'preload')
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
w.destroy()
|
2016-01-12 05:40:23 +03:00
|
|
|
w = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
webPreferences: {
|
|
|
|
preload: preload
|
|
|
|
}
|
2016-03-25 23:03:49 +03:00
|
|
|
})
|
|
|
|
w.loadURL('file://' + path.join(fixtures, 'api', 'preload.html'))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('"node-integration" option', function () {
|
|
|
|
it('disables node integration when specified to false', function (done) {
|
|
|
|
var preload = path.join(fixtures, 'module', 'send-later.js')
|
|
|
|
ipcMain.once('answer', function (event, test) {
|
|
|
|
assert.equal(test, 'undefined')
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
w.destroy()
|
2016-01-12 05:40:23 +03:00
|
|
|
w = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
webPreferences: {
|
|
|
|
preload: preload,
|
|
|
|
nodeIntegration: false
|
|
|
|
}
|
2016-03-25 23:03:49 +03:00
|
|
|
})
|
|
|
|
w.loadURL('file://' + path.join(fixtures, 'api', 'blank.html'))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('beforeunload handler', function () {
|
2016-05-23 07:28:16 +03:00
|
|
|
it('returning undefined would not prevent close', function (done) {
|
2016-08-03 23:10:26 +03:00
|
|
|
w.once('closed', function () {
|
2016-03-25 23:03:49 +03:00
|
|
|
done()
|
|
|
|
})
|
2016-05-23 07:28:16 +03:00
|
|
|
w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-undefined.html'))
|
2016-03-25 23:03:49 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
it('returning false would prevent close', function (done) {
|
2016-08-03 23:10:26 +03:00
|
|
|
w.once('onbeforeunload', function () {
|
2016-03-25 23:03:49 +03:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-false.html'))
|
|
|
|
})
|
|
|
|
|
|
|
|
it('returning empty string would prevent close', function (done) {
|
2016-08-03 23:10:26 +03:00
|
|
|
w.once('onbeforeunload', function () {
|
2016-03-25 23:03:49 +03:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-empty-string.html'))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('new-window event', function () {
|
2016-01-12 05:40:23 +03:00
|
|
|
if (isCI && process.platform === 'darwin') {
|
2016-03-25 23:03:49 +03:00
|
|
|
return
|
2016-01-12 05:40:23 +03:00
|
|
|
}
|
2016-02-09 21:12:45 +03:00
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
it('emits when window.open is called', function (done) {
|
|
|
|
w.webContents.once('new-window', function (e, url, frameName) {
|
|
|
|
e.preventDefault()
|
|
|
|
assert.equal(url, 'http://host/')
|
|
|
|
assert.equal(frameName, 'host')
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
w.loadURL('file://' + fixtures + '/pages/window-open.html')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('emits when link with target is called', function (done) {
|
|
|
|
this.timeout(10000)
|
|
|
|
w.webContents.once('new-window', function (e, url, frameName) {
|
|
|
|
e.preventDefault()
|
|
|
|
assert.equal(url, 'http://host/')
|
|
|
|
assert.equal(frameName, 'target')
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
w.loadURL('file://' + fixtures + '/pages/target-name.html')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('maximize event', function () {
|
2016-01-12 05:40:23 +03:00
|
|
|
if (isCI) {
|
2016-03-25 23:03:49 +03:00
|
|
|
return
|
2016-01-12 05:40:23 +03:00
|
|
|
}
|
2016-02-09 21:12:45 +03:00
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
it('emits when window is maximized', function (done) {
|
|
|
|
this.timeout(10000)
|
|
|
|
w.once('maximize', function () {
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
w.show()
|
|
|
|
w.maximize()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('unmaximize event', function () {
|
2016-01-12 05:40:23 +03:00
|
|
|
if (isCI) {
|
2016-03-25 23:03:49 +03:00
|
|
|
return
|
2016-01-12 05:40:23 +03:00
|
|
|
}
|
2016-02-09 21:12:45 +03:00
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
it('emits when window is unmaximized', function (done) {
|
|
|
|
this.timeout(10000)
|
|
|
|
w.once('unmaximize', function () {
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
w.show()
|
|
|
|
w.maximize()
|
|
|
|
w.unmaximize()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('minimize event', function () {
|
2016-01-12 05:40:23 +03:00
|
|
|
if (isCI) {
|
2016-03-25 23:03:49 +03:00
|
|
|
return
|
2016-01-12 05:40:23 +03:00
|
|
|
}
|
2016-02-09 21:12:45 +03:00
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
it('emits when window is minimized', function (done) {
|
|
|
|
this.timeout(10000)
|
|
|
|
w.once('minimize', function () {
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
w.show()
|
|
|
|
w.minimize()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('beginFrameSubscription method', function () {
|
2016-06-26 05:53:58 +03:00
|
|
|
// This test is too slow, only test it on CI.
|
|
|
|
if (!isCI) return
|
2016-06-25 19:23:40 +03:00
|
|
|
|
2016-06-26 05:53:58 +03:00
|
|
|
this.timeout(20000)
|
|
|
|
|
|
|
|
it('subscribes to frame updates', function (done) {
|
|
|
|
let called = false
|
2016-06-25 19:23:40 +03:00
|
|
|
w.loadURL('file://' + fixtures + '/api/frame-subscriber.html')
|
|
|
|
w.webContents.on('dom-ready', function () {
|
|
|
|
w.webContents.beginFrameSubscription(function (data) {
|
2016-06-26 05:53:58 +03:00
|
|
|
// This callback might be called twice.
|
|
|
|
if (called) return
|
|
|
|
called = true
|
|
|
|
|
2016-06-25 19:23:40 +03:00
|
|
|
assert.notEqual(data.length, 0)
|
|
|
|
w.webContents.endFrameSubscription()
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('subscribes to frame updates (only dirty rectangle)', function (done) {
|
2016-06-26 05:53:58 +03:00
|
|
|
let called = false
|
2016-06-25 19:23:40 +03:00
|
|
|
w.loadURL('file://' + fixtures + '/api/frame-subscriber.html')
|
|
|
|
w.webContents.on('dom-ready', function () {
|
|
|
|
w.webContents.beginFrameSubscription(true, function (data) {
|
2016-06-26 05:53:58 +03:00
|
|
|
// This callback might be called twice.
|
|
|
|
if (called) return
|
|
|
|
called = true
|
|
|
|
|
2016-06-25 19:23:40 +03:00
|
|
|
assert.notEqual(data.length, 0)
|
|
|
|
w.webContents.endFrameSubscription()
|
|
|
|
done()
|
|
|
|
})
|
2016-03-25 23:03:49 +03:00
|
|
|
})
|
|
|
|
})
|
2016-06-25 19:23:40 +03:00
|
|
|
|
|
|
|
it('throws error when subscriber is not well defined', function (done) {
|
|
|
|
w.loadURL('file://' + fixtures + '/api/frame-subscriber.html')
|
2016-06-26 05:53:58 +03:00
|
|
|
try {
|
2016-06-25 19:23:40 +03:00
|
|
|
w.webContents.beginFrameSubscription(true, true)
|
2016-06-29 19:37:10 +03:00
|
|
|
} catch (e) {
|
2016-06-25 19:23:40 +03:00
|
|
|
done()
|
|
|
|
}
|
|
|
|
})
|
2016-03-25 23:03:49 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('savePage method', function () {
|
|
|
|
const savePageDir = path.join(fixtures, 'save_page')
|
|
|
|
const savePageHtmlPath = path.join(savePageDir, 'save_page.html')
|
|
|
|
const savePageJsPath = path.join(savePageDir, 'save_page_files', 'test.js')
|
|
|
|
const savePageCssPath = path.join(savePageDir, 'save_page_files', 'test.css')
|
|
|
|
|
|
|
|
after(function () {
|
2016-01-13 12:12:47 +03:00
|
|
|
try {
|
2016-03-25 23:03:49 +03:00
|
|
|
fs.unlinkSync(savePageCssPath)
|
|
|
|
fs.unlinkSync(savePageJsPath)
|
|
|
|
fs.unlinkSync(savePageHtmlPath)
|
|
|
|
fs.rmdirSync(path.join(savePageDir, 'save_page_files'))
|
|
|
|
fs.rmdirSync(savePageDir)
|
2016-01-13 12:12:47 +03:00
|
|
|
} catch (e) {
|
2016-01-19 22:31:47 +03:00
|
|
|
// Ignore error
|
2016-01-13 12:12:47 +03:00
|
|
|
}
|
2016-03-25 23:03:49 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should save page to disk', function (done) {
|
|
|
|
w.webContents.on('did-finish-load', function () {
|
|
|
|
w.webContents.savePage(savePageHtmlPath, 'HTMLComplete', function (error) {
|
|
|
|
assert.equal(error, null)
|
|
|
|
assert(fs.existsSync(savePageHtmlPath))
|
|
|
|
assert(fs.existsSync(savePageJsPath))
|
|
|
|
assert(fs.existsSync(savePageCssPath))
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
w.loadURL('file://' + fixtures + '/pages/save_page/index.html')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('BrowserWindow options argument is optional', function () {
|
|
|
|
it('should create a window with default size (800x600)', function () {
|
|
|
|
w.destroy()
|
|
|
|
w = new BrowserWindow()
|
|
|
|
var size = w.getSize()
|
|
|
|
assert.equal(size[0], 800)
|
|
|
|
assert.equal(size[1], 600)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('window states', function () {
|
2016-08-15 22:30:26 +03:00
|
|
|
it('does not resize frameless windows when states change', function () {
|
|
|
|
w.destroy()
|
|
|
|
w = new BrowserWindow({
|
|
|
|
frame: false,
|
|
|
|
width: 300,
|
|
|
|
height: 200,
|
|
|
|
show: false
|
|
|
|
})
|
|
|
|
|
|
|
|
w.setMinimizable(false)
|
|
|
|
w.setMinimizable(true)
|
|
|
|
assert.deepEqual(w.getSize(), [300, 200])
|
|
|
|
|
|
|
|
w.setResizable(false)
|
|
|
|
w.setResizable(true)
|
|
|
|
assert.deepEqual(w.getSize(), [300, 200])
|
|
|
|
|
|
|
|
w.setMaximizable(false)
|
|
|
|
w.setMaximizable(true)
|
|
|
|
assert.deepEqual(w.getSize(), [300, 200])
|
|
|
|
|
|
|
|
w.setFullScreenable(false)
|
|
|
|
w.setFullScreenable(true)
|
|
|
|
assert.deepEqual(w.getSize(), [300, 200])
|
|
|
|
|
|
|
|
w.setClosable(false)
|
|
|
|
w.setClosable(true)
|
|
|
|
assert.deepEqual(w.getSize(), [300, 200])
|
|
|
|
})
|
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
describe('resizable state', function () {
|
|
|
|
it('can be changed with resizable option', function () {
|
|
|
|
w.destroy()
|
|
|
|
w = new BrowserWindow({show: false, resizable: false})
|
|
|
|
assert.equal(w.isResizable(), false)
|
2016-08-05 03:10:34 +03:00
|
|
|
|
|
|
|
if (process.platform === 'darwin') {
|
|
|
|
assert.equal(w.isMaximizable(), true)
|
|
|
|
}
|
2016-03-25 23:03:49 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
it('can be changed with setResizable method', function () {
|
|
|
|
assert.equal(w.isResizable(), true)
|
|
|
|
w.setResizable(false)
|
|
|
|
assert.equal(w.isResizable(), false)
|
|
|
|
w.setResizable(true)
|
|
|
|
assert.equal(w.isResizable(), true)
|
|
|
|
})
|
|
|
|
})
|
2016-04-20 08:05:09 +03:00
|
|
|
|
|
|
|
describe('loading main frame state', function () {
|
|
|
|
it('is true when the main frame is loading', function (done) {
|
2016-06-29 19:37:10 +03:00
|
|
|
w.webContents.on('did-start-loading', function () {
|
2016-04-20 08:05:09 +03:00
|
|
|
assert.equal(w.webContents.isLoadingMainFrame(), true)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
w.webContents.loadURL(server.url)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('is false when only a subframe is loading', function (done) {
|
2016-06-29 19:37:10 +03:00
|
|
|
w.webContents.once('did-finish-load', function () {
|
2016-04-20 08:05:09 +03:00
|
|
|
assert.equal(w.webContents.isLoadingMainFrame(), false)
|
2016-06-29 19:37:10 +03:00
|
|
|
w.webContents.on('did-start-loading', function () {
|
2016-04-20 08:05:09 +03:00
|
|
|
assert.equal(w.webContents.isLoadingMainFrame(), false)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
w.webContents.executeJavaScript(`
|
|
|
|
var iframe = document.createElement('iframe')
|
|
|
|
iframe.src = '${server.url}/page2'
|
|
|
|
document.body.appendChild(iframe)
|
|
|
|
`)
|
|
|
|
})
|
|
|
|
w.webContents.loadURL(server.url)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('is true when navigating to pages from the same origin', function (done) {
|
2016-06-29 19:37:10 +03:00
|
|
|
w.webContents.once('did-finish-load', function () {
|
2016-04-20 08:05:09 +03:00
|
|
|
assert.equal(w.webContents.isLoadingMainFrame(), false)
|
2016-06-29 19:37:10 +03:00
|
|
|
w.webContents.on('did-start-loading', function () {
|
2016-04-20 08:05:09 +03:00
|
|
|
assert.equal(w.webContents.isLoadingMainFrame(), true)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
w.webContents.loadURL(`${server.url}/page2`)
|
|
|
|
})
|
|
|
|
w.webContents.loadURL(server.url)
|
|
|
|
})
|
|
|
|
})
|
2016-03-25 23:03:49 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('window states (excluding Linux)', function () {
|
2016-01-23 14:35:30 +03:00
|
|
|
// Not implemented on Linux.
|
2016-03-29 03:16:08 +03:00
|
|
|
if (process.platform === 'linux') return
|
2016-03-25 23:03:49 +03:00
|
|
|
|
|
|
|
describe('movable state', function () {
|
|
|
|
it('can be changed with movable option', function () {
|
|
|
|
w.destroy()
|
|
|
|
w = new BrowserWindow({show: false, movable: false})
|
|
|
|
assert.equal(w.isMovable(), false)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('can be changed with setMovable method', function () {
|
|
|
|
assert.equal(w.isMovable(), true)
|
|
|
|
w.setMovable(false)
|
|
|
|
assert.equal(w.isMovable(), false)
|
|
|
|
w.setMovable(true)
|
|
|
|
assert.equal(w.isMovable(), true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('minimizable state', function () {
|
|
|
|
it('can be changed with minimizable option', function () {
|
|
|
|
w.destroy()
|
|
|
|
w = new BrowserWindow({show: false, minimizable: false})
|
|
|
|
assert.equal(w.isMinimizable(), false)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('can be changed with setMinimizable method', function () {
|
|
|
|
assert.equal(w.isMinimizable(), true)
|
|
|
|
w.setMinimizable(false)
|
|
|
|
assert.equal(w.isMinimizable(), false)
|
|
|
|
w.setMinimizable(true)
|
|
|
|
assert.equal(w.isMinimizable(), true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('maximizable state', function () {
|
|
|
|
it('can be changed with maximizable option', function () {
|
|
|
|
w.destroy()
|
|
|
|
w = new BrowserWindow({show: false, maximizable: false})
|
|
|
|
assert.equal(w.isMaximizable(), false)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('can be changed with setMaximizable method', function () {
|
|
|
|
assert.equal(w.isMaximizable(), true)
|
|
|
|
w.setMaximizable(false)
|
|
|
|
assert.equal(w.isMaximizable(), false)
|
|
|
|
w.setMaximizable(true)
|
|
|
|
assert.equal(w.isMaximizable(), true)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('is not affected when changing other states', function () {
|
|
|
|
w.setMaximizable(false)
|
|
|
|
assert.equal(w.isMaximizable(), false)
|
|
|
|
w.setMinimizable(false)
|
|
|
|
assert.equal(w.isMaximizable(), false)
|
|
|
|
w.setClosable(false)
|
|
|
|
assert.equal(w.isMaximizable(), false)
|
2016-08-05 01:06:49 +03:00
|
|
|
|
|
|
|
w.setMaximizable(true)
|
|
|
|
assert.equal(w.isMaximizable(), true)
|
|
|
|
w.setClosable(true)
|
|
|
|
assert.equal(w.isMaximizable(), true)
|
|
|
|
w.setFullScreenable(false)
|
|
|
|
assert.equal(w.isMaximizable(), true)
|
|
|
|
w.setResizable(false)
|
|
|
|
assert.equal(w.isMaximizable(), true)
|
2016-03-25 23:03:49 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('fullscreenable state', function () {
|
2016-06-18 16:26:26 +03:00
|
|
|
// Only implemented on macOS.
|
2016-03-29 03:16:08 +03:00
|
|
|
if (process.platform !== 'darwin') return
|
2016-03-25 23:03:49 +03:00
|
|
|
|
|
|
|
it('can be changed with fullscreenable option', function () {
|
|
|
|
w.destroy()
|
|
|
|
w = new BrowserWindow({show: false, fullscreenable: false})
|
|
|
|
assert.equal(w.isFullScreenable(), false)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('can be changed with setFullScreenable method', function () {
|
|
|
|
assert.equal(w.isFullScreenable(), true)
|
|
|
|
w.setFullScreenable(false)
|
|
|
|
assert.equal(w.isFullScreenable(), false)
|
|
|
|
w.setFullScreenable(true)
|
|
|
|
assert.equal(w.isFullScreenable(), true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('closable state', function () {
|
|
|
|
it('can be changed with closable option', function () {
|
|
|
|
w.destroy()
|
|
|
|
w = new BrowserWindow({show: false, closable: false})
|
|
|
|
assert.equal(w.isClosable(), false)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('can be changed with setClosable method', function () {
|
|
|
|
assert.equal(w.isClosable(), true)
|
|
|
|
w.setClosable(false)
|
|
|
|
assert.equal(w.isClosable(), false)
|
|
|
|
w.setClosable(true)
|
|
|
|
assert.equal(w.isClosable(), true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('hasShadow state', function () {
|
2016-01-23 15:03:56 +03:00
|
|
|
// On Window there is no shadow by default and it can not be changed
|
|
|
|
// dynamically.
|
2016-03-25 23:03:49 +03:00
|
|
|
it('can be changed with hasShadow option', function () {
|
|
|
|
w.destroy()
|
2016-03-29 03:16:08 +03:00
|
|
|
let hasShadow = process.platform !== 'darwin'
|
2016-03-25 23:03:49 +03:00
|
|
|
w = new BrowserWindow({show: false, hasShadow: hasShadow})
|
|
|
|
assert.equal(w.hasShadow(), hasShadow)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('can be changed with setHasShadow method', function () {
|
2016-03-29 03:16:08 +03:00
|
|
|
if (process.platform !== 'darwin') return
|
2016-03-25 23:03:49 +03:00
|
|
|
|
|
|
|
assert.equal(w.hasShadow(), true)
|
|
|
|
w.setHasShadow(false)
|
|
|
|
assert.equal(w.hasShadow(), false)
|
|
|
|
w.setHasShadow(true)
|
|
|
|
assert.equal(w.hasShadow(), true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2016-06-17 10:57:18 +03:00
|
|
|
describe('parent window', function () {
|
|
|
|
let c = null
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
if (c != null) c.destroy()
|
2016-06-19 06:10:25 +03:00
|
|
|
c = new BrowserWindow({show: false, parent: w})
|
2016-06-17 10:57:18 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
if (c != null) c.destroy()
|
|
|
|
c = null
|
|
|
|
})
|
|
|
|
|
2016-06-19 06:06:08 +03:00
|
|
|
describe('parent option', function () {
|
|
|
|
it('sets parent window', function () {
|
|
|
|
assert.equal(c.getParentWindow(), w)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('adds window to child windows of parent', function () {
|
|
|
|
assert.deepEqual(w.getChildWindows(), [c])
|
|
|
|
})
|
|
|
|
|
|
|
|
it('removes from child windows of parent when window is closed', function (done) {
|
|
|
|
c.once('closed', () => {
|
|
|
|
assert.deepEqual(w.getChildWindows(), [])
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
c.close()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2016-06-17 10:57:18 +03:00
|
|
|
describe('win.setParentWindow(parent)', function () {
|
2016-06-19 09:47:27 +03:00
|
|
|
if (process.platform === 'win32') return
|
2016-06-19 06:06:08 +03:00
|
|
|
|
2016-06-19 06:10:25 +03:00
|
|
|
beforeEach(function () {
|
|
|
|
if (c != null) c.destroy()
|
|
|
|
c = new BrowserWindow({show: false})
|
|
|
|
})
|
|
|
|
|
2016-06-17 10:57:18 +03:00
|
|
|
it('sets parent window', function () {
|
|
|
|
assert.equal(w.getParentWindow(), null)
|
|
|
|
assert.equal(c.getParentWindow(), null)
|
|
|
|
c.setParentWindow(w)
|
|
|
|
assert.equal(c.getParentWindow(), w)
|
|
|
|
c.setParentWindow(null)
|
|
|
|
assert.equal(c.getParentWindow(), null)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('adds window to child windows of parent', function () {
|
|
|
|
assert.deepEqual(w.getChildWindows(), [])
|
|
|
|
c.setParentWindow(w)
|
|
|
|
assert.deepEqual(w.getChildWindows(), [c])
|
|
|
|
c.setParentWindow(null)
|
|
|
|
assert.deepEqual(w.getChildWindows(), [])
|
|
|
|
})
|
|
|
|
|
|
|
|
it('removes from child windows of parent when window is closed', function (done) {
|
|
|
|
c.once('closed', () => {
|
|
|
|
assert.deepEqual(w.getChildWindows(), [])
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
c.setParentWindow(w)
|
|
|
|
c.close()
|
|
|
|
})
|
|
|
|
})
|
2016-06-18 03:51:37 +03:00
|
|
|
|
2016-06-20 08:49:24 +03:00
|
|
|
describe('modal option', function () {
|
|
|
|
// The isEnabled API is not reliable on macOS.
|
|
|
|
if (process.platform === 'darwin') return
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
if (c != null) c.destroy()
|
|
|
|
c = new BrowserWindow({show: false, parent: w, modal: true})
|
|
|
|
})
|
|
|
|
|
2016-06-18 03:51:37 +03:00
|
|
|
it('disables parent window', function () {
|
|
|
|
assert.equal(w.isEnabled(), true)
|
2016-06-20 08:49:24 +03:00
|
|
|
c.show()
|
2016-06-18 03:51:37 +03:00
|
|
|
assert.equal(w.isEnabled(), false)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('enables parent window when closed', function (done) {
|
|
|
|
c.once('closed', () => {
|
|
|
|
assert.equal(w.isEnabled(), true)
|
|
|
|
done()
|
|
|
|
})
|
2016-06-20 08:49:24 +03:00
|
|
|
c.show()
|
2016-06-18 03:51:37 +03:00
|
|
|
c.close()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('disables parent window recursively', function () {
|
2016-06-20 08:49:24 +03:00
|
|
|
let c2 = new BrowserWindow({show: false, parent: w, modal: true})
|
|
|
|
c.show()
|
2016-06-18 03:51:37 +03:00
|
|
|
assert.equal(w.isEnabled(), false)
|
2016-06-20 08:49:24 +03:00
|
|
|
c2.show()
|
|
|
|
assert.equal(w.isEnabled(), false)
|
|
|
|
c.destroy()
|
2016-06-18 03:51:37 +03:00
|
|
|
assert.equal(w.isEnabled(), false)
|
|
|
|
c2.destroy()
|
2016-06-20 08:49:24 +03:00
|
|
|
assert.equal(w.isEnabled(), true)
|
2016-06-18 03:51:37 +03:00
|
|
|
})
|
|
|
|
})
|
2016-06-17 10:57:18 +03:00
|
|
|
})
|
|
|
|
|
2016-03-25 23:03:49 +03:00
|
|
|
describe('window.webContents.send(channel, args...)', function () {
|
|
|
|
it('throws an error when the channel is missing', function () {
|
|
|
|
assert.throws(function () {
|
|
|
|
w.webContents.send()
|
|
|
|
}, 'Missing required channel argument')
|
|
|
|
|
|
|
|
assert.throws(function () {
|
|
|
|
w.webContents.send(null)
|
|
|
|
}, 'Missing required channel argument')
|
|
|
|
})
|
|
|
|
})
|
2016-02-16 07:30:42 +03:00
|
|
|
|
2016-02-04 04:08:46 +03:00
|
|
|
describe('dev tool extensions', function () {
|
2016-05-18 00:52:45 +03:00
|
|
|
describe('BrowserWindow.addDevToolsExtension', function () {
|
2016-08-04 00:12:05 +03:00
|
|
|
let showPanelIntevalId
|
2016-05-18 00:59:33 +03:00
|
|
|
this.timeout(10000)
|
|
|
|
|
2016-05-18 00:56:00 +03:00
|
|
|
beforeEach(function () {
|
|
|
|
BrowserWindow.removeDevToolsExtension('foo')
|
2016-06-10 19:24:00 +03:00
|
|
|
assert.equal(BrowserWindow.getDevToolsExtensions().hasOwnProperty('foo'), false)
|
2016-05-18 00:59:33 +03:00
|
|
|
|
|
|
|
var extensionPath = path.join(__dirname, 'fixtures', 'devtools-extensions', 'foo')
|
|
|
|
BrowserWindow.addDevToolsExtension(extensionPath)
|
2016-06-10 19:24:00 +03:00
|
|
|
assert.equal(BrowserWindow.getDevToolsExtensions().hasOwnProperty('foo'), true)
|
2016-05-18 00:59:33 +03:00
|
|
|
|
2016-05-18 01:05:27 +03:00
|
|
|
w.webContents.on('devtools-opened', function () {
|
2016-08-04 00:12:05 +03:00
|
|
|
showPanelIntevalId = setInterval(function () {
|
2016-05-18 00:59:33 +03:00
|
|
|
if (w && w.devToolsWebContents) {
|
2016-06-29 19:37:10 +03:00
|
|
|
var showLastPanel = function () {
|
2016-05-18 02:40:34 +03:00
|
|
|
var lastPanelId = WebInspector.inspectorView._tabbedPane._tabs.peekLast().id
|
2016-05-18 02:42:37 +03:00
|
|
|
WebInspector.inspectorView.showPanel(lastPanelId)
|
2016-06-29 19:37:10 +03:00
|
|
|
}
|
2016-06-29 19:42:12 +03:00
|
|
|
w.devToolsWebContents.executeJavaScript(`(${showLastPanel})()`)
|
2016-05-18 00:59:33 +03:00
|
|
|
} else {
|
2016-05-18 02:42:21 +03:00
|
|
|
clearInterval(showPanelIntevalId)
|
2016-05-18 00:59:33 +03:00
|
|
|
}
|
2016-05-18 02:40:34 +03:00
|
|
|
}, 100)
|
2016-05-18 00:59:33 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
w.loadURL('about:blank')
|
2016-05-18 00:56:00 +03:00
|
|
|
})
|
|
|
|
|
2016-08-04 00:12:05 +03:00
|
|
|
afterEach(function () {
|
|
|
|
clearInterval(showPanelIntevalId)
|
|
|
|
})
|
|
|
|
|
2016-06-09 19:44:49 +03:00
|
|
|
it('throws errors for missing manifest.json files', function () {
|
|
|
|
assert.throws(function () {
|
|
|
|
BrowserWindow.addDevToolsExtension(path.join(__dirname, 'does-not-exist'))
|
|
|
|
}, /ENOENT: no such file or directory/)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('throws errors for invalid manifest.json files', function () {
|
|
|
|
assert.throws(function () {
|
|
|
|
BrowserWindow.addDevToolsExtension(path.join(__dirname, 'fixtures', 'devtools-extensions', 'bad-manifest'))
|
|
|
|
}, /Unexpected token }/)
|
|
|
|
})
|
|
|
|
|
2016-06-28 23:02:03 +03:00
|
|
|
describe('when the devtools is docked', function () {
|
2016-05-18 00:56:00 +03:00
|
|
|
it('creates the extension', function (done) {
|
|
|
|
w.webContents.openDevTools({mode: 'bottom'})
|
|
|
|
|
|
|
|
ipcMain.once('answer', function (event, message) {
|
2016-06-07 00:36:01 +03:00
|
|
|
assert.equal(message.runtimeId, 'foo')
|
2016-06-07 20:38:01 +03:00
|
|
|
assert.equal(message.tabId, w.webContents.id)
|
2016-06-09 00:57:20 +03:00
|
|
|
assert.equal(message.i18nString, 'foo - bar (baz)')
|
2016-06-28 23:01:51 +03:00
|
|
|
assert.deepEqual(message.storageItems, {
|
|
|
|
local: {hello: 'world'},
|
|
|
|
sync: {foo: 'bar'}
|
|
|
|
})
|
2016-05-18 00:56:00 +03:00
|
|
|
done()
|
|
|
|
})
|
2016-05-18 00:52:45 +03:00
|
|
|
})
|
2016-05-18 00:56:00 +03:00
|
|
|
})
|
2016-05-18 00:52:45 +03:00
|
|
|
|
2016-05-18 00:56:00 +03:00
|
|
|
describe('when the devtools is undocked', function () {
|
|
|
|
it('creates the extension', function (done) {
|
|
|
|
w.webContents.openDevTools({mode: 'undocked'})
|
|
|
|
|
2016-06-07 00:36:01 +03:00
|
|
|
ipcMain.once('answer', function (event, message, extensionId) {
|
|
|
|
assert.equal(message.runtimeId, 'foo')
|
2016-06-07 20:38:01 +03:00
|
|
|
assert.equal(message.tabId, w.webContents.id)
|
2016-05-18 00:56:00 +03:00
|
|
|
done()
|
|
|
|
})
|
2016-05-18 00:52:45 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2016-06-08 19:34:41 +03:00
|
|
|
it('works when used with partitions', function (done) {
|
|
|
|
this.timeout(10000)
|
|
|
|
|
|
|
|
if (w != null) {
|
|
|
|
w.destroy()
|
|
|
|
}
|
|
|
|
w = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
webPreferences: {
|
|
|
|
partition: 'temp'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
var extensionPath = path.join(__dirname, 'fixtures', 'devtools-extensions', 'foo')
|
|
|
|
BrowserWindow.removeDevToolsExtension('foo')
|
|
|
|
BrowserWindow.addDevToolsExtension(extensionPath)
|
|
|
|
|
|
|
|
w.webContents.on('devtools-opened', function () {
|
|
|
|
var showPanelIntevalId = setInterval(function () {
|
|
|
|
if (w && w.devToolsWebContents) {
|
2016-06-29 19:37:10 +03:00
|
|
|
var showLastPanel = function () {
|
2016-06-08 19:34:41 +03:00
|
|
|
var lastPanelId = WebInspector.inspectorView._tabbedPane._tabs.peekLast().id
|
|
|
|
WebInspector.inspectorView.showPanel(lastPanelId)
|
2016-06-29 19:37:10 +03:00
|
|
|
}
|
2016-06-29 19:42:12 +03:00
|
|
|
w.devToolsWebContents.executeJavaScript(`(${showLastPanel})()`)
|
2016-06-08 19:34:41 +03:00
|
|
|
} else {
|
|
|
|
clearInterval(showPanelIntevalId)
|
|
|
|
}
|
|
|
|
}, 100)
|
|
|
|
})
|
|
|
|
|
|
|
|
w.loadURL('about:blank')
|
|
|
|
w.webContents.openDevTools({mode: 'bottom'})
|
|
|
|
|
|
|
|
ipcMain.once('answer', function (event, message) {
|
|
|
|
assert.equal(message.runtimeId, 'foo')
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2016-02-04 04:08:46 +03:00
|
|
|
it('serializes the registered extensions on quit', function () {
|
2016-03-25 23:03:49 +03:00
|
|
|
var extensionName = 'foo'
|
|
|
|
var extensionPath = path.join(__dirname, 'fixtures', 'devtools-extensions', extensionName)
|
|
|
|
var serializedPath = path.join(app.getPath('userData'), 'DevTools Extensions')
|
|
|
|
|
|
|
|
BrowserWindow.addDevToolsExtension(extensionPath)
|
|
|
|
app.emit('will-quit')
|
|
|
|
assert.deepEqual(JSON.parse(fs.readFileSync(serializedPath)), [extensionPath])
|
|
|
|
|
|
|
|
BrowserWindow.removeDevToolsExtension(extensionName)
|
|
|
|
app.emit('will-quit')
|
|
|
|
assert.equal(fs.existsSync(serializedPath), false)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('window.webContents.executeJavaScript', function () {
|
|
|
|
var expected = 'hello, world!'
|
|
|
|
var code = '(() => "' + expected + '")()'
|
|
|
|
|
|
|
|
it('doesnt throw when no calback is provided', function () {
|
|
|
|
const result = ipcRenderer.sendSync('executeJavaScript', code, false)
|
|
|
|
assert.equal(result, 'success')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('returns result when calback is provided', function (done) {
|
|
|
|
ipcRenderer.send('executeJavaScript', code, true)
|
|
|
|
ipcRenderer.once('executeJavaScript-response', function (event, result) {
|
|
|
|
assert.equal(result, expected)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
2016-04-18 20:33:56 +03:00
|
|
|
|
|
|
|
it('works after page load and during subframe load', function (done) {
|
2016-06-29 19:37:10 +03:00
|
|
|
w.webContents.once('did-finish-load', function () {
|
2016-04-18 20:33:56 +03:00
|
|
|
// initiate a sub-frame load, then try and execute script during it
|
|
|
|
w.webContents.executeJavaScript(`
|
|
|
|
var iframe = document.createElement('iframe')
|
2016-04-20 08:05:09 +03:00
|
|
|
iframe.src = '${server.url}/slow'
|
2016-04-18 20:33:56 +03:00
|
|
|
document.body.appendChild(iframe)
|
2016-06-29 19:37:10 +03:00
|
|
|
`, function () {
|
|
|
|
w.webContents.executeJavaScript('console.log(\'hello\')', function () {
|
2016-04-18 20:33:56 +03:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2016-04-20 08:05:09 +03:00
|
|
|
w.loadURL(server.url)
|
2016-04-18 20:33:56 +03:00
|
|
|
})
|
2016-04-27 23:24:08 +03:00
|
|
|
|
|
|
|
it('executes after page load', function (done) {
|
2016-06-29 19:37:10 +03:00
|
|
|
w.webContents.executeJavaScript(code, function (result) {
|
2016-04-27 23:24:08 +03:00
|
|
|
assert.equal(result, expected)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
w.loadURL(server.url)
|
|
|
|
})
|
2016-08-08 19:42:43 +03:00
|
|
|
|
|
|
|
it('works with result objects that have DOM class prototypes', function (done) {
|
|
|
|
w.webContents.executeJavaScript('document.location', function (result) {
|
|
|
|
assert.equal(result.origin, server.url)
|
|
|
|
assert.equal(result.protocol, 'http:')
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
w.loadURL(server.url)
|
|
|
|
})
|
2016-03-25 23:03:49 +03:00
|
|
|
})
|
2016-07-31 18:10:53 +03:00
|
|
|
|
|
|
|
describe('offscreen rendering', function () {
|
2016-08-03 04:27:55 +03:00
|
|
|
this.timeout(10000)
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
if (w != null) w.destroy()
|
|
|
|
w = new BrowserWindow({
|
2016-07-31 18:10:53 +03:00
|
|
|
show: false,
|
|
|
|
webPreferences: {
|
|
|
|
backgroundThrottling: false,
|
|
|
|
offscreen: true
|
|
|
|
}
|
|
|
|
})
|
2016-08-03 04:27:55 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
it('creates offscreen window', function (done) {
|
|
|
|
w.webContents.once('paint', function (event, rect, data, size) {
|
2016-07-31 18:10:53 +03:00
|
|
|
assert.notEqual(data.length, 0)
|
|
|
|
done()
|
|
|
|
})
|
2016-08-03 04:27:55 +03:00
|
|
|
w.loadURL('file://' + fixtures + '/api/offscreen-rendering.html')
|
2016-07-31 18:10:53 +03:00
|
|
|
})
|
|
|
|
|
2016-08-03 04:27:55 +03:00
|
|
|
describe('window.webContents.isOffscreen()', function () {
|
|
|
|
it('is true for offscreen type', function () {
|
|
|
|
w.loadURL('file://' + fixtures + '/api/offscreen-rendering.html')
|
|
|
|
assert.equal(w.webContents.isOffscreen(), true)
|
2016-07-31 18:10:53 +03:00
|
|
|
})
|
|
|
|
|
2016-08-03 04:27:55 +03:00
|
|
|
it('is false for regular window', function () {
|
|
|
|
let c = new BrowserWindow({show: false})
|
|
|
|
assert.equal(c.webContents.isOffscreen(), false)
|
|
|
|
c.destroy()
|
2016-07-31 18:10:53 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2016-08-03 04:27:55 +03:00
|
|
|
describe('window.webContents.isPainting()', function () {
|
|
|
|
it('returns whether is currently painting', function (done) {
|
|
|
|
w.webContents.once('paint', function (event, rect, data, size) {
|
|
|
|
assert.equal(w.webContents.isPainting(), true)
|
2016-07-31 18:10:53 +03:00
|
|
|
done()
|
|
|
|
})
|
2016-08-03 04:27:55 +03:00
|
|
|
w.loadURL('file://' + fixtures + '/api/offscreen-rendering.html')
|
2016-07-31 18:10:53 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2016-08-03 04:27:55 +03:00
|
|
|
describe('window.webContents.stopPainting()', function () {
|
2016-07-31 18:10:53 +03:00
|
|
|
it('stops painting', function (done) {
|
2016-08-03 04:27:55 +03:00
|
|
|
w.webContents.on('dom-ready', function () {
|
|
|
|
w.webContents.stopPainting()
|
|
|
|
assert.equal(w.webContents.isPainting(), false)
|
2016-07-31 18:10:53 +03:00
|
|
|
done()
|
|
|
|
})
|
2016-08-03 04:27:55 +03:00
|
|
|
w.loadURL('file://' + fixtures + '/api/offscreen-rendering.html')
|
2016-07-31 18:10:53 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2016-08-03 04:27:55 +03:00
|
|
|
describe('window.webContents.startPainting()', function () {
|
2016-07-31 18:10:53 +03:00
|
|
|
it('starts painting', function (done) {
|
2016-08-03 04:27:55 +03:00
|
|
|
w.webContents.on('dom-ready', function () {
|
|
|
|
w.webContents.stopPainting()
|
|
|
|
w.webContents.startPainting()
|
|
|
|
w.webContents.once('paint', function (event, rect, data, size) {
|
|
|
|
assert.equal(w.webContents.isPainting(), true)
|
2016-07-31 18:10:53 +03:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
2016-08-03 04:27:55 +03:00
|
|
|
w.loadURL('file://' + fixtures + '/api/offscreen-rendering.html')
|
2016-07-31 18:10:53 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2016-08-03 04:27:55 +03:00
|
|
|
describe('window.webContents.getFrameRate()', function () {
|
2016-07-31 18:10:53 +03:00
|
|
|
it('has default frame rate', function (done) {
|
2016-08-03 04:27:55 +03:00
|
|
|
w.webContents.once('paint', function (event, rect, data, size) {
|
|
|
|
assert.equal(w.webContents.getFrameRate(), 60)
|
2016-07-31 18:10:53 +03:00
|
|
|
done()
|
|
|
|
})
|
2016-08-03 07:04:36 +03:00
|
|
|
w.loadURL('file://' + fixtures + '/api/offscreen-rendering.html')
|
2016-07-31 18:10:53 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2016-08-03 04:27:55 +03:00
|
|
|
describe('window.webContents.setFrameRate(frameRate)', function () {
|
|
|
|
it('sets custom frame rate', function (done) {
|
|
|
|
w.webContents.on('dom-ready', function () {
|
|
|
|
w.webContents.setFrameRate(30)
|
|
|
|
w.webContents.once('paint', function (event, rect, data, size) {
|
|
|
|
assert.equal(w.webContents.getFrameRate(), 30)
|
2016-07-31 18:10:53 +03:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
2016-08-03 04:27:55 +03:00
|
|
|
w.loadURL('file://' + fixtures + '/api/offscreen-rendering.html')
|
2016-07-31 18:10:53 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2016-03-25 23:03:49 +03:00
|
|
|
})
|
2016-09-08 23:31:01 +03:00
|
|
|
|
2016-09-08 23:33:43 +03:00
|
|
|
const assertBoundsEqual = (expect, actual) => {
|
2016-09-08 23:31:01 +03:00
|
|
|
if (isIntegerScaleFactor()) {
|
|
|
|
assert.deepEqual(expect, actual)
|
2016-09-08 23:33:43 +03:00
|
|
|
} else if (Array.isArray(actual)) {
|
2016-09-08 23:31:01 +03:00
|
|
|
assertWithinDelta(expect[0], actual[0], 1, 'x')
|
|
|
|
assertWithinDelta(expect[1], actual[1], 1, 'y')
|
|
|
|
} else {
|
|
|
|
assertWithinDelta(expect.x, actual.x, 1, 'x')
|
|
|
|
assertWithinDelta(expect.y, actual.y, 1, 'y')
|
|
|
|
assertWithinDelta(expect.width, actual.width, 1, 'width')
|
|
|
|
assertWithinDelta(expect.height, actual.height, 1, 'height')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const assertWithinDelta = (expect, actual, delta, label) => {
|
|
|
|
const result = Math.abs(actual[0] - expect[0])
|
|
|
|
assert.ok(result <= delta, `${label} value of ${expect} was not within ${delta} of ${actual}`)
|
|
|
|
}
|
|
|
|
|
|
|
|
const isIntegerScaleFactor = () => {
|
|
|
|
const {scaleFactor} = screen.getPrimaryDisplay()
|
|
|
|
return Math.round(scaleFactor) === scaleFactor
|
|
|
|
}
|