test: fix frame-subscriber test on Mac

This commit is contained in:
Jeremy Apthorp 2018-09-24 16:14:03 -07:00 committed by Aleksei Kuzmin
parent ae12d53884
commit 09f018ce8c

View file

@ -2358,14 +2358,32 @@ describe('BrowserWindow module', () => {
})
it('subscribes to frame updates (only dirty rectangle)', (done) => {
let called = false
let gotInitialFullSizeFrame = false
const [contentWidth, contentHeight] = w.getContentSize()
w.loadFile(path.join(fixtures, 'api', 'frame-subscriber.html'))
w.webContents.on('dom-ready', () => {
w.webContents.beginFrameSubscription(true, (data) => {
w.webContents.on('did-finish-load', () => {
w.webContents.beginFrameSubscription(true, (data, rect) => {
if (data.length === 0) {
// Chromium sometimes sends a 0x0 frame at the beginning of the
// page load.
return
}
if (rect.height === contentHeight && rect.width === contentWidth &&
!gotInitialFullSizeFrame) {
// The initial frame is full-size, but we're looking for a call
// with just the dirty-rect. The next frame should be a smaller
// rect.
gotInitialFullSizeFrame = true
return
}
// This callback might be called twice.
if (called) return
// We asked for just the dirty rectangle, so we expect to receive a
// rect smaller than the full size.
assert(rect.width < contentWidth || rect.height < contentHeight)
called = true
assert.notStrictEqual(data.length, 0)
expect(data.length).to.equal(rect.width * rect.height * 4)
w.webContents.endFrameSubscription()
done()
})