Unverified Commit 577ad2ee authored by fzyzcjy's avatar fzyzcjy Committed by GitHub

Fix error when resetting configurations in tear down phase (#114468)

* move _verifyInvariants

* fix

* fix (mimic import test_api.dart)

* fix

* Update binding.dart

* add tests

* try to move

* Revert "try to move"

This reverts commit d3c466d226cc1abe195af83a2630c70f08e25d7d.

* Update binding.dart
parent c102bf46
...@@ -15,6 +15,7 @@ import 'package:flutter/services.dart'; ...@@ -15,6 +15,7 @@ import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:stack_trace/stack_trace.dart' as stack_trace; import 'package:stack_trace/stack_trace.dart' as stack_trace;
import 'package:test_api/expect.dart' show fail; import 'package:test_api/expect.dart' show fail;
import 'package:test_api/scaffolding.dart'; // ignore: deprecated_member_use
import 'package:test_api/test_api.dart' as test_package show Timeout; // ignore: deprecated_member_use import 'package:test_api/test_api.dart' as test_package show Timeout; // ignore: deprecated_member_use
import 'package:vector_math/vector_math_64.dart'; import 'package:vector_math/vector_math_64.dart';
...@@ -919,6 +920,13 @@ abstract class TestWidgetsFlutterBinding extends BindingBase ...@@ -919,6 +920,13 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
// So that we can assert that it remains the same after the test finishes. // So that we can assert that it remains the same after the test finishes.
_beforeTestCheckIntrinsicSizes = debugCheckIntrinsicSizes; _beforeTestCheckIntrinsicSizes = debugCheckIntrinsicSizes;
bool shouldTearDownVerifyInvariants = false;
addTearDown(() {
if (shouldTearDownVerifyInvariants) {
_verifyTearDownInvariants();
}
});
runApp(Container(key: UniqueKey(), child: _preTestMessage)); // Reset the tree to a known state. runApp(Container(key: UniqueKey(), child: _preTestMessage)); // Reset the tree to a known state.
await pump(); await pump();
// Pretend that the first frame produced in the test body is the first frame // Pretend that the first frame produced in the test body is the first frame
...@@ -949,6 +957,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase ...@@ -949,6 +957,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
_verifyErrorWidgetBuilderUnset(errorWidgetBuilderBeforeTest); _verifyErrorWidgetBuilderUnset(errorWidgetBuilderBeforeTest);
_verifyShouldPropagateDevicePointerEventsUnset(shouldPropagateDevicePointerEventsBeforeTest); _verifyShouldPropagateDevicePointerEventsUnset(shouldPropagateDevicePointerEventsBeforeTest);
_verifyInvariants(); _verifyInvariants();
shouldTearDownVerifyInvariants = true;
} }
assert(inTest); assert(inTest);
...@@ -958,6 +967,11 @@ abstract class TestWidgetsFlutterBinding extends BindingBase ...@@ -958,6 +967,11 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
late bool _beforeTestCheckIntrinsicSizes; late bool _beforeTestCheckIntrinsicSizes;
void _verifyInvariants() { void _verifyInvariants() {
// subclasses such as AutomatedTestWidgetsFlutterBinding overrides this
// to perform more verifications.
}
void _verifyTearDownInvariants() {
assert(debugAssertNoTransientCallbacks( assert(debugAssertNoTransientCallbacks(
'An animation is still running even after the widget tree was disposed.' 'An animation is still running even after the widget tree was disposed.'
)); ));
......
...@@ -12,6 +12,7 @@ library; ...@@ -12,6 +12,7 @@ library;
import 'dart:async'; import 'dart:async';
import 'dart:io'; import 'dart:io';
import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
...@@ -102,4 +103,16 @@ void main() { ...@@ -102,4 +103,16 @@ void main() {
}); });
expect(responded, true); expect(responded, true);
}); });
group('should be able to reset values in either tearDown or end of function', () {
testWidgets('addTearDown should work', (WidgetTester tester) async {
timeDilation = 2;
addTearDown(() => timeDilation = 1);
});
testWidgets('directly reset should work', (WidgetTester tester) async {
timeDilation = 2;
timeDilation = 1;
});
});
} }
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