-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PaintTiming] Add fcp-only buffered flag test
Relevant GitHub issue: GoogleChrome/web-vitals#139 Change-Id: I2884dd4c3432920011e984f6a08ebaf6a2176b67
- Loading branch information
1 parent
507ff1a
commit 2a3db89
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); |