Unverified Commit 0b321e67 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Remove IMobileDevice from globals, hoist to XCDevice constructor (#53144)

* Convert ios_device_logger_test.dart to testWithoutContext

* Remove IMobileDevice from globals, hoist to XCDevice constructor
parent 404bb5a5
...@@ -126,7 +126,6 @@ Future<T> runInContext<T>( ...@@ -126,7 +126,6 @@ Future<T> runInContext<T>(
FuchsiaWorkflow: () => FuchsiaWorkflow(), FuchsiaWorkflow: () => FuchsiaWorkflow(),
GradleUtils: () => GradleUtils(), GradleUtils: () => GradleUtils(),
HotRunnerConfig: () => HotRunnerConfig(), HotRunnerConfig: () => HotRunnerConfig(),
IMobileDevice: () => IMobileDevice(),
IOSDeploy: () => IOSDeploy( IOSDeploy: () => IOSDeploy(
artifacts: globals.artifacts, artifacts: globals.artifacts,
cache: globals.cache, cache: globals.cache,
...@@ -209,6 +208,12 @@ Future<T> runInContext<T>( ...@@ -209,6 +208,12 @@ Future<T> runInContext<T>(
XCDevice: () => XCDevice( XCDevice: () => XCDevice(
processManager: globals.processManager, processManager: globals.processManager,
logger: globals.logger, logger: globals.logger,
iMobileDevice: IMobileDevice(
artifacts: globals.artifacts,
cache: globals.cache,
logger: globals.logger,
processManager: globals.processManager,
),
xcode: globals.xcode, xcode: globals.xcode,
), ),
XcodeProjectInterpreter: () => XcodeProjectInterpreter( XcodeProjectInterpreter: () => XcodeProjectInterpreter(
......
...@@ -24,7 +24,6 @@ import 'cache.dart'; ...@@ -24,7 +24,6 @@ import 'cache.dart';
import 'fuchsia/fuchsia_sdk.dart'; import 'fuchsia/fuchsia_sdk.dart';
import 'ios/ios_deploy.dart'; import 'ios/ios_deploy.dart';
import 'ios/ios_workflow.dart'; import 'ios/ios_workflow.dart';
import 'ios/mac.dart';
import 'ios/plist_parser.dart'; import 'ios/plist_parser.dart';
import 'ios/simulators.dart'; import 'ios/simulators.dart';
import 'ios/xcodeproj.dart'; import 'ios/xcodeproj.dart';
...@@ -72,7 +71,6 @@ AndroidStudio get androidStudio => context.get<AndroidStudio>(); ...@@ -72,7 +71,6 @@ AndroidStudio get androidStudio => context.get<AndroidStudio>();
AndroidSdk get androidSdk => context.get<AndroidSdk>(); AndroidSdk get androidSdk => context.get<AndroidSdk>();
FlutterVersion get flutterVersion => context.get<FlutterVersion>(); FlutterVersion get flutterVersion => context.get<FlutterVersion>();
FuchsiaArtifacts get fuchsiaArtifacts => context.get<FuchsiaArtifacts>(); FuchsiaArtifacts get fuchsiaArtifacts => context.get<FuchsiaArtifacts>();
IMobileDevice get iMobileDevice => context.get<IMobileDevice>();
IOSDeploy get iosDeploy => context.get<IOSDeploy>(); IOSDeploy get iosDeploy => context.get<IOSDeploy>();
IOSSimulatorUtils get iosSimulatorUtils => context.get<IOSSimulatorUtils>(); IOSSimulatorUtils get iosSimulatorUtils => context.get<IOSSimulatorUtils>();
IOSWorkflow get iosWorkflow => context.get<IOSWorkflow>(); IOSWorkflow get iosWorkflow => context.get<IOSWorkflow>();
......
...@@ -83,10 +83,12 @@ class IOSDevice extends Device { ...@@ -83,10 +83,12 @@ class IOSDevice extends Device {
@required Platform platform, @required Platform platform,
@required Artifacts artifacts, @required Artifacts artifacts,
@required IOSDeploy iosDeploy, @required IOSDeploy iosDeploy,
@required IMobileDevice iMobileDevice,
@required Logger logger, @required Logger logger,
}) })
: _sdkVersion = sdkVersion, : _sdkVersion = sdkVersion,
_iosDeploy = iosDeploy, _iosDeploy = iosDeploy,
_iMobileDevice = iMobileDevice,
_fileSystem = fileSystem, _fileSystem = fileSystem,
_logger = logger, _logger = logger,
_platform = platform, _platform = platform,
...@@ -113,6 +115,7 @@ class IOSDevice extends Device { ...@@ -113,6 +115,7 @@ class IOSDevice extends Device {
final FileSystem _fileSystem; final FileSystem _fileSystem;
final Logger _logger; final Logger _logger;
final Platform _platform; final Platform _platform;
final IMobileDevice _iMobileDevice;
/// May be 0 if version cannot be parsed. /// May be 0 if version cannot be parsed.
int get majorSdkVersion { int get majorSdkVersion {
...@@ -374,7 +377,7 @@ class IOSDevice extends Device { ...@@ -374,7 +377,7 @@ class IOSDevice extends Device {
return _logReaders.putIfAbsent(app, () => IOSDeviceLogReader.create( return _logReaders.putIfAbsent(app, () => IOSDeviceLogReader.create(
device: this, device: this,
app: app, app: app,
iMobileDevice: globals.iMobileDevice, iMobileDevice: _iMobileDevice,
)); ));
} }
...@@ -402,11 +405,11 @@ class IOSDevice extends Device { ...@@ -402,11 +405,11 @@ class IOSDevice extends Device {
void clearLogs() { } void clearLogs() { }
@override @override
bool get supportsScreenshot => globals.iMobileDevice.isInstalled; bool get supportsScreenshot => _iMobileDevice.isInstalled;
@override @override
Future<void> takeScreenshot(File outputFile) async { Future<void> takeScreenshot(File outputFile) async {
await globals.iMobileDevice.takeScreenshot(outputFile); await _iMobileDevice.takeScreenshot(outputFile);
} }
@override @override
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import 'dart:async'; import 'dart:async';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:process/process.dart';
import '../application_package.dart'; import '../application_package.dart';
import '../artifacts.dart'; import '../artifacts.dart';
...@@ -15,6 +16,7 @@ import '../base/logger.dart'; ...@@ -15,6 +16,7 @@ import '../base/logger.dart';
import '../base/process.dart'; import '../base/process.dart';
import '../base/utils.dart'; import '../base/utils.dart';
import '../build_info.dart'; import '../build_info.dart';
import '../cache.dart';
import '../flutter_manifest.dart'; import '../flutter_manifest.dart';
import '../globals.dart' as globals; import '../globals.dart' as globals;
import '../macos/cocoapod_utils.dart'; import '../macos/cocoapod_utils.dart';
...@@ -28,26 +30,36 @@ import 'migrations/xcode_build_system_migration.dart'; ...@@ -28,26 +30,36 @@ import 'migrations/xcode_build_system_migration.dart';
import 'xcodeproj.dart'; import 'xcodeproj.dart';
class IMobileDevice { class IMobileDevice {
IMobileDevice() IMobileDevice({
: _idevicesyslogPath = globals.artifacts.getArtifactPath(Artifact.idevicesyslog, platform: TargetPlatform.ios), @required Artifacts artifacts,
_idevicescreenshotPath = globals.artifacts.getArtifactPath(Artifact.idevicescreenshot, platform: TargetPlatform.ios); @required Cache cache,
@required ProcessManager processManager,
@required Logger logger,
}) : _idevicesyslogPath = artifacts.getArtifactPath(Artifact.idevicesyslog, platform: TargetPlatform.ios),
_idevicescreenshotPath = artifacts.getArtifactPath(Artifact.idevicescreenshot, platform: TargetPlatform.ios),
_dyLdLibEntry = cache.dyLdLibEntry,
_processUtils = ProcessUtils(logger: logger, processManager: processManager),
_processManager = processManager;
final String _idevicesyslogPath; final String _idevicesyslogPath;
final String _idevicescreenshotPath; final String _idevicescreenshotPath;
final MapEntry<String, String> _dyLdLibEntry;
final ProcessManager _processManager;
final ProcessUtils _processUtils;
bool get isInstalled => _isInstalled ??= globals.processManager.canRun(_idevicescreenshotPath); bool get isInstalled => _isInstalled ??= _processManager.canRun(_idevicescreenshotPath);
bool _isInstalled; bool _isInstalled;
/// Starts `idevicesyslog` and returns the running process. /// Starts `idevicesyslog` and returns the running process.
Future<Process> startLogger(String deviceID) { Future<Process> startLogger(String deviceID) {
return processUtils.start( return _processUtils.start(
<String>[ <String>[
_idevicesyslogPath, _idevicesyslogPath,
'-u', '-u',
deviceID, deviceID,
], ],
environment: Map<String, String>.fromEntries( environment: Map<String, String>.fromEntries(
<MapEntry<String, String>>[globals.cache.dyLdLibEntry] <MapEntry<String, String>>[_dyLdLibEntry]
), ),
); );
} }
...@@ -61,7 +73,7 @@ class IMobileDevice { ...@@ -61,7 +73,7 @@ class IMobileDevice {
], ],
throwOnError: true, throwOnError: true,
environment: Map<String, String>.fromEntries( environment: Map<String, String>.fromEntries(
<MapEntry<String, String>>[globals.cache.dyLdLibEntry] <MapEntry<String, String>>[_dyLdLibEntry]
), ),
); );
} }
......
...@@ -17,6 +17,7 @@ import '../build_info.dart'; ...@@ -17,6 +17,7 @@ import '../build_info.dart';
import '../convert.dart'; import '../convert.dart';
import '../globals.dart' as globals; import '../globals.dart' as globals;
import '../ios/devices.dart'; import '../ios/devices.dart';
import '../ios/mac.dart';
import '../ios/xcodeproj.dart'; import '../ios/xcodeproj.dart';
import '../reporting/reporting.dart'; import '../reporting/reporting.dart';
...@@ -196,12 +197,15 @@ class XCDevice { ...@@ -196,12 +197,15 @@ class XCDevice {
@required ProcessManager processManager, @required ProcessManager processManager,
@required Logger logger, @required Logger logger,
@required Xcode xcode, @required Xcode xcode,
@required IMobileDevice iMobileDevice,
}) : _processUtils = ProcessUtils(logger: logger, processManager: processManager), }) : _processUtils = ProcessUtils(logger: logger, processManager: processManager),
_logger = logger, _logger = logger,
_iMobileDevice = iMobileDevice,
_xcode = xcode; _xcode = xcode;
final ProcessUtils _processUtils; final ProcessUtils _processUtils;
final Logger _logger; final Logger _logger;
final IMobileDevice _iMobileDevice;
final Xcode _xcode; final Xcode _xcode;
bool get isInstalled => _xcode.isInstalledAndMeetsVersionCheck && xcdevicePath != null; bool get isInstalled => _xcode.isInstalledAndMeetsVersionCheck && xcdevicePath != null;
...@@ -356,6 +360,7 @@ class XCDevice { ...@@ -356,6 +360,7 @@ class XCDevice {
fileSystem: globals.fs, fileSystem: globals.fs,
logger: globals.logger, logger: globals.logger,
iosDeploy: globals.iosDeploy, iosDeploy: globals.iosDeploy,
iMobileDevice: _iMobileDevice,
platform: globals.platform, platform: globals.platform,
)); ));
} }
......
...@@ -51,6 +51,7 @@ void main() { ...@@ -51,6 +51,7 @@ void main() {
MockCache mockCache; MockCache mockCache;
Logger logger; Logger logger;
IOSDeploy iosDeploy; IOSDeploy iosDeploy;
IMobileDevice iMobileDevice;
FileSystem mockFileSystem; FileSystem mockFileSystem;
setUp(() { setUp(() {
...@@ -67,6 +68,12 @@ void main() { ...@@ -67,6 +68,12 @@ void main() {
platform: macPlatform, platform: macPlatform,
processManager: FakeProcessManager.any(), processManager: FakeProcessManager.any(),
); );
iMobileDevice = IMobileDevice(
artifacts: mockArtifacts,
cache: mockCache,
logger: logger,
processManager: FakeProcessManager.any(),
);
}); });
testWithoutContext('successfully instantiates on Mac OS', () { testWithoutContext('successfully instantiates on Mac OS', () {
...@@ -77,6 +84,7 @@ void main() { ...@@ -77,6 +84,7 @@ void main() {
logger: logger, logger: logger,
platform: macPlatform, platform: macPlatform,
iosDeploy: iosDeploy, iosDeploy: iosDeploy,
iMobileDevice: iMobileDevice,
name: 'iPhone 1', name: 'iPhone 1',
sdkVersion: '13.3', sdkVersion: '13.3',
cpuArchitecture: DarwinArch.arm64 cpuArchitecture: DarwinArch.arm64
...@@ -91,6 +99,7 @@ void main() { ...@@ -91,6 +99,7 @@ void main() {
logger: logger, logger: logger,
platform: macPlatform, platform: macPlatform,
iosDeploy: iosDeploy, iosDeploy: iosDeploy,
iMobileDevice: iMobileDevice,
name: 'iPhone 1', name: 'iPhone 1',
cpuArchitecture: DarwinArch.arm64, cpuArchitecture: DarwinArch.arm64,
sdkVersion: '1.0.0' sdkVersion: '1.0.0'
...@@ -102,6 +111,7 @@ void main() { ...@@ -102,6 +111,7 @@ void main() {
logger: logger, logger: logger,
platform: macPlatform, platform: macPlatform,
iosDeploy: iosDeploy, iosDeploy: iosDeploy,
iMobileDevice: iMobileDevice,
name: 'iPhone 1', name: 'iPhone 1',
cpuArchitecture: DarwinArch.arm64, cpuArchitecture: DarwinArch.arm64,
sdkVersion: '13.1.1' sdkVersion: '13.1.1'
...@@ -113,6 +123,7 @@ void main() { ...@@ -113,6 +123,7 @@ void main() {
logger: logger, logger: logger,
platform: macPlatform, platform: macPlatform,
iosDeploy: iosDeploy, iosDeploy: iosDeploy,
iMobileDevice: iMobileDevice,
name: 'iPhone 1', name: 'iPhone 1',
cpuArchitecture: DarwinArch.arm64, cpuArchitecture: DarwinArch.arm64,
sdkVersion: '10' sdkVersion: '10'
...@@ -124,6 +135,7 @@ void main() { ...@@ -124,6 +135,7 @@ void main() {
logger: logger, logger: logger,
platform: macPlatform, platform: macPlatform,
iosDeploy: iosDeploy, iosDeploy: iosDeploy,
iMobileDevice: iMobileDevice,
name: 'iPhone 1', name: 'iPhone 1',
cpuArchitecture: DarwinArch.arm64, cpuArchitecture: DarwinArch.arm64,
sdkVersion: '0' sdkVersion: '0'
...@@ -135,6 +147,7 @@ void main() { ...@@ -135,6 +147,7 @@ void main() {
logger: logger, logger: logger,
platform: macPlatform, platform: macPlatform,
iosDeploy: iosDeploy, iosDeploy: iosDeploy,
iMobileDevice: iMobileDevice,
name: 'iPhone 1', name: 'iPhone 1',
cpuArchitecture: DarwinArch.arm64, cpuArchitecture: DarwinArch.arm64,
sdkVersion: 'bogus' sdkVersion: 'bogus'
...@@ -152,6 +165,7 @@ void main() { ...@@ -152,6 +165,7 @@ void main() {
logger: logger, logger: logger,
platform: platform, platform: platform,
iosDeploy: iosDeploy, iosDeploy: iosDeploy,
iMobileDevice: iMobileDevice,
name: 'iPhone 1', name: 'iPhone 1',
sdkVersion: '13.3', sdkVersion: '13.3',
cpuArchitecture: DarwinArch.arm64, cpuArchitecture: DarwinArch.arm64,
...@@ -205,6 +219,7 @@ void main() { ...@@ -205,6 +219,7 @@ void main() {
logger: logger, logger: logger,
platform: macPlatform, platform: macPlatform,
iosDeploy: iosDeploy, iosDeploy: iosDeploy,
iMobileDevice: iMobileDevice,
name: 'iPhone 1', name: 'iPhone 1',
sdkVersion: '13.3', sdkVersion: '13.3',
cpuArchitecture: DarwinArch.arm64, cpuArchitecture: DarwinArch.arm64,
...@@ -288,6 +303,7 @@ void main() { ...@@ -288,6 +303,7 @@ void main() {
logger: logger, logger: logger,
platform: macPlatform, platform: macPlatform,
iosDeploy: iosDeploy, iosDeploy: iosDeploy,
iMobileDevice: iMobileDevice,
name: 'iPhone 1', name: 'iPhone 1',
sdkVersion: '13.3', sdkVersion: '13.3',
cpuArchitecture: DarwinArch.arm64, cpuArchitecture: DarwinArch.arm64,
...@@ -488,6 +504,7 @@ void main() { ...@@ -488,6 +504,7 @@ void main() {
logger: testLogger, logger: testLogger,
platform: macPlatform, platform: macPlatform,
iosDeploy: mockIosDeploy, iosDeploy: mockIosDeploy,
iMobileDevice: iMobileDevice,
cpuArchitecture: DarwinArch.arm64, cpuArchitecture: DarwinArch.arm64,
); );
...@@ -573,6 +590,7 @@ void main() { ...@@ -573,6 +590,7 @@ void main() {
FakeProcessManager fakeProcessManager; FakeProcessManager fakeProcessManager;
Logger logger; Logger logger;
IOSDeploy iosDeploy; IOSDeploy iosDeploy;
IMobileDevice iMobileDevice;
IOSWorkflow mockIosWorkflow; IOSWorkflow mockIosWorkflow;
setUp(() { setUp(() {
...@@ -590,6 +608,12 @@ void main() { ...@@ -590,6 +608,12 @@ void main() {
platform: macPlatform, platform: macPlatform,
processManager: fakeProcessManager, processManager: fakeProcessManager,
); );
iMobileDevice = IMobileDevice(
artifacts: mockArtifacts,
cache: mockCache,
processManager: fakeProcessManager,
logger: logger,
);
}); });
final List<Platform> unsupportedPlatforms = <Platform>[linuxPlatform, windowsPlatform]; final List<Platform> unsupportedPlatforms = <Platform>[linuxPlatform, windowsPlatform];
...@@ -623,6 +647,7 @@ void main() { ...@@ -623,6 +647,7 @@ void main() {
cpuArchitecture: DarwinArch.arm64, cpuArchitecture: DarwinArch.arm64,
artifacts: mockArtifacts, artifacts: mockArtifacts,
iosDeploy: iosDeploy, iosDeploy: iosDeploy,
iMobileDevice: iMobileDevice,
logger: logger, logger: logger,
platform: macPlatform, platform: macPlatform,
fileSystem: mockFileSystem, fileSystem: mockFileSystem,
......
...@@ -12,6 +12,7 @@ import 'package:flutter_tools/src/build_info.dart'; ...@@ -12,6 +12,7 @@ import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/ios/devices.dart'; import 'package:flutter_tools/src/ios/devices.dart';
import 'package:flutter_tools/src/ios/ios_deploy.dart'; import 'package:flutter_tools/src/ios/ios_deploy.dart';
import 'package:flutter_tools/src/ios/mac.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:mockito/mockito.dart'; import 'package:mockito/mockito.dart';
import 'package:platform/platform.dart'; import 'package:platform/platform.dart';
...@@ -171,6 +172,12 @@ IOSDevice setUpIOSDevice({ ...@@ -171,6 +172,12 @@ IOSDevice setUpIOSDevice({
sdkVersion: '13.3', sdkVersion: '13.3',
cpuArchitecture: DarwinArch.arm64, cpuArchitecture: DarwinArch.arm64,
platform: platform, platform: platform,
iMobileDevice: IMobileDevice(
logger: BufferLogger.test(),
processManager: processManager,
artifacts: artifacts,
cache: cache,
),
iosDeploy: IOSDeploy( iosDeploy: IOSDeploy(
logger: BufferLogger.test(), logger: BufferLogger.test(),
platform: platform, platform: platform,
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter_tools/src/artifacts.dart'; import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/device.dart'; import 'package:flutter_tools/src/device.dart';
import 'package:flutter_tools/src/ios/devices.dart'; import 'package:flutter_tools/src/ios/devices.dart';
...@@ -11,14 +12,19 @@ import 'package:mockito/mockito.dart'; ...@@ -11,14 +12,19 @@ import 'package:mockito/mockito.dart';
import '../../src/common.dart'; import '../../src/common.dart';
import '../../src/context.dart'; import '../../src/context.dart';
import '../../src/testbed.dart';
void main() { void main() {
FakeProcessManager processManager; FakeProcessManager processManager;
MockArtifacts artifacts; MockArtifacts artifacts;
FakeCache fakeCache;
BufferLogger logger;
setUp(() { setUp(() {
processManager = FakeProcessManager.list(<FakeCommand>[]); processManager = FakeProcessManager.list(<FakeCommand>[]);
fakeCache = FakeCache();
artifacts = MockArtifacts(); artifacts = MockArtifacts();
logger = BufferLogger.test();
when(artifacts.getArtifactPath(Artifact.idevicesyslog, platform: TargetPlatform.ios)) when(artifacts.getArtifactPath(Artifact.idevicesyslog, platform: TargetPlatform.ios))
.thenReturn('idevice-syslog'); .thenReturn('idevice-syslog');
}); });
...@@ -37,8 +43,7 @@ void main() { ...@@ -37,8 +43,7 @@ void main() {
expect(decoded, r'I \M-b\M^O syslog!'); expect(decoded, r'I \M-b\M^O syslog!');
}); });
// IMobileDevice uses context. testWithoutContext('IOSDeviceLogReader suppresses non-Flutter lines from output with syslog', () async {
testUsingContext('IOSDeviceLogReader suppresses non-Flutter lines from output with syslog', () async {
processManager.addCommand( processManager.addCommand(
const FakeCommand( const FakeCommand(
command: <String>[ command: <String>[
...@@ -54,18 +59,19 @@ Runner(UIKit)[297] <Notice>: E is for enpitsu" ...@@ -54,18 +59,19 @@ Runner(UIKit)[297] <Notice>: E is for enpitsu"
), ),
); );
final DeviceLogReader logReader = IOSDeviceLogReader.test( final DeviceLogReader logReader = IOSDeviceLogReader.test(
iMobileDevice: IMobileDevice(), iMobileDevice: IMobileDevice(
artifacts: artifacts,
processManager: processManager,
cache: fakeCache,
logger: logger,
),
); );
final List<String> lines = await logReader.logLines.toList(); final List<String> lines = await logReader.logLines.toList();
expect(lines, <String>['A is for ari', 'I is for ichigo']); expect(lines, <String>['A is for ari', 'I is for ichigo']);
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
Artifacts: () => artifacts,
}); });
// IMobileDevice uses context. testWithoutContext('IOSDeviceLogReader includes multi-line Flutter logs in the output with syslog', () async {
testUsingContext('IOSDeviceLogReader includes multi-line Flutter logs in the output with syslog', () async {
processManager.addCommand( processManager.addCommand(
const FakeCommand( const FakeCommand(
command: <String>[ command: <String>[
...@@ -81,7 +87,12 @@ Runner(libsystem_asl.dylib)[297] <Notice>: libMobileGestalt ...@@ -81,7 +87,12 @@ Runner(libsystem_asl.dylib)[297] <Notice>: libMobileGestalt
), ),
); );
final DeviceLogReader logReader = IOSDeviceLogReader.test( final DeviceLogReader logReader = IOSDeviceLogReader.test(
iMobileDevice: IMobileDevice() iMobileDevice: IMobileDevice(
artifacts: artifacts,
processManager: processManager,
cache: fakeCache,
logger: logger,
),
); );
final List<String> lines = await logReader.logLines.toList(); final List<String> lines = await logReader.logLines.toList();
...@@ -91,13 +102,9 @@ Runner(libsystem_asl.dylib)[297] <Notice>: libMobileGestalt ...@@ -91,13 +102,9 @@ Runner(libsystem_asl.dylib)[297] <Notice>: libMobileGestalt
'This is a multi-line message,', 'This is a multi-line message,',
' with a non-Flutter log message following it.', ' with a non-Flutter log message following it.',
]); ]);
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
Artifacts: () => artifacts,
}); });
// IMobileDevice uses context. testWithoutContext('includes multi-line Flutter logs in the output', () async {
testUsingContext('includes multi-line Flutter logs in the output', () async {
processManager.addCommand( processManager.addCommand(
const FakeCommand( const FakeCommand(
command: <String>[ command: <String>[
...@@ -114,7 +121,12 @@ Runner(libsystem_asl.dylib)[297] <Notice>: libMobileGestalt ...@@ -114,7 +121,12 @@ Runner(libsystem_asl.dylib)[297] <Notice>: libMobileGestalt
); );
final DeviceLogReader logReader = IOSDeviceLogReader.test( final DeviceLogReader logReader = IOSDeviceLogReader.test(
iMobileDevice: IMobileDevice() iMobileDevice: IMobileDevice(
artifacts: artifacts,
processManager: processManager,
cache: fakeCache,
logger: logger,
),
); );
final List<String> lines = await logReader.logLines.toList(); final List<String> lines = await logReader.logLines.toList();
...@@ -124,9 +136,6 @@ Runner(libsystem_asl.dylib)[297] <Notice>: libMobileGestalt ...@@ -124,9 +136,6 @@ Runner(libsystem_asl.dylib)[297] <Notice>: libMobileGestalt
'This is a multi-line message,', 'This is a multi-line message,',
' with a non-Flutter log message following it.', ' with a non-Flutter log message following it.',
]); ]);
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
Artifacts: () => artifacts,
}); });
} }
......
...@@ -83,6 +83,7 @@ IOSDevice setUpIOSDevice(FileSystem fileSystem) { ...@@ -83,6 +83,7 @@ IOSDevice setUpIOSDevice(FileSystem fileSystem) {
fileSystem: fileSystem, fileSystem: fileSystem,
logger: BufferLogger.test(), logger: BufferLogger.test(),
iosDeploy: null, // not used in this test iosDeploy: null, // not used in this test
iMobileDevice: null, // not used in this test
platform: FakePlatform(operatingSystem: 'macos'), platform: FakePlatform(operatingSystem: 'macos'),
name: 'iPhone 1', name: 'iPhone 1',
sdkVersion: '13.3', sdkVersion: '13.3',
......
...@@ -14,6 +14,7 @@ import 'package:flutter_tools/src/cache.dart'; ...@@ -14,6 +14,7 @@ import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/device.dart'; import 'package:flutter_tools/src/device.dart';
import 'package:flutter_tools/src/ios/devices.dart'; import 'package:flutter_tools/src/ios/devices.dart';
import 'package:flutter_tools/src/ios/ios_deploy.dart'; import 'package:flutter_tools/src/ios/ios_deploy.dart';
import 'package:flutter_tools/src/ios/mac.dart';
import 'package:flutter_tools/src/mdns_discovery.dart'; import 'package:flutter_tools/src/mdns_discovery.dart';
import 'package:flutter_tools/src/reporting/reporting.dart'; import 'package:flutter_tools/src/reporting/reporting.dart';
import 'package:mockito/mockito.dart'; import 'package:mockito/mockito.dart';
...@@ -390,6 +391,12 @@ IOSDevice setUpIOSDevice({ ...@@ -390,6 +391,12 @@ IOSDevice setUpIOSDevice({
artifacts: artifacts, artifacts: artifacts,
cache: cache, cache: cache,
), ),
iMobileDevice: IMobileDevice(
logger: logger ?? BufferLogger.test(),
processManager: processManager ?? FakeProcessManager.any(),
artifacts: artifacts,
cache: cache,
),
cpuArchitecture: DarwinArch.arm64, cpuArchitecture: DarwinArch.arm64,
); );
} }
......
...@@ -8,6 +8,7 @@ import 'package:file/file.dart'; ...@@ -8,6 +8,7 @@ import 'package:file/file.dart';
import 'package:flutter_tools/src/artifacts.dart'; import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart' show ProcessResult; import 'package:flutter_tools/src/base/io.dart' show ProcessResult;
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/ios/mac.dart'; import 'package:flutter_tools/src/ios/mac.dart';
import 'package:flutter_tools/src/ios/xcodeproj.dart'; import 'package:flutter_tools/src/ios/xcodeproj.dart';
...@@ -36,14 +37,14 @@ class MockIosProject extends Mock implements IosProject {} ...@@ -36,14 +37,14 @@ class MockIosProject extends Mock implements IosProject {}
void main() { void main() {
group('IMobileDevice', () { group('IMobileDevice', () {
final FakePlatform osx = FakePlatform.fromPlatform(const LocalPlatform())
..operatingSystem = 'macos';
final String libimobiledevicePath = globals.fs.path.join('bin', 'cache', 'artifacts', 'libimobiledevice'); final String libimobiledevicePath = globals.fs.path.join('bin', 'cache', 'artifacts', 'libimobiledevice');
final String idevicescreenshotPath = globals.fs.path.join(libimobiledevicePath, 'idevicescreenshot'); final String idevicescreenshotPath = globals.fs.path.join(libimobiledevicePath, 'idevicescreenshot');
MockArtifacts mockArtifacts; MockArtifacts mockArtifacts;
MockCache mockCache; MockCache mockCache;
Logger logger;
setUp(() { setUp(() {
logger = BufferLogger.test();
mockCache = MockCache(); mockCache = MockCache();
mockArtifacts = MockArtifacts(); mockArtifacts = MockArtifacts();
when(mockArtifacts.getArtifactPath(Artifact.idevicescreenshot, platform: anyNamed('platform'))).thenReturn(idevicescreenshotPath); when(mockArtifacts.getArtifactPath(Artifact.idevicescreenshot, platform: anyNamed('platform'))).thenReturn(idevicescreenshotPath);
...@@ -63,7 +64,7 @@ void main() { ...@@ -63,7 +64,7 @@ void main() {
when(mockArtifacts.getArtifactPath(Artifact.idevicescreenshot, platform: anyNamed('platform'))).thenReturn(idevicescreenshotPath); when(mockArtifacts.getArtifactPath(Artifact.idevicescreenshot, platform: anyNamed('platform'))).thenReturn(idevicescreenshotPath);
}); });
testUsingContext('error if idevicescreenshot is not installed', () async { testWithoutContext('error if idevicescreenshot is not installed', () async {
when(mockOutputFile.path).thenReturn(outputPath); when(mockOutputFile.path).thenReturn(outputPath);
// Let `idevicescreenshot` fail with exit code 1. // Let `idevicescreenshot` fail with exit code 1.
...@@ -72,11 +73,14 @@ void main() { ...@@ -72,11 +73,14 @@ void main() {
workingDirectory: null, workingDirectory: null,
)).thenAnswer((_) => Future<ProcessResult>.value(ProcessResult(4, 1, '', ''))); )).thenAnswer((_) => Future<ProcessResult>.value(ProcessResult(4, 1, '', '')));
expect(() async => await globals.iMobileDevice.takeScreenshot(mockOutputFile), throwsA(anything)); final IMobileDevice iMobileDevice = IMobileDevice(
}, overrides: <Type, Generator>{ artifacts: mockArtifacts,
ProcessManager: () => mockProcessManager, cache: mockCache,
Platform: () => osx, processManager: mockProcessManager,
Cache: () => mockCache, logger: logger,
);
expect(() async => await iMobileDevice.takeScreenshot(mockOutputFile), throwsA(anything));
}); });
testUsingContext('idevicescreenshot captures and returns screenshot', () async { testUsingContext('idevicescreenshot captures and returns screenshot', () async {
...@@ -84,15 +88,20 @@ void main() { ...@@ -84,15 +88,20 @@ void main() {
when(mockProcessManager.run(any, environment: anyNamed('environment'), workingDirectory: null)).thenAnswer( when(mockProcessManager.run(any, environment: anyNamed('environment'), workingDirectory: null)).thenAnswer(
(Invocation invocation) => Future<ProcessResult>.value(ProcessResult(4, 0, '', ''))); (Invocation invocation) => Future<ProcessResult>.value(ProcessResult(4, 0, '', '')));
await globals.iMobileDevice.takeScreenshot(mockOutputFile); final IMobileDevice iMobileDevice = IMobileDevice(
artifacts: mockArtifacts,
cache: mockCache,
processManager: mockProcessManager,
logger: logger,
);
await iMobileDevice.takeScreenshot(mockOutputFile);
verify(mockProcessManager.run(<String>[idevicescreenshotPath, outputPath], verify(mockProcessManager.run(<String>[idevicescreenshotPath, outputPath],
environment: <String, String>{'DYLD_LIBRARY_PATH': libimobiledevicePath}, environment: <String, String>{'DYLD_LIBRARY_PATH': libimobiledevicePath},
workingDirectory: null, workingDirectory: null,
)); ));
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager, ProcessManager: () => mockProcessManager,
Cache: () => mockCache,
Artifacts: () => mockArtifacts,
}); });
}); });
}); });
......
...@@ -216,6 +216,7 @@ void main() { ...@@ -216,6 +216,7 @@ void main() {
processManager: processManager, processManager: processManager,
logger: logger, logger: logger,
xcode: mockXcode, xcode: mockXcode,
iMobileDevice: null,
); );
}); });
......
...@@ -844,7 +844,7 @@ class FakeCache implements Cache { ...@@ -844,7 +844,7 @@ class FakeCache implements Cache {
String get storageBaseUrl => null; String get storageBaseUrl => null;
@override @override
MapEntry<String, String> get dyLdLibEntry => null; MapEntry<String, String> get dyLdLibEntry => const MapEntry<String, String>('DYLD_LIBRARY_PATH', '');
@override @override
String get engineRevision => null; String get engineRevision => null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment