diff --git a/src/firefox/index.ts b/src/firefox/index.ts index 0d9e171..cd3c25c 100644 --- a/src/firefox/index.ts +++ b/src/firefox/index.ts @@ -34,7 +34,7 @@ export class FirefoxClient { this.core = new FirefoxCore(options); } - private getBidi(): BiDiFacade { + getBidi(): BiDiFacade { if (!this.bidi) { throw new Error('Not connected'); } diff --git a/src/tools/firefox-prefs.ts b/src/tools/firefox-prefs.ts index 3dea113..6212d33 100644 --- a/src/tools/firefox-prefs.ts +++ b/src/tools/firefox-prefs.ts @@ -4,11 +4,36 @@ * Requires MOZ_REMOTE_ALLOW_SYSTEM_ACCESS=1 */ +import type { BrowsingContext } from 'webdriver-bidi-protocol'; +import { logError } from '../utils/logger.js'; import { successResponse } from '../utils/response-helpers.js'; +import { FirefoxClient } from '../firefox/index.js'; import { generatePrefScript } from '../firefox/pref-utils.js'; import { defineModule, defineToolHandler, type ToolDefinition } from './module.js'; import type { McpToolResponse } from '../types/common.js'; +async function getPrivilegedContext(firefox: FirefoxClient) { + let contexts: BrowsingContext.InfoList = []; + try { + // Get privileged ("chrome") contexts + const result = await firefox.sendBiDiCommand('browsingContext.getTree', { + 'moz:scope': 'chrome', + maxDepth: 1, + }); + contexts = result.contexts || []; + } catch (error) { + logError('Failed to get privileged contexts', error); + } + + if (contexts.length === 0) { + throw new Error( + 'No privileged contexts available. Ensure MOZ_REMOTE_ALLOW_SYSTEM_ACCESS=1 is set.' + ); + } + + return contexts[0]!.context; +} + // ============================================================================ // Tool: set_firefox_prefs // ============================================================================ @@ -38,88 +63,45 @@ export const setFirefoxPrefsTool = { export const handleSetFirefoxPrefs = defineToolHandler( async (args: unknown): Promise => { - try { - const { prefs } = args as { prefs: Record }; - - if (!prefs || typeof prefs !== 'object') { - throw new Error('prefs parameter is required and must be an object'); - } + const { prefs } = args as { prefs: Record }; - const prefEntries = Object.entries(prefs); - if (prefEntries.length === 0) { - return successResponse('No preferences to set'); - } - - const { getFirefox } = await import('../index.js'); - const firefox = await getFirefox(); - - // Get privileged ("chrome") contexts - const result = await firefox.sendBiDiCommand('browsingContext.getTree', { - 'moz:scope': 'chrome', - }); - - const contexts = result.contexts || []; - if (contexts.length === 0) { - throw new Error( - 'No privileged contexts available. Ensure MOZ_REMOTE_ALLOW_SYSTEM_ACCESS=1 is set.' - ); - } + if (!prefs || typeof prefs !== 'object') { + throw new Error('prefs parameter is required and must be an object'); + } - const driver = firefox.getDriver(); - const chromeContextId = contexts[0]!.context; + const prefEntries = Object.entries(prefs); + if (prefEntries.length === 0) { + return successResponse('No preferences to set'); + } - // Remember current context - const originalContextId = firefox.getCurrentContextId(); + const { getFirefox } = await import('../index.js'); + const firefox = await getFirefox(); + const chromeContextId = await getPrivilegedContext(firefox); + const results: string[] = []; + const errors: string[] = []; + // Set each preference + for (const [name, value] of prefEntries) { try { - // Switch to chrome context - await driver.switchTo().window(chromeContextId); - await driver.setContext('chrome'); - - const results: string[] = []; - const errors: string[] = []; - - // Set each preference - for (const [name, value] of prefEntries) { - try { - const script = generatePrefScript(name, value); - await driver.executeScript(script); - results.push(` ${name} = ${JSON.stringify(value)}`); - } catch (error) { - errors.push(` ${name}: ${error instanceof Error ? error.message : String(error)}`); - } - } - - const output: string[] = []; - if (results.length > 0) { - output.push(`Set ${results.length} preference(s):`); - output.push(...results); - } - if (errors.length > 0) { - output.push(`\nFailed to set ${errors.length} preference(s):`); - output.push(...errors); - } - - return successResponse(output.join('\n')); - } finally { - // Restore previous context (skip if already on the right chrome context) - try { - if (originalContextId && originalContextId !== chromeContextId) { - await driver.setContext('content'); - await driver.switchTo().window(originalContextId); - } - } catch { - // Ignore errors restoring context - } - } - } catch (error) { - if (error instanceof Error && error.message.includes('UnsupportedOperationError')) { - throw new Error( - 'Chrome context access not enabled. Set MOZ_REMOTE_ALLOW_SYSTEM_ACCESS=1 environment variable and restart Firefox.' - ); + const script = generatePrefScript(name, value); + await firefox.getBidi().evaluate(chromeContextId, script); + results.push(` ${name} = ${JSON.stringify(value)}`); + } catch (error) { + errors.push(` ${name}: ${error instanceof Error ? error.message : String(error)}`); } - throw error; } + + const output: string[] = []; + if (results.length > 0) { + output.push(`Set ${results.length} preference(s):`); + output.push(...results); + } + if (errors.length > 0) { + output.push(`\nFailed to set ${errors.length} preference(s):`); + output.push(...errors); + } + + return successResponse(output.join('\n')); } ); @@ -149,105 +131,62 @@ export const getFirefoxPrefsTool = { export const handleGetFirefoxPrefs = defineToolHandler( async (args: unknown): Promise => { - try { - const { names } = args as { names: string[] }; - - if (!names || !Array.isArray(names) || names.length === 0) { - throw new Error('names parameter is required and must be a non-empty array'); - } - - const { getFirefox } = await import('../index.js'); - const firefox = await getFirefox(); + const { names } = args as { names: string[] }; - // Get privileged ("chrome") contexts - const result = await firefox.sendBiDiCommand('browsingContext.getTree', { - 'moz:scope': 'chrome', - }); - - const contexts = result.contexts || []; - if (contexts.length === 0) { - throw new Error( - 'No privileged contexts available. Ensure MOZ_REMOTE_ALLOW_SYSTEM_ACCESS=1 is set.' - ); - } - - const driver = firefox.getDriver(); - const chromeContextId = contexts[0]!.context; + if (!names || !Array.isArray(names) || names.length === 0) { + throw new Error('names parameter is required and must be a non-empty array'); + } - // Remember current context - const originalContextId = firefox.getCurrentContextId(); + const { getFirefox } = await import('../index.js'); + const firefox = await getFirefox(); + const chromeContextId = await getPrivilegedContext(firefox); + const results: string[] = []; + const errors: string[] = []; + // Read each preference + for (const name of names) { try { - // Switch to chrome context - await driver.switchTo().window(chromeContextId); - await driver.setContext('chrome'); - - const results: string[] = []; - const errors: string[] = []; - - // Read each preference - for (const name of names) { - try { - // Use getPrefType to determine how to read the pref - const script = ` - (function() { - const type = Services.prefs.getPrefType(${JSON.stringify(name)}); - if (type === Services.prefs.PREF_INVALID) { - return { exists: false }; - } else if (type === Services.prefs.PREF_BOOL) { - return { exists: true, value: Services.prefs.getBoolPref(${JSON.stringify(name)}) }; - } else if (type === Services.prefs.PREF_INT) { - return { exists: true, value: Services.prefs.getIntPref(${JSON.stringify(name)}) }; - } else { - return { exists: true, value: Services.prefs.getStringPref(${JSON.stringify(name)}) }; - } - })() - `; - const prefResult = (await driver.executeScript(`return ${script}`)) as { - exists: boolean; - value?: unknown; - }; - - if (prefResult.exists) { - results.push(` ${name} = ${JSON.stringify(prefResult.value)}`); - } else { - results.push(` ${name} = (not set)`); - } - } catch (error) { - errors.push(` ${name}: ${error instanceof Error ? error.message : String(error)}`); - } - } - - const output: string[] = []; - if (results.length > 0) { - output.push(`Firefox Preferences:`); - output.push(...results); - } - if (errors.length > 0) { - output.push(`\nFailed to read ${errors.length} preference(s):`); - output.push(...errors); - } - - return successResponse(output.join('\n')); - } finally { - // Restore previous context (skip if already on the right chrome context) - try { - if (originalContextId && originalContextId !== chromeContextId) { - await driver.setContext('content'); - await driver.switchTo().window(originalContextId); + // Use getPrefType to determine how to read the pref + const script = ` + (function() { + const type = Services.prefs.getPrefType(${JSON.stringify(name)}); + if (type === Services.prefs.PREF_INVALID) { + return { exists: false }; + } else if (type === Services.prefs.PREF_BOOL) { + return { exists: true, value: Services.prefs.getBoolPref(${JSON.stringify(name)}) }; + } else if (type === Services.prefs.PREF_INT) { + return { exists: true, value: Services.prefs.getIntPref(${JSON.stringify(name)}) }; + } else { + return { exists: true, value: Services.prefs.getStringPref(${JSON.stringify(name)}) }; } - } catch { - // Ignore errors restoring context + })() + `; + const prefResult = await firefox.getBidi().evaluate<{ + exists: boolean; + value?: unknown; + }>(chromeContextId, script); + + if (prefResult.exists) { + results.push(` ${name} = ${JSON.stringify(prefResult.value)}`); + } else { + results.push(` ${name} = (not set)`); } + } catch (error) { + errors.push(` ${name}: ${error instanceof Error ? error.message : String(error)}`); } - } catch (error) { - if (error instanceof Error && error.message.includes('UnsupportedOperationError')) { - throw new Error( - 'Chrome context access not enabled. Set MOZ_REMOTE_ALLOW_SYSTEM_ACCESS=1 environment variable and restart Firefox.' - ); - } - throw error; } + + const output: string[] = []; + if (results.length > 0) { + output.push(`Firefox Preferences:`); + output.push(...results); + } + if (errors.length > 0) { + output.push(`\nFailed to read ${errors.length} preference(s):`); + output.push(...errors); + } + + return successResponse(output.join('\n')); } ); diff --git a/tests/integration/firefox-prefs.integration.test.ts b/tests/integration/firefox-prefs.integration.test.ts new file mode 100644 index 0000000..a2da48f --- /dev/null +++ b/tests/integration/firefox-prefs.integration.test.ts @@ -0,0 +1,97 @@ +/** + * Integration tests for the Firefox preferences tools + * Tests with real Firefox browser in headless mode. + * + * The prefs tools read and write via Services.prefs in a chrome-privileged + * context, which requires MOZ_REMOTE_ALLOW_SYSTEM_ACCESS=1. + */ + +import { describe, it, expect, vi } from 'vitest'; +import { McpToolResponse } from '@/types/common.js'; +import type { FirefoxClient } from '@/firefox/index.js'; +import { handleSetFirefoxPrefs, handleGetFirefoxPrefs } from '@/tools/firefox-prefs.js'; +import { createTestFirefox, closeFirefox } from '../helpers/firefox.js'; + +// The prefs tools resolve the browser through the server's global getFirefox(), +// so it is redirected to the Firefox instance launched by this test. +const testState = vi.hoisted(() => ({ firefox: null as FirefoxClient | null })); + +vi.mock('../../src/index.js', () => ({ + getFirefox: async () => testState.firefox, +})); + +const TEST_PREFS = { + testBoolPref: true, + testIntPref: 42, + testStringPref: 'test value', +}; + +/** Parse the ` name = ` lines of a get_firefox_prefs response. */ +function parsePrefsResponse(text: string): Record { + const prefs: Record = {}; + for (const line of text.split('\n')) { + const match = /^ {2}(\S+) = (.*)$/.exec(line); + if (match) { + prefs[match[1]] = match[2] === '(not set)' ? undefined : JSON.parse(match[2]); + } + } + return prefs; +} + +function responseText(response: McpToolResponse): string { + return response.content.map((item) => (item.text as string) ?? '').join('\n'); +} + +async function runWithFirefox(allowPrivilegedAccess: boolean, testFn: () => Promise) { + try { + testState.firefox = await createTestFirefox({ + env: allowPrivilegedAccess ? { MOZ_REMOTE_ALLOW_SYSTEM_ACCESS: '1' } : {}, + }); + await testFn(); + } finally { + const { firefox } = testState; + testState.firefox = null; + await closeFirefox(firefox); + } +} + +describe('Firefox Prefs Integration Tests', () => { + it('handleGetFirefoxPrefs should handle non-existent preferences', async () => { + await runWithFirefox(true, async () => { + const result = await handleGetFirefoxPrefs({ names: ['nonexistent.pref'] }); + expect(result.isError).toBeUndefined(); + expect(result.content[0].text).toContain('(not set)'); + }); + }, 30000); + + it('handleGetFirefoxPrefs should return helpful error when privileged access is not enabled', async () => { + await runWithFirefox(false, async () => { + const result = await handleGetFirefoxPrefs({ names: Object.keys(TEST_PREFS) }); + expect(result.isError).toBe(true); + expect(result.content[0].text).toContain('MOZ_REMOTE_ALLOW_SYSTEM_ACCESS'); + }); + }, 30000); + + it('handleSetFirefoxPrefs should return helpful error when privileged access is not enabled', async () => { + await runWithFirefox(false, async () => { + const result = await handleSetFirefoxPrefs({ prefs: TEST_PREFS }); + expect(result.isError).toBe(true); + expect(result.content[0].text).toContain('MOZ_REMOTE_ALLOW_SYSTEM_ACCESS'); + }); + }, 30000); + + it('handleGetFirefoxPrefs should read back the values that were set by handleSetFirefoxPrefs', async () => { + await runWithFirefox(true, async () => { + const setResponse = await handleSetFirefoxPrefs({ prefs: TEST_PREFS }); + const setText = responseText(setResponse); + expect(setText).toContain('Set 3 preference(s)'); + expect(setText).not.toContain('Failed to set'); + + const getResponse = await handleGetFirefoxPrefs({ names: Object.keys(TEST_PREFS) }); + const getText = responseText(getResponse); + expect(getText).not.toContain('Failed to read'); + + expect(parsePrefsResponse(getText)).toEqual(TEST_PREFS); + }); + }, 30000); +}); diff --git a/tests/tools/firefox-prefs.test.ts b/tests/tools/firefox-prefs.test.ts index cfc2d60..b5989c5 100644 --- a/tests/tools/firefox-prefs.test.ts +++ b/tests/tools/firefox-prefs.test.ts @@ -70,11 +70,6 @@ describe('Firefox Prefs Tool Definitions', () => { }); describe('Firefox Prefs Tool Handlers', () => { - const mockExecuteScript = vi.fn(); - const mockSetContext = vi.fn(); - const mockSwitchToWindow = vi.fn(); - const mockSendBiDiCommand = vi.fn(); - let originalEnv: string | undefined; beforeEach(() => { @@ -104,135 +99,6 @@ describe('Firefox Prefs Tool Handlers', () => { expect(result.isError).toBeUndefined(); expect(result.content[0].text).toContain('No preferences to set'); }); - - it('should return helpful error when MOZ_REMOTE_ALLOW_SYSTEM_ACCESS results in no privileged contexts', async () => { - delete process.env.MOZ_REMOTE_ALLOW_SYSTEM_ACCESS; - - // Without MOZ_REMOTE_ALLOW_SYSTEM_ACCESS, no privileged contexts are available - mockSendBiDiCommand.mockResolvedValue({ contexts: [] }); - - const mockFirefox = { - sendBiDiCommand: mockSendBiDiCommand, - getDriver: vi.fn(), - getCurrentContextId: vi.fn(), - }; - - mockGetFirefox.mockResolvedValue(mockFirefox); - - const result = await handleSetFirefoxPrefs({ prefs: { 'test.pref': 'value' } }); - - expect(result.isError).toBe(true); - expect(result.content[0].text).toContain('MOZ_REMOTE_ALLOW_SYSTEM_ACCESS'); - }); - - it('should set preferences successfully', async () => { - process.env.MOZ_REMOTE_ALLOW_SYSTEM_ACCESS = '1'; - - mockSendBiDiCommand.mockResolvedValue({ - contexts: [{ context: 'chrome-context-id' }], - }); - - const mockFirefox = { - sendBiDiCommand: mockSendBiDiCommand, - getDriver: vi.fn().mockReturnValue({ - switchTo: () => ({ window: mockSwitchToWindow }), - setContext: mockSetContext, - executeScript: mockExecuteScript, - }), - getCurrentContextId: vi.fn().mockReturnValue('content-context-id'), - }; - - mockGetFirefox.mockResolvedValue(mockFirefox); - - const result = await handleSetFirefoxPrefs({ - prefs: { 'test.bool': true, 'test.int': 42, 'test.string': 'hello' }, - }); - - expect(result.isError).toBeUndefined(); - expect(result.content[0].text).toContain('Set 3 preference(s)'); - expect(mockExecuteScript).toHaveBeenCalledTimes(3); - expect(mockExecuteScript).toHaveBeenCalledWith( - 'Services.prefs.setBoolPref("test.bool", true)' - ); - expect(mockExecuteScript).toHaveBeenCalledWith('Services.prefs.setIntPref("test.int", 42)'); - expect(mockExecuteScript).toHaveBeenCalledWith( - 'Services.prefs.setStringPref("test.string", "hello")' - ); - }); - - it('should handle partial failures gracefully', async () => { - process.env.MOZ_REMOTE_ALLOW_SYSTEM_ACCESS = '1'; - - mockSendBiDiCommand.mockResolvedValue({ - contexts: [{ context: 'chrome-context-id' }], - }); - - mockExecuteScript - .mockResolvedValueOnce(undefined) // first pref succeeds - .mockRejectedValueOnce(new Error('Pref error')); // second fails - - const mockFirefox = { - sendBiDiCommand: mockSendBiDiCommand, - getDriver: vi.fn().mockReturnValue({ - switchTo: () => ({ window: mockSwitchToWindow }), - setContext: mockSetContext, - executeScript: mockExecuteScript, - }), - getCurrentContextId: vi.fn().mockReturnValue('content-context-id'), - }; - - mockGetFirefox.mockResolvedValue(mockFirefox); - - const result = await handleSetFirefoxPrefs({ - prefs: { 'good.pref': 'value', 'bad.pref': 'value' }, - }); - - expect(result.isError).toBeUndefined(); - expect(result.content[0].text).toContain('Set 1 preference(s)'); - expect(result.content[0].text).toContain('Failed to set 1 preference(s)'); - }); - - it('should return error when no privileged contexts available', async () => { - process.env.MOZ_REMOTE_ALLOW_SYSTEM_ACCESS = '1'; - - mockSendBiDiCommand.mockResolvedValue({ contexts: [] }); - - const mockFirefox = { - sendBiDiCommand: mockSendBiDiCommand, - getDriver: vi.fn(), - getCurrentContextId: vi.fn(), - }; - - mockGetFirefox.mockResolvedValue(mockFirefox); - - const result = await handleSetFirefoxPrefs({ prefs: { 'test.pref': 'value' } }); - - expect(result.isError).toBe(true); - expect(result.content[0].text).toContain('No privileged contexts'); - }); - - it('should call getFirefox even when MOZ_REMOTE_ALLOW_SYSTEM_ACCESS not in process.env', async () => { - delete process.env.MOZ_REMOTE_ALLOW_SYSTEM_ACCESS; - - mockSendBiDiCommand.mockResolvedValue({ - contexts: [{ context: 'chrome-context-id' }], - }); - const mockFirefox = { - sendBiDiCommand: mockSendBiDiCommand, - getDriver: vi.fn().mockReturnValue({ - switchTo: () => ({ window: mockSwitchToWindow }), - setContext: mockSetContext, - executeScript: mockExecuteScript, - }), - getCurrentContextId: vi.fn().mockReturnValue('content-context-id'), - }; - mockGetFirefox.mockResolvedValue(mockFirefox); - - const result = await handleSetFirefoxPrefs({ prefs: { 'test.pref': 'value' } }); - - expect(mockGetFirefox).toHaveBeenCalled(); - expect(result.isError).toBeUndefined(); - }); }); describe('handleGetFirefoxPrefs', () => { @@ -249,124 +115,5 @@ describe('Firefox Prefs Tool Handlers', () => { expect(result.isError).toBe(true); expect(result.content[0].text).toContain('names parameter is required'); }); - - it('should return helpful error when MOZ_REMOTE_ALLOW_SYSTEM_ACCESS results in no privileged contexts', async () => { - delete process.env.MOZ_REMOTE_ALLOW_SYSTEM_ACCESS; - - // Without MOZ_REMOTE_ALLOW_SYSTEM_ACCESS, no privileged contexts are available - mockSendBiDiCommand.mockResolvedValue({ contexts: [] }); - - const mockFirefox = { - sendBiDiCommand: mockSendBiDiCommand, - getDriver: vi.fn(), - getCurrentContextId: vi.fn(), - }; - - mockGetFirefox.mockResolvedValue(mockFirefox); - - const result = await handleGetFirefoxPrefs({ names: ['test.pref'] }); - - expect(result.isError).toBe(true); - expect(result.content[0].text).toContain('MOZ_REMOTE_ALLOW_SYSTEM_ACCESS'); - }); - - it('should get preferences successfully', async () => { - process.env.MOZ_REMOTE_ALLOW_SYSTEM_ACCESS = '1'; - - mockSendBiDiCommand.mockResolvedValue({ - contexts: [{ context: 'chrome-context-id' }], - }); - - mockExecuteScript.mockResolvedValue({ exists: true, value: 'test-value' }); - - const mockFirefox = { - sendBiDiCommand: mockSendBiDiCommand, - getDriver: vi.fn().mockReturnValue({ - switchTo: () => ({ window: mockSwitchToWindow }), - setContext: mockSetContext, - executeScript: mockExecuteScript, - }), - getCurrentContextId: vi.fn().mockReturnValue('content-context-id'), - }; - - mockGetFirefox.mockResolvedValue(mockFirefox); - - const result = await handleGetFirefoxPrefs({ names: ['test.pref'] }); - - expect(result.isError).toBeUndefined(); - expect(result.content[0].text).toContain('Firefox Preferences'); - expect(result.content[0].text).toContain('test.pref'); - expect(result.content[0].text).toContain('"test-value"'); - }); - - it('should handle non-existent preferences', async () => { - process.env.MOZ_REMOTE_ALLOW_SYSTEM_ACCESS = '1'; - - mockSendBiDiCommand.mockResolvedValue({ - contexts: [{ context: 'chrome-context-id' }], - }); - - mockExecuteScript.mockResolvedValue({ exists: false }); - - const mockFirefox = { - sendBiDiCommand: mockSendBiDiCommand, - getDriver: vi.fn().mockReturnValue({ - switchTo: () => ({ window: mockSwitchToWindow }), - setContext: mockSetContext, - executeScript: mockExecuteScript, - }), - getCurrentContextId: vi.fn().mockReturnValue('content-context-id'), - }; - - mockGetFirefox.mockResolvedValue(mockFirefox); - - const result = await handleGetFirefoxPrefs({ names: ['nonexistent.pref'] }); - - expect(result.isError).toBeUndefined(); - expect(result.content[0].text).toContain('(not set)'); - }); - - it('should return error when no privileged contexts available', async () => { - process.env.MOZ_REMOTE_ALLOW_SYSTEM_ACCESS = '1'; - - mockSendBiDiCommand.mockResolvedValue({ contexts: [] }); - - const mockFirefox = { - sendBiDiCommand: mockSendBiDiCommand, - getDriver: vi.fn(), - getCurrentContextId: vi.fn(), - }; - - mockGetFirefox.mockResolvedValue(mockFirefox); - - const result = await handleGetFirefoxPrefs({ names: ['test.pref'] }); - - expect(result.isError).toBe(true); - expect(result.content[0].text).toContain('No privileged contexts'); - }); - - it('should call getFirefox even when MOZ_REMOTE_ALLOW_SYSTEM_ACCESS not in process.env', async () => { - delete process.env.MOZ_REMOTE_ALLOW_SYSTEM_ACCESS; - - mockSendBiDiCommand.mockResolvedValue({ - contexts: [{ context: 'chrome-context-id' }], - }); - mockExecuteScript.mockResolvedValue({ exists: true, value: 'test-value' }); - const mockFirefox = { - sendBiDiCommand: mockSendBiDiCommand, - getDriver: vi.fn().mockReturnValue({ - switchTo: () => ({ window: mockSwitchToWindow }), - setContext: mockSetContext, - executeScript: mockExecuteScript, - }), - getCurrentContextId: vi.fn().mockReturnValue('content-context-id'), - }; - mockGetFirefox.mockResolvedValue(mockFirefox); - - const result = await handleGetFirefoxPrefs({ names: ['test.pref'] }); - - expect(mockGetFirefox).toHaveBeenCalled(); - expect(result.isError).toBeUndefined(); - }); }); }); diff --git a/tests/tools/privileged-context-state.test.ts b/tests/tools/privileged-context-state.test.ts index 81e307a..73c375a 100644 --- a/tests/tools/privileged-context-state.test.ts +++ b/tests/tools/privileged-context-state.test.ts @@ -59,25 +59,4 @@ describe('Privileged context state consistency', () => { // currentContextId to 'chrome-context-id' expect(mockSetCurrentContextId).toHaveBeenCalledWith('chrome-context-id'); }); - - it('set_firefox_prefs after select_privileged_context should not revert to old context', async () => { - const { handleSelectPrivilegedContext } = await import('../../src/tools/privileged-context.js'); - const { handleSetFirefoxPrefs } = await import('../../src/tools/firefox-prefs.js'); - - // User selects privileged context - await handleSelectPrivilegedContext({ contextId: 'chrome-context-id' }); - - mockExecuteScript.mockResolvedValue(undefined); - mockSwitchToWindow.mockClear(); - mockSetContext.mockClear(); - - // Call set_firefox_prefs which requires privileged context. - await handleSetFirefoxPrefs({ prefs: { 'browser.ml.enable': true } }); - - const setContextCalls = mockSetContext.mock.calls; - const lastSetContext = setContextCalls[setContextCalls.length - 1]; - - // Check that the context has not switched to content unexpectedly. - expect(lastSetContext[0]).not.toBe('content'); - }); });