Unverified Commit 96dd1984 authored by Valentin Vignal's avatar Valentin Vignal Committed by GitHub

Fix memory leak in `editable_gesture_test.dart` (#144691)

parent 3e63c738
......@@ -6,23 +6,21 @@ import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
void main() {
final TestWidgetsFlutterBinding binding = _GestureBindingSpy();
testWidgets('attach and detach correctly handle gesture',
// TODO(polina-c): clean up leaks, https://github.com/flutter/flutter/issues/134787
experimentalLeakTesting: LeakTesting.settings.withIgnoredAll(),
(_) async {
testWidgets('attach and detach correctly handle gesture', (_) async {
expect(WidgetsBinding.instance, binding);
final TextSelectionDelegate delegate = FakeEditableTextState();
final ViewportOffset offset = ViewportOffset.zero();
addTearDown(offset.dispose);
final RenderEditable editable = RenderEditable(
backgroundCursorColor: Colors.grey,
selectionColor: Colors.black,
textDirection: TextDirection.ltr,
cursorColor: Colors.red,
offset: ViewportOffset.zero(),
offset: offset,
textSelectionDelegate: delegate,
text: const TextSpan(
text: 'test',
......@@ -36,13 +34,17 @@ void main() {
affinity: TextAffinity.upstream,
),
);
addTearDown(editable.dispose);
editable.layout(BoxConstraints.loose(const Size(1000.0, 1000.0)));
final PipelineOwner owner = PipelineOwner(onNeedVisualUpdate: () { });
final _PointerRouterSpy spy = GestureBinding.instance.pointerRouter as _PointerRouterSpy;
final PipelineOwner owner = PipelineOwner(onNeedVisualUpdate: () {});
addTearDown(owner.dispose);
final _PointerRouterSpy spy =
GestureBinding.instance.pointerRouter as _PointerRouterSpy;
editable.attach(owner);
// This should register pointer into GestureBinding.instance.pointerRouter.
editable.handleEvent(const PointerDownEvent(), BoxHitTestEntry(editable, const Offset(10,10)));
editable.handleEvent(const PointerDownEvent(),
BoxHitTestEntry(editable, const Offset(10, 10)));
GestureBinding.instance.pointerRouter.route(const PointerDownEvent());
expect(spy.routeCount, greaterThan(0));
editable.detach();
......@@ -57,7 +59,7 @@ class _GestureBindingSpy extends AutomatedTestWidgetsFlutterBinding {
PointerRouter get pointerRouter => _testPointerRouter;
}
class FakeEditableTextState extends Fake implements TextSelectionDelegate { }
class FakeEditableTextState extends Fake implements TextSelectionDelegate {}
class _PointerRouterSpy extends PointerRouter {
int routeCount = 0;
......
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