parent
04cce89fdc
commit
e4214a6cbe
11 changed files with 1712 additions and 1945 deletions
|
@ -10,11 +10,11 @@ const {BrowserWindow, webContents, ipcMain, session} = remote
|
|||
|
||||
const isCi = remote.getGlobal('isCi')
|
||||
|
||||
describe('webContents module', function () {
|
||||
describe('webContents module', () => {
|
||||
const fixtures = path.resolve(__dirname, 'fixtures')
|
||||
let w
|
||||
|
||||
beforeEach(function () {
|
||||
beforeEach(() => {
|
||||
w = new BrowserWindow({
|
||||
show: false,
|
||||
width: 400,
|
||||
|
@ -25,14 +25,12 @@ describe('webContents module', function () {
|
|||
})
|
||||
})
|
||||
|
||||
afterEach(function () {
|
||||
return closeWindow(w).then(function () { w = null })
|
||||
})
|
||||
afterEach(() => closeWindow(w).then(() => { w = null }))
|
||||
|
||||
describe('getAllWebContents() API', function () {
|
||||
it('returns an array of web contents', function (done) {
|
||||
w.webContents.on('devtools-opened', function () {
|
||||
const all = webContents.getAllWebContents().sort(function (a, b) {
|
||||
describe('getAllWebContents() API', () => {
|
||||
it('returns an array of web contents', (done) => {
|
||||
w.webContents.on('devtools-opened', () => {
|
||||
const all = webContents.getAllWebContents().sort((a, b) => {
|
||||
return a.getId() - b.getId()
|
||||
})
|
||||
|
||||
|
@ -44,24 +42,24 @@ describe('webContents module', function () {
|
|||
done()
|
||||
})
|
||||
|
||||
w.loadURL('file://' + path.join(fixtures, 'pages', 'webview-zoom-factor.html'))
|
||||
w.loadURL(`file://${path.join(fixtures, 'pages', 'webview-zoom-factor.html')}`)
|
||||
w.webContents.openDevTools()
|
||||
})
|
||||
})
|
||||
|
||||
describe('getFocusedWebContents() API', function () {
|
||||
it('returns the focused web contents', function (done) {
|
||||
describe('getFocusedWebContents() API', () => {
|
||||
it('returns the focused web contents', (done) => {
|
||||
if (isCi) return done()
|
||||
|
||||
const specWebContents = remote.getCurrentWebContents()
|
||||
assert.equal(specWebContents.getId(), webContents.getFocusedWebContents().getId())
|
||||
|
||||
specWebContents.once('devtools-opened', function () {
|
||||
specWebContents.once('devtools-opened', () => {
|
||||
assert.equal(specWebContents.devToolsWebContents.getId(), webContents.getFocusedWebContents().getId())
|
||||
specWebContents.closeDevTools()
|
||||
})
|
||||
|
||||
specWebContents.once('devtools-closed', function () {
|
||||
specWebContents.once('devtools-closed', () => {
|
||||
assert.equal(specWebContents.getId(), webContents.getFocusedWebContents().getId())
|
||||
done()
|
||||
})
|
||||
|
@ -69,18 +67,18 @@ describe('webContents module', function () {
|
|||
specWebContents.openDevTools()
|
||||
})
|
||||
|
||||
it('does not crash when called on a detached dev tools window', function (done) {
|
||||
it('does not crash when called on a detached dev tools window', (done) => {
|
||||
const specWebContents = w.webContents
|
||||
|
||||
specWebContents.once('devtools-opened', function () {
|
||||
assert.doesNotThrow(function () {
|
||||
specWebContents.once('devtools-opened', () => {
|
||||
assert.doesNotThrow(() => {
|
||||
webContents.getFocusedWebContents()
|
||||
})
|
||||
specWebContents.closeDevTools()
|
||||
})
|
||||
|
||||
specWebContents.once('devtools-closed', function () {
|
||||
assert.doesNotThrow(function () {
|
||||
specWebContents.once('devtools-closed', () => {
|
||||
assert.doesNotThrow(() => {
|
||||
webContents.getFocusedWebContents()
|
||||
})
|
||||
done()
|
||||
|
@ -91,9 +89,9 @@ describe('webContents module', function () {
|
|||
})
|
||||
})
|
||||
|
||||
describe('isFocused() API', function () {
|
||||
it('returns false when the window is hidden', function () {
|
||||
BrowserWindow.getAllWindows().forEach(function (window) {
|
||||
describe('isFocused() API', () => {
|
||||
it('returns false when the window is hidden', () => {
|
||||
BrowserWindow.getAllWindows().forEach((window) => {
|
||||
assert.equal(!window.isVisible() && window.webContents.isFocused(), false)
|
||||
})
|
||||
})
|
||||
|
@ -101,7 +99,7 @@ describe('webContents module', function () {
|
|||
|
||||
describe('before-input-event event', () => {
|
||||
it('can prevent document keyboard events', (done) => {
|
||||
w.loadURL('file://' + path.join(__dirname, 'fixtures', 'pages', 'key-events.html'))
|
||||
w.loadURL(`file://${path.join(__dirname, 'fixtures', 'pages', 'key-events.html')}`)
|
||||
w.webContents.once('did-finish-load', () => {
|
||||
ipcMain.once('keydown', (event, key) => {
|
||||
assert.equal(key, 'b')
|
||||
|
@ -115,7 +113,7 @@ describe('webContents module', function () {
|
|||
})
|
||||
|
||||
it('has the correct properties', (done) => {
|
||||
w.loadURL('file://' + path.join(__dirname, 'fixtures', 'pages', 'base-page.html'))
|
||||
w.loadURL(`file://${path.join(__dirname, 'fixtures', 'pages', 'base-page.html')}`)
|
||||
w.webContents.once('did-finish-load', () => {
|
||||
const testBeforeInput = (opts) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
@ -199,16 +197,14 @@ describe('webContents module', function () {
|
|||
})
|
||||
})
|
||||
|
||||
describe('sendInputEvent(event)', function () {
|
||||
beforeEach(function (done) {
|
||||
w.loadURL('file://' + path.join(__dirname, 'fixtures', 'pages', 'key-events.html'))
|
||||
w.webContents.once('did-finish-load', function () {
|
||||
done()
|
||||
})
|
||||
describe('sendInputEvent(event)', () => {
|
||||
beforeEach((done) => {
|
||||
w.loadURL(`file://${path.join(__dirname, 'fixtures', 'pages', 'key-events.html')}`)
|
||||
w.webContents.once('did-finish-load', () => done())
|
||||
})
|
||||
|
||||
it('can send keydown events', function (done) {
|
||||
ipcMain.once('keydown', function (event, key, code, keyCode, shiftKey, ctrlKey, altKey) {
|
||||
it('can send keydown events', (done) => {
|
||||
ipcMain.once('keydown', (event, key, code, keyCode, shiftKey, ctrlKey, altKey) => {
|
||||
assert.equal(key, 'a')
|
||||
assert.equal(code, 'KeyA')
|
||||
assert.equal(keyCode, 65)
|
||||
|
@ -220,8 +216,8 @@ describe('webContents module', function () {
|
|||
w.webContents.sendInputEvent({type: 'keyDown', keyCode: 'A'})
|
||||
})
|
||||
|
||||
it('can send keydown events with modifiers', function (done) {
|
||||
ipcMain.once('keydown', function (event, key, code, keyCode, shiftKey, ctrlKey, altKey) {
|
||||
it('can send keydown events with modifiers', (done) => {
|
||||
ipcMain.once('keydown', (event, key, code, keyCode, shiftKey, ctrlKey, altKey) => {
|
||||
assert.equal(key, 'Z')
|
||||
assert.equal(code, 'KeyZ')
|
||||
assert.equal(keyCode, 90)
|
||||
|
@ -233,8 +229,8 @@ describe('webContents module', function () {
|
|||
w.webContents.sendInputEvent({type: 'keyDown', keyCode: 'Z', modifiers: ['shift', 'ctrl']})
|
||||
})
|
||||
|
||||
it('can send keydown events with special keys', function (done) {
|
||||
ipcMain.once('keydown', function (event, key, code, keyCode, shiftKey, ctrlKey, altKey) {
|
||||
it('can send keydown events with special keys', (done) => {
|
||||
ipcMain.once('keydown', (event, key, code, keyCode, shiftKey, ctrlKey, altKey) => {
|
||||
assert.equal(key, 'Tab')
|
||||
assert.equal(code, 'Tab')
|
||||
assert.equal(keyCode, 9)
|
||||
|
@ -246,8 +242,8 @@ describe('webContents module', function () {
|
|||
w.webContents.sendInputEvent({type: 'keyDown', keyCode: 'Tab', modifiers: ['alt']})
|
||||
})
|
||||
|
||||
it('can send char events', function (done) {
|
||||
ipcMain.once('keypress', function (event, key, code, keyCode, shiftKey, ctrlKey, altKey) {
|
||||
it('can send char events', (done) => {
|
||||
ipcMain.once('keypress', (event, key, code, keyCode, shiftKey, ctrlKey, altKey) => {
|
||||
assert.equal(key, 'a')
|
||||
assert.equal(code, 'KeyA')
|
||||
assert.equal(keyCode, 65)
|
||||
|
@ -260,8 +256,8 @@ describe('webContents module', function () {
|
|||
w.webContents.sendInputEvent({type: 'char', keyCode: 'A'})
|
||||
})
|
||||
|
||||
it('can send char events with modifiers', function (done) {
|
||||
ipcMain.once('keypress', function (event, key, code, keyCode, shiftKey, ctrlKey, altKey) {
|
||||
it('can send char events with modifiers', (done) => {
|
||||
ipcMain.once('keypress', (event, key, code, keyCode, shiftKey, ctrlKey, altKey) => {
|
||||
assert.equal(key, 'Z')
|
||||
assert.equal(code, 'KeyZ')
|
||||
assert.equal(keyCode, 90)
|
||||
|
@ -275,7 +271,7 @@ describe('webContents module', function () {
|
|||
})
|
||||
})
|
||||
|
||||
it('supports inserting CSS', function (done) {
|
||||
it('supports inserting CSS', (done) => {
|
||||
w.loadURL('about:blank')
|
||||
w.webContents.insertCSS('body { background-repeat: round; }')
|
||||
w.webContents.executeJavaScript('window.getComputedStyle(document.body).getPropertyValue("background-repeat")', (result) => {
|
||||
|
@ -284,9 +280,9 @@ describe('webContents module', function () {
|
|||
})
|
||||
})
|
||||
|
||||
it('supports inspecting an element in the devtools', function (done) {
|
||||
it('supports inspecting an element in the devtools', (done) => {
|
||||
w.loadURL('about:blank')
|
||||
w.webContents.once('devtools-opened', function () {
|
||||
w.webContents.once('devtools-opened', () => {
|
||||
done()
|
||||
})
|
||||
w.webContents.inspectElement(10, 10)
|
||||
|
@ -310,22 +306,22 @@ describe('webContents module', function () {
|
|||
})
|
||||
})
|
||||
|
||||
describe('focus()', function () {
|
||||
describe('when the web contents is hidden', function () {
|
||||
it('does not blur the focused window', function (done) {
|
||||
describe('focus()', () => {
|
||||
describe('when the web contents is hidden', () => {
|
||||
it('does not blur the focused window', (done) => {
|
||||
ipcMain.once('answer', (event, parentFocused, childFocused) => {
|
||||
assert.equal(parentFocused, true)
|
||||
assert.equal(childFocused, false)
|
||||
done()
|
||||
})
|
||||
w.show()
|
||||
w.loadURL('file://' + path.join(__dirname, 'fixtures', 'pages', 'focus-web-contents.html'))
|
||||
w.loadURL(`file://${path.join(__dirname, 'fixtures', 'pages', 'focus-web-contents.html')}`)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('getOSProcessId()', function () {
|
||||
it('returns a valid procress id', function (done) {
|
||||
describe('getOSProcessId()', () => {
|
||||
it('returns a valid procress id', (done) => {
|
||||
assert.strictEqual(w.webContents.getOSProcessId(), 0)
|
||||
|
||||
w.webContents.once('did-finish-load', () => {
|
||||
|
@ -386,9 +382,7 @@ describe('webContents module', function () {
|
|||
let finalNavigation = false
|
||||
ipcMain.on('set-zoom', (e, host) => {
|
||||
const zoomLevel = hostZoomMap[host]
|
||||
if (!finalNavigation) {
|
||||
w.webContents.setZoomLevel(zoomLevel)
|
||||
}
|
||||
if (!finalNavigation) w.webContents.setZoomLevel(zoomLevel)
|
||||
e.sender.send(`${host}-zoom-set`)
|
||||
})
|
||||
ipcMain.on('host1-zoom-level', (e, zoomLevel) => {
|
||||
|
@ -467,12 +461,12 @@ describe('webContents module', function () {
|
|||
})
|
||||
|
||||
it('can persist when it contains iframe', (done) => {
|
||||
const server = http.createServer(function (req, res) {
|
||||
const server = http.createServer((req, res) => {
|
||||
setTimeout(() => {
|
||||
res.end()
|
||||
}, 200)
|
||||
})
|
||||
server.listen(0, '127.0.0.1', function () {
|
||||
server.listen(0, '127.0.0.1', () => {
|
||||
const url = 'http://127.0.0.1:' + server.address().port
|
||||
const content = `<iframe src=${url}></iframe>`
|
||||
w.webContents.on('did-frame-finish-load', (e, isMainFrame) => {
|
||||
|
@ -557,12 +551,12 @@ describe('webContents module', function () {
|
|||
})
|
||||
})
|
||||
|
||||
describe('will-prevent-unload event', function () {
|
||||
it('does not emit if beforeunload returns undefined', function (done) {
|
||||
w.once('closed', function () {
|
||||
describe('will-prevent-unload event', () => {
|
||||
it('does not emit if beforeunload returns undefined', (done) => {
|
||||
w.once('closed', () => {
|
||||
done()
|
||||
})
|
||||
w.webContents.on('will-prevent-unload', function (e) {
|
||||
w.webContents.on('will-prevent-unload', (e) => {
|
||||
assert.fail('should not have fired')
|
||||
})
|
||||
w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-undefined.html'))
|
||||
|
@ -575,15 +569,15 @@ describe('webContents module', function () {
|
|||
w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-false.html'))
|
||||
})
|
||||
|
||||
it('supports calling preventDefault on will-prevent-unload events', function (done) {
|
||||
it('supports calling preventDefault on will-prevent-unload events', (done) => {
|
||||
ipcRenderer.send('prevent-next-will-prevent-unload', w.webContents.id)
|
||||
w.once('closed', () => done())
|
||||
w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-false.html'))
|
||||
})
|
||||
})
|
||||
|
||||
describe('setIgnoreMenuShortcuts(ignore)', function () {
|
||||
it('does not throw', function () {
|
||||
describe('setIgnoreMenuShortcuts(ignore)', () => {
|
||||
it('does not throw', () => {
|
||||
assert.equal(w.webContents.setIgnoreMenuShortcuts(true), undefined)
|
||||
assert.equal(w.webContents.setIgnoreMenuShortcuts(false), undefined)
|
||||
})
|
||||
|
@ -594,7 +588,7 @@ describe('webContents module', function () {
|
|||
xdescribe('destroy()', () => {
|
||||
let server
|
||||
|
||||
before(function (done) {
|
||||
before((done) => {
|
||||
server = http.createServer((request, response) => {
|
||||
switch (request.url) {
|
||||
case '/404':
|
||||
|
@ -619,7 +613,7 @@ describe('webContents module', function () {
|
|||
})
|
||||
})
|
||||
|
||||
after(function () {
|
||||
after(() => {
|
||||
server.close()
|
||||
server = null
|
||||
})
|
||||
|
@ -659,18 +653,18 @@ describe('webContents module', function () {
|
|||
|
||||
describe('did-change-theme-color event', () => {
|
||||
it('is triggered with correct theme color', (done) => {
|
||||
var count = 0
|
||||
let count = 0
|
||||
w.webContents.on('did-change-theme-color', (e, color) => {
|
||||
if (count === 0) {
|
||||
count++
|
||||
count += 1
|
||||
assert.equal(color, '#FFEEDD')
|
||||
w.loadURL('file://' + path.join(__dirname, 'fixtures', 'pages', 'base-page.html'))
|
||||
w.loadURL(`file://${path.join(__dirname, 'fixtures', 'pages', 'base-page.html')}`)
|
||||
} else if (count === 1) {
|
||||
assert.equal(color, null)
|
||||
done()
|
||||
}
|
||||
})
|
||||
w.loadURL('file://' + path.join(__dirname, 'fixtures', 'pages', 'theme-color.html'))
|
||||
w.loadURL(`file://${path.join(__dirname, 'fixtures', 'pages', 'theme-color.html')}`)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue