-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[image_picker] Image picker fix camera device #3898
Changes from all commits
fd62211
aaa4a39
9c021ad
877b0d8
3a75fe8
00213eb
5b7ff47
b548492
9b8b882
4ffe307
2313548
00ae1ff
30d61c7
ceb2577
4398ae6
22b684a
c93a157
3760e13
72bdca4
23f4d8a
f8fa19d
b5710fb
dc7c3b6
8ef3516
3f7d062
311caf5
04b8e74
46c1e7d
c27a3f3
397f053
27df40e
b24e5c0
1c3db4c
9277b82
290ca88
7467883
0ec6cc8
6b82355
9ffa039
bf8bd36
5a14280
6fe570f
4927206
84b3e65
6294377
2800919
b0022f6
8108389
5d7181b
e65ce44
8634c68
307757c
a2b22d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
|
||
@import image_picker; | ||
@import XCTest; | ||
#import <OCMock/OCMock.h> | ||
|
||
@interface MockViewController : UIViewController | ||
@property(nonatomic, retain) UIViewController *mockPresented; | ||
|
@@ -27,90 +28,152 @@ - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker; | |
@end | ||
|
||
@interface ImagePickerPluginTests : XCTestCase | ||
@property(readonly, nonatomic) id mockUIImagePicker; | ||
@property(readonly, nonatomic) id mockAVCaptureDevice; | ||
@end | ||
|
||
@implementation ImagePickerPluginTests | ||
|
||
#pragma mark - Test camera devices, no op on simulators | ||
- (void)setUp { | ||
_mockUIImagePicker = OCMClassMock([UIImagePickerController class]); | ||
_mockAVCaptureDevice = OCMClassMock([AVCaptureDevice class]); | ||
} | ||
|
||
- (void)testPluginPickImageDeviceBack { | ||
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { | ||
return; | ||
} | ||
// UIImagePickerControllerSourceTypeCamera is supported | ||
OCMStub(ClassMethod( | ||
[_mockUIImagePicker isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])) | ||
.andReturn(YES); | ||
|
||
// UIImagePickerControllerCameraDeviceRear is supported | ||
OCMStub(ClassMethod( | ||
[_mockUIImagePicker isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear])) | ||
.andReturn(YES); | ||
|
||
// AVAuthorizationStatusAuthorized is supported | ||
OCMStub([_mockAVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]) | ||
.andReturn(AVAuthorizationStatusAuthorized); | ||
|
||
// Run test | ||
FLTImagePickerPlugin *plugin = [FLTImagePickerPlugin new]; | ||
FlutterMethodCall *call = | ||
[FlutterMethodCall methodCallWithMethodName:@"pickImage" | ||
arguments:@{@"source" : @(0), @"cameraDevice" : @(0)}]; | ||
[plugin handleMethodCall:call | ||
result:^(id _Nullable r){ | ||
}]; | ||
|
||
XCTAssertEqual([plugin getImagePickerController].cameraDevice, | ||
UIImagePickerControllerCameraDeviceRear); | ||
} | ||
|
||
- (void)testPluginPickImageDeviceFront { | ||
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { | ||
return; | ||
} | ||
// UIImagePickerControllerSourceTypeCamera is supported | ||
OCMStub(ClassMethod( | ||
[_mockUIImagePicker isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])) | ||
.andReturn(YES); | ||
|
||
// UIImagePickerControllerCameraDeviceFront is supported | ||
OCMStub(ClassMethod([_mockUIImagePicker | ||
isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront])) | ||
.andReturn(YES); | ||
|
||
// AVAuthorizationStatusAuthorized is supported | ||
OCMStub([_mockAVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]) | ||
.andReturn(AVAuthorizationStatusAuthorized); | ||
|
||
// Run test | ||
FLTImagePickerPlugin *plugin = [FLTImagePickerPlugin new]; | ||
FlutterMethodCall *call = | ||
[FlutterMethodCall methodCallWithMethodName:@"pickImage" | ||
arguments:@{@"source" : @(0), @"cameraDevice" : @(1)}]; | ||
[plugin handleMethodCall:call | ||
result:^(id _Nullable r){ | ||
}]; | ||
|
||
XCTAssertEqual([plugin getImagePickerController].cameraDevice, | ||
UIImagePickerControllerCameraDeviceFront); | ||
} | ||
|
||
- (void)testPluginPickVideoDeviceBack { | ||
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { | ||
return; | ||
} | ||
// UIImagePickerControllerSourceTypeCamera is supported | ||
OCMStub(ClassMethod( | ||
[_mockUIImagePicker isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])) | ||
.andReturn(YES); | ||
|
||
// UIImagePickerControllerCameraDeviceRear is supported | ||
OCMStub(ClassMethod( | ||
[_mockUIImagePicker isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear])) | ||
.andReturn(YES); | ||
|
||
// AVAuthorizationStatusAuthorized is supported | ||
OCMStub([_mockAVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]) | ||
.andReturn(AVAuthorizationStatusAuthorized); | ||
|
||
// Run test | ||
FLTImagePickerPlugin *plugin = [FLTImagePickerPlugin new]; | ||
FlutterMethodCall *call = | ||
[FlutterMethodCall methodCallWithMethodName:@"pickVideo" | ||
arguments:@{@"source" : @(0), @"cameraDevice" : @(0)}]; | ||
[plugin handleMethodCall:call | ||
result:^(id _Nullable r){ | ||
}]; | ||
|
||
XCTAssertEqual([plugin getImagePickerController].cameraDevice, | ||
UIImagePickerControllerCameraDeviceRear); | ||
} | ||
|
||
- (void)testPluginPickImageDeviceCancelClickMultipleTimes { | ||
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { | ||
return; | ||
} | ||
- (void)testPluginPickVideoDeviceFront { | ||
// UIImagePickerControllerSourceTypeCamera is supported | ||
OCMStub(ClassMethod( | ||
[_mockUIImagePicker isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])) | ||
.andReturn(YES); | ||
|
||
// UIImagePickerControllerCameraDeviceFront is supported | ||
OCMStub(ClassMethod([_mockUIImagePicker | ||
isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront])) | ||
.andReturn(YES); | ||
|
||
// AVAuthorizationStatusAuthorized is supported | ||
OCMStub([_mockAVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]) | ||
.andReturn(AVAuthorizationStatusAuthorized); | ||
|
||
// Run test | ||
FLTImagePickerPlugin *plugin = [FLTImagePickerPlugin new]; | ||
FlutterMethodCall *call = | ||
[FlutterMethodCall methodCallWithMethodName:@"pickImage" | ||
[FlutterMethodCall methodCallWithMethodName:@"pickVideo" | ||
arguments:@{@"source" : @(0), @"cameraDevice" : @(1)}]; | ||
[plugin handleMethodCall:call | ||
result:^(id _Nullable r){ | ||
}]; | ||
plugin.result = ^(id result) { | ||
|
||
}; | ||
[plugin imagePickerControllerDidCancel:[plugin getImagePickerController]]; | ||
[plugin imagePickerControllerDidCancel:[plugin getImagePickerController]]; | ||
XCTAssertEqual([plugin getImagePickerController].cameraDevice, | ||
UIImagePickerControllerCameraDeviceFront); | ||
} | ||
|
||
- (void)testPluginPickVideoDeviceFront { | ||
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { | ||
#pragma mark - Test camera devices, no op on simulators | ||
ydag marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- (void)testPluginPickImageDeviceCancelClickMultipleTimes { | ||
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you aborting the test if the camera is available? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi Stuart, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cyanglaz Was this a bug, or is this intentionally only supposed to run on simulator? That seems bizarre. |
||
return; | ||
} | ||
FLTImagePickerPlugin *plugin = [FLTImagePickerPlugin new]; | ||
FlutterMethodCall *call = | ||
[FlutterMethodCall methodCallWithMethodName:@"pickVideo" | ||
[FlutterMethodCall methodCallWithMethodName:@"pickImage" | ||
arguments:@{@"source" : @(0), @"cameraDevice" : @(1)}]; | ||
[plugin handleMethodCall:call | ||
result:^(id _Nullable r){ | ||
}]; | ||
XCTAssertEqual([plugin getImagePickerController].cameraDevice, | ||
UIImagePickerControllerCameraDeviceFront); | ||
plugin.result = ^(id result) { | ||
|
||
}; | ||
// To ensure the flow does not crash by multiple cancel call | ||
[plugin imagePickerControllerDidCancel:[plugin getImagePickerController]]; | ||
[plugin imagePickerControllerDidCancel:[plugin getImagePickerController]]; | ||
stuartmorgan-g marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
ydag marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#pragma mark - Test video duration | ||
|
||
- (void)testPickingVideoWithDuration { | ||
FLTImagePickerPlugin *plugin = [FLTImagePickerPlugin new]; | ||
FlutterMethodCall *call = [FlutterMethodCall | ||
|
Uh oh!
There was an error while loading. Please reload this page.