flutter/packages/flutter_tools/test/general.shard/emulator_test.dart

394 lines
13 KiB
Dart
Raw Normal View History

// Copyright 2014 The Flutter Authors. All rights reserved.
2018-04-18 10:37:59 +00:00
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:file/file.dart';
import 'package:file/memory.dart';
import 'package:flutter_tools/src/android/android_sdk.dart';
import 'package:flutter_tools/src/android/android_workflow.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/device.dart';
2018-04-18 10:37:59 +00:00
import 'package:flutter_tools/src/emulator.dart';
import 'package:flutter_tools/src/ios/ios_emulators.dart';
import 'package:flutter_tools/src/macos/xcode.dart';
import 'package:test/fake.dart';
2018-04-18 10:37:59 +00:00
import '../src/common.dart';
import '../src/context.dart';
import '../src/fakes.dart';
2018-04-18 10:37:59 +00:00
const FakeEmulator emulator1 = FakeEmulator('Nexus_5', 'Nexus 5', 'Google');
const FakeEmulator emulator2 = FakeEmulator('Nexus_5X_API_27_x86', 'Nexus 5X', 'Google');
const FakeEmulator emulator3 = FakeEmulator('iOS Simulator', 'iOS Simulator', 'Apple');
const List<Emulator> emulators = <Emulator>[
emulator1,
emulator2,
emulator3,
];
// We have to send a command that fails in order to get the list of valid
// system images paths. This is an example of the output to use in the fake.
const String fakeCreateFailureOutput =
'Error: Package path (-k) not specified. Valid system image paths are:\n'
'system-images;android-27;google_apis;x86\n'
'system-images;android-P;google_apis;x86\n'
'system-images;android-27;google_apis_playstore;x86\n'
'null\n'; // Yep, these really end with null (on dantup's machine at least)
const FakeCommand kListEmulatorsCommand = FakeCommand(
command: <String>['avdmanager', 'create', 'avd', '-n', 'temp'],
stderr: fakeCreateFailureOutput,
exitCode: 1,
);
2018-04-18 10:37:59 +00:00
void main() {
FakeProcessManager fakeProcessManager;
FakeAndroidSdk sdk;
FileSystem fileSystem;
Xcode xcode;
Add --create option to `flutter emulators` command (#18235) * Add --create option to flutter emulators * Tweaks to error message * Simplify emulator search logic * Make name optional * Add a note about this option being used with --create * Tweaks to help information * Switch to processManager for easier testing * Don't crash on missing files or missing properties in Android Emulator * Move name suffixing into emulator manager This allows it to be tested in the EmulatorManager tests and also used by daemon later if desired. * Pass the context's android SDK through so it can be mocked by tests * Misc fixes * Add tests around emulator creation Process calls are mocked to avoid needing a real SDK (and to be fast). Full integration tests may be useful, but may require ensuring all build environments etc. are set up correctly. * Simplify avdManagerPath Previous changes were to emulatorPath! * Fix lint errors * Fix incorrect file exgtension for Windows * Fix an issue where no system images would crash reduce throws on an empty collection. * Fix "null" appearing in error messages The name we attempted to use will now always be returned, even in the case of failure. * Add additional info to missing-system-image failure message On Windows after installing Andriod Studio I didn't have any of these and got this message. Installing with sdkmanager fixed the issue. * Fix thrown errors runResult had a toString() but we moved to ProcessResult when switching to ProcessManager to this ended up throwing "Instance of ProcessResult". * Fix package import * Fix more package imports * Move mock implementation into Mock class There seemed to be issues using Lists in args with Mockito that I couldn't figure out (docs say to use typed() but I couldn't make this compile with these lists still).. * Rename method that's ambigious now we have create * Handle where there's no avd path * Add another toList() :( * Remove comment that was rewritten * Fix forbidden import * Make optional arg more obviously optional * Reformat doc * Note that we create a pixel device in help text * Make this a named arg
2018-06-28 07:07:40 +00:00
setUp(() {
fileSystem = MemoryFileSystem.test();
fakeProcessManager = FakeProcessManager.empty();
sdk = FakeAndroidSdk();
xcode = Xcode.test(processManager: fakeProcessManager, fileSystem: fileSystem);
Add --create option to `flutter emulators` command (#18235) * Add --create option to flutter emulators * Tweaks to error message * Simplify emulator search logic * Make name optional * Add a note about this option being used with --create * Tweaks to help information * Switch to processManager for easier testing * Don't crash on missing files or missing properties in Android Emulator * Move name suffixing into emulator manager This allows it to be tested in the EmulatorManager tests and also used by daemon later if desired. * Pass the context's android SDK through so it can be mocked by tests * Misc fixes * Add tests around emulator creation Process calls are mocked to avoid needing a real SDK (and to be fast). Full integration tests may be useful, but may require ensuring all build environments etc. are set up correctly. * Simplify avdManagerPath Previous changes were to emulatorPath! * Fix lint errors * Fix incorrect file exgtension for Windows * Fix an issue where no system images would crash reduce throws on an empty collection. * Fix "null" appearing in error messages The name we attempted to use will now always be returned, even in the case of failure. * Add additional info to missing-system-image failure message On Windows after installing Andriod Studio I didn't have any of these and got this message. Installing with sdkmanager fixed the issue. * Fix thrown errors runResult had a toString() but we moved to ProcessResult when switching to ProcessManager to this ended up throwing "Instance of ProcessResult". * Fix package import * Fix more package imports * Move mock implementation into Mock class There seemed to be issues using Lists in args with Mockito that I couldn't figure out (docs say to use typed() but I couldn't make this compile with these lists still).. * Rename method that's ambigious now we have create * Handle where there's no avd path * Add another toList() :( * Remove comment that was rewritten * Fix forbidden import * Make optional arg more obviously optional * Reformat doc * Note that we create a pixel device in help text * Make this a named arg
2018-06-28 07:07:40 +00:00
sdk
..avdManagerPath = 'avdmanager'
..emulatorPath = 'emulator'
..adbPath = 'adb';
Add --create option to `flutter emulators` command (#18235) * Add --create option to flutter emulators * Tweaks to error message * Simplify emulator search logic * Make name optional * Add a note about this option being used with --create * Tweaks to help information * Switch to processManager for easier testing * Don't crash on missing files or missing properties in Android Emulator * Move name suffixing into emulator manager This allows it to be tested in the EmulatorManager tests and also used by daemon later if desired. * Pass the context's android SDK through so it can be mocked by tests * Misc fixes * Add tests around emulator creation Process calls are mocked to avoid needing a real SDK (and to be fast). Full integration tests may be useful, but may require ensuring all build environments etc. are set up correctly. * Simplify avdManagerPath Previous changes were to emulatorPath! * Fix lint errors * Fix incorrect file exgtension for Windows * Fix an issue where no system images would crash reduce throws on an empty collection. * Fix "null" appearing in error messages The name we attempted to use will now always be returned, even in the case of failure. * Add additional info to missing-system-image failure message On Windows after installing Andriod Studio I didn't have any of these and got this message. Installing with sdkmanager fixed the issue. * Fix thrown errors runResult had a toString() but we moved to ProcessResult when switching to ProcessManager to this ended up throwing "Instance of ProcessResult". * Fix package import * Fix more package imports * Move mock implementation into Mock class There seemed to be issues using Lists in args with Mockito that I couldn't figure out (docs say to use typed() but I couldn't make this compile with these lists still).. * Rename method that's ambigious now we have create * Handle where there's no avd path * Add another toList() :( * Remove comment that was rewritten * Fix forbidden import * Make optional arg more obviously optional * Reformat doc * Note that we create a pixel device in help text * Make this a named arg
2018-06-28 07:07:40 +00:00
});
2018-04-18 10:37:59 +00:00
group('EmulatorManager', () {
// iOS discovery uses context.
2018-04-18 10:37:59 +00:00
testUsingContext('getEmulators', () async {
// Test that EmulatorManager.getEmulators() doesn't throw.
final EmulatorManager emulatorManager = EmulatorManager(
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
processManager: FakeProcessManager.list(<FakeCommand>[
const FakeCommand(
command: <String>['emulator', '-list-avds'],
stdout: 'existing-avd-1',
),
]),
androidSdk: sdk,
androidWorkflow: AndroidWorkflow(
androidSdk: sdk,
featureFlags: TestFeatureFlags(),
operatingSystemUtils: FakeOperatingSystemUtils(),
),
);
await expectLater(() async => emulatorManager.getAllAvailableEmulators(),
returnsNormally);
});
testUsingContext('getEmulators with no Android SDK', () async {
// Test that EmulatorManager.getEmulators() doesn't throw when there's no Android SDK.
final EmulatorManager emulatorManager = EmulatorManager(
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
processManager: FakeProcessManager.list(<FakeCommand>[
const FakeCommand(
command: <String>['emulator', '-list-avds'],
stdout: 'existing-avd-1',
),
]),
androidSdk: null,
androidWorkflow: AndroidWorkflow(
androidSdk: null,
featureFlags: TestFeatureFlags(),
operatingSystemUtils: FakeOperatingSystemUtils(),
),
);
await expectLater(() async => emulatorManager.getAllAvailableEmulators(),
returnsNormally);
});
testWithoutContext('getEmulatorsById', () async {
final TestEmulatorManager testEmulatorManager = TestEmulatorManager(emulators);
expect(await testEmulatorManager.getEmulatorsMatching('Nexus_5'), <Emulator>[emulator1]);
expect(await testEmulatorManager.getEmulatorsMatching('Nexus_5X'), <Emulator>[emulator2]);
expect(await testEmulatorManager.getEmulatorsMatching('Nexus_5X_API_27_x86'), <Emulator>[emulator2]);
expect(await testEmulatorManager.getEmulatorsMatching('Nexus'), <Emulator>[emulator1, emulator2]);
expect(await testEmulatorManager.getEmulatorsMatching('iOS Simulator'), <Emulator>[emulator3]);
expect(await testEmulatorManager.getEmulatorsMatching('ios'), <Emulator>[emulator3]);
2018-04-18 10:37:59 +00:00
});
testUsingContext('create emulator with a missing avdmanager does not crash.', () async {
sdk.avdManagerPath = null;
final EmulatorManager emulatorManager = EmulatorManager(
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
processManager: FakeProcessManager.list(<FakeCommand>[
const FakeCommand(
command: <String>['emulator', '-list-avds'],
stdout: 'existing-avd-1',
),
]),
androidSdk: sdk,
androidWorkflow: AndroidWorkflow(
androidSdk: sdk,
featureFlags: TestFeatureFlags(),
operatingSystemUtils: FakeOperatingSystemUtils(),
),
);
final CreateEmulatorResult result = await emulatorManager.createEmulator();
expect(result.success, false);
expect(result.error, contains('avdmanager is missing from the Android SDK'));
2018-04-18 10:37:59 +00:00
});
Add --create option to `flutter emulators` command (#18235) * Add --create option to flutter emulators * Tweaks to error message * Simplify emulator search logic * Make name optional * Add a note about this option being used with --create * Tweaks to help information * Switch to processManager for easier testing * Don't crash on missing files or missing properties in Android Emulator * Move name suffixing into emulator manager This allows it to be tested in the EmulatorManager tests and also used by daemon later if desired. * Pass the context's android SDK through so it can be mocked by tests * Misc fixes * Add tests around emulator creation Process calls are mocked to avoid needing a real SDK (and to be fast). Full integration tests may be useful, but may require ensuring all build environments etc. are set up correctly. * Simplify avdManagerPath Previous changes were to emulatorPath! * Fix lint errors * Fix incorrect file exgtension for Windows * Fix an issue where no system images would crash reduce throws on an empty collection. * Fix "null" appearing in error messages The name we attempted to use will now always be returned, even in the case of failure. * Add additional info to missing-system-image failure message On Windows after installing Andriod Studio I didn't have any of these and got this message. Installing with sdkmanager fixed the issue. * Fix thrown errors runResult had a toString() but we moved to ProcessResult when switching to ProcessManager to this ended up throwing "Instance of ProcessResult". * Fix package import * Fix more package imports * Move mock implementation into Mock class There seemed to be issues using Lists in args with Mockito that I couldn't figure out (docs say to use typed() but I couldn't make this compile with these lists still).. * Rename method that's ambigious now we have create * Handle where there's no avd path * Add another toList() :( * Remove comment that was rewritten * Fix forbidden import * Make optional arg more obviously optional * Reformat doc * Note that we create a pixel device in help text * Make this a named arg
2018-06-28 07:07:40 +00:00
// iOS discovery uses context.
testUsingContext('create emulator with an empty name does not fail', () async {
final EmulatorManager emulatorManager = EmulatorManager(
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
processManager: FakeProcessManager.list(<FakeCommand>[
const FakeCommand(
command: <String>['emulator', '-list-avds'],
stdout: 'existing-avd-1',
),
const FakeCommand(
command: <String>['avdmanager', 'list', 'device', '-c'],
stdout: 'test\ntest2\npixel\npixel-xl\n',
),
kListEmulatorsCommand,
const FakeCommand(
command: <String>[
'avdmanager',
'create',
'avd',
'-n',
'flutter_emulator',
'-k',
'system-images;android-27;google_apis_playstore;x86',
'-d',
'pixel',
],
)
]),
androidSdk: sdk,
androidWorkflow: AndroidWorkflow(
androidSdk: sdk,
featureFlags: TestFeatureFlags(),
operatingSystemUtils: FakeOperatingSystemUtils(),
),
);
final CreateEmulatorResult result = await emulatorManager.createEmulator();
expect(result.success, true);
Add --create option to `flutter emulators` command (#18235) * Add --create option to flutter emulators * Tweaks to error message * Simplify emulator search logic * Make name optional * Add a note about this option being used with --create * Tweaks to help information * Switch to processManager for easier testing * Don't crash on missing files or missing properties in Android Emulator * Move name suffixing into emulator manager This allows it to be tested in the EmulatorManager tests and also used by daemon later if desired. * Pass the context's android SDK through so it can be mocked by tests * Misc fixes * Add tests around emulator creation Process calls are mocked to avoid needing a real SDK (and to be fast). Full integration tests may be useful, but may require ensuring all build environments etc. are set up correctly. * Simplify avdManagerPath Previous changes were to emulatorPath! * Fix lint errors * Fix incorrect file exgtension for Windows * Fix an issue where no system images would crash reduce throws on an empty collection. * Fix "null" appearing in error messages The name we attempted to use will now always be returned, even in the case of failure. * Add additional info to missing-system-image failure message On Windows after installing Andriod Studio I didn't have any of these and got this message. Installing with sdkmanager fixed the issue. * Fix thrown errors runResult had a toString() but we moved to ProcessResult when switching to ProcessManager to this ended up throwing "Instance of ProcessResult". * Fix package import * Fix more package imports * Move mock implementation into Mock class There seemed to be issues using Lists in args with Mockito that I couldn't figure out (docs say to use typed() but I couldn't make this compile with these lists still).. * Rename method that's ambigious now we have create * Handle where there's no avd path * Add another toList() :( * Remove comment that was rewritten * Fix forbidden import * Make optional arg more obviously optional * Reformat doc * Note that we create a pixel device in help text * Make this a named arg
2018-06-28 07:07:40 +00:00
});
testWithoutContext('create emulator with a unique name does not throw', () async {
final EmulatorManager emulatorManager = EmulatorManager(
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
processManager: FakeProcessManager.list(<FakeCommand>[
const FakeCommand(
command: <String>['avdmanager', 'list', 'device', '-c'],
stdout: 'test\ntest2\npixel\npixel-xl\n',
),
kListEmulatorsCommand,
const FakeCommand(
command: <String>[
'avdmanager',
'create',
'avd',
// The specified name is given with the -n flag.
'-n',
'test',
'-k',
'system-images;android-27;google_apis_playstore;x86',
'-d',
'pixel',
],
)
]),
androidSdk: sdk,
androidWorkflow: AndroidWorkflow(
androidSdk: sdk,
featureFlags: TestFeatureFlags(),
operatingSystemUtils: FakeOperatingSystemUtils(),
),
);
final CreateEmulatorResult result = await emulatorManager.createEmulator(name: 'test');
expect(result.success, true);
Add --create option to `flutter emulators` command (#18235) * Add --create option to flutter emulators * Tweaks to error message * Simplify emulator search logic * Make name optional * Add a note about this option being used with --create * Tweaks to help information * Switch to processManager for easier testing * Don't crash on missing files or missing properties in Android Emulator * Move name suffixing into emulator manager This allows it to be tested in the EmulatorManager tests and also used by daemon later if desired. * Pass the context's android SDK through so it can be mocked by tests * Misc fixes * Add tests around emulator creation Process calls are mocked to avoid needing a real SDK (and to be fast). Full integration tests may be useful, but may require ensuring all build environments etc. are set up correctly. * Simplify avdManagerPath Previous changes were to emulatorPath! * Fix lint errors * Fix incorrect file exgtension for Windows * Fix an issue where no system images would crash reduce throws on an empty collection. * Fix "null" appearing in error messages The name we attempted to use will now always be returned, even in the case of failure. * Add additional info to missing-system-image failure message On Windows after installing Andriod Studio I didn't have any of these and got this message. Installing with sdkmanager fixed the issue. * Fix thrown errors runResult had a toString() but we moved to ProcessResult when switching to ProcessManager to this ended up throwing "Instance of ProcessResult". * Fix package import * Fix more package imports * Move mock implementation into Mock class There seemed to be issues using Lists in args with Mockito that I couldn't figure out (docs say to use typed() but I couldn't make this compile with these lists still).. * Rename method that's ambigious now we have create * Handle where there's no avd path * Add another toList() :( * Remove comment that was rewritten * Fix forbidden import * Make optional arg more obviously optional * Reformat doc * Note that we create a pixel device in help text * Make this a named arg
2018-06-28 07:07:40 +00:00
});
testWithoutContext('create emulator with an existing name errors', () async {
final EmulatorManager emulatorManager = EmulatorManager(
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
processManager: FakeProcessManager.list(<FakeCommand>[
const FakeCommand(
command: <String>['avdmanager', 'list', 'device', '-c'],
stdout: 'test\ntest2\npixel\npixel-xl\n',
),
kListEmulatorsCommand,
const FakeCommand(
command: <String>[
'avdmanager',
'create',
'avd',
'-n',
'existing-avd-1',
'-k',
'system-images;android-27;google_apis_playstore;x86',
'-d',
'pixel',
],
exitCode: 1,
stderr: "Error: Android Virtual Device 'existing-avd-1' already exists.\n"
'Use --force if you want to replace it.'
)
]),
androidSdk: sdk,
androidWorkflow: AndroidWorkflow(
androidSdk: sdk,
featureFlags: TestFeatureFlags(),
operatingSystemUtils: FakeOperatingSystemUtils(),
),
);
final CreateEmulatorResult result = await emulatorManager.createEmulator(name: 'existing-avd-1');
expect(result.success, false);
Add --create option to `flutter emulators` command (#18235) * Add --create option to flutter emulators * Tweaks to error message * Simplify emulator search logic * Make name optional * Add a note about this option being used with --create * Tweaks to help information * Switch to processManager for easier testing * Don't crash on missing files or missing properties in Android Emulator * Move name suffixing into emulator manager This allows it to be tested in the EmulatorManager tests and also used by daemon later if desired. * Pass the context's android SDK through so it can be mocked by tests * Misc fixes * Add tests around emulator creation Process calls are mocked to avoid needing a real SDK (and to be fast). Full integration tests may be useful, but may require ensuring all build environments etc. are set up correctly. * Simplify avdManagerPath Previous changes were to emulatorPath! * Fix lint errors * Fix incorrect file exgtension for Windows * Fix an issue where no system images would crash reduce throws on an empty collection. * Fix "null" appearing in error messages The name we attempted to use will now always be returned, even in the case of failure. * Add additional info to missing-system-image failure message On Windows after installing Andriod Studio I didn't have any of these and got this message. Installing with sdkmanager fixed the issue. * Fix thrown errors runResult had a toString() but we moved to ProcessResult when switching to ProcessManager to this ended up throwing "Instance of ProcessResult". * Fix package import * Fix more package imports * Move mock implementation into Mock class There seemed to be issues using Lists in args with Mockito that I couldn't figure out (docs say to use typed() but I couldn't make this compile with these lists still).. * Rename method that's ambigious now we have create * Handle where there's no avd path * Add another toList() :( * Remove comment that was rewritten * Fix forbidden import * Make optional arg more obviously optional * Reformat doc * Note that we create a pixel device in help text * Make this a named arg
2018-06-28 07:07:40 +00:00
});
// iOS discovery uses context.
testUsingContext('create emulator without a name but when default exists adds a suffix', () async {
final EmulatorManager emulatorManager = EmulatorManager(
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
processManager: FakeProcessManager.list(<FakeCommand>[
const FakeCommand(
command: <String>['emulator', '-list-avds'],
stdout: 'existing-avd-1\nflutter_emulator',
),
const FakeCommand(
command: <String>['avdmanager', 'list', 'device', '-c'],
stdout: 'test\ntest2\npixel\npixel-xl\n',
),
kListEmulatorsCommand,
const FakeCommand(
command: <String>[
'avdmanager',
'create',
'avd',
// a "_2" suffix is added to disambiguate from the existing emulator.
'-n',
'flutter_emulator_2',
'-k',
'system-images;android-27;google_apis_playstore;x86',
'-d',
'pixel',
],
)
]),
androidSdk: sdk,
androidWorkflow: AndroidWorkflow(
androidSdk: sdk,
featureFlags: TestFeatureFlags(),
operatingSystemUtils: FakeOperatingSystemUtils(),
),
);
final CreateEmulatorResult result = await emulatorManager.createEmulator();
expect(result.success, true);
expect(result.emulatorName, 'flutter_emulator_2');
Add --create option to `flutter emulators` command (#18235) * Add --create option to flutter emulators * Tweaks to error message * Simplify emulator search logic * Make name optional * Add a note about this option being used with --create * Tweaks to help information * Switch to processManager for easier testing * Don't crash on missing files or missing properties in Android Emulator * Move name suffixing into emulator manager This allows it to be tested in the EmulatorManager tests and also used by daemon later if desired. * Pass the context's android SDK through so it can be mocked by tests * Misc fixes * Add tests around emulator creation Process calls are mocked to avoid needing a real SDK (and to be fast). Full integration tests may be useful, but may require ensuring all build environments etc. are set up correctly. * Simplify avdManagerPath Previous changes were to emulatorPath! * Fix lint errors * Fix incorrect file exgtension for Windows * Fix an issue where no system images would crash reduce throws on an empty collection. * Fix "null" appearing in error messages The name we attempted to use will now always be returned, even in the case of failure. * Add additional info to missing-system-image failure message On Windows after installing Andriod Studio I didn't have any of these and got this message. Installing with sdkmanager fixed the issue. * Fix thrown errors runResult had a toString() but we moved to ProcessResult when switching to ProcessManager to this ended up throwing "Instance of ProcessResult". * Fix package import * Fix more package imports * Move mock implementation into Mock class There seemed to be issues using Lists in args with Mockito that I couldn't figure out (docs say to use typed() but I couldn't make this compile with these lists still).. * Rename method that's ambigious now we have create * Handle where there's no avd path * Add another toList() :( * Remove comment that was rewritten * Fix forbidden import * Make optional arg more obviously optional * Reformat doc * Note that we create a pixel device in help text * Make this a named arg
2018-06-28 07:07:40 +00:00
});
2018-04-18 10:37:59 +00:00
});
group('ios_emulators', () {
testUsingContext('runs correct launch commands', () async {
fileSystem.directory('/fake/Xcode.app/Contents/Developer/Applications/Simulator.app').createSync(recursive: true);
fakeProcessManager.addCommands(
<FakeCommand>[
const FakeCommand(
command: <String>['/usr/bin/xcode-select', '--print-path'],
stdout: '/fake/Xcode.app/Contents/Developer',
),
const FakeCommand(command: <String>[
'open',
'-n',
'-a',
'/fake/Xcode.app/Contents/Developer/Applications/Simulator.app',
]),
const FakeCommand(command: <String>[
'open',
'-a',
'/fake/Xcode.app/Contents/Developer/Applications/Simulator.app',
])
],
);
const Emulator emulator = IOSEmulator('ios');
await emulator.launch();
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
}, overrides: <Type, Generator>{
ProcessManager: () => fakeProcessManager,
Xcode: () => xcode,
FileSystem: () => fileSystem,
});
});
2018-04-18 10:37:59 +00:00
}
class TestEmulatorManager extends EmulatorManager {
TestEmulatorManager(this.allEmulators);
2018-10-04 05:28:07 +00:00
final List<Emulator> allEmulators;
2018-04-18 10:37:59 +00:00
@override
2018-05-03 16:12:31 +00:00
Future<List<Emulator>> getAllAvailableEmulators() {
return Future<List<Emulator>>.value(allEmulators);
2018-04-18 10:37:59 +00:00
}
}
class FakeEmulator extends Emulator {
const FakeEmulator(String id, this.name, this.manufacturer)
: super(id, true);
2018-04-18 10:37:59 +00:00
@override
final String name;
Add --create option to `flutter emulators` command (#18235) * Add --create option to flutter emulators * Tweaks to error message * Simplify emulator search logic * Make name optional * Add a note about this option being used with --create * Tweaks to help information * Switch to processManager for easier testing * Don't crash on missing files or missing properties in Android Emulator * Move name suffixing into emulator manager This allows it to be tested in the EmulatorManager tests and also used by daemon later if desired. * Pass the context's android SDK through so it can be mocked by tests * Misc fixes * Add tests around emulator creation Process calls are mocked to avoid needing a real SDK (and to be fast). Full integration tests may be useful, but may require ensuring all build environments etc. are set up correctly. * Simplify avdManagerPath Previous changes were to emulatorPath! * Fix lint errors * Fix incorrect file exgtension for Windows * Fix an issue where no system images would crash reduce throws on an empty collection. * Fix "null" appearing in error messages The name we attempted to use will now always be returned, even in the case of failure. * Add additional info to missing-system-image failure message On Windows after installing Andriod Studio I didn't have any of these and got this message. Installing with sdkmanager fixed the issue. * Fix thrown errors runResult had a toString() but we moved to ProcessResult when switching to ProcessManager to this ended up throwing "Instance of ProcessResult". * Fix package import * Fix more package imports * Move mock implementation into Mock class There seemed to be issues using Lists in args with Mockito that I couldn't figure out (docs say to use typed() but I couldn't make this compile with these lists still).. * Rename method that's ambigious now we have create * Handle where there's no avd path * Add another toList() :( * Remove comment that was rewritten * Fix forbidden import * Make optional arg more obviously optional * Reformat doc * Note that we create a pixel device in help text * Make this a named arg
2018-06-28 07:07:40 +00:00
@override
final String manufacturer;
Add --create option to `flutter emulators` command (#18235) * Add --create option to flutter emulators * Tweaks to error message * Simplify emulator search logic * Make name optional * Add a note about this option being used with --create * Tweaks to help information * Switch to processManager for easier testing * Don't crash on missing files or missing properties in Android Emulator * Move name suffixing into emulator manager This allows it to be tested in the EmulatorManager tests and also used by daemon later if desired. * Pass the context's android SDK through so it can be mocked by tests * Misc fixes * Add tests around emulator creation Process calls are mocked to avoid needing a real SDK (and to be fast). Full integration tests may be useful, but may require ensuring all build environments etc. are set up correctly. * Simplify avdManagerPath Previous changes were to emulatorPath! * Fix lint errors * Fix incorrect file exgtension for Windows * Fix an issue where no system images would crash reduce throws on an empty collection. * Fix "null" appearing in error messages The name we attempted to use will now always be returned, even in the case of failure. * Add additional info to missing-system-image failure message On Windows after installing Andriod Studio I didn't have any of these and got this message. Installing with sdkmanager fixed the issue. * Fix thrown errors runResult had a toString() but we moved to ProcessResult when switching to ProcessManager to this ended up throwing "Instance of ProcessResult". * Fix package import * Fix more package imports * Move mock implementation into Mock class There seemed to be issues using Lists in args with Mockito that I couldn't figure out (docs say to use typed() but I couldn't make this compile with these lists still).. * Rename method that's ambigious now we have create * Handle where there's no avd path * Add another toList() :( * Remove comment that was rewritten * Fix forbidden import * Make optional arg more obviously optional * Reformat doc * Note that we create a pixel device in help text * Make this a named arg
2018-06-28 07:07:40 +00:00
@override
Category get category => Category.mobile;
@override
PlatformType get platformType => PlatformType.android;
2018-04-18 13:50:16 +00:00
@override
Future<void> launch() {
throw UnimplementedError('Not implemented in Mock');
2018-04-18 13:50:16 +00:00
}
2018-04-18 10:37:59 +00:00
}
class FakeAndroidSdk extends Fake implements AndroidSdk {
@override
String avdManagerPath;
@override
String emulatorPath;
@override
String adbPath;
@override
String getAvdManagerPath() => avdManagerPath;
@override
String getAvdPath() => 'avd';
@override
Map<String, String> get sdkManagerEnv => <String, String>{};
}