Unverified Commit 2f0b4158 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Add option to silence driver extension errors (#19247)

parent e32e4479
......@@ -37,14 +37,15 @@ const String _extensionMethod = 'ext.flutter.$_extensionMethodName';
typedef Future<String> DataHandler(String message);
class _DriverBinding extends BindingBase with ServicesBinding, SchedulerBinding, GestureBinding, PaintingBinding, RendererBinding, WidgetsBinding {
_DriverBinding(this._handler);
_DriverBinding(this._handler, this._silenceErrors);
final DataHandler _handler;
final bool _silenceErrors;
@override
void initServiceExtensions() {
super.initServiceExtensions();
final FlutterDriverExtension extension = new FlutterDriverExtension(_handler);
final FlutterDriverExtension extension = new FlutterDriverExtension(_handler, _silenceErrors);
registerServiceExtension(
name: _extensionMethodName,
callback: extension.call,
......@@ -62,9 +63,14 @@ class _DriverBinding extends BindingBase with ServicesBinding, SchedulerBinding,
///
/// Optionally you can pass a [DataHandler] callback. It will be called if the
/// test calls [FlutterDriver.requestData].
void enableFlutterDriverExtension({ DataHandler handler }) {
///
/// `slienceErrors` will prevent exceptions from being logged. This is useful
/// for tests where exceptions are expected. Defaults to false. Any errors
/// will still be returned in the `response` field of the result json along
/// with an `isError` boolean.
void enableFlutterDriverExtension({ DataHandler handler, bool silenceErrors = false }) {
assert(WidgetsBinding.instance == null);
new _DriverBinding(handler);
new _DriverBinding(handler, silenceErrors);
assert(WidgetsBinding.instance is _DriverBinding);
}
......@@ -88,7 +94,7 @@ class FlutterDriverExtension {
final TestTextInput _testTextInput = new TestTextInput();
/// Creates an object to manage a Flutter Driver connection.
FlutterDriverExtension(this._requestDataHandler) {
FlutterDriverExtension(this._requestDataHandler, this._silenceErrors) {
_testTextInput.register();
_commandHandlers.addAll(<String, CommandHandlerCallback>{
......@@ -136,6 +142,7 @@ class FlutterDriverExtension {
}
final DataHandler _requestDataHandler;
final bool _silenceErrors;
static final Logger _log = new Logger('FlutterDriverExtension');
......@@ -176,7 +183,8 @@ class FlutterDriverExtension {
return _makeResponse(msg, isError: true);
} catch (error, stackTrace) {
final String msg = 'Uncaught extension error while executing $commandKind: $error\n$stackTrace';
_log.error(msg);
if (!_silenceErrors)
_log.error(msg);
return _makeResponse(msg, isError: true);
}
}
......
......@@ -19,7 +19,7 @@ void main() {
setUp(() {
result = null;
extension = new FlutterDriverExtension((String message) async { log.add(message); return (messageId += 1).toString(); });
extension = new FlutterDriverExtension((String message) async { log.add(message); return (messageId += 1).toString(); }, false);
});
testWidgets('returns immediately when transient callback queue is empty', (WidgetTester tester) async {
......@@ -74,7 +74,7 @@ void main() {
group('getSemanticsId', () {
FlutterDriverExtension extension;
setUp(() {
extension = new FlutterDriverExtension((String arg) async {});
extension = new FlutterDriverExtension((String arg) async {}, true);
});
testWidgets('works when semantics are enabled', (WidgetTester tester) async {
......
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