Better OSR tests (#12817)

* Add features.isOffscreenRenderingEnabled()

* Use .isOffscreenRenderingEnabled() to determine if OSR is available

* Add a helper closeTheWindow() function

* Skip OSR tests if they are disabled
This commit is contained in:
Alexey Kuzmin 2018-05-03 18:10:25 +02:00 committed by Charles Kerr
parent 0a2dc1efb0
commit 3fd0ec99ae
2 changed files with 22 additions and 13 deletions

View file

@ -7,6 +7,14 @@
namespace {
bool IsOffscreenRenderingEnabled() {
#if defined(ENABLE_OSR)
return true;
#else
return false;
#endif
}
bool IsPDFViewerEnabled() {
#if defined(ENABLE_PDF_VIEWER)
return true;
@ -20,6 +28,7 @@ void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Context> context,
void* priv) {
mate::Dictionary dict(context->GetIsolate(), exports);
dict.SetMethod("isOffscreenRenderingEnabled", &IsOffscreenRenderingEnabled);
dict.SetMethod("isPDFViewerEnabled", &IsPDFViewerEnabled);
}

View file

@ -11,6 +11,8 @@ const {closeWindow} = require('./window-helpers')
const {ipcRenderer, remote, screen} = require('electron')
const {app, ipcMain, BrowserWindow, BrowserView, protocol, session, webContents} = remote
const features = process.atomBinding('features')
const isCI = remote.getGlobal('isCi')
const nativeModulesEnabled = remote.getGlobal('nativeModulesEnabled')
@ -21,6 +23,10 @@ describe('BrowserWindow module', () => {
let server
let postData
const closeTheWindow = function () {
return closeWindow(w).then(() => { w = null })
}
before((done) => {
const filePath = path.join(fixtures, 'pages', 'a.html')
const fileStats = fs.statSync(filePath)
@ -82,9 +88,7 @@ describe('BrowserWindow module', () => {
})
})
afterEach(() => {
return closeWindow(w).then(() => { w = null })
})
afterEach(closeTheWindow)
describe('BrowserWindow constructor', () => {
it('allows passing void 0 as the webContents', () => {
@ -3059,17 +3063,13 @@ describe('BrowserWindow module', () => {
})
describe('offscreen rendering', () => {
const isOffscreenRenderingDisabled = () => {
const contents = webContents.create({})
const disabled = typeof contents.isOffscreen !== 'function'
contents.destroy()
return disabled
}
beforeEach(function () {
if (!features.isOffscreenRenderingEnabled()) {
// XXX(alexeykuzmin): "afterEach" hook is not called
// for skipped tests, we have to close the window manually.
return closeTheWindow().then(() => { this.skip() })
}
// Offscreen rendering can be disabled in the build
if (isOffscreenRenderingDisabled()) return
beforeEach(() => {
if (w != null) w.destroy()
w = new BrowserWindow({
width: 100,