Unverified Commit 75a2e5b4 authored by Aizat Azhar's avatar Aizat Azhar Committed by GitHub

Reset framesEnabled to default value at the end of each test (#141844)

Reset `framesEnabled` to `true` at the end of each test as otherwise subsequent tests may fail when pumping a widget

Fixes #141835
parent e8cb0295
......@@ -391,11 +391,12 @@ mixin SchedulerBinding on BindingBase {
AppLifecycleState? get lifecycleState => _lifecycleState;
AppLifecycleState? _lifecycleState;
/// Allows the test framework to reset the lifecycle state back to its
/// initial value.
/// Allows the test framework to reset the lifecycle state and framesEnabled
/// back to their initial values.
@visibleForTesting
void resetLifecycleState() {
void resetInternalState() {
_lifecycleState = null;
_framesEnabled = true;
}
/// Called when the application lifecycle state changes.
......
......@@ -10,7 +10,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('initialLifecycleState is used to init state paused', (WidgetTester tester) async {
final TestWidgetsFlutterBinding binding = tester.binding;
binding.resetLifecycleState();
binding.resetInternalState();
// Use paused as the initial state.
binding.platformDispatcher.initialLifecycleStateTestValue = 'AppLifecycleState.paused';
binding.readTestInitialLifecycleStateFromNativeWindow(); // Re-attempt the initialization.
......@@ -22,7 +22,7 @@ void main() {
testWidgets('Handles all of the allowed states of AppLifecycleState', (WidgetTester tester) async {
final TestWidgetsFlutterBinding binding = tester.binding;
for (final AppLifecycleState state in AppLifecycleState.values) {
binding.resetLifecycleState();
binding.resetInternalState();
binding.platformDispatcher.initialLifecycleStateTestValue = state.toString();
binding.readTestInitialLifecycleStateFromNativeWindow();
expect(ServicesBinding.instance.lifecycleState.toString(), equals(state.toString()));
......
......@@ -43,7 +43,7 @@ void main() {
listener?.dispose();
listener = null;
final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.instance;
binding.resetLifecycleState();
binding.resetInternalState();
binding.platformDispatcher.resetInitialLifecycleState();
assert(TestAppLifecycleListener.registerCount == 0,
'There were ${TestAppLifecycleListener.registerCount} listeners that were not disposed of in tests.');
......
......@@ -397,6 +397,21 @@ void main() {
await tester.pump();
});
testWidgets('resetInternalState resets lifecycleState and framesEnabled to initial state', (WidgetTester tester) async {
// Initial state
expect(tester.binding.lifecycleState, isNull);
expect(tester.binding.framesEnabled, isTrue);
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.paused);
expect(tester.binding.lifecycleState, AppLifecycleState.paused);
expect(tester.binding.framesEnabled, isFalse);
tester.binding.resetInternalState();
expect(tester.binding.lifecycleState, isNull);
expect(tester.binding.framesEnabled, isTrue);
});
testWidgets('scheduleFrameCallback error control test', (WidgetTester tester) async {
late FlutterError error;
try {
......
......@@ -1177,7 +1177,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
// ignore: invalid_use_of_visible_for_testing_member
RendererBinding.instance.initMouseTracker();
// ignore: invalid_use_of_visible_for_testing_member
ServicesBinding.instance.resetLifecycleState();
ServicesBinding.instance.resetInternalState();
}
}
......
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