Unverified Commit 80814553 authored by Ming Lyu (CareF)'s avatar Ming Lyu (CareF) Committed by GitHub

revert widgettester breaking change (#62914)

parent 73208301
...@@ -608,9 +608,12 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker ...@@ -608,9 +608,12 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
Future<int> pumpAndSettle([ Future<int> pumpAndSettle([
Duration duration = const Duration(milliseconds: 100), Duration duration = const Duration(milliseconds: 100),
EnginePhase phase = EnginePhase.sendSemanticsUpdate, EnginePhase phase = EnginePhase.sendSemanticsUpdate,
Duration timeout = const Duration(minutes: 10),
]) { ]) {
assert(duration != null); assert(duration != null);
assert(duration > Duration.zero); assert(duration > Duration.zero);
assert(timeout != null);
assert(timeout > Duration.zero);
assert(() { assert(() {
final WidgetsBinding binding = this.binding; final WidgetsBinding binding = this.binding;
if (binding is LiveTestWidgetsFlutterBinding && if (binding is LiveTestWidgetsFlutterBinding &&
...@@ -623,8 +626,11 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker ...@@ -623,8 +626,11 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
return true; return true;
}()); }());
return TestAsyncUtils.guard<int>(() async { return TestAsyncUtils.guard<int>(() async {
final DateTime endTime = binding.clock.fromNowBy(timeout);
int count = 0; int count = 0;
do { do {
if (binding.clock.now().isAfter(endTime))
throw FlutterError('pumpAndSettle timed out');
await binding.pump(duration, phase); await binding.pump(duration, phase);
count += 1; count += 1;
} while (binding.hasScheduledFrame); } while (binding.hasScheduledFrame);
......
...@@ -465,11 +465,21 @@ void main() { ...@@ -465,11 +465,21 @@ void main() {
testWidgets('pumpAndSettle control test', (WidgetTester tester) async { testWidgets('pumpAndSettle control test', (WidgetTester tester) async {
final AnimationController controller = AnimationController( final AnimationController controller = AnimationController(
duration: const Duration(seconds: 1), duration: const Duration(minutes: 525600),
vsync: const TestVSync(), vsync: const TestVSync(),
); );
expect(await tester.pumpAndSettle(), 1); expect(await tester.pumpAndSettle(), 1);
controller.forward(); controller.forward();
try {
await tester.pumpAndSettle();
expect(true, isFalse);
} catch (e) {
expect(e, isFlutterError);
}
controller.stop();
expect(await tester.pumpAndSettle(), 1);
controller.duration = const Duration(seconds: 1);
controller.forward();
expect(await tester.pumpAndSettle(const Duration(milliseconds: 300)), 5); // 0, 300, 600, 900, 1200ms expect(await tester.pumpAndSettle(const Duration(milliseconds: 300)), 5); // 0, 300, 600, 900, 1200ms
}); });
......
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