tickets
All repositories: gitoria
8.1 KB
// tests/md-paste-files.mjs — tickets#49: a REAL Ctrl+V of a clipboard that holds text AND a picture (a spreadsheet, an office app) pastes the// text, in every editor, files "on" or "off"; a picture alone still goes to the files where files are "on". A real headless Chrome, a real click// into the visual editor, the clipboard filled through the browser's Clipboard API, then a real Ctrl+V key (rawKeyDown with the paste command).// node tests/md-paste-files.mjs <base-url> <path> <editor-article-selector> <value-field-selector> [pre-click-selector] [sid-cookie] [images: on|off]// exit 0 = all passed, 1 = a check failed. Chrome debug port: PASTE_CHROME_PORT (default 8745).import { spawn } from 'node:child_process';import { rmSync, mkdtempSync } from 'node:fs';import { tmpdir } from 'node:os';import { join } from 'node:path';const [BASE, PATH, SEL, VAL, PRE = '', SID = '', FILES = 'off'] = process.argv.slice(2);const DP = Number(process.env.PASTE_CHROME_PORT || 8745), J = JSON.stringify, sleep = ms => new Promise(r => setTimeout(r, ms));const prof = mkdtempSync(join(process.env.PASTE_PROFILE_DIR || tmpdir(), 'pf-'));const ch = spawn('/opt/google/chrome/chrome', ['--headless=new', '--no-sandbox', '--remote-debugging-port=' + DP, '--user-data-dir=' + prof, 'about:blank'], { stdio: 'ignore' });let failed = 0; const check = (n, ok, d) => { console.log((ok ? 'ok ' : 'FAIL ') + n + (ok ? '' : ' ' + d)); if (!ok) failed++; };try {let v; for (let i = 0; i < 60; i++) { try { v = await (await fetch(`http://127.0.0.1:${DP}/json/version`)).json(); break; } catch { await sleep(200); } }const bws = new WebSocket(v.webSocketDebuggerUrl); await new Promise(r => bws.onopen = r);let bid = 0; const bp = new Map(); bws.onmessage = m => { const d = JSON.parse(m.data); if (d.id && bp.has(d.id)) { bp.get(d.id)(d); bp.delete(d.id); } };const bsend = (method, params = {}) => new Promise((res, rej) => { const i = ++bid; bp.set(i, d => d.error ? rej(new Error(J(d.error))) : res(d.result)); bws.send(J({ id: i, method, params })); });await bsend('Browser.grantPermissions', { permissions: ['clipboardReadWrite', 'clipboardSanitizedWrite'], origin: BASE });for (const W of [1280, 390]) {const { targetId } = await bsend('Target.createTarget', { url: 'about:blank' });const ws = new WebSocket(`ws://127.0.0.1:${DP}/devtools/page/${targetId}`); await new Promise(r => ws.onopen = r);let id = 0; const pend = new Map();ws.onmessage = m => { const d = JSON.parse(m.data); if (d.id && pend.has(d.id)) { pend.get(d.id)(d); pend.delete(d.id); } };const send = (method, params = {}) => new Promise((res, rej) => { const i = ++id; pend.set(i, d => d.error ? rej(new Error(method + J(d.error))) : res(d.result)); ws.send(J({ id: i, method, params })); });const ev = async e => { const r = await send('Runtime.evaluate', { expression: e, returnByValue: true, awaitPromise: true, userGesture: true }); if (r.exceptionDetails) throw new Error(J(r.exceptionDetails).slice(0, 300)); return r.result.value; };const press = async (key, code, vk, mod, commands) => { await send('Input.dispatchKeyEvent', { type: 'rawKeyDown', modifiers: mod, key, code, windowsVirtualKeyCode: vk, commands }); await send('Input.dispatchKeyEvent', { type: 'keyUp', modifiers: mod, key, code, windowsVirtualKeyCode: vk }); };const click = async sel => { const r = await ev(`(()=>{const e=document.querySelector(${J(sel)}); e.scrollIntoView({block:'center'}); const r=e.getBoundingClientRect(); return {x:r.x+r.width/2,y:r.y+Math.min(r.height/2,20)}})()`); await sleep(250); for (const [type, x] of [['mouseMoved', {}], ['mousePressed', { button: 'left', clickCount: 1 }], ['mouseReleased', { button: 'left', clickCount: 1 }]]) await send('Input.dispatchMouseEvent', { type, x: r.x, y: r.y, ...x }); await sleep(600); };try {await send('Page.enable'); await send('Runtime.enable'); await send('Network.enable');await send('Emulation.setDeviceMetricsOverride', { width: W, height: W < 600 ? 844 : 900, deviceScaleFactor: 1, mobile: W < 600 });if (SID) await send('Network.setCookie', { name: 'hlsid', value: SID, url: BASE, httpOnly: true });await send('Page.bringToFront'); await send('Page.navigate', { url: BASE + PATH });for (let i = 0; i < 120; i++) { try { if (await ev(`document.readyState==='complete' && !!document.querySelector(${J(SEL.split('|')[0])})`)) break; } catch {} await sleep(300); }await sleep(1500);for (const p of PRE ? PRE.split('|') : []) await click(p);await click(SEL);const clip = async (o) => ev(`(async()=>{ const items={}; const o=${J(o)}; if (o.p!==undefined) items['text/plain']=new Blob([o.p],{type:'text/plain'}); if (o.h!==undefined) items['text/html']=new Blob([o.h],{type:'text/html'}); if (o.img) { const cv=document.createElement('canvas'); cv.width=cv.height=8; cv.getContext('2d').fillRect(0,0,8,8); items['image/png']=await new Promise(r=>cv.toBlob(r)); } await navigator.clipboard.write([new ClipboardItem(items)]); return 1; })()`);const value = () => ev(`document.querySelector(${J(VAL)}).value`);const empty = async () => { await click(SEL); await press('a', 'KeyA', 65, 2, ['selectAll']); await press('Delete', 'Delete', 46, 0, ['deleteBackward']); await sleep(300); };const L = `[${W}] `;await empty();await clip({ p: 'PASTE SPREADSHEET TEXT', img: 1 }); await press('v', 'KeyV', 86, 2, ['paste']); await sleep(1200);let val = await value();check(L + 'text + picture on the clipboard: a real Ctrl+V pastes the text and the field has it', val.includes('PASTE SPREADSHEET TEXT'), J(val));check(L + 'text + picture: the text is in the visible editor', (await ev(`document.querySelector(${J(SEL)}).innerText`)).includes('PASTE SPREADSHEET TEXT'), '');check(L + 'text + picture: no picture was taken as a file', !val.includes('!['), J(val));await empty();await clip({ p: 'plain only', h: '<p>plain only</p>' }); await press('v', 'KeyV', 86, 2, ['paste']); await sleep(900);check(L + 'text + html still pastes', (await value()).includes('plain only'), J(await value()));// a file manager copy: text that is only the names / file:// paths of the files, plus the files: the files are about (as before)for (const nm of ['image.png', 'file:///home/someone/Pictures/image.png\n']) {await empty();await clip({ p: nm, img: 1 }); await press('v', 'KeyV', 86, 2, ['paste']);if (FILES === 'on') {let got = false; for (let i = 0; i < 40 && !got; i++) { await sleep(300); got = (await value()).includes('![') || (await ev(`document.querySelectorAll('li.picked, ul.files li').length`)) > 0; }check(L + 'file manager copy (text = ' + J(nm) + ' + the file): the file is attached', got, J(await value()));} else { await sleep(1200); check(L + 'file manager copy, files "off": no name text is inserted', (await value()) === '', J(await value())); }}await empty();await clip({ p: 'image.png and more words', img: 1 }); await press('v', 'KeyV', 86, 2, ['paste']); await sleep(1200);check(L + 'text that is more than the file names + a picture: the text is pasted', (await value()).includes('and more words'), J(await value()));if (FILES === 'on') {await empty();await clip({ img: 1 }); await press('v', 'KeyV', 86, 2, ['paste']);let got = false; for (let i = 0; i < 40 && !got; i++) { await sleep(300); got = (await value()).includes('![') || (await ev(`document.querySelectorAll('li.picked, ul.files li').length`)) > 0; }check(L + 'a picture alone still goes to the files (files "on")', got, J(await value()));} else {await empty();await clip({ img: 1 }); await press('v', 'KeyV', 86, 2, ['paste']); await sleep(1200);check(L + 'a picture alone, files "off": nothing is inserted', (await value()) === '', J(await value()));}} finally { await bsend('Target.closeTarget', { targetId }).catch(() => {}); }}} catch (e) { console.log('FAIL error ' + e.message); failed++; }finally { try { process.kill(ch.pid); } catch {} await sleep(500); rmSync(prof, { recursive: true, force: true }); }console.log(failed ? `${failed} failed` : '0 failed'); process.exit(failed ? 1 : 0);
Branches
Latest commits
- fd33ee21Sync reviewed components from 8176eb1mre
- 93348453Re-vendor tickets to Hybriel set day35mre
- a4123831tickets#42: the /connect and /login/callback error pages are app pages: the function routes redirect to /connect/failed/<code> and /login/failed/<code> (components/problem.hl, sentences in lib/problems.hl), htmlPage and its hand-written stylesheet are gone; gate tests/error-pages.mjsmre
- cefc7b4atickets: a startup error prints its message before exit 1 (hybriel#247)mre
- 99bd6570tickets: lib/migrate.hl writes no table of another topic any more: projects.hl rewriteSlug / addProjectNamed / hasMembers, tickets.hl moveToProject / ticketRecords / ticketRecordsOf, events.hl renameStates / eventRecords / eventRecordsOf; the migration calls them (tickets#47)mre
- b57161e3tickets: the markup names its own rules (Style.pMessage, Style.olTickets, ...) instead of hand-written class strings that copy a stylesheet rule; the shared bodies sit in lib/looks.hl (tickets#38)mre
- f767b24dtickets: 111 needless let became plain declarations (3 in ticket.hl, ticket_list.hl, comments.hl and 108 never-reassigned, not captured loop-body ones); the 212 really reassigned lets stay (tickets#44)mre
- 16c0d3b5tickets: the modal window is phone first: the full-screen sheet is the base rule, the centred window sits in the min-width 60rem block (tickets#39)mre
- 090ee809tickets: every component's styles in its own nested Style {} block; styles.hl keeps only the theme inherit, the accent and the site-wide rules (tickets#36)mre
- d395763ftickets: ident-access gate ports 8769/8768 (8797 is taken on loreana)mre
- afb9a403tickets: an ident access key (Authorization: Bearer idt_…) works in the API (ident#27 app side): lib/ident-access.hl copied from components, read keys GET only, ident down 503; gate tests/ident-access-tickets.mjsmre
- 48c1ba79tickets: md-paste-files gate with the file manager casesmre
- f04afc43tickets: MdEditor from components 59704ce (a file manager copy still attaches, pipe rows, tickets#49)mre
- 06599fa0tickets: MdEditor from components b0f1ec2 (a clipboard with text always pastes the text, tickets#49); real Ctrl+V gatemre
- 2e1b116ftickets: re-vendor Hybriel master acaceaf3 (framework ec8d6c1d): plugins/web patch queue while a page is built, anonymous session cookies refresh; gate waits for the comment editors to draw (W174) and clicks the form editor when it stands still; security gate: main's code runs on its own binary, lazy-session cookie checksmre
- 361bc0fetickets: re-vendor Hybriel 7a684920 (WIP, not deployed); on Error exits 1 at startup; migrate passes its log by reference; gate checks follow lazy sessions and the 413 refusalmre
- 8a69999cident#28: /login/callback never signs out the session it finds; a valid code puts the user on the same sessionmre
- 337e9b21tickets#37: a comment's files are open to everyone who can read the commentmre
- 1800600ftickets: write the standby service out in full so the boot gate can read the main servicemre
- 8179d287tickets: standby service on its port plus 10 and a deploy that hands over through it without a gapmre