This reverts commit 84a7a611b0.
This commit is contained in:
@@ -71,7 +71,7 @@ void main() {
|
||||
expect(emulator.name, displayName);
|
||||
expect(emulator.manufacturer, manufacturer);
|
||||
expect(emulator.category, Category.mobile);
|
||||
expect(emulator.platformDisplay, 'android');
|
||||
expect(emulator.platformType, PlatformType.android);
|
||||
});
|
||||
|
||||
testWithoutContext('prefers displayname for name', () {
|
||||
|
||||
@@ -2,13 +2,15 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:flutter_tools/src/android/android_workflow.dart';
|
||||
import 'package:flutter_tools/src/base/io.dart';
|
||||
import 'package:flutter_tools/src/base/logger.dart';
|
||||
import 'package:flutter_tools/src/device.dart';
|
||||
import 'package:flutter_tools/src/emulator.dart';
|
||||
import 'package:flutter_tools/src/ios/ios_emulators.dart';
|
||||
import 'package:flutter_tools/src/ios/simulators.dart';
|
||||
import 'package:flutter_tools/src/macos/xcode.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:process/process.dart';
|
||||
@@ -43,10 +45,14 @@ const FakeCommand kListEmulatorsCommand = FakeCommand(
|
||||
);
|
||||
|
||||
void main() {
|
||||
MockProcessManager mockProcessManager;
|
||||
MockAndroidSdk mockSdk;
|
||||
MockXcode mockXcode;
|
||||
|
||||
setUp(() {
|
||||
mockProcessManager = MockProcessManager();
|
||||
mockSdk = MockAndroidSdk();
|
||||
mockXcode = MockXcode();
|
||||
|
||||
when(mockSdk.avdManagerPath).thenReturn('avdmanager');
|
||||
when(mockSdk.getAvdManagerPath()).thenReturn('avdmanager');
|
||||
@@ -293,53 +299,24 @@ void main() {
|
||||
});
|
||||
|
||||
group('ios_emulators', () {
|
||||
MockXcode mockXcode;
|
||||
FakeProcessManager fakeProcessManager;
|
||||
|
||||
bool didAttemptToRunSimulator = false;
|
||||
setUp(() {
|
||||
fakeProcessManager = FakeProcessManager.list(<FakeCommand>[]);
|
||||
mockXcode = MockXcode();
|
||||
when(mockXcode.xcrunCommand()).thenReturn(<String>['xcrun']);
|
||||
when(mockXcode.getSimulatorPath())
|
||||
.thenAnswer((_) => '/fake/simulator.app');
|
||||
when(mockXcode.xcodeSelectPath).thenReturn('/fake/Xcode.app/Contents/Developer');
|
||||
when(mockXcode.getSimulatorPath()).thenAnswer((_) => '/fake/simulator.app');
|
||||
when(mockProcessManager.run(any)).thenAnswer((Invocation invocation) async {
|
||||
final List<String> args = invocation.positionalArguments[0] as List<String>;
|
||||
if (args.length >= 3 && args[0] == 'open' && args[1] == '-a' && args[2] == '/fake/simulator.app') {
|
||||
didAttemptToRunSimulator = true;
|
||||
}
|
||||
return ProcessResult(101, 0, '', '');
|
||||
});
|
||||
});
|
||||
|
||||
testUsingContext('runs correct launch commands', () async {
|
||||
fakeProcessManager.addCommands(<FakeCommand>[
|
||||
const FakeCommand(command: <String>[
|
||||
'open',
|
||||
'-a',
|
||||
'/fake/simulator.app',
|
||||
]),
|
||||
const FakeCommand(command: <String>[
|
||||
'xcrun',
|
||||
'simctl',
|
||||
'boot',
|
||||
'1234',
|
||||
]),
|
||||
]);
|
||||
final SimControl simControl = SimControl.test(
|
||||
processManager: fakeProcessManager,
|
||||
xcode: mockXcode,
|
||||
);
|
||||
|
||||
final IOSSimulator simulator = IOSSimulator(
|
||||
'1234',
|
||||
name: 'iPhone 12',
|
||||
simulatorCategory: 'com.apple.CoreSimulator.SimRuntime.iOS-14-3',
|
||||
simControl: simControl,
|
||||
xcode: mockXcode,
|
||||
);
|
||||
final IOSEmulator emulator = IOSEmulator(simulator);
|
||||
|
||||
expect(emulator.id, '1234');
|
||||
expect(emulator.name, 'iPhone 12');
|
||||
expect(emulator.category, Category.mobile);
|
||||
expect(emulator.platformDisplay, 'iOS-14-3');
|
||||
const Emulator emulator = IOSEmulator('ios');
|
||||
await emulator.launch();
|
||||
expect(fakeProcessManager.hasRemainingExpectations, false);
|
||||
expect(didAttemptToRunSimulator, equals(true));
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => fakeProcessManager,
|
||||
ProcessManager: () => mockProcessManager,
|
||||
Xcode: () => mockXcode,
|
||||
});
|
||||
});
|
||||
@@ -370,11 +347,35 @@ class FakeEmulator extends Emulator {
|
||||
Category get category => Category.mobile;
|
||||
|
||||
@override
|
||||
String get platformDisplay => PlatformType.android.toString();
|
||||
PlatformType get platformType => PlatformType.android;
|
||||
|
||||
@override
|
||||
Future<void> launch() {
|
||||
throw UnimplementedError('Not implemented in Mock');
|
||||
}
|
||||
}
|
||||
|
||||
class MockProcessManager extends Mock implements ProcessManager {
|
||||
|
||||
@override
|
||||
ProcessResult runSync(
|
||||
List<dynamic> command, {
|
||||
String workingDirectory,
|
||||
Map<String, String> environment,
|
||||
bool includeParentEnvironment = true,
|
||||
bool runInShell = false,
|
||||
Encoding stdoutEncoding = systemEncoding,
|
||||
Encoding stderrEncoding = systemEncoding,
|
||||
}) {
|
||||
final String program = command[0] as String;
|
||||
final List<String> args = command.sublist(1) as List<String>;
|
||||
switch (program) {
|
||||
case '/usr/bin/xcode-select':
|
||||
throw ProcessException(program, args);
|
||||
break;
|
||||
}
|
||||
throw StateError('Unexpected process call: $command');
|
||||
}
|
||||
}
|
||||
|
||||
class MockXcode extends Mock implements Xcode {}
|
||||
|
||||
@@ -11,7 +11,6 @@ import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/io.dart';
|
||||
import 'package:flutter_tools/src/base/logger.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/base/process.dart';
|
||||
import 'package:flutter_tools/src/build_info.dart';
|
||||
import 'package:flutter_tools/src/build_system/build_system.dart';
|
||||
import 'package:flutter_tools/src/devfs.dart';
|
||||
@@ -786,19 +785,12 @@ Dec 20 17:04:32 md32-11-vm1 Another App[88374]: Ignore this text'''
|
||||
"availability" : "(available)",
|
||||
"name" : "iPhone 5s",
|
||||
"udid" : "TEST-PHONE-UDID"
|
||||
},
|
||||
{
|
||||
"state" : "Shutdown",
|
||||
"isAvailable" : false,
|
||||
"name" : "iPhone 11",
|
||||
"udid" : "TEST-PHONE-UNAVAILABLE-UDID",
|
||||
"availabilityError" : "runtime profile not found"
|
||||
}
|
||||
],
|
||||
"tvOS 11.4" : [
|
||||
{
|
||||
"state" : "Shutdown",
|
||||
"isAvailable" : true,
|
||||
"availability" : "(available)",
|
||||
"name" : "Apple TV",
|
||||
"udid" : "TEST-TV-UDID"
|
||||
}
|
||||
@@ -832,12 +824,11 @@ Dec 20 17:04:32 md32-11-vm1 Another App[88374]: Ignore this text'''
|
||||
|
||||
testWithoutContext('getDevices succeeds', () async {
|
||||
final List<SimDevice> devices = await simControl.getDevices();
|
||||
expect(devices.length, 4);
|
||||
|
||||
final SimDevice watch = devices[0];
|
||||
expect(watch.category, 'watchOS 4.3');
|
||||
expect(watch.state, 'Shutdown');
|
||||
expect(watch.isAvailable, true);
|
||||
expect(watch.availability, '(available)');
|
||||
expect(watch.name, 'Apple Watch - 38mm');
|
||||
expect(watch.udid, 'TEST-WATCH-UDID');
|
||||
expect(watch.isBooted, isFalse);
|
||||
@@ -845,33 +836,20 @@ Dec 20 17:04:32 md32-11-vm1 Another App[88374]: Ignore this text'''
|
||||
final SimDevice phone = devices[1];
|
||||
expect(phone.category, 'iOS 11.4');
|
||||
expect(phone.state, 'Booted');
|
||||
expect(phone.isAvailable, true);
|
||||
expect(phone.availability, '(available)');
|
||||
expect(phone.name, 'iPhone 5s');
|
||||
expect(phone.udid, 'TEST-PHONE-UDID');
|
||||
expect(phone.isBooted, isTrue);
|
||||
|
||||
final SimDevice unavailablePhone = devices[2];
|
||||
expect(unavailablePhone.category, 'iOS 11.4');
|
||||
expect(unavailablePhone.state, 'Shutdown');
|
||||
expect(unavailablePhone.isAvailable, isFalse);
|
||||
expect(unavailablePhone.name, 'iPhone 11');
|
||||
expect(unavailablePhone.udid, 'TEST-PHONE-UNAVAILABLE-UDID');
|
||||
expect(unavailablePhone.isBooted, isFalse);
|
||||
|
||||
final SimDevice tv = devices[3];
|
||||
final SimDevice tv = devices[2];
|
||||
expect(tv.category, 'tvOS 11.4');
|
||||
expect(tv.state, 'Shutdown');
|
||||
expect(tv.isAvailable, true);
|
||||
expect(tv.availability, '(available)');
|
||||
expect(tv.name, 'Apple TV');
|
||||
expect(tv.udid, 'TEST-TV-UDID');
|
||||
expect(tv.isBooted, isFalse);
|
||||
});
|
||||
|
||||
testWithoutContext('getAvailableDevices succeeds', () async {
|
||||
final List<SimDevice> devices = await simControl.getAvailableDevices();
|
||||
expect(devices.length, 3);
|
||||
});
|
||||
|
||||
testWithoutContext('getDevices handles bad simctl output', () async {
|
||||
when(mockProcessManager.run(any))
|
||||
.thenAnswer((Invocation _) async => ProcessResult(mockPid, 0, 'Install Started', ''));
|
||||
@@ -927,78 +905,6 @@ Dec 20 17:04:32 md32-11-vm1 Another App[88374]: Ignore this text'''
|
||||
throwsToolExit(message: r'Unable to launch'),
|
||||
);
|
||||
});
|
||||
|
||||
testWithoutContext('.boot() calls the right command', () async {
|
||||
await simControl.boot(deviceId);
|
||||
verify(mockProcessManager.run(
|
||||
<String>['xcrun', 'simctl', 'boot', deviceId],
|
||||
environment: anyNamed('environment'),
|
||||
workingDirectory: anyNamed('workingDirectory'),
|
||||
));
|
||||
});
|
||||
});
|
||||
|
||||
group('boot', () {
|
||||
SimControl simControl;
|
||||
MockXcode mockXcode;
|
||||
|
||||
setUp(() {
|
||||
simControl = MockSimControl();
|
||||
mockXcode = MockXcode();
|
||||
when(mockXcode.xcrunCommand()).thenReturn(<String>['xcrun']);
|
||||
});
|
||||
|
||||
testUsingContext('success', () async {
|
||||
final IOSSimulator device = IOSSimulator(
|
||||
'x',
|
||||
name: 'iPhone SE',
|
||||
simulatorCategory: 'iOS 11.2',
|
||||
simControl: simControl,
|
||||
xcode: mockXcode,
|
||||
);
|
||||
when(simControl.boot(any)).thenAnswer((_) async =>
|
||||
RunResult(ProcessResult(0, 0, '', ''), <String>['simctl']));
|
||||
|
||||
expect(await device.boot(), isTrue);
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
});
|
||||
|
||||
testUsingContext('already booted', () async {
|
||||
final IOSSimulator device = IOSSimulator(
|
||||
'x',
|
||||
name: 'iPhone SE',
|
||||
simulatorCategory: 'iOS 11.2',
|
||||
simControl: simControl,
|
||||
xcode: mockXcode,
|
||||
);
|
||||
// 149 means the device is already booted.
|
||||
when(simControl.boot(any)).thenAnswer((_) async =>
|
||||
RunResult(ProcessResult(0, 149, '', ''), <String>['simctl']));
|
||||
|
||||
expect(await device.boot(), isTrue);
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
});
|
||||
|
||||
testUsingContext('failed', () async {
|
||||
final IOSSimulator device = IOSSimulator(
|
||||
'x',
|
||||
name: 'iPhone SE',
|
||||
simulatorCategory: 'iOS 11.2',
|
||||
simControl: simControl,
|
||||
xcode: mockXcode,
|
||||
);
|
||||
when(simControl.boot(any)).thenAnswer((_) async =>
|
||||
RunResult(ProcessResult(0, 1, '', ''), <String>['simctl']));
|
||||
|
||||
expect(await device.boot(), isFalse);
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
});
|
||||
});
|
||||
|
||||
group('startApp', () {
|
||||
|
||||
@@ -114,7 +114,6 @@ void testUsingContext(
|
||||
IOSSimulatorUtils: () {
|
||||
final MockIOSSimulatorUtils mock = MockIOSSimulatorUtils();
|
||||
when(mock.getAttachedDevices()).thenAnswer((Invocation _) async => <IOSSimulator>[]);
|
||||
when(mock.getAvailableDevices()).thenAnswer((Invocation _) async => <IOSSimulator>[]);
|
||||
return mock;
|
||||
},
|
||||
OutputPreferences: () => OutputPreferences.test(),
|
||||
@@ -287,7 +286,7 @@ class FakeDoctor extends Doctor {
|
||||
|
||||
class MockSimControl extends Mock implements SimControl {
|
||||
MockSimControl() {
|
||||
when(getAvailableDevices()).thenAnswer((Invocation _) async => <SimDevice>[]);
|
||||
when(getConnectedDevices()).thenAnswer((Invocation _) async => <SimDevice>[]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user