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

[flutter_tools] Remove web specific vm_service handlers, move handler tests to...

[flutter_tools] Remove web specific vm_service handlers, move handler tests to single location (#80440)
parent bccacfed
......@@ -29,7 +29,6 @@ import '../cache.dart';
import '../dart/language_version.dart';
import '../devfs.dart';
import '../device.dart';
import '../features.dart';
import '../flutter_plugins.dart';
import '../platform_plugins.dart';
import '../plugins.dart';
......@@ -60,7 +59,6 @@ class DwdsWebRunnerFactory extends WebRunnerFactory {
@required FileSystem fileSystem,
@required SystemClock systemClock,
@required Usage usage,
@required FeatureFlags featureFlags,
bool machine = false,
}) {
return ResidentWebRunner(
......@@ -120,6 +118,12 @@ class ResidentWebRunner extends ResidentRunner {
final Usage _usage;
final UrlTunneller _urlTunneller;
@override
Logger get logger => _logger;
@override
FileSystem get fileSystem => _fileSystem;
FlutterDevice get device => flutterDevices.first;
final FlutterProject flutterProject;
DateTime firstBuildTime;
......@@ -162,9 +166,6 @@ class ResidentWebRunner extends ResidentRunner {
}
FlutterVmService _instance;
@override
bool get supportsRestart => true;
@override
Future<void> cleanupAfterSignal() async {
await _cleanup();
......@@ -219,242 +220,12 @@ class ResidentWebRunner extends ResidentRunner {
printDebuggerList();
}
@override
Future<bool> debugDumpApp() async {
if (!supportsServiceProtocol || _vmService == null) {
return false;
}
try {
final String data = await _vmService
.flutterDebugDumpApp(
isolateId: null,
);
_logger.printStatus(data);
} on vmservice.RPCError {
// do nothing.
}
return true;
}
@override
Future<bool> debugDumpRenderTree() async {
if (!supportsServiceProtocol || _vmService == null) {
return false;
}
try {
final String data = await _vmService
.flutterDebugDumpRenderTree(
isolateId: null,
);
_logger.printStatus(data);
} on vmservice.RPCError {
// do nothing.
}
return true;
}
@override
Future<bool> debugDumpLayerTree() async {
if (!supportsServiceProtocol || _vmService == null) {
return false;
}
try {
final String data = await _vmService
.flutterDebugDumpLayerTree(
isolateId: null,
);
_logger.printStatus(data);
} on vmservice.RPCError {
// do nothing.
}
return true;
}
@override
Future<bool> debugDumpSemanticsTreeInTraversalOrder() async {
if (!supportsServiceProtocol) {
return false;
}
try {
await _vmService
?.flutterDebugDumpSemanticsTreeInTraversalOrder(
isolateId: null,
);
} on vmservice.RPCError {
// do nothing.
}
return true;
}
@override
Future<bool> debugTogglePlatform() async {
if (!supportsServiceProtocol) {
return false;
}
try {
final String currentPlatform = await _vmService
?.flutterPlatformOverride(
isolateId: null,
);
final String platform = nextPlatform(currentPlatform);
await _vmService
?.flutterPlatformOverride(
platform: platform,
isolateId: null,
);
_logger.printStatus('Switched operating system to $platform');
} on vmservice.RPCError {
// do nothing.
}
return true;
}
@override
Future<bool> debugToggleBrightness() async {
if (!supportsServiceProtocol) {
return false;
}
try {
final Brightness currentBrightness = await _vmService
?.flutterBrightnessOverride(
isolateId: null,
);
Brightness next;
if (currentBrightness == Brightness.light) {
next = Brightness.dark;
} else if (currentBrightness == Brightness.dark) {
next = Brightness.light;
}
next = await _vmService
?.flutterBrightnessOverride(
brightness: next,
isolateId: null,
);
_logger.printStatus('Changed brightness to $next.');
} on vmservice.RPCError {
// do nothing.
}
return true;
}
@override
Future<void> stopEchoingDeviceLog() async {
// Do nothing for ResidentWebRunner
await device.stopEchoingDeviceLog();
}
@override
Future<bool> debugDumpSemanticsTreeInInverseHitTestOrder() async {
if (!supportsServiceProtocol) {
return false;
}
try {
await _vmService
?.flutterDebugDumpSemanticsTreeInInverseHitTestOrder(
isolateId: null,
);
} on vmservice.RPCError {
// do nothing.
}
return true;
}
@override
Future<bool> debugToggleDebugPaintSizeEnabled() async {
if (!supportsServiceProtocol) {
return false;
}
try {
await _vmService
?.flutterToggleDebugPaintSizeEnabled(
isolateId: null,
);
} on vmservice.RPCError {
// do nothing.
}
return true;
}
@override
Future<bool> debugToggleDebugCheckElevationsEnabled() async {
if (!supportsServiceProtocol) {
return false;
}
try {
await _vmService
?.flutterToggleDebugCheckElevationsEnabled(
isolateId: null,
);
} on vmservice.RPCError {
// do nothing.
}
return true;
}
@override
Future<bool> debugTogglePerformanceOverlayOverride() async {
if (!supportsServiceProtocol) {
return false;
}
try {
await _vmService
?.flutterTogglePerformanceOverlayOverride(
isolateId: null,
);
} on vmservice.RPCError {
// do nothing.
}
return true;
}
@override
Future<bool> debugToggleWidgetInspector() async {
if (!supportsServiceProtocol) {
return false;
}
try {
await _vmService
?.flutterToggleWidgetInspector(
isolateId: null,
);
} on vmservice.RPCError {
// do nothing.
}
return true;
}
@override
Future<bool> debugToggleInvertOversizedImages() async {
if (!supportsServiceProtocol) {
return false;
}
try {
await _vmService
?.flutterToggleInvertOversizedImages(
isolateId: null,
);
} on vmservice.RPCError {
// do nothing.
}
return true;
}
@override
Future<bool> debugToggleProfileWidgetBuilds() async {
if (!supportsServiceProtocol) {
return false;
}
try {
await _vmService
?.flutterToggleProfileWidgetBuilds(
isolateId: null,
);
} on vmservice.RPCError {
// do nothing.
}
return true;
}
@override
Future<int> run({
Completer<DebugConnectionInfo> connectionInfoCompleter,
......
......@@ -172,175 +172,6 @@ void main() {
fileSystem = MemoryFileSystem.test();
});
testUsingContext('Does not hot restart when device does not support it', () async {
fileSystem.file('.packages')
..createSync(recursive: true)
..writeAsStringSync('\n');
// Setup mocks
final MockDevice mockDevice = MockDevice();
when(mockDevice.supportsHotReload).thenReturn(true);
when(mockDevice.supportsHotRestart).thenReturn(false);
when(mockDevice.targetPlatform).thenAnswer((Invocation _) async => TargetPlatform.tester);
// Trigger hot restart.
final List<FlutterDevice> devices = <FlutterDevice>[
FlutterDevice(mockDevice, generator: residentCompiler, buildInfo: BuildInfo.debug)..devFS = mockDevFs,
];
final OperationResult result = await HotRunner(
devices,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug),
target: 'main.dart',
devtoolsHandler: createNoOpHandler,
).restart(fullRestart: true);
// Expect hot restart failed.
expect(result.isOk, false);
expect(result.message, 'hotRestart not supported');
}, overrides: <Type, Generator>{
HotRunnerConfig: () => TestHotRunnerConfig(successfulSetup: true),
Artifacts: () => Artifacts.test(),
FileSystem: () => fileSystem,
Platform: () => FakePlatform(operatingSystem: 'linux'),
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('Does not hot restart when one of many devices does not support it', () async {
fileSystem.file('.packages')
..createSync(recursive: true)
..writeAsStringSync('\n');
// Setup mocks
final MockDevice mockDevice = MockDevice();
final MockDevice mockHotDevice = MockDevice();
when(mockDevice.supportsHotReload).thenReturn(true);
when(mockDevice.supportsHotRestart).thenReturn(false);
when(mockHotDevice.supportsHotReload).thenReturn(true);
when(mockHotDevice.supportsHotRestart).thenReturn(true);
// Trigger hot restart.
final List<FlutterDevice> devices = <FlutterDevice>[
FlutterDevice(mockDevice, generator: residentCompiler, buildInfo: BuildInfo.debug)..devFS = mockDevFs,
FlutterDevice(mockHotDevice, generator: residentCompiler, buildInfo: BuildInfo.debug)..devFS = mockDevFs,
];
final OperationResult result = await HotRunner(
devices,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug),
target: 'main.dart',
devtoolsHandler: createNoOpHandler,
).restart(fullRestart: true);
// Expect hot restart failed.
expect(result.isOk, false);
expect(result.message, 'hotRestart not supported');
}, overrides: <Type, Generator>{
HotRunnerConfig: () => TestHotRunnerConfig(successfulSetup: true),
Artifacts: () => Artifacts.test(),
FileSystem: () => fileSystem,
Platform: () => FakePlatform(operatingSystem: 'linux'),
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('Does hot restarts when all devices support it', () async {
final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
listViews,
FakeVmServiceRequest(
method: 'getIsolate',
args: <String, Object>{
'isolateId': fakeUnpausedIsolate.id,
},
jsonResponse: fakeUnpausedIsolate.toJson(),
),
FakeVmServiceRequest(
method: 'getVM',
jsonResponse: vm_service.VM.parse(<String, Object>{}).toJson()
),
listViews,
FakeVmServiceRequest(
method: 'getIsolate',
args: <String, Object>{
'isolateId': fakeUnpausedIsolate.id,
},
jsonResponse: fakeUnpausedIsolate.toJson(),
),
FakeVmServiceRequest(
method: 'getVM',
jsonResponse: vm_service.VM.parse(<String, Object>{}).toJson()
),
listViews,
listViews,
const FakeVmServiceRequest(
method: 'streamListen',
args: <String, Object>{
'streamId': 'Isolate',
}
),
const FakeVmServiceRequest(
method: 'streamListen',
args: <String, Object>{
'streamId': 'Isolate',
}
),
FakeVmServiceStreamResponse(
streamId: 'Isolate',
event: vm_service.Event(
timestamp: 0,
kind: vm_service.EventKind.kIsolateRunnable,
)
),
FakeVmServiceStreamResponse(
streamId: 'Isolate',
event: vm_service.Event(
timestamp: 0,
kind: vm_service.EventKind.kIsolateRunnable,
)
),
FakeVmServiceRequest(
method: kRunInViewMethod,
args: <String, Object>{
'viewId': fakeFlutterView.id,
'mainScript': 'main.dart.dill',
'assetDirectory': 'build/flutter_assets',
}
),
FakeVmServiceRequest(
method: kRunInViewMethod,
args: <String, Object>{
'viewId': fakeFlutterView.id,
'mainScript': 'main.dart.dill',
'assetDirectory': 'build/flutter_assets',
}
),
]);
// Setup mocks
final MockDevice mockDevice = MockDevice();
final MockDevice mockHotDevice = MockDevice();
when(mockDevice.supportsHotReload).thenReturn(true);
when(mockDevice.supportsHotRestart).thenReturn(true);
when(mockHotDevice.supportsHotReload).thenReturn(true);
when(mockHotDevice.supportsHotRestart).thenReturn(true);
// Trigger a restart.
final List<FlutterDevice> devices = <FlutterDevice>[
FlutterDevice(mockDevice, generator: residentCompiler, buildInfo: BuildInfo.debug)
..vmService = fakeVmServiceHost.vmService
..devFS = mockDevFs,
FlutterDevice(mockHotDevice, generator: residentCompiler, buildInfo: BuildInfo.debug)
..vmService = fakeVmServiceHost.vmService
..devFS = mockDevFs,
];
final HotRunner hotRunner = HotRunner(
devices,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug),
target: 'main.dart',
devtoolsHandler: createNoOpHandler,
);
final OperationResult result = await hotRunner.restart(fullRestart: true);
// Expect hot restart was successful.
expect(hotRunner.uri, mockDevFs.baseUri);
expect(result.isOk, true);
expect(result.message, isNot('hotRestart not supported'));
}, overrides: <Type, Generator>{
HotRunnerConfig: () => TestHotRunnerConfig(successfulSetup: true),
Artifacts: () => Artifacts.test(),
FileSystem: () => fileSystem,
Platform: () => FakePlatform(operatingSystem: 'linux'),
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('setup function fails', () async {
fileSystem.file('.packages')
..createSync(recursive: true)
......@@ -368,76 +199,6 @@ void main() {
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('hot restart supported', () async {
fileSystem.file('.packages')
..createSync(recursive: true)
..writeAsStringSync('\n');
// Setup mocks
final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
listViews,
FakeVmServiceRequest(
method: 'getIsolate',
args: <String, Object>{
'isolateId': fakeUnpausedIsolate.id,
},
jsonResponse: fakeUnpausedIsolate.toJson(),
),
FakeVmServiceRequest(
method: 'getVM',
jsonResponse: vm_service.VM.parse(<String, Object>{}).toJson(),
),
listViews,
const FakeVmServiceRequest(
method: 'streamListen',
args: <String, Object>{
'streamId': 'Isolate',
}
),
FakeVmServiceRequest(
method: kRunInViewMethod,
args: <String, Object>{
'viewId': fakeFlutterView.id,
'mainScript': 'main.dart.dill',
'assetDirectory': 'build/flutter_assets',
}
),
FakeVmServiceStreamResponse(
streamId: 'Isolate',
event: vm_service.Event(
timestamp: 0,
kind: vm_service.EventKind.kIsolateRunnable,
)
),
]);
final MockDevice mockDevice = MockDevice();
when(mockDevice.supportsHotReload).thenReturn(true);
when(mockDevice.supportsHotRestart).thenReturn(true);
when(mockDevice.targetPlatform).thenAnswer((Invocation _) async => TargetPlatform.tester);
// Trigger hot restart.
final List<FlutterDevice> devices = <FlutterDevice>[
FlutterDevice(mockDevice, generator: residentCompiler, buildInfo: BuildInfo.debug)
..vmService = fakeVmServiceHost.vmService
..devFS = mockDevFs,
];
final HotRunner hotRunner = HotRunner(
devices,
debuggingOptions: DebuggingOptions.disabled(BuildInfo.debug),
target: 'main.dart',
devtoolsHandler: createNoOpHandler,
);
final OperationResult result = await hotRunner.restart(fullRestart: true);
// Expect hot restart successful.
expect(hotRunner.uri, mockDevFs.baseUri);
expect(result.isOk, true);
expect(result.message, isNot('setupHotRestart failed'));
}, overrides: <Type, Generator>{
HotRunnerConfig: () => TestHotRunnerConfig(successfulSetup: true),
Artifacts: () => Artifacts.test(),
FileSystem: () => fileSystem,
Platform: () => FakePlatform(operatingSystem: 'linux'),
ProcessManager: () => FakeProcessManager.any(),
});
group('shutdown hook tests', () {
TestHotRunnerConfig shutdownTestingConfig;
......
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