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 {
@override
DevicePortForwarder get portForwarder => _portForwarder ??= IOSDevicePortForwarder(
processManager: globals.processManager,
logger: globals.logger,
logger: _logger,
dyLdLibEntry: globals.cache.dyLdLibEntry,
id: id,
iproxyPath: _iproxyPath,
......
......@@ -30,6 +30,7 @@ import 'package:flutter_tools/src/globals.dart' as globals;
import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/fakes.dart';
import '../../src/mocks.dart';
......@@ -54,7 +55,7 @@ void main() {
const int devicePort = 499;
const int hostPort = 42;
MockDeviceLogReader mockLogReader;
FakeDeviceLogReader mockLogReader;
MockPortForwarder portForwarder;
MockAndroidDevice device;
MockProcessManager mockProcessManager;
......@@ -63,7 +64,7 @@ void main() {
setUp(() {
mockProcessManager = MockProcessManager();
mockLogReader = MockDeviceLogReader();
mockLogReader = FakeDeviceLogReader();
portForwarder = MockPortForwarder();
device = MockAndroidDevice();
vmServiceDoneCompleter = Completer<void>();
......@@ -374,7 +375,7 @@ void main() {
testUsingContext('selects specified target', () async {
const int devicePort = 499;
const int hostPort = 42;
final MockDeviceLogReader mockLogReader = MockDeviceLogReader();
final FakeDeviceLogReader mockLogReader = FakeDeviceLogReader();
final MockPortForwarder portForwarder = MockPortForwarder();
final MockAndroidDevice device = MockAndroidDevice();
final MockHotRunner mockHotRunner = MockHotRunner();
......@@ -434,7 +435,7 @@ void main() {
testUsingContext('fallbacks to protocol observatory if MDNS failed on iOS', () async {
const int devicePort = 499;
const int hostPort = 42;
final MockDeviceLogReader mockLogReader = MockDeviceLogReader();
final FakeDeviceLogReader mockLogReader = FakeDeviceLogReader();
final MockPortForwarder portForwarder = MockPortForwarder();
final MockIOSDevice device = MockIOSDevice();
final MockHotRunner mockHotRunner = MockHotRunner();
......
......@@ -21,6 +21,7 @@ import 'package:webdriver/sync_io.dart' as sync_io;
import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/fakes.dart';
import '../../src/mocks.dart';
void main() {
......@@ -351,7 +352,7 @@ void main() {
final Device mockDevice = MockDevice();
testDeviceManager.addDevice(mockDevice);
final MockDeviceLogReader mockDeviceLogReader = MockDeviceLogReader();
final FakeDeviceLogReader mockDeviceLogReader = FakeDeviceLogReader();
when(mockDevice.getLogReader()).thenReturn(mockDeviceLogReader);
final MockLaunchResult mockLaunchResult = MockLaunchResult();
when(mockLaunchResult.started).thenReturn(true);
......@@ -481,7 +482,7 @@ void main() {
final Device mockDevice = MockDevice();
testDeviceManager.addDevice(mockDevice);
final MockDeviceLogReader mockDeviceLogReader = MockDeviceLogReader();
final FakeDeviceLogReader mockDeviceLogReader = FakeDeviceLogReader();
when(mockDevice.getLogReader()).thenReturn(mockDeviceLogReader);
final MockLaunchResult mockLaunchResult = MockLaunchResult();
when(mockLaunchResult.started).thenReturn(true);
......
......@@ -32,6 +32,7 @@ import 'package:mockito/mockito.dart';
import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/fakes.dart';
import '../../src/mocks.dart';
import '../../src/testbed.dart';
......@@ -279,7 +280,7 @@ void main() {
applyMocksToCommand(command);
final MockDevice mockDevice = MockDevice(TargetPlatform.ios);
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.sdkNameAndVersion).thenAnswer((Invocation invocation) => Future<String>.value('iOS 13'));
// App fails to start because we're only interested in usage
......@@ -633,7 +634,7 @@ class FakeDevice extends Fake implements Device {
@override
DeviceLogReader getLogReader({ ApplicationPackage app }) {
return MockDeviceLogReader();
return FakeDeviceLogReader();
}
@override
......
......@@ -10,11 +10,11 @@ import 'package:quiver/testing/async.dart';
import '../src/common.dart';
import '../src/context.dart';
import '../src/mocks.dart';
import '../src/fakes.dart';
void main() {
group('service_protocol discovery', () {
MockDeviceLogReader logReader;
FakeDeviceLogReader logReader;
ProtocolDiscovery discoverer;
/// Performs test set-up functionality that must be performed as part of
......@@ -37,7 +37,7 @@ void main() {
int devicePort,
Duration throttleDuration = const Duration(milliseconds: 200),
}) {
logReader = MockDeviceLogReader();
logReader = FakeDeviceLogReader();
discoverer = ProtocolDiscovery.observatory(
logReader,
ipv6: false,
......@@ -261,7 +261,7 @@ void main() {
group('port forwarding', () {
testUsingContext('default port', () async {
final MockDeviceLogReader logReader = MockDeviceLogReader();
final FakeDeviceLogReader logReader = FakeDeviceLogReader();
final ProtocolDiscovery discoverer = ProtocolDiscovery.observatory(
logReader,
portForwarder: MockPortForwarder(99),
......@@ -282,7 +282,7 @@ void main() {
});
testUsingContext('specified port', () async {
final MockDeviceLogReader logReader = MockDeviceLogReader();
final FakeDeviceLogReader logReader = FakeDeviceLogReader();
final ProtocolDiscovery discoverer = ProtocolDiscovery.observatory(
logReader,
portForwarder: MockPortForwarder(99),
......@@ -303,7 +303,7 @@ void main() {
});
testUsingContext('specified port zero', () async {
final MockDeviceLogReader logReader = MockDeviceLogReader();
final FakeDeviceLogReader logReader = FakeDeviceLogReader();
final ProtocolDiscovery discoverer = ProtocolDiscovery.observatory(
logReader,
portForwarder: MockPortForwarder(99),
......@@ -324,7 +324,7 @@ void main() {
});
testUsingContext('ipv6', () async {
final MockDeviceLogReader logReader = MockDeviceLogReader();
final FakeDeviceLogReader logReader = FakeDeviceLogReader();
final ProtocolDiscovery discoverer = ProtocolDiscovery.observatory(
logReader,
portForwarder: MockPortForwarder(99),
......@@ -345,7 +345,7 @@ void main() {
});
testUsingContext('ipv6 with Ascii Escape code', () async {
final MockDeviceLogReader logReader = MockDeviceLogReader();
final FakeDeviceLogReader logReader = FakeDeviceLogReader();
final ProtocolDiscovery discoverer = ProtocolDiscovery.observatory(
logReader,
portForwarder: MockPortForwarder(99),
......
......@@ -82,39 +82,14 @@ class FakeCommand {
/// resolves.
final Completer<void> completer;
static bool _listEquals<T>(List<T> a, List<T> b) {
if (a == null) {
return b == null;
}
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;
void _matches(List<String> command, String workingDirectory, Map<String, String> environment) {
expect(command, equals(this.command));
if (this.workingDirectory != null) {
expect(this.workingDirectory, workingDirectory);
}
if (this.environment != null) {
if (environment == null) {
return false;
}
for (final String key in environment.keys) {
if (environment[key] != this.environment[key]) {
return false;
}
}
expect(this.environment, environment);
}
return true;
}
}
......@@ -322,12 +297,7 @@ class _SequenceProcessManager extends FakeProcessManager {
reason: 'ProcessManager was told to execute $command (in $workingDirectory) '
'but the FakeProcessManager.list expected no more processes.'
);
expect(_commands.first._matches(command, workingDirectory, environment), isTrue,
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})}.'
);
_commands.first._matches(command, workingDirectory, environment);
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 {
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) {
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