test: trim redundant browser timing and projection cases (#42159)

* test: remove redundant browser getter and chunking cases

* test: trim synthetic browser effects and default budget replay

* test: trim screencast timeout and viewport projection cases

---------

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
OrcaWin
2026-11-13 14:20:33 -08:00
committed by GitHub
co-authored by OrcaWin
parent f6f5eb6aa3
commit 39ff7be5bd
6 changed files with 2 additions and 209 deletions
@@ -66,54 +66,10 @@ function fakeHost(
},
admit: vi.fn()
}
const emit = (event: BrowserPageEvent): void => pageEvents.forEach((listener) => listener(event))
return { host, tabs, emit }
return { host }
}
describe('runWithActionEffects', () => {
it('waits for a navigation the action started and reports where it landed', async () => {
const guest = fakeGuest()
const appTree = '- heading "Welcome ada" [level=1, ref=e9]\n- button "Submit ticket" [ref=e10]'
const { host } = fakeHost(guest, [UNCHANGED, { snapshot: { kind: 'full', tree: appTree } }])
const result = await runWithActionEffects(host, async () => {
guest.emit('did-start-navigation', { isMainFrame: true, isSameDocument: false })
// A redirecting submit replaces its first navigation, which then fails as ERR_ABORTED.
guest.emit('did-start-navigation', { isMainFrame: true, isSameDocument: false })
guest.emit('did-fail-load', {}, -3, 'ERR_ABORTED', 'http://127.0.0.1/submit', true)
setTimeout(() => {
guest.url = 'http://127.0.0.1/app.html'
guest.title = 'App'
guest.emit('dom-ready')
}, 120)
return { clicked: '@e6' }
})
expect(readBrowserActionEffects(result)).toEqual({
settled: true,
url: 'http://127.0.0.1/app.html',
title: 'App',
page: { lines: appTree.split('\n'), removedLines: 0, full: true, truncated: false }
})
})
it('reports a new tab once it opens and a child window separately', async () => {
const guest = fakeGuest()
const { host, tabs, emit } = fakeHost(guest, [UNCHANGED, UNCHANGED])
const result = await runWithActionEffects(host, async () => {
emit({ kind: 'popup', action: 'window', origin: 'https://accounts.example' })
emit({ kind: 'tab', url: 'http://127.0.0.1/basic2.html' })
setTimeout(() => tabs.set('page-2', 'http://127.0.0.1/basic2.html'), 100)
return { clicked: '@e18' }
})
expect(readBrowserActionEffects(result)).toMatchObject({
newTabs: [{ browserPageId: 'page-2', url: 'http://127.0.0.1/basic2.html' }],
popups: [{ action: 'window', origin: 'https://accounts.example' }]
})
})
it('does not read a replacement guest the caller was never admitted to', async () => {
const guest = fakeGuest()
const replacement = Object.assign(fakeGuest('http://127.0.0.1/app.html', 'App'), { id: 8 })
@@ -1,11 +0,0 @@
import { describe, expect, it } from 'vitest'
import { splitBrowserTextInsertionChunks } from '../../../../shared/browser-text-insertion-chunks'
describe('browser text insertion chunking', () => {
it('keeps a single multibyte character intact when the byte cap is smaller', () => {
const chunks = splitBrowserTextInsertionChunks('😀a', 1)
expect(chunks).toEqual(['😀', 'a'])
expect(chunks.join('')).toBe('😀a')
})
})
@@ -1,63 +0,0 @@
import { Buffer } from 'node:buffer'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { startBrowserScreencast } from './browser-screencast-stream'
import type { BrowserScreencastOptions } from './browser-screencast-stream-types'
import { createMockScreencastWebContents } from './browser-screencast-web-contents-test-double'
function start(
webContents: ReturnType<typeof createMockScreencastWebContents>,
options: BrowserScreencastOptions
) {
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the stream touches only the debugger, isDestroyed and capturePage the doubles provide.
return startBrowserScreencast(webContents as never, options)
}
function startOptions(viewport: boolean) {
return {
format: 'jpeg' as const,
quality: 70,
maxWidth: 1440,
maxHeight: 1200,
everyNthFrame: 2,
minFrameIntervalMs: 0,
holdPaint: () => () => {},
...(viewport ? { viewportWidth: 390, viewportHeight: 844 } : {}),
onFrame: vi.fn(() => true),
onError: vi.fn()
}
}
describe('browser screencast first-frame deadline', () => {
beforeEach(() => {
vi.useFakeTimers()
})
afterEach(() => {
vi.useRealTimers()
})
it('drops a capture that settles after the limit', async () => {
let settleCapture!: (image: unknown) => void
const webContents = Object.assign(createMockScreencastWebContents(), {
capturePage: vi.fn(
() =>
new Promise((resolve) => {
settleCapture = resolve
})
)
})
const options = startOptions(true)
const session = await start(webContents, options)
await vi.advanceTimersByTimeAsync(10_000)
settleCapture({
getSize: () => ({ width: 390, height: 844 }),
toJPEG: () => Buffer.from('late'),
toPNG: () => Buffer.from('late')
})
await vi.advanceTimersByTimeAsync(1_000)
expect(options.onFrame).not.toHaveBeenCalled()
session.stop()
await session.done
})
})
@@ -1,8 +1,6 @@
import { Buffer } from 'node:buffer'
import { describe, expect, it, vi } from 'vitest'
import { decodeBrowserScreencastFrame } from '../../../../shared/browser/screencast/browser-screencast-protocol'
import { startBrowserScreencast } from './browser-screencast-stream'
import { createMockScreencastWebContents } from './browser-screencast-web-contents-test-double'
@@ -76,55 +74,6 @@ async function startOversizedStream(guest: ReturnType<typeof createGuest>, onFra
}
describe('screencast of a guest smaller than the requested viewport (#30341)', () => {
it('re-emulates at the size the guest can paint and labels frames with it', async () => {
const guest = createGuest('webview')
const onFrame = vi.fn()
const session = await startOversizedStream(guest, onFrame)
await vi.waitFor(() =>
expect(guest.debugger.sendCommand).toHaveBeenCalledWith(
'Page.captureScreenshot',
expect.anything()
)
)
expect(emulatedSizes(guest)).toEqual(['1833x1179'])
emitGuestFrame(guest, 1, { width: 1463, height: 849 })
await vi.waitFor(() => expect(emulatedSizes(guest)).toEqual(['1833x1179', '1463x849']))
expect(guest.debugger.sendCommand).toHaveBeenCalledWith('Page.screencastFrameAck', {
sessionId: 1
})
expect(onFrame).not.toHaveBeenCalled()
emitGuestFrame(guest, 2, { width: 1463, height: 849 })
await vi.waitFor(() => expect(onFrame).toHaveBeenCalledTimes(1))
expect(decodeBrowserScreencastFrame(onFrame.mock.calls[0][0])?.metadata).toMatchObject({
deviceWidth: 1463,
deviceHeight: 849
})
session.stop()
await session.done
})
it('gives the requested size back once the guest grows, and follows a new request', async () => {
const guest = createGuest('webview')
const session = await startOversizedStream(guest)
emitGuestFrame(guest, 1, { width: 1463, height: 849 })
await vi.waitFor(() => expect(emulatedSizes(guest)).toHaveLength(2))
emitGuestFrame(guest, 2, { width: 2000, height: 1300 })
await vi.waitFor(() => expect(emulatedSizes(guest).at(-1)).toBe('1833x1179'))
await session.updateViewport({ viewportWidth: 1028, viewportHeight: 1179 })
expect(emulatedSizes(guest).at(-1)).toBe('1028x1179')
emitGuestFrame(guest, 3, { width: 1463, height: 849 })
await vi.waitFor(() => expect(emulatedSizes(guest).at(-1)).toBe('1028x849'))
session.stop()
await session.done
})
it('keeps dropping guest frames until the fitted size is actually emulated', async () => {
const guest = createGuest('webview')
let releaseSnapshot!: () => void
@@ -183,20 +132,4 @@ describe('screencast of a guest smaller than the requested viewport (#30341)', (
session.stop()
})
it('keeps the full request for a window guest, which can grow to it', async () => {
const guest = createGuest('window')
const session = await startOversizedStream(guest)
emitGuestFrame(guest, 1, { width: 1463, height: 849 })
await vi.waitFor(() =>
expect(guest.debugger.sendCommand).toHaveBeenCalledWith('Page.screencastFrameAck', {
sessionId: 1
})
)
expect(emulatedSizes(guest)).toEqual(['1833x1179'])
session.stop()
await session.done
})
})
@@ -142,15 +142,6 @@ describe('BrowserCertificateTrustController', () => {
controller.installSessionRequestGuard(browserSession)
})
it('keeps challenge ownership and expiry when reading a specific guest', () => {
certificateEvent({ controller, guest })
expect(controller.hasFailureForGuest(guest.id)).toBe(true)
expect(controller.hasFailureForGuest(otherGuest.id)).toBe(false)
now += 300_000
expect(controller.hasFailureForGuest(guest.id)).toBe(false)
expect(controller.proceed('page-1', 'challenge-1')).toEqual({ ok: false, reason: 'missing' })
})
it('blocks a session-cached certificate for sibling requests until that guest approves it', () => {
certificateEvent({ controller, guest })
expect(controller.proceed('page-1', 'challenge-1')).toEqual({ ok: true })
@@ -1,20 +1,7 @@
import { describe, expect, it } from 'vitest'
import {
createPageInitiatedTabBudget,
MAX_PAGE_INITIATED_TABS_PER_WINDOW,
PAGE_INITIATED_TAB_WINDOW_MS
} from './browser-page-initiated-tab-budget'
import { createPageInitiatedTabBudget } from './browser-page-initiated-tab-budget'
describe('page-initiated tab budget', () => {
it('refills once the rolling window has passed, so real browsing is unaffected', () => {
const budget = createPageInitiatedTabBudget()
for (let i = 0; i < MAX_PAGE_INITIATED_TABS_PER_WINDOW; i++) {
expect(budget.tryConsume(1_000)).toBe(true)
}
expect(budget.tryConsume(1_000 + PAGE_INITIATED_TAB_WINDOW_MS - 1)).toBe(false)
expect(budget.tryConsume(1_000 + PAGE_INITIATED_TAB_WINDOW_MS)).toBe(true)
})
it('slides rather than resetting, so a paced flood cannot outrun the cap', () => {
const budget = createPageInitiatedTabBudget(2, 1_000)