summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/largest-contentful-paint/transparent-text.html
blob: 9eb978ab5cd8316cc1ae4f116a96a2271a2e9c96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<!--
  Transparent text should not be eligible for LCP.
-->
<style>
  .large-transparent {
    font-size: 2000px;
    position: fixed;
    top: 0;
    left: 0;
    padding: 0;
    margin: 0;
    pointer-events: none;
    color: transparent;
    z-index: -999;
  }
</style>

<body>
  <img src='/images/lcp-133x106.png' id='lcp' />
  <p id="fake_lcp" class='large-transparent'>fake LCP</p>

  <script>
    const LcpEntryListPromise = (t) => {
      return new Promise(resolve => {
        new PerformanceObserver((entryList, observer) => {
          if (entryList.getEntries().length > 0) {
            resolve(entryList.getEntries());

            observer.disconnect();
          }
        }).observe({ type: 'largest-contentful-paint', buffered: true });
      });
    }

    promise_test(async t => {
      assert_implements(window.LargestContentfulPaint, "LargestContentfulPaint is not implemented");

      lcpEntries = await LcpEntryListPromise();

      assert_equals(lcpEntries.length, 1, "There should only be 1 entry.");

      assert_true(lcpEntries[0].url.includes('lcp-133x106.png'), "The LCP entry should be the image.");
    }, "Transparent text should not be LCP.")
  </script>
</body>