addFrameForTest method
Add a synthetic frame for testing — feeds directly into the buffer and triggers jank evaluation without requiring SchedulerBinding.
Auto-injects a monotonic FrameStats.rasterFinishUs when the caller
omits one, so actualFps-sensitive code paths see a populated rolling
window. Pass an explicit rasterFinishUs for tests that care about
window boundaries, batched delivery, or non-monotonic timestamps.
Implementation
@visibleForTesting
void addFrameForTest(FrameStats stats) {
if (!_isEnabled) return;
if (stats.rasterFinishUs == null) {
final latest = _buffer.latest?.rasterFinishUs ?? 0;
stats = stats.copyWith(rasterFinishUs: latest + warningBudgetUs);
}
_totalFramesSeen++;
_firstFrameTimestamp ??= stats.timestamp;
if (stats.vsyncStartUs != null) {
_firstFrameVsyncUs ??= stats.vsyncStartUs;
}
_buffer.add(stats);
onFrame?.call(stats);
_evaluateJank();
_evaluateCacheTrends();
onFrameStats?.call(_buffer);
}