Skip to content

Commit db0ab7a

Browse files
raju-muliyashiyaRaju
authored andcommitted
Added Test cases
1 parent 4c569c5 commit db0ab7a

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

packages/video_player/video_player_avfoundation/darwin/RunnerTests/VideoPlayerTests.m

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,4 +1051,41 @@ - (nonnull AVPlayerItem *)playerItemWithURL:(NSURL *)url {
10511051
return [AVPlayerItem playerItemWithAsset:[AVURLAsset URLAssetWithURL:url options:nil]];
10521052
}
10531053

1054+
- (void)testLoadTracksWithMediaTypeIsCalledOnNewerOS {
1055+
if (@available(iOS 15.0, macOS 12.0, *)) {
1056+
AVAsset *mockAsset = OCMClassMock([AVAsset class]);
1057+
AVPlayerItem *mockItem = OCMClassMock([AVPlayerItem class]);
1058+
OCMStub([mockItem asset]).andReturn(mockAsset);
1059+
1060+
// Stub loadValuesAsynchronouslyForKeys to immediately call completion
1061+
OCMStub([mockAsset loadValuesAsynchronouslyForKeys:[OCMArg any]
1062+
completionHandler:[OCMArg invokeBlock]]);
1063+
1064+
// Stub statusOfValueForKey to return Loaded
1065+
OCMStub([mockAsset statusOfValueForKey:@"tracks" error:[OCMArg anyObjectRef]])
1066+
.andReturn(AVKeyValueStatusLoaded);
1067+
1068+
// Expect loadTracksWithMediaType:completionHandler:
1069+
XCTestExpectation *expectation =
1070+
[self expectationWithDescription:@"loadTracksWithMediaType called"];
1071+
OCMExpect([mockAsset loadTracksWithMediaType:AVMediaTypeVideo completionHandler:[OCMArg any]])
1072+
.andDo(^(NSInvocation *invocation) {
1073+
[expectation fulfill];
1074+
// Invoke the completion handler to prevent leaks or hangs if the code waits for it
1075+
void (^completion)(NSArray<AVAssetTrack *> *, NSError *);
1076+
[invocation getArgument:&completion atIndex:3];
1077+
completion(@[], nil);
1078+
});
1079+
1080+
StubFVPAVFactory *stubAVFactory = [[StubFVPAVFactory alloc] initWithPlayer:nil output:nil];
1081+
FVPVideoPlayer *player =
1082+
[[FVPVideoPlayer alloc] initWithPlayerItem:mockItem
1083+
avFactory:stubAVFactory
1084+
viewProvider:[[StubViewProvider alloc] initWithView:nil]];
1085+
(void)player; // Keep reference
1086+
1087+
[self waitForExpectationsWithTimeout:5.0 handler:nil];
1088+
}
1089+
}
1090+
10541091
@end

0 commit comments

Comments
 (0)