web-font-styled-text-resize-swap.html (2209B)
1 <!doctype html> 2 <script src="/resources/testharness.js"></script> 3 <script src="/resources/testharnessreport.js"></script> 4 <style> 5 @font-face { 6 font-family: "ADTestFaceSwap"; 7 src: url("/fonts/AD.woff?pipe=trickle(d0.5)"); 8 font-display: swap; 9 } 10 11 .test { 12 font-family: "ADTestFaceSwap"; 13 } 14 </style> 15 <!-- 16 Web-font styled text that gets resized during swap period should make a 17 LCP emission if the new size is larger than the existing LCP element size. 18 --> 19 <div class="test">LCP: Web Font Styled Text Resize</div> 20 <script> 21 promise_test(async (t) => { 22 await document.fonts.ready; 23 24 // Verify web font is downloaded. 25 assert_own_property(window, "PerformanceResourceTiming", "ResourceTiming not supported"); 26 let url = "/fonts/AD.woff?pipe=trickle(d0.5)"; 27 var absoluteURL = new URL(url, location.href).href; 28 assert_equals( 29 performance.getEntriesByName(absoluteURL).length, 30 1, 31 "Web font should be downloaded", 32 ); 33 34 // Verify web font is available. 35 assert_true(document.fonts.check("16px ADTestFaceSwap"), "Font should be the web font added"); 36 37 let lcpEntries = []; 38 await Promise.race([ 39 new Promise((resolve, reject) => { 40 t.step_timeout(() => { 41 resolve(lcpEntries); 42 }, 3000); 43 }), 44 new Promise((resolve, reject) => { 45 new PerformanceObserver((list, observer) => { 46 lcpEntries.push(...list.getEntries()); 47 if (lcpEntries.length >= 2) { 48 resolve(); 49 observer.disconnect(); 50 } 51 }).observe({ type: "largest-contentful-paint", buffered: true }); 52 }), 53 ]); 54 55 // Verify there are 2 LCP entries emitted. 56 assert_equals( 57 lcpEntries.length, 58 2, 59 "There should be 2 LCP entries. The 1st one corresponds to the system font and the 2nd the web font.", 60 ); 61 62 // Verify the size of 2nd LCP entry is larger than that of the 1st one. 63 assert_greater_than( 64 lcpEntries[1].size, 65 lcpEntries[0].size, 66 "The size of 2ndLCP entry should be larger than that of the 1st one.", 67 ); 68 }, "LCP should be updated if the web font styled text resizes to be larger during the swap period"); 69 </script>