Skip to content

Commit f9dda6a

Browse files
authored
[image_picker_ios] Fix FLTPHPickerSaveImageToPathOperation property attributes (flutter#6890)
* [image_picker_ios] Fix FLTPHPickerSaveImageToPathOperation property attributes * Format * Replace removed wait
1 parent 42f8093 commit f9dda6a

File tree

9 files changed

+64
-144
lines changed

9 files changed

+64
-144
lines changed

packages/image_picker/image_picker_ios/CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
## 0.8.6+5
2+
3+
* Fixes crash when `imageQuality` is set.
4+
15
## 0.8.6+4
26

3-
* Fix authorization status check for iOS14+ so it includes `PHAuthorizationStatusLimited`.
7+
* Fixes authorization status check for iOS14+ so it includes `PHAuthorizationStatusLimited`.
48

59
## 0.8.6+3
610

packages/image_picker/image_picker_ios/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme

-10
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,6 @@
4747
ReferencedContainer = "container:Runner.xcodeproj">
4848
</BuildableReference>
4949
</TestableReference>
50-
<TestableReference
51-
skipped = "NO">
52-
<BuildableReference
53-
BuildableIdentifier = "primary"
54-
BlueprintIdentifier = "BE7AEE6B26403C46006181AA"
55-
BuildableName = "RunnerUITestiOS14.xctest"
56-
BlueprintName = "RunnerUITestiOS14"
57-
ReferencedContainer = "container:Runner.xcodeproj">
58-
</BuildableReference>
59-
</TestableReference>
6050
<TestableReference
6151
skipped = "NO">
6252
<BuildableReference

packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImagePickerPluginTests.m

+6-6
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ - (void)testPluginPickImageDeviceBack {
5656
camera:FLTSourceCameraRear]
5757
maxSize:[[FLTMaxSize alloc] init]
5858
quality:nil
59-
fullMetadata:@(YES)
59+
fullMetadata:@YES
6060
completion:^(NSString *_Nullable result, FlutterError *_Nullable error){
6161
}];
6262

@@ -89,7 +89,7 @@ - (void)testPluginPickImageDeviceFront {
8989
camera:FLTSourceCameraFront]
9090
maxSize:[[FLTMaxSize alloc] init]
9191
quality:nil
92-
fullMetadata:@(YES)
92+
fullMetadata:@YES
9393
completion:^(NSString *_Nullable result, FlutterError *_Nullable error){
9494
}];
9595

@@ -174,7 +174,7 @@ - (void)testPickMultiImageShouldUseUIImagePickerControllerOnPreiOS14 {
174174

175175
[plugin pickMultiImageWithMaxSize:[FLTMaxSize makeWithWidth:@(100) height:@(200)]
176176
quality:@(50)
177-
fullMetadata:@(YES)
177+
fullMetadata:@YES
178178
completion:^(NSArray<NSString *> *_Nullable result,
179179
FlutterError *_Nullable error){
180180
}];
@@ -193,7 +193,7 @@ - (void)testPickImageWithoutFullMetadata API_AVAILABLE(ios(11)) {
193193
camera:FLTSourceCameraFront]
194194
maxSize:[[FLTMaxSize alloc] init]
195195
quality:nil
196-
fullMetadata:@(NO)
196+
fullMetadata:@NO
197197
completion:^(NSString *_Nullable result, FlutterError *_Nullable error){
198198
}];
199199

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

210210
[plugin pickMultiImageWithMaxSize:[[FLTMaxSize alloc] init]
211211
quality:nil
212-
fullMetadata:@(NO)
212+
fullMetadata:@NO
213213
completion:^(NSArray<NSString *> *_Nullable result,
214214
FlutterError *_Nullable error){
215215
}];
@@ -231,7 +231,7 @@ - (void)testPluginPickImageDeviceCancelClickMultipleTimes {
231231
camera:FLTSourceCameraRear]
232232
maxSize:[[FLTMaxSize alloc] init]
233233
quality:nil
234-
fullMetadata:@(YES)
234+
fullMetadata:@YES
235235
completion:^(NSString *_Nullable result, FlutterError *_Nullable error){
236236
}];
237237

packages/image_picker/image_picker_ios/example/ios/RunnerTests/PickerSaveImageToPathOperationTests.m

