// The browser engine as a separate download: links without an engine, the setup panel in a tab, progress, cancel, // failure and retry, the switch to the page, and Settings → Browser → Browser engine, in both themes and a narrow window. import assert from 'node:assert/strict'; import path from 'node:path'; import { mockTauri, outputDir, runSmoke, smokeUrl } from '../_harness/index.mjs'; await runSmoke('browser/engine', async ({ page }) => { await mockTauri(page, { commands: test => { const status = { state: 'missing', version: '0.1.8', bytes: 160612374, received: 0, error: null }; const snapshot = { profiles: [{ id: 'user', name: 'User' }], tabs: [], bookmarks: [], settings: { search: 'duckduckgo', adblock: true, linkDestination: 'internal', personalRules: '', homepage: '', filterLists: [] } }; let next = 0; Object.assign(test, { status, opened: [], requests: [], confirms: [] }); const copy = () => structuredClone(status); test.setEngine = value => { Object.assign(status, value); test.emit('browser-engine', copy()); }; return { workspace_last_path: () => null, 'plugin:window|is_maximized': () => false, plugins_snapshot: () => ({ root: 'test', plugins: [] }), browser_connect: () => 'engine-session', browser_stop: () => null, browser_engine_status: copy, browser_engine_install: () => { Object.assign(status, { state: 'downloading', received: 0, error: null }); return copy(); }, browser_engine_install_file: copy, browser_engine_cancel: () => { Object.assign(status, { state: 'missing', received: 0 }); return copy(); }, browser_engine_remove: () => { Object.assign(status, { state: 'missing' }); return copy(); }, 'plugin:opener|open_url': ({ url }) => { test.opened.push(url); return null; }, 'plugin:dialog|message': ({ message }) => { test.confirms.push(message); return 'Remove'; }, browser_request: ({ session, command, args }) => { if (session !== 'engine-session') throw Error('Missing browser session'); if (status.state !== 'installed') throw Error('The browser engine is not installed.'); test.requests.push(command); if (command === 'newTab') { const tabId = 'native-' + (++next); snapshot.tabs.push({ id: tabId, profileId: 'user', url: args.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 === 'webData') return { profileId: args.profileId, cookies: [], history: [] }; return structuredClone(snapshot); }, }; }, }); const output = await outputDir('browser/engine'); const shots = async name => { for (const mode of ['dark', 'light']) { await page.evaluate(async mode => { const { saveAppearance } = await import('/src/lib/theme/appearance.ts'); saveAppearance({ theme: 'default', mode }); }, mode); await page.screenshot({ path: path.join(output, `${name}-${mode}.png`) }); } }; const panel = page.locator('.engine.tab'); await page.goto(smokeUrl); // The welcome page shows this button when the browser contribution exists. await page.getByRole('button', { name: 'Open browser', exact: true }).waitFor(); // A web link without an engine goes to the system browser. The contribution reports that it did not open the link. assert.equal(await page.evaluate(async () => (await import('/src/lib/plugins/registry.ts')).pluginHost.get('browser').open('https://example.com/link')), false); assert.deepEqual(await page.evaluate(() => window.__TEST__.requests), [], 'A link does not start the engine.'); // "Open link in app browser" opens a tab with the setup panel and a way out to the system browser. await page.evaluate(async () => (await import('/src/lib/plugins/registry.ts')).pluginHost.get('browser').newTab('https://example.com/docs')); await panel.waitFor(); assert.equal(await panel.getAttribute('data-engine-state'), 'missing'); await panel.getByText('The engine is a separate download of 161 MB.', { exact: false }).waitFor(); await panel.getByRole('button', { name: 'Open in default browser' }).click(); await page.waitForFunction(() => window.__TEST__.opened.includes('https://example.com/docs')); const download = panel.getByRole('button', { name: 'Download the engine' }); await download.focus(); assert.equal(await download.evaluate(element => element.matches(':focus-visible') || document.activeElement === element), true); await shots('missing'); // Download, progress, and cancel. await download.click(); await page.locator('.engine.tab[data-engine-state="downloading"]').waitFor(); await page.evaluate(() => window.__TEST__.setEngine({ received: 80306187 })); await panel.getByText('80 MB of 161 MB', { exact: false }).waitFor(); assert.equal(await panel.locator('progress').evaluate(element => element.value), 80306187); await shots('downloading'); await panel.getByRole('button', { name: 'Cancel' }).click(); await page.locator('.engine.tab[data-engine-state="missing"]').waitFor(); // A failed download shows its cause and Retry. await page.evaluate(() => window.__TEST__.setEngine({ state: 'missing', error: 'The download stopped: the connection was reset.' })); await panel.getByRole('alert').getByText('the connection was reset', { exact: false }).waitFor(); await panel.getByRole('button', { name: 'Retry' }).waitFor(); await shots('failed'); // After the installation, the same tab opens the page. await panel.getByRole('button', { name: 'Retry' }).click(); await page.evaluate(() => window.__TEST__.setEngine({ state: 'installing' })); await page.locator('.engine.tab[data-engine-state="installing"]').waitFor(); await page.evaluate(() => window.__TEST__.setEngine({ state: 'installed', error: null, received: 0 })); await page.locator('[data-browser-state="ready"]').waitFor(); assert.equal(await panel.count(), 0); assert.ok((await page.evaluate(() => window.__TEST__.requests)).includes('newTab')); assert.equal(await page.evaluate(async () => (await import('/src/lib/plugins/registry.ts')).pluginHost.get('browser').open('https://example.com/link')), true); // Settings → Browser: the installed engine, Remove with a confirmation, and the missing engine. await page.goto(smokeUrl + '/?settingsWindow=true'); await page.evaluate(() => window.__TEST__.setEngine({ state: 'installed' })); await page.getByRole('button', { name: 'Browser', exact: true }).click(); const section = page.locator('.engine.settings'); await section.getByText('Version 0.1.8 is installed.').waitFor(); await page.getByRole('button', { name: 'Search engine', exact: true }).waitFor(); await shots('settings-installed'); await section.getByRole('button', { name: 'Remove engine' }).click(); await page.locator('.engine.settings[data-engine-state="missing"]').waitFor(); assert.match((await page.evaluate(() => window.__TEST__.confirms))[0], /Your profiles, bookmarks, and history stay/); assert.equal(await page.getByRole('button', { name: 'Search engine', exact: true }).count(), 0, 'Settings that need the engine are hidden.'); await page.getByText('The other browser settings show after the engine is installed.').waitFor(); await page.setViewportSize({ width: 360, height: 800 }); await shots('settings-missing-narrow'); assert.equal(await page.evaluate(() => document.documentElement.scrollWidth > innerWidth), false); console.log('Browser engine setup, progress, failure, install, links, and Settings checks passed.'); }, { viewport: { width: 1280, height: 800 } });