-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[image_picker_ios] Fix FLTPHPickerSaveImageToPathOperation property attributes #6890
Changes from all commits
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 |
---|---|---|
|
@@ -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 | ||
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. There is no such parameter. |
||
*/ | ||
- (PHPickerResult *)createPickerResultWithProvider:(NSItemProvider *)itemProvider | ||
API_AVAILABLE(ios(14)) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,103 +59,96 @@ - (void)tearDown { | |
[self.app terminate]; | ||
} | ||
|
||
- (void)testPickingFromGallery { | ||
[self launchPickerAndPick]; | ||
} | ||
|
||
- (void)testCancel { | ||
[self launchPickerAndCancel]; | ||
} | ||
|
||
- (void)launchPickerAndCancel { | ||
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. Remove unnecessary utility method. |
||
// 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; | ||
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. Prefer subscripting over predicates for easier reading. |
||
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); | ||
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. Don't need to check that it 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) { | ||
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. This tests the fix, and crashes on master without it. |
||
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 | ||
|
@@ -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", | ||
|
@@ -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 |
---|---|---|
|
@@ -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, *)) { | ||
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. Use |
||
[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 { | ||
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. This |
||
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 { | ||
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. Same, dead code. |
||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was removed at some point.