Skip to content

Commit

Permalink
[image_picker_ios] Fix FLTPHPickerSaveImageToPathOperation property a…
Browse files Browse the repository at this point in the history
…ttributes (flutter#6890)

* [image_picker_ios] Fix FLTPHPickerSaveImageToPathOperation property attributes

* Format

* Replace removed wait
  • Loading branch information
jmagman authored Jan 3, 2023
1 parent 42f8093 commit f9dda6a
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 144 deletions.
6 changes: 5 additions & 1 deletion packages/image_picker/image_picker_ios/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
## 0.8.6+5

* Fixes crash when `imageQuality` is set.

## 0.8.6+4

* Fix authorization status check for iOS14+ so it includes `PHAuthorizationStatusLimited`.
* Fixes authorization status check for iOS14+ so it includes `PHAuthorizationStatusLimited`.

## 0.8.6+3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,6 @@
ReferencedContainer = "container:Runner.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "BE7AEE6B26403C46006181AA"
BuildableName = "RunnerUITestiOS14.xctest"
BlueprintName = "RunnerUITestiOS14"
ReferencedContainer = "container:Runner.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ - (void)testPluginPickImageDeviceBack {
camera:FLTSourceCameraRear]
maxSize:[[FLTMaxSize alloc] init]
quality:nil
fullMetadata:@(YES)
fullMetadata:@YES
completion:^(NSString *_Nullable result, FlutterError *_Nullable error){
}];

Expand Down Expand Up @@ -89,7 +89,7 @@ - (void)testPluginPickImageDeviceFront {
camera:FLTSourceCameraFront]
maxSize:[[FLTMaxSize alloc] init]
quality:nil
fullMetadata:@(YES)
fullMetadata:@YES
completion:^(NSString *_Nullable result, FlutterError *_Nullable error){
}];

Expand Down Expand Up @@ -174,7 +174,7 @@ - (void)testPickMultiImageShouldUseUIImagePickerControllerOnPreiOS14 {

[plugin pickMultiImageWithMaxSize:[FLTMaxSize makeWithWidth:@(100) height:@(200)]
quality:@(50)
fullMetadata:@(YES)
fullMetadata:@YES
completion:^(NSArray<NSString *> *_Nullable result,
FlutterError *_Nullable error){
}];
Expand All @@ -193,7 +193,7 @@ - (void)testPickImageWithoutFullMetadata API_AVAILABLE(ios(11)) {
camera:FLTSourceCameraFront]
maxSize:[[FLTMaxSize alloc] init]
quality:nil
fullMetadata:@(NO)
fullMetadata:@NO
completion:^(NSString *_Nullable result, FlutterError *_Nullable error){
}];

