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
  • Loading branch information
npm1 authored and chromium-wpt-export-bot committed May 3, 2021
1 parent 507ff1a commit 2a3db89
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions paint-timing/fcp-only/buffered-flag.window.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
setup({"hide_test_state": true});
async_test(t => {
assert_implements(window.PerformancePaintTiming, "Paint Timing isn't supported.");
// First observer creates second in callback to ensure the entry has been dispatched by the time
// the second observer begins observing.
let entry_seen = false;
new PerformanceObserver(entries => {
entry_seen = entries.getEntriesByName('first-contentful-paint').length > 0;
// Abort if we have not yet received both paint entries.
if (!entry_seen)
return;

// Second observer requires 'buffered: true' to see the entries.
let firstContentfulPaintSeen = false;
new PerformanceObserver(list => {
let fcp = list.getEntriesByName('first-contentful-paint');
assert_equals(fcp.length, 1, 'Should have an fcp entry');
let entry = fcp[0];
assert_equals(entry.entryType, 'paint');
t.done();
}).observe({'type': 'paint', buffered: true});
}).observe({'entryTypes': ['paint']});
// Trigger the first paint entries
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 2a3db89

Please sign in to comment.