observe-svg-data-uri-background-image.html (1542B)
1 <!DOCTYPE HTML> 2 <meta charset=utf-8> 3 <title>Largest Contentful Paint: observe image.</title> 4 <style> 5 #target { 6 background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="50"><rect fill="lime" width="100" height="50"/></svg>'); 7 width: 100px; 8 height: 50px; 9 } 10 </style> 11 <body> 12 <script src="/resources/testharness.js"></script> 13 <script src="/resources/testharnessreport.js"></script> 14 <script src="resources/largest-contentful-paint-helpers.js"></script> 15 <script> 16 async_test(function (t) { 17 assert_implements(window.LargestContentfulPaint, "LargestContentfulPaint is not implemented"); 18 const beforeLoad = performance.now(); 19 const observer = new PerformanceObserver( 20 t.step_func_done(function(entryList) { 21 assert_equals(entryList.getEntries().length, 1); 22 const entry = entryList.getEntries()[0]; 23 let url = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg"'; 24 url += ' width="100" height="50"><rect fill="lime" width="100"'; 25 url += ' height="50"/></svg>'; 26 // green.svg is 100 by 50 27 const size = 100 * 50; 28 checkImage(entry, url, 'target', size, beforeLoad); 29 }) 30 ); 31 observer.observe({type: 'largest-contentful-paint', buffered: true}); 32 t.step_timeout(() => { 33 assert_unreached("The image should have triggered an LCP entry."); 34 t.done(); 35 }, 1000); 36 }, 'Data-URI background SVG image is observable.'); 37 </script> 38 39 <div id="target" width="100" height="50"></div> 40 </body>