177 lines
12 KiB
JavaScript
177 lines
12 KiB
JavaScript
// Whisper live preview / overlay switch / received-whisper history through the real (hidden, offscreen) UI.
|
|
// Presentation acceptance only: core events and snapshots are SYNTHETIC renderer input sent by this script;
|
|
// no server is contacted and nothing here proves whisper routing or delivery. Input and output stay muted,
|
|
// device capture and every network request are refused, and no key is sent to a global shortcut.
|
|
import assert from 'node:assert/strict';
|
|
import { createHash } from 'node:crypto';
|
|
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
import { tmpdir } from 'node:os';
|
|
import path from 'node:path';
|
|
import { launchApp, root, waitForAsync } from './lib/electron-app.mjs';
|
|
|
|
const args = process.argv.slice(2);
|
|
const option = (key) => (args.includes(`--${key}`) ? args[args.indexOf(`--${key}`) + 1] : undefined);
|
|
const out = path.resolve(root, option('out') ?? 'smoke-out/whisper-preview');
|
|
mkdirSync(out, { recursive: true });
|
|
const profile = mkdtempSync(path.join(tmpdir(), 'teamspeach-whisper-preview-'));
|
|
const result = { scope: 'Disposable offscreen Electron; synthetic snapshots/events; presentation only, no routing or live-server claims', checks: [], errors: [] };
|
|
// Protocol-shaped identities: base64 of a 20-byte SHA-1, like TeamSpeak client and virtual server UIDs.
|
|
const uid = (seed) => createHash('sha1').update(`teamspeach-whisper-fixture:${seed}`).digest('base64');
|
|
const SERVER = uid('server'), ME = uid('me'), ALICE = uid('alice'), BOB = uid('bob'), CAROL = uid('carol'), MALLORY = uid('mallory'), LATE = uid('late');
|
|
let app, page, revision = 0;
|
|
|
|
const send = (event) => app.evaluate(({ BrowserWindow }, value) => BrowserWindow.getAllWindows()[0].webContents.send('core:event', { ...value, connectionId: 'c1' }), event);
|
|
const member = (id, u, nickname, channel_id, extra = {}) => ({ id, uid: u, nickname, channel_id, client_type: 'normal', talk_power: 0, is_self: id === 1,
|
|
input_hardware: true, input_muted: true, output_muted: true, server_groups: [], channel_group_id: 8, ...extra });
|
|
const snapshot = (clients) => ({
|
|
event: 'snapshot', rev: ++revision, own_client_id: 1, own_channel_id: 10,
|
|
server: { uid: SERVER, name: 'Local whisper fixture — not a live server', version: 'fixture', welcome_message: '' }, server_groups: [], channel_groups: [],
|
|
channels: [
|
|
{ id: 10, parent_id: 0, depth: 0, name: 'Lobby', max_clients: -1, codec: 'opus_voice' },
|
|
{ id: 11, parent_id: 10, depth: 1, name: 'Talk', max_clients: -1, codec: 'opus_voice' },
|
|
{ id: 12, parent_id: 0, depth: 0, name: 'Other', max_clients: -1, codec: 'opus_voice' },
|
|
],
|
|
clients,
|
|
});
|
|
const base = () => [member(1, ME, 'Whisper Probe', 10), member(2, ALICE, 'Alice', 12), member(3, BOB, 'Bob', 11), member(4, CAROL, 'Carol', 10)];
|
|
const highlighted = () => page.evaluate(() => [...document.querySelectorAll('#tree .tsv-highlight-whisper-preview')]
|
|
.map((el) => (el.dataset.cid ? `c${el.dataset.cid}` : `u${el.dataset.clid}`)).sort());
|
|
const waitHighlighted = (expected) => page.waitForFunction((want) => JSON.stringify([...document.querySelectorAll('#tree .tsv-highlight-whisper-preview')]
|
|
.map((el) => (el.dataset.cid ? `c${el.dataset.cid}` : `u${el.dataset.clid}`)).sort()) === JSON.stringify(want), expected, { timeout: 10000 });
|
|
const shot = (name) => page.screenshot({ path: path.join(out, name) });
|
|
|
|
try {
|
|
app = await launchApp({ profile, exe: option('exe') });
|
|
const safety = await app.evaluate(({ BrowserWindow, session }) => {
|
|
const win = BrowserWindow.getAllWindows()[0];
|
|
win.webContents.setAudioMuted(true);
|
|
session.defaultSession.setPermissionRequestHandler((_w, _p, done) => done(false));
|
|
session.defaultSession.setPermissionCheckHandler(() => false);
|
|
session.defaultSession.setDevicePermissionHandler?.(() => false);
|
|
globalThis.__whisperBlocked = [];
|
|
session.defaultSession.webRequest.onBeforeRequest({ urls: ['http://*/*', 'https://*/*', 'ws://*/*', 'wss://*/*'] }, (details, done) => { globalThis.__whisperBlocked.push(details.url); done({ cancel: true }); });
|
|
return { visible: win.isVisible(), focused: win.isFocused(), offscreen: win.webContents.isOffscreen(), muted: win.webContents.isAudioMuted() };
|
|
});
|
|
if (safety.visible || safety.focused || !safety.offscreen || !safety.muted) throw new Error(`Unsafe window ${JSON.stringify(safety)}`);
|
|
page = await app.firstWindow();
|
|
page.on('pageerror', (e) => result.errors.push(String(e.stack || e).slice(0, 800)));
|
|
await page.evaluate(() => {
|
|
window.__forbiddenMedia = [];
|
|
for (const key of ['getUserMedia', 'getDisplayMedia']) navigator.mediaDevices[key] = async () => { window.__forbiddenMedia.push(key); throw new DOMException('Device capture forbidden in whisper QA', 'NotAllowedError'); };
|
|
});
|
|
await page.waitForSelector('#view-onboarding', { state: 'visible' });
|
|
await page.fill('#onboarding-nick', 'Whisper Probe');
|
|
await page.click('#onboarding-submit');
|
|
await page.waitForSelector('#view-app', { state: 'visible' });
|
|
await page.setViewportSize({ width: 1280, height: 800 });
|
|
|
|
// Synthetic connected session on c1, muted in and out.
|
|
await send({ event: 'state', state: 'connecting', address: 'fixture.invalid:9987' });
|
|
await send({ event: 'audio_state', input_muted: true, output_muted: true, transmitting: false });
|
|
await send(snapshot(base()));
|
|
await page.waitForSelector('#tree [data-clid="3"]');
|
|
|
|
// Real channel context menu → Settings > Whispers with the pending channel entry; "+" creates the list with it.
|
|
await page.locator('#tree [data-cid="11"] > .row-btn').click({ button: 'right' });
|
|
await page.waitForSelector('#whisper-settings .tsv-whisper-pending-entry');
|
|
await page.locator('#whisper-settings .tsv-whisper-entry-row .is-constructive').click();
|
|
await page.locator('#whisper-settings .ts-whisper-list-cell .ts-input').fill('Fixture list');
|
|
await page.keyboard.press('Enter');
|
|
await waitForAsync(page, async () => (await window.teamspeach.getWhisper()).lists[0]?.whisper_entry_list.length === 1);
|
|
// Client entry: the same call the client menu's "Add to Whisperlist" makes, then the pending-entry button.
|
|
await page.evaluate(async (alice) => (await import('./js/whisper.js')).showWhisperTargetMenu({ type: 1, uuid: alice, name: 'Alice' }), ALICE);
|
|
await page.locator('#whisper-settings .tsv-whisper-pending-entry button').click();
|
|
await waitForAsync(page, async () => (await window.teamspeach.getWhisper()).lists[0]?.whisper_entry_list.length === 2);
|
|
const stored = (await page.evaluate(() => window.teamspeach.getWhisper())).lists[0];
|
|
assert.deepEqual(stored.whisper_entry_list.map((e) => [e.type, e.name]), [[2, 'Lobby/Talk'], [1, 'Alice']]);
|
|
assert.equal(stored.whisper_entry_list[0].uuid, SERVER);
|
|
assert.equal(await page.locator('#whisper-settings .ts-whisper-keybinds-edit').count(), 1);
|
|
result.checks.push('Channel context menu and Add to Whisperlist build a stored list (channel path on this server UID + client UID)');
|
|
|
|
// Key Bindings → Edit opens the existing Key Bindings panel.
|
|
await page.locator('#whisper-settings .ts-whisper-keybinds-edit').click();
|
|
await page.waitForSelector('.settings-panel[data-panel="keys"]:not([hidden])');
|
|
await page.click('#settings-nav [data-panel="whispers"]');
|
|
result.checks.push('Whisper manager Key Bindings → Edit navigates to Settings > Key Bindings');
|
|
|
|
// Switch to Server and Overlay picks the input connection even while another tab is viewed.
|
|
await page.click('#btn-new-connection');
|
|
await waitForAsync(page, async () => {
|
|
const { S } = await import('./js/state.js');
|
|
return S.viewId !== 'c1';
|
|
});
|
|
if (await page.locator('#settings-view').isHidden()) await page.click('#btn-settings');
|
|
await page.click('#settings-nav [data-panel="whispers"]');
|
|
assert.equal(await page.locator('#whisper-settings .tsv-highlight-whisper-preview').count(), 0);
|
|
await page.locator('#whisper-settings .switch-to-overlay-button').click();
|
|
await page.waitForSelector('#whisper-overlay', { state: 'visible' });
|
|
assert.equal(await page.locator('#settings-view').isHidden(), true);
|
|
assert.equal(await page.evaluate(async () => (await import('./js/state.js')).S.viewId), 'c1');
|
|
await waitHighlighted(['c11', 'u2', 'u3']);
|
|
assert.equal(await page.evaluate(() => [...document.querySelectorAll('#whisper-overlay ul')].every(list => getComputedStyle(list).listStyleType === 'none')), true, 'overlay lists must not show browser-default bullets');
|
|
await shot('overlay-preview.png');
|
|
result.checks.push('Switch leaves settings, views c1 (the input connection) and highlights channel Talk, Bob in it and Alice by UID; never self or Carol');
|
|
|
|
// Live Preview off/on in the overlay.
|
|
await page.locator('#whisper-overlay .ts-toggle-wrapper').first().click();
|
|
await waitHighlighted([]);
|
|
await page.locator('#whisper-overlay .ts-toggle-wrapper').first().click();
|
|
await waitHighlighted(['c11', 'u2', 'u3']);
|
|
result.checks.push('Live Preview toggle clears and restores the tree highlight');
|
|
|
|
// Recycled id: client id 2 now belongs to another UID.
|
|
await send(snapshot([member(1, ME, 'Whisper Probe', 10), member(2, MALLORY, 'Mallory', 12), member(3, BOB, 'Bob', 11), member(4, CAROL, 'Carol', 10)]));
|
|
await waitHighlighted(['c11', 'u3']);
|
|
// Session change: disconnect clears everything; the next session resolves Alice under her new id.
|
|
await send({ event: 'state', state: 'disconnected' });
|
|
await waitHighlighted([]);
|
|
await send({ event: 'state', state: 'connecting', address: 'fixture.invalid:9987' });
|
|
await send({ event: 'audio_state', input_muted: true, output_muted: true, transmitting: false });
|
|
await send(snapshot([member(1, ME, 'Whisper Probe', 10), member(5, ALICE, 'Alice', 12), member(3, BOB, 'Bob', 11)]));
|
|
await waitHighlighted(['c11', 'u3', 'u5']);
|
|
result.checks.push('A recycled id with another UID is not highlighted; after a session change only the new snapshot ids are');
|
|
|
|
// History: only received whisper events; a not-yet-known speaker resolves on the next snapshot.
|
|
assert.equal(await page.locator('#whisper-history-btn').isHidden(), true);
|
|
await send({ event: 'whisper_received', client_id: 5 });
|
|
await page.waitForSelector('#whisper-history-btn', { state: 'visible' });
|
|
await page.click('#whisper-history-btn');
|
|
await page.waitForSelector('.ts-whisper-history-entry');
|
|
await send({ event: 'whisper_received', client_id: 9 });
|
|
await send(snapshot([member(1, ME, 'Whisper Probe', 10), member(5, ALICE, 'Alice', 12), member(3, BOB, 'Bob', 11), member(9, LATE, 'Late', 10)]));
|
|
await page.waitForFunction(() => document.querySelectorAll('.ts-whisper-history-entry').length === 2);
|
|
await send(snapshot([member(1, ME, 'Whisper Probe', 10), member(3, BOB, 'Bob', 11), member(9, LATE, 'Late', 10)]));
|
|
await page.waitForFunction(() => document.querySelector('.ts-whisper-history-entry.muted')?.textContent.includes('Alice'));
|
|
const rows = await page.locator('.ts-whisper-history-entry .tsv-item-text').allTextContents();
|
|
assert.equal(rows[0], 'Late');
|
|
assert.match(rows[1], /^Alice \(.+\)$/);
|
|
await shot('history-menu.png');
|
|
await page.click('.ts-whisper-history-clear');
|
|
await page.waitForSelector('.ts-whisper-history-popup', { state: 'detached' });
|
|
assert.equal(await page.locator('#whisper-history-btn').isHidden(), true);
|
|
result.checks.push('History lists received whispers newest first, resolves a late speaker, marks a departed one, and Delete clears it');
|
|
|
|
// Closing the overlay removes the preview.
|
|
await page.locator('#whisper-overlay .tsv-whisper-overlay-header .icon-btn').click();
|
|
await waitHighlighted([]);
|
|
assert.equal(await page.locator('#whisper-overlay').isHidden(), true);
|
|
result.checks.push('Closing the overlay removes every preview highlight');
|
|
|
|
result.forbiddenMedia = await page.evaluate(() => window.__forbiddenMedia);
|
|
result.blockedRequests = await app.evaluate(() => globalThis.__whisperBlocked);
|
|
result.voice = (await page.evaluate(() => window.teamspeachDiagnostics?.snapshot()))?.voice ?? null;
|
|
assert.deepEqual(result.errors, []);
|
|
result.ok = true;
|
|
} catch (error) {
|
|
result.ok = false;
|
|
result.failure = error.stack;
|
|
process.exitCode = 1;
|
|
result.highlighted = await highlighted().catch(() => null);
|
|
await page?.screenshot({ path: path.join(out, 'failure.png') }).catch(() => {});
|
|
} finally {
|
|
if (app) await app.close().catch(() => {});
|
|
rmSync(profile, { recursive: true, force: true });
|
|
writeFileSync(path.join(out, 'result.json'), JSON.stringify(result, null, 2));
|
|
console.log(JSON.stringify(result));
|
|
}
|