[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:
parent
7fdb404a13
commit
08d3deec80
@ -122,9 +122,8 @@ class DartVm {
|
|||||||
Future<List<IsolateRef>> getMainIsolatesByPattern(Pattern pattern) async {
|
Future<List<IsolateRef>> getMainIsolatesByPattern(Pattern pattern) async {
|
||||||
final Map<String, dynamic> jsonVmRef =
|
final Map<String, dynamic> jsonVmRef =
|
||||||
await invokeRpc('getVM', timeout: _kRpcTimeout);
|
await invokeRpc('getVM', timeout: _kRpcTimeout);
|
||||||
final List<Map<String, dynamic>> jsonIsolates = jsonVmRef['isolates'];
|
|
||||||
final List<IsolateRef> result = <IsolateRef>[];
|
final List<IsolateRef> result = <IsolateRef>[];
|
||||||
for (Map<String, dynamic> jsonIsolate in jsonIsolates) {
|
for (Map<String, dynamic> jsonIsolate in jsonVmRef['isolates']) {
|
||||||
final String name = jsonIsolate['name'];
|
final String name = jsonIsolate['name'];
|
||||||
if (name.contains(pattern) && name.contains(new RegExp(r':main\(\)'))) {
|
if (name.contains(pattern) && name.contains(new RegExp(r':main\(\)'))) {
|
||||||
result.add(new IsolateRef._fromJson(jsonIsolate, this));
|
result.add(new IsolateRef._fromJson(jsonIsolate, this));
|
||||||
@ -164,8 +163,7 @@ class DartVm {
|
|||||||
final List<FlutterView> views = <FlutterView>[];
|
final List<FlutterView> views = <FlutterView>[];
|
||||||
final Map<String, dynamic> rpcResponse =
|
final Map<String, dynamic> rpcResponse =
|
||||||
await invokeRpc('_flutter.listViews', timeout: _kRpcTimeout);
|
await invokeRpc('_flutter.listViews', timeout: _kRpcTimeout);
|
||||||
final List<Map<String, dynamic>> flutterViewsJson = rpcResponse['views'];
|
for (Map<String, dynamic> jsonView in rpcResponse['views']) {
|
||||||
for (Map<String, dynamic> jsonView in flutterViewsJson) {
|
|
||||||
final FlutterView flutterView = new FlutterView._fromJson(jsonView);
|
final FlutterView flutterView = new FlutterView._fromJson(jsonView);
|
||||||
if (flutterView != null) {
|
if (flutterView != null) {
|
||||||
views.add(flutterView);
|
views.add(flutterView);
|
||||||
|
@ -107,6 +107,63 @@ void main() {
|
|||||||
expect(views[2].name, 'file://flutterBinary2');
|
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 {
|
test('invalid flutter view missing ID', () async {
|
||||||
final Map<String, dynamic> flutterViewCannedResponseMissingId =
|
final Map<String, dynamic> flutterViewCannedResponseMissingId =
|
||||||
<String, dynamic>{
|
<String, dynamic>{
|
||||||
@ -150,6 +207,50 @@ void main() {
|
|||||||
expect(failingFunction, throwsA(const isInstanceOf<RpcFormatError>()));
|
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 {
|
test('invalid flutter view missing ID', () async {
|
||||||
final Map<String, dynamic> flutterViewCannedResponseMissingIsolateName =
|
final Map<String, dynamic> flutterViewCannedResponseMissingIsolateName =
|
||||||
<String, dynamic>{
|
<String, dynamic>{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user