// A browser window (`?browserWindow=true`): it adopts the moved tab, starts no installed plugin, // and calls only the commands that src-tauri/capabilities/browser.json grants. import assert from 'node:assert/strict'; import { readFile } from 'node:fs/promises'; import path from 'node:path'; import { mockTauri, repoRoot, runSmoke, smokeUrl } from '../_harness/index.mjs'; await runSmoke('browser/window', async ({ page }) => { await mockTauri(page, { label: 'browser-smoke', commands: test => { const snapshot = { profiles: [{ id: 'user', name: 'User' }], tabs: [{ id: 'moved', profileId: 'user', url: 'https://example.com', title: 'Example', loading: false, blocked: 0, canBack: false, canForward: false, transferToken: 'token' }], bookmarks: [], settings: { search: 'duckduckgo', adblock: true, linkDestination: 'internal', personalRules: '', homepage: '', filterLists: [] } }; let next = 0; return { browser_connect: () => 'window-session', browser_stop: () => null, browser_request: ({ session, command, args }) => { if (session !== 'window-session') throw Error('Missing browser session'); if (command === 'newTab') { const tabId = 'native-' + (++next); snapshot.tabs.push({ id: tabId, profileId: 'user', url: 'about:blank', title: 'Browser', loading: false, blocked: 0, canBack: false, canForward: false }); return { tabId }; } if (command === 'closeTab') snapshot.tabs = snapshot.tabs.filter(tab => tab.id !== args.tabId); if (command === 'navigate') { const tab = snapshot.tabs.find(tab => tab.id === args.tabId); tab.url = args.input; } return structuredClone(snapshot); }, // An installed plugin that a browser window must not load. plugins_snapshot: () => ({ root: 'test', plugins: [{ manifest: { schemaVersion: 1, id: 'org.test.tasks', name: 'Tasks', author: 'Test', description: '', version: '1.0.0', apiVersion: 1, entry: 'main.js', access: 'full-app' }, hash: 'tasks', enabled: true, installedAt: 1, path: '', error: null, removal: false }] }), spelling_menu_install: () => null, spelling_menu_uninstall: () => null, 'plugin:window|is_maximized': () => false, }; }, }); await page.goto(smokeUrl + '/?browserWindow=true&browserTab=moved'); await page.getByRole('application', { name: 'RuneStone browser' }).waitFor(); await page.locator('[data-browser-state="ready"]').waitFor(); await page.getByRole('textbox', { name: 'Address or search' }).fill('https://example.org'); await page.getByRole('textbox', { name: 'Address or search' }).press('Enter'); await page.keyboard.press('Control+t'); await page.waitForFunction(() => window.__TEST__.calls.some(call => call.command === 'browser_request' && call.args.command === 'newTab')); const capability = JSON.parse(await readFile(path.join(repoRoot, 'src-tauri/capabilities/browser.json'), 'utf8')); const granted = new Set(capability.permissions); const calls = await page.evaluate(() => [...new Set(window.__TEST__.calls.map(call => call.command))]); assert(!calls.includes('plugins_load'), 'A browser window loads no installed plugin.'); const missing = calls.filter(command => { const plugin = /^plugin:([^|]+)\|(.+)$/.exec(command); // core:default grants the event plugin and the read-only window commands. Window actions need their own permission. if (plugin) return plugin[1] === 'window' && /^(destroy|close|minimize|toggle_maximize|start_dragging)$/.test(plugin[2]) ? !granted.has(`core:window:allow-${plugin[2].replaceAll('_', '-')}`) : !['event', 'window', 'webview', 'app'].includes(plugin[1]); return !granted.has(`allow-${command.replaceAll('_', '-')}`); }); assert.deepEqual(missing, [], 'Every command of the browser window is in capabilities/browser.json.'); console.log(`Browser window commands: ${calls.join(', ')}`); }, { viewport: { width: 1100, height: 750 } });