2016-07-14 16:10:40 +00:00
|
|
|
'use strict'
|
|
|
|
|
2018-11-08 15:57:28 +00:00
|
|
|
const ChildProcess = require('child_process')
|
2018-09-18 18:00:31 +00:00
|
|
|
const fs = require('fs')
|
2017-02-15 22:14:40 +00:00
|
|
|
const http = require('http')
|
2016-07-14 16:10:40 +00:00
|
|
|
const path = require('path')
|
2018-09-13 16:10:51 +00:00
|
|
|
const { closeWindow } = require('./window-helpers')
|
|
|
|
const { emittedOnce } = require('./events-helpers')
|
2018-07-12 11:35:11 +00:00
|
|
|
const chai = require('chai')
|
|
|
|
const dirtyChai = require('dirty-chai')
|
2016-07-14 16:10:40 +00:00
|
|
|
|
2019-03-18 19:37:06 +00:00
|
|
|
const features = process.electronBinding('features')
|
2018-09-27 15:41:09 +00:00
|
|
|
const { ipcRenderer, remote, clipboard } = require('electron')
|
2018-09-13 16:10:51 +00:00
|
|
|
const { BrowserWindow, webContents, ipcMain, session } = remote
|
|
|
|
const { expect } = chai
|
2016-07-14 16:17:16 +00:00
|
|
|
|
2016-07-14 16:33:16 +00:00
|
|
|
const isCi = remote.getGlobal('isCi')
|
2016-07-14 16:10:40 +00:00
|
|
|
|
2018-07-12 11:35:11 +00:00
|
|
|
chai.use(dirtyChai)
|
|
|
|
|
2017-11-23 22:22:43 +00:00
|
|
|
/* The whole webContents API doesn't use standard callbacks */
|
|
|
|
/* eslint-disable standard/no-callback-literal */
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('webContents module', () => {
|
2016-07-14 16:33:16 +00:00
|
|
|
const fixtures = path.resolve(__dirname, 'fixtures')
|
|
|
|
let w
|
2016-07-14 16:10:40 +00:00
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
beforeEach(() => {
|
2016-07-14 16:10:40 +00:00
|
|
|
w = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
width: 400,
|
|
|
|
height: 400,
|
|
|
|
webPreferences: {
|
2019-01-07 19:19:27 +00:00
|
|
|
backgroundThrottling: false,
|
|
|
|
nodeIntegration: true,
|
|
|
|
webviewTag: true
|
2016-07-14 16:10:40 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
afterEach(() => closeWindow(w).then(() => { w = null }))
|
2016-07-14 16:10:40 +00:00
|
|
|
|
2017-03-09 03:06:26 +00:00
|
|
|
describe('webrtc ip policy api', () => {
|
2017-03-09 17:53:01 +00:00
|
|
|
it('can set and get webrtc ip policies', () => {
|
2017-03-09 03:06:26 +00:00
|
|
|
const policies = [
|
|
|
|
'default',
|
|
|
|
'default_public_interface_only',
|
|
|
|
'default_public_and_private_interfaces',
|
|
|
|
'disable_non_proxied_udp'
|
|
|
|
]
|
|
|
|
policies.forEach((policy) => {
|
|
|
|
w.webContents.setWebRTCIPHandlingPolicy(policy)
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(w.webContents.getWebRTCIPHandlingPolicy()).to.equal(policy)
|
2017-03-09 03:06:26 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2017-04-05 06:30:36 +00:00
|
|
|
|
2018-12-05 08:03:39 +00:00
|
|
|
describe('render view deleted events', () => {
|
|
|
|
let server = null
|
|
|
|
|
|
|
|
before((done) => {
|
|
|
|
server = http.createServer((req, res) => {
|
|
|
|
const respond = () => {
|
|
|
|
if (req.url === '/redirect-cross-site') {
|
|
|
|
res.setHeader('Location', `${server.cross_site_url}/redirected`)
|
|
|
|
res.statusCode = 302
|
|
|
|
res.end()
|
|
|
|
} else if (req.url === '/redirected') {
|
|
|
|
res.end('<html><script>window.localStorage</script></html>')
|
|
|
|
} else {
|
|
|
|
res.end()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setTimeout(respond, 0)
|
|
|
|
})
|
|
|
|
server.listen(0, '127.0.0.1', () => {
|
|
|
|
server.url = `http://127.0.0.1:${server.address().port}`
|
|
|
|
server.cross_site_url = `http://localhost:${server.address().port}`
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
after(() => {
|
|
|
|
server.close()
|
|
|
|
server = null
|
|
|
|
})
|
|
|
|
|
|
|
|
it('does not emit current-render-view-deleted when speculative RVHs are deleted', (done) => {
|
|
|
|
let currentRenderViewDeletedEmitted = false
|
|
|
|
w.webContents.once('destroyed', () => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(currentRenderViewDeletedEmitted).to.be.false('current-render-view-deleted was emitted')
|
2018-12-05 08:03:39 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
const renderViewDeletedHandler = () => {
|
|
|
|
currentRenderViewDeletedEmitted = true
|
|
|
|
}
|
|
|
|
w.webContents.on('current-render-view-deleted', renderViewDeletedHandler)
|
|
|
|
w.webContents.on('did-finish-load', (e) => {
|
|
|
|
w.webContents.removeListener('current-render-view-deleted', renderViewDeletedHandler)
|
|
|
|
w.close()
|
|
|
|
})
|
|
|
|
w.loadURL(`${server.url}/redirect-cross-site`)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('emits current-render-view-deleted if the current RVHs are deleted', (done) => {
|
|
|
|
let currentRenderViewDeletedEmitted = false
|
|
|
|
w.webContents.once('destroyed', () => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(currentRenderViewDeletedEmitted).to.be.true('current-render-view-deleted wasn\'t emitted')
|
2018-12-05 08:03:39 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
w.webContents.on('current-render-view-deleted', () => {
|
|
|
|
currentRenderViewDeletedEmitted = true
|
|
|
|
})
|
|
|
|
w.webContents.on('did-finish-load', (e) => {
|
|
|
|
w.close()
|
|
|
|
})
|
|
|
|
w.loadURL(`${server.url}/redirect-cross-site`)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('emits render-view-deleted if any RVHs are deleted', (done) => {
|
|
|
|
let rvhDeletedCount = 0
|
|
|
|
w.webContents.once('destroyed', () => {
|
|
|
|
const expectedRenderViewDeletedEventCount = 3 // 1 speculative upon redirection + 2 upon window close.
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(rvhDeletedCount).to.equal(expectedRenderViewDeletedEventCount, 'render-view-deleted wasn\'t emitted the expected nr. of times')
|
2018-12-05 08:03:39 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
w.webContents.on('render-view-deleted', () => {
|
|
|
|
rvhDeletedCount++
|
|
|
|
})
|
|
|
|
w.webContents.on('did-finish-load', (e) => {
|
|
|
|
w.close()
|
|
|
|
})
|
|
|
|
w.loadURL(`${server.url}/redirect-cross-site`)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('setIgnoreMenuShortcuts(ignore)', () => {
|
|
|
|
it('does not throw', () => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(() => {
|
|
|
|
w.webContents.setIgnoreMenuShortcuts(true)
|
|
|
|
w.webContents.setIgnoreMenuShortcuts(false)
|
|
|
|
}).to.not.throw()
|
2017-06-25 19:01:05 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-11-08 15:57:28 +00:00
|
|
|
describe('create()', () => {
|
|
|
|
it('does not crash on exit', async () => {
|
|
|
|
const appPath = path.join(__dirname, 'fixtures', 'api', 'leak-exit-webcontents.js')
|
|
|
|
const electronPath = remote.getGlobal('process').execPath
|
|
|
|
const appProcess = ChildProcess.spawn(electronPath, [appPath])
|
|
|
|
const [code] = await emittedOnce(appProcess, 'close')
|
|
|
|
expect(code).to.equal(0)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-09-14 08:18:45 +00:00
|
|
|
// Destroying webContents in its event listener is going to crash when
|
|
|
|
// Electron is built in Debug mode.
|
|
|
|
xdescribe('destroy()', () => {
|
2017-04-05 06:30:36 +00:00
|
|
|
let server
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
before((done) => {
|
2017-04-05 06:30:36 +00:00
|
|
|
server = http.createServer((request, response) => {
|
|
|
|
switch (request.url) {
|
|
|
|
case '/404':
|
|
|
|
response.statusCode = '404'
|
|
|
|
response.end()
|
|
|
|
break
|
|
|
|
case '/301':
|
|
|
|
response.statusCode = '301'
|
|
|
|
response.setHeader('Location', '/200')
|
|
|
|
response.end()
|
|
|
|
break
|
|
|
|
case '/200':
|
|
|
|
response.statusCode = '200'
|
|
|
|
response.end('hello')
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
done('unsupported endpoint')
|
|
|
|
}
|
|
|
|
}).listen(0, '127.0.0.1', () => {
|
|
|
|
server.url = 'http://127.0.0.1:' + server.address().port
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
after(() => {
|
2017-04-05 06:30:36 +00:00
|
|
|
server.close()
|
|
|
|
server = null
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should not crash when invoked synchronously inside navigation observer', (done) => {
|
|
|
|
const events = [
|
|
|
|
{ name: 'did-start-loading', url: `${server.url}/200` },
|
|
|
|
{ name: 'dom-ready', url: `${server.url}/200` },
|
|
|
|
{ name: 'did-stop-loading', url: `${server.url}/200` },
|
|
|
|
{ name: 'did-finish-load', url: `${server.url}/200` },
|
|
|
|
// FIXME: Multiple Emit calls inside an observer assume that object
|
|
|
|
// will be alive till end of the observer. Synchronous `destroy` api
|
|
|
|
// violates this contract and crashes.
|
|
|
|
// { name: 'did-frame-finish-load', url: `${server.url}/200` },
|
|
|
|
{ name: 'did-fail-load', url: `${server.url}/404` }
|
|
|
|
]
|
|
|
|
const responseEvent = 'webcontents-destroyed'
|
|
|
|
|
2017-11-23 22:22:43 +00:00
|
|
|
function * genNavigationEvent () {
|
2017-04-05 06:30:36 +00:00
|
|
|
let eventOptions = null
|
|
|
|
while ((eventOptions = events.shift()) && events.length) {
|
|
|
|
eventOptions.responseEvent = responseEvent
|
|
|
|
ipcRenderer.send('test-webcontents-navigation-observer', eventOptions)
|
|
|
|
yield 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-02 01:56:31 +00:00
|
|
|
const gen = genNavigationEvent()
|
2017-04-05 06:30:36 +00:00
|
|
|
ipcRenderer.on(responseEvent, () => {
|
|
|
|
if (!gen.next().value) done()
|
|
|
|
})
|
|
|
|
gen.next()
|
|
|
|
})
|
|
|
|
})
|
2017-08-20 14:48:13 +00:00
|
|
|
|
|
|
|
describe('did-change-theme-color event', () => {
|
|
|
|
it('is triggered with correct theme color', (done) => {
|
2017-10-27 20:45:58 +00:00
|
|
|
let count = 0
|
2017-08-20 14:48:13 +00:00
|
|
|
w.webContents.on('did-change-theme-color', (e, color) => {
|
|
|
|
if (count === 0) {
|
2017-10-27 20:45:58 +00:00
|
|
|
count += 1
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(color).to.equal('#FFEEDD')
|
2018-09-04 14:50:53 +00:00
|
|
|
w.loadFile(path.join(fixtures, 'pages', 'base-page.html'))
|
2017-08-20 14:48:13 +00:00
|
|
|
} else if (count === 1) {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(color).to.be.null()
|
2017-08-20 14:48:13 +00:00
|
|
|
done()
|
|
|
|
}
|
|
|
|
})
|
2018-09-04 14:50:53 +00:00
|
|
|
w.loadFile(path.join(fixtures, 'pages', 'theme-color.html'))
|
2017-08-20 14:48:13 +00:00
|
|
|
})
|
|
|
|
})
|
2017-11-08 07:45:27 +00:00
|
|
|
|
|
|
|
describe('console-message event', () => {
|
|
|
|
it('is triggered with correct log message', (done) => {
|
|
|
|
w.webContents.on('console-message', (e, level, message) => {
|
2017-11-08 08:09:54 +00:00
|
|
|
// Don't just assert as Chromium might emit other logs that we should ignore.
|
|
|
|
if (message === 'a') {
|
|
|
|
done()
|
|
|
|
}
|
2017-11-08 07:45:27 +00:00
|
|
|
})
|
2018-09-04 14:50:53 +00:00
|
|
|
w.loadFile(path.join(fixtures, 'pages', 'a.html'))
|
2017-11-08 07:45:27 +00:00
|
|
|
})
|
|
|
|
})
|
2018-04-05 23:13:24 +00:00
|
|
|
|
2019-01-22 16:47:58 +00:00
|
|
|
describe('ipc-message event', () => {
|
|
|
|
it('emits when the renderer process sends an asynchronous message', async () => {
|
|
|
|
const webContents = remote.getCurrentWebContents()
|
|
|
|
const promise = emittedOnce(webContents, 'ipc-message')
|
|
|
|
|
|
|
|
ipcRenderer.send('message', 'Hello World!')
|
|
|
|
|
|
|
|
const [, channel, message] = await promise
|
|
|
|
expect(channel).to.equal('message')
|
|
|
|
expect(message).to.equal('Hello World!')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('ipc-message-sync event', () => {
|
|
|
|
it('emits when the renderer process sends a synchronous message', async () => {
|
|
|
|
const webContents = remote.getCurrentWebContents()
|
|
|
|
const promise = emittedOnce(webContents, 'ipc-message-sync')
|
|
|
|
|
|
|
|
ipcRenderer.send('handle-next-ipc-message-sync', 'foobar')
|
|
|
|
const result = ipcRenderer.sendSync('message', 'Hello World!')
|
|
|
|
|
|
|
|
const [, channel, message] = await promise
|
|
|
|
expect(channel).to.equal('message')
|
|
|
|
expect(message).to.equal('Hello World!')
|
|
|
|
expect(result).to.equal('foobar')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-04-05 23:13:24 +00:00
|
|
|
describe('referrer', () => {
|
|
|
|
it('propagates referrer information to new target=_blank windows', (done) => {
|
|
|
|
const server = http.createServer((req, res) => {
|
|
|
|
if (req.url === '/should_have_referrer') {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(req.headers.referer).to.equal(`http://127.0.0.1:${server.address().port}/`)
|
2018-04-05 23:13:24 +00:00
|
|
|
return done()
|
|
|
|
}
|
|
|
|
res.end('<a id="a" href="/should_have_referrer" target="_blank">link</a>')
|
|
|
|
})
|
|
|
|
server.listen(0, '127.0.0.1', () => {
|
|
|
|
const url = 'http://127.0.0.1:' + server.address().port + '/'
|
|
|
|
w.webContents.once('did-finish-load', () => {
|
|
|
|
w.webContents.once('new-window', (event, newUrl, frameName, disposition, options, features, referrer) => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(referrer.url).to.equal(url)
|
|
|
|
expect(referrer.policy).to.equal('no-referrer-when-downgrade')
|
2018-04-05 23:13:24 +00:00
|
|
|
})
|
|
|
|
w.webContents.executeJavaScript('a.click()')
|
|
|
|
})
|
|
|
|
w.loadURL(url)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
// TODO(jeremy): window.open() in a real browser passes the referrer, but
|
|
|
|
// our hacked-up window.open() shim doesn't. It should.
|
|
|
|
xit('propagates referrer information to windows opened with window.open', (done) => {
|
|
|
|
const server = http.createServer((req, res) => {
|
|
|
|
if (req.url === '/should_have_referrer') {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(req.headers.referer).to.equal(`http://127.0.0.1:${server.address().port}/`)
|
2018-04-05 23:13:24 +00:00
|
|
|
return done()
|
|
|
|
}
|
|
|
|
res.end('')
|
|
|
|
})
|
|
|
|
server.listen(0, '127.0.0.1', () => {
|
|
|
|
const url = 'http://127.0.0.1:' + server.address().port + '/'
|
|
|
|
w.webContents.once('did-finish-load', () => {
|
|
|
|
w.webContents.once('new-window', (event, newUrl, frameName, disposition, options, features, referrer) => {
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(referrer.url).to.equal(url)
|
|
|
|
expect(referrer.policy).to.equal('no-referrer-when-downgrade')
|
2018-04-05 23:13:24 +00:00
|
|
|
})
|
|
|
|
w.webContents.executeJavaScript('window.open(location.href + "should_have_referrer")')
|
|
|
|
})
|
|
|
|
w.loadURL(url)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2018-04-12 01:57:40 +00:00
|
|
|
|
|
|
|
describe('webframe messages in sandboxed contents', () => {
|
2019-03-14 19:08:54 +00:00
|
|
|
it('responds to executeJavaScript', async () => {
|
|
|
|
w.destroy()
|
|
|
|
w = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
webPreferences: {
|
|
|
|
sandbox: true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
await w.loadURL('about:blank')
|
|
|
|
const result = await w.webContents.executeJavaScript('37 + 5')
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(result).to.equal(42)
|
2019-03-14 19:08:54 +00:00
|
|
|
})
|
2018-04-12 01:57:40 +00:00
|
|
|
})
|
2018-09-18 18:00:31 +00:00
|
|
|
|
2019-01-18 11:03:43 +00:00
|
|
|
describe('preload-error event', () => {
|
|
|
|
const generateSpecs = (description, sandbox) => {
|
|
|
|
describe(description, () => {
|
|
|
|
it('is triggered when unhandled exception is thrown', async () => {
|
|
|
|
const preload = path.join(fixtures, 'module', 'preload-error-exception.js')
|
|
|
|
|
|
|
|
w.destroy()
|
|
|
|
w = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
webPreferences: {
|
|
|
|
sandbox,
|
|
|
|
preload
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
const promise = emittedOnce(w.webContents, 'preload-error')
|
|
|
|
w.loadURL('about:blank')
|
|
|
|
|
|
|
|
const [, preloadPath, error] = await promise
|
|
|
|
expect(preloadPath).to.equal(preload)
|
|
|
|
expect(error.message).to.equal('Hello World!')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('is triggered on syntax errors', async () => {
|
|
|
|
const preload = path.join(fixtures, 'module', 'preload-error-syntax.js')
|
|
|
|
|
|
|
|
w.destroy()
|
|
|
|
w = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
webPreferences: {
|
|
|
|
sandbox,
|
|
|
|
preload
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
const promise = emittedOnce(w.webContents, 'preload-error')
|
|
|
|
w.loadURL('about:blank')
|
|
|
|
|
|
|
|
const [, preloadPath, error] = await promise
|
|
|
|
expect(preloadPath).to.equal(preload)
|
|
|
|
expect(error.message).to.equal('foobar is not defined')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('is triggered when preload script loading fails', async () => {
|
|
|
|
const preload = path.join(fixtures, 'module', 'preload-invalid.js')
|
|
|
|
|
|
|
|
w.destroy()
|
|
|
|
w = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
webPreferences: {
|
|
|
|
sandbox,
|
|
|
|
preload
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
const promise = emittedOnce(w.webContents, 'preload-error')
|
|
|
|
w.loadURL('about:blank')
|
|
|
|
|
|
|
|
const [, preloadPath, error] = await promise
|
|
|
|
expect(preloadPath).to.equal(preload)
|
|
|
|
expect(error.message).to.contain('preload-invalid.js')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
generateSpecs('without sandbox', false)
|
|
|
|
generateSpecs('with sandbox', true)
|
|
|
|
})
|
|
|
|
|
2018-09-18 18:00:31 +00:00
|
|
|
describe('takeHeapSnapshot()', () => {
|
|
|
|
it('works with sandboxed renderers', async () => {
|
|
|
|
w.destroy()
|
|
|
|
w = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
webPreferences: {
|
|
|
|
sandbox: true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-12-06 20:16:19 +00:00
|
|
|
await w.loadURL('about:blank')
|
2018-09-18 18:00:31 +00:00
|
|
|
|
|
|
|
const filePath = path.join(remote.app.getPath('temp'), 'test.heapsnapshot')
|
|
|
|
|
|
|
|
const cleanup = () => {
|
|
|
|
try {
|
|
|
|
fs.unlinkSync(filePath)
|
|
|
|
} catch (e) {
|
|
|
|
// ignore error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
await w.webContents.takeHeapSnapshot(filePath)
|
|
|
|
const stats = fs.statSync(filePath)
|
|
|
|
expect(stats.size).not.to.be.equal(0)
|
|
|
|
} finally {
|
|
|
|
cleanup()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('fails with invalid file path', async () => {
|
|
|
|
w.destroy()
|
|
|
|
w = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
webPreferences: {
|
|
|
|
sandbox: true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-12-06 20:16:19 +00:00
|
|
|
await w.loadURL('about:blank')
|
2018-09-18 18:00:31 +00:00
|
|
|
|
|
|
|
const promise = w.webContents.takeHeapSnapshot('')
|
|
|
|
return expect(promise).to.be.eventually.rejectedWith(Error, 'takeHeapSnapshot failed')
|
|
|
|
})
|
|
|
|
})
|
2018-10-19 00:32:22 +00:00
|
|
|
|
|
|
|
describe('setBackgroundThrottling()', () => {
|
|
|
|
it('does not crash when allowing', (done) => {
|
|
|
|
w.webContents.setBackgroundThrottling(true)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('does not crash when disallowing', (done) => {
|
|
|
|
w.destroy()
|
|
|
|
w = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
width: 400,
|
|
|
|
height: 400,
|
|
|
|
webPreferences: {
|
|
|
|
backgroundThrottling: true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
w.webContents.setBackgroundThrottling(false)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('does not crash when called via BrowserWindow', (done) => {
|
|
|
|
w.setBackgroundThrottling(true)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
2018-11-09 03:42:34 +00:00
|
|
|
|
|
|
|
describe('getPrinterList()', () => {
|
|
|
|
before(function () {
|
|
|
|
if (!features.isPrintingEnabled()) {
|
|
|
|
return closeWindow(w).then(() => {
|
|
|
|
w = null
|
|
|
|
this.skip()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-12-19 06:44:03 +00:00
|
|
|
it('can get printer list', async () => {
|
2018-11-09 03:42:34 +00:00
|
|
|
w.destroy()
|
|
|
|
w = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
webPreferences: {
|
|
|
|
sandbox: true
|
|
|
|
}
|
|
|
|
})
|
2018-12-19 06:44:03 +00:00
|
|
|
await w.loadURL('data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E')
|
|
|
|
const printers = w.webContents.getPrinters()
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(printers).to.be.an('array')
|
2018-11-09 03:42:34 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('printToPDF()', () => {
|
|
|
|
before(function () {
|
|
|
|
if (!features.isPrintingEnabled()) {
|
|
|
|
return closeWindow(w).then(() => {
|
|
|
|
w = null
|
|
|
|
this.skip()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-02-11 19:20:04 +00:00
|
|
|
it('can print to PDF', async () => {
|
|
|
|
w.destroy()
|
|
|
|
w = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
webPreferences: {
|
|
|
|
sandbox: true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
await w.loadURL('data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E')
|
|
|
|
const data = await w.webContents.printToPDF({})
|
2019-05-20 17:04:18 +00:00
|
|
|
expect(data).to.be.an.instanceof(Buffer).that.is.not.empty()
|
2019-02-11 19:20:04 +00:00
|
|
|
})
|
2018-11-09 03:42:34 +00:00
|
|
|
})
|
2019-08-22 10:17:50 +00:00
|
|
|
|
|
|
|
describe('PictureInPicture video', () => {
|
|
|
|
it('works as expected', (done) => {
|
|
|
|
w.destroy()
|
|
|
|
w = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
webPreferences: {
|
|
|
|
sandbox: true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
w.webContents.once('did-finish-load', async () => {
|
|
|
|
const result = await w.webContents.executeJavaScript(
|
|
|
|
`runTest(${features.isPictureInPictureEnabled()})`, true)
|
|
|
|
expect(result).to.be.true()
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
w.loadFile(path.join(fixtures, 'api', 'picture-in-picture.html'))
|
|
|
|
})
|
|
|
|
})
|
2016-07-14 16:10:40 +00:00
|
|
|
})
|