Skip to content

Commit

Permalink
[PaintTiming] Add fcp-only buffered flag test
Browse files Browse the repository at this point in the history
Relevant GitHub issue:
GoogleChrome/web-vitals#139

Change-Id: I2884dd4c3432920011e984f6a08ebaf6a2176b67
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2867865
Reviewed-by: Yoav Weiss <yoavweiss@chromium.org>
Commit-Queue: Nicolás Peña Moreno <npm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#878531}
  • Loading branch information
npm1 authored and chromium-wpt-export-bot committed May 3, 2021
1 parent ef8bcba commit c2f801a
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions paint-timing/fcp-only/buffered-flag.window.js
@@ -0,0 +1,24 @@
setup({"hide_test_state": true});
async_test(t => {
assert_implements(window.PerformancePaintTiming, "Paint Timing isn't supported.");
// First observer creates a second one in the callback to ensure the entry has been dispatched
// by the time the second observer begins observing.
new PerformanceObserver(entries => {
const entry_seen = entries.getEntriesByName('first-contentful-paint').length > 0;
// Abort if we have not yet received the entry.
if (!entry_seen)
return;

// Second observer requires 'buffered: true' to see the entry.
new PerformanceObserver(t.step_func_done(list => {
const fcp = list.getEntriesByName('first-contentful-paint');
assert_equals(fcp.length, 1, 'Should have an fcp entry');
const entry = fcp[0];
assert_equals(entry.entryType, 'paint');
})).observe({'type': 'paint', buffered: true});
}).observe({'entryTypes': ['paint']});
// Trigger the first contentful paint entry.
const img = document.createElement("img");
img.src = "resources/circles.png";
document.body.appendChild(img);
}, "PerformanceObserver with buffered flag sees previous FCP entry.");

0 comments on commit c2f801a

Please sign in to comment.