summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/soft-navigation-heuristics/softnav-before-lcp-paint.tentative.html
blob: d5dc4b74fb33b5bf0499ddae12a98d3789d48841 (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
49
50
51
52
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Detect simple soft navigation.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="resources/soft-navigation-helper.js"></script>
<link rel="stylesheet" type="text/css" href="/fonts/ahem.css" />
</head>
<body>
  <main id=main>
    <div>
      <a id=link><img src="/images/lcp-256x256.png"></a>
    </div>
  </main>
  <script>
    const link = document.getElementById("link");
    testSoftNavigation({
      addContent: async () => {
        // Add an LCP element, large enough to trigger the Soft Navigation
        // heuristics.
        const p = addTextParagraphToMain("Lorem Ipsum", /*element_timing=*/"lcp");
        p.id = "first_lcp";
        // Once the first element is fully painted.
        const observer = new PerformanceObserver(list => {
          // Add a larger element to be the new LCP.
          window.lcp_observer_promise = new Promise(resolve => {
            (new PerformanceObserver(resolve)).observe({type: "element"});
          });
          const p2 = addTextParagraphToMain("LOREM IPSUMER", "real_lcp");
          p2.id = "real_lcp";
          observer.disconnect();
        });
        observer.observe({type: "element", buffered: true});
      },
      link: link,
      validate: async () => {
        await window.lcp_observer_promise;
        const lcps = await getLcpEntries();
        assert_greater_than_equal(lcps.length, 3, "Got at least 3 LCP entries");
        assert_equals(lcps[lcps.length - 2].id, "first_lcp", "Got the first LCP");
        assert_equals(lcps[lcps.length - 1].id, "real_lcp", "Got the real LCP");
      },
      test: "Test that an image LCP followed by 2 smaller soft navigation LCPs"
        + " properly queues both LCP entries, even when the soft navigation"
        + " is detected in between them."});
  </script>
</body>
</html>