Expand All @@ -209,7 +209,7 @@ - (void)testPickMultiImageWithoutFullMetadata API_AVAILABLE(ios(11)) {

[plugin pickMultiImageWithMaxSize:[[FLTMaxSize alloc] init]
quality:nil
fullMetadata:@(NO)
fullMetadata:@NO
completion:^(NSArray<NSString *> *_Nullable result,
FlutterError *_Nullable error){
}];
Expand All @@ -231,7 +231,7 @@ - (void)testPluginPickImageDeviceCancelClickMultipleTimes {
camera:FLTSourceCameraRear]
maxSize:[[FLTMaxSize alloc] init]
quality:nil
fullMetadata:@(YES)
fullMetadata:@YES
completion:^(NSString *_Nullable result, FlutterError *_Nullable error){
}];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ - (void)testSavePNGImageWithoutFullMetadata API_AVAILABLE(ios(14)) {
* Creates a mock picker result using NSItemProvider.
*
* @param itemProvider an item provider that will be used as picker result
* @param identifier local identifier of the asset
*/
- (PHPickerResult *)createPickerResultWithProvider:(NSItemProvider *)itemProvider
API_AVAILABLE(ios(14)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,103 +59,96 @@ - (void)tearDown {
[self.app terminate];
}

- (void)testPickingFromGallery {
[self launchPickerAndPick];
}

- (void)testCancel {
[self launchPickerAndCancel];
}

- (void)launchPickerAndCancel {
// Find and tap on the pick from gallery button.
NSPredicate *predicateToFindImageFromGalleryButton =
[NSPredicate predicateWithFormat:@"label == %@", @"image_picker_example_from_gallery"];

XCUIElement *imageFromGalleryButton =
[self.app.otherElements elementMatchingPredicate:predicateToFindImageFromGalleryButton];
self.app.otherElements[@"image_picker_example_from_gallery"].firstMatch;
if (![imageFromGalleryButton waitForExistenceWithTimeout:kElementWaitingTime]) {
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription);
XCTFail(@"Failed due to not able to find image from gallery button with %@ seconds",
@(kElementWaitingTime));
}

XCTAssertTrue(imageFromGalleryButton.exists);
[imageFromGalleryButton tap];

// Find and tap on the `pick` button.
NSPredicate *predicateToFindPickButton =
[NSPredicate predicateWithFormat:@"label == %@", @"PICK"];

XCUIElement *pickButton = [self.app.buttons elementMatchingPredicate:predicateToFindPickButton];
XCUIElement *pickButton = self.app.buttons[@"PICK"].firstMatch;
if (![pickButton waitForExistenceWithTimeout:kElementWaitingTime]) {
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription);
XCTFail(@"Failed due to not able to find pick button with %@ seconds", @(kElementWaitingTime));
}

XCTAssertTrue(pickButton.exists);
[pickButton tap];

// There is a known bug where the permission popups interruption won't get fired until a tap
// happened in the app. We expect a permission popup so we do a tap here.
[self.app tap];

// Find and tap on the `Cancel` button.
NSPredicate *predicateToFindCancelButton =
[NSPredicate predicateWithFormat:@"label == %@", @"Cancel"];

XCUIElement *cancelButton =
[self.app.buttons elementMatchingPredicate:predicateToFindCancelButton];
XCUIElement *cancelButton = self.app.buttons[@"Cancel"].firstMatch;
if (![cancelButton waitForExistenceWithTimeout:kElementWaitingTime]) {
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription);
XCTFail(@"Failed due to not able to find Cancel button with %@ seconds",
@(kElementWaitingTime));
}

XCTAssertTrue(cancelButton.exists);
[cancelButton tap];

// Find the "not picked image text".
XCUIElement *imageNotPickedText = [self.app.staticTexts
elementMatchingPredicate:[NSPredicate
predicateWithFormat:@"label == %@",
@"You have not yet picked an image."]];
XCUIElement *imageNotPickedText =
self.app.staticTexts[@"You have not yet picked an image."].firstMatch;
if (![imageNotPickedText waitForExistenceWithTimeout:kElementWaitingTime]) {
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription);
XCTFail(@"Failed due to not able to find imageNotPickedText with %@ seconds",
@(kElementWaitingTime));
}
}

XCTAssertTrue(imageNotPickedText.exists);
- (void)testPickingFromGallery {
[self launchPickerAndPickWithMaxWidth:nil maxHeight:nil quality:nil];
}

- (void)launchPickerAndPick {
// Find and tap on the pick from gallery button.
NSPredicate *predicateToFindImageFromGalleryButton =
[NSPredicate predicateWithFormat:@"label == %@", @"image_picker_example_from_gallery"];
- (void)testPickingWithContraintsFromGallery {
[self launchPickerAndPickWithMaxWidth:@200 maxHeight:@100 quality:@50];
}

- (void)launchPickerAndPickWithMaxWidth:(NSNumber *)maxWidth
maxHeight:(NSNumber *)maxHeight
quality:(NSNumber *)quality {
// Find and tap on the pick from gallery button.
XCUIElement *imageFromGalleryButton =
[self.app.otherElements elementMatchingPredicate:predicateToFindImageFromGalleryButton];
self.app.otherElements[@"image_picker_example_from_gallery"].firstMatch;
if (![imageFromGalleryButton waitForExistenceWithTimeout:kElementWaitingTime]) {
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription);
XCTFail(@"Failed due to not able to find image from gallery button with %@ seconds",
@(kElementWaitingTime));
}

XCTAssertTrue(imageFromGalleryButton.exists);
[imageFromGalleryButton tap];

// Find and tap on the `pick` button.
NSPredicate *predicateToFindPickButton =
[NSPredicate predicateWithFormat:@"label == %@", @"PICK"];
if (maxWidth != nil) {
XCUIElement *field = self.app.textFields[@"Enter maxWidth if desired"].firstMatch;
[field tap];
[field typeText:maxWidth.stringValue];
}

if (maxHeight != nil) {
XCUIElement *field = self.app.textFields[@"Enter maxHeight if desired"].firstMatch;
[field tap];
[field typeText:maxHeight.stringValue];
}

XCUIElement *pickButton = [self.app.buttons elementMatchingPredicate:predicateToFindPickButton];
if (quality != nil) {
XCUIElement *field = self.app.textFields[@"Enter quality if desired"].firstMatch;
[field tap];
[field typeText:quality.stringValue];
}

// Find and tap on the `pick` button.
XCUIElement *pickButton = self.app.buttons[@"PICK"].firstMatch;
if (![pickButton waitForExistenceWithTimeout:kElementWaitingTime]) {
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription);
XCTFail(@"Failed due to not able to find pick button with %@ seconds", @(kElementWaitingTime));
}

XCTAssertTrue(pickButton.exists);
[pickButton tap];

// There is a known bug where the permission popups interruption won't get fired until a tap
Expand All @@ -167,8 +160,7 @@ - (void)launchPickerAndPick {
if (@available(iOS 14, *)) {
aImage = [self.app.scrollViews.firstMatch.images elementBoundByIndex:1];
} else {
XCUIElement *allPhotosCell = [self.app.cells
elementMatchingPredicate:[NSPredicate predicateWithFormat:@"label == %@", @"All Photos"]];
XCUIElement *allPhotosCell = self.app.cells[@"All Photos"].firstMatch;
if (![allPhotosCell waitForExistenceWithTimeout:kElementWaitingTime]) {
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription);
XCTFail(@"Failed due to not able to find \"All Photos\" cell with %@ seconds",
Expand All @@ -184,20 +176,14 @@ - (void)launchPickerAndPick {
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription);
XCTFail(@"Failed due to not able to find an image with %@ seconds", @(kElementWaitingTime));
}
XCTAssertTrue(aImage.exists);
[aImage tap];

// Find the picked image.
NSPredicate *predicateToFindPickedImage =
[NSPredicate predicateWithFormat:@"label == %@", @"image_picker_example_picked_image"];

XCUIElement *pickedImage = [self.app.images elementMatchingPredicate:predicateToFindPickedImage];
XCUIElement *pickedImage = self.app.images[@"image_picker_example_picked_image"].firstMatch;
if (![pickedImage waitForExistenceWithTimeout:kElementWaitingTime]) {
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription);
XCTFail(@"Failed due to not able to find pickedImage with %@ seconds", @(kElementWaitingTime));
}

XCTAssertTrue(pickedImage.exists);
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -46,126 +46,67 @@ - (void)tearDown {
[self.app terminate];
}

- (void)testSelectingFromGallery {
// Test the `Select Photos` button which is available after iOS 14.
if (@available(iOS 14, *)) {
[self launchPickerAndSelect];
} else {
return;
}
}

- (void)launchPickerAndSelect {
// Test the `Select Photos` button which is available after iOS 14.
- (void)testSelectingFromGallery API_AVAILABLE(ios(14)) {
// Find and tap on the pick from gallery button.
NSPredicate *predicateToFindImageFromGalleryButton =
[NSPredicate predicateWithFormat:@"label == %@", @"image_picker_example_from_gallery"];

XCUIElement *imageFromGalleryButton =
[self.app.otherElements elementMatchingPredicate:predicateToFindImageFromGalleryButton];
self.app.otherElements[@"image_picker_example_from_gallery"].firstMatch;
if (![imageFromGalleryButton waitForExistenceWithTimeout:kLimitedElementWaitingTime]) {
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription);
XCTFail(@"Failed due to not able to find image from gallery button with %@ seconds",
@(kLimitedElementWaitingTime));
}

XCTAssertTrue(imageFromGalleryButton.exists);
[imageFromGalleryButton tap];

// Find and tap on the `pick` button.
NSPredicate *predicateToFindPickButton =
[NSPredicate predicateWithFormat:@"label == %@", @"PICK"];

XCUIElement *pickButton = [self.app.buttons elementMatchingPredicate:predicateToFindPickButton];
XCUIElement *pickButton = self.app.buttons[@"PICK"].firstMatch;
if (![pickButton waitForExistenceWithTimeout:kLimitedElementWaitingTime]) {
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription);
XCTSkip(@"Pick button isn't found so the test is skipped...");
}

XCTAssertTrue(pickButton.exists);
[pickButton tap];

// There is a known bug where the permission popups interruption won't get fired until a tap
// happened in the app. We expect a permission popup so we do a tap here.
[self.app tap];

// Find an image and tap on it. (IOS 14 UI, images are showing directly)
XCUIElement *aImage;
if (@available(iOS 14, *)) {
aImage = [self.app.scrollViews.firstMatch.images elementBoundByIndex:1];
} else {
XCUIElement *selectedPhotosCell = [self.app.cells
elementMatchingPredicate:[NSPredicate
predicateWithFormat:@"label == %@", @"Selected Photos"]];
if (![selectedPhotosCell waitForExistenceWithTimeout:kLimitedElementWaitingTime]) {
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription);
XCTFail(@"Failed due to not able to find \"Selected Photos\" cell with %@ seconds",
@(kLimitedElementWaitingTime));
}
[selectedPhotosCell tap];
aImage = [self.app.collectionViews elementMatchingType:XCUIElementTypeCollectionView
identifier:@"PhotosGridView"]
.cells.firstMatch;
}
// Find an image and tap on it.
XCUIElement *aImage = [self.app.scrollViews.firstMatch.images elementBoundByIndex:1];
os_log_error(OS_LOG_DEFAULT, "description before picking image %@", self.app.debugDescription);
if (![aImage waitForExistenceWithTimeout:kLimitedElementWaitingTime]) {
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription);
XCTFail(@"Failed due to not able to find an image with %@ seconds",
@(kLimitedElementWaitingTime));
}
XCTAssertTrue(aImage.exists);

