Browse Source

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
Alexey Kuzmin 7 years ago
parent
commit
3fd0ec99ae
2 changed files with 22 additions and 13 deletions
  1. 9 0
      atom/common/api/features.cc
  2. 13 13
      spec/api-browser-window-spec.js

+ 9 - 0
atom/common/api/features.cc

@@ -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);
 }
 

+ 13 - 13
spec/api-browser-window-spec.js

@@ -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
-    }
-
-    // Offscreen rendering can be disabled in the build
-    if (isOffscreenRenderingDisabled()) return
+    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() })
+      }
 
-    beforeEach(() => {
       if (w != null) w.destroy()
       w = new BrowserWindow({
         width: 100,