Unverified Commit a3362a9f authored by Polina Cherkasova's avatar Polina Cherkasova Committed by GitHub

MaterialStatesController should dispatch creation in constructor. (#133826)

This PR also updates other tests to use matcher.
parent 80f737d1
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.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() {
test('MaterialStatesController constructor', () { test('MaterialStatesController constructor', () {
...@@ -12,6 +13,10 @@ void main() { ...@@ -12,6 +13,10 @@ void main() {
expect(MaterialStatesController(<MaterialState>{MaterialState.selected}).value, <MaterialState>{MaterialState.selected}); expect(MaterialStatesController(<MaterialState>{MaterialState.selected}).value, <MaterialState>{MaterialState.selected});
}); });
test('MaterialStatesController dispatches memory events', () {
expect(()=> MaterialStatesController().dispose(), dispatchesMemoryEvents(MaterialStatesController));
});
test('MaterialStatesController update, listener', () { test('MaterialStatesController update, listener', () {
int count = 0; int count = 0;
void valueChanged() { void valueChanged() {
......
...@@ -11,6 +11,7 @@ import 'package:flutter/rendering.dart'; ...@@ -11,6 +11,7 @@ import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.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 GlobalKey widgetKey = GlobalKey(); final GlobalKey widgetKey = GlobalKey();
...@@ -1610,38 +1611,11 @@ void main() { ...@@ -1610,38 +1611,11 @@ void main() {
}); });
test('$FocusManager dispatches object creation in constructor', () { test('$FocusManager dispatches object creation in constructor', () {
final List<ObjectEvent> events = <ObjectEvent>[]; expect(()=> FocusManager().dispose(), dispatchesMemoryEvents(FocusManager));
void listener(ObjectEvent event) {
if (event.object.runtimeType == FocusManager) {
events.add(event);
}
}
MemoryAllocations.instance.addListener(listener);
final FocusManager focusManager = FocusManager();
expect(events, hasLength(1));
focusManager.dispose();
MemoryAllocations.instance.removeListener(listener);
}); });
test('$FocusNode dispatches object creation in constructor', () { test('$FocusNode dispatches object creation in constructor', () {
final List<ObjectEvent> events = <ObjectEvent>[]; expect(()=> FocusNode().dispose(), dispatchesMemoryEvents(FocusNode));
void listener(ObjectEvent event) {
if (event.object.runtimeType == FocusNode) {
events.add(event);
}
}
MemoryAllocations.instance.addListener(listener);
final FocusNode focusManager = FocusNode();
expect(events, hasLength(1));
focusManager.dispose();
MemoryAllocations.instance.removeListener(listener);
}); });
testWidgets('FocusManager notifies listeners when a widget loses focus because it was removed.', (WidgetTester tester) async { testWidgets('FocusManager notifies listeners when a widget loses focus because it was removed.', (WidgetTester tester) async {
......
...@@ -8,6 +8,7 @@ import 'package:flutter/foundation.dart'; ...@@ -8,6 +8,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.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() {
testWidgets('Simple router basic functionality - synchronized', (WidgetTester tester) async { testWidgets('Simple router basic functionality - synchronized', (WidgetTester tester) async {
...@@ -1584,18 +1585,13 @@ testWidgets('ChildBackButtonDispatcher take priority recursively', (WidgetTester ...@@ -1584,18 +1585,13 @@ testWidgets('ChildBackButtonDispatcher take priority recursively', (WidgetTester
}); });
test('$PlatformRouteInformationProvider dispatches object creation in constructor', () { test('$PlatformRouteInformationProvider dispatches object creation in constructor', () {
int eventCount = 0; void createAndDispose() {
void listener(ObjectEvent event) => eventCount++; PlatformRouteInformationProvider(
MemoryAllocations.instance.addListener(listener);
final PlatformRouteInformationProvider registry = PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation(uri: Uri.parse('http://google.com')), initialRouteInformation: RouteInformation(uri: Uri.parse('http://google.com')),
); ).dispose();
}
expect(eventCount, 1);
registry.dispose(); expect(createAndDispose, dispatchesMemoryEvents(PlatformRouteInformationProvider));
MemoryAllocations.instance.removeListener(listener);
}); });
} }
......
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
import 'dart:ui' as ui; import 'dart:ui' as ui;
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.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';
import 'states.dart'; import 'states.dart';
...@@ -396,19 +396,6 @@ void main() { ...@@ -396,19 +396,6 @@ void main() {
}); });
test('$ScrollController dispatches object creation in constructor', () { test('$ScrollController dispatches object creation in constructor', () {
final List<ObjectEvent> events = <ObjectEvent>[]; expect(()=> ScrollController().dispose(), dispatchesMemoryEvents(ScrollController));
void listener(ObjectEvent event) {
if (event.object.runtimeType == ScrollController) {
events.add(event);
}
}
MemoryAllocations.instance.addListener(listener);
final ScrollController controller = ScrollController();
expect(events, hasLength(1));
controller.dispose();
MemoryAllocations.instance.removeListener(listener);
}); });
} }
...@@ -6,6 +6,7 @@ import 'package:flutter/foundation.dart'; ...@@ -6,6 +6,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.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() {
group(LogicalKeySet, () { group(LogicalKeySet, () {
...@@ -667,16 +668,7 @@ void main() { ...@@ -667,16 +668,7 @@ void main() {
}); });
test('$ShortcutManager dispatches object creation in constructor', () { test('$ShortcutManager dispatches object creation in constructor', () {
int eventCount = 0; expect(()=> ShortcutManager().dispose(), dispatchesMemoryEvents(ShortcutManager));
void listener(ObjectEvent event) => eventCount++;
MemoryAllocations.instance.addListener(listener);
final ShortcutManager registry = ShortcutManager();
expect(eventCount, 1);
registry.dispose();
MemoryAllocations.instance.removeListener(listener);
}); });
testWidgets("Shortcuts passes to the next Shortcuts widget if it doesn't map the key", (WidgetTester tester) async { testWidgets("Shortcuts passes to the next Shortcuts widget if it doesn't map the key", (WidgetTester tester) async {
...@@ -1867,16 +1859,7 @@ void main() { ...@@ -1867,16 +1859,7 @@ void main() {
}); });
test('dispatches object creation in constructor', () { test('dispatches object creation in constructor', () {
int eventCount = 0; expect(()=> ShortcutRegistry().dispose(), dispatchesMemoryEvents(ShortcutRegistry));
void listener(ObjectEvent event) => eventCount++;
MemoryAllocations.instance.addListener(listener);
final ShortcutRegistry registry = ShortcutRegistry();
expect(eventCount, 1);
registry.dispose();
MemoryAllocations.instance.removeListener(listener);
}); });
}); });
} }
......
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