summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/paint-timing/fcp-only/fcp-document-opacity-image.html
blob: e407f687086b9c8d9fecf96d6234e57c66d6183c (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
<!DOCTYPE html>
<html class="hide">
<head>
<title>Performance Paint Timing Test: Image FCP due to the documentElement's opacity</title>
<style>
    html {
      will-change: opacity;
    }
    .hide {
        opacity: 0;
    }
</style>
</head>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../resources/utils.js"></script>
<div id="main"></div>
<script>
// Load the image, add it to the DOM and make sure it's decoded.
const load_image = () => {
  const img = document.createElement("img");
  img.src = "../resources/circles.png";
  document.body.appendChild(img);
  return img.decode();
};

const change_opacity = () => {
  document.documentElement.className = "";
}

promise_test(async t => {
  assert_implements(window.PerformancePaintTiming, "Paint Timing isn't supported.");
  await load_image();
  await assertNoFirstContentfulPaint(t);
  change_opacity();
  await waitForAnimationFrames(3);
  const fcp_entries = performance.getEntriesByName('first-contentful-paint');
  assert_equals(fcp_entries.length, 1, "Got an FCP entry");
  const lcp_entries = await new Promise(resolve => {new PerformanceObserver((list) => resolve(list.getEntries())).observe({type: 'largest-contentful-paint', buffered: true})});
  assert_equals(lcp_entries.length, 1, "Got an LCP entry");
  // TODO: Rewrite this assertion after the FCP and LCP precision alignment CL is landed. Currently FCP start time has a higher precision than that of LCP. That means, even if the two are intrinsically the same, FCP.startTime will be larger as it has more fractional digits.
  isLess = fcp_entries[0].startTime < lcp_entries[0].startTime;
  isEqualToMicrosecond = Math.abs(fcp_entries[0].startTime - lcp_entries[0].startTime) < 0.001;
  assert_true(isLess || isEqualToMicrosecond, "FCP should be smaller than FCP.");
}, "Test that FCP after opacity change is not a larger value than LCP");
</script>
</body>
</html>