[frdb] Fix JSON casting in RPC calls. (#18655)

This prevents the error:

`type 'List<dynamic>' is not a subtype of type 'List<Map<String, dynamic>>' `

The test added fails when dart_vm.dart is reverted to `master`, and succeeds in
its current state.  This issue was run into while connecting to the
Dart VM.
This commit is contained in:
Andrew Davies
2018-06-22 14:00:49 -07:00
committed by GitHub
parent 7fdb404a13
commit 08d3deec80
2 changed files with 103 additions and 4 deletions

View File

@@ -107,6 +107,63 @@ void main() {
expect(views[2].name, 'file://flutterBinary2');
});
test('basic flutter view parsing with casting checks', () async {
final Map<String, dynamic> flutterViewCannedResponses = <String, dynamic>{
'views': <dynamic>[
<String, dynamic>{
'type': 'FlutterView',
'id': 'flutterView0',
},
<String, dynamic>{
'type': 'FlutterView',
'id': 'flutterView1',
'isolate': <String, dynamic>{
'type': '@Isolate',
'fixedId': 'true',
'id': 'isolates/1',
'name': 'file://flutterBinary1',
'number': '1',
},
},
<String, dynamic>{
'type': 'FlutterView',
'id': 'flutterView2',
'isolate': <String, dynamic>{
'type': '@Isolate',
'fixedId': 'true',
'id': 'isolates/2',
'name': 'file://flutterBinary2',
'number': '2',
},
},
],
};
Future<json_rpc.Peer> mockVmConnectionFunction(Uri uri) {
when(mockPeer.sendRequest(
typed<String>(any), typed<Map<String, dynamic>>(any)))
.thenAnswer((_) => new Future<Map<String, dynamic>>(
() => flutterViewCannedResponses));
return new Future<json_rpc.Peer>(() => mockPeer);
}
fuchsiaVmServiceConnectionFunction = mockVmConnectionFunction;
final DartVm vm =
await DartVm.connect(Uri.parse('http://whatever.com/ws'));
expect(vm, isNot(null));
final List<FlutterView> 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<String, dynamic> flutterViewCannedResponseMissingId =
<String, dynamic>{
@@ -150,6 +207,50 @@ void main() {
expect(failingFunction, throwsA(const isInstanceOf<RpcFormatError>()));
});
test('get isolates by pattern', () async {
final Map<String, dynamic> vmCannedResponse = <String, dynamic>{
'isolates': <dynamic>[
<String, dynamic>{
'type': '@Isolate',
'fixedId': 'true',
'id': 'isolates/1',
'name': 'file://thingThatWillNotMatch:main()',
'number': '1',
},
<String, dynamic>{
'type': '@Isolate',
'fixedId': 'true',
'id': 'isolates/1',
'name': 'file://flutterBinary1:main()',
'number': '2',
},
<String, dynamic>{
'type': '@Isolate',
'fixedId': 'true',
'id': 'isolates/2',
'name': 'file://flutterBinary2:main()',
'number': '3',
},
],
};
Future<json_rpc.Peer> mockVmConnectionFunction(Uri uri) {
when(mockPeer.sendRequest(
typed<String>(any), typed<Map<String, dynamic>>(any)))
.thenAnswer((_) =>
new Future<Map<String, dynamic>>(() => vmCannedResponse));
return new Future<json_rpc.Peer>(() => mockPeer);
}
fuchsiaVmServiceConnectionFunction = mockVmConnectionFunction;
final DartVm vm =
await DartVm.connect(Uri.parse('http://whatever.com/ws'));
expect(vm, isNot(null));
final List<IsolateRef> isolates =
await vm.getMainIsolatesByPattern('flutterBinary');
expect(isolates.length, 2);
});
test('invalid flutter view missing ID', () async {
final Map<String, dynamic> flutterViewCannedResponseMissingIsolateName =
<String, dynamic>{