test_text-fragments-create-text-directive-no-reveal.html (2313B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>Text Fragment Creation Should Not Reveal Other Elements (Bug 1970909)</title> 5 <meta charset="UTF-8"> 6 <link rel="help" href="https://bugzil.la/1970909"> 7 <script src="/tests/SimpleTest/SimpleTest.js"></script> 8 </head> 9 <body> 10 <div id="hidden1" hidden="until-found">abc</div> 11 12 <details id="details1"> 13 <summary>First Section</summary> 14 <div id="content1">abc</div> 15 </details> 16 17 <details id="details2"> 18 <summary>Second Section</summary> 19 <div id="content2">abc def</div> 20 </details> 21 22 <script> 23 SimpleTest.waitForExplicitFinish(); 24 25 async function runTests() { 26 try { 27 // Creating a text fragment from a selection in details2 should not reveal 28 // other elements (closed <details> or hidden=until-found elements). 29 30 ok(hidden1.hidden === "until-found", 31 "Precondition: hidden1 should have hidden=until-found"); 32 details1.open = false; 33 details2.open = true; 34 35 ok(!details1.open, "Precondition: details1 should be closed"); 36 ok(details2.open, "Precondition: details2 should be open"); 37 38 const range = document.createRange(); 39 range.setStart(content2.firstChild, 0); 40 range.setEnd(content2.firstChild, 3); 41 is(range.toString(), "abc", "Precondition: Range should contain 'abc'"); 42 43 // Create text directive from the range 44 // This will internally search for "abc" to determine if context is needed 45 // and must not reveal other matches of the search string. 46 const textDirective = await SpecialPowers.wrap(document).fragmentDirective.createTextDirectiveForRanges([range]); 47 48 await new Promise(resolve => requestAnimationFrame(resolve)); 49 50 isnot(textDirective, null, "A text directive should be created for 'abc'"); 51 52 is(hidden1.hidden, "until-found", "hidden=until-found element should not be revealed"); 53 ok(!details1.open, "closed details element should not be opened"); 54 ok(details2.open, "already open element which contains the selection should remain open"); 55 is(textDirective, "text=abc,-def", `Text directive "${textDirective}" should be correct`); 56 57 } finally { 58 SimpleTest.finish(); 59 } 60 } 61 62 document.body.onload = runTests; 63 </script> 64 </body> 65 </html>