blob: 22424aabcdd73b3d155ee9461f03d87c033c6b87 [file]
import { strict as assert } from 'node:assert';
import { describe, it } from 'node:test';
import { inactiveWindowElectronArgs, mapFixtureWindowInactive } from './fixture-window.mjs';
function fakeElectronWindow({ visible = true, focused = false } = {}) {
const page = {};
const events = [];
const window = {
showInactive() {
events.push('showInactive');
},
isVisible() {
events.push('isVisible');
return visible;
},
isFocused() {
events.push('isFocused');
return focused;
},
};
const handle = {
async evaluate(callback) {
return callback(window);
},
async dispose() {
events.push('dispose');
},
};
return {
page,
events,
app: {
async browserWindow(target) {
assert.equal(target, page);
return handle;
},
},
};
}
describe('inactiveWindowElectronArgs', () => {
it('forces XWayland only when Electron would otherwise use native Wayland', () => {
assert.deepEqual(inactiveWindowElectronArgs({ XDG_SESSION_TYPE: 'wayland' }, 'linux'), [
'.',
'--ozone-platform=x11',
]);
assert.deepEqual(inactiveWindowElectronArgs({ XDG_SESSION_TYPE: 'x11' }, 'linux'), ['.']);
assert.deepEqual(inactiveWindowElectronArgs({ XDG_SESSION_TYPE: 'wayland' }, 'darwin'), ['.']);
});
});
describe('mapFixtureWindowInactive', () => {
it('maps the BrowserWindow that belongs to the launched page without focusing it', async () => {
const { app, page, events } = fakeElectronWindow();
await mapFixtureWindowInactive(app, page);
assert.deepEqual(events, ['showInactive', 'isVisible', 'isFocused', 'dispose']);
});
it('fails closed and releases the handle when inactive mapping does not take effect', async () => {
const { app, page, events } = fakeElectronWindow({ visible: false });
await assert.rejects(() => mapFixtureWindowInactive(app, page), /visible=false focused=false/);
assert.equal(events.at(-1), 'dispose');
});
});