Unverified Commit 0274f170 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] have the tool print the current canvaskit mode when toggling (#52841)

parent 83fdf78a
...@@ -706,10 +706,11 @@ class _ResidentWebRunner extends ResidentWebRunner { ...@@ -706,10 +706,11 @@ class _ResidentWebRunner extends ResidentWebRunner {
bool get supportsCanvasKit => supportsServiceProtocol; bool get supportsCanvasKit => supportsServiceProtocol;
@override @override
Future<void> toggleCanvaskit() async { Future<bool> toggleCanvaskit() async {
final WebDevFS webDevFS = device.devFS as WebDevFS; final WebDevFS webDevFS = device.devFS as WebDevFS;
webDevFS.webAssetServer.canvasKitRendering = !webDevFS.webAssetServer.canvasKitRendering; webDevFS.webAssetServer.canvasKitRendering = !webDevFS.webAssetServer.canvasKitRendering;
await _wipConnection?.sendCommand('Page.reload'); await _wipConnection?.sendCommand('Page.reload');
return webDevFS.webAssetServer.canvasKitRendering;
} }
@override @override
......
...@@ -732,10 +732,11 @@ abstract class ResidentRunner { ...@@ -732,10 +732,11 @@ abstract class ResidentRunner {
throw '${fullRestart ? 'Restart' : 'Reload'} is not supported in $mode mode'; throw '${fullRestart ? 'Restart' : 'Reload'} is not supported in $mode mode';
} }
/// Toggle whether canvaskit is being used for rendering. /// Toggle whether canvaskit is being used for rendering, returning the new
/// state.
/// ///
/// Only supported on the web. /// Only supported on the web.
Future<void> toggleCanvaskit() { Future<bool> toggleCanvaskit() {
throw Exception('Canvaskit not supported by this runner.'); throw Exception('Canvaskit not supported by this runner.');
} }
...@@ -1207,7 +1208,8 @@ class TerminalHandler { ...@@ -1207,7 +1208,8 @@ class TerminalHandler {
return false; return false;
case 'k': case 'k':
if (residentRunner.supportsCanvasKit) { if (residentRunner.supportsCanvasKit) {
await residentRunner.toggleCanvaskit(); final bool result = await residentRunner.toggleCanvaskit();
globals.printStatus('${result ? 'Enabled' : 'Disabled'} CanvasKit');
return true; return true;
} }
return false; return false;
......
...@@ -437,9 +437,10 @@ void main() { ...@@ -437,9 +437,10 @@ void main() {
expect(residentWebRunner.supportsCanvasKit, true); expect(residentWebRunner.supportsCanvasKit, true);
expect(webAssetServer.canvasKitRendering, false); expect(webAssetServer.canvasKitRendering, false);
await residentWebRunner.toggleCanvaskit(); final bool toggleResult = await residentWebRunner.toggleCanvaskit();
expect(webAssetServer.canvasKitRendering, true); expect(webAssetServer.canvasKitRendering, true);
expect(toggleResult, true);
})); }));
test('Exits when initial compile fails', () => testbed.run(() async { test('Exits when initial compile fails', () => testbed.run(() async {
......
...@@ -108,6 +108,18 @@ void main() { ...@@ -108,6 +108,18 @@ void main() {
verify(mockResidentRunner.printHelp(details: true)).called(3); verify(mockResidentRunner.printHelp(details: true)).called(3);
}); });
testUsingContext('k - toggles CanvasKit rendering and prints results', () async {
when(mockResidentRunner.supportsCanvasKit).thenReturn(true);
when(mockResidentRunner.toggleCanvaskit())
.thenAnswer((Invocation invocation) async {
return true;
});
await terminalHandler.processTerminalInput('k');
verify(mockResidentRunner.toggleCanvaskit()).called(1);
});
testUsingContext('i, I - debugToggleWidgetInspector with service protocol', () async { testUsingContext('i, I - debugToggleWidgetInspector with service protocol', () async {
await terminalHandler.processTerminalInput('i'); await terminalHandler.processTerminalInput('i');
await terminalHandler.processTerminalInput('I'); await terminalHandler.processTerminalInput('I');
......
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