Format controller.dart of flutter_test (#159667)

Format controller.dart of flutter_test

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [ ] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
This commit is contained in:
Flop 2024-12-04 14:07:11 +08:00 committed by GitHub
parent 628ab7f493
commit 74757b3a04
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -322,7 +322,7 @@ class SemanticsController {
/// Recursive depth first traversal of the specified `node`, adding nodes /// Recursive depth first traversal of the specified `node`, adding nodes
/// that are important for semantics to the `traversal` list. /// that are important for semantics to the `traversal` list.
void _accessibilityTraversal(SemanticsNode node, List<SemanticsNode> traversal){ void _accessibilityTraversal(SemanticsNode node, List<SemanticsNode> traversal) {
if (_isImportantForAccessibility(node)) { if (_isImportantForAccessibility(node)) {
traversal.add(node); traversal.add(node);
} }
@ -381,10 +381,10 @@ class SemanticsController {
finders.FinderBase<SemanticsNode> finder, finders.FinderBase<SemanticsNode> finder,
SemanticsAction action, { SemanticsAction action, {
Object? args, Object? args,
bool checkForAction = true bool checkForAction = true,
}) { }) {
final SemanticsNode node = finder.evaluate().single; final SemanticsNode node = finder.evaluate().single;
if (checkForAction && !node.getSemanticsData().hasAction(action)){ if (checkForAction && !node.getSemanticsData().hasAction(action)) {
throw StateError( throw StateError(
'The given node does not support $action. If the action is implicitly ' 'The given node does not support $action. If the action is implicitly '
'supported or an unsupported action is being tested for this node, ' 'supported or an unsupported action is being tested for this node, '
@ -515,12 +515,12 @@ class SemanticsController {
/// [SemanticsAction.moveCursorForwardByCharacter]. /// [SemanticsAction.moveCursorForwardByCharacter].
void moveCursorForwardByCharacter( void moveCursorForwardByCharacter(
finders.FinderBase<SemanticsNode> finder, { finders.FinderBase<SemanticsNode> finder, {
bool shouldModifySelection = false bool shouldModifySelection = false,
}) { }) {
performAction( performAction(
finder, finder,
SemanticsAction.moveCursorForwardByCharacter, SemanticsAction.moveCursorForwardByCharacter,
args: shouldModifySelection args: shouldModifySelection,
); );
} }
@ -533,12 +533,12 @@ class SemanticsController {
/// [SemanticsAction.moveCursorForwardByWord]. /// [SemanticsAction.moveCursorForwardByWord].
void moveCursorForwardByWord( void moveCursorForwardByWord(
finders.FinderBase<SemanticsNode> finder, { finders.FinderBase<SemanticsNode> finder, {
bool shouldModifySelection = false bool shouldModifySelection = false,
}) { }) {
performAction( performAction(
finder, finder,
SemanticsAction.moveCursorForwardByWord, SemanticsAction.moveCursorForwardByWord,
args: shouldModifySelection args: shouldModifySelection,
); );
} }
@ -554,12 +554,12 @@ class SemanticsController {
/// [SemanticsAction.moveCursorBackwardByCharacter]. /// [SemanticsAction.moveCursorBackwardByCharacter].
void moveCursorBackwardByCharacter( void moveCursorBackwardByCharacter(
finders.FinderBase<SemanticsNode> finder, { finders.FinderBase<SemanticsNode> finder, {
bool shouldModifySelection = false bool shouldModifySelection = false,
}) { }) {
performAction( performAction(
finder, finder,
SemanticsAction.moveCursorBackwardByCharacter, SemanticsAction.moveCursorBackwardByCharacter,
args: shouldModifySelection args: shouldModifySelection,
); );
} }
@ -572,12 +572,12 @@ class SemanticsController {
/// [SemanticsAction.moveCursorBackwardByWord]. /// [SemanticsAction.moveCursorBackwardByWord].
void moveCursorBackwardByWord( void moveCursorBackwardByWord(
finders.FinderBase<SemanticsNode> finder, { finders.FinderBase<SemanticsNode> finder, {
bool shouldModifySelection = false bool shouldModifySelection = false,
}) { }) {
performAction( performAction(
finder, finder,
SemanticsAction.moveCursorBackwardByWord, SemanticsAction.moveCursorBackwardByWord,
args: shouldModifySelection args: shouldModifySelection,
); );
} }
@ -606,7 +606,7 @@ class SemanticsController {
void setSelection( void setSelection(
finders.FinderBase<SemanticsNode> finder, { finders.FinderBase<SemanticsNode> finder, {
required int base, required int base,
required int extent required int extent,
}) { }) {
performAction( performAction(
finder, finder,
@ -681,7 +681,7 @@ class SemanticsController {
performAction( performAction(
finder, finder,
SemanticsAction.customAction, SemanticsAction.customAction,
args: CustomSemanticsAction.getIdentifier(action) args: CustomSemanticsAction.getIdentifier(action),
); );
} }
@ -1000,6 +1000,7 @@ abstract class WidgetController {
..._walkLayers(renderView.debugLayer!) ..._walkLayers(renderView.debugLayer!)
]; ];
} }
Iterable<Layer> _walkLayers(Layer layer) sync* { Iterable<Layer> _walkLayers(Layer layer) sync* {
TestAsyncUtils.guardSync(); TestAsyncUtils.guardSync();
yield layer; yield layer;
@ -1059,7 +1060,7 @@ abstract class WidgetController {
/// ///
/// The `pointer` and `button` arguments specify [PointerEvent.pointer] and /// The `pointer` and `button` arguments specify [PointerEvent.pointer] and
/// [PointerEvent.buttons] of the tap event. /// [PointerEvent.buttons] of the tap event.
Future<void> tapOnText(finders.FinderBase<finders.TextRangeContext> textRangeFinder, {int? pointer, int buttons = kPrimaryButton }) { Future<void> tapOnText(finders.FinderBase<finders.TextRangeContext> textRangeFinder, { int? pointer, int buttons = kPrimaryButton }) {
final Iterable<finders.TextRangeContext> ranges = textRangeFinder.evaluate(); final Iterable<finders.TextRangeContext> ranges = textRangeFinder.evaluate();
if (ranges.isEmpty) { if (ranges.isEmpty) {
throw FlutterError(textRangeFinder.toString()); throw FlutterError(textRangeFinder.toString());
@ -1073,13 +1074,12 @@ abstract class WidgetController {
if (tapLocation == null) { if (tapLocation == null) {
final finders.TextRangeContext found = textRangeFinder.evaluate().single; final finders.TextRangeContext found = textRangeFinder.evaluate().single;
throw FlutterError.fromParts(<DiagnosticsNode>[ throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('Finder specifies a TextRange that can not receive pointer events.'), ErrorSummary('Finder specifies a TextRange that can not receive pointer events.'),
ErrorDescription('The finder used was: ${textRangeFinder.toString(describeSelf: true)}'), ErrorDescription('The finder used was: ${textRangeFinder.toString(describeSelf: true)}'),
ErrorDescription('Found a matching substring in a static text widget, within ${found.textRange}.'), ErrorDescription('Found a matching substring in a static text widget, within ${found.textRange}.'),
ErrorDescription('But the "tapOnText" method could not find a hit-testable Offset with in that text range.'), ErrorDescription('But the "tapOnText" method could not find a hit-testable Offset with in that text range.'),
found.renderObject.toDiagnosticsNode(name: 'The RenderBox of that static text widget was', style: DiagnosticsTreeStyle.shallow), found.renderObject.toDiagnosticsNode(name: 'The RenderBox of that static text widget was', style: DiagnosticsTreeStyle.shallow),
] ]);
);
} }
return tapAt(tapLocation, pointer: pointer, buttons: buttons); return tapAt(tapLocation, pointer: pointer, buttons: buttons);
} }
@ -1643,22 +1643,22 @@ abstract class WidgetController {
]; ];
final List<PointerEventRecord> records = <PointerEventRecord>[ final List<PointerEventRecord> records = <PointerEventRecord>[
PointerEventRecord(Duration.zero, <PointerEvent>[ PointerEventRecord(Duration.zero, <PointerEvent>[
PointerAddedEvent( PointerAddedEvent(
position: startLocation, position: startLocation,
), ),
PointerDownEvent( PointerDownEvent(
position: startLocation, position: startLocation,
pointer: pointer, pointer: pointer,
buttons: buttons, buttons: buttons,
), ),
]), ]),
...<PointerEventRecord>[ ...<PointerEventRecord>[
for (int t = 0; t <= intervals; t += 1) for (int t = 0; t <= intervals; t += 1)
PointerEventRecord(timeStamps[t], <PointerEvent>[ PointerEventRecord(timeStamps[t], <PointerEvent>[
PointerMoveEvent( PointerMoveEvent(
timeStamp: timeStamps[t], timeStamp: timeStamps[t],
position: offsets[t+1], position: offsets[t + 1],
delta: offsets[t+1] - offsets[t], delta: offsets[t + 1] - offsets[t],
pointer: pointer, pointer: pointer,
buttons: buttons, buttons: buttons,
), ),
@ -1993,7 +1993,7 @@ abstract class WidgetController {
LogicalKeyboardKey key, { LogicalKeyboardKey key, {
String? platform, String? platform,
String? character, String? character,
PhysicalKeyboardKey? physicalKey PhysicalKeyboardKey? physicalKey,
}) async { }) async {
final bool handled = await simulateKeyDownEvent(key, platform: platform, character: character, physicalKey: physicalKey); final bool handled = await simulateKeyDownEvent(key, platform: platform, character: character, physicalKey: physicalKey);
// Internally wrapped in async guard. // Internally wrapped in async guard.
@ -2032,7 +2032,7 @@ abstract class WidgetController {
LogicalKeyboardKey key, { LogicalKeyboardKey key, {
String? platform, String? platform,
String? character, String? character,
PhysicalKeyboardKey? physicalKey PhysicalKeyboardKey? physicalKey,
}) async { }) async {
// Internally wrapped in async guard. // Internally wrapped in async guard.
return simulateKeyDownEvent(key, platform: platform, character: character, physicalKey: physicalKey); return simulateKeyDownEvent(key, platform: platform, character: character, physicalKey: physicalKey);
@ -2060,10 +2060,10 @@ abstract class WidgetController {
/// corresponding key down and repeat event. /// corresponding key down and repeat event.
/// - [sendKeyEvent] to simulate both the key up and key down in the same call. /// - [sendKeyEvent] to simulate both the key up and key down in the same call.
Future<bool> sendKeyUpEvent( Future<bool> sendKeyUpEvent(
LogicalKeyboardKey key, { LogicalKeyboardKey key, {
String? platform, String? platform,
PhysicalKeyboardKey? physicalKey PhysicalKeyboardKey? physicalKey,
}) async { }) async {
// Internally wrapped in async guard. // Internally wrapped in async guard.
return simulateKeyUpEvent(key, platform: platform, physicalKey: physicalKey); return simulateKeyUpEvent(key, platform: platform, physicalKey: physicalKey);
} }
@ -2096,11 +2096,11 @@ abstract class WidgetController {
/// key down and up event. /// key down and up event.
/// - [sendKeyEvent] to simulate both the key up and key down in the same call. /// - [sendKeyEvent] to simulate both the key up and key down in the same call.
Future<bool> sendKeyRepeatEvent( Future<bool> sendKeyRepeatEvent(
LogicalKeyboardKey key, { LogicalKeyboardKey key, {
String? platform, String? platform,
String? character, String? character,
PhysicalKeyboardKey? physicalKey PhysicalKeyboardKey? physicalKey,
}) async { }) async {
// Internally wrapped in async guard. // Internally wrapped in async guard.
return simulateKeyRepeatEvent(key, platform: platform, character: character, physicalKey: physicalKey); return simulateKeyRepeatEvent(key, platform: platform, character: character, physicalKey: physicalKey);
} }
@ -2175,11 +2175,10 @@ abstract class WidgetController {
Future<void> scrollUntilVisible( Future<void> scrollUntilVisible(
finders.FinderBase<Element> finder, finders.FinderBase<Element> finder,
double delta, { double delta, {
finders.FinderBase<Element>? scrollable, finders.FinderBase<Element>? scrollable,
int maxScrolls = 50, int maxScrolls = 50,
Duration duration = const Duration(milliseconds: 50), Duration duration = const Duration(milliseconds: 50),
} }) {
) {
assert(maxScrolls > 0); assert(maxScrolls > 0);
scrollable ??= finders.find.byType(Scrollable); scrollable ??= finders.find.byType(Scrollable);
return TestAsyncUtils.guard<void>(() async { return TestAsyncUtils.guard<void>(() async {
@ -2219,8 +2218,8 @@ abstract class WidgetController {
finders.FinderBase<Element> finder, finders.FinderBase<Element> finder,
finders.FinderBase<Element> view, finders.FinderBase<Element> view,
Offset moveStep, { Offset moveStep, {
int maxIteration = 50, int maxIteration = 50,
Duration duration = const Duration(milliseconds: 50), Duration duration = const Duration(milliseconds: 50),
}) { }) {
return TestAsyncUtils.guard<void>(() async { return TestAsyncUtils.guard<void>(() async {
while (maxIteration > 0 && finder.evaluate().isEmpty) { while (maxIteration > 0 && finder.evaluate().isEmpty) {