mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-30 16:39:33 +01:00
Toolbar Enter spends one-shot Ctrl; Backspace finds the last grapheme with Segments.containing(); accessory Shift+Tab keeps the draft like a typed one. Pass the captured session to Compose uploads, voice compose and held CJK drafts; clear Ctrl on deletion-only native edits; path picker clears predictions. Clear xterm dead-key state on native commits; restore a borrowed clipboard field before classifying a key; overlay removeChar spans the pending/flushed boundary. Place the trackpad caret from the overlay layout (getInputAnchor, committedText) or validated xterm cells, hiding when unproven; no end-minus-width arithmetic. Grapheme-aware replay Backspace; docs, README rows, changeset and comment updates.
501 lines
22 KiB
TypeScript
501 lines
22 KiB
TypeScript
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
|
||
import { chromium, type Browser, type BrowserContext, type Page } from 'playwright';
|
||
import { WebServer } from '../src/web/server.js';
|
||
import { resolve } from 'node:path';
|
||
// Browser globals are installed by classic scripts, outside TypeScript's module graph.
|
||
type SentInput = { id: string; input: string; time: number };
|
||
type CellAnchor = { col: number; row: number };
|
||
interface TestTerminal {
|
||
textarea: HTMLTextAreaElement;
|
||
element: HTMLElement;
|
||
write(text: string, callback: () => void): void;
|
||
cols: number;
|
||
scrollToTop(): void;
|
||
buffer: { active: { cursorX: number; cursorY: number; viewportY: number; baseY: number } };
|
||
_core: {
|
||
_renderService: { dimensions: { css: { cell: { width: number; height: number } } } };
|
||
_customKeyEventHandler(event: KeyboardEvent): boolean;
|
||
};
|
||
}
|
||
interface NativeOwner {
|
||
reset(reason: string): void;
|
||
}
|
||
interface TestApp {
|
||
terminal: TestTerminal;
|
||
fitAddon: { proposeDimensions(): { cols: number; rows: number } | undefined };
|
||
syncTerminalGeometry(): { cols: number; rows: number } | null;
|
||
_resizeTimeout: number | null;
|
||
activeSessionId: string;
|
||
sessions: Map<string, { id: string; mode: string; status?: string }>;
|
||
_localEchoEnabled: boolean;
|
||
_isLoadingBuffer: boolean;
|
||
_echoPassthroughSessions?: Set<string>;
|
||
_localEchoOverlay: { clear(): void; pendingText: string; getInputEndAnchor(): CellAnchor | null };
|
||
_iosNativeInput: NativeOwner;
|
||
_keyCode229Recovery: unknown;
|
||
_enqueueReliableInput(id: string, input: string): unknown;
|
||
}
|
||
interface TestWindow extends Window {
|
||
app: TestApp;
|
||
__sent: SentInput[];
|
||
CodemanIosNativeInput: { isSupported(): boolean };
|
||
IosReplay: {
|
||
typeKey(ta: HTMLTextAreaElement, text: string): void;
|
||
kev(type: string, key: string, keyCode: number, extra?: { shiftKey?: boolean; ctrlKey?: boolean }): KeyboardEvent;
|
||
edit(ta: HTMLTextAreaElement, inputType: string, data: string): boolean;
|
||
};
|
||
TerminalTile: new (
|
||
id: string,
|
||
mount: HTMLElement,
|
||
options: { mode: string }
|
||
) => {
|
||
connect(): Promise<void>;
|
||
destroy(): void;
|
||
terminal: TestTerminal;
|
||
_iosNativeInput: NativeOwner;
|
||
_keyCode229Recovery: unknown;
|
||
};
|
||
}
|
||
// Real platform timers intentionally cover native reconciliation and the FIFO's 80ms gap.
|
||
|
||
const IOS_UA =
|
||
'Mozilla/5.0 (iPhone; CPU iPhone OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.5.2 Mobile/15E148 Safari/604.1';
|
||
const SESSION = 'ios830-browser';
|
||
|
||
describe('iOS native input served-app wiring (#830)', () => {
|
||
let server: WebServer;
|
||
let browser: Browser;
|
||
let context: BrowserContext;
|
||
let page: Page;
|
||
let baseUrl: string;
|
||
|
||
beforeAll(async () => {
|
||
server = new WebServer(0, false, true);
|
||
await server.start();
|
||
baseUrl = `http://localhost:${server.boundPort}`;
|
||
browser = await chromium.launch({ headless: true });
|
||
context = await browser.newContext({
|
||
userAgent: IOS_UA,
|
||
hasTouch: true,
|
||
permissions: ['clipboard-read', 'clipboard-write'],
|
||
});
|
||
await context.addInitScript(() => {
|
||
Object.defineProperty(navigator, 'maxTouchPoints', { get: () => 5 });
|
||
const native = window.matchMedia.bind(window);
|
||
window.matchMedia = (query) => {
|
||
const result = native(query);
|
||
if (query === '(pointer: coarse)') Object.defineProperty(result, 'matches', { value: true });
|
||
return result;
|
||
};
|
||
});
|
||
}, 90000);
|
||
|
||
afterAll(async () => {
|
||
await browser?.close();
|
||
await server?.stop();
|
||
}, 60000);
|
||
|
||
async function setup(echo: boolean) {
|
||
if (page) await page.close();
|
||
page = await context.newPage();
|
||
await page.goto(baseUrl, { waitUntil: 'domcontentloaded' });
|
||
await page.waitForFunction(() => (window as unknown as TestWindow).app?._iosNativeInput, null, { timeout: 30000 });
|
||
await page.evaluate(
|
||
async ({ echo, session }) => {
|
||
const w = window as unknown as TestWindow;
|
||
const app = w.app;
|
||
app.activeSessionId = session;
|
||
app.sessions.set(session, { id: session, mode: 'shell', status: 'idle' });
|
||
app._localEchoEnabled = echo;
|
||
app._isLoadingBuffer = false;
|
||
app._echoPassthroughSessions?.delete(session);
|
||
app._localEchoOverlay.clear();
|
||
app._iosNativeInput.reset('test');
|
||
w.__sent = [];
|
||
// Observe the real FIFO/handleTerminalData boundary, not _sendInputAsync.
|
||
app._enqueueReliableInput = (id: string, input: string) =>
|
||
w.__sent.push({ id, input, time: performance.now() });
|
||
await new Promise<void>((resolve) => app.terminal.write('\x1bc❯ ', resolve));
|
||
app.terminal.textarea.focus();
|
||
},
|
||
{ echo, session: SESSION }
|
||
);
|
||
expect(
|
||
await page.evaluate(() => ({
|
||
supported: (window as unknown as TestWindow).CodemanIosNativeInput.isSupported(),
|
||
recovery: (window as unknown as TestWindow).app._keyCode229Recovery,
|
||
}))
|
||
).toEqual({ supported: true, recovery: null });
|
||
await page.addScriptTag({ path: resolve(import.meta.dirname, 'fixtures/ios-native-replay.js') });
|
||
}
|
||
|
||
async function run(action: string) {
|
||
return page.evaluate(async (action) => {
|
||
const w = window as unknown as TestWindow;
|
||
const app = w.app;
|
||
const ta = app.terminal.textarea;
|
||
const r = w.IosReplay;
|
||
const type = async (text: string) => {
|
||
for (const ch of text) {
|
||
r.typeKey(ta, ch);
|
||
await new Promise((resolve) => setTimeout(resolve, 20));
|
||
}
|
||
};
|
||
await new Function('app', 'ta', 'r', 'type', `return (async () => { ${action} })()`)(app, ta, r, type);
|
||
await new Promise((resolve) => setTimeout(resolve, 30));
|
||
return { sent: w.__sent, pending: app._localEchoOverlay.pendingText, value: ta.value };
|
||
}, action);
|
||
}
|
||
|
||
async function markerCell() {
|
||
return page.evaluate(() => {
|
||
const terminal = (window as unknown as TestWindow).app.terminal;
|
||
const marker = terminal.element.querySelector<HTMLElement>('.ios-native-caret')!;
|
||
const cell = terminal._core._renderService.dimensions.css.cell;
|
||
return {
|
||
display: marker.style.display,
|
||
col: Math.round(parseFloat(marker.style.left) / cell.width),
|
||
row: Math.round(parseFloat(marker.style.top) / cell.height),
|
||
};
|
||
});
|
||
}
|
||
|
||
for (const echo of [false, true]) {
|
||
it(`suggestion commits hello once, and Enter preserves the 80ms gap (echo ${echo})`, async () => {
|
||
await setup(echo);
|
||
const before = await run("await type('hel'); r.typeKey(ta, 'lo');");
|
||
expect(before.sent.map((x) => x.input)).toEqual(echo ? [] : ['h', 'e', 'l', 'lo']);
|
||
const result = await run('r.enter(ta); await new Promise(resolve => setTimeout(resolve, 110));');
|
||
expect(result.sent.map((x) => x.input)).toEqual(echo ? ['hello', '\r'] : ['h', 'e', 'l', 'lo', '\r']);
|
||
if (echo) expect(result.sent[1].time - result.sent[0].time).toBeGreaterThanOrEqual(75);
|
||
});
|
||
|
||
it(`phrase replacement has no stale prefix (echo ${echo})`, async () => {
|
||
await setup(echo);
|
||
let result = await run("await type('helloworl'); r.replaceSuggestion(ta, 0, 9, 'Hello World');");
|
||
if (echo) result = await run('r.enter(ta); await new Promise(resolve => setTimeout(resolve, 110));');
|
||
expect(terminalLine(result.sent.map((x) => x.input).join('')).replace(/\r$/, '')).toBe('Hello World');
|
||
});
|
||
|
||
it(`keyless hold-delete bursts empty the line (echo ${echo})`, async () => {
|
||
await setup(echo);
|
||
const result = await run("await type('hello'); r.holdDeleteRepeat(ta, 8);");
|
||
expect(result.value).toBe('');
|
||
expect(terminalLine(result.sent.map((x) => x.input).join(''))).toBe('');
|
||
if (echo) {
|
||
expect(result.sent).toEqual([]);
|
||
expect(result.pending).toBe('');
|
||
}
|
||
});
|
||
|
||
it(`dictation replacement and line break never submit (echo ${echo})`, async () => {
|
||
await setup(echo);
|
||
const result = await run(
|
||
"r.edit(ta, 'insertText', 'hello'); r.edit(ta, 'insertText', 'Hello World', [0, 5]); r.edit(ta, 'insertLineBreak', null);"
|
||
);
|
||
// The native field retains dictated newlines; only the shell projection excludes them.
|
||
expect(result.value).toBe('Hello World\n');
|
||
expect(result.sent.some((x) => /[\r\n]/.test(x.input))).toBe(false);
|
||
});
|
||
|
||
it(`toolbar Enter resets the next suggestion baseline (echo ${echo})`, async () => {
|
||
await setup(echo);
|
||
await run("await type('hel'); r.typeKey(ta, 'lo');");
|
||
await page
|
||
.locator('button[onclick="app.sendEnterKey()"]')
|
||
.evaluate((button: HTMLButtonElement) => button.click());
|
||
const result = await run("r.typeKey(ta, 'lo'); await new Promise(resolve => setTimeout(resolve, 110));");
|
||
expect(result.value).toBe('lo');
|
||
expect(result.sent.some((x) => x.input.includes('\x7f'))).toBe(false);
|
||
expect(result.sent.map((x) => x.input).join('')).toBe(echo ? 'hello\r' : 'hello\rlo');
|
||
if (echo) expect(result.pending).toBe('lo');
|
||
});
|
||
|
||
it(`trackpad caret marker sits at cell (4, 0) after he in hello (echo ${echo})`, async () => {
|
||
await setup(echo);
|
||
await run(
|
||
"await type('hello'); if (!app._localEchoEnabled) await new Promise(resolve => app.terminal.write('hello', resolve)); r.caret(ta, 2);"
|
||
);
|
||
expect(await markerCell()).toEqual({ display: 'block', col: 4, row: 0 });
|
||
});
|
||
|
||
it(`a你b wide wrap maps offsets to (78, 0), (0, 1), (2, 1) (echo ${echo})`, async () => {
|
||
await setup(echo);
|
||
await page.evaluate(async () => {
|
||
const app = (window as unknown as TestWindow).app;
|
||
const container = app.terminal.element.parentElement!;
|
||
const proposed = app.fitAddon.proposeDimensions()!;
|
||
const cell = app.terminal._core._renderService.dimensions.css.cell;
|
||
// A raw terminal.resize(80, ...) is undone by the app's ResizeObserver.
|
||
// Size its real box instead, so every subsequent auto-fit also yields 80.
|
||
const width = parseFloat(getComputedStyle(container).width) + (80 - proposed.cols) * cell.width;
|
||
container.style.width = container.style.minWidth = container.style.maxWidth = `${width}px`;
|
||
app.syncTerminalGeometry();
|
||
const layout = Promise.withResolvers<void>();
|
||
requestAnimationFrame(() => requestAnimationFrame(() => layout.resolve()));
|
||
await layout.promise;
|
||
});
|
||
// The real 300ms resize handler can clear the viewport; let it finish
|
||
// before installing the prompt and typing the native field.
|
||
await page.waitForFunction(() => {
|
||
const app = (window as unknown as TestWindow).app;
|
||
return app.terminal.cols === 80 && app._resizeTimeout === null;
|
||
});
|
||
await page.evaluate(async () => {
|
||
const app = (window as unknown as TestWindow).app;
|
||
const written = Promise.withResolvers<void>();
|
||
app.terminal.write('\x1bc' + '.'.repeat(76) + '❯ ', written.resolve);
|
||
await written.promise;
|
||
});
|
||
await run(
|
||
"await type('a你b'); if (!app._localEchoEnabled) await new Promise(resolve => app.terminal.write('a你b', resolve));"
|
||
);
|
||
for (const [offset, col, row] of [
|
||
[0, 78, 0],
|
||
[1, 0, 1],
|
||
[2, 2, 1],
|
||
]) {
|
||
await run(`r.caret(ta, ${offset});`);
|
||
expect(await page.evaluate(() => (window as unknown as TestWindow).app.terminal.cols)).toBe(80);
|
||
expect(await markerCell()).toEqual({ display: 'block', col, row });
|
||
}
|
||
});
|
||
|
||
it(`typing while scrolled back returns the viewport to the prompt (echo ${echo})`, async () => {
|
||
await setup(echo);
|
||
const scrolled = await page.evaluate(async () => {
|
||
const terminal = (window as unknown as TestWindow).app.terminal;
|
||
const written = Promise.withResolvers<void>();
|
||
terminal.write('line\r\n'.repeat(200) + '❯ ', written.resolve);
|
||
await written.promise;
|
||
terminal.scrollToTop();
|
||
return { viewportY: terminal.buffer.active.viewportY, baseY: terminal.buffer.active.baseY };
|
||
});
|
||
expect(scrolled.viewportY).toBe(0);
|
||
expect(scrolled.baseY).toBeGreaterThan(0);
|
||
const result = await run("await type('h');");
|
||
expect(result.sent.map((x) => x.input)).toEqual(echo ? [] : ['h']);
|
||
const viewport = await page.evaluate(() => {
|
||
const buffer = (window as unknown as TestWindow).app.terminal.buffer.active;
|
||
return { viewportY: buffer.viewportY, baseY: buffer.baseY };
|
||
});
|
||
expect(viewport.viewportY).toBe(viewport.baseY);
|
||
});
|
||
|
||
it(`toolbar Enter while scrolled back returns the viewport to the prompt (echo ${echo})`, async () => {
|
||
await setup(echo);
|
||
const scrolled = await page.evaluate(async () => {
|
||
const terminal = (window as unknown as TestWindow).app.terminal;
|
||
const written = Promise.withResolvers<void>();
|
||
terminal.write('line\r\n'.repeat(200) + '❯ ', written.resolve);
|
||
await written.promise;
|
||
terminal.scrollToTop();
|
||
return { viewportY: terminal.buffer.active.viewportY, baseY: terminal.buffer.active.baseY };
|
||
});
|
||
expect(scrolled.viewportY).toBe(0);
|
||
expect(scrolled.baseY).toBeGreaterThan(0);
|
||
await page
|
||
.locator('button[onclick="app.sendEnterKey()"]')
|
||
.evaluate((button: HTMLButtonElement) => button.click());
|
||
// Echo on delivers the CR after the local-echo gap: wait for it on the wire.
|
||
await page.waitForFunction(() => (window as unknown as TestWindow).__sent.some((x) => x.input === '\r'));
|
||
const sent = await page.evaluate(() => (window as unknown as TestWindow).__sent.map((x) => x.input));
|
||
expect(sent).toEqual(['\r']);
|
||
const viewport = await page.evaluate(() => {
|
||
const buffer = (window as unknown as TestWindow).app.terminal.buffer.active;
|
||
return { viewportY: buffer.viewportY, baseY: buffer.baseY };
|
||
});
|
||
expect(viewport.viewportY).toBe(viewport.baseY);
|
||
});
|
||
}
|
||
|
||
for (const target of ['main', 'tile'] as const) {
|
||
for (const modifier of ['shiftKey', 'ctrlKey'] as const) {
|
||
it(`${target} ${modifier} Enter submits only on keydown and swallows keypress/keyup`, async () => {
|
||
await setup(false);
|
||
const result = await page.evaluate(
|
||
async ({ target, modifier, session }) => {
|
||
const w = window as unknown as TestWindow;
|
||
const mount = document.createElement('div');
|
||
document.body.appendChild(mount);
|
||
const tile = target === 'tile' ? new w.TerminalTile(session, mount, { mode: 'shell' }) : null;
|
||
const originalFetch = window.fetch;
|
||
const submitted: unknown[] = [];
|
||
window.fetch = async (input, init) => {
|
||
if (String(input).endsWith(`/api/sessions/${session}/send-key`)) {
|
||
submitted.push(JSON.parse(String(init?.body)));
|
||
return new Response('{}', { status: 200 });
|
||
}
|
||
return originalFetch(input, init);
|
||
};
|
||
try {
|
||
if (tile) await tile.connect();
|
||
const terminal = tile ? tile.terminal : w.app.terminal;
|
||
// Invoke the installed xterm handler for every phase. xterm can deliver
|
||
// keypress even after keydown returns false (the original Shift+Enter bug).
|
||
const phases = [];
|
||
for (const type of ['keydown', 'keypress', 'keyup']) {
|
||
const accepted = terminal._core._customKeyEventHandler(
|
||
w.IosReplay.kev(type, 'Enter', 13, { [modifier]: true })
|
||
);
|
||
await new Promise((resolve) => setTimeout(resolve, 30));
|
||
phases.push({ accepted, submitted: [...submitted], sent: [...w.__sent] });
|
||
}
|
||
return phases;
|
||
} finally {
|
||
window.fetch = originalFetch;
|
||
tile?.destroy();
|
||
mount.remove();
|
||
}
|
||
},
|
||
{ target, modifier, session: SESSION }
|
||
);
|
||
const submission = { key: modifier === 'ctrlKey' ? 'C-Enter' : 'S-Enter' };
|
||
expect(result).toEqual([
|
||
{ accepted: false, submitted: [submission], sent: [] },
|
||
{ accepted: false, submitted: [submission], sent: [] },
|
||
{ accepted: false, submitted: [submission], sent: [] },
|
||
]);
|
||
});
|
||
}
|
||
}
|
||
|
||
for (const modifier of ['shiftKey', 'ctrlKey'] as const) {
|
||
it(`main iOS suggestion word Enter with ${modifier} and non-13 keyCode stays text`, async () => {
|
||
await setup(false);
|
||
const result = await page.evaluate(async (modifier) => {
|
||
const w = window as unknown as TestWindow;
|
||
const app = w.app;
|
||
const submitted: string[] = [];
|
||
const originalFetch = window.fetch;
|
||
window.fetch = async (input, init) => {
|
||
if (String(input).endsWith('/send-key')) {
|
||
submitted.push(String(init?.body));
|
||
return new Response('{}', { status: 200 });
|
||
}
|
||
return originalFetch(input, init);
|
||
};
|
||
try {
|
||
const ta = app.terminal.textarea;
|
||
app.terminal._core._customKeyEventHandler(w.IosReplay.kev('keydown', 'Enter', 69, { [modifier]: true }));
|
||
app.terminal._core._customKeyEventHandler(w.IosReplay.kev('keypress', 'Enter', 69, { [modifier]: true }));
|
||
w.IosReplay.edit(ta, 'insertText', 'Enter');
|
||
app.terminal._core._customKeyEventHandler(w.IosReplay.kev('keyup', 'Enter', 69, { [modifier]: true }));
|
||
await new Promise((resolve) => setTimeout(resolve, 110));
|
||
return { submitted, sent: w.__sent.map((x) => x.input), value: ta.value };
|
||
} finally {
|
||
window.fetch = originalFetch;
|
||
}
|
||
}, modifier);
|
||
expect(result).toEqual({ submitted: [], sent: ['Enter'], value: 'Enter' });
|
||
});
|
||
}
|
||
|
||
it('retains the old session for Enter during its 80ms window', async () => {
|
||
await setup(true);
|
||
const result = await run(
|
||
"await type('hello'); r.enter(ta); app.sessions.set('ios830-second', { id: 'ios830-second', mode: 'shell' }); app._cleanupPreviousSession(app.activeSessionId); app.activeSessionId = 'ios830-second'; await new Promise(resolve => setTimeout(resolve, 110));"
|
||
);
|
||
expect(result.sent.map((x) => [x.id, x.input])).toEqual([
|
||
[SESSION, 'hello'],
|
||
[SESSION, '\r'],
|
||
]);
|
||
});
|
||
|
||
it('trusted Chromium paste arrives once', async () => {
|
||
await setup(false);
|
||
await page.evaluate(() => navigator.clipboard.writeText('trusted paste'));
|
||
const cdp = await context.newCDPSession(page);
|
||
await cdp.send('Input.dispatchKeyEvent', {
|
||
type: 'rawKeyDown',
|
||
key: 'Unidentified',
|
||
code: '',
|
||
windowsVirtualKeyCode: 0,
|
||
commands: ['paste'],
|
||
});
|
||
await cdp.send('Input.dispatchKeyEvent', {
|
||
type: 'keyUp',
|
||
key: 'Unidentified',
|
||
code: '',
|
||
windowsVirtualKeyCode: 0,
|
||
});
|
||
const result = await run('');
|
||
expect(result.sent.map((x) => x.input)).toEqual(['trusted paste']);
|
||
await cdp.detach();
|
||
});
|
||
|
||
it('emoji deletion leaves no lone surrogate in pending echo', async () => {
|
||
await setup(true);
|
||
const result = await run("await type('a😀'); r.backspace(ta);");
|
||
expect(result.pending).toBe('a');
|
||
expect(result.sent).toEqual([]);
|
||
});
|
||
|
||
for (const echo of [false, true]) {
|
||
it.each([
|
||
['red heart', '\u2764\uFE0F'],
|
||
['skin-tone thumbs up', '\u{1F44D}\u{1F3FD}'],
|
||
['flag', '\u{1F1EB}\u{1F1F7}'],
|
||
['ZWJ family', '\u{1F468}\u200D\u{1F469}\u200D\u{1F467}\u200D\u{1F466}'],
|
||
])(`deletes a whole %s grapheme with one backspace (echo ${echo})`, async (_name, emoji) => {
|
||
await setup(echo);
|
||
const result = await run(`await type(${JSON.stringify('ok' + emoji)}); r.backspace(ta);`);
|
||
expect(result.value).toBe('ok');
|
||
expect(result.pending).toBe(echo ? 'ok' : '');
|
||
expect(result.sent.map((x) => x.input)).toEqual(echo ? [] : [...('ok' + emoji), '\x7f']);
|
||
});
|
||
}
|
||
|
||
it('a Pane B/grid TerminalTile owns suggestions for its session without 229 recovery', async () => {
|
||
await setup(false);
|
||
const result = await page.evaluate(async () => {
|
||
const w = window as unknown as TestWindow;
|
||
const mount = document.createElement('div');
|
||
mount.style.cssText = 'position:fixed;left:0;top:0;width:480px;height:320px;z-index:9999';
|
||
document.body.appendChild(mount);
|
||
w.app.sessions.set('ios830-tile', { id: 'ios830-tile', mode: 'shell', status: 'idle' });
|
||
const tile = new w.TerminalTile('ios830-tile', mount, { mode: 'shell' });
|
||
try {
|
||
await tile.connect();
|
||
const ta = tile.terminal.textarea;
|
||
ta.focus();
|
||
for (const ch of 'hel') w.IosReplay.typeKey(ta, ch);
|
||
w.IosReplay.typeKey(ta, 'lo');
|
||
await new Promise((resolve) => setTimeout(resolve, 40));
|
||
return { owner: !!tile._iosNativeInput, recovery: tile._keyCode229Recovery, sent: w.__sent };
|
||
} finally {
|
||
tile.destroy();
|
||
mount.remove();
|
||
}
|
||
});
|
||
expect(result.owner).toBe(true);
|
||
expect(result.recovery).toBeNull();
|
||
expect(result.sent.map((x) => [x.id, x.input])).toEqual(
|
||
['h', 'e', 'l', 'lo'].map((input) => ['ios830-tile', input])
|
||
);
|
||
});
|
||
|
||
it('non-iOS coarse-pointer pages retain 229 recovery', async () => {
|
||
const other = await browser.newContext({ hasTouch: true });
|
||
const desktop = await other.newPage();
|
||
try {
|
||
await desktop.goto(baseUrl, { waitUntil: 'domcontentloaded' });
|
||
await desktop.waitForFunction(() => (window as unknown as TestWindow).app?._keyCode229Recovery, null, {
|
||
timeout: 30000,
|
||
});
|
||
expect(await desktop.evaluate(() => (window as unknown as TestWindow).app._iosNativeInput ?? null)).toBeNull();
|
||
} finally {
|
||
await other.close();
|
||
}
|
||
});
|
||
});
|
||
|
||
function terminalLine(raw: string) {
|
||
const line: string[] = [];
|
||
for (const ch of raw) {
|
||
if (ch === '\x7f') line.pop();
|
||
else line.push(ch);
|
||
}
|
||
return line.join('');
|
||
}
|