Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions dev/integration_tests/flutter_gallery/test/live_smoketest.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart' show kPrimaryButton;
import 'package:flutter/gestures.dart' show PointerDeviceKind, kPrimaryButton;
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart';
Expand Down Expand Up @@ -137,13 +137,18 @@ class _LiveWidgetController extends LiveWidgetController {
return finder;
}

@override
Future<void> tap(FinderBase<Element> finder, { int? pointer, int buttons = kPrimaryButton, bool warnIfMissed = true }) async {
await super.tap(await _waitForElement(finder), pointer: pointer, buttons: buttons, warnIfMissed: warnIfMissed);
}

Future<void> scrollIntoView(FinderBase<Element> finder, {required double alignment}) async {
final FinderBase<Element> target = await _waitForElement(finder);
await Scrollable.ensureVisible(target.evaluate().single, duration: const Duration(milliseconds: 100), alignment: alignment);
}

@override
Future<void> tap(FinderBase<Element> finder, {
int? pointer,
int buttons = kPrimaryButton,
bool warnIfMissed = true,
PointerDeviceKind kind = PointerDeviceKind.touch,
}) async {
await super.tap(await _waitForElement(finder), pointer: pointer, buttons: buttons, warnIfMissed: warnIfMissed, kind: kind);
}
}
14 changes: 7 additions & 7 deletions packages/flutter/test/material/slider_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3432,7 +3432,7 @@ void main() {
await gesture.up();
await tester.pumpAndSettle();
expect(value, isNot(equals(0.5)));
// The slider does not have have focus after the value is changed.
// The slider does not have focus after the value is changed.
expect(focusNode.hasFocus, false);
});

Expand Down Expand Up @@ -3618,8 +3618,8 @@ void main() {
);
}, variant: TargetPlatformVariant.desktop());

