@@ -704,47 +704,40 @@ - (void)testPickMultiVideoWithoutLimit {
704704- (void )testUIImagePickerImmediateCloseReturnsEmptyArray {
705705 FLTImagePickerPlugin *plugin = [[FLTImagePickerPlugin alloc ] init ];
706706
707- XCTestExpectation *resultExpectation = [self expectationWithDescription: @" result" ];
708-
709- FLTImagePickerMethodCallContext *context = [[FLTImagePickerMethodCallContext alloc ]
710- initWithResult: ^void (NSArray <NSString *> *paths, FlutterError *error) {
711- if (paths == nil || paths.count == 0 ) {
712- XCTAssertNil (error);
713- [resultExpectation fulfill ];
714- }
715- }];
716- context.includeImages = YES ;
717- context.maxSize = [[FLTMaxSize alloc ] init ];
718- context.maxItemCount = 1 ;
719- context.requestFullMetadata = NO ;
720-
721- plugin.callContext = context;
722-
723707 UIImagePickerController *controller = [[UIImagePickerController alloc ] init ];
724- UIView *controllerView = controller.view ;
725-
726- UIView *observerView = [[UIView alloc ] init ];
727- [controllerView addSubview: observerView];
728-
729- void (^removeCallback)(void ) = ^{
730- dispatch_after (dispatch_time (DISPATCH_TIME_NOW, (int64_t )(0.1 * NSEC_PER_SEC)),
731- dispatch_get_main_queue (), ^{
732- if (plugin && plugin.callContext == context && !plugin.isProcessingSelection ) {
733- [plugin sendCallResultWithSavedPathList: nil ];
734- }
735- });
736- };
708+ [plugin setImagePickerControllerOverrides: @[ controller ]];
737709
738- UIWindow *testWindow = [[UIWindow alloc ] initWithFrame: CGRectMake (0 , 0 , 100 , 100 )];
739- testWindow.hidden = NO ;
740- [testWindow addSubview: controllerView];
710+ // Mock camera access to avoid permission dialogs and device-specific logic.
711+ id mockUIImagePicker = OCMClassMock ([UIImagePickerController class ]);
712+ OCMStub (ClassMethod ([mockUIImagePicker isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]))
713+ .andReturn (YES );
714+ OCMStub (ClassMethod ([mockUIImagePicker isCameraDeviceAvailable: UIImagePickerControllerCameraDeviceRear]))
715+ .andReturn (YES );
716+ id mockAVCaptureDevice = OCMClassMock ([AVCaptureDevice class ]);
717+ OCMStub ([mockAVCaptureDevice authorizationStatusForMediaType: AVMediaTypeVideo])
718+ .andReturn (AVAuthorizationStatusAuthorized);
741719
742- [testWindow setNeedsLayout ];
743- [testWindow layoutIfNeeded ];
720+ XCTestExpectation *resultExpectation = [self expectationWithDescription: @" result" ];
744721
745- [controllerView removeFromSuperview ];
722+ FLTSourceSpecification *source = [FLTSourceSpecification makeWithType: FLTSourceTypeCamera
723+ camera: FLTSourceCameraRear];
724+ [plugin pickImageWithSource: source
725+ maxSize: [[FLTMaxSize alloc ] init ]
726+ quality: nil
727+ fullMetadata: NO
728+ completion: ^(NSString *_Nullable result, FlutterError *_Nullable error) {
729+ XCTAssertNil (result);
730+ XCTAssertNil (error);
731+ [resultExpectation fulfill ];
732+ }];
746733
747- removeCallback ();
734+ // The `pickImage` call will attach the observer. Now, simulate dismissal.
735+ // This needs to happen on the next run loop to ensure the observer is attached.
736+ dispatch_async (dispatch_get_main_queue (), ^{
737+ UIWindow *testWindow = [[UIWindow alloc ] init ];
738+ [testWindow addSubview: controller.view];
739+ [controller.view removeFromSuperview ];
740+ });
748741
749742 [self waitForExpectationsWithTimeout: 1.0 handler: nil ];
750743}
0 commit comments