From 57260cb65fdb582569b9b39a7e8fcf4be648d039 Mon Sep 17 00:00:00 2001 From: Abdelaziz Mahdy Date: Tue, 31 Dec 2024 14:56:35 -0400 Subject: [PATCH] test: Add test to verify input captions are unsorted --- .../video_player/test/video_player_test.dart | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) 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 50dc871fa471..d2d5f5ae544c 100644 --- a/packages/video_player/video_player/test/video_player_test.dart +++ b/packages/video_player/video_player/test/video_player_test.dart @@ -749,6 +749,31 @@ void main() { }); group('caption', () { + test('makes sure the input captions are unsorted', () async { + final VideoPlayerController controller = + VideoPlayerController.networkUrl( + _localhostUri, + closedCaptionFile: _loadClosedCaption(), + ); + + await controller.initialize(); + final List captions = + (await controller.closedCaptionFile)!.captions.toList(); + + // Check that captions are not in sorted order + bool isSorted = true; + for (int i = 0; i < captions.length - 1; i++) { + if (captions[i].start.compareTo(captions[i + 1].start) > 0) { + isSorted = false; + break; + } + } + + expect(isSorted, false, reason: 'Expected captions to be unsorted'); + expect(captions.map((Caption c) => c.text).toList(), + ['one', 'two', 'three', 'five', 'four'], + reason: 'Captions should be in original unsorted order'); + }); test('works when seeking, includes all captions', () async { final VideoPlayerController controller = VideoPlayerController.networkUrl(