[flutter_tools] remove context from WebWorkflow (#52613)

This commit is contained in:
Jonah Williams 2020-03-16 11:33:00 -07:00 committed by GitHub
parent 48fc135003
commit 028b7dced1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 83 additions and 118 deletions

View file

@ -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,

View file

@ -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);
}

View file

@ -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;

View file

@ -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(),

View file

@ -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;
testWithoutContext('WebWorkflow applies on Linux', () {
final WebWorkflow workflow = WebWorkflow(
platform: FakePlatform(operatingSystem: 'linux'),
featureFlags: TestFeatureFlags(isWebEnabled: true),
);
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,
}));
test('does not apply on other platforms', () => testbed.run(() {
expect(workflow.appliesToHostPlatform, false);
}, overrides: <Type, Generator>{
Platform: () => notSupported,
}));
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),
}));
});
}
class MockProcessManager extends Mock implements ProcessManager {}
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 applies on macOS', () {
final WebWorkflow workflow = WebWorkflow(
platform: FakePlatform(operatingSystem: 'macos'),
featureFlags: TestFeatureFlags(isWebEnabled: true),
);
@override
final Map<String, String> environment;
expect(workflow.appliesToHostPlatform, true);
expect(workflow.canLaunchDevices, true);
expect(workflow.canListDevices, true);
expect(workflow.canListEmulators, false);
});
@override
bool get isLinux => linux;
testWithoutContext('WebWorkflow applies on Windows', () {
final WebWorkflow workflow = WebWorkflow(
platform: FakePlatform(operatingSystem: 'windows'),
featureFlags: TestFeatureFlags(isWebEnabled: true),
);
@override
bool get isMacOS => macos;
expect(workflow.appliesToHostPlatform, true);
expect(workflow.canLaunchDevices, true);
expect(workflow.canListDevices, true);
expect(workflow.canListEmulators, false);
});
@override
bool get isWindows => windows;
testWithoutContext('WebWorkflow does not apply on other platforms', () {
final WebWorkflow workflow = WebWorkflow(
platform: FakePlatform(operatingSystem: 'fuchsia'),
featureFlags: TestFeatureFlags(isWebEnabled: true),
);
expect(workflow.appliesToHostPlatform, false);
});
testWithoutContext('WebWorkflow does not apply if feature flag is disabled', () {
final WebWorkflow workflow = WebWorkflow(
platform: FakePlatform(operatingSystem: 'linux'),
featureFlags: TestFeatureFlags(),
);
expect(workflow.appliesToHostPlatform, false);
expect(workflow.canLaunchDevices, false);
expect(workflow.canListDevices, false);
expect(workflow.canListEmulators, false);
});
}