Unverified Commit 73b6702d authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] refactor iOS tests for Device.startApp into new file (#52854)

parent 2a93afa7
...@@ -383,7 +383,7 @@ class IOSDevice extends Device { ...@@ -383,7 +383,7 @@ class IOSDevice extends Device {
@override @override
DevicePortForwarder get portForwarder => _portForwarder ??= IOSDevicePortForwarder( DevicePortForwarder get portForwarder => _portForwarder ??= IOSDevicePortForwarder(
processManager: globals.processManager, processManager: globals.processManager,
logger: globals.logger, logger: _logger,
dyLdLibEntry: globals.cache.dyLdLibEntry, dyLdLibEntry: globals.cache.dyLdLibEntry,
id: id, id: id,
iproxyPath: _iproxyPath, iproxyPath: _iproxyPath,
......
...@@ -30,6 +30,7 @@ import 'package:flutter_tools/src/globals.dart' as globals; ...@@ -30,6 +30,7 @@ import 'package:flutter_tools/src/globals.dart' as globals;
import '../../src/common.dart'; import '../../src/common.dart';
import '../../src/context.dart'; import '../../src/context.dart';
import '../../src/fakes.dart';
import '../../src/mocks.dart'; import '../../src/mocks.dart';
...@@ -54,7 +55,7 @@ void main() { ...@@ -54,7 +55,7 @@ void main() {
const int devicePort = 499; const int devicePort = 499;
const int hostPort = 42; const int hostPort = 42;
MockDeviceLogReader mockLogReader; FakeDeviceLogReader mockLogReader;
MockPortForwarder portForwarder; MockPortForwarder portForwarder;
MockAndroidDevice device; MockAndroidDevice device;
MockProcessManager mockProcessManager; MockProcessManager mockProcessManager;
...@@ -63,7 +64,7 @@ void main() { ...@@ -63,7 +64,7 @@ void main() {
setUp(() { setUp(() {
mockProcessManager = MockProcessManager(); mockProcessManager = MockProcessManager();
mockLogReader = MockDeviceLogReader(); mockLogReader = FakeDeviceLogReader();
portForwarder = MockPortForwarder(); portForwarder = MockPortForwarder();
device = MockAndroidDevice(); device = MockAndroidDevice();
vmServiceDoneCompleter = Completer<void>(); vmServiceDoneCompleter = Completer<void>();
...@@ -374,7 +375,7 @@ void main() { ...@@ -374,7 +375,7 @@ void main() {
testUsingContext('selects specified target', () async { testUsingContext('selects specified target', () async {
const int devicePort = 499; const int devicePort = 499;
const int hostPort = 42; const int hostPort = 42;
final MockDeviceLogReader mockLogReader = MockDeviceLogReader(); final FakeDeviceLogReader mockLogReader = FakeDeviceLogReader();
final MockPortForwarder portForwarder = MockPortForwarder(); final MockPortForwarder portForwarder = MockPortForwarder();
final MockAndroidDevice device = MockAndroidDevice(); final MockAndroidDevice device = MockAndroidDevice();
final MockHotRunner mockHotRunner = MockHotRunner(); final MockHotRunner mockHotRunner = MockHotRunner();
...@@ -434,7 +435,7 @@ void main() { ...@@ -434,7 +435,7 @@ void main() {
testUsingContext('fallbacks to protocol observatory if MDNS failed on iOS', () async { testUsingContext('fallbacks to protocol observatory if MDNS failed on iOS', () async {
const int devicePort = 499; const int devicePort = 499;
const int hostPort = 42; const int hostPort = 42;
final MockDeviceLogReader mockLogReader = MockDeviceLogReader(); final FakeDeviceLogReader mockLogReader = FakeDeviceLogReader();
final MockPortForwarder portForwarder = MockPortForwarder(); final MockPortForwarder portForwarder = MockPortForwarder();
final MockIOSDevice device = MockIOSDevice(); final MockIOSDevice device = MockIOSDevice();
final MockHotRunner mockHotRunner = MockHotRunner(); final MockHotRunner mockHotRunner = MockHotRunner();
......
...@@ -21,6 +21,7 @@ import 'package:webdriver/sync_io.dart' as sync_io; ...@@ -21,6 +21,7 @@ import 'package:webdriver/sync_io.dart' as sync_io;
import '../../src/common.dart'; import '../../src/common.dart';
import '../../src/context.dart'; import '../../src/context.dart';
import '../../src/fakes.dart';
import '../../src/mocks.dart'; import '../../src/mocks.dart';
void main() { void main() {
...@@ -351,7 +352,7 @@ void main() { ...@@ -351,7 +352,7 @@ void main() {
final Device mockDevice = MockDevice(); final Device mockDevice = MockDevice();
testDeviceManager.addDevice(mockDevice); testDeviceManager.addDevice(mockDevice);
final MockDeviceLogReader mockDeviceLogReader = MockDeviceLogReader(); final FakeDeviceLogReader mockDeviceLogReader = FakeDeviceLogReader();
when(mockDevice.getLogReader()).thenReturn(mockDeviceLogReader); when(mockDevice.getLogReader()).thenReturn(mockDeviceLogReader);
final MockLaunchResult mockLaunchResult = MockLaunchResult(); final MockLaunchResult mockLaunchResult = MockLaunchResult();
when(mockLaunchResult.started).thenReturn(true); when(mockLaunchResult.started).thenReturn(true);
...@@ -481,7 +482,7 @@ void main() { ...@@ -481,7 +482,7 @@ void main() {
final Device mockDevice = MockDevice(); final Device mockDevice = MockDevice();
testDeviceManager.addDevice(mockDevice); testDeviceManager.addDevice(mockDevice);
final MockDeviceLogReader mockDeviceLogReader = MockDeviceLogReader(); final FakeDeviceLogReader mockDeviceLogReader = FakeDeviceLogReader();
when(mockDevice.getLogReader()).thenReturn(mockDeviceLogReader); when(mockDevice.getLogReader()).thenReturn(mockDeviceLogReader);
final MockLaunchResult mockLaunchResult = MockLaunchResult(); final MockLaunchResult mockLaunchResult = MockLaunchResult();
when(mockLaunchResult.started).thenReturn(true); when(mockLaunchResult.started).thenReturn(true);
......
...@@ -32,6 +32,7 @@ import 'package:mockito/mockito.dart'; ...@@ -32,6 +32,7 @@ import 'package:mockito/mockito.dart';
import '../../src/common.dart'; import '../../src/common.dart';
import '../../src/context.dart'; import '../../src/context.dart';
import '../../src/fakes.dart';
import '../../src/mocks.dart'; import '../../src/mocks.dart';
import '../../src/testbed.dart'; import '../../src/testbed.dart';
...@@ -279,7 +280,7 @@ void main() { ...@@ -279,7 +280,7 @@ void main() {
applyMocksToCommand(command); applyMocksToCommand(command);
final MockDevice mockDevice = MockDevice(TargetPlatform.ios); final MockDevice mockDevice = MockDevice(TargetPlatform.ios);
when(mockDevice.isLocalEmulator).thenAnswer((Invocation invocation) => Future<bool>.value(false)); when(mockDevice.isLocalEmulator).thenAnswer((Invocation invocation) => Future<bool>.value(false));
when(mockDevice.getLogReader(app: anyNamed('app'))).thenReturn(MockDeviceLogReader()); when(mockDevice.getLogReader(app: anyNamed('app'))).thenReturn(FakeDeviceLogReader());
when(mockDevice.supportsFastStart).thenReturn(true); when(mockDevice.supportsFastStart).thenReturn(true);
when(mockDevice.sdkNameAndVersion).thenAnswer((Invocation invocation) => Future<String>.value('iOS 13')); when(mockDevice.sdkNameAndVersion).thenAnswer((Invocation invocation) => Future<String>.value('iOS 13'));
// App fails to start because we're only interested in usage // App fails to start because we're only interested in usage
...@@ -633,7 +634,7 @@ class FakeDevice extends Fake implements Device { ...@@ -633,7 +634,7 @@ class FakeDevice extends Fake implements Device {
@override @override
DeviceLogReader getLogReader({ ApplicationPackage app }) { DeviceLogReader getLogReader({ ApplicationPackage app }) {
return MockDeviceLogReader(); return FakeDeviceLogReader();
} }
@override @override
......
...@@ -10,11 +10,11 @@ import 'package:quiver/testing/async.dart'; ...@@ -10,11 +10,11 @@ import 'package:quiver/testing/async.dart';
import '../src/common.dart'; import '../src/common.dart';
import '../src/context.dart'; import '../src/context.dart';
import '../src/mocks.dart'; import '../src/fakes.dart';
void main() { void main() {
group('service_protocol discovery', () { group('service_protocol discovery', () {
MockDeviceLogReader logReader; FakeDeviceLogReader logReader;
ProtocolDiscovery discoverer; ProtocolDiscovery discoverer;
/// Performs test set-up functionality that must be performed as part of /// Performs test set-up functionality that must be performed as part of
...@@ -37,7 +37,7 @@ void main() { ...@@ -37,7 +37,7 @@ void main() {
int devicePort, int devicePort,
Duration throttleDuration = const Duration(milliseconds: 200), Duration throttleDuration = const Duration(milliseconds: 200),
}) { }) {
logReader = MockDeviceLogReader(); logReader = FakeDeviceLogReader();
discoverer = ProtocolDiscovery.observatory( discoverer = ProtocolDiscovery.observatory(
logReader, logReader,
ipv6: false, ipv6: false,
...@@ -261,7 +261,7 @@ void main() { ...@@ -261,7 +261,7 @@ void main() {
group('port forwarding', () { group('port forwarding', () {
testUsingContext('default port', () async { testUsingContext('default port', () async {
final MockDeviceLogReader logReader = MockDeviceLogReader(); final FakeDeviceLogReader logReader = FakeDeviceLogReader();
final ProtocolDiscovery discoverer = ProtocolDiscovery.observatory( final ProtocolDiscovery discoverer = ProtocolDiscovery.observatory(
logReader, logReader,
portForwarder: MockPortForwarder(99), portForwarder: MockPortForwarder(99),
...@@ -282,7 +282,7 @@ void main() { ...@@ -282,7 +282,7 @@ void main() {
}); });
testUsingContext('specified port', () async { testUsingContext('specified port', () async {
final MockDeviceLogReader logReader = MockDeviceLogReader(); final FakeDeviceLogReader logReader = FakeDeviceLogReader();
final ProtocolDiscovery discoverer = ProtocolDiscovery.observatory( final ProtocolDiscovery discoverer = ProtocolDiscovery.observatory(
logReader, logReader,
portForwarder: MockPortForwarder(99), portForwarder: MockPortForwarder(99),
...@@ -303,7 +303,7 @@ void main() { ...@@ -303,7 +303,7 @@ void main() {
}); });
testUsingContext('specified port zero', () async { testUsingContext('specified port zero', () async {
final MockDeviceLogReader logReader = MockDeviceLogReader(); final FakeDeviceLogReader logReader = FakeDeviceLogReader();
final ProtocolDiscovery discoverer = ProtocolDiscovery.observatory( final ProtocolDiscovery discoverer = ProtocolDiscovery.observatory(
logReader, logReader,
portForwarder: MockPortForwarder(99), portForwarder: MockPortForwarder(99),
...@@ -324,7 +324,7 @@ void main() { ...@@ -324,7 +324,7 @@ void main() {
}); });
testUsingContext('ipv6', () async { testUsingContext('ipv6', () async {
final MockDeviceLogReader logReader = MockDeviceLogReader(); final FakeDeviceLogReader logReader = FakeDeviceLogReader();
final ProtocolDiscovery discoverer = ProtocolDiscovery.observatory( final ProtocolDiscovery discoverer = ProtocolDiscovery.observatory(
logReader, logReader,
portForwarder: MockPortForwarder(99), portForwarder: MockPortForwarder(99),
...@@ -345,7 +345,7 @@ void main() { ...@@ -345,7 +345,7 @@ void main() {
}); });
testUsingContext('ipv6 with Ascii Escape code', () async { testUsingContext('ipv6 with Ascii Escape code', () async {
final MockDeviceLogReader logReader = MockDeviceLogReader(); final FakeDeviceLogReader logReader = FakeDeviceLogReader();
final ProtocolDiscovery discoverer = ProtocolDiscovery.observatory( final ProtocolDiscovery discoverer = ProtocolDiscovery.observatory(
logReader, logReader,
portForwarder: MockPortForwarder(99), portForwarder: MockPortForwarder(99),
......
...@@ -82,40 +82,15 @@ class FakeCommand { ...@@ -82,40 +82,15 @@ class FakeCommand {
/// resolves. /// resolves.
final Completer<void> completer; final Completer<void> completer;
static bool _listEquals<T>(List<T> a, List<T> b) { void _matches(List<String> command, String workingDirectory, Map<String, String> environment) {
if (a == null) { expect(command, equals(this.command));
return b == null; if (this.workingDirectory != null) {
} expect(this.workingDirectory, workingDirectory);
if (b == null || a.length != b.length) {
return false;
}
for (int index = 0; index < a.length; index += 1) {
if (a[index] != b[index]) {
return false;
}
}
return true;
}
bool _matches(List<String> command, String workingDirectory, Map<String, String> environment) {
if (!_listEquals(command, this.command)) {
return false;
}
if (this.workingDirectory != null && workingDirectory != this.workingDirectory) {
return false;
} }
if (this.environment != null) { if (this.environment != null) {
if (environment == null) { expect(this.environment, environment);
return false;
}
for (final String key in environment.keys) {
if (environment[key] != this.environment[key]) {
return false;
}
} }
} }
return true;
}
} }
class _FakeProcess implements Process { class _FakeProcess implements Process {
...@@ -322,12 +297,7 @@ class _SequenceProcessManager extends FakeProcessManager { ...@@ -322,12 +297,7 @@ class _SequenceProcessManager extends FakeProcessManager {
reason: 'ProcessManager was told to execute $command (in $workingDirectory) ' reason: 'ProcessManager was told to execute $command (in $workingDirectory) '
'but the FakeProcessManager.list expected no more processes.' 'but the FakeProcessManager.list expected no more processes.'
); );
expect(_commands.first._matches(command, workingDirectory, environment), isTrue, _commands.first._matches(command, workingDirectory, environment);
reason: 'ProcessManager was told to execute $command '
'(in $workingDirectory, with environment $environment) '
'but the next process that was expected was ${_commands.first.command} '
'(in ${_commands.first.workingDirectory}, with environment ${_commands.first.environment})}.'
);
return _commands.removeAt(0); return _commands.removeAt(0);
} }
......
// Copyright 2014 The Flutter 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 'dart:async';
import 'package:flutter_tools/src/device.dart';
/// A fake implementation of the [DeviceLogReader].
class FakeDeviceLogReader extends DeviceLogReader {
@override
String get name => 'FakeLogReader';
StreamController<String> _cachedLinesController;
final List<String> _lineQueue = <String>[];
StreamController<String> get _linesController {
_cachedLinesController ??= StreamController<String>
.broadcast(onListen: () {
_lineQueue.forEach(_linesController.add);
_lineQueue.clear();
});
return _cachedLinesController;
}
@override
Stream<String> get logLines => _linesController.stream;
void addLine(String line) {
if (_linesController.hasListener) {
_linesController.add(line);
} else {
_lineQueue.add(line);
}
}
@override
Future<void> dispose() async {
_lineQueue.clear();
await _linesController.close();
}
}
...@@ -612,40 +612,6 @@ class MockIOSSimulator extends Mock implements IOSSimulator { ...@@ -612,40 +612,6 @@ class MockIOSSimulator extends Mock implements IOSSimulator {
bool isSupportedForProject(FlutterProject flutterProject) => true; bool isSupportedForProject(FlutterProject flutterProject) => true;
} }
class MockDeviceLogReader extends DeviceLogReader {
@override
String get name => 'MockLogReader';
StreamController<String> _cachedLinesController;
final List<String> _lineQueue = <String>[];
StreamController<String> get _linesController {
_cachedLinesController ??= StreamController<String>
.broadcast(onListen: () {
_lineQueue.forEach(_linesController.add);
_lineQueue.clear();
});
return _cachedLinesController;
}
@override
Stream<String> get logLines => _linesController.stream;
void addLine(String line) {
if (_linesController.hasListener) {
_linesController.add(line);
} else {
_lineQueue.add(line);
}
}
@override
Future<void> dispose() async {
_lineQueue.clear();
await _linesController.close();
}
}
void applyMocksToCommand(FlutterCommand command) { void applyMocksToCommand(FlutterCommand command) {
command.applicationPackages = MockApplicationPackageStore(); command.applicationPackages = MockApplicationPackageStore();
} }
......
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