fix(chat): use stock Navigator Back at every screen width
This commit is contained in:
@@ -11,12 +11,13 @@ import { launchChrome, waitForPort, waitForPage, connect, sleep } from './pipeli
|
||||
import { axNodes, waitFor, capture } from './pipelines_probe_cdp_input.mjs';
|
||||
|
||||
const pairs = Number(process.env.CHAT_PAIRS ?? 100);
|
||||
const width = Number(process.env.PROBE_WIDTH ?? 390);
|
||||
const text = '# Recorded answer\n\n' +
|
||||
Array.from({ length: 12 }, (_, i) => `Paragraph ${i}: This is recorded fixture content with **formatting**, an [inert link](https://example.test), and enough text to wrap naturally on a phone.\n`).join('\n') +
|
||||
'\n```dart\n' + Array.from({ length: 25 }, (_, i) => `final value${i} = ${i};`).join('\n') + '\n```\n';
|
||||
const turns = Array.from({ length: pairs }, (_, i) => [
|
||||
{ id: `u${i}`, role: 'user', parts: [{ type: 'text', text: `Recorded question ${i}` }] },
|
||||
{ id: `a${i}`, role: 'assistant', parts: [{ id: `p${i}`, type: 'text', text }] },
|
||||
{ id: `a${i}`, role: 'assistant', parts: [{ id: `p${i}`, type: 'text', text: process.env.CHAT_VARIANCE === '1' ? text.repeat(1 + i % 4) : text }] },
|
||||
]).flat();
|
||||
const folded = process.env.CHAT_FOLDED === '1';
|
||||
const messages = folded ? [turns[0], ...turns.filter(m => m.role === 'assistant')] : turns;
|
||||
@@ -25,7 +26,7 @@ await mkdir(output, { recursive: true });
|
||||
const fixture = await startFixture({ root: resolve(process.argv[2]), chatMessages: messages });
|
||||
const profile = await mkdtemp(join(tmpdir(), 'chat-back-latency-'));
|
||||
const chrome = launchChrome('/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', profile, 'about:blank');
|
||||
const log = { pairs, folded, streaming: process.env.CHAT_STREAM === '1', cpuRate: Number(process.env.CPU_RATE ?? 1), host: process.env.PROBE_PLATFORM ?? 'cupertino', checks: [], captures: [] };
|
||||
const log = { pairs, width, folded, roundTrip: process.env.SCROLL_ROUNDTRIP === '1', fromList: process.env.OPEN_FROM_LIST === '1', streaming: process.env.CHAT_STREAM === '1', cpuRate: Number(process.env.CPU_RATE ?? 1), host: process.env.PROBE_PLATFORM ?? 'cupertino', checks: [], captures: [] };
|
||||
let c;
|
||||
let streamTimer;
|
||||
const requests = new Set();
|
||||
@@ -38,21 +39,37 @@ try {
|
||||
if (log.host === 'material') await c.send('Emulation.setUserAgentOverride', {
|
||||
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/155.0.0.0 Safari/537.36', platform: 'Win32',
|
||||
});
|
||||
await c.send('Emulation.setDeviceMetricsOverride', { width: 390, height: 844, deviceScaleFactor: 1, mobile: true });
|
||||
await c.send('Emulation.setDeviceMetricsOverride', { width, height: 844, deviceScaleFactor: 1, mobile: true });
|
||||
await c.send('Emulation.setCPUThrottlingRate', { rate: log.cpuRate });
|
||||
const opened = performance.now();
|
||||
await c.send('Page.navigate', { url: fixture.url + '/chat/ses_probechat' });
|
||||
await c.send('Page.navigate', { url: fixture.url + (log.fromList ? '/chat' : '/chat/ses_probechat') });
|
||||
assert.ok(await waitFor(() => c.evaluate("Boolean(document.querySelector('flt-semantics-placeholder'))"), 30000));
|
||||
// Mobile semantics activation requires a real pointer at the placeholder's
|
||||
// centre; element.click() at (0,0) does not enable Android web semantics.
|
||||
const rect = await c.evaluate("(() => { const r = document.querySelector('flt-semantics-placeholder').getBoundingClientRect(); return {x:(r.left+r.right)/2,y:(r.top+r.bottom)/2}; })()");
|
||||
await c.send('Input.dispatchMouseEvent', { type: 'mousePressed', x: rect.x, y: rect.y, button: 'left', clickCount: 1 });
|
||||
await c.send('Input.dispatchMouseEvent', { type: 'mouseReleased', x: rect.x, y: rect.y, button: 'left', clickCount: 1 });
|
||||
if (log.fromList) {
|
||||
const row = await waitFor(async () => (await axNodes(c)).find(n => n.name?.value?.startsWith('Probe conversation') && n.backendDOMNodeId && ['group', 'button'].includes(n.role?.value)), 30000);
|
||||
assert.ok(row, 'chat list row');
|
||||
const { model } = await c.send('DOM.getBoxModel', { backendNodeId: row.backendDOMNodeId });
|
||||
const [x1, y1, , , x3, y3] = model.content;
|
||||
await c.send('Input.dispatchMouseEvent', { type: 'mousePressed', x: (x1+x3)/2, y: (y1+y3)/2, button: 'left', clickCount: 1 });
|
||||
await c.send('Input.dispatchMouseEvent', { type: 'mouseReleased', x: (x1+x3)/2, y: (y1+y3)/2, button: 'left', clickCount: 1 });
|
||||
}
|
||||
assert.ok(await waitFor(async () => (await axNodes(c)).some(n => n.name?.value === 'Back'), 45000), 'chat Back ready');
|
||||
await sleep(1800);
|
||||
await c.evaluate('new Promise(r => requestAnimationFrame(() => requestAnimationFrame(r)))');
|
||||
log.openAndSettleMs = performance.now() - opened;
|
||||
await capture(c, output, log, 'chat-before-back');
|
||||
if (log.roundTrip) {
|
||||
await c.send('Input.dispatchMouseEvent', { type: 'mouseWheel', x: width - 10, y: 400, deltaX: 0, deltaY: -1000000 });
|
||||
await sleep(900);
|
||||
await capture(c, output, log, 'chat-scrolled-top');
|
||||
await c.send('Input.dispatchMouseEvent', { type: 'mouseWheel', x: width - 10, y: 400, deltaX: 0, deltaY: 1000000 });
|
||||
await sleep(Number(process.env.SCROLL_SETTLE_MS ?? 300));
|
||||
await capture(c, output, log, 'chat-scrolled-bottom');
|
||||
}
|
||||
if (log.streaming) {
|
||||
streamTimer = setInterval(() => {
|
||||
const request = fetch(fixture.url + '/fixture/chat-event', { method: 'POST', body: JSON.stringify({
|
||||
@@ -65,7 +82,7 @@ try {
|
||||
}
|
||||
const backNodes = (await axNodes(c)).filter(n => /^Back(?:\s|$)/.test(n.name?.value ?? ''));
|
||||
log.backControlNodes = backNodes.map(n => ({name:n.name?.value, role:n.role?.value, backend:n.backendDOMNodeId}));
|
||||
const back = backNodes.find(n => n.backendDOMNodeId);
|
||||
const back = backNodes.find(n => n.backendDOMNodeId && n.role?.value === 'button') ?? backNodes.find(n => n.backendDOMNodeId);
|
||||
assert.ok(back, 'native Back control');
|
||||
const { model } = await c.send('DOM.getBoxModel', { backendNodeId: back.backendDOMNodeId });
|
||||
const [x1, y1, , , x3, y3] = model.content;
|
||||
|
||||
Reference in New Issue
Block a user