Unverified Commit 028b7dce authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] remove context from WebWorkflow (#52613)

parent 48fc1350
......@@ -197,7 +197,10 @@ Future<T> runInContext<T>(
processManager: globals.processManager,
)
),
WebWorkflow: () => const WebWorkflow(),
WebWorkflow: () => WebWorkflow(
featureFlags: featureFlags,
platform: globals.platform,
),
WindowsWorkflow: () => const WindowsWorkflow(),
Xcode: () => Xcode(
logger: globals.logger,
......
......@@ -56,6 +56,16 @@ class _DefaultDoctorValidatorsProvider implements DoctorValidatorsProvider {
List<DoctorValidator> _validators;
List<Workflow> _workflows;
final LinuxWorkflow linuxWorkflow = LinuxWorkflow(
platform: globals.platform,
featureFlags: featureFlags,
);
final WebWorkflow webWorkflow = WebWorkflow(
platform: globals.platform,
featureFlags: featureFlags,
);
@override
List<DoctorValidator> get validators {
if (_validators != null) {
......@@ -67,11 +77,6 @@ class _DefaultDoctorValidatorsProvider implements DoctorValidatorsProvider {
...IntelliJValidator.installedValidators,
...VsCodeValidator.installedValidators,
];
final LinuxWorkflow linuxWorkflow = LinuxWorkflow(
platform: globals.platform,
featureFlags: featureFlags,
);
_validators = <DoctorValidator>[
FlutterValidator(),
if (androidWorkflow.appliesToHostPlatform)
......@@ -119,10 +124,6 @@ class _DefaultDoctorValidatorsProvider implements DoctorValidatorsProvider {
_workflows.add(fuchsiaWorkflow);
}
final LinuxWorkflow linuxWorkflow = LinuxWorkflow(
platform: globals.platform,
featureFlags: featureFlags,
);
if (linuxWorkflow.appliesToHostPlatform) {
_workflows.add(linuxWorkflow);
}
......
......@@ -2,25 +2,33 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import '../base/context.dart';
import 'package:meta/meta.dart';
import 'package:platform/platform.dart';
import '../doctor.dart';
import '../features.dart';
import '../globals.dart' as globals;
/// The web workflow instance.
WebWorkflow get webWorkflow => context.get<WebWorkflow>();
class WebWorkflow extends Workflow {
const WebWorkflow();
const WebWorkflow({
@required Platform platform,
@required FeatureFlags featureFlags,
}) : _platform = platform,
_featureFlags = featureFlags;
final Platform _platform;
final FeatureFlags _featureFlags;
@override
bool get appliesToHostPlatform => featureFlags.isWebEnabled && (globals.platform.isWindows || globals.platform.isMacOS || globals.platform.isLinux);
bool get appliesToHostPlatform => _featureFlags.isWebEnabled &&
(_platform.isWindows ||
_platform.isMacOS ||
_platform.isLinux);
@override
bool get canLaunchDevices => featureFlags.isWebEnabled;
bool get canLaunchDevices => _featureFlags.isWebEnabled;
@override
bool get canListDevices => featureFlags.isWebEnabled;
bool get canListDevices => _featureFlags.isWebEnabled;
@override
bool get canListEmulators => false;
......
......@@ -722,7 +722,8 @@ void main() {
testUsingContext('WebWorkflow is a part of validator workflows if enabled', () async {
when(globals.processManager.canRun(any)).thenReturn(true);
expect(DoctorValidatorsProvider.defaultInstance.workflows.contains(webWorkflow), true);
expect(DoctorValidatorsProvider.defaultInstance.workflows,
contains(isA<WebWorkflow>()));
}, overrides: <Type, Generator>{
FeatureFlags: () => TestFeatureFlags(isWebEnabled: true),
ProcessManager: () => MockProcessManager(),
......
......@@ -2,115 +2,67 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter_tools/src/features.dart';
import 'package:flutter_tools/src/web/chrome.dart';
import 'package:flutter_tools/src/web/workflow.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:mockito/mockito.dart';
import 'package:process/process.dart';
import 'package:platform/platform.dart';
import 'package:flutter_tools/src/web/workflow.dart';
import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/testbed.dart';
void main() {
group('WebWorkflow', () {
Testbed testbed;
MockPlatform notSupported;
MockPlatform windows;
MockPlatform linux;
MockPlatform macos;
MockProcessManager mockProcessManager;
WebWorkflow workflow;
setUpAll(() {
notSupported = MockPlatform(linux: false, windows: false, macos: false);
windows = MockPlatform(windows: true);
linux = MockPlatform(linux: true);
macos = MockPlatform(macos: true);
workflow = const WebWorkflow();
mockProcessManager = MockProcessManager();
testbed = Testbed(setup: () async {
globals.fs.file('chrome').createSync();
when(mockProcessManager.canRun('chrome')).thenReturn(true);
}, overrides: <Type, Generator>{
FeatureFlags: () => TestFeatureFlags(isWebEnabled: true),
ProcessManager: () => mockProcessManager,
});
});
test('Applies on Linux', () => testbed.run(() {
expect(workflow.appliesToHostPlatform, true);
expect(workflow.canLaunchDevices, true);
expect(workflow.canListDevices, true);
expect(workflow.canListEmulators, false);
}, overrides: <Type, Generator>{
Platform: () => linux,
}));
test('Applies on macOS', () => testbed.run(() {
expect(workflow.appliesToHostPlatform, true);
expect(workflow.canLaunchDevices, true);
expect(workflow.canListDevices, true);
expect(workflow.canListEmulators, false);
}, overrides: <Type, Generator>{
Platform: () => macos,
}));
test('Applies on Windows', () => testbed.run(() {
expect(workflow.appliesToHostPlatform, true);
expect(workflow.canLaunchDevices, true);
expect(workflow.canListDevices, true);
expect(workflow.canListEmulators, false);
}, overrides: <Type, Generator>{
Platform: () => windows,
}));
testWithoutContext('WebWorkflow applies on Linux', () {
final WebWorkflow workflow = WebWorkflow(
platform: FakePlatform(operatingSystem: 'linux'),
featureFlags: TestFeatureFlags(isWebEnabled: true),
);
expect(workflow.appliesToHostPlatform, true);
expect(workflow.canLaunchDevices, true);
expect(workflow.canListDevices, true);
expect(workflow.canListEmulators, false);
});
test('does not apply on other platforms', () => testbed.run(() {
expect(workflow.appliesToHostPlatform, false);
}, overrides: <Type, Generator>{
Platform: () => notSupported,
}));
testWithoutContext('WebWorkflow applies on macOS', () {
final WebWorkflow workflow = WebWorkflow(
platform: FakePlatform(operatingSystem: 'macos'),
featureFlags: TestFeatureFlags(isWebEnabled: true),
);
test('does not apply if feature flag is disabled', () => testbed.run(() {
expect(workflow.appliesToHostPlatform, false);
expect(workflow.canLaunchDevices, false);
expect(workflow.canListDevices, false);
expect(workflow.canListEmulators, false);
}, overrides: <Type, Generator>{
Platform: () => macos,
FeatureFlags: () => TestFeatureFlags(isWebEnabled: false),
}));
expect(workflow.appliesToHostPlatform, true);
expect(workflow.canLaunchDevices, true);
expect(workflow.canListDevices, true);
expect(workflow.canListEmulators, false);
});
}
class MockProcessManager extends Mock implements ProcessManager {}
testWithoutContext('WebWorkflow applies on Windows', () {
final WebWorkflow workflow = WebWorkflow(
platform: FakePlatform(operatingSystem: 'windows'),
featureFlags: TestFeatureFlags(isWebEnabled: true),
);
class MockPlatform extends Mock implements Platform {
MockPlatform({
this.windows = false,
this.macos = false,
this.linux = false,
this.environment = const <String, String>{
kChromeEnvironment: 'chrome',
},
expect(workflow.appliesToHostPlatform, true);
expect(workflow.canLaunchDevices, true);
expect(workflow.canListDevices, true);
expect(workflow.canListEmulators, false);
});
final bool windows;
final bool macos;
final bool linux;
testWithoutContext('WebWorkflow does not apply on other platforms', () {
final WebWorkflow workflow = WebWorkflow(
platform: FakePlatform(operatingSystem: 'fuchsia'),
featureFlags: TestFeatureFlags(isWebEnabled: true),
);
@override
final Map<String, String> environment;
@override
bool get isLinux => linux;
expect(workflow.appliesToHostPlatform, false);
});
@override
bool get isMacOS => macos;
testWithoutContext('WebWorkflow does not apply if feature flag is disabled', () {
final WebWorkflow workflow = WebWorkflow(
platform: FakePlatform(operatingSystem: 'linux'),
featureFlags: TestFeatureFlags(),
);
@override
bool get isWindows => windows;
expect(workflow.appliesToHostPlatform, false);
expect(workflow.canLaunchDevices, false);
expect(workflow.canListDevices, false);
expect(workflow.canListEmulators, false);
});
}
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