spec: Make beginFrameSubscription test more reliable

This commit is contained in:
Cheng Zhao 2016-06-26 11:53:58 +09:00
parent e1ad64013e
commit 090c8b89bb

View file

@ -44,7 +44,10 @@ describe('browser-window module', function () {
w = new BrowserWindow({ w = new BrowserWindow({
show: false, show: false,
width: 400, width: 400,
height: 400 height: 400,
webPreferences: {
backgroundThrottling: false
}
}) })
}) })
@ -603,12 +606,20 @@ describe('browser-window module', function () {
}) })
describe('beginFrameSubscription method', function () { describe('beginFrameSubscription method', function () {
it('subscribes to frame updates', function (done) { // This test is too slow, only test it on CI.
this.timeout(20000) if (!isCI) return
this.timeout(20000)
it('subscribes to frame updates', function (done) {
let called = false
w.loadURL('file://' + fixtures + '/api/frame-subscriber.html') w.loadURL('file://' + fixtures + '/api/frame-subscriber.html')
w.webContents.on('dom-ready', function () { w.webContents.on('dom-ready', function () {
w.webContents.beginFrameSubscription(function (data) { w.webContents.beginFrameSubscription(function (data) {
// This callback might be called twice.
if (called) return
called = true
assert.notEqual(data.length, 0) assert.notEqual(data.length, 0)
w.webContents.endFrameSubscription() w.webContents.endFrameSubscription()
done() done()
@ -617,11 +628,14 @@ describe('browser-window module', function () {
}) })
it('subscribes to frame updates (only dirty rectangle)', function (done) { it('subscribes to frame updates (only dirty rectangle)', function (done) {
this.timeout(20000) let called = false
w.loadURL('file://' + fixtures + '/api/frame-subscriber.html') w.loadURL('file://' + fixtures + '/api/frame-subscriber.html')
w.webContents.on('dom-ready', function () { w.webContents.on('dom-ready', function () {
w.webContents.beginFrameSubscription(true, function (data) { w.webContents.beginFrameSubscription(true, function (data) {
// This callback might be called twice.
if (called) return
called = true
assert.notEqual(data.length, 0) assert.notEqual(data.length, 0)
w.webContents.endFrameSubscription() w.webContents.endFrameSubscription()
done() done()
@ -630,10 +644,8 @@ describe('browser-window module', function () {
}) })
it('throws error when subscriber is not well defined', function (done) { it('throws error when subscriber is not well defined', function (done) {
this.timeout(20000)
w.loadURL('file://' + fixtures + '/api/frame-subscriber.html') w.loadURL('file://' + fixtures + '/api/frame-subscriber.html')
try{ try {
w.webContents.beginFrameSubscription(true, true) w.webContents.beginFrameSubscription(true, true)
} catch(e) { } catch(e) {
done() done()