-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ - (void)testSavePNGImageWithoutFullMetadata API_AVAILABLE(ios(14)) {
184184
* Creates a mock picker result using NSItemProvider.
185185
*
186186
* @param itemProvider an item provider that will be used as picker result
187-
* @param identifier local identifier of the asset
188187
*/
189188
- (PHPickerResult *)createPickerResultWithProvider:(NSItemProvider *)itemProvider
190189
API_AVAILABLE(ios(14)) {

packages/image_picker/image_picker_ios/example/ios/RunnerUITests/ImagePickerFromGalleryUITests.m

+37-51
Original file line numberDiff line numberDiff line change
@@ -59,103 +59,96 @@ - (void)tearDown {
5959
[self.app terminate];
6060
}
6161

62-
- (void)testPickingFromGallery {
63-
[self launchPickerAndPick];
64-
}
65-
6662
- (void)testCancel {
67-
[self launchPickerAndCancel];
68-
}
69-
70-
- (void)launchPickerAndCancel {
7163
// Find and tap on the pick from gallery button.
72-
NSPredicate *predicateToFindImageFromGalleryButton =
73-
[NSPredicate predicateWithFormat:@"label == %@", @"image_picker_example_from_gallery"];
74-
7564
XCUIElement *imageFromGalleryButton =
76-
[self.app.otherElements elementMatchingPredicate:predicateToFindImageFromGalleryButton];
65+
self.app.otherElements[@"image_picker_example_from_gallery"].firstMatch;
7766
if (![imageFromGalleryButton waitForExistenceWithTimeout:kElementWaitingTime]) {
7867
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription);
7968
XCTFail(@"Failed due to not able to find image from gallery button with %@ seconds",
8069
@(kElementWaitingTime));
8170
}
8271

83-
XCTAssertTrue(imageFromGalleryButton.exists);
8472
[imageFromGalleryButton tap];
8573

8674
// Find and tap on the `pick` button.
87-
NSPredicate *predicateToFindPickButton =
88-
[NSPredicate predicateWithFormat:@"label == %@", @"PICK"];
89-
90-
XCUIElement *pickButton = [self.app.buttons elementMatchingPredicate:predicateToFindPickButton];
75+
XCUIElement *pickButton = self.app.buttons[@"PICK"].firstMatch;
9176
if (![pickButton waitForExistenceWithTimeout:kElementWaitingTime]) {
9277
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription);
9378
XCTFail(@"Failed due to not able to find pick button with %@ seconds", @(kElementWaitingTime));
9479
}
9580

96-
XCTAssertTrue(pickButton.exists);
9781
[pickButton tap];
9882

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

10387
// Find and tap on the `Cancel` button.
104-
NSPredicate *predicateToFindCancelButton =
105-
[NSPredicate predicateWithFormat:@"label == %@", @"Cancel"];
106-
107-
XCUIElement *cancelButton =
108-
[self.app.buttons elementMatchingPredicate:predicateToFindCancelButton];
88+
XCUIElement *cancelButton = self.app.buttons[@"Cancel"].firstMatch;
10989
if (![cancelButton waitForExistenceWithTimeout:kElementWaitingTime]) {
11090
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription);
11191
XCTFail(@"Failed due to not able to find Cancel button with %@ seconds",
11292
@(kElementWaitingTime));
11393
}
11494

115-
XCTAssertTrue(cancelButton.exists);
11695
[cancelButton tap];
11796

11897
// Find the "not picked image text".
119-
XCUIElement *imageNotPickedText = [self.app.staticTexts
120-
elementMatchingPredicate:[NSPredicate
121-
predicateWithFormat:@"label == %@",
122-
@"You have not yet picked an image."]];
98+
XCUIElement *imageNotPickedText =
99+
self.app.staticTexts[@"You have not yet picked an image."].firstMatch;
123100
if (![imageNotPickedText waitForExistenceWithTimeout:kElementWaitingTime]) {
124101
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription);
125102
XCTFail(@"Failed due to not able to find imageNotPickedText with %@ seconds",
126103
@(kElementWaitingTime));
127104
}
105+
}
128106

129-
XCTAssertTrue(imageNotPickedText.exists);
107+
- (void)testPickingFromGallery {
108+
[self launchPickerAndPickWithMaxWidth:nil maxHeight:nil quality:nil];
130109
}
131110

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

115+
- (void)launchPickerAndPickWithMaxWidth:(NSNumber *)maxWidth
116+
maxHeight:(NSNumber *)maxHeight
117+
quality:(NSNumber *)quality {
118+
// Find and tap on the pick from gallery button.
137119
XCUIElement *imageFromGalleryButton =
138-
[self.app.otherElements elementMatchingPredicate:predicateToFindImageFromGalleryButton];
120+
self.app.otherElements[@"image_picker_example_from_gallery"].firstMatch;
139121
if (![imageFromGalleryButton waitForExistenceWithTimeout:kElementWaitingTime]) {
140122
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription);
141123
XCTFail(@"Failed due to not able to find image from gallery button with %@ seconds",
142124
@(kElementWaitingTime));
143125
}
144-
145-
XCTAssertTrue(imageFromGalleryButton.exists);
146126
[imageFromGalleryButton tap];
147127

