Skip to content

Commit

Permalink
Cover more test/widgets tests with leak tracking #6 (flutter#134884)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksokolovskyi authored Sep 18, 2023
1 parent 658710b commit 2396a41
Show file tree
Hide file tree
Showing 20 changed files with 366 additions and 203 deletions.
11 changes: 6 additions & 5 deletions packages/flutter/test/widgets/notification_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@

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

class MyNotification extends Notification { }

void main() {
testWidgets('Notification basics - toString', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Notification basics - toString', (WidgetTester tester) async {
expect(MyNotification(), hasOneLineDescription);
});

testWidgets('Notification basics - dispatch', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Notification basics - dispatch', (WidgetTester tester) async {
final List<dynamic> log = <dynamic>[];
final GlobalKey key = GlobalKey();
await tester.pumpWidget(NotificationListener<MyNotification>(
Expand All @@ -36,7 +37,7 @@ void main() {
expect(log, <dynamic>['b', notification, 'a', notification]);
});

testWidgets('Notification basics - cancel', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Notification basics - cancel', (WidgetTester tester) async {
final List<dynamic> log = <dynamic>[];
final GlobalKey key = GlobalKey();
await tester.pumpWidget(NotificationListener<MyNotification>(
Expand All @@ -60,7 +61,7 @@ void main() {
expect(log, <dynamic>['b', notification]);
});

testWidgets('Notification basics - listener null return value', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Notification basics - listener null return value', (WidgetTester tester) async {
final List<Type> log = <Type>[];
final GlobalKey key = GlobalKey();
await tester.pumpWidget(NotificationListener<MyNotification>(
Expand All @@ -77,7 +78,7 @@ void main() {
expect(log, <Type>[MyNotification]);
});

testWidgets('Notification basics - listener null return value', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Notification basics - listener null return value', (WidgetTester tester) async {
await tester.pumpWidget(const Placeholder());
final ScrollMetricsNotification n1 = ScrollMetricsNotification(
metrics: FixedScrollMetrics(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'dart:ui' as ui show Image;
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';

import '../image_data.dart';
import '../painting/fake_codec.dart';
Expand All @@ -17,7 +18,7 @@ Future<void> main() async {
final FakeCodec fakeCodec = await FakeCodec.fromData(Uint8List.fromList(kAnimatedGif));
final FakeImageProvider fakeImageProvider = FakeImageProvider(fakeCodec);

testWidgets('Obscured image does not animate', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Obscured image does not animate', (WidgetTester tester) async {
final GlobalKey imageKey = GlobalKey();
await tester.pumpWidget(
MaterialApp(
Expand Down
5 changes: 3 additions & 2 deletions packages/flutter/test/widgets/opacity_repaint_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
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() {
testWidgets('RenderOpacity avoids repainting and does not drop layer at fully opaque', (WidgetTester tester) async {
testWidgetsWithLeakTracking('RenderOpacity avoids repainting and does not drop layer at fully opaque', (WidgetTester tester) async {
RenderTestObject.paintCount = 0;
await tester.pumpWidget(
const ColoredBox(
Expand Down Expand Up @@ -46,7 +47,7 @@ void main() {
expect(RenderTestObject.paintCount, 1);
});

testWidgets('RenderOpacity allows opacity layer to be dropped at 0 opacity', (WidgetTester tester) async {
testWidgetsWithLeakTracking('RenderOpacity allows opacity layer to be dropped at 0 opacity', (WidgetTester tester) async {
RenderTestObject.paintCount = 0;

await tester.pumpWidget(
Expand Down
14 changes: 9 additions & 5 deletions packages/flutter/test/widgets/opacity_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
@Tags(<String>['reduced-test-set'])
library;

import 'dart:ui' as ui;

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';

import 'semantics_tester.dart';

void main() {
testWidgets('Opacity', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Opacity', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);

// Opacity 1.0: Semantics and painting
Expand Down Expand Up @@ -151,7 +154,7 @@ void main() {
semantics.dispose();
});

testWidgets('offset is correctly handled in Opacity', (WidgetTester tester) async {
testWidgetsWithLeakTracking('offset is correctly handled in Opacity', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(useMaterial3: false),
Expand Down Expand Up @@ -184,18 +187,19 @@ void main() {
);
});

testWidgets('empty opacity does not crash', (WidgetTester tester) async {
testWidgetsWithLeakTracking('empty opacity does not crash', (WidgetTester tester) async {
await tester.pumpWidget(
RepaintBoundary(child: Opacity(opacity: 0.5, child: Container())),
);
final Element element = find.byType(RepaintBoundary).first.evaluate().single;
// The following line will send the layer to engine and cause crash if an
// empty opacity layer is sent.
final OffsetLayer offsetLayer = element.renderObject!.debugLayer! as OffsetLayer;
await offsetLayer.toImage(const Rect.fromLTRB(0.0, 0.0, 1.0, 1.0));
final ui.Image image = await offsetLayer.toImage(const Rect.fromLTRB(0.0, 0.0, 1.0, 1.0));
image.dispose();
}, skip: isBrowser); // https://github.com/flutter/flutter/issues/49857

testWidgets('Child shows up in the right spot when opacity is disabled', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Child shows up in the right spot when opacity is disabled', (WidgetTester tester) async {
debugDisableOpacityLayers = true;
final GlobalKey key = GlobalKey();
await tester.pumpWidget(
Expand Down
17 changes: 9 additions & 8 deletions packages/flutter/test/widgets/overflow_bar_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

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('OverflowBar documented defaults', (WidgetTester tester) async {
testWidgetsWithLeakTracking('OverflowBar documented defaults', (WidgetTester tester) async {
const OverflowBar bar = OverflowBar();
expect(bar.spacing, 0);
expect(bar.alignment, null);
Expand All @@ -17,7 +18,7 @@ void main() {
expect(bar.children, const <Widget>[]);
});

testWidgets('Empty OverflowBar', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Empty OverflowBar', (WidgetTester tester) async {
const Size size = Size(16, 24);

await tester.pumpWidget(
Expand Down Expand Up @@ -46,7 +47,7 @@ void main() {
expect(tester.getSize(find.byType(OverflowBar)), Size.zero);
});

testWidgets('OverflowBar horizontal layout', (WidgetTester tester) async {
testWidgetsWithLeakTracking('OverflowBar horizontal layout', (WidgetTester tester) async {
final Key child1Key = UniqueKey();
final Key child2Key = UniqueKey();
final Key child3Key = UniqueKey();
Expand Down Expand Up @@ -93,7 +94,7 @@ void main() {
expect(tester.getRect(find.byKey(child1Key)), const Rect.fromLTRB(10.0 + 96 + 10.0, 8, 10.0 + 10.0 + 144, 56));
});

testWidgets('OverflowBar vertical layout', (WidgetTester tester) async {
testWidgetsWithLeakTracking('OverflowBar vertical layout', (WidgetTester tester) async {
final Key child1Key = UniqueKey();
final Key child2Key = UniqueKey();
final Key child3Key = UniqueKey();
Expand Down Expand Up @@ -174,7 +175,7 @@ void main() {
expect(tester.getRect(find.byKey(child3Key)), const Rect.fromLTRB(100.0/2.0 - 32/2, 112, 100.0/2.0 + 32/2, 144));
});

testWidgets('OverflowBar intrinsic width', (WidgetTester tester) async {
testWidgetsWithLeakTracking('OverflowBar intrinsic width', (WidgetTester tester) async {
Widget buildFrame({ required double width }) {
return Directionality(
textDirection: TextDirection.ltr,
Expand Down Expand Up @@ -205,7 +206,7 @@ void main() {
expect(tester.getSize(find.byType(OverflowBar)).width, 150);
});

testWidgets('OverflowBar intrinsic height', (WidgetTester tester) async {
testWidgetsWithLeakTracking('OverflowBar intrinsic height', (WidgetTester tester) async {
Widget buildFrame({ required double maxWidth }) {
return Directionality(
textDirection: TextDirection.ltr,
Expand Down Expand Up @@ -237,7 +238,7 @@ void main() {
});


testWidgets('OverflowBar is wider that its intrinsic width', (WidgetTester tester) async {
testWidgetsWithLeakTracking('OverflowBar is wider that its intrinsic width', (WidgetTester tester) async {
final Key key0 = UniqueKey();
final Key key1 = UniqueKey();
final Key key2 = UniqueKey();
Expand Down Expand Up @@ -273,7 +274,7 @@ void main() {
expect(tester.getTopLeft(find.byKey(key2)).dx, 600);
});

testWidgets('OverflowBar with alignment should match Row with mainAxisAlignment', (WidgetTester tester) async {
testWidgetsWithLeakTracking('OverflowBar with alignment should match Row with mainAxisAlignment', (WidgetTester tester) async {
final Key key0 = UniqueKey();
final Key key1 = UniqueKey();
final Key key2 = UniqueKey();
Expand Down
9 changes: 5 additions & 4 deletions packages/flutter/test/widgets/overflow_box_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
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('OverflowBox control test', (WidgetTester tester) async {
testWidgetsWithLeakTracking('OverflowBox control test', (WidgetTester tester) async {
final GlobalKey inner = GlobalKey();
await tester.pumpWidget(Align(
alignment: Alignment.bottomRight,
Expand All @@ -30,7 +31,7 @@ void main() {
expect(box.size, equals(const Size(100.0, 50.0)));
});

testWidgets('OverflowBox implements debugFillProperties', (WidgetTester tester) async {
testWidgetsWithLeakTracking('OverflowBox implements debugFillProperties', (WidgetTester tester) async {
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
const OverflowBox(
minWidth: 1.0,
Expand All @@ -50,7 +51,7 @@ void main() {
]);
});

testWidgets('SizedOverflowBox alignment', (WidgetTester tester) async {
testWidgetsWithLeakTracking('SizedOverflowBox alignment', (WidgetTester tester) async {
final GlobalKey inner = GlobalKey();
await tester.pumpWidget(Directionality(
textDirection: TextDirection.rtl,
Expand All @@ -73,7 +74,7 @@ void main() {
);
});

testWidgets('SizedOverflowBox alignment (direction-sensitive)', (WidgetTester tester) async {
testWidgetsWithLeakTracking('SizedOverflowBox alignment (direction-sensitive)', (WidgetTester tester) async {
final GlobalKey inner = GlobalKey();
await tester.pumpWidget(Directionality(
textDirection: TextDirection.rtl,
Expand Down
Loading

0 comments on commit 2396a41

Please sign in to comment.