Skip to content

[image_picker] Add native tests for photo-library access and UIImagePicker completion - #12540

Merged
auto-submit[bot] merged 7 commits into
mainfrom
image_picker_coverage_3_gallery_and_finish_picking
Sep 9, 2026
Merged

auto-submit[bot] merged 7 commits into
mainfrom
image_picker_coverage_3_gallery_and_finish_picking

Conversation

@victogomez-cs

@victogomez-cs victogomez-cs commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #12539.

Adds native unit tests for previously untested paths in FLTImagePickerPlugin.m (photo-library authorization, UIImagePicker launch, and didFinishPickingMediaWithInfo:) before the Objective-C → Swift migration. Production code is unchanged.

This is a tests-only change, so it does not bump the package version or CHANGELOG.

ImagePickerPluginTests go from 52 tests to 70 tests (+18).

New test cases

Photo-library access:

  • testLaunchUIImagePickerGalleryWithoutFullMetadataSkipsAuthorization — gallery without full metadata skips the authorization check
  • testPhotoAccessDeniedReturnsError — denied photo access returns an error
  • testPhotoAccessRestrictedReturnsError — restricted photo access returns an error
  • testPhotoAccessAuthorizedShowsLibrary — authorized access presents the library
  • testPhotoAccessNotDeterminedGrantedShowsLibrary — prompt granted presents the library
  • testPhotoAccessNotDeterminedDeniedReturnsError — prompt denied returns an error
  • testPhotoAccessLimitedReturnsDeniedError — Limited access falls through to denied
  • testPhotoAccessUnknownStatusTreatedAsDenied — unknown status is treated as denied

launchUIImagePickerWithSource::

  • testLaunchUIImagePickerInvalidSourceReturnsError — an invalid source returns an error
  • testLaunchUIImagePickerSetsImageAndVideoMediaTypes — image/video media types and duration are set on the picker

imagePickerController:didFinishPickingMediaWithInfo::

  • testImagePickerDidFinishPickingOriginalImage — original image is saved
  • testImagePickerDidFinishPickingPrefersEditedImage — edited image is preferred over original
  • testImagePickerDidFinishPickingScalesImage — the image is scaled when requested
  • testImagePickerDidFinishPickingWithFullMetadataAsset — full-metadata path uses PHImageManager when an asset is present
  • testImagePickerDidFinishPickingFullMetadataWithoutAsset — full metadata without an asset still completes
  • testImagePickerDidFinishPickingVideo — video is copied successfully
  • testImagePickerDidFinishPickingVideoCopyFailure — a video copy failure is reported
  • testImagePickerDidFinishPickingIgnoredWhenNoCallContext — no callContext is a no-op

Third part of image_picker_ios coverage backfill before the Obj-C → Swift migration for flutter/flutter#119107

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Aug 21, 2026
@victogomez-cs victogomez-cs changed the title [image_picker_ios] Add native tests for photo-library access and UIIm… [image_picker] Add native tests for photo-library access and UIImagePicker completion Aug 21, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds comprehensive unit tests to ImagePickerPluginTests.m for the iOS image picker plugin, covering permission handling, image/video picking, and scaling scenarios. The review feedback identifies a potential memory corruption or crash issue under ARC in three tests where a block is retrieved from NSInvocation using getArgument:atIndex: into a __strong variable, and suggests declaring these block variables as __unsafe_unretained to prevent over-releasing.

Comment on lines +1329 to +1330
void (^handler)(PHAuthorizationStatus status);
[invocation getArgument:&handler atIndex:2];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Under ARC, retrieving a block from NSInvocation using getArgument:atIndex: directly into a __strong block variable can cause memory corruption or crashes due to over-releasing. Since getArgument:atIndex: does not retain the block, the implicit release by ARC when the __strong variable goes out of scope will result in an over-release. To prevent this, declare the block variable as __unsafe_unretained.

Suggested change
void (^handler)(PHAuthorizationStatus status);
[invocation getArgument:&handler atIndex:2];
__unsafe_unretained void (^handler)(PHAuthorizationStatus status);
[invocation getArgument:&handler atIndex:2];

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed and fixed. The authorization handler is now retrieved as __unsafe_unretained so ARC doesn’t over-release the NSInvocation argument.

Comment on lines +1361 to +1362
void (^handler)(PHAuthorizationStatus status);
[invocation getArgument:&handler atIndex:2];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Under ARC, retrieving a block from NSInvocation using getArgument:atIndex: directly into a __strong block variable can cause memory corruption or crashes due to over-releasing. Since getArgument:atIndex: does not retain the block, the implicit release by ARC when the __strong variable goes out of scope will result in an over-release. To prevent this, declare the block variable as __unsafe_unretained.

Suggested change
void (^handler)(PHAuthorizationStatus status);
[invocation getArgument:&handler atIndex:2];
__unsafe_unretained void (^handler)(PHAuthorizationStatus status);
[invocation getArgument:&handler atIndex:2];

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed and fixed. Same fix here: the authorization handler is now __unsafe_unretained.

