Skip to content

Commit 7e86f82

Browse files
[image_picker] Remove use of Pigeon's Dart test generator (#10320)
Updates `image_picker_ios` to use the same test structure that `image_picker_android` already uses: - Removes the use of Pigeon's Dart test generator in favor of DI'ing an implementation of the actual generated Dart API. - Removes the use of the old method channel logger (which was adapted in place during the Pigeon conversion to minimize test changes in the PR that changed the implementation; the fact that it was still being used was tech debt), in favor of structured storage of passed arguments that can be queried directly. This makes tests much shorter and easier to understand and maintain, because if we want to check one parameter in a targeted test, we don't have to assert the entire argument dictionary. - Adds some missing test functionality (e.g., we didn't have tests of any of the non-null return value handling), and removes some duplicate testing (e.g., every possible combination of null and non-null width, hight, and image quality in on giant test). Also does minor cleanup of `image_picker_android`; this conversion had already been done there, but it was still generating an unused `dartTestOut`. Part of flutter/flutter#159886 ## Pre-Review Checklist [^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.
1 parent 2f25693 commit 7e86f82

File tree

6 files changed

+348
-2028
lines changed

6 files changed

+348
-2028
lines changed

packages/image_picker/image_picker_android/pigeons/messages.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import 'package:pigeon/pigeon.dart';
77
@ConfigurePigeon(
88
PigeonOptions(
99
dartOut: 'lib/src/messages.g.dart',
10-
dartTestOut: 'test/test_api.g.dart',
1110
javaOut:
1211
'android/src/main/java/io/flutter/plugins/imagepicker/Messages.java',
1312
javaOptions: JavaOptions(package: 'io.flutter.plugins.imagepicker'),
@@ -94,7 +93,7 @@ class CacheRetrievalResult {
9493
final List<String> paths;
9594
}
9695

97-
@HostApi(dartHostTestHandler: 'TestHostImagePickerApi')
96+
@HostApi()
9897
abstract class ImagePickerApi {
9998
/// Selects images and returns their paths.
10099
@TaskQueue(type: TaskQueueType.serialBackgroundThread)

packages/image_picker/image_picker_android/test/test_api.g.dart

Lines changed: 0 additions & 313 deletions
This file was deleted.

packages/image_picker/image_picker_ios/lib/image_picker_ios.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// found in the LICENSE file.
44
import 'dart:async';
55

6+
import 'package:flutter/foundation.dart' show visibleForTesting;
67
import 'package:image_picker_platform_interface/image_picker_platform_interface.dart';
78

89
import 'src/messages.g.dart';
@@ -43,7 +44,11 @@ SourceCamera _convertCamera(CameraDevice camera) {
4344

4445
/// An implementation of [ImagePickerPlatform] for iOS.
4546
class ImagePickerIOS extends ImagePickerPlatform {
46-
final ImagePickerApi _hostApi = ImagePickerApi();
47+
/// Creates a new plugin implementation instance.
48+
ImagePickerIOS({@visibleForTesting ImagePickerApi? api})
49+
: _hostApi = api ?? ImagePickerApi();
50+
51+
final ImagePickerApi _hostApi;
4752

4853
/// Registers this class as the default platform implementation.
4954
static void registerWith() {

packages/image_picker/image_picker_ios/pigeons/messages.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import 'package:pigeon/pigeon.dart';
77
@ConfigurePigeon(
88
PigeonOptions(
99
dartOut: 'lib/src/messages.g.dart',
10-
dartTestOut: 'test/test_api.g.dart',
1110
objcHeaderOut:
1211
'ios/image_picker_ios/Sources/image_picker_ios/include/image_picker_ios/messages.g.h',
1312
objcSourceOut: 'ios/image_picker_ios/Sources/image_picker_ios/messages.g.m',
@@ -52,7 +51,7 @@ class SourceSpecification {
5251
SourceCamera camera;
5352
}
5453

55-
@HostApi(dartHostTestHandler: 'TestHostImagePickerApi')
54+
@HostApi()
5655
abstract class ImagePickerApi {
5756
@async
5857
@ObjCSelector('pickImageWithSource:maxSize:quality:fullMetadata:')

0 commit comments

Comments
 (0)