Add separate specs for hide/show/minimize visibilitychange events
This commit is contained in:
parent
28cd973805
commit
52137485f2
1 changed files with 90 additions and 59 deletions
|
@ -1413,77 +1413,108 @@ describe('BrowserWindow module', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('document.visibilityState/hidden', function () {
|
describe('document.visibilityState/hidden', function () {
|
||||||
|
beforeEach(function () {
|
||||||
|
w.destroy()
|
||||||
|
})
|
||||||
|
|
||||||
|
function onVisibilityChange (callback) {
|
||||||
|
ipcMain.on('pong', function (event, visibilityState, hidden) {
|
||||||
|
if (event.sender.id === w.webContents.id) {
|
||||||
|
callback(visibilityState, hidden)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function onNextVisibilityChange (callback) {
|
||||||
|
ipcMain.once('pong', function (event, visibilityState, hidden) {
|
||||||
|
if (event.sender.id === w.webContents.id) {
|
||||||
|
callback(visibilityState, hidden)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
ipcMain.removeAllListeners('pong')
|
ipcMain.removeAllListeners('pong')
|
||||||
})
|
})
|
||||||
|
|
||||||
function onNextVisibleEvent (callback) {
|
|
||||||
ipcMain.on('pong', function listener (event, visibilityState, hidden) {
|
|
||||||
if (visibilityState === 'visible' && hidden === false) {
|
|
||||||
ipcMain.removeListener('pong', listener)
|
|
||||||
callback()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function onNextHiddenEvent (callback) {
|
|
||||||
ipcMain.on('pong', function listener (event, visibilityState, hidden) {
|
|
||||||
if (visibilityState === 'hidden' && hidden === true) {
|
|
||||||
ipcMain.removeListener('pong', listener)
|
|
||||||
callback()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
it('visibilityState is initially visible despite window being hidden', function (done) {
|
it('visibilityState is initially visible despite window being hidden', function (done) {
|
||||||
w.destroy()
|
|
||||||
w = new BrowserWindow({ show: false, width: 100, height: 100 })
|
w = new BrowserWindow({ show: false, width: 100, height: 100 })
|
||||||
|
|
||||||
let readyToShow = false
|
let readyToShow = false
|
||||||
w.on('ready-to-show', function () {
|
w.once('ready-to-show', function () {
|
||||||
readyToShow = true
|
readyToShow = true
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.once('pong', function (event, visibilityState, hidden) {
|
onNextVisibilityChange(function (visibilityState, hidden) {
|
||||||
assert.ok(!readyToShow)
|
assert.equal(readyToShow, false)
|
||||||
assert.equal(visibilityState, 'visible')
|
assert.equal(visibilityState, 'visible')
|
||||||
assert.equal(hidden, false)
|
assert.equal(hidden, false)
|
||||||
|
|
||||||
ipcMain.once('pong', function (event, visibilityState, hidden) {
|
done()
|
||||||
assert.ok(false)
|
|
||||||
})
|
|
||||||
|
|
||||||
setTimeout(done, 1000)
|
|
||||||
w.show()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
w.loadURL('file://' + path.join(fixtures, 'pages', 'visibilitychange.html'))
|
w.loadURL('file://' + path.join(fixtures, 'pages', 'visibilitychange.html'))
|
||||||
})
|
})
|
||||||
|
|
||||||
it('visibilityState changes when window is shown and hidden', function (done) {
|
it('visibilityState changes when window is hidden', function (done) {
|
||||||
w.destroy()
|
w = new BrowserWindow({width: 100, height: 100})
|
||||||
w = new BrowserWindow({
|
|
||||||
width: 100,
|
|
||||||
height: 100
|
|
||||||
})
|
|
||||||
|
|
||||||
onNextVisibleEvent(() => {
|
onNextVisibilityChange(function (visibilityState, hidden) {
|
||||||
onNextHiddenEvent(() => {
|
assert.equal(visibilityState, 'visible')
|
||||||
onNextVisibleEvent(() => {
|
assert.equal(hidden, false)
|
||||||
onNextHiddenEvent(done)
|
|
||||||
w.minimize()
|
onNextVisibilityChange(function (visibilityState, hidden) {
|
||||||
})
|
assert.equal(visibilityState, 'hidden')
|
||||||
w.show()
|
assert.equal(hidden, true)
|
||||||
w.focus()
|
|
||||||
|
done()
|
||||||
})
|
})
|
||||||
|
|
||||||
w.hide()
|
w.hide()
|
||||||
})
|
})
|
||||||
|
|
||||||
w.loadURL('file://' + path.join(fixtures, 'pages', 'visibilitychange.html'))
|
w.loadURL('file://' + path.join(fixtures, 'pages', 'visibilitychange.html'))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('visibilityState changes when window is shown', function (done) {
|
||||||
|
w = new BrowserWindow({width: 100, height: 100})
|
||||||
|
|
||||||
|
onNextVisibilityChange(function (visibilityState, hidden) {
|
||||||
|
onVisibilityChange(function (visibilityState, hidden) {
|
||||||
|
if (!hidden) {
|
||||||
|
assert.equal(visibilityState, 'visible')
|
||||||
|
done()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
w.hide()
|
||||||
|
w.show()
|
||||||
|
})
|
||||||
|
|
||||||
|
w.loadURL('file://' + path.join(fixtures, 'pages', 'visibilitychange.html'))
|
||||||
|
})
|
||||||
|
|
||||||
|
it('visibilityState changes when window is minimized', function (done) {
|
||||||
|
w = new BrowserWindow({width: 100, height: 100})
|
||||||
|
|
||||||
|
onNextVisibilityChange(function (visibilityState, hidden) {
|
||||||
|
assert.equal(visibilityState, 'visible')
|
||||||
|
assert.equal(hidden, false)
|
||||||
|
|
||||||
|
onNextVisibilityChange(function (visibilityState, hidden) {
|
||||||
|
assert.equal(visibilityState, 'hidden')
|
||||||
|
assert.equal(hidden, true)
|
||||||
|
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
|
||||||
|
w.minimize()
|
||||||
|
})
|
||||||
|
|
||||||
|
w.loadURL('file://' + path.join(fixtures, 'pages', 'visibilitychange.html'))
|
||||||
|
})
|
||||||
|
|
||||||
it('visibilityState remains visible if backgroundThrottling is disabled', function (done) {
|
it('visibilityState remains visible if backgroundThrottling is disabled', function (done) {
|
||||||
w.destroy()
|
|
||||||
w = new BrowserWindow({
|
w = new BrowserWindow({
|
||||||
show: false,
|
show: false,
|
||||||
width: 100,
|
width: 100,
|
||||||
|
@ -1493,26 +1524,26 @@ describe('BrowserWindow module', function () {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
onNextVisibleEvent(() => {
|
onNextVisibilityChange(function (visibilityState, hidden) {
|
||||||
onNextVisibleEvent(() => {
|
assert.equal(visibilityState, 'visible')
|
||||||
done(new Error('Unexpected visibility change event to visible'))
|
assert.equal(hidden, false)
|
||||||
})
|
|
||||||
onNextHiddenEvent(() => {
|
|
||||||
done(new Error('Unexpected visibility change event to hidden'))
|
|
||||||
})
|
|
||||||
|
|
||||||
w.once('show', () => {
|
onNextVisibilityChange(function (visibilityState, hidden) {
|
||||||
w.once('hide', () => {
|
done(new Error(`Unexpected visibility change event. visibilityState: ${visibilityState} hidden: ${hidden}`))
|
||||||
w.once('show', () => {
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
w.show()
|
|
||||||
})
|
|
||||||
w.hide()
|
|
||||||
})
|
})
|
||||||
w.show()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
w.once('show', () => {
|
||||||
|
w.once('hide', () => {
|
||||||
|
w.once('show', () => {
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
w.show()
|
||||||
|
})
|
||||||
|
w.hide()
|
||||||
|
})
|
||||||
|
w.show()
|
||||||
|
|
||||||
w.loadURL('file://' + path.join(fixtures, 'pages', 'visibilitychange.html'))
|
w.loadURL('file://' + path.join(fixtures, 'pages', 'visibilitychange.html'))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue