| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- // 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 "ImagePickerTestImages.h"
- @import image_picker;
- @import XCTest;
- @interface MockViewController : UIViewController
- @property(nonatomic, retain) UIViewController *mockPresented;
- @end
- @implementation MockViewController
- @synthesize mockPresented;
- - (UIViewController *)presentedViewController {
- return mockPresented;
- }
- @end
- @interface FLTImagePickerPlugin (Test)
- @property(copy, nonatomic) FlutterResult result;
- - (void)handleSavedPath:(NSString *)path;
- - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker;
- @end
- @interface ImagePickerPluginTests : XCTestCase
- @end
- @implementation ImagePickerPluginTests
- #pragma mark - Test camera devices, no op on simulators
- - (void)testPluginPickImageDeviceBack {
- if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
- return;
- }
- 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;
- }
- 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;
- }
- 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;
- }
- FLTImagePickerPlugin *plugin = [FLTImagePickerPlugin new];
- FlutterMethodCall *call =
- [FlutterMethodCall methodCallWithMethodName:@"pickImage"
- arguments:@{@"source" : @(0), @"cameraDevice" : @(1)}];
- [plugin handleMethodCall:call
- result:^(id _Nullable r){
- }];
- plugin.result = ^(id result) {
- };
- [plugin imagePickerControllerDidCancel:[plugin getImagePickerController]];
- [plugin imagePickerControllerDidCancel:[plugin getImagePickerController]];
- }
- - (void)testPluginPickVideoDeviceFront {
- if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
- return;
- }
- FLTImagePickerPlugin *plugin = [FLTImagePickerPlugin new];
- FlutterMethodCall *call =
- [FlutterMethodCall methodCallWithMethodName:@"pickVideo"
- arguments:@{@"source" : @(0), @"cameraDevice" : @(1)}];
- [plugin handleMethodCall:call
- result:^(id _Nullable r){
- }];
- XCTAssertEqual([plugin getImagePickerController].cameraDevice,
- UIImagePickerControllerCameraDeviceFront);
- }
- #pragma mark - Test video duration
- - (void)testPickingVideoWithDuration {
- FLTImagePickerPlugin *plugin = [FLTImagePickerPlugin new];
- FlutterMethodCall *call = [FlutterMethodCall
- methodCallWithMethodName:@"pickVideo"
- arguments:@{@"source" : @(0), @"cameraDevice" : @(0), @"maxDuration" : @95}];
- [plugin handleMethodCall:call
- result:^(id _Nullable r){
- }];
- XCTAssertEqual([plugin getImagePickerController].videoMaximumDuration, 95);
- }
- - (void)testPluginPickImageSelectMultipleTimes {
- FLTImagePickerPlugin *plugin = [FLTImagePickerPlugin new];
- FlutterMethodCall *call =
- [FlutterMethodCall methodCallWithMethodName:@"pickImage"
- arguments:@{@"source" : @(0), @"cameraDevice" : @(0)}];
- [plugin handleMethodCall:call
- result:^(id _Nullable r){
- }];
- plugin.result = ^(id result) {
- };
- [plugin handleSavedPath:@"test"];
- [plugin handleSavedPath:@"test"];
- }
- - (void)testViewController {
- UIWindow *window = [UIWindow new];
- MockViewController *vc1 = [MockViewController new];
- window.rootViewController = vc1;
- UIViewController *vc2 = [UIViewController new];
- vc1.mockPresented = vc2;
- FLTImagePickerPlugin *plugin = [FLTImagePickerPlugin new];
- XCTAssertEqual([plugin viewControllerWithWindow:window], vc2);
- }
- @end
|