summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/soft-navigation-heuristics/visited-link.tentative.html
blob: 0bb149f00e91fc2f0033a6f763543967ef542ab2 (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>
<html>
<head>
<meta charset="utf-8">
<title>Soft navigation visited link paint tests.</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>
</head>
<body>
  <main id=main>
  <a id=link>Click me!</a>
  <a id=visited>link that is really long so it is the LCP</a>
  </main>
  <script>
    const visited = document.getElementById("visited");
    const fake_url = "./fake_" + Math.random();
    visited.href = fake_url;
    const visitFakeURLAndAddInvisibleText = () => {
      requestAnimationFrame(() => requestAnimationFrame(() => {
        history.replaceState({}, "", fake_url);
      }));
      const main = document.getElementById("main");
      const div = document.createElement("div");
      const text = document.createTextNode("Lorem Ipsum");
      div.appendChild(text);
      main.appendChild(div);
    }
    const link = document.getElementById("link");
    testSoftNavigation({
      addContent: async () => {
        await visitFakeURLAndAddInvisibleText();
      },
      link: link,
      validate: async () => {
        await new Promise(r => step_timeout(r, 100));
        const postVisitedLcp = await getLcpEntries();
        assert_not_equals(postVisitedLcp[postVisitedLcp.length - 1].id,
                          "visited",
                          "Soft Nav LCP ID should not be visited");
      },
      test: "Test that a visited link doesn't trigger LCP after a soft " +
            "navigation is detected"});
  </script>
</body>
</html>