Skip to content

Commit 75a2e5b

Browse files
authored
Reset framesEnabled to default value at the end of each test (flutter#141844)
Reset `framesEnabled` to `true` at the end of each test as otherwise subsequent tests may fail when pumping a widget Fixes flutter#141835
1 parent e8cb029 commit 75a2e5b

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

packages/flutter/lib/src/scheduler/binding.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,11 +391,12 @@ mixin SchedulerBinding on BindingBase {
391391
AppLifecycleState? get lifecycleState => _lifecycleState;
392392
AppLifecycleState? _lifecycleState;
393393

394-
/// Allows the test framework to reset the lifecycle state back to its
395-
/// initial value.
394+
/// Allows the test framework to reset the lifecycle state and framesEnabled
395+
/// back to their initial values.
396396
@visibleForTesting
397-
void resetLifecycleState() {
397+
void resetInternalState() {
398398
_lifecycleState = null;
399+
_framesEnabled = true;
399400
}
400401

401402
/// Called when the application lifecycle state changes.

packages/flutter/test/services/lifecycle_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import 'package:flutter_test/flutter_test.dart';
1010
void main() {
1111
testWidgets('initialLifecycleState is used to init state paused', (WidgetTester tester) async {
1212
final TestWidgetsFlutterBinding binding = tester.binding;
13-
binding.resetLifecycleState();
13+
binding.resetInternalState();
1414
// Use paused as the initial state.
1515
binding.platformDispatcher.initialLifecycleStateTestValue = 'AppLifecycleState.paused';
1616
binding.readTestInitialLifecycleStateFromNativeWindow(); // Re-attempt the initialization.
@@ -22,7 +22,7 @@ void main() {
2222
testWidgets('Handles all of the allowed states of AppLifecycleState', (WidgetTester tester) async {
2323
final TestWidgetsFlutterBinding binding = tester.binding;
2424
for (final AppLifecycleState state in AppLifecycleState.values) {
25-
binding.resetLifecycleState();
25+
binding.resetInternalState();
2626
binding.platformDispatcher.initialLifecycleStateTestValue = state.toString();
2727
binding.readTestInitialLifecycleStateFromNativeWindow();
2828
expect(ServicesBinding.instance.lifecycleState.toString(), equals(state.toString()));

packages/flutter/test/widgets/app_lifecycle_listener_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void main() {
4343
listener?.dispose();
4444
listener = null;
4545
final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.instance;
46-
binding.resetLifecycleState();
46+
binding.resetInternalState();
4747
binding.platformDispatcher.resetInitialLifecycleState();
4848
assert(TestAppLifecycleListener.registerCount == 0,
4949
'There were ${TestAppLifecycleListener.registerCount} listeners that were not disposed of in tests.');

packages/flutter/test/widgets/binding_test.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,21 @@ void main() {
397397
await tester.pump();
398398
});
399399

400+
testWidgets('resetInternalState resets lifecycleState and framesEnabled to initial state', (WidgetTester tester) async {
401+
// Initial state
402+
expect(tester.binding.lifecycleState, isNull);
403+
expect(tester.binding.framesEnabled, isTrue);
404+
405+
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.paused);
406+
expect(tester.binding.lifecycleState, AppLifecycleState.paused);
407+
expect(tester.binding.framesEnabled, isFalse);
408+
409+
tester.binding.resetInternalState();
410+
411+
expect(tester.binding.lifecycleState, isNull);
412+
expect(tester.binding.framesEnabled, isTrue);
413+
});
414+
400415
testWidgets('scheduleFrameCallback error control test', (WidgetTester tester) async {
401416
late FlutterError error;
402417
try {

packages/flutter_test/lib/src/binding.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
11771177
// ignore: invalid_use_of_visible_for_testing_member
11781178
RendererBinding.instance.initMouseTracker();
11791179
// ignore: invalid_use_of_visible_for_testing_member
1180-
ServicesBinding.instance.resetLifecycleState();
1180+
ServicesBinding.instance.resetInternalState();
11811181
}
11821182
}
11831183

0 commit comments

Comments
 (0)