cat / goq
clone

turns a linux box into a private steam streaming appliance: plug in, tap your key, play from another computer

release/portal-packaging
goq / portal / window-runtime.test.mjs
window-runtime.test.mjs 2.4K
1import assert from 'node:assert/strict';2import { readFile } from 'node:fs/promises';3import test from 'node:test';45import { createWindowRuntime } from './window-runtime.mjs';67const main = await readFile(new URL('./main.js', import.meta.url), 'utf8');8const nativeMain = await readFile(9 new URL('../src-tauri/src/main.rs', import.meta.url),10 'utf8',11);12const nativeState = await readFile(13 new URL('../src-tauri/src/commands/state.rs', import.meta.url),14 'utf8',15);16const nativeCargo = await readFile(17 new URL('../src-tauri/Cargo.toml', import.meta.url),18 'utf8',19);2021function newHarness() {22 let format = { width: 1280, height: 800, epoch: 3 };23 let surfaceBounds = { width: 1920, height: 1080 };24 const surfaceSizes = [];25 const runtime = createWindowRuntime({26 getFormat: () => format,27 getSurfaceBounds: () => surfaceBounds,28 setSurfaceSize: (geometry) => surfaceSizes.push(geometry),29 });30 return {31 runtime,32 surfaceSizes,33 set format(value) { format = value; },34 set surfaceBounds(value) { surfaceBounds = value; },35 };36}3738test('surface sizing scales to available bounds without changing native window geometry', () => {39 const harness = newHarness();4041 assert.equal(harness.runtime.sizeSurfaceToIncomingStream(), true);42 assert.deepEqual(harness.surfaceSizes, [{ width: 1728, height: 1080 }]);43 assert.deepEqual(Object.keys(harness.runtime), ['sizeSurfaceToIncomingStream']);4445 harness.surfaceBounds = null;46 assert.equal(harness.runtime.sizeSurfaceToIncomingStream(), false);47 harness.format = { width: 0, height: 800, epoch: 4 };48 harness.surfaceBounds = { width: 800, height: 600 };49 assert.equal(harness.runtime.sizeSurfaceToIncomingStream(), false);50 assert.equal(harness.surfaceSizes.length, 1);51});5253test('Portal persists the user window and never derives native geometry from a stream', () => {54 assert.match(nativeCargo, /tauri-plugin-window-state = "2"/);55 assert.match(56 nativeMain,57 /\.plugin\(tauri_plugin_window_state::Builder::default\(\)\.build\(\)\)/,58 );59 assert.doesNotMatch(nativeMain, /set_client_window_size/);60 assert.doesNotMatch(nativeState, /set_client_window_size/);61 assert.doesNotMatch(main, /set_client_window_size/);62 assert.doesNotMatch(main, /fitWindowToIncomingStream/);63 assert.doesNotMatch(main, /scheduleAspectCorrection/);64 assert.match(main, /windowRuntime\.sizeSurfaceToIncomingStream\(\)/);65});