Add more checks to scheduleWarmUpFrame (#13552)
* Add more checks to scheduleWarmUpFrame * review * add test
This commit is contained in:
@@ -669,9 +669,14 @@ abstract class SchedulerBinding extends BindingBase with ServicesBinding {
|
||||
/// If a frame has already been scheduled with [scheduleFrame] or
|
||||
/// [scheduleForcedFrame], this call may delay that frame.
|
||||
///
|
||||
/// If any scheduled frame has already begun or if another
|
||||
/// [scheduleWarmUpFrame] was already called, this call will be ignored.
|
||||
///
|
||||
/// Prefer [scheduleFrame] to update the display in normal operation.
|
||||
void scheduleWarmUpFrame() {
|
||||
assert(!_warmUpFrame);
|
||||
if (_warmUpFrame || schedulerPhase != SchedulerPhase.idle)
|
||||
return;
|
||||
|
||||
final bool hadScheduledFrame = _hasScheduledFrame;
|
||||
_warmUpFrame = true;
|
||||
// We use timers here to ensure that microtasks flush in between.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
@@ -18,8 +19,12 @@ class TestStrategy {
|
||||
}
|
||||
|
||||
void main() {
|
||||
SchedulerBinding scheduler;
|
||||
setUpAll(() {
|
||||
scheduler = new TestSchedulerBinding();
|
||||
});
|
||||
|
||||
test('Tasks are executed in the right order', () {
|
||||
final SchedulerBinding scheduler = new TestSchedulerBinding();
|
||||
final TestStrategy strategy = new TestStrategy();
|
||||
scheduler.schedulingStrategy = strategy.shouldRunTaskWithPriority;
|
||||
final List<int> input = <int>[2, 23, 23, 11, 0, 80, 3];
|
||||
@@ -84,4 +89,25 @@ void main() {
|
||||
expect(executedTasks, hasLength(1));
|
||||
expect(executedTasks[0], equals(0));
|
||||
});
|
||||
|
||||
test('2 calls to scheduleWarmUpFrame just schedules it once', () {
|
||||
final List<VoidCallback> timerQueueTasks = <VoidCallback>[];
|
||||
runZoned(
|
||||
() {
|
||||
// Run it twice without processing the queued tasks.
|
||||
scheduler.scheduleWarmUpFrame();
|
||||
scheduler.scheduleWarmUpFrame();
|
||||
},
|
||||
zoneSpecification: new ZoneSpecification(
|
||||
createTimer: (Zone self, ZoneDelegate parent, Zone zone, Duration duration, void f()) {
|
||||
// Don't actually run the tasks, just record that it was scheduled.
|
||||
timerQueueTasks.add(f);
|
||||
return null;
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
// A single call to scheduleWarmUpFrame queues up 2 Timer tasks.
|
||||
expect(timerQueueTasks.length, 2);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user