Add polling module discovery for Fuchsia (#24994)
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_tools/src/base/logger.dart';
|
||||
import 'package:flutter_tools/src/vmservice.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:process/process.dart';
|
||||
|
||||
@@ -198,6 +200,65 @@ void main() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
group(FuchsiaIsolateDiscoveryProtocol, () {
|
||||
Future<Uri> findUri(List<MockFlutterView> views, String expectedIsolateName) {
|
||||
final MockPortForwarder portForwarder = MockPortForwarder();
|
||||
final MockVMService vmService = MockVMService();
|
||||
final MockVM vm = MockVM();
|
||||
vm.vmService = vmService;
|
||||
vmService.vm = vm;
|
||||
vm.views = views;
|
||||
for (MockFlutterView view in views) {
|
||||
view.owner = vm;
|
||||
}
|
||||
final MockFuchsiaDevice fuchsiaDevice = MockFuchsiaDevice('123', portForwarder, false);
|
||||
final FuchsiaIsolateDiscoveryProtocol discoveryProtocol = FuchsiaIsolateDiscoveryProtocol(
|
||||
fuchsiaDevice,
|
||||
expectedIsolateName,
|
||||
(Uri uri) async => vmService,
|
||||
true // only poll once.
|
||||
);
|
||||
when(fuchsiaDevice.servicePorts()).thenAnswer((Invocation invocation) async => <int>[1]);
|
||||
when(portForwarder.forward(1)).thenAnswer((Invocation invocation) async => 2);
|
||||
when(vmService.getVM()).thenAnswer((Invocation invocation) => Future<void>.value(null));
|
||||
when(vmService.refreshViews()).thenAnswer((Invocation invocation) => Future<void>.value(null));
|
||||
when(vmService.httpAddress).thenReturn(Uri.parse('example'));
|
||||
return discoveryProtocol.uri;
|
||||
}
|
||||
testUsingContext('can find flutter view with matching isolate name', () async {
|
||||
const String expectedIsolateName = 'foobar';
|
||||
final Uri uri = await findUri(<MockFlutterView>[
|
||||
MockFlutterView(null), // no ui isolate.
|
||||
MockFlutterView(MockIsolate('wrong name')), // wrong name.
|
||||
MockFlutterView(MockIsolate(expectedIsolateName)), // matching name.
|
||||
], expectedIsolateName);
|
||||
expect(uri.toString(), 'http://${InternetAddress.loopbackIPv4.address}:0/');
|
||||
}, overrides: <Type, Generator>{
|
||||
Logger: () => StdoutLogger(),
|
||||
});
|
||||
|
||||
testUsingContext('can handle flutter view without matching isolate name', () async {
|
||||
const String expectedIsolateName = 'foobar';
|
||||
final Future<Uri> uri = findUri(<MockFlutterView>[
|
||||
MockFlutterView(null), // no ui isolate.
|
||||
MockFlutterView(MockIsolate('wrong name')), // wrong name.
|
||||
], expectedIsolateName);
|
||||
expect(uri, throwsException);
|
||||
}, overrides: <Type, Generator>{
|
||||
Logger: () => StdoutLogger(),
|
||||
});
|
||||
|
||||
testUsingContext('can handle non flutter view', () async {
|
||||
const String expectedIsolateName = 'foobar';
|
||||
final Future<Uri> uri = findUri(<MockFlutterView>[
|
||||
MockFlutterView(null), // no ui isolate.
|
||||
], expectedIsolateName);
|
||||
expect(uri, throwsException);
|
||||
}, overrides: <Type, Generator>{
|
||||
Logger: () => StdoutLogger(),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
class MockProcessManager extends Mock implements ProcessManager {}
|
||||
@@ -207,3 +268,46 @@ class MockProcessResult extends Mock implements ProcessResult {}
|
||||
class MockFile extends Mock implements File {}
|
||||
|
||||
class MockProcess extends Mock implements Process {}
|
||||
|
||||
class MockFuchsiaDevice extends Mock implements FuchsiaDevice {
|
||||
MockFuchsiaDevice(this.id, this.portForwarder, this.ipv6);
|
||||
|
||||
@override
|
||||
final bool ipv6;
|
||||
@override
|
||||
final String id;
|
||||
@override
|
||||
final DevicePortForwarder portForwarder;
|
||||
}
|
||||
|
||||
class MockPortForwarder extends Mock implements DevicePortForwarder {}
|
||||
|
||||
class MockVMService extends Mock implements VMService {
|
||||
@override
|
||||
VM vm;
|
||||
}
|
||||
|
||||
class MockVM extends Mock implements VM {
|
||||
@override
|
||||
VMService vmService;
|
||||
|
||||
@override
|
||||
List<FlutterView> views;
|
||||
}
|
||||
|
||||
class MockFlutterView extends Mock implements FlutterView {
|
||||
MockFlutterView(this.uiIsolate);
|
||||
|
||||
@override
|
||||
final Isolate uiIsolate;
|
||||
|
||||
@override
|
||||
ServiceObjectOwner owner;
|
||||
}
|
||||
|
||||
class MockIsolate extends Mock implements Isolate {
|
||||
MockIsolate(this.name);
|
||||
|
||||
@override
|
||||
final String name;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user