testWidgetsWithLeakTracking('Value indicator disappears after adjusting the slider', (WidgetTester tester) async {
// This is a regression test for https://github.com/flutter/flutter/issues/123313.
// Regression test for https://github.com/flutter/flutter/issues/123313, which only occurs on desktop platforms.
testWidgetsWithLeakTracking('Value indicator disappears after adjusting the slider on desktop', (WidgetTester tester) async {
final ThemeData theme = ThemeData(useMaterial3: true);
const double currentValue = 0.5;
await tester.pumpWidget(MaterialApp(
Expand All @@ -3630,7 +3630,7 @@ void main() {
value: currentValue,
divisions: 5,
label: currentValue.toStringAsFixed(1),
onChanged: (double value) {},
onChanged: (_) {},
),
),
),
Expand All @@ -3647,8 +3647,8 @@ void main() {
final Offset sliderCenter = tester.getCenter(find.byType(Slider));
final Offset tapLocation = Offset(sliderCenter.dx + 50, sliderCenter.dy);

// Tap the slider to bring up the value indicator.
await tester.tapAt(tapLocation);
// Tap the slider by mouse to bring up the value indicator.
await tester.tapAt(tapLocation, kind: PointerDeviceKind.mouse);
await tester.pumpAndSettle();

// Value indicator is visible.
Expand All @@ -3666,7 +3666,7 @@ void main() {
valueIndicatorBox,
isNot(paints..scale()..path(color: theme.colorScheme.primary)),
);
});
}, variant: TargetPlatformVariant.desktop());

testWidgetsWithLeakTracking('Value indicator remains when Slider is in focus on desktop', (WidgetTester tester) async {
double value = 0.5;
Expand Down
58 changes: 48 additions & 10 deletions packages/flutter_test/lib/src/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -987,14 +987,25 @@ abstract class WidgetController {
/// For example, a test that verifies that tapping a disabled button does not
/// trigger the button would set `warnIfMissed` to false, because the button
/// would ignore the tap.
Future<void> tap(finders.FinderBase<Element> finder, {int? pointer, int buttons = kPrimaryButton, bool warnIfMissed = true}) {
return tapAt(getCenter(finder, warnIfMissed: warnIfMissed, callee: 'tap'), pointer: pointer, buttons: buttons);
Future<void> tap(
finders.FinderBase<Element> finder, {
int? pointer,
int buttons = kPrimaryButton,
bool warnIfMissed = true,
PointerDeviceKind kind = PointerDeviceKind.touch,
}) {
return tapAt(getCenter(finder, warnIfMissed: warnIfMissed, callee: 'tap'), pointer: pointer, buttons: buttons, kind: kind);
}

/// Dispatch a pointer down / pointer up sequence at the given location.
Future<void> tapAt(Offset location, {int? pointer, int buttons = kPrimaryButton}) {
Future<void> tapAt(
Offset location, {
int? pointer,
int buttons = kPrimaryButton,
PointerDeviceKind kind = PointerDeviceKind.touch,
}) {
return TestAsyncUtils.guard<void>(() async {
final TestGesture gesture = await startGesture(location, pointer: pointer, buttons: buttons);
final TestGesture gesture = await startGesture(location, pointer: pointer, buttons: buttons, kind: kind);
await gesture.up();
});
}
Expand All @@ -1012,9 +1023,20 @@ abstract class WidgetController {
/// * [tap], which presses and releases a pointer at the given location.
/// * [longPress], which presses and releases a pointer with a gap in
/// between long enough to trigger the long-press gesture.
Future<TestGesture> press(finders.FinderBase<Element> finder, {int? pointer, int buttons = kPrimaryButton, bool warnIfMissed = true}) {
Future<TestGesture> press(
finders.FinderBase<Element> finder, {
int? pointer,
int buttons = kPrimaryButton,
bool warnIfMissed = true,
PointerDeviceKind kind = PointerDeviceKind.touch,
}) {
return TestAsyncUtils.guard<TestGesture>(() {
return startGesture(getCenter(finder, warnIfMissed: warnIfMissed, callee: 'press'), pointer: pointer, buttons: buttons);
return startGesture(
getCenter(finder, warnIfMissed: warnIfMissed, callee: 'press'),
pointer: pointer,
buttons: buttons,
kind: kind,
);
});
}

Expand All @@ -1030,15 +1052,31 @@ abstract class WidgetController {
/// later verify that long-pressing the same location (using the same finder)
/// has no effect (since the widget is now obscured), setting `warnIfMissed`
/// to false on that second call.
Future<void> longPress(finders.FinderBase<Element> finder, {int? pointer, int buttons = kPrimaryButton, bool warnIfMissed = true}) {
return longPressAt(getCenter(finder, warnIfMissed: warnIfMissed, callee: 'longPress'), pointer: pointer, buttons: buttons);
Future<void> longPress(
finders.FinderBase<Element> finder, {
int? pointer,
int buttons = kPrimaryButton,
bool warnIfMissed = true,
PointerDeviceKind kind = PointerDeviceKind.touch,
}) {
return longPressAt(
getCenter(finder, warnIfMissed: warnIfMissed, callee: 'longPress'),
pointer: pointer,
buttons: buttons,
kind: kind,
);
}

/// Dispatch a pointer down / pointer up sequence at the given location with
/// a delay of [kLongPressTimeout] + [kPressTimeout] between the two events.
Future<void> longPressAt(Offset location, {int? pointer, int buttons = kPrimaryButton}) {
Future<void> longPressAt(
Offset location, {
int? pointer,
int buttons = kPrimaryButton,
PointerDeviceKind kind = PointerDeviceKind.touch,
}) {
return TestAsyncUtils.guard<void>(() async {
final TestGesture gesture = await startGesture(location, pointer: pointer, buttons: buttons);
final TestGesture gesture = await startGesture(location, pointer: pointer, buttons: buttons, kind: kind);
await pump(kLongPressTimeout + kPressTimeout);
await gesture.up();
});
Expand Down