[flutter_tools/dap] Inform DAP client whether restart is supported (#121610)

[flutter_tools/dap] Inform DAP client whether restart is supported
This commit is contained in:
Danny Tuppeny
2023-03-03 12:54:23 +00:00
committed by GitHub
parent 4ab053c252
commit 3494c08448
3 changed files with 49 additions and 7 deletions

View File

@@ -101,6 +101,44 @@ void main() {
expect(adapter.pidsToTerminate, isNot(contains(123)));
});
group('supportsRestartRequest', () {
void testRestartSupport(bool supportsRestart) {
test('notifies client for supportsRestart: $supportsRestart', () async {
final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter(
fileSystem: MemoryFileSystem.test(style: fsStyle),
platform: platform,
supportsRestart: supportsRestart,
);
final FlutterLaunchRequestArguments args = FlutterLaunchRequestArguments(
cwd: '/project',
program: 'foo.dart',
);
// Listen for a Capabilities event that modifies 'supportsRestartRequest'.
final Future<CapabilitiesEventBody> capabilitiesUpdate = adapter
.dapToClientMessages
.where((Map<String, Object?> message) => message['event'] == 'capabilities')
.map((Map<String, Object?> message) => message['body'] as Map<String, Object?>?)
.where((Map<String, Object?>? body) => body != null).cast<Map<String, Object?>>()
.map(CapabilitiesEventBody.fromJson)
.firstWhere((CapabilitiesEventBody body) => body.capabilities.supportsRestartRequest != null);
await adapter.configurationDoneRequest(MockRequest(), null, () {});
final Completer<void> launchCompleter = Completer<void>();
await adapter.launchRequest(MockRequest(), args, launchCompleter.complete);
await launchCompleter.future;
// Ensure the Capabilities update has the expected value.
expect((await capabilitiesUpdate).capabilities.supportsRestartRequest, supportsRestart);
});
}
testRestartSupport(true);
testRestartSupport(false);
});
test('calls "app.stop" on terminateRequest', () async {
final MockFlutterDebugAdapter adapter = MockFlutterDebugAdapter(
fileSystem: MemoryFileSystem.test(style: fsStyle),

View File

@@ -18,6 +18,7 @@ class MockFlutterDebugAdapter extends FlutterDebugAdapter {
required FileSystem fileSystem,
required Platform platform,
bool simulateAppStarted = true,
bool supportsRestart = true,
FutureOr<void> Function(MockFlutterDebugAdapter adapter)? preAppStart,
}) {
final StreamController<List<int>> stdinController = StreamController<List<int>>();
@@ -31,6 +32,7 @@ class MockFlutterDebugAdapter extends FlutterDebugAdapter {
fileSystem: fileSystem,
platform: platform,
simulateAppStarted: simulateAppStarted,
supportsRestart: supportsRestart,
preAppStart: preAppStart,
);
}
@@ -41,6 +43,7 @@ class MockFlutterDebugAdapter extends FlutterDebugAdapter {
required super.fileSystem,
required super.platform,
this.simulateAppStarted = true,
this.supportsRestart = true,
this.preAppStart,
}) {
clientChannel.listen((ProtocolMessage message) {
@@ -51,6 +54,7 @@ class MockFlutterDebugAdapter extends FlutterDebugAdapter {
int _seq = 1;
final ByteStreamServerChannel clientChannel;
final bool simulateAppStarted;
final bool supportsRestart;
final FutureOr<void> Function(MockFlutterDebugAdapter adapter)? preAppStart;
late String executable;
@@ -110,6 +114,7 @@ class MockFlutterDebugAdapter extends FlutterDebugAdapter {
'event': 'app.start',
'params': <String, Object?>{
'appId': 'TEST',
'supportsRestart': supportsRestart,
}
});
}