Unverified Commit c034f1a1 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] fix screenshot command in release mode and help documentation (#65114)

Currently taking a screenshot in release mode crashes and is also not documented as a supported command. Fix both of these and add test cases.
parent 6d46ff7e
......@@ -1102,20 +1102,29 @@ abstract class ResidentRunner {
'flutter',
'png',
);
final List<FlutterView> views = await device
.vmService.getFlutterViews();
try {
if (supportsServiceProtocol && isRunningDebug) {
List<FlutterView> views = <FlutterView>[];
Future<bool> setDebugBanner(bool value) async {
try {
for (final FlutterView view in views) {
await device.vmService.flutterDebugAllowBanner(
false,
value,
isolateId: view.uiIsolate.id,
);
}
return true;
} on Exception catch (error) {
status.cancel();
globals.printError('Error communicating with Flutter on the device: $error');
return false;
}
}
try {
if (supportsServiceProtocol && isRunningDebug) {
// Ensure that the vmService access is guarded by supportsServiceProtocol, it
// will be null in release mode.
views = await device.vmService.getFlutterViews();
if (!await setDebugBanner(false)) {
return;
}
}
......@@ -1123,18 +1132,7 @@ abstract class ResidentRunner {
await device.device.takeScreenshot(outputFile);
} finally {
if (supportsServiceProtocol && isRunningDebug) {
try {
for (final FlutterView view in views) {
await device.vmService.flutterDebugAllowBanner(
true,
isolateId: view.uiIsolate.id,
);
}
} on Exception catch (error) {
status.cancel();
globals.printError('Error communicating with Flutter on the device: $error');
return;
}
await setDebugBanner(true);
}
}
final int sizeKB = outputFile.lengthSync() ~/ 1024;
......
......@@ -185,11 +185,9 @@ class ColdRunner extends ResidentRunner {
@override
void printHelp({ @required bool details }) {
globals.printStatus('Flutter run key commands.');
if (supportsServiceProtocol) {
if (details) {
printHelpDetails();
}
}
commandHelp.h.print();
if (_didAttach) {
commandHelp.d.print();
......
......@@ -188,7 +188,7 @@ void main() {
return testUri;
});
when(mockFlutterDevice.vmService).thenAnswer((Invocation invocation) {
return fakeVmServiceHost.vmService;
return fakeVmServiceHost?.vmService;
});
when(mockFlutterDevice.reloadSources(any, pause: anyNamed('pause'))).thenAnswer((Invocation invocation) async {
return <Future<vm_service.ReloadReport>>[
......@@ -1289,6 +1289,42 @@ void main() {
));
}));
testUsingContext('ResidentRunner printHelpDetails cold runner', () => testbed.run(() {
when(mockDevice.supportsHotRestart).thenReturn(true);
when(mockDevice.supportsScreenshot).thenReturn(true);
fakeVmServiceHost = null;
residentRunner = ColdRunner(
<FlutterDevice>[
mockFlutterDevice,
],
stayResident: false,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.release),
);
residentRunner.printHelp(details: true);
final CommandHelp commandHelp = residentRunner.commandHelp;
// does not supports service protocol
expect(residentRunner.supportsServiceProtocol, false);
// isRunningDebug
expect(residentRunner.isRunningDebug, false);
// does not support CanvasKit
expect(residentRunner.supportsCanvasKit, false);
// does support SkSL
expect(residentRunner.supportsWriteSkSL, false);
// commands
expect(testLogger.statusText, equals(
<dynamic>[
'Flutter run key commands.',
commandHelp.s,
commandHelp.h,
commandHelp.c,
commandHelp.q,
''
].join('\n')
));
}));
testUsingContext('ResidentRunner does support CanvasKit', () => testbed.run(() async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
......@@ -1395,6 +1431,26 @@ void main() {
expect(fakeVmServiceHost.hasRemainingExpectations, false);
}));
testUsingContext('ResidentRunner can take screenshot on release device', () => testbed.run(() async {
when(mockDevice.supportsScreenshot).thenReturn(true);
when(mockDevice.takeScreenshot(any))
.thenAnswer((Invocation invocation) async {
final File file = invocation.positionalArguments.first as File;
file.writeAsBytesSync(List<int>.generate(1024, (int i) => i));
});
residentRunner = ColdRunner(
<FlutterDevice>[
mockFlutterDevice,
],
stayResident: false,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.release),
);
await residentRunner.screenshot(mockFlutterDevice);
expect(testLogger.statusText, contains('1kB'));
}));
testUsingContext('ResidentRunner clears the screen when it should', () => testbed.run(() async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
const String message = 'This should be cleared';
......@@ -1488,9 +1544,7 @@ void main() {
}));
testUsingContext('ResidentRunner does not toggle banner in non-debug mode', () => testbed.run(() async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
listViews,
]);
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
residentRunner = HotRunner(
<FlutterDevice>[
mockFlutterDevice,
......
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