Comment on lines +1545 to +1546
void (^handler)(NSData *, NSString *, CGImagePropertyOrientation, NSDictionary *);
[invocation getArgument:&handler atIndex:4];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Under ARC, retrieving a block from NSInvocation using getArgument:atIndex: directly into a __strong block variable can cause memory corruption or crashes due to over-releasing. Since getArgument:atIndex: does not retain the block, the implicit release by ARC when the __strong variable goes out of scope will result in an over-release. To prevent this, declare the block variable as __unsafe_unretained.

Suggested change
void (^handler)(NSData *, NSString *, CGImagePropertyOrientation, NSDictionary *);
[invocation getArgument:&handler atIndex:4];
__unsafe_unretained void (^handler)(NSData *, NSString *, CGImagePropertyOrientation, NSDictionary *);
[invocation getArgument:&handler atIndex:4];

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed and fixed. The PHImageManager result handler is now retrieved as __unsafe_unretained.

@jmagman jmagman added the triage-ios Should be looked at in iOS triage label Aug 27, 2026
@LouiseHsu
LouiseHsu self-requested a review August 27, 2026 21:55
@victogomez-cs
victogomez-cs force-pushed the image_picker_coverage_3_gallery_and_finish_picking branch from f7d25e0 to 690cb40 Compare August 28, 2026 21:51
@victogomez-cs
victogomez-cs force-pushed the image_picker_coverage_2_camera_and_results branch from e4f1da4 to 865c506 Compare August 28, 2026 21:55
@victogomez-cs
victogomez-cs force-pushed the image_picker_coverage_3_gallery_and_finish_picking branch from 690cb40 to 9868166 Compare August 28, 2026 21:55

@LouiseHsu LouiseHsu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@LongCatIsLooong

Copy link
Copy Markdown
Contributor

(From triage: this can't land until it is rebased on main)

@victogomez-cs
victogomez-cs force-pushed the image_picker_coverage_2_camera_and_results branch from 865c506 to 267cee7 Compare September 3, 2026 22:00
@victogomez-cs
victogomez-cs force-pushed the image_picker_coverage_3_gallery_and_finish_picking branch from 9868166 to 3cbb3b5 Compare September 3, 2026 22:00
@victogomez-cs
victogomez-cs removed this pull request from stack #12541 September 9, 2026 20:49
Base automatically changed from image_picker_coverage_2_camera_and_results to main September 9, 2026 20:49
@victogomez-cs victogomez-cs added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 9, 2026
@auto-submit

auto-submit Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/packages/12540, because - The status or check suite Dashboard Checks has failed. Please fix the issues identified (or deflake) before re-applying this label.

@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Sep 9, 2026
Removed the deprecated MobileCoreServices import and updated media type checks in the `testLaunchUIImagePickerSetsImageAndVideoMediaTypes` test to utilize the new UniformTypeIdentifiers API. This change enhances compatibility with iOS 14 and later. No functional changes to the tests were made.
@victogomez-cs victogomez-cs added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 9, 2026
@auto-submit
auto-submit Bot merged commit cde74b6 into main Sep 9, 2026
13 checks passed
@auto-submit
auto-submit Bot deleted the image_picker_coverage_3_gallery_and_finish_picking branch September 9, 2026 21:42
mboetger pushed a commit to mboetger/flutter that referenced this pull request Sep 10, 2026
…er#192550)

flutter/packages@36e088a...8a35b16

2026-09-10 [email protected] [material_ui]
Migrate M3 buttons template to use new gen_defaults
(flutter/packages#12744)
2026-09-09 [email protected] [cupertino_ui]Add awaitNotRequired to
Future-returning callsites without await (flutter/packages#12817)
2026-09-09 [email protected] [material_ui] Add awaitNotRequired
annotation to material_ui (flutter/packages#12622)
2026-09-09 [email protected] [image_picker] Add native tests
for photo-library access and UIImagePicker completion
(flutter/packages#12540)
2026-09-09 [email protected] [material_ui][cupertino_ui] allow page
routes to opt out of route semantics - flutter#182556 (flutter/packages#12674)
2026-09-09 [email protected] [image_picker] Add native tests
for pick results, camera access, and presentation
(flutter/packages#12539)
2026-09-09 [email protected] [cupertino_ui] Fix platform view sheet
transitions (flutter/packages#12565)
2026-09-09 [email protected]
[camera_android_camerax] Bump cameraxVersion to 1.6.2, remove
concurrent-futures workaround (flutter/packages#12698)
2026-09-09 [email protected] `[material_ui]`
replace identical checks with equality when dealing with enums
(flutter/packages#12633)
2026-09-09 [email protected] Roll Flutter from
b444e78 to 63b9518 (21 revisions) (flutter/packages#12814)
2026-09-09 [email protected]
`[cupertino_ui]` replace identical checks with equality when dealing
with enums (flutter/packages#12632)
2026-09-09 [email protected] [pigeon] add support for multiple swift
outputs (flutter/packages#12720)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected] on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD p: image_picker platform-ios triage-ios Should be looked at in iOS triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants