[flutter_tools] well known device ids (#85184)

This commit is contained in:
Jonah Williams
2021-06-24 18:46:04 -07:00
committed by GitHub
parent c22bedc5a6
commit 88e756d19e
21 changed files with 166 additions and 26 deletions

View File

@@ -71,6 +71,33 @@ void main() {
expect(logger.traceText, contains('Ignored error discovering 0553790d0a4e726f'));
});
testWithoutContext('getDeviceById exact matcher with well known ID', () async {
final FakeDevice device1 = FakeDevice('Windows', 'windows');
final FakeDevice device2 = FakeDevice('Nexus 5X', '01abfc49119c410e');
final FakeDevice device3 = FakeDevice('iPod touch', '82564b38861a9a5');
final List<Device> devices = <Device>[device1, device2, device3];
final BufferLogger logger = BufferLogger.test();
// Because the well known ID will match, no other device discovery will run.
final DeviceManager deviceManager = TestDeviceManager(
devices,
deviceDiscoveryOverrides: <DeviceDiscovery>[
ThrowingPollingDeviceDiscovery(),
LongPollingDeviceDiscovery(),
],
logger: logger,
terminal: Terminal.test(),
wellKnownId: 'windows',
);
Future<void> expectDevice(String id, List<Device> expected) async {
deviceManager.specifiedDeviceId = id;
expect(await deviceManager.getDevicesById(id), expected);
}
await expectDevice('windows', <Device>[device1]);
expect(logger.traceText, isEmpty);
});
testWithoutContext('getDeviceById prefix matcher', () async {
final FakeDevice device1 = FakeDevice('Nexus 5', '0553790d0a4e726f');
final FakeDevice device2 = FakeDevice('Nexus 5X', '01abfc49119c410e');
@@ -467,8 +494,12 @@ class TestDeviceManager extends DeviceManager {
List<DeviceDiscovery> deviceDiscoveryOverrides,
@required Logger logger,
@required Terminal terminal,
String wellKnownId,
}) : super(logger: logger, terminal: terminal, userMessages: UserMessages()) {
_fakeDeviceDiscoverer = FakePollingDeviceDiscovery();
if (wellKnownId != null) {
_fakeDeviceDiscoverer.wellKnownIds.add(wellKnownId);
}
_deviceDiscoverers = <DeviceDiscovery>[
_fakeDeviceDiscoverer,
if (deviceDiscoveryOverrides != null)
@@ -516,6 +547,9 @@ class MockDeviceDiscovery extends Fake implements DeviceDiscovery {
discoverDevicesCalled += 1;
return deviceValues;
}
@override
List<String> get wellKnownIds => <String>[];
}
class FakeFlutterProject extends Fake implements FlutterProject {}
@@ -545,6 +579,9 @@ class LongPollingDeviceDiscovery extends PollingDeviceDiscovery {
@override
bool get canListAnything => true;
@override
final List<String> wellKnownIds = <String>[];
}
class ThrowingPollingDeviceDiscovery extends PollingDeviceDiscovery {
@@ -560,6 +597,9 @@ class ThrowingPollingDeviceDiscovery extends PollingDeviceDiscovery {
@override
bool get canListAnything => true;
@override
List<String> get wellKnownIds => <String>[];
}
class FakeTerminal extends Fake implements Terminal {

View File

@@ -96,6 +96,17 @@ void main() {
).devices, hasLength(1));
});
testWithoutContext('LinuxDevice has well known id "linux"', () async {
expect(LinuxDevices(
fileSystem: MemoryFileSystem.test(),
platform: linux,
featureFlags: TestFeatureFlags(isLinuxEnabled: true),
logger: BufferLogger.test(),
processManager: FakeProcessManager.any(),
operatingSystemUtils: FakeOperatingSystemUtils(),
).wellKnownIds, <String>['linux']);
});
testWithoutContext('LinuxDevice: discoverDevices', () async {
// Timeout ignored.
final List<Device> devices = await LinuxDevices(

View File

@@ -132,6 +132,22 @@ void main() {
expect(await macOSDevices.devices, hasLength(1));
});
testWithoutContext('has a well known device id macos', () async {
final MacOSDevices macOSDevices = MacOSDevices(
fileSystem: MemoryFileSystem.test(),
processManager: FakeProcessManager.any(),
logger: BufferLogger.test(),
platform: macOS,
operatingSystemUtils: FakeOperatingSystemUtils(),
macOSWorkflow: MacOSWorkflow(
featureFlags: TestFeatureFlags(isMacOSEnabled: true),
platform: macOS,
),
);
expect(macOSDevices.wellKnownIds, <String>['macos']);
});
testWithoutContext('can discover devices with a provided timeout', () async {
final MacOSDevices macOSDevices = MacOSDevices(
fileSystem: MemoryFileSystem.test(),

View File

@@ -9,7 +9,6 @@ import 'dart:async';
import 'package:file/file.dart';
import 'package:file/memory.dart';
import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/base/config.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/build_info.dart';
@@ -181,7 +180,6 @@ FlutterTesterDevices setUpFlutterTesterDevices() {
artifacts: Artifacts.test(),
processManager: FakeProcessManager.any(),
fileSystem: MemoryFileSystem.test(),
config: Config.test(),
flutterVersion: FakeFlutterVersion(),
operatingSystemUtils: FakeOperatingSystemUtils(),
);

View File

@@ -124,6 +124,21 @@ void main() {
contains(isA<GoogleChromeDevice>()));
});
testWithoutContext('Has well known device ids chrome, edge, and web-server', () async {
final WebDevices webDevices = WebDevices(
featureFlags: TestFeatureFlags(isWebEnabled: true),
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
platform: FakePlatform(
operatingSystem: 'linux',
environment: <String, String>{}
),
processManager: FakeProcessManager.any(),
);
expect(webDevices.wellKnownIds, <String>['chrome', 'web-server', 'edge']);
});
testWithoutContext('Chrome device is not listed when Chrome cannot be run', () async {
final FakeProcessManager processManager = FakeProcessManager.empty();
processManager.excludedExecutables = <String>{kLinuxExecutable};

View File

@@ -116,6 +116,22 @@ void main() {
).devices, hasLength(2));
});
testWithoutContext('WindowsDevices has windows and winuwp well known devices', () async {
final FeatureFlags featureFlags = TestFeatureFlags(isWindowsEnabled: true, isWindowsUwpEnabled: true);
expect(WindowsDevices(
windowsWorkflow: WindowsWorkflow(
featureFlags: featureFlags,
platform: FakePlatform(operatingSystem: 'windows')
),
operatingSystemUtils: FakeOperatingSystemUtils(),
logger: BufferLogger.test(),
processManager: FakeProcessManager.any(),
fileSystem: MemoryFileSystem.test(),
featureFlags: featureFlags,
uwptool: FakeUwpTool(),
).wellKnownIds, <String>['windows', 'winuwp']);
});
testWithoutContext('WindowsDevices ignores the timeout provided to discoverDevices', () async {
final WindowsDevices windowsDevices = WindowsDevices(
windowsWorkflow: WindowsWorkflow(

View File

@@ -175,6 +175,9 @@ class FakePollingDeviceDiscovery extends PollingDeviceDiscovery {
@override
Stream<Device> get onRemoved => _onRemovedController.stream;
@override
List<String> wellKnownIds = <String>[];
}
/// A fake implementation of the [DeviceLogReader].