Browse Source

test: fixup GDK_BACKEND test

Shelley Vohr 3 years ago
parent
commit
fcef5a5333

+ 1 - 0
shell/common/platform_util_linux.cc

@@ -19,6 +19,7 @@
 #include "dbus/bus.h"
 #include "dbus/message.h"
 #include "dbus/object_proxy.h"
+#include "shell/browser/electron_browser_main_parts.h"
 #include "shell/common/platform_util_internal.h"
 #include "ui/gtk/gtk_util.h"
 #include "url/gurl.h"

+ 60 - 0
spec-main/chromium-spec.ts

@@ -367,6 +367,66 @@ describe('web security', () => {
   });
 });
 
+ifdescribe(process.platform === 'linux')('subprocesses', () => {
+  let appProcess: ChildProcess.ChildProcessWithoutNullStreams | undefined;
+  afterEach(() => {
+    if (appProcess && !appProcess.killed) {
+      appProcess.kill();
+      appProcess = undefined;
+    }
+  });
+
+  it('does not propagate GDK_BACKEND', async () => {
+    const appPath = path.join(fixturesPath, 'api', 'gdk-backend-check');
+    appProcess = ChildProcess.spawn(process.execPath, [appPath], {
+      env: {
+        GDK_BACKEND: ''
+      }
+    });
+
+    let output = '';
+    appProcess.stdout.on('data', (data) => { output += data; });
+    let stderr = '';
+    appProcess.stderr.on('data', (data) => { stderr += data; });
+
+    const [code, signal] = await emittedOnce(appProcess, 'exit');
+    if (code !== 0) {
+      throw new Error(`Process exited with code "${code}" signal "${signal}" output "${output}" stderr "${stderr}"`);
+    }
+
+    output = output.replace(/(\r\n|\n|\r)/gm, '');
+
+    const backend = String(process.env.GDK_BACKEND);
+    expect(output).to.not.equal(backend);
+    expect(output).to.be.empty();
+  });
+
+  it('successfully honors GDK_BACKEND set in the subproc', async () => {
+    const appPath = path.join(fixturesPath, 'api', 'gdk-backend-check');
+    appProcess = ChildProcess.spawn(process.execPath, [appPath], {
+      env: {
+        GDK_BACKEND: 'wayland'
+      }
+    });
+
+    let output = '';
+    appProcess.stdout.on('data', (data) => { output += data; });
+    let stderr = '';
+    appProcess.stderr.on('data', (data) => { stderr += data; });
+
+    const [code, signal] = await emittedOnce(appProcess, 'exit');
+    if (code !== 0) {
+      throw new Error(`Process exited with code "${code}" signal "${signal}" output "${output}" stderr "${stderr}"`);
+    }
+
+    output = output.replace(/(\r\n|\n|\r)/gm, '');
+
+    const backend = String(process.env.GDK_BACKEND);
+    expect(output).to.not.equal(backend);
+    expect(output).to.equal('wayland');
+  });
+});
+
 describe('command line switches', () => {
   let appProcess: ChildProcess.ChildProcessWithoutNullStreams | undefined;
   afterEach(() => {

+ 8 - 0
spec/fixtures/api/gdk-backend-check/main.js

@@ -0,0 +1,8 @@
+const { app } = require('electron');
+
+app.whenReady().then(() => {
+  process.stdout.write(String(process.env.GDK_BACKEND));
+  process.stdout.end();
+
+  app.quit();
+});

+ 5 - 0
spec/fixtures/api/gdk-backend-check/package.json

@@ -0,0 +1,5 @@
+{
+  "name": "electron-test-gdk-backend-check",
+  "main": "main.js"
+}
+