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:
@@ -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