Updates AutomatedTestWidgetsFlutterBinding.pump
to support microsecond precision (#132401)
* Updated `AutomatedTestWidgetsFlutterBinding.pump` to use microseconds instead of milliseconds * Added a test to prevent regression of the microsecond precision * Fixed a test that incorrectly assumed millisecond precision Closes #112610
This commit is contained in:
parent
36df956056
commit
e1ec3581bd
@ -1257,7 +1257,7 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
|
|||||||
if (hasScheduledFrame) {
|
if (hasScheduledFrame) {
|
||||||
_currentFakeAsync!.flushMicrotasks();
|
_currentFakeAsync!.flushMicrotasks();
|
||||||
handleBeginFrame(Duration(
|
handleBeginFrame(Duration(
|
||||||
milliseconds: _clock!.now().millisecondsSinceEpoch,
|
microseconds: _clock!.now().microsecondsSinceEpoch,
|
||||||
));
|
));
|
||||||
_currentFakeAsync!.flushMicrotasks();
|
_currentFakeAsync!.flushMicrotasks();
|
||||||
handleDrawFrame();
|
handleDrawFrame();
|
||||||
|
@ -12,8 +12,8 @@ library;
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
@ -57,6 +57,18 @@ void main() {
|
|||||||
order += 1;
|
order += 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('timeStamp should be accurate to microsecond precision', (WidgetTester tester) async {
|
||||||
|
final WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
|
await tester.pumpWidget(const CircularProgressIndicator());
|
||||||
|
|
||||||
|
final Duration timeStampBefore = widgetsBinding.currentSystemFrameTimeStamp;
|
||||||
|
await tester.pump(const Duration(microseconds: 12345));
|
||||||
|
final Duration timeStampAfter = widgetsBinding.currentSystemFrameTimeStamp;
|
||||||
|
|
||||||
|
expect(timeStampAfter - timeStampBefore, const Duration(microseconds: 12345));
|
||||||
|
});
|
||||||
|
|
||||||
group('elapseBlocking', () {
|
group('elapseBlocking', () {
|
||||||
testWidgets('timer is not called', (WidgetTester tester) async {
|
testWidgets('timer is not called', (WidgetTester tester) async {
|
||||||
bool timerCalled = false;
|
bool timerCalled = false;
|
||||||
|
@ -119,12 +119,17 @@ void main() {
|
|||||||
|
|
||||||
await tester.pumpFrames(target, const Duration(milliseconds: 55));
|
await tester.pumpFrames(target, const Duration(milliseconds: 55));
|
||||||
|
|
||||||
expect(logPaints, <int>[0, 17000, 34000, 50000]);
|
// `pumpframes` defaults to 16 milliseconds and 683 microseconds per pump,
|
||||||
|
// so we expect 4 pumps of 16683 microseconds each in the 55ms duration.
|
||||||
|
expect(logPaints, <int>[0, 16683, 33366, 50049]);
|
||||||
logPaints.clear();
|
logPaints.clear();
|
||||||
|
|
||||||
await tester.pumpFrames(target, const Duration(milliseconds: 30), const Duration(milliseconds: 10));
|
await tester.pumpFrames(target, const Duration(milliseconds: 30), const Duration(milliseconds: 10));
|
||||||
|
|
||||||
expect(logPaints, <int>[60000, 70000, 80000]);
|
// Since `pumpFrames` was given a 10ms interval per pump, we expect the
|
||||||
|
// results to continue from 50049 with 10000 microseconds per pump over
|
||||||
|
// the 30ms duration.
|
||||||
|
expect(logPaints, <int>[60049, 70049, 80049]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
group('pageBack', () {
|
group('pageBack', () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user