(page: Page, delaysMs: number[])
| 408 | } |
| 409 | |
| 410 | async function routeFakeDelayedPsnrSession(page: Page, delaysMs: number[]): Promise<void> { |
| 411 | const delays = delaysMs.map((delay) => Math.max(0, Math.trunc(delay))); |
| 412 | const installState = (nextDelays: number[]) => { |
| 413 | Object.defineProperty(window, '__COLMAP_WEBVIEW_FAKE_PSNR__', { |
| 414 | configurable: true, |
| 415 | value: { |
| 416 | delays: nextDelays, |
| 417 | sessionCount: 0, |
| 418 | computeCount: 0, |
| 419 | disposedCount: 0, |
| 420 | completed: [] as number[], |
| 421 | }, |
| 422 | }); |
| 423 | }; |
| 424 | |
| 425 | await page.addInitScript(installState, delays); |
| 426 | await page.evaluate(installState, delays); |
| 427 | |
| 428 | await page.route('**/src/splat/webgpu/psnrSplatSession.ts*', async (route) => { |
| 429 | await route.fulfill({ |
| 430 | contentType: 'application/javascript', |
| 431 | body: ` |
| 432 | const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); |
| 433 | |
| 434 | export async function createWebGpuSplatPsnrSession() { |
| 435 | const state = window.__COLMAP_WEBVIEW_FAKE_PSNR__; |
| 436 | ++state.sessionCount; |
| 437 | return { |
| 438 | async computeImageMetric(options) { |
| 439 | const computeId = ++state.computeCount; |
| 440 | await delay(state.delays[computeId - 1] ?? 0); |
| 441 | state.completed.push(computeId); |
| 442 | return { |
| 443 | psnr: 20 + computeId, |
| 444 | mse: computeId, |
| 445 | validPixelCount: options.width * options.height, |
| 446 | }; |
| 447 | }, |
| 448 | dispose() { |
| 449 | state.disposedCount += 1; |
| 450 | }, |
| 451 | }; |
| 452 | } |
| 453 | `, |
| 454 | }); |
| 455 | }); |
| 456 | } |
| 457 | |
| 458 | async function resetFakeDelayedPsnrSession(page: Page, delaysMs: number[]): Promise<void> { |
| 459 | const delays = delaysMs.map((delay) => Math.max(0, Math.trunc(delay))); |
no outgoing calls
no test coverage detected