diff --git a/packages/video_player/video_player/pubspec.yaml b/packages/video_player/video_player/pubspec.yaml index c19f6c6f77ca..525d8c274976 100644 --- a/packages/video_player/video_player/pubspec.yaml +++ b/packages/video_player/video_player/pubspec.yaml @@ -33,6 +33,7 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter + leak_tracker_flutter_testing: any topics: - video diff --git a/packages/video_player/video_player/test/flutter_test_config.dart b/packages/video_player/video_player/test/flutter_test_config.dart new file mode 100644 index 000000000000..9907e578b84b --- /dev/null +++ b/packages/video_player/video_player/test/flutter_test_config.dart @@ -0,0 +1,13 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; + +import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart'; + +Future testExecutable(FutureOr Function() testMain) async { + LeakTesting.enable(); + LeakTracking.warnForUnsupportedPlatforms = false; + await testMain(); +} diff --git a/packages/video_player/video_player/test/video_player_test.dart b/packages/video_player/video_player/test/video_player_test.dart index f6eef2448119..1e699efc449e 100644 --- a/packages/video_player/video_player/test/video_player_test.dart +++ b/packages/video_player/video_player/test/video_player_test.dart @@ -131,6 +131,7 @@ void main() { testWidgets('update texture', (WidgetTester tester) async { final FakeController controller = FakeController(); + addTearDown(controller.dispose); await tester.pumpWidget(VideoPlayer(controller)); expect(find.byType(Texture), findsNothing); @@ -146,6 +147,7 @@ void main() { testWidgets('update controller', (WidgetTester tester) async { final FakeController controller1 = FakeController(); + addTearDown(controller1.dispose); controller1.textureId = 101; await tester.pumpWidget(VideoPlayer(controller1)); expect( @@ -155,6 +157,7 @@ void main() { findsOneWidget); final FakeController controller2 = FakeController(); + addTearDown(controller2.dispose); controller2.textureId = 102; await tester.pumpWidget(VideoPlayer(controller2)); expect( @@ -169,6 +172,7 @@ void main() { final FakeController controller = FakeController.value( const VideoPlayerValue( duration: Duration.zero, rotationCorrection: 180)); + addTearDown(controller.dispose); controller.textureId = 1; await tester.pumpWidget(VideoPlayer(controller)); final Transform actualRotationCorrection = @@ -189,6 +193,7 @@ void main() { (WidgetTester tester) async { final FakeController controller = FakeController.value(const VideoPlayerValue(duration: Duration.zero)); + addTearDown(controller.dispose); controller.textureId = 1; await tester.pumpWidget(VideoPlayer(controller)); expect(find.byType(Transform), findsNothing); @@ -315,6 +320,7 @@ void main() { VideoPlayerController.networkUrl( Uri.parse('https://127.0.0.1'), ); + addTearDown(controller.dispose); await controller.initialize(); await controller.play(); verifyPlayStateRespondsToLifecycle(controller, @@ -334,6 +340,7 @@ void main() { test('network url', () async { final VideoPlayerController controller = VideoPlayerController.networkUrl(Uri.parse('https://127.0.0.1')); + addTearDown(controller.dispose); await controller.initialize(); expect( @@ -356,6 +363,7 @@ void main() { Uri.parse('https://127.0.0.1'), formatHint: VideoFormat.dash, ); + addTearDown(controller.dispose); await controller.initialize(); expect( @@ -378,6 +386,7 @@ void main() { Uri.parse('https://127.0.0.1'), httpHeaders: {'Authorization': 'Bearer token'}, ); + addTearDown(controller.dispose); await controller.initialize(); expect( @@ -401,6 +410,7 @@ void main() { final VideoPlayerController controller = VideoPlayerController.networkUrl(invalidUrl); + addTearDown(controller.dispose); late Object error; fakeVideoPlayerPlatform.forceInitError = true; @@ -464,6 +474,7 @@ void main() { () async { final VideoPlayerController controller = VideoPlayerController.networkUrl(_localhostUri); + addTearDown(controller.dispose); fakeVideoPlayerPlatform.forceInitError = true; await controller.initialize().catchError((dynamic e) {}); @@ -485,6 +496,7 @@ void main() { test('dispose', () async { final VideoPlayerController controller = VideoPlayerController.networkUrl(_localhostUri); + addTearDown(controller.dispose); expect( controller.textureId, VideoPlayerController.kUninitializedTextureId); @@ -500,6 +512,7 @@ void main() { test('calling dispose() on disposed controller does not throw', () async { final VideoPlayerController controller = VideoPlayerController.networkUrl(_localhostUri); + addTearDown(controller.dispose); await controller.initialize(); await controller.dispose(); @@ -510,6 +523,7 @@ void main() { test('play', () async { final VideoPlayerController controller = VideoPlayerController.networkUrl(Uri.parse('https://127.0.0.1')); + addTearDown(controller.dispose); await controller.initialize(); expect(controller.value.isPlaying, isFalse); @@ -529,6 +543,7 @@ void main() { test('play before initialized does not call platform', () async { final VideoPlayerController controller = VideoPlayerController.networkUrl(_localhostUri); + addTearDown(controller.dispose); expect(controller.value.isInitialized, isFalse); @@ -540,6 +555,7 @@ void main() { test('play restarts from beginning if video is at end', () async { final VideoPlayerController controller = VideoPlayerController.networkUrl(_localhostUri); + addTearDown(controller.dispose); await controller.initialize(); const Duration nonzeroDuration = Duration(milliseconds: 100); @@ -557,6 +573,7 @@ void main() { test('setLooping', () async { final VideoPlayerController controller = VideoPlayerController.networkUrl(_localhostUri); + addTearDown(controller.dispose); await controller.initialize(); expect(controller.value.isLooping, isFalse); @@ -568,6 +585,7 @@ void main() { test('pause', () async { final VideoPlayerController controller = VideoPlayerController.networkUrl(_localhostUri); + addTearDown(controller.dispose); await controller.initialize(); await controller.play(); @@ -583,6 +601,7 @@ void main() { test('works', () async { final VideoPlayerController controller = VideoPlayerController.networkUrl(_localhostUri); + addTearDown(controller.dispose); await controller.initialize(); expect(await controller.position, Duration.zero); @@ -595,6 +614,7 @@ void main() { test('before initialized does not call platform', () async { final VideoPlayerController controller = VideoPlayerController.networkUrl(_localhostUri); + addTearDown(controller.dispose); expect(controller.value.isInitialized, isFalse); @@ -606,6 +626,7 @@ void main() { test('clamps values that are too high or low', () async { final VideoPlayerController controller = VideoPlayerController.networkUrl(_localhostUri); + addTearDown(controller.dispose); await controller.initialize(); expect(await controller.position, Duration.zero); @@ -622,6 +643,7 @@ void main() { test('works', () async { final VideoPlayerController controller = VideoPlayerController.networkUrl(_localhostUri); + addTearDown(controller.dispose); await controller.initialize(); expect(controller.value.volume, 1.0); @@ -635,6 +657,7 @@ void main() { test('clamps values that are too high or low', () async { final VideoPlayerController controller = VideoPlayerController.networkUrl(_localhostUri); + addTearDown(controller.dispose); await controller.initialize(); expect(controller.value.volume, 1.0); @@ -651,6 +674,7 @@ void main() { test('works', () async { final VideoPlayerController controller = VideoPlayerController.networkUrl(_localhostUri); + addTearDown(controller.dispose); await controller.initialize(); expect(controller.value.playbackSpeed, 1.0); @@ -664,6 +688,7 @@ void main() { test('rejects negative values', () async { final VideoPlayerController controller = VideoPlayerController.networkUrl(_localhostUri); + addTearDown(controller.dispose); await controller.initialize(); expect(controller.value.playbackSpeed, 1.0); @@ -698,6 +723,7 @@ void main() { expect(controller.value.isPlaying, isTrue); await controller.pause(); + await tester.runAsync(controller.dispose); }); testWidgets('does not restart when dragging to end', @@ -723,6 +749,7 @@ void main() { expect(controller.value.position, controller.value.duration); expect(controller.value.isPlaying, isFalse); + await tester.runAsync(controller.dispose); }); }); @@ -733,6 +760,7 @@ void main() { _localhostUri, closedCaptionFile: _loadClosedCaption(), ); + addTearDown(controller.dispose); await controller.initialize(); expect(controller.value.position, Duration.zero); @@ -766,6 +794,7 @@ void main() { _localhostUri, closedCaptionFile: _loadClosedCaption(), ); + addTearDown(controller.dispose); await controller.initialize(); controller.setCaptionOffset(const Duration(milliseconds: 100)); @@ -803,6 +832,7 @@ void main() { _localhostUri, closedCaptionFile: _loadClosedCaption(), ); + addTearDown(controller.dispose); await controller.initialize(); controller.setCaptionOffset(const Duration(milliseconds: -100)); @@ -842,6 +872,7 @@ void main() { VideoPlayerController.networkUrl( _localhostUri, ); + addTearDown(controller.dispose); await controller.initialize(); expect(controller.closedCaptionFile, null); @@ -859,6 +890,7 @@ void main() { _localhostUri, closedCaptionFile: _loadClosedCaption(), ); + addTearDown(controller.dispose); await controller.initialize(); expect( @@ -893,6 +925,7 @@ void main() { expect(controller.value.isPlaying, isFalse); expect(controller.value.position, nonzeroDuration); + await tester.runAsync(controller.dispose); }); testWidgets('playback status', (WidgetTester tester) async { @@ -917,6 +950,7 @@ void main() { )); await tester.pumpAndSettle(); expect(controller.value.isPlaying, isFalse); + await tester.runAsync(controller.dispose); }); testWidgets('buffering status', (WidgetTester tester) async { @@ -953,6 +987,7 @@ void main() { .add(VideoEvent(eventType: VideoEventType.bufferingEnd)); await tester.pumpAndSettle(); expect(controller.value.isBuffering, isFalse); + await tester.runAsync(controller.dispose); }); }); }); @@ -1155,6 +1190,7 @@ void main() { _localhostUri, videoPlayerOptions: VideoPlayerOptions(mixWithOthers: true), ); + addTearDown(controller.dispose); await controller.initialize(); expect(controller.videoPlayerOptions!.mixWithOthers, true); @@ -1167,6 +1203,7 @@ void main() { allowBackgroundPlayback: true, ), ); + addTearDown(controller.dispose); await controller.initialize(); await controller.play(); @@ -1181,6 +1218,7 @@ void main() { _localhostUri, videoPlayerOptions: VideoPlayerOptions(), ); + addTearDown(controller.dispose); await controller.initialize(); await controller.play(); @@ -1211,6 +1249,7 @@ void main() { _localhostUri, videoPlayerOptions: VideoPlayerOptions(), ); + addTearDown(controller.dispose); await controller.initialize(); @@ -1238,6 +1277,7 @@ void main() { _localhostUri, videoPlayerOptions: VideoPlayerOptions(), ); + addTearDown(controller.dispose); await controller.initialize(); @@ -1275,6 +1315,7 @@ void main() { _localhostUri, videoPlayerOptions: VideoPlayerOptions(), ); + addTearDown(controller.dispose); await controller.initialize();