@@ -904,6 +904,68 @@ void main() {
904
904
}, overrides: < Type , Generator > {
905
905
MDnsVmServiceDiscovery : () => FakeMDnsVmServiceDiscovery (),
906
906
});
907
+
908
+ group ('IOSDevice.startApp attaches in debug mode via device logging' , () {
909
+ late FakeMDnsVmServiceDiscovery mdnsDiscovery;
910
+ setUp (() {
911
+ mdnsDiscovery = FakeMDnsVmServiceDiscovery (returnsNull: true );
912
+ });
913
+
914
+ testUsingContext ('when mDNS fails' , () async {
915
+ final FileSystem fileSystem = MemoryFileSystem .test ();
916
+ final FakeProcessManager processManager = FakeProcessManager .empty ();
917
+
918
+ final Directory temporaryXcodeProjectDirectory = fileSystem.systemTempDirectory.childDirectory ('flutter_empty_xcode.rand0' );
919
+ final Directory bundleLocation = fileSystem.currentDirectory;
920
+ final IOSDevice device = setUpIOSDevice (
921
+ processManager: processManager,
922
+ fileSystem: fileSystem,
923
+ isCoreDevice: true ,
924
+ coreDeviceControl: FakeIOSCoreDeviceControl (),
925
+ xcodeDebug: FakeXcodeDebug (
926
+ expectedProject: XcodeDebugProject (
927
+ scheme: 'Runner' ,
928
+ xcodeWorkspace: temporaryXcodeProjectDirectory.childDirectory ('Runner.xcworkspace' ),
929
+ xcodeProject: temporaryXcodeProjectDirectory.childDirectory ('Runner.xcodeproj' ),
930
+ hostAppProjectName: 'Runner' ,
931
+ ),
932
+ expectedDeviceId: '123' ,
933
+ expectedLaunchArguments: < String > ['--enable-dart-profiling' ],
934
+ expectedBundlePath: bundleLocation.path,
935
+ )
936
+ );
937
+ final IOSApp iosApp = PrebuiltIOSApp (
938
+ projectBundleId: 'app' ,
939
+ bundleName: 'Runner' ,
940
+ uncompressedBundle: bundleLocation,
941
+ applicationPackage: bundleLocation,
942
+ );
943
+ final FakeDeviceLogReader deviceLogReader = FakeDeviceLogReader ();
944
+
945
+ device.portForwarder = const NoOpDevicePortForwarder ();
946
+ device.setLogReader (iosApp, deviceLogReader);
947
+
948
+ unawaited (mdnsDiscovery.completer.future.whenComplete (() {
949
+ // Start writing messages to the log reader.
950
+ Timer .run (() {
951
+ deviceLogReader.addLine ('Foo' );
952
+ deviceLogReader.addLine ('The Dart VM service is listening on http://127.0.0.1:456' );
953
+ });
954
+ }));
955
+
956
+ final LaunchResult launchResult = await device.startApp (iosApp,
957
+ prebuiltApplication: true ,
958
+ debuggingOptions: DebuggingOptions .enabled (BuildInfo .debug),
959
+ platformArgs: < String , dynamic > {},
960
+ );
961
+
962
+ expect (launchResult.started, true );
963
+ expect (launchResult.hasVmService, true );
964
+ expect (await device.stopApp (iosApp), true );
965
+ }, overrides: < Type , Generator > {
966
+ MDnsVmServiceDiscovery : () => mdnsDiscovery,
967
+ });
968
+ });
907
969
});
908
970
});
909
971
}
@@ -974,6 +1036,10 @@ class FakeDevicePortForwarder extends Fake implements DevicePortForwarder {
974
1036
}
975
1037
976
1038
class FakeMDnsVmServiceDiscovery extends Fake implements MDnsVmServiceDiscovery {
1039
+ FakeMDnsVmServiceDiscovery ({this .returnsNull = false });
1040
+ bool returnsNull;
1041
+
1042
+ Completer <void > completer = Completer <void >();
977
1043
@override
978
1044
Future <Uri ?> getVMServiceUriForLaunch (
979
1045
String applicationId,
@@ -984,6 +1050,11 @@ class FakeMDnsVmServiceDiscovery extends Fake implements MDnsVmServiceDiscovery
984
1050
bool useDeviceIPAsHost = false ,
985
1051
Duration timeout = Duration .zero,
986
1052
}) async {
1053
+ completer.complete ();
1054
+ if (returnsNull) {
1055
+ return null ;
1056
+ }
1057
+
987
1058
return Uri .tryParse ('http://0.0.0.0:1234' );
988
1059
}
989
1060
}
0 commit comments