mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
[flutter_tools] Make AndroidConsole check for next line (#52353)
This commit is contained in:
parent
ac6ea52b37
commit
605debfcff
@ -42,21 +42,29 @@ class AndroidConsole {
|
||||
}
|
||||
|
||||
Future<String> getAvdName() async {
|
||||
if (_queue == null) {
|
||||
return null;
|
||||
}
|
||||
_write('avd name\n');
|
||||
return _readResponse();
|
||||
}
|
||||
|
||||
void destroy() {
|
||||
if (_socket != null) {
|
||||
_socket.destroy();
|
||||
_socket = null;
|
||||
_queue = null;
|
||||
}
|
||||
_socket?.destroy();
|
||||
_socket = null;
|
||||
_queue = null;
|
||||
}
|
||||
|
||||
Future<String> _readResponse() async {
|
||||
if (_queue == null) {
|
||||
return null;
|
||||
}
|
||||
final StringBuffer output = StringBuffer();
|
||||
while (true) {
|
||||
if (!await _queue.hasNext) {
|
||||
destroy();
|
||||
return null;
|
||||
}
|
||||
final String text = await _queue.next;
|
||||
final String trimmedText = text.trim();
|
||||
if (trimmedText == 'OK') {
|
||||
@ -72,6 +80,6 @@ class AndroidConsole {
|
||||
}
|
||||
|
||||
void _write(String text) {
|
||||
_socket.add(ascii.encode(text));
|
||||
_socket?.add(ascii.encode(text));
|
||||
}
|
||||
}
|
||||
|
@ -523,6 +523,8 @@ flutter:
|
||||
const String dummyEmulatorId = 'dummyEmulatorId';
|
||||
final Future<Socket> Function(String host, int port) unresponsiveSocket =
|
||||
(String host, int port) async => MockUnresponsiveAndroidConsoleSocket();
|
||||
final Future<Socket> Function(String host, int port) disconnectingSocket =
|
||||
(String host, int port) async => MockDisconnectingAndroidConsoleSocket();
|
||||
final Future<Socket> Function(String host, int port) workingSocket =
|
||||
(String host, int port) async => MockWorkingAndroidConsoleSocket(dummyEmulatorId);
|
||||
String hardware;
|
||||
@ -597,6 +599,14 @@ flutter:
|
||||
AndroidConsoleSocketFactory: () => unresponsiveSocket,
|
||||
ProcessManager: () => mockProcessManager,
|
||||
});
|
||||
|
||||
testUsingContext('returns null on early disconnect', () async {
|
||||
final AndroidDevice device = AndroidDevice('emulator-5555');
|
||||
expect(await device.emulatorId, isNull);
|
||||
}, overrides: <Type, Generator>{
|
||||
AndroidConsoleSocketFactory: () => disconnectingSocket,
|
||||
ProcessManager: () => mockProcessManager,
|
||||
});
|
||||
});
|
||||
|
||||
group('portForwarder', () {
|
||||
@ -980,6 +990,26 @@ class MockUnresponsiveAndroidConsoleSocket extends Mock implements Socket {
|
||||
void add(List<int> data) {}
|
||||
}
|
||||
|
||||
/// An Android console socket that drops all input and returns no output.
|
||||
class MockDisconnectingAndroidConsoleSocket extends Mock implements Socket {
|
||||
MockDisconnectingAndroidConsoleSocket() {
|
||||
_controller.add('Android Console: Welcome!\n');
|
||||
// Include OK in the same packet here. In the response to "avd name"
|
||||
// it's sent alone to ensure both are handled.
|
||||
_controller.add('Android Console: Some intro text\nOK\n');
|
||||
}
|
||||
|
||||
final StreamController<String> _controller = StreamController<String>();
|
||||
|
||||
@override
|
||||
Stream<E> asyncMap<E>(FutureOr<E> convert(Uint8List event)) => _controller.stream as Stream<E>;
|
||||
|
||||
@override
|
||||
void add(List<int> data) {
|
||||
_controller.close();
|
||||
}
|
||||
}
|
||||
|
||||
class AndroidPackageTest extends ApplicationPackage {
|
||||
AndroidPackageTest() : super(id: 'app-id');
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user