mirror of
https://github.com/flutter/flutter
synced 2024-08-25 11:07:06 +00:00
Fix memory leak in editable_gesture_test.dart
(#144691)
This commit is contained in:
parent
3e63c7385d
commit
96dd1984ec
|
@ -6,23 +6,21 @@ import 'package:flutter/gestures.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
final TestWidgetsFlutterBinding binding = _GestureBindingSpy();
|
final TestWidgetsFlutterBinding binding = _GestureBindingSpy();
|
||||||
|
|
||||||
testWidgets('attach and detach correctly handle gesture',
|
testWidgets('attach and detach correctly handle gesture', (_) async {
|
||||||
// TODO(polina-c): clean up leaks, https://github.com/flutter/flutter/issues/134787
|
|
||||||
experimentalLeakTesting: LeakTesting.settings.withIgnoredAll(),
|
|
||||||
(_) async {
|
|
||||||
expect(WidgetsBinding.instance, binding);
|
expect(WidgetsBinding.instance, binding);
|
||||||
final TextSelectionDelegate delegate = FakeEditableTextState();
|
final TextSelectionDelegate delegate = FakeEditableTextState();
|
||||||
|
final ViewportOffset offset = ViewportOffset.zero();
|
||||||
|
addTearDown(offset.dispose);
|
||||||
final RenderEditable editable = RenderEditable(
|
final RenderEditable editable = RenderEditable(
|
||||||
backgroundCursorColor: Colors.grey,
|
backgroundCursorColor: Colors.grey,
|
||||||
selectionColor: Colors.black,
|
selectionColor: Colors.black,
|
||||||
textDirection: TextDirection.ltr,
|
textDirection: TextDirection.ltr,
|
||||||
cursorColor: Colors.red,
|
cursorColor: Colors.red,
|
||||||
offset: ViewportOffset.zero(),
|
offset: offset,
|
||||||
textSelectionDelegate: delegate,
|
textSelectionDelegate: delegate,
|
||||||
text: const TextSpan(
|
text: const TextSpan(
|
||||||
text: 'test',
|
text: 'test',
|
||||||
|
@ -36,13 +34,17 @@ void main() {
|
||||||
affinity: TextAffinity.upstream,
|
affinity: TextAffinity.upstream,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
addTearDown(editable.dispose);
|
||||||
editable.layout(BoxConstraints.loose(const Size(1000.0, 1000.0)));
|
editable.layout(BoxConstraints.loose(const Size(1000.0, 1000.0)));
|
||||||
|
|
||||||
final PipelineOwner owner = PipelineOwner(onNeedVisualUpdate: () { });
|
final PipelineOwner owner = PipelineOwner(onNeedVisualUpdate: () {});
|
||||||
final _PointerRouterSpy spy = GestureBinding.instance.pointerRouter as _PointerRouterSpy;
|
addTearDown(owner.dispose);
|
||||||
|
final _PointerRouterSpy spy =
|
||||||
|
GestureBinding.instance.pointerRouter as _PointerRouterSpy;
|
||||||
editable.attach(owner);
|
editable.attach(owner);
|
||||||
// This should register pointer into GestureBinding.instance.pointerRouter.
|
// 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());
|
GestureBinding.instance.pointerRouter.route(const PointerDownEvent());
|
||||||
expect(spy.routeCount, greaterThan(0));
|
expect(spy.routeCount, greaterThan(0));
|
||||||
editable.detach();
|
editable.detach();
|
||||||
|
@ -57,7 +59,7 @@ class _GestureBindingSpy extends AutomatedTestWidgetsFlutterBinding {
|
||||||
PointerRouter get pointerRouter => _testPointerRouter;
|
PointerRouter get pointerRouter => _testPointerRouter;
|
||||||
}
|
}
|
||||||
|
|
||||||
class FakeEditableTextState extends Fake implements TextSelectionDelegate { }
|
class FakeEditableTextState extends Fake implements TextSelectionDelegate {}
|
||||||
|
|
||||||
class _PointerRouterSpy extends PointerRouter {
|
class _PointerRouterSpy extends PointerRouter {
|
||||||
int routeCount = 0;
|
int routeCount = 0;
|
||||||
|
|
Loading…
Reference in a new issue