From acda272cf262379cba215af750434d021231c0e9 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Mon, 8 Mar 2021 08:09:04 -0800 Subject: [PATCH] [flutter_tools] add tool feature/scaffold for UWP (#77399) --- .../lib/src/application_package.dart | 2 + packages/flutter_tools/lib/src/artifacts.dart | 3 + .../flutter_tools/lib/src/build_info.dart | 5 +- packages/flutter_tools/lib/src/device.dart | 1 + packages/flutter_tools/lib/src/features.dart | 16 +++ .../lib/src/runner/flutter_command.dart | 1 + .../lib/src/windows/windows_device.dart | 65 +++++++++ .../test/general.shard/features_test.dart | 132 +++++++++++------- .../windows/windows_device_test.dart | 21 ++- packages/flutter_tools/test/src/fakes.dart | 6 + 10 files changed, 198 insertions(+), 54 deletions(-) diff --git a/packages/flutter_tools/lib/src/application_package.dart b/packages/flutter_tools/lib/src/application_package.dart index 8cbe068245..1432f5b29f 100644 --- a/packages/flutter_tools/lib/src/application_package.dart +++ b/packages/flutter_tools/lib/src/application_package.dart @@ -111,6 +111,8 @@ class ApplicationPackageFactory { return applicationBinary == null ? FuchsiaApp.fromFuchsiaProject(FlutterProject.current().fuchsia) : FuchsiaApp.fromPrebuiltApp(applicationBinary); + case TargetPlatform.windows_uwp_x64: + throw UnsupportedError('Cannot build for windows_uwp_x64'); } assert(platform != null); return null; diff --git a/packages/flutter_tools/lib/src/artifacts.dart b/packages/flutter_tools/lib/src/artifacts.dart index 8fa18fa19a..314b2e38a6 100644 --- a/packages/flutter_tools/lib/src/artifacts.dart +++ b/packages/flutter_tools/lib/src/artifacts.dart @@ -521,6 +521,9 @@ class CachedArtifacts implements Artifacts { case TargetPlatform.android: assert(false, 'cannot use TargetPlatform.android to look up artifacts'); return null; + case TargetPlatform.windows_uwp_x64: + assert(false, 'cannot use TargetPlatform.windows_uwp_x64 to look up artifacts'); + return null; } assert(false, 'Invalid platform $platform.'); return null; diff --git a/packages/flutter_tools/lib/src/build_info.dart b/packages/flutter_tools/lib/src/build_info.dart index 0fcf78244c..bfc0a2f80b 100644 --- a/packages/flutter_tools/lib/src/build_info.dart +++ b/packages/flutter_tools/lib/src/build_info.dart @@ -485,6 +485,7 @@ enum TargetPlatform { linux_x64, linux_arm64, windows_x64, + windows_uwp_x64, fuchsia_arm64, fuchsia_x64, tester, @@ -578,10 +579,12 @@ String getNameForTargetPlatform(TargetPlatform platform, {DarwinArch darwinArch} return 'darwin-x64'; case TargetPlatform.linux_x64: return 'linux-x64'; - case TargetPlatform.linux_arm64: + case TargetPlatform.linux_arm64: return 'linux-arm64'; case TargetPlatform.windows_x64: return 'windows-x64'; + case TargetPlatform.windows_uwp_x64: + return 'windows-uwp-x64'; case TargetPlatform.fuchsia_arm64: return 'fuchsia-arm64'; case TargetPlatform.fuchsia_x64: diff --git a/packages/flutter_tools/lib/src/device.dart b/packages/flutter_tools/lib/src/device.dart index 4c81f1b515..666ca4aa5d 100644 --- a/packages/flutter_tools/lib/src/device.dart +++ b/packages/flutter_tools/lib/src/device.dart @@ -418,6 +418,7 @@ class FlutterDeviceManager extends DeviceManager { logger: logger, fileSystem: fileSystem, windowsWorkflow: windowsWorkflow, + featureFlags: featureFlags, ), WebDevices( featureFlags: featureFlags, diff --git a/packages/flutter_tools/lib/src/features.dart b/packages/flutter_tools/lib/src/features.dart index 38dbf8a851..fa8538c208 100644 --- a/packages/flutter_tools/lib/src/features.dart +++ b/packages/flutter_tools/lib/src/features.dart @@ -54,6 +54,9 @@ abstract class FeatureFlags { /// Whether the CFE experimental invalidation strategy is enabled. bool get isExperimentalInvalidationStrategyEnabled => true; + /// Whether the windows UWP embedding is enabled. + bool get isWindowsUwpEnabled => false; + /// Whether a particular feature is enabled for the current channel. /// /// Prefer using one of the specific getters above instead of this API. @@ -100,6 +103,9 @@ class FlutterFeatureFlags implements FeatureFlags { @override bool get isExperimentalInvalidationStrategyEnabled => isEnabled(experimentalInvalidationStrategy); + @override + bool get isWindowsUwpEnabled => isEnabled(windowsUwpEmbedding); + @override bool isEnabled(Feature feature) { final String currentChannel = _flutterVersion.channel; @@ -336,6 +342,16 @@ const Feature experimentalInvalidationStrategy = Feature( ), ); +/// The feature for enabling the Windows UWP embeding. +const Feature windowsUwpEmbedding = Feature( + name: 'Flutter for Windows UWP', + configSetting: 'enable-windows-uwp-desktop', + master: FeatureChannelSetting( + available: true, + enabledByDefault: false, + ), +); + /// A [Feature] is a process for conditionally enabling tool features. /// /// All settings are optional, and if not provided will generally default to diff --git a/packages/flutter_tools/lib/src/runner/flutter_command.dart b/packages/flutter_tools/lib/src/runner/flutter_command.dart index 83d3b3d956..1137abc006 100644 --- a/packages/flutter_tools/lib/src/runner/flutter_command.dart +++ b/packages/flutter_tools/lib/src/runner/flutter_command.dart @@ -1430,6 +1430,7 @@ DevelopmentArtifact _artifactFromTargetPlatform(TargetPlatform targetPlatform) { case TargetPlatform.fuchsia_arm64: case TargetPlatform.fuchsia_x64: case TargetPlatform.tester: + case TargetPlatform.windows_uwp_x64: // No artifacts currently supported. return null; } diff --git a/packages/flutter_tools/lib/src/windows/windows_device.dart b/packages/flutter_tools/lib/src/windows/windows_device.dart index 479802938d..35a528f353 100644 --- a/packages/flutter_tools/lib/src/windows/windows_device.dart +++ b/packages/flutter_tools/lib/src/windows/windows_device.dart @@ -7,12 +7,14 @@ import 'package:meta/meta.dart'; import 'package:process/process.dart'; +import '../application_package.dart'; import '../base/file_system.dart'; import '../base/logger.dart'; import '../base/os.dart'; import '../build_info.dart'; import '../desktop_device.dart'; import '../device.dart'; +import '../features.dart'; import '../project.dart'; import 'application_package.dart'; import 'build_windows.dart'; @@ -68,6 +70,59 @@ class WindowsDevice extends DesktopDevice { } } +// A device that represents a desktop Windows UWP target. +class WindowsUWPDevice extends DesktopDevice { + WindowsUWPDevice({ + @required ProcessManager processManager, + @required Logger logger, + @required FileSystem fileSystem, + @required OperatingSystemUtils operatingSystemUtils, + }) : super( + 'windows-uwp', + platformType: PlatformType.windows, + ephemeral: false, + processManager: processManager, + logger: logger, + fileSystem: fileSystem, + operatingSystemUtils: operatingSystemUtils, + ); + + @override + bool isSupported() => false; + + @override + String get name => 'Windows (UWP)'; + + @override + Future get targetPlatform async => TargetPlatform.windows_uwp_x64; + + @override + bool isSupportedForProject(FlutterProject flutterProject) { + // TODO(flutter): update with detection once FlutterProject knows + // about the UWP structure. + return false; + } + + @override + Future buildForDevice( + covariant WindowsApp package, { + String mainPath, + BuildInfo buildInfo, + }) async { + await buildWindows( + FlutterProject.current().windows, + buildInfo, + target: mainPath, + ); + } + + @override + String executablePathForDevice(ApplicationPackage package, BuildMode buildMode) { + // TODO(flutter): update once application package factory knows about UWP bundle. + throw UnsupportedError('Windows UWP device not implemented.'); + } +} + class WindowsDevices extends PollingDeviceDiscovery { WindowsDevices({ @required ProcessManager processManager, @@ -75,11 +130,13 @@ class WindowsDevices extends PollingDeviceDiscovery { @required FileSystem fileSystem, @required OperatingSystemUtils operatingSystemUtils, @required WindowsWorkflow windowsWorkflow, + @required FeatureFlags featureFlags, }) : _fileSystem = fileSystem, _logger = logger, _processManager = processManager, _operatingSystemUtils = operatingSystemUtils, _windowsWorkflow = windowsWorkflow, + _featureFlags = featureFlags, super('windows devices'); final FileSystem _fileSystem; @@ -87,6 +144,7 @@ class WindowsDevices extends PollingDeviceDiscovery { final ProcessManager _processManager; final OperatingSystemUtils _operatingSystemUtils; final WindowsWorkflow _windowsWorkflow; + final FeatureFlags _featureFlags; @override bool get supportsPlatform => _windowsWorkflow.appliesToHostPlatform; @@ -106,6 +164,13 @@ class WindowsDevices extends PollingDeviceDiscovery { processManager: _processManager, operatingSystemUtils: _operatingSystemUtils, ), + if (_featureFlags.isWindowsUwpEnabled) + WindowsUWPDevice( + fileSystem: _fileSystem, + logger: _logger, + processManager: _processManager, + operatingSystemUtils: _operatingSystemUtils, + ) ]; } diff --git a/packages/flutter_tools/test/general.shard/features_test.dart b/packages/flutter_tools/test/general.shard/features_test.dart index 259673c207..d83ab92084 100644 --- a/packages/flutter_tools/test/general.shard/features_test.dart +++ b/packages/flutter_tools/test/general.shard/features_test.dart @@ -81,27 +81,27 @@ void main() { expect(featureFlags.isWebEnabled, true); }); - testWithoutContext('flutter web help string', () { + testWithoutContext('Flutter web help string', () { expect(flutterWebFeature.generateHelpMessage(), 'Enable or disable Flutter for web. ' 'This setting will take effect on the master, dev, beta, and stable channels.'); }); - testWithoutContext('flutter macOS desktop help string', () { + testWithoutContext('Flutter macOS desktop help string', () { expect(flutterMacOSDesktopFeature.generateHelpMessage(), 'Enable or disable beta-quality support for desktop on macOS. ' 'This setting will take effect on the master, dev, beta, and stable channels. ' 'Newer beta versions are available on the beta channel.'); }); - testWithoutContext('flutter Linux desktop help string', () { + testWithoutContext('Flutter Linux desktop help string', () { expect(flutterLinuxDesktopFeature.generateHelpMessage(), 'Enable or disable beta-quality support for desktop on Linux. ' 'This setting will take effect on the master, dev, beta, and stable channels. ' 'Newer beta versions are available on the beta channel.'); }); - testWithoutContext('flutter Windows desktop help string', () { + testWithoutContext('Flutter Windows desktop help string', () { expect(flutterWindowsDesktopFeature.generateHelpMessage(), 'Enable or disable beta-quality support for desktop on Windows. ' 'This setting will take effect on the master, dev, beta, and stable channels. ' @@ -124,81 +124,81 @@ void main() { /// Flutter Web - testWithoutContext('flutter web off by default on master', () { + testWithoutContext('Flutter web off by default on master', () { when(mockFlutterVerion.channel).thenReturn('master'); expect(featureFlags.isWebEnabled, false); }); - testWithoutContext('flutter web enabled with config on master', () { + testWithoutContext('Flutter web enabled with config on master', () { when(mockFlutterVerion.channel).thenReturn('master'); testConfig.setValue('enable-web', true); expect(featureFlags.isWebEnabled, true); }); - testWithoutContext('flutter web enabled with environment variable on master', () { + testWithoutContext('Flutter web enabled with environment variable on master', () { when(mockFlutterVerion.channel).thenReturn('master'); when(mockPlatform.environment).thenReturn({'FLUTTER_WEB': 'true'}); expect(featureFlags.isWebEnabled, true); }); - testWithoutContext('flutter web off by default on dev', () { + testWithoutContext('Flutter web off by default on dev', () { when(mockFlutterVerion.channel).thenReturn('dev'); expect(featureFlags.isWebEnabled, false); }); - testWithoutContext('flutter web enabled with config on dev', () { + testWithoutContext('Flutter web enabled with config on dev', () { when(mockFlutterVerion.channel).thenReturn('dev'); testConfig.setValue('enable-web', true); expect(featureFlags.isWebEnabled, true); }); - testWithoutContext('flutter web enabled with environment variable on dev', () { + testWithoutContext('Flutter web enabled with environment variable on dev', () { when(mockFlutterVerion.channel).thenReturn('dev'); when(mockPlatform.environment).thenReturn({'FLUTTER_WEB': 'true'}); expect(featureFlags.isWebEnabled, true); }); - testWithoutContext('flutter web off by default on beta', () { + testWithoutContext('Flutter web off by default on beta', () { when(mockFlutterVerion.channel).thenReturn('beta'); expect(featureFlags.isWebEnabled, false); }); - testWithoutContext('flutter web enabled with config on beta', () { + testWithoutContext('Flutter web enabled with config on beta', () { when(mockFlutterVerion.channel).thenReturn('beta'); testConfig.setValue('enable-web', true); expect(featureFlags.isWebEnabled, true); }); - testWithoutContext('flutter web not enabled with environment variable on beta', () { + testWithoutContext('Flutter web not enabled with environment variable on beta', () { when(mockFlutterVerion.channel).thenReturn('beta'); when(mockPlatform.environment).thenReturn({'FLUTTER_WEB': 'true'}); expect(featureFlags.isWebEnabled, true); }); - testWithoutContext('flutter web on by default on stable', () { + testWithoutContext('Flutter web on by default on stable', () { when(mockFlutterVerion.channel).thenReturn('stable'); testConfig.removeValue('enable-web'); expect(featureFlags.isWebEnabled, true); }); - testWithoutContext('flutter web enabled with config on stable', () { + testWithoutContext('Flutter web enabled with config on stable', () { when(mockFlutterVerion.channel).thenReturn('stable'); testConfig.setValue('enable-web', true); expect(featureFlags.isWebEnabled, true); }); - testWithoutContext('flutter web not enabled with environment variable on stable', () { + testWithoutContext('Flutter web not enabled with environment variable on stable', () { when(mockFlutterVerion.channel).thenReturn('stable'); when(mockPlatform.environment).thenReturn({'FLUTTER_WEB': 'enabled'}); @@ -207,80 +207,80 @@ void main() { /// Flutter macOS desktop. - testWithoutContext('flutter macos desktop off by default on master', () { + testWithoutContext('Flutter macos desktop off by default on master', () { when(mockFlutterVerion.channel).thenReturn('master'); expect(featureFlags.isMacOSEnabled, false); }); - testWithoutContext('flutter macos desktop enabled with config on master', () { + testWithoutContext('Flutter macos desktop enabled with config on master', () { when(mockFlutterVerion.channel).thenReturn('master'); testConfig.setValue('enable-macos-desktop', true); expect(featureFlags.isMacOSEnabled, true); }); - testWithoutContext('flutter macos desktop enabled with environment variable on master', () { + testWithoutContext('Flutter macos desktop enabled with environment variable on master', () { when(mockFlutterVerion.channel).thenReturn('master'); when(mockPlatform.environment).thenReturn({'FLUTTER_MACOS': 'true'}); expect(featureFlags.isMacOSEnabled, true); }); - testWithoutContext('flutter macos desktop off by default on dev', () { + testWithoutContext('Flutter macos desktop off by default on dev', () { when(mockFlutterVerion.channel).thenReturn('dev'); expect(featureFlags.isMacOSEnabled, false); }); - testWithoutContext('flutter macos desktop enabled with config on dev', () { + testWithoutContext('Flutter macos desktop enabled with config on dev', () { when(mockFlutterVerion.channel).thenReturn('dev'); testConfig.setValue('enable-macos-desktop', true); expect(featureFlags.isMacOSEnabled, true); }); - testWithoutContext('flutter macos desktop enabled with environment variable on dev', () { + testWithoutContext('Flutter macos desktop enabled with environment variable on dev', () { when(mockFlutterVerion.channel).thenReturn('dev'); when(mockPlatform.environment).thenReturn({'FLUTTER_MACOS': 'true'}); expect(featureFlags.isMacOSEnabled, true); }); - testWithoutContext('flutter macos desktop off by default on beta', () { + testWithoutContext('Flutter macos desktop off by default on beta', () { when(mockFlutterVerion.channel).thenReturn('beta'); expect(featureFlags.isMacOSEnabled, false); }); - testWithoutContext('flutter macos desktop enabled with config on beta', () { + testWithoutContext('Flutter macos desktop enabled with config on beta', () { when(mockFlutterVerion.channel).thenReturn('beta'); testConfig.setValue('enable-macos-desktop', true); expect(featureFlags.isMacOSEnabled, true); }); - testWithoutContext('flutter macos desktop enabled with environment variable on beta', () { + testWithoutContext('Flutter macos desktop enabled with environment variable on beta', () { when(mockFlutterVerion.channel).thenReturn('beta'); when(mockPlatform.environment).thenReturn({'FLUTTER_MACOS': 'true'}); expect(featureFlags.isMacOSEnabled, true); }); - testWithoutContext('flutter macos desktop off by default on stable', () { + testWithoutContext('Flutter macos desktop off by default on stable', () { when(mockFlutterVerion.channel).thenReturn('stable'); expect(featureFlags.isMacOSEnabled, false); }); - testWithoutContext('flutter macos desktop enabled with config on stable', () { + testWithoutContext('Flutter macos desktop enabled with config on stable', () { when(mockFlutterVerion.channel).thenReturn('stable'); testConfig.setValue('enable-macos-desktop', true); expect(featureFlags.isMacOSEnabled, true); }); - testWithoutContext('flutter macos desktop enabled with environment variable on stable', () { + testWithoutContext('Flutter macos desktop enabled with environment variable on stable', () { when(mockFlutterVerion.channel).thenReturn('stable'); when(mockPlatform.environment).thenReturn({'FLUTTER_MACOS': 'true'}); @@ -288,80 +288,80 @@ void main() { }); /// Flutter Linux Desktop - testWithoutContext('flutter linux desktop off by default on master', () { + testWithoutContext('Flutter linux desktop off by default on master', () { when(mockFlutterVerion.channel).thenReturn('master'); expect(featureFlags.isLinuxEnabled, false); }); - testWithoutContext('flutter linux desktop enabled with config on master', () { + testWithoutContext('Flutter linux desktop enabled with config on master', () { when(mockFlutterVerion.channel).thenReturn('master'); testConfig.setValue('enable-linux-desktop', true); expect(featureFlags.isLinuxEnabled, true); }); - testWithoutContext('flutter linux desktop enabled with environment variable on master', () { + testWithoutContext('Flutter linux desktop enabled with environment variable on master', () { when(mockFlutterVerion.channel).thenReturn('master'); when(mockPlatform.environment).thenReturn({'FLUTTER_LINUX': 'true'}); expect(featureFlags.isLinuxEnabled, true); }); - testWithoutContext('flutter linux desktop off by default on dev', () { + testWithoutContext('Flutter linux desktop off by default on dev', () { when(mockFlutterVerion.channel).thenReturn('dev'); expect(featureFlags.isLinuxEnabled, false); }); - testWithoutContext('flutter linux desktop enabled with config on dev', () { + testWithoutContext('Flutter linux desktop enabled with config on dev', () { when(mockFlutterVerion.channel).thenReturn('dev'); testConfig.setValue('enable-linux-desktop', true); expect(featureFlags.isLinuxEnabled, true); }); - testWithoutContext('flutter linux desktop enabled with environment variable on dev', () { + testWithoutContext('Flutter linux desktop enabled with environment variable on dev', () { when(mockFlutterVerion.channel).thenReturn('dev'); when(mockPlatform.environment).thenReturn({'FLUTTER_LINUX': 'true'}); expect(featureFlags.isLinuxEnabled, true); }); - testWithoutContext('flutter linux desktop off by default on beta', () { + testWithoutContext('Flutter linux desktop off by default on beta', () { when(mockFlutterVerion.channel).thenReturn('beta'); expect(featureFlags.isLinuxEnabled, false); }); - testWithoutContext('flutter linux desktop enabled with config on beta', () { + testWithoutContext('Flutter linux desktop enabled with config on beta', () { when(mockFlutterVerion.channel).thenReturn('beta'); testConfig.setValue('enable-linux-desktop', true); expect(featureFlags.isLinuxEnabled, true); }); - testWithoutContext('flutter linux desktop enabled with environment variable on beta', () { + testWithoutContext('Flutter linux desktop enabled with environment variable on beta', () { when(mockFlutterVerion.channel).thenReturn('beta'); when(mockPlatform.environment).thenReturn({'FLUTTER_LINUX': 'true'}); expect(featureFlags.isLinuxEnabled, true); }); - testWithoutContext('flutter linux desktop off by default on stable', () { + testWithoutContext('Flutter linux desktop off by default on stable', () { when(mockFlutterVerion.channel).thenReturn('stable'); expect(featureFlags.isLinuxEnabled, false); }); - testWithoutContext('flutter linux desktop enabled with config on stable', () { + testWithoutContext('Flutter linux desktop enabled with config on stable', () { when(mockFlutterVerion.channel).thenReturn('stable'); testConfig.setValue('enable-linux-desktop', true); expect(featureFlags.isLinuxEnabled, true); }); - testWithoutContext('flutter linux desktop enabled with environment variable on stable', () { + testWithoutContext('Flutter linux desktop enabled with environment variable on stable', () { when(mockFlutterVerion.channel).thenReturn('stable'); when(mockPlatform.environment).thenReturn({'FLUTTER_LINUX': 'true'}); @@ -369,85 +369,113 @@ void main() { }); /// Flutter Windows desktop. - testWithoutContext('flutter windows desktop off by default on master', () { + testWithoutContext('Flutter Windows desktop off by default on master', () { when(mockFlutterVerion.channel).thenReturn('master'); expect(featureFlags.isWindowsEnabled, false); }); - testWithoutContext('flutter windows desktop enabled with config on master', () { + testWithoutContext('Flutter Windows desktop enabled with config on master', () { when(mockFlutterVerion.channel).thenReturn('master'); testConfig.setValue('enable-windows-desktop', true); expect(featureFlags.isWindowsEnabled, true); }); - testWithoutContext('flutter windows desktop enabled with environment variable on master', () { + testWithoutContext('Flutter Windows desktop enabled with environment variable on master', () { when(mockFlutterVerion.channel).thenReturn('master'); when(mockPlatform.environment).thenReturn({'FLUTTER_WINDOWS': 'true'}); expect(featureFlags.isWindowsEnabled, true); }); - testWithoutContext('flutter windows desktop off by default on dev', () { + testWithoutContext('Flutter Windows desktop off by default on dev', () { when(mockFlutterVerion.channel).thenReturn('dev'); expect(featureFlags.isWindowsEnabled, false); }); - testWithoutContext('flutter windows desktop enabled with config on dev', () { + testWithoutContext('Flutter Windows desktop enabled with config on dev', () { when(mockFlutterVerion.channel).thenReturn('dev'); testConfig.setValue('enable-windows-desktop', true); expect(featureFlags.isWindowsEnabled, true); }); - testWithoutContext('flutter windows desktop not enabled with environment variable on dev', () { + testWithoutContext('Flutter Windows desktop not enabled with environment variable on dev', () { when(mockFlutterVerion.channel).thenReturn('dev'); when(mockPlatform.environment).thenReturn({'FLUTTER_WINDOWS': 'true'}); expect(featureFlags.isWindowsEnabled, true); }); - testWithoutContext('flutter windows desktop off by default on beta', () { + testWithoutContext('Flutter Windows desktop off by default on beta', () { when(mockFlutterVerion.channel).thenReturn('beta'); expect(featureFlags.isWindowsEnabled, false); }); - testWithoutContext('flutter windows desktop enabled with config on beta', () { + testWithoutContext('Flutter Windows desktop enabled with config on beta', () { when(mockFlutterVerion.channel).thenReturn('beta'); testConfig.setValue('enable-windows-desktop', true); expect(featureFlags.isWindowsEnabled, true); }); - testWithoutContext('flutter windows desktop enabled with environment variable on beta', () { + testWithoutContext('Flutter Windows desktop enabled with environment variable on beta', () { when(mockFlutterVerion.channel).thenReturn('beta'); when(mockPlatform.environment).thenReturn({'FLUTTER_WINDOWS': 'true'}); expect(featureFlags.isWindowsEnabled, true); }); - testWithoutContext('flutter windows desktop off by default on stable', () { + testWithoutContext('Flutter Windows desktop off by default on stable', () { when(mockFlutterVerion.channel).thenReturn('stable'); expect(featureFlags.isWindowsEnabled, false); }); - testWithoutContext('flutter windows desktop enabled with config on stable', () { + testWithoutContext('Flutter Windows desktop enabled with config on stable', () { when(mockFlutterVerion.channel).thenReturn('stable'); testConfig.setValue('enable-windows-desktop', true); expect(featureFlags.isWindowsEnabled, true); }); - testWithoutContext('flutter windows desktop enabled with environment variable on stable', () { + testWithoutContext('Flutter Windows desktop enabled with environment variable on stable', () { when(mockFlutterVerion.channel).thenReturn('stable'); when(mockPlatform.environment).thenReturn({'FLUTTER_WINDOWS': 'true'}); expect(featureFlags.isWindowsEnabled, true); }); + + // Windows UWP desktop + + testWithoutContext('Flutter Windows UWP desktop off by default on master', () { + when(mockFlutterVerion.channel).thenReturn('master'); + + expect(featureFlags.isWindowsUwpEnabled, false); + }); + + testWithoutContext('Flutter Windows UWP desktop enabled with config on master', () { + when(mockFlutterVerion.channel).thenReturn('master'); + testConfig.setValue('enable-windows-uwp-desktop', true); + + expect(featureFlags.isWindowsUwpEnabled, true); + }); + + testWithoutContext('Flutter Windows UWP desktop off by default on stable', () { + when(mockFlutterVerion.channel).thenReturn('stable'); + + expect(featureFlags.isWindowsUwpEnabled, false); + }); + + testWithoutContext('Flutter Windows UWP desktop not enabled with config on stable', () { + when(mockFlutterVerion.channel).thenReturn('stable'); + testConfig.setValue('enable-windows-uwp-desktop', true); + + expect(featureFlags.isWindowsUwpEnabled, false); + }); }); } diff --git a/packages/flutter_tools/test/general.shard/windows/windows_device_test.dart b/packages/flutter_tools/test/general.shard/windows/windows_device_test.dart index 8eb78fb383..d7a77f56f6 100644 --- a/packages/flutter_tools/test/general.shard/windows/windows_device_test.dart +++ b/packages/flutter_tools/test/general.shard/windows/windows_device_test.dart @@ -10,6 +10,7 @@ import 'package:flutter_tools/src/base/logger.dart'; import 'package:flutter_tools/src/base/platform.dart'; import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/device.dart'; +import 'package:flutter_tools/src/features.dart'; import 'package:flutter_tools/src/project.dart'; import 'package:flutter_tools/src/windows/application_package.dart'; import 'package:flutter_tools/src/windows/windows_device.dart'; @@ -43,8 +44,9 @@ void main() { expect(await WindowsDevices( windowsWorkflow: WindowsWorkflow( featureFlags: TestFeatureFlags(isWindowsEnabled: false), - platform: FakePlatform(operatingSystem: 'windows') + platform: FakePlatform(operatingSystem: 'windows'), ), + featureFlags: TestFeatureFlags(isWindowsEnabled: false), operatingSystemUtils: FakeOperatingSystemUtils(), logger: BufferLogger.test(), processManager: FakeProcessManager.any(), @@ -62,9 +64,25 @@ void main() { logger: BufferLogger.test(), processManager: FakeProcessManager.any(), fileSystem: MemoryFileSystem.test(), + featureFlags: TestFeatureFlags(isWindowsEnabled: true), ).devices, hasLength(1)); }); + testWithoutContext('WindowsDevices lists a UWP Windows device if feature is enabled', () async { + final FeatureFlags featureFlags = TestFeatureFlags(isWindowsEnabled: true, isWindowsUwpEnabled: true); + expect(await WindowsDevices( + windowsWorkflow: WindowsWorkflow( + featureFlags: featureFlags, + platform: FakePlatform(operatingSystem: 'windows') + ), + operatingSystemUtils: FakeOperatingSystemUtils(), + logger: BufferLogger.test(), + processManager: FakeProcessManager.any(), + fileSystem: MemoryFileSystem.test(), + featureFlags: featureFlags, + ).devices, hasLength(2)); + }); + testWithoutContext('WindowsDevices ignores the timeout provided to discoverDevices', () async { final WindowsDevices windowsDevices = WindowsDevices( windowsWorkflow: WindowsWorkflow( @@ -75,6 +93,7 @@ void main() { logger: BufferLogger.test(), processManager: FakeProcessManager.any(), fileSystem: MemoryFileSystem.test(), + featureFlags: TestFeatureFlags(isWindowsEnabled: true), ); // Timeout ignored. final List devices = await windowsDevices.discoverDevices(timeout: const Duration(seconds: 10)); diff --git a/packages/flutter_tools/test/src/fakes.dart b/packages/flutter_tools/test/src/fakes.dart index ff7e383c73..564981b8cd 100644 --- a/packages/flutter_tools/test/src/fakes.dart +++ b/packages/flutter_tools/test/src/fakes.dart @@ -552,6 +552,7 @@ class TestFeatureFlags implements FeatureFlags { this.isIOSEnabled = true, this.isFuchsiaEnabled = false, this.isExperimentalInvalidationStrategyEnabled = false, + this.isWindowsUwpEnabled = false, }); @override @@ -581,6 +582,9 @@ class TestFeatureFlags implements FeatureFlags { @override final bool isExperimentalInvalidationStrategyEnabled; + @override + final bool isWindowsUwpEnabled; + @override bool isEnabled(Feature feature) { switch (feature) { @@ -602,6 +606,8 @@ class TestFeatureFlags implements FeatureFlags { return isFuchsiaEnabled; case experimentalInvalidationStrategy: return isExperimentalInvalidationStrategyEnabled; + case windowsUwpEmbedding: + return isWindowsUwpEnabled; } return false; }