[go: nahoru, domu]

Skip to content

Commit

Permalink
Cover more test/widgets tests with leak tracking #7 (flutter#134943)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksokolovskyi committed Sep 20, 2023
1 parent b0a90ae commit e6d160a
Show file tree
Hide file tree
Showing 29 changed files with 409 additions and 263 deletions.
9 changes: 5 additions & 4 deletions packages/flutter/test/widgets/pop_scope_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';

import 'navigator_utils.dart';

Expand Down Expand Up @@ -34,7 +35,7 @@ void main() {
.setMockMethodCallHandler(SystemChannels.platform, null);
});

testWidgets('toggling canPop on root route allows/prevents backs', (WidgetTester tester) async {
testWidgetsWithLeakTracking('toggling canPop on root route allows/prevents backs', (WidgetTester tester) async {
bool canPop = false;
late StateSetter setState;
late BuildContext context;
Expand Down Expand Up @@ -79,7 +80,7 @@ void main() {
variant: TargetPlatformVariant.all(),
);

testWidgets('toggling canPop on secondary route allows/prevents backs', (WidgetTester tester) async {
testWidgetsWithLeakTracking('toggling canPop on secondary route allows/prevents backs', (WidgetTester tester) async {
final GlobalKey<NavigatorState> nav = GlobalKey<NavigatorState>();
bool canPop = true;
late StateSetter setState;
Expand Down Expand Up @@ -247,7 +248,7 @@ void main() {
variant: TargetPlatformVariant.all(),
);

testWidgets('removing PopScope from the tree removes its effect on navigation', (WidgetTester tester) async {
testWidgetsWithLeakTracking('removing PopScope from the tree removes its effect on navigation', (WidgetTester tester) async {
bool usePopScope = true;
late StateSetter setState;
late BuildContext context;
Expand Down Expand Up @@ -299,7 +300,7 @@ void main() {
variant: TargetPlatformVariant.all(),
);

testWidgets('identical PopScopes', (WidgetTester tester) async {
testWidgetsWithLeakTracking('identical PopScopes', (WidgetTester tester) async {
bool usePopScope1 = true;
bool usePopScope2 = true;
late StateSetter setState;
Expand Down
5 changes: 3 additions & 2 deletions packages/flutter/test/widgets/positioned_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import 'dart:async';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';

void main() {
testWidgets('Positioned constructors', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Positioned constructors', (WidgetTester tester) async {
final Widget child = Container();
final Positioned a = Positioned(
left: 101.0,
Expand Down Expand Up @@ -56,7 +57,7 @@ void main() {
expect(c.height, null);
});

testWidgets('Can animate position data', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Can animate position data', (WidgetTester tester) async {
final RelativeRectTween rect = RelativeRectTween(
begin: RelativeRect.fromRect(
const Rect.fromLTRB(10.0, 20.0, 20.0, 30.0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';

class ExpandingBox extends StatefulWidget {
const ExpandingBox({ super.key, required this.collapsedSize, required this.expandedSize });
Expand Down Expand Up @@ -53,7 +54,7 @@ class _ExpandingBoxState extends State<ExpandingBox> with AutomaticKeepAliveClie
}

void main() {
testWidgets('shrink listview', (WidgetTester tester) async {
testWidgetsWithLeakTracking('shrink listview', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: ListView.builder(
itemBuilder: (BuildContext context, int index) => index == 0
Expand Down Expand Up @@ -98,7 +99,7 @@ void main() {
expect(position.pixels, 100.0);
});

testWidgets('shrink listview while dragging', (WidgetTester tester) async {
testWidgetsWithLeakTracking('shrink listview while dragging', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: ListView.builder(
itemBuilder: (BuildContext context, int index) => index == 0
Expand Down Expand Up @@ -157,7 +158,7 @@ void main() {
expect(position.pixels, 50.0);
});

testWidgets('shrink listview while ballistic', (WidgetTester tester) async {
testWidgetsWithLeakTracking('shrink listview while ballistic', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: GestureDetector(
onTap: () { assert(false); },
Expand Down Expand Up @@ -220,7 +221,7 @@ void main() {
expect(position.pixels, 0.0);
});

testWidgets('expanding page views', (WidgetTester tester) async {
testWidgetsWithLeakTracking('expanding page views', (WidgetTester tester) async {
await tester.pumpWidget(const Padding(padding: EdgeInsets.only(right: 200.0), child: TabBarDemo()));
await tester.tap(find.text('bike'));
await tester.pump();
Expand All @@ -231,7 +232,7 @@ void main() {
expect(bike2.center, bike1.shift(const Offset(100.0, 0.0)).center);
});

testWidgets('changing the size of the viewport when overscrolled', (WidgetTester tester) async {
testWidgetsWithLeakTracking('changing the size of the viewport when overscrolled', (WidgetTester tester) async {
Widget build(double height) {
return Directionality(
textDirection: TextDirection.rtl,
Expand Down Expand Up @@ -265,7 +266,7 @@ void main() {
expect(oldPosition, newPosition);
});

testWidgets('inserting and removing an item when overscrolled', (WidgetTester tester) async {
testWidgetsWithLeakTracking('inserting and removing an item when overscrolled', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/62890

const double itemExtent = 100.0;
Expand Down
16 changes: 9 additions & 7 deletions packages/flutter/test/widgets/raw_keyboard_listener_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';

void main() {
testWidgets('Can dispose without keyboard', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Can dispose without keyboard', (WidgetTester tester) async {
final FocusNode focusNode = FocusNode();
addTearDown(focusNode.dispose);
await tester.pumpWidget(RawKeyboardListener(focusNode: focusNode, child: Container()));
await tester.pumpWidget(RawKeyboardListener(focusNode: focusNode, child: Container()));
await tester.pumpWidget(Container());
});

testWidgets('Fuchsia key event', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Fuchsia key event', (WidgetTester tester) async {
final List<RawKeyEvent> events = <RawKeyEvent>[];

final FocusNode focusNode = FocusNode();
addTearDown(focusNode.dispose);

await tester.pumpWidget(
RawKeyboardListener(
Expand All @@ -43,13 +46,13 @@ void main() {
expect(typedData.isModifierPressed(ModifierKey.metaModifier, side: KeyboardSide.left), isTrue);

await tester.pumpWidget(Container());
focusNode.dispose();
}, skip: isBrowser); // [intended] This is a Fuchsia-specific test.

testWidgets('Web key event', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Web key event', (WidgetTester tester) async {
final List<RawKeyEvent> events = <RawKeyEvent>[];

final FocusNode focusNode = FocusNode();
addTearDown(focusNode.dispose);

await tester.pumpWidget(
RawKeyboardListener(
Expand All @@ -74,13 +77,13 @@ void main() {
expect(typedData.isModifierPressed(ModifierKey.metaModifier, side: KeyboardSide.left), isTrue);

await tester.pumpWidget(Container());
focusNode.dispose();
});

testWidgets('Defunct listeners do not receive events', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Defunct listeners do not receive events', (WidgetTester tester) async {
final List<RawKeyEvent> events = <RawKeyEvent>[];

final FocusNode focusNode = FocusNode();
addTearDown(focusNode.dispose);

await tester.pumpWidget(
RawKeyboardListener(
Expand Down Expand Up @@ -108,6 +111,5 @@ void main() {
expect(events.length, 0);

await tester.pumpWidget(Container());
focusNode.dispose();
});
}
3 changes: 2 additions & 1 deletion packages/flutter/test/widgets/reassemble_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';

void main() {
testWidgets('reassemble does not crash', (WidgetTester tester) async {
testWidgetsWithLeakTracking('reassemble does not crash', (WidgetTester tester) async {
await tester.pumpWidget(const MaterialApp(
home: Text('Hello World'),
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';

@immutable
class Pair<T> {
Expand Down Expand Up @@ -239,7 +240,7 @@ class RenderSwapper extends RenderBox {
BoxParentData parentDataFor(RenderObject renderObject) => renderObject.parentData! as BoxParentData;

void main() {
testWidgets('RenderObjectElement *RenderObjectChild methods get called with correct arguments', (WidgetTester tester) async {
testWidgetsWithLeakTracking('RenderObjectElement *RenderObjectChild methods get called with correct arguments', (WidgetTester tester) async {
const Key redKey = ValueKey<String>('red');
const Key blueKey = ValueKey<String>('blue');
Widget widget() {
Expand Down
11 changes: 6 additions & 5 deletions packages/flutter/test/widgets/render_object_widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';

final BoxDecoration kBoxDecorationA = BoxDecoration(border: nonconst(null));
final BoxDecoration kBoxDecorationB = BoxDecoration(border: nonconst(null));
Expand Down Expand Up @@ -75,7 +76,7 @@ class TestNonVisitingRenderObject extends RenderBox with RenderObjectWithChildMi
}

void main() {
testWidgets('RenderObjectWidget smoke test', (WidgetTester tester) async {
testWidgetsWithLeakTracking('RenderObjectWidget smoke test', (WidgetTester tester) async {
await tester.pumpWidget(DecoratedBox(decoration: kBoxDecorationA));
SingleChildRenderObjectElement element =
tester.element(find.byElementType(SingleChildRenderObjectElement));
Expand All @@ -94,7 +95,7 @@ void main() {
expect(renderObject.position, equals(DecorationPosition.background));
});

testWidgets('RenderObjectWidget can add and remove children', (WidgetTester tester) async {
testWidgetsWithLeakTracking('RenderObjectWidget can add and remove children', (WidgetTester tester) async {

void checkFullTree() {
final SingleChildRenderObjectElement element =
Expand Down Expand Up @@ -178,7 +179,7 @@ void main() {
childBareTree();
});

testWidgets('Detached render tree is intact', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Detached render tree is intact', (WidgetTester tester) async {

await tester.pumpWidget(DecoratedBox(
decoration: kBoxDecorationA,
Expand Down Expand Up @@ -220,7 +221,7 @@ void main() {
expect(grandChild.child, isNull);
});

testWidgets('Can watch inherited widgets', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Can watch inherited widgets', (WidgetTester tester) async {
final Key boxKey = UniqueKey();
final TestOrientedBox box = TestOrientedBox(key: boxKey);

Expand All @@ -242,7 +243,7 @@ void main() {
expect(decoration.color, equals(const Color(0xFF0000FF)));
});

testWidgets('RenderObject not visiting children provides helpful error message', (WidgetTester tester) async {
testWidgetsWithLeakTracking('RenderObject not visiting children provides helpful error message', (WidgetTester tester) async {
await tester.pumpWidget(
TestNonVisitingWidget(
child: Container(color: const Color(0xFFED1D7F)),
Expand Down
Loading

0 comments on commit e6d160a

Please sign in to comment.