2019-11-27 23:04:02 +00:00
|
|
|
// Copyright 2014 The Flutter Authors. All rights reserved.
|
2019-08-02 23:02:02 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2021-01-27 23:17:53 +00:00
|
|
|
// @dart = 2.8
|
|
|
|
|
2020-09-30 00:50:33 +00:00
|
|
|
import 'package:file/memory.dart';
|
2019-10-15 19:50:44 +00:00
|
|
|
import 'package:flutter_tools/src/base/file_system.dart';
|
2019-08-02 23:02:02 +00:00
|
|
|
import 'package:flutter_tools/src/base/io.dart';
|
|
|
|
import 'package:flutter_tools/src/build_info.dart';
|
|
|
|
import 'package:flutter_tools/src/compile.dart';
|
|
|
|
import 'package:flutter_tools/src/device.dart';
|
|
|
|
import 'package:flutter_tools/src/resident_runner.dart';
|
|
|
|
import 'package:flutter_tools/src/run_cold.dart';
|
|
|
|
import 'package:flutter_tools/src/vmservice.dart';
|
|
|
|
import 'package:meta/meta.dart';
|
|
|
|
import 'package:mockito/mockito.dart';
|
|
|
|
|
|
|
|
import '../src/common.dart';
|
|
|
|
import '../src/context.dart';
|
|
|
|
|
|
|
|
void main() {
|
2020-06-03 20:27:47 +00:00
|
|
|
testUsingContext('Exits with code 2 when when HttpException is thrown '
|
|
|
|
'during VM service connection', () async {
|
2021-02-18 08:01:04 +00:00
|
|
|
final FakeResidentCompiler residentCompiler = FakeResidentCompiler();
|
2020-06-03 20:27:47 +00:00
|
|
|
final MockDevice mockDevice = MockDevice();
|
|
|
|
when(mockDevice.supportsHotReload).thenReturn(true);
|
|
|
|
when(mockDevice.supportsHotRestart).thenReturn(false);
|
|
|
|
when(mockDevice.targetPlatform).thenAnswer((Invocation _) async => TargetPlatform.tester);
|
|
|
|
when(mockDevice.sdkNameAndVersion).thenAnswer((Invocation _) async => 'Android 10');
|
|
|
|
|
|
|
|
final List<FlutterDevice> devices = <FlutterDevice>[
|
|
|
|
TestFlutterDevice(
|
|
|
|
device: mockDevice,
|
|
|
|
generator: residentCompiler,
|
|
|
|
exception: const HttpException('Connection closed before full header was received, '
|
|
|
|
'uri = http://127.0.0.1:63394/5ZmLv8A59xY=/ws'),
|
|
|
|
),
|
|
|
|
];
|
|
|
|
|
|
|
|
final int exitCode = await ColdRunner(devices,
|
|
|
|
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
|
2020-11-20 22:17:11 +00:00
|
|
|
target: 'main.dart',
|
2021-02-02 00:06:02 +00:00
|
|
|
).attach(
|
|
|
|
enableDevTools: false,
|
|
|
|
);
|
2020-06-03 20:27:47 +00:00
|
|
|
expect(exitCode, 2);
|
2019-08-02 23:02:02 +00:00
|
|
|
});
|
2019-10-15 19:50:44 +00:00
|
|
|
|
|
|
|
group('cleanupAtFinish()', () {
|
|
|
|
MockFlutterDevice mockFlutterDeviceFactory(Device device) {
|
|
|
|
final MockFlutterDevice mockFlutterDevice = MockFlutterDevice();
|
|
|
|
when(mockFlutterDevice.stopEchoingDeviceLog()).thenAnswer((Invocation invocation) => Future<void>.value(null));
|
|
|
|
when(mockFlutterDevice.device).thenReturn(device);
|
|
|
|
return mockFlutterDevice;
|
|
|
|
}
|
|
|
|
|
|
|
|
testUsingContext('disposes each device', () async {
|
|
|
|
final MockDevice mockDevice1 = MockDevice();
|
|
|
|
final MockDevice mockDevice2 = MockDevice();
|
|
|
|
final MockFlutterDevice mockFlutterDevice1 = mockFlutterDeviceFactory(mockDevice1);
|
|
|
|
final MockFlutterDevice mockFlutterDevice2 = mockFlutterDeviceFactory(mockDevice2);
|
|
|
|
|
|
|
|
final List<FlutterDevice> devices = <FlutterDevice>[mockFlutterDevice1, mockFlutterDevice2];
|
|
|
|
|
|
|
|
await ColdRunner(devices,
|
|
|
|
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
|
2020-11-20 22:17:11 +00:00
|
|
|
target: 'main.dart',
|
2019-10-15 19:50:44 +00:00
|
|
|
).cleanupAtFinish();
|
|
|
|
|
|
|
|
verify(mockDevice1.dispose());
|
|
|
|
verify(mockFlutterDevice1.stopEchoingDeviceLog());
|
|
|
|
verify(mockDevice2.dispose());
|
|
|
|
verify(mockFlutterDevice2.stopEchoingDeviceLog());
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
group('cold run', () {
|
|
|
|
testUsingContext('calls runCold on attached device', () async {
|
|
|
|
final MockDevice mockDevice = MockDevice();
|
|
|
|
final MockFlutterDevice mockFlutterDevice = MockFlutterDevice();
|
|
|
|
when(mockFlutterDevice.device).thenReturn(mockDevice);
|
|
|
|
when(mockFlutterDevice.runCold(
|
|
|
|
coldRunner: anyNamed('coldRunner'),
|
|
|
|
route: anyNamed('route')
|
|
|
|
)).thenAnswer((Invocation invocation) => Future<int>.value(1));
|
|
|
|
final List<FlutterDevice> devices = <FlutterDevice>[mockFlutterDevice];
|
2020-09-30 00:50:33 +00:00
|
|
|
final File applicationBinary = MemoryFileSystem.test().file('binary');
|
2019-10-15 19:50:44 +00:00
|
|
|
final int result = await ColdRunner(
|
|
|
|
devices,
|
|
|
|
applicationBinary: applicationBinary,
|
|
|
|
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
|
2020-11-20 22:17:11 +00:00
|
|
|
target: 'main.dart',
|
2021-02-02 00:06:02 +00:00
|
|
|
).run(
|
|
|
|
enableDevTools: false,
|
|
|
|
);
|
2020-01-08 20:35:12 +00:00
|
|
|
|
2019-10-15 19:50:44 +00:00
|
|
|
expect(result, 1);
|
|
|
|
verify(mockFlutterDevice.runCold(
|
|
|
|
coldRunner: anyNamed('coldRunner'),
|
|
|
|
route: anyNamed('route'),
|
|
|
|
));
|
|
|
|
});
|
|
|
|
});
|
2019-08-02 23:02:02 +00:00
|
|
|
}
|
|
|
|
|
2019-10-15 19:50:44 +00:00
|
|
|
class MockFlutterDevice extends Mock implements FlutterDevice {}
|
2019-08-02 23:02:02 +00:00
|
|
|
class MockDevice extends Mock implements Device {
|
|
|
|
MockDevice() {
|
|
|
|
when(isSupported()).thenReturn(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class TestFlutterDevice extends FlutterDevice {
|
|
|
|
TestFlutterDevice({
|
|
|
|
@required Device device,
|
|
|
|
@required this.exception,
|
2019-09-24 06:06:09 +00:00
|
|
|
@required ResidentCompiler generator,
|
2019-08-02 23:02:02 +00:00
|
|
|
}) : assert(exception != null),
|
2020-03-06 22:53:36 +00:00
|
|
|
super(device, buildInfo: BuildInfo.debug, generator: generator);
|
2019-08-02 23:02:02 +00:00
|
|
|
|
|
|
|
/// The exception to throw when the connect method is called.
|
|
|
|
final Exception exception;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Future<void> connect({
|
|
|
|
ReloadSources reloadSources,
|
|
|
|
Restart restart,
|
|
|
|
CompileExpression compileExpression,
|
2020-05-27 17:10:41 +00:00
|
|
|
GetSkSLMethod getSkSLMethod,
|
2020-06-09 18:18:03 +00:00
|
|
|
PrintStructuredErrorLogMethod printStructuredErrorLogMethod,
|
2020-07-29 17:05:40 +00:00
|
|
|
bool disableDds = false,
|
2020-09-16 23:27:42 +00:00
|
|
|
bool disableServiceAuthCodes = false,
|
|
|
|
int hostVmServicePort,
|
|
|
|
int ddsPort,
|
2020-07-29 17:05:40 +00:00
|
|
|
bool ipv6 = false,
|
2020-12-05 01:16:30 +00:00
|
|
|
bool allowExistingDdsInstance = false,
|
2019-08-02 23:02:02 +00:00
|
|
|
}) async {
|
|
|
|
throw exception;
|
|
|
|
}
|
|
|
|
}
|
2021-02-18 08:01:04 +00:00
|
|
|
|
|
|
|
class FakeResidentCompiler extends Fake implements ResidentCompiler {}
|