Unverified Commit 8e8add52 authored by Kaushik Iska's avatar Kaushik Iska Committed by GitHub

[flutter_tool] Screenshot command must require device only for _kDeviceType (#44227)

There are cases where we have access to the observatory without having a device connection accessible.
parent 8cd892b3
...@@ -63,18 +63,27 @@ class ScreenshotCommand extends FlutterCommand { ...@@ -63,18 +63,27 @@ class ScreenshotCommand extends FlutterCommand {
Device device; Device device;
static void validateOptions(String screenshotType, Device device, String observatoryUri) {
switch (screenshotType) {
case _kDeviceType:
if (device == null) {
throwToolExit('Must have a connected device for screenshot type $screenshotType');
}
if (!device.supportsScreenshot) {
throwToolExit('Screenshot not supported for ${device.name}.');
}
break;
default:
if (observatoryUri == null) {
throwToolExit('Observatory URI must be specified for screenshot type $screenshotType');
}
}
}
@override @override
Future<FlutterCommandResult> verifyThenRunCommand(String commandPath) async { Future<FlutterCommandResult> verifyThenRunCommand(String commandPath) async {
device = await findTargetDevice(); device = await findTargetDevice();
if (device == null) { validateOptions(argResults[_kType], device, argResults[_kObservatoryUri]);
throwToolExit('Must have a connected device');
}
if (argResults[_kType] == _kDeviceType && !device.supportsScreenshot) {
throwToolExit('Screenshot not supported for ${device.name}.');
}
if (argResults[_kType] != _kDeviceType && argResults[_kObservatoryUri] == null) {
throwToolExit('Observatory URI must be specified for screenshot type ${argResults[_kType]}');
}
return super.verifyThenRunCommand(commandPath); return super.verifyThenRunCommand(commandPath);
} }
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter_tools/src/commands/screenshot.dart';
import '../src/common.dart';
import '../src/context.dart';
void main() {
group('Validate screenshot options', () {
testUsingContext('rasterizer and skia screenshots do not require a device', () async {
ScreenshotCommand.validateOptions('rasterizer', null, 'dummy_observatory_uri');
ScreenshotCommand.validateOptions('skia', null, 'dummy_observatory_uri');
});
testUsingContext('rasterizer and skia screenshots require observatory uri', () async {
expect(() => ScreenshotCommand.validateOptions('rasterizer', null, null), throwsToolExit());
expect(() => ScreenshotCommand.validateOptions('skia', null, null), throwsToolExit());
});
testUsingContext('device screenshots require device', () async {
expect(() => ScreenshotCommand.validateOptions('device', null, null), throwsToolExit());
});
});
}
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