content-visibility-039.html (2015B)
1 <!doctype HTML> 2 <html> 3 <meta charset="utf8"> 4 <title>Display Locking: measure forced SVG text</title> 5 <link rel="author" title="Vladimir Levin" href="mailto:vmpstr@chromium.org"> 6 <link rel="help" href="https://drafts.csswg.org/css-contain/#content-visibility"> 7 <meta name="assert" content="content-visibility hidden svg descendant has correct layout"> 8 9 <style> 10 #container { 11 width: 100px; 12 height: 100px; 13 background: lightgreen; 14 } 15 .hidden { 16 content-visibility: hidden; 17 } 18 </style> 19 20 <div id="parent"></div> 21 22 <script src="/resources/testharness.js"></script> 23 <script src="/resources/testharnessreport.js"></script> 24 25 <script> 26 async_test((t) => { 27 let length; 28 function measureForced() { 29 t.step(() => { 30 length = document.getElementById("text").getComputedTextLength(); 31 assert_not_equals(length, 0, "forced"); 32 33 }); 34 } 35 36 function measureWhenVisible() { 37 t.step(() => { 38 const visible_length = document.getElementById("text").getComputedTextLength(); 39 assert_not_equals(visible_length, 0, "when visible"); 40 assert_equals(visible_length, length, "when visible"); 41 }); 42 } 43 44 function construct(container) { 45 container.innerHTML = ` 46 <svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"> 47 <style> 48 .t { font: 10px sans-serif; } 49 </style> 50 <text id="text" x="10" y="10" class="t">This is text</text> 51 </svg> 52 `; 53 } 54 55 async function runTest() { 56 const container = document.createElement("div"); 57 container.id = "container"; 58 59 document.getElementById("parent").appendChild(container); 60 container.classList.add("hidden"); 61 requestAnimationFrame(() => { 62 construct(container); 63 measureForced(); 64 65 container.classList.remove("hidden"); 66 requestAnimationFrame(() => { 67 measureWhenVisible(); 68 t.done(); 69 }); 70 }); 71 } 72 73 window.onload = function() { 74 requestAnimationFrame(() => requestAnimationFrame(runTest)); 75 }; 76 }, "Measure Forced SVG Text"); 77 </script> 78 79 </html>