// @ts-nocheck import test from 'node:test'; import assert from 'node:assert/strict'; import { NavigationCommands } from '../src/commands/navigation'; import { JobManager } from '../src/classes/JobManager'; import { makeChromeMock } from './chrome-mock'; function makeNavigationCommands() { return new NavigationCommands({ jobs: new JobManager() }); } test('navigate.open waits until Firefox updates about:blank to the requested URL', async () => { const originalChrome = globalThis.chrome; const originalBrowser = globalThis.browser; const originalNavigator = globalThis.navigator; const firefoxApi = makeChromeMock(); const targetUrl = 'https://example.com/?browser-cli-firefox-open-wait=1'; let getCalls = 0; try { delete globalThis.chrome; globalThis.browser = { ...firefoxApi, runtime: { getManifest: () => ({ version: '0.15.1' }), getBrowserInfo: async () => ({ name: 'Firefox', vendor: 'Mozilla', version: '151.0.2', buildID: 'test' }), }, tabs: { ...firefoxApi.tabs, create: async () => ({ id: 123, windowId: 1, index: 0, active: true, groupId: -1, url: 'about:blank' }), get: async () => { getCalls += 1; return { id: 123, windowId: 1, index: 0, active: true, groupId: -1, url: getCalls < 2 ? 'about:blank' : targetUrl, }; }, }, }; Object.defineProperty(globalThis, 'navigator', { value: { platform: 'test-platform', userAgent: 'Mozilla/5.0 Firefox/151.0.2' }, configurable: true, }); const result = await makeNavigationCommands().commands['navigate.open']({ url: targetUrl, focus: true }); assert.equal(result.id, 123); assert.equal(result.url, targetUrl); assert.ok(getCalls >= 2); } finally { if (originalChrome === undefined) delete globalThis.chrome; else globalThis.chrome = originalChrome; if (originalBrowser === undefined) delete globalThis.browser; else globalThis.browser = originalBrowser; Object.defineProperty(globalThis, 'navigator', { value: originalNavigator, configurable: true, }); } });