148-
// Find and tap on the `pick` button.
149-
NSPredicate *predicateToFindPickButton =
150-
[NSPredicate predicateWithFormat:@"label == %@", @"PICK"];
128+
if (maxWidth != nil) {
129+
XCUIElement *field = self.app.textFields[@"Enter maxWidth if desired"].firstMatch;
130+
[field tap];
131+
[field typeText:maxWidth.stringValue];
132+
}
133+
134+
if (maxHeight != nil) {
135+
XCUIElement *field = self.app.textFields[@"Enter maxHeight if desired"].firstMatch;
136+
[field tap];
137+
[field typeText:maxHeight.stringValue];
138+
}
151139

152-
XCUIElement *pickButton = [self.app.buttons elementMatchingPredicate:predicateToFindPickButton];
140+
if (quality != nil) {
141+
XCUIElement *field = self.app.textFields[@"Enter quality if desired"].firstMatch;
142+
[field tap];
143+
[field typeText:quality.stringValue];
144+
}
145+
146+
// Find and tap on the `pick` button.
147+
XCUIElement *pickButton = self.app.buttons[@"PICK"].firstMatch;
153148
if (![pickButton waitForExistenceWithTimeout:kElementWaitingTime]) {
154149
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription);
155150
XCTFail(@"Failed due to not able to find pick button with %@ seconds", @(kElementWaitingTime));
156151
}
157-
158-
XCTAssertTrue(pickButton.exists);
159152
[pickButton tap];
160153

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

190181
// Find the picked image.
191-
NSPredicate *predicateToFindPickedImage =
192-
[NSPredicate predicateWithFormat:@"label == %@", @"image_picker_example_picked_image"];
193-
194-
XCUIElement *pickedImage = [self.app.images elementMatchingPredicate:predicateToFindPickedImage];
182+
XCUIElement *pickedImage = self.app.images[@"image_picker_example_picked_image"].firstMatch;
195183
if (![pickedImage waitForExistenceWithTimeout:kElementWaitingTime]) {
196184
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription);
197185
XCTFail(@"Failed due to not able to find pickedImage with %@ seconds", @(kElementWaitingTime));
198186
}
199-
200-
XCTAssertTrue(pickedImage.exists);
201187
}
202188

203189
@end

packages/image_picker/image_picker_ios/example/ios/RunnerUITests/ImagePickerFromLimitedGalleryUITests.m

+11-70
Original file line numberDiff line numberDiff line change
@@ -46,126 +46,67 @@ - (void)tearDown {
4646
[self.app terminate];
4747
}
4848

49-
- (void)testSelectingFromGallery {
50-
// Test the `Select Photos` button which is available after iOS 14.
51-
if (@available(iOS 14, *)) {
52-
[self launchPickerAndSelect];
53-
} else {
54-
return;
55-
}
56-
}
57-
58-
- (void)launchPickerAndSelect {
49+
// Test the `Select Photos` button which is available after iOS 14.
50+
- (void)testSelectingFromGallery API_AVAILABLE(ios(14)) {
5951
// Find and tap on the pick from gallery button.
60-
NSPredicate *predicateToFindImageFromGalleryButton =
61-
[NSPredicate predicateWithFormat:@"label == %@", @"image_picker_example_from_gallery"];
62-
6352
XCUIElement *imageFromGalleryButton =
64-
[self.app.otherElements elementMatchingPredicate:predicateToFindImageFromGalleryButton];
53+
self.app.otherElements[@"image_picker_example_from_gallery"].firstMatch;
6554
if (![imageFromGalleryButton waitForExistenceWithTimeout:kLimitedElementWaitingTime]) {
6655
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription);
6756
XCTFail(@"Failed due to not able to find image from gallery button with %@ seconds",
6857
@(kLimitedElementWaitingTime));
6958
}
70-
71-
XCTAssertTrue(imageFromGalleryButton.exists);
7259
[imageFromGalleryButton tap];
7360

7461
// Find and tap on the `pick` button.
75-
NSPredicate *predicateToFindPickButton =
76-
[NSPredicate predicateWithFormat:@"label == %@", @"PICK"];
77-
78-
XCUIElement *pickButton = [self.app.buttons elementMatchingPredicate:predicateToFindPickButton];
62+
XCUIElement *pickButton = self.app.buttons[@"PICK"].firstMatch;
7963
if (![pickButton waitForExistenceWithTimeout:kLimitedElementWaitingTime]) {
8064
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription);
8165
XCTSkip(@"Pick button isn't found so the test is skipped...");
8266
}
83-
84-
XCTAssertTrue(pickButton.exists);
8567
[pickButton tap];
8668

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

