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.
|
|
|
|
|
2021-01-27 23:17:53 +00:00
|
|
|
// @dart = 2.8
|
|
|
|
|
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-10-03 04:52:53 +00:00
|
|
|
import 'package:flutter_tools/src/base/logger.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-25 19:25:12 +00:00
|
|
|
import 'package:flutter_tools/src/project.dart';
|
2019-04-19 01:05:04 +00:00
|
|
|
import 'package:flutter_tools/src/windows/application_package.dart';
|
2019-01-15 15:45:04 +00:00
|
|
|
import 'package:flutter_tools/src/windows/windows_device.dart';
|
2020-10-03 04:52:53 +00:00
|
|
|
import 'package:flutter_tools/src/windows/windows_workflow.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
|
|
|
|
|
|
|
void main() {
|
2020-10-03 04:52:53 +00:00
|
|
|
testWithoutContext('WindowsDevice defaults', () async {
|
|
|
|
final WindowsDevice windowsDevice = setUpWindowsDevice();
|
|
|
|
final PrebuiltWindowsApp windowsApp = PrebuiltWindowsApp(executable: 'foo');
|
|
|
|
|
|
|
|
expect(await windowsDevice.targetPlatform, TargetPlatform.windows_x64);
|
|
|
|
expect(windowsDevice.name, 'Windows');
|
|
|
|
expect(await windowsDevice.installApp(windowsApp), true);
|
|
|
|
expect(await windowsDevice.uninstallApp(windowsApp), true);
|
|
|
|
expect(await windowsDevice.isLatestBuildInstalled(windowsApp), true);
|
|
|
|
expect(await windowsDevice.isAppInstalled(windowsApp), true);
|
|
|
|
expect(windowsDevice.category, Category.desktop);
|
|
|
|
|
|
|
|
expect(windowsDevice.supportsRuntimeMode(BuildMode.debug), true);
|
|
|
|
expect(windowsDevice.supportsRuntimeMode(BuildMode.profile), true);
|
|
|
|
expect(windowsDevice.supportsRuntimeMode(BuildMode.release), true);
|
|
|
|
expect(windowsDevice.supportsRuntimeMode(BuildMode.jitRelease), false);
|
|
|
|
});
|
|
|
|
|
|
|
|
testWithoutContext('WindowsDevices does not list devices if the workflow is unsupported', () async {
|
|
|
|
expect(await WindowsDevices(
|
|
|
|
windowsWorkflow: WindowsWorkflow(
|
|
|
|
featureFlags: TestFeatureFlags(isWindowsEnabled: false),
|
|
|
|
platform: FakePlatform(operatingSystem: 'windows')
|
|
|
|
),
|
|
|
|
operatingSystemUtils: FakeOperatingSystemUtils(),
|
|
|
|
logger: BufferLogger.test(),
|
|
|
|
processManager: FakeProcessManager.any(),
|
|
|
|
fileSystem: MemoryFileSystem.test(),
|
|
|
|
).devices, <Device>[]);
|
|
|
|
});
|
|
|
|
|
|
|
|
testWithoutContext('WindowsDevices lists a devices if the workflow is supported', () async {
|
|
|
|
expect(await WindowsDevices(
|
|
|
|
windowsWorkflow: WindowsWorkflow(
|
|
|
|
featureFlags: TestFeatureFlags(isWindowsEnabled: true),
|
|
|
|
platform: FakePlatform(operatingSystem: 'windows')
|
|
|
|
),
|
|
|
|
operatingSystemUtils: FakeOperatingSystemUtils(),
|
|
|
|
logger: BufferLogger.test(),
|
|
|
|
processManager: FakeProcessManager.any(),
|
|
|
|
fileSystem: MemoryFileSystem.test(),
|
|
|
|
).devices, hasLength(1));
|
|
|
|
});
|
|
|
|
|
|
|
|
testWithoutContext('WindowsDevices ignores the timeout provided to discoverDevices', () async {
|
|
|
|
final WindowsDevices windowsDevices = WindowsDevices(
|
|
|
|
windowsWorkflow: WindowsWorkflow(
|
|
|
|
featureFlags: TestFeatureFlags(isWindowsEnabled: true),
|
|
|
|
platform: FakePlatform(operatingSystem: 'windows')
|
|
|
|
),
|
|
|
|
operatingSystemUtils: FakeOperatingSystemUtils(),
|
|
|
|
logger: BufferLogger.test(),
|
|
|
|
processManager: FakeProcessManager.any(),
|
|
|
|
fileSystem: MemoryFileSystem.test(),
|
|
|
|
);
|
|
|
|
// Timeout ignored.
|
|
|
|
final List<Device> devices = await windowsDevices.discoverDevices(timeout: const Duration(seconds: 10));
|
|
|
|
expect(devices, hasLength(1));
|
|
|
|
});
|
|
|
|
|
|
|
|
testWithoutContext('isSupportedForProject is true with editable host app', () async {
|
|
|
|
final FileSystem fileSystem = MemoryFileSystem.test();
|
|
|
|
final WindowsDevice windowsDevice = setUpWindowsDevice(fileSystem: fileSystem);
|
|
|
|
fileSystem.file('pubspec.yaml').createSync();
|
|
|
|
fileSystem.file('.packages').createSync();
|
|
|
|
fileSystem.directory('windows').createSync();
|
|
|
|
fileSystem.file(fileSystem.path.join('windows', 'CMakeLists.txt')).createSync();
|
|
|
|
final FlutterProject flutterProject = setUpFlutterProject(fileSystem.currentDirectory);
|
|
|
|
|
|
|
|
expect(windowsDevice.isSupportedForProject(flutterProject), true);
|
|
|
|
});
|
|
|
|
|
|
|
|
testWithoutContext('isSupportedForProject is false with no host app', () async {
|
|
|
|
final FileSystem fileSystem = MemoryFileSystem.test();
|
|
|
|
final WindowsDevice windowsDevice = setUpWindowsDevice(fileSystem: fileSystem);
|
|
|
|
fileSystem.file('pubspec.yaml').createSync();
|
|
|
|
fileSystem.file('.packages').createSync();
|
|
|
|
final FlutterProject flutterProject = setUpFlutterProject(fileSystem.currentDirectory);
|
|
|
|
|
|
|
|
expect(windowsDevice.isSupportedForProject(flutterProject), false);
|
|
|
|
});
|
|
|
|
|
|
|
|
testWithoutContext('isSupportedForProject is false with no build file', () async {
|
|
|
|
final FileSystem fileSystem = MemoryFileSystem.test();
|
|
|
|
final WindowsDevice windowsDevice = setUpWindowsDevice(fileSystem: fileSystem);
|
|
|
|
fileSystem.file('pubspec.yaml').createSync();
|
|
|
|
fileSystem.file('.packages').createSync();
|
|
|
|
fileSystem.directory('windows').createSync();
|
|
|
|
final FlutterProject flutterProject = setUpFlutterProject(fileSystem.currentDirectory);
|
|
|
|
|
|
|
|
expect(windowsDevice.isSupportedForProject(flutterProject), false);
|
|
|
|
});
|
|
|
|
|
|
|
|
testWithoutContext('executablePathForDevice uses the correct package executable', () async {
|
|
|
|
final WindowsDevice windowsDevice = setUpWindowsDevice();
|
|
|
|
final MockWindowsApp mockApp = MockWindowsApp();
|
|
|
|
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);
|
|
|
|
|
|
|
|
expect(windowsDevice.executablePathForDevice(mockApp, BuildMode.debug), debugPath);
|
|
|
|
expect(windowsDevice.executablePathForDevice(mockApp, BuildMode.profile), profilePath);
|
|
|
|
expect(windowsDevice.executablePathForDevice(mockApp, BuildMode.release), releasePath);
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
WindowsDevice setUpWindowsDevice({
|
|
|
|
FileSystem fileSystem,
|
|
|
|
Logger logger,
|
|
|
|
ProcessManager processManager,
|
|
|
|
}) {
|
|
|
|
return WindowsDevice(
|
|
|
|
fileSystem: fileSystem ?? MemoryFileSystem.test(),
|
|
|
|
logger: logger ?? BufferLogger.test(),
|
|
|
|
processManager: processManager ?? FakeProcessManager.any(),
|
|
|
|
operatingSystemUtils: FakeOperatingSystemUtils(),
|
|
|
|
);
|
|
|
|
}
|
2019-04-19 01:05:04 +00:00
|
|
|
|
2019-10-09 23:28:10 +00:00
|
|
|
class MockWindowsApp extends Mock implements WindowsApp {}
|