tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

web-font-styled-text-resize-swap-subnode.html (2275B)


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