test: fixup GDK_BACKEND test

This commit is contained in:
Shelley Vohr
2021-06-09 15:49:06 +02:00
parent 711d8a4bf4
commit fcef5a5333
4 changed files with 74 additions and 0 deletions

View File

@@ -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"

View File

@@ -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(() => {

View File

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

View File

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