diff --git a/packages/fuchsia_remote_debug_protocol/lib/src/dart/dart_vm.dart b/packages/fuchsia_remote_debug_protocol/lib/src/dart/dart_vm.dart index 98df7e6336..67736d6e31 100644 --- a/packages/fuchsia_remote_debug_protocol/lib/src/dart/dart_vm.dart +++ b/packages/fuchsia_remote_debug_protocol/lib/src/dart/dart_vm.dart @@ -122,9 +122,8 @@ class DartVm { Future> getMainIsolatesByPattern(Pattern pattern) async { final Map jsonVmRef = await invokeRpc('getVM', timeout: _kRpcTimeout); - final List> jsonIsolates = jsonVmRef['isolates']; final List result = []; - for (Map jsonIsolate in jsonIsolates) { + for (Map jsonIsolate in jsonVmRef['isolates']) { final String name = jsonIsolate['name']; if (name.contains(pattern) && name.contains(new RegExp(r':main\(\)'))) { result.add(new IsolateRef._fromJson(jsonIsolate, this)); @@ -164,8 +163,7 @@ class DartVm { final List views = []; final Map rpcResponse = await invokeRpc('_flutter.listViews', timeout: _kRpcTimeout); - final List> flutterViewsJson = rpcResponse['views']; - for (Map jsonView in flutterViewsJson) { + for (Map jsonView in rpcResponse['views']) { final FlutterView flutterView = new FlutterView._fromJson(jsonView); if (flutterView != null) { views.add(flutterView); diff --git a/packages/fuchsia_remote_debug_protocol/test/src/dart/dart_vm_test.dart b/packages/fuchsia_remote_debug_protocol/test/src/dart/dart_vm_test.dart index 62c7f9fd66..0b4a6ec36d 100644 --- a/packages/fuchsia_remote_debug_protocol/test/src/dart/dart_vm_test.dart +++ b/packages/fuchsia_remote_debug_protocol/test/src/dart/dart_vm_test.dart @@ -107,6 +107,63 @@ void main() { expect(views[2].name, 'file://flutterBinary2'); }); + test('basic flutter view parsing with casting checks', () async { + final Map flutterViewCannedResponses = { + 'views': [ + { + 'type': 'FlutterView', + 'id': 'flutterView0', + }, + { + 'type': 'FlutterView', + 'id': 'flutterView1', + 'isolate': { + 'type': '@Isolate', + 'fixedId': 'true', + 'id': 'isolates/1', + 'name': 'file://flutterBinary1', + 'number': '1', + }, + }, + { + 'type': 'FlutterView', + 'id': 'flutterView2', + 'isolate': { + 'type': '@Isolate', + 'fixedId': 'true', + 'id': 'isolates/2', + 'name': 'file://flutterBinary2', + 'number': '2', + }, + }, + ], + }; + + Future mockVmConnectionFunction(Uri uri) { + when(mockPeer.sendRequest( + typed(any), typed>(any))) + .thenAnswer((_) => new Future>( + () => flutterViewCannedResponses)); + return new Future(() => mockPeer); + } + + fuchsiaVmServiceConnectionFunction = mockVmConnectionFunction; + final DartVm vm = + await DartVm.connect(Uri.parse('http://whatever.com/ws')); + expect(vm, isNot(null)); + final List views = await vm.getAllFlutterViews(); + expect(views.length, 3); + // Check ID's as they cannot be null. + expect(views[0].id, 'flutterView0'); + expect(views[1].id, 'flutterView1'); + expect(views[2].id, 'flutterView2'); + + // Verify names. + expect(views[0].name, equals(null)); + expect(views[1].name, 'file://flutterBinary1'); + expect(views[2].name, 'file://flutterBinary2'); + }); + test('invalid flutter view missing ID', () async { final Map flutterViewCannedResponseMissingId = { @@ -150,6 +207,50 @@ void main() { expect(failingFunction, throwsA(const isInstanceOf())); }); + test('get isolates by pattern', () async { + final Map vmCannedResponse = { + 'isolates': [ + { + 'type': '@Isolate', + 'fixedId': 'true', + 'id': 'isolates/1', + 'name': 'file://thingThatWillNotMatch:main()', + 'number': '1', + }, + { + 'type': '@Isolate', + 'fixedId': 'true', + 'id': 'isolates/1', + 'name': 'file://flutterBinary1:main()', + 'number': '2', + }, + { + 'type': '@Isolate', + 'fixedId': 'true', + 'id': 'isolates/2', + 'name': 'file://flutterBinary2:main()', + 'number': '3', + }, + ], + }; + + Future mockVmConnectionFunction(Uri uri) { + when(mockPeer.sendRequest( + typed(any), typed>(any))) + .thenAnswer((_) => + new Future>(() => vmCannedResponse)); + return new Future(() => mockPeer); + } + + fuchsiaVmServiceConnectionFunction = mockVmConnectionFunction; + final DartVm vm = + await DartVm.connect(Uri.parse('http://whatever.com/ws')); + expect(vm, isNot(null)); + final List isolates = + await vm.getMainIsolatesByPattern('flutterBinary'); + expect(isolates.length, 2); + }); + test('invalid flutter view missing ID', () async { final Map flutterViewCannedResponseMissingIsolateName = {