فینورا پرو - سامانه جامع حسابداری و صدور فاکتور

test(q01): exercise desktop focus restoration and reject confirmation HTML injection in native WebView2

davoodmehraban89 committed Oct 30, 2026 at 23:57 UTC 8c91c8a33768b50b67dc5b45128d3348490660ac
1 file changed +28 -1
tests/windows-vm-ui-interaction-audit-browser.js
+28 -1
@@ -183,6 +183,10 @@
183 // Cross-app dialog behavior: nested modal focus, Escape and focus return.
184 const modalTrigger=hamburger;
185 modalTrigger.focus();
186 + if (getComputedStyle(modalTrigger).display === 'none' ||
187 + document.activeElement !== modalTrigger) {
188 + throw Error('Desktop sidebar toggle cannot receive keyboard focus before opening a dialog');
189 + }
190 let unexpectedConfirm=false;
191 FINORA.Modal.open({title:'Q01 Synthetic outer dialog',
192 body:'<input id="q01ModalField" value="synthetic" />',
@@ -248,7 +252,14 @@
252 document.dispatchEvent(new KeyboardEvent('keydown',{key:'Escape',bubbles:true,cancelable:true}));
253 await wait(15);
254 if(document.querySelector('.modal-backdrop') || document.activeElement!==modalTrigger ||
251 - unexpectedConfirm) throw Error('Escape did not restore focus to original control');
255 + unexpectedConfirm) {
256 + const focused=document.activeElement;
257 + throw Error('Escape did not restore focus to original control: ' + JSON.stringify({
258 + remainingDialogs:document.querySelectorAll('.modal-backdrop').length,
259 + focusedTag:focused?.tagName,focusedId:focused?.id,
260 + expectedId:modalTrigger.id,unexpectedConfirm
261 + }));
262 + }
263 // Open a fresh synthetic confirmation: a user clicking Cancel must NOT
264 // execute the callback. Deliberate Confirm should execute exactly once.
265 let syntheticConfirmed=0;
@@ -276,7 +287,23 @@
287 if(syntheticConfirmed!==1 || FINORA.Modal.stack.length){
288 throw Error('synthetic Confirm callback not exactly once or dialog not dismissed');
289 }
290 + // A confirmation message can contain user-provided contact names. It must
291 + // never be interpreted as HTML or create a DOM node with event handlers.
292 + const hostileMessage='<img src=x onerror="window.Q01_INJECTED=true">';
293 + FINORA.Modal.confirm({title:'Q01 text-only confirmation',
294 + message:hostileMessage,onConfirm:()=>{syntheticConfirmed++;}});
295 + await wait(25);
296 + const safeConfirm=FINORA.Modal.stack[FINORA.Modal.stack.length-1]?.card;
297 + if (!safeConfirm || safeConfirm.querySelector('[data-confirm-message]')?.textContent!==hostileMessage ||
298 + safeConfirm.querySelector('img') || window.Q01_INJECTED) {
299 + throw Error('Confirmation message was interpreted as executable HTML');
300 + }
301 + safeConfirm.querySelector('[data-action="cancel"]').click();
302 + if (syntheticConfirmed!==1 || FINORA.Modal.stack.length) {
303 + throw Error('Text-only confirmation Cancel executed a callback or leaked a dialog');
304 + }
305 const modalKeyboard={roleAndLabel:true,nestedDialogIsolation:true,
306 + confirmationTextEscaped:true,
307 escapeClosesWithoutConfirm:true,focusReturnsToTrigger:true,
308 enterOnFocusedCancelDoesNotSave:true,enterOnInputDoesNotSubmit:true,
309 tabAndShiftTabStayInsideTopDialog:true,