[aImage tap];

// Find and tap on the `Done` button.
NSPredicate *predicateToFindDoneButton =
[NSPredicate predicateWithFormat:@"label == %@", @"Done"];

XCUIElement *doneButton = [self.app.buttons elementMatchingPredicate:predicateToFindDoneButton];
XCUIElement *doneButton = self.app.buttons[@"Done"].firstMatch;
if (![doneButton waitForExistenceWithTimeout:kLimitedElementWaitingTime]) {
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription);
XCTSkip(@"Permissions popup could not fired so the test is skipped...");
}

XCTAssertTrue(doneButton.exists);
[doneButton tap];

// Find an image and tap on it to have access to selected photos.
if (@available(iOS 14, *)) {
aImage = [self.app.scrollViews.firstMatch.images elementBoundByIndex:1];
} else {
XCUIElement *selectedPhotosCell = [self.app.cells
elementMatchingPredicate:[NSPredicate
predicateWithFormat:@"label == %@", @"Selected Photos"]];
if (![selectedPhotosCell waitForExistenceWithTimeout:kLimitedElementWaitingTime]) {
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription);
XCTFail(@"Failed due to not able to find \"Selected Photos\" cell with %@ seconds",
@(kLimitedElementWaitingTime));
}
[selectedPhotosCell tap];
aImage = [self.app.collectionViews elementMatchingType:XCUIElementTypeCollectionView
identifier:@"PhotosGridView"]
.cells.firstMatch;
}
aImage = [self.app.scrollViews.firstMatch.images elementBoundByIndex:1];

os_log_error(OS_LOG_DEFAULT, "description before picking image %@", self.app.debugDescription);
if (![aImage waitForExistenceWithTimeout:kLimitedElementWaitingTime]) {
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription);
XCTFail(@"Failed due to not able to find an image with %@ seconds",
@(kLimitedElementWaitingTime));
}
XCTAssertTrue(aImage.exists);
[aImage tap];

// Find the picked image.
NSPredicate *predicateToFindPickedImage =
[NSPredicate predicateWithFormat:@"label == %@", @"image_picker_example_picked_image"];

XCUIElement *pickedImage = [self.app.images elementMatchingPredicate:predicateToFindPickedImage];
XCUIElement *pickedImage = self.app.images[@"image_picker_example_picked_image"].firstMatch;
if (![pickedImage waitForExistenceWithTimeout:kLimitedElementWaitingTime]) {
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription);
XCTFail(@"Failed due to not able to find pickedImage with %@ seconds",
@(kLimitedElementWaitingTime));
}

XCTAssertTrue(pickedImage.exists);
}

@end
Loading

0 comments on commit f9dda6a

Please sign in to comment.