From 11bf7f068714794ae3752fecdc70cb1134953ff7 Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Mon, 6 Jul 2020 12:28:29 -0700 Subject: [PATCH] Take screenshots of wirelessly paired iOS devices (#60623) --- .../flutter_tools/lib/src/ios/devices.dart | 4 +- packages/flutter_tools/lib/src/ios/mac.dart | 9 ++++- .../test/general.shard/ios/mac_test.dart | 38 +++++++++++++++++-- 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/packages/flutter_tools/lib/src/ios/devices.dart b/packages/flutter_tools/lib/src/ios/devices.dart index e07445b2d9..51d650fdd8 100644 --- a/packages/flutter_tools/lib/src/ios/devices.dart +++ b/packages/flutter_tools/lib/src/ios/devices.dart @@ -509,11 +509,11 @@ class IOSDevice extends Device { void clearLogs() { } @override - bool get supportsScreenshot => _iMobileDevice.isInstalled && interfaceType == IOSDeviceInterface.usb; + bool get supportsScreenshot => _iMobileDevice.isInstalled; @override Future takeScreenshot(File outputFile) async { - await _iMobileDevice.takeScreenshot(outputFile, id); + await _iMobileDevice.takeScreenshot(outputFile, id, interfaceType); } @override diff --git a/packages/flutter_tools/lib/src/ios/mac.dart b/packages/flutter_tools/lib/src/ios/mac.dart index f8a5cbb942..4398459041 100644 --- a/packages/flutter_tools/lib/src/ios/mac.dart +++ b/packages/flutter_tools/lib/src/ios/mac.dart @@ -24,6 +24,7 @@ import '../macos/xcode.dart'; import '../project.dart'; import '../reporting/reporting.dart'; import 'code_signing.dart'; +import 'devices.dart'; import 'migrations/ios_migrator.dart'; import 'migrations/project_base_configuration_migration.dart'; import 'migrations/remove_framework_link_and_embedding_migration.dart'; @@ -66,13 +67,19 @@ class IMobileDevice { } /// Captures a screenshot to the specified outputFile. - Future takeScreenshot(File outputFile, String deviceID) { + Future takeScreenshot( + File outputFile, + String deviceID, + IOSDeviceInterface interfaceType, + ) { return _processUtils.run( [ _idevicescreenshotPath, outputFile.path, '--udid', deviceID, + if (interfaceType == IOSDeviceInterface.network) + '--network', ], throwOnError: true, environment: Map.fromEntries( diff --git a/packages/flutter_tools/test/general.shard/ios/mac_test.dart b/packages/flutter_tools/test/general.shard/ios/mac_test.dart index b0db2bb3e0..fb1f89a5f7 100644 --- a/packages/flutter_tools/test/general.shard/ios/mac_test.dart +++ b/packages/flutter_tools/test/general.shard/ios/mac_test.dart @@ -14,6 +14,7 @@ import 'package:flutter_tools/src/base/platform.dart'; import 'package:flutter_tools/src/base/process.dart'; import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/globals.dart' as globals; +import 'package:flutter_tools/src/ios/devices.dart'; import 'package:flutter_tools/src/ios/mac.dart'; import 'package:flutter_tools/src/ios/xcodeproj.dart'; import 'package:flutter_tools/src/project.dart'; @@ -85,10 +86,14 @@ void main() { logger: logger, ); - expect(() async => await iMobileDevice.takeScreenshot(mockOutputFile, '1234'), throwsA(anything)); + expect(() async => await iMobileDevice.takeScreenshot( + mockOutputFile, + '1234', + IOSDeviceInterface.usb, + ), throwsA(anything)); }); - testWithoutContext('idevicescreenshot captures and returns screenshot', () async { + testWithoutContext('idevicescreenshot captures and returns USB screenshot', () async { when(mockOutputFile.path).thenReturn(outputPath); when(mockProcessManager.run(any, environment: anyNamed('environment'), workingDirectory: null)).thenAnswer( (Invocation invocation) => Future.value(ProcessResult(4, 0, '', ''))); @@ -100,12 +105,39 @@ void main() { logger: logger, ); - await iMobileDevice.takeScreenshot(mockOutputFile, '1234'); + await iMobileDevice.takeScreenshot( + mockOutputFile, + '1234', + IOSDeviceInterface.usb, + ); verify(mockProcessManager.run([idevicescreenshotPath, outputPath, '--udid', '1234'], environment: {'DYLD_LIBRARY_PATH': libimobiledevicePath}, workingDirectory: null, )); }); + + testWithoutContext('idevicescreenshot captures and returns network screenshot', () async { + when(mockOutputFile.path).thenReturn(outputPath); + when(mockProcessManager.run(any, environment: anyNamed('environment'), workingDirectory: null)).thenAnswer( + (Invocation invocation) => Future.value(ProcessResult(4, 0, '', ''))); + + final IMobileDevice iMobileDevice = IMobileDevice( + artifacts: mockArtifacts, + cache: mockCache, + processManager: mockProcessManager, + logger: logger, + ); + + await iMobileDevice.takeScreenshot( + mockOutputFile, + '1234', + IOSDeviceInterface.network, + ); + verify(mockProcessManager.run([idevicescreenshotPath, outputPath, '--udid', '1234', '--network'], + environment: {'DYLD_LIBRARY_PATH': libimobiledevicePath}, + workingDirectory: null, + )); + }); }); });