Unverified Commit e1ec3581 authored by pdblasi-google's avatar pdblasi-google Committed by GitHub

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
parent 36df9560
......@@ -1257,7 +1257,7 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
if (hasScheduledFrame) {
_currentFakeAsync!.flushMicrotasks();
handleBeginFrame(Duration(
milliseconds: _clock!.now().millisecondsSinceEpoch,
microseconds: _clock!.now().microsecondsSinceEpoch,
));
_currentFakeAsync!.flushMicrotasks();
handleDrawFrame();
......
......@@ -12,8 +12,8 @@ library;
import 'dart:async';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
......@@ -57,6 +57,18 @@ void main() {
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', () {
testWidgets('timer is not called', (WidgetTester tester) async {
bool timerCalled = false;
......
......@@ -119,12 +119,17 @@ void main() {
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();
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', () {
......
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