desktop workflow, devices, and test (#26511)

This commit is contained in:
Jonah Williams
2019-01-15 07:45:04 -08:00
committed by GitHub
parent fda193aa5d
commit 3a694a6d5d
15 changed files with 792 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
// Copyright 2018 The Chromium Authors. All rights reserved.
// 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/base/platform.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/linux/linux_device.dart';
import 'package:flutter_tools/src/device.dart';
import 'package:mockito/mockito.dart';
import '../src/common.dart';
import '../src/context.dart';
void main() {
group(LinuxDevice, () {
final LinuxDevice device = LinuxDevice();
final MockPlatform notLinux = MockPlatform();
when(notLinux.isLinux).thenReturn(false);
when(notLinux.environment).thenReturn(const <String, String>{});
test('defaults', () async {
expect(await device.targetPlatform, TargetPlatform.linux_x64);
expect(device.name, 'Linux');
});
test('unimplemented methods', () {
expect(() => device.installApp(null), throwsA(isInstanceOf<UnimplementedError>()));
expect(() => device.uninstallApp(null), throwsA(isInstanceOf<UnimplementedError>()));
expect(() => device.isLatestBuildInstalled(null), throwsA(isInstanceOf<UnimplementedError>()));
expect(() => device.startApp(null), throwsA(isInstanceOf<UnimplementedError>()));
expect(() => device.stopApp(null), throwsA(isInstanceOf<UnimplementedError>()));
expect(() => device.isAppInstalled(null), throwsA(isInstanceOf<UnimplementedError>()));
});
test('noop port forwarding', () async {
final LinuxDevice device = LinuxDevice();
final DevicePortForwarder portForwarder = device.portForwarder;
final int result = await portForwarder.forward(2);
expect(result, 2);
expect(portForwarder.forwardedPorts.isEmpty, true);
});
testUsingContext('No devices listed if platform unsupported', () async {
expect(await LinuxDevices().devices, <Device>[]);
}, overrides: <Type, Generator>{
Platform: () => notLinux,
});
});
}
class MockPlatform extends Mock implements Platform {}

View File

@@ -0,0 +1,58 @@
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:mockito/mockito.dart';
import 'package:flutter_tools/src/linux/linux_workflow.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/cache.dart';
import '../src/common.dart';
import '../src/context.dart';
void main() {
group(LinuxWorkflow, () {
final MockPlatform linux = MockPlatform();
final MockPlatform notLinux = MockPlatform();
when(linux.isLinux).thenReturn(true);
when(notLinux.isLinux).thenReturn(false);
testUsingContext('Applies to linux platform', () {
expect(linuxWorkflow.appliesToHostPlatform, true);
}, overrides: <Type, Generator>{
Platform: () => linux,
});
testUsingContext('Does not apply to non-linux platform', () {
expect(linuxWorkflow.appliesToHostPlatform, false);
}, overrides: <Type, Generator>{
Platform: () => notLinux,
});
final MockFileSystem fileSystem = MockFileSystem();
final MockDirectory directory = MockDirectory();
Cache.flutterRoot = '';
when(fileSystem.directory(Cache.flutterRoot)).thenReturn(directory);
when(directory.parent).thenReturn(directory);
when(directory.childDirectory('flutter-desktop-embedding')).thenReturn(directory);
when(directory.existsSync()).thenReturn(true);
testUsingContext('defaults', () {
expect(linuxWorkflow.canListEmulators, false);
expect(linuxWorkflow.canLaunchDevices, true);
expect(linuxWorkflow.canListDevices, true);
}, overrides: <Type, Generator>{
Platform: () => linux,
FileSystem: () => fileSystem,
});
});
}
class MockFileSystem extends Mock implements FileSystem {}
class MockDirectory extends Mock implements Directory {}
class MockPlatform extends Mock implements Platform {
@override
Map<String, String> get environment => const <String, String>{};
}