2019-11-27 23:04:02 +00:00
|
|
|
// Copyright 2014 The Flutter Authors. All rights reserved.
|
2019-04-25 21:01:28 +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
|
|
|
|
|
2020-06-23 18:14:38 +00:00
|
|
|
import 'package:file/memory.dart';
|
|
|
|
import 'package:flutter_tools/src/base/file_system.dart';
|
2019-06-20 15:47:54 +00:00
|
|
|
import 'package:flutter_tools/src/base/io.dart';
|
2020-05-06 15:15:39 +00:00
|
|
|
import 'package:flutter_tools/src/build_info.dart';
|
2021-02-03 03:31:03 +00:00
|
|
|
import 'package:flutter_tools/src/device.dart';
|
2019-04-25 21:01:28 +00:00
|
|
|
import 'package:flutter_tools/src/test/flutter_platform.dart';
|
2021-03-12 00:05:05 +00:00
|
|
|
import 'package:test/fake.dart';
|
2019-11-14 17:31:36 +00:00
|
|
|
import 'package:test_core/backend.dart'; // ignore: deprecated_member_use
|
2019-04-25 21:01:28 +00:00
|
|
|
|
2019-07-13 18:51:44 +00:00
|
|
|
import '../src/common.dart';
|
|
|
|
import '../src/context.dart';
|
2019-04-25 21:01:28 +00:00
|
|
|
|
|
|
|
void main() {
|
2020-06-23 18:14:38 +00:00
|
|
|
FileSystem fileSystem;
|
|
|
|
|
|
|
|
setUp(() {
|
|
|
|
fileSystem = MemoryFileSystem.test();
|
2020-11-11 21:50:41 +00:00
|
|
|
fileSystem
|
|
|
|
.file('.dart_tool/package_config.json')
|
|
|
|
..createSync(recursive: true)
|
|
|
|
..writeAsStringSync('{"configVersion":2,"packages":[]}');
|
2020-06-23 18:14:38 +00:00
|
|
|
});
|
|
|
|
|
2019-04-25 21:01:28 +00:00
|
|
|
group('FlutterPlatform', () {
|
2020-04-27 21:47:43 +00:00
|
|
|
testUsingContext('ensureConfiguration throws an error if an '
|
|
|
|
'explicitObservatoryPort is specified and more than one test file', () async {
|
|
|
|
final FlutterPlatform flutterPlatform = FlutterPlatform(
|
|
|
|
shellPath: '/',
|
2021-02-03 03:31:03 +00:00
|
|
|
debuggingOptions: DebuggingOptions.enabled(
|
|
|
|
BuildInfo.debug,
|
|
|
|
hostVmServicePort: 1234,
|
|
|
|
),
|
2021-02-17 18:06:04 +00:00
|
|
|
enableObservatory: false,
|
2020-04-27 21:47:43 +00:00
|
|
|
);
|
2021-03-12 00:05:05 +00:00
|
|
|
flutterPlatform.loadChannel('test1.dart', FakeSuitePlatform());
|
2020-04-27 21:47:43 +00:00
|
|
|
|
2021-03-12 00:05:05 +00:00
|
|
|
expect(() => flutterPlatform.loadChannel('test2.dart', FakeSuitePlatform()), throwsToolExit());
|
2020-06-23 18:14:38 +00:00
|
|
|
}, overrides: <Type, Generator>{
|
|
|
|
FileSystem: () => fileSystem,
|
|
|
|
ProcessManager: () => FakeProcessManager.any(),
|
2019-04-25 21:01:28 +00:00
|
|
|
});
|
|
|
|
|
2020-04-27 21:47:43 +00:00
|
|
|
testUsingContext('ensureConfiguration throws an error if a precompiled '
|
|
|
|
'entrypoint is specified and more that one test file', () {
|
|
|
|
final FlutterPlatform flutterPlatform = FlutterPlatform(
|
2021-02-03 03:31:03 +00:00
|
|
|
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
|
2020-04-27 21:47:43 +00:00
|
|
|
shellPath: '/',
|
|
|
|
precompiledDillPath: 'example.dill',
|
2021-02-17 18:06:04 +00:00
|
|
|
enableObservatory: false,
|
2020-04-27 21:47:43 +00:00
|
|
|
);
|
2021-03-12 00:05:05 +00:00
|
|
|
flutterPlatform.loadChannel('test1.dart', FakeSuitePlatform());
|
2020-04-27 21:47:43 +00:00
|
|
|
|
2021-03-12 00:05:05 +00:00
|
|
|
expect(() => flutterPlatform.loadChannel('test2.dart', FakeSuitePlatform()), throwsToolExit());
|
2020-06-23 18:14:38 +00:00
|
|
|
}, overrides: <Type, Generator>{
|
|
|
|
FileSystem: () => fileSystem,
|
|
|
|
ProcessManager: () => FakeProcessManager.any(),
|
2019-06-28 17:37:27 +00:00
|
|
|
});
|
|
|
|
|
2019-06-20 15:47:54 +00:00
|
|
|
testUsingContext('installHook creates a FlutterPlatform', () {
|
|
|
|
expect(() => installHook(
|
|
|
|
shellPath: 'abc',
|
2021-02-03 03:31:03 +00:00
|
|
|
debuggingOptions: DebuggingOptions.enabled(
|
|
|
|
BuildInfo.debug,
|
|
|
|
startPaused: true,
|
|
|
|
),
|
2019-06-20 15:47:54 +00:00
|
|
|
enableObservatory: false,
|
2020-01-27 22:36:02 +00:00
|
|
|
), throwsAssertionError);
|
2019-06-20 15:47:54 +00:00
|
|
|
|
|
|
|
expect(() => installHook(
|
|
|
|
shellPath: 'abc',
|
2021-02-03 03:31:03 +00:00
|
|
|
debuggingOptions: DebuggingOptions.enabled(
|
|
|
|
BuildInfo.debug,
|
|
|
|
startPaused: true,
|
|
|
|
hostVmServicePort: 123,
|
|
|
|
),
|
2019-06-20 15:47:54 +00:00
|
|
|
enableObservatory: false,
|
2020-01-27 22:36:02 +00:00
|
|
|
), throwsAssertionError);
|
2019-06-20 15:47:54 +00:00
|
|
|
|
|
|
|
FlutterPlatform capturedPlatform;
|
|
|
|
final Map<String, String> expectedPrecompiledDillFiles = <String, String>{'Key': 'Value'};
|
|
|
|
final FlutterPlatform flutterPlatform = installHook(
|
|
|
|
shellPath: 'abc',
|
2021-02-03 03:31:03 +00:00
|
|
|
debuggingOptions: DebuggingOptions.enabled(
|
|
|
|
BuildInfo.debug,
|
|
|
|
startPaused: true,
|
|
|
|
disableServiceAuthCodes: true,
|
|
|
|
hostVmServicePort: 200,
|
|
|
|
),
|
2019-06-20 15:47:54 +00:00
|
|
|
enableObservatory: true,
|
|
|
|
machine: true,
|
|
|
|
precompiledDillPath: 'def',
|
|
|
|
precompiledDillFiles: expectedPrecompiledDillFiles,
|
|
|
|
updateGoldens: true,
|
|
|
|
buildTestAssets: true,
|
|
|
|
serverType: InternetAddressType.IPv6,
|
|
|
|
icudtlPath: 'ghi',
|
|
|
|
platformPluginRegistration: (FlutterPlatform platform) {
|
|
|
|
capturedPlatform = platform;
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(identical(capturedPlatform, flutterPlatform), equals(true));
|
|
|
|
expect(flutterPlatform.shellPath, equals('abc'));
|
2021-02-03 03:31:03 +00:00
|
|
|
expect(flutterPlatform.debuggingOptions.buildInfo, equals(BuildInfo.debug));
|
|
|
|
expect(flutterPlatform.debuggingOptions.startPaused, equals(true));
|
|
|
|
expect(flutterPlatform.debuggingOptions.disableServiceAuthCodes, equals(true));
|
|
|
|
expect(flutterPlatform.debuggingOptions.hostVmServicePort, equals(200));
|
2019-06-20 15:47:54 +00:00
|
|
|
expect(flutterPlatform.enableObservatory, equals(true));
|
|
|
|
expect(flutterPlatform.machine, equals(true));
|
|
|
|
expect(flutterPlatform.host, InternetAddress.loopbackIPv6);
|
|
|
|
expect(flutterPlatform.precompiledDillPath, equals('def'));
|
|
|
|
expect(flutterPlatform.precompiledDillFiles, expectedPrecompiledDillFiles);
|
|
|
|
expect(flutterPlatform.updateGoldens, equals(true));
|
|
|
|
expect(flutterPlatform.buildTestAssets, equals(true));
|
|
|
|
expect(flutterPlatform.icudtlPath, equals('ghi'));
|
|
|
|
});
|
2019-04-25 21:01:28 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-03-12 00:05:05 +00:00
|
|
|
class FakeSuitePlatform extends Fake implements SuitePlatform {}
|
2019-06-28 17:37:27 +00:00
|
|
|
|
|
|
|
// A FlutterPlatform with enough fields set to load and start a test.
|
|
|
|
class TestFlutterPlatform extends FlutterPlatform {
|
2021-02-17 18:06:04 +00:00
|
|
|
TestFlutterPlatform() : super(
|
2019-06-28 17:37:27 +00:00
|
|
|
shellPath: '/',
|
2021-02-03 03:31:03 +00:00
|
|
|
debuggingOptions: DebuggingOptions.enabled(
|
2021-02-17 18:06:04 +00:00
|
|
|
const BuildInfo(
|
|
|
|
BuildMode.debug,
|
|
|
|
'',
|
|
|
|
treeShakeIcons: false,
|
|
|
|
),
|
2021-02-03 03:31:03 +00:00
|
|
|
),
|
2020-09-30 17:14:13 +00:00
|
|
|
);
|
2019-07-13 18:51:44 +00:00
|
|
|
}
|