gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitf04afc43f04afc43tickets: MdEditor from components 59704ce (a file manager copy still attaches, pipe rows, tickets#49)mref04afc43/tests/md-paste-files.mjs

7.0 KB

  1. // 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
  2. // 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
  3. // into the visual editor, the clipboard filled through the browser's Clipboard API, then a real Ctrl+V key (rawKeyDown with the paste command).
  4. // node tests/md-paste-files.mjs <base-url> <path> <editor-article-selector> <value-field-selector> [pre-click-selector] [sid-cookie] [images: on|off]
  5. // exit 0 = all passed, 1 = a check failed. Chrome debug port: PASTE_CHROME_PORT (default 8745).
  6. import { spawn } from 'node:child_process';
  7. import { rmSync, mkdtempSync } from 'node:fs';
  8. import { tmpdir } from 'node:os';
  9. import { join } from 'node:path';
  10. const [BASE, PATH, SEL, VAL, PRE = '', SID = '', FILES = 'off'] = process.argv.slice(2);
  11. const DP = Number(process.env.PASTE_CHROME_PORT || 8745), J = JSON.stringify, sleep = ms => new Promise(r => setTimeout(r, ms));
  12. const prof = mkdtempSync(join(process.env.PASTE_PROFILE_DIR || tmpdir(), 'pf-'));
  13. const ch = spawn('/opt/google/chrome/chrome', ['--headless=new', '--no-sandbox', '--remote-debugging-port=' + DP, '--user-data-dir=' + prof, 'about:blank'], { stdio: 'ignore' });
  14. let failed = 0; const check = (n, ok, d) => { console.log((ok ? 'ok ' : 'FAIL ') + n + (ok ? '' : ' ' + d)); if (!ok) failed++; };
  15. try {
  16. 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); } }
  17. const bws = new WebSocket(v.webSocketDebuggerUrl); await new Promise(r => bws.onopen = r);
  18. 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); } };
  19. 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 })); });
  20. await bsend('Browser.grantPermissions', { permissions: ['clipboardReadWrite', 'clipboardSanitizedWrite'], origin: BASE });
  21. for (const W of [1280, 390]) {
  22. const { targetId } = await bsend('Target.createTarget', { url: 'about:blank' });
  23. const ws = new WebSocket(`ws://127.0.0.1:${DP}/devtools/page/${targetId}`); await new Promise(r => ws.onopen = r);
  24. let id = 0; const pend = new Map();
  25. 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); } };
  26. 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 })); });
  27. 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; };
  28. 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 }); };
  29. 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); };
  30. try {
  31. await send('Page.enable'); await send('Runtime.enable'); await send('Network.enable');
  32. await send('Emulation.setDeviceMetricsOverride', { width: W, height: W < 600 ? 844 : 900, deviceScaleFactor: 1, mobile: W < 600 });
  33. if (SID) await send('Network.setCookie', { name: 'hlsid', value: SID, url: BASE, httpOnly: true });
  34. await send('Page.bringToFront'); await send('Page.navigate', { url: BASE + PATH });
  35. 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); }
  36. await sleep(1500);
  37. for (const p of PRE ? PRE.split('|') : []) await click(p);
  38. await click(SEL);
  39. 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; })()`);
  40. const value = () => ev(`document.querySelector(${J(VAL)}).value`);
  41. const empty = async () => { await click(SEL); await press('a', 'KeyA', 65, 2, ['selectAll']); await press('Delete', 'Delete', 46, 0, ['deleteBackward']); await sleep(300); };
  42. const L = `[${W}] `;
  43. await empty();
  44. await clip({ p: 'PASTE SPREADSHEET TEXT', img: 1 }); await press('v', 'KeyV', 86, 2, ['paste']); await sleep(1200);
  45. let val = await value();
  46. 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));
  47. check(L + 'text + picture: the text is in the visible editor', (await ev(`document.querySelector(${J(SEL)}).innerText`)).includes('PASTE SPREADSHEET TEXT'), '');
  48. check(L + 'text + picture: no picture was taken as a file', !val.includes('!['), J(val));
  49. await empty();
  50. await clip({ p: 'plain only', h: '<p>plain only</p>' }); await press('v', 'KeyV', 86, 2, ['paste']); await sleep(900);
  51. check(L + 'text + html still pastes', (await value()).includes('plain only'), J(await value()));
  52. if (FILES === 'on') {
  53. await empty();
  54. await clip({ img: 1 }); await press('v', 'KeyV', 86, 2, ['paste']);
  55. 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; }
  56. check(L + 'a picture alone still goes to the files (files "on")', got, J(await value()));
  57. } else {
  58. await empty();
  59. await clip({ img: 1 }); await press('v', 'KeyV', 86, 2, ['paste']); await sleep(1200);
  60. check(L + 'a picture alone, files "off": nothing is inserted', (await value()) === '', J(await value()));
  61. }
  62. } finally { await bsend('Target.closeTarget', { targetId }).catch(() => {}); }
  63. }
  64. } catch (e) { console.log('FAIL error ' + e.message); failed++; }
  65. finally { try { process.kill(ch.pid); } catch {} await sleep(500); rmSync(prof, { recursive: true, force: true }); }
  66. console.log(failed ? `${failed} failed` : '0 failed'); process.exit(failed ? 1 : 0);

Branches

Latest commits

  • 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
  • 0398145ctickets: the table grid rule is marked functional for check-thememre
  • 40fddc20tickets takes components e54f83a: tables get thin grey lines from the theme, desktop toolbar stays one row with the Table button, F4 check counts 11 buttonsmre
  • c1b77d61tickets#35: text typed before the editor is built is taken in once by the build (the input handler no longer writes it to the field first, which doubled the first letters); the gate failure shows the surfacemre
  • 32bf1873tickets#35: the gate types right after the load with the CPU slowed, no waitingmre
  • 64ea9ca2tickets#35: text typed into the reply editor before the page has finished starting is kept; the gate types right after loadmre
  • ccd3a327tickets: the security gate expects frame-src to be exactly the ident address (the sign-in frame), still no wildcard or selfmre
  • 4348dbabident#31: the selector's sign-in returns to the page the user started on (return attribute = the login callback with next), gate checkmre
  • 66ef3005Merge branch 'iw-ident-widget'mre
  • bc0ad663tickets: a gap between your name and Log out in the phone header (they touched); gate checks itmre
  • 2f818d46UX2: report, LOG line, e2e fixes, gate pause after loadmre
  • af3ef7c4gate: the legacy state line says progressmre
  • 62480a00tickets#33: a state change with a note is a comment card in the feed (same framework rendering, can be liked, edited, deleted), its state line stands alone; gate checks for a new comment with and without a state change, at once and after a reloadmre