// 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(); }