Skip to content

Commit

Permalink
Cover more test/widgets tests with leak tracking flutter#9 (#135054)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksokolovskyi authored Sep 20, 2023
1 parent d0004c9 commit c3db020
Show file tree
Hide file tree
Showing 41 changed files with 366 additions and 230 deletions.
28 changes: 22 additions & 6 deletions packages/flutter/test/widgets/selection_container_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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() {

Expand All @@ -20,9 +21,11 @@ void main() {
);
}

testWidgets('updates its registrar and delegate based on the number of selectables', (WidgetTester tester) async {
testWidgetsWithLeakTracking('updates its registrar and delegate based on the number of selectables', (WidgetTester tester) async {
final TestSelectionRegistrar registrar = TestSelectionRegistrar();
final TestContainerDelegate delegate = TestContainerDelegate();
addTearDown(delegate.dispose);

await pumpContainer(
tester,
SelectionContainer(
Expand All @@ -42,9 +45,11 @@ void main() {
expect(delegate.selectables.length, 3);
});

testWidgets('disabled container', (WidgetTester tester) async {
testWidgetsWithLeakTracking('disabled container', (WidgetTester tester) async {
final TestSelectionRegistrar registrar = TestSelectionRegistrar();
final TestContainerDelegate delegate = TestContainerDelegate();
addTearDown(delegate.dispose);

await pumpContainer(
tester,
SelectionContainer(
Expand All @@ -65,10 +70,13 @@ void main() {
expect(delegate.selectables.length, 0);
});

testWidgets('Swapping out container delegate does not crash', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Swapping out container delegate does not crash', (WidgetTester tester) async {
final TestSelectionRegistrar registrar = TestSelectionRegistrar();
final TestContainerDelegate delegate = TestContainerDelegate();
addTearDown(delegate.dispose);
final TestContainerDelegate childDelegate = TestContainerDelegate();
addTearDown(childDelegate.dispose);

await pumpContainer(
tester,
SelectionContainer(
Expand All @@ -90,6 +98,8 @@ void main() {
expect(delegate.value.hasContent, isTrue);

final TestContainerDelegate newDelegate = TestContainerDelegate();
addTearDown(newDelegate.dispose);

await pumpContainer(
tester,
SelectionContainer(
Expand All @@ -112,10 +122,13 @@ void main() {
expect(tester.takeException(), isNull);
});

testWidgets('Can update within one frame', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Can update within one frame', (WidgetTester tester) async {
final TestSelectionRegistrar registrar = TestSelectionRegistrar();
final TestContainerDelegate delegate = TestContainerDelegate();
addTearDown(delegate.dispose);
final TestContainerDelegate childDelegate = TestContainerDelegate();
addTearDown(childDelegate.dispose);

await pumpContainer(
tester,
SelectionContainer(
Expand All @@ -139,9 +152,11 @@ void main() {
expect(delegate.value.hasContent, isTrue);
});

testWidgets('selection container registers itself if there is a selectable child', (WidgetTester tester) async {
testWidgetsWithLeakTracking('selection container registers itself if there is a selectable child', (WidgetTester tester) async {
final TestSelectionRegistrar registrar = TestSelectionRegistrar();
final TestContainerDelegate delegate = TestContainerDelegate();
addTearDown(delegate.dispose);

await pumpContainer(
tester,
SelectionContainer(
Expand Down Expand Up @@ -181,9 +196,10 @@ void main() {
expect(registrar.selectables.length, 0);
});

testWidgets('selection container gets registrar from context if not provided', (WidgetTester tester) async {
testWidgetsWithLeakTracking('selection container gets registrar from context if not provided', (WidgetTester tester) async {
final TestSelectionRegistrar registrar = TestSelectionRegistrar();
final TestContainerDelegate delegate = TestContainerDelegate();
addTearDown(delegate.dispose);

await pumpContainer(
tester,
Expand Down
3 changes: 2 additions & 1 deletion packages/flutter/test/widgets/semantics_10_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import 'package:flutter/material.dart';
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';

import 'semantics_tester.dart';

void main() {
testWidgets('can cease to be semantics boundary after markNeedsSemanticsUpdate() has already been called once', (WidgetTester tester) async {
testWidgetsWithLeakTracking('can cease to be semantics boundary after markNeedsSemanticsUpdate() has already been called once', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);

await tester.pumpWidget(
Expand Down
3 changes: 2 additions & 1 deletion packages/flutter/test/widgets/semantics_11_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import 'package:flutter/material.dart';
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';

import 'semantics_tester.dart';

void main() {
testWidgets('markNeedsSemanticsUpdate() called on non-boundary with non-boundary parent', (WidgetTester tester) async {
testWidgetsWithLeakTracking('markNeedsSemanticsUpdate() called on non-boundary with non-boundary parent', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);

await tester.pumpWidget(
Expand Down
3 changes: 2 additions & 1 deletion packages/flutter/test/widgets/semantics_1_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
import 'package:flutter/material.dart';
import 'package:flutter/widgets.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('Semantics 1', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Semantics 1', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);

// smoketest
Expand Down
3 changes: 2 additions & 1 deletion packages/flutter/test/widgets/semantics_2_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
import 'package:flutter/material.dart';
import 'package:flutter/widgets.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('Semantics 2', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Semantics 2', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);

// this test is the same as the test in Semantics 1, but
Expand Down
3 changes: 2 additions & 1 deletion packages/flutter/test/widgets/semantics_3_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
import 'package:flutter/material.dart';
import 'package:flutter/widgets.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('Semantics 3', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Semantics 3', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);

// implicit annotators
Expand Down
3 changes: 2 additions & 1 deletion packages/flutter/test/widgets/semantics_4_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
import 'package:flutter/material.dart';
import 'package:flutter/widgets.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('Semantics 4', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Semantics 4', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);

// O
Expand Down
3 changes: 2 additions & 1 deletion packages/flutter/test/widgets/semantics_5_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
import 'package:flutter/material.dart';
import 'package:flutter/widgets.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('Semantics 5', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Semantics 5', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);

await tester.pumpWidget(
Expand Down
3 changes: 2 additions & 1 deletion packages/flutter/test/widgets/semantics_6_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
import 'package:flutter/material.dart';
import 'package:flutter/widgets.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('can change semantics in a branch blocked by BlockSemantics', (WidgetTester tester) async {
testWidgetsWithLeakTracking('can change semantics in a branch blocked by BlockSemantics', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);

final TestSemantics expectedSemantics = TestSemantics.root(
Expand Down
3 changes: 2 additions & 1 deletion packages/flutter/test/widgets/semantics_7_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
import 'package:flutter/material.dart';
import 'package:flutter/widgets.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('Semantics 7 - Merging', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Semantics 7 - Merging', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);

String label;
Expand Down
3 changes: 2 additions & 1 deletion packages/flutter/test/widgets/semantics_8_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
import 'package:flutter/material.dart';
import 'package:flutter/widgets.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('Semantics 8 - Merging with reset', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Semantics 8 - Merging with reset', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);

await tester.pumpWidget(
Expand Down
7 changes: 4 additions & 3 deletions packages/flutter/test/widgets/semantics_9_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import 'package:flutter/material.dart';
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';

import 'semantics_tester.dart';

void main() {
group('BlockSemantics', () {
testWidgets('hides semantic nodes of siblings', (WidgetTester tester) async {
testWidgetsWithLeakTracking('hides semantic nodes of siblings', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);

await tester.pumpWidget(Stack(
Expand Down Expand Up @@ -49,7 +50,7 @@ void main() {
semantics.dispose();
});

testWidgets('does not hides semantic nodes of siblings outside the current semantic boundary', (WidgetTester tester) async {
testWidgetsWithLeakTracking('does not hides semantic nodes of siblings outside the current semantic boundary', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);

await tester.pumpWidget(Directionality(textDirection: TextDirection.ltr, child: Stack(
Expand Down Expand Up @@ -103,7 +104,7 @@ void main() {
semantics.dispose();
});

testWidgets('node is semantic boundary and blocking previously painted nodes', (WidgetTester tester) async {
testWidgetsWithLeakTracking('node is semantic boundary and blocking previously painted nodes', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);
final GlobalKey stackKey = GlobalKey();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
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';

import 'semantics_tester.dart';

void main() {
testWidgets('Semantics can merge sibling group', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Semantics can merge sibling group', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);
const SemanticsTag first = SemanticsTag('1');
const SemanticsTag second = SemanticsTag('2');
Expand Down Expand Up @@ -74,7 +75,7 @@ void main() {
semantics.dispose();
});

testWidgets('Semantics can drop semantics config', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Semantics can drop semantics config', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);
const SemanticsTag first = SemanticsTag('1');
const SemanticsTag second = SemanticsTag('2');
Expand Down Expand Up @@ -132,7 +133,7 @@ void main() {
semantics.dispose();
});

testWidgets('Semantics throws when mark the same config twice case 1', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Semantics throws when mark the same config twice case 1', (WidgetTester tester) async {
const SemanticsTag first = SemanticsTag('1');
const SemanticsTag second = SemanticsTag('2');
const SemanticsTag third = SemanticsTag('3');
Expand Down Expand Up @@ -178,7 +179,7 @@ void main() {
expect(tester.takeException(), isAssertionError);
});

testWidgets('Semantics throws when mark the same config twice case 2', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Semantics throws when mark the same config twice case 2', (WidgetTester tester) async {
const SemanticsTag first = SemanticsTag('1');
const SemanticsTag second = SemanticsTag('2');
const SemanticsTag third = SemanticsTag('3');
Expand Down Expand Up @@ -224,7 +225,7 @@ void main() {
expect(tester.takeException(), isAssertionError);
});

testWidgets('RenderObject with semantics child delegate will mark correct boundary dirty', (WidgetTester tester) async {
testWidgetsWithLeakTracking('RenderObject with semantics child delegate will mark correct boundary dirty', (WidgetTester tester) async {
final UniqueKey inner = UniqueKey();
final UniqueKey boundaryParent = UniqueKey();
final UniqueKey grandBoundaryParent = UniqueKey();
Expand Down
5 changes: 3 additions & 2 deletions packages/flutter/test/widgets/semantics_clipping_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
import 'package:flutter/material.dart';
import 'package:flutter/widgets.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('SemanticNode.rect is clipped', (WidgetTester tester) async {
testWidgetsWithLeakTracking('SemanticNode.rect is clipped', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);

await tester.pumpWidget(const Directionality(
Expand Down Expand Up @@ -67,7 +68,7 @@ void main() {
semantics.dispose();
});

testWidgets('SemanticsNode is not removed if out of bounds and merged into something within bounds', (WidgetTester tester) async {
testWidgetsWithLeakTracking('SemanticsNode is not removed if out of bounds and merged into something within bounds', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);

await tester.pumpWidget(const Directionality(
Expand Down
Loading

0 comments on commit c3db020

Please sign in to comment.