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 {
Device device;
@override
Future<FlutterCommandResult> verifyThenRunCommand(String commandPath) async {
device = await findTargetDevice();
static void validateOptions(String screenshotType, Device device, String observatoryUri) {
switch (screenshotType) {
case _kDeviceType:
if (device == null) {
throwToolExit('Must have a connected device');
throwToolExit('Must have a connected device for screenshot type $screenshotType');
}
if (argResults[_kType] == _kDeviceType && !device.supportsScreenshot) {
if (!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]}');
break;
default:
if (observatoryUri == null) {
throwToolExit('Observatory URI must be specified for screenshot type $screenshotType');
}
}
}
@override
Future<FlutterCommandResult> verifyThenRunCommand(String commandPath) async {
device = await findTargetDevice();
validateOptions(argResults[_kType], device, argResults[_kObservatoryUri]);
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