91-
// Find an image and tap on it. (IOS 14 UI, images are showing directly)
92-
XCUIElement *aImage;
93-
if (@available(iOS 14, *)) {
94-
aImage = [self.app.scrollViews.firstMatch.images elementBoundByIndex:1];
95-
} else {
96-
XCUIElement *selectedPhotosCell = [self.app.cells
97-
elementMatchingPredicate:[NSPredicate
98-
predicateWithFormat:@"label == %@", @"Selected Photos"]];
99-
if (![selectedPhotosCell waitForExistenceWithTimeout:kLimitedElementWaitingTime]) {
100-
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription);
101-
XCTFail(@"Failed due to not able to find \"Selected Photos\" cell with %@ seconds",
102-
@(kLimitedElementWaitingTime));
103-
}
104-
[selectedPhotosCell tap];
105-
aImage = [self.app.collectionViews elementMatchingType:XCUIElementTypeCollectionView
106-
identifier:@"PhotosGridView"]
107-
.cells.firstMatch;
108-
}
73+
// Find an image and tap on it.
74+
XCUIElement *aImage = [self.app.scrollViews.firstMatch.images elementBoundByIndex:1];
10975
os_log_error(OS_LOG_DEFAULT, "description before picking image %@", self.app.debugDescription);
11076
if (![aImage waitForExistenceWithTimeout:kLimitedElementWaitingTime]) {
11177
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription);
11278
XCTFail(@"Failed due to not able to find an image with %@ seconds",
11379
@(kLimitedElementWaitingTime));
11480
}
115-
XCTAssertTrue(aImage.exists);
81+
11682
[aImage tap];
11783

11884
// Find and tap on the `Done` button.
119-
NSPredicate *predicateToFindDoneButton =
120-
[NSPredicate predicateWithFormat:@"label == %@", @"Done"];
121-
122-
XCUIElement *doneButton = [self.app.buttons elementMatchingPredicate:predicateToFindDoneButton];
85+
XCUIElement *doneButton = self.app.buttons[@"Done"].firstMatch;
12386
if (![doneButton waitForExistenceWithTimeout:kLimitedElementWaitingTime]) {
12487
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription);
12588
XCTSkip(@"Permissions popup could not fired so the test is skipped...");
12689
}
127-
128-
XCTAssertTrue(doneButton.exists);
12990
[doneButton tap];
13091

13192
// Find an image and tap on it to have access to selected photos.
132-
if (@available(iOS 14, *)) {
133-
aImage = [self.app.scrollViews.firstMatch.images elementBoundByIndex:1];
134-
} else {
135-
XCUIElement *selectedPhotosCell = [self.app.cells
136-
elementMatchingPredicate:[NSPredicate
137-
predicateWithFormat:@"label == %@", @"Selected Photos"]];
138-
if (![selectedPhotosCell waitForExistenceWithTimeout:kLimitedElementWaitingTime]) {
139-
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription);
140-
XCTFail(@"Failed due to not able to find \"Selected Photos\" cell with %@ seconds",
141-
@(kLimitedElementWaitingTime));
142-
}
143-
[selectedPhotosCell tap];
144-
aImage = [self.app.collectionViews elementMatchingType:XCUIElementTypeCollectionView
145-
identifier:@"PhotosGridView"]
146-
.cells.firstMatch;
147-
}
93+
aImage = [self.app.scrollViews.firstMatch.images elementBoundByIndex:1];
94+
14895
os_log_error(OS_LOG_DEFAULT, "description before picking image %@", self.app.debugDescription);
14996
if (![aImage waitForExistenceWithTimeout:kLimitedElementWaitingTime]) {
15097
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription);
15198
XCTFail(@"Failed due to not able to find an image with %@ seconds",
15299
@(kLimitedElementWaitingTime));
153100
}
154-
XCTAssertTrue(aImage.exists);
155101
[aImage tap];
156102

157103
// Find the picked image.
158-
NSPredicate *predicateToFindPickedImage =
159-
[NSPredicate predicateWithFormat:@"label == %@", @"image_picker_example_picked_image"];
160-
161-
XCUIElement *pickedImage = [self.app.images elementMatchingPredicate:predicateToFindPickedImage];
104+
XCUIElement *pickedImage = self.app.images[@"image_picker_example_picked_image"].firstMatch;
162105
if (![pickedImage waitForExistenceWithTimeout:kLimitedElementWaitingTime]) {
163106
os_log_error(OS_LOG_DEFAULT, "%@", self.app.debugDescription);
164107
XCTFail(@"Failed due to not able to find pickedImage with %@ seconds",
165108
@(kLimitedElementWaitingTime));
166109
}
167-
168-
XCTAssertTrue(pickedImage.exists);
169110
}
170111

171112
@end

0 commit comments

Comments
 (0)