Preserve accumulated client implementation since v0.1.4, including local identities, multi-server state, chat, administration, audio and streaming controls. Refine official-source layout, original artwork, responsive composer overflow, settings navigation and chat scroll anchoring. Current verification: Node suite passes; isolated packaged chat and responsive control smokes pass without device capture. Native core is reused, not rebuilt in this pass. Strict whole-screen visual parity remains incomplete; no 1:1 or cross-platform acceptance claim. Local checkpoint only; no release or push.
177 lines
10 KiB
JavaScript
177 lines
10 KiB
JavaScript
'use strict';
|
|
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const { EventEmitter } = require('node:events');
|
|
const { CaptureController, captureCapabilities } = require('../app/main/capture');
|
|
|
|
function fixture(options = {}) {
|
|
let time = 1000;
|
|
const frame = { url: 'app://teamspeach/index.html' };
|
|
const contents = Object.assign(new EventEmitter(), { mainFrame: frame });
|
|
const win = { isDestroyed: () => false, webContents: contents };
|
|
const source = { id: 'window:42:0', name: 'Generated capture fixture', appIcon: null };
|
|
const calls = [];
|
|
const controller = new CaptureController({ desktopCapturer: { async getSources(arg) { calls.push(arg); return [source]; } }, getWindow: () => win, appOrigin: 'app://teamspeach', platform: 'win32', release: '10.0.26100', env: {}, now: () => time, ...options });
|
|
let handler, installOptions;
|
|
controller.install({ setDisplayMediaRequestHandler(fn, opts) { handler = fn; installOptions = opts; } });
|
|
const details = { requestingUrl: frame.url, isMainFrame: true, mediaTypes: [] };
|
|
const request = { frame, securityOrigin: 'app://teamspeach/', videoRequested: true, audioRequested: false, userGesture: true };
|
|
return { controller, contents, calls, frame, source, details, request, installOptions, advance: () => { time += 16000; }, grant: (change = {}) => controller.permissionRequestAllowed(contents, 'media', { ...details, ...change }), invoke(change = {}) { let result; handler({ ...request, ...change }, value => { result = value; }); return result; }, invokeAsync(change = {}) { return new Promise(resolve => handler({ ...request, ...change }, resolve)); } };
|
|
}
|
|
async function arm(f, options = {}) {
|
|
await f.controller.listSources({ types: ['window'] });
|
|
assert.equal(f.controller.select({ sourceId: f.source.id, ...options }).ok, true);
|
|
}
|
|
|
|
test('platform decisions do not assert native verification', () => {
|
|
const windows = captureCapabilities({ platform: 'win32', release: '10.0.19045', env: {} });
|
|
assert.equal(windows.audio.system.supported, true);
|
|
assert.equal(windows.audio.excludeSelf.supported, false);
|
|
assert.equal(windows.audio.excludeSelf.verified, false);
|
|
for (const desktop of ['GNOME', 'KDE', 'Hyprland', 'niri', 'sway']) {
|
|
const linux = captureCapabilities({ platform: 'linux', release: '6.12', env: { WAYLAND_DISPLAY: 'wayland-0', XDG_CURRENT_DESKTOP: desktop } });
|
|
assert.equal(linux.backend, 'pipewire-portal');
|
|
assert.equal(linux.audio.system.supported, false);
|
|
}
|
|
assert.equal(captureCapabilities({ platform: 'linux', env: { DISPLAY: ':0' } }).backend, 'x11-desktop-capturer');
|
|
assert.equal(captureCapabilities({ platform: 'darwin', release: '24.0.0' }).nativePicker, true);
|
|
assert.equal(captureCapabilities({ platform: 'darwin', release: '23.1.0' }).audio.excludeSelf.supported, false);
|
|
assert.equal(captureCapabilities({ platform: 'darwin', release: '23.2.0' }).audio.excludeSelf.supported, true);
|
|
});
|
|
|
|
test('only explicitly enumerated source gets a single gesture-bound grant', async () => {
|
|
const f = fixture();
|
|
assert.equal(f.grant(), false);
|
|
await arm(f);
|
|
assert.deepEqual(f.calls[0].thumbnailSize, { width: 0, height: 0 });
|
|
assert.equal(f.grant(), true);
|
|
assert.equal(f.grant(), false);
|
|
assert.deepEqual(f.invoke(), { video: { id: f.source.id, name: f.source.name } });
|
|
assert.equal(f.invoke(), null);
|
|
});
|
|
|
|
test('foreign origin, subframes, camera and missing main-frame marker cannot borrow display grant', async () => {
|
|
const f = fixture();
|
|
await arm(f);
|
|
for (const details of [{ requestingUrl: 'https://example.org/' }, { isMainFrame: false }, { isMainFrame: undefined }, { mediaTypes: ['video'] }]) assert.equal(f.grant(details), false);
|
|
assert.equal(f.grant(), true);
|
|
assert.equal(f.invoke({ frame: { url: f.frame.url } }), null);
|
|
});
|
|
|
|
test('missing gesture and mismatched audio deny without fallback', async () => {
|
|
for (const change of [{ userGesture: false }, { audioRequested: true }, { securityOrigin: 'app://foreign/' }, { videoRequested: false }]) {
|
|
const f = fixture();
|
|
await arm(f); f.grant();
|
|
assert.equal(f.invoke(change), null);
|
|
assert.equal(f.controller.selection, null);
|
|
}
|
|
});
|
|
|
|
test('cancel, navigation, renderer exit, window destruction and expiry revoke pending grants', async () => {
|
|
for (const action of [f => f.controller.cancel(), f => f.contents.emit('did-start-navigation', {}, '', false, true), f => f.contents.emit('render-process-gone'), f => f.contents.emit('destroyed'), f => f.advance()]) {
|
|
const f = fixture(); await arm(f); action(f); assert.equal(f.grant(), false); f.controller.cancel();
|
|
}
|
|
});
|
|
|
|
test('unsupported application/system audio never becomes all-system capture', async () => {
|
|
const f = fixture(); await f.controller.listSources();
|
|
assert.equal(f.controller.select({ sourceId: f.source.id, audioMode: 'applications' }).error.code, 'application_audio_unavailable');
|
|
const linux = fixture({ platform: 'linux', release: '6.12', env: {} }); await linux.controller.listSources();
|
|
assert.equal(linux.controller.select({ sourceId: linux.source.id, audioMode: 'system' }).error.code, 'system_audio_unavailable');
|
|
assert.equal(linux.invoke({ audioRequested: true }), null);
|
|
});
|
|
|
|
test('system audio is explicit and never loopbackWithMute', async () => {
|
|
const f = fixture(); await arm(f, { audioMode: 'system' }); f.grant();
|
|
assert.equal(f.invoke({ audioRequested: true }).audio, 'loopback');
|
|
});
|
|
|
|
test('invalid IPC shapes and stale IDs are explicit failures', async () => {
|
|
const f = fixture();
|
|
for (const options of [null, [], 'window', { unknown: true }]) {
|
|
assert.equal((await f.controller.listSources(options)).ok, false);
|
|
assert.equal(f.controller.select(options).ok, false);
|
|
}
|
|
assert.equal(f.controller.select({ sourceId: 'screen:0:0' }).error.code, 'capture_source_expired');
|
|
});
|
|
|
|
test('camera grant allows only one video-only request and never microphone', () => {
|
|
const f = fixture();
|
|
assert.equal(f.controller.select({ sourceId: 'camera:observed-device-id' }).ok, true);
|
|
assert.equal(f.grant({ mediaTypes: ['audio', 'video'] }), false);
|
|
assert.equal(f.grant({ mediaTypes: [] }), false);
|
|
assert.equal(f.grant({ mediaTypes: ['video'] }), true);
|
|
assert.equal(f.grant({ mediaTypes: ['video'] }), false);
|
|
assert.equal(f.invoke(), null);
|
|
});
|
|
|
|
test('macOS native picker denial cannot silently select first desktop source', async () => {
|
|
const f = fixture({ platform: 'darwin', release: '24.0.0' });
|
|
const result = await f.controller.listSources();
|
|
assert.equal(result.sources[0].id, 'native-picker');
|
|
assert.equal(f.calls.length, 0);
|
|
assert.equal(f.installOptions.useSystemPicker, true);
|
|
assert.equal(f.controller.select({ sourceId: 'native-picker' }).ok, true); f.grant();
|
|
assert.equal(f.invoke(), null);
|
|
});
|
|
|
|
test('portal opens only on an explicit display request and cancellation has no fallback', async () => {
|
|
const failed = fixture({ platform: 'linux', env: { WAYLAND_DISPLAY: 'wayland-0' }, desktopCapturer: { getSources: async () => { throw new Error('chooser cancelled'); } } });
|
|
assert.equal((await failed.controller.listSources()).sources[0].id, 'native-picker');
|
|
failed.controller.select({ sourceId: 'native-picker' }); failed.grant();
|
|
assert.equal(await failed.invokeAsync(), null);
|
|
const selected = fixture({ platform: 'linux', env: { WAYLAND_DISPLAY: 'wayland-0' } });
|
|
await selected.controller.listSources();
|
|
assert.equal(selected.calls.length, 0);
|
|
selected.controller.select({ sourceId: 'native-picker' }); selected.grant();
|
|
assert.equal((await selected.invokeAsync()).video.id, selected.source.id);
|
|
let resolve;
|
|
const pending = fixture({ platform: 'linux', env: { WAYLAND_DISPLAY: 'wayland-0' }, desktopCapturer: { getSources: () => new Promise(r => { resolve = r; }) } });
|
|
pending.controller.select({ sourceId: 'native-picker' }); pending.grant();
|
|
const request = pending.invokeAsync(); pending.controller.cancel(); resolve([pending.source]);
|
|
assert.equal(await request, null);
|
|
assert.equal(pending.controller.sources.size, 0);
|
|
});
|
|
|
|
test('capture IPC requires genuine isolated-world user activation', async () => {
|
|
const f = fixture();
|
|
const handlers = new Map();
|
|
f.controller.registerIpc({ handle: (name, fn) => handlers.set(name, fn) }, () => true);
|
|
const event = { sender: f.contents, senderFrame: f.frame };
|
|
f.contents.executeJavaScriptInIsolatedWorld = async (world, scripts) => {
|
|
assert.equal(world, 1001);
|
|
assert.equal(scripts[0].code, 'navigator.userActivation.isActive');
|
|
return false;
|
|
};
|
|
assert.equal((await handlers.get('capture:select')(event, { sourceId: 'camera:test' })).error.code, 'capture_gesture_required');
|
|
f.contents.executeJavaScriptInIsolatedWorld = async () => true;
|
|
assert.equal((await handlers.get('capture:select')(event, { sourceId: 'camera:test' })).ok, true);
|
|
f.controller.cancel();
|
|
});
|
|
|
|
test('application-audio grant hooks follow successful explicit source selection', async () => {
|
|
const hooks = [];
|
|
const f = fixture({ onSelected: selection => { hooks.push(['selected', selection.sourceId]); return { appAudioSessionId: 'session' }; }, onCaptureGranted: selection => hooks.push(['granted', selection.sourceId]) });
|
|
await f.controller.listSources();
|
|
assert.equal(f.controller.select({ sourceId: f.source.id }).appAudioSessionId, 'session');
|
|
assert.deepEqual(hooks, [['selected', f.source.id]]);
|
|
f.grant(); f.invoke();
|
|
assert.deepEqual(hooks, [['selected', f.source.id], ['granted', f.source.id]]);
|
|
});
|
|
|
|
test('camera and native-picker permission consumption clears only the capture timer', () => {
|
|
for (const options of [{}, { platform: 'darwin', release: '24.0.0' }]) {
|
|
const calls = [];
|
|
const f = fixture({ ...options, onSelected: () => ({ appAudioSessionId: 'eligible-token' }), onCaptureGranted: () => calls.push('eligible') });
|
|
const native = options.platform === 'darwin';
|
|
const selected = f.controller.select({ sourceId: native ? 'native-picker' : 'camera:observed' });
|
|
assert.equal(selected.appAudioSessionId, 'eligible-token');
|
|
assert.notEqual(f.controller.timer, null);
|
|
assert.equal(f.grant({ mediaTypes: native ? [] : ['video'] }), true);
|
|
assert.equal(f.controller.timer, null);
|
|
assert.deepEqual(calls, ['eligible']);
|
|
f.controller.cancel();
|
|
assert.deepEqual(calls, ['eligible']);
|
|
}
|
|
});
|