Unverified Commit 21be8372 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

implement debugTogglePlatform for the web (#42951)

parent e67f9a3f
......@@ -384,6 +384,34 @@ class ResidentWebRunner extends ResidentRunner {
}
}
@override
Future<void> debugTogglePlatform() async {
try {
final vmservice.Response response = await _vmService.callServiceExtension(
'ext.flutter.platformOverride');
final String currentPlatform = response.json['value'];
String nextPlatform;
switch (currentPlatform) {
case 'android':
nextPlatform = 'iOS';
break;
case 'iOS':
nextPlatform = 'android';
break;
}
if (nextPlatform == null) {
return;
}
await _vmService.callServiceExtension(
'ext.flutter.platformOverride', args: <String, Object>{
'value': nextPlatform,
});
printStatus('Switched operating system to $nextPlatform');
} on vmservice.RPCError {
return;
}
}
@override
Future<void> debugDumpSemanticsTreeInInverseHitTestOrder() async {
try {
......
......@@ -435,6 +435,26 @@ void main() {
args: <String, Object>{'enabled': true})).called(1);
}));
test('debugTogglePlatform', () => testbed.run(() async {
_setupMocks();
final BufferLogger bufferLogger = logger;
final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
unawaited(residentWebRunner.run(
connectionInfoCompleter: connectionInfoCompleter,
));
await connectionInfoCompleter.future;
when(mockVmService.callServiceExtension('ext.flutter.platformOverride'))
.thenAnswer((Invocation _) async {
return Response.parse(<String, Object>{'value': 'iOS'});
});
await residentWebRunner.debugTogglePlatform();
expect(bufferLogger.statusText, contains('Switched operating system to android'));
verify(mockVmService.callServiceExtension('ext.flutter.platformOverride',
args: <String, Object>{'value': 'android'})).called(1);
}));
test('cleanup of resources is safe to call multiple times', () => testbed.run(() async {
_setupMocks();
bool debugClosed = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment