RuneStone 1.0.0
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
// Native built-in browser: page rendering at device pixel ratio, the page context menu, editing commands, and session checks.
|
||||
// Start a debug app with an isolated identifier (com.runestone.browser-test or com.runestone.spelling-test) and remote debugging on port 9224:
|
||||
// set WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS=--remote-debugging-port=9224
|
||||
// pnpm tauri dev --config "{\"identifier\":\"com.runestone.browser-test\"}"
|
||||
// The browser runtime needs `npm ci --prefix browser-runtime`. The test loads https://example.com/.
|
||||
// Run `node tests/native/browser.native.mjs`. NATIVE_CDP_URL (or the older BROWSER_NATIVE_CDP) overrides http://127.0.0.1:9224.
|
||||
import path from 'node:path';
|
||||
import assert from 'node:assert/strict';
|
||||
import { writeFile } from 'node:fs/promises';
|
||||
import { outputDir, playwright } from '../smoke/_harness/index.mjs';
|
||||
const { chromium } = playwright();
|
||||
const browser = await chromium.connectOverCDP(process.env.NATIVE_CDP_URL || process.env.BROWSER_NATIVE_CDP || 'http://127.0.0.1:9224');
|
||||
const output = await outputDir('native/browser');
|
||||
const page = browser.contexts()[0].pages()[0];
|
||||
const raw = (command, args = {}) => page.evaluate(({ command, args }) => window.__TAURI_INTERNALS__.invoke(command, args), { command, args });
|
||||
const profile = await raw('plugins_snapshot');
|
||||
assert.ok(/[\\/]com\.runestone\.(?:browser|spelling)-test[\\/]plugins$/.test(profile.root), 'Native acceptance requires an isolated test profile.');
|
||||
const session = await raw('browser_connect');
|
||||
const request = (command, args = {}) => raw('browser_request', { command, args, session });
|
||||
const initialTabs = (await request('state')).tabs.map(tab => tab.id);
|
||||
let tabId;
|
||||
try {
|
||||
await page.keyboard.press('Control+t');
|
||||
await page.getByRole('button', { name: 'Open browser', exact: true }).click();
|
||||
const surface = page.getByRole('application', { name: 'Web page', exact: true }).last();
|
||||
await page.locator('.browser[data-browser-state="ready"]').last().waitFor();
|
||||
tabId = await page.locator('.browser[data-browser-state="ready"]').last().getAttribute('data-browser-tab');
|
||||
const address = page.getByRole('textbox', { name: 'Address or search', exact: true }).last();
|
||||
await address.fill('https://example.com/'); await address.press('Enter');
|
||||
for (let attempt = 0; attempt < 60; attempt++) {
|
||||
const snapshot = await request('agentSnapshot', { tabId });
|
||||
if (snapshot.text.includes('documentation examples')) break;
|
||||
if (attempt === 59) throw Error(`Public test page did not load: ${snapshot.text}`);
|
||||
await page.waitForTimeout(250);
|
||||
}
|
||||
await page.waitForFunction(() => [...document.querySelectorAll('.surface img')].some(image => image.complete && image.naturalWidth > 0));
|
||||
const dimensions = await surface.locator('img').evaluate(image => ({ width: image.naturalWidth, height: image.naturalHeight,
|
||||
css: image.getBoundingClientRect().width, scale: devicePixelRatio, source: image.src.slice(0, 30) }));
|
||||
assert.ok(dimensions.width >= dimensions.css * dimensions.scale - 2, JSON.stringify(dimensions));
|
||||
const bounds = await surface.boundingBox();
|
||||
await page.mouse.click(bounds.x + 20, bounds.y + 20, { button: 'right' });
|
||||
const menu = page.getByRole('menu', { name: 'Browser page actions', exact: true });
|
||||
await menu.waitFor();
|
||||
assert.equal(await menu.getByRole('menuitem', { name: 'Reload', exact: true }).count(), 1);
|
||||
await page.keyboard.press('Escape'); await menu.waitFor({ state: 'detached' });
|
||||
await request('edit', { tabId, action: 'selectAll' });
|
||||
await page.waitForTimeout(100);
|
||||
await request('edit', { tabId, action: 'copy' });
|
||||
await page.waitForTimeout(100);
|
||||
await address.focus(); await page.keyboard.press('Control+a'); await page.keyboard.press('Control+v');
|
||||
assert.match(await address.inputValue(), /documentation examples/);
|
||||
await address.fill('https://example.com/');
|
||||
await assert.rejects(raw('browser_request', { command: 'edit', args: { tabId, action: 'copy' }, session: 'invalid-session' }), /session/i);
|
||||
await assert.rejects(request('contextAction', { tabId, token: 'stale-menu', action: 'saveImage' }), /no longer available/);
|
||||
await page.screenshot({ path: path.join(output, 'acceptance.png') });
|
||||
await writeFile(path.join(output, 'acceptance.json'), JSON.stringify({ dimensions, passed: [
|
||||
'Native Tauri-to-Electron page rendering and high-DPI frame delivery', 'Native page context event opens the shared host menu',
|
||||
'Native editing commands copy real webpage text', 'Session and stale-menu checks reject invalid requests',
|
||||
] }, null, 2));
|
||||
console.log('PASS native browser transport, rendering, context menu, editing and session protection');
|
||||
} finally {
|
||||
if (tabId && !initialTabs.includes(tabId)) { await page.keyboard.press('Escape'); await page.keyboard.press('Control+w'); }
|
||||
await browser.close();
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
// Native editing menus in inputs, textareas, and dialogs: unsupported WebView2 commands stay hidden, Undo and spelling work, and focus returns, in both themes.
|
||||
// Start a debug app with the isolated identifier com.runestone.spelling-test and remote debugging on port 9237:
|
||||
// set WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS=--remote-debugging-port=9237
|
||||
// pnpm tauri dev --config "{\"identifier\":\"com.runestone.spelling-test\"}"
|
||||
// Run `node tests/native/menuScope.native.mjs`. NATIVE_CDP_URL (or the older SPELLING_CDP_URL) overrides http://127.0.0.1:9237.
|
||||
import { writeFile } from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import assert from 'node:assert/strict';
|
||||
import { outputDir, playwright } from '../smoke/_harness/index.mjs';
|
||||
const { chromium } = playwright();
|
||||
const browser = await chromium.connectOverCDP(process.env.NATIVE_CDP_URL || process.env.SPELLING_CDP_URL || 'http://127.0.0.1:9237');
|
||||
const page = browser.contexts()[0].pages()[0];
|
||||
page.setDefaultTimeout(15000);
|
||||
const captures = [];
|
||||
try {
|
||||
await page.waitForFunction(() => !!window.__TAURI_INTERNALS__);
|
||||
await page.getByRole('button', { name: 'Settings (Ctrl+,)', exact: true }).waitFor();
|
||||
const identity = await page.evaluate(async () => (await import('/node_modules/@tauri-apps/api/path.js')).appDataDir());
|
||||
assert.match(identity, /[\\/]com\.runestone\.spelling-test[\\/]?$/);
|
||||
await page.evaluate(async () => {
|
||||
const { listen } = await import('/node_modules/@tauri-apps/api/event.js');
|
||||
window.nativeMenuPayload = null;
|
||||
await listen('spelling-menu', ({ payload }) => window.nativeMenuPayload = payload);
|
||||
await (await import('/node_modules/@tauri-apps/api/core.js')).invoke('spelling_menu_install');
|
||||
});
|
||||
const output = await outputDir('native/menuScope');
|
||||
const capturesFile = path.join(output, 'native-filtered-items.json');
|
||||
const menu = page.getByRole('menu', { name: 'Spelling actions', exact: true });
|
||||
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);
|
||||
for (const kind of ['input', 'textarea', 'dialog']) {
|
||||
await page.evaluate(kind => {
|
||||
document.getElementById('native-menu-field')?.remove(); document.getElementById('native-menu-dialog')?.remove();
|
||||
const field = document.createElement(kind === 'input' ? 'input' : 'textarea');
|
||||
field.id = 'native-menu-field'; field.spellcheck = true; field.value = 'I recieved a letter.';
|
||||
field.style.cssText = 'position:fixed;left:100px;top:100px;width:500px;height:100px;font:16px/24px Arial;padding:10px;z-index:100';
|
||||
if (kind === 'dialog') { const dialog = document.createElement('dialog'); dialog.id = 'native-menu-dialog'; dialog.append(field); document.body.append(dialog); dialog.showModal(); }
|
||||
else document.body.append(field);
|
||||
field.focus();
|
||||
}, kind);
|
||||
const field = page.locator('#native-menu-field');
|
||||
await field.press('End');
|
||||
await field.pressSequentially(' TEST');
|
||||
await field.click({ button: 'right', position: { x: 300, y: kind === 'input' ? 50 : 22 } });
|
||||
await menu.waitFor();
|
||||
const payload = await page.evaluate(() => window.nativeMenuPayload);
|
||||
captures.push({ mode, kind, value: await field.inputValue(), payload });
|
||||
await writeFile(capturesFile, JSON.stringify(captures, null, 2));
|
||||
const flatten = items => items.flatMap(item => [item, ...flatten(item.children)]);
|
||||
const entries = flatten(payload.items);
|
||||
assert.ok(entries.every(item => item.kind === 3 || !['share', 'writingDirection', 'voiceTyping', 'other'].includes(item.name)));
|
||||
assert.ok(entries.some(item => item.name === 'undo' && item.enabled), mode + ' ' + kind + ' keeps native Undo enabled');
|
||||
assert.ok(entries.some(item => item.name === 'emoji'));
|
||||
assert.ok(entries.some(item => item.name === 'copy'));
|
||||
assert.equal(await menu.getByRole('menuitem', { name: /More tools|Writing direction|Voice typing|Share/ }).count(), 0);
|
||||
assert.equal(await menu.evaluate(node => getComputedStyle(node).borderColor), 'rgba(0, 0, 0, 0)');
|
||||
if (kind === 'textarea') await page.screenshot({ path: path.join(output, `native-${mode}.png`) });
|
||||
await menu.getByRole('menuitem', { name: 'Undo Ctrl+Z', exact: true }).click();
|
||||
await page.waitForFunction(() => document.getElementById('native-menu-field').value === 'I recieved a letter.').catch(async error => { console.error('Undo result', await field.inputValue()); throw error; });
|
||||
await field.click({ button: 'right', position: { x: 48, y: kind === 'input' ? 50 : 22 } });
|
||||
await menu.getByRole('menuitem', { name: 'received', exact: true }).click();
|
||||
assert.equal(await field.inputValue(), 'I received a letter.');
|
||||
await field.press('Control+z');
|
||||
assert.equal(await field.inputValue(), 'I recieved a letter.');
|
||||
await field.click({ button: 'right', position: { x: 48, y: kind === 'input' ? 50 : 22 } });
|
||||
await menu.waitFor();
|
||||
await page.keyboard.press('Escape');
|
||||
assert.equal(await field.evaluate(node => document.activeElement === node), true);
|
||||
}
|
||||
}
|
||||
await writeFile(capturesFile, JSON.stringify(captures, null, 2));
|
||||
console.log('PASS: real WebView2 menus omit unsupported commands, retain editing and spelling, execute native Undo, correct spelling with undo, and restore focus in fields and dialogs in both themes.');
|
||||
} finally {
|
||||
await page.evaluate(() => { document.getElementById('native-menu-field')?.remove(); document.getElementById('native-menu-dialog')?.remove(); }).catch(() => {});
|
||||
await browser.close();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
// Native spelling menu in Writer, inputs, textareas, and dialogs: WebView2 Undo, spelling corrections, and editor undo.
|
||||
// Start a debug app with the isolated identifier com.runestone.spelling-test, a hidden window, a separate
|
||||
// WEBVIEW2_USER_DATA_FOLDER outside Vite's watch paths, and remote debugging on port 9224:
|
||||
// set WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS=--remote-debugging-port=9224
|
||||
// pnpm tauri dev --config "{\"identifier\":\"com.runestone.spelling-test\"}"
|
||||
// Run `node tests/native/spelling.native.mjs`. NATIVE_CDP_URL (or the older SPELLING_CDP_URL) overrides http://127.0.0.1:9224.
|
||||
// SPELLING_APP_URL overrides http://localhost:1420. SPELLING_WORKSPACE overrides the workspace folder in output/smoke/native/spelling/.
|
||||
// The normal app identifier is rejected before this test writes any workspace files.
|
||||
import { mkdir, writeFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import assert from "node:assert/strict";
|
||||
import { outputDir, playwright } from "../smoke/_harness/index.mjs";
|
||||
|
||||
const { chromium } = playwright();
|
||||
const browser = await chromium.connectOverCDP(process.env.NATIVE_CDP_URL || process.env.SPELLING_CDP_URL || "http://127.0.0.1:9224");
|
||||
const page = browser.contexts()[0].pages()[0];
|
||||
page.setDefaultTimeout(15000);
|
||||
try {
|
||||
await page.goto(process.env.SPELLING_APP_URL || "http://localhost:1420");
|
||||
const data = await page.evaluate(async () => {
|
||||
const { appDataDir } = await import("/node_modules/@tauri-apps/api/path.js");
|
||||
return appDataDir();
|
||||
});
|
||||
assert.match(data, /[\\/]com\.runestone\.spelling-test[\\/]?$/, "Use the isolated spelling-test app identifier");
|
||||
const output = await outputDir("native/spelling");
|
||||
const workspace = path.resolve(process.env.SPELLING_WORKSPACE || path.join(output, "workspace"));
|
||||
await mkdir(workspace, { recursive: true });
|
||||
await writeFile(path.join(workspace, "Spelling.md"), "# Spelling\n\nI recieved a letter.\n");
|
||||
await page.evaluate(async path => {
|
||||
const { invoke } = await import("/node_modules/@tauri-apps/api/core.js");
|
||||
await invoke("workspace_open", { path });
|
||||
}, workspace);
|
||||
await page.reload();
|
||||
await page.locator('[data-tree-rel="Spelling.md"]').click();
|
||||
const editor = page.locator(".cm-content");
|
||||
await editor.waitFor();
|
||||
const line = page.getByText("I recieved a letter.", { exact: true });
|
||||
const rect = await line.boundingBox();
|
||||
await line.click();
|
||||
const before = await editor.innerText();
|
||||
await page.keyboard.press("End");
|
||||
await page.keyboard.type(" TEST");
|
||||
const typed = await editor.innerText();
|
||||
assert.notEqual(typed, before);
|
||||
await page.mouse.click(rect.x + 42, rect.y + rect.height / 2, { button: "right" });
|
||||
const menu = page.getByRole("menu", { name: "Spelling actions", exact: true });
|
||||
await menu.waitFor();
|
||||
await page.screenshot({ path: path.join(output, "spelling-menu.png") });
|
||||
const undo = menu.getByRole("menuitem", { name: "Undo Ctrl+Z", exact: true });
|
||||
assert.equal(await undo.isEnabled(), true, "The native Undo command is enabled after typing");
|
||||
await undo.click();
|
||||
await page.waitForFunction(previous => document.querySelector(".cm-content")?.innerText !== previous, typed);
|
||||
const remaining = (await editor.innerText()).match(/^I recieved a letter\.(.*)$/m)?.[1];
|
||||
assert.ok(remaining !== undefined && remaining.length < " TEST".length && " TEST".startsWith(remaining), "Native Undo reduces the appended text and preserves the original paragraph");
|
||||
// WebView2 and CodeMirror can group typing differently. Restore the fixture through editor history.
|
||||
for (let attempt = 0; attempt < 8 && await editor.innerText() !== before; attempt++) {
|
||||
await page.keyboard.press("Control+z");
|
||||
await page.evaluate(() => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))));
|
||||
}
|
||||
assert.equal(await editor.innerText(), before, "Bounded keyboard Undo restores the exact original editor text");
|
||||
console.log("PASS: real WebView2 Undo reduces the typed text, and bounded editor Undo restores the fixture.");
|
||||
|
||||
await page.mouse.click(rect.x + 42, rect.y + rect.height / 2, { button: "right" });
|
||||
await menu.waitFor();
|
||||
const suggestion = menu.getByRole("menuitem", { name: "received", exact: true });
|
||||
if (await suggestion.count()) {
|
||||
await suggestion.click();
|
||||
await page.waitForFunction(() => document.querySelector(".cm-content")?.innerText.includes("I received a letter."));
|
||||
await page.keyboard.press("Control+z");
|
||||
await page.waitForFunction(() => document.querySelector(".cm-content")?.innerText.includes("I recieved a letter."));
|
||||
console.log("PASS: native spelling correction and editor undo.");
|
||||
} else {
|
||||
await page.keyboard.press("Escape");
|
||||
assert.notEqual(process.env.REQUIRE_NATIVE_SUGGESTIONS, "1", "The test WebView2 profile supplied no spelling suggestions");
|
||||
console.log("SKIP: native spelling correction. This WebView2 profile supplied no suggestions. Desktop acceptance is still required.");
|
||||
}
|
||||
for (const kind of ["input", "textarea", "dialog"]) {
|
||||
await page.evaluate(kind => {
|
||||
const field = document.createElement(kind === "input" ? "input" : "textarea");
|
||||
field.id = "native-spelling-field"; field.spellcheck = true;
|
||||
field.value = "I recieved a letter.";
|
||||
field.style.cssText = "position:fixed;left:250px;top:200px;width:500px;height:100px;font:16px/24px Arial;padding:10px;z-index:100";
|
||||
if (kind === "dialog") { const dialog = document.createElement("dialog"); dialog.id = "native-spelling-dialog"; dialog.append(field); document.body.append(dialog); dialog.showModal(); }
|
||||
else document.body.append(field);
|
||||
field.focus();
|
||||
}, kind);
|
||||
const field = page.locator("#native-spelling-field"), box = await field.boundingBox();
|
||||
await page.mouse.click(box.x + 48, box.y + (kind === "input" ? box.height / 2 : 22), { button: "right" });
|
||||
await menu.getByRole("menuitem", { name: "received", exact: true }).click();
|
||||
assert.equal(await field.inputValue(), "I received a letter.", kind + " corrects the clicked word");
|
||||
await page.keyboard.press("Control+z");
|
||||
assert.equal(await field.inputValue(), "I recieved a letter.", kind + " retains undo");
|
||||
await page.evaluate(() => { document.getElementById("native-spelling-field")?.remove(); document.getElementById("native-spelling-dialog")?.remove(); });
|
||||
}
|
||||
console.log("PASS: native spelling corrections and undo in inputs, card textareas, and top-layer dialogs.");
|
||||
} finally {
|
||||
await page.keyboard.press("Escape").catch(() => {});
|
||||
await browser.close();
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
// Native windows: an empty-tab transfer opens a window that acknowledges the saved tab, and the settings window's theme export rejects invalid JSON.
|
||||
// Start a debug app with the isolated identifier com.runestone.spelling-test, a workspace open, and remote debugging on port 9224:
|
||||
// set WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS=--remote-debugging-port=9224
|
||||
// pnpm tauri dev --config "{\"identifier\":\"com.runestone.spelling-test\"}"
|
||||
// Run `node tests/native/tabTransferAndThemeExport.native.mjs`. NATIVE_CDP_URL (or the older SPELLING_CDP_URL) overrides http://127.0.0.1:9224.
|
||||
import assert from 'node:assert/strict';
|
||||
import { playwright } from '../smoke/_harness/index.mjs';
|
||||
const {chromium}=playwright();
|
||||
const browser=await chromium.connectOverCDP(process.env.NATIVE_CDP_URL || process.env.SPELLING_CDP_URL || 'http://127.0.0.1:9224');
|
||||
const context=browser.contexts()[0];
|
||||
const page=context.pages().find(page => new URL(page.url()).pathname === '/' && !new URL(page.url()).search);
|
||||
assert.ok(page, 'The isolated main window must be open.');
|
||||
let transferred, settings;
|
||||
try {
|
||||
const identity=await page.evaluate(async()=> (await import('/node_modules/@tauri-apps/api/path.js')).appDataDir());
|
||||
assert.match(identity, /[\\/]com\.runestone\.spelling-test[\\/]?$/);
|
||||
const pending=context.waitForEvent('page');
|
||||
// The source window offers the tab through the host and waits for the acknowledgement that the host sends to it alone.
|
||||
const token=await page.evaluate(async()=>{
|
||||
const {invoke}=await import('/node_modules/@tauri-apps/api/core.js');
|
||||
const {listen}=await import('/node_modules/@tauri-apps/api/event.js');
|
||||
const {getCurrentWindow}=await import('/node_modules/@tauri-apps/api/window.js');
|
||||
const root=await invoke('workspace_last_path');
|
||||
const token=crypto.randomUUID(), id=crypto.randomUUID();
|
||||
window.__nativeTransferAccepted=false;
|
||||
await listen('tab-transfer-accepted',event=>{ if(event.payload.id===token) window.__nativeTransferAccepted=true; },{target:getCurrentWindow().label});
|
||||
const payload=JSON.stringify({reading:false,buffer:{id,relPath:'empty:'+id,name:'New tab',kind:'empty',imageUrl:null,contents:'',saved:'',chrome:'Writing',chromeOverride:null}});
|
||||
await invoke('tab_transfer_offer',{id:token,root,payload});
|
||||
await invoke('workspace_open_window',{path:root,transfer:token});
|
||||
return token;
|
||||
});
|
||||
transferred=await pending;
|
||||
await transferred.locator('.empty').waitFor();
|
||||
assert.ok(transferred.url().includes('?tabTransfer='+token));
|
||||
assert.ok(!transferred.url().includes('index.html'));
|
||||
assert.equal(await transferred.getByText('404',{exact:true}).count(),0);
|
||||
await page.waitForFunction(()=>window.__nativeTransferAccepted===true);
|
||||
console.log('PASS: native empty-tab transfer loads the splash screen and acknowledges its saved tab state.');
|
||||
await transferred.evaluate(async()=> (await import('/node_modules/@tauri-apps/api/window.js')).getCurrentWindow().close()); transferred=undefined;
|
||||
settings=context.pages().find(page => page.url().includes('settingsWindow=true'));
|
||||
const next=settings ? Promise.resolve(settings) : context.waitForEvent('page');
|
||||
await page.evaluate(async()=> (await import('/node_modules/@tauri-apps/api/core.js')).invoke('settings_open_window'));
|
||||
settings=await next;
|
||||
await settings.waitForURL(/settingsWindow=true/);
|
||||
await settings.waitForLoadState('domcontentloaded');
|
||||
const error=await settings.evaluate(async()=>{
|
||||
try { await (await import('/node_modules/@tauri-apps/api/core.js')).invoke('theme_export',{contents:'{',defaultName:'test.json'}); }
|
||||
catch(error) { return String(error); }
|
||||
});
|
||||
assert.equal(error,'The theme contains invalid JSON.');
|
||||
console.log('PASS: the native settings window can call theme export; invalid JSON stops before the save dialog.');
|
||||
} finally {
|
||||
for(const target of [transferred,settings]) if(target&&!target.isClosed()) await target.evaluate(async()=> (await import('/node_modules/@tauri-apps/api/window.js')).getCurrentWindow().close()).catch(()=>{});
|
||||
await browser.close();
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
// Native tree and windows: rename undo keeps folders expanded, Open in new window moves a tab without changing the saved layout,
|
||||
// 50 MiB of JSON passes through workspace IPC, and a large background image survives a reload.
|
||||
// Start a debug app with the isolated identifier com.runestone.pass3-test and remote debugging on port 9236:
|
||||
// set WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS=--remote-debugging-port=9236
|
||||
// pnpm tauri dev --config "{\"identifier\":\"com.runestone.pass3-test\"}"
|
||||
// Run `node tests/native/treeRename.native.mjs`. NATIVE_CDP_URL (or the older NAVIGATION_NATIVE_CDP) overrides http://127.0.0.1:9236.
|
||||
// The test opens a workspace in the system temporary folder.
|
||||
import assert from 'node:assert/strict';
|
||||
import { mkdir, writeFile } from 'node:fs/promises';
|
||||
import { join } from 'node:path';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { outputDir, playwright } from '../smoke/_harness/index.mjs';
|
||||
|
||||
const { chromium } = playwright();
|
||||
const browser = await chromium.connectOverCDP(process.env.NATIVE_CDP_URL || process.env.NAVIGATION_NATIVE_CDP || 'http://127.0.0.1:9236');
|
||||
const context = browser.contexts()[0];
|
||||
const page = context.pages().find(page => new URL(page.url()).pathname === '/' && !new URL(page.url()).search);
|
||||
assert.ok(page, 'The isolated main window must be open.');
|
||||
page.setDefaultTimeout(20000);
|
||||
const output = await outputDir('native/treeRename');
|
||||
// Settings and reload pages use the app's own dev server, not a fixed port.
|
||||
const origin = new URL(page.url()).origin;
|
||||
const workspace = join(tmpdir(), 'runestone-pass3-native-workspace');
|
||||
const results = {};
|
||||
let detached;
|
||||
try {
|
||||
const identity = await page.evaluate(async () => (await import('/node_modules/@tauri-apps/api/path.js')).appDataDir());
|
||||
assert.match(identity, /[\\/]com\.runestone\.pass3-test[\\/]?$/);
|
||||
results.identity = identity;
|
||||
await mkdir(join(workspace, 'folder', 'nested'), { recursive: true });
|
||||
await mkdir(join(workspace, 'other'), { recursive: true });
|
||||
await writeFile(join(workspace, 'folder', 'nested', 'note.md'), '# Native note\n\nText for transfer.\n');
|
||||
await writeFile(join(workspace, 'other', 'keep.md'), '# Keep');
|
||||
await page.evaluate(async path => {
|
||||
await (await import('/node_modules/@tauri-apps/api/core.js')).invoke('workspace_open', { path });
|
||||
localStorage.setItem('runestone.workbenchLayout', JSON.stringify({ leftOpen: true, rightOpen: true, leftWidth: 260, rightWidth: 240, leftView: 'files' }));
|
||||
}, workspace);
|
||||
await page.reload();
|
||||
const row = path => page.locator(`[data-tree-rel="${path}"]`);
|
||||
await row('folder').click(); await row('folder/nested').click(); await row('other').click();
|
||||
await row('folder/nested/note.md').click({ button: 'right' });
|
||||
await page.getByRole('menuitem', { name: 'Rename', exact: true }).click();
|
||||
await page.locator('.tree input').fill('renamed.md'); await page.locator('.tree input').press('Enter');
|
||||
await row('folder/nested/renamed.md').waitFor();
|
||||
await row('folder/nested/renamed.md').focus(); await page.keyboard.press('Control+z');
|
||||
await row('folder/nested/note.md').waitFor();
|
||||
for (const path of ['folder', 'folder/nested', 'other']) assert.equal(await row(path).getAttribute('aria-expanded'), 'true');
|
||||
results.renameUndoPreservesExpandedFolders = true;
|
||||
await row('folder/nested/note.md').click();
|
||||
await page.getByRole('tab', { name: /note.md/ }).waitFor();
|
||||
await page.getByText('Text for transfer.', { exact: true }).waitFor();
|
||||
const savedLayout = await page.evaluate(() => localStorage.getItem('runestone.workbenchLayout'));
|
||||
const pending = context.waitForEvent('page');
|
||||
await page.getByRole('tab', { name: /note.md/ }).click({ button: 'right' });
|
||||
await page.getByRole('menuitem', { name: 'Open in new window', exact: true }).click();
|
||||
detached = await pending;
|
||||
await detached.getByRole('tab', { name: /note.md/ }).waitFor();
|
||||
await detached.evaluate(async () => (await import('/node_modules/@tauri-apps/api/window.js')).getCurrentWindow().minimize());
|
||||
await detached.getByText('Text for transfer.', { exact: true }).waitFor();
|
||||
assert.ok(detached.url().includes('tabTransfer='));
|
||||
assert.equal(await detached.locator('.shell.left-open,.shell.right-open').count(), 0);
|
||||
await page.getByRole('tab', { name: /note.md/ }).waitFor({ state: 'detached' });
|
||||
const sourceClosed = await page.getByRole('tab', { name: /note.md/ }).count() === 0;
|
||||
await detached.getByRole('button', { name: 'Show outline', exact: true }).click();
|
||||
assert.equal(await page.evaluate(() => localStorage.getItem('runestone.workbenchLayout')), savedLayout);
|
||||
await detached.getByRole('button', { name: 'Hide outline', exact: true }).click();
|
||||
results.nativeTransfer = { sourceClosed, columnsHidden: true, savedLayoutPreserved: true };
|
||||
for (const mode of ['light', 'dark']) {
|
||||
await detached.evaluate(async mode => { const { saveAppearance } = await import('/src/lib/theme/appearance.ts'); saveAppearance({ theme: 'default', mode }); }, mode);
|
||||
await detached.screenshot({ path: join(output, `detached-${mode}.png`) });
|
||||
}
|
||||
results.imageJsonIpc = await page.evaluate(async () => {
|
||||
const { invoke } = await import('/node_modules/@tauri-apps/api/core.js');
|
||||
const bytes = 50 * 1024 * 1024;
|
||||
const pixel = Uint8Array.from(atob('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jM1sAAAAASUVORK5CYII='), char => char.charCodeAt(0));
|
||||
const blob = new Blob([pixel, new Uint8Array(bytes - pixel.length)], { type: 'image/png' });
|
||||
const data = await new Promise((resolve, reject) => { const reader = new FileReader(); reader.onload = () => resolve(reader.result); reader.onerror = reject; reader.readAsDataURL(blob); });
|
||||
const contents = JSON.stringify({ schema: 1, data });
|
||||
const start = performance.now();
|
||||
await invoke('workspace_write', { rel: '.runestone/pm/images/native-50mib.json', contents });
|
||||
const written = performance.now();
|
||||
const read = await invoke('workspace_read', { rel: '.runestone/pm/images/native-50mib.json' });
|
||||
return { bytes, jsonLength: contents.length, matches: read === contents, writeMs: Math.round(written - start), readMs: Math.round(performance.now() - written) };
|
||||
});
|
||||
assert.equal(results.imageJsonIpc.matches, true);
|
||||
await page.goto(`${origin}/?settingsWindow=true`);
|
||||
await page.getByRole('button', { name: 'Appearance', exact: true }).click();
|
||||
const pixel = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jM1sAAAAASUVORK5CYII=', 'base64');
|
||||
const largeImage = Buffer.concat([pixel, Buffer.alloc(1_900_000 - pixel.length)]);
|
||||
await page.getByLabel('Background image file', { exact: true }).setInputFiles({ name: 'native-large.png', mimeType: 'image/png', buffer: largeImage });
|
||||
// The appearance is in the settings file of the host.
|
||||
await page.waitForFunction(() => window.__TAURI_INTERNALS__.invoke('settings_read').then(file => !!file.sections.appearance?.newTabBackground?.imageId));
|
||||
await page.goto(`${origin}/`);
|
||||
// The image is on the work area layer behind the empty tab (src/lib/layout/Workbench.svelte:1258, :1543-1549).
|
||||
await page.locator('.empty').waitFor();
|
||||
await page.waitForFunction(() => getComputedStyle(document.querySelector('.workarea-background')).backgroundImage.includes('blob:'));
|
||||
await page.reload(); await page.locator('.empty').waitFor();
|
||||
await page.waitForFunction(() => getComputedStyle(document.querySelector('.workarea-background')).backgroundImage.includes('blob:'));
|
||||
results.largeBackground = { bytes: largeImage.length, renderedAfterReload: true };
|
||||
await page.screenshot({ path: join(output, 'large-background.png') });
|
||||
await writeFile(join(output, 'results.json'), JSON.stringify(results, null, 2));
|
||||
console.log(JSON.stringify(results));
|
||||
} catch (error) {
|
||||
await writeFile(join(output, 'partial-results.json'), JSON.stringify(results, null, 2));
|
||||
console.error({ error: String(error), main: await page.locator('body').innerText().catch(() => ''), detached: detached && !detached.isClosed() ? await detached.locator('body').innerText().catch(() => '') : null });
|
||||
throw error;
|
||||
} finally {
|
||||
if (detached && !detached.isClosed()) await detached.evaluate(async () => (await import('/node_modules/@tauri-apps/api/window.js')).getCurrentWindow().destroy()).catch(() => {});
|
||||
await browser.close();
|
||||
}
|
||||
Reference in New Issue
Block a user