Commit c2d62d36 authored by Nicolás Peña Moreno's avatar Nicolás Peña Moreno Committed by Commit Bot

[Longtasks] Fix buffering before observer

When we shipped longtasks with buffered flag, we forgot to remove a
check that would prevent longtask creation when there's no observer.
This CL fixes this and adds a test for this case. It also moves the
UseCounter to the observe() method.

Bug: 1131385
Change-Id: I2911b9ab044db7394bcf64f64b1e599959cbdc37
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2463594Reviewed-by: default avatarSteve Kobes <skobes@chromium.org>
Commit-Queue: Nicolás Peña Moreno <npm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816664}
parent ca85f7f8
......@@ -675,10 +675,6 @@ void Performance::AddLongTaskTiming(base::TimeTicks start_time,
const String& container_src,
const String& container_id,
const String& container_name) {
if (!HasObserverFor(PerformanceEntry::kLongTask))
return;
UseCounter::Count(GetExecutionContext(), WebFeature::kLongTaskObserver);
auto* entry = MakeGarbageCollected<PerformanceLongTaskTiming>(
MonotonicTimeToDOMHighResTimeStamp(start_time),
MonotonicTimeToDOMHighResTimeStamp(end_time), name, container_type,
......
......@@ -211,6 +211,9 @@ void PerformanceObserver::observe(const PerformanceObserverInit* observer_init,
if (filter_options_ & PerformanceEntry::kResource) {
UseCounter::Count(GetExecutionContext(), WebFeature::kResourceTiming);
}
if (filter_options_ & PerformanceEntry::kLongTask) {
UseCounter::Count(GetExecutionContext(), WebFeature::kLongTaskObserver);
}
if (is_registered_)
performance_->UpdatePerformanceObserverFilterOptions();
else
......
async_test(t => {
assert_implements(window.PerformanceLongTaskTiming, 'Longtasks are not supported.');
// Create a long task before any observer.
const begin = window.performance.now();
while (window.performance.now() < begin + 60);
// After a timeout, add an observer with buffered flag.
t.step_timeout(() => {
new PerformanceObserver(t.step_func_done(list => {
list.getEntries().forEach(entry => {
assert_equals(entry.entryType, 'longtask');
assert_equals(entry.name, 'self');
assert_greater_than(entry.duration, 50);
});
})).observe({type: 'longtask', buffered: true});
}, 0);
}, 'PerformanceObserver with buffered flag can see previous longtask entries.');
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment