2019-11-27 23:04:02 +00:00
|
|
|
// Copyright 2014 The Flutter Authors. All rights reserved.
|
2019-01-15 15:45:04 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-04-25 19:25:12 +00:00
|
|
|
import 'package:file/memory.dart';
|
2019-04-19 01:05:04 +00:00
|
|
|
import 'package:flutter_tools/src/base/file_system.dart';
|
2020-07-23 01:23:20 +00:00
|
|
|
import 'package:flutter_tools/src/base/logger.dart';
|
2020-10-03 04:52:53 +00:00
|
|
|
import 'package:flutter_tools/src/base/os.dart';
|
2020-05-06 15:15:39 +00:00
|
|
|
import 'package:flutter_tools/src/base/platform.dart';
|
2019-01-15 15:45:04 +00:00
|
|
|
import 'package:flutter_tools/src/build_info.dart';
|
2020-05-06 15:15:39 +00:00
|
|
|
import 'package:flutter_tools/src/device.dart';
|
2019-04-19 01:05:04 +00:00
|
|
|
import 'package:flutter_tools/src/linux/application_package.dart';
|
2019-01-15 15:45:04 +00:00
|
|
|
import 'package:flutter_tools/src/linux/linux_device.dart';
|
2019-04-25 19:25:12 +00:00
|
|
|
import 'package:flutter_tools/src/project.dart';
|
2019-01-15 15:45:04 +00:00
|
|
|
import 'package:mockito/mockito.dart';
|
|
|
|
|
2019-07-13 18:51:44 +00:00
|
|
|
import '../../src/common.dart';
|
|
|
|
import '../../src/context.dart';
|
2020-03-16 21:15:00 +00:00
|
|
|
import '../../src/testbed.dart';
|
2019-01-15 15:45:04 +00:00
|
|
|
|
2020-07-23 01:23:20 +00:00
|
|
|
final FakePlatform linux = FakePlatform(
|
|
|
|
operatingSystem: 'linux',
|
|
|
|
);
|
|
|
|
final FakePlatform windows = FakePlatform(
|
|
|
|
operatingSystem: 'windows',
|
|
|
|
);
|
2019-01-15 15:45:04 +00:00
|
|
|
|
2020-07-23 01:23:20 +00:00
|
|
|
void main() {
|
2020-03-16 21:15:00 +00:00
|
|
|
|
|
|
|
testWithoutContext('LinuxDevice defaults', () async {
|
2020-07-23 01:23:20 +00:00
|
|
|
final LinuxDevice device = LinuxDevice(
|
|
|
|
processManager: FakeProcessManager.any(),
|
|
|
|
logger: BufferLogger.test(),
|
2020-09-22 23:57:04 +00:00
|
|
|
fileSystem: MemoryFileSystem.test(),
|
2020-10-03 04:52:53 +00:00
|
|
|
operatingSystemUtils: FakeOperatingSystemUtils(),
|
2020-07-23 01:23:20 +00:00
|
|
|
);
|
|
|
|
|
2019-10-11 18:23:12 +00:00
|
|
|
final PrebuiltLinuxApp linuxApp = PrebuiltLinuxApp(executable: 'foo');
|
2020-06-24 00:19:29 +00:00
|
|
|
expect(await device.targetPlatform, TargetPlatform.linux_x64);
|
2020-06-30 18:28:02 +00:00
|
|
|
expect(device.name, 'Linux');
|
2019-10-11 18:23:12 +00:00
|
|
|
expect(await device.installApp(linuxApp), true);
|
|
|
|
expect(await device.uninstallApp(linuxApp), true);
|
|
|
|
expect(await device.isLatestBuildInstalled(linuxApp), true);
|
|
|
|
expect(await device.isAppInstalled(linuxApp), true);
|
|
|
|
expect(await device.stopApp(linuxApp), true);
|
|
|
|
expect(device.category, Category.desktop);
|
2020-06-08 18:20:15 +00:00
|
|
|
|
|
|
|
expect(device.supportsRuntimeMode(BuildMode.debug), true);
|
|
|
|
expect(device.supportsRuntimeMode(BuildMode.profile), true);
|
|
|
|
expect(device.supportsRuntimeMode(BuildMode.release), true);
|
|
|
|
expect(device.supportsRuntimeMode(BuildMode.jitRelease), false);
|
2019-10-11 18:23:12 +00:00
|
|
|
});
|
2019-08-09 18:25:12 +00:00
|
|
|
|
2020-03-16 21:15:00 +00:00
|
|
|
testWithoutContext('LinuxDevice: no devices listed if platform unsupported', () async {
|
2020-02-28 18:27:27 +00:00
|
|
|
expect(await LinuxDevices(
|
2020-09-22 23:57:04 +00:00
|
|
|
fileSystem: MemoryFileSystem.test(),
|
2020-07-23 01:23:20 +00:00
|
|
|
platform: windows,
|
2020-03-16 21:15:00 +00:00
|
|
|
featureFlags: TestFeatureFlags(isLinuxEnabled: true),
|
2020-07-23 01:23:20 +00:00
|
|
|
logger: BufferLogger.test(),
|
|
|
|
processManager: FakeProcessManager.any(),
|
2020-10-03 04:52:53 +00:00
|
|
|
operatingSystemUtils: FakeOperatingSystemUtils(),
|
2020-03-16 21:15:00 +00:00
|
|
|
).devices, <Device>[]);
|
|
|
|
});
|
|
|
|
|
|
|
|
testWithoutContext('LinuxDevice: no devices listed if Linux feature flag disabled', () async {
|
|
|
|
expect(await LinuxDevices(
|
2020-09-22 23:57:04 +00:00
|
|
|
fileSystem: MemoryFileSystem.test(),
|
2020-07-23 01:23:20 +00:00
|
|
|
platform: linux,
|
2020-03-16 21:15:00 +00:00
|
|
|
featureFlags: TestFeatureFlags(isLinuxEnabled: false),
|
2020-07-23 01:23:20 +00:00
|
|
|
logger: BufferLogger.test(),
|
|
|
|
processManager: FakeProcessManager.any(),
|
2020-10-03 04:52:53 +00:00
|
|
|
operatingSystemUtils: FakeOperatingSystemUtils(),
|
2020-02-28 18:27:27 +00:00
|
|
|
).devices, <Device>[]);
|
2019-01-15 15:45:04 +00:00
|
|
|
});
|
2019-04-25 19:25:12 +00:00
|
|
|
|
2020-03-16 21:15:00 +00:00
|
|
|
testWithoutContext('LinuxDevice: devices', () async {
|
|
|
|
expect(await LinuxDevices(
|
2020-09-22 23:57:04 +00:00
|
|
|
fileSystem: MemoryFileSystem.test(),
|
2020-07-23 01:23:20 +00:00
|
|
|
platform: linux,
|
2020-03-16 21:15:00 +00:00
|
|
|
featureFlags: TestFeatureFlags(isLinuxEnabled: true),
|
2020-07-23 01:23:20 +00:00
|
|
|
logger: BufferLogger.test(),
|
|
|
|
processManager: FakeProcessManager.any(),
|
2020-10-03 04:52:53 +00:00
|
|
|
operatingSystemUtils: FakeOperatingSystemUtils(),
|
2020-03-16 21:15:00 +00:00
|
|
|
).devices, hasLength(1));
|
|
|
|
});
|
|
|
|
|
|
|
|
testWithoutContext('LinuxDevice: discoverDevices', () async {
|
|
|
|
// Timeout ignored.
|
|
|
|
final List<Device> devices = await LinuxDevices(
|
2020-09-22 23:57:04 +00:00
|
|
|
fileSystem: MemoryFileSystem.test(),
|
2020-07-23 01:23:20 +00:00
|
|
|
platform: linux,
|
2020-03-16 21:15:00 +00:00
|
|
|
featureFlags: TestFeatureFlags(isLinuxEnabled: true),
|
2020-07-23 01:23:20 +00:00
|
|
|
logger: BufferLogger.test(),
|
|
|
|
processManager: FakeProcessManager.any(),
|
2020-10-03 04:52:53 +00:00
|
|
|
operatingSystemUtils: FakeOperatingSystemUtils(),
|
2020-03-16 21:15:00 +00:00
|
|
|
).discoverDevices(timeout: const Duration(seconds: 10));
|
|
|
|
expect(devices, hasLength(1));
|
|
|
|
});
|
|
|
|
|
2020-10-03 04:52:53 +00:00
|
|
|
testWithoutContext('LinuxDevice.isSupportedForProject is true with editable host app', () async {
|
|
|
|
final FileSystem fileSystem = MemoryFileSystem.test();
|
|
|
|
fileSystem.file('pubspec.yaml').createSync();
|
|
|
|
fileSystem.file('.packages').createSync();
|
|
|
|
fileSystem.directory('linux').createSync();
|
|
|
|
final FlutterProject flutterProject = setUpFlutterProject(fileSystem.currentDirectory);
|
2019-04-25 19:25:12 +00:00
|
|
|
|
2020-07-23 01:23:20 +00:00
|
|
|
expect(LinuxDevice(
|
|
|
|
logger: BufferLogger.test(),
|
|
|
|
processManager: FakeProcessManager.any(),
|
2020-10-03 04:52:53 +00:00
|
|
|
fileSystem: fileSystem,
|
|
|
|
operatingSystemUtils: FakeOperatingSystemUtils(),
|
2020-07-23 01:23:20 +00:00
|
|
|
).isSupportedForProject(flutterProject), true);
|
2019-04-25 19:25:12 +00:00
|
|
|
});
|
|
|
|
|
2020-10-03 04:52:53 +00:00
|
|
|
testWithoutContext('LinuxDevice.isSupportedForProject is false with no host app', () async {
|
|
|
|
final FileSystem fileSystem = MemoryFileSystem.test();
|
|
|
|
fileSystem.file('pubspec.yaml').createSync();
|
|
|
|
fileSystem.file('.packages').createSync();
|
|
|
|
final FlutterProject flutterProject = setUpFlutterProject(fileSystem.currentDirectory);
|
2019-04-25 19:25:12 +00:00
|
|
|
|
2020-07-23 01:23:20 +00:00
|
|
|
expect(LinuxDevice(
|
|
|
|
logger: BufferLogger.test(),
|
|
|
|
processManager: FakeProcessManager.any(),
|
2020-10-03 04:52:53 +00:00
|
|
|
fileSystem: fileSystem,
|
|
|
|
operatingSystemUtils: FakeOperatingSystemUtils(),
|
2020-07-23 01:23:20 +00:00
|
|
|
).isSupportedForProject(flutterProject), false);
|
2019-04-25 19:25:12 +00:00
|
|
|
});
|
2019-10-09 23:28:10 +00:00
|
|
|
|
2020-10-03 04:52:53 +00:00
|
|
|
testWithoutContext('LinuxDevice.executablePathForDevice uses the correct package executable', () async {
|
2019-10-09 23:28:10 +00:00
|
|
|
final MockLinuxApp mockApp = MockLinuxApp();
|
2020-07-23 01:23:20 +00:00
|
|
|
final LinuxDevice device = LinuxDevice(
|
|
|
|
logger: BufferLogger.test(),
|
|
|
|
processManager: FakeProcessManager.any(),
|
2020-09-22 23:57:04 +00:00
|
|
|
fileSystem: MemoryFileSystem.test(),
|
2020-10-03 04:52:53 +00:00
|
|
|
operatingSystemUtils: FakeOperatingSystemUtils(),
|
2020-07-23 01:23:20 +00:00
|
|
|
);
|
2019-10-09 23:28:10 +00:00
|
|
|
const String debugPath = 'debug/executable';
|
|
|
|
const String profilePath = 'profile/executable';
|
|
|
|
const String releasePath = 'release/executable';
|
|
|
|
when(mockApp.executable(BuildMode.debug)).thenReturn(debugPath);
|
|
|
|
when(mockApp.executable(BuildMode.profile)).thenReturn(profilePath);
|
|
|
|
when(mockApp.executable(BuildMode.release)).thenReturn(releasePath);
|
|
|
|
|
2020-07-23 01:23:20 +00:00
|
|
|
expect(device.executablePathForDevice(mockApp, BuildMode.debug), debugPath);
|
|
|
|
expect(device.executablePathForDevice(mockApp, BuildMode.profile), profilePath);
|
|
|
|
expect(device.executablePathForDevice(mockApp, BuildMode.release), releasePath);
|
2019-10-09 23:28:10 +00:00
|
|
|
});
|
2019-01-15 15:45:04 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 04:52:53 +00:00
|
|
|
FlutterProject setUpFlutterProject(Directory directory) {
|
|
|
|
final FlutterProjectFactory flutterProjectFactory = FlutterProjectFactory(
|
|
|
|
fileSystem: directory.fileSystem,
|
|
|
|
logger: BufferLogger.test(),
|
|
|
|
);
|
|
|
|
return flutterProjectFactory.fromDirectory(directory);
|
|
|
|
}
|
|
|
|
|
2019-10-09 23:28:10 +00:00
|
|
|
class MockLinuxApp extends Mock implements LinuxApp {}
|
2020-10-03 04:52:53 +00:00
|
|
|
class FakeOperatingSystemUtils extends Fake implements OperatingSystemUtils {
|
|
|
|
@override
|
|
|
|
String get name => 'Linux';
|
|
|
|
}
|