44
55import 'dart:async' ;
66
7+ import 'package:fake_async/fake_async.dart' ;
78import 'package:file/memory.dart' ;
89import 'package:flutter_tools/src/android/android_device.dart' ;
910import 'package:flutter_tools/src/application_package.dart' ;
@@ -25,6 +26,7 @@ import 'package:flutter_tools/src/device_port_forwarder.dart';
2526import 'package:flutter_tools/src/device_vm_service_discovery_for_attach.dart' ;
2627import 'package:flutter_tools/src/ios/application_package.dart' ;
2728import 'package:flutter_tools/src/ios/devices.dart' ;
29+ import 'package:flutter_tools/src/ios/simulators.dart' ;
2830import 'package:flutter_tools/src/macos/macos_ipad_device.dart' ;
2931import 'package:flutter_tools/src/mdns_discovery.dart' ;
3032import 'package:flutter_tools/src/project.dart' ;
@@ -1528,6 +1530,52 @@ void main() {
15281530 DeviceManager : () => testDeviceManager,
15291531 },
15301532 );
1533+
1534+ group ('prints warning when too slow' , () {
1535+ late SlowWarningCallbackBufferLogger logger;
1536+
1537+ setUp (() {
1538+ logger = SlowWarningCallbackBufferLogger .test ();
1539+ });
1540+
1541+ testUsingContext (
1542+ 'to find on iOS Simulator' ,
1543+ () async {
1544+ final FakeIOSSimulator device = FakeIOSSimulator ();
1545+ testDeviceManager.devices = < Device > [device];
1546+ FakeAsync ().run ((FakeAsync fakeAsync) {
1547+ createTestCommandRunner (
1548+ AttachCommand (
1549+ stdio: stdio,
1550+ logger: logger,
1551+ terminal: terminal,
1552+ signals: signals,
1553+ platform: platform,
1554+ processInfo: processInfo,
1555+ fileSystem: testFileSystem,
1556+ ),
1557+ ).run (< String > ['attach' ]);
1558+
1559+ logger.expectedWarning =
1560+ 'The Dart VM Service was not discovered after 30 seconds. '
1561+ 'This may be due to limited mDNS support in the iOS Simulator.\n\n '
1562+ 'Click "Allow" to the prompt on your device asking if you would like to find and connect devices on your local network. '
1563+ 'If you selected "Don\' t Allow", you can turn it on in Settings > Your App Name > Local Network. '
1564+ "If you don't see your app in the Settings, uninstall the app and rerun to see the prompt again.\n\n "
1565+ 'If you do not receive a prompt, either run "flutter attach" before starting the '
1566+ 'app or use the Dart VM service URL from the Xcode console with '
1567+ '"flutter attach --debug-url=<URL>".\n ' ;
1568+ fakeAsync.elapse (const Duration (seconds: 30 ));
1569+ });
1570+ },
1571+ overrides: < Type , Generator > {
1572+ FileSystem : () => testFileSystem,
1573+ ProcessManager : () => FakeProcessManager .any (),
1574+ Logger : () => logger,
1575+ DeviceManager : () => testDeviceManager,
1576+ },
1577+ );
1578+ });
15311579 });
15321580}
15331581
@@ -1966,6 +2014,62 @@ class FakeIOSDevice extends Fake implements IOSDevice {
19662014 }
19672015}
19682016
2017+ class FakeIOSSimulator extends Fake implements IOSSimulator {
2018+ @override
2019+ final String name = 'name' ;
2020+
2021+ @override
2022+ String get displayName => name;
2023+
2024+ @override
2025+ bool isSupported () => true ;
2026+
2027+ @override
2028+ bool isSupportedForProject (FlutterProject flutterProject) => true ;
2029+
2030+ @override
2031+ bool get isConnected => true ;
2032+
2033+ @override
2034+ DeviceConnectionInterface get connectionInterface => DeviceConnectionInterface .attached;
2035+
2036+ @override
2037+ bool get ephemeral => true ;
2038+
2039+ @override
2040+ Future <TargetPlatform > get targetPlatform async => TargetPlatform .ios;
2041+
2042+ @override
2043+ final PlatformType platformType = PlatformType .ios;
2044+
2045+ @override
2046+ bool get isWirelesslyConnected => false ;
2047+
2048+ @override
2049+ DevicePortForwarder portForwarder = RecordingPortForwarder ();
2050+
2051+ @override
2052+ VMServiceDiscoveryForAttach getVMServiceDiscoveryForAttach ({
2053+ String ? appId,
2054+ String ? fuchsiaModule,
2055+ int ? filterDevicePort,
2056+ int ? expectedHostPort,
2057+ required bool ipv6,
2058+ required Logger logger,
2059+ }) {
2060+ final MdnsVMServiceDiscoveryForAttach mdnsVMServiceDiscoveryForAttach =
2061+ MdnsVMServiceDiscoveryForAttach (
2062+ device: this ,
2063+ appId: appId,
2064+ deviceVmservicePort: filterDevicePort,
2065+ hostVmservicePort: expectedHostPort,
2066+ usesIpv6: ipv6,
2067+ useDeviceIPAsHost: isWirelesslyConnected,
2068+ );
2069+ return mdnsVMServiceDiscoveryForAttach;
2070+ }
2071+ }
2072+
19692073class FakeMDnsClient extends Fake implements MDnsClient {
19702074 FakeMDnsClient (
19712075 this .ptrRecords,
@@ -2054,3 +2158,21 @@ class FakeTerminal extends Fake implements AnsiTerminal {
20542158 @override
20552159 Stream <String > get keystrokes => StreamController <String >().stream;
20562160}
2161+
2162+ class SlowWarningCallbackBufferLogger extends BufferLogger {
2163+ SlowWarningCallbackBufferLogger .test () : super .test ();
2164+
2165+ String ? expectedWarning;
2166+
2167+ @override
2168+ Status startSpinner ({
2169+ VoidCallback ? onFinish,
2170+ Duration ? timeout,
2171+ SlowWarningCallback ? slowWarningCallback,
2172+ TerminalColor ? warningColor,
2173+ }) {
2174+ expect (slowWarningCallback, isNotNull);
2175+ expect (slowWarningCallback !(), expectedWarning);
2176+ return SilentStatus (stopwatch: Stopwatch (), onFinish: onFinish)..start ();
2177+ }
2178+ }
0 commit comments