Simplify logging code in flutter_driver (#45945)
* Simplify logging code in flutter_driver
It appears nobody is benefitting from this logic, so we may as well not pay the cost.
* Make all of the driver interface public.
This is the second attempt at this; it should be better than before because the Logger interface, which conflicted in various places, no longer exists.
See #45733 for original attempt.
This reverts commit 0ce9206ef4 (PR #45924).
This commit is contained in:
@@ -21,21 +21,23 @@ const Duration _kTestTimeout = Duration(milliseconds: 1234);
|
||||
const String _kSerializedTestTimeout = '1234';
|
||||
|
||||
void main() {
|
||||
final List<String> log = <String>[];
|
||||
driverLog = (String source, String message) {
|
||||
log.add('$source: $message');
|
||||
};
|
||||
|
||||
group('FlutterDriver.connect', () {
|
||||
List<LogRecord> log;
|
||||
StreamSubscription<LogRecord> logSub;
|
||||
MockVMServiceClient mockClient;
|
||||
MockVM mockVM;
|
||||
MockIsolate mockIsolate;
|
||||
MockPeer mockPeer;
|
||||
|
||||
void expectLogContains(String message) {
|
||||
expect(log.map<String>((LogRecord r) => '$r'), anyElement(contains(message)));
|
||||
expect(log, anyElement(contains(message)));
|
||||
}
|
||||
|
||||
setUp(() {
|
||||
log = <LogRecord>[];
|
||||
logSub = flutterDriverLog.listen(log.add);
|
||||
log.clear();
|
||||
mockClient = MockVMServiceClient();
|
||||
mockVM = MockVM();
|
||||
mockIsolate = MockIsolate();
|
||||
@@ -53,7 +55,6 @@ void main() {
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
await logSub.cancel();
|
||||
restoreVmServiceConnectFunction();
|
||||
});
|
||||
|
||||
@@ -548,8 +549,7 @@ void main() {
|
||||
|
||||
group('sendCommand error conditions', () {
|
||||
test('local default timeout', () async {
|
||||
final List<String> log = <String>[];
|
||||
final StreamSubscription<LogRecord> logSub = flutterDriverLog.listen((LogRecord s) => log.add(s.toString()));
|
||||
log.clear();
|
||||
when(mockIsolate.invokeExtension(any, any)).thenAnswer((Invocation i) {
|
||||
// completer never completed to trigger timeout
|
||||
return Completer<Map<String, dynamic>>().future;
|
||||
@@ -559,13 +559,11 @@ void main() {
|
||||
expect(log, <String>[]);
|
||||
time.elapse(kUnusuallyLongTimeout);
|
||||
});
|
||||
expect(log, <String>['[warning] FlutterDriver: waitFor message is taking a long time to complete...']);
|
||||
await logSub.cancel();
|
||||
expect(log, <String>['FlutterDriver: waitFor message is taking a long time to complete...']);
|
||||
});
|
||||
|
||||
test('local custom timeout', () async {
|
||||
final List<String> log = <String>[];
|
||||
final StreamSubscription<LogRecord> logSub = flutterDriverLog.listen((LogRecord s) => log.add(s.toString()));
|
||||
log.clear();
|
||||
when(mockIsolate.invokeExtension(any, any)).thenAnswer((Invocation i) {
|
||||
// completer never completed to trigger timeout
|
||||
return Completer<Map<String, dynamic>>().future;
|
||||
@@ -576,8 +574,7 @@ void main() {
|
||||
expect(log, <String>[]);
|
||||
time.elapse(customTimeout);
|
||||
});
|
||||
expect(log, <String>['[warning] FlutterDriver: waitFor message is taking a long time to complete...']);
|
||||
await logSub.cancel();
|
||||
expect(log, <String>['FlutterDriver: waitFor message is taking a long time to complete...']);
|
||||
});
|
||||
|
||||
test('remote error', () async {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
@@ -17,6 +18,16 @@ import 'package:flutter_driver/src/common/wait.dart';
|
||||
import 'package:flutter_driver/src/extension/extension.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
Future<void> silenceDriverLogger(AsyncCallback callback) async {
|
||||
final DriverLogCallback oldLogger = driverLog;
|
||||
driverLog = (String source, String message) { };
|
||||
try {
|
||||
await callback();
|
||||
} finally {
|
||||
driverLog = oldLogger;
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
group('waitUntilNoTransientCallbacks', () {
|
||||
FlutterDriverExtension extension;
|
||||
@@ -530,197 +541,201 @@ void main() {
|
||||
});
|
||||
|
||||
testWidgets('descendant finder', (WidgetTester tester) async {
|
||||
flutterDriverLog.listen((LogRecord _) {}); // Silence logging.
|
||||
final FlutterDriverExtension extension = FlutterDriverExtension((String arg) async => '', true);
|
||||
await silenceDriverLogger(() async {
|
||||
final FlutterDriverExtension extension = FlutterDriverExtension((String arg) async => '', true);
|
||||
|
||||
Future<String> getDescendantText({ String of, bool matchRoot = false}) async {
|
||||
final Map<String, Object> arguments = GetText(Descendant(
|
||||
of: ByValueKey(of),
|
||||
matching: ByValueKey('text2'),
|
||||
matchRoot: matchRoot,
|
||||
), timeout: const Duration(seconds: 1)).serialize();
|
||||
final Map<String, dynamic> result = await extension.call(arguments);
|
||||
if (result['isError']) {
|
||||
return null;
|
||||
Future<String> getDescendantText({ String of, bool matchRoot = false}) async {
|
||||
final Map<String, Object> arguments = GetText(Descendant(
|
||||
of: ByValueKey(of),
|
||||
matching: ByValueKey('text2'),
|
||||
matchRoot: matchRoot,
|
||||
), timeout: const Duration(seconds: 1)).serialize();
|
||||
final Map<String, dynamic> result = await extension.call(arguments);
|
||||
if (result['isError']) {
|
||||
return null;
|
||||
}
|
||||
return GetTextResult.fromJson(result['response']).text;
|
||||
}
|
||||
return GetTextResult.fromJson(result['response']).text;
|
||||
}
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Column(
|
||||
key: const ValueKey<String>('column'),
|
||||
children: const <Widget>[
|
||||
Text('Hello1', key: ValueKey<String>('text1')),
|
||||
Text('Hello2', key: ValueKey<String>('text2')),
|
||||
Text('Hello3', key: ValueKey<String>('text3')),
|
||||
],
|
||||
)
|
||||
)
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Column(
|
||||
key: const ValueKey<String>('column'),
|
||||
children: const <Widget>[
|
||||
Text('Hello1', key: ValueKey<String>('text1')),
|
||||
Text('Hello2', key: ValueKey<String>('text2')),
|
||||
Text('Hello3', key: ValueKey<String>('text3')),
|
||||
],
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
expect(await getDescendantText(of: 'column'), 'Hello2');
|
||||
expect(await getDescendantText(of: 'column', matchRoot: true), 'Hello2');
|
||||
expect(await getDescendantText(of: 'text2', matchRoot: true), 'Hello2');
|
||||
expect(await getDescendantText(of: 'column'), 'Hello2');
|
||||
expect(await getDescendantText(of: 'column', matchRoot: true), 'Hello2');
|
||||
expect(await getDescendantText(of: 'text2', matchRoot: true), 'Hello2');
|
||||
|
||||
// Find nothing
|
||||
Future<String> result = getDescendantText(of: 'text1', matchRoot: true);
|
||||
await tester.pump(const Duration(seconds: 2));
|
||||
expect(await result, null);
|
||||
// Find nothing
|
||||
Future<String> result = getDescendantText(of: 'text1', matchRoot: true);
|
||||
await tester.pump(const Duration(seconds: 2));
|
||||
expect(await result, null);
|
||||
|
||||
result = getDescendantText(of: 'text2');
|
||||
await tester.pump(const Duration(seconds: 2));
|
||||
expect(await result, null);
|
||||
result = getDescendantText(of: 'text2');
|
||||
await tester.pump(const Duration(seconds: 2));
|
||||
expect(await result, null);
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('descendant finder firstMatchOnly', (WidgetTester tester) async {
|
||||
flutterDriverLog.listen((LogRecord _) {}); // Silence logging.
|
||||
final FlutterDriverExtension extension = FlutterDriverExtension((String arg) async => '', true);
|
||||
await silenceDriverLogger(() async {
|
||||
final FlutterDriverExtension extension = FlutterDriverExtension((String arg) async => '', true);
|
||||
|
||||
Future<String> getDescendantText() async {
|
||||
final Map<String, Object> arguments = GetText(Descendant(
|
||||
of: ByValueKey('column'),
|
||||
matching: const ByType('Text'),
|
||||
firstMatchOnly: true,
|
||||
), timeout: const Duration(seconds: 1)).serialize();
|
||||
final Map<String, dynamic> result = await extension.call(arguments);
|
||||
if (result['isError']) {
|
||||
return null;
|
||||
Future<String> getDescendantText() async {
|
||||
final Map<String, Object> arguments = GetText(Descendant(
|
||||
of: ByValueKey('column'),
|
||||
matching: const ByType('Text'),
|
||||
firstMatchOnly: true,
|
||||
), timeout: const Duration(seconds: 1)).serialize();
|
||||
final Map<String, dynamic> result = await extension.call(arguments);
|
||||
if (result['isError']) {
|
||||
return null;
|
||||
}
|
||||
return GetTextResult.fromJson(result['response']).text;
|
||||
}
|
||||
return GetTextResult.fromJson(result['response']).text;
|
||||
}
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Column(
|
||||
key: const ValueKey<String>('column'),
|
||||
children: const <Widget>[
|
||||
Text('Hello1', key: ValueKey<String>('text1')),
|
||||
Text('Hello2', key: ValueKey<String>('text2')),
|
||||
Text('Hello3', key: ValueKey<String>('text3')),
|
||||
],
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Column(
|
||||
key: const ValueKey<String>('column'),
|
||||
children: const <Widget>[
|
||||
Text('Hello1', key: ValueKey<String>('text1')),
|
||||
Text('Hello2', key: ValueKey<String>('text2')),
|
||||
Text('Hello3', key: ValueKey<String>('text3')),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
);
|
||||
|
||||
expect(await getDescendantText(), 'Hello1');
|
||||
expect(await getDescendantText(), 'Hello1');
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('ancestor finder', (WidgetTester tester) async {
|
||||
flutterDriverLog.listen((LogRecord _) {}); // Silence logging.
|
||||
final FlutterDriverExtension extension = FlutterDriverExtension((String arg) async => '', true);
|
||||
await silenceDriverLogger(() async {
|
||||
final FlutterDriverExtension extension = FlutterDriverExtension((String arg) async => '', true);
|
||||
|
||||
Future<Offset> getAncestorTopLeft({ String of, String matching, bool matchRoot = false}) async {
|
||||
final Map<String, Object> arguments = GetOffset(Ancestor(
|
||||
of: ByValueKey(of),
|
||||
matching: ByValueKey(matching),
|
||||
matchRoot: matchRoot,
|
||||
), OffsetType.topLeft, timeout: const Duration(seconds: 1)).serialize();
|
||||
final Map<String, dynamic> response = await extension.call(arguments);
|
||||
if (response['isError']) {
|
||||
return null;
|
||||
Future<Offset> getAncestorTopLeft({ String of, String matching, bool matchRoot = false}) async {
|
||||
final Map<String, Object> arguments = GetOffset(Ancestor(
|
||||
of: ByValueKey(of),
|
||||
matching: ByValueKey(matching),
|
||||
matchRoot: matchRoot,
|
||||
), OffsetType.topLeft, timeout: const Duration(seconds: 1)).serialize();
|
||||
final Map<String, dynamic> response = await extension.call(arguments);
|
||||
if (response['isError']) {
|
||||
return null;
|
||||
}
|
||||
final GetOffsetResult result = GetOffsetResult.fromJson(response['response']);
|
||||
return Offset(result.dx, result.dy);
|
||||
}
|
||||
final GetOffsetResult result = GetOffsetResult.fromJson(response['response']);
|
||||
return Offset(result.dx, result.dy);
|
||||
}
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Center(
|
||||
child: Container(
|
||||
key: const ValueKey<String>('parent'),
|
||||
height: 100,
|
||||
width: 100,
|
||||
child: Center(
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
key: const ValueKey<String>('leftchild'),
|
||||
width: 25,
|
||||
height: 25,
|
||||
),
|
||||
Container(
|
||||
key: const ValueKey<String>('righttchild'),
|
||||
width: 25,
|
||||
height: 25,
|
||||
),
|
||||
],
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Center(
|
||||
child: Container(
|
||||
key: const ValueKey<String>('parent'),
|
||||
height: 100,
|
||||
width: 100,
|
||||
child: Center(
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
key: const ValueKey<String>('leftchild'),
|
||||
width: 25,
|
||||
height: 25,
|
||||
),
|
||||
Container(
|
||||
key: const ValueKey<String>('righttchild'),
|
||||
width: 25,
|
||||
height: 25,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
),
|
||||
)
|
||||
);
|
||||
)
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
expect(
|
||||
await getAncestorTopLeft(of: 'leftchild', matching: 'parent'),
|
||||
const Offset((800 - 100) / 2, (600 - 100) / 2),
|
||||
);
|
||||
expect(
|
||||
await getAncestorTopLeft(of: 'leftchild', matching: 'parent', matchRoot: true),
|
||||
const Offset((800 - 100) / 2, (600 - 100) / 2),
|
||||
);
|
||||
expect(
|
||||
await getAncestorTopLeft(of: 'parent', matching: 'parent', matchRoot: true),
|
||||
const Offset((800 - 100) / 2, (600 - 100) / 2),
|
||||
);
|
||||
expect(
|
||||
await getAncestorTopLeft(of: 'leftchild', matching: 'parent'),
|
||||
const Offset((800 - 100) / 2, (600 - 100) / 2),
|
||||
);
|
||||
expect(
|
||||
await getAncestorTopLeft(of: 'leftchild', matching: 'parent', matchRoot: true),
|
||||
const Offset((800 - 100) / 2, (600 - 100) / 2),
|
||||
);
|
||||
expect(
|
||||
await getAncestorTopLeft(of: 'parent', matching: 'parent', matchRoot: true),
|
||||
const Offset((800 - 100) / 2, (600 - 100) / 2),
|
||||
);
|
||||
|
||||
// Find nothing
|
||||
Future<Offset> result = getAncestorTopLeft(of: 'leftchild', matching: 'leftchild');
|
||||
await tester.pump(const Duration(seconds: 2));
|
||||
expect(await result, null);
|
||||
// Find nothing
|
||||
Future<Offset> result = getAncestorTopLeft(of: 'leftchild', matching: 'leftchild');
|
||||
await tester.pump(const Duration(seconds: 2));
|
||||
expect(await result, null);
|
||||
|
||||
result = getAncestorTopLeft(of: 'leftchild', matching: 'righttchild');
|
||||
await tester.pump(const Duration(seconds: 2));
|
||||
expect(await result, null);
|
||||
result = getAncestorTopLeft(of: 'leftchild', matching: 'righttchild');
|
||||
await tester.pump(const Duration(seconds: 2));
|
||||
expect(await result, null);
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('ancestor finder firstMatchOnly', (WidgetTester tester) async {
|
||||
flutterDriverLog.listen((LogRecord _) {}); // Silence logging.
|
||||
final FlutterDriverExtension extension = FlutterDriverExtension((String arg) async => '', true);
|
||||
await silenceDriverLogger(() async {
|
||||
final FlutterDriverExtension extension = FlutterDriverExtension((String arg) async => '', true);
|
||||
|
||||
Future<Offset> getAncestorTopLeft() async {
|
||||
final Map<String, Object> arguments = GetOffset(Ancestor(
|
||||
of: ByValueKey('leaf'),
|
||||
matching: const ByType('Container'),
|
||||
firstMatchOnly: true,
|
||||
), OffsetType.topLeft, timeout: const Duration(seconds: 1)).serialize();
|
||||
final Map<String, dynamic> response = await extension.call(arguments);
|
||||
if (response['isError']) {
|
||||
return null;
|
||||
Future<Offset> getAncestorTopLeft() async {
|
||||
final Map<String, Object> arguments = GetOffset(Ancestor(
|
||||
of: ByValueKey('leaf'),
|
||||
matching: const ByType('Container'),
|
||||
firstMatchOnly: true,
|
||||
), OffsetType.topLeft, timeout: const Duration(seconds: 1)).serialize();
|
||||
final Map<String, dynamic> response = await extension.call(arguments);
|
||||
if (response['isError']) {
|
||||
return null;
|
||||
}
|
||||
final GetOffsetResult result = GetOffsetResult.fromJson(response['response']);
|
||||
return Offset(result.dx, result.dy);
|
||||
}
|
||||
final GetOffsetResult result = GetOffsetResult.fromJson(response['response']);
|
||||
return Offset(result.dx, result.dy);
|
||||
}
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Center(
|
||||
child: Container(
|
||||
height: 200,
|
||||
width: 200,
|
||||
child: Center(
|
||||
child: Container(
|
||||
height: 100,
|
||||
width: 100,
|
||||
child: Center(
|
||||
child: Container(
|
||||
key: const ValueKey<String>('leaf'),
|
||||
height: 50,
|
||||
width: 50,
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Center(
|
||||
child: Container(
|
||||
height: 200,
|
||||
width: 200,
|
||||
child: Center(
|
||||
child: Container(
|
||||
height: 100,
|
||||
width: 100,
|
||||
child: Center(
|
||||
child: Container(
|
||||
key: const ValueKey<String>('leaf'),
|
||||
height: 50,
|
||||
width: 50,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
);
|
||||
|
||||
expect(
|
||||
await getAncestorTopLeft(),
|
||||
const Offset((800 - 100) / 2, (600 - 100) / 2),
|
||||
);
|
||||
expect(
|
||||
await getAncestorTopLeft(),
|
||||
const Offset((800 - 100) / 2, (600 - 100) / 2),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('GetDiagnosticsTree', (WidgetTester tester) async {
|
||||
|
||||
Reference in New Issue
Block a user