From 2a3db895806a217b2c1467d02553247de9ba0fdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Pe=C3=B1a=20Moreno?= Date: Mon, 3 May 2021 08:36:29 -0700 Subject: [PATCH] [PaintTiming] Add fcp-only buffered flag test Relevant GitHub issue: https://github.com/GoogleChrome/web-vitals/pull/139 Change-Id: I2884dd4c3432920011e984f6a08ebaf6a2176b67 --- paint-timing/fcp-only/buffered-flag.window.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 paint-timing/fcp-only/buffered-flag.window.js diff --git a/paint-timing/fcp-only/buffered-flag.window.js b/paint-timing/fcp-only/buffered-flag.window.js new file mode 100644 index 000000000000000..cd5073c279d3646 --- /dev/null +++ b/paint-timing/fcp-only/buffered-flag.window.js @@ -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.");