WIP VI improve UX [snapshot task 2]
This commit is contained in:
1 parent
a73b3075b6
commit
8665d04f2c
6 files changed
+95
-66
No files matched your search
+41
-32
@@ -106,7 +106,10 @@ async function page(url = origin) {
|
||||
// Background tabs otherwise skip focus/blur events, which the name editor relies on.
|
||||
await call('Emulation.setFocusEmulationEnabled', { enabled: true }, sessionId);
|
||||
await call('Page.addScriptToEvaluateOnNewDocument', { source: `(${installBrowserContext.toString()})()` }, sessionId);
|
||||
if (streaming) await call('Page.addScriptToEvaluateOnNewDocument', { source: 'window.showSaveFilePicker = undefined;' }, sessionId);
|
||||
// The native picker would block headless runs; simulateSlowDisk installs a test double where needed.
|
||||
await call('Page.addScriptToEvaluateOnNewDocument', { source: 'window.showSaveFilePicker = undefined;' }, sessionId);
|
||||
// Without streaming downloads the app falls back to memory, whose bytes the default checks read in-page.
|
||||
if (!streaming) await call('Page.addScriptToEvaluateOnNewDocument', { source: "Object.defineProperty(navigator, 'serviceWorker', { value: undefined });" }, sessionId);
|
||||
if (turn) await call('Page.addScriptToEvaluateOnNewDocument', { source: `(${forceRelay.toString()})(${JSON.stringify(transport)})` }, sessionId);
|
||||
await call('Page.navigate', { url }, sessionId);
|
||||
for (let n = 0; n < 100; n++) {
|
||||
@@ -180,7 +183,26 @@ async function connect(sender: string, receiver: string, size: number, changedId
|
||||
}
|
||||
}
|
||||
}
|
||||
async function verifySavedFile(path: string, size: number) {
|
||||
const deadline = Date.now() + 30000;
|
||||
while (true) {
|
||||
try { if ((await stat(path)).size === size) break; } catch {}
|
||||
if (Date.now() > deadline) throw new Error('Browser did not finish saving the download.');
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
}
|
||||
let bytes = 0;
|
||||
for await (const chunk of createReadStream(path)) {
|
||||
assert.ok((chunk as Buffer).every(byte => byte === 123), 'Downloaded bytes must match');
|
||||
bytes += (chunk as Buffer).length;
|
||||
}
|
||||
assert.equal(bytes, size);
|
||||
await rm(path);
|
||||
}
|
||||
try {
|
||||
// Received files land in the throwaway profile instead of the user's Downloads.
|
||||
const downloads = join(profile, 'downloads');
|
||||
await mkdir(downloads);
|
||||
await call('Browser.setDownloadBehavior', { behavior: 'allow', downloadPath: downloads });
|
||||
if (connections) {
|
||||
const sender = await page(), receiver = await page(origin.replace('127.0.0.1', 'localhost'));
|
||||
const selectConnection = (session: string, name: string) => evaluate(session, (name: string) => {
|
||||
@@ -219,7 +241,7 @@ try {
|
||||
await click(sender, 'Add connection');
|
||||
await wait(sender, () => document.querySelector('.title-line h1')?.textContent === 'Con 2');
|
||||
assert.equal(await evaluate(sender, () => !!document.querySelector('.fingerprint')), false);
|
||||
await click(receiver, 'Receive in memory (up to 64 MiB)');
|
||||
await click(receiver, 'Accept file');
|
||||
await wait(sender, () => document.querySelector('.connection-link .connection-preview')?.textContent === 'browser-test.bin');
|
||||
assert.equal(await evaluate(sender, () => document.querySelectorAll('.activity-item').length), 0, 'Hidden session activity must stay in its own slot');
|
||||
await selectConnection(sender, 'Work laptop');
|
||||
@@ -227,7 +249,7 @@ try {
|
||||
assert.deepEqual(await evaluate(sender, () => [...document.querySelectorAll('.fp-row code')].map(item => item.textContent)), fingerprints);
|
||||
await evaluate(sender, () => window.__hellcon.chooseFile(1234, 'after-switch.bin'));
|
||||
await wait(receiver, () => document.querySelector('.incoming')?.textContent?.includes('after-switch.bin'));
|
||||
await click(receiver, 'Receive in memory (up to 64 MiB)');
|
||||
await click(receiver, 'Accept file');
|
||||
await wait(sender, () => document.querySelectorAll('.activity-item').length === 2);
|
||||
const received = await evaluate(receiver, async () => {
|
||||
const bytes = new Uint8Array(await (await fetch(window.__hellcon.element<HTMLAnchorElement>('a.download').href)).arrayBuffer());
|
||||
@@ -322,9 +344,6 @@ try {
|
||||
console.log('PASS: removal can be cancelled, persists across reload, closes cached sessions in other tabs, and replaces the last slot with a fresh Con 1.');
|
||||
assert.deepEqual(browserErrors, []);
|
||||
} else if (streaming) {
|
||||
const downloads = join(profile, 'downloads');
|
||||
await mkdir(downloads);
|
||||
await call('Browser.setDownloadBehavior', { behavior: 'allow', downloadPath: downloads });
|
||||
const sender = await page(), receiver = await page();
|
||||
await click(receiver, 'Receive');
|
||||
for (const size of [0, 1024 * 1024 + 7, 120 * 1024 * 1024]) {
|
||||
@@ -334,23 +353,10 @@ try {
|
||||
await wait(receiver, () => !!document.querySelector('.incoming'));
|
||||
}
|
||||
assert.equal(await evaluate(receiver, () => typeof window.showSaveFilePicker), 'undefined');
|
||||
await click(receiver, `Receive as download (${size === 0 ? '0 B' : (size / 1024 ** 2).toFixed(1) + ' MiB'})`);
|
||||
await click(receiver, 'Accept file');
|
||||
await wait(sender, () => window.__hellcon.element('[role=status]').textContent?.includes('confirmed the complete file'));
|
||||
assert.match(await evaluate(receiver, () => window.__hellcon.element('[role=status]').textContent), /Check Downloads/);
|
||||
const destination = join(downloads, 'browser-test.bin');
|
||||
const deadline = Date.now() + 30000;
|
||||
while (true) {
|
||||
try { if ((await stat(destination)).size === size) break; } catch {}
|
||||
if (Date.now() > deadline) throw new Error('Browser did not finish saving the download.');
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
}
|
||||
let bytes = 0;
|
||||
for await (const chunk of createReadStream(destination)) {
|
||||
assert.ok((chunk as Buffer).every(byte => byte === 123), 'Downloaded bytes must match');
|
||||
bytes += (chunk as Buffer).length;
|
||||
}
|
||||
assert.equal(bytes, size);
|
||||
await rm(destination);
|
||||
await verifySavedFile(join(downloads, 'browser-test.bin'), size);
|
||||
console.log(`PASS: hosted app streams ${size} bytes to a real browser download without the native save picker; exact file bytes verified.`);
|
||||
}
|
||||
assert.deepEqual(browserErrors, []);
|
||||
@@ -367,7 +373,7 @@ try {
|
||||
await connect(sender, receiver, 2 * 1024 * 1024 + 7);
|
||||
await checkAccessibility(sender, 'Send during transfer');
|
||||
await checkAccessibility(receiver, 'Receive before accepting a file');
|
||||
await click(receiver, 'Receive in memory (up to 64 MiB)');
|
||||
await click(receiver, 'Accept file');
|
||||
await wait(sender, () => window.__hellcon.element('[role=status]').textContent?.includes('confirmed the complete file'));
|
||||
await checkAccessibility(sender, 'Send after transfer');
|
||||
await checkAccessibility(receiver, 'Receive after transfer');
|
||||
@@ -378,6 +384,8 @@ try {
|
||||
return { length: bytes.length, valid: bytes.every(b => b === 123) };
|
||||
});
|
||||
assert.deepEqual(data, { length: 2 * 1024 * 1024 + 7, valid: true });
|
||||
assert.match(await evaluate(receiver, () => window.__hellcon.element('[role=status]').textContent), /Check Downloads/);
|
||||
await verifySavedFile(join(downloads, 'browser-test.bin'), 2 * 1024 * 1024 + 7);
|
||||
await wait(sender, () => window.__hellcon.element<HTMLTextAreaElement>('#connection-diagnostics').value.includes('pairs='));
|
||||
const diagnostics = await evaluate(sender, () => window.__hellcon.element<HTMLTextAreaElement>('#connection-diagnostics').value);
|
||||
assert.match(diagnostics, /local code: host=\d+/);
|
||||
@@ -385,7 +393,7 @@ try {
|
||||
assert.match(diagnostics, /requestsSent=/);
|
||||
assert.match(diagnostics, /transfer done/);
|
||||
assert.doesNotMatch(diagnostics, /browser-test\.bin|a=candidate:|a=ice-pwd:|a=fingerprint:|\.local\b/);
|
||||
console.log('PASS: real two-page WebRTC flow; full fingerprints; no metadata before both confirmations; exact file and receipt.');
|
||||
console.log('PASS: real two-page WebRTC flow; full fingerprints; no metadata before both confirmations; exact file and receipt; memory fallback saves to Downloads automatically.');
|
||||
console.log('PASS: invalid offers can be replaced; invalid answers can be corrected without losing the live offer.');
|
||||
const originalFingerprints = await evaluate(sender, () => [...document.querySelectorAll('.fp-row code')].map(e => e.textContent));
|
||||
for (const size of [0, 4097]) {
|
||||
@@ -395,7 +403,7 @@ try {
|
||||
assert.equal(await evaluate(receiver, () => window.__hellcon.element<HTMLAnchorElement>('a.download').href), previousDownload);
|
||||
assert.equal(await evaluate(sender, () => window.__hellcon.element('[role=status]').textContent), 'Waiting for the receiver to accept the file…');
|
||||
assert.deepEqual(await evaluate(sender, () => [...document.querySelectorAll('.fp-row code')].map(e => e.textContent)), originalFingerprints);
|
||||
await click(receiver, 'Receive in memory (up to 64 MiB)');
|
||||
await click(receiver, 'Accept file');
|
||||
await wait(sender, () => window.__hellcon.element('[role=status]').textContent?.includes('confirmed the complete file'));
|
||||
const next = await evaluate(receiver, async () => {
|
||||
const link = window.__hellcon.element<HTMLAnchorElement>('a.download');
|
||||
@@ -424,8 +432,8 @@ try {
|
||||
await wait(receiver, () => !!document.querySelector('.incoming'));
|
||||
await click(receiver, 'Decline file');
|
||||
await wait(receiver, () => document.querySelector('.incoming')?.textContent?.includes('queued.bin'));
|
||||
await click(sender, 'Receive in memory (up to 64 MiB)');
|
||||
await click(receiver, 'Receive in memory (up to 64 MiB)');
|
||||
await click(sender, 'Accept file');
|
||||
await click(receiver, 'Accept file');
|
||||
await wait(sender, () => document.querySelector<HTMLAnchorElement>('a.download')?.download === 'return.bin');
|
||||
await wait(receiver, () => document.querySelector<HTMLAnchorElement>('a.download')?.download === 'queued.bin');
|
||||
for (const [session, size] of [[sender, 8193], [receiver, 1024]] as const) {
|
||||
@@ -446,7 +454,7 @@ try {
|
||||
console.log('PASS: Reset restores the ready state on both sides.');
|
||||
await evaluate(receiver, simulateSlowDisk);
|
||||
await connect(sender, receiver, 2 * 1024 * 1024);
|
||||
await click(receiver, 'Choose destination & receive to disk');
|
||||
await click(receiver, 'Accept file');
|
||||
await wait(receiver, () => !!window.__hellcon.releaseWrite);
|
||||
await evaluate(sender, () => window.__hellcon.chooseFile(1024, 'pending-at-disconnect.bin'));
|
||||
assert.equal(await evaluate(sender, () => !!document.querySelector('ul[aria-label="Files waiting to send"]')), true);
|
||||
@@ -459,8 +467,9 @@ try {
|
||||
console.log('PASS: privacy-safe candidate/check diagnostics remain available after completion and failure.');
|
||||
console.log('PASS: Disconnect closes the connection and aborts the receiver’s pending disk write.');
|
||||
await click(sender, 'Reset'); await click(receiver, 'Reset');
|
||||
await evaluate(receiver, () => { window.showSaveFilePicker = undefined; });
|
||||
await connect(sender, receiver, 2048);
|
||||
await click(receiver, 'Receive in memory (up to 64 MiB)');
|
||||
await click(receiver, 'Accept file');
|
||||
await wait(sender, () => window.__hellcon.element('[role=status]').textContent?.includes('confirmed the complete file'));
|
||||
console.log('PASS: fresh code exchange after a failed transfer succeeds without reloading either page.');
|
||||
if (!turn) {
|
||||
@@ -490,7 +499,7 @@ try {
|
||||
await wait(session, () => !!document.querySelector('.device-settings code'));
|
||||
}
|
||||
await checkAccessibility(identitySender, 'remembered identity');
|
||||
await click(identityReceiver, 'Receive in memory (up to 64 MiB)');
|
||||
await click(identityReceiver, 'Accept file');
|
||||
await wait(identitySender, () => document.body.textContent?.includes('The receiver confirmed the complete file.'));
|
||||
await click(identitySender, 'Disconnect');
|
||||
await wait(identityReceiver, () => [...document.querySelectorAll('button')].some(button => button.textContent === 'Reset'));
|
||||
@@ -515,7 +524,7 @@ try {
|
||||
await input(identitySender, '#answer-input', answer); await click(identitySender, 'Connect');
|
||||
await wait(identityReceiver, () => !!document.querySelector('.incoming'));
|
||||
for (const session of [identitySender, identityReceiver]) assert.ok(await evaluate(session, () => document.body.textContent?.includes('Paired device authenticated')));
|
||||
await click(identityReceiver, 'Receive in memory (up to 64 MiB)');
|
||||
await click(identityReceiver, 'Accept file');
|
||||
await wait(identitySender, () => document.body.textContent?.includes('The receiver confirmed the complete file.'));
|
||||
const rememberedBytes = await evaluate(identityReceiver, async () => { const bytes = new Uint8Array(await (await fetch(window.__hellcon.element<HTMLAnchorElement>('a.download').href)).arrayBuffer()); return { length: bytes.length, valid: bytes.every(byte => byte === 123) }; });
|
||||
assert.deepEqual(rememberedBytes, { length: 4096, valid: true });
|
||||
@@ -542,7 +551,7 @@ try {
|
||||
await click(forgottenSide, 'Both fingerprints match — confirm');
|
||||
await wait(identityReceiver, () => !!document.querySelector('.incoming'));
|
||||
await wait(forgottenSide, () => !!document.querySelector('.device-settings code'));
|
||||
await click(identityReceiver, 'Receive in memory (up to 64 MiB)');
|
||||
await click(identityReceiver, 'Accept file');
|
||||
await wait(identitySender, () => document.body.textContent?.includes('The receiver confirmed the complete file.'));
|
||||
await click(identitySender, 'Disconnect');
|
||||
await wait(identityReceiver, () => !document.querySelector('.incoming'));
|
||||
@@ -569,7 +578,7 @@ try {
|
||||
await click(identityReceiver, 'Create device identity');
|
||||
await wait(identityReceiver, () => !!document.querySelector('.device-settings code'));
|
||||
await connect(identitySender, identityReceiver, 512, true);
|
||||
await click(identityReceiver, 'Receive in memory (up to 64 MiB)');
|
||||
await click(identityReceiver, 'Accept file');
|
||||
await wait(identitySender, () => document.body.textContent?.includes('The receiver confirmed the complete file.'));
|
||||
assert.ok(await evaluate(identitySender, () => document.body.textContent?.includes('This device was not remembered.')));
|
||||
assert.equal(await pairedKey(identitySender), senderPaired, 'Changed identity must not replace the paired device automatically');
|
||||
|
||||
@@ -4,7 +4,7 @@ import { crossBrowserDriver } from './cross-browser-driver.ts';
|
||||
import { isRecord } from '../src/lib/validation.ts';
|
||||
import { createServer } from 'node:http';
|
||||
import { spawn, type ChildProcess } from 'node:child_process';
|
||||
import { readFile, mkdtemp, rm } from 'node:fs/promises';
|
||||
import { readFile, mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';
|
||||
import { dirname, extname, join, resolve } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { tmpdir } from 'node:os';
|
||||
@@ -52,6 +52,10 @@ let timer: ReturnType<typeof setTimeout> | undefined;
|
||||
try{
|
||||
for(const name of ['brave','firefox']){
|
||||
const profile=await mkdtemp(join(tmpdir(),'hellcon-'+name+'-'));profiles.push(profile);
|
||||
// Received files are saved automatically; keep them in the throwaway profile instead of the user's Downloads.
|
||||
const downloads=join(profile,'downloads');await mkdir(downloads);
|
||||
if(name==='brave'){await mkdir(join(profile,'Default'));await writeFile(join(profile,'Default','Preferences'),JSON.stringify({download:{default_directory:downloads,prompt_for_download:false}}));}
|
||||
else await writeFile(join(profile,'user.js'),['user_pref("browser.download.folderList", 2);','user_pref("browser.download.dir", '+JSON.stringify(downloads)+');','user_pref("browser.download.useDownloadDir", true);','user_pref("browser.download.always_ask_before_handling_new_types", false);'].join('\n'));
|
||||
const role=(name==='brave')!==reversed?'sender':'receiver';
|
||||
const args=name==='brave'?['--headless','--no-sandbox','--disable-gpu','--no-first-run','--no-default-browser-check','--user-data-dir='+profile,origin+'/?role='+role]:['--headless','--no-remote','--profile',profile,origin+'/?role='+role];
|
||||
const child=spawn(process.env[name==='brave'?'BRAVE_PATH':'FIREFOX_PATH']||'/usr/bin/'+name,args,{stdio:['ignore','ignore','pipe']});children.push(child);
|
||||
|
||||
@@ -13,6 +13,8 @@ export async function crossBrowserDriver(provider: string) {
|
||||
const role = new URL(location.href).searchParams.get('role');
|
||||
if (role !== 'sender' && role !== 'receiver') throw new Error('Invalid role');
|
||||
const { click, input, wait, element } = window.__hellcon;
|
||||
// Use the memory fallback so the received bytes can be checked in-page.
|
||||
Object.defineProperty(navigator, 'serviceWorker', { value: undefined });
|
||||
const pause = (ms: number) => new Promise<void>(resolve => setTimeout(resolve, ms));
|
||||
const post = async (key: string, value: unknown) => fetch('/.test/' + key, {method:'POST', headers:{'Content-Type':'application/json'}, body:JSON.stringify(value)});
|
||||
const get = async <K extends keyof Exchange>(key: K): Promise<Exchange[K] | null> => (await fetch('/.test/' + key)).json();
|
||||
@@ -43,7 +45,7 @@ try {
|
||||
if(fps[0]!==other[1]||fps[1]!==other[0])throw new Error('Fingerprints do not match');
|
||||
click('Both fingerprints match — confirm');
|
||||
if(role==='receiver'){
|
||||
await stage('waiting for metadata');await wait(()=>document.querySelector('.incoming'));click('Receive in memory (up to 64 MiB)');
|
||||
await stage('waiting for metadata');await wait(()=>document.querySelector('.incoming'));click('Accept file');
|
||||
await stage('receiving');await wait(()=>document.querySelector('a.download'));
|
||||
await wait(()=>get('senderResult'));
|
||||
await pause(250);
|
||||
|
||||
Reference in new issue
Block a user