Skip to content

Truly independent web browser

1.6 KB
Raw Blame
<!DOCTYPE html>
<head>
<title>Performance Paint Timing: Check that paintTime/presentationTime are available</title>
</head>
<body>
<script src="../resources/utils.js"></script>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script>
  setup({"hide_test_state": true});
  promise_test(async t => {
    assert_implements(window.PerformancePaintTiming, "Paint Timing isn't supported.");
    assert_implements("paintTime" in window.PerformancePaintTiming.prototype, "Paint Timing doesn't expose `paintTime`");
    await new Promise(r => window.addEventListener('load', r));
    await assertNoFirstContentfulPaint(t);
    const img = document.createElement('img');
    img.src = '../resources/circles.png';
    document.body.append(img);
    const reference_time = performance.now();
    const performance_entry_promise = new Promise(resolve => {
        new PerformanceObserver(entries => {
            const [entry] = entries.getEntriesByName("first-contentful-paint");
            if (entry)
                resolve(entry);
        }).observe({type: "paint"});
    });
    const entry = await performance_entry_promise;
    assert_greater_than(entry.paintTime, reference_time);
    if ("presentationTime" in entry && entry.presentationTime !== null) {
      assert_greater_than(entry.presentationTime, entry.paintTime);
      assert_equals(entry.presentationTime, entry.startTime);
    } else {
      assert_equals(entry.paintTime, entry.startTime);
    }
}, "Paint timing entries should expose paintTime and presentationTime");
</script>
</body>
</html>