forked from Blendman974/faceclaw
139 lines
6.7 KiB
JavaScript
139 lines
6.7 KiB
JavaScript
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const { loader } = require('./helpers/load-typescript.cjs');
|
|
const graphics = require('../.test-build/app/graphics/image.js');
|
|
const planes = require('../.test-build/app/graphics/plane.js');
|
|
const { encodeShellScene } = require('../.test-build/app/graphics/shell-scene.js');
|
|
const { readPresentation, paintPresentation } = require('../.test-build/app/graphics/presentation-wire.js');
|
|
const { DrawOp } = require('../.test-build/app/graphics/display-list.js');
|
|
|
|
function fixture(width = 640, height = 480, retained = false) {
|
|
const screen = { width, height, top: 0 };
|
|
const load = loader({}, {
|
|
'../graphics/image': graphics, '../graphics/plane': planes,
|
|
'../graphics/screen-size': { screenWidth: () => screen.width, screenHeight: () => screen.height },
|
|
'../native/frame-timings': { spanCurrent: (_name, action) => action() },
|
|
'./gestures': { isDirectionalInput: () => false },
|
|
'../../graphics/image': graphics, '../../graphics/plane': planes, '../gestures': {},
|
|
'./geometry': {
|
|
appViewportSize: () => ({ width: screen.width - 64, height: Math.min(288, screen.height) }),
|
|
appViewportRect: () => ({ x: 32, y: screen.top, width: screen.width - 64, height: Math.min(288, screen.height) }),
|
|
SHELL_OPAQUE_BLACK: 1,
|
|
},
|
|
});
|
|
const { LayerStack, noopLayerActions } = load('app/ui/layers.ts');
|
|
const { ShellModalLayer, modalRect } = load('app/ui/shell/modal-layer.ts');
|
|
let lowerPaints = 0, innerSize, removed = 0;
|
|
const background = { paint() {
|
|
lowerPaints++;
|
|
const image = new graphics.GrayImage(screen.width, screen.height);
|
|
image.fillRect(0, 0, 24, 100, 170);
|
|
return image;
|
|
} };
|
|
const stack = new LayerStack(background, noopLayerActions);
|
|
const inner = {
|
|
paint(ctx) {
|
|
innerSize = ctx.stack.getBaseSize();
|
|
const image = new graphics.GrayImage(innerSize.width, innerSize.height);
|
|
image.fillRect(6, 6, 8, 8, 240);
|
|
if (retained) image.drawMenuSelection(new graphics.GrayImage(20, 12, 255), 20, 18, 60, 120, 3, 0);
|
|
return image;
|
|
},
|
|
handleInput() {},
|
|
};
|
|
const modal = new ShellModalLayer(inner, noopLayerActions, { removed() { removed++; } });
|
|
return { screen, stack, modal, modalRect, innerSize: () => innerSize, lowerPaints: () => lowerPaints, removed: () => removed };
|
|
}
|
|
|
|
// Real shell encoder and presentation decoder, replayed over a separate app
|
|
// in native ShellScene.calls order: opaque cropped surface, then retained calls.
|
|
function sceneFrame(f, appValue = 200) {
|
|
const bytes = encodeShellScene(f.stack.paintUndimmed());
|
|
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
const frame = new graphics.GrayImage(f.screen.width, f.screen.height, appValue);
|
|
const original = frame.pixels.slice(), layers = [];
|
|
let p = 2;
|
|
for (let i = 0; i < view.getUint16(0, true); i++) {
|
|
const x = view.getInt16(p + 2, true), y = view.getInt16(p + 4, true);
|
|
const width = view.getUint16(p + 6, true), height = view.getUint16(p + 8, true);
|
|
const count = view.getUint16(p + 12, true);
|
|
assert.ok(5 + Math.ceil(width / 2) * height <= 65536);
|
|
assert.equal(view.getUint16(p + 10, true), 256, 'vector mask does not rely on zero dim keeping no halftone');
|
|
const image = new graphics.GrayImage(width, height);
|
|
image.pixels.set(bytes.subarray(p + 16, p + 16 + width * height));
|
|
frame.bitBlt(image, x, y);
|
|
p += 16 + width * height;
|
|
const selections = [];
|
|
for (let j = 0; j < count; j++) {
|
|
const record = readPresentation(bytes, p);
|
|
selections.push(record.selection);
|
|
paintPresentation(frame.pixels, original, frame.width, frame.height, record.selection);
|
|
p = record.end;
|
|
}
|
|
layers.push({ x, y, width, height, selections });
|
|
}
|
|
assert.equal(p + 2, bytes.length, 'complete scene decoded');
|
|
return { frame, layers, bytes };
|
|
}
|
|
|
|
test('G2 notification serializes through the production shell scene within one 64 KiB surface', () => {
|
|
const f = fixture();
|
|
f.stack.push(f.modal);
|
|
const { layers } = sceneFrame(f);
|
|
assert.equal(layers.length, 1);
|
|
assert.deepEqual({ ...layers[0], selections: undefined }, { ...f.modalRect(), selections: undefined });
|
|
assert.equal(f.lowerPaints(), 0, 'chrome must not enter the scene');
|
|
const mask = layers[0].selections[0].displayList;
|
|
assert.equal(mask.resources.length, 0, 'no full-screen image or image tiles');
|
|
assert.ok(mask.calls.every(call => call.op === DrawOp.CLEAR && call.color === 0 && call.clip));
|
|
});
|
|
|
|
test('notification omits chrome and blacks out a separate app until dismissed', () => {
|
|
const f = fixture(), before = sceneFrame(f).frame;
|
|
assert.equal(f.lowerPaints(), 1);
|
|
f.stack.push(f.modal);
|
|
const { frame, layers } = sceneFrame(f);
|
|
assert.equal(f.lowerPaints(), 1);
|
|
assert.equal(layers.length, 1);
|
|
assert.equal(frame.getPixel(0, 0), 0);
|
|
assert.equal(frame.getPixel(639, 479), 0);
|
|
assert.ok(!frame.pixels.includes(200), 'margins hide separate app surface');
|
|
assert.ok(!frame.pixels.includes(170), 'status bar and switcher hidden');
|
|
assert.ok(frame.pixels.includes(240), 'notification remains visible');
|
|
f.stack.pop();
|
|
assert.equal(f.removed(), 1);
|
|
const closed = sceneFrame(f);
|
|
assert.deepEqual(closed.frame.pixels, before.pixels);
|
|
assert.equal(closed.layers[0].selections.length, 0, 'dismiss removes blackout');
|
|
});
|
|
|
|
test('notification mask follows resize, band position and restore without covering content', () => {
|
|
const f = fixture();
|
|
f.stack.push(f.modal);
|
|
for (const [width, height, top] of [[640, 480, 0], [540, 220, 0], [640, 480, 192], [640, 480, 0]]) {
|
|
Object.assign(f.screen, { width, height, top });
|
|
const { frame, layers } = sceneFrame(f), rect = f.modalRect();
|
|
assert.equal(frame.getPixel(width - 1, height - 1), 0);
|
|
assert.equal(frame.getPixel(rect.x, rect.y), 110);
|
|
assert.equal(frame.getPixel(rect.x + 2, rect.y + 2), 1, 'interior opaque black');
|
|
assert.equal(frame.getPixel(rect.x + 10, rect.y + 10), 240);
|
|
assert.ok(!frame.pixels.includes(200), 'no app pixels survive');
|
|
assert.equal(layers[0].height, rect.height);
|
|
assert.deepEqual({ ...f.innerSize() }, { width: rect.width - 8, height: rect.height - 8 });
|
|
}
|
|
});
|
|
|
|
test('notification retains inner menu presentations after blackout with correct offsets', () => {
|
|
const f = fixture(640, 480, true);
|
|
f.stack.push(f.modal);
|
|
const { layers, frame } = sceneFrame(f), rect = f.modalRect();
|
|
const { selections } = layers[0];
|
|
assert.equal(selections.length, 2, 'mask and selection both cross real encoder');
|
|
const row = selections[0];
|
|
assert.ok(row.displayList, 'selection is retained, not a frozen raster');
|
|
assert.equal(row.x, rect.x + 4 + 20);
|
|
assert.equal(row.y, rect.y + 4 + 18);
|
|
assert.equal(frame.getPixel(row.x + 10, row.y + 6), 240);
|
|
assert.equal(frame.getPixel(0, 0), 0);
|
|
});
|