[DAP] Add a custom event to pass flutter.serviceExtensionStateChanged… (#93870)

This commit is contained in:
Danny Tuppeny
2021-11-23 04:12:33 +00:00
committed by GitHub
parent fae84f6714
commit 77fca35877
4 changed files with 111 additions and 1 deletions

View File

@@ -220,6 +220,54 @@ void main() {
await dap.client.terminate();
});
testWithoutContext('sends events for extension state updates', () async {
final BasicProject _project = BasicProject();
await _project.setUpIn(tempDir);
const String debugPaintRpc = 'ext.flutter.debugPaint';
// Create a future to capture the isolate ID when the debug paint service
// extension loads, as we'll need that to call it later.
final Future<String> isolateIdForDebugPaint = dap.client
.serviceExtensionAdded(debugPaintRpc)
.then((Map<String, Object/*?*/> body) => body['isolateId'] as String);
// Launch the app and wait for it to print "topLevelFunction" so we know
// it's up and running.
await Future.wait(<Future<Object>>[
dap.client.outputEvents.firstWhere((OutputEventBody output) =>
output.output.startsWith('topLevelFunction')),
dap.client.start(
launch: () => dap.client.launch(
cwd: _project.dir.path,
toolArgs: <String>['-d', 'flutter-tester'],
),
),
], eagerError: true);
// Capture the next relevant state-change event (which should occur as a
// result of the call below).
final Future<Map<String, Object/*?*/>> stateChangeEventFuture =
dap.client.serviceExtensionStateChanged(debugPaintRpc);
// Enable debug paint to trigger the state change.
await dap.client.custom(
'callService',
<String, Object/*?*/>{
'method': debugPaintRpc,
'params': <String, Object/*?*/>{
'enabled': true,
'isolateId': await isolateIdForDebugPaint,
},
},
);
// Ensure the event occurred, and its value was as expected.
final Map<String, Object/*?*/> stateChangeEvent = await stateChangeEventFuture;
expect(stateChangeEvent['value'], 'true'); // extension state change values are always strings
await dap.client.terminate();
});
}
/// Extracts the output from a set of [OutputEventBody], removing any

View File

@@ -78,6 +78,16 @@ class DapTestClient {
return _eventController.stream.where((Event e) => e.event == event);
}
/// Returns a stream of custom 'dart.serviceExtensionAdded' events.
Stream<Map<String, Object?>> get serviceExtensionAddedEvents =>
events('dart.serviceExtensionAdded')
.map((Event e) => e.body! as Map<String, Object?>);
/// Returns a stream of custom 'flutter.serviceExtensionStateChanged' events.
Stream<Map<String, Object?>> get serviceExtensionStateChangedEvents =>
events('flutter.serviceExtensionStateChanged')
.map((Event e) => e.body! as Map<String, Object?>);
/// Returns a stream of 'dart.testNotification' custom events from the
/// package:test JSON reporter.
Stream<Map<String, Object?>> get testNotificationEvents =>
@@ -171,6 +181,18 @@ class DapTestClient {
return completer.future;
}
/// Returns a Future that completes with the next serviceExtensionAdded
/// event for [extension].
Future<Map<String, Object?>> serviceExtensionAdded(String extension) => serviceExtensionAddedEvents.firstWhere(
(Map<String, Object?> body) => body['extensionRPC'] == extension,
orElse: () => throw 'Did not recieve $extension extension added event before stream closed');
/// Returns a Future that completes with the next serviceExtensionStateChanged
/// event for [extension].
Future<Map<String, Object?>> serviceExtensionStateChanged(String extension) => serviceExtensionStateChangedEvents.firstWhere(
(Map<String, Object?> body) => body['extension'] == extension,
orElse: () => throw 'Did not recieve $extension extension state changed event before stream closed');
/// Initializes the debug adapter and launches [program]/[cwd] or calls the
/// custom [launch] method.
Future<void> start({