120 lines
8.6 KiB
JavaScript
120 lines
8.6 KiB
JavaScript
import { nativeRequest } from './native-support.mjs';
|
|
import { chromium } from 'playwright';
|
|
import { spawn } from 'node:child_process';
|
|
import { cp, mkdir, writeFile } from 'node:fs/promises';
|
|
import { resolve, basename, dirname } from 'node:path';
|
|
import net from 'node:net';
|
|
import assert from 'node:assert/strict';
|
|
|
|
if (process.platform !== 'win32') throw new Error('This native smoke test uses Windows WebView2.');
|
|
const host = resolve(process.env.RUNESTONE_ROOT || '..');
|
|
const portServer = net.createServer(); await new Promise(resolve => portServer.listen(0, '127.0.0.1', resolve));
|
|
const port = portServer.address().port; await new Promise(resolve => portServer.close(resolve));
|
|
const native = spawn(resolve(host, 'src-tauri/target/debug/runestone.exe'), [], { windowsHide: true, stdio: 'ignore',
|
|
env: { ...process.env, WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS: `--remote-debugging-port=${port}` } });
|
|
let browser, page;
|
|
const passed = [];
|
|
try {
|
|
for (let attempt = 0; attempt < 60; attempt++) {
|
|
try { browser = await chromium.connectOverCDP(`http://127.0.0.1:${port}`); break; }
|
|
catch { await new Promise(resolve => setTimeout(resolve, 500)); }
|
|
}
|
|
if (!browser) throw new Error('The isolated RuneStone test window did not start.');
|
|
const context = browser.contexts()[0];
|
|
page = context.pages()[0];
|
|
if (!page) page = await context.waitForEvent('page');
|
|
page.setDefaultTimeout(30_000);
|
|
const errors = []; page.on('pageerror', error => errors.push(error.message));
|
|
await page.waitForFunction(() => !!window.__TAURI_INTERNALS__?.invoke);
|
|
const invoke = (command, args = {}) => nativeRequest(page, command, args);
|
|
let snapshot = await invoke('plugins_snapshot');
|
|
const pluginRoot = resolve(snapshot.root);
|
|
assert.equal(basename(pluginRoot), 'plugins');
|
|
assert.equal(basename(dirname(pluginRoot)), 'com.runestone.browser-test', 'Never modify a real RuneStone profile.');
|
|
await page.evaluate(() => window.dispatchEvent(new Event('focus')));
|
|
await page.getByRole('button', { name: 'Open browser', exact: true }).waitFor();
|
|
const initial = await invoke('browser_request', { command: 'state', args: {} });
|
|
await invoke('browser_request', { command: 'settings', args: { ...initial.settings, homepage: '', adblock: true, linkDestination: 'internal' } });
|
|
await mkdir('output', { recursive: true });
|
|
await page.screenshot({ path: 'output/runestone-browser-splash.png' });
|
|
await page.getByRole('button', { name: 'Open browser', exact: true }).click();
|
|
const address = page.getByRole('textbox', { name: 'Address or search', exact: true });
|
|
await address.waitFor();
|
|
await page.locator('.surface img').waitFor();
|
|
const state = await invoke('browser_request', { command: 'state', args: {} });
|
|
assert.equal(state.profiles[0].name, 'User'); assert.ok(!state.profiles.some(item => item.id === 'agent'));
|
|
assert.equal(state.tabs[0].url, 'about:blank');
|
|
passed.push('browser opens inside the RuneStone editor with a User profile');
|
|
await address.fill('https://example.com/'); await address.press('Enter');
|
|
await page.waitForFunction(() => [...document.querySelectorAll('[role=tab]')].some(tab => /Example|example/i.test(tab.textContent)), { timeout: 30_000 });
|
|
await mkdir('output', { recursive: true });
|
|
await page.screenshot({ path: 'output/runestone-browser-internal.png' });
|
|
passed.push('a public HTTPS page renders inside the native RuneStone window');
|
|
await page.getByRole('button', { name: 'Bookmark this page', exact: true }).click();
|
|
await page.getByRole('button', { name: 'Bookmarks', exact: true }).click();
|
|
await page.locator('.bookmarks .link').first().waitFor();
|
|
passed.push('web bookmarks appear in the existing Bookmarks pane');
|
|
await page.getByRole('button', { name: 'Settings (Ctrl+,)', exact: true }).click();
|
|
await page.getByRole('button', { name: 'Browser', exact: true }).click();
|
|
const settings = page.getByRole('dialog', { name: 'Settings', exact: true });
|
|
await settings.getByRole('button', { name: 'New blank profile', exact: true }).waitFor();
|
|
const adblockSwitch = settings.getByRole('switch', { name: 'Block ads and trackers', exact: true });
|
|
const linkSwitch = settings.getByRole('switch', { name: 'Open web links in RuneStone', exact: true });
|
|
await adblockSwitch.uncheck(); await linkSwitch.uncheck();
|
|
await settings.getByRole('textbox', { name: 'Homepage', exact: true }).fill('https://example.com/');
|
|
const lists = settings.getByRole('textbox', { name: 'Ad blocking lists', exact: true });
|
|
assert.match(await lists.inputValue(), /easylist\.txt/);
|
|
await lists.fill('https://easylist.to/easylist/easylist.txt');
|
|
await settings.getByRole('button', { name: 'Save browser settings', exact: true }).click();
|
|
await settings.getByText('Changes saved.', { exact: true }).waitFor();
|
|
let saved = await invoke('browser_request', { command: 'state', args: {} });
|
|
assert.equal(saved.settings.homepage, 'https://example.com/');
|
|
assert.equal(saved.settings.linkDestination, 'external');
|
|
assert.equal(saved.settings.adblock, false);
|
|
assert.deepEqual(saved.settings.filterLists, ['https://easylist.to/easylist/easylist.txt']);
|
|
assert.equal(await adblockSwitch.evaluate(node => getComputedStyle(node).appearance), 'none');
|
|
await adblockSwitch.focus(); await page.keyboard.press('Space');
|
|
assert.equal(await adblockSwitch.isChecked(), true);
|
|
await settings.getByRole('button', { name: 'Save browser settings', exact: true }).click();
|
|
await settings.getByText('Changes saved.', { exact: true }).waitFor();
|
|
await settings.getByRole('textbox', { name: 'Homepage', exact: true }).scrollIntoViewIfNeeded();
|
|
await page.screenshot({ path: 'output/runestone-browser-settings.png' });
|
|
await page.evaluate(() => document.documentElement.dataset.theme = 'light');
|
|
await page.screenshot({ path: 'output/runestone-browser-settings-light.png' });
|
|
await page.evaluate(() => document.documentElement.dataset.theme = 'dark');
|
|
await page.keyboard.press('Escape');
|
|
await settings.waitFor({ state: 'detached' });
|
|
await page.getByRole('button', { name: 'New browser tab', exact: true }).click();
|
|
await page.waitForFunction(() => [...document.querySelectorAll('[role=tab]')].filter(tab => /Example|example/i.test(tab.textContent)).length >= 2);
|
|
saved = await invoke('browser_request', { command: 'state', args: {} });
|
|
assert.equal(saved.tabs.at(-1).url, 'https://example.com/');
|
|
await page.getByRole('button', { name: 'Settings (Ctrl+,)', exact: true }).click();
|
|
await page.getByRole('button', { name: 'Browser', exact: true }).click();
|
|
await page.waitForFunction(() => document.querySelector('input[aria-label="Homepage"]')?.value === 'https://example.com/');
|
|
assert.equal(await settings.getByRole('textbox', { name: 'Homepage', exact: true }).inputValue(), 'https://example.com/');
|
|
assert.equal(await linkSwitch.isChecked(), false);
|
|
passed.push('splash launch, sliding switches, filter-list edits and homepage persist and work in the native app');
|
|
const profileName = settings.getByRole('textbox', { name: 'New profile name', exact: true });
|
|
const suffix = Date.now().toString().slice(-6);
|
|
const research = `Research ${suffix}`, copy = `User copy ${suffix}`;
|
|
await profileName.fill(research); await settings.getByRole('button', { name: 'New blank profile', exact: true }).click();
|
|
await page.waitForFunction(name => [...document.querySelectorAll('.settings option')].some(option => option.textContent === name), research);
|
|
await settings.getByLabel('Profile', { exact: true }).selectOption('user');
|
|
await profileName.fill(copy); await settings.getByRole('button', { name: 'Duplicate profile', exact: true }).click();
|
|
await page.waitForFunction(name => [...document.querySelectorAll('.settings option')].some(option => option.textContent === name), copy);
|
|
passed.push('blank and duplicate profile actions work in RuneStone Settings');
|
|
assert.equal(await address.last().evaluate(node => getComputedStyle(node).borderRadius), await page.locator('.toolbar .icon-btn').last().evaluate(node => getComputedStyle(node).borderRadius));
|
|
passed.push('browser controls share RuneStone corner tokens in both themes');
|
|
await invoke('browser_stop');
|
|
passed.push('browser cleanup revokes the window session');
|
|
assert.deepEqual(errors, []);
|
|
await writeFile('output/native-plugin-smoke.json', JSON.stringify({ passed, errors }, null, 2));
|
|
for (const name of passed) console.log(`PASS ${name}`);
|
|
} catch (error) {
|
|
if (page) { await mkdir('output', { recursive: true }); await page.screenshot({ path: 'output/native-failure.png' }).catch(() => {}); console.error(await page.locator('body').innerText().catch(() => '')); }
|
|
throw error;
|
|
} finally {
|
|
if (browser) { await browser.close().catch(() => {}); }
|
|
native.kill();
|
|
}
|