RuneStone 1.0.0
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
// The built-in browser: navigation, profiles, independence from the legacy package, same-tab view replacement, a plug-in sidebar, and settings.
|
||||
import assert from 'node:assert/strict';
|
||||
import path from 'node:path';
|
||||
import { mockTauri, outputDir, runSmoke, smokeUrl } from '../_harness/index.mjs';
|
||||
|
||||
await runSmoke('browser/builtin', async ({ page }) => {
|
||||
await mockTauri(page, {
|
||||
commands: test => {
|
||||
const snapshot = { profiles: [{ id: 'user', name: 'Existing user' }], tabs: [], bookmarks: [{ id: 'saved', profileId: 'user', title: 'Existing bookmark', url: 'https://example.com' }], settings: { search: 'duckduckgo', adblock: true, linkDestination: 'internal', personalRules: '', homepage: '', filterLists: [] } };
|
||||
const check = Object.assign(test, { loads: [], commands: [], legacy: false, removed: false, mounts: [], cleanups: [] });
|
||||
let next = 0;
|
||||
const plugin = (id, name, version, hash) => ({ manifest: { schemaVersion: 1, id, name, author: 'Test', description: '', version, apiVersion: 1, entry: 'main.js', access: 'full-app' }, hash, enabled: true, installedAt: 1, path: '', error: null, removal: false });
|
||||
return {
|
||||
browser_connect: () => 'window-session',
|
||||
workspace_last_path: () => null,
|
||||
'plugin:window|is_maximized': () => false,
|
||||
plugins_snapshot: () => ({ root: 'test', plugins: [
|
||||
plugin('org.test.boards', 'Boards', '0.1.0', 'fixture'),
|
||||
...(check.legacy && !check.removed ? [plugin('runestone.browser', 'Browser', '0.1.6', 'old')] : []),
|
||||
] }),
|
||||
plugins_load: ({ id }) => {
|
||||
check.loads.push(id);
|
||||
if (id === 'runestone.browser') throw Error('The old browser package must not load');
|
||||
return `export function activate(api) {
|
||||
for (const id of ['board-a', 'board-b']) api.registerView({ id, title: id, placement: 'editor', mount(el) {
|
||||
window.__TEST__.mounts.push(id); el.textContent = id;
|
||||
if (id === 'board-a') { const b = document.createElement('button'); b.textContent = 'Select board B'; b.onclick = () => api.replaceView('board-a', 'board-b'); el.append(b); }
|
||||
return () => { window.__TEST__.cleanups.push(id); };
|
||||
}});
|
||||
api.registerView({ id:'sidebar', title:'Sidebar fixture', placement:'sidebar', navigation:true, icon:'git', mount(el) { el.textContent='Plugin sidebar fixture'; }});
|
||||
}`;
|
||||
},
|
||||
browser_request: ({ session, command, args }) => {
|
||||
if (session !== 'window-session') throw Error('Missing browser session');
|
||||
check.commands.push(command);
|
||||
if (command === 'newTab') { const tabId = 'native-' + (++next); snapshot.tabs.push({ id: tabId, profileId: args.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; tab.title = 'Example'; }
|
||||
if (command === 'settings') Object.assign(snapshot.settings, args);
|
||||
return structuredClone(snapshot);
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
const output = await outputDir('browser/builtin');
|
||||
const external = () => page.evaluate(() => performance.getEntriesByType('resource').find(entry => new URL(entry.name).pathname === '/src/lib/plugins/external.ts').name);
|
||||
const editorKeys = module => page.evaluate(async module => {
|
||||
const { get } = await import('/node_modules/.vite/deps/svelte_store.js');
|
||||
return get((await import(module)).pluginEditors).map(view => view.key);
|
||||
}, module);
|
||||
try {
|
||||
await page.goto(smokeUrl);
|
||||
await page.waitForFunction(async () => { const { pluginHost } = await import('/src/lib/plugins/registry.ts'); return !!pluginHost.get('browser'); });
|
||||
await page.getByRole('button', { name: 'Open browser', exact: true }).click();
|
||||
await page.locator('[data-browser-state="ready"]').waitFor();
|
||||
await page.getByRole('textbox', { name: 'Address or search' }).fill('https://example.com');
|
||||
await page.getByRole('textbox', { name: 'Address or search' }).press('Enter');
|
||||
await page.waitForFunction(() => window.__TEST__.commands.includes('navigate'));
|
||||
await page.getByRole('button', { name: 'Browser profile' }).click();
|
||||
assert.equal(await page.getByRole('menuitemradio', { checked: true }).count(), 1);
|
||||
await page.keyboard.press('Escape');
|
||||
const module = await external();
|
||||
await page.evaluate(async module => { window.__TEST__.legacy = true; await (await import(module)).refreshPlugins(); }, module);
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.loads.includes('runestone.browser')), false);
|
||||
await page.evaluate(async module => { window.__TEST__.removed = true; await (await import(module)).refreshPlugins(); }, module);
|
||||
assert.equal(await page.locator('[data-browser-state="ready"]').count(), 1);
|
||||
await page.evaluate(async module => { (await import(module)).openPluginView('org.test.boards', 'board-a'); }, module);
|
||||
const before = await editorKeys(module);
|
||||
await page.getByRole('button', { name: 'Select board B' }).click();
|
||||
await page.getByRole('tabpanel', { name: 'board-b', exact: true }).waitFor();
|
||||
await page.waitForFunction(() => window.__TEST__.mounts.includes('board-b') && window.__TEST__.cleanups.includes('board-a'));
|
||||
assert.deepEqual(await editorKeys(module), before);
|
||||
await page.getByRole('button', { name: 'Sidebar fixture', exact: true }).click();
|
||||
await page.getByText('Plugin sidebar fixture', { exact: true }).waitFor();
|
||||
assert.equal(await page.getByRole('tabpanel', { name: 'board-b', exact: true }).count(), 1);
|
||||
for (const theme of ['dark', 'light']) {
|
||||
await page.evaluate(theme => document.documentElement.dataset.theme = theme, theme);
|
||||
await page.screenshot({ path: path.join(output, `builtin-browser-${theme}.png`) });
|
||||
}
|
||||
await page.goto(smokeUrl + '/?settingsWindow=true');
|
||||
await page.getByRole('button', { name: 'Browser', exact: true }).click();
|
||||
await page.getByRole('button', { name: 'Search engine', exact: true }).waitFor({ state: 'visible' });
|
||||
assert.match(await page.getByRole('button', { name: 'Profile', exact: true }).innerText(), /Existing user/);
|
||||
await page.setViewportSize({ width: 360, height: 800 });
|
||||
for (const theme of ['dark', 'light']) {
|
||||
await page.evaluate(theme => document.documentElement.dataset.theme = theme, theme);
|
||||
await page.screenshot({ path: path.join(output, `browser-settings-${theme}.png`) });
|
||||
assert.equal(await page.evaluate(() => document.documentElement.scrollWidth > innerWidth), false);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(await page.evaluate(async () => {
|
||||
const m = await import(performance.getEntriesByType('resource').find(entry => new URL(entry.name).pathname === '/src/lib/plugins/external.ts').name);
|
||||
const read = store => { let value; store.subscribe(x => value = x)(); return value; };
|
||||
const { calls, emit, workspace, ...state } = window.__TEST__;
|
||||
return { state, text: document.body.innerText, errors: read(m.externalErrors), views: read(m.pluginEditors), tools: read(m.pluginTools) };
|
||||
}).catch(reason => ({ diagnosticError: String(reason) })), page.errors);
|
||||
throw error;
|
||||
}
|
||||
console.log('Built-in browser, legacy package independence, same-tab replacement and plugin sidebar checks passed.');
|
||||
}, { viewport: { width: 1280, height: 800 } });
|
||||
Reference in New Issue
Block a user