Make device discovery asynchronous (#10803)
Migrates DeviceDiscovery.devices and all device-specific lookup to be asynchronous.
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:file/file.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/ios/devices.dart';
|
||||
@@ -30,15 +32,15 @@ void main() {
|
||||
|
||||
testUsingContext('return no devices if Xcode is not installed', () async {
|
||||
when(mockXcode.isInstalled).thenReturn(false);
|
||||
expect(IOSDevice.getAttachedDevices(), isEmpty);
|
||||
expect(await IOSDevice.getAttachedDevices(), isEmpty);
|
||||
}, overrides: <Type, Generator>{
|
||||
Xcode: () => mockXcode,
|
||||
});
|
||||
|
||||
testUsingContext('returns no devices if none are attached', () async {
|
||||
when(mockXcode.isInstalled).thenReturn(true);
|
||||
when(mockXcode.getAvailableDevices()).thenReturn('');
|
||||
final List<IOSDevice> devices = IOSDevice.getAttachedDevices();
|
||||
when(mockXcode.getAvailableDevices()).thenReturn(new Future<String>.value(''));
|
||||
final List<IOSDevice> devices = await IOSDevice.getAttachedDevices();
|
||||
expect(devices, isEmpty);
|
||||
}, overrides: <Type, Generator>{
|
||||
Xcode: () => mockXcode,
|
||||
@@ -46,7 +48,7 @@ void main() {
|
||||
|
||||
testUsingContext('returns attached devices', () async {
|
||||
when(mockXcode.isInstalled).thenReturn(true);
|
||||
when(mockXcode.getAvailableDevices()).thenReturn('''
|
||||
when(mockXcode.getAvailableDevices()).thenReturn(new Future<String>.value('''
|
||||
Known Devices:
|
||||
je-mappelle-horse [ED6552C4-B774-5A4E-8B5A-606710C87C77]
|
||||
La tele me regarde (10.3.2) [98206e7a4afd4aedaff06e687594e089dede3c44]
|
||||
@@ -55,8 +57,8 @@ iPhone 6 Plus (9.3) [FBA880E6-4020-49A5-8083-DCD50CA5FA09] (Simulator)
|
||||
iPhone 6s (11.0) [E805F496-FC6A-4EA4-92FF-B7901FF4E7CC] (Simulator)
|
||||
iPhone 7 (11.0) + Apple Watch Series 2 - 38mm (4.0) [60027FDD-4A7A-42BF-978F-C2209D27AD61] (Simulator)
|
||||
iPhone SE (11.0) [667E8DCD-5DCD-4C80-93A9-60D1D995206F] (Simulator)
|
||||
''');
|
||||
final List<IOSDevice> devices = IOSDevice.getAttachedDevices();
|
||||
'''));
|
||||
final List<IOSDevice> devices = await IOSDevice.getAttachedDevices();
|
||||
expect(devices, hasLength(2));
|
||||
expect(devices[0].id, '98206e7a4afd4aedaff06e687594e089dede3c44');
|
||||
expect(devices[0].name, 'La tele me regarde');
|
||||
|
||||
@@ -37,7 +37,7 @@ class MockPollingDeviceDiscovery extends PollingDeviceDiscovery {
|
||||
MockPollingDeviceDiscovery() : super('mock');
|
||||
|
||||
@override
|
||||
List<Device> pollingGetDevices() => _devices;
|
||||
Future<List<Device>> pollingGetDevices() async => _devices;
|
||||
|
||||
@override
|
||||
bool get supportsPlatform => true;
|
||||
@@ -52,7 +52,7 @@ class MockPollingDeviceDiscovery extends PollingDeviceDiscovery {
|
||||
}
|
||||
|
||||
@override
|
||||
List<Device> get devices => _devices;
|
||||
Future<List<Device>> get devices async => _devices;
|
||||
|
||||
@override
|
||||
Stream<Device> get onAdded => _onAddedController.stream;
|
||||
|
||||
Reference in New Issue
Block a user