mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[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.
This commit is contained in:
parent
8cd892b39b
commit
8e8add524e
@ -63,18 +63,27 @@ class ScreenshotCommand extends FlutterCommand {
|
||||
|
||||
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
|
||||
Future<FlutterCommandResult> verifyThenRunCommand(String commandPath) async {
|
||||
device = await findTargetDevice();
|
||||
if (device == null) {
|
||||
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]}');
|
||||
}
|
||||
validateOptions(argResults[_kType], device, argResults[_kObservatoryUri]);
|
||||
return super.verifyThenRunCommand(commandPath);
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,26 @@
|
||||
// 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());
|
||||
});
|
||||
});
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user