const test = require('node:test'); const assert = require('node:assert/strict'); const { loader } = require('./helpers/load-typescript.cjs'); const { GrayImage } = require('../.test-build/app/graphics/image.js'); function fixture() { let options, hooks; const paints = [], heights = []; const session = { manifest: { name: 'Test', packageId: 'test.app' }, renderWindowIcon() {}, contextMenuItems: () => [], keepsScreenOn: () => false, attachWindow(value) { hooks = value; }, paint(size, focused) { paints.push({ ...size, focused }); const image = new GrayImage(size.width, size.height); image.setPixel(0, 0, 255); image.setPixel(size.width - 1, size.height - 1, 120); // Deliberately overflow a deferred text run: stock clips it at 576x288. image.drawFwText({ bakeFwTextRun(target, run, dx, dy) { target.fillRect(run.x + dx, run.y + dy, 20, 20, run.value); } }, 570, 280, 200, [{}]); return image; }, }; const load = loader({}, { '../../graphics/image': { GrayImage }, './compositor': { EVENHUB_SCREEN_WIDTH: 576, EVENHUB_SCREEN_HEIGHT: 288 }, '../../ui/gestures': {}, '../../ui/shell/shell': { shell: {} }, './session': {}, '../../ui/shell/chrome-layer': { windowIcon: () => () => null, makeImageWindowIcon: () => () => null }, './installed-apps': {}, '../../ui/shell/in-process-window': { createInProcessWindow(value) { options = value; return { window: {}, stack: {}, requestRender() {}, setHeightMode(mode) { heights.push(mode); } }; } }, }); load('app/apps/evenhub/evenhub-window.ts').createEvenHubWindow('test', 'test', session, {}, () => {}, () => {}); return { paints, heights, hooks: () => hooks, paint(width, height, focused = true) { return options.baseLayer.paint({ stack: { getBaseSize: () => ({ width, height }), isFocused: () => focused } }); }, }; } test('stock EvenHub canvas remains 576x288 through full-screen entry, resize and exit', () => { const f = fixture(); for (const [width, height] of [[576, 288], [640, 480], [576, 452], [640, 480], [576, 288]]) { const image = f.paint(width, height); assert.deepEqual(f.paints.at(-1), { width: 576, height: 288, focused: true }); assert.equal(image.width, width); assert.equal(image.height, height); } }); test('full screen centers stock pixels at native scale and clips overflowing text to the stock canvas', () => { const f = fixture(); const stock = f.paint(576, 288).withDrawsBaked(); const full = f.paint(640, 480).withDrawsBaked(); for (let y = 0; y < 480; y++) { for (let x = 0; x < 640; x++) { const expected = x >= 32 && x < 608 && y >= 96 && y < 384 ? stock.getPixel(x - 32, y - 96) : 0; assert.equal(full.getPixel(x, y), expected); } } }); test('only an explicit extended-layout request opts into the taller canvas', () => { const f = fixture(); f.paint(640, 480, false); assert.deepEqual(f.paints.at(-1), { width: 576, height: 288, focused: false }); f.hooks().setTallCanvas(true); assert.deepEqual(f.heights, ['max']); f.paint(576, 452); assert.equal(f.paints.at(-1).height, 452); f.paint(640, 480); assert.equal(f.paints.at(-1).width, 576); assert.equal(f.paints.at(-1).height, 480); f.hooks().setTallCanvas(false); f.paint(640, 480); assert.deepEqual(f.heights, ['max', 'medium']); assert.equal(f.paints.at(-1).height, 288); });