spec: Remove duplicate code in tests

This commit is contained in:
Cheng Zhao 2016-08-03 10:27:55 +09:00
Родитель ba9aa13bd8
Коммит c8b544ee1f
2 изменённых файлов: 47 добавлений и 105 удалений

Просмотреть файл

@ -1169,153 +1169,95 @@ describe('browser-window module', function () {
}) })
describe('offscreen rendering', function () { describe('offscreen rendering', function () {
it('creates offscreen window', function (done) {
this.timeout(10000) this.timeout(10000)
let w_ = new BrowserWindow({
beforeEach(function () {
if (w != null) w.destroy()
w = new BrowserWindow({
show: false, show: false,
width: 400,
height: 400,
webPreferences: { webPreferences: {
backgroundThrottling: false, backgroundThrottling: false,
offscreen: true offscreen: true
} }
}) })
w_.loadURL('file://' + fixtures + '/api/offscreen-rendering.html') })
w_.webContents.once('paint', function (event, rect, data, size) {
it('creates offscreen window', function (done) {
w.webContents.once('paint', function (event, rect, data, size) {
assert.notEqual(data.length, 0) assert.notEqual(data.length, 0)
done() done()
}) })
w.loadURL('file://' + fixtures + '/api/offscreen-rendering.html')
}) })
describe('window.webContents.isOffscreen', function () { describe('window.webContents.isOffscreen()', function () {
it('has offscreen type', function () { it('is true for offscreen type', function () {
let w_ = new BrowserWindow({ w.loadURL('file://' + fixtures + '/api/offscreen-rendering.html')
show: false, assert.equal(w.webContents.isOffscreen(), true)
width: 400,
height: 400,
webPreferences: {
backgroundThrottling: false,
offscreen: true
}
})
w_.loadURL('file://' + fixtures + '/api/offscreen-rendering.html')
assert.equal(w_.webContents.isOffscreen(), true)
}) })
it('is a regular window', function () { it('is false for regular window', function () {
assert.equal(w.webContents.isOffscreen(), false) let c = new BrowserWindow({show: false})
assert.equal(c.webContents.isOffscreen(), false)
c.destroy()
}) })
}) })
describe('window.webContents.isPainting', function () { describe('window.webContents.isPainting()', function () {
it('is currently painting', function (done) { it('returns whether is currently painting', function (done) {
this.timeout(10000) w.webContents.once('paint', function (event, rect, data, size) {
let w_ = new BrowserWindow({ assert.equal(w.webContents.isPainting(), true)
show: false,
width: 400,
height: 400,
webPreferences: {
backgroundThrottling: false,
offscreen: true
}
})
w_.loadURL('file://' + fixtures + '/api/offscreen-rendering.html')
w_.webContents.once('paint', function (event, rect, data, size) {
assert.equal(w_.webContents.isPainting(), true)
done() done()
}) })
w.loadURL('file://' + fixtures + '/api/offscreen-rendering.html')
}) })
}) })
describe('window.webContents.stopPainting', function () { describe('window.webContents.stopPainting()', function () {
it('stops painting', function (done) { it('stops painting', function (done) {
this.timeout(10000) w.webContents.on('dom-ready', function () {
let w_ = new BrowserWindow({ w.webContents.stopPainting()
show: false, assert.equal(w.webContents.isPainting(), false)
width: 400,
height: 400,
webPreferences: {
backgroundThrottling: false,
offscreen: true
}
})
w_.loadURL('file://' + fixtures + '/api/offscreen-rendering.html')
w_.webContents.on('dom-ready', function () {
w_.webContents.stopPainting()
assert.equal(w_.webContents.isPainting(), false)
done() done()
}) })
w.loadURL('file://' + fixtures + '/api/offscreen-rendering.html')
}) })
}) })
describe('window.webContents.startPainting', function () { describe('window.webContents.startPainting()', function () {
it('starts painting', function (done) { it('starts painting', function (done) {
this.timeout(10000) w.webContents.on('dom-ready', function () {
let w_ = new BrowserWindow({ w.webContents.stopPainting()
show: false, w.webContents.startPainting()
width: 400, w.webContents.once('paint', function (event, rect, data, size) {
height: 400, assert.equal(w.webContents.isPainting(), true)
webPreferences: {
backgroundThrottling: false,
offscreen: true
}
})
w_.loadURL('file://' + fixtures + '/api/offscreen-rendering.html')
w_.webContents.on('dom-ready', function () {
w_.webContents.stopPainting()
w_.webContents.startPainting()
w_.webContents.once('paint', function (event, rect, data, size) {
assert.equal(w_.webContents.isPainting(), true)
done() done()
}) })
}) })
w.loadURL('file://' + fixtures + '/api/offscreen-rendering.html')
}) })
}) })
describe('window.webContents.getFrameRate', function () { describe('window.webContents.getFrameRate()', function () {
it('has default frame rate', function (done) { it('has default frame rate', function (done) {
this.timeout(10000) w.webContents.once('paint', function (event, rect, data, size) {
let w_ = new BrowserWindow({ assert.equal(w.webContents.getFrameRate(), 60)
show: false,
width: 400,
height: 400,
webPreferences: {
backgroundThrottling: false,
offscreen: true
}
})
w_.loadURL('file://' + fixtures + '/api/offscreen-rendering.html')
w_.webContents.once('paint', function (event, rect, data, size) {
assert.equal(w_.webContents.getFrameRate(), 60)
done() done()
}) })
}) })
w.loadURL('file://' + fixtures + '/api/offscreen-rendering.html')
}) })
describe('window.webContents.setFrameRate', function () { describe('window.webContents.setFrameRate(frameRate)', function () {
it('has custom frame rate', function (done) { it('sets custom frame rate', function (done) {
this.timeout(10000) w.webContents.on('dom-ready', function () {
let w_ = new BrowserWindow({ w.webContents.setFrameRate(30)
show: false, w.webContents.once('paint', function (event, rect, data, size) {
width: 400, assert.equal(w.webContents.getFrameRate(), 30)
height: 400,
webPreferences: {
backgroundThrottling: false,
offscreen: true
}
})
w_.loadURL('file://' + fixtures + '/api/offscreen-rendering.html')
w_.webContents.on('dom-ready', function () {
w_.webContents.setFrameRate(30)
w_.webContents.once('paint', function (event, rect, data, size) {
assert.equal(w_.webContents.getFrameRate(), 30)
done() done()
}) })
}) })
w.loadURL('file://' + fixtures + '/api/offscreen-rendering.html')
}) })
}) })
}) })

Просмотреть файл

@ -38,7 +38,7 @@ describe('webContents module', function () {
w.webContents.on('devtools-opened', function () { w.webContents.on('devtools-opened', function () {
const all = webContents.getAllWebContents().sort(function (a, b) { const all = webContents.getAllWebContents().sort(function (a, b) {
return a.getId() - b.getId() return a.getId() - b.getId()
}).filter(function (wc) { return wc.getType() !== 'offscreen' }) })
assert.equal(all.length, 4) assert.equal(all.length, 4)
assert.equal(all[0].getType(), 'window') assert.equal(all[0].getType(), 'window')