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.
|
|
|
|
|
2019-10-14 22:26:14 +00:00
|
|
|
import 'package:flutter_tools/src/build_info.dart';
|
2019-06-20 15:47:54 +00:00
|
|
|
import 'package:flutter_tools/src/base/io.dart';
|
2019-04-25 21:01:28 +00:00
|
|
|
import 'package:flutter_tools/src/test/flutter_platform.dart';
|
2019-06-28 17:37:27 +00:00
|
|
|
import 'package:meta/meta.dart';
|
2019-04-25 21:01:28 +00:00
|
|
|
|
2020-01-06 19:04:20 +00:00
|
|
|
import 'package:platform/platform.dart';
|
2019-04-25 21:01:28 +00:00
|
|
|
import 'package:mockito/mockito.dart';
|
2019-06-28 17:37:27 +00:00
|
|
|
import 'package:process/process.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() {
|
|
|
|
group('FlutterPlatform', () {
|
|
|
|
testUsingContext('ensureConfiguration throws an error if an explicitObservatoryPort is specified and more than one test file', () async {
|
2019-10-14 22:26:14 +00:00
|
|
|
final FlutterPlatform flutterPlatform = FlutterPlatform(buildMode: BuildMode.debug, shellPath: '/', explicitObservatoryPort: 1234);
|
2019-06-28 17:37:27 +00:00
|
|
|
flutterPlatform.loadChannel('test1.dart', MockSuitePlatform());
|
2020-01-27 22:36:02 +00:00
|
|
|
expect(() => flutterPlatform.loadChannel('test2.dart', MockSuitePlatform()), throwsToolExit());
|
2019-04-25 21:01:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
testUsingContext('ensureConfiguration throws an error if a precompiled entrypoint is specified and more that one test file', () {
|
2019-10-14 22:26:14 +00:00
|
|
|
final FlutterPlatform flutterPlatform = FlutterPlatform(buildMode: BuildMode.debug, shellPath: '/', precompiledDillPath: 'example.dill');
|
2019-06-28 17:37:27 +00:00
|
|
|
flutterPlatform.loadChannel('test1.dart', MockSuitePlatform());
|
2020-01-27 22:36:02 +00:00
|
|
|
expect(() => flutterPlatform.loadChannel('test2.dart', MockSuitePlatform()), throwsToolExit());
|
2019-06-28 17:37:27 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
group('The FLUTTER_TEST environment variable is passed to the test process', () {
|
|
|
|
MockPlatform mockPlatform;
|
|
|
|
MockProcessManager mockProcessManager;
|
|
|
|
FlutterPlatform flutterPlatform;
|
|
|
|
final Map<Type, Generator> contextOverrides = <Type, Generator>{
|
|
|
|
Platform: () => mockPlatform,
|
|
|
|
ProcessManager: () => mockProcessManager,
|
|
|
|
};
|
|
|
|
|
|
|
|
setUp(() {
|
|
|
|
mockPlatform = MockPlatform();
|
|
|
|
mockProcessManager = MockProcessManager();
|
|
|
|
flutterPlatform = TestFlutterPlatform();
|
|
|
|
});
|
|
|
|
|
|
|
|
Future<Map<String, String>> captureEnvironment() async {
|
|
|
|
flutterPlatform.loadChannel('test1.dart', MockSuitePlatform());
|
|
|
|
await untilCalled(mockProcessManager.start(any, environment: anyNamed('environment')));
|
|
|
|
final VerificationResult toVerify = verify(mockProcessManager.start(any, environment: captureAnyNamed('environment')));
|
|
|
|
expect(toVerify.captured, hasLength(1));
|
2020-01-27 22:36:02 +00:00
|
|
|
expect(toVerify.captured.first, isA<Map<String, String>>());
|
2019-11-24 05:54:43 +00:00
|
|
|
return toVerify.captured.first as Map<String, String>;
|
2019-06-28 17:37:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
testUsingContext('as true when not originally set', () async {
|
|
|
|
when(mockPlatform.environment).thenReturn(<String, String>{});
|
|
|
|
final Map<String, String> capturedEnvironment = await captureEnvironment();
|
|
|
|
expect(capturedEnvironment['FLUTTER_TEST'], 'true');
|
|
|
|
}, overrides: contextOverrides);
|
|
|
|
|
|
|
|
testUsingContext('as true when set to true', () async {
|
|
|
|
when(mockPlatform.environment).thenReturn(<String, String>{'FLUTTER_TEST': 'true'});
|
|
|
|
final Map<String, String> capturedEnvironment = await captureEnvironment();
|
|
|
|
expect(capturedEnvironment['FLUTTER_TEST'], 'true');
|
|
|
|
}, overrides: contextOverrides);
|
|
|
|
|
|
|
|
testUsingContext('as false when set to false', () async {
|
|
|
|
when(mockPlatform.environment).thenReturn(<String, String>{'FLUTTER_TEST': 'false'});
|
|
|
|
final Map<String, String> capturedEnvironment = await captureEnvironment();
|
|
|
|
expect(capturedEnvironment['FLUTTER_TEST'], 'false');
|
|
|
|
}, overrides: contextOverrides);
|
|
|
|
|
|
|
|
testUsingContext('unchanged when set', () async {
|
|
|
|
when(mockPlatform.environment).thenReturn(<String, String>{'FLUTTER_TEST': 'neither true nor false'});
|
|
|
|
final Map<String, String> capturedEnvironment = await captureEnvironment();
|
|
|
|
expect(capturedEnvironment['FLUTTER_TEST'], 'neither true nor false');
|
|
|
|
}, overrides: contextOverrides);
|
|
|
|
|
|
|
|
testUsingContext('as null when set to null', () async {
|
|
|
|
when(mockPlatform.environment).thenReturn(<String, String>{'FLUTTER_TEST': null});
|
|
|
|
final Map<String, String> capturedEnvironment = await captureEnvironment();
|
|
|
|
expect(capturedEnvironment['FLUTTER_TEST'], null);
|
|
|
|
}, overrides: contextOverrides);
|
2019-04-25 21:01:28 +00:00
|
|
|
});
|
2019-06-20 15:47:54 +00:00
|
|
|
|
|
|
|
testUsingContext('installHook creates a FlutterPlatform', () {
|
|
|
|
expect(() => installHook(
|
2019-10-14 22:26:14 +00:00
|
|
|
buildMode: BuildMode.debug,
|
2019-06-20 15:47:54 +00:00
|
|
|
shellPath: 'abc',
|
|
|
|
enableObservatory: false,
|
2019-09-24 06:06:09 +00:00
|
|
|
startPaused: true,
|
2020-01-27 22:36:02 +00:00
|
|
|
), throwsAssertionError);
|
2019-06-20 15:47:54 +00:00
|
|
|
|
|
|
|
expect(() => installHook(
|
2019-10-14 22:26:14 +00:00
|
|
|
buildMode: BuildMode.debug,
|
2019-06-20 15:47:54 +00:00
|
|
|
shellPath: 'abc',
|
|
|
|
enableObservatory: false,
|
|
|
|
startPaused: false,
|
2019-09-24 06:06:09 +00:00
|
|
|
observatoryPort: 123,
|
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',
|
|
|
|
enableObservatory: true,
|
|
|
|
machine: true,
|
|
|
|
startPaused: true,
|
|
|
|
disableServiceAuthCodes: true,
|
|
|
|
port: 100,
|
|
|
|
precompiledDillPath: 'def',
|
|
|
|
precompiledDillFiles: expectedPrecompiledDillFiles,
|
2019-10-14 22:26:14 +00:00
|
|
|
buildMode: BuildMode.debug,
|
2019-06-20 15:47:54 +00:00
|
|
|
trackWidgetCreation: true,
|
|
|
|
updateGoldens: true,
|
|
|
|
buildTestAssets: true,
|
|
|
|
observatoryPort: 200,
|
|
|
|
serverType: InternetAddressType.IPv6,
|
|
|
|
icudtlPath: 'ghi',
|
|
|
|
platformPluginRegistration: (FlutterPlatform platform) {
|
|
|
|
capturedPlatform = platform;
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(identical(capturedPlatform, flutterPlatform), equals(true));
|
|
|
|
expect(flutterPlatform.shellPath, equals('abc'));
|
|
|
|
expect(flutterPlatform.enableObservatory, equals(true));
|
|
|
|
expect(flutterPlatform.machine, equals(true));
|
|
|
|
expect(flutterPlatform.startPaused, equals(true));
|
|
|
|
expect(flutterPlatform.disableServiceAuthCodes, equals(true));
|
|
|
|
expect(flutterPlatform.port, equals(100));
|
|
|
|
expect(flutterPlatform.host, InternetAddress.loopbackIPv6);
|
|
|
|
expect(flutterPlatform.explicitObservatoryPort, equals(200));
|
|
|
|
expect(flutterPlatform.precompiledDillPath, equals('def'));
|
|
|
|
expect(flutterPlatform.precompiledDillFiles, expectedPrecompiledDillFiles);
|
2019-10-14 22:26:14 +00:00
|
|
|
expect(flutterPlatform.buildMode, equals(BuildMode.debug));
|
2019-06-20 15:47:54 +00:00
|
|
|
expect(flutterPlatform.trackWidgetCreation, equals(true));
|
|
|
|
expect(flutterPlatform.updateGoldens, equals(true));
|
|
|
|
expect(flutterPlatform.buildTestAssets, equals(true));
|
|
|
|
expect(flutterPlatform.icudtlPath, equals('ghi'));
|
|
|
|
});
|
2019-04-25 21:01:28 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-06-28 17:37:27 +00:00
|
|
|
class MockSuitePlatform extends Mock implements SuitePlatform {}
|
|
|
|
|
|
|
|
class MockProcessManager extends Mock implements ProcessManager {}
|
|
|
|
|
|
|
|
class MockPlatform extends Mock implements Platform {}
|
|
|
|
|
|
|
|
class MockHttpServer extends Mock implements HttpServer {}
|
|
|
|
|
|
|
|
// A FlutterPlatform with enough fields set to load and start a test.
|
|
|
|
//
|
|
|
|
// Uses a mock HttpServer. We don't want to bind random ports in our CI hosts.
|
|
|
|
class TestFlutterPlatform extends FlutterPlatform {
|
|
|
|
TestFlutterPlatform() : super(
|
2019-10-14 22:26:14 +00:00
|
|
|
buildMode: BuildMode.debug,
|
2019-06-28 17:37:27 +00:00
|
|
|
shellPath: '/',
|
|
|
|
precompiledDillPath: 'example.dill',
|
|
|
|
host: InternetAddress.loopbackIPv6,
|
|
|
|
port: 0,
|
|
|
|
updateGoldens: false,
|
|
|
|
startPaused: false,
|
|
|
|
enableObservatory: false,
|
|
|
|
buildTestAssets: false,
|
|
|
|
);
|
|
|
|
|
|
|
|
@override
|
|
|
|
@protected
|
|
|
|
Future<HttpServer> bind(InternetAddress host, int port) async => MockHttpServer();
|
2019-07-13 18:51:44 +00:00
|
|
|
}
|