Re-enable SemanticsAction.focus matchers (#150990)

## Description

This re-enables the `SemanticsAction.focus` matchers so that they actually do something now instead of ignoring the action.

This was so that we could land the focus action changes without causing breakages in customer tests, and now that customer tests have been updated, we can land this PR turning it on again.

## Related Issues
 - Fixes https://github.com/flutter/flutter/issues/149842

## Related PRs
 - https://github.com/flutter/flutter/pull/149840

## Tests
 - Updates semantics tests to actually look for the focus action.
This commit is contained in:
Greg Spencer
2024-07-08 14:01:56 -07:00
committed by GitHub
parent f2be1260df
commit c082abe629
16 changed files with 122 additions and 82 deletions

View File

@@ -2266,10 +2266,6 @@ class _MatchesSemanticsData extends Matcher {
required bool? isExpanded,
// Actions
required bool? hasTapAction,
// TODO(gspencergoog): Once this has landed, and customer tests have been
// updated, remove the ignore below.
// https://github.com/flutter/flutter/issues/149842
// ignore: avoid_unused_constructor_parameters
required bool? hasFocusAction,
required bool? hasLongPressAction,
required bool? hasScrollLeftAction,
@@ -2329,9 +2325,7 @@ class _MatchesSemanticsData extends Matcher {
},
actions = <SemanticsAction, bool>{
if (hasTapAction != null) SemanticsAction.tap: hasTapAction,
// TODO(gspencergoog): Once this has landed, and customer tests have
// been updated, add a line here that adds handling for
// hasFocusAction. https://github.com/flutter/flutter/issues/149842
if (hasFocusAction != null) SemanticsAction.focus: hasFocusAction,
if (hasLongPressAction != null) SemanticsAction.longPress: hasLongPressAction,
if (hasScrollLeftAction != null) SemanticsAction.scrollLeft: hasScrollLeftAction,
if (hasScrollRightAction != null) SemanticsAction.scrollRight: hasScrollRightAction,
@@ -2429,19 +2423,12 @@ class _MatchesSemanticsData extends Matcher {
if (tooltip != null) {
description.add(' with tooltip: $tooltip');
}
// TODO(gspencergoog): Remove filter once customer tests have been updated
// with the proper actions information for focus.
// https://github.com/flutter/flutter/issues/149842
final Map<ui.SemanticsAction, bool> nonFocusActions =
Map<ui.SemanticsAction, bool>.fromEntries(actions.entries.where(
(MapEntry<ui.SemanticsAction, bool> e) => e.key != SemanticsAction.focus
));
if (nonFocusActions.isNotEmpty) {
final List<SemanticsAction> expectedActions = nonFocusActions.entries
if (actions.isNotEmpty) {
final List<SemanticsAction> expectedActions = actions.entries
.where((MapEntry<ui.SemanticsAction, bool> e) => e.value)
.map((MapEntry<ui.SemanticsAction, bool> e) => e.key)
.toList();
final List<SemanticsAction> notExpectedActions = nonFocusActions.entries
final List<SemanticsAction> notExpectedActions = actions.entries
.where((MapEntry<ui.SemanticsAction, bool> e) => !e.value)
.map((MapEntry<ui.SemanticsAction, bool> e) => e.key)
.toList();
@@ -2620,17 +2607,10 @@ class _MatchesSemanticsData extends Matcher {
if (maxValueLength != null && maxValueLength != data.maxValueLength) {
return failWithDescription(matchState, 'maxValueLength was: ${data.maxValueLength}');
}
// TODO(gspencergoog): Remove filter once customer tests have been updated
// with the proper actions information for focus.
// https://github.com/flutter/flutter/issues/149842
final Map<ui.SemanticsAction, bool> nonFocusActions =
Map<ui.SemanticsAction, bool>.fromEntries(actions.entries.where(
(MapEntry<ui.SemanticsAction, bool> e) => e.key != SemanticsAction.focus
));
if (nonFocusActions.isNotEmpty) {
if (actions.isNotEmpty) {
final List<SemanticsAction> unexpectedActions = <SemanticsAction>[];
final List<SemanticsAction> missingActions = <SemanticsAction>[];
for (final MapEntry<ui.SemanticsAction, bool> actionEntry in nonFocusActions.entries) {
for (final MapEntry<ui.SemanticsAction, bool> actionEntry in actions.entries) {
final ui.SemanticsAction action = actionEntry.key;
final bool actionExpected = actionEntry.value;
final bool actionPresent = (action.index & data.actions) == action.index;