Unverified Commit 09940e4a authored by Greg Price's avatar Greg Price Committed by GitHub

Make tester.startGesture less async, for better stack traces (#123946)

Make tester.startGesture less async, for better stack traces
parent 806c1f81
......@@ -1133,6 +1133,19 @@ abstract class WidgetController {
return result;
}
TestGesture _createGesture({
int? pointer,
required PointerDeviceKind kind,
required int buttons,
}) {
return TestGesture(
dispatcher: sendEventToBinding,
kind: kind,
pointer: pointer ?? _getNextPointer(),
buttons: buttons,
);
}
/// Creates gesture and returns the [TestGesture] object which you can use
/// to continue the gesture using calls on the [TestGesture] object.
///
......@@ -1143,12 +1156,7 @@ abstract class WidgetController {
PointerDeviceKind kind = PointerDeviceKind.touch,
int buttons = kPrimaryButton,
}) async {
return TestGesture(
dispatcher: sendEventToBinding,
kind: kind,
pointer: pointer ?? _getNextPointer(),
buttons: buttons,
);
return _createGesture(pointer: pointer, kind: kind, buttons: buttons);
}
/// Creates a gesture with an initial appropriate starting gesture at a
......@@ -1172,11 +1180,7 @@ abstract class WidgetController {
PointerDeviceKind kind = PointerDeviceKind.touch,
int buttons = kPrimaryButton,
}) async {
final TestGesture result = await createGesture(
pointer: pointer,
kind: kind,
buttons: buttons,
);
final TestGesture result = _createGesture(pointer: pointer, kind: kind, buttons: buttons);
if (kind == PointerDeviceKind.trackpad) {
await result.panZoomStart(downLocation);
} else {
......
......@@ -7,6 +7,7 @@ import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/semantics.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:stack_trace/stack_trace.dart';
class TestDragData {
const TestDragData(
......@@ -555,6 +556,34 @@ void main() {
},
);
testWidgets(
'WidgetTester.tap appears in stack trace on error',
(WidgetTester tester) async {
// Regression test from https://github.com/flutter/flutter/pull/123946
await tester.pumpWidget(
const MaterialApp(home: Scaffold(body: Text('target'))));
final TestGesture gesture = await tester.startGesture(
tester.getCenter(find.text('target')), pointer: 1);
addTearDown(() => gesture.up());
Trace? stackTrace;
try {
await tester.tap(find.text('target'), pointer: 1);
} on Error catch (e) {
stackTrace = Trace.from(e.stackTrace!);
}
expect(stackTrace, isNotNull);
final int tapFrame = stackTrace!.frames.indexWhere(
(Frame frame) => frame.member == 'WidgetController.tap');
expect(tapFrame, greaterThanOrEqualTo(0));
expect(stackTrace.frames[tapFrame].package, 'flutter_test');
expect(stackTrace.frames[tapFrame+1].member, 'main.<fn>');
expect(stackTrace.frames[tapFrame+1].package, null);
},
);
testWidgets(
'ensureVisible: scrolls to make widget visible',
(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